Skip to content

Commit

Permalink
guards for reading files
Browse files Browse the repository at this point in the history
  • Loading branch information
fradav committed May 4, 2020
1 parent 8ecc37e commit 888701c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/readreftable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ Reftable<MatrixXd> readreftable(string headerpath, string reftablepath, size_t N
if (!quiet) cout << "///////////////////////////////////////// read headers" << endl;

ifstream headerStream(headerpath,ios::in);
if (headerStream.fail()){
cout << "No header file, exiting" << endl;
exit(1);
}
headerStream >> noskipws;
const std::string hS(istream_iterator<char>{headerStream}, {});

Expand Down Expand Up @@ -108,6 +112,10 @@ Reftable<MatrixXd> readreftable(string headerpath, string reftablepath, size_t N


ifstream reftableStream(reftablepath,ios::in|ios::binary);
if (reftableStream.fail()){
cout << "No Reftable, exiting" << endl;
exit(1);
}
size_t realnrec = readAndCast<int,size_t>(reftableStream);
// reftableStream.read(reinterpret_cast<char *>(realnrec_i),sizeof(realnr));
size_t nrec = N > 0 ? min(realnrec,N) : realnrec;
Expand Down Expand Up @@ -161,6 +169,10 @@ Reftable<MatrixXd> readreftable_scen(string headerpath, string reftablepath, siz
if (!quiet) cout << "///////////////////////////////////////// read headers" << endl;

ifstream headerStream(headerpath,ios::in);
if (headerStream.fail()){
cout << "No header file, exiting" << endl;
exit(1);
}
headerStream >> noskipws;
const std::string hS(istream_iterator<char>{headerStream}, {});

Expand Down Expand Up @@ -240,6 +252,10 @@ Reftable<MatrixXd> readreftable_scen(string headerpath, string reftablepath, siz


ifstream reftableStream(reftablepath,ios::in|ios::binary);
if (headerStream.fail()){
cout << "No Reftable, exiting" << endl;
exit(1);
}
size_t realnrec = readAndCast<int,size_t>(reftableStream);
// reftableStream.read(reinterpret_cast<char *>(realnrec_i),sizeof(realnr));
if (N == 0) N = realnrec;
Expand Down

0 comments on commit 888701c

Please sign in to comment.