Fortran Fortran Help. Reading space delimited floats

AI Thread Summary
The discussion centers on reading double precision data from a text file using Fortran95. The user, a beginner, seeks a method to efficiently read lines containing three floating-point numbers with variable digit lengths, while ensuring the process is optimized for performance given the large dataset of approximately 30,000 lines. A solution is proposed using the default format specifier in Fortran, which allows for reading the data directly into variables. The user successfully implements this approach by adding a dummy string variable to handle any non-numeric characters preceding the floats, resulting in a seamless reading process.
Rotarman
Messages
3
Reaction score
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
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)
 
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!
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Replies
6
Views
2K
Replies
2
Views
3K
Replies
19
Views
7K
Replies
4
Views
13K
Replies
3
Views
4K
Replies
1
Views
6K
Replies
3
Views
7K
Replies
3
Views
4K
Replies
1
Views
5K
Back
Top