Commands can be executed conditionally by using the 'if' command. Analogous to FORTRAN, the if-control structure takes the following form:
if ( <logical expression> ) then
...commands to be executed ...
elseif ( <logical expression> ) then
...commands to be executed ...
else
...commands to be executed ...
endif
The logical expressions are explained in section 6.3. Enclosed within an if block any valid KUPLOT command can be used. This includes calls to the sublevels further if blocks, do loops or macros, even if these macros contain if blocks or do loops themselves. The 'elseif' and 'else' section is optional. The maximum level of nesting is limited by the parameter MAXLEV in the file 'doloop.inc'. If necessary adjust this parameter to allow for deeper nesting. All commands from the first 'if' command to the corresponding 'endif' are read and stored in an internal array. This array can take at most 'MAXCOM' (defined in file 'doloop.inc' as well) commands at every level of nesting. If lengthy macro files are included in the do loop, this parameter might have to be adjusted.
If an if block (or a do loop) needs to be terminated, the 'break' command will perform this function. The parameter on the 'break' command line gives the number of nested levels of 'do' and 'if' blocks to be terminated. The interpreter will continue execution with the first command following the corresponding 'enddo' or 'endif' command. See the example in section 6.5 for further explanations.
1 load xy,test.dat
2 #
3 do i[1]=1,np[1]
4 if(dy[1,i[1]].gt.0.0) then
5 y[1,i[1]]=(1.0+0.1*(0.5-ran(0)))*y[1,i[1]]
6 endif
7 enddo
The example listed above illustrates the use of loops and conditional
statements within KUPLOT. Again, the line numbers are given for easy
reference and not part of the actual KUPLOT input. First a 1D data
set is loaded (line 1). In line 3 starts a do-loop over all data points of
data set 1. The variable np[1] contains this information (see Table
6.1 in section 6.1). In this example a
random
noise shall be added to all data points with
.
The
conditional statement in line 4 is true for those points. Since the
function 'ran' produces a uniformly distributed pseudo random number in
the range 0.0 to 1.0, the factor the y-value is multiplied with (line 5)
ranges from 0.95 to 1.05.