CERN home page CERN home page Consult pages Consult pages Writeups at CERN Writeups at CERN Garfield pages Garfield pages Help Help algebra algebra variables variables types types Table of contents Keyword index

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 constant of this type, NILL, is predefined.


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 = operators. 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

All numbers are stored in single machine precision. No distinction is made between reals and integers.

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.

Logicals in Garfield are not equivalent to numbers, i.e. one can not normally replace True by 1.

Both True and False are stored as constants, there are also some predefined globals of this type.


Histogram

Garfield histograms are currently 1-dimensional only.

Histograms are usually created with a call to BOOK_HISTOGRAM. Several instructions can generate histograms as part of their output.

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 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.

Parts of matrices can be addressed as illustrated in the following examples. 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 1xn-matrix to an n-matrix, or use the NUMBER function to change a 1x1x...x1-matrix to a number.

1-dimensional matrix:

     A = (9 8 7)     A[1,2,3,1] = (9 8 7 9)

2-dimensional matrix:

         ( 1 2 3 )             ( 3 2 )
     A = ( 2 4 6 )   A[3,2;] = ( 6 4 )     A[;1] = ( 1 2 3 )
         ( 3 6 9 )             ( 9 6 )

One may use a 1-dimensional matrix to index elements of another matrix. This 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`)

Notes:

  1. Addressing outside the array bounds is not permitted.
  2. A 2x3-Matrix is not, as in Fortran, equivalent to a 6-Matrix - one has to use both indices in a 2x3-Matrix and only a single index in a 6-Matrix.

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 15/01/01 at 23:07.