Fixing Fortran 77 Output Bugs with Negative Exponents

  • Fortran
  • Thread starter conquertheworld5
  • Start date
  • Tags
    Fortran Output
In summary, The speaker inherited some legacy code written in Fortran77 and has been struggling with some quirks while modifying it. They are currently having trouble with the formatting of values in the third column of an ASCII file, specifically with negative exponents. The speaker has tried adjusting the format statement, but the 'E' is still being omitted for exponents with more than two digits. They are looking for advice on how to fix this issue and also mention that it may be a reflection of a larger problem in the code. They also reference the Fortran 77 standard which states that the 'e' is omitted for exponents greater than 99.
  • #1
conquertheworld5
22
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
  • #2
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
 
  • #3
Thanks!
 

Related to Fixing Fortran 77 Output Bugs with Negative Exponents

1. What is Fortran 77 and why is it important?

Fortran 77 is a programming language commonly used in scientific and engineering applications. It was first developed in the late 1950s and has since been updated to include new features and improvements. It is important because it is still widely used today, especially in legacy code, and has a large library of mathematical and scientific functions.

2. What are negative exponents and why do they cause bugs in Fortran 77 output?

Negative exponents are a mathematical concept where a number is raised to a negative power, indicating division by that number. In Fortran 77, output with negative exponents can cause bugs because the default output format does not display them correctly. This can lead to incorrect results or difficulty in reading and interpreting the output.

3. How can negative exponents be fixed in Fortran 77 output?

There are several ways to fix negative exponents in Fortran 77 output. One option is to use the "E" edit descriptor in the WRITE statement, which allows for scientific notation and can display negative exponents correctly. Another option is to use the "G" edit descriptor, which automatically switches between fixed point and scientific notation based on the magnitude of the number. It is also important to make sure the output width is large enough to accommodate the negative exponent.

4. Can negative exponents be avoided altogether in Fortran 77?

Yes, negative exponents can be avoided in Fortran 77 by using the "D" edit descriptor in the WRITE statement. This descriptor displays numbers in decimal format and can handle a wider range of values without negative exponents. However, this may not always be feasible or practical depending on the specific application.

5. Are there any other common bugs or issues that can occur in Fortran 77 output?

Yes, there are other common bugs and issues that can occur in Fortran 77 output, such as truncation errors, incorrect formatting, and precision loss. It is important to carefully check and test the output to ensure accuracy and address any potential issues that may arise.

Similar threads

  • Programming and Computer Science
Replies
3
Views
2K
  • Programming and Computer Science
Replies
8
Views
3K
  • Programming and Computer Science
Replies
34
Views
3K
  • Programming and Computer Science
Replies
29
Views
2K
  • Programming and Computer Science
Replies
3
Views
416
  • Programming and Computer Science
Replies
4
Views
4K
  • Programming and Computer Science
Replies
29
Views
5K
  • Programming and Computer Science
Replies
9
Views
3K
  • Programming and Computer Science
Replies
22
Views
4K
  • Programming and Computer Science
Replies
25
Views
2K
Back
Top