inquire文について

inquire はその名の通りいろいろ問い合わせて確認できるらしい.
今のところよく使うのはopenedくらい.

ファイルが開かれているか確認する(opened)

inquire(unit=fileID,opened=TFopen)

で,装置番号 fileID が既に展開されているか確認できる.TFopen には logical 値が返される.
何に使うのかといえば,subroutine でファイルに出力する時とか.
以下に例示する.

subroutine FOOBARSUB(...,fileID,...)
    implicit none

    !!! input arguments
    integer, intent(in) :: fileID

    !!! local variables
    logical :: TFopen

    !*** write out if already opened
    inquire(unit=fileID,err=900,opened=TFopen)
    if(TFopen)then
      write(fileID,101) hoge
    else
      write(*,*) fileID,'なんてものはない.'
    endif
    101 format(...)
    ! ... others ...
    return

    !!エラー時の処理
    900 write(*,*) 'inquireでエラー'
end subroutine

errをつけているのは,しょうもないミスで計算が止まるのを防ぐため.


Front page   Edit Diff Attach Copy Rename Reload   New List of pages Search Recent changes   Help   RSS of recent changes
Last-modified: 2018-04-20 (Fri) 15:04:14 (2197d)