ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_InputsName.H File Reference
#include <AMReX.H>
#include <AMReX_Print.H>
#include <fstream>
#include <string>
#include <unordered_map>
Include dependency graph for ERF_InputsName.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void CheckForDuplicateInputs (const std::string &inputs_file)
 

Variables

std::string inputs_name
 

Function Documentation

◆ CheckForDuplicateInputs()

void CheckForDuplicateInputs ( const std::string &  inputs_file)
inline
27 {
28  std::ifstream ifs(inputs_file);
29 
30  if (!ifs.is_open()) {
31  amrex::Abort("Could not open inputs file: " + inputs_file);
32  }
33 
34  struct EntryInfo {
35  int line_number;
36  std::string value;
37  };
38 
39  std::unordered_map<std::string, EntryInfo> seen;
40 
41  std::string line;
42  int line_number = 0;
43  bool found_duplicates = false;
44 
45  while (std::getline(ifs, line))
46  {
47  ++line_number;
48 
49  // Remove comments
50  auto hash_pos = line.find('#');
51  if (hash_pos != std::string::npos) {
52  line = line.substr(0, hash_pos);
53  }
54 
55  line = trim_copy(line);
56 
57  // Skip blank lines
58  if (line.empty()) continue;
59 
60  // Skip lines that are not assignments
61  auto eq_pos = line.find('=');
62  if (eq_pos == std::string::npos) continue;
63 
64  std::string key = trim_copy(line.substr(0, eq_pos));
65  std::string value = trim_copy(line.substr(eq_pos + 1));
66 
67  auto it = seen.find(key);
68 
69  if (it != seen.end())
70  {
71  found_duplicates = true;
72 
73  amrex::Print()
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";
80  }
81  else
82  {
83  seen.emplace(key, EntryInfo{line_number, value});
84  }
85  }
86 
87  if (found_duplicates)
88  {
89  amrex::Abort("Duplicate inputs detected in inputs file");
90  }
91 }
amrex::Real value
Definition: ERF_HurricaneDiagnostics.H:20

Referenced by main().

Here is the caller graph for this function:

Variable Documentation

◆ inputs_name

std::string inputs_name
extern

Referenced by main(), and ERF::writeJobInfo().