      SUBROUTINE SEQUEN(LSTREC,CREC,NERR,LO,NREC)
C
C -- ROUTINE TO CHECK FOR PROPER RECORD SEQUENCING IN IEH FORMAT DATA.
C
      CHARACTER LSTREC*1,CREC*1
      INTEGER LO,NREC,NERR
C
      INTEGER NERSAV
C
      NERSAV = NERR
C
      IF(CREC .EQ. '3' .OR. CREC .EQ. '4' .OR. CREC .EQ. '5' .OR.
     *   CREC .EQ. '7') THEN
C         -- DETAIL RECORD.
          IF(LSTREC .EQ. '1') THEN
              WRITE(LO,*)' MISSING 2 CARD.'
              NERR = NERR + 1
          ELSE IF(LSTREC .EQ. '8') THEN
              WRITE(LO,*)' DETAIL CARDS CAN''T FOLLOW A FOOTNOTE',
     *                   ' CARD.'
              NERR = NERR + 1
          ENDIF
      ELSE IF(CREC .EQ. '1') THEN
C         -- FIRST HEADER RECORD.
          IF(LSTREC .EQ. '1') THEN
              WRITE(LO,*)' TWO 1 CARDS IN A ROW. MISSING 2 CARD.'
              NERR = NERR + 1
          ENDIF
      ELSE IF(CREC .EQ. '2') THEN
C         -- SECOND MASTER RECORD.
          IF(LSTREC .NE. '1') THEN
              WRITE(LO,*)' 2 CARD DOES NOT FOLLOW A 1 CARD.'
              NERR = NERR + 1
          ENDIF
      ELSE IF(CREC .EQ. '8') THEN
C         -- FOOTNOTE RECORD.
          IF(LSTREC .EQ. '1') THEN
              WRITE(LO,*)' MISSING A 2 CARD.'
              NERR = NERR + 1
          ENDIF
      ELSE IF(CREC .EQ. '9') THEN
C         -- TEXT RECORD.
          IF(LSTREC .EQ. '1') THEN
              WRITE(LO,*)' 9 CARD CANNOT FOLLOW A 1 CARD.'
              NERR = NERR + 1
          ENDIF
      ENDIF
C
C
      IF(NERR .GT. NERSAV) THEN
          WRITE(LO,*)' RECORD SEQUENCING ERROR ABOVE DETECTED AT',
     *               ' RECORD NUMBER',NREC
      ENDIF
C
      RETURN
      END
