Fortran 95 read statement

  • #1
3
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
 

Answers and Replies

  • #2
FactChecker
Science Advisor
Gold Member
6,541
2,620
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.)
 
  • #3
3
0
Thank you very much :-) The list-directed works perfectly!
 

Related Threads on Fortran 95 read statement

  • Last Post
Replies
12
Views
7K
Replies
12
Views
223
Replies
8
Views
3K
  • Last Post
Replies
1
Views
1K
  • Last Post
Replies
9
Views
30K
Replies
4
Views
8K
Replies
2
Views
3K
  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
4
Views
2K
Top