Initializing help system before first use

Runtime parameters

A convenient means of modifying data in a Mosel model when running the model (that is, without having to modify the model itself and recompile it) is to use runtime parameters. Such parameters are declared at the beginning of the model in a parameters block where every parameter is given a default value that will be applied if no other value is specified for this parameter at the model execution.

Consider the following model rtparams.mos that may receive parameters of four different types—integer, real, string, and Boolean—and prints out their values.

model "Runtime parameters"
 parameters
  PARAM1 = 0
  PARAM2 = 0.5
  PARAM3 = ''
  PARAM4 = false
 end-parameters

 writeln(PARAM1, "  ", PARAM2, "  ", PARAM3, "  ", PARAM4)

end-model 

The master model runrtparam.mos executing this (sub)model may look as follows—all runtime parameters are given new values:

model "Run model rtparams"
 uses "mmjobs"

 declarations
  modPar: Model
 end-declarations
                                   ! Compile the model file
 if compile("rtparams.mos")<>0 then exit(1); end-if
 load(modPar, "rtparams.bim")      ! Load the bim file
                                   ! Start model execution
 run(modPar, "PARAM1=" + 2 + ",PARAM2=" + 3.4 +
             ",PARAM3='a string'" + ",PARAM4=" + true)
 wait                              ! Wait for model termination
 dropnextevent                     ! Ignore termination event message

end-model 

An alternative formulation to the above makes use of the subroutine setmodpar to define the parameter values for the submodel (notice that we need to load the module mmsystem for the text handling functionality)—after starting the model run we delete the parameters definition; it would also be possible to remove individual parameter value settings by applying resetmodpar to the object params.

model "Run model rtparams 2"
 uses "mmjobs", "mmsystem"

 declarations
  modPar: Model
  params: text
 end-declarations
                                   ! Compile the model file
 if compile("rtparams.mos")<>0 then exit(1); end-if
 load(modPar, "rtparams.bim")      ! Load the bim file
 setmodpar(params, "PARAM1", 2)    ! Set values for model parameters
 setmodpar(params, "PARAM2", 3.4)
 setmodpar(params, "PARAM3", 'a string')
 setmodpar(params, "PARAM4", true)
 run(modPar, params)               ! Start model execution
 params:= ""                       ! Delete the parameters definition
 wait                              ! Wait for model termination
 dropnextevent                     ! Ignore termination event message

end-model