String Functions - Ultramarine.com String Functions

Perhaps one of the more useful concepts MOSES employs is the "String Function." A string function converts an input string into another string, and the general syntax of a string function is:

     &FUNCTION(ARG(1), ARG(2), ......)

There are quite a few things which can be accomplished with string functions. In the next several sections specific string functions will be discussed, but some examples are a string function is o check if a variable has been defined. The function:


     &V_EXIST(VARNAM)

will return the string, .TRUE. if the variable VARNAM has been defined. If VARNAM has not been defined, a value of .FALSE. is returned. Another useful string function is &FORMAT which is used for formatting, and its form is:


     &FORMAT(FMT, STRING)

Here FMT is a formatting instruction and STRING is the string to be formatted. If STRING is a number, then FMT can be a FORTRAN format (e.g. F10.2, I3, etc.). Otherwise, FMT must be either: UPPER, LOWER, FIRST, or COMMA. For UPPER, the entire string will be made into upper case characters, and for LOWER, the converse will occur. FIRST transforms only the first character in the string into upper case. Finally, COMMA adds a comma after each token in the string and an "and" between the last two tokens. FMT can have at most 8 characters.

To compress a logical phrase, one can use the function:


     &LOGICAL(LPHRASE)

Here, a logical phrase is a string of numbers, characters, and logical variables combined by logical operators. Here, numbers are any string which can be converted to a number and logical variables are strings with values of either .TRUE. or .FALSE.. Any two tokens can be compared by the logical operators: .EQ. and .NE.. For numbers, four additional operators are available: .LT., .LE., .GT., and .GE.. These six operators denote respectively: equal, not equal, less than, less than or equal, greater than, and greater than or equal.

A single logical variable can be modified by the operator .NOT., and two logical variables can be combined by the two operators .AND. and .OR.. As examples, consider:

     &LOGICAL(A .EQ. A)
     &LOGICAL(.NOT. A .EQ. A .AND. B .EQ. B)
     &LOGICAL(5 .LE. 4)
     &LOGICAL(5 .GT. 4 .OR. A .EQ. B)

The strings resulting from these functions would be respectively: .TRUE., .FALSE., .FALSE., and .TRUE..