A Transformation Functions

 A.1 General Form
 A.2 Expression Syntax
 A.3 Built-in Functions

This Appendix describes the form and syntax of transformation functions and the way in which they are used to define transformations.

A.1 General Form

A transformation is defined by specifying two ordered sets of transformation functions which define its forward and inverse mappings. These functions are stored as character data (typically in the elements of two CHARACTER arrays) and have the general form:

<variable > [= <expression >]

where <variable > is a valid variable name and <expression > is an arithmetic expression. Transformation functions therefore resemble Fortran 77 assignment statements, except that the contents of the square brackets [...] may be omitted in appropriate circumstances (see below). Variables and data coordinates.  Variables are used in transformation functions to represent the coordinates of data points which will be transformed. Their names may be chosen freely to make the definition as comprehensible as possible; they may be of any length and may contain any alphanumeric character (including underscore) although they must start with an alphabetic character. A variable becomes defined when it appears on the left hand side of a transformation function and the name of each variable must appear on the left hand side of one (and only one) such function. Variables which appear on the left hand side of forward transformation functions are termed output variables, while those appearing on the left hand side of inverse transformation functions are termed input variables. Variables act only as “dummy arguments” and their names have no significance outside the transformation being defined. The correspondence between variables and the coordinates of external data points is established by the order in which the variables are defined. In the following, for instance, the first coordinate of an input data point would correspond with the variable ‘ALPHA’ and the second coordinate with ‘OMEGA’, while the two coordinates of an output data point would correspond with the variables ‘p’ and ‘q’ respectively:

Forward p = ALPHA + 2 q = 44−2∗OMEGA
Inverse ALPHA = p−2 OMEGA = (44−q)/2
Note that expressions appearing on the right hand side of forward transformation functions may only refer to input variables, while those appearing on the right hand side of inverse transformation functions may only refer to output variables. Unspecified mappings.  Either (although not both) of a transformation’s mappings may be left unspecified by omitting the right hand sides (and ‘ =’ signs) from all the relevant transformation functions. Thus, the transformation given by:
Forward p = ALPHA + 2 q = 44−2∗OMEGA Inverse ALPHA OMEGA
has only the forward mapping defined (the remainder of the inverse functions serves simply to define the names of the input variables). To define only the inverse mapping, the right hand sides of all the forward transformation functions would be omitted instead.

A.2 Expression Syntax

The right hand sides of transformation functions closely follow the syntax of Fortran 77 arithmetic expressions. The main differences (in addition to the less restrictive naming rules for variables) are:

The following describes particular features of the expression syntax in more detail. Constants.  Numerical constants may be written using any of the standard Fortran 77 forms (integer, real or double precision). For positive constants, a preceding + sign is optional. Thus, all the following are valid constants:

0 1 57 +666 1.0 +3. 0.5438
.303 .5 1.234d6 4.6e3 9E4 +.44D+19 3e0
The special constant ‘ <BAD >’ may also be used and represents a bad (i.e. undefined) value; any expression containing it evaluates to the standard Starlink bad value for the data type being transformed.

At present there is no distinction between the data types of constants, so the form in which they are written does not matter and their interpretation depends only on the type of arithmetic in use when the expression is evaluated. This, in turn, may depend on the type of data being transformed (Section 5.2) so constant values are converted automatically to the data type required. For instance, a constant written as ‘2.1’ might be interpreted as

integer (2), real (2.1E0), or double precision (2.1D0) according to the type of arithmetic being used. N.B. Handling of data types may change in future to allow implicit type conversion and “mixed mode” arithmetic. To avoid possible problems, floating-point to integer conversion of constants should currently be avoided if the constant has a fractional part. In practice such cases are rare.

Arithmetic operations. The standard arithmetic operators +, , , / and are available and their use is identical to Fortran 77, thus:

Q + 3.0 add 3.0 to Q
-6.7 - DATA subtract DATA from 6.7
INPUT * 14 multiply INPUT by 14
4 / V2 divide 4 by V2
NUMBER ** INDEX raise NUMBER to the power INDEX

The normal rules of operator precedence apply. Matching pairs of parentheses may also be used (and are recommended) to explicitly define the order of expression evaluation; they may be nested arbitrarily deeply. Note that the precision with which arithmetic is performed is not determined until an expression is actually evaluated (Section 5.2).6

Boolean operations. The standard logical/boolean operators .EQ., .NE., .GT., .LT., .GE., .LE., .OR., .AND. and .NOT. are available and their use is identical to Fortran 77, except that there is no distinct logical data type. These boolean operators have numerical operands and return numerical values. A numerical value is considered “true” if it is non-zero and “false” if it is zero.7 The above operators return a value of 1 for “true” and zero for “false”.

These operators may also be specified within an expression using the equivalent C forms: ==, !=, >, <, >=, <=, ||, && and !.

These operators can be used with the built-in function “QIF”. This function has 3 arguments. It returns the value of its second argument if its first argument is non-zero (i.e. “true”), and returns the value of its third argument otherwise. It can be used like the “?” operator in the C programming language.

A.3 Built-in Functions

Standard functions. A set of standard built-in functions is available and corresponds closely with the Fortran 77 set of intrinsic functions (Table 2). Function invocations take the same form as in Fortran and may be nested arbitrarily deeply.

These built-in functions are all generic and will adapt to the type of arithmetic being used. Some, however, do not support integer arithmetic and a bad value will be returned if this is in use (see Table 2). There are no data type conversion functions at present.





Function
Number of
arguments
Description






SQRT 1 square root: arg
LOG 1 natural logarithm: ln(arg)
LOG10 1 common logarithm: log 10(arg)
EXP 1 exponential: exp(arg)
ABS 1 absolute (positive) value: arg
NINT 1 nearest integer value to arg
MAX 2 or more maximum of arguments
MIN 2 or more minimum of arguments
DIM 2 Fortran DIM (positive difference) function
MOD 2 Fortran MOD (remainder) function
SIGN 2 Fortran SIGN (transfer of sign) function
SIN* 1 sine function: sin(arg)
COS* 1 cosine function: cos(arg)
TAN* 1 tangent function: tan(arg)
ASIN* 1 inverse sine function: sin 1(arg)
ACOS* 1 inverse cosine function: cos 1(arg)
ATAN* 1 inverse tangent function: tan 1(arg)
ATAN2* 2 Fortran ATAN2 (inverse tangent) function
SINH* 1 hyperbolic sine function: sinh(arg)
COSH* 1 hyperbolic cosine function: cosh(arg)
TANH* 1 hyperbolic tangent function: tanh(arg)



*Function does not support integer arithmetic.




Table 2: The standard built-in functions. The angular arguments/results of all trigonometric functions are in radians.

Additional functions.  Some additional built-in functions, which do not match the standard Fortran 77 set, are also defined. At present these simply comprise the VAX Fortran extensions to this set (Table 3). They are also generic but do not support integer arithmetic.




Function
Number of
arguments
Description






SIND 1 sine function: sin(arg)
COSD 1 cosine function: cos(arg)
TAND 1 tangent function: tan(arg)
ASIND 1 inverse sine function: sin 1(arg)
ACOSD 1 inverse cosine function: cos 1(arg)
ATAND 1 inverse tangent function: tan 1(arg)
ATAN2D 2 VAX Fortran ATAN2D (inverse tangent) function




Table 3: Additional built-in functions; angular arguments/results are in degrees. None of these functions supports integer arithmetic.

In addition, the following non-standard functions are provided:
IDV
- Performs integer division. It has two arguments. The function value is formed by taking the integer part of the two arguments, dividing them, and then returning the integer part of the result.
QIF
- Has three arguments. It returns the value of its second argument if its first argument is non-zero (i.e. “true”), and returns the value of its third argument otherwise. It can be used like the “?” operator in the C programming language.

6Expressions such as ‘X 2.0’ and ‘X 2’ cannot currently be distinguished, whereas in Fortran they are different and the latter will evaluate more efficiently. Consequently (unless integer arithmetic is being used) the exponentiation operator ‘ ’ is an inefficient way of squaring a number and the equivalent expression ‘XX’ is preferred. This deficiency will be removed in future.

7This is the same convention used in the C programming language.