-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement CSV file import for C++ SolutionArray #163
Comments
Regarding parsing of CSV files in C++, here are some preliminary findings
|
I feel like there has to be something in Boost to do this... Implementing a csv parser from scratch seems overkill 🤔 |
Wouldn't be too hard if this regex were supported by C++'s |
Not sure it would even resolve the problem, but I wanted to add a word of caution. |
Too bad. I just confirmed that PS: this is how to get the header line after opening the file ... string line;
std::getline(file, line);
boost::regex rgx(
"(?:^|,)(?=[^\"]|(\")?)\"?((?(1)[^\"]*|[^,\"]*))\"?(?=,|$)");
vector<string> labels;
auto line_begin = boost::sregex_iterator(line.begin(), line.end(), rgx);
auto line_end = boost::sregex_iterator();
for (boost::sregex_iterator item = line_begin; item != line_end; ++item) {
boost::smatch match = *item;
labels.push_back(match.str(2));
} The syntax would be the same for |
We could vendor this single file, header-only CSV reader: https://github.com/ben-strasser/fast-cpp-csv-parser, or something similar. |
Abstract
Recent work added HDF support to
Sim1D::save/restore
(Cantera/cantera#1385) and implementedSolutionArray::save/restore
for HDF and YAML (Cantera/cantera#1426). On the back-end,SolutionArray
handles file IO in both cases. As those methods are implemented in the C++ layer, they are portable across all API's.Adding CSV support to
SolutionArray::save/restore
in C++ to replace Python'sSolutionArray.write_csv/read_csv
is a logical extension. It can build on the existing infrastructure, and would be a good way of handling CSV support in a consistent way - which would replace the historically grown patchwork of dissimilar approaches used at the moment. One additional benefit would be to resolve Cantera/cantera#1372.Motivation
Describe the need for the proposed change:
Possible Solutions
Create versions of
SolutionArray::readEntry/writeEntry
that handle CSV. While writing is straight-forward, reading CSV will need the implementation of a suitable parser. Per Cantera/cantera#1372 (comment) by @spethSolutionArray::writeEntry
implementation is proposed in Implement C++ SolutionArray::save for CSV output cantera#1508 ... update: now mergedSolutionArray::readEntry
implementation is missingReferences
The text was updated successfully, but these errors were encountered: