Language Syntax

Declarations


All SPP variables must be declared. This includes scalars and arrays, as well as functions. All declarations must precede the body of the procedure. That is, they must be between the procedure statement and the begin statement. Although the language does not require that procedure arguments be declared before local variables and functions, it is customary and a good practice. The syntax of a type declaration is the same for parameters, variables, and procedures.

type_spec object [, object [,... ]]
Here, type_spec may be any of the seven fundamental data types, a derived type such as pointer, or extern. A list of one or more data objects follows. An object may be a variable,
array, or procedure. The declaration for each type of object has a unique syntax, as follows:

procedure	 identifier()
variable	 identifier
array	 identifier[dimension_list]
Note that all declaration statements must begin at the first character of the line. That is, there may be no white space between the beginning of the line and the beginning of the declaration.

Scalar Variables

Scalar variables are declared with the data type statements and the name of the variable. For example:

int     rows            # Number of rows 
int     cols            # Number of columns 
real    x, y            # Coordinates 
bool    verbose         # Print verbose output? 
Customarily, most variables are described by an in-line comment.

Arrays

Arrays are declared similarly to scalars, with the array size appended to the variable name and enclosed in square brackets ([ and ]). The sizes of each dimension are separated by commas within the brackets.

type_spec object[dim[,dim,... ]]
Note that here the outer square brackets are required, the inner ones represent optional multiple dimensions. Arrays may be up to seven dimensions and are
one-indexed by default. That is, the first element is numbered one. Multiply dimensioned arrays are ordered such that the leftmost dimensions vary the fastest, as they are Fortran arrays. Arrays are referenced using the variable name with the element number(s) in square brackets ([]). As many dimensions must be used in the reference as in the declaration. It is not permitted to address an array outside its declared scope, but is not detected by the compiler. The following examples illustrate how to declare subscripted variables in SPP:

The last example declares image to be 100 by 100 elements in size. The first element would be specified as image[1,1], followed by image[2,1], image[3,1], ... image[1,2], image[2,2], ... image[100,100]. The size of each dimension of an array may be specified by any compile time constant expression, or by an integer parameter or parameters, if the array is a formal parameter to the procedure. If the array is declared as a formal procedure argument and the size of the highest (rightmost, or most slowly varying) dimension is unknown, the size of that dimension should be given as ARB (for arbitrary). The declared dimensionality of an array passed as a formal parameter to a procedure may be less than or equal to the actual dimensionality of the array. For example, the following example declares several arrays and uses some of them as arguments to functions.

Note that the integer array intarr is declared as two-dimensional but referenced in the procedure as one-dimensional. The short array 3darray is declared as three-dimensional in both the calling and called procedure. However, in the called procedure, the last dimension is declared as ARB, while the others are declared with passed arguments. The lower dimensions must be declared explicitly in order for the function to compute the index of the elements. It is highly recommended to use defined (macro) constants instead of absolute constants to declare array sizes. This makes maintenance much easier in that the value is declared only once. If the constant is defined outside of a procedure, then any procedure in the same file may access the same constant, eliminating the need to pass a dimension to the functions. In addition, if the constants are defined in an include file they are available to procedures in more than one file.

Functions

External functions, whether supplied by the programmer or part of a library package must be declared in a manner similar to variables. This does not include intrinsic functions such as sin(), abs(), etc. (see "Intrinsic Functions" on page 36). Functions may be declared to be any valid SPP data type. For example, if the program includes a real valued function named myfunc, its declaration and invocation might appear as in Example 1.3.



External Functions

The extern data type declares a variable as a function. The name of the function may then be passed as an actual argument in a procedure call. In the formal procedure (dummy) arguments, the same argument must also be declared extern.

Common

Global common provides a means for sharing data between separately compiled procedures. The common statement is a declaration, and must be used only in the declarations section of a procedure. Each procedure referencing the same common must declare that common in the same way.

common /identifier/ object [, object [, ... ]]
For example,

common  /vfnxtn/ nextn, iraf, os, map 
To avoid the possibility of two procedures declaring the same common area differently in separate procedures, the common declaration should be placed in an include file (see
"Include Files" on page 39). This permits considerably more reliable and easy maintenance, avoiding changes in one procedure without changing another.

Scalar Variables
Arrays
Functions
External Functions
Common

Generated with CERN WebMaker