Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to preserve Fortran array bounds in ASSOCIATE block?

Tags:

arrays

fortran

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!

like image 894
Li Dong Avatar asked Oct 05 '22 20:10

Li Dong


1 Answers

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
like image 72
Vladimir F Героям слава Avatar answered Oct 10 '22 04:10

Vladimir F Героям слава