Roland Schilling wrote:
>
> On Thu, 6 Mar 2003, Michael Metcalf wrote:
>
> > If you want an optional mask, and you don't have too many FORALL statements,
> > then you can always use a structure like:
> >
> > SUBROUTINE S(........, MASK,...)
> > LOGICAL, OPTIONAL, DIMENSION(:) :: MASK
> > :
> > IF(PRESENT(MASK)) THEN
> > FORALL(..., MASK) ....
> > ELSE
> > FORALL(...) ...
> > END IF
>
> That's exactly what I'm doing. When first writing down this I stumbled
> across the points in question. My interest was mainly academic.
>
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.
You only need to "fix" your subroutine in one place; but at the cost
of exectuing "complicated" FORALLs everywhere.
I think the reason for the prohibition is "regularity". The mask
thingo in a FORALL can be any expression and it's hard to write rules
that say "it's OK for some expressions to have a non-present optional
argument if the expression is only a single term". It's hard to
remember and the "obvious" question is "well then, why doesn't
MASK .OR. SOMETHING_ELSE simply revert to SOMETHING_ELSE if MASK
isn't PRESENT?" Gotta draw a line somewhere. At least, that's
my opinion.
Dick Hendrickson
> Regards,
> Roland
>
> +----------------------------------------------------------------------+
> | Roland Schilling Home-Office: +49(89)32929-670 |
> | Max-Planck-Institut für Gravitationsphysik Phone: +49(89)32905-265 |
> | -- Albert-Einsten-Institut -- Fax: +49(89)32905-200 |
> | D-85748 Garching E-mail: [log in to unmask] |
> | Germany http://www.geo600.uni-hannover.de |
> +----------------------------------------------------------------------+
|