Dick Hendrickson writes:
> A sometimes better way to handle optional arguments is to copy them in.
> Depending on the size of MASK, and how often it's used, and how much
> execution speed matters, and .... Something like
>
> > > SUBROUTINE S(........, MASK,...)
> > > LOGICAL, OPTIONAL, DIMENSION(:) :: MASK
> LOGICAL, DIMENSION(Size(MASK)) :: local_MASK
> local_MASK = .TRUE.
> > > IF(PRESENT(MASK)) local_MASK = MASK
>
> > > FORALL(..., local_MASK) ....
>
> might be easier to follow.
Indeed, that is such a common paradigm (used for all kinds of things)
that I personally would like to see something like it as a feature in
a future version of the standard. Basically, I'd like some property
of a dummy argument to say that the actual argument is optional, but
if the actual argument is omitted, make a temporary local for the
dummy. There are some details to address, when the time comes.
One of those details, by the way, is related to a bug in the above
snippet. You might need to address issues like array shapes for cases
where the actual is omitted. In the above snippet, the dimension
declaration for local_mask is illegal if mask is not present.
I'd have to check the exact wording of the standard to see whether
the above code is ilegal on its face or just if S is invoked with
mask not present, but since the whole point is to be able to invoke
it with mask not present, that detail is somewhat irrelevant.
--
Richard Maine | Good judgment comes from experience;
[log in to unmask] | experience comes from bad judgment.
| -- Mark Twain
|