Solve FORTRAN READ Problems: Troubleshooting & Manual

  • Fortran
  • Thread starter jasonbot
  • Start date
  • Tags
    Fortran
In summary, the conversation discusses a problem with FORTRAN code where the file being written to is closing before it is written to, causing an error. A solution is suggested to add a line to rewind the file after it is opened. The conversation also mentions gfortran and suggests some resources for learning FORTRAN, including "Professional Programmer's Guide to Fortran77" and Michael Metcalf's Fortran 90 CNL Articles.
  • #1
jasonbot
17
0
Hi,

I'm having trouble with some FORTRAN code I'm trying to use.

I receive an error:

Code:
At line 769 of file ../src/mpolar.f (unit = 11, file = 'polarx.387')
Fortran runtime error: Sequential READ or WRITE not allowed after EOF marker, possibly use REWIND or BACKSPACE

Upon inspection of the code the following appears:

Code:
  55 READ(LU11,END=60) DUMMY
      GO TO 55
C
C
C---- the polar dump file doesn't exist, so write new header
   56 CONTINUE
      WRITE(LU11) NAME, ' MSES   ', VERSION
      WRITE(LU11) MACHIN, REYNIN/1.0E6, ACRIT
      WRITE(LU11) IMATYP, IRETYP
      WRITE(LU11) NBL, II
      WRITE(LU11) (ILEB(N), ITEB(N), IIB(N), N=1, NBL)
      DO 59 N=1, NBL
        WRITE(LU11) (XB(IB,N), YB(IB,N), IB=1, IIB(N))
   59 CONTINUE
C
   60 CONTINUE
C
      CLOSE(LU11)
      RETURN
      END ! PXINIT

as far as I understand the file is closing before it is written to. Upon inspection of the file system the file does get created but it is empty.

Could someone possibly explain to me what the code is trying to do and possibly suggest a solution?

I'm new to fortran code so I don't understand the syntax. Is there a good online manual for fortran?
 
Technology news on Phys.org
  • #2
Post your complete code. That may get you more suggestions. It's hard to follow what the routine is trying to do with just this snippet of code.
 
  • #3
I have attached the file that is giving me problems. The file is compiled with a makefile
 

Attachments

  • mpolar.f.zip
    8.5 KB · Views: 337
  • #4
The file is open with status='unknown', such that if the file does not exist, it is created. There is then a read attempt, which in your case reaches the end of the file because it has just been created by the open statement and is empty. This is followed by a write to the file (since line 769 can only be reached if the file did not previously exist), where the program complains that it can't write since the file pointer is now beyond the EOF marker.

This is a strange behavior, probably a quirk of gcc, as a Fortran program would normally be expected to point just before the EOF marker when the EOF is reached. (I've tried with another compiler and the program executed normally.) To remedy the situation, just add the following line right after 56 CONTINUE:

REWIND(LU11)
 
  • Like
Likes 1 person
  • #5
DrClaude said:
The file is open with status='unknown', such that if the file does not exist, it is created. There is then a read attempt, which in your case reaches the end of the file because it has just been created by the open statement and is empty. This is followed by a write to the file (since line 769 can only be reached if the file did not previously exist), where the program complains that it can't write since the file pointer is now beyond the EOF marker.

This is a strange behavior, probably a quirk of gcc, as a Fortran program would normally be expected to point just before the EOF marker when the EOF is reached. (I've tried with another compiler and the program executed normally.) To remedy the situation, just add the following line right after 56 CONTINUE:

REWIND(LU11)

Thank you so much! It seems to be working! I guess the error shouldve been self explanatory but since I have no working knowledge of fortran I didnt know the syntax that I needed to get the programme working.

Just to add, however, I was using gfortran not gcc. I don't know if that made a difference?

As I asked before, what is a good online resource to learn fortran?
 
  • #6

1. What is FORTRAN and how is it used in scientific computing?

FORTRAN (FORmula TRANslation) is a high-level programming language commonly used in scientific and technical computing. It was developed in the 1950s and is still widely used today due to its efficiency and ability to handle complex mathematical calculations. FORTRAN is used to write programs for tasks such as data analysis, simulation, and numerical computation.

2. What are some common problems encountered when reading data using FORTRAN?

Some common problems when reading data with FORTRAN include incorrect data types, missing data or formatting errors, and issues with file permissions. These can lead to errors or incorrect results when running the program. It is important to carefully check the data and ensure that the correct data types and formats are used in the program.

3. How can I troubleshoot FORTRAN READ problems?

To troubleshoot FORTRAN READ problems, it is important to first identify the source of the error or issue. This can be done by carefully reviewing the program code and checking for any typos or incorrect syntax. Debugging tools such as print statements can also be used to track the flow of the program and identify any potential errors. Additionally, checking the input data and ensuring it is in the correct format can help resolve READ problems.

4. Are there any resources or manuals available for troubleshooting FORTRAN READ problems?

Yes, there are various resources and manuals available for troubleshooting FORTRAN READ problems. The official FORTRAN language reference manual and user guides provide detailed information on the syntax and usage of READ statements. Online forums and communities dedicated to FORTRAN programming can also be a helpful resource for troubleshooting specific problems.

5. How can I prevent FORTRAN READ problems in the future?

To prevent READ problems in FORTRAN, it is important to ensure that the input data is in the correct format and matches the data types specified in the program. It is also helpful to use debugging tools and thorough testing to catch any errors before running the program. Keeping up-to-date with the latest FORTRAN language updates and best practices can also help prevent READ problems in the future.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
2
Views
7K
  • Programming and Computer Science
Replies
2
Views
1K
Replies
10
Views
958
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
6
Views
2K
  • Programming and Computer Science
Replies
4
Views
8K
  • Programming and Computer Science
Replies
14
Views
1K
  • Programming and Computer Science
Replies
4
Views
4K
Back
Top