IAP GITLAB

Skip to content
Snippets Groups Projects
Commit 968325e6 authored by Ralf M Ulrich's avatar Ralf M Ulrich
Browse files

better error messages

parent 47e6e5ab
No related branches found
No related tags found
No related merge requests found
...@@ -21,6 +21,7 @@ namespace corsika_data { ...@@ -21,6 +21,7 @@ namespace corsika_data {
struct DataFile { struct DataFile {
std::ifstream file_in_; std::ifstream file_in_;
std::string file_name_;
boost::iostreams::filtering_istream in_; boost::iostreams::filtering_istream in_;
DataFile() {} DataFile() {}
~DataFile() {} ~DataFile() {}
...@@ -34,10 +35,12 @@ namespace corsika_data { ...@@ -34,10 +35,12 @@ namespace corsika_data {
auto i1 = s.find_first_not_of(" \t\r\n"); // trimm right auto i1 = s.find_first_not_of(" \t\r\n"); // trimm right
auto i2 = s.find_first_of(" \t\r\n", i1); // trimm left auto i2 = s.find_first_of(" \t\r\n", i1); // trimm left
std::string trimmed(s.substr(i1, i2 - i1)); std::string trimmed(s.substr(i1, i2 - i1));
file_name_ = trimmed;
file_in_.open(trimmed, ios_base::in | ios_base::binary); file_in_.open(trimmed, ios_base::in | ios_base::binary);
if (!file_in_ || !file_in_.good()) { if (!file_in_ || !file_in_.good()) {
std::cerr << std::string("Cannot open file: \'") + trimmed << "\'" << std::endl; std::cerr << std::string("Cannot open file: \'") + file_name_ << "\'"
throw std::runtime_error(std::string("Cannot open file: ") + trimmed); << std::endl;
throw std::runtime_error(std::string("Cannot open file: ") + file_name_);
} }
if (trimmed.rfind(".bz2") == trimmed.length() - 4) if (trimmed.rfind(".bz2") == trimmed.length() - 4)
in_.push(boost::iostreams::bzip2_decompressor()); in_.push(boost::iostreams::bzip2_decompressor());
...@@ -48,20 +51,27 @@ namespace corsika_data { ...@@ -48,20 +51,27 @@ namespace corsika_data {
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
in_ >> data[i]; in_ >> data[i];
if (!in_.good()) { if (!in_.good()) {
throw std::runtime_error(std::string("Cannot FillArray i=") + throw std::runtime_error(std::string("Cannot FillArray i/length=") +
std::to_string(i)); std::to_string(i) + "/" + std::to_string(length) +
" in file " + file_name_);
} }
} }
} }
double ReadNextNumber() { double ReadNextNumber() {
double data; double data;
in_ >> data; in_ >> data;
if (!in_.good()) { throw std::runtime_error(std::string("Cannot ReadNextNumber")); } if (!in_.good()) {
throw std::runtime_error(
std::string("Cannot ReadNextNumber in file " + file_name_));
}
return data; return data;
} }
int ReadNextText(std::string& data) { int ReadNextText(std::string& data) {
std::getline(in_, data, ' '); std::getline(in_, data, ' ');
if (!in_.good()) { throw std::runtime_error(std::string("Cannot ReadNextText")); } if (!in_.good()) {
throw std::runtime_error(
std::string("Cannot ReadNextText in file " + file_name_));
}
return 0; return 0;
} }
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment