Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions FML/COLASolver/src/Simulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ void NBodySimulation<NDIM, T>::init() {
const int col_k = 0;
const int col_pofk = 1;
std::vector<int> cols_to_keep{col_k, col_pofk};
const int nheaderlines = 1;
const int nheaderlines = -1; // skip header comments
auto pofkdata = FML::FILEUTILS::read_regular_ascii(ic_input_filename, ncols, cols_to_keep, nheaderlines);

karr.resize(pofkdata.size());
Expand Down Expand Up @@ -838,7 +838,7 @@ void NBodySimulation<NDIM, T>::init() {
const int col_k = 0;
const int col_tofk = 1;
std::vector<int> cols_to_keep{col_k, col_tofk};
const int nheaderlines = 1;
const int nheaderlines = -1; // skip header comments
auto tofkdata = FML::FILEUTILS::read_regular_ascii(ic_input_filename, ncols, cols_to_keep, nheaderlines);

karr.resize(tofkdata.size());
Expand Down
7 changes: 4 additions & 3 deletions FML/FileUtils/FileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ namespace FML {
// Read a regular ascii files with nskip header lines and containing ncol collums
// nestimated_lines is the amount we allocate for originally. Reallocated if file is larger
// Not perfect for realy large files due to all the allocations we have to do
// If nskip is negative, header lines starting with # are skipped
DVector2D read_regular_ascii(std::string filename,
int ncols,
std::vector<int> cols_to_keep,
int nskip,
size_t nestimated_lines) {

// Sanity check
assert(cols_to_keep.size() > 0 and nskip >= 0 and ncols > 0);
assert(cols_to_keep.size() > 0 and ncols > 0);
for (auto & i : cols_to_keep)
assert(i < ncols and i >= 0);

Expand All @@ -37,8 +38,8 @@ namespace FML {
DVector newline(ntokeep);
DVector temp(ncols);

// Read and skip header lines
for (int i = 0; i < nskip; i++) {
// Read and skip header lines (fixed number or all lines starting with #)
for (int i = 0; i < nskip || (nskip < 0 && fp && fp.peek() == '#'); i++) {
std::string line;
std::getline(fp, line);
#ifdef DEBUG_READASCII
Expand Down