Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Gfortran/f90 (MinGW) read file problem

  1. May 24, 2012 #1
    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
  2. jcsd
  3. May 24, 2012 #2
    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.
  4. May 25, 2012 #3


    Staff: Mentor

    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...
  5. May 25, 2012 #4
    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
    12345.6789 543.2111111 <-wanted to get data here
    #station data <- but was on this

    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.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook