C     PROGRAM TO READ THE CONTENTS OF AN 'UNKNOWN' MAG TAPE TO TRY AND
C     DECIPHER THE STRUCTURE OF THE TAPE.
C     PROGRAM JUST SEQUENTIALLY TRIES TO READ AND THEN OUTPUT (IN OCTAL OR
C     ASCII) ONE RECORD OF THE TAPE AT A TIME
C
C     MAG TAPE MUST BE MOUNTED AS A 'FOREIGN VOLUMN'
C
      DIMENSION IBUF(512),ISTAT(2),IPRM(6)
      LOGICAL*1 JBUF(8192)
      EQUIVALENCE (IBUF,JBUF)
C     SET UP VALUES FOR WTQIO WORK
      IOATT="1400
      IODET="2000
      IORLB="1000
      IORWD="2400
      IOSKIP="2440
      IEDAO="363
      IEEOF="366
      ISIZE=512
      ITI=5
      IMT0=4
      ILP=3
      CALL GETADR(IPRM,IBUF)
      IPRM(2)=ISIZE
C     ATTACH MT0:
      CALL WTQIO(IOATT,IMT0,1,50,ISTAT)
C     REWIND MT0:
      CALL WTQIO(IORWD,IMT0,1,50,ISTAT)
  100 CONTINUE
C     START OF MAIN LOOP*** READ ONE RECORD
      CALL WTQIO(IORLB,IMT0,1,50,ISTAT,IPRM,ISW)
D     WRITE(ITI,150)ISTAT
D 150 FORMAT(' ISTAT = ',2(2X,O6))
      IF(ISTAT(1).EQ.1)GOTO 400
      IF(ISTAT(1).EQ.IEDAO) WRITE(ITI,200)
  200 FORMAT(' RECORD SIZE EXCEEDED BUFFER, DATA LOST',/)
      IF(ISTAT(1).EQ.IEEOF) WRITE(ITI,300)
  300 FORMAT(' END OF FILE DURING READ',/)
  400 WRITE(ITI,500) ISTAT(2)
  500 FORMAT(' SIZE OF RECORD (IN BYTES) = ',O6)
  550 WRITE(ITI,600)
  600 FORMAT('$LIST BUFFER (1=YES,2=NO,3=NEXT FILE) ? ')
      READ(ITI,700) IANS
  700 FORMAT(I2)
      IF(IANS.GT.1) GOTO 3000
C     YES, WRITE BUFFER
      ICOUNT=ISTAT(2)/2+1
      WRITE(ITI,800)
  800 FORMAT('$TI (1), OR LP (2) OUTPUT ? ')
      READ(ITI,700)IANS
      WRITE(ITI,900)
  900 FORMAT('$OCTAL(1),BYTE(2), OR ASCII(3) OUTPUT ? ')
      READ(ITI,700)JANS
      IOUT=ITI
      IF(IANS.EQ.2) IOUT=ILP
      DO 1500 J=1,ICOUNT,8
      ITEST=0
      DO 950 K=1,8
      IF(IBUF(J+K-1).NE.0)GOTO 975
  950 CONTINUE
C     FELL THROUGH, ALL ZERO'S
      GOTO 1500
  975 IF(JANS.EQ.3) WRITE(IOUT,1000)J*2-2,(JBUF(I),I=J*2-1,J*2+14)
 1000 FORMAT(' ',O6,1X,20('\',A1))
      IF(JANS.EQ.1) WRITE(IOUT,1100)J*2-2,(IBUF(I),I=J,J+7)
 1100 FORMAT(' ',O6,1X,8(1X,O6))
      IF(JANS.EQ.2) WRITE(IOUT,1200)J*2-2,(JBUF(I),I=J*2-1,J*2+14)
 1200 FORMAT(' ',O3,1X,16(1X,O6))
 1500 CONTINUE
      GOTO 550
C     HERE IF END OF FILE
 2000 WRITE(ITI,2100)
 2100 FORMAT('$NEXT FILE (1=YES,2=NO) ? ')
      READ(ITI,700)IANS
      IF(IANS.EQ.1) GOTO 100
      CALL WTQIO(IODET,IMT0,1,50,ISTAT)
      STOP
 3000 IF(IANS.EQ.2)GOTO 100
C     SET TO SKIP REST OF FILE
      IF(ISTAT(1).EQ.IEEOF)GO TO 100	!DON'T NEED TO SKIP IF EOF ALREADY
      WRITE(ITI,3100)
 3100 FORMAT('$NUMBER OF FILES TO SKIP ? ')
      READ(ITI,3200)INUMB
 3200 FORMAT(I4)
      IPRM(1)=INUMB
      CALL WTQIO(IOSKIP,IMT0,1,50,ISTAT,IPRM)
      CALL GETADR(IPRM,IBUF)
      GOTO 100
      END
