      SUBROUTINE COLDVR(RETMET,CHNCMB,CNFLIM,AMASPT,AMALNE,
     1			DELSPT,DELSCN,RUNFILTR,LATLMT,NOH1BS,ERSTAT)
      IMPLICIT NONE
C
C********************************************************************
C
C   NAME- COLDVR
C
C   LANGUAGE- VS FORTRAN  TYPE- SUBROUTINE      COMPUTER- CRAY J916 
C
C   VERSION- 1.0    DATE- 11/15/91   PROGRAMMER- JEFF MANNING (SMSRC)
C   VERSION- 2.0    DATE- 05/05/94   PROGRAMMER- FRANK TILLEY (SMSRC)
C                   XATOV-1 REPLACE COMMON BLOCK /RETGRD/ WITH PARAMETER
C                   FILE RTVPARM AND COMMON BLOCK /RTVGRD/.  REPLACE
C                   COMMON BLOCK /BUFFER/ WITH PARAMETER FILE INSPARM
C                   AND COMMON BLOCK /INSCOM/.
C   VERSION- 2.1    DATE- 06/10/94   PROGRAMMER- JEFF MANNING (SMSRC)
C                   XATOV-12 NEED TO COLLOCATE ONE OUT OF EVERY TWO
C                   HIRS SPOTS TO THE RETRIEVAL GRID RATHER THAN ONE
C                   OUT OF EVERY 3X3 ARRAY.  NEED TO CHANGE THE
C                   DIMENSIONS OF RHRNBR AND RHRNOV.
C   VERSION- 2.2    DATE- 12/12/94   PROGRAMMER- CARLA NEIGH (SMSRC)
C        XATOV-87:  REPLACE COLLOCATION OF MSU AND SSU TO HIRS WITH
C                   COLLOCATION OF AMSU-A AND AMSU-B TO HIRS.  REMOVE
C                   CALLING ARGUMENTS FOR 3D CONSISTENCY TEST.  ADD
C                   CALLING ARGUMENTS FOR AMSU-A AND AMSU-B SPOTS
C                   COLLOCATED TO HIRS.  REMOVE HARD-CODING OF NUMBERS
C                   THAT EXIST IN PARAMETER FILES.  FIX BUGS INTRODUCED
C                   BY PREVIOUS CHANGE TO ROUTINE.  COMMENT OUT 3D
C                   CONSISTENCY TEST.
C   VERSION- 2.3    DATE- 07/12/95   PROGRAMMER- LI LU (SMSRC)
C       ATOVS-138:  INPUT ARGUMENTS DELSPT AND DELSCN ARE ADDED.
C		    COLLOCATION OF AMSU-A TO HIRS IS REPLACED WITH CALL
C		    TO AMABLI. COLLOCATION OF AMSU-B TO HIRS IS REMOVED
C		    AND REPLACED BY A COMMENT. THE CALL TO THE ROUTINE
C		    FOR PERFORMING THE 3D CONSISTENCY TEST IS UNCOMMENTED.
C   VERSION- 2.4    DATE- 10/02/95   PROGRAMMER- LI LU (SMSRC)
C       ATOVS-221:  SPOT CONFIDENCE MINIMUM LIMIT IS ADDED AS A
C                   CALLING ARGUMENT TO THE CALL TO AMABLI.
C   VERSION- 3.0    DATE- 05/28/96   PROGRAMMER- TIM GARDNER (HSTX)
C   VERSION- 3.1    DATE- 05/30/96   PROGRAMMER- TIM GARDNER (HSTX)
C   VERSION- 3.2    DATE- 09/19/97   PROGRAMMER- LEAH WILSON (HSTX)
C   VERSION- 3.3    DATE- 05/05/98   PROGRAMMER- LEAH WILSON (RSTX)
C   VERSION- 3.4    DATE- 06/18/98   PROGRAMMER- BRIAN BARIL (RSTX)
C   VERSION- 3.5    DATE- 10/01/98   PROGRAMMER- M.P.FERGUSON(RITSS)
C   VERSION- 3.6    DATE- 10/08/98   PROGRAMMER- M.P.FERGUSON(RITSS)
C   VERSION- 3.7    DATE- 05/27/99   PROGRAMMER- A. ALLEGRINO (RITSS)
C   VERSION- 3.8    DATE- 06/16/99   PROGRAMMER- A. ALLEGRINO (RITSS)
C   VERSION- 3.9    DATE- 10/25/99   PROGRAMMER- A. ALLEGRINO (RITSS)
C   VERSION- 3.10   DATE- 02/14/00   PROGRAMMER- M.P.FERGUSON (RITSS)
C   VERSION- 3.11   DATE- 03/16/00   PROGRAMMER- LEAH WILSON (RAYTHEON)
C   VERSION- 3.12   DATE- 05/05/00   PROGRAMMER- A. ALLEGRINO (RAYTHEON)
C   VERSION- 3.13   DATE- 06/15/00   PROGRAMMER- A. ALLEGRINO (RAYTHEON)
C   VERSION- 3.14   DATE- 08/03/00   PROGRAMMER- A. ALLEGRINO (RAYTHEON)
C   VERSION- 4.0    DATE- 09/12/00   PROGRAMMER- M.P.FERGUSON (RITSS)
C   VERSION- 4.1    DATE- 02/27/03   PROGRAMMER- Rickey Rollins (CSC)
C   VERSION- 4.2    DATE- 02/17/04   PROGRAMMER- F. TILLEY (RAYTHEON)
C   VERSION- 4.3    DATE- 08/11/06   PROGRAMMER- F. TILLEY (IMSG)
C
C   FUNCTION- THIS ROUTINE IS THE DRIVER ROUTINE FOR COLLOCATION OF
C             THE AMSU-A TO THE HIRS, AND THE COLLOCATION OF THE
C             RETRIEVAL GRID TO THE HIRS.  THIS ROUTINE ALSO PERFORMS
C             THE 3-DIMENSIONAL CONSISTENCY TEST.
C
C   VERSION- 3.0 DOCUMENTATION AND SYNTAX CHANGES FOR ATOVS BASELINE
C                ON THE CRAY.
C
C   VERSION- 3.1 FIXED BUG CAUSING SECOND DIMENSION IN RETANC TO BE
C                EXCEEDED OCCASIONALLY WHEN A SPOT IS MISSING IN
C                THE OVERLAP REGION.
C   VERSION- 3.2 RTOVS UPGRADES TO FIX RETRIEVAL FLAG ARRAY SO 
C                D3CON USES AN EXPANDED RETREIVAL FLAG, AND TO
C                MODIFY RETRIEVAL FLAG VALUES FROM CLEAR TO CLOUDY
C                IF THE 3D FILTER FLAG INDICATES A QUESTIONABLE
C                OR BAD SPOT, AND TO CREATE A RETREIVAL SURFACE
C                TYPE ARRAY.  ADD HIRDAT AND HDATEL TO CALL TO
C                CLRSPT.
C   VERSION- 3.3 ALLOW D3CON TO BE EXECUTED OR NOT BASED ON RUNFILTR.
C   VERSION- 3.4 CHANGED THE LOOPS TO INCREMENT BY TWOS IN ORDER TO
C                CREATE A UNIFORM 2X2 GRID.  SINCE THERE ARE 38 LINES
C                OF HIRS EARTH LOCATION DATA (LINES 6 -> 43), THE
C                OVERLAP BUFFER CONSISTS OF LINES 40 AND 42.  LINES 
C                44 AND 45 ARE CALIBRATION.  LINES 45 TO 50 APPAEAR
C                TO BE JUST EXTRA.  BOUNDARIES WERE ALL CHANGED 
C                ACCORDINGLY.
C   VERSION- 3.5 INCREASED DIMENSION OF CHNCMB TO (2X4).
C   VERSION- 3.6 ADDED PROPO2 TO CALLING LISTS FOR CLRSPT AND CLDSPT.
C   VERSION- 3.7 COMMENTED OUT THE CALL OF AMABLI SINCE IT IS CALLED
C                IN SUBROUTINE CONDVR.
C   VERSION- 3.8 REMOVED CNFLIM FROM CALLING LISTS FOR CLRSPT AND CLDSPT
C                SINCE SPOT CONFIDENCE TESTING IS REMOVED FROM THESE
C                ROUTINES.
C   VERSION- 3.9 CHANGED THE ASSIGNING OF THE PRECIPITATION EDITING FLAG
C                IN THE RETRIEVAL ANCILLARY BUFFER TO COINCIDE WITH THE
C                LOGICAL IN THE SUBROUTINE PRECIP.F
C   VERSION- 3.10 INCREASED DIMENSION OF CHNCMB TO (2X4X2).
C   VERSION- 3.11 TO CORRECT MISLOCATION AND MISSING LINES IN RODF BUFFER,
C                 CHANGE THIS TO REFLECT THAT LINES 48 & 49 ARE THE
C                 CALIBRATION LINES OF EVERY FRAME.  USABLE DATA IS SUB-
C                 SAMPLED (EVERY 2 LINES) STARTING AT LINE 10 AND ENDING 
C                 AT LINE 49 - THIS GIVES THE 20 LINES THAT GO INTO 
C                 RETDAT/RETANC.  (REFER TO SUBROUTINE INHIRS FOR
C                 DOCUMENTATION ON THE FRAME LAYOUT.)  REMOVE ALL REFERENCES
C                 TO JCNT, XRETFLG, XRETFOV, RHRNOV, AND RHRNBR, AND 
C                 COMMENT OUT D3CON CODE COMPLETELY, SINCE THIS WILL HAVE
C                 TO BE TOTALLY RE-WRITTEN BEFORE IT IS USABLE IN ATOVS.
C                 KEEP CALLING ARGUMENTS UNCHANGED (EVEN THOUGH SOME ARE
C                 NO LONGER USED) FOR FUTURE REFERENCE.  ALPHABETIZE
C                 LOCAL PARAMETERS LIST FOR EASE OF VIEWING.
C   VERSION- 3.12 THE PRECIPITATION FLAG IN THE ARRAY RETANC IS SET TO ZERO
C                 IF THERE IS NO PRECIPITATION. THIS CORRECTS PR#15
C   VERSION- 3.13 CHANGED THE REFERENCE TO THE MEDIAN FILTER WITHIN THE AMSUA
C                 ANCILLARY BUFFER TO ACCOUNT FOR VALUES GREATER THAN 1.
C                 (WR#74)
C   VERSION- 3.14 CHANGED THE REFERENCE TO THE MEDIAN FILTER WITHIN THE AMSUA
C                 ANCILLARY BUFFER TO CHECK FOR VALUES GREATER THAN 1.
C                 A VALUE OF 1 SIGNIFIES THAT THE MEDIAN FILTER WAS NOT APPLIED.
C   VERSION- 4.0  FOV SELECTION WAS CONSIDERABLY SIMPLIFIED FOR THIS ROUTINE.
C                 THE MAIN LOOP WHICH GOES THROUGH THE 2X2 BOX WAS MODIFIED TO
C                 CALL SUBROUTINE PIKSPT INSTEAD OF EITHER CLRSPT OR CLDSPT, AND
C                 ALL CALLS TO THESE TWO ROUTINES (AS WELL AS THOSE TO NSTSPT)
C                 WERE REMOVED.  THE CODE IS EASIER TO UNDERSTAND NOW (PR #24).
C   VERSION- 4.1    DATE- 02/27/03   PROGRAMMER- Rickey Rollins (CSC)
C        Replace R4SPV equivalence test with ISR4SPV function        
C   VERSION- 4.2  ADDED CALL TO SUBROUTINE AB2HIR TO COLLOCATE AMSU-B TO HIRS.
C   VERSION- 4.3  ADDED CALLING ARGUMENT 'NOH1BS' AND SKIPPED THE CALL TO
C                 SUBROUTINE AB2HIR IF THIS FLAG IS TRUE.
C
C   CALLING SEQUENCE PARAMETERS-
C     VARIABLE      TYPE    I/O       DEFINITION
C     ---------     ----    ---       ----------
C     RETMET        INT      I        RETRIEVAL METHOD ARRAY.
C                                     (DIMENSIONED 3)
C     CHNCMB        INT      I        ARRAY CONTAINING THE CLEAR,
C                                     CLOUDY,  NO-HIRS, AND HI-TERRAIN
C                                     CHANNEL MASKS, FOR LAND AND SEA
C                                     RETRIEVALS.
C                                     (DIM 2 X 4 X 2).
C     CNFLIM        INT      I        THE MINIMUM SPOT CONFIDENCE LIMIT.
C     AMASPT        INT      I        ARRAY (DIM INSPARM:HNSPOT X
C                                     INSPARM:HTOTLN) OF AMSU-A SPOT
C                                     NUMBERS COLLOCATED TO EACH HIRS
C                                     SPOT.
C     AMALNE        INT      I        ARRAY (DIM INSPARM:HNSPOT X
C                                     INSPARM:HTOTLN) OF AMSU-A LINE
C                                     NUMBERS COLLOCATED TO EACH HIRS
C                                     SPOT.
C     DELSPT	    REAL     I	      ARRAY (DIM INSPARM:HNSPOT X
C				      INSPARM:HTOTLN) CONTAINING SPOT
C				      DISPLACEMENT OF HIRS SPOT TO THE
C				      CLOSEST COLLOCATED AMSU-A SPOT.
C     DELSCN	    REAL     I	      ARRAY (DIM INSPARM:HNSPOT X
C				      INSPARM:HTOTLN) CONTAINING LINE
C				      DISPLACEMENT OF HIRS SPOT TO THE
C				      CLOSEST COLLOCATED AMSU-A SPOT.
C     RUNFILTR      INT      I        1=EXECUTE D3CON, 0 = NO D3CON
C     LATLMT       REAL      I        LATITUDE THRESHOLD FROM THE SOFTFLAGS
C                                     FILE, USED FOR PRECIPITATION EDITING
C     NOH1BS        LOG      I        FLAG SET TO TRUE IF NO HIRS 1B* IS
C                                     AVAILABLE.
C     ERSTAT        INT      O        ERROR STATUS CODE-SEE EXIT STATES.
C
C   LOCAL PARAMETERS-
C     VARIABLE      TYPE      DESCRIPTION
C     --------      ----      -----------
C     ACCLNE        INT       ACCEPTABLE HIRS LINE NUMBER CONTAINING
C                             THE HIRS SPOT TO GO INTO THE RETRIEVAL
C                             GRID.
C     ACCSPT        INT       ACCEPTABLE HIRS SPOT TO GO INTO THE
C                             RETRIEVAL GRID.
C     CLEAR         LOG       FLAG INDICATING THAT A CLEAR SPOT IS
C                             AVAILABLE.
C     ELEMNT        INT       COUNTER FOR THE HIRS DATA ELEMENTS THAT
C                             CORRESPOND TO THE AMSU CHANNEL DATA.
C     GDNSTR        LOG       N* FLAG INDICATING A GOOD N* VALUE HAS
C                             BEEN FOUND.
C     I,J           INT       DO LOOP COUNTERS.
C     IBIT          INT       INDICATES THE BIT TO BE SET FOR THE
C                             CHANNEL AVAILABILITY OF THE AMSU CHANNELS.
C     ITEMP         INT       TEMPORARY VARIABLE FOR HOLDING THE CHANNEL
C                             AVAILABILITY FOR THE AMSU INSTRUMENTS.
C     J             INT       RETRIEVAL GRID LINE COUNTER.
C     LINE          INT       LINE COUNTER.
C     NOFRAM        LOG       LOGICAL FLAG INDICATING THAT THE HIRS IS
C                             UNAVAILABLE FOR THE CURRENT FRAME.
C     NOHIRS        LOG       FLAG INDICATING THAT NO HIRS SPOTS ARE
C                             AVAILABLE.
C     PROPO2        INT       PROPORTION BETWEEN CLEAR AND CLOUDY FIELDS-
C                             OF-VIEW.
C     RTEMP         REAL      THE VARIABLE (REAL TYPE) EQUIVALENCED TO
C                             ITEMP AND USED FOR SETTING THE CHANNEL
C                             AVAILABILITY IN THE RETRIEVALS ANCILLARY
C                             BUFFER.
C     RETCON        INT       RETRIEVAL CONDITION.
C     RETLNE        INT       RETRIEVAL GRID LINE COUNTER.
C     RETPNT        INT       RETRIEVAL GRID POINT COUNTER.
C     RMETHD        INT       RETRIEVAL METHOD, USED IN SETTING THE
C                             RETRIEVAL FLAG.
C     RTLNE         INT       NUMBER OF RETRIEVAL LINES OVER THE
C                             EXTENDED DATA FRAME.
C     SPOT          INT       SPOT COUNTER.
C     SRFTYP        REAL      SURFACE TYPE ARRAY.
C
C   SUBROUTINE USED- AMABLI, CLRSPT, NOHSPT, NSTSPT, CLDSPT, D3CON
C
C   FUNCTIONS USED- IBSET, BTEST, NINT, REAL, MOD
C
C   EXIT STATES- 0 INDICATES NO ERRORS FOUND.
C               99 INDICATES A FATAL ERROR FROM A CALLED ROUTINE.
C
C********************************************************************
C
      INCLUDE'INSPARM'
      INCLUDE'INSCOM'
      INCLUDE'ERPARM'
      INCLUDE'ERINFO'
      INCLUDE'INPARM'
      INCLUDE'RTVPARM'
      INCLUDE'RTVGRD'
      INCLUDE'SPVAL'
      INCLUDE'FRMINF'
      INCLUDE'STBGEO'
C
      INTEGER RETMET(3), CHNCMB(2,4,2), CNFLIM, ERSTAT, RUNFILTR
      INTEGER AMASPT(HNSPOT,HTOTLN), AMALNE(HNSPOT,HTOTLN)
      REAL    DELSPT(HNSPOT,HTOTLN), DELSCN(HNSPOT,HTOTLN)
      LOGICAL NOH1BS
C
      INTEGER I, LINE, SPOT, RETCON, ITEMP, ELEMNT, J, JCNT
      INTEGER RETLNE, RETPNT, ACCLNE, ACCSPT, IBIT, RMETHD, RTLNE
      REAL    RTEMP, PROPO2, SRFTYP(RNGRDP,RTOTLN+HTOTBF), LATLMT
      LOGICAL CLEAR, NOHIRS, GDNSTR, NOFRAM
      LOGICAL ISR4SPV
C
      EQUIVALENCE(RTEMP,ITEMP)
C
C     INITIALIZE VARIABLES.
C
      RTLNE = RTOTLN + HTOTBF
      NOHIRS = .FALSE.
      NOFRAM = .FALSE.
      RETLNE = 0
      ACCLNE = I4SPV
      ACCSPT = I4SPV
C
C     CHECK TO SEE IF THE AMSU-A IS AN AVAILABLE INSTRUMENT.
C
C     IF (BTEST(FRMCNF,30)) THEN
C
C        COLLOCATE THE AMSU-A TO THE HIRS.
C
C        CALL AMABLI(AMASPT,DELSPT,AMALNE,DELSCN,CNFLIM,ERSTAT)
C        IF (ERSTAT .EQ. 99) RETURN
C
C     ENDIF
C
C     NO COLLOCATION OF AMSU-B TO HIRS IS DONE, HOWEVER THE SPACE FOR
C     COLLOCATED AMSU-B VALUES IS IN THE HIRS DATA BUFFER FOR POSSIBLE
C     FUTURE USE.
ccft
C     IF THE AMSU-B/MHS INSTRUMENT IS PRESENT, FIND THE AMSU-B/MHS SPOT
C     CLOSEST TO EACH HIRS SPOT IF THE HIRS IS PRESENT.
C
      IF ((BTEST(FRMCNF,29)) .AND. (.NOT.(NOH1BS))) THEN
         CALL AB2HIR(AMBDAT,AMBANC,HIRDAT,HIRANC)
      END IF
C
C     CHECK TO SEE IF THE HIRS IS AN AVAILABLE INSTRUMENT.
C
      IF (.NOT.BTEST(FRMCNF,31)) THEN
C
C        SET THE NOFRAM FLAG TO TRUE.
C
         NOFRAM = .TRUE.
C
      ENDIF
C
C     INITIALIZE THE SURFACE TYPE ARRAY.
C
      DO 80 J=1, RTLNE
          DO 70 I = 1, RNGRDP
            SRFTYP(I,J) = R4SPV
  70     CONTINUE
  80  CONTINUE
C
C     THIS SECTION HANDLES THE COLLOCATION OF THE HIRS TO THE RETRIEVAL
C     GRID.
C
C     LOOP THROUGH LINES IN THE HIRS DATA BUFFER.
C
C    NOTE THAT LOOPING THROUGH ODD LINES CAUSES PROBLEMS IN GRD2X2 WHEN
C    CONVERTING TO HIRS SPOT (1-56) AND LINE FROM HIRS SPOT (1-2800)
C    IN THE FRAME (ROUND-OFF ERROR CAUSES MISSING SPOTS OF DATA ON R1T),
C    SO COLDVR M*U*S*T BEGIN ON AN EVEN LINE.  TO MAXIMIZE THE AMOUNT OF
C    DATA AVAILABLE, IT MUST START ON LINE HTOTBF.  IF THIS ROUTINE IS
C    EVER MODIFIED TO LOOP OVER ODD LINES, THE ROUND-OFF ERROR MUST BE
C    ADDRESSED EVERYWHERE IN SPGDVR THAT THE 1-2800 SPOT NUMBER IS 
C    CONVERTED TO A SPOT AND LINE NUMBER. NOTE LINE 50 IS NOT USED.

      DO 130 LINE = HTOTBF,HTOTLN-1,2
C
C        SET THE RETRIEVAL GRID POINT COUNTER TO ZERO.
C
         RETPNT = 0
C
C        INCREMENT BY 1 THE RETRIEVAL GRID LINE COUNTER.
C        
         RETLNE = RETLNE+1
         J = J + 1
C
C        LOOP THROUGH EVERY OTHER HIRS SPOT.
C
         DO 120 SPOT = 1,HNSPOT,2
C
C           INCREMENT BY 1 THE RETRIEVAL GRID POINT COUNTER (EACH
C           RETRIEVAL GRID POINT CORRESPONDS TO EVERY OTHERS HIRS SPOT).
C
            RETPNT = RETPNT + 1
C
C           CHECK TO SEE IF THE HIRS IS AVAILABLE.
C
            IF (NOFRAM) THEN
C
C              THE HIRS IS UNAVAILABLE FOR THE FRAME, THUS NO HIRS SPOTS
C              CAN BE FOUND.
C
               CALL NOHSPT(SPOT,LINE,CHNCMB,ACCSPT,ACCLNE)
C
C              SET THE RETRIEVAL CONDITION FOR NOHIRS.
C
               RETCON = 3
               RMETHD = RETMET(3)
C
            ELSE
C
C             CALL THE SUBROUTINE PIKSPT TO FIND THE MOST ACCEPTABLE
C             SPOT, BE IT CLEAR OR CLOUDY.
C
              CALL PIKSPT(SPOT,LINE,CHNCMB,HNSPOT,HTOTLN,HNANC,
     1                   HIRANC,ACCSPT,ACCLNE,CLEAR,NOHIRS,
     2                   HIRDAT,HDATEL)

C
C             CHECK TO SEE IF NO HIRS SPOTS ARE AVAILABLE.
C
              IF (NOHIRS) THEN
C
C                CALL THE SUBROUTINE NOHSPT TO FIND THE MOST ACCEPTABLE
C                SPOT BASED ON THE OTHER SOUNDINGS INSTRUMENTS.
C
                 CALL NOHSPT(SPOT,LINE,CHNCMB,ACCSPT,ACCLNE)
C
C                RESET THE NOHIRS FLAG TO FALSE FOR THE NEXT SPOT.
C
                 NOHIRS = .FALSE.
C
C                SET THE RETRIEVAL CONDITION FOR NOHIRS.
C
                 RETCON = 3
                 RMETHD = RETMET(3)
C
              ELSE
C
C                CHECK TO SEE IF CLEAR SPOTS ARE AVAILABLE.
C
                 IF (CLEAR) THEN
C
C                   SET THE RETRIEVAL CONDITION FOR CLEAR HIRS.
C
                    RETCON = 0
                    RMETHD = RETMET(1)
                 ELSE
C
C                SET THE RETRIEVAL CONDITION FOR CLOUDY HIRS.
C
                    RETCON = 2
                    RMETHD = RETMET(2)
C
                 ENDIF
C
              ENDIF
C
            ENDIF
C
C           FILL THE RETRIEVALS ARRAY.
C
            IF (ACCSPT.EQ.I4SPV) THEN
C
C   IF LINES IS WITHIN FRAME (I.E. 10-49) AND ACCSPT IS MISSING, 
C   FLAG LINE AS MISSING.
C
               IF ((LINE.GE.HTOTBF).AND.(LINE.LE.HTOTLN-1))
     1            THEN
                  RETANC(RETPNT,RETLNE,1) = R4SPV
                  RETANC(RETPNT,RETLNE,2) = 0.0
                  RETANC(RETPNT,RETLNE,3) = 0.0
                  RETANC(RETPNT,RETLNE,4) = R4SPV
                  RETANC(RETPNT,RETLNE,8) = R4SPV
                ENDIF
            ELSE

C   IF LINES IS WITHIN FRAME (I.E. 10-49), WRITE THE OVERALL
C   HIRS SPOT NUMBER TO THE RETANC BUFFER

               IF ((LINE.GE.HTOTBF).AND.(LINE.LE.HTOTLN-1))
     1            THEN
C
C                 PUT THE HIRS SPOT NUMBER INTO THE RETRIEVALS
C                 ANCILLARY ARRAY.
C
                  RETANC(RETPNT,RETLNE,1) = (HNSPOT*(ACCLNE-1))+ACCSPT
C
C                 PUT THE HIRS CHANNEL AVAILABILITY FLAG INTO THE
C                 RETRIEVALS ARRAY.
C
                  RETANC(RETPNT,RETLNE,2) = HIRANC(ACCSPT,ACCLNE,7)
C
C                 PUT THE AMSU CHANNEL AVAILABILITY FLAGS INTO
C                 THE RETRIEVALS ANCILLARY ARRAY.
C
                  ITEMP = 0
                  DO 110 ELEMNT = HNCHAN+1, HNCHAN+ANCHAN+BNCHAN
                     IF (.NOT. ISR4SPV(HIRDAT(ACCSPT,ACCLNE,ELEMNT)))
     +               THEN
                        IBIT = ELEMNT - HNCHAN
                        ITEMP = IBSET(ITEMP,32 - IBIT)
                     ENDIF
  110             CONTINUE
C
                  RETANC(RETPNT,RETLNE,3) = RTEMP
C
C                 PUT THE RETRIEVAL FLAG INTO THE RETRIEVAL ANCILLARY
C                 ARRAY.
C
                  RETANC(RETPNT,RETLNE,4) = (RETCON*16) + RMETHD
C
C                 PUT THE PRECIPITATION FLAG INTO THE RETRIEVALS
C                 ANCILLARY ARRAY.
C
C                 CHANGED THE PRECIP EDIT FLAG TO HAVE BOTH THE
C                 MEDIAN FILTER AND THE COMBINATION CLW/LPI FLAG
C                 AS WAS DONE IN THE PRECIP.F SUBROUTINE
C
C                 CHECK OVER LAND (BASED ON AMSU-A FOV)
C
                  IF(AMAANC(AMASPT(ACCSPT,ACCLNE),AMALNE(ACCSPT,
     1            ACCLNE),8) .EQ.1) THEN
                     IF(AMAANC(AMASPT(ACCSPT,ACCLNE),AMALNE(ACCSPT,
     1               ACCLNE),13).EQ.1.AND.AMAANC(AMASPT(ACCSPT,ACCLNE)      
     2               ,AMALNE(ACCSPT,ACCLNE),9) .GT. 1) THEN
                        RETANC(RETPNT,RETLNE,8)= 1
                     ELSE
                        RETANC(RETPNT,RETLNE,8)= 0   
                     ENDIF
                  ENDIF
C
C                 IF SEA, CHECK THE LATITUDE (BACED ON AMSU-A FOV) 
C
                  IF(AMAANC(AMASPT(ACCSPT,ACCLNE),AMALNE(ACCSPT,
     1            ACCLNE),8) .EQ.0) THEN
                     IF(ABS(AMAANC(AMASPT(ACCSPT,ACCLNE),AMALNE(ACCSPT,
     1               ACCLNE),1)) .GT. LATLMT) THEN
                        IF(AMAANC(AMASPT(ACCSPT,ACCLNE),AMALNE(ACCSPT,
     1                  ACCLNE),13) .EQ. 1 .AND. AMAANC(AMASPT(ACCSPT,
     2                  ACCLNE),AMALNE(ACCSPT,ACCLNE),9) .GT. 1) THEN
                           RETANC(RETPNT,RETLNE,8)= 1
                        ELSE
                           RETANC(RETPNT,RETLNE,8)= 0   
                        ENDIF
                     ELSE
                        RETANC(RETPNT,RETLNE,8)=AMAANC(AMASPT(ACCSPT,
     1                  ACCLNE),AMALNE(ACCSPT,ACCLNE),13)
                     ENDIF
                  ENDIF
C
C                 PUT THE TERRAIN TYPE INTO THE SURFACE TYPE ARRAY.
C
                  SRFTYP(RETPNT,RETLNE) = HIRANC(ACCSPT,ACCLNE,9)
C
               ENDIF
            ENDIF
C
  120    CONTINUE
C
  130 CONTINUE
C
C####################################################################
C COMPLETELY COMMENT OUT THE FILTER MODULE, PER VERSION 3.11.
C IT WILL HAVE TO UNDERGO EXTENSIVE RE-CONFIGURATION, AND SHOULD ONLY
C BE LOOKING AT THE RETDAT/RETANC ARRAYS.  VARIABLES USED BY D3CON AND
C AMABLI (ABOVE) WERE LEFT INTACT IN CASE THESE ROUTINES ARE EVER
C RUN IN THIS SUBROUTINE IN THE FUTURE.
C
C     CHECK TO SEE IF THE HIRS AND AMSU-A ARE AVAILABLE INSTRUMENTS,
C     IF THE FILTER IS TO BE RUN.
C
C     IF(RUNFILTR.EQ.1) THEN
C        IF ((BTEST(FRMCNF,31)).AND.(BTEST(FRMCNF,30))) THEN
C
C     PERFORM THE 3-D CONSISTENCY TEST USING ROUTINE D3CON.
C
C              CALL D3CON(RHRNBR,XRETFLG,SRFTYP,ERSTAT)
C              IF (ERSTAT .EQ. 99) RETURN
C
C     CONVERT THE CLEAR RETRIEVALS FLAG VALUES TO CLOUDY IF THE 3D
C     CONSISTENCY FILTER FLAG IS QUESTIONABLE OR BAD.
C
C           DO K=1,RNGRDP
C              DO L=1,19
C                 IF(RETANC(K,L,4).LE.16) THEN
C                    IF(FILTOT(K,L).EQ.1.OR.FILTOT(K,L).EQ.4)
C    1                  RETANC(K,L,4) = 32
C                    ENDIF
C              ENDDO
C           ENDDO
C        ENDIF
C     ENDIF
C####################################################################
C
C     RETURN TO CALLING ROUTINE.
C
      RETURN
      END
