Fortran Reading Real Numbers in Fortran 95: Tips and Tricks

  • Thread starter Thread starter Sirluke
  • Start date Start date
  • Tags Tags
    fortran
AI Thread Summary
The discussion focuses on reading a row of real numbers from a text file using Fortran. The user initially attempts to read the data with a specific format statement but encounters incorrect results. A solution is provided to use list-directed input by replacing the original read statement with "read(1,*)," which successfully resolves the issue. The user confirms that this method works perfectly for their needs.
Sirluke
Messages
3
Reaction score
0
Hi Guys

I need some help with reading a row of real numbers on a text file using fortran. On my text file the row is:
74.05 112.91 154.03 193.90 236 276.71 61.12.
I would like to point out that these numbers are chemical parameters that can vary but they usually have up to two digits in the decimal part and three in the unit part. So if I write:

open(1,'file.txt)
.
read(1,100) vector
100 format (7(f6.2))

then i get very wrong results in reading the data, how can i fix this? Thank you very much
 
Technology news on Phys.org
Try a list-directed read. Just replace the 'read(1,100) with read(1,*). If the dimension of vector is 7, it should work. Otherwise, you need to specify that it should only try to read 7 numbers: read(1,100) vector(1), vector(2), vector(3), vector(4), vector(5), vector(6), vector(7), (There are other ways to specify the 7 variables, but this should work.)
 
Thank you very much :-) The list-directed works perfectly!
 
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
12
Views
3K
Replies
5
Views
5K
Replies
5
Views
2K
Replies
1
Views
3K
Replies
2
Views
2K
Replies
20
Views
9K
Replies
6
Views
2K
Replies
22
Views
5K
Back
Top