ClassVar (08/27/02)

CRHM

ClassVar - observation or module variable object.

class __declspec(dllexport) ClassVar {

typedef void (ClassVar:: *SomeFunct) (void);

public:

string module; // module creating variable

string name; // variable name

string help; // description given in call

string units; // units given in call

TVar varType; // enum TVar {none, Int, Float, notused, Read, ReadI, ReadF}

long dim; // number of HRUs

long lay; // layer dimension, 0 - no layers else the number of layers

bool local; // inhibits display in ListBox1

bool optional; // when an observation indicates that they variable is not mandatory.

bool PointPlot; // normal plotting mode is line.  Used for sparse data.

float * values; // simple floating point variable

long * ivalues; // simple long variable

float ** layvalues; // multi-layer floating point variable

long **ilayvalues; // multi-layer long variable

long offset; // when an observation variable gives data column.

long cnt; //  when an observation variable gives dimension of observation.

ClassData *FileData; // when an observation points to file.

ClassVar *FunctVar; // pointer to variable used by UserFunct

SomeFunct UserFunct; // pointer to variable function.  typedef void (ClassVar:: *SomeFunct) (void);

ClassVar(string module = "none", string name = "none"): module(module), name(name), varType(none), dim(0), lay(0), optional(false),values(NULL), ivalues(NULL), layvalues(NULL), ilayvalues(NULL), local(false),offset(0), cnt(0), FileData(NULL), UserFunct(NULL), FunctVar(NULL), PointPlot(false) {};

ClassVar(string module, string name, TDim dimen,string help, string units, TVar varType, bool PointPlot = false);

ClassVar(string module, string name, long dim,string help, string units, TVar varType, bool PointPlot = false);

ClassVar(string module, string name, long cnt, long offset, ClassData * FileData): module(module), name(name), varType(Read), dim(cnt), lay(0), optional(false), local(false), offset(offset), cnt(cnt), FileData(FileData), UserFunct(NULL), FunctVar(NULL), values(NULL), ivalues(NULL), layvalues(NULL), ilayvalues(NULL), PointPlot(false) {};

virtual __fastcall ~ClassVar();

ClassVar(const ClassVar & Cl);

ClassVar & operator=(const ClassVar & Cl);

float &operator[](int ii) {return values[ii];}

virtual void ClassVarData(); // reads current interval values from observation file data buffer into variable.

virtual void ReadVar(void);

virtual string UserName(void){return module + ' ' + name;};

virtual void Avg(void); // function handling average value.

virtual void Min(void); // function handling minimum value.

virtual void Max(void); // function handling maximum value.

virtual void Dtot(void); // function handling daily sum of value.

virtual void Tot(void); // function handling sum of value.

virtual void First(void); // function handling first value of day.

virtual void Last(void); // function handling last value of day.

};

 

General.

    Ways of creating variables are:

  1. Modules can create module variables by calling declvar(...) in their *.dec routine.
  2. Observation variables are created by a call to declread(...) in ClassData::DataReadFile(...).
  3. Tmain::AddObsPlot(...) calls the ClassVar copy constructor when displaying observation functions.
  4.  

Data Members.

TVar varType.

// enum TVar {none, Int, Float, notused, Read, ReadI, ReadF};

The variable is created as long or floating point depending on the value of varType.

When observation files are loaded before the model modules,  the observation variables have initial values of varType equal to Read as the data type is indeterminate until a module using the observation is opened.

 

TDim dimen.

// enum TDim {ONE=1, TWO, THREE, FOUR, FIVE, SIX, NHRU, NOBS, NLAY, NDEF};

For variables only NHRU and NLAY are permissible for values for dimen.

The following variables are set as follows depending upon the value of TDim in the call to declvar(...).

long dim; // NHRU dimension.

long lay; // secondary array dimension.

// dim = getdim(NHRU);

// if (dimen == NLAY)  lay = getdim(dimen); else lay = 0;

N.B.

    Only one of the following 4 pointers (values, ivalues, layvalues and ilayvalues) is allocated storage and the remainder are left as NULL.  This is different from how they are handled for ClassPar.

float * values.

Pointer to allocated one dimensional floating point array.  NULL if long parameter.

long *ivalues;

Pointer to allocated long array one dimensional.  NULL if floating point parameter.

float ** layvalues;

Two dimensional pointer array to which storage is assigned when the parameter is floating point, otherwise is NULL.  The first dimension is lay and the second is dim.

 

long **ilayvalues;

Two dimensional pointer array to which storage is assigned when the parameter is long, otherwise is NULL.  The first dimension is lay and the second is dim.

Member Functions.

Constructors.

  1. default

    ClassPar(string module = "none", string param = "none") : module(module), param(param), dim(0), values(NULL), ivalues(NULL), layvalues(NULL), ilayvalues(NULL)  {};

  2. used

ClassPar(string module, string param, TDim dimen, string valstr, float minVal, float maxVal, string help, string units, TVar varType, int defdim);

Destructor

virtual __fastcall ~ClassVar();

Copy constructor

ClassVar(ClassVar &p);

Create copy allocating new storage for data members.

Operator =

float &operator=(ClassVar &p);

Operator [ ]

float &operator[](int ii) {return values[ii];}