covid-sim
covid-sim copied to clipboard
More robust parameter file handling
Part 2 of #74. This pull is related to my other PR #228 which deals with the CLI parameter parsing aspects of #74. You may note that the raw_extract()
number extraction code from ParamFile.hpp
looks similar to the parse_number()
function in PR #228. Eventually these two implementations could be combined into a separate file, but I think they can exist independently for now.
The main goals of this Pull-Request are:
- A more clean and concise way of extracting parameter values (fewer 160+ character lines)
- A type-safe approach towards extracting values
- Logging when a value overflows/underflows the storage size of the output variable
- Replacing the use of
fscanf()
andsprintf()
withstd::ifstream
andstd::istringstream
.
- Logging when the actual number of parameters extracted doesn't match the expected
- Logging when a parameter value isn't specified and a default value is instead used
- Exiting when a required parameter value isn't found
Things that are missing from this draft PR right now (I will update as I make more commits):
- [ ] Wildcard CLI parameters (e.g. specifying
#1
in a param file and using/CLP1
value from the CLI) - [x] Extracting string values
- [ ] Extracting matrix values (values that span more than 1 line)
- [ ] Extracting values into a proportion array where the default value is
1
at index 0 and0
in every other place. - [ ] Extracting values into an array with a default array specified (e.g.
output[4]
can havedefault{ 1, 2, 3, 4}
) - [x] Extracting ICDF values. I'm currently watching #316
- [ ] Outputting a parameter file with all merged and de-duplicated values
I will continue to work on this PR, but please let me know if there are any design decisions you would like to discuss or changes you would like to be made!
Cheers!
It appears that old ABI of the libstdc++ used in the Docker CentOS 7 container doesn't allow for the C++11 function std::string::erase(const_iterator)
to be used, which is why that CI check is failing.
Either -DGLIBCXX_USE_CXX11_ABI=1
needs to be passed to the command-line for that build, or an alternative should be found and used.
References:
Things I would like to see in this PR:
- Detection and warning of when we do have multiple values for a field
- Detection and warning of when a parameter is specified in a config file but not read.
- A new command-line option that enables output of a parameter file that when used as the input will result in the same config.