Fortran Library Reference

tstate: Get Logical State of Tape I/O Channel

The function is called by:

INTEGER*4 tstate

n = tstate( tlu, fileno, recno, errf, eoff, eotf, tcsr )

tlu

INTEGER*4

Input 

Tape logical unit, in range 0 to 7 

fileno

INTEGER*4

Output 

Current file number  

recno

INTEGER*4

Output 

Current record number 

errf

LOGICAL

Output 

True=an error occurred  

eoff

LOGICAL

Output 

True=the current file is at EOF  

eotf

LOGICAL

Output 

True=tape has reached logical end-of-tape  

tcsr

INTEGER*4

Output 

True=hardware errors on the device. It contains the tape drive control status register. If the error is software, then tcsr is returned as zero. The values returned in this status register vary grossly with the brand and size of tape drive.

For details, see st(4s).

While eoff is true, you cannot read from that tlu. You can set this EOF status flag to false by using tskipf() to skip one file and zero records:


    n = tskipf( tlu, 1, 0). 

Then you can read any valid record that follows.

End-of-tape (EOT) is indicated by an empty file, often referred to as a double EOF mark. You cannot read past EOT, but you can write past it.

Example: Write three files of two records each:


    CHARACTER devnam*10 / '/dev/nrst0' /,
&                 f0rec1*512 / "eins" /, f0rec2*512 / "zwei" /,
&                 f1rec1*512 / "ichi" /, f1rec2*512 / "ni__" /,
&                 f2rec1*512 / "un__" /, f2rec2*512 / "deux" /
    INTEGER*4 n / 0 /, tlu / 1 /, tclose, topen, trewin, twrite
    LOGICAL islabeled / .false. /
    n = topen( tlu, devnam, islabeled )
    n = trewin( tlu )
    n = twrite( tlu, f0rec1 )
    n = twrite( tlu, f0rec2 )
    n = tclose( tlu )
    n = topen( tlu, devnam, islabeled )
    n = twrite( tlu, f1rec1 )
    n = twrite( tlu, f1rec2 )
    n = tclose( tlu )
    n = topen( tlu, devnam, islabeled )
    n = twrite( tlu, f2rec1 )
    n = twrite( tlu, f2rec2 )
    n = tclose( tlu )
    END

The next example uses tstate() to trap EOF and get at all files.

Example: Use tstate() in a loop that reads all records of the 3 files written in the previous example:


    CHARACTER devnam*10 / '/dev/nrst0' /, onerec*512 / " " /
    INTEGER*4 f, n / 0 /, tlu / 1 /, tcsr, topen, tread, 
&        trewin, tskipf, tstate
    LOGICAL errf, eoff, eotf, islabeled / .false. /
    n = topen( tlu, devnam, islabeled )
    n = tstate( tlu, fn, rn, errf, eoff, eotf, tcsr )
    WRITE(*,1)  'open:', fn, rn, errf, eoff, eotf, tcsr
1    FORMAT(1X, A10, 2I2, 1X, 1L, 1X, 1L,1X, 1L, 1X, I2 )
2    FORMAT(1X, A10,1X,A4,1X,2I2,1X,1L,1X,1L,1X,1L,1X,I2)
    n = trewin( tlu )
    n = tstate( tlu, fn, rn, errf, eoff, eotf, tcsr )
    WRITE(*,1)  'rewind:', fn, rn, errf, eoff, eotf, tcsr
    DO f = 1, 3
       eoff = .false.
       DO WHILE ( .NOT. eoff )
          n = tread( tlu, onerec )
          n = tstate( tlu, fn, rn, errf, eoff, eotf, tcsr )
          IF (.NOT. eoff) WRITE(*,2) 'read:', onerec, 
&            fn, rn, errf, eoff, eotf, tcsr
       END DO
       n = tskipf( tlu, 1, 0 )
       n = tstate( tlu, fn, rn, errf, eoff, eotf, tcsr )
       WRITE(*,1)  'tskip: ', fn, rn, errf, eoff, eotf, tcsr
    END DO
    END

The output is:


open: 0 0 F F F 0 
rewind: 0 0 F F F 0 
read: eins 0 1 F F F 0 
read: zwei 0 2 F F F 0 
tskip: 1 0 F F F 0 
read: ichi 1 1 F F F 0 
read: ni__ 1 2 F F F 0 
tskip: 2 0 F F F 0 
read: un__ 2 1 F F F 0 
read: deux 2 2 F F F 0 
tskip: 3 0 F F F 0 

A summary of EOF and EOT follows:

See also: ioctl(2), mtio(4s), perror(3F), read(2), st(4s), and write(2).