*
* $Id$
*
* $Log$
* Revision 1.1  1996/03/08 15:21:53  mclareni
* Initial revision
*
*
#if defined(CERNLIB_VAXS)
#include "sys/CERNLIB_machine.h"
#include "_epio/pilot.h"
#if defined(CERNLIB_TAPEFORM)
C THIS IS THE SOURCE FOR THE PROGRAM CALLED BY THE TAPEFORMAT
C COMMAND DESCRIBED IN THE NEXT DECK
C
C PLEASE NOTE THAT YOU MAY HAVE TO REDEFINE KEY3-KEY6 FOR YOUR INSTALLATION
      IMPLICIT INTEGER(A-Z)
      BYTE KEY1(5),KEY2(7),KEY3(6),KEY4(6),KEY5(6),KEY6(6)
      DATA KEY1  /4,1HS,1HW,1HA,1HP/
      DATA KEY2  /6,1HN,1HO,1HS,1HW,1HA,1HP/
      DATA KEY3  /5,1HM,1HT,1HA,1H0,1H:/
      DATA KEY4  /5,1HM,1HT,1HA,1H1,1H:/
      DATA KEY5  /5,1HM,1HT,1HA,1H2,1H:/
      DATA KEY6  /5,1HM,1HT,1HA,1H3,1H:/
      INTEGER*4 KEYVECT(5),KEYVECT2(9)
      DATA KEYVECT(1) /4/, KEYVECT2(1) /8/
      INTEGER*4 GETLINE(2),MAGTAP(2),MODE(2)
      BYTE RECBUF(80)
      EXTERNAL SS$_NORMAL,MT$K_NORMAL11,MT$K_NORMAL15
      EXTERNAL LIB$_SYNTAXERR
      KEYVECT(2)=%LOC(KEY1)
      KEYVECT(3)=1
      KEYVECT(4)=%LOC(KEY2)
      KEYVECT(5)=2
      KEYVECT2(2)=%LOC(KEY3)
      KEYVECT2(4)=%LOC(KEY4)
      KEYVECT2(6)=%LOC(KEY5)
      KEYVECT2(8)=%LOC(KEY6)
      GETLINE(1)=80
      GETLINE(2)=%LOC(RECBUF)
      CALL LIB$GET_FOREIGN(GETLINE,,GETLINE(1))
      IF(GETLINE(1) .NE. 0) THEN
        NCH=GETLINE(1)
        DO 10 I=1,NCH
        IF(RECBUF(I) .NE. 1H ) GOTO 11
 0010   CONTINUE
        GETLINE(1)=0
        GOTO 99
 0011   MAGTAP(2)=%LOC(RECBUF(I))
        MAGTAP(1)=I
        DO 12 I=MAGTAP(1),NCH
        IF(RECBUF(I) .EQ. 1H ) GOTO 14
 0012   CONTINUE
 0013   STATUS=%LOC(LIB$_SYNTAXERR)
        GOTO 9000
 0014   MAGTAP(1)=I-MAGTAP(1)
        K=I
        DO 15 I=K,NCH
        IF(RECBUF(I) .NE. 1H ) GOTO 16
 0015   CONTINUE
 0016   MODE(1)=NCH-I+1
        MODE(2)=%LOC(RECBUF(I))
        ENDIF
 0099 IF(GETLINE(1) .EQ. 0) THEN
 0100   MAGTAP(1)=80
        MAGTAP(2)=GETLINE(2)
        STATUS=LIB$GET_INPUT(MAGTAP,'Device name:',MAGTAP(1))
        IF(STATUS .NE. %LOC(SS$_NORMAL)) GOTO 9000
        IF(MAGTAP(1) .EQ. 0) GOTO 100
        ENDIF
      STATUS = LIB$LOOKUP_KEY (MAGTAP,KEYVECT2,,,)
      IF(STATUS .NE. %LOC(SS$_NORMAL)) GOTO 9000
      STATUS = SYS$ASSIGN(MAGTAP,ICHN,,)
      IF(STATUS .NE. %LOC(SS$_NORMAL)) GOTO 9000
      IF(GETLINE(1) .EQ. 0) THEN
 0200   MODE(1)=80
        MODE(2)=GETLINE(2)
        STATUS=LIB$GET_INPUT(MODE,'Tape mode  :',MODE(1))
        IF(STATUS .NE. %LOC(SS$_NORMAL)) GOTO 9000
        IF(MODE(1) .EQ. 0) GOTO 200
        ENDIF
      STATUS = LIB$LOOKUP_KEY (MODE,KEYVECT,KEYVAL,,)
      IF(STATUS .NE. %LOC(SS$_NORMAL)) GOTO 9000
      IF(KEYVAL .EQ. 1) THEN
        STATUS=MT_FORMAT(ICHN,MT$K_NORMAL15)
        ENDIF
      IF(KEYVAL .EQ. 2) THEN
        STATUS=MT_FORMAT(ICHN,MT$K_NORMAL11)
        ENDIF
 9000 CALL SYS$EXIT(%VAL(STATUS))
      END
#endif
#endif
