PURIFY
Next-generation radio interferometric imaging
data.in.h
Go to the documentation of this file.
1 #ifndef PURIFY_DATA_H
2 #define PURIFY_DATA_H
3 
4 #include <fstream>
5 #include <string>
6 #include <vector>
7 #include <sys/stat.h>
8 
9 #include "purify/types.h"
10 #include "purify/directories.h"
11 namespace purify {
13 template <class T>
14 typename std::enable_if<std::is_scalar<T>::value, std::vector<T>>::type read_data(
15  const std::string& filename) {
16  std::ifstream data_file(filename);
17  if (!data_file) throw std::runtime_error("Test data is missing: " + filename);
18  std::string s;
19  // read data
20  std::vector<T> data;
21  for (std::string s; std::getline(data_file, s, ',');) {
22  data.push_back(std::stod(s));
23  }
24  return data;
25 }
27 template <class T>
28 typename std::enable_if<std::is_same<t_complex, T>::value, std::vector<T>>::type read_data(
29  const std::string& filename) {
30  std::ifstream data_file(filename);
31  if (!data_file) throw std::runtime_error("Test data is missing: " + filename);
32  std::string real = "";
33  std::string imag = "";
34  // read data
35  std::vector<T> data;
36  for (std::string real; std::getline(data_file, real, ',');) {
37  real.erase(0, 1);
38  if (!std::getline(data_file, imag, ')')) break;
39  data.push_back(T(std::stod(real), std::stod(imag)));
40  real = "";
41  imag = "";
42  }
43  return data;
44 }
45 
46 std::vector<t_complex> read_data(const std::vector<t_real>& input) {
47  std::vector<t_complex> output;
48  for (auto a = input.begin(); a != input.end(); a++) output.push_back(t_complex(*a, 0.));
49  return output;
50 }
51 
52 } // namespace purify
53 #endif
std::enable_if< std::is_scalar< T >::value, std::vector< T > >::type read_data(const std::string &filename)
read real values from data file
Definition: data.in.h:14