1

I would like to create a pointer to an array with smaller dimension. For example, I have some array arr(1:2, 1:10, 1:10).

Now I want to create a pointer to arr(1:1, 1:10, 1:10) but I want to delete first I don't know how I should name it by it look like index, and second pointer to (2:2, 1:10, 1:10).

I need it because I would like to send array with 2 dimensions (matrix) to a function.

Here is an indication of what I want to do, with pseudocode.

INTEGER, DIMENSION (1:2, 1:10, 1:10), TARGET :: BOUNDRIES
INTEGER, DIMENSION (:,:), POINTER : LEFT_BOUNDRY

LEFT_BOUNDRY => BOUNDRIES(1,1:10,1:10)
DO i = 1,n
    DO j = 1,10
    write(*,*) LEFT_BOUNDRY(i,j)
    END DO
END DO

Is it possible to do it?

5
  • 1
    From your description, you don't necessarily need a pointer at all. Could you perhaps just pass arr(2,:,:) to the function? You'd need to show the function interface for us to advise on that. Commented Nov 30, 2017 at 21:22
  • The function which I would like to use is ww2.odu.edu/~agodunov/computing/programs/book2/Ch06/Inverse.f90 I know that I can edit it but I don;t want to do that and I don't know it is possible. Commented Nov 30, 2017 at 22:23
  • There is not a single pointer in that link. Which functiin do you have in mind? Can you copy the header (argument list + argument declarations) into your question? Commented Nov 30, 2017 at 22:41
  • I've tried to "tidy" your question a little bit, but I can't easily change the second paragraph without danger of changing your meaning. Could you please explain what you mean by that? [If you aren't a native English writer, that's fine, someone just needs to be sure they know what you want to say to be able to draft it for you.] Commented Nov 30, 2017 at 23:00
  • @francescalus the OP is likely not very comfortable writing in English, and the post is hard to comprehend as it stands. Probably the second paragraph needs to be rewritten disregarding the less understandable bits. Commented Dec 2, 2017 at 13:42

1 Answer 1

2

When we have a dummy argument in a function or a subroutine (collectively, procedure) we have a corresponding actual argument when we execute that procedure. Consider the subroutine s:

subroutine s(x)
  real x(5,2)
  ...
end subroutine s

The dummy argument x is in this case an explicit shape array, of rank 2, shape [5,2].

If we want to

call s(y)

where y is some real thing we don't need to have y a whole array which is of rank 2 and shape [5,2]. We simply need to have y have at least ten elements and a thing called storage association maps those ten elements to x when we are in the subroutine.

Imagine, then

real y1(10), y2(1,10), y3(29)
call s(y1)
call s(y2)
call s(y3)

Each of these works (in the final case, it's just the first ten elements that become associated with the dummy argument).

Crucially, it's a so-called element sequence that is important when choosing the elements to associate with x. Consider

real y(5,12,10,10)
call s (y(1,1,1:2,3:7))

This is an array section of y of ten elements. Those ten elements together become x in the subroutine s.

To conclude, if you want to pass arr(2,1:10,1:10) (which is actually a rank 2 array section) to a rank 2 argument which is an explicit shape array of no more than 100 elements, everything is fine.

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.