As mentioned before,
the Monitor performs symbol substitutions on MIDAS command lines in the
first pass
by replacing symbol names in the command line with
their current value. For character symbols just the string is put in; for
symbols of other types the binary data are converted to ASCII using the
formats specified in the SET/FORMAT command.
This substitution is iterated until no more
symbol substitutions are possible.
Keywords, descriptors, pixel values of an image or elements of a table
are valid symbols in the MIDAS command language.
The following syntax is used to distinguish among keywords , descriptors ,
pixel values and table elements :
star refers to the value stored in the keyword star
galaxy,disk refers to the contents of descriptor disk
of frame galaxy.bdf
galaxy[x,y] refers to the value of the image pixel at coordinate x,y
of the 2--dimensional frame galaxy.bdf
dust,:particles, refers to the element of the table dust.tbl
in column labeled :particles and row 7
dust,#2, refers to the element of the table dust.tbl
in the second column and row 77
Elements of numerical keywords with more than one element are specified
like elements in a FORTRAN vector, e.g. INPUTR(7).
Also substrings of character keywords are indicated as in FORTRAN,
e.g. INPUTC(2:5). These features are also implemented for descriptors
but not for table entries (yet).
Any algebraic expression using the operators +, -, , /
and parentheses ( , ) and constants as well as any symbol
above which defines
MIDAS data is supported by the command COMPUTE/KEYWORD and its
short form key = expression. This also applies to all the other
direct assignments of single values to MIDAS data structures we had described
above in section ,
e.g. image[x,y] = expression.
Let us look at an example of this:
!+
! Example 6, MIDAS procedure exa6.prg
!+
DEFINE/PARAM P1 ? N "Enter alpha value: " -88.5,912.4
DEFINE/PARAM P2 ? N "Enter loop_count: " 1,999
DEFINE/MAXPAR 2 ! max. 2 parameters expected
WRITE/KEYWORD VAR/R/1/1 0. ! init key VAR
VAR = P1 * 3.3 ! set VAR to 3.3 (contents of P1)
WRITE/DESCR myframe rval/r/1/2 0.0,0.0 !
LOOP: ! declare label LOOP
VAR = 1.+VAR ! set VAR = 1.0 + VAR
myframe,rval(2) = var+12.99
WRITE/OUT myframe,rval(2)
myframe[@10,@20] = 20.0-myframe,rval(2)
WRITE/OUT myframe[@10,@20]
mytable,:DEC,@7 = myframe[@10,@20]*2.0
WRITE/OUT mytable,:DEC,@7
WRITE/OUT " "
IF VAR .LE. P2 GOTO LOOP ! go to label LOOP, if VAR contents of P2
Then the command @@ exa6 1.0 5.2 will yield:
.72900E+01
2.71000E+00
5.42000E+00
1.82900E+01
1.71000E+00
3.42000E+00
Note character keywords COMPUTE/KEYWORD only supports character concatenation (`//'). If you want to write a character string into a character keyword, use WRITE/KEYWORD instead. Therefore, if we had written VAR = P1 * 3.3 instead of VAR = P1 * 3.3 in the procedure exa5.prg, MIDAS would have protested because no multiplication is permitted for character keywords.
You may want to use symbol substitutions for sending the output of a MIDAS
command to an ASCII file or to the terminal depending upon the
contents of e.g., the character keyword mykey.
Setting keyword mykey once to ">outfile" or ">terminal"
if you want output to
a file or not together with the command line WRITE/TABLE
mytab mykey in your procedure will not work!
For, the check for the output redirection is done at the
very first parsing of the command line before any symbols in that line
are replaced...
Instead, setting mykey to "outfile" or "terminal" and changing
the command line to: WRITE/TABLE mytab >mykey
will do the intended switching of output to a file or terminal.
Since symbols may be tested in conditional statements and thus change
the control flow of a MIDAS procedure, they provide the link
between application programs and the MIDAS command language.
The number of characters
used in the ASCII representation of a numerical symbol may be controlled
via the command SET/FORMAT I-format for integer symbols and
SET/FORMAT x-format,y-format (where x or y can be
E, G or F) for real (x-format) and double
(y-format) precision symbols. Integer symbols are then encoded
via I--format (with leading zeroes not suppressed) and real or double
precision symbols
as E--format, G--format or F--format (used as in FORTRAN 77):
!+
! Example 7, MIDAS procedure exa7.prg
!+
WRITE/KEYWORD INPUTI 12 ! set INPUTI(1) to 12
WRITE/KEYWORD INPUTR 12.345 ! set INPUTR(1) to 12.345
! and set INPUTD(1) to 123456.98765432
WRITE/KEYWORD INPUTD 123456.98765432
WRITE/OUT inputi(1) inputr(1) inputd(1)
SET/FORMAT I2 ! use format I2.2 for integer symbols
! and use format E12.8 and G22.8 for real and double symbols
SET/FORMAT E12.8,G22.8
WRITE/OUT inputi(1) inputr(1) inputd(1)
SET/FORMAT i5 ! use format I5.5 for integer symbols
! and use format F12.4 and E22.13 for real and double symbols
SET/FORMAT f12.4,e22.13
WRITE/OUT inputi(1) inputr(1) inputd(1)
The command @@ exa7 will yield:
0012 1.23450E+01 1.23457E+05 default is I4 and E15.5,E15.5
12 1.23450003E+01 1.23456988E+05 uses I2 and E12.8,G22.8
00012 12.345 1.2345698765432E+05 uses I5 and F12.4,E22.13
If you want to omit any leading zeroes for integer symbols use SET/FORMAT
I1, then only the necessary digits will be displayed.
Note MIDAS version 94NOV the same format was used for real and double symbols. This led to problems when real and double symbols in the same command line had to be substituted.
Use SET/FORMAT f-format to only change the format for real symbols and SET/FORMAT ,f-format to only change the format for double symbols.
Substitution begins inside the curly brackets, starting at the deepest nested
level:
WRITE/OUT IN_AINPUTC(1:3)
will display SPIRALABC on the terminal, if key IN_A contains the string
SPIRAL and key INPUTC(1:3) the string ABC.
It is sometimes necessary to substitute symbols in a nested order:
!+
! Example 8, MIDAS procedure exa8.prg
!+
DEFINE/PARAM P1 myframe IMA "Enter name for input frame: "
SET/FORMAT F5.1
WRITE/OUT P1,STEP(1)
the command @@ exa8 will force the Monitor to substitute the last
command line in exa8.prg first to:
WRITE/OUT myframe,STEP(1) and then yield:
20.5
assuming that descriptor STEP of myframe.bdf contains
20.5 as first element.
This example also illustrates the concept of recursive substitution .