28 const int io_node = 0;
35 std::ifstream fin(params_file.c_str());
37 vout.
crucial(
m_vl,
"ParameterManager_YAML: unable to read parameter file: %s.\n", params_file.c_str());
42 fin.seekg(0, std::ios::end);
43 filesize = fin.tellg();
44 fin.seekg(0, std::ios::beg);
46 int padding = 8 - (filesize % 8);
48 vout.
paranoiac(
m_vl,
"ParameterManager_YAML::read_params: filesize = %d, padding = %d\n", filesize, padding);
54 buf =
new char [filesize];
55 memset(buf, 0, filesize);
57 fin.read(buf, filesize - padding);
65 buf =
new char [filesize];
66 memset(buf, 0, filesize);
71 std::istringstream iss(buf);
81 typedef std::pair<int, Parameters *> Level;
84 char *ch =
new char[linesize];
86 std::stack<Level> level_reserve;
88 Level top_level(-1, params_top);
89 level_reserve.push(top_level);
94 int indent_prev = indent;
96 while (fin.getline(ch, linesize))
101 string keystr, valstr;
113 indent = indent_prev;
117 if (indent < indent_prev) {
119 while (!level_reserve.empty())
121 Level level = level_reserve.top();
123 if (level.first < indent) {
124 params = level.second;
134 if (valstr.length() == 0) {
139 Level level(indent, params);
140 level_reserve.push(level);
147 if (params && params->
find_int(keystr)) {
148 int val = atoi(valstr.c_str());
151 vout.
paranoiac(
m_vl,
" int entry found for key = \"%s\", value = %d\n", keystr.c_str(), val);
161 vout.
paranoiac(
m_vl,
" double entry found for key = \"%s\", value = %f\n", keystr.c_str(), val);
171 vout.
paranoiac(
m_vl,
" int_vector entry found for key = \"%s\"\n", keystr.c_str());
177 valarray<double> vec;
181 vout.
paranoiac(
m_vl,
" double_vector entry found for key = \"%s\"\n", keystr.c_str());
189 vout.
paranoiac(
m_vl,
" string entry found for key = \"%s\", value = \"%s\"\n", keystr.c_str(), valstr.c_str());
195 if (params && (keystr ==
"verbose_level")) {
215 string::size_type i2 = line.find(
"#");
217 if (i2 != string::npos) {
218 line.erase(i2, line.length() - i2);
221 string::size_type i1 = line.find(
":");
223 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 valarray<int> vec_tmp(size_max);
271 if (valstr[0] !=
'[') {
272 vout.
crucial(
m_vl,
"ParameterManager_YAML: wrong format of vector.\n");
277 if (valstr[valstr.length() - 1] !=
']') {
278 vout.
crucial(
m_vl,
"ParameterManager_YAML: wrong format of vector.\n");
281 valstr.erase(valstr.length() - 1, 1);
286 while (valstr.length() > 0)
288 string::size_type i1 = valstr.find(
",");
290 if (i1 != string::npos) {
291 string elem = valstr.substr(0, i1);
292 valstr.erase(0, i1 + 1);
295 vec_tmp[size] = atoi(elem.c_str());
299 string elem = valstr;
300 valstr.erase(0, elem.length());
303 vec_tmp[size] = atoi(elem.c_str());
307 if (size > size_max) {
314 for (
int i = 0; i < size; ++i) {
327 valarray<double> vec_tmp(size_max);
332 if (valstr[0] !=
'[') {
333 vout.
crucial(
m_vl,
"ParameterManager_YAML: wrong format of vector.\n");
338 if (valstr[valstr.length() - 1] !=
']') {
339 vout.
crucial(
m_vl,
"ParameterManager_YAML: wrong format of vector.\n");
342 valstr.erase(valstr.length() - 1, 1);
347 while (valstr.length() > 0)
349 string::size_type i1 = valstr.find(
",");
351 if (i1 != string::npos) {
352 string elem = valstr.substr(0, i1);
353 valstr.erase(0, i1 + 1);
361 string elem = valstr;
362 valstr.erase(0, elem.length());
370 if (size > size_max) {
377 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)
bool find_double(const string &) const
void convert_double_vector(std::valarray< double > &vec, std::string &valstr)
convert from string to double vector.
int remove_space(std::string &)
remove spaces from both side of a string.
static int broadcast(size_t size, void *data, int sender)
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
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 set_double_vector(const string &key, const std::valarray< double > &value)
void paranoiac(const char *format,...)
void crucial(const char *format,...)
void convert_int_vector(std::valarray< int > &vec, std::string &valstr)
convert from string to int vector.
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::valarray< int > &value)
bool find_int_vector(const string &) const
static VerboseLevel set_verbose_level(const std::string &str)