The following contains an example of a simple application which uses the NDF_ routines to add the data arrays of two NDF data structures to produce a new NDF. This is not quite the simplest ``add'' application which could be written, but is close to it. Nevertheless, it will do a good job, and will respond correctly to unforseen circumstances or conditions which it is not designed to handle by issuing sensible error messages.
The intention here is simply to give a flavour of how the NDF_ routines are
used, so don't worry if you don't understand all the details.
The example is followed by some brief programming notes which include
references to other relevant sections of this document which can be
consulted if necessary.
If you are interested, a more sophisticated ``add'' application with extra
commentary can also be found in §.
SUBROUTINE ADD( STATUS ) [1]
INCLUDE 'SAE_PAR' [2]
INTEGER STATUS, EL, NDF1, NDF2, NDF3, PNTR1( 1 ), PNTR2( 1 ), PNTR3( 1 )
* Check inherited global status and begin an NDF context.
IF ( STATUS .NE. SAI__OK ) RETURN [3]
CALL NDF_BEGIN [4]
* Obtain identifiers for the two input NDFs and trim their pixel-index
* bounds to match.
CALL NDF_ASSOC( 'IN1', 'READ', NDF1, STATUS ) [5]
CALL NDF_ASSOC( 'IN2', 'READ', NDF2, STATUS )
CALL NDF_MBND( 'TRIM', NDF1, NDF2, STATUS ) [6]
* Create a new output NDF based on the first input NDF.
CALL NDF_PROP( NDF1, 'Axis,Quality', 'OUT', NDF3, STATUS ) [7]
* Map the input and output data arrays.
CALL NDF_MAP( NDF1, 'Data', '_REAL', 'READ', PNTR1, EL, STATUS ) [8]
CALL NDF_MAP( NDF2, 'Data', '_REAL', 'READ', PNTR2, EL, STATUS )
CALL NDF_MAP( NDF3, 'Data', '_REAL', 'WRITE', PNTR3, EL, STATUS )
* Check that the input arrays do not contain bad pixels.
CALL NDF_MBAD( .FALSE., NDF1, NDF2, 'Data', .TRUE., BAD, STATUS ) [9]
* Add the data arrays.
CALL ADDIT( EL, %VAL( PNTR1( 1 ) ), %VAL( PNTR2( 1 ) ), [10]
: %VAL( PNTR3( 1 ) ), STATUS )
* End the NDF context.
CALL NDF_END( STATUS ) [12]
END
* Subroutine to perform the addition.
SUBROUTINE ADDIT( EL, A, B, C, STATUS ) [11]
INCLUDE 'SAE_PAR'
INTEGER EL, STATUS, I
REAL A( EL ), B( EL ), C( EL )
IF ( STATUS .NE. SAI__OK ) RETURN
DO 1 I = 1, EL
C( I ) = A( I ) + B( I )
1 CONTINUE
END
Programming notes: