Run-Time error writing integer into a string

I get an error message
<<
PGFIO-F-235/formatted write/internal file/edit descriptor does not match item type.
In source file toto.f90, at line number 22

when running source code:
<<
function writenumber(number) result(charout)
implicit none
integer(KIND=8), intent(in) :: number
character(len=16) :: charout
! Local variables:
character6 :: sm
character
9 :: sp
character7 :: szero = ’ 000000’
if (number < 0) then
! Nagative API
if (-number > 1000000_8) then
!| write(sm, FMT=’(I6)’) mod(-number, 1000000_8)
write(sm, FMT=’(I6)’) -number - 1000000_8 * (-number/1000000_8)
write(sp, FMT=’(I9)’) -number/1000000_8
charout = ‘-’ // trim(adjustl(sp)) // szero(1:7-len_trim(adjustl(sm))) // adjustl(sm)
else
write(charout, FMT=’(I7)’) number
endif
elseif (number > 1000000_8) then
write(sm, FMT=’(I6)’) number - 1000000_8 * (number/1000000_8)
write(sp, FMT=’(I6)’) (number/1000000_8)
charout = trim(adjustl(sp)) // szero(1:7-len_trim(adjustl(sm))) // adjustl(sm)
else
write(charout, FMT=’(I6)’) number
endif
end function writenumber
program toto
implicit none
integer(KIND=8) :: number
character
16, external :: writenumber
number = 1328 * 10000
write(6, FMT=’(“w=”,A,".")’) writenumber(number)
end program toto

as though writes to string variable and to file descriptor overlap…
I use pgf95 -V
pgf95 10.3-0 64-bit target on x86-64 Linux -tp core2-64

Any help appreciated.

Hi cessenat,

The problem is that your program is using recursive I/O. This is a F2003 feature that isn’t supported yet. Our current plan is to have F2003 fully supported by the end of the year, but this one is lower in priority. To work around the issue, use a temporary character array to store the value returned from ‘wnumber’.

Hope this helps,
Mat

program toto
implicit none
integer(KIND=8) :: number
character*16 :: wnumber
character*16, external :: writenumber
number = 1328 * 10000
wnumber = writenumber(number)
write(6, FMT='("w=",A,".")') wnumber
end program toto

Hello,

I ignored writing to a string was like an I/O.
Anyway, this feature works with ifort release9.0 from February 2006, and gfortran and even with open64. I shall have to wait.

Thanks for the answer,

Sincerely,

Olivier Cessenat.