      SUBROUTINE GRD2X2(HNSPOT,IHRNBR,HIR2X2)
      IMPLICIT NONE
C
C********************************************************************
C
C   NAME- GRD2X2
C
C   LANGUAGE- FORTRAN 77     TYPE- SUBROUTINE      COMPUTER- CRAY  
C
C   VERSION- 1.0    DATE- 06/02/93   PROGRAMMER- BRIAN BARIL (RSTX)
C   VERSION- 1.1    DATE- 10/22/98   PROGRAMMER- BRIAN BARIL (ITSS)
C   VERSION- 1.2    DATE- 03/03/99   PROGRAMMER- BRIAN BARIL (ITSS)
C   VERSION- 1.3    DATE- 12/02/04   PROGRAMMER- FRANK TILLEY (RAYTHEON)
C
C   FUNCTION- THIS ROUTINE IS A MODIFICATION OF GRD3X3. ITS FUNCTION
C   IS TO CALCULATE THE ASSOCIATED 2X2 ARRAY GIVEN THE HIRS SPOT 
C   NUMBER USED (OVERALL) IN THE RETRIEVALS BUFFER.           
C   
C   VERSION- 1.1    FIXED A BUG THAT CAUSED CAUSED THE LINE NUMBER
C                   TO BE OFF BY ONE UNDER CERTAIN CONDITIONS. THIS
C                   CAUSED SOME BEST SPOT VALUES TO BE ZERO.
C   VERSION- 1.2    MIXED MODE CALCULATION OF SPOT AND LINE WAS
C                   CAUSING ERRONEUOS RESULTS.  PROBLEM FIXED.
C   VERSION- 1.3    'MOD' DOES NOT WORK PROPERLY WITH REAL VALUES.
C                   EXPLICITLY DECLARED ALL VARIABLES AND USED MOD 
C                   WITH INTEGER LINE VALUE.
C                   
C         
C
C   CALLING SEQUENCE PARAMETERS-
C     VARIABLE      TYPE   I/O      DESCRIPTION
C     --------      ---   ----      -----------
C     HNSPOT        INT     I       TOTAL NUMBER OF HIRS SPOTS PER
C                                   SCAN LINE.
C     IHRNBR        INT     I       THE HIRS SPOT NUMBER (OVERALL) IN
C                                   THE RETRIEVALS BUFFER.
C     HIR2X2        INT     O       THE ASSOCIATED 2X2 FOR THE GIVEN
C                                   HIRS SPOT.
C
C   LOCAL PARAMTERS-
C     VARIABLE      TYPE      DEFINITION
C     --------      ----      ----------
C     I,J,K          INT      LOOP COUNTERS.
C     LCTR           INT      LINE COUNTER.
C     SCTR           INT      SPOT COUNTER.
C     ILINE          INT      LOOP COUNTER DESIGNATING THE LINE
C                             BOUNDARIES OF THE ASSOCIATED 2X2
C                             ARRAY.
C     ISPOT          INT      LOOP COUNTER DESIGNATING THE SPOT
C                             BOUNDARIES OF THE ASSOCIATED 2X2
C                             ARRAY.
C     SPOT           INT      THE HIRS SPOT NUMBER IN THE HIRS SCAN
C                             LINE.
C     LINE           INT      THE HIRS LINE NUMBER.
C                             2X2 ARRAY.
C
C   SUBROUTINE USED- NONE.
C
C   FUNCTIONS USED-  INT, NINT, REAL
C
C   EXIT STATES- NONE.
C
C********************************************************************
C
      INTEGER HIR2X2(2,2,2), SPOT, LINE, CTRLNE, CTRSPT
      INTEGER HNSPOT, I, J, K, LCTR, SCTR, IHRNBR, ISPOT, ILINE
      REAL    RLNCNR,ILNCNR,RSPCNR,ISPCNR

C
      INCLUDE 'SPVAL'
C
C     INITIALIZE VARIABLES.
C
      DO 30, K=1,2
         DO 20, J=1,2
            DO 10, I=1,2
               HIR2X2(I,J,K) = I4SPV
   10       CONTINUE
   20    CONTINUE
   30 CONTINUE
C

      
C
C     CALCULATE THE LINE NUMBER OF THE SPOT OF INTEREST.
C
      LINE = (IHRNBR / HNSPOT) + 1
C     
C     DO MOD FOR SPOT ON INTEGER VALUES
C
      SPOT = MOD(IHRNBR,HNSPOT)
      IF(SPOT.EQ. 0) THEN
         LINE = LINE - 1
         SPOT = HNSPOT
      ENDIF    
C
C     FIND THE LOWER LEFT CORNER SPOT
C     I.E. LINE IS EVEN, SPOT IS ODD
C

      RLNCNR = REAL(LINE)/2.0
      ILNCNR = REAL(LINE/2)
      RSPCNR = REAL(SPOT)/2.0
      ISPCNR = REAL(SPOT/2)

      IF(RLNCNR.NE.ILNCNR) LINE = LINE - 1
      IF(RSPCNR.EQ.ISPCNR) SPOT = SPOT - 1

C
C     FIND THE SURROUNDING SPOTS FOR THE 2X2 ARRAY.
C     CREATE A CLOCKWISE 2X2 ARRAY STARTING AT THE 
C     LOWER LEFT SPOT ON THE RETRIEVAL GRID BOX
C     

      SCTR = 0
      DO 90, ISPOT = SPOT, SPOT + 1                              
         SCTR = SCTR + 1
         LCTR = 0
         DO 80, ILINE = LINE, LINE + 1
            LCTR = LCTR + 1
            HIR2X2(SCTR,LCTR,1) = ISPOT
            HIR2X2(SCTR,LCTR,2) = ILINE
   80    CONTINUE
   90 CONTINUE
C
C
      RETURN
      END
