This appendix discusses the syntax permitted for expressions passed to the expression parser.
Expressions are input to CAT as argument EXPR
of subroutine CAT_EIDNT
(see Section 7).
Expressions have an algebraic format, and comprise: columns, vector column elements, parameters
and constants linked by arithmetic operators and mathematical functions. For example, suppose that a
catalogue contained scalar columns called x
, y
and z
and parameters called p
and q
. Some valid
expressions are:
| (2) |
Remember that in CAT column and parameter names are not case-sensitive. Thus the following column or parameter names would all be considered equivalent:
HD_NUMBER
HD_Number
hd_number
FLUX
would be
‘FLUX[4] + 2.0
’.
The arithmetic operators are:
+ | addition, |
- | subtraction, |
* | multiplication, |
/ | division. |
brackets (‘(
’ and ‘)
’) may be used as required.
Table 16 lists the mathematical functions which are provided. The letters denote data types permitted, coded as follows: B = BYTE, H = half INTEGER, I = INTEGER, R = REAL, D = DOUBLE PRECISION, C = CHARACTER, L = LOGICAL. The appearance of N as an argument means that any numeric type (BHIRD) is permitted, as a result it means that the type is the widest type of any of the arguments. R/D means that the result is REAL unless one or more arguments is of DOUBLE PRECISION type in which case D is the result.
Function | Notes |
B = BYTE(N) | convert to BYTE data type |
H = HALF(N) | convert to INTEGER*2 data type |
I = INT(N) | convert to INTEGER data type |
R = REAL(N) | convert to REAL data type |
D = DBLE(N) | convert to DOUBLE PRECISION data type |
I = NINT(N) | convert to nearest INTEGER |
N = MIN(N,N) | the function must have precisely two arguments |
N = MAX(N,N) | the function must have precisely two arguments |
N = MOD(N,N) | remainder |
N = ABS(N) | absolute value |
R/D = SQRT(N) | square root |
R/D = LOG(N) | natural logarithm |
R/D = LOG10(N) | logarithm to the base 10 |
R/D = EXP(N) | exponential |
R/D = SIN(N) | sine; argument in radians |
R/D = COS(N) | cosine; argument in radians |
R/D = TAN(N) | tangent; argument in radians |
R/D = ASIN(N) | arc-sine; result in radians |
R/D = ACOS(N) | arc-cosine; result in radians |
R/D = ATAN(N) | arc-tangent; result in radians |
R/D = ATAN2(N,N) | arc-tangent (two arguments) result in radians |
I = IAND(I,I) | bitwise logical AND |
I = IOR(I,I) | bitwise logical OR |
I = XOR(I,I) | bitwise logical exclusive OR |
R/D = DTOR(N) | degrees to radians conversion |
R/D = RTOD(N) | radians to degrees conversion |
C = UPCASE(C) | convert character string to upper case |
C = STRIP(C) | leading and trailing spaces are removed |
C = SUBSTR(C,N,N) | returns characters from positions argument 2 |
to argument 3 inclusive, with the positions | |
starting at 1 | |
L = NULL(*) | .TRUE. if argument is NULL |
D = HMSRAD(N,N,N) | converts 3 arguments hours, minutes and |
seconds to radians | |
D = DMSRAD(C,N,N,N) | first argument is the sign (‘+’ or ‘-’ ), |
converts degrees, minutes and seconds to radians | |
D = GREAT(N,N,N,N) | great circle distance between two spherical |
coordinates. All the input arguments and the | |
return argument are in radians. The input arguments | |
are in the order: (α1,δ1,α2,δ2) | |
D = PANGLE(N,N,N,N) | Position angle of point (α2,δ2) from point |
(α1,δ1). All the input arguments and the return | |
argument are in radians. The input arguments are in | |
the order: (α1,δ1,α2,δ2) | |
The expression string can contain constants, column and parameter names, operators, functions, and parentheses. In general the usual rules of algebra and Fortran should be followed, with some minor exceptions, as noted below.
CAT__SZCMP
characters long, and may consist
of letters, digits, and underscores, except that the first character must not be a digit.
FLUX[4]
or MAGNITUDE[13]
. The first element of the vector is numbered one.
.TRUE.
or .FALSE.
but abbreviations of these words are
allowed down to .T.
and .F.
1992-JUL-26 12:34:56
92.7.26
26/7/92T3:45
.GE. .NE.
) as well as in the Fortran 90 forms (for example,
>=
/=
).
.AND. .OR. and .NOT.
are provided as an alternative: &
|
#
respectively.
.AND.
and .OR.
where spaces or parentheses separate them from names or constants, but the
logical constants and the .NOT.
operator need the enclosing dots to distinguish them from other
lexical items in all cases.
NINT
or INT
function should be used (as appropriate) if an INTEGER result is
required.
MAX
and MIN
must have exactly two arguments.
-2**3
will come out as ‘+8’ not ‘-8’.
The operator precedence rules are show in Table 17. The rules of Fortran 90 are used as far as possible; in this table the larger numbers denote higher precedence (tighter binding).
Precedence | Function/operator |
2 | start/end of expression |
4 | ( ) |
6 | , |
8 | .EQV. .NEQV. |
10 | .OR. |
12 | .AND. & |
14 | .NOT. # |
16 | .EQ. .GE. .GT. .LE. .LT. .NE. |
18 | FROM TO |
20 | // |
22 | + - (binary operators) |
24 | + - (unary operators) |
26 | * / |
28 | ** |
30 | all functions |
Note that all operators except **
associate from left to right, but **
and functions associate from right
to left.