Symbol Evaluation Rules

Follow

Once defined, a symbol variable may be used on any succeeding command line. A symbol variable is identified to the input interpreter by preceding the variable name with a $ sign. The input interpreter identifies the variable name and substitutes the value of the variable in its place. Standard syntax rules require that the variable name must be delimited by blanks and cannot contain embedded blanks. The following example illustrates this point. The values of variable N1 and N2 are defined and then used to compute the value of N3.

symb n1 = 20 
symb n2 = 40
symb n3 = $n1 + $n2

The input interpreter performs variable substitution in a single pass from right to left as shown here.

symb n4 = $n1 + $n2 + $n3     /*<-- parser starts from here and works to the left side

This approach allows for variable names to be composed of other variables as shown below. Several examples of the symbol substitution functionality are:

symb n = 3
symb sum3 = 300.7
symb name = sum3
symb test1 = $sum$n
symb test2 = $$name

where, for the last assignment statement, the interpreter first evaluates $NAME to SUM3 before proceeding to evaluate $SUM3 and consequently, the value of TEST2 will be 300.7. Similarly, TEST1 will also be set to 300.7 since $N will first be evaluated to 3 before proceeding to evaluate $SUM3.

In certain situations, the user may need to guide the input interpreter by using parenthesis to physically denote the name of Symbol variables to evaluate. For example:

symb nrun = 3
symb name = a
text file = model$(name)$(nrun)results

This sets text variable FILE to MODELA3RESULTS. If the parentheses are not included, the interpreter does not evaluate the variable names properly.

The input interpreter identifies a variable name to evaluate as the string between the $ and a terminating character. Terminating characters include: blank, period, comma, $, ( , ) , and /. Therefore, the following text string representing a file name would be set to /USA/RUN1.20

symb job = 1
symb project = usa
symb index = 20
text filename = /$project/run$job.$index

Controlling Formats for Variable Substitutions in Text Strings

When arithmetic operations are performed, the full numerical precision of all variables is maintained throughout the Symbol substitution process. However, when performing symbol substitution within text strings to generate labels, filenames, etc., a user may need control over the formatting of the text substitution. Typically, a user will want to control the appearance of the values of floating point variables. For example:

symb theta = 90.5
symb phi = 25.5
text filename = data.theta.$theta.phi.$phi

if a user generates a file name containing the value of real variables THETA and PHI, the default format for a floating point value substitution is (g15.7) in Fortran convention which produces the following value for FILENAME:

  • data.theta.90.50000.phi.25.50000

To change the format, a user must define the format of the variable of interest using Fortran format syntax for a single variable. The symbol name must be followed immediately by the % sign and then a valid single variable format enclosed in parentheses The following illustrates the use of the formatting construct.

text filename = data.theta.$theta.phi.$phi%(f5.1)

Once a format for a particular variable type is specified, the default format for that type of variable is set to the format declaration and used in interpreting the rest of the input line. As the input interpreter evaluates the line from right to left, declaring a format for PHI causes the same format to be used for THETA, producing the following value for FILENAME:

  • data.theta.90.5.phi.25.5

Note that leading blanks produced by a specified format are stripped by default during the substitution process. Succeeding input lines revert to the original default format for real variable substitutions.

In certain cases, a user may not want the leading blanks stripped during the substitution process. Embedding the “<” character between the % and the start of the format specification causes any leading blanks to be present in the substituted string. Embedding the “>” character between the % and the start of the format specification causes any leading blanks to be filled with zeros in the substituted string. For example, the following statements:

symb n1 = 20
symb data1 = 30.5238
text label1 = 'values:$n1 & $data1'
text label2 = 'values:$n1%(i5) & $data1%(f6.1)'
text label3 = 'values:$n1%<(i5) & $data1%<(f6.1)'
text label4 = 'values:$n1%>(i5) & $data1%>(f6.1)'

produce the following results:

  • label1 = values:20 & 30.52380
  • label2 = values:20 & 30.5
  • label3 = values: 20 & 30.5
  • label4 = values:00020 & 0030.5

THE IF, ELSEIF, ELSE and ENDIF STATEMENTS

Symbol supports the IF, ELSEIF, ELSE and ENDIF statements in order to provide structured, conditional branching constructs. An example of the use of these statement is:

if ( $n eq 1 ) then
symb comment = first
elseif ( $n eq $nlast ) then
symb comment = last
else
symb comment = middle
endif

An IF conditional must begin with an IF statement and terminate with an ENDIF statement. The basic form of the IF statement is:

  • IF ( datum1 op datum2 ) THEN

where op is any of the conditional operators: EQ, NE, LT, LE, GT and GE whose meanings correspond to their usage in Fortran. datum1 and datum2 can be either numeric or character data. Multiple conditionals may be used in a single IF statement by using the AND or OR Boolean operators. The order of conditionals may be controlled through the use of parenthesis. Several examples are:

if ( $n eq 1 and $x ne 0.0 ) then

and

if ( $n eq 1 and ( $x ne 0.0 or $y ne 0.0 ) ) then

The form of the ELSEIF statement is similar to the IF statement.

The ELSE and ENDIF statements have no other input parameters on the command line.

Once an IF statement is encountered, the following input lines down to the terminating ENDIF statement are read in and stored as an IF procedure which is then invoked. If an ENDIF statement is accidentally omitted from the input file, the code will read to the end of the file and terminate with an error.

Nested sets of IF statements are allowed.

An example is:

if ( $n eq 1 ) then
if ( $iset eq 1 ) then
symb comment = first1
elseif ( $iset eq 2 ) then
symb comment = first2
endif
elseif ( $n eq $nlast ) then
if ( $iset eq 1 ) then
symb comment = last1
elseif ( $iset eq 2 ) then
symb comment = last2
endif
endif

WARNING: 1) Including the STOP command within an IF/ELSEIF logic block will result in termination of the job at the time the STOP command is read. Use SYMB #EXIT to provide a code termination statement within an IF/ELSEIF logic block.
2) In-line functions on and IF/ELSEIF line are not interpreted. e.g., do not use use commands such as: IF ( ABS ( $N ) EQ 1 ) THEN

THE END$ STATEMENT

The END$ statement identifies a line in the input command file and has the form:

 end$ linename

where:

  • linename = from 1 to 8 character name identifying this line

The program does not require that linename be unique. That is, more than one END$ statement can have the same name.

The END$ statement is used to identify the location in the input stream to branch to for GOTO statements and the ending points of do loops and procedures defined with the DO and PROC statements, respectively.

0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.