FORTRAN adding trailing zeros 0s

  • Context: Fortran 
  • Thread starter Thread starter byrdman1982
  • Start date Start date
  • Tags Tags
    Fortran
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
4 replies · 2K views
byrdman1982
Messages
1
Reaction score
0
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
 
on Phys.org
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.
 
byrdman1982 said:
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
What you mean are 8 bytes and 4 bytes, not the 8 bits and 4 bits that you wrote.
 
Perhaps he's using real*4 and real*8 specifications?

The "real*4" statement specifies the variable names to be single precision 4-byte real numbers which has 7 digits of accuracy ...

The "real*8" statement specifies the variable names to be double precision 8-byte real numbers which has 15 digits of accuracy ...

Quotes by http://www-classes.usc.edu/engr/ce/108/text/fbk01.htm
 
byrdman1982 said:
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
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: