Programmer Guide > Constants and Variables > Variables
  

Variables
Variables are named repositories where information is stored. A variable may contain a scalar, vector, multidimensional array, or structure of virtually any size. Arrays may contain elements of any of the nine basic data types plus structures. Variables may be used to store images, spectra, single quantities, names, tables, etc.
The following are the basic data types that variables may have:
*BYTE—An eight-bit unsigned integer ranging in value from
0 to 255. Pixels in images are commonly represented as byte data.
*INT—A 16-bit signed integer ranging from –32,768 to +32,767.
*INT32—A 32-bit signed integer.
*LONG—A 32-bit (or 64-bit in 64-bit PV‑WAVE) signed integer.
*FLOAT—A 32-bit single-precision number in the range of ±1038, with 7 decimal places of significance.
*DOUBLE—A 64-bit double-precision number in the range of ±10308, with 14 decimal places of significance.
*COMPLEX—A real-imaginary pair of single-precision floating numbers.
*DCOMPLEX—A real-imaginary pair of double-precision floating numbers.
*STRING—A sequence of characters, from 0 to 32,767 characters in length. This data type is used to transfer alphanumeric strings as well as date/time data for calendar-based analysis.
*Structure—An aggregation made from the basic data types, other structures, and arrays. Date/time data is handled internally as a structure.
*LIST—An array of expressions and variables where each element can have a different data type.
*ASARR—An associative array. Similar to a LIST, but elements are stored and retrieved as keyword:value pairs.
Attributes of Variables
Each variable has a structure and a type, which can change dynamically during the execution of a program or terminal session.
One important advantage that PV-WAVE has over program languages such as C and FORTRAN is that you do not need to declare variables. When a variable is assigned a value, it is automatically declared as a specific data type.
 
note
The dynamic nature of PV-WAVE variables may seem unusual to you if you are used to strongly typed languages such as C and FORTRAN. For example, in PV-WAVE you can write a valid statement that assigns a scalar variable to an array variable, or a string variable to an array variable.
Structure of Variables
A variable may contain either a single value (a scalar), or it may contain a number of values of the same type (an array). Note that one-dimensional arrays are often referred to as vectors in the PV-WAVE documentation. Strings are considered a single value and a string array contains a number of fixed-length strings. A single instance of a structure is considered a scalar.
In addition, a variable may associate an array structure with a file; these variables are called associated variables. Referencing an associated variable causes data to be read from or written to the file. Associated variables and the related ASSOC function are described in Working with Data Files, and in the PV‑WAVE Reference.
Type of Variables
A variable may have one and only one of the following types: UNDEFINED, BYTE, INT, INT32, LONG, FLOAT, DOUBLE, COMPLEX, DCOMPLEX, STRING, Structure, LIST, or ASARR.
When a variable appears on the left-hand side of an assignment statement its attributes are copied from those of the expression on the right-hand side. For example, the statement:
ABC = DEF
redefines or initializes the variable ABC with the attributes and value of variable DEF. Attributes previously assigned to the variable are destroyed.
 
note
This is an example of PV-WAVE’s loose data typing. This may be confusing to programmers who are used to strongly typed languages where such an assignment statement would produce an error.
Initially, every variable has the single attribute of undefined. Attempts to use undefined variables result in an error.
Names of Variables
Variables are named by identifiers that have the following characteristics:
*Each identifier must begin with a letter and may contain from one to 31 characters.
*The second and following characters may be a letter, digit, the underscore character, or the dollar sign.
*A variable name may not contain embedded spaces, because spaces are considered to be delimiters.
*Characters after the first 31 are ignored.
*Names are case insensitive, lowercase letters are converted to uppercase; so the variable name abc is equivalent to the name ABC.
*A variable may not have the same name as a function or reserved word. This will result in a syntax error. Avoid the following reserved words:
 
AND
BEGIN
CASE
COMMON
DO
ELSE
END
ENDCASE
ENDELSE
ENDFOR
ENDIF
ENDREP
ENDWHILE
EQ
FOR
FUNCTION
GE
GOTO
GT
IF
LE
LT
MOD
NE
NOT
OF
ON_IOERROR
OR
PRO
REPEAT
THEN
UNTIL
WHILE
XOR
 
 
 
Examples of Variable Names illustrates examples of valid and invalid variable names.
 
Table 2-8: Examples of Variable Names  
Correct
Incorrect
Reason
A
EOF
Conflicts with function name
A6
6A
Doesn’t start with a letter
INIT_STATE
_INIT
Doesn’t start with a letter
ABC$DEF
AB@
Illegal character, @
My_variable
ab cd
Embedded space
System Variables
System variables are a special class of predefined variables, available to all program units. Their names always begin with the exclamation mark character (!). System variables are used to set the options for plotting, to set various internal modes, to return error status, and perform other functions.
 
note
For detailed information on each system variable, see the PV‑WAVE Reference.
System variables have a predefined type and structure which cannot be changed. When an expression is stored into a system variable, it is converted to the type of the variable if necessary and possible.
Certain system variables are read only, and their values may not be changed. You may define new system variables with the DEFSYSV procedure.
Examples of system variable references are:
; Change the standard WAVE> prompt to a new string. 
!Prompt = 'Good Morning: ' 
; Store value of the cursor system variable !C in A. 
A = !C 
; Use !Radeg, a system variable containing a radians-to- degrees
; conversion factor, to convert radians to degrees.
PRINT, ACOS(a) * !Radeg 
; Set default plot title. !P is a structure, in which Title 
; is a field.
!P.Title = 'Cross Section'
If an error message appears that refers to the system variables !D, !P, !X, !Y, or !Z, the error message will contain an “expanded” name for the system variable. The “expanded” names of these system variables are:
*Device for !D
*Plot for !P
*Axis for !X, !Y, and !Z

Version 2017.1
Copyright © 2019, Rogue Wave Software, Inc. All Rights Reserved.