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,
    Tom
     
  2. jcsd
  3. Aug 14, 2014 #2

    DrClaude

    User Avatar

    Staff: Mentor

    Hi byrdman, welcome to PF!

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

    23.134

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

    23.13451

    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

    Mark44

    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

    dlgoff

    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
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: FORTRAN adding trailing zeros 0s
  1. Linking Fortran (Replies: 5)

Loading...