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!
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

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