On Mar 14, 2005, at 5:28 AM, Alexei Matveev wrote:
>> WHERE(A /= 0.0) B = 1.0 / A
>>
>> It is also equivalent to:
>>
>> FORALL (I = 1:N, J = 1:N)
>> WHERE(A(I, J) .NE. 0.0) B(I, J) = 1.0/A(I, J)
>> END FORALL
> Is such usage of WHERE (specifying array coordinates)
> legal in f95?
No. And it makes little sense. WHERE is an array assignment. You have
no arrays in the WHERE inside the FORALL above. Note that, although A
is an array, A(I,J) is not. You want just the plain WHERE, as shown
before the FORALL. The FORALL isn't doing anything for you here other
than confusing things. WHERE is already an array form, you don't need
a FORALL wrapped around it; in fact, that is counterproductive (and
makes the WHERE illegal in this case).
> forall(ir=1:vl, ie=1:n_exps)
> where(rad0(ir,ie)<50.0_r8_kind) ! ****** HERE ******
> rad0(ir,ie) = norms(ie) * exp( - rad0(ir,ie) )
> elsewhere
> rad0(ir,ie) = 0.0_r8_kind
> endwhere
> end forall
Ok. Here you have a different issue because of the reference to norms,
which isn't the same rank as rad. I think you could do this as shown
below (untested). Note that the FORALL just applies to 1 dimension,
leaving the WHERE to the other; in this case, the mask expression in
the where is still an array (of rank 1).
forall(ie=1:n_exps)
where(rad0(:,ie)<50.0_r8_kind) ! ****** HERE ******
rad0(:,ie) = norms(ie) * exp( - rad0(:,ie) )
elsewhere
rad0(:,ie) = 0.0_r8_kind
endwhere
end forall
I'd probably just do the whole thing with DO loops. I doubt that you
will see any actual benefit from using WHERE and FORALL. You might
well see the version with FORALL being slower; that seems to be common
experience with FORALL.
--
Richard Maine | Good judgment comes from experience;
[log in to unmask] | experience comes from bad judgment.
| -- Mark Twain
|