Re: operation on module arguments

gottoomanyaccounts@xxxxxxxxx wrote:
Richard E Maine wrote:
I actually thought of that kind of thing (which I see that Brooks
mentioned also), but decided not to "go there". Somehow, I suspect that
if the OP didn't want the extra bother of manually updating c when
needed... well... I didn't want to be responsible for the medical
problems likely to result when he saw what this trick would take. :-(

Actually, before I posted the question, I was reading Fortran 90/95
Explained, Ch5.5. One of examples is show the interface operation
operating a derived type, but, well, I didn't quite get it. I will be
happy to know any method that enables me get rid of manual updating. I
will try my best to stay cool. -_-

Another option, incidentally, is something like this:

module foo
implicit none
real :: c
real, private :: a, b
real function geta()
geta = a
end function
real function getb()
getb = b
end function
real subroutine seta(a_in)
real a_in
a = a_in
end function
real subroutine setb(b_in)
real b_in
b = b_in
end function
end module

program main
use foo
implicit none
call seta(1.0)
call setb(9.0)
write(*,*) c
end program

This ensures that c gets updated every time a and b are updated, by requiring that only the seta and setb subroutines can be used to update a and b.

- Brooks

The "bmoses-nospam" address is valid; no unmunging needed.