Fortran  [Fortran] Problem reading formatted text file

AI Thread Summary
A user encountered an issue while trying to read data from a formatted ASCII text file generated by their code. The file contained four columns, but the fourth column, rho, was incorrectly reading the second value of the third column instead of its intended value. After troubleshooting various formatting tweaks and dummy objects without success, a reboot of the computer resolved the issue, allowing the original code to function correctly. The user shared the solution for future reference, emphasizing the importance of using the correct file opening and reading commands.
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 jim mcnamara
Technology news on Phys.org
Thanks for noting the solution, it may help future searchers.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
8
Views
1K
Replies
2
Views
1K
Replies
12
Views
3K
Replies
5
Views
5K
Replies
5
Views
2K
Replies
57
Views
5K
Replies
1
Views
3K
Replies
2
Views
2K
Replies
2
Views
3K
Back
Top