title: Fortran Function does not return value to the main program
body: <p>I have called a function <code>integ</code> from another function <code>rter3</code>. I have printed <code>integ</code> values from the <code>integ</code> function and it prints legitimate values. But when I print <code>integ</code> values at <code>rter3</code> function, it prints <code>0.00</code> . I have tried all I could to understand why it does that but could not figure out. Please help me out here. Thanks.</p>
  
  <pre><code>function rter3(z,c1,nx1,xarray,xlocation,angl3r,gamr,probr,aaa,da1)
      use data
      integer:: z,o,nx1,lc
      double precision:: c1(nx1),w1,w2,rter3,angl3r,gamr,probr(100),aaa,da1,rati2,xarray(nx1),xlocation,div1
      double precision:: variable
      dx=0.1
      rati2=20.0
      !write(*,*) z,o,nx1,xlocation,angl3,gam
      w1=div1(c1(z-1),c1(z),dx)
      w2=div1(c1(z),c1(z+1),dx)
      variable=integ(nx1,c1,xarray,xlocation,dx,angl3r,gamr,probr,aaa,da1,w1,w2)
      rter3=rati2*variable
      write(*,*) "rter3=", rter3, variable, rati2, xlocation, gam, angl3, da1
  end function rter3
  
  function integ(nxx,hfield,xfield,loc1,diff,angl3,gam,prob,afield,dprob,ab2,af2)
      implicit none
      integer :: l,nxx,dui,kk,indx,indt
      double precision:: du(101),prob(100),am1,a,ap1,angl3,gam,diff,dprob,integ,function12,afield(100),xfield(nxx)
      double precision:: loc1,loc2,hfield(nxx),am2,ap2,ab2,af2
      !write(*,*) 'test loop', loc1, diff, angl3, gam, dprob
  
      do kk=1,100
          do l=1,nxx
              if (0.95*xfield(l)&gt;=loc1-afield(kk).and. 1.05*xfield(l)&lt;loc1-afield(kk)) then
                  dui=l
                  !call exit()
              endif
          enddo
          !dui= loc1-kk
          !write(*,*) "Entered integ", dui
          !write(*,*) dui
          if (dui&lt;=3) then
              dui=3
          endif
          if (dui&gt;= nxx-2) then
              dui=nxx-2
          endif
          am1=hfield(dui-1)
          am2=hfield(dui-2)
          a=hfield(dui)
          ap2=hfield(dui+2)
          ap1=hfield(dui+1)
          du(kk)=abs(prob(kk)*(function12(am2,am1,ap1,ap2,diff,angl3,gam,ab2,af2))*dprob)
      enddo
  
      integ=sum(du)
      write(*,*) "integration value=", integ, nxx, loc1, diff, angl3, gam, dprob
  end function integ
  </code></pre>
  
  <p>So, those are the individual functions for your reference. Please let me know if you feel something is wrong. The whole code is very big but if you feel you need to see it, I shall attach it. Thanks again.</p>