|
|
Up |
|
|
  |
Author: ralf.schaaralf.schaa Date: Sep 12, 2008 01:06
Dear experts,
is the following where-construct allowed ?
real, dimension(045) :: A
real, dimension(100) :: B
! fill A with numbers - invalid numbers are indicated by -9999.
! now fill B
where( A /= -9999. )
B = A
else where
B = -9999.
end where
For this construct it is always Size(B) > Size(A) with shown
dimensions.
The Absoft Compiler does not complain (v9.0)
Thanks
-Ralf
|
| |
|
| | 9 Comments |
|
  |
Author: Arjen MarkusArjen Markus Date: Sep 12, 2008 01:40
On 12 sep, 10:06, "ralf.schaa" gmail.com> wrote:
> Dear experts,
> is the following where-construct allowed ?
>
> real, dimension(045) :: A
> real, dimension(100) :: B
>
> ! fill A with numbers - invalid numbers are indicated by -9999.
>
> ! now fill B
> where( A /= -9999. )
> B = A
> else where
> B = -9999.
> end where
>
> For this construct it is always Size(B) > Size(A) with shown
> dimensions.
>
> The Absoft Compiler does not complain (v9.0) ...
|
| Show full article (0.67Kb) |
|
| | no comments |
|
  |
Author: ralf.schaaralf.schaa Date: Sep 12, 2008 01:45
On Sep 12, 7:06 pm, "ralf.schaa" gmail.com> wrote:
[snip]
> The Absoft Compiler does not complain (v9.0)
and an update from Gfortran 4.3.1 and CVF 6.6C: both complain about
the different array sizes
|
| |
| no comments |
|
  |
Author: ralf.schaaralf.schaa Date: Sep 12, 2008 01:48
On Sep 12, 7:40 pm, Arjen Markus wrote:
> On 12 sep, 10:06, "ralf.schaa" gmail.com> wrote:
[snip]
> I do not think so. What happens if you turn on array bound checking?
> (gfortran refuses to compile it, by the way, clearly indicating
> the problem)
yeah, I tested it just a minute ago ...
thanks Arjen - I give up the where-construct. It's a pity since it is
fancy and short ...
-Ralf
|
| |
| no comments |
|
  |
Author: YuraYura Date: Sep 12, 2008 06:09
program test
implicit none
INTEGER n
real, dimension(045) :: A
real, dimension(100) :: B
|
| Show full article (0.40Kb) |
| no comments |
|
  |
Author: nospamnospam Date: Sep 12, 2008 08:34
ralf.schaa gmail.com> wrote:
> is the following where-construct allowed ?
[where with non-conformable arrays]
> The Absoft Compiler does not complain (v9.0)
While the answer was implied by other replies, nobody explicitly
answered this from a standard perspective other than for Arjen's "I do
not think so."
I'll verify Arjen's answer. No, it is not allowed. (And it wouldn't be
consistent to allow it any more than lots of other whole array things
with nonconformable arrays; one could imagine definitions that used just
part of the arrays in some cases, but that's not how the language does
it anywhere.)
It isn't the kind of error that compilers are required to catch, but of
course, doing so where practical is a desirable feature in a compiler.
--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
|
| |
| no comments |
|
  |
Author: DanDan Date: Sep 12, 2008 17:48
You can still use the WHERE statement to do what you want cleanly and
simply (2 short lines).
! Fill all elements of B() with invalid numbers
! Then reset values in B() that correspond to valid elements in A()
B = -9999.
WHERE( A /= -9999. ) B(1:size(A)) = A
Dan
|
| |
| no comments |
|
  |
Author: michaelmetcalfmichaelmetcalf Date: Sep 12, 2008 23:55
On Sep 13, 2:48 am, Dan aol.com> wrote:
> You can still use the WHERE statement to do what you want cleanly and
> simply (2 short lines).
>
> ! Fill all elements of B() with invalid numbers
> ! Then reset values in B() that correspond to valid elements in A()
>
> B = -9999.
> WHERE( A /= -9999. ) B(1:size(A)) = A
>
> Dan
And ineffiently: many elements of B will be set twice. That's what the
elsewhere clause is for.
Regards,
Mike Metcalf
|
| |
| no comments |
|
  |
Author: Kurt KallbladKurt Kallblad Date: Sep 13, 2008 03:50
> You can still use the WHERE statement to do what you want
> cleanly and
> simply (2 short lines).
>
> ! Fill all elements of B() with invalid numbers
> ! Then reset values in B() that correspond to valid elements in
> A()
>
> B = -9999.
> WHERE( A /= -9999. ) B(1:size(A)) = A
>
> Dan
Way use where at all?
B(1:min(size(A),size(B))) = A(1:min(size(A),size(B)))
B(size(A)+1:)= -9999.
will do the work even if size(A) > size(B).
For the OP's dimensions its enough with:
|
| Show full article (0.66Kb) |
| no comments |
|
  |
|
|
  |
Author: glen herrmannsfeldtglen herrmannsfeldt Date: Sep 13, 2008 05:10
> On Sep 13, 2:48 am, Dan aol.com> wrote:
>> B = -9999.
>> WHERE( A /= -9999. ) B(1:size(A)) = A
> And ineffiently: many elements of B will be set twice.
> That's what the elsewhere clause is for.
It is hard to make generalizations on efficiency, but
it is likely that testing a value is slower than
assigning a value. One possible exception would be
avoiding the write to the swap file if you are
thrashing virtual storage. There are better fixes
in that case, though.
-- glen
|
| |
| no comments |
|
RELATED THREADS |
  |
|
|
|