astMathMap

Create a MathMap

Description:

This function creates a new MathMap and optionally initialises its attributes.

A MathMap is a Mapping which allows you to specify a set of forward and/or inverse transformation functions using arithmetic operations and mathematical functions similar to those available in C. The MathMap interprets these functions at run-time, whenever its forward or inverse transformation is required. Because the functions are not compiled in the normal sense (unlike an IntraMap), they may be used to describe coordinate transformations in a transportable manner. A MathMap therefore provides a flexible way of defining new types of Mapping whose descriptions may be stored as part of a dataset and interpreted by other programs.

Synopsis

AstMathMap astMathMap( int nin, int nout, int nfwd, const char fwd[], int ninv, const char inv[], const char options, ... )

Parameters:

nin
Number of input variables for the MathMap. This determines the value of its Nin attribute.
nout
Number of output variables for the MathMap. This determines the value of its Nout attribute.
nfwd
The number of forward transformation functions being supplied. This must be at least equal to " nout" , but may be increased to accommodate any additional expressions which define intermediate variables for the forward transformation (see the " Calculating Intermediate Values" section below).
fwd
An array (with " nfwd" elements) of pointers to null terminated strings which contain the expressions defining the forward transformation. The syntax of these expressions is described below.
ninv
The number of inverse transformation functions being supplied. This must be at least equal to " nin" , but may be increased to accommodate any additional expressions which define intermediate variables for the inverse transformation (see the " Calculating Intermediate Values" section below).
inv
An array (with " ninv" elements) of pointers to null terminated strings which contain the expressions defining the inverse transformation. The syntax of these expressions is described below.
options
Pointer to a null-terminated string containing an optional comma-separated list of attribute assignments to be used for initialising the new MathMap. The syntax used is identical to that for the astSet function and may include " printf" format specifiers identified by " %" symbols in the normal way. If no initialisation is required, a zero-length string may be supplied.
...
If the " options" string contains " %" format specifiers, then an optional list of additional arguments may follow it in order to supply values to be substituted for these specifiers. The rules for supplying these are identical to those for the astSet function (and for the C " printf" function).

Returned Value

astMathMap()
A pointer to the new MathMap.

Notes:

Defining Transformation Functions

A MathMap s transformation functions are supplied as a set of expressions in an array of character strings. Normally you would supply the same number of expressions for the forward transformation, via the " fwd" parameter, as there are output variables (given by the MathMap s Nout attribute). For instance, if Nout is 2 you might use:

which defines a transformation from Cartesian to polar coordinates. Here, the variables that appear on the left of each expression (" r" and " theta" ) provide names for the output variables and those that appear on the right (" x" and " y" ) are references to input variables.

To complement this, you must also supply expressions for the inverse transformation via the " inv" parameter. In this case, the number of expressions given would normally match the number of MathMap input coordinates (given by the Nin attribute). If Nin is 2, you might use:

which expresses the transformation from polar to Cartesian coordinates. Note that here the input variables (" x" and " y" ) are named on the left of each expression, and the output variables (" r" and " theta" ) are referenced on the right.

Normally, you cannot refer to a variable on the right of an expression unless it is named on the left of an expression in the complementary set of functions. Therefore both sets of functions (forward and inverse) must be formulated using the same consistent set of variable names. This means that if you wish to leave one of the transformations undefined, you must supply dummy expressions which simply name each of the output (or input) variables. For example, you might use:

for the inverse transformation above, which serves to name the input variables but without defining an inverse transformation.

Calculating Intermediate Values

It is sometimes useful to calculate intermediate values and then to use these in the final expressions for the output (or input) variables. This may be done by supplying additional expressions for the forward (or inverse) transformation functions. For instance, the following array of five expressions describes 2-dimensional pin-cushion distortion:

Here, we first calculate three intermediate results (" r" , " rout" and " theta" ) and then use these to calculate the final results (" xout" and " yout" ). The MathMap knows that only the final two results constitute values for the output variables because its Nout attribute is set to 2. You may define as many intermediate variables in this way as you choose. Having defined a variable, you may then refer to it on the right of any subsequent expressions.

Note that when defining the inverse transformation you may only refer to the output variables " xout" and " yout" . The intermediate variables " r" , " rout" and " theta" (above) are private to the forward transformation and may not be referenced by the inverse transformation. The inverse transformation may, however, define its own private intermediate variables.

Expression Syntax

The expressions given for the forward and inverse transformations closely follow the syntax of the C programming language (with some extensions for compatibility with Fortran). They may contain references to variables and literal constants, together with arithmetic, boolean, relational and bitwise operators, and function invocations. A set of symbolic constants is also available. Each of these is described in detail below. Parentheses may be used to over-ride the normal order of evaluation. There is no built-in limit to the length of expressions and they are insensitive to case or the presence of additional white space.

Variables

Variable names must begin with an alphabetic character and may contain only alphabetic characters, digits, and the underscore character " _" . There is no built-in limit to the length of variable names.

Literal Constants

Literal constants, such as " 0" , " 1" , " 0.007" or " 2.505e-16" may appear in expressions, with the decimal point and exponent being optional (a " D" may also be used as an exponent character for compatibility with Fortran). A unary minus " -" may be used as a prefix.

Arithmetic Precision

All arithmetic is floating point, performed in double precision.

Propagation of Missing Data

Unless indicated otherwise, if any argument of a function or operator has the value AST__BAD (indicating missing data), then the result of that function or operation is also AST__BAD, so that such values are propagated automatically through all operations performed by MathMap transformations. The special value AST__BAD can be represented in expressions by the symbolic constant " <bad >" .

A <bad > result (i.e. equal to AST__BAD) is also produced in response to any numerical error (such as division by zero or numerical overflow), or if an invalid argument value is provided to a function or operator.

Arithmetic Operators

The following arithmetic operators are available:

Boolean Operators

Boolean values are represented using zero to indicate false and non-zero to indicate true. In addition, the value AST__BAD is taken to mean " unknown" . The values returned by boolean operators may therefore be 0, 1 or AST__BAD. Where appropriate, " tri-state" logic is implemented. For example, " a||b" may evaluate to 1 if " a" is non-zero, even if " b" has the value AST__BAD. This is because the result of the operation would not be affected by the value of " b" , so long as " a" is non-zero.

The following boolean operators are available:

Relational Operators

Relational operators return the boolean result (0 or 1) of comparing the values of two floating point values for equality or inequality. The value AST__BAD may also be returned if either argument is <bad >.

The following relational operators are available:

Note that relational operators cannot usefully be used to compare values with the <bad > value (representing missing data), because the result is always <bad >. The isbad() function should be used instead.

Bitwise Operators

The bitwise operators provided by C are often useful when operating on raw data (e.g. from instruments), so they are also provided for use in MathMap expressions. In this case, however, the values on which they operate are floating point values rather than pure integers. In order to produce results which match the pure integer case, the operands are regarded as fixed point binary numbers (i.e. with the binary equivalent of a decimal point) with negative numbers represented using twos-complement notation. For integer values, the resulting bit pattern corresponds to that of the equivalent signed integer (digits to the right of the point being zero). Operations on the bits representing the fractional part are also possible, however.

The following bitwise operators are available:

Note that no bit inversion operator (" " in C) is provided. This is because inverting the bits of a twos-complement fixed point binary number is equivalent to simply negating it. This differs from the pure integer case because bits to the right of the binary point are also inverted. To invert only those bits to the left of the binary point, use a bitwise exclusive OR with the value -1 (i.e. " x^-1" ).

Functions

The following functions are available:

Symbolic Constants

The following symbolic constants are available (the enclosing " < >" brackets must be included):

Evaluation Precedence and Associativity

Items appearing in expressions are evaluated in the following order (highest precedence first):

All operators associate from left-to-right, except for unary +, unary -, !, .not. and which associate from right-to-left.