types 

algebra: variables: types


Undefined

A variable has type Undefined if:

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.


String

Strings are character sequences.

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`


Number

Numbers are stored in single machine precision. No distinction is made between reals and integers. Thus, they are the equivalent of INTEGER and REAL combined in Fortran and of float and int in C.

The numbers 0, 1, 2 and PI are constants, there are also predefined globals of this type.


Logical

There are only 2 logical values: True and False. They are written as such, without the dots that are used in Fortran. There is no C equivalent of this data type; instead C uses the integer value 1 to represent True and 0 for False.

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.


Histogram

Histograms are used to investigate statistical properties of a quantity, e.g. the distribution of the gain in an RPC or the arrival time distribution in a drift chamber. Histograms consist of a series of so-called bins, which each count the number of times the quantity being histogrammed has a value in the range covered by the bin.

Garfield histograms are currently 1-dimensional only, and they have adjacent, equal size bins. They come in 2 flavours:

Autorange histograms are assigned a range on the basis of the first entries that the histogram receives. Automatic range setting is requested by specifying the AUTOSCALE option when the histogram is booked. As long as the range of an autorange histogram has not been set, arithmetic can not be applied to it nor can the histogram be plotted. Autorange histograms can however, at any stage, be written out to a file and retrieved.

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)/3
Each 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.


Matrix

You can, during a Garfield run, create matrices, carry out operations on them, store them for later use etc.

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:

  1. Addressing outside the array bounds is not permitted.
  2. A 2\&times;3-Matrix is not, as in Fortran, equivalent to a 6-Matrix - the indexing expression consists of 2 parts in a 2\&times;3-Matrix and of only 1 part in a 6-Matrix.
  3. Keep in mind that the number of dimensions does not change, A[;1] is a 2-dimensional matrix ! Use RESHAPE_MATRIX if you wish to transform a 1\&times;n-matrix to an n-matrix, or use the NUMBER function to change a 1\&times;1\&times;...\&times;1-matrix to a number.


Go to the top level, to algebra, to variables, to types, to the topic index, to the table of contents, or to the full text.

Formatted on 21/01/18 at 16:55.