Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
97 Views

Extract global variables in a Fortran program

I would like to extract the shared variables between two arbitrary subroutines (with nested calls to other subroutines with a long depth) in a Fortran program. One solution that sound intuitive is to find the intersection of the global variables of the two subroutines. I wonder if there is any compiler option that can generate the list of global variables used by a subroutine?

0 Kudos
3 Replies
Highlighted
Black Belt
75 Views

What does "global" mean, in the context of a Fortran program? Certainly not the global variables that one can have in C or assembler. In Fortran 77, members of shared COMMON blocks could be considered "global" in a restricted sense -- the block name was shared, but variable names could be different in different subprograms that access a common block. In modern Fortran, module variables could be considered global to all subprograms that use that module.

Intel Fortran can generate a cross-reference listing, but you will have to do some post processing of the listing files to correlate variables shared across subprograms and source files.

Take a look at source code analysis tools such as Hyperkwic from Polyhedron (https://polyhedron.com/?product=plusfort#hy ) to see if they are suitable.

0 Kudos
Highlighted
New Contributor I
38 Views

I assume you are referring to named or blank COMMON BLOCKs. I was given here a very useful advice which helped me a lot. Move all COMMON BLOCK declarations to one or more modules and then share them with your subroutines. You will discover very quickly if you have a variable named differently in one of the subroutines which can be one of the problems you are encountering. For the second possible problem of mismatched variable sizes or shapes,  the compiler should catch some of them. Size mismatch will cause run time error. You may have to do some work, but it is really worth it.

I. Konuk

0 Kudos
Highlighted
New Contributor I
35 Views

f you insist on suing different names, you can use EQUIVALENCE statement. At least you will know that is the case.

0 Kudos