Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!

Two FORTRAN program

peter_m_
Beginner
77 Views

I have 2 different FORTRAN programs (quite big programs). Let us call program 'A' and 'B'

My program 'B' needs to use a subroutine of program A (exactly the same subroutine). Is it possible to call that subroutine of A from a subroutine of B?

Any examples will be appreciated.

Peter

 

0 Kudos
2 Replies
jimdempseyatthecove
Black Belt
77 Views

What you normally do is separate the subroutine into its own source file then either:

a) Add the source file to both of your projects/makefile for (A and B).

b) Compile the shared subroutine(s) into a Library project, then add this library (and dependency on) to both of your projects. The recommended practice in Fortran is to place the subroutine into a CONTAINS section of a module, then USE the module in A and B. The path to the .mod file must be in your INCLUDE path, the path to the resultant .obj file (when not placed into a library) may also need to be specified.

Jim Dempsey

jimdempseyatthecove
Black Belt
77 Views

If you are using Microsoft Visual Studio, you can have a single Solution that has three Projects:

   one Project to build the subroutine(s) Library or Modules
   one Project to build program A (dependent on the Library Project)
   and one Project to build program B (dependent on the Library Project).

For debugging you then set the Startup Project to your choice of either A or B.

Jim Dempsey

Reply