next up previous contents index
Next: DATA Statement Up: Input/Output Facilities Previous: Implied DO-loops

REWIND and BACKSPACE Statements

   

These file-positioning statements may only be used on external sequential files; most systems will restrict them to files stored on suitable peripheral devices such as discs or tapes.

REWIND repositions a file to the beginning of information so that the next READ statement will read the first record; if a WRITE statement is used after REWIND all existing records on the file are destroyed. REWIND has no effect if the file is already rewound. If a REWIND statement is used on a unit which is connected but does not exist (e.g. a pre-connected output file) it creates the file.

BACKSPACE moves the file position back by one record so that the record can be re-read or over-written. There is no effect if the file is already positioned at the beginning of information but it is an error to back-space a file which does not exist. It is also illegal to back-space over records written by list-directed formatting (because the number of records produced each time is system-dependent). A few operating systems find it difficult to implement the BACKSPACE statement directly and actually manage it only by rewinding the file and spacing forward to the appropriate record. It is sometimes possible to avoid backspacing a file by allocating buffers within the program and, for a formatted file, using an internal file READ and WRITE statements.

These statements have similar general forms:
REWIND( control-list )
BACKSPACE( control-list )
where the control-list may contain:

 
          UNIT=integer-expression 
          IOSTAT=integer-variable 
          ERR=label
The unit identifier is compulsory, the others optional. If only the unit identifier is used then (for compatibility with Fortran66) an abbreviated form of the statement is permitted:
REWIND integer-expression
BACKSPACE integer-expression
where the integer expression identifies the unit number.


next up previous contents index
Next: DATA Statement Up: Input/Output Facilities Previous: Implied DO-loops
Helen Rowlands
8/27/1998