Code Comments
Programming Forum and web based access to our favorite programming groups.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
Post Follow-up to this messageLouis 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.
Post Follow-up to this messagelluang@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 = ---
Post Follow-up to this messageThank 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. >
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.