Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
11 Views

class(*) arrays in move_alloc

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

0 Kudos
1 Reply
Highlighted
Black Belt
11 Views

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.
 

0 Kudos