Data Types
CSL supports a number of data types for variables and constants. By default, any implicitly declared variable is a double precision floating-point type. To declare a variable as an integer, logical or character type, or to explicitly declare as a floating point type, the DIMENSION keyword, along with one of the following type specifiers are used:
REAL |
Double-precision floating point type |
INTEGER |
Long integer type |
LOGICAL |
Boolean type (true/false) |
CHARACTER |
String; size does not need to be defined |
The following code snippet includes some examples of the various variable data types being declared and initialized:
dimension integer x, y ! declares two scalar integer variables
constant x = -10 ! variable x is also constant
y = 3000
dimension real z1, z2 ! explicitly declares two floating-point variables
z1 = 4.23
constant z2 = 1.2345 ! z2 is also a constant
z3 = 0.0001 ! implicitly declares a floating-point variable
constant z4 = 0.00123 ! implicitly declares a floating-point constant
dimension character name ! declares a string variable
name = 'hello'
Matrix and Array Variables
The dimension statement is also used to declare variables to be arrays or multi-dimensional matrices. Note that square brackets are now used to denote both array/matrix declaration, and assignment/reference of elements in arrays/matrices. This differs from other implementations of the CSL language which use parentheses. This change was made for consistency with other modern programming languages, and to prevent conflicts between function invocation (parentheses) and array notation (square brackets).
dimension real z1[3], z2[3, 4] ! declares an array and matrix of floating-point variables
constant z1 = 1.0, 2.0, 3.0 ! z1 is a constant whose elements are initialized
z2[1, 2] = 3.234 ! one element of z2 is initialized