      SUBROUTINE HEADCHK(RECLEN,NCNT,ISTAT)
C
C THIS ROUTINE CHECKS KEY EDR HEADER BLOCK FIELDS FOR ACCEPTABLE VALUES.
C THE ERROR FLAG ISTAT IS SET AT FIRST OCCURANCE OF AN IMPROPER VALUE AND 
C THE ROUTINE IS EXITTED.
C
C    ISTAT = 0  GOOD RETURN
C    ISTAT = 1  BAD RETURN
C
C SANDY KRAMER  08/11/94
C
      INTEGER*2 RECLEN
C
      INCLUDE 'UNPACK.INC'
C
      IF ( RECLEN.NE.716 .AND.
     &     RECLEN.NE.1712 .AND.
     &     RECLEN.NE.3704 .AND.
     &     RECLEN.NE.3860 .AND.
     &     RECLEN.NE.3992 .AND.
     &     RECLEN.NE.5848 .AND.
     &     RECLEN.NE.6512 .AND.
     &     RECLEN.NE.6536 .AND.
     &     RECLEN.NE.11280 ) THEN
       WRITE(6,800) RECLEN,NCNT
       ISTAT = 1
       RETURN
      ELSE IF ( RECID.LT.0 .OR. RECID.GT.15 ) THEN
       WRITE(6,801) NCNT
       ISTAT = 1
       RETURN
      ELSE IF ( DATMOD.LT.0 .OR. DATMOD.GT.31 ) THEN
       WRITE(6,802) NCNT
       ISTAT = 1
       RETURN
      ELSE IF ( DRSDAT.LT.32 .OR. DRSDAT.GT.48 ) THEN
       WRITE(6,803) NCNT
       ISTAT = 1
       RETURN
      ELSE IF ( YEAR3.LT.0 .OR. YEAR3.GT.99 ) THEN
       WRITE(6,804) NCNT
       ISTAT = 1
       RETURN
      ELSE IF ( SCETHR.LT.0 .OR. SCETHR.GT.8784 ) THEN
       WRITE(6,805) NCNT
       ISTAT = 1
       RETURN
      ELSE IF ( SCETSC.LT.0 .OR. SCETSC.GT.3600 ) THEN
       WRITE(6,806) NCNT
       ISTAT = 1
       RETURN
      ELSE IF ( SCETML.LT.0 .OR. SCETML.GT.999 ) THEN
       WRITE(6,807) NCNT
       ISTAT = 1
       RETURN
      ELSE 
       ISTAT = 0
      END IF
C
      RETURN
  800 FORMAT(1X,'*HEADCHK*  INVALID RECORD LENGTH OF ',I5.5,
     &          ' BYTES AT RECORD',1X,I5)
  801 FORMAT(1X,'*HEADCHK*  INVALID RECORD IDENTIFICATION AT RECORD',
     &       1X,I5)
  802 FORMAT(1X,'*HEADCHK*  INVALID DATA MODE AT RECORD',1X,I5)
  803 FORMAT(1X,'*HEADCHK*  INVALID DRS DATA TYPE AT RECORD',1X,I5)
  804 FORMAT(1X,'*HEADCHK*  INVALID SCET YEAR AT RECORD',1X,I5)
  805 FORMAT(1X,'*HEADCHK*  INVALID SCET HOUR AT RECORD',1X,I5)
  806 FORMAT(1X,'*HEADCHK*  INVALID SCET SECONDS AT RECORD',1X,I5)
  807 FORMAT(1X,'*HEADCHK*  INVALID SCET MILLISECONDS AT RECORD',1X,I5)
      END
