Fortran Help. Reading space delimited floats

In summary, The conversation is about using Fortran95 to read data from a text file in double precision. The data is between 7 and 10 digits long and has no specific pattern. The person suggests using the default format specifier to read the data, which worked successfully.
  • #1
Rotarman
3
0
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
 
Technology news on Phys.org
  • #2
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
This worked! I tried it without high hopes because there's 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 to Fortran Help. Reading space delimited floats

1. What is Fortran?

Fortran is a high-level programming language used primarily for scientific computing. It was developed in the 1950s and is still widely used today for its efficiency and ability to handle complex mathematical calculations.

2. How do I read space delimited floats in Fortran?

To read space delimited floats in Fortran, you can use the "READ" statement with the "F" format specifier. This allows you to specify the number of digits after the decimal point and the total number of digits for each float value.

3. What is the difference between space delimited and comma delimited floats?

The main difference between space delimited and comma delimited floats is the delimiter used to separate the values. Space delimited floats are separated by spaces, while comma delimited floats are separated by commas. In Fortran, both can be read using the "READ" statement with the appropriate format specifier.

4. Can I read other types of data besides floats with Fortran?

Yes, Fortran can read and manipulate various types of data, including integers, characters, and logical values. The format specifier used with the "READ" statement will depend on the type of data you are trying to read.

5. Is there a limit to the number of space delimited floats I can read in Fortran?

The maximum number of space delimited floats that can be read in Fortran depends on the specific implementation and the amount of memory available. However, most modern Fortran compilers have the ability to handle large amounts of data, so there is typically no practical limit.

Similar threads

  • Programming and Computer Science
Replies
6
Views
1K
Replies
10
Views
984
  • Programming and Computer Science
Replies
19
Views
6K
  • Programming and Computer Science
Replies
2
Views
3K
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
1
Views
8K
  • Programming and Computer Science
Replies
4
Views
12K
  • Programming and Computer Science
Replies
1
Views
5K
  • Programming and Computer Science
Replies
3
Views
4K
  • Programming and Computer Science
Replies
4
Views
4K
Back
Top