- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Great! Thanks Jugoslav
Eddie
Eddie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
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