where and nonconformable arrays  Fortran
This is a discussion on where and nonconformable arrays  Fortran ; Dear experts,
is the following whereconstruct 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
...

where and nonconformable arrays
Dear experts,
is the following whereconstruct 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

Re: where and nonconformable arrays
On 12 sep, 10:06, "ralf.schaa" <Ralf.Sc...@gmail.com> wrote:
> Dear experts,
> is the following whereconstruct 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
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)
Regards,
Arjen

Re: where and nonconformable arrays
On Sep 12, 7:06 pm, "ralf.schaa" <Ralf.Sc...@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

Re: where and nonconformable arrays
On Sep 12, 7:40 pm, Arjen Markus <arjen.mar...@wldelft.nl> wrote:
> On 12 sep, 10:06, "ralf.schaa" <Ralf.Sc...@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 whereconstruct. It's a pity since it is
fancy and short ...
Ralf

Re: where and nonconformable arrays
program test
implicit none
INTEGER n
real, dimension(045) :: A
real, dimension(100) :: B
print *, 'Hello World'
! fill A with numbers  invalid numbers are indicated by 9999.
do n=1,45
A(n) = n
enddo
A(5) = 9999.
! now fill B
B = 9999.
where( A /= 9999. )
B(1:45) = A
elsewhere
B(1:45) = 9999.
end where
do n=1,100
print *, n, ',', B(n)
enddo
end program test

Re: where and nonconformable arrays
ralf.schaa <Ralf.Schaa@gmail.com> wrote:
> is the following whereconstruct allowed ?
[where with nonconformable 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

Re: where and nonconformable arrays
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

Re: where and nonconformable arrays
On Sep 13, 2:48 am, Dan <dant...@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


Re: where and nonconformable arrays
michaelmetcalf@compuserve.com wrote:
> On Sep 13, 2:48 am, Dan <dant...@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