newbie: passing parameters to subroutine

From: Louis Luangkesorn (lluang_at_verizon.net)
Date: 09/26/04


Date: 26 Sep 2004 06:16:52 -0700

Ok. I realize that this is something that must be obvious to anyone
who has programed in Fortran for any length of time, but I don't have
any such person around right now.

I am trying to use an array to hold the results of a subroutine. When
I do so, the value I get back in the calling function is not the same
as the value that the variable has at the end of the subroutine. Is
there anything obvious (or not so obvious) that I'm doing wrong?
Thank you for your help. I've spent days tracking this down.

The calling subroutine(properly indented for G77):

subroutine pipe( . . .)
real*8::pc(0:368)
DATA pc /369 * 0.0d0/
<snip>
      PRINT *, 'MMCIN:cr, rhor:', cr, rhor
      CALL MMC(cr,rhor,pc,sump,maxr)
      PRINT *, 'MMCOUT:cr, rhor, pc(0), sump, maxr :', cr, rhor,
     ! pc(0),sump , maxr
<snip>

The subroutine being called:

      subroutine MMC(c,rho,pc,sump,maxc)
      implicit none
      real*8::c,rho,pc(0:368),r,sump
<snip>
      print *, "MMC: p0, sump, maxc", pc(0),sump, maxc
      end subroutine MMC
 

The output:

MMCIN:cr, rhor: 1. 0.724261284
MMC: p0, sump, maxc 0.99612261 1. 2
MMCOUT:cr, rhor, pc(0), sump, maxr : 1. 0.724261284 -8.72913609E+015
 1. 2

Note that the value of p0 = pc(0) changed from the end of subroutine
to when it returned. I have also used 1000 in the place of 368 in
both locations (I happen to know that the array will not go beyond
368)

Thanks in advance.

Louis Luangkesorn



Relevant Pages

  • Re: g95 wish list
    ... (big snip on dimension of (1) ... > have a bounds check which fails if the subroutine references X. ... allowing the full dimension information to be ... > the possibility of a check as to whether you passed an array of size 2 ...
    (comp.lang.fortran)
  • Re: passing only the real parts of a complex array to a function
    ... When a subroutine is called with an expression instead ... of a variable (scalar or array) the called routine can't ... Even PL/I pseudo-variables won't do this, ...
    (comp.lang.fortran)
  • Re: passing functions or subroutines in a subroutine
    ... They are not quite as general as function pointers in C, ... a DIMENSION statement which would make it an array. ...
    (comp.lang.fortran)
  • Re: How to list the statement of all var ?
    ... > of an object when the question was about `var' statements? ... And as soon as i will test it for this particular host ... to use an Object object instead of an Array object. ...
    (comp.lang.javascript)
  • Re: VB .Net and Intel Visual Fortran 9
    ... having is that the VB program cannot load the DLL. ... subroutine) to accept an array from VB - in my case a 2D array. ... Declare Sub mmult Lib "test.dll" (ByRef i As Double, ByRef j As Double, ...
    (comp.lang.fortran)