Hello community,
in the following program, user-defined IO formatted read behaves unusually on complex numbers in ifort 17.0.4.
module m implicit none type :: t_type complex :: x integer :: i character(len=10) :: s contains procedure :: t_read generic :: read(formatted) => t_read end type contains subroutine t_read(t, unit, iotype, vlist, iostat, iomsg) implicit none class(t_type), intent(inout) :: t character(len=*), intent(in) :: iotype integer, intent(in), dimension(:) :: vlist integer, intent(in) :: unit integer, intent(out) :: iostat character(len=*), intent(inout) :: iomsg ! TEST 1 (OK): !read(unit,*,iostat=iostat,iomsg=iomsg) t%x, t%i ! (1.0,2.0), 3 !if (iostat /= 0) return ! TEST 2 (ERROR): !read(unit,*,iostat=iostat,iomsg=iomsg) t%x ! (1.0,2.0) !if (iostat /= 0) return !read(unit,*,iostat=iostat,iomsg=iomsg) t%i ! ERROR !if (iostat /= 0) return ! TEST 3 (DEBUG): read(unit,*,iostat=iostat,iomsg=iomsg) t%x ! (1.0,2.0) if (iostat /= 0) return read(unit,*,iostat=iostat,iomsg=iomsg) t%s ! ')' if (iostat /= 0) return read(unit,*,iostat=iostat,iomsg=iomsg) t%i ! 3 if (iostat /= 0) return end subroutine end module program p use m implicit none integer :: iostat character(len=255) :: str, iomsg type(t_type) :: t ! Defaults: t%x = (0.0,0.0) t%i = 0 t%s = repeat('X',len(t%s)) ! List-directed IO: str = '(1.0,2.0) 3' read(str,*,iostat=iostat,iomsg=iomsg) t ! Output: print *, t%x, t%i, "'", trim(t%s), "'" if (iostat /= 0) print *, trim(iomsg) ! OUTPUT for TEST 1: ! (1.000000,2.000000) 3 'XXXXXXXXXX' ! OUTPUT for TEST2: ! (1.000000,2.000000) 0 'XXXXXXXXXX' ! User Defined I/O procedure returned error 59, message: 'list-directed ! I/O syntax error, unit -5, file Internal List-Directed Read' ! OUTPUT for TEST 3: ! (1.000000,2.000000) 3 ')' end program
The output from ifort 17.0.4 is reported for the three test-cases.
It looks as if the list-directed read does NOT advance beyond the closing parenthesis of the complex number literal in TEST 2, which is verified in TEST 3. Is this a bug or a feature?
Instead, with iifort 16.0.4, TEST 1 and TEST 2 yied similar output as expected.
Any ideas on workarounds that work both in ifort 16.0.4 AND 17.0.4 (and future versions) are appreciated.
Kind regards
Ferdinand