Rewind

Statement Purpose

The rewind statement will position an external file connected for sequential access at the very first record in that file.

Valid Specifiers

rewind (unit, iostat, err)

Unit

The unit specifier must be an integer unit number that corresponds a file that was linked to the program earlier using the open command. It lets the computer know which file needs to be rewound (marker of current position set to the beginning of the file).

Iostat=

The iostat= specifier is purely optional. If used, it needs an integer variable placed after the equals sign. The compiler will then assign either a value of zero to the integer variable denoting no error occurred when rewinding the file or a positive value if an error occurred. The type of error that occurs will dictate exactly what positive value is assigned to the integer variable. Interpretation of the meaning of non-zero value is system dependent.

Err=

This is another purely optional specifier for the rewind statement. It provides statement label to branch to if an error occurs while rewinding the file.

Usage

One instance in which this statement is useful is when a file is read to get the number of lines that are contained within it before any data is read from the file. For instance if the following read was done to find the number of lines contained within the file,
		100 read(37,*,end=101) dummy
		      ldata = ldata + 1
		      Go to 100 
		101 continue 
It would leave the position marker at the end of the file. Before actual data values could be read, the rewind command would have to issued as follows.
		Rewind(37)

For more information and examples see

lecture twenty two

examples: log_plot.f and noadv.f

Up one level / Home


Written by Jason Wehr : jcw142@psu.edu and Maintained by John Mahaffy : jhm@cac.psu.edu