Software Archive
Read-only legacy content
17060 Discussions

Passing allocatable arrays

Intel_C_Intel
Employee
1,288 Views
How do I pass allocatable arrays? The following code compiles in CVF version 6.6 on NT, but the array is not passed properly from the main routine to subroutine and back.
Eddie Breeveld

 
      module generator 
       implicit none 
       interface 
         subroutine WZDMG(WZMPTR) 
          double precision, allocatable :: WZMPTR(:) 
         end subroutine 
       end interface 
      end module 
 
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc 
 
      program main 
      use generator 
      implicit none 
      double precision, allocatable :: WZMPTR(:) 
 
      allocate(WZMPTR(1)) 
      wzmptr(1) = 8.7654d0 
      print *,'1: Main', shape(WZMPTR), wzmptr(1) 
      call WZDMG(WZMPTR) 
      print *,'2: Main', shape(WZMPTR), wzmptr(1), wzmptr(99) 
      stop 
      end 
 
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccc 
 
      subroutine WZDMG(WZMPTR) 
      use generator 
      implicit none 
      double precision, allocatable :: WZMPTR(:) 
 
      print *,'1: wzdmg', shape(WZMPTR), wzmptr(1) 
      allocate(WZMPTR(1000)) 
      WZMPTR(99) = 12.345d0 
      print *,'2: wzdmg', shape(WZMPTR), wzmptr(1), wzmptr(99) 
      return 
      end 
 
0 Kudos
5 Replies
Jugoslav_Dujic
Valued Contributor II
1,288 Views
That compiles? My CFV5.0D rightfully complains that dummy argument cannot be allocatable, as the standard says. You have to replace ALLOCATABLE attributes with POINTER attributes and it will work.

Also, note that you have a memory leak in the example -- wzmptr allocated in the PROGRAM can never be deallocated since its association with allocated memory is lost when it's allocated again in the subroutine.

Jugoslav
0 Kudos
Intel_C_Intel
Employee
1,288 Views
Great! Thanks Jugoslav

Eddie
0 Kudos
Steven_L_Intel1
Employee
1,288 Views
Yes, it would compile in 6.6 - 6.6 partially implements a new Fortran 2000 feature called "Allocatable components of derived types" which also permits dummy arguments to be ALLOCATABLE. There are a number of bugs in the implementation, which is why we haven't documented it yet, though the next update will fix a lot of them.

Your source looks like it should be ok to me - I'll run it past our expert in this area to see what he thinks.

Steve
0 Kudos
Intel_C_Intel
Employee
1,288 Views
You can work around this problem till the next release by making WZMPTR assumed-shape in the interface block (i.e. get rid of the ALLOCATABLE attribute there) and declaring it to be a POINTER rather than ALLOCATABLE in the actual subroutine. You will also have to compile the debug version as this doesn't work in the release version. Of course if you implement this workaround you should comment these illegal declarations so that you can find them easily when CVF fixes the bug(s) you are working around. Probably you are better off making everything POINTERs for now.
0 Kudos
rahzan
New Contributor I
1,288 Views
James or Steve or ...,
I have dang little experience using pointers in CVF.
Is there a complete example of how to pass allocatable array using pointers all within docuemented implementation of CVF6.6?
I especially cannot use the debug code since the compuations get too slow unoptimized.
0 Kudos
Reply