For Programmers: Free Programming Magazines  


Home > Archive > Fortran > March 2006 > short size for transfer









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author short size for transfer
Thomas Koenig

2006-03-26, 7:01 pm

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

2006-03-26, 7:01 pm

Thomas Koenig <Thomas.Koenig@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

2006-03-26, 10:00 pm

In article <1hct8ra.19xbqs41kr1ym4N%nospam@see.signature>,
Richard Maine <nospam@see.signature> wrote:
>Thomas Koenig <Thomas.Koenig@online.de> wrote:
>
>
>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.harper@vuw.ac.nz phone (+64)(4)463 5341 fax (+64)(4)463 5045
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com