      SUBROUTINE CHGFIL                                                   00001 
C                                                                         00002 
CC    LBUFR AND DATA INITIALIZATION                                       00003 
C                                                                         00004 
      LOGICAL*1 WRITE(5)                                                  00005 
      INCLUDE 'SY:BCOM.FTN'                                               00006 
      INCLUDE 'SY:FLGCM.FTN'                                              00007 
      INCLUDE 'SY:LABCM.FTN'                                              00008 
      INCLUDE 'SY:MTCOMM.FTN'                                             00009 
      INCLUDE 'SY:MTFCB.FTN'                                              00010 
      DATA WRITE(1),WRITE(2),WRITE(3),WRITE(4),WRITE(5)                   00011 
     1 /1HW,1HR,1HI,1HT,1HE/                                              00012 
C                                                                         00013 
CC    IDENTIFY ROUTINE                                                    00014 
C                                                                         00015 
      IF (DEBUG) TYPE 1                                                   00016 
1     FORMAT(' CHGFIL')                                                   00017 
C                                                                         00018 
C                                                                         00019 
CC    TEST WHETHER INPUT OR OUTPUT MODE                                   00020 
C                                                                         00021 
      CALL STRCOM(TYPE,WRITE,5,IRET)                                      00022 
      IF(IRET.EQ.0) GO TO 32758                                           00023 
C                                                                         00024 
CC    INPUT MODE                                                          00025 
C                                                                         00026 
CC    READ TWO EOF LABELS                                                 00027 
C                                                                         00028 
      CALL REOF12                                                         00029 
      IF (DEBUG) TYPE 1                                                   00030 
C                                                                         00031 
CC    READ TWO HEADER LABELS                                              00032 
C                                                                         00033 
      CALL RHDR12(IFLAG)                                                  00034 
      IF (DEBUG) TYPE 1                                                   00035 
      IF(IFLAG.NE.0) GO TO 32757                                          00036 
      RETURN                                                              00037 
32757 TYPE 4                                                              00039 
4     FORMAT(' YOU HAVE REACHED LEOT')                                    00040 
      RETURN                                                              00041 
C                                                                         00043 
CC    OUTPUT MODE                                                         00044 
C                                                                         00045 
C                                                                         00046 
CC    WRITE TWO EOF LABELS                                                00047 
C                                                                         00048 
32758 CALL WEOF12                                                         00049 
      IF (DEBUG) TYPE 1                                                   00050 
C                                                                         00051 
CC    INCREMENT FILE COUNTER                                              00052 
C                                                                         00053 
      KTFILE = KTFILE + 1                                                 00054 
C                                                                         00055 
CC    WRITE TWO HDR LABELS OF A LOGICAL END-OF-TAPE                       00056 
C                                                                         00057 
      IF(LABFLG .EQ. 2) GO TO 32756                                       00058 
      CALL WHDR12                                                         00059 
      IF (DEBUG) TYPE 1                                                   00060 
C                                                                         00062 
CC    WRITE LOGICAL END-OF-TAPE                                           00063 
C                                                                         00064 
32756 IF(.NOT.(LABFLG .EQ. 2)) GO TO 32755                                00065 
      ASSIGN 32753 TO I32754                                              00066 
      GO TO 32754                                                         00066 
32753 ASSIGN 32752 TO I32754                                              00067 
      GO TO 32754                                                         00067 
32752 CONTINUE                                                            00068 
32755 RETURN                                                              00069 
32754 CONTINUE                                                            00070 
      MAGERR = .FALSE.                                                    00071 
      CALL MTEOF (MTLUN,ISTAT)                                            00072 
      IF(.NOT.(MTERRL)) GO TO 32751                                       00073 
      ASSIGN 32749 TO I32750                                              00073 
      GO TO 32750                                                         00073 
32749 CONTINUE                                                            00073 
32751 GO TO I32754                                                        00074 
32750 CONTINUE                                                            00075 
      CALL ERROR(TTLUN,'WRITE MAGTAPE FAILED',MTDSW,MTIOS)                00076 
      ASSIGN 32747 TO I32748                                              00077 
      GO TO 32748                                                         00077 
32747 GO TO I32750                                                        00078 
32748 CONTINUE                                                            00079 
      MAGERR = .TRUE.                                                     00080 
      GO TO I32748                                                        00081 
      END                                                                 00082 
