gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-252-gf9a3f78
a Global And Modular Bsm Inference Tool
ascii_table_reader.cpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
16 
18 
19 namespace Gambit
20 {
21 
22 
23  int ASCIItableReader::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  std::string line;
33  while(std::getline(in, line))
34  {
35  if (line[0] == '#') continue; // Ignore comments lines, starting with "#"
36  std::stringstream ss(line);
37 
38  size_t i = 0;
39  double tmp;
40  while(ss >> tmp)
41  {
42  if ( i+1 > data.size() ) data.resize(i+1);
43  data[i].push_back(tmp);
44  i++;
45  }
46  }
47  in.close();
48  return 0;
49  }
50 
51 
52  void ASCIItableReader::setcolnames(std::vector<std::string> names)
53  {
54  if ( (int) names.size() == ncol )
55  {
56  size_t i = 0;
57  for (auto it = names.begin(); it != names.end(); it++)
58  {
59  colnames[*it] = i;
60  i++;
61  }
62  }
63  else
64  {
65  std::cout << "Warning in ASCIItableReader: Column number incompatible." << std::endl;
66  }
67  }
68 
69 
70 }
EXPORT_SYMBOLS error & utils_error()
Utility errors.
void setcolnames(std::vector< std::string > names)
Simple reader for ASCII tables.
#define LOCAL_INFO
Definition: local_info.hpp:34
std::map< std::string, int > colnames
std::vector< std::vector< double > > data
int read(std::string filename)
TODO: see if we can use this one:
Definition: Analysis.hpp:33