Oli,
Your adv_x is effectively designed, as you say, to do its
work in-place when the arguments are aliased (were it legal).
When they aren't aliased, adv_x has the additional behavior
of "moving" the input array data into the output array data.
I'd suggest just defining adv_x as it is intended:
subroutine adv_x (phi)
real, intent(inout) :: phi(:,:,:) ! phiold on entry, phinew on exit
Then let the caller explicitly handle the "copy" when you
wish to retain the input array data:
subroutine adv_xyz (phinew, phiold)
real, intent(in) :: phiold(:,:,:)
real, intent(out) :: phinew(:,:,:)
phinew = phiold
call adv_x(phinew)
call adv_y(phinew)
call adv_z(phinew)
end subroutine
I'm assuming here that you don't desire to alias phinew and
phiold. You don't say exactly how adv_xyz and adv_zyx are
used, but I suspect that you should even move the "copy"
up to their caller and make adv_xyz do its work in-place too
with a single intent(inout) argument.
As far as your thought to use pointers in adv_x, I would
strongly discourage that for a number of reasons I won't go
into. That aside, I doubt that approach could really make
the code standard conforming, though I haven't examined the
standard to see -- aliasing of changeable data is a
disaster waiting to happen.
Cheers,
Neil
--
Neil Carlson
Computational Physics and Methods (CCS-2)
Los Alamos National Laboratory
PO Box 1663, MS D413 · Los Alamos, NM 87545
505.665.6386 · 505.665.4972 (fax)
|