Fortran Gfortran/f90 (MinGW) read file problem

  • Thread starter Thread starter solarblast
  • Start date Start date
  • Tags Tags
    File
AI Thread Summary
The discussion revolves around reading a specific line from a text file in Fortran, where a floating-point read operation is failing due to a "bad value" error. The user is attempting to read a line containing numerical data but encounters issues, possibly due to control characters from a Linux-generated file. It was suggested that using a hex editor might reveal hidden characters affecting the read operation. The user identified a mistake in their reading logic, confusing the format of the data being read, which led to reading an incorrect line. They are working with a text file that includes comments and varying data formats, and plan to simplify the file structure by consolidating comments to facilitate easier reading into a namelist format. The overall goal is to convert an old Fortran code to Fortran 90 while managing the complexities of the data structure.
solarblast
Messages
146
Reaction score
2
I'm trying to read a dat (txt) file. Win7. It has this 80 character line that I want to read:
6364.1543 .95003538 .953223371.97825229 .100000 6.203.200 00.6480MEANOK A

The relevant parts of the program are:
real :: dummy
500 format(f10.4)
read(unit=astro_in, fmt=500) dummy !<----line 92
write(*,*) "dummy",dummy

It prints this:

dummy 6364.2583

At line 92 of file create-meteor_orbit-namelists.f90 (unit = 10, file = 'METEOR_Legacy.DAT')
Fortran runtime error: Bad value during floating point read.

Any idea what's going on?

It has read read lines like this above it:

Open(unit=astro_in, file="METEOR_Legacy.DAT", status = "OLD")

eof_swt = .False.
do while(eof_swt .EQV. .False.)
Read(unit=astro_in, fmt="(a80)", iostat=eof) card
 
Technology news on Phys.org
By using Err=k, I found that the error corresponds to 5010 LIBERROR_READ_VALUE, which is not really very helpful, since it already shows a "bad value" error.

Possibly this has to do with something related to the Linux end of line character. The file came from Linux.
 
I'm wondering if there might be some control character embedded in the first number, one that doesn't show up when you view the file as text, but causes problems when you attempt to read the number into your fortran code. If you can view the file in a hex editor/viewer, it's possible there is an extra character right after the '.' in your first number.

Just a guess...
 
Thanks for your response. I had some code mixed up between using

Read(unit=astro_in, fmt="(a80)", iostat=eof) card
and Read(card, fmt="(a80)", iostat=eof) card

As a consequence, I really had read a card ahead that had a completely different format. I'm reading a txt file that looks like:
#solar data
#f10.4!f12.7!
12345.6789 543.2111111 <-wanted to get data here
#station data <- but was on this
#coment
#comment
#comment
data
data
data

The file is sprinkled with a varying number comments followed by varying amount of data lines. Each group of data cards requires a different read format. I'm trying to put the data into a namelist form. There are nine groups.

The data file contains about 150 lines. I think I'll manually modify the comments, so there really is only one comment card before each group, which will include a count of the number of cards below it. Too complex otherwise. Converting old (punch cards format) fortran to f90.
 
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
3
Views
3K
Replies
5
Views
5K
Replies
2
Views
3K
Replies
2
Views
2K
Replies
4
Views
8K
Replies
2
Views
3K
Replies
13
Views
5K
Replies
1
Views
2K
Replies
19
Views
6K
Back
Top