program tst
write(*,'(1x,A3)')efld(1d-101),efld(1d50),efld(1d101)
contains
function efld(x)
double precision, intent(in) :: x
character (len=3) :: efld
integer :: i
if(x <1d100> 1d-100)then
i = FLOOR( LOG10( x ) )
write(efld,'(SP,I3)')i
else
if(x < 1d-100)then
efld='-in'
else
efld='+in'
endif
endif
return
end function efld
end program tst
should produce the output
-in
+50
+in
However, PGI Fortran 11.9 on Win7-X64 gives this runtime error
PGFIO-F-235/formatted write/internal file/edit descriptor does not match item type.
In source file tinf.f90, at line number 10
If I am not mistaken, the SP edit control should apply to formatted output of all numeric types, including integers.
It turns out that the SP edit may not be the cause of the problem reported above. Rather, the bug may affect internal writes in which the format contains control edit descriptors.
This variant program
program tst2
implicit none
double precision :: y(5) = (/ 1d-100, 1d-50, 0d0, 1d50, 1d100 /)
integer :: i
do i=1,5
write(*,'(1x,ES12.3,2x,A3)')y(i), fexp(y(i))
end do
contains
function fexp(x) result(s)
implicit none
double precision :: x ! x > 0
character(len=3) :: s, fex
integer :: i
if(x == 0d0) then
s = 'zer'
return
endif
i = floor(log10(x))
if(i .lt. -99)then
s = '-in'
else if(i .gt. +99) then
s = '+in'
else
if( i .lt. 0 ) then
write (fex,"('-',I2)") -i
else if ( i .gt. 0)then
write (fex,"('+',I2)") i
else
fex = ' '
endif
s = fex
endif
return
end function fexp
end program tst2
gives the output
1.000-100 -in
PGFIO-F-235/formatted write/internal file/edit descriptor does not match item type.
In source file tinf2.f90, at line number 26
Recursive I/O is the last F2003 feature yet to be added to the compilers. It should have been added already but unfortunately had unexpected delays.
Our developers are almost finished (I just tested your code and it works fine with our internal development compiler), but I’m not sure exactly which release to expect it to be available. I’ll ask once our developers are back Winter Break.