-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Open
Labels
Description
Consider the following code
module m
type base
integer id
real :: data(3)
complex cx
contains
procedure :: readBaseFmtd
generic :: read(formatted) => readBaseFmtd
end type
contains
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
read (unit, *, iostat=iostat, iomsg=iomsg) dtv%id
read (unit, *, iostat=iostat, iomsg=iomsg) dtv%data
read (unit, *, iostat=iostat, iomsg=iomsg) dtv%cx
end subroutine
end module
program dcmlChildRead012
use m
type(base) :: b1
integer :: stat
character(20) :: msg
open (1, file='dcmlChildRead012.data', decimal='coMMa')
write (1, 100) (i, (j*1.11, j=i,i+1), cmplx(2*i, i**2), i=1,1)
rewind(1)
100 format (i5, 1x, e15.8, 1x, e15.8, " /", /, " (", e15.8, " ; ", e15.8, ') ')
b1%data =-1.0
read (1, *, iostat=stat, iomsg=msg) b1
!! verify b1
print*, b1%id
print*, b1%data
print*, b1%cx
end
The test case is using a slash to terminate the reading of b%data
when it has 3 elements but the input file has only 2 input value.
The expected output is
> a.out
1
1.110000014 2.220000029 -1.000000000
(2.000000000,1.000000000)
Both gfortran and XLF output the expected value.