diff options
author | astrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675> | 2008-12-15 07:26:12 +0000 |
---|---|---|
committer | astrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675> | 2008-12-15 07:26:12 +0000 |
commit | 1f4a944064bc42284c33e6b755353d191cf288e8 (patch) | |
tree | c8cb2253dea5f395e0f867aa6976433bd3eb00de /misc/data_loaders.hpp | |
download | opt-utilities-1f4a944064bc42284c33e6b755353d191cf288e8.tar.bz2 |
git-svn-id: file:///home/svn/opt_utilities@1 ed2142bd-67ad-457f-ba7c-d818d4011675
Diffstat (limited to 'misc/data_loaders.hpp')
-rw-r--r-- | misc/data_loaders.hpp | 180 |
1 files changed, 180 insertions, 0 deletions
diff --git a/misc/data_loaders.hpp b/misc/data_loaders.hpp new file mode 100644 index 0000000..6d2195d --- /dev/null +++ b/misc/data_loaders.hpp @@ -0,0 +1,180 @@ +#ifndef DATA_LOADERS_H +#define DATA_LOADERS_H +#include <core/fitter.hpp> +#include <core/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 |