Expressions in CURSA are mainly used for two purposes:
The rules for expressions are similar in both cases and both usages are described here.
Expressions for creating a new column 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:
(12) |
Remember that in CURSA column and parameter names are not case-sensitive. Thus the following column or parameter names would all be considered equivalent:
Vector column elements occur in expressions with their usual syntax: the name of the base column
followed by the element number enclosed in square brackets. The first element in a vector is
numbered one. For example, an expression to add two to the fourth element of vector FLUX
would be
‘FLUX[4] + 2.0
’.
Expressions for defining a selection have a similar algebraic format to those for creating a new column. However, they must include a relational operator to define the selection criterion. All the other rules are exactly as for defining a new column. Following the above example some valid expressions for defining a selection are:
(13) |
Angles can be included in expressions using sexagesimal notation. For example:
(14) |
(remember that if a sexagesimal number is unsigned it is interpreted as hours; to be interpreted as degrees it must be signed).
The arithmetic operators are:
+ | addition, |
- | subtraction, |
* | multiplication, |
/ | division. |
brackets (‘(
’ and ‘)
’) may be used as required.
Table 19 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, seconds to |
radians | |
D = DMSRAD(C,N,N,N) | first argument is the sign (‘’ or ‘-’ ), |
converts degrees, minutes, 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: , | |
D = PANGLE(N,N,N,N) | position angle of point from point |
. All the input arguments and the return | |
argument are in radians. The input arguments are in | |
the order: , | |
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.
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.
.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 20. 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.