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 vout.
paranoiac(
m_vl,
"ParameterManager_YAML::read_params: filesize = %d\n", filesize);
50 buf =
new char [filesize];
52 fin.read(buf, filesize);
60 buf =
new char [filesize];
65 std::istringstream iss(buf);
75 typedef std::pair<int, Parameters *> Level;
78 char *ch =
new char[linesize];
80 string keystr, valstr;
82 std::stack<Level> level_reserve;
84 Level top_level(-1, params_top);
85 level_reserve.push(top_level);
90 int indent_prev = indent;
92 while (fin.getline(ch, linesize))
107 indent = indent_prev;
111 if (indent < indent_prev) {
113 while (!level_reserve.empty())
115 Level level = level_reserve.top();
117 if (level.first < indent) {
118 params = level.second;
128 if (valstr.length() == 0) {
133 Level level(indent, params);
134 level_reserve.push(level);
141 if (params && params->
find_int(keystr)) {
142 int val = atoi(valstr.c_str());
145 vout.
paranoiac(
m_vl,
" int entry found for key = \"%s\", value = %d\n", keystr.c_str(), val);
155 vout.
paranoiac(
m_vl,
" double entry found for key = \"%s\", value = %f\n", keystr.c_str(), val);
165 vout.
paranoiac(
m_vl,
" int_vector entry found for key = \"%s\"\n", keystr.c_str());
171 valarray<double> vec;
175 vout.
paranoiac(
m_vl,
" double_vector entry found for key = \"%s\"\n", keystr.c_str());
183 vout.
paranoiac(
m_vl,
" string entry found for key = \"%s\", value = \"%s\"\n", keystr.c_str(), valstr.c_str());
189 if (params && (keystr ==
"verbose_level")) {
209 string::size_type i2 = line.find(
"#");
211 if (i2 != string::npos) {
212 line.erase(i2, line.length() - i2);
215 string::size_type i1 = line.find(
":");
217 if (i1 == string::npos) {
224 keystr = line.substr(0, i1);
225 valstr = line.substr(i1 + 1, line.length() - i1 - 1);
239 while (str.length() > 0 && str[0] ==
' ')
245 while (str.length() > 0 && str[str.length() - 1] ==
' ')
247 str.erase(str.length() - 1, 1);
260 valarray<int> vec_tmp(size_max);
265 if (valstr[0] !=
'[') {
266 vout.
crucial(
m_vl,
"ParameterManager_YAML: wrong format of vector.\n");
271 if (valstr[valstr.length() - 1] !=
']') {
272 vout.
crucial(
m_vl,
"ParameterManager_YAML: wrong format of vector.\n");
275 valstr.erase(valstr.length() - 1, 1);
280 while (valstr.length() > 0)
282 string::size_type i1 = valstr.find(
",");
284 if (i1 != string::npos) {
285 string elem = valstr.substr(0, i1);
286 valstr.erase(0, i1 + 1);
289 vec_tmp[size] = atoi(elem.c_str());
293 string elem = valstr;
294 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) {
321 valarray<double> vec_tmp(size_max);
326 if (valstr[0] !=
'[') {
327 vout.
crucial(
m_vl,
"ParameterManager_YAML: wrong format of vector.\n");
332 if (valstr[valstr.length() - 1] !=
']') {
333 vout.
crucial(
m_vl,
"ParameterManager_YAML: wrong format of vector.\n");
336 valstr.erase(valstr.length() - 1, 1);
341 while (valstr.length() > 0)
343 string::size_type i1 = valstr.find(
",");
345 if (i1 != string::npos) {
346 string elem = valstr.substr(0, i1);
347 valstr.erase(0, i1 + 1);
355 string elem = valstr;
356 valstr.erase(0, elem.length());
364 if (size > size_max) {
371 for (
int i = 0; i < size; ++i) {