Skip to content

Commit

Permalink
[base] Create framework for SolutionArray::save CSV output
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Jun 22, 2023
1 parent ea2fe2f commit 065de1e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
25 changes: 17 additions & 8 deletions include/cantera/base/SolutionArray.h
Expand Up @@ -210,6 +210,14 @@ class SolutionArray
static void writeHeader(AnyMap& root, const string& id, const string& desc,
bool overwrite=false);

/*!
* Write SolutionArray data to comma-separated data file.
*
* @param fname Name of CSV file
* @param overwrite Force overwrite if file exists; optional (default=false)
*/
void writeEntry(const string& fname, bool overwrite=false);

/*!
* Write SolutionArray data to container file.
*
Expand All @@ -234,17 +242,18 @@ class SolutionArray
bool overwrite=false);

/*!
* Save current SolutionArray and header to a container file.
* Save current SolutionArray and header to a data file.
*
* @param fname Name of output container file (YAML or HDF)
* @param id Identifier of root location within the container file
* @param sub Name identifier for the subgroup holding actual data
* @param desc Custom comment describing the dataset to be stored
* @param overwrite Force overwrite if sub exists; optional (default=false)
* @param fname Name of output container file (CSV, YAML or HDF)
* @param id Identifier of root location within container file (YAML/HDF only)
* @param sub Name identifier for subgroup holding actual data (YAML/HDF only)
* @param desc Custom comment describing dataset to be stored (YAML/HDF only)
* @param overwrite Force overwrite if file and/or data entry exists; optional
* (default=false)
* @param compression Compression level; optional (default=0; HDF only)
*/
void save(const string& fname, const string& id, const string& sub,
const string& desc, bool overwrite=false, int compression=0);
void save(const string& fname, const string& id="", const string& sub="",
const string& desc="", bool overwrite=false, int compression=0);

/*!
* Read header data from container file.
Expand Down
13 changes: 12 additions & 1 deletion src/base/SolutionArray.cpp
Expand Up @@ -966,6 +966,11 @@ void SolutionArray::writeHeader(AnyMap& root, const string& id,
data.update(preamble(desc));
}

void SolutionArray::writeEntry(const string& fname, bool overwrite)
{
throw NotImplementedError("SolutionArray::writeEntry");
}

void SolutionArray::writeEntry(const string& fname, const string& id, const string& sub,
bool overwrite, int compression)
{
Expand Down Expand Up @@ -1139,7 +1144,7 @@ void SolutionArray::append(const vector<double>& state, const AnyMap& extra)
}

void SolutionArray::save(const string& fname, const string& id, const string& sub,
const string& desc, bool overwrite, int compression)
const string& desc, bool overwrite, int compression)
{
if (m_size < m_dataSize) {
throw NotImplementedError("SolutionArray::save",
Expand Down Expand Up @@ -1167,6 +1172,12 @@ void SolutionArray::save(const string& fname, const string& id, const string& su
AnyMap::clearCachedFile(fname);
return;
}
if (extension == "csv") {
if (id != "") {
warn_user("SolutionArray::save", "Parameter 'id' not used for CSV output.");
}
writeEntry(fname, overwrite);
}
throw CanteraError("SolutionArray::save",
"Unknown file extension '{}'.", extension);
}
Expand Down

0 comments on commit 065de1e

Please sign in to comment.