Re: Pointer-valued function to access inner components
- From: Walter Spector <w6ws_xthisoutx@xxxxxxxxxxxxx>
- Date: Sat, 17 Feb 2007 04:56:44 GMT
Michael Metcalf wrote:
"Walter Spector" <w6ws_xthisoutx@xxxxxxxxxxxxx> wrote in message
news:45D5C9C7.41820D64@xxxxxxxxxxxxxxxx
No, that points to a *copy* of the diagonal.Agreed. Is this then what you meant (following Richard's hint)?
common/c/a...
Well, placing things in COMMON doesn't make them very dynamic.
But that is certainly one approach.
I was thinking more of the following:
program testdiag
implicit none
real, allocatable, target :: a(:,:)
real, pointer :: adiag(:)
integer :: i, j
integer :: n
write (*,'(a)', advance='no') 'size of matrix? '
read *, n
allocate (a(n,n))
a = 0
print *, 'A before:'
do, j=1, size (a,1)
write (*,'(100f5.2)') (a(j,i), i=1, size (a,2))
end do
adiag => getdiag (a, size (a,1))
adiag = 42.42
print *
print *, 'A after:'
do, j=1, size (a,1)
write (*,'(100f6.2)') (a(j,i), i=1, size (a,2))
end do
contains
function getdiag (t, tn)
! Return a F90 pointer which points to the diagonal of T.
integer, intent(in) :: tn
real, target :: t(tn+1,*)
real, pointer :: getdiag(:)
getdiag => t(1,:tn)
end function
end program
The above works fine, in practice, with a lot of different
compilers. I've used it with Intel, SGI IRIX, g95, gfortran,
and Salford compilers. However, it might be argued that it violates
the letter of the Standard... So one must be careful not to use it
in a situation where the compiler will potentially perform
a copyin/copyout on array A during the procedure call.
When copyin/copyout does get in the way, Cray pointers can come in
handy. Or, I presume, some of the new F2003 intrinsics. Time
will tell.
W.
.
- Follow-Ups:
- Re: Pointer-valued function to access inner components
- From: Ron Shepard
- Re: Pointer-valued function to access inner components
- From: highegg
- Re: Pointer-valued function to access inner components
- References:
- Pointer-valued function to access inner components
- From: Salvatore
- Re: Pointer-valued function to access inner components
- From: Richard Maine
- Re: Pointer-valued function to access inner components
- From: Salvatore
- Re: Pointer-valued function to access inner components
- From: glen herrmannsfeldt
- Re: Pointer-valued function to access inner components
- From: Walter Spector
- Re: Pointer-valued function to access inner components
- From: Michael Metcalf
- Re: Pointer-valued function to access inner components
- From: Walter Spector
- Re: Pointer-valued function to access inner components
- From: Michael Metcalf
- Pointer-valued function to access inner components
- Prev by Date: Re: uniform distribution with a random dimension usign IMSL
- Next by Date: Re: Pointer-valued function to access inner components
- Previous by thread: Re: Pointer-valued function to access inner components
- Next by thread: Re: Pointer-valued function to access inner components
- Index(es):
Relevant Pages
|
|