-2

I have been experimenting with the following code:

program hello
    write(*,"(i9)") 10
end program hello

and varying the format string, trying to make write output a string just the size needed to represent the integer number, but so far I was unable to manage it. How to write 'fit' integers in Fortran?

lvella
  • 12,754
  • 11
  • 54
  • 106
  • possible duplicate of [Output formatting: too much whitespace in gfortran](http://stackoverflow.com/questions/24844250/output-formatting-too-much-whitespace-in-gfortran) – francescalus Feb 25 '15 at 20:35
  • There are several other potential duplicates, but many rely on `I0` which is not F90. Do you really need a Fortran 90 answer? – francescalus Feb 25 '15 at 20:38
  • Well, if possible without me having to write my own formatting subroutine, I prefer. I am used to rely on standards... – lvella Feb 25 '15 at 20:43
  • `I0` has been standard for twenty years. [My comment was not "standard Fortran?", but "Does it need to be Fortran 90 and not later?" based on your tag choice.] – francescalus Feb 25 '15 at 20:50
  • 1
    Specifically, don't you mind Fortran 95? (in my opinion you really should not) – Vladimir F Героям слава Feb 25 '15 at 20:56
  • Understood now. I myself don't mind using Fortran 95, and judging for what you are saying, probably nobody will. – lvella Feb 25 '15 at 22:55

1 Answers1

5

A I0 edit descriptor is the correct way for output of integers with the correct width. This was introduced in Fortran 95. All current Fortran compilers which were Fortran 90 compilers have been updated to Fortran 95 years ago.