Search code examples
fortrangfortranfortran-common-block

Variable strangely takes the value zero after the call of a subroutine


I have been facing some issues trying to convert a code previously compiled with compaq visual fortran 6.6 to gfortran.
Here is a specific problem I have met with gfortran :
There is a variable called "et" which takes the value 3E+10. Then the program calls a subroutine. "et" doesn't appear in the subroutine, but after coming back to the main program it has now the value 0.
When compliling with compaq visual fortran I didn't have this problem.
The code I am working on is a huge scientific program, so I put below only a small part of it :

c
c     calculate load/unload modulus
c
500   t=(s1-s3)/2.
      aa=1.00
      if(iconeps.ne.1)bb=1.00
      if(smean.lt.ap1) smean=ap1
      if(xn.gt.0.000001) aa=(smean/atmp)**xn
      if(iconeps.eq.1)go to 220
      if(xm.gt.0.000001) bb=(smean/atmp)**xm
220   if(t.ge.0.99*sm1) go to 600
      et=xku*aa*atmp+tt*tm1
      if(iconeps.ne.1)bt=xkb*atmp*bb
      go to  900
600   et=(xkl*aa*atmp+tt*tm1)*(1.0-rf*sr)**2
      if(iconeps.ne.1)bt=xkb*atmp*bb
900   continue
      btmax=17.0*et
      btmin=0.33*et

      if(iconeps.ne.1)then
      tbt=(alf1+alf3*dtt)*dtt*(1.+vide)*tm2
      btf=bt+tbt
      bt=btf
      endif

      if(bt.lt.btmin) bt=btmin
      if(bt.gt.btmax) bt=btmax
      if(iconeps.eq.1)go to 1100

1000  continue

1050  if(mt.eq.mtyp4c)goto 1100
      s=0.0
      t=0.0
      call shap4n(s,t,f,pfs,pft)                           ! Modification by NHV
      call thick4n(s,t,xe,ye,thick)
      call bmat4n(xe,ye,f,pfs,pft,b,detj,thick)

c     calculate incremental strains

      do 1300 i=1,4
      temp=0.0
      do 1200 j=1,8
1200  temp=temp+b(i,j)*disp(j)
1300  depi(i)=temp
      epsv=0.0
      do 1400 i=1,2
1400  epsv=epsv+depi(i)
  epsv=epsv+depi(4)

      ev=vide-(1.+vide)*epsv

      if(ev.lt.0.0)ev=vide*.01

1100  continue

      call perm(permws,xkw,coef,rw,tvisc,ev,vide,tt,pp)

: "et" keeps the good value until just before calling the subroutine "perm". Just after this subroutine it takes the value zero.
"et" isn't in any common block
This piece of code is part of a subroutine called by several different subroutines. What is even more strange is that when it is called in other parts of the code I doesn't have this problem ("et" keeps its value)
So if someone has ever met this kind of problem or have any idea about it I will be very gratefull


Solution

  • Perhaps you have a memory access error, such as an array bounds violation, or a mismatch between actual and dummy arguments. Are the interfaces of the subroutines explicit, such as being "used" from a module? Also try turning on compiler debugging options ... obviously subscript checking, but others might catch something. An extensive set for gfortran 4.5 or 4.6 is:

    -O2 -fimplicit-none -Wall -Wline-truncation -Wcharacter-truncation -Wsurprising -Waliasing -Wimplicit-interface -Wunused-parameter -fwhole-file -fcheck=all -std=f2008 -pedantic -fbacktrace

    Subscript checking is included in fcheck=all