I found nothing in Google, so…
I try to use all objected-oriented features of Fortran 90 and create module for some specific work (like class in C++). I have written something like this:
module test
integer, PRIVATE :: dummy
PUBLIC :: sub
contains
subroutine sub()
dummy = 1
end subroutine sub
end module test
But, I have about 10 such subroutines and it’s very bad idea to place them all into one file. Is it possible to tell compiler, that sub is module subroutine, but place it in another file? Because, it looks like this code will be compiled only if I define body of sub there.
As a direct answer to your question – yes – you can use a
INCLUDEline to reference a file that contains the definition ofsubfrom within the file that contains the definition of the rest of the module (the include line for the files with the subroutine code would come after theCONTAINSstatement in the module.However, this is an atypical arrangement. Further, if it is a “very bad idea to place them all into one file”, then is it a good idea (or necessary) to have the presumably disparate subroutines available from the one module?
The more conventional F90 solution is for the shared data (dummy) to be placed in one “low level” module as public entities, to place the subroutine definitions into a series of “intermediate level” modules that use the low level module as required, and then for a final “high level” module that uses the intermediate modules and provide a collective export to client code. Source code conventions, rather than language rules, are then used to avoid client code from directly using the intermediate and low level modules.
Fortran 2008 allows additional structures and control through the submodule feature, where module procedures interfaces can be defined in a separate program unit to the module procedure implementation.