Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Fortran 95 read statement

  1. Oct 9, 2015 #1
    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
     
  2. jcsd
  3. Oct 9, 2015 #2

    FactChecker

    User Avatar
    Science Advisor
    Gold Member

    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.)
     
  4. Oct 9, 2015 #3
    Thank you very much :-) The list-directed works perfectly!
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook