diff options
Diffstat (limited to 'parser.cpp')
-rw-r--r-- | parser.cpp | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/parser.cpp b/parser.cpp new file mode 100644 index 0000000..39527ed --- /dev/null +++ b/parser.cpp @@ -0,0 +1,114 @@ +#include "header.hpp" +#include "parser.hpp" + +void ParserLine::parse() +{ + + key.clear(); + value.clear(); + + if (!line.empty() && line.find("//", 0) != 0) { + + uint splitloc = line.find(":", 0); // find the colon + key = line.substr(0, splitloc); // store the key and value strings + key.erase(std::remove(key.begin(), key.end(), ' '), key.end()); // remove spaces and tabs + key.erase(std::remove(key.begin(), key.end(), '\t'), key.end()); + std::string val = line.substr(splitloc+1, line.length()-splitloc); + + size_t splitter = val.find("//", 0); + std::string strloc; + if (splitter != std::string::npos) { + strloc = val.substr(0, splitter); + } else { + strloc = val; + } + + value.clear(); + value.str(strloc); + + } + +} + + +void Parser::read_options(std::string fname) +{ + + std::ifstream fInStream(fname); + std::string line; + ParserLine pline; + + // initialize all read-in values to -999 + fuzz = -999; + n_agent = -999; + n_iteration = -999; + + if (fInStream.is_open()) { + + while (std::getline(fInStream, line)) { + + pline.line = line; + pline.parse(); + + if (!pline.key.empty()) { + + // Match the key and store the value + if (!strcmp("surfacemesh", pline.key.c_str())) { + pline.value >> surface_mesh_file; + } + else if (!strcmp("surfacedata", pline.key.c_str())) { + pline.value >> surface_data_file; + } + else if (!strcmp("surfacetime", pline.key.c_str())) { + double time; + while (pline.value >> time) { + surface_time.push_back(time); + } + } + else if (!strcmp("surfacegroup", pline.key.c_str())) { + std::string group; + while (pline.value >> group) { + surface_data_group.push_back(group); + } + } + else if (!strcmp("subsurfacemesh", pline.key.c_str())) { + pline.value >> subsurface_mesh_file; + } + else if (!strcmp("subsurfacedata", pline.key.c_str())) { + pline.value >> subsurface_data_file; + } + else if (!strcmp("subsurfacetime", pline.key.c_str())) { + double time; + while (pline.value >> time) { + subsurface_time.push_back(time); + } + } + else if (!strcmp("subsurfacegroup", pline.key.c_str())) { + std::string group; + while (pline.value >> group) { + subsurface_data_group.push_back(group); + } + } + else if (!strcmp("n_agent", pline.key.c_str())) { + pline.value >> n_agent; + } + else if (!strcmp("fuzz", pline.key.c_str())) { + pline.value >> fuzz; + } + else if (!strcmp("seed", pline.key.c_str())) { + pline.value >> seed; + } + else if (!strcmp("n_iteration", pline.key.c_str())) { + pline.value >> n_iteration; + } + else { + std::cerr << "[!!] Unrecognised option key" << std::endl; + } + + } + + } + + } + +} |