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

FORTRAN adding trailing zeros 0s

  1. Aug 14, 2014 #1
    Aloha all,

    I am reading in real data values in a FORTRAN program that are something like 23.134. The problem is that the program adds extra numbers on the end to make it 8bit, so I end up with 23.13451. This is throwing everything off. Is there a way to make the values have trailing 0s instead of random numbers, so that they read 23.13400? I unfortunately need to have 3 decimal places for this particular project, so using 4 bit reals isn't going to work.

    Thanks for the help,
  2. jcsd
  3. Aug 14, 2014 #2


    User Avatar

    Staff: Mentor

    Hi byrdman, welcome to PF!

    If I understand correcty, you have a file containing something like


    which you read into a real, and printing out that real results in


    I have never seen that behaviour. Which compiler are you using?
    It would be helpful if you could post some sample data and the part of your code where you read in the data.

    For now, the only thing I can think of is that ff the data file is structured ("neat" columns), using a formatted read might help.
  4. Aug 14, 2014 #3


    Staff: Mentor

    What you mean are 8 bytes and 4 bytes, not the 8 bits and 4 bits that you wrote.
  5. Aug 14, 2014 #4


    User Avatar
    Science Advisor
    Gold Member

    Perhaps he's using real*4 and real*8 specifications?

    Quotes by http://www-classes.usc.edu/engr/ce/108/text/fbk01.htm
  6. Aug 15, 2014 #5
    My guess is that you are reading these value in incorrectly.
    What do your read statement, format statement, and data line look like?
    Last edited by a moderator: Aug 15, 2014
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook