OPEN(parameter,parameter,...) CLOSE(parameter,parameter,...)where parameter has one of the following forms :-
keyword keyword=value
All parameters, except UNIT are optional. This parameter has the form:-
UNIT=expressionThis defines the logical unit number and it is good programming practise to define an integer variable for every unit number - see for example the program shown in section 10.1. The other parameters most useful to someone new to FORTRAN are shown below:-
='UNFORMATTED
The above parameters are normally only supplied with the OPEN statement and all, with the possible exception of FILE, take sensible defaults. The CLOSE statement usually only has the UNIT parameter. The OPEN and CLOSE statements are optional. If a READ or WRITE statement is encountered for a logical unit number that has not previously been declared in an OPEN statement then a default OPEN is given. The default taken is computer dependant and may not be what the user wants. So get into the habit of giving an OPEN for each unit. When the program ends all units that are open have a default CLOSE performed and this may be good enough. However an output file may not be complete, or even exist, until a CLOSE is given so for long running programs that write out intermediate results (sometimes called checkpoints), the file should be closed as soon as possible. If two OPENs are given for the same unit number without an intervening CLOSE, the second will automatically CLOSE the first.
1 2 3 ... 11 12 13 ...When the program runs type out the first part of it using the command:-
cat number.datAfter typing out the first few lines type Ctrl C to stop it. Use the ls command to see how big the file is :-
ls -l number.datNow write a program that reads the file back in and types out the first 10 records. The program should continue to read to the end of the file and then type out the last record and the number of records in the file. Now repeat both prorams but using UNFORMATTED I/O. See how big number.dat is this time but DO NOT try to type it out.