On 21/01/23 9:01 PM,
ali_n...@yahoo.com wrote:
> The main program with too many subroutines and functions is existed. Some of the subroutines and functions also use subroutines, functions, and modules. I decided to write them in independent files due to clarity in the main program. Then I created an independent file as a module to collect them with the include command.
>
> Now I have one main program and one independent file for the module. I compile the program but it shows an error. The error is about missing mentioned subroutine in the above independent file.
>
> My question in general is: If you have a program with one main program and a number of sub-programs (subroutines, functions, and modules), which also they have sub-programs, what method do you use to run it?
Your situation is what most programs in general will present.
I prefer to have all functions and subroutines grouped into
modules. To run, this would then require something like:
$> g95 -o prog this_mod.f90 that_mod.f90 other-mod.f90 main.f90
$> ./prog argument1 argument2 ...
If you do not want to construct the first line (with the
modules all in the right order before the main program) by
hand, then you can use some 'make file' tooling, or some GUI
that does those things (but I never use the latter). Finding
the dependencies between the modules can be tricky, but as
long as there are only a dozen or so, a few trials and errors
can still solve it.
And if you do not have the situation where all is encapsulated
into modules, you could of course add the files with those
"lonely" functions and subroutines to the compile line with
the modules and the main program. But often this means that
those functions and subroutines would then need an interface
added to the main program, and/or the modules that use them,
for proper functioning. It usually pays of (and it keeps the
other files simpler) to avoid lonely routines and put them
in one or more modules, where the interface is then defined
just once.
On the other hand, for historical reasons one might want to
keep some functions (like Lapack or BLAS routines) exactly
as they are provided.. Having a few all-Caps fixed-format
Fortran 77 files in the list has its charm, of course!
--
Jos