next up previous 225
Next: Selections
Up: Carrying on
Previous: Vector columns

Expressions

In CAT an expression is an algebraic expression involving the names of columns and parameters and constants, linked by arithmetic operators and mathematical and astronomical functions. The syntax for expressions is described in Appendix [*]. The first step towards manipulating an expression is to obtain an identifier for it. Routine CAT_EIDNT is used for this purpose. If the expression is invalid (for example because it contains the name of a column which does not exist in the catalogue) this routine will return with an error status. Once you have an identifier for an expression the expression can be evaluated using the same routines that GET the values of a column (you are `getting the value of the expression'). Clearly, values cannot be written to expressions and there is no equivalent of PUTting a value to a column.

Suppose that a catalogue contained columns called x and y and parameter p. The following example illustrates evaluating the expression `x + y + p + 2.0' (that is, getting its value) for the first twenty-five rows of the catalogue. The evaluated expression for each row is read into REAL variable8 EXPVAL. In the example the value is overwritten for each successive row; in a real application it would be processed or stored in some way.

      INTEGER
     :  CI,      ! Catalogue identifier.
     :  EI,      ! Expression identifier.
     :  ROW      ! Current row.
      REAL
     :  EXPVAL   ! Value read for current row.
      LOGICAL
     :  NULFLG   ! Null value flag.
       .
       .
       .

First get an identifier for the expression.

      CALL CAT_EIDNT (CI, 'x + y + p + 2.0', EI, STATUS)

Then loop through the first twenty-five rows getting the value for the expression.

      DO ROW = 1, 25
         CALL CAT_RGET (CI, ROW, STATUS)

         CALL CAT_EGT0R (EI, EXPVAL, NULFLG, STATUS)
           .
           .
           .

      END DO

Null values for expressions work just like null values for scalar columns. If a null value is generated CAT_EGT0$<$t$>$ returns the appropriate Starlink `bad' value rather than a genuine datum, and the null value flag (argument NULFLG in the example) is set to .TRUE. Expressions can evaluate to null in a number of ways: perhaps individual fields in the expression are themselves null, or an arithmetic exception (such as $\div$ by zero) might occur in the expression.



next up previous 225
Next: Selections
Up: Carrying on
Previous: Vector columns

CAT [1ex
Starlink User Note 181
A.C. Davenhall
4th April 2001
E-mail:ussc@star.rl.ac.uk

Copyright © 2001 Council for the Central Laboratory of the Research Councils