Gfortran/f90 (MinGW) read file problem

  • Context: Fortran 
  • Thread starter Thread starter solarblast
  • Start date Start date
  • Tags Tags
    File
Click For Summary

Discussion Overview

The discussion revolves around a problem encountered while reading a data file in Fortran using Gfortran/f90 on Windows 7. Participants are exploring issues related to reading formatted data from a text file, particularly focusing on the formatting and potential hidden characters that may cause runtime errors.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Exploratory

Main Points Raised

  • One participant reports a Fortran runtime error when attempting to read a floating-point number from a data file, suggesting that the format used may not match the data structure.
  • Another participant identifies the error code LIBERROR_READ_VALUE but finds it unhelpful, speculating that the issue might be related to line endings from a Linux-originated file.
  • A different participant proposes the possibility of hidden control characters in the data that could interfere with reading the values correctly, suggesting the use of a hex editor to investigate further.
  • One participant acknowledges a mix-up in their reading code, realizing they had read a line ahead with a different format, which contributed to the error. They describe the complexity of the data file structure, which includes comments and varying formats for different data groups.
  • The same participant mentions plans to simplify the data file by modifying comments to ensure a consistent format for reading, indicating the challenges of converting old Fortran code to f90.

Areas of Agreement / Disagreement

Participants express various hypotheses regarding the cause of the error, with no consensus reached on a definitive solution. Multiple competing views on potential issues and solutions remain present throughout the discussion.

Contextual Notes

The discussion highlights the complexity of reading formatted data from files with mixed content, including comments and varying data structures. There is an acknowledgment of the need for careful handling of file formats and potential hidden characters that may not be visible in standard text 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
 
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.
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
9K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 13 ·
Replies
13
Views
5K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 19 ·
Replies
19
Views
7K