Question

I just read the very good question/answers here about proper ways to use modules in Fortran. By writing subroutines in modules, one makes them explicit, in addition to clarifying the code.

To my knowledge, a module has to be put in a single file, for instance "mod_exemple.f90". Programs I write are often very long, with many subroutines that indeed could be sorted by purpose and thus be put in modules. The problem: that would do very long module files, with hundreds of lines.

Can you split a module over several files? Is it advised? Why? Do you have other suggestions that splitting?

Was it helpful?

Solution

I would advoid splitting a module over mutiple files, it is not that standard a practice and I would find it more difficult to read/understand than if all related routines were in the same file. If your modules are too large then I strongly suggest rethinking the logic of the modules and seeing if you cannot factor out common code and utility routines into their own modules. Rather than having your related code spread across multiple files a well documented, well formated single file module source would be best solution, regardless of how many lines that takes.

OTHER TIPS

Yes, you can, but you have to use include, or cpp's #include, or submodules, which are not widely supported feature of Fortran 2003.

If long and logicaly separate units have to end up in the same file for some reason (submodules not yet available, for example), I do not see anything bad in using separate files and include them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top