!--------------------------------------------------------!
! $BI=Bj(B: $B=PNO$K4X$9$k@_Dj$*$h$S(B
! $BMzNr(B: 2003/10/28 
!--------------------------------------------------------!
module com_step
  
  implicit none

  !$B6-3&CM$NFI$_9~$_4V3V(B
  integer, save :: bound_dt    ! $B4pHWCO7A<B9T4V3V(B
  integer, save :: Ms_dt       ! Ms $B$NFI$_9~$_4V3V(B
  integer, save :: Ts_dt       ! Ts $B$NFI$_9~$_4V3V(B

  namelist /bc_dt/ bound_dt, Ms_dt, Ts_dt

  ! $B=PNO%U%!%$%kFI$_9~$_4V3V(B
  integer, save :: rs_dt       !  $B%j%9%?!<%H%U%!%$%k$N=PNO4V3V(B 
  integer, save :: monit2D_dt  !  2 $B<!85%b%K%?$N=PNO4V3V(B
  integer, save :: monit3D_dt  !  3 $B<!85%b%K%?$N=PNO4V3V(B

  namelist /out_dt/ rs_dt, monit2D_dt, monit3D_dt

  ! $BFI$_9~$_!&=PNO%U%i%0(B
  integer, save :: bound_flg    ! $B4pHWCO7A<B9T%U%i%0(B
  integer, save :: Ms_flg       ! Ms $B$NFI$_9~$_%U%i%0(B
  integer, save :: Ts_flg       ! Ts $B$NFI$_9~$_%U%i%0(B


  integer, save :: rs_flg       ! $B%j%9%?!<%H%U%!%$%k$N=PNO%U%i%0(B
  integer, save :: monit2D_flg  ! 2 $B<!85%b%K%?$N(B on/off $B%U%i%0(B
  integer, save :: monit3D_flg  ! 3 $B<!85%b%K%?$N(B on/off $B%U%i%0(B
  integer, save :: exT_flg  ! $B29EY7W;;$N(B on/off $B%U%i%0(B


  
!--------------------------------------------------------!
contains                  
!--------------------------------------------------------!
  subroutine com_step_ini
    use prm,    only: dt
    use prmphys, only: s_a

    ! $B=PNO!&6-3&CM$NFI$_9~$_$K4X$9$k@_Dj(B. $BC10L$OG/?t(B
    ! $B0J2<Cm0U(B. 

    
    implicit none

    !--------------------------------------------------------!
    ! $BEG$-=P$5$l$k%j%9%?!<%H%U%!%$%k$N=PNO4V3V$r=i4|CM$K$7$?$i(B
    ! $B6-3&CM$NFI$_9~$_$OKh%9%F%C%W$8$c$J$$$N$G7k2LJQ$o$k2DG=@-(B
    ! $B$"$j(B.
    !--------------------------------------------------------!
    
    ! $B$H$j$"$($:$NNc(B
    bound_dt =  dt/s_a
    Ms_dt =  dt/s_a
    Ts_dt =  dt/s_a
    
    rs_dt = 20000 * dt/s_a       ! $B$H$j$"$($:(B 1 $B2s$@$1=PNO(B
    write(6, *)'rs_dt=',  rs_dt
    monit2D_dt = 10  * dt/s_a
    monit3D_dt = 10  * dt/s_a

    
!    REWIND(5)
    READ (5,bc_dt)
    WRITE(6,bc_dt)
    READ (5,out_dt)
    WRITE(6,out_dt)

  end subroutine com_step_ini
!--------------------------------------------------------!


!--------------------------------------------------------!
  subroutine  com_step_run(it)
    ! $B%b%K%?(B, $B%j%9%?!<%H%U%!%$%k$N=PNO(B
    ! $B6-3&CM$NFI$_9~$_$N%U%i%0(B
    ! $B$N%U%i%0$rN)$F$k(B
    use prm,   only :  dt, dt_T
    use prmphys, only : s_a

    implicit none

    integer, INTENT(IN)  :: it

    ! $B4pHWCO7A(B
    if(MOD(it, bound_dt/(dt/s_a))==0)then
       bound_flg = 1
    else
       bound_flg = 0
    end if
    ! $B$+$sM\NL(B
    if(MOD(it, Ms_dt/(dt/s_a))==0)then
       Ms_flg = 1
    else
       Ms_flg = 0
    end if
    ! $BI=LL29EY(B
    if(MOD(it, Ts_dt/(dt/s_a))==0)then
       Ts_flg = 1
    else
       Ts_flg = 0
    end if

    ! $B%b%K%?(B, $B%j%9%?!<%H%U%!%$%k$N=PNO(B
    if(MOD(it, rs_dt/(dt/s_a))==0)then
       rs_flg = 1
    else
       rs_flg = 0
    end if

    if(MOD(it, monit2D_dt/(dt/s_a))==0)then
       monit2D_flg = 1
    else
       monit2D_flg = 0
    end if

    if(MOD(it, monit3D_dt/(dt/s_a))==0)then
       monit3D_flg = 1
    else
       monit3D_flg = 0
    end if

    ! $B29EY7W;;(B
    if(MOD(it, dt_T/dt)==0)then
       exT_flg = 1
    else
       exT_flg = 0
    end if
    
  end subroutine com_step_run

end module com_step
