1 #ifndef ERF_INPUTS_NAME_H_
2 #define ERF_INPUTS_NAME_H_
5 #include <AMReX_Print.H>
9 #include <unordered_map>
15 std::string trim_copy (std::string s)
17 auto b = s.find_first_not_of(
" \t\r");
18 if (b == std::string::npos)
return "";
20 auto e = s.find_last_not_of(
" \t\r");
21 return s.substr(b, e - b + 1);
28 std::ifstream ifs(inputs_file);
31 amrex::Abort(
"Could not open inputs file: " + inputs_file);
39 std::unordered_map<std::string, EntryInfo> seen;
43 bool found_duplicates =
false;
45 while (std::getline(ifs, line))
50 auto hash_pos = line.find(
'#');
51 if (hash_pos != std::string::npos) {
52 line = line.substr(0, hash_pos);
55 line = trim_copy(line);
58 if (line.empty())
continue;
61 auto eq_pos = line.find(
'=');
62 if (eq_pos == std::string::npos)
continue;
64 std::string key = trim_copy(line.substr(0, eq_pos));
65 std::string
value = trim_copy(line.substr(eq_pos + 1));
67 auto it = seen.find(key);
71 found_duplicates =
true;
74 <<
"\nDuplicate input detected:\n"
75 <<
" Key : " << key <<
"\n"
76 <<
" First line : " << it->second.line_number
77 <<
" Value : " << it->second.value <<
"\n"
78 <<
" Second line : " << line_number
79 <<
" Value : " <<
value <<
"\n";
83 seen.emplace(key, EntryInfo{line_number,
value});
89 amrex::Abort(
"Duplicate inputs detected in inputs file");
amrex::Real value
Definition: ERF_HurricaneDiagnostics.H:20