Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
18 Views

Write small numbers as zero

Hi All

I have inherited a fortran program from somebody and have run into a situation where it prints very small numbers out with the write statement, something like -8.97639E-30 or 7.36475-173. How can I get the program to write numbers under a certain threshold value to be zero without having to trawl through the code and do a check everywhere. Is there a compiler option I can use for instance?

Thanks in advance

Ed

0 Kudos
3 Replies
Black Belt Retired Employee
18 Views

There is not such an option.

There is not such an option. I assume that -173 exponent value is double-precision, as I don't think a denormalized single will go that small.

--
Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran
0 Kudos
Highlighted
18 Views

You will have to dig through

You will have to dig through your program because either the FORMAT edit descriptors (or lack thereof with *), are specifying that the print is to supply the exponents of such small (or large) numbers. IOW has E, EN, ES or G formatting. Change these to F formatting (Fw.d). This transfers real numbers without exponent.

If you really want exponents printed, except for very small numbers, then you will need to qualify a cutoff point. For this, often one writes a specialized formatting subroutine that handles, in your case, very small numbers.

Jim Dempsey

0 Kudos
Highlighted
Black Belt
18 Views

An alternative to consider is

An alternative to consider is to write a post-processor program. If you have lots of text interspersed with the numbers, that can be difficult to do. On the other hand, if there are only numbers on some lines and only text on others, the post-processor would be very easy to implement.

0 Kudos