- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a a prrety large 1D array allocated. Let us say x(1:100000000). Then I want to use a 2D array pointer y(1:50000000,1:2) to point to x, so I can access array elements in a more meaningful way.
Is there an easy way to do this? I do not want to reallocate memory and copy x to y.
Thanks.
Is there an easy way to do this? I do not want to reallocate memory and copy x to y.
Thanks.
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Easy way - pass X(1) to a subroutine where the argument is declared (1:50000000,1:2) and do what you need there. This can also be done with pointer remapping in version 12 but I'll have to do some experiments first. You can also fake it by using C_F_POINTER(C_LOC(X),P,[50000000,2]) where P is a POINTER with dimension (:,:).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thanks Steve.
Few further questions:
Is the pointer remapping written in Fortran standard?
If I use C_F_POINTER to remap the pointer and later x becomes unaccessable, then can I deallocate memory with ponter Y?
Few further questions:
Is the pointer remapping written in Fortran standard?
If I use C_F_POINTER to remap the pointer and later x becomes unaccessable, then can I deallocate memory with ponter Y?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There are a few things that the program below does not test but it looks like pointer remapping is working in IVF 12 update 1.
Abhi
-----
Abhi
-----
[fxfortran] Program Test_PointerPartition ! ! Purpose: Test bounds remapping for pointers. ! Implicit None Real(8), Target :: A(0:20), C(22:26) Real(8), Pointer :: B(:) Integer, Target :: G(100) Integer, Pointer :: H(:,:) Integer :: i ! !########## ! A = 1.0d0; C = 0.0d0 Nullify(B) B => A(11:20) print *, LBOUND(B), UBOUND(B) ! correct answer: 1, 10 Nullify(B) B => A print *, LBOUND(B), UBOUND(B) ! correct answer: 0, 20 Nullify(B) B => A(:) print *, LBOUND(B), UBOUND(B) ! correct answer: 1, 21 Nullify(B) B => C print *, LBOUND(B), UBOUND(B) ! correct answer: 22, 26 Nullify(B) B => C(:) print *, LBOUND(B), UBOUND(B) ! correct answer: 1, 5 Nullify(B) B(51:60) => A(11:20) print *, LBOUND(B), UBOUND(B) ! correct answer: 51, 60 Nullify(B) B(1:5) => C print *, LBOUND(B), UBOUND(B) ! correct answer: 1, 5 Nullify(H) H(0:24,2:5) => G print *, LBOUND(H), UBOUND(H) ! correct answer: {0, 2}, {24,5} do i=1,Size(G) G(i) = i end do print *, H(5,:) ! correct answer: {6,31,56,81} End Program Test_PointerPartition[/fxfortran]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Pointer remapping is standard F2003. If you create a new pointer with C_F_POINTER you can still deallocate using the original pointer.

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