ICLIB::DataFile2D Class Reference

#include <DataFile2D.h>

Inherits ICLIB::DataFile.

Inheritance diagram for ICLIB::DataFile2D:

Inheritance graph
[legend]
Collaboration diagram for ICLIB::DataFile2D:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 DataFile2D ()
virtual ~DataFile2D ()
virtual void load (const std::string &filename)
virtual void save (const std::string &filename)
void getArrayValues (vector< double > &aray, int &xdim, int &ydim)
void setArrayValues (const vector< double > &aray, int xdim, int ydim)

Detailed Description

Definition at line 8 of file DataFile2D.h.


Constructor & Destructor Documentation

ICLIB::DataFile2D::DataFile2D  ) 
 

Definition at line 6 of file DataFile2D.cpp.

References ICLIB::DataFile::mFilename.

00006                        {
00007         mFilename = "<unknown filename>";
00008 }

ICLIB::DataFile2D::~DataFile2D  )  [virtual]
 

Definition at line 10 of file DataFile2D.cpp.

00010                         {
00011 }


Member Function Documentation

void ICLIB::DataFile2D::getArrayValues vector< double > &  aray,
int &  xdim,
int &  ydim
[virtual]
 

Implements ICLIB::DataFile.

Definition at line 144 of file DataFile2D.cpp.

00144                                                                         {
00145 }

void ICLIB::DataFile2D::load const std::string &  filename  )  [virtual]
 

Implements ICLIB::DataFile.

Definition at line 13 of file DataFile2D.cpp.

References ICLIB::DataFile::clear(), and ICLIB::DataFile::mFilename.

00013                                                                          {
00014         mFilename = filename;
00015         clear();
00016         std::ifstream file(filename.c_str());
00017         if(!file) {
00018                 std::ostringstream err;
00019                 err << "could not open file " << filename << " for reading";
00020                 throw FileNotFoundException(filename,
00021                                                                         "DataFile2D::load",
00022                                                                         __FILE__,
00023                                                                         __LINE__);
00024                 /*Tango::Except::throw_exception( 
00025                         static_cast<const char*>("TANGO_DEVICE_ERROR"), 
00026                         static_cast<const char*>(err.str().c_str()),
00027                         static_cast<const char*>("DataFile2D::load"));*/
00028         }
00029         std::string line;
00030         std::vector< std::string > keys;
00031         if(std::getline(file,line)) {
00032                 std::istringstream iline(line);
00033                 std::string key;
00034                 while(std::getline(iline,key,','))
00035                         keys.push_back(key);
00036         }
00037         if(keys.size()!=3) {
00038                 std::ostringstream err;
00039                 err << "error while parsing file " << filename << " : invalid header";
00040                 throw ParseException (  filename,
00041                                                                 "DataFile2D::load",
00042                                                                 __FILE__,
00043                                                                 __LINE__);
00044                 /*Tango::Except::throw_exception( 
00045                         static_cast<const char*>("TANGO_DEVICE_ERROR"), 
00046                         static_cast<const char*>(err.str().c_str()),
00047                         static_cast<const char*>("DataFile2D::load"));*/
00048         }
00049         // parse first line (xdata)
00050         if(std::getline(file,line)) {
00051                 //cout << "\nline: " << line << endl;
00052                 std::istringstream iline(line);
00053                 //cout << "istringstream.str(): " << iline.str() << endl;
00054                 double tmp;
00055                 Values xdata;
00056                 if(iline >> tmp)
00057                 {
00058                         //cout << "tmp x: " << tmp <<endl;
00059                         xdata.push_back(tmp);
00060                         while(iline >> tmp)
00061                         {
00062                                 //cout << "tmp x: " << tmp <<endl;
00063                                 xdata.push_back(tmp);
00064                         }
00065                 }
00066                 Values ydata;
00067                 Values zdata;
00068                 // parse next lines : ydata and zdata
00069                 while(std::getline(file,line)) {
00070                         //cout << "\nline: " << line << endl;
00071                         std::istringstream iline(line);
00072                         //cout << "istringstream.str(): " << iline.str() << endl;
00073                         double tmp;
00074                         if(iline >> tmp) 
00075                         {
00076                                 //cout << "tmp y: " << tmp <<endl;
00077                                 ydata.push_back(tmp);
00078                                 while(iline >> tmp)
00079                                 {
00080                                         //cout << "tmp z: " << tmp <<endl;
00081                                         zdata.push_back(tmp);   
00082                                 }
00083                         }
00084                 }
00085                 setValues(keys[0],xdata);
00086                 setValues(keys[1],ydata);
00087                 setValues(keys[2],zdata);
00088         }
00089 }

Here is the call graph for this function:

void ICLIB::DataFile2D::save const std::string &  filename  )  [virtual]
 

Implements ICLIB::DataFile.

Definition at line 91 of file DataFile2D.cpp.

References ICLIB::DataFile::mValues.

00091                                                                          {
00092         std::ofstream file(filename.c_str(),ios::out);
00093         if(!file) {
00094                 std::ostringstream err;
00095                 err << "could not open file " << filename << " for writing";
00096                 throw FileNotFoundException(filename,
00097                                                                         "DataFile2D::save",
00098                                                                         __FILE__,
00099                                                                         __LINE__);
00100                 /*Tango::Except::throw_exception( 
00101                         static_cast<const char*>("TANGO_DEVICE_ERROR"), 
00102                         static_cast<const char*>(err.str().c_str()),
00103                         static_cast<const char*>("DataFile2D::save"));*/
00104         }
00105         if(mValues.size()==3) {
00106                 // write header, get data
00107                 ValuesMap::iterator it = mValues.begin();
00108                 file << it->first;
00109                 std::vector< double >& xdata = it->second;
00110                 ++it;
00111                 file << "," << it->first;
00112                 std::vector< double >& ydata = it->second;
00113                 ++it;
00114                 file << "," << it->first;
00115                 std::vector< double >& zdata = it->second;
00116                 file << std::endl;
00117 
00118                 // write xdata
00119                 file << "0.0\t";
00120                 long x=0;
00121                 while(x<xdata.size()) {
00122                         file << xdata[x];
00123                         if(++x<xdata.size())
00124                                 file << "\t";
00125                         else
00126                                 file << std::endl;
00127                 }
00128 
00129                 // write ydata and zdata
00130                 for(long y=0; y<ydata.size(); ++y) {
00131                         file << ydata[y] << "\t";
00132                         x=0;
00133                         while(x<xdata.size() && y*xdata.size()+x<zdata.size()) {
00134                                 file << zdata[y*xdata.size()+x];
00135                                 if(++x<xdata.size())
00136                                         file << "\t";
00137                                 else 
00138                                         file << std::endl;
00139                         }
00140                 }
00141         }
00142 }

void ICLIB::DataFile2D::setArrayValues const vector< double > &  aray,
int  xdim,
int  ydim
[virtual]
 

Implements ICLIB::DataFile.

Definition at line 147 of file DataFile2D.cpp.

00147                                                                             {
00148 }


The documentation for this class was generated from the following files:
Generated on Tue Apr 14 09:51:03 2009 for Interpolator Library by  doxygen 1.4.5