Fortran Fixing Fortran 77 Output Bugs with Negative Exponents

  • Thread starter Thread starter conquertheworld5
  • Start date Start date
  • Tags Tags
    Fortran Output
AI Thread Summary
The discussion revolves around issues encountered while modifying legacy Fortran 77 code, specifically related to output formatting of floating-point numbers. The user is successfully writing array values to an ASCII file but faces a formatting problem where the 'E' character is omitted from scientific notation for negative exponents greater than two digits. Despite attempts to adjust the format statement to accommodate this, the issue persists. The user acknowledges that the small values likely indicate a deeper problem in the code, but is primarily focused on resolving the formatting issue. Reference to the Fortran 77 standard indicates that the omission of 'E' for exponents with a modulus greater than 99 is expected behavior. The user seeks clarification on why this occurs and how to ensure the 'E' is printed consistently.
conquertheworld5
Messages
22
Reaction score
0
I recently inherited some legacy code written in fortran77 which I'm going to be modifying quite a bit, and at this stage I find that I'm continually getting stuck on small fortran quirks... Just wondering if I could get some advice on this particular problem.

I'm outputting the values of several arrays one element at a time since I'm already looping over all the elements for other reasons:


Code:
write(5,101) x(j),z(i),dp(i,j)
101 format(2e15.5,1e15.5)


I get some nice columns as expected in my ascii file:
Code:
.10790E+03   .92222E+02  .53132E-02
.10790E+03   .94909E+02  .12401E-12
.10790E+03   .97909E+02  .43214E-50

The problem is that the third column occasionally has values that have 3-digit negative exponents and for some reason the E is being left out. So instead of .23414E-200, I'm getting .223414-200. I've tried increasing the number of characters and the number of significant digits in the format statement but no matter what I do, it doesn't print the E for any negative exponent with more than two digits.
Anyone know:
1) Why this is happening?
2) How to get it to print the E?

Also, I recognize that these are SMALL numbers, and they probably reflect some other problem in the code somewhere. So when I figure that out, I probably won't have to worry about this problem, but it's bugging me that I can't get the E to print with the numbers as is...
 
Technology news on Phys.org
I think its part of the Fortran 77 standard to do this. If you look here: http://www.fortran.com/F77_std/rjcnf0001-sh-13.html#sh-13.5.9.2.2 the table indicates that the 'e' is omitted for exponents whose modulus is greater than 99
 
Thanks!
 
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 have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
3
Views
2K
Replies
3
Views
4K
Replies
29
Views
5K
Replies
4
Views
2K
Replies
4
Views
1K
Replies
22
Views
5K
Replies
5
Views
2K
Replies
6
Views
3K
Back
Top