next up previous contents
Next: Compilation and Linking Up: No Title Previous: General Overview

Application Code

Full code for the simple application and all necessary subroutines is listed here, interspersed with more comprehensive comments and notes written in italics. A copy of this file can be obtained from the Birmingham FTP or WWW site. The code has been reduced to the almost-minimum required - the next document will cover more comprehensive methods that perform extra checking and involve access axis, error and quality information.

      SUBROUTINE SIMPLE( STATUS )
All ASTERIX applications are written as subroutines with an INTEGER status value as their sole argument. The program wrapper is generated during linking.
*  Type Definitions:
      IMPLICIT NONE

*  Global Constants:
      INCLUDE '/star/include/sae_par'
      INCLUDE 'adi_par'
Choose a central place to store the ASTERIX include files (eg. /star/asterix/include) and either create a symbolic link (%ln -s /star/asterix/include/adi_par) or specify that directory when compiling (%f77 -c simple.f -I/star/asterix/include).
*  Status:
      INTEGER            STATUS

*  Local variables:
      INTEGER            IFID                ! Input file identifier
      INTEGER            IDPTR               ! Input data array pointer
      INTEGER            NDIM                ! Number of dimensions
      INTEGER            DIMS(ADI__MXDIM)    ! Size of dimensions

      LOGICAL            DATAOK              ! Is the data present?

*  Initialise ASTERIX
      CALL AST_INIT()
Must be called before any serious work can start.
*  Obtain name of data file, and get an identifier to it
      CALL USI_ASSOC( 'INP', 'BINDS', 'UPDATE', IFID, STATUS )
      IF ( STATUS .NE. SAI__OK ) RETURN
ASSOC implies that a pointer is to be associated with a file. INP is the parameter name as specified in the interface file. BINDS is the type of data expected in this file (a binned data set). UPDATE instructs the file to be opened for reading and writing. IFID is the pointer to the opened file.
*  Look for components.
      CALL BDI_CHK( IFID, 'Data', DATAOK, STATUS )
      IF ( .NOT. DATAOK ) STATUS = SAI__ERROR
The file is checked to see if contains a data section (ie. a component called `INP'.DATA_ARRAY).
*  Get shape of input data
      CALL BDI_GETSHP( IFID, ADI__MXDIM, DIMS, NDIM, STATUS )
Get the dimensionality and size of the main data component in the file.
*  Map the data
      CALL BDI_MAPR( IFID, 'Data', 'UPDATE', IDPTR, STATUS )
The data component is mapped to the pointer IDPTR as REAL values and for both reading and writing.
*  Modify the array
      CALL SIMPLE_TASK( %VAL(IDPTR), NDIM, DIMS, STATUS )
To use the values mapped by a pointer it must first be eVALuated by passing it as an argument to a subroutine.
*  Tidy up
      CALL AST_CLOSE()
      CALL AST_ERR( STATUS )
Closing down ASTERIX unmaps the data and file pointers, closes the opened file, and frees all other resources that have been used internally by ASTERIX and Starlink. The modified data values are automatically written back to the data file, as it was opened for UPDATE and the data mapped for UPDATE. Then, if any errors have been encountered, print an explanatory message to the screen.
      END

      SUBROUTINE SIMPLE_TASK( DATA, NDIM, DIMS, STATUS )

*  Global constants:
      INCLUDE '/star/include/sae_par'

*  Status:
      INTEGER            STATUS

*  Import:
      REAL               DATA(*)             ! Array of data values
The data pointer has now become a standard data type after evaluation.
      INTEGER            NDIM                ! Number of dimensions
      INTEGER            DIMS(*)             ! Size of dimensions
*  Local variables:
      INTEGER            NELM                ! Number of data elements
      INTEGER            I                   ! Loop variable

*  Check inherited global status
      IF ( STATUS .NE. SAI__OK ) RETURN

*  Get size of the data array
      CALL ARR_SUMDIM( NDIM, DIMS, NELM )
Find the total number of data values by multiplying up the dimensions.
* Perform the task as a vector operation on the data
      DO I = 1, NELM
        DATA(I) = SQRT( DATA(I) )
      END DO
The pointer has been evaluated as a 1-D data array to allow for simple processing of the values. The actually file may contain a scalar value or an array with from 1 to 7 dimensions.
      END



next up previous contents
Next: Compilation and Linking Up: No Title Previous: General Overview



Asterix
Tue Feb 10 12:19:15 GMT 1998