Initializing help system before first use

Definition of parameters

Mosel parameters are scalars of one of the four basic types (real/integer/string/boolean). Packages can define new parameters by declaring their names and type in the parameters section. The package needs to store the current values of the parameters in separate model entities and will usually initialize default values for the parameters.

package parpkg

 ! Specify parameter names and types
 parameters
  "p1":real
  "p2":integer
  "p3":string
  "p4":boolean
 end-parameters

 ! Entities for storing current parameter values
 declarations
  myp1: real
  myp2: integer
  myp3: string
  myp4: boolean
 end-declarations

 ! Set default values for parameters
 myp1:=0.25
 myp2:=10
 myp3:="default"
 myp4:=true

 !... Parameter access routines ...
end-package

The access routines for the four parameter types have a fixed format, namely packagename∼get[r|i|s|b]param and packagename∼set[r|i|s|b]param as shown in the code extract below.

 ! Get value of a real parameter
 public function parpkg~getrparam(p:string):real
  case p of
   "p1": returned:=myp1
  end-case
 end-function

 ! Get value of an integer parameter
 public function parpkg~getiparam(p:string):integer
  case p of
   "p2": returned:=myp2
  end-case
 end-function

 ! Get value of a string parameter
 public function parpkg~getsparam(p:string):string
  case p of
   "p3": returned:=myp3
  end-case
 end-function

 ! Get value of a boolean parameter
 public function parpkg~getbparam(p:string):boolean
  case p of
   "p4": returned:=myp4
  end-case
 end-function

 ! Set value for real parameters
 public procedure parpkg~setparam(p:string,v:real)
  case p of
   "p1": myp1:=v
  end-case
 end-procedure

 ! Set value for integer parameters
 public procedure parpkg~setparam(p:string,v:integer)
  case p of
   "p2": myp2:=v
  end-case
 end-procedure

 ! Set value for string parameters
 public procedure parpkg~setparam(p:string,v:string)
  case p of
   "p3": myp3:=v
  end-case
 end-procedure

 ! Set value procedure for boolean parameters
 public procedure parpkg~setparam(p:string,v:boolean)
  case p of
   "p4": myp4:=v
  end-case
 end-procedure

A model using the package 'parpkg' will access the package parameters via Mosel's standard getparam and setparam routines ( the parameter names are not case-sensitive and their names can be preceded by the package name).

model "Packages with parameters"
 uses 'parpkg'

 ! Display default parameter values
 writeln("Default values:",
   " p1=", getparam("parpkg.P1"), " p2=", getparam("P2"),
   " p3=", getparam("parpkg.p3"), " p4=", getparam("p4"))

 ! Change values
 setparam("p1",133)
 setparam("parpkg.p2",-77)
 setparam("P3","tluafed")
 setparam("parpkg.P4",not getparam("parpkg.P4"))

end-model