The following application calculates and displays the maximum pixel value in an NDF's data array. It is typical of a class of applications which read a single NDF as input, but do not produce any output data structure.
In this example, the choice has been made to handle all values using single-precision (_REAL) arithmetic and not to handle bad pixel values at all. Strictly speaking, the call to NDF_MBAD to check for the presence of bad pixels is not essential, but it does help by producing an error message if someone should inadvertently use this program on data which does contain bad pixels.
SUBROUTINE GETMAX( STATUS )
*+
* Name:
* GETMAX
* Purpose:
* Obtain the maximum pixel value.
* Description:
* This routine finds the maximum pixel value in the data array of
* an NDF and displays the result.
* ADAM Parameters:
* NDF = NDF (Read)
* The NDF data structure whose data array is to be examined.
* Implementation Status:
* This routine deliberately does not handle NDFs whose data arrays
* contain bad pixels. Real arithmetic is used to compute the
* maximum.
*-
* Type Definitions:
IMPLICIT NONE ! No implicit typing
* Global Constants:
INCLUDE 'SAE_PAR' ! Standard SAE constants
* Status:
INTEGER STATUS ! Global status
* Local Variables:
INTEGER EL ! Number of mapped pixels
INTEGER INDF ! NDF identifier
INTEGER PNTR( 1 ) ! Pointer to mapped values
LOGICAL BAD ! Bad pixels present? (junk variable)
REAL HIGH ! Maximum pixel value
*.
* Check inherited global status.
IF ( STATUS .NE. SAI__OK ) RETURN
* Obtain the input NDF and map its data array as _REAL values for
* reading.
CALL NDF_ASSOC( 'NDF', 'READ', INDF, STATUS )
CALL NDF_MAP( INDF, 'Data', '_REAL', 'READ', PNTR, EL, STATUS )
* Check that there are no bad pixels present.
CALL NDF_MBAD( .FALSE., INDF, INDF, 'Data', .TRUE., BAD, STATUS )
* Find the maximum pixel value and display the result.
CALL MAXIT( EL, %VAL( PNTR( 1 ) ), HIGH, STATUS )
CALL MSG_SETR( 'HIGH', HIGH )
CALL MSG_OUT( 'GETMAX_HIGH', ' Maximum value is ^HIGH', STATUS )
* Annul the NDF identifier.
CALL NDF_ANNUL( INDF, STATUS )
END
SUBROUTINE MAXIT( EL, ARRAY, HIGH, STATUS )
*+
* Name:
* MAXIT
* Purpose:
* Find the maximum value in a real array.
* Invocation:
* CALL MAXIT( EL, ARRAY, HIGH, STATUS )
* Description:
* The routine returns the maximum element value in a real array.
* Arguments:
* EL = INTEGER (Given)
* Number of array elements.
* ARRAY( EL ) = REAL (Given)
* The real array.
* HIGH = REAL (Returned)
* Maximum element value.
* STATUS = INTEGER (Given and Returned)
* The global status.
*-
* Type Definitions:
IMPLICIT NONE ! No implicit typing
* Global Constants:
INCLUDE 'SAE_PAR' ! Standard SAE constants
* Arguments Given:
INTEGER EL
REAL ARRAY( * )
* Arguments Returned:
REAL HIGH
* Status:
INTEGER STATUS ! Global status
* Local Variables:
INTEGER I ! Loop counter
*.
* Check inherited global status.
IF ( STATUS .NE. SAI__OK ) RETURN
* Find the maximum array value.
HIGH = ARRAY( 1 )
DO 1 I = 2, EL
IF ( ARRAY( I ) .GT. HIGH ) HIGH = ARRAY( I )
1 CONTINUE
END
The following is an example ADAM interface file (getmax.ifl) for the application above.
interface GETMAX
parameter NDF # NDF to be examined
position 1
prompt 'Data structure'
endparameter
endinterface