- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I have the following problem. I have a 3D array:
V(N+2,0:N+2,N+2)
so the second dimension is one unit larger then the other two, and also the second dimension index starts at 0.
Now I pass a portion of it to a subroutine 'sub1'
do i=1:N+2
do k=1:N+2
call sub1(V(i,:,k))
end do
endo do
subroutine sub1(a)
real, dimension(:),intent(in) :: a
...
end subroutine sub1
The problem is that subroutine sub1 thinks that the index of array 'a' goes from 1 to N+3, therefore everything is shifted and it' s a mess! How can I go around it? So that also inside sub1 I can work with index 0 to N+2 for array a.
Thanks
I have the following problem. I have a 3D array:
V(N+2,0:N+2,N+2)
so the second dimension is one unit larger then the other two, and also the second dimension index starts at 0.
Now I pass a portion of it to a subroutine 'sub1'
do i=1:N+2
do k=1:N+2
call sub1(V(i,:,k))
end do
endo do
subroutine sub1(a)
real, dimension(:),intent(in) :: a
...
end subroutine sub1
The problem is that subroutine sub1 thinks that the index of array 'a' goes from 1 to N+3, therefore everything is shifted and it' s a mess! How can I go around it? So that also inside sub1 I can work with index 0 to N+2 for array a.
Thanks
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I found this:
To address this problem, when the lower bound is not 1, one can pass it from the caller and the callee uses it to declare an assumed-shape array.
If someone has got a better idea that is welcome too! Thanks
To address this problem, when the lower bound is not 1, one can pass it from the caller and the callee uses it to declare an assumed-shape array.
Suppose the caller has the following:
The callee could declare an assumed-shape array like the following:INTEGER, DIMENSION(-3:3) :: x .......... CALL SomeOne(x, -3)
In this case, the extent of array y() agrees with that of actual argument array x()SUBROUTINE SomeOne(y, LowerBound) IMPLICIT NONE INTEGER, DIMENSION(LowerBound:), INTENT(IN) :: y .......... END SUBROUTINE SomeOne
If someone has got a better idea that is welcome too! Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The conventions for passing assumed shape arrays as arguments are defined by the Fortran standard. The default value of the lower bound of an array index is 1.
If you know that the subroutine will always be called with the argument being an array with index starting at 0, you can use the following:
If you know that the subroutine will always be called with the argument being an array with index starting at 0, you can use the following:
[fortran]SUBROUTINE SomeOne(y) IMPLICIT NONE INTEGER, DIMENSION(0:), INTENT(IN) :: y .......... [/fortran]

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page