program io
  implicit none
  character(*), parameter:: fnam = "zzz-io.tmp"
  call mkfile
contains

  subroutine mkfile
    use n3error, only: die
    use n3io, only: fopen, fwrite, fclose
    integer:: buf(1024)
    integer:: i, h, iostat
    call fopen(fnam, "w>", 1024, h)
    if (h < 0) then
      print *, 'fopen'
      call die
    endif
    do, i = 1, size(buf)
      buf(i) = i
    enddo
    call fwrite(h, size(buf), buf, iostat)
    if (iostat /= 0) then
      print *, 'fwrite', iostat
      call die
    endif
    call fclose(h, iostat)
    if (iostat /= 0) then
      print *, 'fclose', iostat
      call die
    endif
  end subroutine

end program
