Campbell Scientific CR9000X Measurement and Control System User Manual

Page 180

Advertising
background image

Section 5. Program Declarations

Variables declared by Public within a subroutine or function are local to that
subroutine or function. The same variable name can be used within other
subroutines or functions or as a global variable without conflict.

THE PUBLIC STATEMENT HAS THESE PARTS:

VarName This parameter is the name for the defined variable. Variables names can be up

to 16 characters in length. Note, however, when outputting the variable to a
data table, the suffix containing the output type (e.g., _avg) is appended to the
end of the variable name. Therefore, to stay within the 16 character limit, most
variables should be no more than 12 characters (which allows for the 4
additional characters that may be needed for output processing identifiers).

Size

The size subscript parameters are optional. They are used to set up the
dimensions of a variable array. The maximum number of array dimensions
allowed in a Public statement is three (two if setting up an array of Strings). If
you attempt to dimension a variable higher than three dimensional, an error
will occur.

For example:

Public Flow(8,3,5) would create a three-dimensional array called Flow that
has 8 x 3 x 5, or 120 elements.

Public TCTemp(9) would create a one-dimensional array with 9 elements
called TCTemp.

The Option Base for dimensions is always 1; therefore, the lowest number in a
dimension is 1 and not 0. If a variable is dimensioned to a size that is too small
for its use in the program, a "Variable out of bounds" error will be returned
when the program is compiled by the datalogger.

As Type

The Public instruction can be used with the optional As Type descriptor to
define the data format for the variable (e.g., PUBLIC Flag1 As BOOLEAN).
The four data types are:

Float: The default IEEE4 data type; a 32-bit floating-point with a 24-bit
mantissa data type. Float gives a range of roughly -3x10^34 to 3x10^34 with
about seven digits of precision. If no data type is specified, Float is used.

Long: Sets the variable to a 32-bit long integer, ranging from -2,147,483,648
to +2,147,483,647 (31 bits plus the sign bit).

Boolean: Sets the variable to a 4-byte Boolean. Boolean variables are typically
used for flags and to represent conditions or hardware that have only 2 states
(e.g., On/Off, Ports). A Boolean variable uses the same 32-bit long integer
format as a Long but can set to only one of two values: True, which is
represented as –1, and false, which is represented with 0.

String * size: Sets the variable to a string of ASCII characters, NULL
terminated, with size specifying the maximum number of characters in the
string (note that the null termination character counts as one of the characters
in the string). The size argument is optional. The minimum string size, and the
default if size is not specified, is 16 (15 usable bytes and 1 terminating byte).
String size is allocated in multiples of 4 bytes. Thus, a string declared as 18
bytes will actually be 20 bytes (19 usable bytes and 1 terminating byte). A
string is convenient in handling serial sensors, dial strings, text messages, etc.

5-10

Advertising