XGC1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
check_aif_flx_format.hpp
Go to the documentation of this file.
1 #ifndef CHECK_AIF_FLX_FORMAT_HPP
2 #define CHECK_AIF_FLX_FORMAT_HPP
3 
4 #include <iostream>
5 #include <fstream>
6 #include <sstream>
7 #include <string>
8 #include "globals.hpp"
9 
10 /* This subroutine checks if the flx.aif file is in the old format
11  * It assumes nnode>1
12  */
13 inline bool is_old_flx_format(const std::string& filename){
14  // Open file
15  std::ifstream file(filename);
16 
17  // Check if file could be opened
18  if(!file.is_open()){
19  printf("\nError: %s not found", filename.c_str());
20  exit_XGC("\nThe flx.aif file is required.\n");
21  }
22 
23  // Read file line by line
24  std::string line;
25  int line_count = 0;
26  int n_entries_on_line_5 = 0;
27  int n_entries_on_line_6 = 0;
28  while (std::getline(file, line)){
29  line_count++;
30 
31  // To distinguish between the two formats, we need only count the number of
32  // entries on Lines 5 and 6.
33  if(line_count==5) {
34  // Count how many entries are on this line
35  std::istringstream iss(line);
36  int entry;
37  while (iss >> entry){
38  n_entries_on_line_5++;
39  }
40  }
41 
42  if(line_count==6) {
43  // Count how many entries are on this line
44  std::istringstream iss(line);
45  int entry;
46  while (iss >> entry){
47  n_entries_on_line_6++;
48  }
49 
50  // Exit loop after Line 6
51  break;
52  }
53  }
54  file.close();
55 
56  // In the new format, the only way that both Line 5 and Line 6 could be size 1 is if nnode==1, which we assume is not the case.
57  // Also, if there were 0 entries due to the file being too short, that could only be the old format. Therefore we can distinguish them:
58  if(n_entries_on_line_5<=1 && n_entries_on_line_6<=1){
59  // Old format
60  printf(" Flux surface file %s identified as using the OLD format. Consider converting to the new format.\n", filename.c_str());
61  return true;
62  }else{
63  // New format
64  printf(" Flux surface file %s identified as using the NEW format.\n", filename.c_str());
65  return false;
66  }
67 }
68 
69 #endif
void exit_XGC(std::string msg)
Definition: globals.hpp:37
bool is_old_flx_format(const std::string &filename)
Definition: check_aif_flx_format.hpp:13