open (list-of-specifiers)where the most common specifiers are:
[UNIT=] u IOSTAT= ios ERR= err FILE= fname STATUS= sta ACCESS= acc FORM= frm RECL= rlThe unit number u is a number in the range 9-99 that denotes this file (the programmer may chose any number but he/she has to make sure it is unique).
ios is the I/O status identifier and should be an integer variable. Upon return, ios is zero if the stement was successful and returns a non-zero value otherwise.
err is a label which the program will jump to if there is an error.
fname is a character string denoting the file name.
sta is a character string that has to be either NEW, OLD or SCRATCH. It shows the prior status of the file. A scrath file is a file that is created and deleted when the file is closed (or the program ends).
acc must be either SEQUENTIAL or DIRECT. The default is SEQUENTIAL.
frm must be either FORMATTED or UNFORMATTED. The default is UNFORMATTED.
rl specifies the length of each record in a direct-acccess file.
For more details on these specifiers, see a good Fortran 77 book.
After a file has been opened, you can access it by read and write statements. When you are done with the file, it should be closed by the statement
close ([UNIT=]u[,IOSTAT=ios,ERR=err,STATUS=sta])where, as usual, the parameters in brackets are optional.
read ([UNIT=]u, [FMT=]fmt, IOSTAT=ios, ERR=err, END=s) write([UNIT=]u, [FMT=]fmt, IOSTAT=ios, ERR=err, END=s)where most of the specifiers have been described above. The END=s specifier defines which statement label the program jumps to if it reaches end-of-file.
program inpdat c c This program reads n points from a data file and stores them in c 3 arrays x, y, z. c integer nmax, u parameter (nmax=1000, u=20) real x(nmax), y(nmax), z(nmax) c Open the data file open (u, FILE='points.dat', STATUS='OLD') c Read the number of points read(u,*) n if (n.GT.nmax) then write(*,*) 'Error: n = ', n, 'is larger than nmax =', nmax goto 9999 endif c Loop over the data points do 10 i= 1, n read(u,100) x(i), y(i), z(i) 10 enddo 100 format (3(F10.4)) c Close the file close (u) c Now we should process the data somehow... c (missing part) 9999 stop end