00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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 }