0

I am trying read some values from Fortran like below:

526.54789076609, 123.03020447201

and my code:

program readPrecise
parameter ( u1=31,maxSize=2 )
real massVector(maxSize)

open(UNIT=u1,FILE="shellMatrices.mtx",FORM="FORMATTED",STATUS='OLD')

read(u1,'(F15.11)'), massVector

close(UNIT=u1)

stop
end

Output:

    526.54791259766
    123.03020477295

I can read from the file but there is precision problem and it is reading some values wrong, even if I use 'F15.11' format, somehow it is changing my data. If you have any idea about how I can solve this problem, it would be great.Thanks in advance

Cagatay
  • 1
  • 4
  • Hello, welcome on this site. Always use the most generic tag ([tag:fortran]) and only add the version tag ([tag:fortran77]) if you need to specify the version too. Not many people follow the version tags alone. – Vladimir F Героям слава Jun 01 '15 at 17:05
  • 2
    Possible duplicate http://stackoverflow.com/questions/10016261/precision-problems-of-real-numbers-in-fortran or http://stackoverflow.com/questions/10016261/precision-problems-of-real-numbers-in-fortran?lq=1 This is not a problem, just use higher precision reals (`double precision`). Read about floating point numbers on wikipedia http://en.wikipedia.org/wiki/Floating_point – Vladimir F Героям слава Jun 01 '15 at 17:07
  • @VladimirF Thank you so much, and sorry for this silly question, I am quite new in FORTRAN. – Cagatay Jun 01 '15 at 17:21

0 Answers0