      SUBROUTINE RHDR12(IFLAG)                                            00001 
C                                                                         00002 
C     THIS SUBROUTINE READS HDR1 AND HDR2 RECORDS.                        00003 
C     VERIFIES FILE IDENTIFIER, FILE-SET IDENTIFIER, BLOCK LENGTH,        00004 
C     AND RECORD LENGTH.                                                  00005 
C                                                                         00006 
C                                                                         00007 
      INCLUDE 'SY:BCOM.FTN'                                               00008 
      INCLUDE 'SY:FLGCM.FTN'                                              00009 
      INCLUDE 'SY:LABCM.FTN'                                              00010 
      INCLUDE 'SY:MTCOMM.FTN'                                             00011 
      INCLUDE 'SY:MTFCB.FTN'                                              00012 
C                                                                         00013 
      LOGICAL*1 LVOL1(80)                                                 00014 
      EQUIVALENCE (IVOL1, LVOL1)                                          00015 
      DATA NBUFER/2800/                                                   00016 
C                                                                         00017 
      DATA HDR1,HDR2/4HHDR1,4HHDR2/                                       00018 
C                                                                         00019 
CC    IDENTIFY ROUTINE                                                    00020 
C                                                                         00021 
      IF (DEBUG) TYPE 1                                                   00022 
1     FORMAT (' RHDR12')                                                  00023 
C                                                                         00024 
      IFLAG = 0                                                           00025 
C                                                                         00026 
C**   READ HDR1 RECORD (OR POSSIBLY EOF MARK IF AT EOT)                   00027 
      ASSIGN 32757 TO I32758                                              00028 
      GO TO 32758                                                         00028 
C*    TEST FOR END-OF-FILE                                                00029 
32757 IF(.NOT.(MAGEND)) GO TO 32756                                       00030 
      MAGEND = .FALSE.                                                    00031 
      IFLAG = -1                                                          00032 
      RETURN                                                              00033 
C*    VERIFY HDR1 RECORD                                                  00035 
32756 CALL STRCOM (BUFR(1), HDR1, 4, IRET)                                00036 
      IF(IRET.EQ.0) GO TO 32755                                           00037 
      TYPE 2, BUFR(1)                                                     00038 
2     FORMAT (' *HDR1* RECORD NOT FOUND, FOUND INSTEAD WAS ', A4 /)       00039 
      ASSIGN 32753 TO I32754                                              00040 
      GO TO 32754                                                         00040 
32753 CONTINUE                                                            00041 
C *   VERIFY FILE IDENTIFIER                                              00042 
32755 IF(.NOT.(LABFLG .EQ. 0)) GO TO 32752                                00043 
      DO 32751 I=1,17                                                     00044 
      LBDATA(I) = DDFNAM(I)                                               00044 
32751 CONTINUE                                                            00044 
32752 IF(.NOT.(LABFLG .EQ. 1)) GO TO 32750                                00046 
      DO 32749 I=1,17                                                     00047 
      LBDATA(I) = DFNAME(I)                                               00047 
32749 CONTINUE                                                            00047 
32750 CALL STRCOM (LBUFR(5), LBDATA(1), 17, IRET)                         00049 
      IF(IRET.EQ.0) GO TO 32748                                           00050 
      TYPE 3, (LBDATA(L), L=1,17), (LBUFR(K), K=5,21)                     00051 
3     FORMAT (' FILE IDENTIFIER IS NOT AS EXPECTED '/                     00052 
     1  ' EXPECTED VALUE:  ', 17A1, 10X,' TAPE VALUE:  ',17A1 /)          00053 
C *   VERIFY FILE-SET IDENTIFIER (VOLUME IDENTIFIER FROM VOL1 LABEL)      00055 
32748 CALL STRCOM (LBUFR(22),VSNLST(1),6,IRET)                            00056 
      IF(IRET.EQ.0) GO TO 32747                                           00057 
      TYPE 4, (VSNLST(L),L=1,6), (LBUFR(K),K=22,27)                       00058 
4     FORMAT (' FILE-SET IDENTIFIER IS NOT AS EXPECTED'/                  00059 
     1   ' EXPECTED VALUE:  ',6A1,10X,' TAPE VALUE:  ',6A1/)              00060 
      ASSIGN 32746 TO I32754                                              00061 
      GO TO 32754                                                         00061 
32746 CONTINUE                                                            00062 
C                                                                         00063 
CC    NOW CHECK HDR2                                                      00064 
C                                                                         00065 
32747 ASSIGN 32745 TO I32758                                              00066 
      GO TO 32758                                                         00066 
C                                                                         00067 
CC    VERIFY HDR2 RECORD                                                  00068 
C                                                                         00069 
32745 CALL STRCOM (BUFR(1),HDR2,4,IRET)                                   00070 
      IF(IRET.EQ.0) GO TO 32744                                           00071 
      TYPE 5, BUFR(1)                                                     00072 
5     FORMAT (' *HDR2* RECORD NOT FOUND, FOUND INSTEAD WAS ',A4/)         00073 
      ASSIGN 32743 TO I32754                                              00074 
      GO TO 32754                                                         00074 
32743 CONTINUE                                                            00075 
C                                                                         00076 
CC    OBTAIN BLOCK LENGTH                                                 00077 
C                                                                         00078 
32744 DECODE (5,6,LBUFR(6)) IBLOCL                                        00079 
6     FORMAT (I5)                                                         00080 
      IF(IBLOCL.LE.2046) GO TO 32742                                      00081 
      TYPE 7, IBLOCL                                                      00082 
7     FORMAT (' BLOCK LENGTH = ',I5,' (SHOULD BE .LE. 2046)'/)            00083 
C                                                                         00085 
CC    OBTAIN RECORD LENGTH                                                00086 
C                                                                         00087 
32742 DECODE (5,6,LBUFR(11)) IRECL                                        00088 
      IF(IRECL.LE.2046) GO TO 32741                                       00089 
      TYPE 8, IRECL                                                       00090 
8     FORMAT (' RECORD LENGTH = ',I5,' (SHOULD BE .LE. 2046)'/)           00091 
C                                                                         00093 
CC    READ EOF MARK                                                       00094 
C                                                                         00095 
32741 ASSIGN 32740 TO I32758                                              00096 
      GO TO 32758                                                         00096 
32740 IF(MAGEND) GO TO 32739                                              00097 
      TYPE 9                                                              00098 
9     FORMAT (' NO EOF AFTER HDR2')                                       00099 
      ASSIGN 32738 TO I32754                                              00100 
      GO TO 32754                                                         00100 
32738 CONTINUE                                                            00101 
32739 MTEOFL=.FALSE.                                                      00102 
      MAGEND = .FALSE.                                                    00103 
      RETURN                                                              00104 
32758 CONTINUE                                                            00105 
      ASSIGN 32736 TO I32737                                              00105 
      GO TO 32737                                                         00105 
32736 GO TO I32758                                                        00105 
32737 CONTINUE                                                            00106 
      MAGERR = .FALSE.                                                    00107 
      NBUFER=2800                                                         00108 
      CALL MTRLB(MTLUN,LBUFR,NBUFER,ISTAT)                                00109 
      IF(.NOT.(ISTAT.EQ.0)) GO TO 32735                                   00110 
      MAGEND = .FALSE.                                                    00111 
      NBUFER = MTIOS(2)                                                   00112 
32735 IF(.NOT.(ISTAT.EQ.1)) GO TO 32734                                   00114 
      ASSIGN 32732 TO I32733                                              00114 
      GO TO 32733                                                         00114 
32732 CONTINUE                                                            00114 
32734 IF(.NOT.(ISTAT.EQ.2)) GO TO 32731                                   00115 
      IF(.NOT.(MTIOS(1).NE.MTEOFS)) GO TO 32729                           00116 
      ASSIGN 32728 TO I32733                                              00116 
      GO TO 32733                                                         00116 
32728 GO TO 32730                                                         00116 
32729 MAGEND = .TRUE.                                                     00117 
32730 CONTINUE                                                            00118 
32731 GO TO I32737                                                        00119 
32733 CONTINUE                                                            00120 
      CALL ERROR (TTLUN,'READ MAGTAPE FAILED',MTDSW,MTIOS)                00121 
      ASSIGN 32726 TO I32727                                              00122 
      GO TO 32727                                                         00122 
32726 GO TO I32733                                                        00123 
32727 CONTINUE                                                            00124 
      MAGERR = .TRUE.                                                     00125 
      GO TO I32727                                                        00126 
32754 CONTINUE                                                            00127 
      IABORT = 1                                                          00128 
      IF (IABORT .EQ. 1) STOP                                             00129 
      GO TO I32754                                                        00130 
      END                                                                 00131 
