Re: operation on module arguments
- From: Brooks Moses <bmoses-nospam@xxxxxxxxxxxxxxxxxx>
- Date: Thu, 21 Sep 2006 14:36:57 -0700
gottoomanyaccounts@xxxxxxxxx wrote:
I have a question about how I can update the variables declared on a
module by simply having the USE statement only. To illustrate, for
example
file foo.f90
--------------
module foo
implicite none
real :: a, b, c
**** (anything I need here to make c=a+b)
end module foo
=========================
file main.f90
----------------
program main
use foo
implicit none
a= 1.0
b= 9.0
write(*,*) c
end program
=========================
The point is, I want c always to be the sum of a and b. In the main
program, a and b may be read in from an external file, (in the example
above, they get explicitly set.) What I want is, when a and b get
changed, c is automatically updated, I don't have to call another
subgrogram to update c. All I would like to have is just the 'use foo'
statement in the main program.
module foo
implicit none
real :: a, b
contains
real function c()
c = a + b
end function
end module
program main
use foo
implicit none
a = 1.0
b = 9.0
write(*,*) c()
end program
Alternately, you could make a and b some sort of special user-defined type, and define an assignment operator for that type that also updates c when a value is assigned to a or b. However, this doesn't work if a and b are directly read in via a read statement.
- Brooks
--
The "bmoses-nospam" address is valid; no unmunging needed.
.
- References:
- operation on module arguments
- From: gottoomanyaccounts
- operation on module arguments
- Prev by Date: Re: operation on module arguments
- Next by Date: Re: operation on module arguments
- Previous by thread: Re: operation on module arguments
- Next by thread: Re: operation on module arguments
- Index(es):
Relevant Pages
|