Re: question about negative indices in fortran 77
From: Jose Miguel Pasini (jmpeightyfour_at_cornell.nospam.edu)
Date: Wed, 29 Dec 2004 14:45:08 -0500
On Wed, 29 Dec 2004 12:21:34 -0700
"James Van Buskirk" <email@example.com> wrote:
> "Jose Miguel Pasini" <firstname.lastname@example.org> wrote in
> > Now we arrive at the interesting part. Let's say I have the
> > following declaration at the beginning of a subroutine:
> > implicit real*8 (a-h,o-z)
> > real*8 e(m*n),d(m*n),c(m*n),b(m*n),a(m*n),
> > & ef(m*n),df(m*n),cf(m*n),bf(m*n),af(m*n),
> > & x(m*n),y(m*n),r(m*n),up(m*n),aux(m*n)
> > The way I understand it, an expression like d(-i) is equivalent to
> > e(m*n-i).
> If this code worked, there is something that ties all those
> declared arrays together somehow. Since this is f77, all
> those arrays aren't automatic arrays, so they must be dummy
> arguments or in common. You must include the code from the
> subroutine statement up to the first executable statement
> within the subroutine. Then we can determine whether the
> arrays are dummy arguments or in common. If they are dummies,
> your compiler should have the capacity to give you a
> traceback so you can know where the subroutine was fatally
> called from. From there we might conceivably need the
> declarations of the calling subprogram and the values of
> any actual arguments.
Thank you very much for the comments. You nailed it on the head! I'd
like to also thank the other people that have answered so promptly.
Indeed, the arrays are dummy arguments, and the subroutine that calls
this one uses arguments from a common block, where they're declared in a
different order. Actually, in the common block they're declared like
this (the same letters are used)
real*8 d(nxy),e(nxy), etc.
instead of the other way around. Here nxy=(m+2)*(n+2). Therefore, in
order to sanitize the program I should change the declarations in the
real*8 e((m+2)*(n+2)),d((m+2)*(n+2)), etc
and then change the reference to e(-i) into d((m+2)*(n+2) - i).
-- Jose Miguel Pasini To reach me, replace the numbers with actual numbers.