- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Say I define and allocate array
integer, parameter :: n = 128 real,dimension(:) :: u allocate(u(-1:n+2))
Now I would I like to pass it to a subroutine,
subroutine do_something(u) real,dimension(:),intent(inout) :: u u(-1) = 0 end subroutine do_something
This ends up with a warning. How do I let the subroutine know that the array has negative indices?
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Look at Assumed-Shape Specifications in the documentation.
If your array size is unknown, but the array base index is always -1, then
subroutine do_something(u) real,dimension(-1:),intent(inout) :: u u(-1) = 0 end subroutine do_something
** keep in mind the note in the documentation that assumed shape array passing requires an interface for the subroutine/function (if not within a module).
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Or Assumed-Rank specification:
subroutine do_something(u) real,dimension(..),intent(inout) :: u if(RANK(u) .ne.1) Stop ! 1D array only print *,lbound(u) u(-1) = 0 end subroutine do_something
Jim Dempsey
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