E Examples of Using IRQ

 E.1 Adding a new quality name
 E.2 Finding pixels which satisfy a quality expression

E.1 Adding a new quality name

This example shows a code fragment which adds the quality name SATURATED to an NDF and then assigns the quality to all pixels with value greater than 10.0. An error is reported if the quality name is already in use.

*  Include ADAM, IRQ and NDF symbolic constants.       

      INCLUDE ’SAE_PAR’                                

      INCLUDE ’IRQ_PAR’                                

      INCLUDE ’IRQ_ERR’                                

      INCLUDE ’NDF_PAR’                                

                                                       

*  Declare local INTEGER variables.                    

      INTEGER NDFIN, NDF2, NDIM, LBND(NDF__MXDIM), NEL,

     :        UBND(NDF__MXDIM), PNT, PNT2, PLACE,      

     :        STATUS                                   

                                                       

*  Declare local LOGICAL variables.                    

      INTEGER FOUND                                    

                                                       

*  Declare local CHARACTER variables.                  

      CHARACTER*(DAT__SZLOC) LOCS(5),XLOC              

      CHARACTER*(DAT__SZNAM) XNAME                     

                                                       

*  Start an NDF context.                               

      CALL NDF_BEGIN                                   

                                                       

*  Obtain an identifier for the input NDF.             

      CALL NDF_ASSOC( ’IN’, ’READ’, NDFIN, STATUS )    

                                                       

*  Attempt to locate any existing quality name         

*  information in the input NDF. If such information is

*  found, LOCS is returned holding a set of five HDS   

*  locators which identify the NDF and various items of

*  quality information. XNAME is returned holding the  

*  name of the NDF extension in which the information  

*  was found. If no quality name information is found, 

*  then an error is reported.                          

      CALL IRQ_FIND( NDFIN, LOCS, XNAME, STATUS )      

                                                       

*  If no quality name information was found, annul the 

*  error. New quality names information will be set up 

*  in the "IRAS" NDF extension.                        

      IF( STATUS .EQ. IRQ__NOQNI ) THEN                

         CALL ERR_ANNUL( STATUS )                      

                                                       

*  If the "IRAS" extension does not exist, create it.  

         CALL NDF_XSTAT( NDFIN, ’IRAS’, FOUND, STATUS )

         IF( .NOT. FOUND ) THEN                        

            CALL NDF_XNEW( NDFIN, ’IRAS’, ’IRAS’, 0, 0,

     :                     XLOC, STATUS )              

            CALL DAT_ANNUL( XLOC, STATUS )             

         END IF                                        

                                                       

*  Create a new structure to hold quality information  

*  in the "IRAS" NDF extension.                        

         CALL IRQ_NEW( NDFIN, ’IRAS’, LOCS, STATUS )   

      END IF                                           

                                                       

*  Attempt to add the quality name "SATURATED" to the  

*  NDF. If the name already exists an error will be    

*  reported.                                           

      CALL IRQ_ADDQN( LOCS, ’SATURATED’, .FALSE.,      

     :  ’Pixels with value greater than 10.0’, STATUS )

                                                       

*  Get a temporary NDF which is the same shape as the  

*  input NDF.                                          

      CALL NDF_BOUND( NDFIN, NDF__MXDIM, LBND, UBND,   

     :                NDIM, STATUS )                   

      CALL NDF_TEMP( PLACE, STATUS )                   

      CALL NDF_NEW( ’_REAL’, NDIM, LBND, UBND, PLACE,  

     :              NDF2, STATUS )                     

                                                       

*  Map the DATA array, initialising its contents to    

*  zero.                                               

      CALL NDF_MAP( NDF2, ’DATA’, ’_REAL’,             

     :              ’WRITE/ZERO’, PNT2, NEL, STATUS )  

                                                       

*  Map the DATA array of the input NDF.                

      CALL NDF_MAP( NDFIN, ’DATA’, ’_REAL’, ’READ’,    

     :              PNT, NEL, STATUS )                 

                                                       

*  Set pixels bad in the temporary array which         

*  correspond to pixels greater than 10.0 in the input 

*  NDF.                                                

      CALL MASKIT( %VAL(PNT), %VAL(PNT2), NEL, 10.0,   

     :             STATUS )                            

                                                       

*  Assign the quality SATURATED to all the pixels which

*  are bad in the temporary NDF.                       

      CALL IRQ_SETQM( LOCS, .TRUE., ’SATURATED’, NEL,  

     :               %VAL( PNT2 ), STATUS )            

                                                       

*  Release the resources used by IRQ.                  

      CALL IRQ_RLSE( LOCS, STATUS )                    

                                                       

*  End the NDF context.                                

      CALL NDF_END( STATUS )                           

E.2 Finding pixels which satisfy a quality expression

This example produces a copy of an input NDF in which all pixels which do not satisfy the quality expression “.NOT.( BACKGROUND .OR. SATURATED ) ” are set bad.

*  Attempt to locate any quality name information in   

*  the input NDF. If no quality name information is    

*  found, then an error is reported.                   

      CALL IRQ_FIND( NDFIN, LOCS, XNAME, STATUS )      Note 1

                                                       

*  Attempt to compile the quality expression.          

      QEXP = ’.NOT. ( SATURATED .OR. BACKGROUND )’     

      CALL IRQ_COMP( LOCS, IRQ__QNREF, .TRUE., QEXP,   Note 2

     :             UNDEF, NUNDEF, ERRPNT, IDQ, STATUS )

                                                       

*  Produce a temporary copy of the input NDF.          

      CALL NDF_TEMP( PLACE, STATUS )                   

      CALL NDF_COPY( NDFIN, PLACE, NDF2, STATUS )      

                                                       

*  Map the DATA array for UPDATE access.               

      CALL NDF_MAP( NDF2, ’DATA’, ’_REAL’, ’UPDATE’,   

     :              PNT2, NEL, STATUS )                

                                                       

*  Find all pixels which do not satisfy the quality    

*  expression and set them bad in the NDF copy.        

      CALL IRQ_SBAD( IDQ, .FALSE., NEL, %VAL( PNT2 ),  

     :               ALLBAD, NOBAD, STATUS )           

                                                       

*  Unmap the NDF copy.                                 

      CALL NDF_UNMAP( NDFIN, ’DATA’, STATUS )          

                                                       

*  Close down the IRQ identifier system.               

      CALL IRQ_CLOSE( STATUS )                         

                                                       

*  Release the resources used by IRQ.                  

      CALL IRQ_RLSE( LOCS, STATUS )                    

Programming notes:

(1)
NDFIN is the NDF identifier for the input NDF and should have been obtained previously. If the NDF contains no quality name information, then an error will be reported by IRQ_FIND.
(2)
The quality expression must be assigned to a character variable, since the call to IRQ_COMP updates the expression by removing leading blanks, and converting the expression to upper case. An access violation would result if a literal string were supplied as an argument, instead of a character variable. If either of the quality names SATURATED or BACKGROUND is not defined in the input NDF, then an error will be reported by IRQ_COMP, and the undefined names will be returned in the UNDEF array.