Need to remove leading zeros for floating point output
Jerry DeLisle
jvdelisle@verizon.net
Fri Oct 19 20:42:00 GMT 2007
Steve Kargl wrote:
> On Fri, Oct 19, 2007 at 07:53:21PM +0000, Nick Stamatakos wrote:
>> Is there compiler option or other way to remove Leading zeros from
>> floating point fortran output? In HP f90 FORTRAN there is an option
>> called:
>> +io77 Suppresses the generation of the optional leading
>> "0" before the decimal point for real numbers
>> printed with the E and F edit descriptors.
>> Fortran 77 suppressed these leading
>> zeros unless
>> the NOSTANDARDIO flag was used. Along with
>> +gformat77, the +io77 flag provides formatted
>> output compatibility with the
>> Fortran 77 product.
>>
>> What is the equivalent compiler or other way to implement this option?
>> I can't find it anywhere.
>>
>
> gfortran doesn't have an option to what you want. You could
> however chop the leading zero with an internal write.
>
> program a
> character(len=20) s
> real x
> x = 0.1234
> write(s,'(E12.5)') x
> s = adjustl(s)
> if (s(1:1) == '0') then
> s(1:len(s)-1) = s(2:len(s))
> end if
> print *, x, s
> end program a
>
> troutmask:kargl[206] gfc -o z l.f90
> troutmask:kargl[207] ./z
> 0.1234000 .12340E+00
>
In write_float.def, we have
/* Output an optional leading zero. */
if (leadzero)
*(out++) = '0';
leadzero is a flag telling us we have room for a leading zero. We could add an
option to set that byte to ' ' to suppress it. That would not be available
until gfortran version 4.4. It is straightforward to do though.
Jerry
Jerry
More information about the Fortran
mailing list