- #1
Bruno Solheid
- 1
- 0
Hi, I have some doubts about how to open files in fortran 77.
The file must to be inside some particular directory?
Sorry about my english.
The file must to be inside some particular directory?
Sorry about my english.
C open(10, file='testopen.dat',status='unknown')
C open(10, file='..\testopen.dat',status='unknown')
open(10, file='c:\proj\f77\testopen.dat',status='unknown')
C read(10,*)x
C read(10,*)y
C print *,x,y
C rewind 10
write(10,*)10.0
write(10,*)12.0
print *,10.0,12.0
stop
end
In Fortran 77, files are opened using the OPEN statement. This statement requires specifying the file name, file access mode, and other file attributes such as record length and organization. For example, to open a file named "data.txt" for reading, the statement would be OPEN(1, FILE='data.txt', STATUS='OLD')
'OLD' is a file access mode in Fortran 77 that specifies the file is being opened for reading. This means that the program can only read data from the file and cannot write or modify it.
To open a file for writing, the file access mode 'NEW' should be used in the OPEN statement. This will create a new file or overwrite an existing file with the same name. Additionally, the file attribute 'STATUS='REPLACE'' should be used to ensure that the file is replaced if it already exists.
In Fortran 77, formatted files have data that is written in a specific format, such as decimal numbers, and can be easily read by humans. Unformatted files, on the other hand, have data written in a binary format and cannot be easily read by humans. Unformatted files are generally used for efficiency and to store large amounts of data.
To close a file in Fortran 77, the CLOSE statement is used. This statement requires specifying the file unit number that was used in the OPEN statement. For example, if the file was opened using OPEN(1, FILE='data.txt'), the statement to close the file would be CLOSE(1).