question about negative indices in fortran 77

From: Jose Miguel Pasini (jmpeightyfour_at_cornell.nospam.edu)
Date: 12/29/04


Date: Wed, 29 Dec 2004 10:53:52 -0500

Dear friends,

I am working with an "inherited" program written in Fortran 77. The
program works fine as it is (both on Compaq compilers for windows and
Intel compilers for linux), but now I'm doing some modifications and I
need to debug it. The problem is that some (I guess very old)
subroutines use negative indices in arrays, so whenever I compile
with Intel Fortran 8.1 for linux with -C option, the program stops at
these calls and doesn't arrive at the interesting parts.

I'm checking for violations of array bounds because the program is doing
something really weird: a variable is changing its value inside a
subroutine where it isn't touched (neither read nor written!). The only
thing that I've seen trigger this kind of behavior in other languages
has always been array bounds violations (even just reading forbidden
memory).

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). Using this I can translate the whole subroutine into something
more sensible that the debugger will allow. I actually did it with one
subroutine, and the results are identical to what I obtained before the
translation. Now I want to do the same thing to another subroutine that
is very similar, but I have the following problem: there is a reference
to e(-i), but since "e" is the first array in the declaration, where is
the memory allocated for this?

Please forgive me if this is a silly question in this forum. I am mostly
a C/C++ guy and my head tends to explode just a bit when I see code that
depends on the details of memory layout :-)

Thank you very much in advance,

-- 
Jose Miguel Pasini
To reach me, replace the numbers with actual numbers.