-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Labels
Description
Consider the following code:
module m
type data
integer(4) :: k
end type
type container
integer(4) :: j
type(data), pointer :: d
end type
type base
integer(4) :: i
type(container), pointer :: c
end type
interface read(formatted)
subroutine readformatted(dtv, unit, iotype, v_list, iostat, iomsg )
import base
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
end subroutine
end interface
end module
program position102
use m
integer :: stat
character(200) :: msg = ''
class(base), allocatable :: b1
class(base), pointer :: b2
namelist /nml/ b1, b2
allocate( b1, b2) !b1%c, b1%c%d )
allocate( b1%c, b2%c)
allocate( b1%c%d, b2%c%d )
open (1, file = 'position102.1', form='formatted', access='sequential' )
read (1,NML=nml, iostat=stat, iomsg=msg)
end program
subroutine readformatted (dtv, unit, iotype, v_list, iostat, iomsg)
use m, only: base, container
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
read (unit, "(TL100, I4)", iostat=iostat, iomsg=iomsg) dtv%i
print*, iostat
print*, iomsg
if ( iostat /= 0 ) ERROR STOP 6
end subroutine
The input file position102.1
is:
&NML
B1=1001 &BASEDTIO
C1=1002 &CONTAINERDTIO
D1=1003
/
/ B2=2001 &BASEDTIO
C1=2002 &CONTAINERDTIO
D1=2003
/
/
/
The full test case is testing the namelist read on nested derived type list item.
Flang failed at
> a.out
1001
Bad character 'B' in INTEGER input field
Fortran ERROR STOP: code 6
Both gfortran and XLF executed the program successfully.