It may compile with no error message, but did you actually run it?
I tried with gfortran and ifort. Both compile with no error message, but
both give segmentation faults when you run the program. Bill Long has told
you why.
An easy change to the program makes actually writing the interface block
unnecessary:
program test
real, target :: a(3,4,5), b(3,4)
real, pointer :: p(:,:,:)
ForAll (i=1:3, j=1:4, k=1:5) a(i,j,k) = i*100 + j*10 + k
ForAll (i=1:3, j=1:4 ) b(i,j ) = i*10 + j
print *, a(2, 3, 1)
call get_ptr(p,a,3,4,5)
print *, p(2, 3, 1)
print *, b(2, 3 )
call get_ptr(p,b,3,4,1)
print *, p(2, 3, 1)
contains
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
end program test
Cheers, Wes
On Fri, 13 Apr 2012, Bill Long wrote:
> 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
Dr. W. J. Metzger Experimental High Energy Physics Group
tel. +31-24-3653127 Faculty of Science
+31-24-3652099 (secr.) Radboud University Nijmegen
fax. +31-24-3652191 Heyendaalseweg 135
6525 AJ Nijmegen, The Netherlands
e-mail: [log in to unmask] or [log in to unmask]
http://home.cern.ch/metzger/ or http://www.hef.ru.nl/~wes
|