Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

redefining array bounds

OP1
New Contributor III
449 Views

Dear forum,

I would like to knowif it is possible to redefine array bounds once an array has been allocated. I am not talking about the bounds of a dummy array argument; but the bounds of an actual allocatable array.

For instance

INTEGER,ALLOCATABLE :: A(:)
...
ALLOCATE(A(10)) ! The bounds are 1 and 10
...
! Here I want to redefine the bounds of A (making sure that the condition UBOUND(A)-LBOUND(A)+1=10 is still verified)

Is it possible to do this? I know that of course I could do ALLOCATE(A(-2:7)) at the very begining - but I'd like to change these bounds after the array is allocated.

Olivier

0 Kudos
2 Replies
Steven_L_Intel1
Employee
449 Views
Fortran 2003 has a "pointer remapping" feature where you could do something like this:

INTEGER, POINTER :: AX(:)
AX(-2:7) => A

but this is not yet supported in Intel Fortran.

There is a library routine FOR_DESCRIPTOR_ASSIGN that can be used to rewrite an array descriptor, so you could do something like this:

USE IFCORE
...
INTEGER, POINTER :: AX(:)
...
CALL FOR_DESCRIPTOR_ASSIGN(AX, LOC(A), SIZEOF(A(1)), &
IOR(FOR_DESCRIPTOR_ARRAY_DEFINED, &
IOR(FOR_DESCRIPTOR_ARRAY_NODEALLOC, FOR_DESCRIPTOR_ARRAY_CONTIGUOUS)), &
RANK=1, DIMS_INFO=[-2,7,4])

Now you use AX instead of A.
0 Kudos
OP1
New Contributor III
449 Views
Thank you Steve!

I'll look into this carefully. It seems it's exactly what I need!

Olivier
0 Kudos
Reply