Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

newbie: passing parameters to subroutine
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

Report this thread to moderator Post Follow-up to this message
Old Post
Louis Luangkesorn
09-26-04 08:57 PM


Re: newbie: passing parameters to subroutine
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.



Report this thread to moderator Post Follow-up to this message
Old Post
Gordo
09-26-04 08:57 PM


Re: newbie: passing parameters to subroutine
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 featu
re
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.salford
software..../downloads.html
or the Lahey compiler at http://www.lahey.com/ . The Fortran 77 static analy
zer
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 News
groups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =
---

Report this thread to moderator Post Follow-up to this message
Old Post
beliavsky@aol.com
09-26-04 08:57 PM


Re: newbie: passing parameters to subroutine
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:<4156c7
41_1@127.0.0.1>...
<snip>
>
> I don't see anything wrong. Hazarding a guess, if your code tries to acces
s
> out-of-bound array elements the symptoms of this problem can appear anywhe
re.
>
>
> Btw real*8 is not standard Fortran, and the "::" in a declaration is a fea
ture
> 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.salfo
rdsoftware..../downloads.html
> or the Lahey compiler at http://www.lahey.com/ . The Fortran 77 static ana
lyzer
> FTNCHEK at http://www.dsm.fordham.edu/~ftnchek/ is useful.
>

Report this thread to moderator Post Follow-up to this message
Old Post
Louis Luangkesorn
09-28-04 02:04 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Fortran archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:23 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.