Creating a Macro to dynamically change parameters at model run time.
Normally parameters have an intial value which is held constant throughout a model run. This is the correct behaviour for parameters like elevation, area etc. However, vegetation height is a variable during the growing season. It should be handled as a variable. This is easily accomplished using a macro. Two examples follow. The first illustrates how the vegetation height may read from an observation file and the second if the height versus time relationship is known.
1) Using an observation file holding vegetation heights.
The following macro reads the observation Heights and writes it every interval to the parameter Ht. The variable Ht_Var was created so that the heights could be displayed as there is no method of charting parameters in CRHM (assumed to be constants).
Ht_file
declreadobs,Heights, NOBS, "Vegetation height", (m)
declparam, Ht, NHRU,0.1, 0.01, 10.0, description, (m)
declvar, Ht_Var, NHRU, "vegetation height", (m)
command
Ht[hh] = Heights[hh]
Ht_Var[hh] = Ht[hh]
end
2) Programming vegetation heights.
The following macro is written assuming the crop grows continuously from a Julian date to a maximum value.
Ht_Change
declparam, Ht, NHRU,0.1, 0.01, 100.0, description, (m)
declparam, Ht_change, NHRU,0.1, 0.01, 1.0, description, (m)
declparam, Ht_min, NHRU,0.1, 0.01, 3.0, description, (m)
declparam, Ht_max, NHRU,0.1, 0.01, 3.0, description, (m)
declparam, Ht_Julian, NHRU,195, 1, 366, description, ()
declvar, Ht_Var, NHRU, "vegetation height", (m)
declvar, Ht_Start, NHRU, "vegetation height", ()
command
if(STEP == 1)
Ht[hh] = Ht_min[hh]
endif
if(JULIAN >= Ht_Julian)
Ht_Start[hh] = JULIAN
if(LASTINT)
Ht[hh] = Ht[hh] +
Ht_change[hh]
endif
if( Ht[hh] > Ht_max[hh])
Ht[hh] = Ht_max[hh]
endif
endif
Ht_Var[hh] = Ht[hh]
end
Using the Height change macro modules.
After the macro code is added to the editor answer YES to the query asking if
the modules should be loaded. The modules must be next added to the current model using
the normal BUILD/CONSTRUCT screen. After adding the height macro module and during
the build process, CRHM will ask if the module should be deleted, answer NO.
This is necessary as CRHM is not able to determine ihow the module is used.