Fortran Help. Reading space delimited floats

  • Fortran
  • Thread starter Rotarman
  • Start date
  • #1
3
0

Main Question or Discussion Point

Hi all, long time lurker: finally have a question I couldn't find already answered.

I'm doing some work with Fortran95 for a research project, and I'm a complete noob, so pardon me. The issue is that I have some data I'd like to read from a text file in double precision that is between 7 and 10 digits long on a single line (ex: 156.254569 25.485975 2.698757) and no pattern to how many digits (1-3) before the decimal. I'd thought about maybe doing something funky like turning them into strings then breaking it up into three strings somehow and turning each back into a float, but I'm not entirely sure how I'd go about it. As well, there are ~30k lines and each will be read at least 3 times for computations, so I'd like to keep it as simple as possible to speed up calculations. Anyone have a neat solution (or an ugly one) for this?

Thanks in advance
 

Answers and Replies

  • #2
jtbell
Mentor
15,544
3,453
Have you tried using the default format that a * format specifier gives you?

read (unit_num, *) a, b, c

(with a, b, c declared as having the appropriate precision, of course)
 
  • #3
3
0
This worked! I tried it without high hopes because theres letters before the floats on each line, but adding a dummy variable formatted as a string, it read everything without a hiccup. Thanks so much!
 

Related Threads on Fortran Help. Reading space delimited floats

Replies
4
Views
10K
Replies
0
Views
7K
Replies
1
Views
5K
Replies
1
Views
2K
Replies
2
Views
597
Replies
2
Views
29K
Replies
6
Views
1K
  • Last Post
Replies
9
Views
30K
  • Last Post
Replies
5
Views
9K
  • Last Post
Replies
2
Views
2K
Top