33 std::string to_str(
const std::vector<T>& v)
35 std::ostringstream ss;
38 for (
size_t i = 0, n = v.size(); i < n; ++i) {
39 if (i != 0) ss <<
", ";
51 const int io_node = 0;
58 std::ifstream fin(params_file.c_str());
60 vout.
crucial(m_vl,
"%s: unable to read parameter file: %s.\n", class_name.c_str(), params_file.c_str());
65 fin.seekg(0, std::ios::end);
66 filesize = fin.tellg();
67 fin.seekg(0, std::ios::beg);
69 int padding = 8 - (filesize % 8);
71 vout.
paranoiac(m_vl,
"%s::%s: filesize = %d, padding = %d\n", class_name.c_str(), __func__, filesize, padding);
77 buf =
new char [filesize];
78 memset(buf, 0, filesize);
80 fin.read(buf, filesize - padding);
88 buf =
new char [filesize];
89 memset(buf, 0, filesize);
94 process_params(buf, params);
124 vout.
crucial(m_vl,
"%s: tag \"Parameters\" not found.\n", class_name.c_str());
128 traverse(root, params_top);
135 if (!elem || !params)
return;
138 traverse_item(e, params);
146 if (!elem || !params)
return;
148 std::string tag(elem->
Name());
150 vout.
paranoiac(m_vl,
"%s::%s: tag = \"%s\"\n", class_name.c_str(), __func__, tag.c_str());
153 vout.
paranoiac(m_vl,
"%s::%s: matched entry for parameters.\n", class_name.c_str(), __func__);
159 int val = atoi(elem->
GetText());
161 vout.
paranoiac(m_vl,
"%s::%s: matched entry for int. val = %d\n", class_name.c_str(), __func__, val);
163 return params->
set_int(tag, val);
169 vout.
paranoiac(m_vl,
"%s::%s: matched entry for double. expr = %s, val = %20.16e\n", class_name.c_str(), __func__, elem->
GetText(), val);
175 vout.
paranoiac(m_vl,
"%s::%s: matched entry for string. val = %s\n", class_name.c_str(), __func__, elem->
GetText());
181 std::vector<int> val = convert_to_int_vector(elem);
183 vout.
paranoiac(m_vl,
"%s::%s: matched entry for int vector. val = %s\n", class_name.c_str(), __func__, to_str(val).c_str());
189 std::vector<double> val = convert_to_double_vector(elem);
191 vout.
paranoiac(m_vl,
"%s::%s: matched entry for double vector. val = %s\n", class_name.c_str(), __func__, to_str(val).c_str());
196 if (tag ==
"verbose_level") {
199 vout.
paranoiac(m_vl,
"%s::%s: matched entry for verbose_level. val = %d\n", class_name.c_str(), __func__,
vl);
205 vout.
paranoiac(m_vl,
"%s::%s: no match. skipped.\n", class_name.c_str(), __func__);
212 if (!elem)
return std::vector<int>();
215 if (!ee)
return std::vector<int>();
217 std::map<int, int> array;
220 if (strcmp(ee->Name(),
"value") == 0) {
221 vout.
paranoiac(m_vl,
"%s::%s: plain array.\n", class_name.c_str(), __func__);
227 if (e->QueryIntAttribute(
"id", &
id) ==
XML_SUCCESS) {
230 vout.
general(m_vl,
"%s::%s: array index not found.\n", class_name.c_str(), __func__);
235 vout.
crucial(m_vl,
"%s::%s: inappropriate array index %d.\n", class_name.c_str(), __func__, id);
239 if (
id > max_index) {
243 int val = atoi(e->GetText());
245 vout.
paranoiac(m_vl,
"%s::%s: id = %d, value = %d\n", class_name.c_str(), __func__, id, val);
251 vout.
paranoiac(m_vl,
"%s::%s: directional array.\n", class_name.c_str(), __func__);
256 std::string tag = std::string(e->Name());
260 }
else if (tag ==
"y") {
262 }
else if (tag ==
"z") {
264 }
else if (tag ==
"t") {
267 vout.
crucial(
"%s::%s: unknown array index \"%s\".\n", class_name.c_str(), __func__, tag.c_str());
271 if (
id > max_index) {
275 int val = atoi(e->GetText());
277 vout.
paranoiac(m_vl,
"%s::%s: id = %s (%d), value = %d\n", class_name.c_str(), __func__, tag.c_str(), id, val);
283 vout.
paranoiac(m_vl,
"%s::%s: max_index = %d\n", class_name.c_str(), __func__, max_index);
285 std::vector<int> v(max_index + 1);
287 for (std::map<int, int>::const_iterator p = array.begin(); p != array.end(); ++p) {
288 v[p->first] = p->second;
298 if (!elem)
return std::vector<double>();
301 if (!ee)
return std::vector<double>();
303 std::map<int, double> array;
306 if (strcmp(ee->Name(),
"value") == 0) {
307 vout.
paranoiac(m_vl,
"%s::%s: plain array.\n", class_name.c_str(), __func__);
313 if (e->QueryIntAttribute(
"id", &
id) ==
XML_SUCCESS) {
316 vout.
general(m_vl,
"%s::%s: array index not found.\n", class_name.c_str(), __func__);
321 vout.
crucial(m_vl,
"%s::%s: inappropriate array index %d.\n", class_name.c_str(), __func__, id);
325 if (
id > max_index) {
329 double val =
EvalExpr(e->GetText()).parse();
331 vout.
paranoiac(m_vl,
"%s::%s: id = %d, expr = %s, value = %20.16e\n", class_name.c_str(), __func__, id, e->GetText(), val);
337 vout.
paranoiac(m_vl,
"%s::%s: directional array.\n", class_name.c_str(), __func__);
342 std::string tag = std::string(e->Name());
346 }
else if (tag ==
"y") {
348 }
else if (tag ==
"z") {
350 }
else if (tag ==
"t") {
353 vout.
crucial(
"%s::%s: unknown array index \"%s\".\n", class_name.c_str(), __func__, tag.c_str());
357 if (
id > max_index) {
361 double val =
EvalExpr(e->GetText()).parse();
363 vout.
paranoiac(m_vl,
"%s::%s: id = %s (%d), expr = %s, value = %20.16e\n", class_name.c_str(), __func__, tag.c_str(), id, e->GetText(), val);
369 vout.
paranoiac(m_vl,
"%s::%s: max_index = %d\n", class_name.c_str(), __func__, max_index);
371 std::vector<double> v(max_index + 1);
373 for (std::map<int, double>::const_iterator p = array.begin(); p != array.end(); ++p) {
374 v[p->first] = p->second;
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
XMLError Parse(const char *xml, size_t nBytes=(size_t)(-1))
void general(const char *format,...)
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
bool find_Parameters(const string &) const
static int broadcast(size_t size, void *data, int sender)
void set_VerboseLevel(Bridge::VerboseLevel value)
const char * GetErrorStr2() const
Return a possibly helpful secondary diagnostic location or string.
Parameters * get_Parameters(const string &key) const
void process_params(const char *buf, Parameters *params)
read parameters from input file stream.
void set_string(const string &key, const string &value)
bool find_string(const string &) const
const XMLElement * FirstChildElement(const char *value=0) const
const char * GetText() const
EvalExpr class for algebraic expression in parameter strings.
bool find_double_vector(const string &) const
std::vector< int > convert_to_int_vector(const tinyxml2::XMLElement *elem)
convert from string to int vector.
void paranoiac(const char *format,...)
void traverse(const tinyxml2::XMLElement *elem, Parameters *params)
static const std::string class_name
void crucial(const char *format,...)
const char * GetErrorStr1() const
Return a possibly helpful diagnostic location or string.
void set_double(const string &key, const double value)
const XMLElement * NextSiblingElement(const char *value=0) const
Get the next (right) sibling element of this node, with an optionally supplied name.
static int broadcast(int count, double *data, int sender)
broadcast array of double from sender.
void traverse_item(const tinyxml2::XMLElement *elem, Parameters *params)
static int nodeid()
alternative name for self().
std::vector< double > convert_to_double_vector(const tinyxml2::XMLElement *elem)
convert from string to double vector.
void set_int_vector(const string &key, const std::vector< int > &value)
bool find_int_vector(const string &) const
const char * ErrorName() const
static VerboseLevel set_verbose_level(const std::string &str)
const char * Name() const
Get the name of an element (which is the Value() of the node.)