SambaFileReader.cpp

Go to the documentation of this file.
00001 // SambaFileReader.cpp: implementation of the SambaFileReader class.
00002 //
00004 
00005 #ifdef WIN32 
00006 #pragma warning(disable:4786)
00007 #endif
00008 #include "SambaFileReader.h"
00009 #include <stdlib.h>
00010 #include <vector>
00011 #include <stdio.h>
00012 using namespace std;
00013 
00014 
00016 // Construction/Destruction
00018 namespace Interpolator
00019 {
00021 SambaFileReader::SambaFileReader()
00022 {
00023 
00024 }
00025 
00027 SambaFileReader::~SambaFileReader()
00028 {
00029 
00030         if (_mThetaEncoder) 
00031         {
00032                 delete [] _mThetaEncoder;
00033                 _mThetaEncoder = 0;
00034         }
00035         
00036         if (_mThetaReal) 
00037         {
00038                 delete [] _mThetaReal;
00039                 _mThetaReal = 0;
00040         }
00041         
00042         if (_mThetaDiff) 
00043         {
00044                 delete [] _mThetaDiff;
00045                 _mThetaDiff = 0;
00046         }
00047 
00048 }
00049 
00052 SambaFileReader::SambaFileReader(const std::string& sFileName) : FileReader(sFileName) 
00053 {
00054         Parse();
00055 }
00056 
00061 SambaFileReader::SambaFileReader(const std::string& sFileName,long lNbColumns,long lNbLines) : FileReader(sFileName,lNbColumns,lNbLines)
00062 {
00063         Parse();
00064 }
00065 
00070 void SambaFileReader::Parse() // throw (ParseException)
00071 {
00072 
00073 int iNbData = getNbData();
00074 if(Interpolator::_verb == true) cout << "NbData : " << iNbData << endl;
00075 
00076 int iNbVariables = getNbVariables();
00077 if(Interpolator::_verb == true) cout << "NbVariables : " << iNbVariables << endl;
00078 
00079 //Reading of the first line to extract the variables names
00080 std::string sColumn1Name;
00081 
00082  int i=0;
00083 
00084 for (i=0;i<iNbVariables;i++) 
00085 {
00086         sColumn1Name = extractString();
00087         if(Interpolator::_verb == true) cout << "Column " << i << " --> " << sColumn1Name << endl;
00088 }
00089 
00090 _mThetaEncoder  = new double[iNbData];
00091 _mThetaReal             = new double[iNbData];
00092 _mThetaDiff             = new double[iNbData];
00093 double dValue;
00094 
00096 for (i=0;i<iNbData;i++) 
00097 {
00098         for (int j=0;j<iNbVariables;j++) 
00099         {
00100                 dValue = extractDouble();
00101                 
00102                 if (j==1) 
00103                 {
00104                         _mThetaEncoder[i]       = DegresToRadians(dValue);
00105                 }
00106                 if (j==4) 
00107                 {
00108                         _mThetaReal[i]          = DegresToRadians(dValue);      
00109                 }
00110                 if (j==5) 
00111                 {       
00112                         _mThetaDiff[i]          = DegresToRadians(dValue);      
00113                 }
00114         }
00115         
00116 }
00117 
00118 if(Interpolator::_verb == true) cout << "_mThetaEncoder" <<endl;
00119 for (int k=0;k<iNbData;k++)
00120 {
00121         if(Interpolator::_verb == true) cout.precision(10);
00122         if(Interpolator::_verb == true) cout << "k=" << k << " --> " << _mThetaEncoder[k] << endl;
00123 }
00124 
00125 if(Interpolator::_verb == true) cout << "_mThetaReal" <<endl;
00126 for (int l=0;l<iNbData;l++)
00127 { 
00128         if(Interpolator::_verb == true) cout.precision(10);
00129         if(Interpolator::_verb == true) cout <<  "l=" << l << " --> " << _mThetaReal[l] << endl;
00130 }
00131 
00132 if(Interpolator::_verb == true) cout << "ThetaEncoder-ThetaReal" <<endl;
00133 for (int m=0;m<iNbData;m++)
00134 {
00135         if(Interpolator::_verb == true) cout.precision(10);
00136         if(Interpolator::_verb == true) cout << "m=" << m << " --> " << _mThetaDiff[m] << endl;
00137 }
00138         
00139 }
00140 
00143 double* SambaFileReader::getThetaEncoder() const // throw (NullPointerException)
00144 {
00145         if (_mThetaEncoder == 0) throw NullPointerException("_mThetaEncoder","SambaFileReader::getThetaEncoder()",__FILE__,__LINE__);
00146         return _mThetaEncoder;
00147 }
00148 
00150 double* SambaFileReader::getThetaReal() const // throw (NullPointerException)
00151 {
00152         if (_mThetaReal == 0) throw NullPointerException("_mThetaEncoder","SambaFileReader::getThetaEncoder()",__FILE__,__LINE__);
00153         return _mThetaReal;
00154 }
00155 
00157 double* SambaFileReader::getThetaDiff() const // throw (NullPointerException)
00158 {
00159         if (_mThetaDiff == 0) throw NullPointerException("_mThetaDiff","SambaFileReader::getThetaDiff()",__FILE__,__LINE__);
00160         return _mThetaDiff;
00161 }
00162 
00165 double SambaFileReader::getXValue(int i) const // throw (IndexOutOfBoundException)
00166 {
00167         if ((0<=i) && (i<getNbData())) 
00168         {
00169                 return _mThetaEncoder[i];
00170         }
00171         else throw IndexOutOfBoundException("i",i,0,getNbData(),"SambaFileReader::getXValue(int i)",__FILE__,__LINE__);
00172 }
00173 
00176 double SambaFileReader::getYValue(int i) const // throw (IndexOutOfBoundException)
00177 {
00178         
00179         if ((0<=i) && (i<getNbData())) 
00180         {
00181                 return _mThetaReal[i];
00182         }
00183         else throw IndexOutOfBoundException("i",i,0,getNbData(),"SambaFileReader::getYValue(int i)",__FILE__,__LINE__);
00184 
00185 }
00186 
00189 double SambaFileReader::getThetaEncoderValue(int i) const // throw (IndexOutOfBoundException)
00190 {
00191 
00192         if ((0<=i) && (i<getNbData())) 
00193         {
00194                 return getXValue(i);
00195         }
00196         else throw IndexOutOfBoundException("i",i,0,getNbData(),"SambaFileReader::getThetaEncoderValue(int i)",__FILE__,__LINE__);
00197 }
00198 
00201 double SambaFileReader::getThetaRealValue(int i) const // throw (IndexOutOfBoundException)      
00202 {
00203 
00204         if ((0<=i) && (i<getNbData())) 
00205         {
00206                 return getYValue(i);
00207         }
00208         else throw IndexOutOfBoundException("i",i,0,getNbData(),"SambaFileReader::getThetaRealValue(int i)",__FILE__,__LINE__);
00209 }
00210 
00211 }
00212 

Generated on Tue Apr 14 09:50:28 2009 for Interpolator Library by  doxygen 1.4.5