[Fortran] Problem reading formatted text file

Click For Summary
SUMMARY

The discussion addresses a problem encountered while reading a formatted ASCII text file in Fortran. The user initially faced issues where the fourth column, rho, was incorrectly assigned the value of the second entry from the third column. After troubleshooting, including rebooting the computer, the user discovered that the original code was correct. The solution involved using the Fortran commands open(unit=ilun_ascii,file=fileloc_ascii,form='formatted', status='old') and read(ilun_ascii,*) x, y, z, rho to successfully read the data.

PREREQUISITES
  • Understanding of Fortran programming language
  • Familiarity with formatted I/O operations in Fortran
  • Knowledge of ASCII file structure and data types
  • Basic troubleshooting techniques for code execution issues
NEXT STEPS
  • Research Fortran formatted I/O functions and their syntax
  • Explore common issues in reading ASCII files in Fortran
  • Learn about debugging techniques in Fortran programming
  • Investigate the impact of system libraries on Fortran code execution
USEFUL FOR

This discussion is beneficial for Fortran developers, programmers dealing with formatted I/O, and anyone troubleshooting data reading issues in scientific computing applications.

Morridini
Messages
4
Reaction score
1
Hi all, I have a problem I'm trying to solve.

I have a code that has written a simple ascii text file like this:
write(ilun_out, '(E23.15,A,E23.15,A,E23.15,A,E23.15)' x, ' ', y, ' ', z, ' ', rho

So this provides a nice looking ascii file with four columns, separated by a small space. Now I want to read this data into another code... and nothing works. No matter how much I try to tweak the formatting, reading in the spaces into "dummy" objects etc, I get the same problem.

The problem is that the fourth column, rho, is never read. Upon checking what I had read in I see that instead of getting the FIRST value of column FOUR, rho instead has the value of the SECOND value of column THREE.

Anyone know what's going on here?

Cheers

UPDATE: Ok I have no idea WHAT was going on, it might have been some problems with libraries or the compiler acting up, but after a computer reboot my original try actually worked... so there wasn't anything wrong in the code itself. Oh well.

In case anyone ever has a similar problem, the solution is the rather simple way of doing this:
open(unit=ilun_ascii,file=fileloc_ascii,form='formatted', status='old')
read(ilun_ascii,*) x, y, z, rho
 
Last edited:
  • Like
Likes   Reactions: jim mcnamara
Technology news on Phys.org
Thanks for noting the solution, it may help future searchers.
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 57 ·
2
Replies
57
Views
6K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K