title: Adding gaussian noise in fortran to an array of data
body: <p>I need some help in adding Gaussian noise to my Fortran code. I have to basically construct an array of size 4. I enter the value into the array and then I have to add the noise. I have tried looking this up on the internet and have found solutions which uses an array of random numbers and then adds guassian noise to the array, but was unable to find solution for adding the noise to a pre-set array.</p>
  
  <p>I have given the part of the code below</p>
  
  <pre><code>real, dimesnsion(1:4):: stoke
  
  !create an array
  stoke(1)=sum_iu
  stoke(2)=diff_iu
  stoke(3)=sum_iq
  stoke(4)=diff_iq
  
  do ij=1,4
  
     print*, 'stoke=' ,ij,'=',stoke(ij)
  
  end do
  
  ! add gaussian noise to the data
  
  do ij=1,xx-1,2
  
        temp= sd*sqrt(-2.0*log(stoke(ij)))*cos(2*pi*(stoke(ij+1)))+mean
        stoke(ij+1)=sd*sqrt(-2.0*log(stoke(ij))) * sin(2*pi*(stoke(ij+1)))+mean
        stoke(ij)=temp
  
  print*,'the values are= ','stoke(ij)',stoke(ij),'stoke(ij+1)',stoke(ij+1)
  end do
  </code></pre>
  
  <p>When I run this it outputs the result as NaN for the four output values. But in case I use a random number <code>array(size=4)</code> in place of <code>stokes(4)</code> it does display the numbers.</p>