Re: operation on module arguments




dpb wrote:
gottoomanyaccounts@xxxxxxxxx wrote:
Hi there,

I have a question about how I can update the variables declared on a
module by simply having the USE statement only....

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.
...

As Richard points out, there's no functionality like that in Fortran so
you can't achieve the stated object w/o adding something else to the
code. But, you can certainly add the necessary code to be executed at
each point in the program where either a or b or both are modified. In
your example, if there is a READ statement that includes either, then
after that and before c is referenced elsewhere simply include the
statement
c = a + b and that will accomplish the task.

This is what I originally thought and indeed the motivation I posted
this question. Since a , b , and c are defined together in one module,
when any of them gets modified (by whatever method) in the main
program, others should be able to updated automatically, by this way, I
kind of think the module is self-defined. If I have to impose the
update manually, the concept of module gets a little bit less elegant
(this is only my own opinion, may not make sense to any one here :)).

Of course, this requires that you do have to be sure to find every
place where either can be or are modified either by a direct assignment
or from an indirect use (such as a side effect of a subroutine if used
as an argument or as affected by being in COMMON or similar). And, of
course, it also means c has to be verified to not have any operations
carried out on it other than these.

One would assume that if the objective is as stated, these wouldn't be
terribly difficult constraints, but they do have to be imposed manually.

.