2010-07-06

interface module (interface block) のテンプレ @ F90

あまりにもよく忘れるので

! interface module
module my_inter
  
  ! interface block
  ! すべての subroutine の冒頭部分と仮引数宣言をコピペする。
  ! subroutine 側で引数の名前や数を変えたら、
  ! こちらにも反映させないといけない(正直メンドイ)。
  ! そのかわり subroutine を module に入れなくても F90 化できる

  interface
    
    subroutine sub1( int, char, real_arr )
      implicit none
      integer, intent(in) :: int
      character(len=24), intent(in) :: char
      real(8), intent(out) :: real_arr(0:) !下限のみ指定する形状引継ぎ配列
      integer :: i, j, k
    endsubroutine sub1

    subroutine sub2
      ...
    endsubroutine sub2

  endinterface
  
endmodule my_inter

でもって、call する側の subroutine では、普通の module のときと同じように、

subroutine sub3
  use my_inter, only : sub1 ! これでsub1が利用可能に
  implicit none
    ...
    call sub1( &
      &   int = int & ! intent(in)
      & , char = char & ! intent(in)
      & , real_arr = real_arr & ! intent(out)
    & )
    ...
  return
endsubroutine sub3


みたいに使う。

No comments: