What am I doing wrong? Passing pointers to subroutines.



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 ========

.



Relevant Pages

  • Re: Use of CallByName()
    ... Your call line is more universal than mine in that it will call a subroutine from any module in the workbook as long as the subroutine names on each module are unique. ... If you had, say, two subroutines named Sub1, one on Module1 and the other on Module2, your code line would error out unless the programmer specifically specified which Module's Sub1 he/she wanted. ... Sub testme() ... MsgBox "sub3" ...
    (microsoft.public.excel.programming)
  • procedure argument
    ... SUBROUTINE sub ... SUBROUTINE sub1 ... SUBROUTINE process (sub) ...
    (comp.lang.fortran)
  • Re: Subroutines in Separate Files
    ... I can't just focus/compile on sub1. ... all Sub's use some common variables as follows: ... end subroutine sub1 ... End Module Utils ...
    (comp.lang.fortran)
  • Re: Are these the same arguments?
    ... If sub1 is elemental, the first call only acts on ... and the subroutine is like ... dimension p,q,r ... The example above is not standard-conforming. ...
    (comp.lang.fortran)