import selected module variables within that module's procedures

import selected module variables within that module's procedures

Post by beliavsk » Wed, 01 Nov 2006 07:24:40


I wish there were a way to import only a few module variables, derived
types, and procedures into a procedure of the module, for example

module foo_mod
integer :: i,j
contains
subroutine sub()
use foo_mod, only: i ! NOT a legal Fortran 95 statement
end subroutine sub
end module foo_mod

but one cannot write "use foo_mod" within module foo_mod. Is there a
way to get this effect in Fortran 95? Fortran 2003? Could the
"submodule" of TR 19767 accomplish this?
 
 
 

import selected module variables within that module's procedures

Post by higheg » Wed, 01 Nov 2006 17:59:29


you can simply modularize more:

module foo_mod_h
integer:: i,j
end module

module foo_mod_sub
contains
subroutine sub()
use foo_mod_h,only: i
end subroutine
end module

module foo_mod
use foo_mod_h
use foo_mod_sub
end module

another alternative, is making all the subroutines external,
let them USE the module and provide interfaces within the module.
This approach requires extracting and updating of interfaces
appropriately (similar to C headers, but other module advantages
remain).

 
 
 

import selected module variables within that module's procedures

Post by dpb » Thu, 02 Nov 2006 04:58:58


...

...snip sample code...

That works and is a good alternative..


I recommend against this as an alternative. It loses one of the prime
advantages for modules, namely the automagic generation of explicit
interfaces which are required in some instances and desirable in all
(and the subject of many questions here). It inserts a labor-intensive
process which is also error-prone and makes the maintenance of these
new pieces of (unecessary) code a continuing burden...
 
 
 

import selected module variables within that module's procedures

Post by Craig Powe » Thu, 02 Nov 2006 05:26:40


Isn't this something along the lines of the proposed control of host
association that has been suggested previously in this group?
 
 
 

import selected module variables within that module's procedures

Post by Dan Nagl » Thu, 02 Nov 2006 06:41:30

Hello,




<snip>


True. But see Michel Olagnon's f90aib available via
http://www.yqcomputer.com/

--
Cheers!

Dan Nagle
Purple Sage Computing Solutions, Inc.