Interpolator::FileWriter Class Reference

This class provides basics tools to write files
It is mainly used for the correcting and coupling files
Thanks to this abstract class, it is possible to define a specific file writer for each scientific group
The only things to do is to implement the Write method. More...

#include <FileWriter.h>

List of all members.

Public Member Functions

 FileWriter ()
 FileWriter (const std::string &sPath, const std::string &sFileName)
 FileWriter (const std::string &sPath, const std::string &sFileName, long lNbVariables, long lNbDatas)
 FileWriter (const std::string &sPath, const std::string &sFileName, long lNbDatas, double *mXdata, double *mYdata)
 FileWriter (const std::string &sCompleteFilePath, long lNbDatas, double *mXdata, double *mYdata)
 FileWriter (const std::string &sPath, const std::string &sFileName, long lIndex, std::string &sExtension, long lNbDatas, double *mXdata, double *mYdata)
 FileWriter (const std::string &sCompleteFilePath, gsl_vector *mXdata, gsl_vector *mYdata)
 FileWriter (const std::string &sPath, const std::string &sFileName, long lIndex, const std::string &sExtension, gsl_vector *mXdata, gsl_vector *mYdata)
 FileWriter (const std::string &sCompleteFilePath, double dThetaTheorical, double dThetaMechanical, double dTolerance)
 For Swing theta theorical -> theta mechanical table updating Specific method must be 4 columns !!!
long FileWriter::FindLine (GenericFileReader1D *mFile, double dThetaTheorical, double dTolerance)
bool isWritable ()
virtual ~FileWriter ()
double writeDouble ()
std::string writeString ()
int writeInt ()
std::string writeLine ()
long extractFileSize ()
long extractNbFileLines ()
long extractBufferSize ()
long getFileSize () const
long getNbFileLines () const
long getBufferSize () const
long getNbVariables () const
long getNbData () const
void setFileSize (long lFileSize)
void setNbFileLines (long lNbFileLines)
void setBufferSize (long lBufferSize)
void setNbVariables (long lNbVariables)
void setNbData (long lNbData)
void copyFileToBuffer ()
void extractHeader ()

Private Attributes

std::string _sFileName
long _lNbVariables
long _lNbData
std::stringstream _mFileBuffer
long _lBufferSize
long _lFileSize
long _lNbFileLines


Detailed Description

This class provides basics tools to write files
It is mainly used for the correcting and coupling files
Thanks to this abstract class, it is possible to define a specific file writer for each scientific group
The only things to do is to implement the Write method.

Definition at line 29 of file FileWriter.h.


Constructor & Destructor Documentation

Interpolator::FileWriter::FileWriter  ) 
 

Definition at line 13 of file FileWriter.cpp.

00014 {
00015 
00016 }

Interpolator::FileWriter::FileWriter const std::string &  sPath,
const std::string &  sFileName
 

Interpolator::FileWriter::FileWriter const std::string &  sPath,
const std::string &  sFileName,
long  lNbVariables,
long  lNbDatas
 

Interpolator::FileWriter::FileWriter const std::string &  sPath,
const std::string &  sFileName,
long  lNbDatas,
double *  mXdata,
double *  mYdata
 

Definition at line 23 of file FileWriter.cpp.

00024 {
00025         std::string sCompleteFilePath = sPath;
00026                                 sCompleteFilePath+=sFileName;
00027         
00028         std::ofstream fFile(sCompleteFilePath.c_str(),ios::out);
00029     
00030         for (int i=0;i<lNbDatas;i++)
00031         {
00032                 fFile << mXdata[i] << "\t" << mYdata[i] << endl;
00033         }
00034 
00035         fFile.close();
00036 }

Interpolator::FileWriter::FileWriter const std::string &  sCompleteFilePath,
long  lNbDatas,
double *  mXdata,
double *  mYdata
 

Definition at line 38 of file FileWriter.cpp.

00039 {
00040         std::ofstream fFile(sCompleteFilePath.c_str(),ios::out);
00041     
00042         for (int i=0;i<lNbDatas;i++)
00043         {
00044                 fFile << mXdata[i] << "\t" << mYdata[i] << endl;
00045         }
00046 
00047         fFile.close();
00048 }

Interpolator::FileWriter::FileWriter const std::string &  sPath,
const std::string &  sFileName,
long  lIndex,
std::string &  sExtension,
long  lNbDatas,
double *  mXdata,
double *  mYdata
 

Definition at line 50 of file FileWriter.cpp.

00055 {
00056 
00057         std::string sCompleteFilePath = sPath;
00058                                 sCompleteFilePath+="/"; 
00059                                 sCompleteFilePath+=sFileName;   
00060                                 sCompleteFilePath+="_"; 
00061                                 sCompleteFilePath+=ltos(lIndex);
00062                                 sCompleteFilePath+="."; 
00063                                 sCompleteFilePath+=sExtension;  
00064 
00065         std::ofstream fFile(sCompleteFilePath.c_str(),ios::out);
00066     
00067         for (int i=0;i<lNbDatas;i++)
00068         {
00069                 fFile << mXdata[i] << "\t" << mYdata[i] << endl;
00070         }
00071 
00072         fFile.close();
00073 }

Interpolator::FileWriter::FileWriter const std::string &  sCompleteFilePath,
gsl_vector *  mXdata,
gsl_vector *  mYdata
 

Definition at line 81 of file FileWriter.cpp.

00082 {
00083         std::ofstream fFile(sCompleteFilePath.c_str(),ios::out);
00084         size_t lNbDatas = mXdata->size;
00085 
00086         for (unsigned int i=0;i<lNbDatas;i++)
00087         {
00088                 fFile << gsl_vector_get(mXdata,i) << "\t" << gsl_vector_get(mYdata,i) << endl;
00089         }
00090 
00091         fFile.close();
00092 }

Interpolator::FileWriter::FileWriter const std::string &  sPath,
const std::string &  sFileName,
long  lIndex,
const std::string &  sExtension,
gsl_vector *  mXdata,
gsl_vector *  mYdata
 

Definition at line 94 of file FileWriter.cpp.

00099 {
00100         size_t lNbDatas = mXdata->size;
00101         std::string sCompleteFilePath = sPath;
00102                                 sCompleteFilePath+="/"; 
00103                                 sCompleteFilePath+=sFileName;   
00104                                 sCompleteFilePath+="_"; 
00105                                 sCompleteFilePath+=ltos(lIndex);
00106                                 sCompleteFilePath+="."; 
00107                                 sCompleteFilePath+=sExtension;  
00108 
00109         std::ofstream fFile(sCompleteFilePath.c_str(),ios::out);
00110     
00111         for (unsigned int i=0;i<lNbDatas;i++)
00112         {
00113                 fFile << gsl_vector_get(mXdata,i) << "\t" << gsl_vector_get(mYdata,i) << endl;
00114         }
00115 
00116         fFile.close();
00117 }

Interpolator::FileWriter::FileWriter const std::string &  sCompleteFilePath,
double  dThetaTheorical,
double  dThetaMechanical,
double  dTolerance
 

For Swing theta theorical -> theta mechanical table updating Specific method must be 4 columns !!!

Definition at line 123 of file FileWriter.cpp.

References Interpolator::GenericFileReader1D::getColumnName(), getNbData(), Interpolator::FileReader::getNbData(), getNbVariables(), Interpolator::FileReader::getNbVariables(), and Interpolator::GenericFileReader1D::getValue().

00127 {
00128         
00129         GenericFileReader1D* mFile = new GenericFileReader1D(sCompleteFilePath);
00130   //- Get number of line in the file
00131         long    lNbData                                 = mFile->getNbData();
00132         
00133         std::ofstream fFile(sCompleteFilePath.c_str(),ios::out);
00134         fFile.precision(20);
00135         
00136   //- find the line associated to the theorical theta value and with a tolerance
00137         long lLineToModify = FindLine(mFile,dThetaTheorical,dTolerance);
00138 
00139         fFile << mFile->getNbVariables() << endl;       //Must be 4 !!!
00140 
00141         bool bAddingLine                = false;
00142         bool bInsertAtBeginning = false;
00143         
00144         if (lLineToModify == -1)
00145         {
00146                 //bAddingLine = true;
00147                 double dFirstValue = mFile->getValue(1,0);
00148                 double dLastValue = mFile->getValue(1,lNbData-1);
00149 
00150                 if ((dThetaTheorical > dFirstValue) && (dThetaTheorical < dLastValue))
00151                 {
00152                         //In this case no value must be inserted its only because the tolerance around the ThetaTheorical value can be checked.
00153                         bAddingLine = false;
00154                 }
00155                 else
00156                 {
00157                         if (dFirstValue >= dThetaTheorical) 
00158                         {
00159                                 bAddingLine                     = true;
00160                                 bInsertAtBeginning      = true;
00161                         }
00162                         else
00163                         {
00164                                 bAddingLine                     = true;
00165                                 bInsertAtBeginning      = false;
00166                         }
00167                 }
00168         }
00169         
00170         double dOffset = dThetaMechanical - dThetaTheorical;
00171 
00172         //Generate a new file
00173         if (bAddingLine)
00174                 fFile << (lNbData+1) << endl;
00175         else
00176                 fFile << lNbData << endl;
00177         
00178         int i,j;
00179         for (i=0;i<mFile->getNbVariables();i++)
00180         {
00181                 fFile << mFile->getColumnName(i) << "\t\t";
00182         }
00183         fFile << endl;
00184         
00185         if (bAddingLine && bInsertAtBeginning) 
00186         {
00187                         fFile << RadiansToDegres(dThetaTheorical) << "\t\t";
00188                         fFile << dThetaTheorical << "\t\t";
00189                         fFile << dOffset << "\t\t";
00190                         fFile << dThetaMechanical << "\n";
00191         }
00192 
00193         for (i=0;i<mFile->getNbData();i++)
00194         {
00195                 if (i == lLineToModify)
00196                 {
00197                         fFile << RadiansToDegres(dThetaTheorical) << "\t\t";
00198                         fFile << dThetaTheorical << "\t\t";
00199                         fFile << dOffset << "\t\t";
00200                         fFile << dThetaMechanical << "\n";
00201                 }
00202                 else
00203                 {
00204                         for (j=0;j<mFile->getNbVariables();j++)
00205                         {
00206                                 fFile << mFile->getValue(j,i) << "\t\t";
00207                         } 
00208                         fFile << endl;
00209                 }
00210         }
00211 
00212         if ((bAddingLine) && (!bInsertAtBeginning))
00213         {
00214 
00215                 //We have to check if must be inserted in th
00216 
00217                 fFile << RadiansToDegres(dThetaTheorical) << "\t\t";
00218                 fFile << dThetaTheorical << "\t\t";
00219                 fFile << dOffset << "\t\t";
00220                 fFile << dThetaMechanical << "\n";
00221         }
00222 
00223         fFile.close();
00224 }

Here is the call graph for this function:

Interpolator::FileWriter::~FileWriter  )  [virtual]
 

Definition at line 18 of file FileWriter.cpp.

00019 {
00020 
00021 }


Member Function Documentation

void Interpolator::FileWriter::copyFileToBuffer  ) 
 

long Interpolator::FileWriter::extractBufferSize  ) 
 

long Interpolator::FileWriter::extractFileSize  ) 
 

void Interpolator::FileWriter::extractHeader  ) 
 

long Interpolator::FileWriter::extractNbFileLines  ) 
 

long Interpolator::FileWriter::FileWriter::FindLine GenericFileReader1D mFile,
double  dThetaTheorical,
double  dTolerance
 

long Interpolator::FileWriter::getBufferSize  )  const
 

long Interpolator::FileWriter::getFileSize  )  const
 

long Interpolator::FileWriter::getNbData  )  const
 

Referenced by FileWriter().

long Interpolator::FileWriter::getNbFileLines  )  const
 

long Interpolator::FileWriter::getNbVariables  )  const
 

Referenced by FileWriter().

bool Interpolator::FileWriter::isWritable  ) 
 

void Interpolator::FileWriter::setBufferSize long  lBufferSize  ) 
 

void Interpolator::FileWriter::setFileSize long  lFileSize  ) 
 

void Interpolator::FileWriter::setNbData long  lNbData  ) 
 

void Interpolator::FileWriter::setNbFileLines long  lNbFileLines  ) 
 

void Interpolator::FileWriter::setNbVariables long  lNbVariables  ) 
 

double Interpolator::FileWriter::writeDouble  ) 
 

int Interpolator::FileWriter::writeInt  ) 
 

std::string Interpolator::FileWriter::writeLine  ) 
 

std::string Interpolator::FileWriter::writeString  ) 
 


Member Data Documentation

long Interpolator::FileWriter::_lBufferSize [private]
 

Definition at line 101 of file FileWriter.h.

long Interpolator::FileWriter::_lFileSize [private]
 

Definition at line 102 of file FileWriter.h.

long Interpolator::FileWriter::_lNbData [private]
 

Definition at line 97 of file FileWriter.h.

long Interpolator::FileWriter::_lNbFileLines [private]
 

Definition at line 103 of file FileWriter.h.

long Interpolator::FileWriter::_lNbVariables [private]
 

Definition at line 96 of file FileWriter.h.

std::stringstream Interpolator::FileWriter::_mFileBuffer [private]
 

Definition at line 99 of file FileWriter.h.

std::string Interpolator::FileWriter::_sFileName [private]
 

Definition at line 94 of file FileWriter.h.


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