fortran77: arrays of pointers or arrays of structures?
Question
I'm trying to optimize a code in fortran77 and I'd like to know whether the arrays declared in the following way inside a routine or an header file are arrays of pointers or arrays of structures:
case 1: real*8 xred(maxatm)
case 2: common /atoms/ x(maxatm)
I've already searched over the internet but I couldn't find any info on this, the only thing I found was that when you pass an array to a routine it is passed by reference. But regarding when it is declared in header file or inside the routine I found nothing.
Thanks in advance!
Solution
Within a .f77 'header'/common/.CMN file you are declaring your variables to be used within your program. The space required for these variables is established at compile time for each file that contains the header declaration. So for 'My.CMN' which contains
REAL*8 XEDG(-2:MAXNB+4) ! left x-edges of cells
REAL*8 YEDG(-2:MAXNB+4) ! left y-edges of cells
REAL*8 XC(-2:MAXNB+4) ! X CELL CENTERS
REAL*8 YC(-2:MAXNB+4) ! Y CELL CENTERS
These variables are created each time they are declared in a .f77 file via INCLUDE 'My.CMN'
.
However, using a common block
COMMON /GRID/ XEDG,YEDG,XC,YC
tells the compiler that the variables contained within a given .CMN file (or whatever) are to some extend global/shared, here the compiler will use pointers to the relevent space in memory.
The COMMON statement defines a block of main memory storage so that
different program units can share the same data without using arguments.
See here for more information on COMMON
and here for the Sun FORTRAN 77 4.0 Compiler Reference Manual.