Help with Fortran 77 - File Opening Questions

  • Fortran
  • Thread starter Bruno Solheid
  • Start date
  • Tags
    Fortran
In summary, The conversation discusses how to open files in Fortran 77 and whether the file needs to be in a specific directory. It suggests using different code depending on the operating system, and provides examples for Windows and Unix/Linux. It also mentions the different status options for the file. The code also includes a sample of reading and writing data from the file.
  • #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.
 
Technology news on Phys.org
  • #2
If you are using Windows, try the following code. If you are using Unix or Linux, change the back-slash to slash, and use the appropriate directory name, for example:
/usr/myname/f77/test.dat
The status could be 'new', 'old', 'unknown', and there are other options.

Code:
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
 
  • #3


Hello, opening files in Fortran 77 is a straightforward process. First, you need to declare the file name and its associated unit number in the program. Then, you can use the OPEN statement to open the file for reading or writing. The file does not have to be in a specific directory, but you do need to provide the full path to the file if it is not in the current working directory. Additionally, make sure to use the correct file mode (e.g. 'READ' or 'WRITE') and specify the file format (e.g. 'FORMATTED' or 'UNFORMATTED'). If you are still having trouble, please provide more specific details about your doubts and I will be happy to assist you further. And don't worry about your English, it's not a problem. Let me know if you have any further questions.
 

1. How do I open a file in Fortran 77?

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')

2. What does the file access mode 'OLD' mean?

'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.

3. How do I open a file for writing in Fortran 77?

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.

4. What is the difference between formatted and unformatted files in Fortran 77?

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.

5. How do I close a file in Fortran 77?

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).

Similar threads

  • Programming and Computer Science
Replies
3
Views
388
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
17
Views
4K
  • Programming and Computer Science
Replies
0
Views
237
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
16
Views
3K
  • Programming and Computer Science
Replies
7
Views
2K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
2
Views
376
Back
Top