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

omgclimatedataprocessorcontroller.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002   climatedataprocessor.cpp  -  description
00003   -------------------
00004 begin                : Thu May 15 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 "omgclimatedataprocessorcontroller.h"
00019 #include "omgclimatedataprocessor.h"
00020 #include "omgfilewriter.h"
00021 #include "omgclimatefilereader.h"
00022 #include "omgclimatefilegroup.h"
00023 #include <iostream>
00024 //QT Includes
00025 #include <QTextStream>
00026 #include <QMessageBox> //this must go!
00027 #include <QDir>
00028 #include <QRegExp>
00029 #include <QVector>
00030 
00031 const float NO_DATA=-9999.0;
00032 
00033 OmgClimateDataProcessorController::OmgClimateDataProcessorController() : QObject()
00034 {
00035 
00036     // initialise the fileGroup file names  - not strictly needed but neater
00037     QString myString=QString("");
00038     meanTempFileName=myString;
00039     minTempFileName=myString;
00040     maxTempFileName=myString;
00041     diurnalTempFileName=myString;
00042     meanPrecipFileName=myString;
00043     frostDaysFileName=myString;
00044     totalSolarRadFileName=myString;
00045     windSpeedFileName=myString;
00046 
00047     outputFilePath = myString;
00048     inputFileType=OmgClimateFileReader::GDAL;
00049 
00050 
00051 }
00052 
00054 OmgClimateDataProcessorController::~OmgClimateDataProcessorController()
00055 {}
00056 
00057 
00058 const QString OmgClimateDataProcessorController::getOutputHeader()
00059 {
00060     return outputHeader;
00061 }
00062 
00063 void OmgClimateDataProcessorController::setOutputHeader( const QString& theOutputHeader)
00064 {
00065     outputHeader = theOutputHeader;
00066 }
00067 
00068 bool OmgClimateDataProcessorController::makeInputFileTypeMap()
00069 {
00070     QString myString;
00071     OmgClimateFileReader::FileType myFileType;
00072     inputFileTypeMap.clear();
00073     // Copied from OmgClimateFileReader header file:
00074     //enum FileType { GDAL, HADLEY_SRES , HADLEY_IS92 ,  IPCC_OBSERVED ,
00075     //                                    VALDES ,  ECHAM4 ,  CSIRO_MK2 ,  NCAR_CSM_PCM , GFDL_R30 , CGCM2 ,
00076     //                                    CCSR_AGCM_OGCM };
00077 
00078 
00079     //declare the key value
00080     myString=QString("GDAL Supported Raster");
00081     //convert it to toUpper case
00082     myString=myString.toUpper();
00083     //set its associated enum
00084     myFileType=OmgClimateFileReader::GDAL;
00085     //add it to the associative array
00086     inputFileTypeMap[myString]=myFileType;
00087 
00088     //declare the key value
00089     myString=QString("Hadley Centre HadCM3 SRES Scenario");
00090     //convert it to toUpper case
00091     myString=myString.toUpper();
00092     //set its associated enum
00093     myFileType=OmgClimateFileReader::HADLEY_SRES;
00094     //add it to the associative array
00095     inputFileTypeMap[myString]=myFileType;
00096 
00097     //declare the key value
00098     myString=QString("Hadley Centre HadCM3 IS92a Scenario");
00099     //convert it to toUpper case
00100     myString=myString.toUpper();
00101     //set its associated enum
00102     myFileType=OmgClimateFileReader::HADLEY_IS92;
00103     //add it to the associative array
00104     inputFileTypeMap[myString]=myFileType;
00105 
00106     //declare the key value
00107     myString=QString("IPCC Observed Climatology");
00108     //convert it to toUpper case
00109     myString=myString.toUpper();
00110     //set its associated enum
00111     myFileType=OmgClimateFileReader::IPCC_OBSERVED;
00112     //add it to the associative array
00113     inputFileTypeMap[myString]=myFileType;
00114 
00115     //declare the key value
00116     myString=QString("University of Reading Palaeoclimate data");
00117     //convert it to toUpper case
00118     myString=myString.toUpper();
00119     //set its associated enum
00120     myFileType=OmgClimateFileReader::VALDES;
00121     //add it to the associative array
00122     inputFileTypeMap[myString]=myFileType;
00123 
00124     //declare the key value
00125     myString=QString("Max Planck Institute fur Meteorologie (MPIfM) ECHAM4 data");
00126     //convert it to toUpper case
00127     myString=myString.toUpper();
00128     //set its associated enum
00129     myFileType=OmgClimateFileReader::ECHAM4;
00130     //add it to the associative array
00131     inputFileTypeMap[myString]=myFileType;
00132 
00133     //declare the key value
00134     myString=QString("CSIRO-Mk2 Model data");
00135     //convert it to toUpper case
00136     myString=myString.toUpper();
00137     //set its associated enum
00138     myFileType=OmgClimateFileReader::CSIRO_MK2;
00139     //add it to the associative array
00140     inputFileTypeMap[myString]=myFileType;
00141 
00142     //declare the key value
00143     myString=QString("National Center for Atmospheric Research (NCAR) NCAR-CSM and NCAR-PCM data");
00144     //convert it to toUpper case
00145     myString=myString.toUpper();
00146     //set its associated enum
00147     myFileType=OmgClimateFileReader::NCAR_CSM_PCM;
00148     //add it to the associative array
00149     inputFileTypeMap[myString]=myFileType;
00150 
00151     //declare the key value
00152     myString=QString("Geophysical Fluid Dynamics Laboratory (GFDL) R30 Model data");
00153     //convert it to toUpper case
00154     myString=myString.toUpper();
00155     //set its associated enum
00156     myFileType=OmgClimateFileReader::GFDL_R30;
00157     //add it to the associative array
00158     inputFileTypeMap[myString]=myFileType;
00159 
00160     //declare the key value
00161     myString=QString("Canadian Center for Climate Modelling and Analysis (CCCma) CGCM2 Model data");
00162     //convert it to toUpper case
00163     myString=myString.toUpper();
00164     //set its associated enum
00165     myFileType=OmgClimateFileReader::CGCM2;
00166     //add it to the associative array
00167     inputFileTypeMap[myString]=myFileType;
00168 
00169     //declare the key value
00170     myString=QString("CCSR/NIES AGCM model data and CCSR OGCM model data");
00171     //convert it to toUpper case
00172     myString=myString.toUpper();
00173     //set its associated enum
00174     myFileType=OmgClimateFileReader::CCSR_AGCM_OGCM;
00175     //add it to the associative array
00176     inputFileTypeMap[myString]=myFileType;
00177 
00178     return true;
00179 }
00180 
00181 bool OmgClimateDataProcessorController::makeOutputFileTypeMap()
00182 {
00183     QString myString;
00184     OmgFileWriter::FileType myFileType;
00185     outputFileTypeMap.clear();
00186     // Copied from OmgFileWriter header file:
00187     //enum FileFormatEnum { GDAL_TIFF, CSM_MATLAB , CSM_OCTAVE ,  GARP ,  ESRI_ASCII ,  PLAIN };
00188 
00189     //declare the key value
00190     myString=QString("GDAL Tiff Image");
00191     //convert it to toUpper case
00192     myString=myString.toUpper();
00193     //set its associated enum
00194     myFileType=OmgFileWriter::ESRI_ASCII;
00195     //add it to the associative array
00196     outputFileTypeMap[myString]=myFileType;
00197 
00198     //declare the key value
00199     myString=QString("Matlab");
00200     //convert it to toUpper case
00201     myString=myString.toUpper();
00202     //set its associated enum
00203     myFileType=OmgFileWriter::MATLAB;
00204     //add it to the associative array
00205     outputFileTypeMap[myString]=myFileType;
00206 
00207     //declare the key value
00208     myString=QString("ESRI ASCII Grid");
00209     //convert it to toUpper case
00210     myString=myString.toUpper();
00211     //set its associated enum
00212     myFileType=OmgFileWriter::ESRI_ASCII;
00213     //add it to the associative array
00214     outputFileTypeMap[myString]=myFileType;
00215 
00216     //declare the key value
00217     myString=QString("Plain matrix with no header");
00218     //convert it to toUpper case
00219     myString=myString.toUpper();
00220     //set its associated enum
00221     myFileType=OmgFileWriter::PLAIN;
00222     //add it to the associative array
00223     outputFileTypeMap[myString]=myFileType;
00224     return true;
00225 }
00226 
00227 const QString  OmgClimateDataProcessorController::getMeanTempFileName()
00228 {
00229     return meanTempFileName;
00230 }
00231 
00232 void OmgClimateDataProcessorController::setMeanTempFileName( QString theFileName)
00233 {
00234     meanTempFileName = theFileName;
00235     qDebug( "meanTempFileName set to : " + meanTempFileName.toLocal8Bit() );
00236 }
00237 
00238 const QString  OmgClimateDataProcessorController::getMinTempFileName()
00239 {
00240     return minTempFileName;
00241 }
00242 
00243 void OmgClimateDataProcessorController::setMinTempFileName( QString theFileName)
00244 {
00245     minTempFileName = theFileName;
00246     qDebug( "minTempFileName set to : " + minTempFileName.toLocal8Bit() );
00247 }
00248 
00249 const QString  OmgClimateDataProcessorController::getMaxTempFileName()
00250 {
00251     return maxTempFileName;
00252 }
00253 
00254 void OmgClimateDataProcessorController::setMaxTempFileName( QString theFileName)
00255 {
00256     maxTempFileName = theFileName;
00257     qDebug( "maxTempFileName set to : " + maxTempFileName.toLocal8Bit() );
00258 }
00259 
00260 const QString  OmgClimateDataProcessorController::getDiurnalTempFileName()
00261 {
00262     return diurnalTempFileName;
00263 }
00264 
00265 void OmgClimateDataProcessorController::setDiurnalTempFileName( QString theFileName)
00266 {
00267     diurnalTempFileName = theFileName;
00268     qDebug( "diurnalTempFileName set to : " + diurnalTempFileName.toLocal8Bit() );
00269 }
00270 
00271 const QString  OmgClimateDataProcessorController::getMeanPrecipFileName()
00272 {
00273     return meanPrecipFileName;
00274 }
00275 
00276 void OmgClimateDataProcessorController::setMeanPrecipFileName( QString theFileName)
00277 {
00278     meanPrecipFileName = theFileName;
00279     qDebug( "meanPrecipFileName set to : " + meanPrecipFileName.toLocal8Bit() );
00280 }
00281 
00282 const QString  OmgClimateDataProcessorController::getFrostDaysFileName()
00283 {
00284 
00285     qDebug( "frostDaysFileName set to : " + frostDaysFileName.toLocal8Bit() );
00286     return frostDaysFileName;
00287 }
00288 
00289 void OmgClimateDataProcessorController::setFrostDaysFileName( QString theFileName)
00290 {
00291     frostDaysFileName = theFileName;
00292     qDebug( "frostDaysFileName set to : " + frostDaysFileName.toLocal8Bit() );
00293 }
00294 
00295 const QString  OmgClimateDataProcessorController::getTotalSolarRadFileName()
00296 {
00297     return totalSolarRadFileName;
00298 }
00299 
00300 void OmgClimateDataProcessorController::setTotalSolarRadFileName( QString theFileName)
00301 {
00302     totalSolarRadFileName = theFileName;
00303 
00304     qDebug( "totalSolarRadFileName set to : " + totalSolarRadFileName.toLocal8Bit() );
00305 }
00306 
00307 const QString  OmgClimateDataProcessorController::getWindSpeedFileName()
00308 {
00309     return windSpeedFileName;
00310 }
00311 
00312 void OmgClimateDataProcessorController::setWindSpeedFileName( QString theFileName)
00313 {
00314     windSpeedFileName = theFileName;
00315     qDebug( "windSpeedFileName set to : " + windSpeedFileName.toLocal8Bit() );
00316 }
00317 
00318 const QString  OmgClimateDataProcessorController::getOutputFilePathString()
00319 {
00320     return outputFilePath;
00321 }
00322 
00323 void OmgClimateDataProcessorController::setOutputFilePathString( QString theFilePathString)
00324 {
00325     outputFilePath = theFilePathString;
00326     qDebug( "outputFilePath set to : " + outputFilePath.toLocal8Bit() );
00327 }
00328 
00329 bool OmgClimateDataProcessorController::makeFileGroups()
00330 {
00331 
00332     /*   These are the possible filegroups available:
00333          -----------------------------------------------------------------
00334          meanTempFileGroup;
00335          minTempFileGroup;
00336          maxTempFileGroup;
00337          diurnalTempFileGroup;
00338          meanPrecipFileGroup;
00339          frostDaysFileGroup;
00340          totalSolarRadFileGroup;
00341          windSpeedFileGroup;
00342          -----------------------------------------------------------------
00343          */
00344     const int START_YEAR=1; //this will be deprecated soon!
00345     if (meanTempFileName==QString(""))
00346     {
00347         qDebug(     "makeFileGroups - meanTempFileName is NOT initialised! *****************************" );
00348     }
00349     else
00350     {
00351         meanTempFileGroup = initialiseFileGroup(meanTempFileName,START_YEAR);
00352     }
00353 
00354     if (minTempFileName==QString(""))
00355     {
00356         qDebug(     "makeFileGroups - minTempFileName is NOT initialised! *****************************" );
00357     }
00358     else
00359     {
00360         minTempFileGroup = initialiseFileGroup(minTempFileName,START_YEAR);
00361     }
00362 
00363     if (maxTempFileName==QString(""))
00364     {
00365         qDebug(     "makeFileGroups - maxTempFileName is NOT initialised! *****************************" );
00366     }
00367     else
00368     {
00369         maxTempFileGroup = initialiseFileGroup(maxTempFileName,START_YEAR);
00370     }
00371 
00372     if (diurnalTempFileName==QString(""))
00373     {
00374         qDebug(     "makeFileGroups - diurnalTempFileName is NOT initialised! *****************************" );
00375     }
00376     else
00377     {
00378         diurnalTempFileGroup = initialiseFileGroup(diurnalTempFileName,START_YEAR);
00379     }
00380 
00381     if (meanPrecipFileName==QString(""))
00382     {
00383         qDebug(     "makeFileGroups - meanPrecipFileName is NOT initialised! *****************************" );
00384     }
00385     else
00386     {
00387         meanPrecipFileGroup = initialiseFileGroup(meanPrecipFileName,START_YEAR);
00388     }
00389 
00390     if (meanPrecipFileName==QString(""))
00391     {
00392         qDebug(     "makeFileGroups - meanPrecipFileName is NOT initialised! *****************************" );
00393     }
00394     else
00395     {
00396         meanPrecipFileGroup = initialiseFileGroup(meanPrecipFileName,START_YEAR);
00397     }
00398 
00399 
00400     if (frostDaysFileName==QString(""))
00401     {
00402         qDebug(     "makeFileGroups - frostDaysFileName is NOT initialised! *****************************" );
00403     }
00404     else
00405     {
00406         frostDaysFileGroup = initialiseFileGroup(frostDaysFileName,START_YEAR);
00407     }
00408 
00409 
00410     if (totalSolarRadFileName==QString(""))
00411     {
00412         qDebug( "makeFileGroups - totalSolarRadFileName is NOT initialised! *****************************" );
00413     }
00414     else
00415     {
00416         totalSolarRadFileGroup = initialiseFileGroup(totalSolarRadFileName,START_YEAR);
00417     }
00418 
00419 
00420     if (windSpeedFileName==QString(""))
00421     {
00422         qDebug( "makeFileGroups - totalSolarRadFileName is NOT initialised! *****************************" );
00423     }
00424     else
00425     {
00426         windSpeedFileGroup = initialiseFileGroup(windSpeedFileName,START_YEAR);
00427     }
00428     return true;
00429 }
00430 /*   Construct a filegroup given a base file name.
00431  *   @param theStartYear Used when processing data NOT in series to shift the
00432  *           internal file pointer to the correct year. Note this is a base 1 number.
00433  *           Default is 1.
00434  */
00435 OmgClimateFileGroup *OmgClimateDataProcessorController::initialiseFileGroup(QString theFileName,int theStartYear=1)
00436 {
00437     OmgClimateFileGroup * myFileGroup = new OmgClimateFileGroup();
00438     qDebug( "initialiseFileGroup - theFileName is initialised to : " + theFileName.toLocal8Bit() );
00439     if (filesInSeriesFlag)
00440     {
00441         //we have a separate file for each months data - the
00442         //assumption we make then is that the user selected the first file
00443         //e.g. file_00.asc and that the remaining files are numbered sequentially
00444         qDebug( "initialiseFileGroup - files in series!" );
00445         //create a file group from this file
00446         qDebug( "initialiseFileGroup - theFileName = " + theFileName.toLocal8Bit() );
00447         //need to add some error handling here...
00448 
00449        QFileInfo myFileInfo(theFileName);
00450        QString myPath = myFileInfo.dir().path();
00451        QString myExtension = myFileInfo.completeSuffix(); //include all dotted extensions e.g. tar.gz
00452        QString myFileName = myFileInfo.baseName();//exclude all dotted extentsions e.g. will return 'file' from 'file.tar.gz'
00454        QString myFileNameBase = myFileName.left(myFileName.length()-2);//e.g. 'somefile00' becomes 'somefile'
00455 
00456         for (int myInt=1; myInt < 13; myInt++)
00457         {
00458             QString myCurrentFileName = myPath+QDir::separator()+myFileNameBase;
00459 
00460             if (myInt < 10)
00461             {
00462                 myCurrentFileName+=QString("0")+QString::number(myInt);
00463             }
00464             else
00465             {
00466                 myCurrentFileName+=QString::number(myInt);
00467             }
00468             myCurrentFileName+="."+myExtension;
00469             qDebug( "initialiseFileGroup - opening file : " + myCurrentFileName.toLocal8Bit() );
00470             OmgClimateFileReader *myOmgClimateFileReader = new OmgClimateFileReader();
00471             myOmgClimateFileReader->initialise(myCurrentFileName,inputFileType);            
00472             qDebug( "initialiseFileGroup - *** Adding " + myCurrentFileName.toLocal8Bit()
00473             + " to file group *********************" );
00474             myFileGroup->add(myOmgClimateFileReader);
00475 
00476         }
00477 
00478         return myFileGroup;
00479 
00480     }//end of first part of file in series flag test
00481     else
00482     {
00483         //the file is not in series this consists of a single file with
00484         //multiple datablocks - one for each period (day / month / year etc)
00485         qDebug( "initialiseFileGroup - files NOT in series!" );
00486         qDebug( "initialiseFileGroup - theFileName = " + theFileName.toLocal8Bit() );
00487         //need to add some error handling here...
00488         //calculate the actual blocks numbers represented by the start & end years
00489         unsigned int myCurrentBlockInt = ((theStartYear-1)*12)+1;
00490         unsigned int myEndBlockInt = (12*theStartYear)+1;
00491 
00492         printf ("ClimatteDataProcessor::initialiseFileGroup Calculated start block : %i and end block is %i\n",
00493                 myCurrentBlockInt,
00494                 myEndBlockInt
00495                );
00496 
00497         //now we loop through 12 blocks to create our filegroup
00498         //this is the loop that sets up file readers - one per data
00499         //block for the required year, for the current month.
00500         for (unsigned int myInt=myCurrentBlockInt; myInt < myEndBlockInt; ++myInt)
00501         {
00502             OmgClimateFileReader *myOmgClimateFileReader = new OmgClimateFileReader();
00503             myOmgClimateFileReader->initialise(theFileName,inputFileType);            
00504             myOmgClimateFileReader->setActiveBlock(myInt);
00505             myFileGroup->add(myOmgClimateFileReader);
00506             qDebug( "Adding block " + QString::number(myInt).toLocal8Bit() + " to the block list to be processed" );
00507         }
00508 
00509         //ownership of the filereader pointer is transferred to the file group
00510 
00511         return myFileGroup;
00512     } //end of second part of files in series flag test
00513 
00514 }
00515 
00516 
00518 const OmgClimateFileReader::FileType OmgClimateDataProcessorController::getInputFileType()
00519 {
00520     return inputFileType;
00521 }
00523 void OmgClimateDataProcessorController::setInputFileType( const OmgClimateFileReader::FileType theInputFileType)
00524 {
00525     inputFileType = theInputFileType;
00526 }
00527 
00529 void OmgClimateDataProcessorController::setInputFileType( const QString theInputFileTypeString)
00530 {
00531 
00532 
00533     QString myString = theInputFileTypeString;
00534     OmgClimateFileReader::FileType myInputFileType;
00535     //make sure the fileTypeMap exists
00536     makeInputFileTypeMap();
00537     //convert the input string to ucase
00538     myString=myString.toUpper();
00539     //look up the filetype enum given the string
00540     myInputFileType = inputFileTypeMap[myString];
00541     //set the filetype given the enum
00542     setInputFileType (myInputFileType);
00543 
00544 }
00545 
00546 
00548 const OmgFileWriter::FileType OmgClimateDataProcessorController::getOutputFileType()
00549 {
00550     return outputFileType;
00551 }
00553 void OmgClimateDataProcessorController::setOutputFileType( const OmgFileWriter::FileType theOutputFileType)
00554 {
00555     outputFileType = theOutputFileType;
00556 }
00557 
00559 void OmgClimateDataProcessorController::setOutputFileType( const QString theOutputFileTypeString)
00560 {
00561 
00562 
00563     QString myString = theOutputFileTypeString;
00564     OmgFileWriter::FileType myOutputFileType;
00565     //make sure the fileTypeMap exists
00566     makeOutputFileTypeMap();
00567     //convert the Output string to ucase
00568     myString=myString.toUpper();
00569     //look up the filetype enum given the string
00570     myOutputFileType = outputFileTypeMap[myString];
00571     //set the filetype given the enum
00572     setOutputFileType (myOutputFileType);
00573 
00574 }
00575 
00581 bool  OmgClimateDataProcessorController::makeAvailableCalculationsMap()
00582 {
00583 #ifdef QGISDEBUG
00584     qDebug( "OmgClimateDataProcessorController::makeAvailableCalculationsMap() called!" );
00585 #endif
00586 
00587     QString myString;
00588     bool myBool=false;  //default is not to perform any eligible  calculation
00589     availableCalculationsMap.clear();
00590     /*   These are the possible filegroups available:
00591          -----------------------------------------------------------------
00592          meanTempFileName;
00593          minTempFileName;
00594          maxTempFileName;
00595          diurnalTempFileName;
00596          meanPrecipFileName;
00597          frostDaysFileName;
00598          totalSolarRadFileName;
00599          windSpeedFileName;
00600          -----------------------------------------------------------------
00601          */
00602     qDebug( "Mean Temp FileName : " +  getMeanTempFileName().toLocal8Bit() );
00603     qDebug( "Max Temp FileName : " + getMaxTempFileName().toLocal8Bit() );
00604     qDebug( "Min Temp FileName : " + getMinTempFileName().toLocal8Bit() );
00605     qDebug( "Diurnal Temp FileName : " + getDiurnalTempFileName().toLocal8Bit() );
00606     qDebug( "Mean Precipitation FileName : " + getMeanPrecipFileName().toLocal8Bit() );
00607     qDebug( "Frost Days FileName : " + getFrostDaysFileName().toLocal8Bit() );
00608     qDebug( "Total Solar Radiation FileName : " + getTotalSolarRadFileName().toLocal8Bit() );
00609     qDebug( "Wind Speed FileName : " + getWindSpeedFileName().toLocal8Bit() );
00610 
00611     if (diurnalTempFileName != "")
00612     {
00613         //declare the key value
00614         myString=QString("Annual mean diurnal temperature range");
00615         //add it to the associative array
00616         availableCalculationsMap[myString]=myBool;
00617     }
00618 
00619     if (frostDaysFileName != "")
00620     {
00621         //declare the key value
00622         myString=QString("Annual mean number of frost days");
00623         //add it to the associative array
00624         availableCalculationsMap[myString]=myBool;
00625     }
00626 
00627     if (totalSolarRadFileName != "")
00628     {
00629         qDebug( "Solar incident radiation : " +    totalSolarRadFileName.toLocal8Bit() );
00630         //declare the key value
00631         myString=QString("Annual mean total incident solar radiation");
00632         //add it to the associative array
00633         availableCalculationsMap[myString]=myBool;
00634     }
00635 
00636     if (maxTempFileGroup && minTempFileName  != "" && maxTempFileName != "" )
00637     {
00638         //declare the key value
00639         myString=QString("Annual temperature range");
00640         //add it to the associative array
00641         availableCalculationsMap[myString]=myBool;
00642     }
00643 
00644     if (maxTempFileName != "")
00645     {
00646         //declare the key value
00647         myString=QString("Highest temperature in warmest month");
00648         //add it to the associative array
00649         availableCalculationsMap[myString]=myBool;
00650     }
00651 
00652     if (minTempFileName != "")
00653     {
00654         //declare the key value
00655         myString=QString("Lowest temperature in coolest month");
00656         //add it to the associative array
00657         availableCalculationsMap[myString]=myBool;
00658     }
00659     if (meanPrecipFileName != "")
00660     {
00661         //declare the key value
00662         myString=QString("Mean daily precipitation");
00663         //add it to the associative array
00664         availableCalculationsMap[myString]=myBool;
00665     }
00666     if (meanPrecipFileName != "" && meanTempFileName != "" )
00667     {
00668         //declare the key value
00669         myString=QString("Mean daily precipitation in coolest month");
00670         //add it to the associative array
00671         availableCalculationsMap[myString]=myBool;
00672     }
00673     if (meanPrecipFileName != "" && meanTempFileName != "" )
00674     {
00675         //declare the key value
00676         myString=QString("Mean daily precipitation in coolest quarter");
00677         //add it to the associative array
00678         availableCalculationsMap[myString]=myBool;
00679     }
00680     if (meanPrecipFileName != "" )
00681     {
00682         //declare the key value
00683         myString=QString("Mean daily precipitation in driest month");
00684         //add it to the associative array
00685         availableCalculationsMap[myString]=myBool;
00686     }
00687     if (meanPrecipFileName != "" )
00688     {
00689         //declare the key value
00690         myString=QString("Mean daily precipitation in driest quarter");
00691         //add it to the associative array
00692         availableCalculationsMap[myString]=myBool;
00693     }
00694     if (meanPrecipFileName != ""  &&  meanTempFileName != ""  )
00695     {
00696         //declare the key value
00697         myString=QString("Mean daily precipitation in warmest month");
00698         //add it to the associative array
00699         availableCalculationsMap[myString]=myBool;
00700     }
00701     if (meanPrecipFileName != ""  && meanTempFileName != ""  )
00702     {
00703         //declare the key value
00704         myString=QString("Mean daily precipitation in warmest quarter");
00705         //add it to the associative array
00706         availableCalculationsMap[myString]=myBool;
00707     }
00708     if (meanPrecipFileName != ""  )
00709     {
00710         //declare the key value
00711         myString=QString("Mean daily precipitation in wettest month");
00712         //add it to the associative array
00713         availableCalculationsMap[myString]=myBool;
00714     }
00715     if (meanPrecipFileName != ""  )
00716     {
00717         //declare the key value
00718         myString=QString("Mean daily precipitation in wettest quarter");
00719         //add it to the associative array
00720         availableCalculationsMap[myString]=myBool;
00721     }
00722     if (diurnalTempFileName != "" && meanTempFileName !="")
00723     {
00724         //declare the key value
00725         myString=QString("Mean diurnal temperature range in coolest month");
00726         //add it to the associative array
00727         availableCalculationsMap[myString]=myBool;
00728     }
00729     if ( diurnalTempFileName != "" && meanTempFileName !="")
00730     {
00731         //declare the key value
00732         myString=QString("Mean diurnal temperature range in warmest month");
00733         //add it to the associative array
00734         availableCalculationsMap[myString]=myBool;
00735     }
00736     if (  meanPrecipFileName != ""  &&  frostDaysFileName != "")
00737     {
00738         //declare the key value
00739         myString=QString("Mean precipitation in frost free months");
00740         //add it to the associative array
00741         availableCalculationsMap[myString]=myBool;
00742     }
00743     if ( meanTempFileName !="")
00744     {
00745         //declare the key value
00746         myString=QString("Mean temperature");
00747         //add it to the associative array
00748         availableCalculationsMap[myString]=myBool;
00749     }
00750     if (meanTempFileName !="")
00751     {
00752         //declare the key value
00753         myString=QString("Mean temperature in coolest month");
00754         //add it to the associative array
00755         availableCalculationsMap[myString]=myBool;
00756     }
00757     if ( meanTempFileName !="")
00758     {
00759         //declare the key value
00760         myString=QString("Mean temperature in coolest quarter");
00761         //add it to the associative array
00762         availableCalculationsMap[myString]=myBool;
00763     }
00764     if ( meanTempFileName !="" &&  frostDaysFileName != "")
00765     {
00766         //declare the key value
00767         myString=QString("Mean temperature in frost free months");
00768         //add it to the associative array
00769         availableCalculationsMap[myString]=myBool;
00770     }
00771     if ( meanTempFileName !="")
00772     {
00773         //declare the key value
00774         myString=QString("Mean temperature in warmest month");
00775         //add it to the associative array
00776         availableCalculationsMap[myString]=myBool;
00777     }
00778     if ( meanTempFileName !="")
00779     {
00780         //declare the key value
00781         myString=QString("Mean temperature in warmest quarter");
00782         //add it to the associative array
00783         availableCalculationsMap[myString]=myBool;
00784     }
00785     if ( windSpeedFileName != "")
00786     {
00787         //declare the key value
00788         myString=QString("Mean wind speed");
00789         //add it to the associative array
00790         availableCalculationsMap[myString]=myBool;
00791     }
00792     if ( minTempFileName !="")
00793     {
00794         //declare the key value
00795         myString=QString("Number of months with minimum temperature above freezing");
00796         //add it to the associative array
00797         availableCalculationsMap[myString]=myBool;
00798     }
00799     if ( totalSolarRadFileName != "" && meanTempFileName !="")
00800     {
00801         //declare the key value
00802         myString=QString("Radiation in coolest month");
00803         //add it to the associative array
00804         availableCalculationsMap[myString]=myBool;
00805     }
00806     if ( totalSolarRadFileName != ""  && meanTempFileName !="")
00807     {
00808         //declare the key value
00809         myString=QString("Radiation in coolest quarter");
00810         //add it to the associative array
00811         availableCalculationsMap[myString]=myBool;
00812     }
00813     if ( totalSolarRadFileName != "" && meanPrecipFileName != "")
00814     {
00815         //declare the key value
00816         myString=QString("Radiation in driest month");
00817         //add it to the associative array
00818         availableCalculationsMap[myString]=myBool;
00819     }
00820     if (totalSolarRadFileName != "" && meanPrecipFileName != "")
00821     {
00822         //declare the key value
00823         myString=QString("Radiation in driest quarter");
00824         //add it to the associative array
00825         availableCalculationsMap[myString]=myBool;
00826     }
00827     if ( totalSolarRadFileName != ""  && meanTempFileName != "")
00828     {
00829         //declare the key value
00830         myString=QString("Radiation in warmest month");
00831         //add it to the associative array
00832         availableCalculationsMap[myString]=myBool;
00833     }
00834     if ( totalSolarRadFileName != ""  && meanTempFileName != "")
00835     {
00836         //declare the key value
00837         myString=QString("Radiation in warmest quarter");
00838         //add it to the associative array
00839         availableCalculationsMap[myString]=myBool;
00840     }
00841     if ( totalSolarRadFileName != "" && meanPrecipFileName != "")
00842     {
00843         //declare the key value
00844         myString=QString("Radiation in wettest month");
00845         //add it to the associative array
00846         availableCalculationsMap[myString]=myBool;
00847     }
00848     if ( totalSolarRadFileName != ""  && meanPrecipFileName != "")
00849     {
00850         //declare the key value
00851         myString=QString("Radiation in wettest quarter");
00852         //add it to the associative array
00853         availableCalculationsMap[myString]=myBool;
00854     }
00855     if ( meanPrecipFileName != "")
00856     {
00857         //declare the key value
00858         myString=QString("Standard deviation of mean precipitation");
00859         //add it to the associative array
00860         availableCalculationsMap[myString]=myBool;
00861     }
00862     if (meanTempFileName != "")
00863     {
00864         //declare the key value
00865         myString=QString("Standard deviation of mean temperature");
00866         //add it to the associative array
00867         availableCalculationsMap[myString]=myBool;
00868     }
00869 
00870     //presume all went ok - need to add better error checking later
00871     return true;
00872 } //end of makeAvailableCalculationsMap
00873 
00875 QMap <QString, bool > OmgClimateDataProcessorController::getAvailableCalculationsMap()
00876 {
00877 
00878     return  availableCalculationsMap;
00879 
00880 }
00881 
00882 bool OmgClimateDataProcessorController::addUserCalculation(QString theCalculationName)
00883 {
00884     QMap<QString, bool>::iterator myMapIterator = availableCalculationsMap.begin();
00885     myMapIterator = availableCalculationsMap.find(theCalculationName);
00886 
00887     if (myMapIterator != availableCalculationsMap.end())
00888     {
00889         myMapIterator.value()=true;
00890         //presume all went ok - need to add better error checking later
00891         return true;
00892     }
00893     else
00894     {
00895         return false;
00896     }
00897 }
00898 
00899 
00900 
00901 
00902 
00904 const bool OmgClimateDataProcessorController::getFilesInSeriesFlag()
00905 {
00906     return filesInSeriesFlag;
00907 }
00909 void OmgClimateDataProcessorController::setFilesInSeriesFlag( const bool theFlag)
00910 {
00911     filesInSeriesFlag = theFlag;
00912 }
00913 
00916 bool OmgClimateDataProcessorController::run()
00917 {
00918   qDebug( "OmgClimateDataProcessorController run() method called.\n " );
00919   qDebug( "Go and have a cup of tea cause this may take a while!" );
00920   qDebug( "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" );
00921 
00922   //create a data processor to do the low level processing
00923   OmgClimateDataProcessor myDataProcessor;
00924   //work out how many variables we are going to calculate
00925   int myNumberOfVariablesInt = 0;
00926   QMap<QString, bool>::const_iterator myIter;
00927   for (myIter=availableCalculationsMap.begin(); myIter != availableCalculationsMap.end(); myIter++)
00928   {
00929     if (myIter.value()) //true
00930     {
00931       myNumberOfVariablesInt++;
00932     }
00933   }
00934   //
00935   //work out how many cells need to be processed for each calculations
00936   //
00937   int myNumberOfCells =0;
00938   int myXDimInt= 0;
00939   int myYDimInt=0;
00940   if (meanTempFileGroup)
00941   {
00942     myNumberOfCells = meanTempFileGroup->elementCount();
00943     myXDimInt=meanTempFileGroup->xDim();
00944     myYDimInt=meanTempFileGroup->yDim();
00945   }
00946   else if (minTempFileGroup)
00947   {
00948     myNumberOfCells = minTempFileGroup->elementCount();
00949     myXDimInt=minTempFileGroup->xDim();
00950     myYDimInt=minTempFileGroup->yDim();
00951   }
00952   else if (maxTempFileGroup)
00953   {
00954     myNumberOfCells = maxTempFileGroup->elementCount();
00955     myXDimInt=maxTempFileGroup->xDim();
00956     myYDimInt=maxTempFileGroup->yDim();
00957   }
00958   else if (diurnalTempFileGroup)
00959   {
00960     myNumberOfCells = diurnalTempFileGroup->elementCount();
00961     myXDimInt=diurnalTempFileGroup->xDim();
00962     myYDimInt=diurnalTempFileGroup->yDim();
00963   }
00964   else if (meanPrecipFileGroup)
00965   {
00966     myNumberOfCells = meanPrecipFileGroup->elementCount();
00967     myXDimInt=meanPrecipFileGroup->xDim();
00968     myYDimInt=meanPrecipFileGroup->yDim();
00969   }
00970   else if (frostDaysFileGroup)
00971   {
00972     myNumberOfCells = frostDaysFileGroup->elementCount();
00973     myXDimInt=frostDaysFileGroup->xDim();
00974     myYDimInt=frostDaysFileGroup->yDim();
00975   }
00976   else if (totalSolarRadFileGroup)
00977   {
00978     myNumberOfCells = totalSolarRadFileGroup->elementCount();
00979     myXDimInt=totalSolarRadFileGroup->xDim();
00980     myYDimInt=totalSolarRadFileGroup->yDim();
00981   }
00982   else if (windSpeedFileGroup)
00983   {
00984     myNumberOfCells = windSpeedFileGroup->elementCount();
00985     myXDimInt=windSpeedFileGroup->xDim();
00986     myYDimInt=windSpeedFileGroup->yDim();
00987   }
00988   //check nothing fishy is going on
00989   if (myNumberOfCells ==  0)
00990   {
00991     return false;
00992   }
00993 
00994 
00995   //send singals so progress monitors can set themselves up
00996   emit numberOfCellsToCalc(myNumberOfCells);
00997   emit numberOfVariablesToCalc(myNumberOfVariablesInt);
00998 
00999 
01000   //create a filewriter map for storing the OUTPUTS of each selected user calculation
01001   //this is not very element - I put the filewriter pointer into a struct and then  put the struct in to the
01002   //map, because I cant seem to be able to put the pointer directly into the map itself :-(
01003   QMap<QString, OmgFileWriterStruct> myOmgFileWriterMap;
01004 
01005   for (myIter=availableCalculationsMap.begin(); myIter != availableCalculationsMap.end(); myIter++)
01006   {
01007     if (myIter.value()) //true
01008     {
01009       qDebug( "Adding " +  myIter.key().toLocal8Bit() + " to myOmgFileWriterMap\n");
01010       //create the fileWriter object
01011       //note I am not using pointer & the 'new' keyword here
01012       //because map doesnt let me add a pointer to the list
01013 
01014       QString myFileName = myIter.key();
01015 
01016       //replace any spaces with underscores in the name
01017       myFileName = myFileName.replace( QRegExp(" "), "_");
01018       //set the extension
01019       myFileName =  outputFilePath + myFileName + ".asc";
01020       OmgFileWriter * myOmgFileWriter = new OmgFileWriter(myFileName,outputFileType);
01021 
01022       //Use externally defined header if its been set
01023       if (!outputHeader.isEmpty())
01024       {
01025         myOmgFileWriter->writeString(outputHeader);
01026       }
01027       //Otherwise calculate one dynamically
01028       else
01029       {
01030         // Use the matrix dimensions to create the ascii file
01031         // Warning: this assumes a GLOBAL dataset
01032         // Warning: this screws up cellsizes that are not square
01033         // Warning: this only works for integers at present
01034         QString myHeader=
01035             QString ("ncols         ") +
01036             QString::number (myXDimInt) + 
01037             QString ("\n")+
01038             QString ("nrows         ") + 
01039             QString::number (myYDimInt) + 
01040             QString ("\n")+
01041             QString ("xllcorner     -180\n")+
01042             QString ("yllcorner     -90\n")+
01043             QString ("cellsize      ") + 
01044             QString::number (360/static_cast<float>(myXDimInt)) +
01045             QString ("\n")+
01046             QString ("nodata_value  -9999.5\n");
01047         myOmgFileWriter->writeString(myHeader);
01048         // Formerly this was fixed to the following
01049         //QString myHeader=
01050         //QString ("ncols         720\n")+
01051         //QString ("nrows         360\n")+
01052         //QString ("xllcorner     -180\n")+
01053         //QString ("yllcorner     -90\n")+
01054         //QString ("cellsize      0.5\n")+
01055         //QString ("nodata_value  -9999\n");                    myOmgFileWriter->writeString(myHeader);
01056 
01057       }
01058 
01059       qDebug( "Added " + myOmgFileWriter->fileName().toLocal8Bit() );
01060       OmgFileWriterStruct myOmgFileWriterStruct;
01061       myOmgFileWriterStruct.fileWriter=myOmgFileWriter;
01062       myOmgFileWriterStruct.fullFileName=myFileName;
01063       //add it to the map
01064       myOmgFileWriterMap[myIter.key()]=myOmgFileWriterStruct;
01065       qDebug( "Added " + myOmgFileWriterStruct.fullFileName.toLocal8Bit() );
01066     }
01067   }
01068 
01069 
01070   // cycle through each FileGroup, fetching the element array from it and running any user
01071   // selected calculations, then writing the outputs to its associated filewriter in
01072   // myOmgFileWriterMap
01073 
01074 
01075   if (meanTempFileGroup && meanTempFileName !="" &&
01076           availableCalculationsMap["Mean temperature"])
01077   {
01078     emit variableStart("Mean temperature");
01079     qDebug( "OmgClimateDataProcessorController::run - Mean temperature requested" );
01080     //move to start of the current data matrix
01081     meanTempFileGroup->rewind();
01082 
01083     //get the struct containing the filewriter pointer and full file name from the writer map
01084     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Mean temperature"];
01085     //get the filewriter from out of the struct
01086     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
01087 
01088     int myXCountInt=0;
01089     bool myFirstIterationFlag=true;
01090     while (!meanTempFileGroup->isAtMatrixEnd())
01091     {
01092       QVector<float> myVector;
01093       //get the next element from the file group
01094       myVector = meanTempFileGroup->getElementVector();
01095       //we are using mean over year summary
01096       float myFloat = myDataProcessor.mean(myVector );
01097       if (myFirstIterationFlag || meanTempFileGroup->isAtMatrixEnd())
01098       {
01099         //this next bit is just for debugging purposes"
01100         printVectorAndResult(myVector,myFloat);
01101         myFirstIterationFlag=false;
01102       }
01103       //write the result to our output file
01104       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
01105       if (!myResultFlag)
01106       {
01107         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
01108         
01109         return false;
01110       }
01111       myXCountInt++;
01112       if (myXCountInt%myXDimInt==0)
01113       {
01114         myOmgFileWriter->writeString("\n");
01115       }
01117     }
01118     qDebug( " ++++++ Emitting variableDone signal! " );
01119     emit variableDone(myOmgFileWriterStruct.fullFileName);
01120 
01121   }
01122   if (diurnalTempFileGroup && diurnalTempFileName != "" &&
01123           availableCalculationsMap["Annual mean diurnal temperature range"])
01124   {
01125     emit variableStart("Annual mean diurnal temperature range");
01126     qDebug( "OmgClimateDataProcessorController::run Annual mean diurnal temperature range requested" );
01127     //move to start of the current data matrix
01128     diurnalTempFileGroup->rewind();
01129     //get the struct containing the filewriter pointer and full file name from the writer map
01130     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Annual mean diurnal temperature range"];
01131     //get the filewriter from out of the struct
01132     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
01133     int myXCountInt=0;
01134     while (!diurnalTempFileGroup->isAtMatrixEnd())
01135     {
01136       QVector<float> myVector;
01137       //get the next element from the file group
01138       myVector = diurnalTempFileGroup->getElementVector();
01139       //we are using mean over year summary
01140       float myFloat = myDataProcessor.mean(myVector );
01141       //write the result to our output file
01142       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
01143       if (!myResultFlag)
01144       {
01145         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
01146         
01147         return false;
01148       }
01149       myXCountInt++;
01150       if (myXCountInt%myXDimInt==0)
01151       {
01152         myOmgFileWriter->writeString("\n");
01153       }
01155     }
01156     emit variableDone(myOmgFileWriterStruct.fullFileName);
01157   }
01158 
01159   if (frostDaysFileGroup && frostDaysFileName != "" &&
01160           availableCalculationsMap["Annual mean number of frost days"])
01161   {
01162     emit variableStart("Annual mean number of frost days");
01163     qDebug( "OmgClimateDataProcessorController::run Annual mean number of frost days requested" );
01164     //move to start of the current data matrix
01165     frostDaysFileGroup->rewind();
01166     //get the struct containing the filewriter pointer and full file name from the writer map
01167     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Annual mean number of frost days"];
01168     //get the filewriter from out of the struct
01169     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
01170     int myXCountInt=0;
01171     while (!frostDaysFileGroup->isAtMatrixEnd())
01172     {
01173       QVector<float> myVector;
01174       //get the next element from the file group
01175       myVector = frostDaysFileGroup->getElementVector();
01176 
01177       //we are using mean over year summary
01178       float myFloat = myDataProcessor.mean(myVector );
01179       //write the result to our output file
01180       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
01181       if (!myResultFlag)
01182       {
01183         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
01184         
01185         return false;
01186       }
01187       myXCountInt++;
01188       if (myXCountInt%myXDimInt==0)
01189       {
01190         myOmgFileWriter->writeString("\n");
01191       }
01193     }
01194     emit variableDone(myOmgFileWriterStruct.fullFileName);
01195   }
01196 
01197   if (totalSolarRadFileGroup && totalSolarRadFileName != "" &&
01198           availableCalculationsMap["Annual mean total incident solar radiation"])
01199   {
01200     emit variableStart("Annual mean total incident solar radiation");
01201     qDebug( "OmgClimateDataProcessorController::run Annual mean total incident solar radiation requested" );
01202     //move to start of the current data matrix
01203     totalSolarRadFileGroup->rewind();
01204     //get the struct containing the filewriter pointer and full file name from the writer map
01205     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Annual mean total incident solar radiation"];
01206     //get the filewriter from out of the struct
01207     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
01208     int myXCountInt=0;
01209     while (!totalSolarRadFileGroup->isAtMatrixEnd())
01210     {
01211       QVector<float> myVector;
01212       //get the next element from the file group
01213       myVector = totalSolarRadFileGroup->getElementVector();
01214       //we are using mean over year summary
01215       float myFloat = myDataProcessor.mean(myVector );
01216       //write the result to our output file
01217       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
01218       if (!myResultFlag)
01219       {
01220         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
01221         
01222         return false;
01223       }
01224       myXCountInt++;
01225       if (myXCountInt%myXDimInt==0)
01226       {
01227         myOmgFileWriter->writeString("\n");
01228       }
01229       //emit cellDone( myFloat );
01230     }
01231     emit variableDone(myOmgFileWriterStruct.fullFileName);
01232   }
01233 
01234   if ( minTempFileGroup
01235           && maxTempFileGroup
01236           && minTempFileName != ""
01237           && maxTempFileName != ""
01238           && availableCalculationsMap["Annual temperature range"])
01239   {
01240 
01241     emit variableStart("Annual temperature range");
01242     qDebug( "OmgClimateDataProcessorController::run - Annual temperature range requested" );
01243     //move to start of the current data matrix
01244     minTempFileGroup->rewind();
01245     maxTempFileGroup->rewind();
01246     //get the struct containing the filewriter pointer and full file name from the writer map
01247     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Annual temperature range"];
01248     //get the filewriter from out of the struct
01249     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
01250     int myXCountInt=0;
01251     while (!minTempFileGroup->isAtMatrixEnd())
01252     {
01253       QVector<float> myVector, myVector2;
01254       //get the next element from the file group
01255       myVector = minTempFileGroup->getElementVector();
01256       myVector2 = maxTempFileGroup->getElementVector();
01257       //we are using mean over year summary
01258       float myFloat = myDataProcessor.greatestTotalRange(myVector,myVector2);
01259       //write the result to our output file
01260       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
01261       if (!myResultFlag)
01262       {
01263         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
01264         
01265         return false;
01266       }
01267       myXCountInt++;
01268       if (myXCountInt%myXDimInt==0)
01269       {
01270         myOmgFileWriter->writeString("\n");
01271       }
01272       //emit cellDone( myFloat );
01273     }
01274     emit variableDone(myOmgFileWriterStruct.fullFileName);
01275   }
01276 
01277   if (maxTempFileGroup
01278           && maxTempFileName != ""
01279           && availableCalculationsMap["Highest temperature in warmest month"])
01280   {
01281     emit variableStart("Highest temperature in warmest month");
01282     qDebug( "OmgClimateDataProcessorController::run - Highest temperature in warmest month requested" );
01283     maxTempFileGroup->rewind();
01284     //get the struct containing the filewriter pointer and full file name from the writer map
01285     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Highest temperature in warmest month"];
01286     //get the filewriter from out of the struct
01287     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
01288     int myXCountInt=0;
01289     while (!maxTempFileGroup->isAtMatrixEnd())
01290     {
01291       QVector<float> myVector;
01292       //get the next element from the file group
01293       myVector = maxTempFileGroup->getElementVector();
01294       //we are using mean over year summary
01295       float myFloat = myDataProcessor.highestValue(myVector);
01296       //write the result to our output file
01297       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
01298       if (!myResultFlag)
01299       {
01300         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
01301         
01302         return false;
01303       }
01304       myXCountInt++;
01305       if (myXCountInt%myXDimInt==0)
01306       {
01307         myOmgFileWriter->writeString("\n");
01308       }
01309       //emit cellDone( myFloat );
01310     }
01311     emit variableDone(myOmgFileWriterStruct.fullFileName);
01312   }
01313 
01314   if (minTempFileGroup
01315           && minTempFileName != ""
01316           && availableCalculationsMap["Lowest temperature in coolest month"])
01317   {
01318     emit variableStart("Lowest temperature in coolest month");
01319     qDebug( "OmgClimateDataProcessorController::run - Lowest temperature in coolest month requested" );
01320     minTempFileGroup->rewind();
01321     //get the struct containing the filewriter pointer and full file name from the writer map
01322     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Lowest temperature in coolest month"];
01323     //get the filewriter from out of the struct
01324     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
01325     int myXCountInt=0;
01326     while (!minTempFileGroup->isAtMatrixEnd())
01327     {
01328       QVector<float> myVector;
01329       //get the next element from the file group
01330       myVector = minTempFileGroup->getElementVector();
01331       //we are using mean over year summary
01332       float myFloat = myDataProcessor.lowestValue(myVector);
01333       //write the result to our output file
01334       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
01335       if (!myResultFlag)
01336       {
01337         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
01338         
01339         return false;
01340       }
01341       myXCountInt++;
01342       if (myXCountInt%myXDimInt==0)
01343       {
01344         myOmgFileWriter->writeString("\n");
01345       }
01346       //emit cellDone( myFloat );
01347     }
01348     emit variableDone(myOmgFileWriterStruct.fullFileName);
01349 
01350   }
01351   if (meanPrecipFileGroup
01352           && meanPrecipFileName != ""
01353           && availableCalculationsMap["Mean daily precipitation"])
01354   {
01355     emit variableStart("Mean daily precipitation");
01356     qDebug( "OmgClimateDataProcessorController::run Mean daily precipitation" );
01357     meanPrecipFileGroup->rewind();
01358     //get the struct containing the filewriter pointer and full file name from the writer map
01359     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Mean daily precipitation"];
01360     //get the filewriter from out of the struct
01361     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
01362     int myXCountInt=0;
01363     while (!meanPrecipFileGroup->isAtMatrixEnd())
01364     {
01365       QVector<float> myVector;
01366       //get the next element from the file group
01367       myVector = meanPrecipFileGroup->getElementVector();
01368       //we are using mean over year summary
01369       float myFloat = myDataProcessor.mean(myVector );
01370       //write the result to our output file
01371       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
01372       if (!myResultFlag)
01373       {
01374         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
01375         
01376         return false;
01377       }
01378       myXCountInt++;
01379       if (myXCountInt%myXDimInt==0)
01380       {
01381         myOmgFileWriter->writeString("\n");
01382       }
01383       //emit cellDone( myFloat );
01384     }
01385     emit variableDone(myOmgFileWriterStruct.fullFileName);
01386   }
01387   if ( meanPrecipFileGroup &&  minTempFileGroup
01388           && meanPrecipFileName != "" && meanTempFileName != ""
01389           && availableCalculationsMap["Mean daily precipitation in coolest month"])
01390   {
01391     emit variableStart("Mean daily precipitation in coolest month");
01392     qDebug( "OmgClimateDataProcessorController::run Mean daily precipitation in coolest month" );
01393     meanPrecipFileGroup->rewind();
01394     meanTempFileGroup->rewind();
01395     //get the struct containing the filewriter pointer and full file name from the writer map
01396     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Mean daily precipitation in coolest month"];
01397     //get the filewriter from out of the struct
01398     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
01399     int myXCountInt=0;
01400     while (!meanPrecipFileGroup->isAtMatrixEnd())
01401     {
01402       QVector<float> myVector,myVector2;
01403       //get the next element from the file group
01404       myVector = meanPrecipFileGroup->getElementVector();
01405       myVector2 = meanTempFileGroup->getElementVector();
01406       //we are using mean over year summary
01407       int myBlockInt = myDataProcessor.monthWithLowestValue(myVector2);
01408       float myFloat=NO_DATA;
01409       if (static_cast<int>(myBlockInt) != NO_DATA)
01410       {
01411           myFloat  = myDataProcessor.valueGivenMonth(myVector,myBlockInt);
01412       }
01413       //write the result to our output file
01414       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
01415       if (!myResultFlag)
01416       {
01417         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
01418         
01419         return false;
01420       }
01421       myXCountInt++;
01422       if (myXCountInt%myXDimInt==0)
01423       {
01424         myOmgFileWriter->writeString("\n");
01425       }
01426       //emit cellDone( myFloat );
01427     }
01428     emit variableDone(myOmgFileWriterStruct.fullFileName);
01429   }
01430   if (meanPrecipFileGroup &&  minTempFileGroup && meanPrecipFileName != ""
01431           && meanTempFileName != ""
01432           && availableCalculationsMap["Mean daily precipitation in coolest quarter"])
01433   {
01434     emit variableStart("Mean daily precipitation in coolest quarter");
01435     qDebug( "OmgClimateDataProcessorController::run Mean daily precipitation in coolest month" );
01436     meanPrecipFileGroup->rewind();
01437     meanTempFileGroup->rewind();
01438     //get the struct containing the filewriter pointer and full file name from the writer map
01439     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Mean daily precipitation in coolest quarter"];
01440     //get the filewriter from out of the struct
01441     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
01442     int myXCountInt=0;
01443     while (!meanPrecipFileGroup->isAtMatrixEnd())
01444     {
01445       QVector<float> myVector,myVector2;
01446       //get the next element from the file group
01447       myVector = meanPrecipFileGroup->getElementVector();
01448       myVector2 = meanTempFileGroup->getElementVector();
01449       //we are using mean over year summary
01450       int myBlockInt = myDataProcessor.firstMonthOfLowestQ(myVector2);
01451       float myFloat=NO_DATA;
01452       if (static_cast<int>(myBlockInt) != NO_DATA)
01453       {
01454          myFloat  = myDataProcessor.meanOverQuarter(myVector,myBlockInt);
01455       }
01456       //write the result to our output file
01457       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
01458       if (!myResultFlag)
01459       {
01460         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
01461         
01462         return false;
01463       }
01464       myXCountInt++;
01465       if (myXCountInt%myXDimInt==0)
01466       {
01467         myOmgFileWriter->writeString("\n");
01468       }
01469       //emit cellDone( myFloat );
01470     }
01471     emit variableDone(myOmgFileWriterStruct.fullFileName);
01472   }
01473   if (meanPrecipFileGroup &&  meanPrecipFileName != ""  &&
01474           availableCalculationsMap["Mean daily precipitation in driest month"])
01475   {
01476     emit variableStart("Mean daily precipitation in driest month");
01477     qDebug( "OmgClimateDataProcessorController::run Mean daily precipitation in driest month" );
01478     meanPrecipFileGroup->rewind();
01479     //get the struct containing the filewriter pointer and full file name from the writer map
01480     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Mean daily precipitation in driest month"];
01481     //get the filewriter from out of the struct
01482     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
01483     int myXCountInt=0;
01484     while (!meanPrecipFileGroup->isAtMatrixEnd())
01485     {
01486       QVector<float> myVector;
01487       //get the next element from the file group
01488       myVector = meanPrecipFileGroup->getElementVector();
01489       //we are using mean over year summary
01490       float myFloat = myDataProcessor.lowestValue(myVector );
01491       //write the result to our output file
01492       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
01493       if (!myResultFlag)
01494       {
01495         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
01496         
01497         return false;
01498       }
01499       myXCountInt++;
01500       if (myXCountInt%myXDimInt==0)
01501       {
01502         myOmgFileWriter->writeString("\n");
01503       }
01504       //emit cellDone( myFloat );
01505     }
01506     emit variableDone(myOmgFileWriterStruct.fullFileName);
01507   }
01508   if (meanPrecipFileGroup &&  meanPrecipFileName != ""  &&
01509           availableCalculationsMap["Mean daily precipitation in driest quarter"])
01510   {
01511     emit variableStart("Mean daily precipitation in driest quarter");
01512     qDebug( "OmgClimateDataProcessorController::run Mean daily precipitation in driest quarter" );
01513     meanPrecipFileGroup->rewind();
01514     //get the struct containing the filewriter pointer and full file name from the writer map
01515     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Mean daily precipitation in driest quarter"];
01516     //get the filewriter from out of the struct
01517     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
01518     int myXCountInt=0;
01519     while (!meanPrecipFileGroup->isAtMatrixEnd())
01520     {
01521       QVector<float> myVector;
01522       //get the next element from the file group
01523       myVector = meanPrecipFileGroup->getElementVector();
01524       //we are using mean over year summary
01525       float myFloat = myDataProcessor.meanOverLowestQ(myVector);
01526       //write the result to our output file
01527       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
01528       if (!myResultFlag)
01529       {
01530         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
01531         
01532         return false;
01533       }
01534       myXCountInt++;
01535       if (myXCountInt%myXDimInt==0)
01536       {
01537         myOmgFileWriter->writeString("\n");
01538       }
01539       //emit cellDone( myFloat );
01540     }
01541     emit variableDone(myOmgFileWriterStruct.fullFileName);
01542   }
01543   if (meanPrecipFileGroup &&  meanPrecipFileName != ""
01544           && meanTempFileGroup
01545           && meanTempFileName != ""
01546           && availableCalculationsMap["Mean daily precipitation in warmest month"])
01547   {
01548     emit variableStart("Mean daily precipitation in warmest month");
01549     qDebug( "OmgClimateDataProcessorController::run Mean daily precipitation in warmest month" );
01550     //move to the start of data blocks
01551     meanPrecipFileGroup->rewind();
01552     meanTempFileGroup->rewind();
01553     //get the struct containing the filewriter pointer and full file name from the writer map
01554     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Mean daily precipitation in warmest month"];
01555     //get the filewriter from out of the struct
01556     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
01557     int myXCountInt=0;
01558     while (!meanPrecipFileGroup->isAtMatrixEnd())
01559     {
01560       QVector<float> myVector,myVector2;
01561       //get the next element from the file group
01562       myVector = meanPrecipFileGroup->getElementVector();
01563       myVector2 = meanTempFileGroup->getElementVector();
01564       //we are using mean over year summary
01565       int myBlockInt = myDataProcessor.monthWithHighestValue(myVector2);
01566       float myFloat=NO_DATA;
01567       if (static_cast<int>(myBlockInt) != NO_DATA)
01568       {
01569         myFloat  = myDataProcessor.valueGivenMonth(myVector,myBlockInt);
01570       }
01571       //write the result to our output file
01572       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
01573       if (!myResultFlag)
01574       {
01575         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
01576         
01577         return false;
01578       }
01579       myXCountInt++;
01580       if (myXCountInt%myXDimInt==0)
01581       {
01582         myOmgFileWriter->writeString("\n");
01583       }
01584       //emit cellDone( myFloat );
01585     }
01586     emit variableDone(myOmgFileWriterStruct.fullFileName);
01587   }
01588   if (meanPrecipFileGroup &&  meanPrecipFileName != ""
01589           && meanTempFileGroup &&  meanTempFileName != ""
01590           &&availableCalculationsMap["Mean daily precipitation in warmest quarter"])
01591   {
01592     emit variableStart("Mean daily precipitation in warmest quarter");
01593     qDebug( "OmgClimateDataProcessorController::run Mean daily precipitation in warmest quarter" );
01594     meanPrecipFileGroup->rewind();
01595     meanTempFileGroup->rewind();
01596     //get the struct containing the filewriter pointer and full file name from the writer map
01597     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Mean daily precipitation in warmest quarter"];
01598     //get the filewriter from out of the struct
01599     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
01600     int myXCountInt=0;
01601     while (!meanPrecipFileGroup->isAtMatrixEnd())
01602     {
01603       QVector<float> myVector,myVector2;
01604       //get the next element from the file group
01605       myVector = meanPrecipFileGroup->getElementVector();
01606       myVector2 = meanTempFileGroup->getElementVector();
01607       //we are using mean over year summary
01608       int myCurrentBlockOfWarmestQuarterInt = myDataProcessor.firstMonthOfHighestQ(myVector2);
01609       float myFloat=NO_DATA;
01610       if (static_cast<int>(myCurrentBlockOfWarmestQuarterInt) != NO_DATA)
01611       {
01612         myFloat = myDataProcessor.meanOverQuarter(myVector,myCurrentBlockOfWarmestQuarterInt);
01613       }
01614       //write the result to our output file
01615       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
01616       if (!myResultFlag)
01617       {
01618         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
01619         
01620         return false;
01621       }
01622       myXCountInt++;
01623       if (myXCountInt%myXDimInt==0)
01624       {
01625         myOmgFileWriter->writeString("\n");
01626       }
01627       //emit cellDone( myFloat );
01628     }
01629     emit variableDone(myOmgFileWriterStruct.fullFileName);
01630   }
01631   if (meanPrecipFileGroup &&  meanPrecipFileName != ""   &&
01632           availableCalculationsMap["Mean daily precipitation in wettest month"])
01633   {
01634     emit variableStart("Mean daily precipitation in wettest month");
01635     qDebug( "OmgClimateDataProcessorController::run Mean daily precipitation in wettest month" );
01636     meanPrecipFileGroup->rewind();
01637     //get the struct containing the filewriter pointer and full file name from the writer map
01638     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Mean daily precipitation in wettest month"];
01639     //get the filewriter from out of the struct
01640     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
01641     int myXCountInt=0;
01642     while (!meanPrecipFileGroup->isAtMatrixEnd())
01643     {
01644       QVector<float> myVector;
01645       //get the next element from the file group
01646       myVector = meanPrecipFileGroup->getElementVector();
01647       //we are using mean over year summary
01648       float myFloat = myDataProcessor.highestValue(myVector );
01649       //write the result to our output file
01650       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
01651       if (!myResultFlag)
01652       {
01653         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
01654         
01655         return false;
01656       }
01657       myXCountInt++;
01658       if (myXCountInt%myXDimInt==0)
01659       {
01660         myOmgFileWriter->writeString("\n");
01661       }
01662       //emit cellDone( myFloat );
01663     }
01664     emit variableDone(myOmgFileWriterStruct.fullFileName);
01665   }
01666   if (meanPrecipFileGroup &&  meanPrecipFileName != ""   &&
01667           availableCalculationsMap["Mean daily precipitation in wettest quarter"])
01668   {
01669     emit variableStart("Mean daily precipitation in wettest quarter");
01670     qDebug( "OmgClimateDataProcessorController::run Mean daily precipitation in wettest quarter" );
01671     meanPrecipFileGroup->rewind();
01672     //get the struct containing the filewriter pointer and full file name from the writer map
01673     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Mean daily precipitation in wettest quarter"];
01674     //get the filewriter from out of the struct
01675     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
01676     int myXCountInt=0;
01677     while (!meanPrecipFileGroup->isAtMatrixEnd())
01678     {
01679       QVector<float > myVector;
01680       //get the next element from the file group
01681       myVector = meanPrecipFileGroup->getElementVector();
01682       //we are using mean over year summary
01683       float myFloat = myDataProcessor.meanOverHighestQ(myVector);
01684       //write the result to our output file
01685       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
01686       if (!myResultFlag)
01687       {
01688         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
01689         
01690         return false;
01691       }
01692       myXCountInt++;
01693       if (myXCountInt%myXDimInt==0)
01694       {
01695         myOmgFileWriter->writeString("\n");
01696       }
01697       //emit cellDone( myFloat );
01698     }
01699     emit variableDone(myOmgFileWriterStruct.fullFileName);
01700   }
01701   if (diurnalTempFileGroup && diurnalTempFileName != ""
01702           && meanTempFileGroup
01703           && meanTempFileName !=""
01704           && availableCalculationsMap["Mean diurnal temperature range in coolest month"])
01705   {
01706     emit variableStart("Mean diurnal temperature range in coolest month");
01707     qDebug( "OmgClimateDataProcessorController::run Mean diurnal temperature range in coolest month" );
01708     diurnalTempFileGroup->rewind();
01709     meanTempFileGroup->rewind();
01710     //get the struct containing the filewriter pointer and full file name from the writer map
01711     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Mean diurnal temperature range in coolest month"];
01712     //get the filewriter from out of the struct
01713     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
01714     int myXCountInt=0;
01715     while (!diurnalTempFileGroup->isAtMatrixEnd())
01716     {
01717       QVector<float> myVector,myVector2;
01718       //get the next element from the file group
01719       myVector = diurnalTempFileGroup->getElementVector();
01720       myVector2 = meanTempFileGroup->getElementVector();
01721       //we are using mean over year summary
01722       int myCoolestBlockInt = myDataProcessor.monthWithLowestValue(myVector2);
01723       float myFloat=NO_DATA;
01724       if (static_cast<int>(myCoolestBlockInt) != NO_DATA)
01725       {
01726         myFloat = myDataProcessor.valueGivenMonth(myVector,myCoolestBlockInt);
01727       }
01728       //write the result to our output file
01729       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
01730       if (!myResultFlag)
01731       {
01732         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
01733         
01734         return false;
01735       }
01736       myXCountInt++;
01737       if (myXCountInt%myXDimInt==0)
01738       {
01739         myOmgFileWriter->writeString("\n");
01740       }
01741       //emit cellDone( myFloat );
01742     }
01743     emit variableDone(myOmgFileWriterStruct.fullFileName);
01744   }
01745   if (diurnalTempFileGroup && diurnalTempFileName != "" && meanTempFileGroup
01746           && meanTempFileName !=""
01747           && availableCalculationsMap["Mean diurnal temperature range in warmest month"])
01748   {
01749     emit variableStart("Mean diurnal temperature range in warmest month");
01750     qDebug( "OmgClimateDataProcessorController::run Mean diurnal temperature range in warmest month" );
01751     diurnalTempFileGroup->rewind();
01752     meanTempFileGroup->rewind();
01753     //get the struct containing the filewriter pointer and full file name from the writer map
01754     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Mean diurnal temperature range in warmest month"];
01755     //get the filewriter from out of the struct
01756     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
01757     int myXCountInt=0;
01758     while (!diurnalTempFileGroup->isAtMatrixEnd())
01759     {
01760       QVector<float> myVector,myVector2;
01761       //get the next element from the file group
01762       myVector = diurnalTempFileGroup->getElementVector();
01763       myVector2 = meanTempFileGroup->getElementVector();
01764       //we are using mean over year summary
01765       int myCoolestBlockInt = myDataProcessor.monthWithHighestValue(myVector2);
01766       float myFloat=NO_DATA;
01767       if (static_cast<int>(myCoolestBlockInt) != NO_DATA)
01768       {
01769         myFloat = myDataProcessor.valueGivenMonth(myVector,myCoolestBlockInt);
01770       }
01771       //write the result to our output file
01772       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
01773       if (!myResultFlag)
01774       {
01775         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
01776         
01777         return false;
01778       }
01779       myXCountInt++;
01780       if (myXCountInt%myXDimInt==0)
01781       {
01782         myOmgFileWriter->writeString("\n");
01783       }
01784       //emit cellDone( myFloat );
01785     }
01786     emit variableDone(myOmgFileWriterStruct.fullFileName);
01787   }
01788   if (meanPrecipFileGroup &&  meanPrecipFileName != ""  && frostDaysFileGroup
01789           && frostDaysFileName != ""
01790           && availableCalculationsMap["Mean precipitation in frost free months"])
01791   {
01792     emit variableStart("Mean precipitation in frost free months");
01793     qDebug( "OmgClimateDataProcessorController::run Mean precipitation in frost free months" );
01794     meanPrecipFileGroup->rewind();
01795     frostDaysFileGroup->rewind();
01796     //get the struct containing the filewriter pointer and full file name from the writer map
01797     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Mean precipitation in frost free months"];
01798     //get the filewriter from out of the struct
01799     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
01800     int myXCountInt=0;
01801     while (!meanPrecipFileGroup->isAtMatrixEnd())
01802     {
01803       QVector<float> myVector,myVector2;
01804       //get the next element from the file group
01805       myVector = meanPrecipFileGroup->getElementVector();
01806       myVector2 = frostDaysFileGroup->getElementVector();
01807       //we are using mean over year summary
01808       float myFloat = myDataProcessor.meanValueOverFrostFreeMonths(myVector2, myVector);
01809       //write the result to our output file
01810       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
01811       if (!myResultFlag)
01812       {
01813         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
01814         
01815         return false;
01816       }
01817       myXCountInt++;
01818       if (myXCountInt%myXDimInt==0)
01819       {
01820         myOmgFileWriter->writeString("\n");
01821       }
01822       //emit cellDone( myFloat );
01823     }
01824     emit variableDone(myOmgFileWriterStruct.fullFileName);
01825   }
01826 
01827   if (meanTempFileGroup && meanTempFileName !="" &&
01828           availableCalculationsMap["Mean temperature in coolest month"])
01829   {
01830     emit variableStart("Mean temperature in coolest month");
01831     qDebug( "OmgClimateDataProcessorController::run Mean temperature in coolest month" );
01832 
01833     meanTempFileGroup->rewind();
01834     //get the struct containing the filewriter pointer and full file name from the writer map
01835     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Mean temperature in coolest month"];
01836     //get the filewriter from out of the struct
01837     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
01838     int myXCountInt=0;
01839     while (!meanTempFileGroup->isAtMatrixEnd())
01840     {
01841       QVector<float> myVector,myVector2;
01842       //get the next element from the file group
01843       myVector = meanTempFileGroup->getElementVector();
01844       //we are using mean over year summary
01845       float myFloat = myDataProcessor.lowestValue(myVector );
01846       //write the result to our output file
01847       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
01848       if (!myResultFlag)
01849       {
01850         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
01851         
01852         return false;
01853       }
01854       myXCountInt++;
01855       if (myXCountInt%myXDimInt==0)
01856       {
01857         myOmgFileWriter->writeString("\n");
01858       }
01859       //emit cellDone( myFloat );
01860     }
01861     emit variableDone(myOmgFileWriterStruct.fullFileName);
01862   }
01863   if (meanTempFileGroup && meanTempFileName !="" &&
01864           availableCalculationsMap["Mean temperature in coolest quarter"])
01865   {
01866     emit variableStart("Mean temperature in coolest quarter");
01867     qDebug( "OmgClimateDataProcessorController::run Mean temperature in coolest quarter" );
01868     meanTempFileGroup->rewind();
01869     //get the struct containing the filewriter pointer and full file name from the writer map
01870     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Mean temperature in coolest quarter"];
01871     //get the filewriter from out of the struct
01872     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
01873     int myXCountInt=0;
01874     while (!meanTempFileGroup->isAtMatrixEnd())
01875     {
01876       QVector<float> myVector,myVector2;
01877       //get the next element from the file group
01878       myVector = meanTempFileGroup->getElementVector();
01879       //we are using mean over year summary
01880       float myFloat = myDataProcessor.meanOverLowestQ(myVector);
01881       //write the result to our output file
01882       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
01883       if (!myResultFlag)
01884       {
01885         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
01886         
01887         return false;
01888       }
01889       myXCountInt++;
01890       if (myXCountInt%myXDimInt==0)
01891       {
01892         myOmgFileWriter->writeString("\n");
01893       }
01894       //emit cellDone( myFloat );
01895     }
01896     emit variableDone(myOmgFileWriterStruct.fullFileName);
01897   }
01898   if (meanTempFileGroup && meanTempFileName !="" && frostDaysFileGroup
01899           && frostDaysFileName != ""
01900           && availableCalculationsMap["Mean temperature in frost free months"])
01901   {
01902     emit variableStart("Mean temperature in frost free months");
01903     qDebug( "OmgClimateDataProcessorController::run Mean temperature in frost free months" );
01904     meanTempFileGroup->rewind();
01905     frostDaysFileGroup->rewind();
01906     //get the struct containing the filewriter pointer and full file name from the writer map
01907     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Mean temperature in frost free months"];
01908     //get the filewriter from out of the struct
01909     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
01910     int myXCountInt=0;
01911     while (!meanTempFileGroup->isAtMatrixEnd())
01912     {
01913       QVector<float> myVector,myVector2;
01914       //get the next element from the file group
01915       myVector = meanTempFileGroup->getElementVector();
01916       myVector2 = frostDaysFileGroup->getElementVector();
01917       //we are using mean over year summary
01918       float myFloat = myDataProcessor.meanValueOverFrostFreeMonths(myVector2, myVector);
01919       //write the result to our output file
01920       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
01921       if (!myResultFlag)
01922       {
01923         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
01924         
01925         return false;
01926       }
01927       myXCountInt++;
01928       if (myXCountInt%myXDimInt==0)
01929       {
01930         myOmgFileWriter->writeString("\n");
01931       }
01932       //emit cellDone( myFloat );
01933     }
01934     emit variableDone(myOmgFileWriterStruct.fullFileName);
01935   }
01936   if (meanTempFileGroup && meanTempFileName !="" &&
01937           availableCalculationsMap["Mean temperature in warmest month"])
01938   {
01939     emit variableStart("Mean temperature in warmest month");
01940     qDebug( "OmgClimateDataProcessorController::run Mean temperature in warmest month" );
01941     meanTempFileGroup->rewind();
01942     //get the struct containing the filewriter pointer and full file name from the writer map
01943     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Mean temperature in warmest month"];
01944     //get the filewriter from out of the struct
01945     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
01946     int myXCountInt=0;
01947     while (!meanTempFileGroup->isAtMatrixEnd())
01948     {
01949       QVector<float> myVector,myVector2;
01950       //get the next element from the file group
01951       myVector = meanTempFileGroup->getElementVector();
01952       //we are using mean over year summary
01953       float myFloat = myDataProcessor.highestValue(myVector );
01954       //write the result to our output file
01955       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
01956       if (!myResultFlag)
01957       {
01958         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
01959         
01960         return false;
01961       }
01962       myXCountInt++;
01963       if (myXCountInt%myXDimInt==0)
01964       {
01965         myOmgFileWriter->writeString("\n");
01966       }
01967       //emit cellDone( myFloat );
01968     }
01969     emit variableDone(myOmgFileWriterStruct.fullFileName);
01970   }
01971   if (meanTempFileGroup && meanTempFileName !="" &&
01972           availableCalculationsMap["Mean temperature in warmest quarter"])
01973   {
01974     emit variableStart("Mean temperature in warmest quarter");
01975     qDebug( "OmgClimateDataProcessorController::run Mean temperature in warmest quarter" );
01976     meanTempFileGroup->rewind();
01977     //get the struct containing the filewriter pointer and full file name from the writer map
01978     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Mean temperature in warmest quarter"];
01979     //get the filewriter from out of the struct
01980     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
01981     int myXCountInt=0;
01982     while (!meanTempFileGroup->isAtMatrixEnd())
01983     {
01984       QVector<float> myVector,myVector2;
01985       //get the next element from the file group
01986       myVector = meanTempFileGroup->getElementVector();
01987       //we are using mean over year summary
01988       float myFloat = myDataProcessor.meanOverHighestQ(myVector);
01989       //write the result to our output file
01990       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
01991       if (!myResultFlag)
01992       {
01993         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
01994         
01995         return false;
01996       }
01997       myXCountInt++;
01998       if (myXCountInt%myXDimInt==0)
01999       {
02000         myOmgFileWriter->writeString("\n");
02001       }
02002       //emit cellDone( myFloat );
02003     }
02004     emit variableDone(myOmgFileWriterStruct.fullFileName);
02005   }
02006   if (windSpeedFileGroup && windSpeedFileName != "" &&
02007           availableCalculationsMap["Mean wind speed"])
02008   {
02009     emit variableStart("Mean wind speed");
02010     qDebug( "OmgClimateDataProcessorController::run Mean wind speed" );
02011     windSpeedFileGroup->rewind();
02012     //get the struct containing the filewriter pointer and full file name from the writer map
02013     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Mean wind speed"];
02014     //get the filewriter from out of the struct
02015     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
02016     int myXCountInt=0;
02017     while (!windSpeedFileGroup->isAtMatrixEnd())
02018     {
02019       QVector<float> myVector;
02020       //get the next element from the file group
02021       myVector = windSpeedFileGroup->getElementVector();
02022       //we are using mean over year summary
02023       float myFloat = myDataProcessor.mean(myVector );
02024       //write the result to our output file
02025       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
02026       if (!myResultFlag)
02027       {
02028         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
02029         
02030         return false;
02031       }
02032       myXCountInt++;
02033       if (myXCountInt%myXDimInt==0)
02034       {
02035         myOmgFileWriter->writeString("\n");
02036       }
02037       //emit cellDone( myFloat );
02038     }
02039     emit variableDone(myOmgFileWriterStruct.fullFileName);
02040   }
02041   if (minTempFileGroup && minTempFileName !="" &&
02042           availableCalculationsMap["Number of months with minimum temperature above freezing"])
02043   {
02044     emit variableStart("Number of months with minimum temperature above freezing");
02045     qDebug( "OmgClimateDataProcessorController::run Number of months with minimum temperature above freezing" );
02046     minTempFileGroup->rewind();
02047     //get the struct containing the filewriter pointer and full file name from the writer map
02048     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Number of months with minimum temperature above freezing"];
02049     //get the filewriter from out of the struct
02050     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
02051     int myXCountInt=0;
02052     while (!minTempFileGroup->isAtMatrixEnd())
02053     {
02054       QVector<float> myVector;
02055       //get the next element from the file group
02056       myVector = minTempFileGroup->getElementVector();
02057       //we are using mean over year summary
02058       float myFloat = myDataProcessor.numberOfMonthsAboveZero(myVector );
02059       //write the result to our output file
02060       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
02061       if (!myResultFlag)
02062       {
02063         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
02064         
02065         return false;
02066       }
02067       myXCountInt++;
02068       if (myXCountInt%myXDimInt==0)
02069       {
02070         myOmgFileWriter->writeString("\n");
02071       }
02072       //emit cellDone( myFloat );
02073     }
02074     emit variableDone(myOmgFileWriterStruct.fullFileName);
02075   }
02076   if (totalSolarRadFileGroup && totalSolarRadFileName != ""
02077           && meanTempFileGroup && meanTempFileName !=""
02078           && availableCalculationsMap["Radiation in coolest month"])
02079   {
02080     emit variableStart("Radiation in coolest quarter");
02081     qDebug( "OmgClimateDataProcessorController::run Radiation in coolest month" );
02082     totalSolarRadFileGroup->rewind();
02083     meanTempFileGroup->rewind();
02084     //get the struct containing the filewriter pointer and full file name from the writer map
02085     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Radiation in coolest month"];
02086     //get the filewriter from out of the struct
02087     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
02088     int myXCountInt=0;
02089     while (!totalSolarRadFileGroup->isAtMatrixEnd())
02090     {
02091       QVector<float> myVector,myVector2;
02092       //get the next element from the file group
02093       myVector = totalSolarRadFileGroup->getElementVector();
02094       myVector2 = meanTempFileGroup->getElementVector();
02095       //we are using mean over year summary
02096       int myCoolestBlockInt = myDataProcessor.monthWithLowestValue(myVector2);
02097       float myFloat=NO_DATA;
02098       if (static_cast<int>(myCoolestBlockInt) != NO_DATA)
02099       {
02100         myFloat = myDataProcessor.valueGivenMonth(myVector,myCoolestBlockInt );
02101       }
02102       //write the result to our output file
02103       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
02104       if (!myResultFlag)
02105       {
02106         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
02107         
02108         return false;
02109       }
02110       myXCountInt++;
02111       if (myXCountInt%myXDimInt==0)
02112       {
02113         myOmgFileWriter->writeString("\n");
02114       }
02115       //emit cellDone( myFloat );
02116     }
02117     emit variableDone(myOmgFileWriterStruct.fullFileName);
02118   }
02119   if (totalSolarRadFileGroup && totalSolarRadFileName != ""
02120           && meanTempFileGroup && meanTempFileName !=""
02121           && availableCalculationsMap["Radiation in coolest quarter"])
02122   {
02123     emit variableStart("Radiation in coolest quarter");
02124     qDebug( "OmgClimateDataProcessorController::run Radiation in coolest quarter" );
02125     totalSolarRadFileGroup->rewind();
02126     meanTempFileGroup->rewind();
02127     //get the struct containing the filewriter pointer and full file name from the writer map
02128     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Radiation in coolest quarter"];
02129     //get the filewriter from out of the struct
02130     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
02131     int myXCountInt=0;
02132     while (!totalSolarRadFileGroup->isAtMatrixEnd())
02133     {
02134       QVector<float> myVector,myVector2;
02135       //get the next element from the file group
02136       myVector = totalSolarRadFileGroup->getElementVector();
02137       myVector2 = meanTempFileGroup->getElementVector();
02138       //we are using mean over year summary
02139       int myFirstBlockInt = myDataProcessor.firstMonthOfLowestQ(myVector2);
02140       float myFloat=NO_DATA;
02141       if (static_cast<int>(myFirstBlockInt) != NO_DATA)
02142       {
02143         myFloat = myDataProcessor.meanOverQuarter(myVector,myFirstBlockInt );
02144       }
02145       //write the result to our output file
02146       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
02147       if (!myResultFlag)
02148       {
02149         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
02150         
02151         return false;
02152       }
02153       myXCountInt++;
02154       if (myXCountInt%myXDimInt==0)
02155       {
02156         myOmgFileWriter->writeString("\n");
02157       }
02158       //emit cellDone( myFloat );
02159     }
02160     emit variableDone(myOmgFileWriterStruct.fullFileName);
02161   }
02162   if (totalSolarRadFileGroup && totalSolarRadFileName != ""
02163           && meanTempFileGroup && meanTempFileName != ""
02164           && availableCalculationsMap["Radiation in warmest month"])
02165   {
02166     emit variableStart("Radiation in warmest month");
02167     qDebug( "OmgClimateDataProcessorController::run Radiation in warmest month" );
02168     totalSolarRadFileGroup->rewind();
02169     meanTempFileGroup->rewind();
02170     //get the struct containing the filewriter pointer and full file name from the writer map
02171     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Radiation in warmest month"];
02172     //get the filewriter from out of the struct
02173     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
02174     int myXCountInt=0;
02175     while (!totalSolarRadFileGroup->isAtMatrixEnd())
02176     {
02177       QVector<float> myVector,myVector2;
02178       //get the next element from the file group
02179       myVector = totalSolarRadFileGroup->getElementVector();
02180       myVector2 = meanTempFileGroup->getElementVector();
02181       //we are using mean over year summary
02182       int myHighestBlockInt = myDataProcessor.monthWithHighestValue(myVector2);
02183       float myFloat=NO_DATA;
02184       if (static_cast<int>(myHighestBlockInt) != NO_DATA)
02185       {
02186         myFloat = myDataProcessor.valueGivenMonth(myVector,myHighestBlockInt );
02187       }
02188       //write the result to our output file
02189       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
02190       if (!myResultFlag)
02191       {
02192         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
02193         
02194         return false;
02195       }
02196       myXCountInt++;
02197       if (myXCountInt%myXDimInt==0)
02198       {
02199         myOmgFileWriter->writeString("\n");
02200       }
02201       //emit cellDone( myFloat );
02202     }
02203     emit variableDone(myOmgFileWriterStruct.fullFileName);
02204   }
02205   if (totalSolarRadFileGroup && totalSolarRadFileName != ""
02206           && meanTempFileGroup && meanTempFileName != ""
02207           && availableCalculationsMap["Radiation in warmest quarter"])
02208   {
02209     emit variableStart("Radiation in warmest quarter");
02210     qDebug( "OmgClimateDataProcessorController::run Radiation in warmest quarter" );
02211     totalSolarRadFileGroup->rewind();
02212     meanTempFileGroup->rewind();
02213     //get the struct containing the filewriter pointer and full file name from the writer map
02214     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Radiation in warmest quarter"];
02215     //get the filewriter from out of the struct
02216     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
02217     int myXCountInt=0;
02218     while (!totalSolarRadFileGroup->isAtMatrixEnd())
02219     {
02220 
02221       QVector<float> myVector,myVector2;
02222       //get the next element from the file group
02223       myVector = totalSolarRadFileGroup->getElementVector();
02224       myVector2 = meanTempFileGroup->getElementVector();
02225       //we are using mean over year summary
02226       int myFirstBlockInt = myDataProcessor.firstMonthOfHighestQ(myVector2);
02227       float myFloat=NO_DATA;
02228       if (static_cast<int>(myFirstBlockInt) != NO_DATA)
02229       {
02230         myFloat = myDataProcessor.meanOverQuarter(myVector,myFirstBlockInt );
02231       }
02232       //write the result to our output file
02233       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
02234       if (!myResultFlag)
02235       {
02236         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
02237         
02238         return false;
02239       }
02240       myXCountInt++;
02241       if (myXCountInt%myXDimInt==0)
02242       {
02243         myOmgFileWriter->writeString("\n");
02244       }
02245       //emit cellDone( myFloat );
02246     }
02247     emit variableDone(myOmgFileWriterStruct.fullFileName);
02248   }
02249   if (totalSolarRadFileGroup && totalSolarRadFileName != ""
02250           && meanPrecipFileGroup && meanPrecipFileName != ""
02251           && availableCalculationsMap["Radiation in driest month"])
02252   {
02253     emit variableStart("Radiation in driest month");
02254     qDebug( "OmgClimateDataProcessorController::run Radiation in driest month" );
02255     totalSolarRadFileGroup->rewind();
02256     meanPrecipFileGroup->rewind();
02257     //get the struct containing the filewriter pointer and full file name from the writer map
02258     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Radiation in driest month"];
02259     //get the filewriter from out of the struct
02260     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
02261     int myXCountInt=0;
02262     while (!totalSolarRadFileGroup->isAtMatrixEnd())
02263     {
02264       QVector<float> myVector,myVector2;
02265       //get the next element from the file group
02266       myVector = totalSolarRadFileGroup->getElementVector();
02267       myVector2 = meanPrecipFileGroup->getElementVector();
02268       //we are using mean over year summary
02269       int myDriestBlockInt = myDataProcessor.monthWithLowestValue(myVector2);
02270       float myFloat=NO_DATA;
02271       if (static_cast<int>(myDriestBlockInt) != NO_DATA)
02272       {
02273         myFloat = myDataProcessor.valueGivenMonth(myVector,myDriestBlockInt );
02274       }
02275       //write the result to our output file
02276       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
02277       if (!myResultFlag)
02278       {
02279         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
02280         
02281         return false;
02282       }
02283       myXCountInt++;
02284       if (myXCountInt%myXDimInt==0)
02285       {
02286         myOmgFileWriter->writeString("\n");
02287       }
02288       //emit cellDone( myFloat );
02289     }
02290     emit variableDone(myOmgFileWriterStruct.fullFileName);
02291   }
02292   if (totalSolarRadFileGroup && totalSolarRadFileName != ""
02293           && meanPrecipFileGroup && meanPrecipFileName != ""
02294           && availableCalculationsMap["Radiation in driest quarter"])
02295   {
02296     emit variableStart("Radiation in driest quarter");
02297     qDebug( "OmgClimateDataProcessorController::run Radiation in driest quarter" );
02298     totalSolarRadFileGroup->rewind();
02299     meanPrecipFileGroup->rewind();
02300     //get the struct containing the filewriter pointer and full file name from the writer map
02301     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Radiation in driest quarter"];
02302     //get the filewriter from out of the struct
02303     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
02304     int myXCountInt=0;
02305     while (!totalSolarRadFileGroup->isAtMatrixEnd())
02306     {
02307       QVector<float> myVector,myVector2;
02308       //get the next element from the file group
02309       myVector = totalSolarRadFileGroup->getElementVector();
02310       myVector2 = meanPrecipFileGroup->getElementVector();
02311       //we are using mean over year summary
02312       int myFirstBlockInt = myDataProcessor.firstMonthOfLowestQ(myVector2);
02313       float myFloat=NO_DATA;
02314       if (static_cast<int>(myFirstBlockInt) != NO_DATA)
02315       {
02316         myFloat = myDataProcessor.meanOverQuarter(myVector,myFirstBlockInt );
02317       }
02318       //write the result to our output file
02319       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
02320       if (!myResultFlag)
02321       {
02322         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
02323         
02324         return false;
02325       }
02326       myXCountInt++;
02327       if (myXCountInt%myXDimInt==0)
02328       {
02329         myOmgFileWriter->writeString("\n");
02330       }
02331       //emit cellDone( myFloat );
02332     }
02333     emit variableDone(myOmgFileWriterStruct.fullFileName);
02334   }
02335 
02336   if (totalSolarRadFileGroup && totalSolarRadFileName != ""
02337           && meanPrecipFileGroup && meanPrecipFileName != ""
02338           && availableCalculationsMap["Radiation in wettest month"])
02339   {
02340     emit variableStart("Radiation in wettest month");
02341     qDebug( "OmgClimateDataProcessorController::run Radiation in wettest month" );
02342     totalSolarRadFileGroup->rewind();
02343     meanPrecipFileGroup->rewind();
02344     //get the struct containing the filewriter pointer and full file name from the writer map
02345     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Radiation in wettest month"];
02346     //get the filewriter from out of the struct
02347     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
02348     int myXCountInt=0;
02349     while (!totalSolarRadFileGroup->isAtMatrixEnd())
02350     {
02351       QVector<float> myVector,myVector2;
02352       //get the next element from the file group
02353       myVector = totalSolarRadFileGroup->getElementVector();
02354       myVector2 = meanPrecipFileGroup->getElementVector();
02355       //we are using mean over year summary
02356       int myWettestBlockInt = myDataProcessor.monthWithHighestValue(myVector2);
02357       float myFloat=NO_DATA;
02358       if (static_cast<int>(myWettestBlockInt) != NO_DATA)
02359       {
02360         myFloat = myDataProcessor.valueGivenMonth(myVector,myWettestBlockInt );
02361       }
02362       //write the result to our output file
02363       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
02364       if (!myResultFlag)
02365       {
02366         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
02367         
02368         return false;
02369       }
02370       myXCountInt++;
02371       if (myXCountInt%myXDimInt==0)
02372       {
02373         myOmgFileWriter->writeString("\n");
02374       }
02375       //emit cellDone( myFloat );
02376     }
02377     emit variableDone(myOmgFileWriterStruct.fullFileName);
02378   }
02379   if (totalSolarRadFileGroup && totalSolarRadFileName != ""
02380           && meanPrecipFileGroup && meanPrecipFileName != ""
02381           && availableCalculationsMap["Radiation in wettest quarter"])
02382   {
02383     emit variableStart("Radiation in wettest quarter");
02384     qDebug( "OmgClimateDataProcessorController::run Radiation in wettest quarter" );
02385     totalSolarRadFileGroup->rewind();
02386     meanPrecipFileGroup->rewind();
02387     //get the struct containing the filewriter pointer and full file name from the writer map
02388     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Radiation in wettest quarter"];
02389     //get the filewriter from out of the struct
02390     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
02391     int myXCountInt=0;
02392     while (!totalSolarRadFileGroup->isAtMatrixEnd())
02393     {
02394       QVector<float> myVector,myVector2;
02395       //get the next element from the file group
02396       myVector = totalSolarRadFileGroup->getElementVector();
02397       myVector2 = meanPrecipFileGroup->getElementVector();
02398       //we are using mean over year summary
02399       int myFirstBlockInt = myDataProcessor.firstMonthOfHighestQ(myVector2);
02400       float myFloat=NO_DATA;
02401       if (static_cast<int>(myFirstBlockInt) != NO_DATA)
02402       {
02403         myFloat = myDataProcessor.meanOverQuarter(myVector,myFirstBlockInt );
02404       }
02405       //write the result to our output file
02406       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
02407       if (!myResultFlag)
02408       {
02409         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
02410         
02411         return false;
02412       }
02413       myXCountInt++;
02414       if (myXCountInt%myXDimInt==0)
02415       {
02416         myOmgFileWriter->writeString("\n");
02417       }
02418       //emit cellDone( myFloat );
02419     }
02420     emit variableDone(myOmgFileWriterStruct.fullFileName);
02421   }
02422   if (meanPrecipFileGroup && meanPrecipFileName != "" &&
02423           availableCalculationsMap["Standard deviation of mean precipitation"])
02424   {
02425     emit variableStart("Standard deviation of mean precipitation");
02426     qDebug( "OmgClimateDataProcessorController::run Standard deviation of mean precipitation" );
02427     meanPrecipFileGroup->rewind();
02428     //get the struct containing the filewriter pointer and full file name from the writer map
02429     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Standard deviation of mean precipitation"];
02430     //get the filewriter from out of the struct
02431     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
02432     int myXCountInt=0;
02433     while (!meanPrecipFileGroup->isAtMatrixEnd())
02434     {
02435       QVector<float> myVector;
02436       //get the next element from the file group
02437       myVector = meanPrecipFileGroup->getElementVector();
02438       //we are using mean over year summary
02439       float myFloat = myDataProcessor.stddevOverYear(myVector);
02440       //write the result to our output file
02441       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
02442       if (!myResultFlag)
02443       {
02444         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
02445         
02446         return false;
02447       }
02448       myXCountInt++;
02449       if (myXCountInt%myXDimInt==0)
02450       {
02451         myOmgFileWriter->writeString("\n");
02452       }
02453       //emit cellDone( myFloat );
02454     }
02455     emit variableDone(myOmgFileWriterStruct.fullFileName);
02456   }
02457   if (meanTempFileGroup && meanTempFileName != ""
02458           && availableCalculationsMap["Standard deviation of mean temperature"])
02459   {
02460     emit variableStart("Standard deviation of mean temperature");
02461     qDebug( "OmgClimateDataProcessorController::run Standard deviation of mean temperature" );
02462     meanTempFileGroup->rewind();
02463     //get the struct containing the filewriter pointer and full file name from the writer map
02464     OmgFileWriterStruct myOmgFileWriterStruct = myOmgFileWriterMap["Standard deviation of mean temperature"];
02465     //get the filewriter from out of the struct
02466     OmgFileWriter *myOmgFileWriter = myOmgFileWriterStruct.fileWriter;
02467     int myXCountInt=0;
02468     while (!meanTempFileGroup->isAtMatrixEnd())
02469     {
02470       QVector<float> myVector;
02471       //get the next element from the file group
02472       myVector = meanTempFileGroup->getElementVector();
02473       //we are using mean over year summary
02474       float myFloat = myDataProcessor.stddevOverYear(myVector);
02475       //write the result to our output file
02476       bool myResultFlag = myOmgFileWriter->writeElement( myFloat );
02477       if (!myResultFlag)
02478       {
02479         qDebug( "Error! Writing an element to " +  myOmgFileWriterStruct.fullFileName.toLocal8Bit() +  " failed " );
02480         
02481         return false;
02482       }
02483       myXCountInt++;
02484       if (myXCountInt%myXDimInt==0)
02485       {
02486         myOmgFileWriter->writeString("\n");
02487       }
02488       //emit cellDone( myFloat );
02489     }
02490     emit variableDone(myOmgFileWriterStruct.fullFileName);
02491   }
02492   return true;
02493 }
02494 
02495 void OmgClimateDataProcessorController::printVectorAndResult(QVector<float> theVector, float theResult)
02496 {
02497     int myVectorLengthInt=theVector.size();
02498     QString myString;
02499     for (int myInt = 0; myInt <= myVectorLengthInt-1; myInt++)
02500     {
02501 
02502         myString += QString::number(theVector[myInt]) + ",";
02503     }
02504     qDebug( myString.toLocal8Bit() + "\t : " + QString::number(theResult).toLocal8Bit() );
02505 }
02506 
02508 QString OmgClimateDataProcessorController::getDescription()
02509 {
02510     //must have an include for sstream.h!
02511 
02512     QString myString, myNumber;
02513     myString += "\n Climate Data Processor Description \n";
02514     myString += " ---------------------------------- \n";
02515 
02516 
02517     myNumber = QString::number(getInputFileType());
02518     myString += QString("Input File Type Enum : ") + myNumber+ QString("\n");
02519 
02520     myNumber = QString::number(getOutputFileType());
02521     myString += QString("Output File Type Enum : ") + myNumber + QString("\n");
02522 
02523 
02524     //these properties are just plain strings and dont need conversion
02525     myString += QString("Mean Temp FileName : ") + getMeanTempFileName() + QString("\n");
02526     myString += QString("Max Temp FileName : ") + getMaxTempFileName() + QString("\n");
02527     myString += QString("Min Temp FileName : ") + getMinTempFileName() + QString("\n");
02528     myString += QString("Diurnal Temp FileName : ") + getDiurnalTempFileName() + QString("\n");
02529     myString += QString("Mean Precipitation FileName : ") + getMeanPrecipFileName() + QString("\n");
02530     myString += QString("Frost Days FileName : ") + getFrostDaysFileName() + QString("\n");
02531     myString += QString("Total Solar Radiation FileName : ") + getTotalSolarRadFileName() + QString("\n");
02532     myString += QString("Wind Speed FileName : ") + getWindSpeedFileName() + QString("\n");
02533     if (filesInSeriesFlag)
02534     {
02535         myString += QString("Datafiles are a series of numbered files for each month \n");
02536     }
02537     else
02538     {
02539         myString += QString("Datafiles contain all monthly data in a single file \n");
02540     }
02541 
02542     //List the calculations in  availableCalculationsMap  using an iterator
02543     myString += QString("Listing items in availableCalculationsMap \n");
02544     myString += QString("Boolean value suffix indicates whether the user want to use this calculation \n");
02545     myString += QString("---------------------------------------------------------------------------------------------------- \n");
02546     QMap<QString, bool>::const_iterator myIter;
02547     for (myIter=availableCalculationsMap.begin(); myIter != availableCalculationsMap.end(); myIter++)
02548     {
02549         if (myIter.value())
02550         {
02551             myString += myIter.key() + QString(": true\n");
02552         }
02553         else
02554         {
02555             myString += myIter.key() + QString(": false\n");
02556         }
02557     }
02558     myString += QString("---------------------------------------------------------------------------------------------------- \n");
02559 
02560     return myString;
02561 
02562 }
02563 
02564 
02565 
02566 

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