      SUBROUTINE AMAODB(AMADAT,AMAANC,AODREC,AMACNT,AODF1ST,ALAST,
     1                  LIMREC,GETLIMOB,OBSAMA,MAXLMT,ERSTAT)
      IMPLICIT NONE
C
C**********************************************************************
C
C   NAME- AMAODB
C
C   LANGUAGE- VS FORTRAN  TYPE- SUBROUTINE      COMPUTER- CRAY J916
C
C   VERSION- 2.0    DATE- 10/26/94   PROGRAMMER- SURYA JANDHYALA(SMSRC)
C   VERSION- 2.1    DATE- 01/19/95   PROGRAMMER- ALEX POZDNYAK(SMSRC)
C     XATOV-96:   STATEMENT 'IF(MISSNG) GO TO 30' CHANGED TO 'IF(MISSNG)
C                 GO TO 40'.
C   VERSION- 2.2    DATE- 12/8/95    PROGRAMMER- CHARLES A. DEAN
C            ATOVS- 274:  MADE CALLING ARGUMENTS CONSISTENT WITH HIRODB
C                         REMOVED CALL TO SPGFAU FOR AMA_FOVQ.
C                         REMOVED ISCNQ AND SCNQ VARIABLES. 
C                         CHANGED ASPOTS, ALINES, AELEMS, AND ANPARM TO
C                         ANSPOT,ATOTLN,ADATE, AND ANANC FROM /INSPARM/.    
C   VERSION- 3.0    DATE- 06/20/96  PROGRAMMER- LEAH WILSON (HSTX)
C            MODIFICATIONS FOR ATOVS BASELINE ON CRAY.
C   VERSION- 4.0    DATE- 09/02/97  PROGRAMMER- LEAH WILSON (HSTX)
C            REPLACE IRDB WITH AODF.  REMOVE AMAOD$.
C   VERSION- 4.1    DATE- 01/30/98  PROGRAMMER- LEAH WILSON (RAYTHEON)
C            ADD NODE TO AODF. 
C   VERSION- 4.2    DATE- 02/20/98  PROGRAMMER- LEAH WILSON (R-STX)
C            ADD AMACNT,AODF1ST,ALAST.
C   VERSION- 4.3    DATE- 04/06/98  PROGRAMMER- AMERICO ALLEGRINO,
C                                               LEAH WILSON (R-STX)
C            ADD CODE TO EXTRACT THE PARAMETERS NECESSARY FOR LIMB
C            CORRECTION AND WRITE THEM TO A SEPARATE FILE.
C   VERSION- 4.4    DATE- 07/16/98  PROGRAMMER- AMERICO ALLEGRINO (RAYTHEON)
C            ADD CODE TO CALCULATE CLOUD LIQUID WATER, TOTAL PRECIPITABLE
C            WATER OVER THE OPEN OCEANS AND, OVER LAND, A PRECIPITATION
C            INDEX.  THESE WILL BE USED TO FILTER THE LIMB CORRECTION
C            DATA COLLECTION. HIGH TERRAIN WILL ALSO BE EXCLUDED.
C   VERSION- 4.5    DATE- 08/06/98  PROGRAMMER- AMERICO ALLEGRINO (RAYTHEON)
C            ADDED THE AMSU-A LIMB CORRECTED DATA  ARRAY LCAMSA TO THE LIST
C            OF CALLED PARAMETERS SO THAT THE LIMB CORRECTED AMSU-A DATA
C            COULD BE PLACED ONTO THE AODF.
C   VERSION- 4.6    DATE- 08/26/98  PROGRAMMER- AMERICO ALLEGRINO (RAYTHEON)
C            CHANGED THE SCREENING OF THE LCDC SO THAT THE DATA IS SCREENED
C            FOR HIGH TERRAIN ONLY
C   VERSION- 4.7    DATE- 09/18/98  PROGRAMMER- AMERICO ALLEGRINO (RAYTHEON)
C            REMOVED THE POLARIZATION ADJUSTMENT (AKA RFI) FROM THE LCDC   
C            PROCESS. NOTE: SHOULD HAVE HAD ANOTHER VERSION EXPLAINING
C            THE ADDITION OF THE POLARIZATION ADJUSTMENT (OOPS!!!!)
C   VERSION- 4.8    DATE- 11/09/98  PROGRAMMER- AMERICO ALLEGRINO (RAYTHEON)
C            REMOVED THE AGOODL TEST
C   VERSION- 4.9    DATE- 11/10/98  PROGRAMMER- AMERICO ALLEGRINO (RAYTHEON)
C            ADDED RALPH FERRARO'S CALCULATIONS OF TOTAL PRECIPITABLE WATER,
C            CLOUD LIQUID WATER, SEA ICE, AND RAIN/NO_RAIN OVER OCEAN AND
C            SNOW COVER AND RAIN/NO_RAIN OVER LAND 
C   VERSION- 5.0    DATE- 12/03/98  PROGRAMMER- AMERICO ALLEGRINO (RAYTHEON)
C            ADDED THE MAXIMUM LIMIT FOR THE AMSUA SURFACE PARAMETERS
C   VERSION- 5.1    DATE-  4/14/99  PROGRAMMER- AMERICO ALLEGRINO (RAYTHEON)
C            REPLACED ALL OCCURANCES OF LCAMSA WITH AMADAT AND UPDATED
C            THE AMSU-A SURFACE PARAMETER CALCULATIONS.
C   VERSION- 5.2    DATE-  5/17/99  PROGRAMMER- AMERICO ALLEGRINO (RAYTHEON)
C            INCLUDED A CALCULATION OF CLOUD CLEARED AMSU-A CHANNELS 4 AND 5
C            USING THE CLOUD LIQUID WATER PARAMETER.
C   VERSION- 5.3    DATE-  5/26/99  PROGRAMMER- AMERICO ALLEGRINO (RAYTHEON)
C            REMOVED THE CALCULATIONS OF THE AMSUA SURFACE PRODUCTS FROM
C            THIS ROUTINE. THE SURFACE PRODUCTS ARE CALCULATED IN A NEW
C            ROUTINE AMASFC AND ARE STORED IN THE BUFFER AMADAT.
C   VERSION- 5.4    DATE-  6/02/99  PROGRAMMER- AMERICO ALLEGRINO (RAYTHEON)
C            REINTRODUCED THE LAND PRECIPITATION INDEX AS A SURFACE PRODUCT.
C   VERSION- 5.5    DATE-  6/22/99  PROGRAMMER- AMERICO ALLEGRINO (RAYTHEON)
C            INTRODUCED A CLW/LPI/PRECIP FLAG IN AMAANC(I,J,13) AND USED IT
C            TO REMOVE PRECIPITATION CONTAMINATED SPOTS FROM AMSU-A CHANNELS
C             4 & 5 INSTEAD OF USING THE MEDIAN FILTER PRECIP FLAG.
C   VERSION- 5.6    DATE-  7/15/99  PROGRAMMER- AMERICO ALLEGRINO (RAYTHEON)
C            REPLACED CLOUD CLEARED AMSUA CH 4 IN AMADAT(I,J,49) WITH
C            CLOUD CLEARED AMSUA CH 6.
C   VERSION- 5.7    DATE-  7/16/99  PROGRAMMER- AMERICO ALLEGRINO (RAYTHEON)
C            REPLACED CLOUD CLEARED AMSUA CH 6 IN AMADAT(I,J,49) WITH
C            CLOUD CLEARED AMSUA CH 4.
C   VERSION- 5.8    DATE- 12/5/00  PROGRAMMER-  M.P.FERGUSON (RITSS)
C            CHANGES TO ALLOW NONUSE OF SELECTED AMSU-A CHANNELS.  COMMON
C            AMASTAT ADDED, AND BADAMA ARRAY INITIALIZED (PR # 28).
C   VERSION- 5.9    DATE- 07/08/02  PROGRAMMER-  A. ALLEGRINO (RAYTHEON)
C            CHANGED TEST FORM MISSING BRIGHTNESS TEMPERATURE DATA TO
C            CHECK THE LIMB ADJUSTED TEMPERATURES AS WELL AS THE UNLIMB
C            ADJUSTED TEMPERATURES. (PR#61)
C   VERSION- 7.0    DATE- 08/06/02 PROGRAMMER- FRANK TILLEY (RAYTHEON)
C            ADDED AMBDAT, AMBANC, AND OBSAMB TO THE CALLING ARGUMENTS
C            FOR AMSU-B DATA. ADDED AMSU-B DATA TO THE OUTPUT TO THE
C            AMSU-A ORBITAL DATA FILE RECORD. REMOVED UNUSED CALLING
C            ARGUMENT LIMBADJ, DECLARED VARIABLES JDAY, IERR, AND ILERR.
C   VERSION- 7.1    DATE- 11/06/02 PROGRAMMER- A. ALLEGRINO (RAYTHEON)
C            REPLACED THE RAIN/NO RAIN FLAG WITH AMSUA CH 1 EMISSIVITY
C            AND REPLACED THE LAND PRECIPITATION INDEX WITH AMSUA CH2
C            EMISSIVITY
C   VERSION- 7.2 DATE 11/14/01 PORTED TO IBM SP.  REPLACED CRAY2IBM WITH
C            ASSIGNMENT TO I*2 VARIABLE.
C   VERSION- 7.3   DATE-02/13/02    PROGRAMMER- R. ROLLINS (CSC)
C       CORRECTED MOVE OF AODFBUF to I2AODF
C       CHANGED I4SPV to I2SPV (size of write buffer is I*2)
C   VERSION- 7.4   DATE- 02/27/03   PROGRAMMER- Rickey Rollins (CSC)
C       Replace R4SPV equivalence test with ISR4SPV function
C   VERSION- 7.5   DATE- 08/15/03   PROGRAMMER- Frank Tilley (Raytheon)
C       Changed declaration of AODFBUF from INTEGER to INTEGER*2 and
C       got rid of I2AODF. Equivalenced AODFBUF to C2AODF.
C   VERSION- 7.6   DATE- 12/17/03   PROGRAMMER- Frank Tilley (Raytheon)
C       Added a check for negative (missing) scan times in the DO 60
C       loop and skipped any lines where the scan time is missing.
C   VERSION- 7.7   DATE- 01/22/04   PROGRAMMER- Frank Tilley (Raytheon)
C       Removed AMSU-B code. The AMSU-B data will go into its own ODF.
C
C   FUNCTION-** THIS SUBROUTINE WRITES OUT A FRAME OF AMSU-A
C               DATA TO THE AMSU-A ORBITAL DATA FILE (AODF) A
C               CYCLE (SPOT) AT A TIME.
C
C   FILES-
C     DSN OR DESCRIPTIVE TITLE I/O   UNIT   FUNCTIONAL DESCRIPTION
C     ------------------------ ---   ----   ----------------------
C     .../AODF                  O    AIDFU  AODF FILE.
C     .../KIDS                  O    KUNIT  KIDS MESSAGE FILE.
C     .../*AMAX*.LIMOBS         O    ALMUNT TEMPERATURE DATA FOR LIMB
C                                           CORRECTION COEFFICIENT
C                                           GENERATION. 
C
C   CALLING SEQUENCE PARAMETERS-
C     VARIABLE          TYPE I/O  FUNCTION
C     --------          ---- ---  --------
C     AMADAT            REAL I/O  ARRAY OF DIMENSION (ANSPOT X ATOTLN
C                                 X ADATEL) WHICH HOLDS ONE DATA FRAME
C                                 OF 256 SECONDS OF AMSU-A SPOTS.
C     AMAANC            REAL I/O  ARRAY OF DIMENSION (ANSPOT X ATOTLN
C                                 X ANANC) WHICH HOLDS THE ANCILLARY
C                                 AMSU-A INFORMATION.
C     AODREC            INT    I  AODF RECORD NUMBER.
C     AMACNT            INT    O  NUMBER OF RECS WRITTEN TO AODF.
C     AODF1ST           INT    O  FIRST AMSU-A LINE WRITTEN TO AODF.
C     ALAST             INT    O  LARST AMSU-A LINE WRITTEN TO AODF.
C     LIMREC            INT   I/O COUNTS NUMBER OF RECS WRITTEN TO ALMUNT.
C     GETLIMOB          INT    I  =1 MEANS COLLECT SUB-1B* DATA. 
C     OBSAMA           REAL    I  UNLIMB CORRECTED AMSU-A DATA ARRAY.
C     MAXLMT           REAL    I  ARRAY WHICH CONTAINS THE MAXIMUM VALUES
C                                 FOR THE AMSUA SURFACE PRODUCTS
C                                 MAXLMT(1) = MAXIMUM TPW LIMIT
C                                 MAXLMT(2) = MAXIMUM CLW LIMIT
C     ERSTAT            INT    O  NORMALLY SET TO 0 BUT IF AN ERROR
C                                 OCCURS AN ERROR STATUS CODE IS SET.
C
C   COMMON AREA PARAMETERS- FRMINF,INSPARM,INPARM,SPVAL,SPGUNT
C
      INCLUDE 'INSPARM'
      INCLUDE 'FRMINF'
      INCLUDE 'INPARM'
      INCLUDE 'SPVAL'
      INCLUDE 'SPGUNT'
      INCLUDE 'ERPARM'
      INCLUDE 'ERINFO'
      INCLUDE 'AMASTAT'
      INCLUDE 'MONSTA'
C
C   LOCAL PARAMETERS-
C     VARIABLE          TYPE  DESCRIPTION
C     --------          ----  -------------------------------------
C     DUMMY             INT   VECTOR OF DIMENSION 2 HOLDING THE PLACE
C                             OF THE RECORD AND BYTE POINTERS.
C     I,J,K             INT   LOOP CONTROL INDICES.
C     MISSNG         LOGICAL  SET TRUE WHEN ALL BRIGHTNESS TEMPERATURES
C                             IN RDATCY ARE MISSING.
C     M                 INT   SCAN LINE NUMBER USED IN COMPUTING
C                             SPOTNR.
C     N                 INT   AMOUNT OF OVERFLOW SCAN LINES IN AMADAT.
C     RDATCY            REAL  VECTOR OF DIMENSION INPARM:ANCHAN WITH
C                             BRIGHTNESS TEMPERATURES OF AMSU-A DATA.
C     STAT              INT   ERROR STATUS RETURNED BY FMU'S.
C     SPOTNR            INT   SPOT NUMBER WITHIN THE DATA FRAME.
C     SPTCON            INT   INTEGER TO HOLD THE SPOT CONFIDENCE
C                             VALUE.
C     TERTYP            INT   INTEGER TO HOLD THE TERRAIN TYPE
C                             VALUE OF THE REAL AMAANC BUFFER
C                             EQUIVALENCED TO CERTYP.
C     C6TEMP           CH*6   TEMPOARARY FOR WRITING TO KIDS.
C     KMSG            CH*100  KIDS MESSAGE BUFFER.
C     AODFBUF          INT    8-BYTE AODF RECORD BUFFER.
C     DUMOBS           INT    DUMMY FOR WRITING TO AODF.
C     LIMAOBS          INT    ARRAY TO HOLD OBSERVATIONS FOR
C                             AMSU-A LIMB CORRECTION.
C     YEAR             INT    SCAN YEAR
C     MONTH            INT    SCAN MONTH
C     DAY              INT    SCAN DAY OF THE MONTH
C     HOUR             INT    SCAN HOUR OF THE DAY 
C     MIN              INT    SCAN MINUTES         
C     SEC              INT    SCAN SECONDS
C     SCNTIM           INT    ARRAY HOLDING THE SCAN DATE AND TIME
C     TOTELEM          INT    TOTAL NUMBER OF ELEMENTS IN THE LIMB
C                             OBS ARRAY (NUMBER OF SPOTS * (NUMBER OF
C                             CHANNELS + LAT + LONG + NODE)) + 4 TIME
C                             ELEMENTS
C     DYOFMN           INT    BEGINNING JULIAN DAY OF EACH MONTH - 1
C     JDAY             INT    JULIAN DAY
C     I4LIMAOBS        CH*1   I*4 VERSION OF THE LIMAOBS ARRAY.
C
C   SUBPROGRAMS CALLED-  KIDS 
C
C   EXIT STATES-
C       ERSTAT =  0; INDICATING NO ERROR FOUND
C       ERSTAT = 99; INDICATING A FATAL ERROR WAS DETECTED
C
C********************************************************************
C
      INTEGER ERSTAT, AODREC, IOERR, AMACNT,AODF1ST,ALAST
      REAL AMADAT(ANSPOT,ATOTLN,ADATEL),OBSAMA(ANSPOT,ATOTLN,ADATEL)
      REAL AMAANC(ANSPOT,ATOTLN,ANANC),MAXLMT(2)
C
      INTEGER    AODFLN, TOTELEM, ABFLEN
      PARAMETER (AODFLN=232, ABFLEN=AODFLN/2)
      PARAMETER (TOTELEM=ANSPOT*(ANCHAN+3)+4)
      CHARACTER*1 I4LIMAOBS(TOTELEM*4)
      CHARACTER*4 C4TEMP
      CHARACTER*6 C6TEMP
      CHARACTER*100 KMSG
      INTEGER SPOTNR,STAT, DUMOBS
      INTEGER IDX,I,J,K,M,N,SPTCON,TERTYP
      INTEGER DUMMY(2),LIMREC,GETLIMOB,DYOFMN(12)
      INTEGER FORDGTYR
      INTEGER SCNTIME(3),YEAR,MONTH,DAY,HOUR,MIN,SEC,JDAY
      INTEGER*4 LIMAOBS(TOTELEM)
      INTEGER*2 AODFBUF(ABFLEN)
      EQUIVALENCE (LIMAOBS, I4LIMAOBS)
      REAL RDATCY(ANCHAN)
      LOGICAL MISSNG, PACK,A1ST
      LOGICAL ISR4SPV
ccft  PARAMETER (N=ATOTBF/2)
      PARAMETER (N=ATOTBF)
      DATA DYOFMN/0,31,59,90,120,151,181,212,243,273,304,334/
C
C
C**********************************************************************
C
C INITIALIZE N TO REPRESENT THE OVERFLOW LINES AT THE BEGINNING OF
C THE BUFFER, WHICH IS HALF THE TOTAL OVERFLOW SCAN LINES.
C
      AMACNT = 0
      SPOTNR = 0
      M=N+1
      IOERR=0
      A1ST = .TRUE.
      PACK = .TRUE.
      DO IDX=1,ABFLEN
         AODFBUF(IDX) = I2SPV
      END DO  
C
C THE AMSU-A BUFFERS, PASSED IN THE CALL, CONTAIN A DATA FRAME
C CONSISTING OF 4 SCAN LINES OVERLAP AT THE BEGINNING AND THE END OF
C THE BUFFER.
C
C BEGIN LOOP OF ACTIVE SCAN LINES.  IF THE GETLIMOB FLAG IS SET TO 1,
C THEN EXTRACT THE DATA NECESSARY FOR THE LIMB CORRECTION COEFFICIENT
C GENERATION. (BUFFER LINES 9 THROUGH 40 = 32 SCANS)
C
ccft  DO 60 J = 1+N,ATOTLN-N
      DO 60 J = 1+N,ATOTLN
C
C INITIALIZE THE AMSU-A LIMB DATA ARRAY
C
          IF(GETLIMOB.EQ.1) THEN
             DO M=1,TOTELEM
                LIMAOBS(M)=0
             ENDDO
C
C IF THE SCAN TIME IS NEGATIVE (A MISSING VALUE), SKIP THE SPOT
C
            IF (ASCTIM(1,J).LT.0) GO TO 60
C
C
C  LOAD ORBIT NUMBER INTO LIMB DATA ARRAY & GET SCAN TIME IN YEAR/MONTH
C  , DAY/HOUR AND MIN/SEC AND THEN CONVERT TIME TO JULIAN DAY AND TENTHS
C  SECONDS.
C
             LIMAOBS(1)=SORB(2)
             CALL ODBTIM(ASCTIM(1,J),ASCTIM(2,J),SCNTIME)
             YEAR = SCNTIME(1)/100
             MONTH = SCNTIME(1) - ((SCNTIME(1)/100)*100)
             DAY = SCNTIME(2)/100
             HOUR = SCNTIME(2) - ((SCNTIME(2)/100)*100)
             MIN = SCNTIME(3)/100
             SEC = SCNTIME(3) - ((SCNTIME(3)/100)*100)
C
C CHECK TO SEE IF YEAR IS 2000 OR ABOVE.
C
             FORDGTYR = YEAR
             IF(YEAR .LT. 98) FORDGTYR=2000 + YEAR
C
C CALCULATE THE JULIAN DAY
C
             JDAY = DYOFMN(MONTH) + DAY
             IF(MOD(YEAR,4).EQ.0 .OR. MOD(FORDGTYR,400).EQ.0) THEN
                IF(MONTH.GT.2) JDAY = JDAY + 1
             ENDIF
             LIMAOBS(2) = YEAR
             LIMAOBS(3) = JDAY
C
C CALCULATE THE YEARTIME IN DECISECONDS
C
             LIMAOBS(4)= SEC* 10 + MIN*600 + HOUR*36000 +
     >                        (JDAY-1)*864000
          ENDIF
C
C LOAD THE AMSU-A BRIGHTNESS TEMPERATURES FOR CHANNELS 1-15 PER SPOT.
C
          DO 50 I = 1,ANSPOT
             DO IDX=1,ABFLEN
                AODFBUF(IDX) = I2SPV
             END DO  
C
C START FILLING AODF RECORD BUFFER.
C
              AODFBUF(1) = 2
              DUMOBS = 2
C
C  FIRST, DETERMINE IF RDATCY HAS ANY MISSING VALUES.  IF IT IS ALL 
C  MISSING, DO NOT WRITE THIS RECORD BUT GO TO 30 SO SPOTNR IS
C  SET CORRECTLY.
C
              MISSNG = .TRUE.
              DO 20 K = 1,ANCHAN
                  RDATCY(K)=OBSAMA(I,J,K)
                  IF(BADAMA(I,J,K).EQ.1)RDATCY(K) = R4SPV
                  IF(.NOT. ISR4SPV(RDATCY(K))) MISSNG = .FALSE.
   20         CONTINUE
              IF(MISSNG) GO TO 30
C
C  SINCE ALL RDATCY ARE NOT MISSING, FILL THE AODF BUFFER AND THE
C  LIMB COLLECTION BUFFER, IF SPECIFIED.
C  PLACE THE LIMB CORRECTED AMSU-A DATA INTO THE AODF BUFFER AT POSITIONS
C  31-45.
C
               DO 25 K=1,ANCHAN
                  IF (.NOT. ISR4SPV(RDATCY(K))) THEN
                     AODFBUF(DUMOBS) = NINT(RDATCY(K) * 64.0)
                  ENDIF
                  IF (.NOT. ISR4SPV(AMADAT(I,J,K))) THEN
                     AODFBUF(DUMOBS+29) = NINT(AMADAT(I,J,K) * 64.0)
                  ENDIF
                  DUMOBS = DUMOBS + 1
   25          CONTINUE

C 
C  CAPTURING DATA FOR LIMB CORRECTION 
C
               IF(GETLIMOB.EQ.1) THEN
                  DO 27 K=1,ANCHAN
                  IF (ISR4SPV(RDATCY(K))) THEN
                      LIMAOBS(K+7+(18*(I-1)))=0
                   ELSE
                      LIMAOBS(K+7+(18*(I-1)))=NINT(RDATCY(K)*100.0)
                   ENDIF
   27              CONTINUE
               ENDIF
C
C LOAD THE SOLAR ZENITH ANGLE OF THE AMSU-A SPOT.
C
               IF (.NOT. ISR4SPV(AMAANC(I,J,3))) THEN
                  AODFBUF(17) = NINT(AMAANC(I,J,3) * 128.0)
               END IF
C
C LOAD THE SATELLITE ZENITH ANGLE OF THE AMSU-A SPOT.
C
              IF (.NOT. ISR4SPV(AMAANC(I,J,4))) THEN
                 AODFBUF(18) = NINT(AMAANC(I,J,4) * 128.0)
              END IF
C
C LOAD THE SPOT NUMBER IN REFERENCE TO THE DATA FRAME.
C
   30         CONTINUE
              IF(J .GT. M) THEN
                 SPOTNR = (J - (N + 1))*ANSPOT
                 M = J
              ENDIF
              SPOTNR = SPOTNR + 1
              IF(MISSNG) GOTO 50
              AODFBUF(19) = SPOTNR
C
C LOAD THE LATITUDE OF THE SPOT.
C
              IF (AMAANC(I,J,1).GE.(-90.0)) THEN
                 IF (AMAANC(I,J,1).LE.90.0) THEN
                    AODFBUF(20) = NINT(AMAANC(I,J,1)*128.0)
                 END IF
              END IF
C
C LOAD THE LONGITUDE OF THE SPOT.
C
              IF (AMAANC(I,J,2).GE.(-180.0)) THEN
                 IF (AMAANC(I,J,2).LE.180.0) THEN
                    AODFBUF(21) = NINT(AMAANC(I,J,2)*128.0)
                 END IF
              END IF
C
C LOAD THE SPOT CONFIDENCE VALUE.
C
              SPTCON = NINT(AMAANC(I,J,5))
              IF (.NOT. ISR4SPV(AMAANC(I,J,5))) THEN
                 AODFBUF(22) = SPTCON
              END IF
C
C LOAD THE CHANNEL AVAILABILITY.
C
              AODFBUF(23) = NINT(AMAANC(I,J,6))
C
C LOAD THE TERRAIN HEIGHT OF THE SPOT.
C
              AODFBUF(24) = NINT(AMAANC(I,J,7))
C
C LOAD THE TERRAIN TYPE OF THE SPOT.
C
              TERTYP = NINT(AMAANC(I,J,8))
              IF (.NOT. ISR4SPV(AMAANC(I,J,8))) THEN
                 AODFBUF(25) = TERTYP
              END IF
C
C LOAD THE PRECIP EDITING FLAG OF THE SPOT.
C
              AODFBUF(26) = NINT(AMAANC(I,J,9))
C
C STORE CLOUD LIQUID WATER CONTENT, TOTAL PRECIPITABLE WATER AND 
C SEA ICE CONCENTRATION, RAIN/NORAIN FLAG, SNOW COVER, THE
C CLOUD CLEARED AMSU-A CHANNELS 4 AND 5 AND 6 IN THE AODF.
C  AMADAT(I,J,16) = CLOUD LIQUID WATER
C  AMADAT(I,J,17) = TOTAL PRECIPITABLE WATER
C  AMADAT(I,J,18) = SEA ICE CONCENTRATION
C  AMADAT(I,J,19) = RAIN/NORAIN FLAG
C  CHANGED TO AMADAT(I,J,19) = AMSU-A CH 1 EMISSIVITY (11/06/02)
C  AMADAT(I,J,20) = SNOW COVER
C  AMADAT(I,J,21) = CLOUD CLEARED AMSU-A CHANNEL 4
C  AMADAT(I,J,22) = CLOUD CLEARED AMSU-A CHANNEL 5
C  AMADAT(I,J,23) = CLOUD CLEARED AMSU-A CHANNEL 6
C  AMADAT(I,J,24) = LAND PRECIPITATION INDEX      
C  CHANGED TO AMADAT(I,J,24) = AMSU-A CH 2 EMISSIVITY (11/06/02)
C
C  REPLACED THE CLOUD CLEARED AMSU_A CHANNELS WITH THE 
C  PRECIPITATION SCREENED AMSU-A CHANNELS 4 AND 5
C
C  AMADAT(I,J,25) = PRECIPITATION SCREENED AMSU-A CHANNEL 4
C  AMADAT(I,J,26) = PRECIPITATION SCREENED AMSU-A CHANNEL 5
C
              AODFBUF(27) = NINT(AMADAT(I,J,16) * 64.0)
              AODFBUF(29) = NINT(AMADAT(I,J,17) * 64.0)
              AODFBUF(30) = NINT(AMADAT(I,J,24) * 64.0)
              IF (.NOT. ISR4SPV(AMADAT(I,J,18))) THEN
                 AODFBUF(46) = NINT(AMADAT(I,J,18)) 
              ENDIF
              IF (.NOT. ISR4SPV(AMADAT(I,J,19))) THEN
                 AODFBUF(47) = NINT(AMADAT(I,J,19) * 64.0)
              ENDIF
              IF (.NOT. ISR4SPV(AMADAT(I,J,20))) THEN
                 AODFBUF(48) = NINT(AMADAT(I,J,20))
              ENDIF
C LEAVE THE PRECIPITATION SCREENED AMSU-A CHANNEL 4 AND
C CHANNEL 5 SLOTS AS MISSING IF THE SPOT IS PRECIP
C CONTAMINATED.
              IF (.NOT. ISR4SPV(AMAANC(I,J,13))) THEN
                 AODFBUF(49) = NINT(AMADAT(I,J,21) * 64.0)
                 AODFBUF(50) = NINT(AMADAT(I,J,22) * 64.0)
              ENDIF
C
C LEAVE ROOM FOR BIAS CORRECTED AMSU-A CHANNEL DATA
C IN AODFBUF(51-65) AND 15 SPARES IN AODFBUF(66-80).    
C
C
C STORE THE COMPUTED SEA SURFACE TEMPERATURE USED TO COMPUTE
C SEA EMISSIVITY. (ASA, 11/12/02)
C
              AODFBUF(66) = NINT(AMAANC(I,J,15)*64.0)
C
C CHANGED IF STATEMENT TO SCREEN FOR HIGH TERRAIN ONLY  (ASA) 8/26/98
C
              IF (AMAANC(I,J,7) .GT. 1500) THEN
                 DO K=1,ANCHAN
                    LIMAOBS(K+7+(18*(I-1)))=0
                 ENDDO
              ENDIF
C
C LOAD THE NODE OF THE SPOT.
C
              AODFBUF(28) = NINT(AMAANC(I,J,11))
C
C PLACE THE LATITUDE, LONGITUDE, AND NODE INTO THE OBSERVATION RECORD
C FOR THE LIMB CORRECTION COEFFICIENT CREATION.
C               
              IF(GETLIMOB.EQ.1) THEN
                 LIMAOBS(5+(18*(I-1)))=NINT(AMAANC(I,J,1)*100.0)
                 LIMAOBS(6+(18*(I-1)))=NINT(AMAANC(I,J,2)*100.0)
                 LIMAOBS(7+(18*(I-1)))=AODFBUF(28)
              ENDIF
C
C INCREMENT THE RECORD COUNTER & WRITE THE SPOT TO THE AODF.
C
              AODREC = AODREC + 1
              WRITE(UNIT=AIDFU,REC=AODREC,IOSTAT=IOERR,ERR=900) AODFBUF
              IF(IOERR.NE.0) GO TO 900
C
C UPDATE INFORMATION FOR AODF FRAME HEADER
C
              AMACNT = AMACNT + 1
              IF(A1ST) THEN
                 AODF1ST = J
                 A1ST = .FALSE.
              ENDIF
              ALAST = J
   50     CONTINUE
          TOTALN = TOTALN + 1
C 
C  UPDATE LIMBOBS FILES
C 
          IF(GETLIMOB.EQ.1) THEN
             LIMREC = LIMREC + 1
             WRITE(UNIT=ALMUNT,REC=LIMREC,IOSTAT=IOERR,ERR=901) 
     1             I4LIMAOBS
             IF(IOERR.NE.0) GO TO 901
          ENDIF
C
C   CHECK NEXT LINE.
C
   60 CONTINUE
      GO TO 1000
C
  900 KMSG = '* FATAL ERROR * WRITING RECORD        OF AODF FILE'
      WRITE(C6TEMP,'(I6)') AODREC
      KMSG(32:37) =  C6TEMP
      IF(IOERR.NE.0) THEN
         KMSG(39:100) = 'WITH IOSTAT =     '
         WRITE(C4TEMP,'(I4)') IOERR
         KMSG(53:56) = C4TEMP
      ENDIF
      SUBNAM='SPGDVR'
      CALL KIDS(KUNIT,SUBNAM,0,KMSG,0)
C
C  SINCE SOMETHING WAS WRONG WITH THIS RECORD, DECREMENT THE RECORD
C  NUMBER COUNTER FOR THIS FILE
C
      AODREC = AODREC - 1
      ERSTAT = 99
      GO TO 1000
C
  901 KMSG(1:50)='* FATAL ERROR * WRITING RECORD        OF LIMB AMSU'
      KMSG(51:100)='-A OBSERVATIONS FILE.'
      WRITE(C6TEMP,'(I6)') LIMREC
      KMSG(32:37) = C6TEMP
      IF(IOERR.NE.0) THEN
         KMSG(71:100) = ' WITH IOSTAT =     '
         WRITE(C4TEMP,'(I4)') IOERR
         KMSG(86:89) = C4TEMP
      ENDIF
      SUBNAM='SPGDVR'
      CALL KIDS(KUNIT,SUBNAM,0,KMSG,0)
C
C  SINCE SOMETHING WAS WRONG WITH THIS RECORD, DECREMENT THE RECORD
C  NUMBER COUNTER FOR THIS FILE
C
      LIMREC = LIMREC - 1
      ERSTAT = 99
      GO TO 1000
C
C
 1000 RETURN
      END

