fortran - Passing a subarray of allocatable array to a subroutine, with right bounds -


in parallel program i'm writing, defined lot of multidimensional allocatable arrays (actually 1d, 2d or 3d) allocated negative lower bounds during execution. reason why did each process handles, in 2d example, 14 14 a matrix , shares overlap of 2 layers four neighboring processes, matrix allocated bounds (-1:12,-1:12), "internal" part of matrix corresponds indices 1 10. (italic represent choice/input dependency).

the problem in doing didn't realize have been impossible rely on this fortran2003 feature, making impossible call mysub(a(:,i),...) in caller unit , refer dummy counterpart of a in subroutine using actual bounds (-1 , 12), since a(:,i) expression, , not variable.

the problem solved if pass whole array a subroutine, explained in previous linked answer, force me write "bigger" , less universal subroutine, which, on contrary, meant act on one-dimensional subarrays.

is possible pass subarray of allocatable array (e.g. a(:,1)) subroutine in way subroutine aware of bounds of actual variable?

as far know: no, not possible.

be aware often, do not want care actual lower bound of array in subroutine. if have subroutine sums array or similar, want loop 1 size of array. , want able pass arrays such subroutines.

if need start specific index in subroutine can always

1. declare lower bound magic constant

real, intent(inout) :: array(-1:,-1:,-1:) 

maybe not nice, use in main production code because started way years ago.

2. declare lower bound constant in module , use that

 use contants   real, intent(inout) :: array(lb:,lb:,lb:) 

3. pass lower bound dummy argument

integer, intent(in) :: lb real, intent(inout) :: array(lb:,lb:,lb:) 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -