How to handle empty txt files when reading data in Fortran 90?

  • Context: Fortran 
  • Thread starter Thread starter toni_2374
  • Start date Start date
  • Tags Tags
    Data Fortran
Click For Summary
SUMMARY

The discussion focuses on handling empty text files in Fortran 90 when reading data. The recommended solution involves utilizing the ERROR= and END= options in the READ statement to manage file reading errors effectively. The ERROR= option captures various errors, while the END= option specifically addresses the scenario of encountering an empty file. Implementing these options allows the program to continue executing even when the input file lacks data.

PREREQUISITES
  • Understanding Fortran 90 syntax and structure
  • Familiarity with the READ statement in Fortran 90
  • Knowledge of error handling mechanisms in programming
  • Basic file I/O operations in Fortran 90
NEXT STEPS
  • Research the ERROR= option in Fortran 90 READ statements
  • Explore the END= option in Fortran 90 for file handling
  • Learn about exception handling in Fortran programming
  • Investigate best practices for file I/O in Fortran 90
USEFUL FOR

This discussion is beneficial for Fortran developers, programmers dealing with file I/O operations, and anyone looking to improve error handling in their Fortran 90 applications.

toni_2374
Messages
5
Reaction score
0
Hi
I have a problem with reading data in fortran 90. my programs try to read a txt file that only contains one number in it but if the txt file is empty it stops. i want to make it continue what should i do?
 
Technology news on Phys.org
Look up the ERROR= option for the READ statement.
 
Even better, look up the END= option.

ERROR= might pick up any type of error, not just that the file doesn't contain enough data.
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 25 ·
Replies
25
Views
4K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 17 ·
Replies
17
Views
7K
  • · Replies 2 ·
Replies
2
Views
2K