Need to remove leading zeros for floating point output

Steve Kargl sgk@troutmask.apl.washington.edu
Fri Oct 19 20:23:00 GMT 2007


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          

-- 
Steve



More information about the Fortran mailing list