F90 code structure question

F90 code structure question

I have a piece of fully-functional code that has the structure illustrated as File X (see attached).  I want to transfer the subroutines to an Include file and reference it.  I'm not sure how to handle the Module.  I have actually created File Y & File Z, as illustrated.

File Y compiles w/o errors.

Compile File Z has 4 errors:

For example, regarding the 1st line (Module Share) in File Y:  This statement is positioned incorrectly and/or has syntax errors.

It seems not to like the Module being out in the include file.

Is this enough to give any clues as to what might be going on?  Has anyone ever tried to do this?

Downloadapplication/vnd.ms-excel Structure Convert.xls16.5 KB
4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

You have two options:

a) Add Y.f90 to your project and replace "include 'T.f90'" with "USE Share"
b) Move "include 'T.f90'" to preceed "Program Main"

Method a) is preferred.

Jim Dempsey

Beautiful, Jim. Thanks for thinking in abstract terms w/o actual code. Your grasp was perfect.

FWIW, with your (b), by 'T.f90' you meant 'Y.f90'. Beyond that, both units (Y.f90 & Z.f90) compiled fine. However, on Build, I got this error:
The source files "(path)Y.f90" and "(path)Z.f90" are both configured to produce the output file "(path) Share.mod". The project cannot be built.

Regarding your (a), I already had both files added to the project. By replacing "include 'T.f90" (you meant Y.f90) with "USE Share", everything worked out marvelously! I'm off and running.

Thanks for your help, Jim. I can see why you're a Black Belt (smile).

You are correct on the T vs Y, I guess I lost home key position of the keyboard (T next to Y).

You cannot have a solution/project with both options as this would attempt to create two Share.mod files.
Unlike C++ (templates) where static declarations and member functions global functions can appear in multiple files, FORTRAN does not permit this. Modules (data and functions) must be declared once.

Sometimes you can fool the compiler into using multiple same named modules, however this often exhibits itself by
a) builds always rebuilds built files (circular reference behavior)
b) builds reporting build errors (multi-threaded build having mod file being deleted or in use by rebuild in one thread while being USED in another thead)

If you see either of the above behaviors look at a) circular references, or b) multiple declarations of the module

Jim Dempsey

Leave a Comment

Please sign in to add a comment. Not a member? Join today