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.

.