FORTRAN adding trailing zeros 0s

  • Context: Fortran 
  • Thread starter Thread starter byrdman1982
  • Start date Start date
  • Tags Tags
    Fortran
Click For Summary

Discussion Overview

The discussion revolves around the issue of reading real data values in a FORTRAN program, specifically addressing the unexpected addition of digits beyond the desired decimal places. Participants explore how to format the output to maintain three decimal places without introducing random numbers.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant describes encountering an issue where reading a value like 23.134 results in an output of 23.13451, which disrupts their data processing.
  • Another participant questions the compiler being used and suggests that formatted reading might help if the data file is structured.
  • There is a clarification regarding the terminology used, correcting "8bit" to "8 bytes" and "4bit" to "4 bytes." This indicates a potential misunderstanding of data types in FORTRAN.
  • A suggestion is made that the participant might be using real*4 and real*8 specifications, which define single and double precision floating-point numbers, respectively.
  • A later reply prompts the original poster to provide details about their read statement, format statement, and the data line to better diagnose the issue.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the cause of the issue, and multiple viewpoints regarding potential solutions and misunderstandings about data types are present.

Contextual Notes

There are limitations in the discussion regarding missing details about the code and data structure, which may affect the ability to diagnose the problem accurately.

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
 
Technology news 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:

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 19 ·
Replies
19
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 21 ·
Replies
21
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 13 ·
Replies
13
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K