I want to be able to reset elements in an array which are not in a consecutive block of memory. I thought to use an array of pointers for this rather than a pointer array, as my understanding of pointer arrays is that they must point to a coherent block of memory (e.g pointer(1:10,1:10) => target(1:100) )
My simple test program is as follows:
program test
implicit none
integer, target :: arr(4,4)
type ptr
integer, pointer :: p
end type ptr
type(ptr), dimension(2) :: idx
arr=0
idx(1)%p=>arr(2,2)
idx(2)%p=>arr(4,2)
idx(1)%p=5 ! this is okay
idx(2)%p=5 ! this is okay
idx(1:2)%p=5 ! this gives an error
print *,arr
end program test
The first two statements idx(n)%p=5 are okay, but I want to be able to set a chunk of the array in one statement using the spanning method idx(1:n)%p=5 but when I do this I get the following compile error:
Error: Component to the right of a part reference with nonzero rank must not have the POINTER attribute at (1)
Can I set the value of a chunk of array entries using pointer somehow? Perhaps it is in fact possible with a pointer array rather than an array of pointers...
I think this is related to Fortran: using a vector to index a multidimensional array
but I can't see how to use that answer here.