33#ifndef __GENERATE_SIMULATION_H__
34#define __GENERATE_SIMULATION_H__
62 std::map<std::string,std::string> userValues) {
67 scaleVars_.insert(std::pair<std::string, double>(
"GUNSOLB", 1.));
71 dictionary_.insert(userValues.begin(),userValues.end());
89 std::ostringstream outdata;
90 outdata.precision(15);
92 while(infile.good()) {
94 std::getline(infile, line,
'\n');
97 std::map<std::string, std::string>::iterator itr =
dictionary_.begin();
99 size_t pos = line.find(
"_" + itr->first +
"_");
100 while(pos != std::string::npos) {
101 line.replace(pos, itr->first.length() + 2, itr->second);
102 pos = line.find(
"_" + itr->first +
"_");
106 outdata << line << std::endl;
111 std::ofstream outfile(outputFile.c_str());
112 outfile.precision(15);
113 outfile << outdata.str();
115 outfile.rdbuf()->pubsync();
147 namespace fs = std::filesystem;
149 fs::path pwd = fs::current_path();
153 std::ifstream infile;
157 unsigned int line_nr = 0;
158 while(infile.good()) {
159 std::fill_n(tmp, 1024,
'\0');
160 infile.getline(tmp, 1024);
163 std::string stmp(tmp);
165 if (stmp.size() == 0)
169 stmp,
"\r\n\v\f\t ",
true);
171 if (all_strings.size() < 2) {
172 std::cout <<
"PROBLEM with the following line "
173 <<
"(at least name and value required)!"
175 std::cout << stmp << std::endl;
176 std::ostringstream ex;
177 ex <<
"Invalid data file on line " << line_nr;
179 "GenerateOpalSimulation::fillDictionary()",
183 std::string varname = all_strings[0];
184 std::string value = all_strings[1];
185 scale(varname, &value);
186 dictionary_.insert(std::pair<std::string, std::string>(
198 std::istringstream instr(*value);
205 std::ostringstream of;
std::vector< std::string > split_any_of(const std::string &s, const std::string &delims, bool compress)
std::string trim_chars(const std::string &s, const std::string &chars)
void scale(std::string name, std::string *value)
Helper method to scale variable if necessary.
~GenerateOpalSimulation()
std::string tmplFile_
template filename
std::map< std::string, double > scaleVars_
holds all variables that need scaling
void writeInputFile(std::string outputFile)
GenerateOpalSimulation(std::string tmplFile, std::string varDictionary, std::map< std::string, std::string > userValues)
std::map< std::string, std::string > dictionary_
holds parsed template data
std::string varDictionary_
data filename