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:
1.72900E+01
2.71000E+00
5.42000E+00
1.82900E+01
1.71000E+00
3.42000E+00
Note The 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.
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 E-format (or F-format) for real and double
precision symbols. Integer symbols are then encoded
via I--format (with leading zeroes not suppressed) and real or double
precision symbols
as E--format or F--format:
!+
! 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
WRITE/KEYWORD INPUTD 1234.5678 ! set INPUTD(1) to 1234.5678
WRITE/OUT inputi(1) inputr(1) inputd(1)
SET/FORMAT I2 ! use format I2.2 for integer symbols
SET/FORMAT E12.8 ! use format E12.8 for real/double symbols
WRITE/OUT inputi(1) inputr(1) inputd(1)
SET/FORMAT I5 ! use format I5.5 for integer symbols
SET/FORMAT F12.4 ! use format F12.4 for real/double symbols
WRITE/OUT inputi(1) inputr(1) inputd(1)
The command @@ exa7 will yield:
0012 1.23450E+01 1.23457E+03 default is I4 and E15.5
12 1.23450003E+01 1.23456780E+03 uses I2 and E12.8
00012 12.3450 1234.5678 uses I5 and F12.4
If you want to omit any leading zeroes for integer symbols use SET/FORMAT
I1, then only the necessary digits will be displayed.
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 .