Module_Macro Group (09/08/11)

CRHM Macro

Macro declgroup.

   The Macro Group feature allows a number of modules to be grouped under one name and treated as one module.

    The first line of the macro is the module or group name.  In this case MyGroupA, MyGroupB and MyGroupC.

    The following lines up to the command token, list the modules making up the group.  They must be arranged in the correct execution order.

    The tokens command and end complete the definition of the group.There should not be any lines between  command and end.

    Multiple macro groups and macros can be defined together.

MyGroupA

declgroup  // defaults to  number of HRUs defined in the model.

    obs

    calcsun

command

end

MyGroupB

declgroup 5  // five  HRUs.

    intcp

    pbsm

    albedo

    netall

    ebsm

    evap

command

end

MyGroupC

declgroup 0  // defaults to  number of HRUs defined in the model.

    crack

    smbal

    route

command

end

Module Naming Convention.

    Group variable names cannot use the original variable name otherwise their would be a naming conflict.  To avoid this problem, the first macro group defined has the suffix "@A" the next "@B", "@C" etc.Because of this the search order defined in the a following section has been adopted.

Group parameters.

    The group will have all the parameters of every module in the group.   If a parameter is used by more than one module in the group these modules all share the same parameter values.

Module Linking Order.

    Modules can use "*"  or explicitly specify the source module name,   e.g. *.hru_t and Obs.hru_t for the linking to work correctly. Obs.hru_t can only link to the module"Obs" and no other module or group.

    The module linking search order is as follows.

  1. Specific module, e.g. Obs.hru_t.  Will only match Obs.hru_t.
  2. Wild root module or group, e.g. *.hru_t and *[email protected] *.hru_t would match any module with an output hru_t. *[email protected] will only match the hru_t output of the first group defined i.e. with suffix @A
  3. Wild group module stripped of its group suffix.  *[email protected] is reduced to *.hru_t before searching. *[email protected] will match any module with an output hru_t.
  4. Wild group module stripped of its group suffix and a search is made of any groups after their group suffix has been removed. *[email protected] is reduced to *.hru_t before searching all groups for *.hru_t, i.e. after their suffix has been removed.

CreateGroup in the Macro edit menu.

    This command allows an existing project to be convertede to a group.   The new group has the name of the original project with "_A" appended.   If the project is added multiple times the other groups will have "_B", "_C", etc. appended.

    Multiple different projects may be added in any order.  In every case the suffix "_A", "_B" etc. will be added.

    The final model is build in the usual way by going to the menu "Build/Construct" and selecting the groups and building as normal.  The number of HRUs in each group is determined from the project that the group was created from originally. At this time all parameters are CRHM default values.

    After the model is built the original project parameter values may be moved into the new model by proceeding to the Parameter menu and loading the parameter file - "CreateGroup.par".  Care should be taken to use the current directory as the same file name is always used.  If this step is not taken parameter values will default to the module parameter default values.

    During the preceding steps the number of HRUs should not be changed as the number of HRUs in the original project and the generated groups must be identical or they will not updated to the values in "CreateGroup.par".

    The new project should be saved at this time and re-loaded before any further editing is carried out.

    The number of HRUs in any group can be changed by inserting/changing the value on the "declgroup" instruction in the Macro defining the group.   Note that if the value is missing or equal to 0,  the number of HRUs in the group will be the global value.

    When the number of HRUs is reduced the parameters are truncated.   If the number of HRUs is increased the last value is duplicated as often as necessary.  An exception is a serial parameter, "1, 2, 3!" for example, then the series is expanded.

    It is important the names of the groups are not changed or the link between the original parameter values saved in the file "CreateGroup.par" and the groups will be broken causing the error "Unknown Parameter in parameter file" will occur for every parameter.