Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

class(*) arrays in move_alloc

may_ka
Beginner
334 Views

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
IanH
Honored Contributor II
334 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
Reply