-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Labels
Description
Consider the following code:
module m
type base
integer id
complex(4), allocatable :: cx
character(:), allocatable :: name
contains
procedure :: reset => resetBase
procedure, pass(dtv) :: readBaseFmtd
generic :: read(formatted) => readBaseFmtd
end type
contains
subroutine resetBase (b)
class(base), intent(out) :: b
end subroutine
subroutine readBaseFmtd (dtv, unit, iotype, v_list, iostat, iomsg)
class(base), intent(inout) :: dtv
integer, intent(in) :: unit
character(*), intent(in) :: iotype
integer, intent(in) :: v_list(:)
integer, intent(out) :: iostat
character(*), intent(inout) :: iomsg
character(50) fmt
call dtv%reset
allocate (dtv%cx)
if (iotype(1:2) == 'DT') then ! take the format from the supplier
if (size(v_list) < 1) then
iostat = 100
iomsg = 'expecting at least 1 value in v_list'
return
end if
write (fmt, *, decimal='POint') iotype(3:)
allocate (character(v_list(1)) :: dtv%name)
read (unit, fmt, iostat=iostat, iomsg=iomsg) dtv%id, dtv%cx, dtv%name
else if (iotype == 'LISTDIRECTED') then
read (unit, *, iostat=iostat, iomsg=iomsg) icharLen
if (iostat /= 0) return
allocate (character(icharLen) :: dtv%name)
read (unit, *, iostat=iostat, iomsg=iomsg) dtv%id, dtv%cx, dtv%name
end if
end subroutine
end module
program dcmlChildRead001
use m
class (base), allocatable :: b1(:)
logical(4), external :: precision_x8
character(:), allocatable :: name
open (1, file='dcmlChildRead001.in', form='formatted', access='stream', &
decimal='coMMa', delim='quote')
write (1, '(10(i5, 1x, 2e15.7, 1x, a7, i3.3))', pos=1, advance='no') &
(i, cmplx(sin(i*1.0), i*1.0), 'xlftest', i, i=1, 10)
write (1, *, delim='none') &
(i, i, cmplx(sin(i*1.0), i*1.0), '"xlftest', i, '"', i = 11, 20)
!! now read data in b1
allocate (b1(20))
do i = 1, 20
b1(i)%id = -i
allocate (b1(i)%cx, source=cmplx(i))
allocate (b1(i)%name, source='IBM')
end do
read (1, '(10DT"(i5,1x,2e15.7,1x,a)"(10))', pos=1, advance='no') b1(::2)
read (1, *) b1(2::2)
end
Flang failed at the runtime with
> a.out
fatal Fortran runtime error(t.f:90): invalid character (0x31) after list-directed input value, at column 19 in record 2
IOT/Abort trap(coredump)
Both ifort and XLF executes the program successfully.