title: Writing multiple output files in Fortran
body: <p>Dear All, I am writing a code that writes the out put in multiple files named as 1.dat, 2.dat, ..... Here is my code but it gives some unusual output. May you tell me what is wrong in my code please? Basically I could not get the correct syntax to open multiple files, write on them and close before the next file is opened. Thank you. <strong><em>My Code</em></strong>:</p>
  
  <pre><code>implicit double precision (a-h,o-z),integer(i-n)
  dimension b(3300,78805),bb(78805)
  character*70,fn 
  character*80,fnw 
  nf = 3600       ! NUMBER OF FILES
  nj = 360        ! Number of rows in file.
  do j = 1, nj
      bb(j)  = 0.0
  end do
  c-------!Body program-----------------------------------------------
  iout = 0    ! Output Files upto "ns" no.
  DO i= 1,nf  ! LOOP FOR THE NUMBER OF FILES
      if(mod(i,180).eq.0.0) then
          open(unit = iout, file = 'formatted')
          x = 0.0
          do j = 1, nj
              bb(j) = sin(x)
              write(iout,11) int(x),bb(j)
              x = x + 1.0
          end do
          close(iout)
          iout = iout + 1
      end if
  END DO
  11  format(i0,'.dat')   
  END
  </code></pre>