|
|
Dataplot Program Control
Types of Program Control Structures
|
Dataplot provides the following types of program control
structures:
|
|
|
Looping
|
Looping Can Often Be Avoided
|
Most Dataplot programs do not need loops. In FORTRAN, for
example, the use of loops is commonly used for intermediate
calculations en route to the final output. In Dataplot,
however, the existence of numerous high-level graphics and
analysis commands frequently obviates the need for such
intermediate looping.
|
Loops Implemented with the LOOP Command
|
If a loop is required, it is initiated with the
LOOP command. The general
syntax is
|
The loop index will be a parameter in the usual Dataplot sense. As the loop is being executed, the loop index will be successively changed (depending on start, increment, and stop values). The
Loop Index Parameter can be Used in Computations
|
The loop index parameter is global and can be used by any
calculation or specification within the loop. Thus
|
will result in the sequence 1, 2, 3, ..., 9, 10 being printed. You should not modify the value of the loop index parameter. If you do, you will obtain unpredictable (and undesirable) results.
Some Examples
|
The following loop
|
LET A2(D) = A LET B2(D) = B LET S(D) = RESSD The following loop
ERASE LOOP FOR I = 10 10 80
LET IX2=IX1+10 LET IY2=IX2 BOX IX1 IYl IX2 IY2
Values in the LOOP Command Can Be Either Numbers or Parameters
|
As is usual, the start value, increment, and stop
value can be either numbers or parameters. Thus
|
LET B = 1 LET C= 5 LOOP FOR L = A B C
BREAK LOOP
|
Loops can prematurely terminated with the
BREAK LOOP command.
|
Checking the Value of the Loop Index Parameter
|
The checking of the loop index parameter is done at the
beginning of the loop. It is possible for a loop
not to be executed at all (if the increment is
positive and the stop value is smaller than the
start value; or if the increment is negative and
the stop value is larger than the start value); thus
|
LOOP FOR A = 1 1 STOP
Loops Can Be Nested Seven Deep
|
Loops can be nested seven deep. Thus to generate plots of Y
versus X for each combination of variables OP (with three
levels), LAB (with five levels), and DAY (with five levels),
one could enter
|
LOOP FOR L = 1 1 5 LOOP FOR D = 1 1 5
END OP LOOP END OF LOOP
Using the Substitution Character (^) in Loops
|
To have the 60 plots sequenced and to have them properly
labeled with the current operator, lab, and day value, one
could use the ^ keyword in conjunction with the ..LABEL command,
as follows:
|
LOOP FOR 0 = 1 1 3 LOOP FOR L = 1 1 5 LOOP FOR D = 1 1 5
X2LABEL LAB = ^L X3LABEL DAY = ^D PLOT Y X SUBSET OP O 5UBSET LAB L SUBSET DAY D END OF LOOP END OF LOOP
CALL Command in Loops
|
Any valid Dataplot command can be executed within the context
of a loop. A particular1y important command is the
CALL command that alllows a
subprogram to be referenced. Thus for more complicated
applications, it may be of interest to set up a loop in the
main program and then specify a desired set of operations in
a subprogram, as in
|
LOOP FOR L = 1 1 4 LOOP FOR D = 1 1 5
END OF LOOP END OF LOOP
X2LABEL LAB = ^L X3LABEL DAY = ^D PLOT Y X SUBSET OP 0 SUBSET LAB L SUBSET DAY
|
|
Conditional Execution
|
Two Methods for Conditional Execution
|
Conditional execution of statements is handled in
two different ways in Dataplot:
|
SUBSET/ |
EXCEPT/ FOR Clauses
Method 1 is the most popular and is the most straightforward way
of conditionally executing commands. It is a Dataplot feature
that any graphics or analysis command can be conditionally
executed (that is, have its execution restricted to a certain
subset of data, or have its execution contingent on the value of
certain variables) by simply appending the qualification to the
end of the command line. As far as the analyst is concerned,
the primary general objective is to generate a plot, carry out
a fit, carry out an analysis of variance, etc., whereas the
restriction of such an activity to a specific subset is, in a
sense, an afterthought. This being the case, the Dataplot
structure is to have the Dataplot command (PLOT, FIT, ANOVA,
etc.) appear first and foremost on the line, and then to simply
append the qualification to the end of the line. Thus it is
easy and natural to extend
|
FIT Y = A+B*LOG(X) ANOVA Y X1 X2 X3
FIT Y = A+B*LOG(X) SUBSET X > 50 EXCEPT X = 140 ANOVA Y X1 X2 FOR I = 1 1 40
IF Command
|
Method 2 is a much less popular way of conditionally executing
statements, but does have occasional application. To
conditionally execute a "chunk" of Dataplot code, one can use
the IF command in combination with the END OF IF (or END
IF) command. The general form for the IF command is
|
Some Examples of the IF Command
|
The conditionality specification is done in terms
of parameter values (as opposed to variable values
in the SUBSET/EXCEPT qualification). For example,
suppose a variable X has 100 values in it and it
is desired to determine the maximum value in X.
The easiest way to do this in Dataplot is to simply enter
|
LOOP FOR I = 1 1 100
IF XI > MAX
As a second example, suppose it is desired to determine that cambination of A and B (over a specified lattice of values) for which the L1 fit of A+LOG(B+X) is achieved. The easiest way to carry this out in Dataplot is
PRE-FIT A+LOG(B+X) FOR A = 1 1 10 FOR B = l00 20 200
LOOP FOR A = 1 1 10
LET PRED = A+LOG(B+X) LET RES = Y-PRED LET RES2 = ABS(RES2) LET SUMAD = SUM RES2 . IF SUMAD < MIN
LET B2 = B .
IF Statements Can Be Nested 10 Deep
|
IF statements can be nested up to 10 deep, as in
|
IF B > 7 IF C <= 100
END OF IF END OF IF
|
Any valid Dataplot statment can occur within the
context of the IF set of statements. A
particularly powerful entry is thc CALL statement
which allows subprograms to be executed.
Thus, for example, to conditionally execute
(only if the residuals standard deviation RESSD
from some fit is less than .1) a subprogram XYZ,
one could enter
|
IF Command Lightly Used in Dataplot
|
The IF capability in DATAPL0T is a low-level
capability (no one does IF as an end objective in
itself). Conditionally executing a chunk of code
is an elementary capability of any computer
language. In Dataplot, due to the existence of
high-level capabilities, and due to the
SUBSET/EXCEPT/FOR qualification capability, the IF
capability is only lightly used.
|
|
|
Subprograms
|
Subprograms are Independent Programs Stored in External
ASCII Files
|
The typical Dataplot program consists of a main prooram. The
existence of higher-level capabilities (e.g., PLOT, FIT, LET,
etc.) often precludes complicated nesting of subprograms.
However, subprograms can be included in Dataplot as needed.
|
Subprograms are completely independent programs in their own right and must be placed in separate mass storage files. Such subprograms are accessed via the CALL command and are identified by the name of the mass storage file in which the subprogram resides. These files are simply ASCII files that contain Dataplot commands. There is no special structure or compilation required.
Example
|
For example,
|
Rules for Subprograms
|
The following are the basic rules governing the use of
Dataplot subprograms.
|
Common Usages of Subprograms
|
The four most important ways in which subprogram
usage arises are as follows:
|
(where the parameter C is pre-defined but may also be redefined within the subprogram being called) would cause subprogram SIGMA to be called a variable number of times depending on how C is redefined within the loop.
Main Program Can Be Initiated With CALL
|
As one would expect, execution of a pre-stored
main program may be initiated in an identica1
fashion as one would execute a subprogram, namely
via the CALL command. Thus, for example, if the
analyst has signed onto Dataplot, and if a
pre-stored main program resides in a file called
A, then execution of the main program could start
with the entry of the statement
|
|
Creating Subprograms
|
Use Your Local Editor
|
The most common and most efficient method for
creating Dataplot subprograms is via the local
editor. That is, before the analyst enters
Dataplot, he/she enters into a file with
the local editor and creates a Dataplot program
and any needed Dataplot subprograms. There is no
substitute for an excellent local editor and the
analyst is encouraged to use such an editor for
creating Dataplot programs and subprograms.
|
Create Dataplot Subprogram on the Fly Using CREATE
|
One the other hand, it is at times convenient to
be able to create a Dataplot subprogram "on the
fly" while one is executing a Dataplot program. A
prime example of this is in the construction of
diagrammatic graphics in which one makes an
interactive pass at forming the diagram, stores
the commands that were used en route, and then
executes these commands as a block in a semi-interactive mode.
|
If one is running Dataplot interactively, one can automatically store the entered interactive command lines into a file by use of the CREATE command. For example, to instruct Dataplot that all subsequently keyed-in commands should be in a file XYZ.DP as they are being entered, the analyst would enter
|
Listing Subprograms - LIST
|
LIST Command
|
The LIST
command can be used to list the contents
of any file. Usually such a capability
is taken advantage of when the file
contains a subprogram, but it can also be used
when the file contains data. The usual convention
about periods following the file name is followed.
Thus to list the contents of the file XYZ, one enters
|
|
Date created: 06/05/2001
|