00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _OMGCLIMATEFILEREADER_H_
00021 #define _OMGCLIMATEFILEREADER_H_
00022
00023 #include <QFile>
00024 #include <QString>
00025 #include <QVector>
00026 #include <QMap>
00027 #include <QTextStream>
00028 #include <fstream>
00029 #include <iostream>
00030
00031 #include <gdal_priv.h>
00032
00037 class OMG_LIB_EXPORT OmgClimateFileReader : public QObject
00038 {
00039 Q_OBJECT;
00040
00041 public:
00042
00043
00044
00045
00049 enum FileType { GDAL,
00050 HADLEY_SRES,
00051 HADLEY_IS92,
00052 HADLEY_SRES_MEAN,
00053 IPCC_OBSERVED,
00054 VALDES,
00055 ECHAM4,
00056 CSIRO_MK2,
00057 NCAR_CSM_PCM,
00058 GFDL_R30,
00059 CGCM2,
00060 CCSR_AGCM_OGCM,
00061 CRU_CL1_MONTHLY };
00062
00063
00064
00065
00066
00067
00069 OmgClimateFileReader();
00070
00072 OmgClimateFileReader(QString theFileName,FileType theFileType);
00073
00075 ~OmgClimateFileReader();
00076
00082 bool initialise(QString theFileNameString, FileType theFileType);
00083
00089 float getElement();
00090
00096 const long currentElementNo();
00097
00102 const long currentRow();
00103
00108 const long currentCol();
00109
00110
00115 const int headerLineCount();
00116
00126 bool setActiveBlock( const unsigned int theBlockNo);
00127
00134 const int activeBlock();
00135
00136
00141 const bool isAtMatrixEnd();
00142
00143
00148 const QString filename();
00149
00150
00151
00159 const OmgClimateFileReader::FileType getFileType();
00160
00162 const long yDim();
00164 const long xDim();
00166 const int blockHeaderLineCount();
00168 QString getOmgClimateFileReaderInfo();
00170 const int blockStartPos();
00172 bool moveToHeader();
00174 const int blockCount();
00176 int getNumberOfBlocks();
00183 void printFirstCellInEachBlock();
00191 void printLastCellInEachBlock();
00197 void printBlockMarkers();
00201 void printBlock(int theBlock);
00202 signals:
00203 void error (QString theError);
00204 void message (QString theMessage);
00205
00206 private:
00207
00214 bool setFileType( const FileType theNewVal);
00228 QVector <int> getBlockMarkers(bool forceFlag=false);
00229
00236 double readValue ( void *theData, GDALDataType theType, int theIndex );
00237
00238
00239
00240
00242 static const unsigned int mMaxLineLength=100;
00244 unsigned int mXDim;
00246 unsigned int mYDim;
00248 FileType mFileType;
00250 QString mFileName;
00252 bool mEndOfMatrixFlag;
00254 int mActiveBlockNo;
00256 int mFileHeaderLines;
00258 unsigned int mCurrentColumn;
00260 unsigned int mCurrentRow;
00262 unsigned int mCurrentElementNo;
00264 std::ifstream mTextStream;
00266 char mBuffer[mMaxLineLength];
00268 GDALDataset * mGdalDataset;
00269
00271 int mBlockHeaderLines;
00273 int mBlockStartPos;
00275 QVector <int> mBlockMarkersVector;
00276
00277
00278 };
00279
00280 #endif