Fields
- Updated2025-10-31
- 4 minute(s) read
Use the field data type to store a series of numeric or text values together. All elements in a field have the same data type.
Define fields using the following pattern:
type [] identifier
Use one of the following types as the data type:
Definition Options
| Data Type | Global | Local |
|---|---|---|
| int32[] | ✔ | ✔ |
| int16[] | — | ✔ |
| int8[] | — | ✔ |
| uint32[] | — | ✔ |
| uint16[] | — | ✔ |
| uint8[] | — | ✔ |
| real64[] | ✔ | ✔ |
| real32[] | — | ✔ |
| text | — | ✔ |
Defining Global Fields
To define a global field variable in PAscript, enter the int32[] or real64[] data types in a section globals code block. Then, enter the variable name.
Example
program
section globals
int32[] intField // int32 field
real64[] realField // real64 field
endsection
intField[0] = 1
realField[0] = 1.2
endprogramDefining Local Fields
Define local fields using the following pattern:
type[size] identifier [=initialization]
Defining Field Dimensions
Select one dimension, two dimensions, or three dimensions for the field shape.
type[n] identifier // Field with n elements type[m,n] identifier // field with m rows and n columns type[p,m,n] identifier // Field with p pages, m rows and n columns
In this case, initialization is optional. If uninitialized, the elements in the field are set to 0 or the empty string "".
Initializing Fields
Initializing fields is optional.
Use the following rules to initialize fields:
- Values in a column are separated by a comma ,
- Values in rows are separated by a semicolon ;
- Elements of a page are separated by square brackets [ ]
type[n] identifier = [Element_1, ... element_n]
type[m,n] identifier = [Element_11, ... element_1n;
Element_21, ... element_2n;
...
Element_m1, ... element_mn]
type[p,m,n] identifier = [Element_111, ... element_11n;
Element_121, ... element_12n;
...
Element_1m1, ... element_1mn]
[...]
[Element_p11, ... element_p1n;
Element_p21, ... element_p2n;
...
Element_pm1, ... element_pmn]
- If you initialize the fields, specifying the field dimensions is optional.
- When initializing both type dimensions and fields, the following must match:
- Row
- Column
- Page counts
- The number of columns per row must not vary.
- The number of rows per page must not vary.
Example
program
section globals
...
endsection
int32[2] field1 // empty integer field with two elements
int32[2,3] field2 = [ 1,2,2; 4,5,6 ] // integer field with two rows and three columns
int32[2,2,2] field3 = [ 1,2; 3,4] [5,6; 7,8] //integer field with two pages, two rows, and two columns
...
endprogram
Access to a Field Element
Access a field element with square brackets [] and the relevant index for the corresponding column, row, and page.
Read and Write Fields Example 1
program int32 value int32[2,3] field2 = [1,2,3; 4,5,6] // integer field with two rows and three columns int23[2,2,2] field3 = [1,2; 3,4][5,6; 7,8] // integer field with two pages, two rows, and two columns value = field2[0,2]; // accesses element in first row, thrid column; value is now 3 value = field2[0,1,1]; // accesses element in first page, second row, second column; value is now 4 field3[0,1,1] = 10; // field3 is now [1,2; 3,10][5,6; 7,8] endprogram
You can use smaller dimensions than were defined for the field. You are not required to specify all indices. The indices include the page index, row index, and column index. For example, you can specify only the column index. You can also specify only the column and row index. In this case, 0 is used for the undefined indexes.
Read and Write Fields Example 2
program int32 value int32[2,3] field2 = [1,2,3; 4,5,6] // integer field with two rows and three columns int23[2,2,2] field3 = [1,2; 3,4][5,6; 7,8] // integer field with two pages, two rows, and two columns value = field2[2] // row index is implied as 0; accesses element in first row, third column; value is now 3 value = field3[1,0]; // page index is implied as 0; accesses element in first page, second row, first column; value is now 4 value = field3[1]; // page and row index are implied as 0; access element in first page, first row, second column; value is now 2 field2[2] = 10; // row index is implied as 0; accesses element in first row, third column; field2 is now [1,2,10; 4,5,6] endprogram
Copying Fields
Use the :copyFrom() type function to copy the contents of a field to another field.
The dimensions of the destination adapts to the dimensions of the source.
A subsequent change to the dimension or value in one field has no effect on the dimension or value in the other field.
Example: Copying Fields
int32[2,2] target=[9,8;7,6] int32[3] source=[1,2,3] target:copyFrom(source) // target is now a 1x3 field with values [1,2,3]
Referencing Fields
The = operator causes the target field to reference the source field.
The dimension of the destination adapts to the dimension of the source.
A subsequent change to the dimension or value in one field effects the dimension or value in the other field.
Example: Referencing Fields
program
int32[2,3] source = [1,2,3; 4,5,6]
int32[2,2,3] target
// copy the field
target = source // target and source now have a shape of [2,3] and a value of [1,2,3; 4,5,6]
source[0,1] = 10 // target and source now have a value of [1,10,3; 4,5,6]
endprogram