ClassPar - CRHM parameter object.
class __declspec(dllexport) ClassPar {
public:
string module; // module creating/using the parameter.
string param; // parameter name.
string help; // description given in module call.
string units; // units given in module call.
TVar varType; // enum TVar {none, Int, Float, notused, Read, ReadI, ReadF};
TDim dimen; // enum TDim {ONE=1, TWO, THREE, FOUR, FIVE, SIX, NHRU, NOBS, NLAY, NDEF};
long dim; // primary array dimension.
long lay; // secondary array dimension.
// value of varType determines parameter type and determines if.
float * values;
long *ivalues;
float ** layvalues;
long **ilayvalues;
string valstr; // fill string passed to parser to set default parameter values.
float minVal; // minimum parameter value defined by module author.
float maxVal; // maximum parameter value defined by module author.
ClassPar(string module = "none", string param = "none")
: module(module), param(param), dim(0), values(NULL), ivalues(NULL), layvalues(NULL), ilayvalues(NULL)
{};
ClassPar(string module, string param, TDim dimen, string valstr, float minVal, float maxVal, string help, string units, TVar varType, int defdim);
ClassPar(ClassPar &p); // copy constructor
virtual __fastcall ~ClassPar();
float &operator[](int ii) {return values[ii];}
bool Same(ClassPar &p); // compares parameter data
void Change(ClassPar &p); // changes this values to p
virtual string UserName(void){return module + ' ' + param;};
friend class parser;
};
General.
Modules create all parameters by calling declparam(...) in their *.dec routine. Note that this is the only way parameters can be instantiated.
Data Members.
TVar varType.
// enum TVar {none, Int, Float, notused, Read, ReadI, ReadF};
A parameter is created as long or floating point as determined by varType being Int or Float.
TDim dimen.
// enum TDim {ONE=1, TWO, THREE, FOUR, FIVE, SIX, NHRU, NOBS, NLAY, NDEF};
A parameter is created to serve one of the following purposes:
- One dimensional (NHRU) - simple module parameter.
- One dimensional (NOBS) - used only for observation manipulation.
- One dimensional ( ONE) ... (SIX).
- TWO dimensional (NLAY, NHRU) - used in multi - layer models.
- TWO dimensional (1, NDEF) - used to indirectly assign model parameters.
The following variables are set as follows depending upon the value of TDim, dim and lay in the call to declparam(...).
long dim; // primary array dimension.
long lay; // secondary array dimension.
// if(dim == NLAY) { lay = getdim(dimen); dim = getdim(NHRU);}
// else if(dimen == NDEF) { lay = defdim; dim = 1;}
// else if(dimen < NHRU) dim = getdim(dimen);
// else dim = getdim(NHRU);
N.B.
The following 4 pointers (values/layvalues and ivalues/ilayvalues) are always handled as pairs. Storage is allocated to layvalues or ilayvalues and values or ivalues is set equal to the first layer. The other pair are left as NULL. This is different from how they are handled for ClassVar.
float * values.
Pointer to allocated floating point array defined in layvalues[0]. NULL if long parameter.
long *ivalues;
Pointer to allocated long array defined in ilayvalues[0]. 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.
- default
ClassPar(string module = "none", string param = "none") : module(module), param(param), dim(0), values(NULL), ivalues(NULL), layvalues(NULL), ilayvalues(NULL) {};
- 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 ~ClassPar();
Copy constructor
ClassPar(ClassPar &p);
Create copy allocating new storage for data members.
Operator [ ]
float &operator[](int ii) {return values[ii];}
Compare Parameters
bool Same(ClassPar &p);
Returns false if any parameter value is different.
Change Parameter
void Change(ClassPar &p);
Assign parameter values to those given by &p
Return names string
virtual string UserName(void){return module + ' ' + param;};
Parse default string and assign values
friend class parser;