!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! $B%b%K%?!<$NEPO?(B
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutine monit_ini
  use com_monit, only: com_monit_ini_pre, com_monit_ini, sum_2, sum_3
  implicit none

  call com_monit_ini_pre

  call monit_regist                 &
& (1, '2D   ', 'HIGHT     ', 'SNP')  

  call monit_regist                 &
& (1, '2D   ', 'Hbnd      ', 'SNP')  
  call monit_regist                 &
& (1, '2D   ', 'uflux     ', 'AVR')  
  call monit_regist                 &
& (0, '2D   ', 'Usfc1     ', 'SNP')  


  call monit_regist                 &
& (1, '3D   ', 'Uvec1     ', 'SNP')  

  call monit_regist                 &
& (1, '3D   ', 'Wvec1     ', 'SNP')  
  call monit_regist                 &
& (1, '3D   ', 'Temp      ', 'SNP')  
  call monit_regist                 &
& (1, '3D   ', 'HOMOTEMP  ', 'SNP')  
  call monit_regist                 &
& (1, '3D   ', 'hoge      ', 'SNP')  
                     

  call com_monit_ini
  write(6, *) 'com_monit_ini=', shape(sum_2)
  write(6, *) 'com_monit_ini=', shape(sum_3)
  
end subroutine monit_ini


subroutine monit_regist(mswch, mtype, mname, mtflg)
  use com_monit, only: &
       & mxptr_2,      &
       & mxptr_3,      &
       & mxptr_nouse_2,&
       & mxptr_nouse_3,&
       & name_2       ,&
       & name_nouse_2 ,&
       & swch_2       ,&
       & tflg_2       ,&
       & name_3       ,&
       & name_nouse_3 ,&
       & swch_3       ,&
       & tflg_3        


  implicit none
  integer                         :: i
  integer           , INTENT(IN)  :: mswch  ! 0 (not write), 1(write)
  character(LEN=5)  , INTENT(IN)  :: mtype  ! 2D or 3D
  character(LEN=10) , INTENT(IN)  :: mname
  character(LEN=3)  , INTENT(IN)  :: mtflg  ! SNP or AVE
  
  if(mtflg /= 'SNP' .AND. mtflg /= 'AVR')THEN
     WRITE(6,*) 'tflg should be SNP or AVR. ',mname,' ',mtflg
     stop 'monit_regist'
  end if


  if ( mtype == '2D   ' ) then
     do i =1, mxptr_2
        if(mname == name_2(i))THEN
           write(6,*) 'The keyword was used :',mtype,mname
           stop 'monit_regist'
        end if
     end do
     if( (mswch == 1))then
        mxptr_2 = mxptr_2 + 1
        swch_2(mxptr_2) = mswch
        name_2(mxptr_2) = mname
        tflg_2(mxptr_2) = mtflg
     else
        mxptr_nouse_2 = mxptr_nouse_2 + 1
        name_nouse_2(mxptr_nouse_2) = mname
     end if
  elseif( mtype =='3D   ')then
     do i =1, mxptr_3
        if(mname == name_3(i))THEN
           write(6,*) 'The keyword was used :',mtype,mname
           stop 'monit_regist'
        end if
     end do
     if( (mswch == 1))then
        mxptr_3 = mxptr_3 + 1
        swch_3(mxptr_3) = mswch
        name_3(mxptr_3) = mname
        tflg_3(mxptr_3) = mtflg
     else
        mxptr_nouse_3 = mxptr_nouse_3 + 1
        name_nouse_3(mxptr_nouse_3) = mname
     end if
  end if

end subroutine monit_regist
