All arithmetic is permitted between variables of this type and a variable of any other type. All such operations result in a variable of the type Undefined, with the exception of the TYPE function.
One of the pre-defined constants is of this type: NILL.
Strings are usually created by enclosing a series of characters in reverse quotes, as illustrated in the examples below.
Strings can be concatenated with the / operator and can be lexically compared with each other using the >, < and = operator. The functions NUMBER and STRING convert Strings to Numbers and vv. There is also a series of procedures that act on Strings: STRING_DELETE, STRING_INDEX, STRING_LENGTH, STRING_LOWER, STRING_MATCH, STRING_PORTION, STRING_REPLACE, STRING_UPPER, STRING_WORD and STRING_WORDS.
Strings are internally stored in a dynamic buffer which has a fixed maximum total size. The buffer remembers the length of each string. One does not declare the length of Strings since the length is implied by the initialisation and operations the string has undergone. The length of a string can vary in time.
There are no constant strings, but there are predefined globals of type String.
Examples:
Global gas_file `gas.dat`Global p=1 Global gas_file `gas_p`/string(p)/`.gas`
The numbers 0, 1, 2 and PI are constants, there are also predefined globals of this type.
Both True and False are stored as constants and there are several predefined globals of this type. Logicals can also be created by applying a comparison operator to variables of other data types:
Global equal `aaa`=`a`/`aa` Global bigger 5>2^2
Logicals can be acted upon with operators, as & (and) and | (or) as well as with the NOT, STRING and TYPE functions.
Logicals are commonly used in the conditions of If_lines, If_blocks and Do loops:
Do Say "Quit ? Please reply with True or False" Parse terminal quit If type(quit)#`Logical` Then Say "Please answer with True or False" Elseif quit Then Say "Quit" Leave Endif Enddo
Logicals in Garfield are not equivalent to numbers, i.e. one can not normally replace True by 1. Similarly, one can not apply mixed arithmetic between Logicals and Numbers.
Garfield histograms are currently 1-dimensional only, and they have adjacent, equal size bins. They come in 2 flavours:
Histograms are usually created with a call to BOOK_HISTOGRAM. Several instructions can generate histograms as part of their output.
Histograms can be subject of most of the ordinary arithmetic operators and functions. Mixed arithmetic between Numbers and histograms is permitted and results in histograms.
Example:
Call get_histogram(part1,`file1.hist`,`delay`) Call get_histogram(part2,`file2,hist`,`delay`) Call get_histogram(part3,`file3,hist`,`delay`) Global delay=(part1+part2+part3)/3Each of a series of jobs, run in parallel, has created an histogram called DELAY, filled it, and written it to a file. The histograms from the 3 files are retrieved and averaged.
Histograms can also be operated on by a series of procedures, For instance, histograms can, by means of the WRITE_HISTOGRAM_RZ procedure, be written out to an RZ file for further processing with PAW.
There are no predefined constant histograms, nor globals of this type.
Matrices can be created in a variety of ways:
The usual arithmetic operators and functions can be applied to matrices as if they were numbers. Mixed arithmetic between Numbers and matrices is permitted and results in matrices. Applying arithmetic to entire matrices is much faster than looping over the elements.
Parts of matrices can be addressed with the following syntax:
Some examples for a 1-dimensional matrix:
A = (9 8 7) A[1,2,3,1] = (9 8 7 9) A[1+ROW(2)] = (8 7)The ROW function returns a 1-dimensional Matrix that contains the numbers 1 to the value of the argument, in this case the numbers 1 and 2. Indexing using 1-dimensional matrices is particularly convenient to extract a large sub-matrix, such as in the following example where one only fits the central portion of a cosine curve with a parabola:
Global x=-pi+2*pi*(row(500)-1)/499 Global y=cos(x) Call fit_polynomial(x[200+row(100)],y[200+row(100)],0.001, ... a0,a1,a2,ea0,ea1,ea2,`plot`)
When indexing a 2-dimensional matrix, one needs a semi-colon to separate the indices along the 1st and 2nd dimension. Remember that an empty indexing part selects that entire dimension:
( 1 2 3 ) ( 3 2 ) A = ( 2 4 6 ) A[3,2;] = ( 6 4 ) A[;1] = ( 1 2 3 ) ( 3 6 9 ) ( 9 6 )
Notes:
Formatted on 21/01/18 at 16:55.