QCReader.hpp

Go to the documentation of this file.
00001 //*****************************************************************************//
00002 //                                                                             //
00003 //   Copyright (c) 2001                                                        //
00004 //      INRIA                                                                  //
00005 //      54600 VILLERS LES NANCY                                                //
00006 //      France                                                                 //
00007 //                                                                             //
00008 //*****************************************************************************//
00009 //                                                                             //
00010 //               *** NOTICE OF PROPRIETARY INFORMATION ***                     //
00011 //                                                                             //
00012 // The information contained in this file is considered proprietary and the    //
00013 // exclusive property of  INRIA. This information may not be disclosed,        //
00014 // duplicated or used, in whole or in part, for  any purpose  whatsoever       //
00015 // without express written authorization from INRIA                            //
00016 //                                                                             //
00017 //*****************************************************************************//
00018 
00019 
00020 #ifndef QC_READER_H_
00021 #define QC_READER_H_
00022 
00023 
00024 #include <string>
00025 #include <iostream>
00026 #include <fstream>
00027 #include <sstream>
00028 #include <vector>
00029 
00030 
00031 #include "QCFiles.hpp"
00032 #include "QCGeneralData.hpp"
00033 
00034 
00035 class QCSystem;
00036 
00037 
00042 
00043 class QCReader
00044 {
00045 
00047 public:
00048 
00052   QCReader (void): inputPath(""), filename(""), input(NULL), line(NULL)
00053   {};
00057   ~QCReader (void) { closeFile(); };
00061   void openFile (const string& filename, const string& path = ".");
00065   void closeFile (void);
00069   void readMasterFile (const string& name, QCFiles& files,
00070                        const string& path = ".");
00074   void readGeneralFile (const string&  name, QCGeneralData& data,
00075                         const string&  path = ".");
00079   void readAtomsFile (const string& name, QCSystem& system, const string& path = ".");
00083   template <class TPParam>
00084   void readParameterFile (const string& name, TPParam *& params, int&  nbParams,
00085                           const string& path = ".");
00086   /*
00087    *
00088    */
00089   template <class TPMDSystem>
00090   void readPartitionFile (const string& name, QCGeneralData& data, TPMDSystem& mdSystem, const string& path = ".");
00094   template <class Numeric>
00095   inline void readValAfterLiteral (const string& literal, Numeric& ref);
00099   template <class Numeric>
00100   inline void readLiteralAndVal (const string& literal, Numeric& ref);
00101 
00103 protected:
00104 
00106 private:
00107   template <class TPMDSystem>
00108   void readNewPartitionFile (QCGeneralData& data, TPMDSystem& mdSystem);
00109   template <class TPMDSystem>
00110   void readOldPartitionFile (QCGeneralData& data, TPMDSystem& mdSystem);
00111 
00115   void gotoNextLine (void);
00119   bool lineIsValid (void) { 
00120     return (line->size()>0 && line->find(COMMENT) != 0 && line->find(COMMENT_BIS) != 0);
00121   };
00125   void gotoNextValidLine (void); 
00129   void readCoordLine (std::string& type, QCFloat* coords, const int dim, int& nfrag);  
00133   void readAtomLine (std::string& type, QCFloat* coords, const int dim, int& nfrag, 
00134                      int& nbAA, std::string & fragStr, std::vector<int> &connect);
00138   inline istringstream* readMultiLiteral (const string& literal);
00139 
00142 public:
00146   static const string    NB_ATOMS;
00147   static const string    NB_ATOM_TYPES;
00148   static const string    SYSTEM_CHARGE;
00149   static const string    SPIN_MULTIPLICITY;
00150   static const string    COMMENT;
00151 
00155   static const string    GENERAL_FILE;
00156   static const string    PARAMETER_FILE;
00157   static const string    ATOMS_FILE;
00158   static const string    RESULT_FILE;
00159   static const string    PARTITION_FILE;
00160   static const string    DENSITY_FILE;
00161 
00165   static const string    MODEL_TYPE;
00166   static const string    PARAMETER_TYPE;
00167   static const string    COMPUTATION_TYPE;
00168   static const string    MAIN_ALGORITHM;
00169   static const string    DIAGO_ALGORITHM;
00170   static const string    SHIFT_LEVEL_PARAM;
00171   static const string    INTG_ACQUISITION_METHOD;
00172   static const string    INIT_DENSITY_MATRIX;
00173   static const string    ENERGY_THRESHOLD;
00174   static const string    ENERGY_MAX_ITER;
00175   static const string    DERIVATION_TYPE;
00176   static const string    DERIV_SHIFT_BHVR;
00177   static const string    DELTA_Q;
00178 
00179 //
00180   static const string    NB_PARTITIONS;
00181   static const string    BUFFER_DIAMETER;
00182   static const string    CUT_RADIUS;
00183   static const string    READ_PARTITION_FILE;
00184   static const string    PARTITION_TYPE;
00185   static const string    PARTITIONER_TYPE;
00186   static const string    BUFFER1_RADIUS, BUFFER2_RADIUS, PARTITION_TYPEP;
00187 
00191   static const string    NB_SUBDOMAIN;
00192   static const string    NB_ATOMS_PART;
00193   static const string    PARTITION_DESCRIPTION;
00194   static const string    PARTITION;
00195   static const string    COMMENT_BIS;
00196 
00197 
00198 protected:
00199 private:
00203   static const int       MAX_LENGTH;
00207   string inputPath;
00211   string filename;
00215   ifstream *input;
00219   string *line;
00220 };
00221 
00222 
00223 
00227 inline void trim (string& str) {
00228   int first, last, len;
00229   
00230   len = str.size();
00231   first = str.find_first_not_of(" \t");
00232   if (first > 0 && first < len)
00233     str.erase(str.begin(), str.begin()+first);
00234   
00235   len = str.size();
00236   last  = str.find_last_not_of(" \t");
00237   if (last < len && last > 0)
00238     str.erase(str.begin()+last+1, str.end());
00239 }
00240 
00241 
00245 template <class T>
00246 void QCReader::readValAfterLiteral (const string& literal, T& ref)
00247 {
00248   gotoNextValidLine();
00249   assert (*line == literal);
00250   gotoNextValidLine();
00251   istringstream isstrm (*line);
00252   isstrm >> ref;
00253 }
00254 
00255 
00256 
00260 template <class T>
00261 void QCReader::readLiteralAndVal (const string& literal, T& ref)
00262 {
00263   gotoNextValidLine();
00264   istringstream *isstrm = readMultiLiteral(literal);
00265   string str;  
00266   *isstrm >> str;
00267   assert(DOUBLE_DOT == str);
00268   *isstrm >> ref;
00269   delete isstrm;
00270 }
00271 
00272 
00273 
00277 istringstream*
00278 QCReader::readMultiLiteral (const string& literal) {
00279   istringstream literalStr (literal);
00280   istringstream *lineStr = new istringstream(*line);
00281   string s1;
00282   string s2;
00283   while (literalStr >> s1){
00284     *lineStr >> s2;
00285     assert (s1 == s2);
00286   }
00287   
00288   return lineStr;
00289 }
00290 
00291 
00292 #endif // QC_READER_H_

Generated on Sat Jan 28 21:07:30 2006 for QC++ by  doxygen 1.4.4