next up previous 211
Next: Including escape characters in messages
Up: MSG - Message Reporting System
Previous: Message tokens


Formatted tokens

The MSG_SETx subroutines encode numeric values in the most concise format that will describe the supplied value. This is normally what is wanted for a simple message. Sometimes, however, a specific format is required; for example, the message may form part of a table. More precise numeric formats could be achieved using the Fortran WRITE statement with the Message System, e.g.

*  Local Constants:
      CHARACTER * 12 FUNITS
      PARAMETER( FUNITS = ' erg/cm2/A/s' )

*  Local Variables:
      CHARACTER * 12 VALUE

      ...

*  Output the flux value.
      WRITE( VALUE, '( 1E12.5 )' ) FLUX
      CALL MSG_SETC( 'FLUX', VALUE )
      CALL MSG_SETC( 'FLUX', FUNITS )
      CALL MSG_OUT( 'EXAMPLE_RESULT', 
     :             'Emission flux is ^FLUX.', STATUS )

which would produce the message:

Emission flux is  2.40000E+00 (erg/cm2/A/s).

In this case, the first call to MSG_SETC assigns the supplied character string VALUE to the named token ``FLUX''.

Since this sequence of a formatted internal WRITE followed by a call to MSG_SETC is of general use, it is provided in a set of subroutines of the form:

      CALL MSG_FMTx( TOKEN, FORMAT, VALUE )

where FORMAT is a valid Fortran 77 format string which can be used to encode the supplied value, VALUE. As for MSG_SETx, x corresponds to one of the five standard Fortran data types - D, R, I, L and C.

Using MSG_FMTx, the example given above can be performed by:

*  Output the flux value.
      CALL MSG_FMTR( 'FLUX', '1E12.5', FLUX )
      CALL MSG_SETC( 'FLUX', FUNITS )
      CALL MSG_OUT( 'EXAMPLE_RESULT', 
     :             'Emission flux is ^FLUX.', STATUS )

The use of the MSG_FMTx routines along with their ability to append values of any type to existing tokens is a very powerful tool for constructing tabular output from applications software.



next up previous 211
Next: Including escape characters in messages
Up: MSG - Message Reporting System
Previous: Message tokens

MERS (MSG and ERR) Message and Error Reporting Systems
Starlink User Note 104
P C T Rees
A J Chipperfield
22 October 2001
E-mail:ussc@star.rl.ac.uk

Copyright © 2001 Council for the Central Laboratory of the Research Councils