Sophie

Sophie

distrib > Mageia > 7 > i586 > by-pkgid > d2e0b949db9ebf58fe04ed755553fbf4 > files > 832

eso-midas-doc-17FEBpl1.2-3.mga7.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>Conditional Statements, Branching</TITLE>
<META NAME="description" CONTENT="Conditional Statements, Branching">
<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="node44.html">
<LINK REL="previous" HREF="node42.html">
<LINK REL="up" HREF="node38.html">
<LINK REL="next" HREF="node44.html">
</HEAD>
<BODY >
<!--Navigation Panel-->
<A NAME="tex2html1025"
 HREF="node44.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next"
 SRC="icons.gif/next_motif.gif"></A> 
<A NAME="tex2html1021"
 HREF="node38.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up"
 SRC="icons.gif/up_motif.gif"></A> 
<A NAME="tex2html1015"
 HREF="node42.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous"
 SRC="icons.gif/previous_motif.gif"></A> 
<A NAME="tex2html1023"
 HREF="node1.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents"
 SRC="icons.gif/contents_motif.gif"></A> 
<A NAME="tex2html1024"
 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="tex2html1026"
 HREF="node44.html">Special Functions</A>
<B> Up:</B> <A NAME="tex2html1022"
 HREF="node38.html">MIDAS Command Language</A>
<B> Previous:</B> <A NAME="tex2html1016"
 HREF="node42.html">Local Keywords</A>
<BR>
<BR>
<!--End of Navigation Panel-->

<H2><A NAME="SECTION00665000000000000000">&#160;</A> <A NAME="2180">&#160;</A><A NAME="2181">&#160;</A>
<A NAME="conditional-statements">&#160;</A>
<BR>
Conditional Statements, Branching
</H2>

<P>
As in FORTRAN&nbsp;77 any of the following forms of the <TT>IF</TT> statement  
may be used:<BLOCKQUOTE>
<TT>IF log_exp command	</TT>! command = any MIDAS command<TT>
<BR>
</TT>! with at most 4 params.</BLOCKQUOTE>
<P></P>
<BLOCKQUOTE>
<TT>IF log_exp THEN		</TT>! xyz = any logical expression<TT> <BR>
    ...
<BR>
ELSEIF log_exp THEN  	</TT>! uvw = any logical expression<TT> <BR>
    ...
<BR>
ELSE <BR>
    ...
<BR>
ENDIF</TT></BLOCKQUOTE>
<P></P>
<BLOCKQUOTE>
<TT>IF log_exp THEN <BR>
    ...
<BR>
ENDIF</TT></BLOCKQUOTE><TT>IF</TT> blocks may be nested up to 8&nbsp;levels deep in a procedure.
<BR>
The logical expression <TT>`log_exp'</TT> is of the form:<BLOCKQUOTE>
<TT>arg1 &nbsp;op&nbsp; arg2</TT></BLOCKQUOTE>where <I>arg1, arg2</I> are either names of keywords (this includes also
the names P1, ..., P8) or constants, and <I>op</I> may be
any of <TT>.EQ.</TT>, <TT>.NE.</TT>,
<TT>.GT.</TT>, <TT>.GE.</TT>, <TT>.LT.</TT> or <TT>.LE.</TT> (with the same meaning as
in FORTRAN&nbsp;77).
As with symbol substitution, specify single elements of an array and
substrings via,
e.g., <TT>OUTPUTI(7)</TT> and <TT>IN_B(2:15)</TT>.
<BR>
If we do<BLOCKQUOTE>
<TT>WRITE/KEYWORD INPUTC beer <BR>
WRITE/KEYWORD OUTPUTC wine <BR>
WRITE/KEYWORD INPUTR/R/1/3 1.,2.,3. </TT></BLOCKQUOTE>Then,<BLOCKQUOTE>
<TT>INPUTC .EQ. "beer"	</TT>is TRUE<TT>
<BR>
INPUTC .EQ. "BEER"	</TT>is also TRUE<TT>
<BR>
INPUTC .EQ. OUTPUTC	</TT>is FALSE<TT>
<BR>
INPUTC(2:2) .EQ. OUTPUTC(4:4) </TT>is TRUE<TT>
<BR>
INPUTR(2) .GT. 5.4	</TT>is FALSE</BLOCKQUOTE>In string comparisons upper and lower case characters are not distinguished in
order to guarantee case insensitivity.
<BR>
Character keywords can only be compared to character keywords or character
constants (which are enclosed by double quotes). This can become tricky
in conjunction with symbol substitution:<BLOCKQUOTE>
<TT>!+ <BR>
  ! Example 13a, MIDAS procedure exa13a.prg <BR>
  !+ <BR>
DEFINE/PARAM P1 ? N "Enter number: "
<BR>
DEFINE/MAXPAR 1 </TT>! only one parameter expected<TT>
<BR>
IF </TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img154.gif"
 ALT="$\{$"><TT>P1</TT><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img155.gif"
 ALT="$\}$"><TT> .EQ. 1  THEN <BR>
WRITE/OUT P1 = 1
<BR>
ELSE  <BR>
WRITE/OUT P1 is not = 1
<BR>
ENDIF</TT></BLOCKQUOTE>Entering <TT>@@ exa13a 1</TT> as well as <TT>@@ exa13a 001</TT> will give the expected
output message <TT>P1 = 1</TT> since the line
<TT>IF </TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img156.gif"
 ALT="$\{$"><TT>P1</TT><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img157.gif"
 ALT="$\}$"><TT> .EQ. 1  THEN</TT> 
has been converted in the first pass by the Monitor to
<BR>
<TT>IF 1 .EQ. 1  THEN</TT>  or <TT>IF 001 .EQ. 1 THEN</TT> <BR>
and the two integer constants are equal. Now, consider the almost identical
procedure <TT>exa13b.prg</TT>:<BLOCKQUOTE>
<TT>!+ <BR>
  ! Example 13b, MIDAS procedure exa13b.prg <BR>
  !+ <BR>
DEFINE/PARAM P1 ? N "Enter number: "
<BR>
DEFINE/MAXPAR 1 </TT>! only one parameter expected<TT>
<BR>
IF P1 .EQ. 1  THEN <BR>
WRITE/OUT P1 = 1
<BR>
ELSE  <BR>
WRITE/OUT P1 is not = 1
<BR>
ENDIF </TT></BLOCKQUOTE>Entering <TT>@@ exa13b 1</TT> will return the error message
<TT>invalid IF statement...</TT> and abort. Why?
<BR>
Well, in the <TT>IF</TT> statement above the contents of the character keyword P1,
which is the character `1', is compared to the integer constant 1, an invalid
comparison.
<BR>
We modify the procedure once more:<BLOCKQUOTE>
<TT>!+ <BR>
  ! Example 13c, MIDAS procedure exa13c.prg <BR>
  !+ <BR>
DEFINE/PARAM P1 ? N "Enter number: "
<BR>
DEFINE/MAXPAR 1 </TT>! only one parameter expected<TT>
<BR>
IF P1 .EQ. "1"  THEN <BR>
WRITE/OUT P1 = 1
<BR>
ELSE  <BR>
WRITE/OUT P1 is not = 1
<BR>
ENDIF</TT></BLOCKQUOTE>Now, entering <TT>@@ exa13c 1</TT> will work and yield
<TT>P1 = 1</TT> but <TT>@@ exa13c 001</TT> will output <TT>P1 is not = 1</TT> since the
string "001" is not equal to "1".
<BR>
&nbsp;&nbsp; <BR>
As another example let us see, how we can check if a parameter has been
entered at all:<BLOCKQUOTE>
<TT>!+ <BR>
  ! Example 14a, MIDAS procedure exa14a.prg <BR>
  !+ <BR>
DEFINE/PARAM P6 + NUMBER "Enter first input number: " <BR>
IF P6(1:1) .EQ. "+" THEN <BR>
WRITE/KEYWORD INPUTC NONE </TT>! no P6 entered, set INPUTC accordingly<TT> <BR>
ELSE <BR>
WRITE/KEYWORD INPUTI/I/7/1 </TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img158.gif"
 ALT="$\{$"><TT>P6</TT><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img159.gif"
 ALT="$\}$">! store contents of P6 in INPUTI(7)<TT> <BR>
WRITE/KEYWORD INPUTC YES </TT>!indicate, that INPUTI holds a valid number<TT> <BR>
ENDIF</TT></BLOCKQUOTE>However, if we also want to check the limits of the given number we have to
use the <TT>DEFINE/PARAMETER</TT> command again, because testing "<TT>+</TT>" 
against a numerical interval would lead to an error:<BLOCKQUOTE>
<TT>!+ <BR>
  ! Example 14b, MIDAS procedure exa14b.prg <BR>
  !+ <BR>
DEFINE/PARAM P6 + NUMBER "Enter first input number: " <BR>
IF P6(1:1) .EQ. "+" THEN <BR>
WRITE/KEYWORD INPUTC NONE </TT>! no P6 entered, set INPUTC accordingly<TT> <BR>
ELSE <BR>
DEFINE/PARAM P6 + NUMBER "Enter first input number: " 22,1024
<BR>
WRITE/KEYWORD INPUTI/I/7/1 </TT><IMG
 WIDTH="17" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img160.gif"
 ALT="$\{$"><TT>P6</TT><IMG
 WIDTH="16" HEIGHT="44" ALIGN="MIDDLE" BORDER="0"
 SRC="img161.gif"
 ALT="$\}$">! store contents of P6 in INPUTI(7)<TT> <BR>
WRITE/KEYWORD INPUTC YES </TT>!indicate, that INPUTI holds a valid number<TT> <BR>
ENDIF</TT></BLOCKQUOTE>Since, in the <TT>ELSE</TT> branch we know that parameter P6 is given, the default
value "<TT>+</TT>" itself is never tested against the interval [22,1024]. <BR>
&nbsp;&nbsp; <BR>
For testing multiple alternatives
use the <TT>BRANCH</TT> command. It has the syntax:
<BR>
<TT>BRANCH variable &nbsp;casea,caseb,...,casez &nbsp;labela,labelb,...,labelz</TT>.<BLOCKQUOTE>
<TT>!+ <BR>
  ! Example 15, MIDAS procedure exa15.prg <BR>
  !+ <BR>
DEFINE/PARAMETER P1 ? C "Enter method: "  <BR>
DEFINE/MAXPAR 1 </TT>! only one parameter expected<TT>
<BR>
  ! <BR>
  ! Use the first 2 characters of parameter P1 to distinguish the methods 
  BRANCH P1(1:2) AN,DI,HY ANALOG,DIGIT,HYBRID <BR>
  ! <BR> 
  ! fall through if no match ... <BR>
WRITE/OUT Invalid option - please try again <BR>
RETURN
<BR>
  ! <BR>
ANALOG:  <BR>
RUN ANALO <BR>
RETURN  <BR>
  ! <BR>
DIGIT:  <BR>
RUN DIGI <BR>
RETURN  <BR>
  ! <BR>
HYBRID:  <BR>
RUN HYBRI </TT></BLOCKQUOTE>Then, <TT>@@ exa15 ANALOG</TT> will execute the command <TT>RUN ANALO</TT> and
<TT>@@ exa15 digital</TT> or <TT>@@ exa15 di</TT> will run the program <TT>digi.exe</TT>.

<P>
<HR>
<!--Navigation Panel-->
<A NAME="tex2html1025"
 HREF="node44.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next"
 SRC="icons.gif/next_motif.gif"></A> 
<A NAME="tex2html1021"
 HREF="node38.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up"
 SRC="icons.gif/up_motif.gif"></A> 
<A NAME="tex2html1015"
 HREF="node42.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous"
 SRC="icons.gif/previous_motif.gif"></A> 
<A NAME="tex2html1023"
 HREF="node1.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents"
 SRC="icons.gif/contents_motif.gif"></A> 
<A NAME="tex2html1024"
 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="tex2html1026"
 HREF="node44.html">Special Functions</A>
<B> Up:</B> <A NAME="tex2html1022"
 HREF="node38.html">MIDAS Command Language</A>
<B> Previous:</B> <A NAME="tex2html1016"
 HREF="node42.html">Local Keywords</A>
<!--End of Navigation Panel-->
<ADDRESS>
<I>Petra Nass</I>
<BR><I>1999-06-09</I>
</ADDRESS>
</BODY>
</HTML>