arrays - Add element to FORTRAN pointer? -


i have array arr in fortran going 1 n need test each element against elements preceding , succeeding (i.e. i against i-1 , i+1) - problem being elements 1 , n have n or 1 predecessor or successor, respectively (i.e. loops).

instead of testing first , last elements separately, i'd rather run loop like:

do i=1,n    call testi(i-1,i,i+1) end 

and define pointer (in order not use dummy array , twice memory) like

arrpointer(0) => arr(n) arrpointer(1:n) => arr(1:n) arrpointer(n+1) => arr(1) 

to "simulate" loop in array. (note each array element vector - arr(i)%vec(1:m) )

the above not work each new definition of pointer overwrite previous. question arises:

is there way add element pointer array without deleting previous definitions?

ps:

as current workaround, use allocatable type array pointers:

type :: pointerarray   real, pointer :: elementpointer(:) end type pointerarray type(pointerarray), allocatable :: arrpointer(:)  arrpointer(0)%elementpointer => arr(n) i=1,n   arrpointer(i)%elementpointer => arr(i) end arrpointer(n+1)%elementpointer => arr(1) 

while replacing loop below not work:

arrpointer(1:n)%elementpointer => arr(1:n) 

however there might simpler way of not aware, type arrays pointers again make code not nicely readable.

i don't think there's way pointers way envision. instead, recommend using integer array dimensioned 0:n+1 map desired 1:n range. example:

integer :: i(0:n+1), j  real :: a(n)   ! -- setup  j=1,n     i(j) = j  enddo  i(0) = n  i(n+1) = 1   ! -- can do:  j=1,n     ! call mysub(a(i(j-1)), a(i(j)), a(i(j+1)))  enddo  

alternatively, use function define i(j).


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -