Prev: Determining Screen Resolution
Next: Random_number
From: happycamper on 11 Feb 2010 13:16 Can you associate a pointer or something to a 3d matrix in such a way that access through the pointer gives a 1D view or the 3d matrix?
From: dpb on 11 Feb 2010 13:38 happycamper wrote: > Can you associate a pointer or something to a 3d matrix in such a way > that > access through the pointer gives a 1D view or the 3d matrix? Yes, or EQUIVALENCE to a 1D array is another simple way. --
From: happycamper on 11 Feb 2010 13:49 On Feb 11, 12:38 pm, dpb <n...(a)non.net> wrote: > happycamper wrote: > > Can you associate a pointer or something to a 3d matrix in such a way > > that > > access through the pointer gives a 1D view or the 3d matrix? > > Yes, or EQUIVALENCE to a 1D array is another simple way. > > -- How about in modules? What would be the syntax?
From: dpb on 11 Feb 2010 13:59 happycamper wrote: > On Feb 11, 12:38 pm, dpb <n...(a)non.net> wrote: >> happycamper wrote: >>> Can you associate a pointer or something to a 3d matrix in such a way >>> that >>> access through the pointer gives a 1D view or the 3d matrix? >> Yes, or EQUIVALENCE to a 1D array is another simple way. >> >> -- > > How about in modules? What would be the syntax? Don't see it matters module or not (other than the obvious of being in scope). That is, can't equivalence a module-variable to another outside the module but only within so wouldn't work if the module source isn't available. Is that the question? --
From: happycamper on 11 Feb 2010 14:14
On Feb 11, 12:59 pm, dpb <n...(a)non.net> wrote: > happycamper wrote: > > On Feb 11, 12:38 pm, dpb <n...(a)non.net> wrote: > >> happycamper wrote: > >>> Can you associate a pointer or something to a 3d matrix in such a way > >>> that > >>> access through the pointer gives a 1D view or the 3d matrix? > >> Yes, or EQUIVALENCE to a 1D array is another simple way. > > >> -- > > > How about in modules? What would be the syntax? > > Don't see it matters module or not (other than the obvious of being in > scope). That is, can't equivalence a module-variable to another outside > the module but only within so wouldn't work if the module source isn't > available. > > Is that the question? > > -- This does not compile: subroutine test(nz,nx,ny,arr) integer :: nz,nx,ny real :: arr(nz,nx,ny) real :: arr1d(nz*nx*ny) equivalence (arr1,arr) end program test real , allocatable :: arr(:,:,:) integer :: nz=5,nx=5,ny=5 integer :: i,j,k,val allocate(arr(nz,nx,ny)) do i = 1, ny do j = 1, nx do k = 1, nz val = k+j+i arr(k,j,i) = float(val) enddo enddo enddo call test(nz,nx,ny,arr) end program test I want to look at an allocated 3d array as a 1d array at some point. |