Initializing help system before first use

Definition of constants

The following package myconstants defines one integer, one real, one string, and two boolean constants.

package myconstants

 public declarations
  MYCST_BIGM = 10000          ! A large integer value
  MYCST_TOL = 0.00001         ! A tolerance value
  MYCST_LINE =                ! String constant
     "----------------------------------------------------------------"
  MYCST_FLAG = true           ! Constant with value true
  MYCST_NOFLAG = false        ! Constant with value false
 end-declarations

end-package

The structure of a package is similar to the structure of Mosel models, with the difference that we use the keyword package instead of model to mark its beginning and end.

After compiling our package with the standard Mosel command (assuming the package is saved in file myconstants.mos)

mosel comp myconstants

it can be used in a Mosel model (file myconst_test.mos):

model "Test myconstants package"
 uses "myconstants"

 writeln(MYCST_LINE)
 writeln("BigM value: ", MYCST_BIGM, ", tolerance value: ", MYCST_TOL)
 writeln("Boolean flags: ", MYCST_FLAG, " ", MYCST_NOFLAG)
 writeln(MYCST_LINE)

end-model

Having made sure that Mosel is able to find our package myconstants.bim (see the notes about package location at Packages), executing the test model above will produce the following output:

----------------------------------------------------------------
BigM value: 10000, tolerance value: 1e-05
Boolean flags: true false
----------------------------------------------------------------

When comparing with the C implementation of the module example myconstants in the Mosel Native Interface User Guide we can easily see that the package version is much shorter.