Alternative to COMMON in Fortran 90

Alternative to COMMON in Fortran 90


I am a F90 newbie and need advice on the following problem. I am converting an old program from F77 to F90. In this program a number of time-dependent differential equations are solved for different but coupled geometries (so-called linked runs) by looping through all geometries during each time step. In the F77 version, all the variables and constants for all runs are stored in one large array, and the variables for the current run are accessed via a COMMON-block. To read/write all variables for each run the following type of coding is used:

C main program 
real store_vars(12,3) 
integer irun 
real a,b,c(10) 
common /variables/a,b,c 
do irun=1,3 
C Read variables for current run from storage array. 
    call store(irun,'R',store_vars) 
C Do stuff with a,b and c... 
C Write variables for current run to storage array. 
    call store(irun,'W',store_vars) 
subroutine store(irun,action,store_vars) 
integer irun 
character action 
real store_vars(12,3),run_vars(12) 
common /variables/run_vars 
if (action.eq.'W') 
C Write to storage array. 
    do i=1,12 
C Read from storage array. 
    do i=1,12 

How do I do this without the COMMON-block in Fortran 90 and without having to list all the variables in the subroutine "store" (there are quite a few of them)? I'm trying to move the code away from F77 by using modules for global variables, but I haven't figured out a way to do the above in a "nice" way. Since the code is used for research users may modify the code and add global variables, so I don't want the person in question having to make changes in lots of files and subroutines. Preferably, the user will only have to add a declaration in one module and then change an integer in the same or one other module which somehow indicates the number of variables. I thought about some kind of array of integer pointers that would simply be looped through in the "store" routine, but it seems every pointer has to be declared to the size of the target. Wouldn't this require changes in the "store" routine for every added global variable?

Thanks for any hints,


1 post / 0 new
For more complete information about compiler optimizations, see our Optimization Notice.