aboutsummaryrefslogtreecommitdiffstats
path: root/misc/data_loaders.hpp
blob: d0f07e7795aeab7e7b8b03cd6f61550f78b951c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#ifndef DATA_LOADERS_H
#define DATA_LOADERS_H
#include <core/fitter.hpp>
#include <data_sets/default_data_set.hpp>
#include <iostream>
#include <fstream>
#include <cmath>

namespace opt_utilities
{
  template <typename Ty,typename Tx>
  class dl_x_y_ye;

  template <typename Ty,typename Tx>
  std::istream& operator>>(std::istream& ifs,dl_x_y_ye<Ty,Tx>& dl);

  template <typename Ty,typename Tx>
  class dl_x_xe_y_ye;

  template <typename Ty,typename Tx>
  std::istream& operator>>(std::istream& ifs,dl_x_xe_y_ye<Ty,Tx>& dl);

  template <typename Ty,typename Tx>
  class dl_x_xu_xl_y_yu_yl;
  
  template <typename Ty,typename Tx>
  std::istream& operator>> (std::istream& ifs,dl_x_xu_xl_y_yu_yl<Ty,Tx>& dl);

  template <typename Ty,typename Tx>
  class dl_x_y_ye
  {
  private:
    default_data_set<Ty,Tx> ds;
  public:
    data_set<Ty,Tx>& get_data_set()
    {
      return ds;
    }

    void load_from(std::istream& ifs)
    {
      for(;;)
	{
	  Tx x;
	  Tx x_err;
	  Ty y;
	  Ty y_err(1);
	  
	  ifs>>x>>y>>y_err;
	  
	  if(!ifs.good())
	    {
	      break;
	    }
	  data<Ty,Tx> d(x,y,y_err,y_err,x_err,x_err);
	  ds.push_back(d);
	}
      //return ifs;
    }

    void load_from(const char* name)
    {
      std::ifstream ifs(name);
      load_from(ifs);

    }
    //friend std::istream& operator>> <>(std::istream& ifs,dl_x_y_ye<Ty,Tx>& dl);
  };

  template <typename Ty,typename Tx>
  std::istream& operator>>(std::istream& ifs,dl_x_y_ye<Ty,Tx>& dl)
  {
    dl.load_from(ifs);
    return ifs;
  }


  template <typename Ty,typename Tx>
  class dl_x_xe_y_ye
  {
  private:
    default_data_set<Ty,Tx> ds;
  public:
    data_set<Ty,Tx>& get_data_set()
    {
      return ds;
    }

    void load_from(std::istream& ifs)
    {
      for(;;)
	{
	  Tx x;
	  Tx x_err;
	  Ty y;
	  Ty y_err(1);
	  
	  ifs>>x>>x_err>>y>>y_err;
	  
	  if(!ifs.good())
	    {
	      break;
	    }
	  data<Ty,Tx> d(x,y,y_err,y_err,x_err,x_err);
	  ds.push_back(d);
	}
    }

    void load_from(const char* name)
    {
      std::ifstream ifs(name);
      load_from(ifs); 
    }
  };

  template <typename Ty,typename Tx>
  std::istream& operator>>(std::istream& ifs,dl_x_xe_y_ye<Ty,Tx>& dl)
  {
    dl.load_from(ifs);
    return ifs;
  }

  template <typename Ty,typename Tx>
  class dl_x_xu_xl_y_yu_yl
  {
  private:
  
    default_data_set<Ty,Tx> ds;
  public:
    data_set<Ty,Tx>& get_data_set()
    {
      return ds;
    }
    
    void load_from(std::istream& ifs)
    {
      for(;;)
	{
	  Tx x;
	  Tx xl,xu;
	  Ty y;
	  Ty yl(1),yu(1);
	  
	  ifs>>x>>xu>>xl>>y>>yu>>yl;
	  
	  xu=std::abs(xu);
	  xl=std::abs(xl);
	  yu=std::abs(yu);
	  yl=std::abs(yl);
	  
	  if(!ifs.good())
	    {
	      break;
	    }
	  data<Ty,Tx> d(x,y,yl,yu,xl,xu);
	  ds.push_back(d);
	}
    }

    void load_from(const char* name)
    {
      std::ifstream ifs(name);
      load_from(ifs);
    }
  };

  template <typename Ty,typename Tx>
  std::istream& operator>> (std::istream& ifs,dl_x_xu_xl_y_yu_yl<Ty,Tx>& dl)
  {
    dl.load_from(ifs);
    return ifs;
  }

  

}


#endif
//EOF