F90 code structure question

F90 code structure question

Ritratto di coulteraqs

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?

AllegatoDimensione
Scarica Structure Convert.xls16.5 KB
4 post / 0 new
Ultimo contenuto
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione
Ritratto di jimdempseyatthecove

You have two options:

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

Method a) is preferred.

Jim Dempsey

www.quickthreadprogramming.com
Ritratto di coulteraqs

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).

Ritratto di jimdempseyatthecove

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

www.quickthreadprogramming.com

Accedere per lasciare un commento.