Best solution:
It turns out that the easiest solution is to use the g
specifier ("g" for "generalized editing"). That accepts a 0
to mean unspecified/processor-dependent width, which is exactly what I wanted. This is preferable to leaving the entire format unspecified (write(*,*)
) because you can still control other parts of the output, for example:
real :: num
character(len=10) :: word
num = 3.14159
word = 'pi = '
write (*, '(a5,g0)') word, num
yields this:
pi = 3.14159012
Thanks to Vladimir F for the idea (seen here).
Inferior alternative:
My first thought this morning after seeing High Performance Mark's answer was to write the real number to a character string and then use that:
character(len=20) :: cnum
write (cnum, *), num
write (*, '(a5,a)') word, trim(adjustl(cnum))
It yields the same output as the best solution, but it is a little more complicated and it doesn't offer quite as much control, but it gets close.