Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28632 Discussions

Referencing to array pointers in fortran

jdbaba
Beginner
342 Views

I have acquired the big fortran code and I am trying to refer to the array and output the array values. I can't output the results properly. 

For example an array of two dimensions array1(:,:) is referred by a pointer as follows: 

intereger(pntrsize) , pointer: dps 

Now, I want to print out the values of array1(2,3) but I don't know how to print that value using pointers. Can anyone give any suggestions on using pointers properly in fortran ? Everytime I try to tweak things, I always get zero values. 

0 Kudos
1 Reply
mecej4
Honored Contributor III
342 Views

Why do you wish to use pointers? Could you accomplish your task without them? You can output array values by using the array name, suitably subscripted, in a WRITE statement. Why is doing this not adequate?

program xuseptr
implicit none
integer :: x(2,3),i,j

do i=1,2; do j=1,3; x(i,j)=i+j
end do; end do

call parray(x)

contains
subroutine parray(x)
implicit none
integer, dimension(:,:),target :: x
integer, pointer, dimension(:,:) :: p

p=>x
write(*,10)(p(i,1),i=1,ubound(x,1))
10 format(2x,2I8)
end subroutine
end program

 

0 Kudos
Reply