Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fortran Modules

Status
Not open for further replies.

sagn

Programmer
Jun 7, 2001
166
US
Hi

I am rebuilding old code to use modules. In these modules are subroutines.

Often a subroutine will perform a similar function as
another sub in a different module. I would like to call these subroutines the same thing. For example : Output

If possible to do this,
How would I reference these subroutines?


For example, is something like this possible?

USE Mod1
USE Mod2

Call Mod1%Output(x)
Call Mod2%Output(y)

Is so, what would the syntax actually be? Thanks.
 
This looks much like a definition of a class in C++. Up to my knowledge this is not possible in Fortran. But I am only familiar with Fortran 95 and there might have been some new features added in the last years. Many compilers have added features to Fortran 95 that are part of future specifications.

If those subroutines / functions are similar, why not write a new one and link it the normal way to your program to be called anytime ? (I never understood the benefit of including procedures in modules anyway).


Norbert
 
Thanks. I didn;t think it was a feature but wanted to make sure.

The reason I do not want to use a single procedure (subroutine) is that
1) they are not "identical"
2) I like having modules I can take out and move about
.. modules that are 'all - inclusive'
3) Whenever I start new programming projects, I always like to go and find new ways of doing things. They are not always the best but I sure do learn a lot!

Anyway, thanks for your answer.
 
You can use aliases
Code:
use Mod1, Mod1Output => Output
use Mod2, Mod2Output => Output

call Mod1Output(x) ! calls the one from Mod1
call Mod2Output(y) ! calls the one from Mod2
 
Hmmmmm interesting... looks like c pointer to a function or procedure...

Thanks... I'll give it a try.
 
@ xwb:
What structure is this ? Is this standard Fortran 95 ?

Norbert
 
Yes it is standard F95. You can expose specific routines or rename routines for modules. To expose specific routines, use the ONLY keyword

! expose all routines in Mod1
use Mod1
! only expose fred in Mod2
use Mod2, ONLY: fred
! Output only accessible by local name Dump
! all other routines are exposed
use Mod3, Dump=>Output
 
Thanks,

getting old as a cow, but still there is something to learn...

Norbert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top