include/qcfield.h

00001 /***************************************************************************
00002  *   Quantum Construct (qC++)                                                                  *
00003  *   The Quantum Physics Computational Library                                         *
00004  *   Copyright (C) 2005 by Shekhar S. Chandra                                      *
00005  *   Shekhar.Chandra@sci.monash,edu.au                                     *
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  ***************************************************************************/
00022 /*
00023         Ver Info - QCField.h
00024         1.0.0 - Original Implementation
00025 */
00026 
00027 #ifndef QCFIELD_H
00028 #define QCFIELD_H
00029 
00030 #include <fstream>
00031 #include <blitz/array.h>
00032 
00033 using namespace blitz;
00034 
00038 typedef double fieldType;
00039 
00040 static int filePrecision = 12;
00041 
00046 template <typename T, int rank>
00047 class QCField
00048 {
00049 public:
00050         // -------------------------------------------------------
00056         QCField(void);
00060         QCField(int noOfRows, int noOfCols);
00064         ~QCField(void);
00066 
00067         // -------------------------------------------------------
00073         void setSize(int noOfRows, int noOfCols)
00074         {       Field.resize(noOfRows,noOfCols);        }
00078         void resize(int noOfRows, int noOfCols)
00079         {       Field.resizeAndPreserve(noOfRows,noOfCols);     }
00083         Array<T,rank>* accessArray()
00084         {       return &Field;  }
00088         Array<T,rank>& array()
00089         {       return Field;   }
00091 
00092         // -------------------------------------------------------
00098         int noOfRows()
00099         {       return Field.rows();    }
00103         int noOfColumns()
00104         {       return Field.cols();    }
00108         int height()
00109         {       return Field.extent(thirdDim);  }
00111 
00112         // -------------------------------------------------------
00118         void assignElement(int atRow, int atCol, T value)
00119         {       Field(atRow,atCol) = value;     }
00123         void assignElement(int atRow, int atCol, int atHeight, T value)
00124         {       Field(atRow,atCol,atHeight) = value;    }
00128         T retrieveElement(int atRow, int atCol)
00129         {       return Field(atRow,atCol);      }
00133         T retrieveElement(int atRow, int atCol, int atHeight)
00134         {       return Field(atRow,atCol,atHeight);     }
00136 
00137         // -------------------------------------------------------
00143         void dumpToStdErr()
00144         {       cerr << Field;  }
00148         bool readFromFile(const char* fileName);
00152         bool writeToFile(const char* fileName);
00154 
00155 protected:
00156         Array<T,rank> Field; 
00157 };
00158 #endif
00159 
00160 template <typename T, int rank>
00161 QCField<T,rank>::QCField(void)
00162 {
00163 }
00164 
00165 template <typename T, int rank>
00166 QCField<T,rank>::QCField(int noOfRows, int noOfCols)
00167 {
00168         setSize(noOfRows,noOfCols);
00169 }
00170 
00171 template <typename T, int rank>
00172 QCField<T,rank>::~QCField(void)
00173 {
00174         Field.free();
00175 }
00176 
00177 template <typename T, int rank>
00178 bool QCField<T,rank>::readFromFile(const char* fileName)
00179 {
00180         ifstream inFile(fileName,ios::in);
00181         inFile.precision(filePrecision);
00182 
00183         if(inFile.fail())
00184         {
00185                 cerr << "File Error: " << fileName << endl;
00186                 return false;
00187         }
00188         else
00189         {
00190                 inFile >> Field;
00191                 inFile.close();
00192                 return true;
00193         }
00194 }
00195 
00196 template <typename T, int rank>
00197 bool QCField<T,rank>::writeToFile(const char* fileName)
00198 {
00199         ofstream outFile(fileName,ios::out);
00200         outFile.precision(filePrecision);
00201 
00202         if(outFile.fail())
00203         {
00204                 cerr << "File Error: " << fileName << endl;
00205                 return false;
00206         }
00207         else
00208         {
00209                 outFile << Field;
00210                 outFile.close();
00211                 return true;
00212         }
00213 }

Generated on Sat May 13 13:22:48 2006 for Quantum Construct (qC++) by  doxygen 1.4.6-NO