30 const int io_node = 0;
37 std::ifstream fin(params_file.c_str());
44 fin.seekg(0, std::ios::end);
45 filesize = fin.tellg();
46 fin.seekg(0, std::ios::beg);
48 int padding = 8 - (filesize % 8);
56 buf =
new char [filesize];
57 memset(buf, 0, filesize);
59 fin.read(buf, filesize - padding);
67 buf =
new char [filesize];
68 memset(buf, 0, filesize);
73 std::istringstream iss(buf);
83 typedef std::pair<int, Parameters *> Level;
86 char *ch =
new char[linesize];
88 std::stack<Level> level_reserve;
90 Level top_level(-1, params_top);
91 level_reserve.push(top_level);
96 int indent_prev = indent;
98 while (fin.getline(ch, linesize))
100 indent_prev = indent;
103 string keystr, valstr;
115 indent = indent_prev;
119 if (indent < indent_prev) {
121 while (!level_reserve.empty())
123 Level level = level_reserve.top();
125 if (level.first < indent) {
126 params = level.second;
136 if (valstr.length() == 0) {
141 Level level(indent, params);
142 level_reserve.push(level);
149 if (params && params->
find_int(keystr)) {
150 int val = atoi(valstr.c_str());
153 vout.
paranoiac(
m_vl,
" int entry found for key = \"%s\", value = %d\n", keystr.c_str(), val);
163 vout.
paranoiac(
m_vl,
" double entry found for key = \"%s\", value = %f\n", keystr.c_str(), val);
169 std::vector<int> vec;
173 vout.
paranoiac(
m_vl,
" int_vector entry found for key = \"%s\"\n", keystr.c_str());
179 std::vector<double> vec;
183 vout.
paranoiac(
m_vl,
" double_vector entry found for key = \"%s\"\n", keystr.c_str());
191 vout.
paranoiac(
m_vl,
" string entry found for key = \"%s\", value = \"%s\"\n", keystr.c_str(), valstr.c_str());
197 if (params && (keystr ==
"verbose_level")) {
217 string::size_type i2 = line.find(
"#");
219 if (i2 != string::npos) {
220 line.erase(i2, line.length() - i2);
223 string::size_type i1 = line.find(
":");
224 if (i1 == string::npos) {
230 keystr = line.substr(0, i1);
231 valstr = line.substr(i1 + 1, line.length() - i1 - 1);
245 while (str.length() > 0 && str[0] ==
' ')
251 while (str.length() > 0 && str[str.length() - 1] ==
' ')
253 str.erase(str.length() - 1, 1);
266 std::vector<int> vec_tmp(size_max);
270 if (valstr[0] !=
'[') {
276 if (valstr[valstr.length() - 1] !=
']') {
280 valstr.erase(valstr.length() - 1, 1);
284 while (valstr.length() > 0)
286 string::size_type i1 = valstr.find(
",");
287 if (i1 != string::npos) {
288 string elem = valstr.substr(0, i1);
289 valstr.erase(0, i1 + 1);
291 vec_tmp[size] = atoi(elem.c_str());
294 string elem = valstr;
295 valstr.erase(0, elem.length());
297 vec_tmp[size] = atoi(elem.c_str());
301 if (size > size_max) {
308 for (
int i = 0; i < size; ++i) {
320 std::vector<double> vec_tmp(size_max);
324 if (valstr[0] !=
'[') {
330 if (valstr[valstr.length() - 1] !=
']') {
334 valstr.erase(valstr.length() - 1, 1);
338 while (valstr.length() > 0)
340 string::size_type i1 = valstr.find(
",");
341 if (i1 != string::npos) {
342 string elem = valstr.substr(0, i1);
343 valstr.erase(0, i1 + 1);
349 string elem = valstr;
350 valstr.erase(0, elem.length());
357 if (size > size_max) {
364 for (
int i = 0; i < size; ++i) {
bool find_int(const string &) const
void read_params(const std::string ¶ms_file, Parameters *params)
read parameters from file.
static void abort()
terminate communicator
void set_int(const string &key, const int value)
void set_double_vector(const string &key, const std::vector< double > &value)
bool find_double(const string &) const
int remove_space(std::string &)
remove spaces from both side of a string.
void convert_double_vector(std::vector< double > &vec, std::string &valstr)
convert from string to double vector.
static int broadcast(size_t size, void *data, int sender)
static const std::string class_name
void set_VerboseLevel(Bridge::VerboseLevel value)
Parameters * get_Parameters(const string &key) const
void set_string(const string &key, const string &value)
bool find_string(const string &) const
void convert_int_vector(std::vector< int > &vec, std::string &valstr)
convert from string to int vector.
int set_key_and_value(std::string &keystr, std::string &valstr, std::string &line)
extract key and value from a given line.
EvalExpr class for algebraic expression in parameter strings.
bool find_double_vector(const string &) const
void paranoiac(const char *format,...)
void crucial(const char *format,...)
void set_double(const string &key, const double value)
Bridge::VerboseLevel m_vl
static int broadcast(int count, double *data, int sender)
broadcast array of double from sender.
static int nodeid()
alternative name for self().
void set_int_vector(const string &key, const std::vector< int > &value)
bool find_int_vector(const string &) const
static VerboseLevel set_verbose_level(const std::string &str)