A Expression syntax

 A.1 Creating a new column
 A.2 Defining a new selection
 A.3 Details of expressions
 A.4 Mathematical functions provided
 A.5 Rules for expressions
 A.6 Operator precedence

Expressions in CURSA are mainly used for two purposes:

The rules for expressions are similar in both cases and both usages are described here.

A.1 Creating a new column

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:

x p x + p (x + y + 2) / (p + q) (2.0*x + y + 3.75*p) + 13.0) / (z + 1.8*q) (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:

  HD_NUMBER
  HD_Number
  hd_number

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’.

A.2 Defining a new selection

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:

x > 3.0 x > y + p + 2.36 y == 3 (13)

Angles can be included in expressions using sexagesimal notation. For example:

dec > +190:30:00   .AND.   dec < +191:30:00 (14)

(remember that if a sexagesimal number is unsigned it is interpreted as hours; to be interpreted as degrees it must be signed).

A.3 Details of expressions

The arithmetic operators are:

+ addition,
- subtraction,
* multiplication,
/ division.

brackets (‘(’ and ‘)’) may be used as required.

A.4 Mathematical functions provided

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: (α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)

Table 19: Mathematical functions which may be used in expressions

A.5 Rules for expressions

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.

(1)
Spaces are permitted between items, except that a function-name must be followed immediately by a left parenthesis. Spaces are not permitted within items such as names and numerical constants, but can be used within character strings and date/time values in curly braces.
(2)
Lower-case letters are treated everywhere as identical to the corresponding upper-case letter.
(3)
Column and parameter names can be up to fifteen characters long, and may consist of letters, digits, and underscores, except that the first character must not be a digit.
(4)
Vector elements are supported but with a restricted syntax: they may consist of a name followed by an unsigned integer constant subscript enclosed in square brackets, for example FLUX[4] or MAGNITUDE[13]. The first element of the vector is numbered one.
(5)
CHARACTER constants may be enclosed in a pair of single or double quotes; embedded quotes of the same type may be denoted by doubling up on the quote character within the string, for example ’DON’’T’ or "DON""T".
(6)
LOGICAL constants may be .TRUE. or .FALSE. but abbreviations of these words are allowed down to .T. and .F.
(7)
Numerical constants may appear in any valid form for Fortran 77 (except that embedded spaces are not allowed). Some additional forms are also permitted, as shown below.
(8)
%Xstring %Ostring %Bstring for hexadecimal, octal and binary INTEGER constants respectively.
(9)
Angles in sexagesimal notation: colons must be used to separate items, for example hours:minutes:seconds (or degrees:minutes:seconds). If there is a leading sign then the value will be taken as degrees:minutes:seconds, otherwise hours:minutes:seconds. In either case the value is converted to RADIANS.
(10)
A date/time value may be given as a string enclosed in curly braces; a range of common formats are permitted, with order year-month-day or day-month-year, and the month as a number or three-character abbreviation. The time may follow with colons separating hours:minutes:seconds. Examples of some valid dates:
  1992-JUL-26 12:34:56
  92.7.26
  26/7/92T3:45
(11)
Relational operators are supported in both Fortran 77 form (for example .GE. .NE.) as well as in the Fortran 90 forms (for example, >= /= ).
(12)
Single-symbol forms for .AND. .OR. and .NOT. are provided as an alternative: & |# respectively.
(13)
The dots may be left off the Fortran 77 forms of the relational operators and the logical operators .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.
(14)
INTEGER division does not result in truncation (as in Fortran) but produces a floating-point result. The NINT or INT function should be used (as appropriate) if an INTEGER result is required.
(15)
The functions MAX and MIN must have exactly two arguments.
(16)
All arithmetic is carried out internally in DOUBLE PRECISION (but the compiler works out the effective data type of the result using the normal expression rules).
(17)
Exponentiation is performed by log/exp functions, with use of ABS to avoid taking logs of negative arguments, thus -2**3 will come out as ‘+8’ not ‘-8’.

A.6 Operator precedence

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

Table 20: Operator precedence rules

Note that all operators except ** associate from left to right, but ** and functions associate from right to left.