gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-252-gf9a3f78
a Global And Modular Bsm Inference Tool
ascii_dict_reader.cpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
10 //
16 
18 
19 namespace Gambit
20 {
21 
22 
23  int ASCIIdictReader::read(std::string filename)
24  {
25  std::ifstream in(filename.c_str(), std::ios::binary);
26  if (in.fail())
27  {
28  std::ostringstream errmsg;
29  errmsg << "Failed to read file '"<< filename <<"'. Check if file exists.";
30  utils_error().raise(LOCAL_INFO, errmsg.str());
31  }
32 
33  std::string line;
34  while(std::getline(in, line))
35  {
36  if (line[0] == '#' || line.empty() ) continue; // Ignore comments lines, starting with "#" and empty lines
37  std::stringstream ss(line);
38 
39  double tmp;
40  std::string key;
41  std::vector<double> data_tmp;
42 
43  ss >> key;
44  while(ss >> tmp)
45  {
46  data_tmp.push_back(tmp);
47  }
48 
49 
50  if (std::find(keys.begin(), keys.end(), key) != keys.end())
51  {
52  duplicate = true;
53  }
54 
55  dict[key] = data_tmp;
56  keys.push_back(key);
57 
58  }
59  in.close();
60  return 0;
61  }
62 
63 
64 
65 }
EXPORT_SYMBOLS error & utils_error()
Utility errors.
Simple reader for ASCII tables.
#define LOCAL_INFO
Definition: local_info.hpp:34
std::vector< std::string > keys
std::map< std::string, std::vector< double > > dict
TODO: see if we can use this one:
Definition: Analysis.hpp:33
int read(std::string filename)