The high level overview of my situation is described here. I am breaking it apart into smaller, specific questions, such as this one, regarding extensive use of global variables in a procedural style.


In the large legacy Fortran codebase that me and some other new team members have inherited, the use of global variables by way of common blocks is extensive. There are thousands of arrays that are passed around between various modules (via include syntax).

Is there a overall strategy of working with and managing Fortran global variables and common blocks in such a massive way (1000s of shared arrays)? Are there any alternatives to global variables (e.g., database) that don't take a huge performance hit?

It seems to me that since the common block feature is part of the Fortran language (in order to make it fast by basically doing in-memory compute?), then it was intended to be used this way. However, on the other end of the argument is the advice that use of global variables is bad practice, mainly because it is hard to debug because changes to state can happen from so many different places (modules, subroutines).

Also, by alternatives to the global variable approach, I am thinking about some data layer that is not so tightly coupled like a database, where the data storage is abstracted away from the main Fortran program. This way we could be more flexible with our choice for data storage and could also interface to this data storage from other places like Python programs.

  • 1
    Downvoters! Please be a good citizen and provide a comment to help me improve the question, so I can iterate and hopefully make it better and more useful. You can still downvote :), I just would like to know the reason why. – ximiki Feb 12 at 21:23
  • I guess your best bet is to introduce some (Pseudo) OO features into the Fortran codebase, like explained here, and then follow the advice about global variables in existing legacy code in this answer – Doc Brown Feb 22 at 9:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.