For Programmers: Free Programming Magazines  


Home > Archive > Fortran > September 2004 > newbie: passing parameters to subroutine









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author newbie: passing parameters to subroutine
Louis Luangkesorn

2004-09-26, 3:57 pm

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
Gordo

2004-09-26, 3:57 pm

Louis Luangkesorn wrote:
> 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>
> 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


Except for pc, the precision of the arguments in MMC in the calling routine
do not match their precision in subroutine MMC.


beliavsky@aol.com

2004-09-26, 3:57 pm


lluang@verizon.net (Louis Luangkesorn) wrote:
>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)


I don't see anything wrong. Hazarding a guess, if your code tries to access
out-of-bound array elements the symptoms of this problem can appear anywhere.


Btw real*8 is not standard Fortran, and the "::" in a declaration is a feature
of Fortran 90 that g77 appears to support.

I highly recommend trying to compile your code with some other compilers,
for example the Salford FTN77 Personal Edition (for Windows) at http://www.salfordsoftware.co.uk/co.../downloads.html
or the Lahey compiler at http://www.lahey.com/ . The Fortran 77 static analyzer
FTNCHEK at http://www.dsm.fordham.edu/~ftnchek/ is useful.



----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Louis Luangkesorn

2004-09-28, 9:04 am

Thank you for the pointer to FTNCHEK. I don't think I've ever seen so
many error messages all at once after I figured out how to get it to
look at my whole project at one time. Once I waded through the N
messages, N>>0, it worked.

Louis

"beliavsky@aol.com" <beliavsky@127.0.0.1:7501> wrote in message news:<4156c741_1@127.0.0.1>...
<snip>
>
> I don't see anything wrong. Hazarding a guess, if your code tries to access
> out-of-bound array elements the symptoms of this problem can appear anywhere.
>
>
> Btw real*8 is not standard Fortran, and the "::" in a declaration is a feature
> of Fortran 90 that g77 appears to support.
>
> I highly recommend trying to compile your code with some other compilers,
> for example the Salford FTN77 Personal Edition (for Windows) at http://www.salfordsoftware.co.uk/co.../downloads.html
> or the Lahey compiler at http://www.lahey.com/ . The Fortran 77 static analyzer
> FTNCHEK at http://www.dsm.fordham.edu/~ftnchek/ is useful.
>

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com