Fortran FORTRAN adding trailing zeros 0s

  • Thread starter Thread starter byrdman1982
  • Start date Start date
  • Tags Tags
    Fortran
AI Thread Summary
The discussion centers on a FORTRAN programming issue where a user encounters unexpected trailing digits when reading real data values, resulting in outputs like 23.13451 instead of the desired 23.13400. The user requires three decimal places for their project and is unable to use 4-byte reals due to precision constraints. Suggestions include checking the compiler being used, ensuring the data file is structured properly, and using formatted reads. Clarifications are made regarding the terminology of 8 bytes versus 8 bits, emphasizing the importance of correct data type specifications. The conversation highlights the need for accurate read and format statements to resolve the issue.
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:
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Replies
19
Views
2K
Replies
2
Views
1K
Replies
6
Views
3K
Replies
21
Views
3K
Replies
13
Views
4K
Replies
1
Views
3K
Back
Top