I ran this program on an SGI using the NAG F95 compiler Release 4.0. I
added a print *, "Entered RES1" statement in RES1 and a print *, "Entered
RES2" statement in RES2 just to confirm that RES is working properly. The
answer that I got for P1 was 11 21 31 41 12 22 32 42 13 23 33 43 14 24 34
44 and got the same answer for P2. These are the answers that I would have
expected.
Jack Hatfield
At 6/6/00 06:57 PM, Van Snyder wrote:
>
>I've tried the following program with two compilers. I think they both
>get the "wrong" answers for P1 and P2. Neither one reports an error at
>compile- or run-time. I've reported to the vendors.
>
>Maybe it's my mistake.
>
>I think P1 should be
> 11 12 13 14 21 22 23 24 31 32 33 34 41 42 43 44
>and P2 should be
> 1 5 9 13
> 2 6 10 14
> 3 7 11 15
> 4 8 12 16
>
>1. What do you think the "right" answers are for P1 and P2?
>2. Do you have a compiler that does what you (or I) expect?
>
>Best regards,
>Van Snyder
>==========================================================================
>module RESHAPERS
> interface RES
> module procedure RES1, RES2
> end interface
>contains
> function RES1 ( R1 )
> integer, pointer :: RES1(:)
> integer, target :: R1(:)
> res1 => r1
> end function RES1
> function RES2 ( R2 )
> integer, pointer :: RES2(:,:)
> integer, target :: R2(:,:)
> res2 => r2
> end function RES2
>end module RESHAPERS
>
>program TEST
> use RESHAPERS
> integer, pointer :: P1(:)
> integer, pointer :: P2(:,:)
>
> integer, target :: T1(16) = (/ (i,i=1,16) /)
> integer, target :: T2(4,4) = reshape( (/ ((10*i+j,i=1,4),j=1,4) /),
(/4,4/) )
>
> p1 => res(reshape(t2,(/16/)))
> p2 => res(reshape(t1,(/4,4/)))
>
> print *, 'T1 ='
> print '(16i3)', t1
> print *, 'T2 ='
> print '(4i3)', (t2(i,:),i=1,4)
> print *, 'P1 => res(reshape(t2,(/16/))) ='
> print '(16i3)', p1
> print *, 'P2 => res(reshape(t1,(/4,4/))) ='
> print '(4i3)', (p2(i,:),i=1,4)
> print *, 'SHAPE(P1) =', shape(p1)
> print *, 'SHAPE(P2) =', shape(p2)
>end program TEST
>
-------------------------------------------------------
Jack Hatfield
Sr. Software Engineer
Mission Analysis Software Team
Jet Propulsion Laboratory
4800 Oak Grove Dr
MS 301-140L
Pasadena, CA 91109-8099
Office: 301-140R
Email: [log in to unmask]
Phone: 818-354-2198
Fax: 818-393-9900
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|