4 An example CTG application

The following gives a short example of how CTG routines might be used within an ADAM task.

        SUBROUTINE COPY( STATUS )
  
  *  Global Constants:
        INCLUDE ’GRP_PAR’          ! Standard GRP constants
  
  *  Local Variables:
        INTEGER CIN                ! GRP identifier for an input catalogue
        INTEGER COUT               ! GRP identifer for an output catalogue
        LOGICAL FLAG               ! Has group ended with flag character?
        INTEGER GIDIN              ! GRP identifier for group of input cat’s
        INTEGER GIDOUT             ! GRP identifer for group of output cat’s
        INTEGER I                  ! Loop counter
        INTEGER NUMIN              ! Number of input catalogues
        INTEGER NUMOUT             ! Number of output catalogues
        INTEGER STATUS             ! The global status
  *.
  
  *  Inialise the group identifiers to indicate that groups do not have
  *  any initial members.
        GIDIN = GRP__NOID
        GIDOUT = GRP__NOID
  
  *  Create group of input catalogues using the parameter IN.
        CALL CTG_ASSOC( ’IN’, .TRUE., GIDIN, NUMIN, FLAG, STATUS )
  
  *  Create group of output catalogues using the parameter OUT, that
  *  possibly works by modifying the values in the input group.
        CALL CTG_CREAT( ’OUT’, GIDIN, GIDOUT, NUMOUT, FLAG, STATUS )
  
  *  Loop over group members.
        DO I = 1, NUMIN
  
  *  Get the identifier for an existing catalogue from the input group.
           CALL CTG_NDFAS( GIDIN, I, ’READ’, CIN, STATUS )
  
  *  Get the identifier for the output catalogue from the output group.
           CALL CTG_NDFAS( GIDOUT, I, ’WRITE’, COUT, STATUS )
  
  *  Proceed to create output catalogue by editing the input catalogue
  *  using the CAT library.
                 :             :             :             :
  
  *  Release CAT resources.
           CALL CAT_TRLSE( CIN, STATUS )
           CALL CAT_TRLSE( COUT, STATUS )
        END DO
  
  *  Release GRP resources.
        CALL GRP_DELET( GIDIN, STATUS )
        CALL GRP_DELET( GIDOUT, STATUS )
  
        END

When this program is compiled and run, the user is asked for two ADAM parameters, IN and OUT. Each catalogue in the list specified by the IN parameter is simply copied to the corresponding name in the list specified by the OUT parameter. For instance, running
  copy in=data[12].fits out=*-new

would write new catalogues data1-new.fits and data2-new.fits which were edited copies of the existing files data1.fits and data2.fits. If data1 and data2 do not represent FITS catalogues an error will be signalled and the user will be prompted to enter a different value for IN.

Note that a few corners have been cut in the above code, in particular checking that the input and output groups have the same size and STATUS testing. Additionally, no action is taken when the FLAG character is given at the end of a group specification—conventionally this would indicate that the user should be allowed to add further members.