Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

why does this variable change?

Status
Not open for further replies.

ivy1977

Programmer
Jan 10, 2006
4
US
I have a problem in my fortran program. A variable changes after I call a subroutine, but I don't change this variable during the calling of the subroutine. In order to figure out, I put this variable into the subroutine(but it is not changed in the subroutine). I find that this variable is changed in the subroutine. I feel very strange about this. The subroutine is as following:
*******************************************
subroutine collc(nxf,nyf,wrf,nxc,nyc,wrc,funcd1,funcd0,fdd1,te)

implicit none
integer :: ic,jc,k,iff,jf,nxf,nyf,nxc,nyc
real*8, dimension(nxf,nyf,9) :: wrf,funcd1
real*8, dimension(nxc,nyc,9) :: wrc,funcd0,fdd1
real*8, intent(in) :: te

print *, te,11
pause

do k=1,9
do jc=1,nyc
do ic=1,nxc
wrc(ic,jc,k)=0.0
enddo
enddo
enddo

print *, te,22
pause

do k=1,9
do jc=2,nyc-1
do ic=2,nxc-1
iff=ic*2-1
jf=jc*2-1
wrc(ic,jc,k)=wrc(ic,jc,k)+wrf(iff, jf, k)/2.0
wrc(ic,jc,k)=wrc(ic,jc,k)+wrf(iff+1,jf, k)/4.0
wrc(ic,jc,k)=wrc(ic,jc,k)+wrf(iff-1,jf, k)/4.0
wrc(ic,jc,k)=wrc(ic,jc,k)+wrf(iff, jf+1,k)/4.0
wrc(ic,jc,k)=wrc(ic,jc,k)+wrf(iff, jf-1,k)/4.0
wrc(ic,jc,k)=wrc(ic,jc,k)+wrf(iff+1,jf+1,k)/8.0
wrc(ic,jc,k)=wrc(ic,jc,k)+wrf(iff+1,jf-1,k)/8.0
wrc(ic,jc,k)=wrc(ic,jc,k)+wrf(iff-1,jf+1,k)/8.0
wrc(ic,jc,k)=wrc(ic,jc,k)+wrf(iff-1,jf-1,k)/8.0
enddo
enddo
enddo

print *, te,33
pause

do k=1,9
do jc=1,nyc
do ic=1,nxc
funcd0(ic,jc,k)=funcd1(ic*2-1,jc*2-1,k)
fdd1(ic,jc,k)=funcd1(ic*2-1,jc*2-1,k)
enddo
enddo
enddo

print *, te,44
pause

return
end

*******************************************

And the result is as following:

0.000000000000000E+000 11
FORTRAN PAUSE
PAUSE prompt>
0.000000000000000E+000 22
FORTRAN PAUSE
PAUSE prompt>
0.000000000000000E+000 33
FORTRAN PAUSE
PAUSE prompt>
0.108468249176599 44

We can see that te changes from 0.0 (at 33) to 0.108 (at 44) . There is no overflow warning at all. Does anybody have an idea about this?
Thanks!
 
What are the values of nxf and nyf? Are they the same values as you have declared or are they bigger/smaller than what you have declared? eg

real*8, dimension(10,20,9):: wrc

Are you calling collc with 10, 20 or smaller or bigger numbers?
 
in fact, nxf=257,nyf=65 and nxc=129,nyc=33
 
In fact? Where is this fact (print *, nxc etc). Check actual array parameters (types and extents) of this call (funcd0 and fdd1 especially)...
 
there is no problem in calling this subroutine but the te always change as I described. Does anybody know why?
 
And 'nxf=257,nyf=65 and nxc=129,nyc=33' are requested by my physical model.
 
Calling collc is no problem, of course. May you present a context of this calling: actual parameters declarations, for example (better with debug print)? You may pass a small array then overlap it (and te var too) in the last loop (and Fortran compiler does not recognize this situation)...

Var values and physical model requirements are totally different things in the real world, alas...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top