I am trying to understand some old FORTRAN code and have reached a point that puzzles me.
In the main program, a 1-D work array has been defined.
i.e. -
REAL WORKA(30)
Later on, portions of this work array are passed into a few sub-routines:
e.g. -
CALL SNAME1 (10, WORKA(1), WORKA(11), WORKA(21))
Subroutine SNAME1, itself, might be defined as follows:
SUBROUTINE SNAME1 (N, VEC1, VEC2, VEC3)
DIMENSION VEC1(10), VEC2(10), VEC3(10)
So far, so good. I think I know what is going on.
Instead of creating three arrays, a single large array has been created, and portions passed in to act like separate arrays.
By carefully managing the array index, VEC1 is WORKA elements 1 through 10, VEC2 is WORKA elements 11 through 20, and VEC3 is WORKA elements 21 through 30.
All are 1-D arrays.
However, I am now looking at a few sub-routines where the work array is being passed in like a 1-D array, but inside the sub-routine, it looks like a 3-D array.
e.g. -
MDIM = 10
. . .
CALL SNAME5 (MDIM, WORKA(1), WORKA(11), WORKA)
. . .
Inside SNAME5, the last three parameters are defined like the following:
SUBROUTINE SNAME5 (MDIM, VEC1, VEC2, VEC3)
DIMENSION VEC1(MDIM, 2, N), VEC2(2, MDIM, N), VEC3(MDIM, N, 2)
Now it looks like portions of the work array are being accessed like a 3-D array. (Or am I mistaken?)
I am trying to unravel this code. How does FORTRAN access a 1-D array via 3-D array notation?
Would VEC1(I, J, K) be the equivalent of WORKA(IMDIM + J2 + K)?
(Dang! Why did they have to write code like this?!?!)