ClassData (08/27/02)

CRHM

ClassData - observation file object.

 

class Classmacro;

class parser;

class __declspec(dllexport) ClassData {

public:

string DataFileName; // filename from dialogue control

string Description; // not used

float **Data; // memory allocated to hold observations. [obs, Line].  If NULL after instantiating a ClassData object it indicates that an error has occurred.

double *Times; // holds sparse times

double Dt1; // file start time (days)

double Dt2; // file end time (days)

long Lines; // # of lines of data (or intervals) in file - calculated from (Dt2 - Dt1)*Freq

long DataCnt; // total # of data items/line.

long MacroCnt; // # of new observations created by filters.

double Interval; // calculated from (Dt2 - Dt1) (days)

long Freq; // calculated from 1/Interval

long IndxMin; // range of data available referenced to base file.

long IndxMax; // range of data available referenced to base file.

long ModN; // divisor for data less frequent than basic interval.

Classmacro *myMacro; // Classmacro object to process this files filters.

bool Simulation; // Set when filter 'Sim' is used to synthesize observations.

ClassData(string DataFileName) : DataFileName(DataFileName), Data(NULL), myMacro(NULL), DataCnt(0), MacroCnt(0), Simulation(false), ModN(0), Times(NULL) {DataReadFile();};

virtual __fastcall ~ClassData();

void DataReadFile(void);

bool Execute(void) {return (Data); }

};

 

Member Functions.

Constructor.

    Creates a new object and calls DataReadFile()  to actually read observation file.

Destructor

    Deletes allocated storage for observation data and sparse times.

void DataReadFile(void);

  1. Error is thrown if datafile cannot be opened.
  2. The first line of the observation file is discarded.  It is assumed to be a user comment.
  3. The header lines are read and processed.  Characters in column 1 and 2 determines the command.
    1. '#' indicates the end of the header.  Ignore line and begin reading values.
    2. '$$' assume a comment and continue after ignoring the line.
    3. '$' and next character not '$' indicates a filter.  Processing is done by myMacro->addfilter.
    4. If not one of the above the line is assumed to be the definition of an observation variable.  If any filters have been defined before all observation variables are defined an error is thrown as this is illegal.  The variable is processed by declread().
  4. Time variables are next determined as follows:
    • If data from a data file
      1. The current position in the data file is saved, i.e. the first line of data.
      2. The time field is read and saved as Dt1.  If Global::DTstart is zero indicating the first observation file, it is set equal to Dt1.
      3. Read the time field of the next line and calculate the Interval and daily frequency (Freq).
      4. If Freq == 0, then the SparseFlag is set to TRUE and Freq = 1.
      5. Interval is recalculated as 1/Freq.
      6. IndxMin is set.
      7. Position to the beginning of the last line in the file.
      8. Read the time field and save as Dt2.  If Global::DTend is zero indicating the first observation file, it is set equal to Dt2.
      9. If current observation file has more data than the first observation file set Dt2 = Global::DTend.
      10. Calculate the number of data lines to be read.
      11. IndxMax is set.
      12. If daily data increment number of data lines by one.
      13. Reposition to the beginning of the data using the position saved in 1.
    • If synthesizing data using the simulation filter, the values above will have already been set by the filter object.
  5. Memory is allocated to hold the observation values
  6. A call is made to myMacro->fixup() to update pointer values.
  7. The cursor is changed to an hourglass. 
  8. The following code is contained in a 'try __finally' to return the cursor to normal when finished and a loop to read Lines lines.

    Only if data from a data file

    1. Read the time field
    2. If eof() break from loop after setting Lines to current iteration count.
    3. If current time is less than that of the previous line,  throw an error exception.
    4. If current time is great than the last time display a warning and set the SparseFlag.
    5. Read the observation data.  Ignore extra data but throw an error if data is short.

    Call myMacro->execute to execute filters which in the case of 'Sim' also generates observation data.

  9. If not Sparse data delete the array Times as it is only required for soarse data.
  10. Delete myMacro.
  11. Close the data file.
  12. Return.

bool Execute(void) {return (Data); }

    Data is NULL if an error has occurred in instantiating a ClassData object.  Errors include faulty time data,  earlier dates occurring after later dates and insufficient number of data on a line.  Missing times cause the file to be sparse data.  Extra data on a line is ignored.

double *Times;

    When the observation file is read by DataReadFile(void), the date/time for every interval is saved in this array.  This array is only retained if the file holds sparse data otherwise it is released.