!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!$BI=Bj(B: $B%b%K%?=PNO%5%V%k!<%A%s(B
!$BMzNr(B: 2003/10/30
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
module monit_out
  use prm, only : IMAX, JMAX, KMAX
  use file_switch, only : monit2D_UID, monit3D_UID

  implicit none

  integer, save  ::  rcNO_2D = 1
  integer, save  ::  rcNO_3D = 1

contains

  subroutine monit2D_out
    use prm      , only : IMAX, JMAX
    use com_step , only : monit2D_dt
    use com_monit, only : sum_2, mxptr_2, tflg_2

    implicit none
    real(4)       :: VAR(1:IMAX, 1:JMAX)
    real(8)       :: dtime
    integer       :: k 
    



    do k = 1, mxptr_2
       if(tflg_2(k)=='AVR')then
          dtime = monit2D_dt
       else
          dtime = 1.0D0
       end if
       VAR(:, :) =  sum_2(:, :, k)/dtime
       write(monit2D_UID, rec=rcNO_2D)VAR
       rcNO_2D = rcNO_2D + 1
    end do
    


  end subroutine monit2D_out



  subroutine monit3D_out
    use prm      , only : IMAX, JMAX,KMAX
    use com_step , only : monit3D_dt
    use com_monit, only : sum_3, mxptr_3, tflg_3

    implicit none
    real(4)       :: VAR(1:IMAX, 1:JMAX, 1:KMAX)
    real(8)       :: dtime
    integer       :: l
   



    do l = 1, mxptr_3
       if(tflg_3(l)=='AVR')then
          dtime = monit3D_dt
       else
          dtime = 1.0D0
       end if
       VAR(:, :, :) =  sum_3(:, :, :, l)/dtime
       write(monit3D_UID, rec=rcNO_3D)VAR
       rcNO_3D = rcNO_3D + 1
    end do
    


  end subroutine monit3D_out



subroutine monit2D_out_tmp(VAR)


  implicit none

  real(8), INTENT(IN) :: VAR(1:IMAX, 1:JMAX)
  real(4)             :: VAR_4(1:IMAX, 1:JMAX)
  VAR_4 = VAR
  write(6, *) 'rcNO_2D=', rcNO_2D
  write(monit2D_UID, rec=rcNO_2D)VAR_4
  rcNO_2D = rcNO_2D + 1

end subroutine monit2D_out_tmp

subroutine monit3D_out_tmp(VAR)
  implicit none

  real(8), INTENT(IN) :: VAR(1:IMAX, 1:JMAX, 1:KMAX)
  real(4)             :: VAR_4(1:IMAX, 1:JMAX, 1:KMAX)
  VAR_4 = VAR
  write(monit3D_UID, rec=rcNO_3D)VAR_4
  rcNO_3D = rcNO_3D + 1

end subroutine monit3D_out_tmp

end module monit_out
