×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Modules in fortran 90

Modules in fortran 90

Modules in fortran 90

(OP)
I am using a subroutine in a code I have written, which used modules. Something weird happens when I compile the code with the module that corresponds to this subroutine. Actually, the whole subroutine is called as a module (it is an open access subroutine). The thing is that, in order to compile properly the whole module must be at the beginning of the code, otherwise I get the following error when attempting to compile with gfortran:

use gaussian
1
Fatal Error: Can't open module file ‘gaussian.mod’ for reading at (1): No such file or directory
compilation terminated.


However, if the module is at the beginning of the code it compiles ok. But it is impractical for coding, because I like to have my main code at the beginning of the file. However, once compiled, it doesn't matter if I move the whole module (subroutine) to the end, while I keep the compiled "gaussian.mod" file in the directory.

Is there a way to fix this problem? I mean, it is clear that I can keep the mod file, or even move the bunch of code that does that thing, but I would prefer something more elegant to do the job.

RE: Modules in fortran 90

The easiest way is to run the build twice.

Alternatively, make it hierarchical so that the lower modules do not call the upper modules. Then compile in that order.

RE: Modules in fortran 90

(OP)
Hi. What you mean with running the build twice? Thanks!

RE: Modules in fortran 90

Run the build - that will create some of the mod files. Then run the build again to get the system to build.

RE: Modules in fortran 90

(OP)
Hi. Thank you again. I'm not familiar with the terminology you are using, sorry for that. I actually don't know what "running the build" means. I compile my code in a linux system using gfortran, basically I type at the command line something like "gfortran mycode.f90 -o mycompiledcode.x". You mean I should this twice? because when I do it the first time I get the error I've posted before, unless I already have the gauss.mod file in the directory where I'm compiling the code.

RE: Modules in fortran 90

If you are using a makefile, then just run make twice.
If you are building each object and then linking manually then you need to work out the hierarchy. Have a look at the use clauses. Say you have the following.

main.f90 - use aaa, use bbb
aaa.f90 - use ccc
bbb.f90
ccc.f90

This gives you a tree

CODE

main +- aaa
     |- bbb -- ccc 
This means that the build order should be

ccc
aaa
bbb
main

It does not matter if aaa is done before bbb or vice versa. If you have

CODE

main +- aaa -- bbb
     |- bbb -- ccc 
then it must be

ccc
bbb
aaa
main

This does not cater for mutually recursive modules. If you have mutually recursive modules then you need to break the recursion.

RE: Modules in fortran 90

(OP)
Ok. I think I'm not doing things so correctly, and my level of understanding of the compilation procedure is just superficial (I know the compiler just translate my Fortran code to machine code, that's all it does for me). I'm not familiar with what you are saying about trees, but I understand that there is a hierarchy of dependencies. The way I was doing it was just copying the whole module inside my code, and then using it. That's how the problem appeared.

I'm not using makefiles, I've never get used to do it, but I know it is probably the best way to work. I just write a bunch of code of ten thousand lines, and compile it. It's probably not the best way to work, but I got used to it, and it gets the job done, but maybe I should study more that sort of thing.

Do you have any reference where I can read about all this?

Thanks a lot!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close