next up previous
Next: 8. Using Scalars and Floating Up: A Tutorial on the Previous: 6. Controlling the Output with

7. System Parameter Access with Register P

 

The macro language provides read-only registers for the most important system parameters, such as current module, current scenario or the current date. However, when writing complex macros, it is often necessary to access all kind of other data bank or system parameters. The special register p is available for accessing such parameters. For this purpose, each available parameter is assigned an address, which is to be used to access this parameter. When the p register is set to such an address, the value of the corresponding parameter is used when the p register is used in substitutions or conditionals. Thus, the p register is different from the other registers, since it behaves differently for read and write accesses: parameter addresses are written to the p register, and parameter values are read from it.

The classes of parameters that are accessible via the p register are: global data bank parameters, scenario numbers, scenario parameters, and other system parameters. The following table lists the corresponding addresses:

System Parameter Register P
address:contents:
1-80Global parameters, as described in Appendix C.1 of EMME/2 User's Manual.
101-200External scenario numbers (0: scenario slot empty, -1: scenario slot not available in data bank)
1001-1280Scenario parameters 1-280 of the current scenario, as described in Appendix C.1 of EMME/2 User's Manual.
2000-2011 System parameters, as defined below
2001Software (1: EMME/2, 2: STAN)
2002Licence number
2003Licence size (1-12)
2004Type of operating system (1: UNIX, 2: DOS, 3: VMS)
2005CPU time used since creation of the data bank (in 1/10 secs)
2006Current year (0-99)
2007Current month (1-12)
2008Current day of month (1-31)
2009Current hour (0-23)
2010Current minute (0-59)
2011Current second (0-59)
As an example, look at the following example sequence, which computes the number of entries that are still available in the turn table of the current scenario. This number is computed as the difference of the global parameter 55 (MTURN, maximum turn table size in data bank) and the scenario parameter 4 (NTURN, current size of turn table), as follows:

    ~p=55        / global parameter MTURN, maximum size of turn table
    ~x=%p%       / X=MTURN
    ~p=1004      / scenario parameter NTURN, current size of turn table
    ~x-%p%       / X=X-NTURN
    ~/ Number of available turn table entries in scenario %s% is %x%.

Note that there is a potential synchronization problem when accessing the system parameters 2006 - 2011 for assembling a string with the current time. Imagine e.g. that this operation was started just a few milliseconds before midnight, so that instead of 92-05-16 23:59:59 one could obtain the string 92-05-16 00:00:00, which would clearly be wrong. To avoid such problems, the internal time values are replaced only if either more than 2 seconds passed since last time parameter access, or the last time parameter accessed was of higher or equal index. With these rules, no synchronization problems occur when accessing time parameters sequentially in the order given above.



Exercise 7.1:
Write a macro which scans the data bank for scenarios which are prepared for assignment, but not yet assigned, and perform the corresponding assignments.



Exercise 7.2:
Write a ``wrapper'' macro cputime which calls the macro given as parameter and, after completion, reports the number of cpu seconds that were used during the execution of that macro.



Exercise 7.3:
Write a macro filecopy which copies the file given as the first parameter into the file given as second parameter. The macro should work equally well on DOS, UNIX and VAX/VMS systems.


next up previous
Next: 8. Using Scalars and Floating Up: A Tutorial on the Previous: 6. Controlling the Output with

Heinz Spiess, EMME/2 Support Center
Fri Sep 27 13:04:28 MET DST 1996