- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, I'd like to set up a 1D pointer to access a 2D allocatable array.
EQUIVALENCE would be the perfect solution, but this isn't allowed for
allocatables. The best solution I can come up with is clunky (see
below). Does anyone have a better (standard) method?
real , allocatable :: Arr(:,:)
real :: Vec(*)
pointer (Addr , Vec)
integer i , j
allocate( Arr(-10:20,-13:77) )
Addr = LOC(Arr)
Thanks
John
real , allocatable :: Arr(:,:)
real :: Vec(*)
pointer (Addr , Vec)
integer i , j
allocate( Arr(-10:20,-13:77) )
Addr = LOC(Arr)
Thanks
John
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The following is bog-standard F2003 and works in Intel Fortran 10. Note the required TARGET attribute on Arr.
use iso_c_binding
implicit none
real, allocatable, target :: Arr(:,:)
real, pointer :: vec(:)
allocate (Arr(2,3))
Arr = reshape([1,2,3,4,5,6],[2,3])
call c_f_pointer (c_loc(Arr), vec, [size(Arr)])
print *, shape(vec)
print *, vec
end
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Steve! This is exactly what I needed.
Regards
John
Regards
John
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