next up previous 225
Next: Reference
Up: Carrying on
Previous: Selections

Indices

In CAT an index is a mechanism for accessing the rows of a catalogue in the order that they would have were the catalogue sorted into ascending or descending order on some (numeric) column. That is, an index presents the application with a `virtual catalogue' which appears to have been sorted on the specified column. Every index that you create has a unique identifier. Once you have obtained an index identifier it can be passed to CAT_RGET instead of a catalogue identifier, and CAT_RGET will return subsequent rows corresponding to ascending or descending order of the column used to generate the index.

Indices are created using routine CAT_INEW. Version 8.1 of CAT supports only temporary indices which persist only for the duration of the application which generated them and perish when it terminates. Future versions of CAT will support permanent indices which persist after the program which generated them terminates.

Suppose that you wished to generate an index on column DEC of data type REAL9 and then process the rows of the catalogue using this index.

      INTEGER
     :  CI,      ! Catalogue identifier.
     :  FI,      ! Identifier for column DEC.
     :  II,      ! Identifier for index generated from column DEC.
     :  NUMROW,  ! Number of rows in the catalogue.
     :  ROW      ! Current row.
      REAL
     :  DECVAL   ! Value read for DEC from current row in index.
      LOGICAL
     :  NULFLG   ! Null value flag.
       .
       .
       .

First get an identifier for column DEC.

      CALL CAT_TIDNT (CI, 'DEC', FI, STATUS)

Next create an index and get an identifier for it.

      CALL CAT_INEW (FI, 'TEMP', CAT__ASCND, II, STATUS)

The second argument indicates that the index is temporary rather than permanent; `TEMP' is the only permitted value here in version 8.1 of CAT. The third argument indicates whether the index is to correspond to ascending (`CAT__ASCND') or descending (`CAT__DSCND') order.

To access the rows via the index simply determine the number of rows in the catalogue and then loop through the rows, passing the index identifier, II, rather than then catalogue identifier, to routine CAT_RGET. The values obtained might be processed in some way, or written out to generate a sorted catalogue.

      CALL CAT_TROWS (CI, NUMROW, STATUS)

      DO ROW = 1, NUMROW
         CALL CAT_RGET (II, ROW, STATUS)

         CALL CAT_EGT0R (FI, DECVAL, NULFLG, STATUS)
           .
           .
           .

      END DO



next up previous 225
Next: Reference
Up: Carrying on
Previous: Selections

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