3 ! Functional test of User Defined Derived Type IO.
5 ! This tests a combination of module procedure and generic procedure
6 ! and performs reading and writing an array with a pseudo user defined
7 ! tag at the beginning of the file.
11 integer :: myarray(15)
13 procedure
:: user_defined_read
14 generic
:: read (formatted
) => user_defined_read
16 type, extends(udt
) :: more
17 integer :: someinteger
= -25
20 interface write(formatted
)
21 module procedure user_defined_write
24 integer :: result_array(15)
26 subroutine user_defined_read (dtv
, unit
, iotype
, v_list
, iostat
, iomsg
)
27 class(udt
), intent(inout
) :: dtv
28 integer, intent(in
) :: unit
29 character(*), intent(in
) :: iotype
30 integer, intent(in
) :: v_list (:)
31 integer, intent(out
) :: iostat
32 character(*), intent(inout
) :: iomsg
33 character(10) :: typestring
36 read (unit
, '(a6)', iostat
=iostat
, iomsg
=iomsg
) typestring
37 typestring
= trim(typestring
)
40 if (typestring
.eq
.' UDT: ') then
41 read (unit
, fmt
=*, iostat
=iostat
, iomsg
=iomsg
) dtv
%myarray
47 if (typestring
.eq
.' MORE: ') then
48 read (unit
, fmt
=*, iostat
=iostat
, iomsg
=iomsg
) dtv
%myarray
54 end subroutine user_defined_read
56 subroutine user_defined_write (dtv
, unit
, iotype
, v_list
, iostat
, iomsg
)
57 class(udt
), intent(in
) :: dtv
58 integer, intent(in
) :: unit
59 character(*), intent(in
) :: iotype
60 integer, intent(in
) :: v_list (:)
61 integer, intent(out
) :: iostat
62 character(*), intent(inout
) :: iomsg
63 character(10) :: typestring
66 write (unit
, fmt
=*, iostat
=iostat
, iomsg
=iomsg
) "UDT: "
67 write (unit
, fmt
=*, iostat
=iostat
, iomsg
=iomsg
) dtv
%myarray
69 write (unit
, fmt
=*, iostat
=iostat
, iomsg
=iomsg
) "MORE: "
70 write (unit
, fmt
=*, iostat
=iostat
, iomsg
=iomsg
) dtv
%myarray
73 end subroutine user_defined_write
80 class (more
), allocatable
:: somemore
81 integer :: thesize
, i
, ios
84 ! Create a file that contains some data for testing.
85 open (10, form
='formatted', status
='scratch')
86 write(10, '(a)') ' UDT: '
88 write(10,'(i5)', advance
='no') i
93 result_array
= (/ (i
, i
= 1, 15) /)
94 more1
%myarray
= result_array
95 read (10, fmt
='(dt)', advance
='no', iomsg
=iomsg
) udt1
96 if (iomsg
.ne
.'SUCCESS') STOP 1
97 if (any(udt1
%myarray
.ne
.result_array
)) STOP 1
99 open (10, form
='formatted', status
='scratch')
100 write (10, '(dt)') more1
103 read (10, '(dt)', iostat
=ios
, iomsg
=iomsg
) more1
104 if (iomsg
.ne
.'SUCCESS') STOP 1
105 if (any(more1
%myarray
.ne
.result_array
)) STOP 1