      SUBROUTINE CHKFRM(MXGDLN,LIMIT,GOODLN,QFLAGS,NUMLIN,NUMLAP,INSTRU,
     +                  ERSTAT)
      IMPLICIT NONE
C
C***********************************************************************
C   NAME- CHKFRM
C
C   LANGUAGE- FORTRAN 77     TYPE- SUBROUTINE    COMPUTER- CRAY    
C
C   VERSION- 1.0      DATE- 12/13/90   PROGRAMMER- CARLA NEIGH (SMSRC)
C   VERSION- 2.0      DATE- 12/5/95    PROGRAMMER- CARLA NEIGH (SMSRC)
C     ATOVS-268:  ADDED CALLING ARGUMENTS GOODLN, QFLAGS, NFATAL,
C                 NUMLIN, NUMLAP, FLAGID AND FLGSEQ FOR PASSING TO
C                 SQISUM.
C   VERSION- 3.0      DATE- 05/15/96   PROGRAMMER- ALEX POZDNYAK (FDC) 
C       FOR REHOSTING TO THE CRAY, CHANGED ALL I*4 DECLARATIONS TO
C       INTEGER AND ALL LOG*1 DECLARATIONS TO LOGICAL.
C   VERSION- 3.1      DATE- 12/16/99   PROGRAMMER- LEAH WILSON (RAYTHEON)
C       REMOVE NFATAL,FLAGID,FLGSEQ.  REMOVE SQISUM, INLINE CHKFR$.
C       ADDED CALLING ARGUMENT INSTRU TO REPLACE COMMON /ERINFO/:INSTR.
C   VERSION- 3.2      DATE- 11/30/04   PROGRAMMER- FRANK TILLEY (RAYTHEON)
C       UNDER WR #230 (NOAA-N READINESS) CHANGED 'HIRS/3' TO 'HIRS' IN
C       THE MESSAGE TEXT THAT REPORTS FAILURE OF THE ADJACENT LINS TEST.
C       NOAA-N FLIES THE HIRS/4, WHILE NOAA-KLM SATELLITES FLY THE HIRS/3.
C
C   FUNCTION-  CHKFRM CHECKS THE NUMBER OF MAXIMUM ADJACENT GOOD
C              QUALITY LINES FROM A DATA FRAME AGAINST LIMITS
C              OBTAINED FROM THE CDB.  IF THE LIMIT IS NOT MET,
C              THE DATA FRAME IS FLAGGED AS UNAVAILABLE IN THE
C              FRAME CONFIGURATION AND ROUTINES ARE CALLED TO
C              WRITE OUT A COUNT OF MISSING AND BAD LINES AND A
C              SCAN QUALITY INFORMATION SUMMARY TO THE KIDS FILE. 
C
C   CALLING SEQUENCES-
C      VARIABLE   TYPE I/O  DESCRIPTION
C      --------   ---- ---  -----------
C      MXGDLN     INT   I    MAXIMUM NUMBER OF ADJACENT GOOD LINES
C                            IN INSTRUMENT DATA FRAME
C      LIMIT      INT   I    NUMBER OF ADJACENT GOOD LINES NEEDED FOR
C                            GOOD FRAME (FROM CDB)
C      GOODLN     LOG   I    ARRAY (DIM NUMLIN) CONTAINING THE DUMMY
C                            LINE MAP, WHERE .TRUE. INDICATES A 
C                            USABLE SCAN LINE AND .FALSE. INDICATES AN
C                            UNUSABLE SCAN LINE.
C      QFLAGS     INT   I    ARRAY (DIM 32 X NUMLIN) OF SCAN LINE 
C                            QUALITY FLAGS FROM 1B* DATA FOR EACH SCAN
C                            LINE.
C      NUMLIN     INT   I    NUMBER OF LINES IN FRAME.
C      NUMLAP     INT   I    NUMBER OF LINES IN FRAME OVERLAP. 
C      INSTRU     INT   I    INSTRUMENT NUMBER.
C      ERSTAT     INT   O    RETURN CODE INDICATING IF ERROR OCCURRED
C                            IN EXECUTION OF CHKFR$, = 0 IF NO ERROR
C                            OR NON-FATAL ERROR OCCURRED.
C
C   LOCAL VARIABLES-
C      VARIABLE   TYPE       DESCRIPTION
C     --------   ----       -----------
C      STATUS      INT       STATUS CODE RETURNED FROM CHKFR$
C      BSHFT       INT       USED TO SHIFT BITS OF CONFIG
C      KMSG        CH*100    KIDS MESSAGE BUFFER
C      C4TEMP       CH*4     HOLDING BUFFER FOR WRITING TO KIDS.
C
C   SUBROUTINES CALLED- KIDS.          
C
C   INTRINSIC FUNCTIONS USED- IBCLR
C
C   EXIT STATES -  ERSTAT IS SET TO 99 WHEN A FATAL ERROR OCCURS
C                  IN CHKFR$ OR SQISUM.
C
C***********************************************************************
C
      INCLUDE 'ERPARM'
      INCLUDE 'ERINFO'
      INCLUDE 'MONSTA'
      INCLUDE 'SPGUNT'
      CHARACTER*2 C2TEMP
      CHARACTER*4 C4TEMP
      CHARACTER*6 INSTNAM(3)
      CHARACTER*100 KMSG
      CHARACTER*32 FLAGID(32)
      INTEGER   NUMLIN, MXGDLN, LIMIT, QFLAGS(32,NUMLIN), NFATAL, INSTRU 
      INTEGER   NUMLAP, ERSTAT, FLGSEQ(32), STATUS, BSHFT
      LOGICAL*1   GOODLN(NUMLIN)
      DATA INSTNAM / 'HIRS  ','AMSU-A','      '/
C
C    SUBNAM IS SET TO MAIN MODULE NAME, SINCE KIDS SUBROUTINE DETERMINES
C    NAME OF CURRENT SUBROUTINE.
C
      SUBNAM = 'SPGDVR'
      ERSTAT = 0
C
      IF (MXGDLN .LT. LIMIT) THEN
C
C  INCREMENT THE ADJACENT GOOD LINE COUNTER.
C
         ADJSCT(INSTRU) =ADJSCT(INSTRU) + 1
C
C    LIMIT IS NOT MET. CLEAR FRAME INSTR BIT AND DISPLAY ERROR MESSAGE. 
C
C    IBCLR TREATS THE BITS OF A 4 BYTE WORD AS BEING ORDERED
C    RIGHT TO LEFT FROM 0 TO 31.  FOR OUR PURPOSES IN FRMCNF
C    AND CONFIG, WE CONSIDER BITS AS BEING ORDERED FROM LEFT
C    TO RIGHT FROM 1 TO 32.  THUS TO SET WHAT WE CONSIDER TO
C    BE THE CORRECT BIT CORRESPONDING TO INSTR, THE BIT SET
C    WITH IBCLR MUST BE 32-INSTR. (BIT 1 CORRESPONDS TO BIT
C    31, 2 TO 30, 3 TO 29....)
C
         BSHFT=32-INSTRU
         FRMCNF=IBCLR(FRMCNF,BSHFT)
         IF(INSTRU.GT.2) INSTRU = 3
C
        KMSG(1:47)='* FRAME    ERROR *        adj. good lines      '
        KMSG(48:100)='does not meet req.      - Frame unusable'
        WRITE(C2TEMP,'(I2)') FRMNBR
        KMSG(9:10) = C2TEMP
        KMSG(20:25) = INSTNAM(INSTRU)
        WRITE(C4TEMP,'(I4)') MXGDLN
        KMSG(43:46) = C4TEMP
        WRITE(C4TEMP,'(I4)') LIMIT
        KMSG(67:70) = C4TEMP
        PRINT *,KMSG
        CALL KIDS(KUNIT,SUBNAM,0,KMSG,0)
C
      ENDIF
C
      RETURN
      END
