Gfortran/f90 (MinGW) read file problem

  • Context: Fortran 
  • Thread starter Thread starter solarblast
  • Start date Start date
  • Tags Tags
    File
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
3 replies · 7K views
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
 
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.