So far, we’ve covered the essential building blocks of Fortran: built-in types and declaration, arithmetic, control flow, and procedures. In theory, this is all you need to write correct and powerful Fortran programs. In practice, however, as your app or library grows in size, organization of your source code becomes ever more important. This is where modules come to the rescue.
Modules allow you to organize variable and procedure definitions in a meaningful way, and make them accessible for use in programs, procedures, or other modules. Modern Fortran libraries are typically organized in one or more modules. Large applications define most functionality in modules, with only the top-level code being defined in the main program. In this chapter, we’ll write a few modules to define variables and functions. We’ll then access the modules from the main program of our tsunami simulator.