Reputation: 5897
The following code demonstrates that for gfortran one may have the processor decide the width of the format descriptor for an integer and floating point number:
program test
double precision :: x = 5.321568756
integer :: i = 53254
write(*, '(I0)') i
write(*, '(F0.3)') x
end program test
When compiled, this code outputs
53254
5.322
Is it also possible to have the processor decide on the number of decimal points that are output with the write
statement? In other words, to have the above program output the following:
53254
5.321568756
without explicitly providing the number of decimal points in the format descriptor like '(F0.9)'
. Something like '(F0.(default number of decimal points here))'
Upvotes: 0
Views: 550
Reputation: 37228
You can use the g0
edit descriptor, like:
program test
double precision :: x = 5.321568756
integer :: i = 53254
write(*, '(I0)') i
write(*, '(F0.3)') x
write(*, '(G0)') x
end program test
(The difference between the G and F edit descriptors is that when the value gets large/small enough, the G edit descriptor switches to exponential notation. Usually that's what you want, though)
Upvotes: 3