103 if (!infofile.is_open())
120 EXCEPTION(
"Couldn't read info file correctly");
132 std::stringstream suffix;
135 mDataFilename = rDirectory + rBaseName +
"_" + suffix.str() +
".dat";
147 if (!ancillaryfile.is_open())
149 EXCEPTION(
"Couldn't open ancillary data file");
151 std::string dimension;
152 std::getline(ancillaryfile, dimension);
153 std::stringstream dimension_stream(dimension);
154 std::string dimension_unit, dimension_name, header;
155 dimension_stream >> header;
158 int unitpos = header.find(
"(") + 1;
160 dimension_name = header.substr(0, unitpos - 1);
161 dimension_unit = header.substr(unitpos, header.length() - unitpos - 1);
164 ancillaryfile.close();
174 if (!datafile.is_open())
179 std::string variables;
180 std::getline(datafile, variables);
181 std::stringstream variable_stream(variables);
182 std::string header, variable, unit;
186 while (variable_stream >> header)
189 int unitpos = header.find(
"(") + 1;
191 variable = header.substr(0, unitpos - 1);
192 unit = header.substr(unitpos, header.length() - unitpos - 1);
215 std::string first_line;
216 std::string first_entry;
217 unsigned last_pos=0u;
219 while (first_entry.length()==0 && !datafile.eof())
221 std::getline(datafile, first_line);
222 std::stringstream stream(first_line);
223 stream >> first_entry;
224 last_pos = stream.tellg();
225 while (stream.good() && last_pos <170)
227 std::string last_entry;
228 stream >> last_entry;
229 if (stream.tellg() > 0)
231 last_pos = stream.tellg();
236 if (datafile.eof() && first_entry.length()==0)
238 EXCEPTION(
"Unable to determine field width from file as cannot find any data entries");
240 assert (last_pos > 0u);
242 size_t dot_pos = first_entry.find(
".");
243 size_t e_pos = first_entry.find(
"e");
244 if (dot_pos == std::string::npos || e_pos == std::string::npos)
246 EXCEPTION(
"Badly formatted scientific data field");
249 unsigned est_field_width = e_pos - dot_pos - 1 + 8;
251 if (last_pos % est_field_width == 0)
257 assert ( last_pos % (est_field_width+1) == 0 || (last_pos+1) % (est_field_width+1) == 0 );
290 EXCEPTION(
"Data file has no fixed dimension");
302 int column = (*col).second;
317 std::string::size_type underscore_pos = datafile.rfind(
"_", datafile.length());
318 std::stringstream suffix;
322 if (underscore_pos != std::string::npos)
324 datafile = datafile.substr(0, underscore_pos+1) + suffix.str() +
".dat";
388 std::ifstream datafile(rFilename.c_str(), std::ios::in);
392 assert(datafile.is_open());
395 bool end_of_file_reached =
false;
398 end_of_file_reached = std::getline(datafile, value).eof();
400 while (!end_of_file_reached)
402 end_of_file_reached = std::getline(datafile, value).eof();