Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
26745 Discussions

Passing negative indexed arrays to a subroutine

Navdeep_Rana
Beginner
148 Views

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?

0 Kudos
2 Replies
jimdempseyatthecove
Black Belt
148 Views

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

jimdempseyatthecove
Black Belt
148 Views

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