Re: avoiding trailing zeros



norbert9@xxxxxxxxx wrote:
Is there an edit descriptor in Fortran that suppresses trailing zeros,
but outputs significant digits when not zero?

My (unformatted) output looks typically like
.... 0. 0. 0. 0. 0. 0. 0.7875317755557483 0.7862384282167548
0.784890147719363 ....
Many values are zero, but others are not. To save storage space I
would like it to output
.... 0. 0. 0. 0. 0. 0. 0.7875 0.7862 0.7849 ....

With the edit descriptor f6.4, it would look like
.... 0.0000 0.0000 0.0000 0.0000 0.0000 0.000 0.7875 0.7862
0.7849 ....
which is not space efficient either.

Is there a way to get a fixed number of digits, but avoid the trailing
zeros when the output is exactly zero?

You might write into a string, and replace occurrences of "0 " with " "
until all have disappeared before actually printing the string.

.



Relevant Pages

  • Re: avoiding trailing zeros
    ... but outputs significant digits when not zero? ... Many values are zero, but others are not. ... To save storage space I ... Unformatted means there is NO format, ...
    (comp.lang.fortran)
  • Re: avoiding trailing zeros
    ... but outputs significant digits when not zero? ... Many values are zero, but others are not. ... To save storage space I ... Unformatted means there is NO format, ...
    (comp.lang.fortran)
  • Re: avoiding trailing zeros
    ... but outputs significant digits when not zero? ... Then pass down the string to locate a decimal point at j1, ... only zeroes till a blank at j2. ...
    (comp.lang.fortran)
  • Re: avoiding trailing zeros
    ... but outputs significant digits when not zero? ... Many values are zero, but others are not. ... To save storage space I ... Unformatted means there is NO format, ...
    (comp.lang.fortran)
  • Re: avoiding trailing zeros
    ... but outputs significant digits when not zero? ... Many values are zero, but others are not. ... To save storage space I ... This method wastes time as well as being more involved than ...
    (comp.lang.fortran)