      SUBROUTINE LCCDBV(ERSTAT)
C***********************************************************************
C
C   NAME- LCCDBV
C
C   LANGUAGE- FORTRAN 77     TYPE- SUBROUTINE      COMPUTER- CRAY  
C
C   VERSION- 1.0    DATE- 10/12/94     PROGRAMMER- TERESA SIMMS, SMSRC
C   VERSION- 3.0    DATE- 05/10/96     PROGRAMMER- ALEX POZDNYAK (FDC)
C      MODIFIED TO RUN ON THE CRAY.  REPLACED I*4 WITH INT.
C   VERSION- 3.1    DATE- 07/25/97     PROGRAMMER- LEAH WILSON (HSTX) 
C      REPLACE CDB UTILITIES WITH NEW 8-BYTE CDB UTILITIES.  REMOVE
C      LCCDB$ SINCE NEW UTILITIES HANDLE ERRORS. 
C   VERSION- 3.2    DATE- 02/06/98     PROGRAMMER- LEAH WILSON (R-STX)  
C      ADD CHECK OF ASSOCIATED CHANNEL ARRAY, AND STOP PROCESSING
C      IF ERROR IS FOUND.
C   VERSION- 3.3    DATE- 03/04/02     PROGRAMMER- FRANK TILLEY (RAYTHEON)
C      FOR WR #22, CHANGED DIMENSIONS OF THE AMSU-B COEFFS FROM 5,4,90,0
C      TO 5,4,30,0. ADDED CDB CALL TO EXTRACT AMSU-B ASSOCIATED CHANNELS.
C  
C   FUNCTION- THIS SUBROUTINE FILLS THE COMMON BLOCK /LCCOEF/ WITH
C             VALUES NEEDED FOR GLOBAL LIMB CORRECTION.
C
C   COMMON AREA PARAMETERS- LCCOEF, SPGUNT
C
C   FILES-
C     DSN OR DESCRIPTIVE TITLE  I/O   UNIT  FUNCTIONAL DESCRIPTION
C     ------------------------  ---   ----  ----------------------
C     CDB                        I   CDBUNT  COEFFICIENT DATABASE.
C     KIDS                       O   KUNIT   KIDS MESSAGE FILE.   
C
C   CALLING SEQUENCE PARAMETERS-
C   NAME    TYPE   I/O   DESCRIPTION
C   ----    ----   ---   -----------
C   ERSTAT   INT    O    ERROR RETURN CODE.
C                         = 0 IF NO ERROR OCCURS,
C                         = 99 IF A FATAL ERROR OCCURS.
C
C   COMMON AREA PARAMETERS-
C
C   LOCAL PARAMETERS-
C   NAME    TYPE   DESCRIPTION
C   ----    ----   -----------
C   MSGCOD   INT   MESSAGE CODE TO PASS TO LCCDB$.
C   STATUS   INT   STATUS RETURNED FROM CALLED SUBROUTINES.
C
C   SUBPROGRAMS CALLED-  REALCOEF, INTCOEF, LCCDB$
C
C   EXIT STATES-
C    ERSTAT = 99 : FATAL ERROR ACCESSING THE CDB.
C
C   COMMENTS- IT IS ASSUMED THAT OPEN/CLOSE CDB OPERATIONS ARE CALLED
C             OUTSIDE THIS ROUTINE.
C
C***********************************************************************
C
      INCLUDE 'LCCOEF'
      INCLUDE 'SPGUNT'
C
      INTEGER ERSTAT, LPREDICTOR, LPREDICTAND, LCOUNT
      INTEGER MSGCOD, STATUS
ccft
      integer i, j, k, l
      CHARACTER*2 C2TEMP
      CHARACTER*8 SUBNAM
      CHARACTER*100 KMSG
      SUBNAM = 'SPGDVR  '
C
      ERSTAT = 0
C
C    GET THE GLOBAL LIMB CORRECTION COEFFICIENTS FOR THE HIRS.
C
      CALL REALCOEF(CDBUNT,'LIMBCORR','HIRS    ','COEFFS  ',20,4,56,
     1              0,LCCHIR,'GET',STATUS)
      IF(STATUS.NE.0) GO TO 900
C
C    GET THE GLOBAL LIMB CORRECTION COEFFICIENTS FOR THE AMSU-A.
C
      CALL REALCOEF(CDBUNT,'LIMBCORR','AMSUA   ','COEFFS  ',15,4,30,
     1              0,LCCAMA,'GET',STATUS)
      IF(STATUS.NE.0) GO TO 900
C
C    GET THE GLOBAL LIMB CORRECTION COEFFICIENTS FOR THE AMSU-B.
C  <<COMMENTED OUT WHILE COEFFS ARE READ FROM UNIT 75. WR #22 FHT>>
C     CALL REALCOEF(CDBUNT,'LIMBCORR','AMSUB   ','COEFFS  ',5,4,30,
C    1              0,LCCAMB,'GET',STATUS)
C     IF(STATUS.NE.0) GO TO 900
C
C    GET THE ASSOCIATED CHANNEL ARRAY FOR THE HIRS. 
C
      CALL INTCOEF(CDBUNT,'LIMBCORR','HIRS    ','ASSOCHAN',20,20,0,
     1             0,ASOHIR,'GET',STATUS)
      IF(STATUS.NE.0) GO TO 900
C
C    PERFORM QUALITY CHECKING ON THE HIRS ASSOCIATED CHANNEL ARRAY.
C    IF ANY CHANNEL HAS NO ASSOCIATED CHANNELS, STOP PROCESSING
C    SINCE THIS WILL CAUSE LIMB CORRECTION PROBLEMS.
C
      DO LPREDICTAND=1,20
        LCOUNT =0
        DO LPREDICTOR=1,20
          IF(ASOHIR(LPREDICTOR,LPREDICTAND).EQ.1) LCOUNT=LCOUNT+1
        ENDDO
        IF(LCOUNT.EQ.0) THEN
        KMSG(1:50)='* FATAL ERROR * HIRS Ch.    has no associated chan'
        KMSG(51:100)='nels.  Check CDB LIMBCORR/HIRS/ASSOCHAN coeff.  '
           WRITE(C2TEMP,'(I2)') LPREDICTAND
           CALL KIDS(KUNIT,SUBNAM,1,KMSG,0)
           ERSTAT = 99
           GO TO 900
        ENDIF
      ENDDO
C
C    GET THE ASSOCIATED CHANNEL ARRAY FOR THE AMSU-A.
C
      CALL INTCOEF(CDBUNT,'LIMBCORR','AMSUA   ','ASSOCHAN',15,15,0,
     1             0,ASOAMA,'GET',STATUS)
      IF(STATUS.NE.0) GO TO 900
C
C    PERFORM QUALITY CHECKING ON THE AMSU-A ASSOCIATED CHANNEL ARRAY.
C    IF ANY CHANNEL HAS NO ASSOCIATED CHANNELS, STOP PROCESSING
C    SINCE THIS WILL CAUSE LIMB CORRECTION PROBLEMS.
C
      DO LPREDICTAND=1,15
        LCOUNT =0
        DO LPREDICTOR=1,15
          IF(ASOAMA(LPREDICTOR,LPREDICTAND).EQ.1) LCOUNT=LCOUNT+1
        ENDDO
        IF(LCOUNT.EQ.0) THEN
        KMSG(1:50)='* FATAL ERROR *AMSU-A ch    has no associated chan'
        KMSG(51:100)='nels.  Check CDB LIMBCORR/AMSUA/ASSOCHAN coeff. '
           WRITE(C2TEMP,'(I2)') LPREDICTAND
           CALL KIDS(KUNIT,SUBNAM,1,KMSG,0)
           ERSTAT = 99
           GO TO 900
        ENDIF
      ENDDO
C
C    GET THE ASSOCIATED CHANNEL ARRAY FOR THE AMSU-B.
C
      CALL INTCOEF(CDBUNT,'LIMBCORR','AMSUB   ','ASSOCHAN',5,5,0,
     1             0,ASOAMB,'GET',STATUS)
      IF(STATUS.NE.0) GO TO 900
ccft
c     print *,' ASOAMB '
c     do i = 1, 5
c        print *, (asoamb(j,i),j=1,5)
c     end do
C
C    PERFORM QUALITY CHECKING ON THE AMSU-B ASSOCIATED CHANNEL ARRAY.
C    IF ANY CHANNEL HAS NO ASSOCIATED CHANNELS, STOP PROCESSING
C    SINCE THIS WILL CAUSE LIMB CORRECTION PROBLEMS.
C
      DO LPREDICTAND=1,5
        LCOUNT =0
        DO LPREDICTOR=1,5
          IF(ASOAMB(LPREDICTOR,LPREDICTAND).EQ.1) LCOUNT=LCOUNT+1
        ENDDO
        IF(LCOUNT.EQ.0) THEN
        KMSG(1:50)='* FATAL ERROR *AMSU-B ch    has no associated chan'
        KMSG(51:100)='nels.  Check CDB LIMBCORR/AMSUB/ASSOCHAN coeff. '
           WRITE(C2TEMP,'(I2)') LPREDICTAND
           CALL KIDS(KUNIT,SUBNAM,1,KMSG,0)
           ERSTAT = 99
           GO TO 900
        ENDIF
      ENDDO
      GO TO 1000
C
  900 ERSTAT = 99
C
 1000 RETURN
      END
