PDA

View Full Version : [LF] Circular usage of module


Lahey Support
08-15-2003, 01:33 AM
I have a large program with about 25 modules (object oriented), in which there
is a circular usage. Module1 needs stuff in Module2, and Module2 needs stuff in
Module1.

I think there are 2 solutions:

- Joint Module1 and Module2 into Module1and2.
- Call from Module1 an external function that access Module2 data and services,
that breaks the module dependance of 1 to 2.

The 1st solution is hard to implement. I have many redumdant or similar private
definitions and services (I need inheritance...)

So there is the second... I have create an external function
(GetStuffFromModule2), called by Module1. The large program is not working
currently (not because of this problem), so I have test this solution with a
very simplyfied example:

(begin of file)

module Module1
implicit none
interface
function GetStuffFromModule2(Arg1)
implicit none
real, intent(in) :: Arg1
real :: GetStuffFromModule2
end function GetStuffFromModule2
end interface
contains
function Module1Function(Argument)
real, intent(in) :: Argument
real :: Module1Function
Module1Function = sqrt(GetStuffFromModule2(Argument))
return
end function Module1Function
end module

module Module2
use Module1
implicit none
real, save :: LocalSaved
contains
function Module2Function(Arg1,Arg2)
real, intent(in) :: Arg1,Arg2
real :: Module2Function
LocalSaved = Arg2
Module2Function = Module1Function(Arg1)
return
end function Module2Function
end module

function GetStuffFromModule2(Arg1)
use Module2
implicit none
real, intent(in) :: Arg1
real :: GetStuffFromModule2
GetFromModule2 = Arg1 + LocalSaved * 2.
end function GetStuffFromModule2

program test
use Module2
implicit none
print *, Module2Function(4.,3.1416)
stop
end

(end of file)

The program works. The answer is 3.2067...

In the interface to GetStuffFromModule2, I have omit the line "use Module2" from
the real function definition. In a large scale program, may I have a problem
(memory corruption, underflow, ....) because of the omission?


Sylvain Bergeron
Senior consultant
Groupe-conseil Aon
Phone: (514) 288-7575 ext: 4323
Fax: (514) 845-0678


----------------------------------------------------------
To unsubscribe, send to [address removed] the following
as the first and only line of the message body:
unsubscribe fortran
----------------------------------------------------------