1

I'm working on a project where I have a number of arrays of the same size in the 1st, 2nd and 3rd dimension, although the sizes may vary in the 4th dimension.

I would like to group these arrays by constructing a pointer which concatenates these arrays.

To make this less abstract, let's say I have 2 arrays:

A (size: N1 x N2 x N3 x N4a)
B (size: N1 x N2 x N3 x N4b)

in previous versions of the project these arrays where copied to an array C of size N1 x N2 x N3 x (N4a + N4b) which would then be passed to a subroutine to perform ffts on this array.

I would like to avoid this copying operation and construct a pointer p which would contain the same data as the array C in the previous version but without the explicit copying and additional memory allocation.

Is this possible in Fortran?

1 Answer 1

1

No. A pointer cannot point across two otherwise independent objects like that at the same time.

Depending on your situation, what might be workable is to start with an array that is of dimension (N1,N2,N3,N4a+N4b) and then make A and B associated (pointer, storage or argument) to the relevant parts of that initial big array in some way.

REAL, TARGET :: c(N1,N2,N3,N4a+N4b)
REAL, POINTER :: a(:,:,:,:)
REAL, POINTER :: b(:,:,:,:)

a => c(:,:,:,:n4a)
b => c(:,:,:,n4a+1:)
! Go forth and do things with a and b.

! Then later do things with c.

In the dark times, before Fortran had dynamic memory allocation of any sort, this sort of one-array-to-rule-them-all that then got divvied out was in common usage.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.