1 #ifndef __GENERATE_SIMULATION_H__
2 #define __GENERATE_SIMULATION_H__
12 #include <boost/algorithm/string.hpp>
44 std::map<std::string,std::string> userValues) {
49 scaleVars_.insert(std::pair<std::string, double>(
"GUNSOLB", 1.));
53 dictionary_.insert(userValues.begin(),userValues.end());
71 std::ostringstream outdata;
72 outdata.precision(15);
74 while(infile.good()) {
76 std::getline(infile, line,
'\n');
81 size_t pos = line.find(
"_" + itr->first +
"_");
82 while(pos != std::string::npos) {
83 line.replace(pos, itr->first.length() + 2, itr->second);
84 pos = line.find(
"_" + itr->first +
"_");
93 std::ofstream outfile(outputFile.c_str());
95 outfile << outdata.str();
97 outfile.rdbuf()->pubsync();
129 std::ifstream infile;
133 unsigned int line_nr = 0;
134 while(infile.good()) {
135 std::fill_n(tmp, 1024,
'\0');
136 infile.getline(tmp, 1024);
139 std::string stmp(tmp);
144 std::vector<std::string> all_strings;
145 boost::split(all_strings, stmp,
146 boost::is_any_of(
"\r\n\v\f\t "),
147 boost::token_compress_on);
149 if(all_strings.size() < 2) {
150 std::cout <<
"PROBLEM with the following line "
151 <<
"(at least name and value required)!"
154 std::ostringstream ex;
155 ex <<
"Invalid data file on line " << line_nr;
157 "GenerateOpalSimulation::fillDictionary()",
161 std::string varname = all_strings[0];
162 std::string value = all_strings[1];
163 scale(varname, &value);
164 dictionary_.insert(std::pair<std::string, std::string>(
176 std::istringstream instr(*value);
183 std::ostringstream of;
std::string varDictionary_
data filename
Generates an OPAL input file from data and template file.
void scale(std::string name, std::string *value)
Helper method to scale variable if necessary.
std::map< std::string, double > scaleVars_
holds all variables that need scaling
std::map< std::string, std::string > dictionary_
holds parsed template data
GenerateOpalSimulation(std::string tmplFile, std::string varDictionary, std::map< std::string, std::string > userValues)
std::string::iterator iterator
~GenerateOpalSimulation()
void writeInputFile(std::string outputFile)
Inform & endl(Inform &inf)
std::string tmplFile_
template filename