title: How do I diagnose bus error in fortran
body: <p>I'm learning how to use fortran to do some data analysis. I'm working through the following example:</p>
  
  <pre><code>program linalg
    implicit none
  
    real :: v1(3), v2(3), m(3,3)
    integer :: i,j
  
    v1(1) = 0.25
    v1(2) = 1.2
    v1(3) = 0.2
  
    ! use nested do loops to initialise the matrix
    ! to the unit matrix
    do i=1,3
       do j=1,3
          m(i,j) = 0.0
       end do
       m(i,j) = 1.0
    end do
  
    ! do a matrix multiplicationof a vector equivalent to v2i = mij v1j
    do i = 1,3
       v2(i) = 0.0
       do j = 1,3
          v2(i) = v2(i) + m(i,j)*v1(j)
       end do
    end do
  
    write(*,*) 'v2 = ', v2
  
  end program linalg
  </code></pre>
  
  <p>which I execute with </p>
  
  <pre><code>f95 -o linalg linalg.f90
  ./linalg
  </code></pre>
  
  <p>However, I get the following message in the terminal:</p>
  
  <pre><code>Bus error
  </code></pre>
  
  <p>Some links that I've followed online suggest that this is to do with not having pre-define a variable, but I am sure that I have in this script and cannot find where the error is coming from. Is there another reason I would be getting this error? </p>