I would like to preserve array bounds in associate block as:
integer a(2:4,2)
associate (b => a(:,1))
print *, lbound(b), ubound(b)
end associate
I expect the bounds of b
is 2
and 4
, but in fact they are 1
and 3
. How to do this? Thanks in advance!
You are associating to a subarray, its boundaries always start at 1. Try
print *, lbound(a(:,1),1)
AFAIK you can not use the pointer remapping trick in associate
construct. Specifically: "If the selector is an array, the associating entity is an array with a lower bound for each dimension equal to the value of the intrinsic LBOUND(selector)."
But you can of course use pointers
integer,target :: a(2:4,2)
integer,pointer :: c(:)
associate (b => a(:,1))
print *, lbound(b), ubound(b)
end associate
c(2:4) => a(:,1)
print *, lbound(c), ubound(c)
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With