33#ifndef __GENERATE_SIMULATION_H__
34#define __GENERATE_SIMULATION_H__
44#include <boost/algorithm/string.hpp>
45#include "boost/filesystem.hpp"
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');
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 +
"_");
111 std::ofstream outfile(outputFile.c_str());
112 outfile.precision(15);
113 outfile << outdata.str();
115 outfile.rdbuf()->pubsync();
147 namespace fs = boost::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);
168 std::vector<std::string> all_strings;
169 boost::split(all_strings, stmp,
170 boost::is_any_of(
"\r\n\v\f\t "),
171 boost::token_compress_on);
173 if(all_strings.size() < 2) {
174 std::cout <<
"PROBLEM with the following line "
175 <<
"(at least name and value required)!"
178 std::ostringstream ex;
179 ex <<
"Invalid data file on line " << line_nr;
181 "GenerateOpalSimulation::fillDictionary()",
185 std::string varname = all_strings[0];
186 std::string value = all_strings[1];
187 scale(varname, &value);
188 dictionary_.insert(std::pair<std::string, std::string>(
200 std::istringstream instr(*value);
207 std::ostringstream of;
Inform & endl(Inform &inf)
std::string::iterator iterator
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