#author("2020-03-05T16:54:57+09:00","default:Miyashita","Miyashita")
#author("2020-03-05T16:55:31+09:00","default:Miyashita","Miyashita")
*inquire文について [#xbfac96e]
inquire はその名の通りいろいろ問い合わせて確認できるらしい.~
今のところよく使うのはopenedくらい.

***ファイルが開かれているか確認する(opened) [#o78a1b1c]
#codeprettify(lang-fortran){{
inquire(unit=fileID,opened=TFopen)
}}
で,装置番号 fileID が既に展開されているか確認できる.TFopen には logical 値が返される.~
何に使うのかといえば,subroutine でファイルに出力する時とか.~
以下に例示する.
#codeprettify(lang-fortran){{
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