fc2ブログ

浅葱さんのブログ

ええ、以前はぷらしのすとか言っていましたよ

[fortran-stdio] buffering logic

I got better expression of buffering logic:
  !private
  subroutine flushblock(unit, iostat)
    integer, intent(in):: unit
    integer, intent(out):: iostat
    if (info(unit)%hot) then
      call writeblock(unit, info(unit)%cached%blk, info(unit)%buf, iostat)
      info(unit)%hot = .false.
    else
      iostat = 0
    endif
  end subroutine

  !private
  subroutine fetchblock(unit, i, iostat)
    integer, intent(in):: unit, i
    integer, intent(out):: iostat
    call set_buffer(unit, iostat)
    if (iostat /= 0) return
    if (info(unit)%cur%blk == i) return
    call flushblock(unit, iostat)
    if (iostat /= 0) return
    call readblock(unit, i, info(unit)%buf, iostat)
  end subroutine

This pair of routines are written at the viewpoint of buffer management, instead of top-down approach from read/write. I believe that such a inversion of viewpoint is important in programming.

スポンサーサイト



コメント

コメントの投稿


管理者にだけ表示を許可する

トラックバック

トラックバック URL
http://prasinos.blog2.fc2.com/tb.php/53-b849a21a
この記事にトラックバックする(FC2ブログユーザー)