0% found this document useful (0 votes)
34 views2 pages

BACKSPACE in FORTRAN

The document discusses the BACKSPACE statement in Fortran, which repositions a connected file to just before the preceding record. It must be used with files connected for sequential access, and its behavior is unpredictable for direct-access or append files. Optional arguments like IOSTAT and ERR can be used, and ERR can also be used with the READ statement to handle errors.

Uploaded by

tata sudiyanto
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views2 pages

BACKSPACE in FORTRAN

The document discusses the BACKSPACE statement in Fortran, which repositions a connected file to just before the preceding record. It must be used with files connected for sequential access, and its behavior is unpredictable for direct-access or append files. Optional arguments like IOSTAT and ERR can be used, and ERR can also be used with the READ statement to handle errors.

Uploaded by

tata sudiyanto
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

In Fortran, the `backspace` statement is used to reposition a file connected to a

specified unit number to just before the preceding record. For example,
`backspace(22)` would reposition the file connected to unit 22 to just before the
preceding record¹.

It's important to note that the `backspace` statement has no effect on a terminal
file and must be connected for sequential access. The execution of a `backspace`
statement on a direct-access file or an append access file is not defined in the
FORTRAN 77 Standard and is unpredictable¹.

Source: Conversation with Bing, 7/27/2023


(1) BACKSPACE (FORTRAN 77 Language Reference) - Oracle.
https://docs.oracle.com/cd/E19957-01/805-4939/6j4m0vn7j/index.html.
(2) The use of backspace character ( char(8) ) in Fortran.
https://stackoverflow.com/questions/47712486/the-use-of-backspace-character-char8-
in-fortran.
(3) BACKSPACE in Fortran Tutorial 23 July 2023 - Wisdom Jobs India.
https://www.wisdomjobs.com/e-university/fortran-tutorial-167/backspace-3790.html.

######################

Yes, if unit 22 is associated with a text file, then the `backspace(22)` statement
would reposition that file to just before the preceding record. The file type
(e.g., `.txt`) does not affect the behavior of the `backspace` statement.

In the context of a text file, a record typically refers to a line of text. So, if
unit 22 is associated with a text file, then the `backspace(22)` statement would
reposition the file to just before the preceding line of text.

##########
does statement BACKSPACE require any other specifier beside the unit number ?
#########

The `BACKSPACE` statement in Fortran requires only the unit number as a mandatory
argument. However, it can also accept optional arguments such as `IOSTAT` and
`ERR`. The `IOSTAT` argument specifies an integer variable that will receive the
I/O status after the `BACKSPACE` statement is executed. The `ERR` argument
specifies a statement label to which control will be transferred in case of an
error during the execution of the `BACKSPACE` statement.

Here is an example that shows how these optional arguments can be used:

```
integer :: iostat
...
backspace(22, iostat=iostat, err=999)
...
999 write(*,*) 'Error during BACKSPACE'
```

In this example, the `iostat` variable will receive the I/O status after the
`backspace` statement is executed. If an error occurs during the execution of the
`backspace` statement, control will be transferred to the statement labeled `999`,
which writes an error message to the screen.

##############
can the err specifier also be used in READ statement ?
##############
Yes, the `ERR` specifier can also be used with the `READ` statement in Fortran.
Similar to its use with the `BACKSPACE` statement, the `ERR` specifier in a `READ`
statement specifies a statement label to which control will be transferred in case
of an error during the execution of the `READ` statement.

Here is an example that shows how the `ERR` specifier can be used with a `READ`
statement:

```
integer :: i
...
read(*,*,err=999) i
...
999 write(*,*) 'Error during READ'
```

In this example, if an error occurs during the execution of the `read` statement,
control will be transferred to the statement labeled `999`, which writes an error
message to the screen.

You might also like