title: Fortran runtime error: Text file busy
body: <p>I have written a simple program to generate an output file, but every time I run it, no matter what unit number I give it, the compiler always gives the error:</p>
  
  <pre><code>Fortran runtime error: Text file busy
  </code></pre>
  
  <p>Here is the program:</p>
  
  <pre><code>program plottest
  implicit none
  
  integer :: z,k,m,j,i
  double precision :: delta_Tem, deltax, deltaz, a
  double precision, dimension(:,:), allocatable :: T_n, T_g_init
  double precision, dimension(:), allocatable :: x
  double precision, parameter :: pi = 3.141592653589793239d0
  double precision, parameter :: T_hot = 300
  double precision, parameter :: T_cold = 276
  double precision, parameter :: D = 4 !height z (cm)
  double precision, parameter :: L = 5 !length x (cm)
  integer, parameter :: Nz = 9 !resolution in z
  integer, parameter :: Nx = 6 !resolution in x
  integer, parameter :: N = 10 !resolution in n
  
  delta_Tem = T_hot-T_cold
  deltaz = D/(Nz-1) !(cm)
  deltax = L/(Nx-1) !(cm)
  a = L/D
  
  allocate(T_n(N,Nz))
  allocate(T_g_init(Nx,Nz))
  allocate(x(1:Nx))
  
  z=0
  T_n(1,1)=T_hot
  do k=2,Nz
      T_n(1,k) = T_hot-((k-1)*delta_Tem)
  end do
  
  z=0
  T_n(2,1)=0
  do k=1,Nz
      do m=2,N
          T_n(m,k) = T_n(1,k)*sin(pi*(k-1)*deltaz)
      enddo
  enddo
  
  do j=1,Nx
      x(j) = x(j)+deltax
  enddo
  
  do k=1,Nz
      do j=1,Nx
          do m=1,N
              T_g_init(j,k)=T_g_init(j,k)+T_n(m,k)*cos(m*pi*x(j)/a)
          enddo
      enddo
  enddo
  
  open(unit = 15, file = "plottest")
  do, i=1,n
      do, j=1,k
          write(15,"(F25.5)") T_g_init(i,j)   
          if (j==k) write(15,"(A1)") "X"
      enddo
  enddo
  close(15)
  
  deallocate(T_n)
  deallocate(T_g_init)
  deallocate(x)
  
  end program plottest
  </code></pre>
  
  <p>As far as I know, there are no other processes running, and no other text files open. I'm stumped.</p>