What am I doing wrong? Passing pointers to subroutines.
- From: mrkkbb_007@xxxxxxxxxxx
- Date: 4 Oct 2005 09:35:21 -0700
I get different answers when I compare the results of the following F90
codes shown below. In short the subroutine SUB1, generates a block of
a matrix given row and column location. SUB1 uses a row-major
representation of the block matrix; I do not want to rewrite SUB1.
SUB1 generates the same block matrix within but when I print this block
outside in the main routine CODE1, it is different from CODE2. As far
as I know, I do take into account row-major vs. column-major by doing
the transpose in CODE1, but just to make sure I compared the resulting
blocks by sorting them, the numbers are different! I'm at a loss, I
even tried getting rid off the pointer in CODE1, and passing the matrix
directly, but I get the same as with a pointer. There must be
something I am missing here.
Thanks all,
==================================== CODE1 ===========
<< snip >>
double precision, pointer, dimension(:,:) :: pA
double precision, allocatable, target, dimension(:,:) :: A
allocate ...
A = 0.0d0
<< snip >>
DO ...
nr = er-sr+1
nc = ec-sc+1
pA => A(sr:er, sc:ec)
! Call subroutine to generate section of A
call sub1(pA, sr, er, sc, ec, nr, nc )
pA = transpose(pA)
write(*,*) pA
nullify(pA)
END DO ...
<< snip >>
==================================== END CODE1 =======
==================================== CODE2 ===========
double precision, dimension(:) :: tA
<< snip >>
DO ...
! Call subroutine to generate section of A
call sub1(tA, sr, er, sc, ec, nr, nc )
write(*,*) tA
END DO ...
<< snip >>
==================================== END CODE2 =======
==================================== SUB1 ============
subroutine sub1(sA,sr,er,sc,ec,nr,nc)
integer :: nr, nc
double precision, dimension(nr*nc), intent(out) :: sA
<< Do whatever to generate the sA >>
==================================== END SUB1 ========
.
- Follow-Ups:
- Re: What am I doing wrong? Passing pointers to subroutines.
- From: James Van Buskirk
- Re: What am I doing wrong? Passing pointers to subroutines.
- Prev by Date: Re: generic module procedures with function arguments
- Next by Date: Re: What am I doing wrong? Passing pointers to subroutines.
- Previous by thread: restated question about externals
- Next by thread: Re: What am I doing wrong? Passing pointers to subroutines.
- Index(es):
Relevant Pages
|