BACKSPACE

Statement: Positions a file at the beginning of the preceding record, making it available for subsequent I/O processing. It takes one of the following forms:

Syntax

BACKSPACE ([UNIT=]io-unit [, ERR=label] [, IOSTAT=i-var])
BACKSPACE io-unit

io-unit
(Input) Is an external unit specifier.

label
Is the label of the branch target statement that receives control if an error occurs.

i-var
(Output) Is a scalar integer variable that is defined as a positive integer if an error occurs and zero if no error occurs.

Rules and Behavior

Use the BACKSPACE statement with files connected for sequential access. BACKSPACE cannot be used to skip over records that have been written using list-directed or namelist formatting.

The I/O unit number must specify an open file on disk or magnetic tape.

Backspacing from the current record n is performed by rewinding to the start of the file and then performing n-1 successive READs to reach the previous record.

A BACKSPACE statement must not be specified for a file that is open for direct or append access, because n is not available to the Fortran I/O system.

If a file is already positioned at the beginning of a file, a BACKSPACE statement has no effect.

If the file is positioned between the last record and the end-of-file record, BACKSPACE positions the file at the start of the last record.

Compatibility

CONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIB

See Also: REWIND, ENDFILE, Data Transfer I/O Statements, Branch Specifiers

Examples

  BACKSPACE 5
  BACKSPACE (5)
  BACKSPACE lunit
  BACKSPACE (UNIT = lunit, ERR = 30, IOSTAT = ios)

The following statement repositions the file connected to I/O unit 4 back to the preceding record:

  BACKSPACE 4

Consider the following statement:

  BACKSPACE (UNIT=9, IOSTAT=IOS, ERR=10)

This statement positions the file connected to unit 9 back to the preceding record. If an error occurs, control is transferred to the statement labeled 10, and a positive integer is stored in variable IOS.