Sophie

Sophie

distrib > Mageia > 5 > i586 > by-pkgid > 37ce2601040f8edc2329d4714238376a > files > 829

eso-midas-doc-13SEPpl1.2-3.mga5.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<!--Converted with LaTeX2HTML 98.1p1 release (March 2nd, 1998)
originally by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds
* revised and updated by:  Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
  Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<HTML>
<HEAD>
<TITLE>Symbol Substitution in Command Procedures</TITLE>
<META NAME="description" CONTENT="Symbol Substitution in Command Procedures">
<META NAME="keywords" CONTENT="vol1">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<LINK REL="STYLESHEET" HREF="vol1.css">
<LINK REL="next" HREF="node41.html">
<LINK REL="previous" HREF="node39.html">
<LINK REL="up" HREF="node38.html">
<LINK REL="next" HREF="node41.html">
</HEAD>
<BODY >
<!--Navigation Panel-->
<A NAME="tex2html989"
 HREF="node41.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next"
 SRC="icons.gif/next_motif.gif"></A> 
<A NAME="tex2html985"
 HREF="node38.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up"
 SRC="icons.gif/up_motif.gif"></A> 
<A NAME="tex2html979"
 HREF="node39.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous"
 SRC="icons.gif/previous_motif.gif"></A> 
<A NAME="tex2html987"
 HREF="node1.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents"
 SRC="icons.gif/contents_motif.gif"></A> 
<A NAME="tex2html988"
 HREF="node216.html">
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index"
 SRC="icons.gif/index_motif.gif"></A> 
<BR>
<B> Next:</B> <A NAME="tex2html990"
 HREF="node41.html">DO Loops</A>
<B> Up:</B> <A NAME="tex2html986"
 HREF="node38.html">MIDAS Command Language</A>
<B> Previous:</B> <A NAME="tex2html980"
 HREF="node39.html">Passing Parameters in MIDAS</A>
<BR>
<BR>
<!--End of Navigation Panel-->

<H2><A NAME="SECTION00662000000000000000">&#160;</A> <A NAME="1998">&#160;</A>
<A NAME="symbol-substitution">&#160;</A>
<BR>
Symbol Substitution in Command Procedures
</H2>

<P>
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 <TT>SET/FORMAT</TT> 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.
<BR>
&nbsp;&nbsp; <BR>
The following syntax for substitution is used to distinguish among 
keywords<A NAME="2001">&#160;</A>, descriptors<A NAME="2002">&#160;</A>, 
pixel<A NAME="2003">&#160;</A> values and table elements<A NAME="2004">&#160;</A>:
 
<IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img49.gif"
 ALT="$\{$">star<IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img50.gif"
 ALT="$\}$">
is a string representing the value stored in the keyword 
<I>star</I> <BR>
If <I>star</I> is not a character keyword, the numerical value of <I>star</I> 
will be converted to an ASCII string according to the format defined 
via the SET/FORMAT command. Therefore, take care, you may lose precision if 
an inadequate format is chosen.
 
<IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img51.gif"
 ALT="$\{$">galaxy,disk<IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img52.gif"
 ALT="$\}$">
is a string representing the value stored in 
descriptor <I>disk</I> of the image frame <I>galaxy.bdf</I>
<BR>
If <I>disk</I> is not a character descriptor, the numerical value of
<I>disk</I> will be converted to an ASCII string according to &nbsp;...&nbsp; 

<P>
<IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img53.gif"
 ALT="$\{$">galaxy[x,y]<IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img54.gif"
 ALT="$\}$">
 is a string representing the value of the
image pixel at coordinate x,y of the 2-dimensional frame <I>galaxy.bdf</I>.
<BR>
This value will always be converted to an ASCII string according to &nbsp;...&nbsp; 

<P>
<IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img55.gif"
 ALT="$\{$">dust,:particles,<IMG
 WIDTH="28" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img56.gif"
 ALT="$7\}$">
is a string representing the 
element of the table <I>dust.tbl</I> in the column labeled <I>:particles</I> 
and row <I>#7</I>  <BR>
If the table element is not of type character, the numerical value will be
converted to an ASCII string according to &nbsp;...&nbsp; 

<P>
<IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img57.gif"
 ALT="$\{$">dust,#2,<IMG
 WIDTH="39" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img58.gif"
 ALT="$77\}$">
is a string representing the element of the table
<I>dust.tbl</I> in the second column and row <I>77</I>
&nbsp;&nbsp;
<BR>
Elements of numerical keywords with more than one element are specified
like elements in a FORTRAN vector, e.g. <TT>INPUTR(7)</TT>, that also means that
the first element has the index 1 (not 0).
Also substrings of character keywords are indicated as in FORTRAN,
e.g. <TT>INPUTC(2:5)</TT>. These features are also implemented for descriptors
but not for table entries (yet).  <BR>
&nbsp;&nbsp; <BR>
Since the outcome of symbol substitution is a character string, it can be used
in place of any operand of a Midas command, like the command, qualifier
or parameters, e.g. <TT>WRITE/OUT </TT><IMG
 WIDTH="27" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img59.gif"
 ALT="$\{\{$"><TT>P1</TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img60.gif"
 ALT="$\}$"><TT>,STEP(1)</TT><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img61.gif"
 ALT="$\}$">.
<BR>
&nbsp;&nbsp; <BR>
It's with the the command <TT>COMPUTE/KEYWORD</TT> and its short form 
<TT>variable = expression</TT> (called <I>direct assignment</I>), with 
<I>variable</I> any of
<I>keyword, descriptor, image-pixel</I> or <I>table-element</I> that symbol
substitution gets a bit more complex. Therefore, we shall elaborate on that
in some more detail.
<BR>
&nbsp;&nbsp; <BR>
First, the result (left hand side) keyword, descriptor, table element, etc. is
specified WITHOUT the brackets, i.e
 
<TT>Midas &gt; compute/keyw dust,#2,77 = inputr(6)*m$sin(inputr(12))</TT>
<BR>
or
 
<TT>Midas &gt; dust,#2,77 = inputr(6)*m$sin(inputr(12))</TT>
<BR>
&nbsp;&nbsp;
<BR>
Any algebraic expression using the operators +<TT>, </TT>-<TT>, </TT>*<TT>,&nbsp;/&nbsp; </TT>
and parentheses <TT>(</TT> , <TT>)</TT> and constants as well as any <I>variable</I> 
explained above is supported by the command
<TT>COMPUTE/KEYWORD</TT> (and direct assignments).
However, since keywords are the ``objects" of the right-hand expression in this 
command they don't have
to be enclosed in curly brackets unless we need a
conversion from character keywords to numerical data. If a keyword name is
found as operand in the <TT>COMPUTE/KEYWORD</TT> command, automatically its
content is taken (character strings have to be enclosed in double quotes).
Using curly brackets always and thus substitution at the 
parsing 
stage of the Midas command line introduces dependency on the <TT>SET/FORMAT</TT>
command and thus the possible danger of loss of precision for numerical
keywords.
<BR>
But this is only true for keywords - all other variables like
descriptors, table elements, etc. have to to be either converted to ASCII
strings via the curly brackets (or accessed via the M$VALUE function)!

<P>
<TT>Midas &gt; inputd = image,step(2)+outputd(5)</TT>
<BR>
is WRONG. Whereas,

<P>
<TT>Midas &gt; outputr(12) = outputr(1)-inputi(12)+</TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img62.gif"
 ALT="$\{$"><TT>galaxy,step(2)</TT><IMG
 WIDTH="25" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img63.gif"
 ALT="$\})$">
<BR>
is O.K.
<BR>
&nbsp;&nbsp; <BR>
Also the commands <TT>DO, IF</TT> and <TT>BRANCH</TT> operate on keywords or
constants only.
So again, the name of a keyword indicates already to use it's contents, whereas
 character strings have to be enclosed in double quotes.
&nbsp;&nbsp;
<BR>
Inside a Midas procedure the line:
 
<TT>if </TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img64.gif"
 ALT="$\{$"><TT>inputi</TT><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img65.gif"
 ALT="$\}$"><TT> .eq. 22 then</TT>
<BR>
is not wrong, but:
 
<TT>if inputi .eq. 22 then</TT>
<BR>
is better, since <I>inputi</I> is an integer keyword and needs therefore no
conversion from character string to numerical value.
<BR>
However, if e.g. parameter <TT>P3</TT> contains a number, then
 
<TT>if p3 .eq. 22 then</TT>
<BR>
is WRONG, instead:
 
<TT>if </TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img66.gif"
 ALT="$\{$"><TT>p3</TT><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img67.gif"
 ALT="$\}$"><TT> .eq. 22 then</TT>
<BR>
has to be used, since the parameters are implemented as character keywords.
<BR>
&nbsp;&nbsp;
<BR>
Let us look at another examples:<BLOCKQUOTE>
<TT>!+ <BR>
  ! Example 6, MIDAS procedure exa6.prg <BR>
  !+ <BR>
DEFINE/PARAM P1 ? N "Enter alpha value: " -88.5,912.4 <BR>
DEFINE/PARAM P2 ? N "Enter loop_count: " 1,999 <BR>
DEFINE/MAXPAR 2 </TT>! max. 2 parameters expected<TT>
<BR>
WRITE/KEYWORD VAR/R/1/1 0.	</TT>! init key VAR<TT> <BR>
VAR = </TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img68.gif"
 ALT="$\{$"><TT>P1</TT><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img69.gif"
 ALT="$\}$"><TT> * 3.3	</TT>! see remark a<TT>
<BR>
WRITE/DESCR myframe rval/r/1/2 0.0,0.0
  !  <BR>
LOOP:                      		</TT>! declare label LOOP<TT> <BR>
VAR = 1.+VAR	        	</TT>! see remark b<TT>
<BR>
myframe,rval(2) = var+12.99
<BR>
WRITE/OUT </TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img70.gif"
 ALT="$\{$"><TT>myframe,rval(2)</TT><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img71.gif"
 ALT="$\}$"><TT> <BR>
myframe[@10,@20] = 20.0-</TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img72.gif"
 ALT="$\{$"><TT>myframe,rval(2)</TT><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img73.gif"
 ALT="$\}$"><TT> <BR>
WRITE/OUT </TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img74.gif"
 ALT="$\{$"><TT>myframe[@10,@20]</TT><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img75.gif"
 ALT="$\}$"><TT> <BR>
mytable,:DEC,@7 = </TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img76.gif"
 ALT="$\{$"><TT>myframe[@10,@20]</TT><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img77.gif"
 ALT="$\}$"><TT>*2.0
<BR>
WRITE/OUT </TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img78.gif"
 ALT="$\{$"><TT>mytable,:DEC,@7</TT><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img79.gif"
 ALT="$\}$"><TT> <BR>
WRITE/OUT " " <BR>
IF VAR .LE. </TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img80.gif"
 ALT="$\{$"><TT>P2</TT><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img81.gif"
 ALT="$\}$"><TT> GOTO LOOP		</TT>! go to label LOOP,
  if VAR <IMG
 WIDTH="23" HEIGHT="39" ALIGN="MIDDLE" BORDER="0"
 SRC="img82.gif"
 ALT="$\leq$">
contents of P2</BLOCKQUOTE>Then the command <TT>@@ exa6 1.0 5.2</TT> will yield:<BLOCKQUOTE>
<TT>1.72900E+01  <BR>
2.71000E+00  <BR>
5.42000E+00  <BR>
   <BR>
1.82900E+01  <BR>
1.71000E+00  <BR>
3.42000E+00 </TT></BLOCKQUOTE>&nbsp;&nbsp;
<BR>
Remark A:
<BR>
Parameter <TT>P1</TT> is implemented as a character keyword. Therefore, 
  we have to use <IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img83.gif"
 ALT="$\{$"><TT>P1</TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img84.gif"
 ALT="$\}$"><TT> * 3.3</TT> in the expression to convert the
character data in <TT>P1</TT> to numerical data (both operands must be numeric).
<BR>
If we had written <TT>VAR = P1 * 3.3</TT>, MIDAS would have protested because 
in the righthand expression
we would have tried to multiply a char. string with a float.
<BR>
&nbsp;&nbsp;
<BR>
Remark B:
<BR>
Here we use keyword <TT>VAR</TT> directly (i.e. without curly brackets) since
ist's a float keyword, so both operands of the righthand expression are
of numeric type.
<BR>
&nbsp;&nbsp;
<BR><BLOCKQUOTE>
<DIV ALIGN="CENTER">
<B>Note</DIV>
<I>For character keywords <TT>COMPUTE/KEYWORD</TT> only supports character
  concatenation (`//').
  If you want to write a character string into a character keyword, use 
  <TT>WRITE/KEYWORD</TT> instead.</I></B></BLOCKQUOTE>&nbsp;&nbsp;
<BR>
To recapitulate it you must use curly brackets
with keywords in <TT>COMPUTE/KEYWORD</TT> if you need to convert
   a character keyword to a numeric constant - but no conversion problems
   (like loss of precision) here. This is, for example, the case
   when you want to use the contents of the (character) parameters
 <TT>P1, ..., P8</TT>
   in a numeric expression, e.g.:
<BR>
<TT>outputr(3) = {p1}*outputr(12)</TT>
<BR>
This line would be translated to:
<BR>
<TT>outputr(3) = 0026*outputr(12)</TT>
<BR>
in the first pass over the command line, so the right hand side
contains a numerical constant and a keyword - a valid numerical expression.
<BR>
However, the Midas command line:
<BR>
<TT>outputr(3) = p1*outputr(12)</TT>
<BR>
would involve a char. and real keyword in the evaluation of the right hand
side and is therefore illegal syntax.
<BR>
&nbsp;&nbsp;
<BR>
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.
<BR>
The number of characters
used in the ASCII representation of a numerical symbol is controlled
via the command <TT>SET/FORMAT format</TT> for integer symbols and
<BR>
<TT>SET/FORMAT rformat,dformat</TT> 
for real (rformat) and double 
(dformat) precision symbols. Similar to FORTRAN the 
I-format (with leading zeroes not suppressed) is used for integer symbols
and real or double precision symbols
use the E-format, G-format or F-format:<BLOCKQUOTE>
<TT>!+ <BR>
  ! Example 7, MIDAS procedure exa7.prg <BR>
  !+ <BR>
WRITE/KEYWORD INPUTI 12		</TT>! set INPUTI(1) to 12<TT>
<BR>
WRITE/KEYWORD INPUTR 12.345	</TT>! set INPUTR(1) to 12.345<TT>
<BR>
                        </TT>! and set INPUTD(1) to 123456.98765432<TT>
<BR>
WRITE/KEYWORD INPUTD 123456.98765432
<BR>
WRITE/OUT </TT><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img85.gif"
 ALT="$\{$"><TT>inputi(1)</TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img86.gif"
 ALT="$\}$"><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img87.gif"
 ALT="$\{$"><TT>inputr(1)</TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img88.gif"
 ALT="$\}$"><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img89.gif"
 ALT="$\{$"><TT>inputd(1)</TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img90.gif"
 ALT="$\}$"><TT> <BR>
SET/FORMAT I2			</TT>! use format I2.2 for integer symbols<TT> <BR>
  </TT>! and use format E12.8 and G22.8 for real and double symbols<TT>
<BR>
SET/FORMAT E12.8,G22.8 <BR>
WRITE/OUT </TT><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img91.gif"
 ALT="$\{$"><TT>inputi(1)</TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img92.gif"
 ALT="$\}$"><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img93.gif"
 ALT="$\{$"><TT>inputr(1)</TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img94.gif"
 ALT="$\}$"><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img95.gif"
 ALT="$\{$"><TT>inputd(1)</TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img96.gif"
 ALT="$\}$"><TT> <BR>
SET/FORMAT i5			</TT>! use format I5.5 for integer symbols<TT> <BR>
  </TT>! and use format F12.4 and E22.13 for real and double symbols<TT>
<BR>
SET/FORMAT f12.4,e22.13 <BR>
WRITE/OUT </TT><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img97.gif"
 ALT="$\{$"><TT>inputi(1)</TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img98.gif"
 ALT="$\}$"><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img99.gif"
 ALT="$\{$"><TT>inputr(1)</TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img100.gif"
 ALT="$\}$"><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img101.gif"
 ALT="$\{$"><TT>inputd(1)</TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img102.gif"
 ALT="$\}$"></BLOCKQUOTE>The command <TT>@@ exa7</TT>  will yield:<BLOCKQUOTE>
<TT>0012 1.23450E+01 1.23457E+05	</TT>default is I4 and E15.5,E15.5<TT>
<BR>
12 1.23450003E+01 1.23456988E+05 </TT>uses I2 and E12.8,G22.8<TT>
<BR>
00012 12.345 1.2345698765432E+05		</TT>uses I5 and F12.4,E22.13</BLOCKQUOTE>If you want to omit any leading zeroes for integer symbols use <TT>SET/FORMAT
I1</TT>, then only the necessary digits will be displayed.<BLOCKQUOTE>
<DIV ALIGN="CENTER">
<B>Note</DIV>
<I>Use <TT>SET/FORMAT f-format</TT> to only change the format for real symbols and
<TT>SET/FORMAT ,f-format</TT> to only change the format for double symbols.</I></B></BLOCKQUOTE>&nbsp;&nbsp; <BR>
The format which is specified via the SET/FORMAT command must be set
individually in the body of each procedure.
For backward compatibility the default is <TT>SET/FORMAT I4 
E15.5,E15.5</TT> (format I4 for integer values, E15.5 for real and double precision 
values).

<P>
This represents a hidden danger with numeric (especially double precision) 
data because you might loose precision. Consider the following example:<BLOCKQUOTE>
<TT>!+ <BR>
  ! Example 7a, MIDAS procedure exa7a.prg <BR>
  !+ <BR>
inputd = 1234.55667701
<BR>
write/keyword outputd/d/1/1 </TT><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img103.gif"
 ALT="$\{$"><TT>inputd</TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img104.gif"
 ALT="$\}$"><TT>
<BR>
set/format ,f20.10
<BR>
write/out </TT><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img105.gif"
 ALT="$\{$"><TT>outputd(1)</TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img106.gif"
 ALT="$\}$"></BLOCKQUOTE>
<P>
When executing <TT>@@ exa7a</TT>
you will get 1234.5601 instead of 1234.55677701
 even though you used the
   <I>large</I> format f20.10 for the representation of keyword OUTPUTD.
   What happened? Well, let's show the substitutions, so we do
<BR>
<TT>Midas &gt; echo/full</TT>
<BR>
<TT>Midas &gt; @@ exa7a</TT>
&nbsp;&nbsp;
<BR>
and we get:<BLOCKQUOTE>
<TT>1 &gt; inputd = 1234.55667701
<BR>
1 &gt; write/keyword outputd/d/1/1 </TT><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img107.gif"
 ALT="$\{$"><TT>inputd</TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img108.gif"
 ALT="$\}$"><TT>
<BR>
write/keyword outputd/d/1/1 1.23456E+03
<BR>
1 &gt; SET/FORMAT ,f20.10
<BR>
1 &gt; WRITE/OUT </TT><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img109.gif"
 ALT="$\{$"><TT>outputd</TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img110.gif"
 ALT="$\}$"><TT>
<BR>
WRITE/OUT 1234.5601
<BR>
1234.5601</TT></BLOCKQUOTE>&nbsp;&nbsp;
<BR>
So keyword OUTPUTD got the contents of INPUTD formatted according to the
default format for double precision values (e15.5), which yields 1234.560 ...
<BR>
&nbsp;&nbsp;
<BR>
If we change to:<BLOCKQUOTE>
<TT>!+ <BR>
  ! Example 7b, MIDAS procedure exa7b.prg <BR>
  !+ <BR>
set/format ,f20.10
<BR>
inputd = 1234.55667701
<BR>
write/keyword outputd/d/1/1 </TT><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img111.gif"
 ALT="$\{$"><TT>inputd</TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img112.gif"
 ALT="$\}$"><TT>
<BR>
write/out </TT><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img113.gif"
 ALT="$\{$"><TT>outputd</TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img114.gif"
 ALT="$\}$"></BLOCKQUOTE>   (and turn the echo off) we get from <TT>@@ exa7b</TT> the output
   1234.55677701  as expected.
<BR>

<P>
So it's good practice to always put <TT>SET/FORMAT</TT> into the begin of
your procedure if you use substitutions.
<BR>
&nbsp;&nbsp;
<BR>
However, the best would be to use no substitution at all via:<BLOCKQUOTE>
<TT>!+ <BR>
  ! Example 7c, MIDAS procedure exa7c.prg <BR>
  !+ <BR>
inputd = 1234.55667701
<BR>
outputd = inputd
<BR>
SET/FORMAT ,f20.10
<BR>
WRITE/OUT </TT><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img115.gif"
 ALT="$\{$"><TT>outputd</TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img116.gif"
 ALT="$\}$"><TT>
<BR></TT></BLOCKQUOTE>Now, we get from <TT>@@ exa7c</TT> the output 1234.55677701  as expected and
we don't have to worry about the <TT>SET/FORMAT</TT> command.
<BR>
&nbsp;&nbsp;
<BR>
Substitution begins inside the curly brackets, starting at the deepest nested
level:<BLOCKQUOTE>
<TT>WRITE/OUT </TT><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img117.gif"
 ALT="$\{$"><TT>IN_A</TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img118.gif"
 ALT="$\}$"><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img119.gif"
 ALT="$\{$"><TT>INPUTC(1:3)</TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img120.gif"
 ALT="$\}$"></BLOCKQUOTE>will display <TT>SPIRALABC</TT> on the terminal, if key IN_A contains the string
<TT>SPIRAL</TT> and key INPUTC(1:3) the string <TT>ABC</TT>. 
<BR>
It is sometimes necessary to substitute symbols in a nested order:<BLOCKQUOTE>
<TT>!+ <BR>
  ! Example 8, MIDAS procedure exa8.prg <BR>
  !+ <BR>
DEFINE/PARAM P1 myframe IMA "Enter name for input frame: " <BR>
SET/FORMAT F5.1 <BR>
WRITE/OUT </TT><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img121.gif"
 ALT="$\{$"><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img122.gif"
 ALT="$\{$"><TT>P1</TT><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img123.gif"
 ALT="$\}$"><TT>,STEP(1)</TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img124.gif"
 ALT="$\}$"></BLOCKQUOTE>the command <TT>@@ exa8 </TT> will force the Monitor to substitute the last
command line in <TT>exa8.prg</TT> first to:&nbsp;&nbsp;
<TT>WRITE/OUT </TT><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img125.gif"
 ALT="$\{$"><TT>myframe,STEP(1)</TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img126.gif"
 ALT="$\}$">
and then yield:&nbsp;&nbsp;
<TT>20.5</TT> <BR>
assuming that descriptor <TT>STEP</TT> of <TT>myframe.bdf</TT> contains
<TT>20.5</TT> as first element. 
This example also illustrates the concept of recursive substitution<A NAME="2124">&#160;</A>.
<BR>
&nbsp;&nbsp;
<BR>
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 <TT>mykey</TT>.
<BR>
Setting keyword <TT>mykey</TT> once to "&gt;outfile" or "&gt;terminal"
if you want output to
a file or not together with the command line <TT>WRITE/TABLE
mytab </TT><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img127.gif"
 ALT="$\{$"><TT>mykey</TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img128.gif"
 ALT="$\}$">
&nbsp;in your procedure will <I>not</I> work!
<BR>
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...
<BR>
Instead, setting <TT>mykey</TT> to "outfile" or "terminal" and changing
the command line to: &nbsp;&nbsp;<TT>WRITE/TABLE mytab &gt;</TT><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img129.gif"
 ALT="$\{$"><TT>mykey</TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img130.gif"
 ALT="$\}$">
<BR>
will do the intended switching of output to a file or terminal.
<BR>
&nbsp;&nbsp;
<BR>

<P>
<HR>
<!--Navigation Panel-->
<A NAME="tex2html989"
 HREF="node41.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next"
 SRC="icons.gif/next_motif.gif"></A> 
<A NAME="tex2html985"
 HREF="node38.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up"
 SRC="icons.gif/up_motif.gif"></A> 
<A NAME="tex2html979"
 HREF="node39.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous"
 SRC="icons.gif/previous_motif.gif"></A> 
<A NAME="tex2html987"
 HREF="node1.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents"
 SRC="icons.gif/contents_motif.gif"></A> 
<A NAME="tex2html988"
 HREF="node216.html">
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index"
 SRC="icons.gif/index_motif.gif"></A> 
<BR>
<B> Next:</B> <A NAME="tex2html990"
 HREF="node41.html">DO Loops</A>
<B> Up:</B> <A NAME="tex2html986"
 HREF="node38.html">MIDAS Command Language</A>
<B> Previous:</B> <A NAME="tex2html980"
 HREF="node39.html">Passing Parameters in MIDAS</A>
<!--End of Navigation Panel-->
<ADDRESS>
<I>Petra Nass</I>
<BR><I>1999-06-09</I>
</ADDRESS>
</BODY>
</HTML>