The VEC_ routines are a set of subroutines which perform arithmetic, mathematical operations and type conversion on vectorised arrays of data stored using any numerical type. They incorporate handling of numerical errors and propagation of the standard bad values in a way that is fully compatible with the VAL_ functions.
VEC_ routines are invoked by statements of the form:
or
where name specifies the operation to be performed and:
The VEC_ routines are designed for optimum efficiency when processing large arrays of data and are consequently far more efficient at performing this task than the corresponding VAL_ functions. When possible, VEC_ routines should always be used in preference to VAL_ functions unless the number of calculations to be performed is small (typically 1000 or less).
The main disadvantage in using VEC_ routines is likely to be the additional programming effort, because workspace arrays will probably be required and may have to be acquired dynamically — unless only a single operation is being performed. Also, certain operations cannot be performed using VEC_ routines (summing the pixels in an image for example) and, in such cases, routines from the NUM facility (section 4) may have to be used instead. Note, however, that if NUM_ routines are used, then security against numerical errors is more difficult to achieve and (especially in the case of arithmetic operations) VAX-specific programming techniques may be required. The resulting applications will not then be portable.
The error handling strategy used by the VEC_ routines is as follows:
On exit, the IERR argument will contain the index of the first array element which generated a numerical error (or zero if there were no errors) and NERR will contain a count of the number of numerical errors which occurred. If more than one error occurred, then the STATUS value returned will be appropriate to the first of these.
Arithmetic and mathematical operations may be performed on vectorised arrays of data of any numerical type by invoking appropriate VEC_ routines, using statements such as:
or
Here, the VEC_ routine takes a vectorised input argument array (or arrays) with N elements of type T and returns a vectorised result array which is also of type T, having performed the arithmetic or mathematical operation specified by FUNC on each array element. The data type code T may be any of those specified in Table 1 and FUNC may be any of the function codes specified in Tables 2 & 3. The number of input argument arrays (1 or 2) appropriate to each function is also indicated in these latter Tables.
Thus, for example, the subroutine VEC_ADDUW adds two vectorised unsigned word arrays to produce an array of unsigned word results, while VEC_SQRTD evaluates the square root of a single vectorised array of double precision values, returning an array of double precision results.
Conversion of vectorised arrays between numerical data types may be performed by invoking the appropriate VEC_ type conversion routines, using statements such as:
Here, the VEC_ routine takes a vectorised input argument array with N elements of type T and returns a vectorised result array of type T, having performed type conversion on each array element. The data type codes T and T may be any of those specified in Table 1.
Thus, for example, the subroutine VEC_BTOUW converts a vectorised array of byte data into unsigned word data, while VEC_DTOI converts a vectorised array from double precision to integer.
Note that conversions from floating point types (_REAL or _DOUBLE) to non-floating point types result in rounding of the data (not truncation as would happen with a Fortran assignment statement).