Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

omgclimatefilegroup.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002   filegroup.cpp  -  description
00003   -------------------
00004 begin                : Sat May 10 2003
00005 copyright            : (C) 2003 by Tim Sutton
00006 email                : t.sutton@reading.ac.uk
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "omgclimatefilegroup.h"
00019 
00020 OmgClimateFileGroup::OmgClimateFileGroup() : QObject()
00021 {
00022   mElementCount=0;
00023   mXDim=0;
00024   mYDim=0;
00025   mEndOfMatrixFlag=false;
00026 }
00027 
00028 OmgClimateFileGroup::~OmgClimateFileGroup()
00029 {
00030 }
00031 void OmgClimateFileGroup::close()
00032 {
00033   QVectorIterator<OmgClimateFileReader *> myIterater(mReaderVector);
00034   while (myIterater.hasNext()) 
00035   {
00036     OmgClimateFileReader * myReader = myIterater.next() ;
00037     delete myReader;
00038   }
00039   mReaderVector.clear();
00040 }
00041 bool OmgClimateFileGroup::add(OmgClimateFileReader* theReader)
00042 {
00043   if (!theReader)
00044   {
00045       emit error (QString("OmgClimateFileGroup::addOmgClimateFileReader() error - theReader is uninitialised!"));
00046       return false;
00047   }
00048 
00049   //expand the filereader vector by one and insert the new filereader
00050   //onto the end of the list
00051   mReaderVector.push_back(theReader);
00052   int mySizeInt = mReaderVector.count();
00053   //see if this was the first filereader being added and if so set the
00054   //mElementCount property.
00055   if (mySizeInt==1)
00056   {
00057     mElementCount=theReader->xDim() * theReader->yDim();
00058     mXDim=theReader->xDim();
00059     mYDim=theReader->yDim();
00060     qDebug("First reader in group has properties: x %ld , y %ld",theReader->xDim(),theReader->yDim());
00061   }
00062   return true;
00063 }
00064 
00065 int OmgClimateFileGroup::elementCount()
00066 {
00067   return mElementCount;
00068 }
00069 
00070 int OmgClimateFileGroup::fileCount()
00071 {
00072   return mReaderVector.count();
00073 }
00074  
00075 
00076 QVector<float> OmgClimateFileGroup::getElementVector()
00077 {
00078   QVector<float> myFloatVector;
00079   if (mReaderVector.isEmpty())
00080   {
00081     emit (QString("Error, the file group is empty, how can I get an element when there are no files?"));
00082     return myFloatVector;
00083   }
00084   
00085   //test that there are some files in our filereader group
00086   if (0==mReaderVector.count())
00087   {
00088     emit (QString("Error, the file group is empty, how can I get an element when there are no files?"));
00089     return myFloatVector;
00090   }
00091   //test we are not at the end of the matrix
00092   if (true==mEndOfMatrixFlag)
00093   {
00094     emit (QString("Error, the file group is at the end of the matrix. Use rewind before trying to read from it again!"));
00095     return myFloatVector;
00096   }
00097   //retrieve the each OmgClimateFileReader from the colelction and get its current element
00098   bool myFirstFlag=true;
00099   QVectorIterator<OmgClimateFileReader *> myIterater(mReaderVector);
00100   while (myIterater.hasNext()) 
00101   {
00102     OmgClimateFileReader * myReader = myIterater.next() ;
00103     float myFloat = myReader->getElement();
00104     //test if we are at the end of the matrix
00105     if ( myFirstFlag==true)
00106     {
00107       mEndOfMatrixFlag=myReader->isAtMatrixEnd();
00108       myFirstFlag=false;
00109     }
00110     myFloatVector.push_back(myFloat);
00111   }
00112 
00113   return myFloatVector;
00114 }
00115 
00116 const bool OmgClimateFileGroup::isAtMatrixEnd()
00117 {
00118   return mEndOfMatrixFlag;
00119 }
00120 
00121 bool OmgClimateFileGroup::rewind()
00122 {
00123   if (0==mReaderVector.count())
00124   {
00125     return false;
00126   }
00127   QVectorIterator<OmgClimateFileReader *> myIterater(mReaderVector);
00128   while (myIterater.hasNext()) 
00129   {
00130     OmgClimateFileReader * myReader = myIterater.next() ;
00131     myReader->setActiveBlock(0);
00132   }
00133   mEndOfMatrixFlag=false;
00134   //add better error checking
00135   return true;
00136 }
00137 

Generated on Mon Apr 28 15:08:11 2008 for openModellerDesktop by  doxygen 1.4.1-20050210