XGCa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
check_input_file.hpp
Go to the documentation of this file.
1 #ifndef CHECK_INPUT_FILE_HPP
2 #define CHECK_INPUT_FILE_HPP
3 
4 #include "NamelistReader.hpp"
5 #include "globals.hpp"
6 
7 struct CheckerEntry{
8  std::string name;
9  std::string msg;
10 
11  CheckerEntry(std::string name, std::string msg) : name(name), msg(msg) {}
12 };
13 
16  std::vector<CheckerEntry> deprecated;
17  std::vector<CheckerEntry> removed;
20 
21  public:
22 
24  // Include a file that contains all the deprecated and removed inputs
26  announce_all();
27  }
28 
29  void deprecate(std::string list, std::string name, std::string msg){
30  if(nlr->namelist_present(list)){
31  nlr->use_namelist(list);
32  if(nlr->present(name)){
33  deprecated.push_back(CheckerEntry(name, msg));
34  found_deprecated = true;
35  }
36  }
37  }
38 
39  void remove(std::string list, std::string name, std::string msg){
40  if(nlr->namelist_present(list)){
41  nlr->use_namelist(list);
42  if(nlr->present(name)){
43  removed.push_back(CheckerEntry(name, msg));
44  found_removed = true;
45  }
46  }
47  }
48 
49  void announce_all(){
50  if(is_rank_zero()){
51  if(found_deprecated){
52  printf("\n\n\n******** WARNING: Deprecated input detected *********\n");
53  for(int i=0; i<deprecated.size(); i++){
54  printf("\n Input parameter: %s", deprecated[i].name.c_str());
55  printf("\n Suggestion: %s\n", deprecated[i].msg.c_str());
56  }
57  }
58 
59  if(found_removed){
60  printf("\n\n\n******** ERROR: Removed input detected *********\n");
61  for(int i=0; i<removed.size(); i++){
62  printf("\n Input parameter: %s", removed[i].name.c_str());
63  printf("\n Suggestion: %s\n", removed[i].msg.c_str());
64  }
65  }
66 
67  if(!nlr->namelist_present("diff_param")){
68  printf("\n\n\n******** ERROR: Missing namelist detected *********\n");
69  printf("\n Add diff_param to input file\n");
70  }
71 
73  printf("\nIf this input file is in an official example, please let the XGC team know so we can update the example.\n");
74  printf("\n****************************************************\n\n");
75  }
76  }
77 
78  if(found_removed){
79  exit_XGC("\nExiting XGC\n");
80  }
81  }
82 };
83 
84 /* Checks input file for deprecated or removed inputs. Provide a specific instruction to the user!
85  * */
87  InputChecker ic(nlr);
88 }
89 
90 #endif
bool found_removed
Definition: check_input_file.hpp:19
bool is_rank_zero()
Definition: globals.hpp:26
void check_input_file(NLReader::NamelistReader &nlr)
Definition: check_input_file.hpp:86
bool present(const string &param)
Definition: NamelistReader.hpp:337
Definition: NamelistReader.hpp:163
InputChecker(NLReader::NamelistReader &nlr)
Definition: check_input_file.hpp:23
CheckerEntry(std::string name, std::string msg)
Definition: check_input_file.hpp:11
Definition: check_input_file.hpp:7
std::vector< CheckerEntry > deprecated
Definition: check_input_file.hpp:16
void use_namelist(const string &namelist)
Definition: NamelistReader.hpp:322
NLReader::NamelistReader * nlr
Definition: check_input_file.hpp:15
std::vector< CheckerEntry > removed
Definition: check_input_file.hpp:17
bool namelist_present(const string &namelist)
Definition: NamelistReader.hpp:312
void exit_XGC(std::string msg)
Definition: globals.hpp:36
void deprecate(std::string list, std::string name, std::string msg)
Definition: check_input_file.hpp:29
Definition: check_input_file.hpp:14
bool found_deprecated
Definition: check_input_file.hpp:18
void announce_all()
Definition: check_input_file.hpp:49
std::string msg
Definition: check_input_file.hpp:9
std::string name
Definition: check_input_file.hpp:8