title: Fortran: Variables changing on their own
body: <p>I'm having a problem of variables getting over-written for I don't know what reason. I've posted a chunk of the code below so you can see how things are declared. The variables strain,Qi,Qf,Qd,tel and Gc are passed into the subroutine and used to calculate ssgrad,strn0,strss0.</p>
  
  <p>My problem is that tel and Gc are passed into the subroutine OK but are for some reason change value during this chunk of code.</p>
  
  <p>Using print statements I've found that the problem first occurs during the 2nd do loop. When I set strss0 to 0, Gc and tel change value from both being equal to 1, to seemingly random numbers: tel=11.52822 Gc=-8.789086 (Just shown for the sake of example)</p>
  
  <p>Each time I run the code they are set to the same values though.</p>
  
  <p>Just to let you know, this subroutine interfaces with a commercial finite element package.</p>
  
  <p>Many thanks in advance for any help with this</p>
  
  <pre><code>subroutine initcalcs(strain,Qi,Qf,Qd,tel,Gc,ssgrad,strn0,strss0)
  
    implicit none
  
    integer :: i,j
  
    real*8:: nstrn0,nstrs0,strn0,strnf,varsq,normvar,lmbda0,lmbdaf,
   # ssgrad,t0,tt,tel,nstrnf,nstrsf,Gc
  
    real*8, dimension(3) :: strain,stran0,stranf,strss0,strssf,var
  
    real*8, dimension(3,3) :: Qd,Qi,Qf
  
  
    lmbda0=1.0d0                                                                                          
  
  
    nstrn0=0.0d0                                                                             
    do i=1,3
          stran0(i)=0.0d0
          stran0(i)=strain(i)*lmbda0                                                         
          nstrn0=nstrn0+stran0(i)**2                                                         
    end do                                                                                    
  
    nstrn0=dsqrt(nstrn0)                                                                     
  
  
    do i=1,3
          strss0(i)=0.0d0 
    end do
  </code></pre>