| 1312 | } |
| 1313 | |
| 1314 | void SolutionArray::save(const string& fname, const string& name, const string& sub, |
| 1315 | const string& desc, bool overwrite, int compression, |
| 1316 | const string& basis) |
| 1317 | { |
| 1318 | if (m_size < m_dataSize) { |
| 1319 | throw NotImplementedError("SolutionArray::save", |
| 1320 | "Unable to save sliced data."); |
| 1321 | } |
| 1322 | size_t dot = fname.find_last_of("."); |
| 1323 | string extension = (dot != npos) ? toLowerCopy(fname.substr(dot + 1)) : ""; |
| 1324 | if (extension == "csv") { |
| 1325 | if (name != "") { |
| 1326 | warn_user("SolutionArray::save", |
| 1327 | "Parameter 'name' not used for CSV output."); |
| 1328 | } |
| 1329 | writeEntry(fname, overwrite, basis); |
| 1330 | return; |
| 1331 | } |
| 1332 | if (basis != "") { |
| 1333 | warn_user("SolutionArray::save", |
| 1334 | "Argument 'basis' is not used for HDF or YAML output.", basis); |
| 1335 | } |
| 1336 | if (extension == "h5" || extension == "hdf" || extension == "hdf5") { |
| 1337 | writeHeader(fname, name, desc, overwrite); |
| 1338 | writeEntry(fname, name, sub, true, compression); |
| 1339 | return; |
| 1340 | } |
| 1341 | if (extension == "yaml" || extension == "yml") { |
| 1342 | // Check for an existing file and load it if present |
| 1343 | AnyMap data; |
| 1344 | std::ifstream file(fname); |
| 1345 | if (file.good() && file.peek() != std::ifstream::traits_type::eof()) { |
| 1346 | data = AnyMap::fromYamlFile(fname); |
| 1347 | } |
| 1348 | writeHeader(data, name, desc, overwrite); |
| 1349 | writeEntry(data, name, sub, true); |
| 1350 | |
| 1351 | // Write the output file and remove the now-outdated cached file |
| 1352 | std::ofstream out(fname); |
| 1353 | out << data.toYamlString(); |
| 1354 | AnyMap::clearCachedFile(fname); |
| 1355 | return; |
| 1356 | } |
| 1357 | throw CanteraError("SolutionArray::save", |
| 1358 | "Unknown file extension '{}'.", extension); |
| 1359 | } |
| 1360 | |
| 1361 | AnyMap SolutionArray::readHeader(const string& fname, const string& name) |
| 1362 | { |