Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

short size for transfer

3 views
Skip to first unread message

Thomas Koenig

unread,
Mar 26, 2006, 2:59:36 PM3/26/06
to
Is the following program standard-conforming and should it print
anything (assuming that 1.0*8.0 yields 8.0)?

program main
complex :: z
real, dimension(2) :: cmp
z = (1.0, 2.0)
cmp = 4.0
cmp = transfer(z, cmp, 1) * 8.0
if (cmp(1) .ne. 8.0 .or. cmp(2) .ne. 4.0) print *,"unequal"
end program main

I suspect it isn't standard-conforming, because the size is too short
for cmp, but I'd like to be sure.

Richard Maine

unread,
Mar 26, 2006, 5:18:36 PM3/26/06
to
Thomas Koenig <Thomas...@online.de> wrote:

> Is the following program standard-conforming...


>
> program main
> complex :: z
> real, dimension(2) :: cmp
> z = (1.0, 2.0)
> cmp = 4.0
> cmp = transfer(z, cmp, 1) * 8.0
> if (cmp(1) .ne. 8.0 .or. cmp(2) .ne. 4.0) print *,"unequal"
> end program main
>
> I suspect it isn't standard-conforming, because the size is too short
> for cmp, but I'd like to be sure.

It is not conforming (and this anything may happen). I guess I'm
surprised that you aren't sure. I suspect that the complications of
TRANSFER are just distracting you from the simple part, which you did
mention. The details of the exact value of the TRANFER result don't
matter; all you need to know, as you allude to, is that the result is a
rank 1 array of size 1. So the question reduces to one of whether

cmp = x

is valid when cmp is an array of size 2 and x is an array of size 1. It
isn't. Shape must match in arra-to-array assignments. Why would you even
think otherwise? Are you perhaps thinking about the fact that

cmp = 4.0

is valid with 4.0 being scalar? If so, it is important to remember that
an array of size 1 is *NOT* the same thing as a scalar.

--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain

John Harper

unread,
Mar 26, 2006, 8:31:56 PM3/26/06
to
In article <1hct8ra.19xbqs41kr1ym4N%nos...@see.signature>,

Richard Maine <nos...@see.signature> wrote:
>Thomas Koenig <Thomas...@online.de> wrote:
>
>> Is the following program standard-conforming...
>>
>> program main
>> complex :: z
>> real, dimension(2) :: cmp
>> z = (1.0, 2.0)
>> cmp = 4.0
>> cmp = transfer(z, cmp, 1) * 8.0
>> if (cmp(1) .ne. 8.0 .or. cmp(2) .ne. 4.0) print *,"unequal"
>> end program main
>>
>> I suspect it isn't standard-conforming, because the size is too short
>> for cmp, but I'd like to be sure.
>
>It is not conforming (and this anything may happen).

A minor change that makes it standard-conforming is in line 6:
cmp(1:1) = transfer(z, cmp, 1) * 8.0
and then it prints nothing.
--
John Harper, School of Mathematics, Statistics and Computer Science,
Victoria University, PO Box 600, Wellington, New Zealand
e-mail john....@vuw.ac.nz phone (+64)(4)463 5341 fax (+64)(4)463 5045

0 new messages