Quantcast
Channel: Intel® Software - Intel® Fortran Compiler for Linux* and macOS*
Viewing all articles
Browse latest Browse all 2746

User defined derived-ype IO for extended type

$
0
0

I'd like to add user defined derived-type IO for an extended type. However I got an error message
"error #8638: The type/rank signature for arguments of this specific subroutine is identical to another specific subroutine that shares the same defined I/O." Anyone has idea how to do this?

The test code is here.

module mymod
type :: mydata_t
character(len=10) :: name
contains
procedure :: write_unfmt_mydata
generic :: write(unformatted) => write_unfmt_mydata
end type mydata_t

type, extends(mydata_t) :: myint_t
integer :: nn
integer, pointer :: xx(:)
contains
procedure :: write_unfmt_myint
!! How can I add an UDIO for an extended type?
!! The following line causes compilation error
generic :: write(unformatted) => write_unfmt_myint

end type myint_t

contains
subroutine write_unfmt_mydata(dtv, unit, iostat, iomsg)
class(mydata_t), intent(in) :: dtv
integer, intent(in) :: unit
integer, intent(out) :: iostat
character(len=*), intent(inout) :: iomsg

write(unit, iostat=iostat, iomsg=iomsg) dtv%name
end subroutine write_unfmt_mydata

subroutine write_unfmt_myint(dtv, unit, iostat, iomsg)
class(myint_t), intent(in) :: dtv
integer, intent(in) :: unit
integer, intent(out) :: iostat
character(len=*), intent(inout) :: iomsg

write(unit, iostat=iostat, iomsg=iomsg) dtv%mydata_t
write(unit, iostat=iostat, iomsg=iomsg) dtv%nn
write(unit, iostat=iostat, iomsg=iomsg) dtv%xx(1:nn)
end subroutine write_unfmt_myint

end module mymod
program test
use mymod

type(mydata_t) :: dd
type(myint_t) :: ii
dd = mydata_t( 'xyz' )
ii%name = 'abc'
ii%nn = 100
allocate(ii%xx(ii%nn))
ii%xx = 5

open(10, file='test.dat', form='unformatted')
write(10) dd
write(10) ii
end program test


Viewing all articles
Browse latest Browse all 2746

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>