Fortran90 problem, runtime error

Click For Summary
SUMMARY

The discussion centers on a Fortran90 runtime error encountered when executing a program that reads from and writes to a file simultaneously. The error message indicates an "End of file" issue at line 11 of the code. Key recommendations include ensuring the file exists before attempting to read from it and using the 'FORMATTED' option when opening the file to avoid potential conflicts during simultaneous read/write operations.

PREREQUISITES
  • Understanding of Fortran90 programming syntax
  • Familiarity with file I/O operations in Fortran
  • Knowledge of runtime error handling in programming
  • Basic debugging techniques for Fortran code
NEXT STEPS
  • Research Fortran90 file I/O operations, focusing on the OPEN statement
  • Learn about handling runtime errors in Fortran90
  • Explore the implications of simultaneous read/write operations in file handling
  • Investigate the use of the FORMATTED option in Fortran file operations
USEFUL FOR

This discussion is beneficial for Fortran developers, programmers troubleshooting file I/O issues, and anyone looking to improve their understanding of runtime errors in Fortran90.

Saxby
Messages
45
Reaction score
0
Hello, I've been playing around with some code (as shown below) and for some reason everytime i run this code I am told:

At line 11 of file tester.f90
Fortran runtime error: End of file

I'm not really sure what's causing it, is it the position of my Open file?
Any help would be much aprrieiated :)

PROGRAM tester

!Turn off implicit typing
IMPLICIT NONE

INTEGER :: a, b

OPEN(10,FILE='tester.out')

WRITE(10,*) 'Please give value for a'
READ(10,*) a

IF (a < 0) THEN
WRITE(10,*) 'Wrong number'
STOP
END IF

WRITE(10,*) 'Please give value for b'
READ(10,*) b

IF (b > 0) THEN
WRITE(10,*) 'Wrong number'
STOP
END IF

WRITE(10,*) a * b

CLOSE(10)

END PROGRAM tester
 
Technology news on Phys.org
Are you sure the file exists?

You are writing to the file and reading from it simultaneously. This can cause problems if not done carefully.

When opening the file, FORM ='FORMATTED' should probably be used.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 17 ·
Replies
17
Views
7K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 2 ·
Replies
2
Views
9K
  • · Replies 14 ·
Replies
14
Views
3K
  • · Replies 2 ·
Replies
2
Views
8K
  • · Replies 4 ·
Replies
4
Views
3K