Chapter 3. Organizing your Fortran code using modules
Chapter 4 from Modern Fortran by Milan Curcic
This chapter covers:
- Accessing variables and procedures in modules
- Writing your own custom module
- Refactoring the tsunami simulator with modules
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 in 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 that will be accessed from the main program of our tsunami simulator.