@garynewport doesn’t show all the ways in which element
and individual element variables e.g., hydrogen
are used in the code.
Chances are high the code is setup to load some data into the rank-2 array for element
and the purpose of equivalence is as an alias to the values.
If so, an even braver option, one that will be “kosher” with respect to current Fortran standard, might just be to employ the TARGET
and POINTER
attributes. And apply the PROTECTED
to the aliases i.e., the objects with the POINTER attribute in order to some guard against the pitfalls of working with POINTER
s in the code.
That is, what is currently
module helium
use stellar_values, only: me, mh, mj
real, save :: element(mj, me), velement(mj, me)
real, save :: hydrogen(mj), vhydrogen(mj)
..
Equivalence (hydrogen, element(1,1))
..
Equivalence (vhydrogen, velement(1,1))
can instead be as follows:
module helium
use stellar_values, only: me, mh, mj
real, target, save :: element(mj, me), velement(mj, me)
real, pointer, save, protected :: hydrogen(:) => element(:,1)
real, pointer, save, protected :: vhydrogen(:) => velement(:,1)
..
At the point of use in the rest of OP’s code with objects such as hydrogen
and vhydrogen
, etc., no change be needed.
An advantage with working with TARGET
↔ POINTER
paired attributes as a use case for aliases is type safety besides the fact it is in line with the use case that led to the introduction of the facility in Fortran 90 revision circa 1991.