On 4/13/12 2:52 AM, Oliver Fuhrer wrote:
> Dear all,
>
> Thanks for all your replies! I think I found another solution to problem. I am by no means a Fortran standards expert, but it seems to run with PGI, Cray and GNU compilers...
>
> subroutine get_ptr(p,var,nx,ny,nz)
> real, pointer :: p(:,:,:)
> integer :: nx,ny,nz
> real, target :: var(nx,ny,nz)
> p => var
> end subroutine get_ptr
>
> program test
> real, target :: a(3,4,5), b(3,4)
> real, pointer :: p(:,:,:)
> call get_ptr(p,a,3,4,5)
> call get_ptr(p,b,3,4,1)
> end program test
>
> Any comments are appreciated!
>
The method of effectively changing the rank of an explicit-shape array
through argument association (element sequence association) has been
standard for many decades, and is an effective technique.
The program shown above does have a problem, though. An interface for
get_ptr is required in the main program because it has dummy arguments
with the POINTER and TARGET attributes. Indeed, the Cray compiler
complains (when test and get_ptr are in the same file):
> ftn of.f90
call get_ptr(p,a,3,4,5)
^
ftn-954 crayftn: ERROR TEST, File = of.f90, Line = 11, Column = 1
Procedure "GET_PTR", defined at line 1 (of.f90) must have an explicit
interface because one or more arguments have the TARGET attribute.
call get_ptr(p,b,3,4,1)
^
ftn-954 crayftn: ERROR TEST, File = of.f90, Line = 12, Column = 1
Procedure "GET_PTR", defined at line 1 (of.f90) must have an explicit
interface because one or more arguments have the TARGET attribute.
PGi didn't complain, but that is permitted since compilers are not
required to diagnose this error.
Cheers,
Bill
> Cheers,
> Oli
>
>
>> -----Original Message-----
>> From: Fortran 90 List [mailto:[log in to unmask]] On
>> Behalf Of Malcolm Cohen
>> Sent: Donnerstag, 12. April 2012 06:17
>> To: [log in to unmask]
>> Subject: Re: 3d pointer to 2d target
>>
>> I wrote:
>>> Well then, you could do it the other way around:
>>> Real,Target :: p(30,40,1)
>>> Real,Pointer :: a(:,:)
>>> a => a3(:,:,1)
>>
>> That last line should have been
>> a=>p(:,:,1)
>>
>>> Or if sometimes you want p to point to a, and sometimes to something else
>>>
>>> Real,Target :: a3(30,40,1)
>>> Real,Pointer :: a(:,:),p(:,:,:)
>>> a => a3(:,:,1)
>>> p => a3
>>
>> Cheers,
>> --
>> ................................Malcolm Cohen, Nihon NAG, Tokyo.
--
Bill Long [log in to unmask]
Fortran Technical Support & voice: 651-605-9024
Bioinformatics Software Development fax: 651-605-9142
Cray Inc./Cray Plaza, Suite 210/380 Jackson St./St. Paul, MN 55101
|