- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
is there any way to make the example below working??
Program Test
Class(*), allocatable :: tmp(:,:)
integer :: i
integer, allocatable :: b(:,:)
Allocate(integer::tmp(3,3))
open(50,file="tmp1.txt",action="read",status="old",iostat=i)
if(i/=0) Then
write(*,*) i
End if
Do i=1,3
Select Type(tmp)
Type Is(Integer)
read(50,*) tmp(i,:)
End Select
End Do
Do i=1,3
Select Type(tmp)
Type Is(Integer)
write(*,*) tmp(i,:)
End Select
end Do
Select Type(tmp)
Type Is(Integer)
call move_alloc(tmp,b)
End Select
End Program Test
While everything shakes out nicely, the "move_alloc" construct doesn't. I could circumvent it by using a source allocation, but that would double the memory usage until I deallocate tmp. If I haven't got it wrong move_alloc cannot be used because Select Type creates a pointer.
The purpose of the whole exercise is to have a generalized reading routine for rectangular arrays (without writing extra code and using an interface) where I just provide a keyword telling with what data type tmp should be allocated.
Any ideas.
Thanks
Karl
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No.
Unlimited polymorphic objects in Fortran 2008 are not really suitable for use in generic programming. They have a role to play in generic storage.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page