[comp.unix.questions] Reading IBM Tape

zellich@stl-07sima.army.mil ( Rich Zellich) (05/28/90)

If the problem is reading a standard-label EBCDIC tape, then we have a
general-purpose utility program that can read it and write an ASCII stream
to disk (dropping the labels).  The utility actually uses the information
in the labels, so it can handle blocked or unblocked, and fixed or variable
lenght records, as well as multi-reel files, multi-file reels, or combinations
of both multi-reel/-file.

The kicker is that the main section of the program is written in COBOL
(Philon COBOL), with the low-level I/O done by file open, close, read, and
write subroutines in C.

If this program (set of 5, actually, with the low-level I/O subroutines)
will help anyone, send me E-mail and I'll try to send it to you (my host
does *not* use domain name service, but still relies on the old NIC host
tables, so I may or may not be able to reply to the From: address in any
given received message).

Cheers,
Rich

pvo@sapphire.OCE.ORST.EDU (Paul O'Neill) (05/31/90)

In article <23453@adm.BRL.MIL> zellich@stl-07sima.army.mil ( Rich Zellich) writes:
>If the problem is reading a standard-label EBCDIC tape, then .......
>
You might try this:

(tcopy the tape first and adjust the ibs block size accordingly)

#!/usr/local/bin/perl
#
#       readEBCDICansi
#
#       6 apr 90
#       Paul V. O'Neill
#	Coastal Imaging Lab
#	Oregon State University
#
#       read an ansi-labeled tape coded in EBCDIC!


while(1) {
    open(HEADER, 'dd if=/dev/nrmt0 ibs=80 conv=ascii cbs=80|');
    $name = '';                                 # undef for die test
    while(<HEADER>) {                           # read the ansi header w/ dd
        print $_;                               # verbosely
        $name = $1 if /^HDR1(\w*)/;     # found file name (ignores ".ext")
    }
    close(HEADER);
    print "$name\n\n";                          # more verbosity
    die "$0: Looks like EOT $! $?\n" if $?;     # dd return error
    $name || die "$0: No name found $! $?\n";   # dd ok, but no name!

    open(OUT, ">$name");                        # open the output disk file
    open(DATA, 'dd if=/dev/nrmt0 ibs=3600 conv=ascii|');
    while(<DATA>) {                             # read tape file w/ dd
        s/\015//;                               # strip out infidel CR's
        print OUT $_;                           # and write to disk file
    }
    close OUT;
    close DATA;
    system 'mt -f /dev/nrmt0 fsf 1';            # skip the trailer tape file
}


Paul O'Neill                 pvo@oce.orst.edu		DoD 000006
Coastal Imaging Lab
OSU--Oceanography
Corvallis, OR  97331         503-737-3251