- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Suppose that you have an array A(2,6,10). Is it possible to construct a second array B(2,6) from pointers p1, p2?
p1 => A(1,1:6)
p2 => A(2,1:6)
p1 => A(1,1:6)
p2 => A(2,1:6)
Link Copied
7 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There are many ways in which this can be done. Here is one that you can try to find out if it meets your needs.
I have ignored the ",10" part of your description of array A, just as your assignments to p1 and p2 did.
I have ignored the ",10" part of your description of array A, just as your assignments to p1 and p2 did.
[fortran]program tptr integer, dimension(2,6),target :: A, B integer, pointer, dimension(:) :: p1,p2 data A/11,21,12,22,13,23,14,24,15,25,16,26/ p1 => A(1,:) ! p1 and p2 are 1-D arrays p2 => A(2,:) B = reshape((/ p1, p2 /),(/2,6/)) !assemble the pieces into B write(*,'(1x,6I4)')B end program tptr [/fortran]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks mecej!
Is it possible to do the same by avoiding the decleration of array B?
Is it possible to do the same by avoiding the decleration of array B?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I don't understand what "do the same" is intended to mean, but the following modification (with references to array B removed) runs fine:
[fortran]program tptr integer, dimension(2,6),target :: A integer, pointer, dimension(:) :: p1,p2 data A/11,21,12,22,13,23,14,24,15,25,16,26/ p1 => A(1,:) ! p1 and p2 are 1-D arrays p2 => A(2,:) write(*,'(1x,6I4)')reshape((/ p1, p2 /),(/2,6/)) end program tptr [/fortran]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Be mindful that p1 and p2 in the above example are stride 2 arrays that are 1D (p1 points to every other element of A and p2 points to the other every other elements of A).
Jim
Jim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The problem is very simple:
Suppose the matrix A(2,3,:) which third dimension varies... also:
[ a11 a12 a13 ]
[ a21 a22 a23 ]
How can i extract the first two dimensions of matrix A and put them like this:
[ a11 a21 ]
[ a12 a22 ]
[ a13 a23 ]
using the 1D pointers p1, p2 which:
[p1] = [ a11 a12 a13 ]
[p2] = [ a21 a22 a23 ]
Suppose the matrix A(2,3,:) which third dimension varies... also:
[ a11 a12 a13 ]
[ a21 a22 a23 ]
How can i extract the first two dimensions of matrix A and put them like this:
[ a11 a21 ]
[ a12 a22 ]
[ a13 a23 ]
using the 1D pointers p1, p2 which:
[p1] = [ a11 a12 a13 ]
[p2] = [ a21 a22 a23 ]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If that's what you want, no need to do chopping up and reassembling or using pointers.
Use TRANSPOSE !
Use TRANSPOSE !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It's not working for non-square matrices!!!!!! I can't transpose a 3 dimension matrix!

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