For leading zeros in integer numbers, we can use format such as "i4.4"
to produce such as "0037". Is there a similar way in Fortran 90 to
produce leading zeros in REAL numbers, such as 0045.28? Or do I have
to split the parts BEFORE and AFTER the decimal point and manipulate
them separately?
Thank you for reading and replying!
--Roland
I do not think there is an edit descriptor for that, but here is
a small program that will do what you want:
program vv
real :: x = 45.28
character(len=20) :: string
write( string, '(f10.2)' ) x
string = repeat( '0', 10-len_trim(adjustl(string))) // adjustl
(string)
write( *, *) string
end program
The trick is:
- Write the number according to the format required
- Replace as many leading blanks as necessary by 0.
There are other ways too, but this is fairly compact (though not as
compact as a format) and you can easily put it in a function/
subroutine
(beware of recursive writes though)
Regards,
Arjen
for *positive* real values.
Arjen and John: Thank you for your replies and detailed code. I have
thought about other awkward methods, but the functions like "repeat"
and "adjustl" are not in the pool of the active functions in my mind.
Thank you again!
--Roland
Hm, yes, you are right. I did not think of that. Including a sign
will make the code a bit more complicated ... The principle stays the
same.
Regards,
Arjen
Only slightly more so, as the sign is in a fixed position
in the output.