StructureType/EndStructureType (Define Structure)

The StructureType instruction is used to define a structure. The EndStructureType statement designates the end of the structure definition. Structures are used to organize variables and display data in a structured manner and can significantly shorten program code, especially for instructions that output an array of values, such as AVW200(), GPS(), SDI12Recorder() and more. For example, a single StructureType may be used to organize and display data for multiple vibrating wire sensors or many SDI-12 sensors without creating aliases for each sensor.

Another advantage of structures is the ability to define different variable types within the same array. For example, with GPS(), latitude minutes and longitude minutes may be double precision while other values in the output array are single precision.

Structures may also be used as the destination variable for measurement instructions. Inside the destination structure, you can declare an array of multipliers and offsets for each measurement that are easy to view and adjust in the field.

Syntax

StructureType Name

structure list

EndStructureType

Remarks

Each StructureType is given a name. The StructureType name is limited to 20 characters and must start with an alphabetical character. Note that the StructureType name cannot be any of the predefined table names in the datalogger; that is, Public, Status, Settings, or DataTableInfo. Multiple structures may be declared as the same StructureType.

The StructureList consists of a comma-delimited or a line-separated list of variables or variable arrays that will be grouped together into one StructureType. Variable types supported are Float, Long, String, Boolean, and Double. If a variable within the StructureType is to be used as the destination for a measurement instruction, the variable should be declared as type Float and as read only, with the ReadOnly() instruction.

After a StructureType is defined, it is assigned to a structure. Structures may be declared as ClosedPublic A CRBasic command for declaring and dimensioning variables. Variables declared with Public can be monitored during datalogger operation. or ClosedDim A CRBasic command for declaring and dimensioning variables. Variables declared with Dim remain hidden during datalogger operations.. When declared as Public, structures can be viewed and manipulated remotely, similar to constants in a ConstTable.

Special considerations apply when working with arrays of structures. When saving to a data table with repetitions (i.e., to a variable array), the FieldNames instruction is required (see Program Example #1). The labels specified in FieldNames() will prefix the values saved to the data table. Without FieldNames(), the compiler will generate a duplicate field name error.

Additionally, not all elements of an array of structures will be accessible from the Table Monitor in the software. Rather, the full contents of an array of structures is only visible by collecting them as a table. Therefore, if manual access to all array elements is required for modifying values, it is better to declare them as separate Public structures of the same type, rather than as an array.

Structures can also be accessed programmatically using Structure.Structure-variable syntax, which is analogous to Tablename.Fieldname syntax. Structure variables may be initialized just like any other variable.

Structures may also be passed into subroutines, used within functions or with pointers (that is., pointers may point to structures, see Pointer-to-Structure Example).

The EndStructureType statement marks the end of the StructureType definition.

Parameters

Name

The name for the StructureType. The name is limited to 20 characters and must start with an alphabetical character. Note that the StructureType name cannot be any of the predefined table names in the datalogger; that is, Public, Status, Settings, or DataTableInfo. Multiple structures may be declared as the same StructureType.