       subroutine smtone(lx,ly,x,y,z,mx,my,nu,nv,u,v,w)
C...01/09/78
       dimension x(lx),y(ly),z(lx,ly),u(nu),v(nv),w(nu,nv)
      dimension z1(2),ox(3),oy(3),o(3,3)
       lx0=lx
       ly0=ly
       lxm1=lx0-1
       lym1=ly0-1
       lxm2=lxm1-1
       lym2=lym1-1
       mx0=mx
       my0=my
       nu0=nu
       nv0=nv
       mxp1=mx+1
       myp1=my+1
       mxm1=mx-1
       mym1=my-1
       if(mxm1.le.0) go to 420
       if(mym1.le.0) go to 430
       if(nu0.ne.lxm1*mx0+1) go to 440
       if(nv0.ne.lym1*my0+1) go to 450
       if(lx0.le.2) go to 510
       do 10 ix=2,lx0
       if(x(ix-1)-x(ix)) 10,530,540
10     continue
       if(ly0.le.2) go to 520
       do 20 iy=2,ly0
       if(y(iy-1)-y(iy)) 20,550,560
20     continue
       rmx=1.0/mx0
       ku=1
       x4=x(1)
       u(1)=x4
       do 120 ix=2,lx0
       x3=x4
       x4=x(ix)
       du=(x4-x3)*rmx
       do 110 jx=1,mxm1
       ku=ku+1
       u(ku)=u(ku-1)+du
110    continue
       ku=ku+1
       u(ku)=x4
120    continue
       rmy=1.0/my0
       kv=1
       y4=y(1)
       v(1)=y4
       do 141 iy=2,ly0
       y3=y4
       y4=y(iy)
       dv=(y4-y3)*rmy
       do 130 jy=1,mym1
       kv=kv+1
       v(kv)=v(kv-1)+dv
130    continue
       kv=kv+1
       v(kv)=y4
141    continue
       jmx=mx0
       do 30 ix=1,lxm1
       if(ix.eq.lxm1) jmx=mxp1
       jmy=my0
       nx0=(ix-1)*mx0
       do 30 iy=1, lym1
       ny0=(iy-1)*my0
       if(iy.eq.lxm1) jmy=myp1
       do 30 jx=1,jmx
       nx=nx0+jx
       ux=u(nx)
       do 30 jy=1,jmy
       ny=ny0+jy
       uy=v(ny)
       ix1=ix+1
       iy1=iy+1
       ix2=ix1+1
       iy2=iy1+1
       ixm1=ix-1
       iym1=iy-1
       xix=x(ix)
       yiy=y(iy)
       dx=x(ix1)-xix
       dy=y(iy1)-yiy
       vx=(ux-xix)/dx
       vy=(uy-yiy)/dy
       qx1=vx*dx
       qy1=vy*dy
       vdx2=qx1*qx1
       vdy2=qy1*qy1
       ox(1)=xix
       ox(2)=x(ix1)
       oy(1)=yiy
       oy(2)=y(iy1)
       o(1,1)=z(ix,iy)
       o(1,2)=z(ix,iy1)
       o(2,1)=z(ix1,iy)
       o(2,2)=z(ix1,iy1)
       if(ix.eq.lxm1) go to 801
       if(iy.eq.lym1) go to 802
       ox(3)=x(ix2)
       oy(3)=y(iy2)
       o(1,3)=z(ix,iy2)
       o(2,3)=z(ix1,iy2)
       o(3,1)=z(ix2,iy)
       o(3,2)=z(ix2,iy1)
       o(3,3)=z(ix2,iy2)
       go to 703
801    ox(3)=x(lx0)-x(ixm1)+xix
       tloc=(x(ixm1)-ox(3))/dx
       if(iy.eq.lym1) go to 803
       oy(3)=y(iy2)
       o(1,3)=z(ix,iy2)
       o(2,3)=z(ix1,iy2)
       do 804 loc=1,3
       loc1=iym1+loc
804    o(3,loc)=z(ixm1,loc1)+(z(ix,loc1)-z(lx0,loc1))*tloc
       goto 703
802    ox(3)=x(ix2)
       oy(3)=y(ly0)-y(iym1)+yiy
       o(3,1)=z(ix2,iy)
       o(3,2)=z(ix2,iy1)
       tloc=(y(iym1)-oy(3))/dy
       do 805 loc=1,3
       loc1=ixm1+loc
805    o(loc,3)=z(loc1,iym1)+(z(loc1,iy)-z(loc1,ly0))*tloc
       go to 703
803    oy(3)=y(ly0)-y(iym1)+yiy
       o(3,1)=z(ixm1,iy)+(z(ix,iy)-z(lx0,iy))*tloc
       o(3,2)=z(ixm1,ly0)+(z(ix,ly0)-z(lx0,ly0))*tloc
       tloc=(y(iym1)-oy(3))/dy
       o(1,3)=z(ix,iym1)+(z(ix,iy)-z(ix,ly0))*tloc
       o(2,3)=z(lx0,iym1)+(z(lx0,iy)-z(lx0,ly0))*tloc
       o(3,3)=(o(3,2)+o(2,3))*0.5
703    qx2=0.5*vdx2*(vx-1.0)*(ox(3)-ox(1))/dx
       qy2=0.5*vdy2*(vy-1.0)*(oy(3)-oy(1))/dy
       i=1
      go to 170
140    ox(2)=xix
       ox(3)=x(ix1)
       oy(2)=yiy
       oy(3)=y(iy1)
       o(2,2)=z(ix,iy)
       o(2,3)=z(ix,iy1)
       o(3,2)=z(ix1,iy)
       o(3,3)=z(ix1,iy1)
       if(ix.eq.1) go to 901
       if(iy.eq.1) go to 902
       ox(1)=x(ixm1)
       oy(1)=y(iym1)
       o(1,1)=z(ixm1,iym1)
       o(1,2)=z(ixm1,iy)
       o(1,3)=z(ixm1,iy1)
       o(2,1)=z(ix,iym1)
       o(3,1)=z(ix1,iym1)
       go to 710
901    ox(1)=x(1)-x(3)+x(2)
       tloc=(ox(1)-x(3))/dx
       if(iy.eq.1) go to 903
       oy(1)=y(iym1)
       o(2,1)=z(1,iym1)
       o(3,1)=z(2,iym1)
       do 904 loc=1,3
       loc1=iym1-1+loc
904    o(1,loc)=z(3,loc1)+(z(2,loc1)-z(1,loc1))*tloc
       go to 710
902    ox(1)=x(ixm1)
       oy(1)=y(1)-y(3)+y(2)
       go to 710
903    oy(1)=y(1)+y(2)-y(3)
       o(1,2)=z(3,1)+(z(2,1)-z(1,1))*tloc
       o(1,3)=z(3,2)+(z(2,2)-z(1,2))*tloc
       tloc=(oy(1)-y(3))/dy
       o(2,1)=z(1,3)+(z(1,2)-z(1,1))*tloc
       o(3,1)=z(2,3)+(z(2,2)-z(2,1))*tloc
       o(1,1)=(o(1,2)+o(2,1))*0.5
710    xm1=(ox(1)-ox(2))/dx
       ym1=(oy(1)-oy(2))/dy
       qx1=(vx-xm1)*dx
       qy1=(vy-ym1)*dy
       qx2=0.5*(1.0-xm1)*vdx2*(2.0-vx)
       qy2=0.5*(1.0-ym1)*vdy2*(2.0-vy       )
       i=2
170    x10=ox(2)-ox(1)
       y10=oy(2)-oy(1)
       s3=qx2/(ox(3)-ox(1))
       s4=qy2/(oy(3)-oy(1))
       s5=s3/(ox(3)-ox(2))
       s6=s4/(oy(3)-oy(2))
       s3=s3/x10
       s4=s4/y10
       s1=qx1/x10
      s2=qy1/y10
      s12=s1*s2
      s14=s1*s4
      s23=s2*s3
      s34=s3*s4
      s25=s2*s5
      s45=s4*s5
      s16=s1*s6
      s36=s3*s6
      z21=s25+s25-4.*s45
      z12=s16+s16-4.*s36
      z20=s5+s5-z21
      z02=s6+s6-z12
      z22=4.*s5*s6
      z21=z21-z22
      z00=s12-s14-s14-s23-s23+4.*s34
      z001=s2-s4-s4
      z002=s1-s3-s3
      z01=z001-z00-z02
      z10=z002-z00-z20
      z11=z00-z21-z12
      z12=z12-z22
      z00=z00-z001-z002+1.
      z1(i)=z00*o(1,1)+z10*o(2,1)+z01*o(1,2)+z11*o(2,2)+
     +z22*o(3,3)+z20*o(3,1)+z02*o(1,3)+z21*o(3,2)+z12*o(2,3)
       if(i.eq.1) go to 140
       w(nx,ny)=0.5*(z1(1)+z1(2))
30    continue
      return
420    write (*,620)
       go to 590
430    write (*,630)
       go to 590
440    write (*,640)
       go to 590
450    write (*,650)
       go to 590
510   write (*,310)
      go to 590
520   write (*,320)
      go to 590
530   write (*,330)
      go to 590
540   write (*,340)
      go to 590
550   write (*,350)
      go to 590
560   write (*,360)
590   write (*,390)
310   format('   ***  LX LESS 3')
390   format('   ***  ERROR DETECTED IN ROUTINE   SMTONE')
320   format('   ***  LY LESS 3')
 330     format('   ***  X(I) EQUAL X(I+1)')
340   format('   ***  X(I) GREATER X(I+1)')
 350     format('   ***  Y(I) EQUAL Y(I+1)')
360   format('   ***  Y(I) GREATER Y(I+1)')
620    format('   ***  MX LESS TWO')
630    format ('   ***  MY LESS TWO')
 640    format('   ***  NU NOT EQUAL (LX-1)*NX+1')
 650    format('   ***  NV NOT EQUAL (LY-1)*NY+1')
      return
       end


module da_vtox_transforms

   !---------------------------------------------------------------------------
   ! Purpose: Contains routines used to transform control variable V to model
   !          variables X.
   !---------------------------------------------------------------------------

   use module_dm, only : wrf_dm_sum_real,wrf_dm_sum_reals
#ifdef DM_PARALLEL
   use module_dm, only : local_communicator, mytask, ntasks, ntasks_x, &
      ntasks_y, data_order_xy, data_order_xyz
   use module_comm_dm, only : halo_psichi_uv_adj_sub,halo_ssmi_xa_sub,halo_sfc_xa_sub, &
      halo_radar_xa_w_sub, halo_xa_sub, halo_psichi_uv_sub, &
      halo_psichi_uv_sub, halo_xa_wpec_sub,halo_xb_wpec_sub
   use da_par_util, only : true_mpi_real, mpi_sum, comm
#endif
   use module_domain, only : xb_type, xpose_type, ep_type, vp_type, x_type, domain, get_ijk_from_grid
   use module_domain, only : x_subtype

#ifdef A2C
   use da_control, only : trace_use, var4d, cos_xls, cos_xle, sin_xle, sin_xls, pi, global, &
      vertical_ip,alphacv_method,use_ssmitbobs,use_rainobs, &
      use_radarobs,use_radar_rf,use_radar_rhv,use_radar_rqv, &
      use_ssmiretrievalobs, use_ssmt2obs, use_ssmt1obs, use_gpspwobs, use_gpsztdobs, &
      use_gpsrefobs,use_gpsephobs,sfc_assi_options, test_transforms, vert_corr, fg_format, &
      fg_format_kma_global, fg_format_wrf_arw_regional,fg_format_wrf_nmm_regional, &
      stdout, use_rad, crtm_cloud, vert_corr_2, fg_format_wrf_arw_global, &
      alphacv_method_vp, alphacv_method_xa, vertical_ip_0, trace_use_dull,&
      ids,ide,jds,jde,kds,kde, ims,ime,jms,jme,kms,kme, cv_options_hum, &
      its,ite,jts,jte,kts,kte, ips,ipe,jps,jpe,kps,kpe, cv_size, cv_options, &
      use_background_errors
#else
   use da_control, only : trace_use, var4d, ims,ime,jms,jme,kms,kme,jds,jde,kds,kde, &
      its,ite,jts,jte,kts,kte, cos_xls, cos_xle, sin_xle, sin_xls, pi, global, &
      vertical_ip,alphacv_method,use_ssmitbobs,use_rainobs, &
      use_radarobs,use_radar_rf,use_radar_rhv,use_radar_rqv, &
      use_ssmiretrievalobs, use_ssmt2obs, use_ssmt1obs, use_gpspwobs, use_gpsztdobs, &
      use_gpsrefobs,use_gpsephobs,sfc_assi_options, test_transforms, vert_corr, fg_format, &
      fg_format_kma_global, fg_format_wrf_arw_regional,fg_format_wrf_nmm_regional, &
      ids, ide, stdout, use_rad, crtm_cloud, vert_corr_2, fg_format_wrf_arw_global, &
      alphacv_method_vp, alphacv_method_xa, vertical_ip_0, trace_use_dull, &
      ips,ipe,jps,jpe,kps,kpe, cv_size, cv_options, cv_options_hum, cloud_cv_options, &
      use_background_errors,do_normalize,use_rf,len_scaling1, len_scaling2, len_scaling3, len_scaling4, &
      len_scaling5, len_scaling6, len_scaling7, len_scaling8, len_scaling9, len_scaling10, len_scaling11
#endif

   use da_control, only : anal_type_hybrid_dual_res, myproc, num_procs,dual_res_upscale_opt, &
                          ensdim_alpha
   use da_control, only : its_int,ite_int,jts_int,jte_int,kts_int,kte_int,shw, &
                          ims_int,ime_int,jms_int,jme_int,kms_int,kme_int, &
                          ids_int,ide_int,jds_int,jde_int,kds_int,kde_int, &
                          ips_int,ipe_int,jps_int,jpe_int,kps_int,kpe_int
   use da_control, only : dual_res_type, aens_locs
   use da_control, only : c1h, c2h, use_cv_w, alpha_hydrometeors

   use da_define_structures, only : be_type, xbx_type,da_zero_vp_type,da_zero_x
   use da_dynamics, only : da_psichi_to_uv,da_psichi_to_uv_adj
   use da_physics, only : da_uvprho_to_w_lin,da_uvprho_to_w_adj, &
      da_pt_to_rho_adj, da_pt_to_rho_lin,da_moist_phys_lin, &
      da_tprh_to_q_lin, da_tprh_to_q_adj,       &
      da_moist_phys_adj, da_transform_xtogpsref_lin, da_transform_xtotpw, &
      da_transform_xtowtq, da_transform_xtotpw_adj, &
      da_transform_xtogpsref_adj, da_transform_xtowtq_adj, &
      da_transform_xtoztd_lin, da_transform_xtoztd_adj
   use da_par_util, only : da_vv_to_cv, da_cv_to_vv

   use da_recursive_filter, only : da_transform_through_rf, &
      da_transform_through_rf_adj, da_apply_rf, da_apply_rf_adj, &
      da_transform_through_rf_dual_res, da_transform_through_rf_adj_dual_res
   use da_reporting, only : da_error, message, da_warning, da_message
   use da_spectral, only : da_vtovv_spectral,da_vtovv_spectral_adj
   use da_ssmi, only : da_transform_xtoseasfcwind_lin,da_transform_xtotb_adj, &
      da_transform_xtoseasfcwind_adj, da_transform_xtotb_lin
   use da_tools, only : da_set_boundary_xa
   use da_tracing, only : da_trace_entry, da_trace_exit
   use da_wrf_interfaces, only : wrf_debug
   use da_wavelet, only: da_transform_through_wavelet, da_transform_through_wavelet_adj, nij

   implicit none

   contains

#include "da_add_flow_dependence_vp.inc"
#include "da_add_flow_dependence_vp_adj.inc"
#include "da_check_eof_decomposition.inc"
#include "da_transform_vtovv.inc"
#include "da_transform_vtovv_adj.inc"
#include "da_transform_rescale.inc"
#include "da_transform_vtox.inc"
#include "da_transform_xtoxa.inc"
#include "da_transform_vtox_adj.inc"
#include "da_transform_xtoxa_adj.inc"
#include "da_transform_vptox.inc"
#include "da_transform_vptox_adj.inc"
#include "da_transform_vvtovp.inc"
#include "da_transform_vvtovp_adj.inc"
#include "da_transform_vptovv.inc"
#include "da_transform_vpatox.inc"
#include "da_transform_vpatox_adj.inc"
#include "da_vertical_transform.inc"
#include "da_get_vpoles.inc"
#include "da_get_spoles.inc"
#include "da_get_avpoles.inc"
#include "da_get_aspoles.inc"
#include "da_transform_vtovv_global.inc"
#include "da_transform_vtovv_global_adj.inc"

#include "da_transform_bal.inc"
#include "da_transform_bal_adj.inc"
#include "da_apply_be.inc"
#include "da_apply_be_adj.inc"

#include "da_transform_vvtovp_dual_res.inc"
#include "da_transform_vvtovp_adj_dual_res.inc"

#include "da_copy_xa.inc"
#include "da_add_xa.inc"

#include "da_calc_flow_dependence_xa.inc"
#include "da_calc_flow_dependence_xa_dual_res.inc"
#include "da_calc_flow_dependence_xa_adj.inc"
#include "da_calc_flow_dependence_xa_adj_dual_res.inc"
#include "da_dual_res_c2n_ad.inc"

end module da_vtox_transforms


!-------------------------------------------------------------------------------
!> module ADMIN TIME
!!
!! @par Description
!!          Time management for SCALE-LES
!!
!! @author Team SCALE
!!
!<
module mod_admin_time
  !-----------------------------------------------------------------------------
  !
  !++ used modules
  !
  use scale_precision
  use scale_stdio
  use scale_prof
  !-----------------------------------------------------------------------------
  implicit none
  private
  !-----------------------------------------------------------------------------
  !
  !++ Public procedure
  !
  public :: ADMIN_TIME_setup
  public :: ADMIN_TIME_checkstate
  public :: ADMIN_TIME_advance

  !-----------------------------------------------------------------------------
  !
  !++ Public parameters & variables
  !
  real(DP), public :: TIME_DTSEC_ATMOS_RESTART  !< time interval of atmosphere restart    [sec]
  real(DP), public :: TIME_DTSEC_OCEAN_RESTART  !< time interval of ocean restart         [sec]
  real(DP), public :: TIME_DTSEC_LAND_RESTART   !< time interval of land restart          [sec]
  real(DP), public :: TIME_DTSEC_URBAN_RESTART  !< time interval of urban restart         [sec]

  integer,  public :: TIME_DSTEP_ATMOS_RESTART  !< time interval of atmosphere restart    [sec]
  integer,  public :: TIME_DSTEP_OCEAN_RESTART  !< time interval of ocean restart         [sec]
  integer,  public :: TIME_DSTEP_LAND_RESTART   !< time interval of land restart          [sec]
  integer,  public :: TIME_DSTEP_URBAN_RESTART  !< time interval of urban restart         [sec]

  logical,  public :: TIME_DOATMOS_step         !< execute atmospheric component in this step?
  logical,  public :: TIME_DOATMOS_DYN          !< execute dynamics?
  logical,  public :: TIME_DOATMOS_PHY_CP       !< execute physics(cumulus     )?
  logical,  public :: TIME_DOATMOS_PHY_MP       !< execute physics(microphysics)?
  logical,  public :: TIME_DOATMOS_PHY_RD       !< execute physics(radiation   )?
  logical,  public :: TIME_DOATMOS_PHY_SF       !< execute physics(surface flux)?
  logical,  public :: TIME_DOATMOS_PHY_TB       !< execute physics(turbulence  )?
  logical,  public :: TIME_DOATMOS_PHY_CH       !< execute physics(chemistry   )?
  logical,  public :: TIME_DOATMOS_PHY_AE       !< execute physics(aerosol     )?
  logical,  public :: TIME_DOATMOS_restart      !< execute atmosphere restart output?
  logical,  public :: TIME_DOOCEAN_step         !< execute ocean component in this step?
  logical,  public :: TIME_DOOCEAN_restart      !< execute ocean restart output?
  logical,  public :: TIME_DOLAND_step          !< execute land component in this step?
  logical,  public :: TIME_DOLAND_restart       !< execute land restart output?
  logical,  public :: TIME_DOURBAN_step         !< execute urban component in this step?
  logical,  public :: TIME_DOURBAN_restart      !< execute urban restart output?
  logical,  public :: TIME_DOend                !< finish program in this step?

  !-----------------------------------------------------------------------------
  !
  !++ Private procedure
  !
  !-----------------------------------------------------------------------------
  !
  !++ Private parameters & variables
  !
  integer,  private :: TIME_STARTDATE(6) = (/ 0, 1, 1, 0, 0, 0 /)
  real(DP), private :: TIME_STARTMS      = 0.0_DP !< [millisec]
  integer,  private :: TIME_STARTDAY
  real(DP), private :: TIME_STARTSEC

  integer,  private :: TIME_ENDDATE(6)
  real(DP), private :: TIME_ENDMS
  integer,  private :: TIME_ENDDAY
  real(DP), private :: TIME_ENDSEC

  integer,  private :: TIME_RES_ATMOS_DYN     = 0
  integer,  private :: TIME_RES_ATMOS_PHY_CP  = 0
  integer,  private :: TIME_RES_ATMOS_PHY_MP  = 0
  integer,  private :: TIME_RES_ATMOS_PHY_RD  = 0
  integer,  private :: TIME_RES_ATMOS_PHY_SF  = 0
  integer,  private :: TIME_RES_ATMOS_PHY_TB  = 0
  integer,  private :: TIME_RES_ATMOS_PHY_CH  = 0
  integer,  private :: TIME_RES_ATMOS_PHY_AE  = 0
  integer,  private :: TIME_RES_ATMOS_RESTART = 0
  integer,  private :: TIME_RES_OCEAN         = 0
  integer,  private :: TIME_RES_OCEAN_RESTART = 0
  integer,  private :: TIME_RES_LAND          = 0
  integer,  private :: TIME_RES_LAND_RESTART  = 0
  integer,  private :: TIME_RES_URBAN         = 0
  integer,  private :: TIME_RES_URBAN_RESTART = 0

  real(DP), private :: TIME_WALLCLOCK_START             ! Start time of wall clock             [sec]
  real(DP), private :: TIME_WALLCLOCK_LIMIT   = -1.0_DP ! Elapse time limit of wall clock time [sec]
  real(DP), private :: TIME_WALLCLOCK_SAFE    =  0.9_DP ! Safety coefficient for elapse time limit

  real(DP), private, parameter :: eps = 1.E-6_DP !> epsilon for timesec

  !-----------------------------------------------------------------------------
contains
  !-----------------------------------------------------------------------------
  !> Setup
  subroutine ADMIN_TIME_setup( &
       setup_TimeIntegration )
    use scale_process, only: &
       PRC_MPIstop, &
       PRC_MPItime
    use scale_const, only: &
       UNDEF8 => CONST_UNDEF8
    use scale_calendar, only: &
       CALENDAR_date2daysec,    &
       CALENDAR_daysec2date,    &
       CALENDAR_adjust_daysec,  &
       CALENDAR_combine_daysec, &
       CALENDAR_unit2sec,       &
       CALENDAR_date2char
    use scale_time, only: &
       TIME_DTSEC,                 &
       TIME_NOWDATE,               &
       TIME_NOWMS,                 &
       TIME_NOWDAY,                &
       TIME_NOWSEC,                &
       TIME_NOWDAYSEC,             &
       TIME_NOWSTEP,               &
       TIME_NSTEP,                 &
       TIME_DTSEC_ATMOS_DYN,       &
       TIME_NSTEP_ATMOS_DYN,       &
       TIME_DTSEC_ATMOS_PHY_CP,    &
       TIME_DTSEC_ATMOS_PHY_MP,    &
       TIME_DTSEC_ATMOS_PHY_RD,    &
       TIME_DTSEC_ATMOS_PHY_SF,    &
       TIME_DTSEC_ATMOS_PHY_TB,    &
       TIME_DTSEC_ATMOS_PHY_CH,    &
       TIME_DTSEC_ATMOS_PHY_AE,    &
       TIME_DTSEC_OCEAN,           &
       TIME_DTSEC_LAND,            &
       TIME_DTSEC_URBAN,           &
       TIME_DTSEC_WALLCLOCK_CHECK, &
       TIME_DSTEP_ATMOS_DYN,       &
       TIME_DSTEP_ATMOS_PHY_CP,    &
       TIME_DSTEP_ATMOS_PHY_MP,    &
       TIME_DSTEP_ATMOS_PHY_RD,    &
       TIME_DSTEP_ATMOS_PHY_SF,    &
       TIME_DSTEP_ATMOS_PHY_TB,    &
       TIME_DSTEP_ATMOS_PHY_CH,    &
       TIME_DSTEP_ATMOS_PHY_AE,    &
       TIME_DSTEP_OCEAN,           &
       TIME_DSTEP_LAND,            &
       TIME_DSTEP_URBAN,           &
       TIME_DSTEP_WALLCLOCK_CHECK, &
       TIME_OFFSET_YEAR,           &
       TIME_STARTDAYSEC
    implicit none

    logical, intent(in) :: setup_TimeIntegration

    real(DP)               :: TIME_DURATION                = UNDEF8
    character(len=H_SHORT) :: TIME_DURATION_UNIT           = "SEC"
    real(DP)               :: TIME_DT                      = UNDEF8
    character(len=H_SHORT) :: TIME_DT_UNIT                 = "SEC"

    real(DP)               :: TIME_DT_ATMOS_DYN            = UNDEF8
    character(len=H_SHORT) :: TIME_DT_ATMOS_DYN_UNIT       = "SEC"
    real(DP)               :: TIME_DT_ATMOS_PHY_CP         = UNDEF8
    character(len=H_SHORT) :: TIME_DT_ATMOS_PHY_CP_UNIT    = ""
    real(DP)               :: TIME_DT_ATMOS_PHY_MP         = UNDEF8
    character(len=H_SHORT) :: TIME_DT_ATMOS_PHY_MP_UNIT    = ""
    real(DP)               :: TIME_DT_ATMOS_PHY_RD         = UNDEF8
    character(len=H_SHORT) :: TIME_DT_ATMOS_PHY_RD_UNIT    = ""
    real(DP)               :: TIME_DT_ATMOS_PHY_SF         = UNDEF8
    character(len=H_SHORT) :: TIME_DT_ATMOS_PHY_SF_UNIT    = ""
    real(DP)               :: TIME_DT_ATMOS_PHY_TB         = UNDEF8
    character(len=H_SHORT) :: TIME_DT_ATMOS_PHY_TB_UNIT    = ""
    real(DP)               :: TIME_DT_ATMOS_PHY_CH         = UNDEF8
    character(len=H_SHORT) :: TIME_DT_ATMOS_PHY_CH_UNIT    = ""
    real(DP)               :: TIME_DT_ATMOS_PHY_AE         = UNDEF8
    character(len=H_SHORT) :: TIME_DT_ATMOS_PHY_AE_UNIT    = ""
    real(DP)               :: TIME_DT_ATMOS_RESTART        = UNDEF8
    character(len=H_SHORT) :: TIME_DT_ATMOS_RESTART_UNIT   = ""

    real(DP)               :: TIME_DT_OCEAN                = UNDEF8
    character(len=H_SHORT) :: TIME_DT_OCEAN_UNIT           = ""
    real(DP)               :: TIME_DT_OCEAN_RESTART        = UNDEF8
    character(len=H_SHORT) :: TIME_DT_OCEAN_RESTART_UNIT   = ""

    real(DP)               :: TIME_DT_LAND                 = UNDEF8
    character(len=H_SHORT) :: TIME_DT_LAND_UNIT            = ""
    real(DP)               :: TIME_DT_LAND_RESTART         = UNDEF8
    character(len=H_SHORT) :: TIME_DT_LAND_RESTART_UNIT    = ""

    real(DP)               :: TIME_DT_URBAN                = UNDEF8
    character(len=H_SHORT) :: TIME_DT_URBAN_UNIT           = ""
    real(DP)               :: TIME_DT_URBAN_RESTART        = UNDEF8
    character(len=H_SHORT) :: TIME_DT_URBAN_RESTART_UNIT   = ""

    real(DP)               :: TIME_DT_WALLCLOCK_CHECK      = UNDEF8
    character(len=H_SHORT) :: TIME_DT_WALLCLOCK_CHECK_UNIT = ""

    NAMELIST / PARAM_TIME / &
       TIME_STARTDATE,               &
       TIME_STARTMS,                 &
       TIME_DURATION,                &
       TIME_DURATION_UNIT,           &
       TIME_DT,                      &
       TIME_DT_UNIT,                 &
       TIME_DT_ATMOS_DYN,            &
       TIME_DT_ATMOS_DYN_UNIT,       &
       TIME_DT_ATMOS_PHY_CP,         &
       TIME_DT_ATMOS_PHY_CP_UNIT,    &
       TIME_DT_ATMOS_PHY_MP,         &
       TIME_DT_ATMOS_PHY_MP_UNIT,    &
       TIME_DT_ATMOS_PHY_RD,         &
       TIME_DT_ATMOS_PHY_RD_UNIT,    &
       TIME_DT_ATMOS_PHY_SF,         &
       TIME_DT_ATMOS_PHY_SF_UNIT,    &
       TIME_DT_ATMOS_PHY_TB,         &
       TIME_DT_ATMOS_PHY_TB_UNIT,    &
       TIME_DT_ATMOS_PHY_CH,         &
       TIME_DT_ATMOS_PHY_CH_UNIT,    &
       TIME_DT_ATMOS_PHY_AE,         &
       TIME_DT_ATMOS_PHY_AE_UNIT,    &
       TIME_DT_ATMOS_RESTART,        &
       TIME_DT_ATMOS_RESTART_UNIT,   &
       TIME_DT_OCEAN,                &
       TIME_DT_OCEAN_UNIT,           &
       TIME_DT_OCEAN_RESTART,        &
       TIME_DT_OCEAN_RESTART_UNIT,   &
       TIME_DT_LAND,                 &
       TIME_DT_LAND_UNIT,            &
       TIME_DT_LAND_RESTART,         &
       TIME_DT_LAND_RESTART_UNIT,    &
       TIME_DT_URBAN,                &
       TIME_DT_URBAN_UNIT,           &
       TIME_DT_URBAN_RESTART,        &
       TIME_DT_URBAN_RESTART_UNIT,   &
       TIME_DT_WALLCLOCK_CHECK,      &
       TIME_DT_WALLCLOCK_CHECK_UNIT, &
       TIME_WALLCLOCK_LIMIT,         &
       TIME_WALLCLOCK_SAFE

    real(DP)          :: TIME_DURATIONSEC
    character(len=27) :: startchardate
    character(len=27) :: endchardate

    integer :: ierr
    !---------------------------------------------------------------------------

    if( IO_L ) write(IO_FID_LOG,*)
    if( IO_L ) write(IO_FID_LOG,*) '++++++ Module[TIME] / Categ[COMMON] / Origin[SCALElib]'

    !--- read namelist
    rewind(IO_FID_CONF)
    read(IO_FID_CONF,nml=PARAM_TIME,iostat=ierr)
    if( ierr < 0 ) then !--- missing
       if( IO_L ) write(IO_FID_LOG,*) '*** Not found namelist. Default used.'
    elseif( ierr > 0 ) then !--- fatal error
       write(*,*) 'xxx Not appropriate names in namelist PARAM_TIME. Check!'
       call PRC_MPIstop
    endif

    if( IO_LNML ) write(IO_FID_LOG,nml=PARAM_TIME)

    ! check time setting
    if ( setup_TimeIntegration ) then
       if ( TIME_DT == UNDEF8 ) then
          write(*,*) 'xxx Not found TIME_DT.'
          call PRC_MPIstop
       endif
       if ( TIME_DURATION == UNDEF8 ) then
          write(*,*) 'xxx Not found TIME_DURATION.'
          call PRC_MPIstop
       endif

       ! DYN
       if ( TIME_DT_ATMOS_DYN == UNDEF8 ) then
          if( IO_L ) write(IO_FID_LOG,*) '*** Not found TIME_DT_ATMOS_DYN. TIME_DT is used.'
          TIME_DT_ATMOS_DYN = TIME_DT
       endif
       if ( TIME_DT_ATMOS_DYN_UNIT == '' ) then
          if( IO_L ) write(IO_FID_LOG,*) '*** Not found TIME_DT_ATMOS_DYN_UNIT. TIME_DT_UNIT is used.'
          TIME_DT_ATMOS_DYN_UNIT = TIME_DT_UNIT
       endif
       ! PHY_CP
       if ( TIME_DT_ATMOS_PHY_CP == UNDEF8 ) then
          if( IO_L ) write(IO_FID_LOG,*) '*** Not found TIME_DT_ATMOS_PHY_CP. TIME_DT is used.'
          TIME_DT_ATMOS_PHY_CP = TIME_DT
       endif
       if ( TIME_DT_ATMOS_PHY_CP_UNIT == '' ) then
          if( IO_L ) write(IO_FID_LOG,*) '*** Not found TIME_DT_ATMOS_PHY_CP_UNIT. TIME_DT_UNIT is used.'
          TIME_DT_ATMOS_PHY_CP_UNIT = TIME_DT_UNIT
       endif
       ! PHY_MP
       if ( TIME_DT_ATMOS_PHY_MP == UNDEF8 ) then
          if( IO_L ) write(IO_FID_LOG,*) '*** Not found TIME_DT_ATMOS_PHY_MP. TIME_DT is used.'
          TIME_DT_ATMOS_PHY_MP = TIME_DT
       endif
       if ( TIME_DT_ATMOS_PHY_MP_UNIT == '' ) then
          if( IO_L ) write(IO_FID_LOG,*) '*** Not found TIME_DT_ATMOS_PHY_MP_UNIT. TIME_DT_UNIT is used.'
          TIME_DT_ATMOS_PHY_MP_UNIT = TIME_DT_UNIT
       endif
       ! PHY_RD
       if ( TIME_DT_ATMOS_PHY_RD == UNDEF8 ) then
          if( IO_L ) write(IO_FID_LOG,*) '*** Not found TIME_DT_ATMOS_PHY_RD. TIME_DT is used.'
          TIME_DT_ATMOS_PHY_RD = TIME_DT
       endif
       if ( TIME_DT_ATMOS_PHY_RD_UNIT == '' ) then
          if( IO_L ) write(IO_FID_LOG,*) '*** Not found TIME_DT_ATMOS_PHY_RD_UNIT. TIME_DT_UNIT is used.'
          TIME_DT_ATMOS_PHY_RD_UNIT = TIME_DT_UNIT
       endif
       ! PHY_SF
       if ( TIME_DT_ATMOS_PHY_SF == UNDEF8 ) then
          if( IO_L ) write(IO_FID_LOG,*) '*** Not found TIME_DT_ATMOS_PHY_SF. TIME_DT is used.'
          TIME_DT_ATMOS_PHY_SF = TIME_DT
       endif
       if ( TIME_DT_ATMOS_PHY_SF_UNIT == '' ) then
          if( IO_L ) write(IO_FID_LOG,*) '*** Not found TIME_DT_ATMOS_PHY_SF_UNIT. TIME_DT_UNIT is used.'
          TIME_DT_ATMOS_PHY_SF_UNIT = TIME_DT_UNIT
       endif
       ! PHY_TB
       if ( TIME_DT_ATMOS_PHY_TB == UNDEF8 ) then
          if( IO_L ) write(IO_FID_LOG,*) '*** Not found TIME_DT_ATMOS_PHY_TB. TIME_DT is used.'
          TIME_DT_ATMOS_PHY_TB = TIME_DT
       endif
       if ( TIME_DT_ATMOS_PHY_TB_UNIT == '' ) then
          if( IO_L ) write(IO_FID_LOG,*) '*** Not found TIME_DT_ATMOS_PHY_TB_UNIT. TIME_DT_UNIT is used.'
          TIME_DT_ATMOS_PHY_TB_UNIT = TIME_DT_UNIT
       endif
       ! PHY_CH
       if ( TIME_DT_ATMOS_PHY_CH == UNDEF8 ) then
          if( IO_L ) write(IO_FID_LOG,*) '*** Not found TIME_DT_ATMOS_PHY_CH. TIME_DT is used.'
          TIME_DT_ATMOS_PHY_CH = TIME_DT
       endif
       if ( TIME_DT_ATMOS_PHY_CH_UNIT == '' ) then
          if( IO_L ) write(IO_FID_LOG,*) '*** Not found TIME_DT_ATMOS_PHY_CH_UNIT. TIME_DT_UNIT is used.'
          TIME_DT_ATMOS_PHY_CH_UNIT = TIME_DT_UNIT
       endif
       ! PHY_AE
       if ( TIME_DT_ATMOS_PHY_AE == UNDEF8 ) then
          if( IO_L ) write(IO_FID_LOG,*) '*** Not found TIME_DT_ATMOS_PHY_AE. TIME_DT is used.'
          TIME_DT_ATMOS_PHY_AE = TIME_DT
       endif
       if ( TIME_DT_ATMOS_PHY_AE_UNIT == '' ) then
          if( IO_L ) write(IO_FID_LOG,*) '*** Not found TIME_DT_ATMOS_PHY_AE_UNIT. TIME_DT_UNIT is used.'
          TIME_DT_ATMOS_PHY_AE_UNIT = TIME_DT_UNIT
       endif
       ! ATMOS RESTART
       if ( TIME_DT_ATMOS_RESTART == UNDEF8 ) then
          if( IO_L ) write(IO_FID_LOG,*) '*** Not found TIME_DT_ATMOS_RESTART. TIME_DURATION is used.'
          TIME_DT_ATMOS_RESTART = TIME_DURATION
       endif
       if ( TIME_DT_ATMOS_RESTART_UNIT == '' ) then
          if( IO_L ) write(IO_FID_LOG,*) '*** Not found TIME_DT_ATMOS_RESTART_UNIT. TIME_DURATION_UNIT is used.'
          TIME_DT_ATMOS_RESTART_UNIT = TIME_DURATION_UNIT
       endif
       ! OCEAN
       if ( TIME_DT_OCEAN == UNDEF8 ) then
          if( IO_L ) write(IO_FID_LOG,*) '*** Not found TIME_DT_OCEAN. TIME_DT is used.'
          TIME_DT_OCEAN = TIME_DT
       endif
       if ( TIME_DT_OCEAN_UNIT == '' ) then
          if( IO_L ) write(IO_FID_LOG,*) '*** Not found TIME_DT_OCEAN_UNIT. TIME_DT_UNIT is used.'
          TIME_DT_OCEAN_UNIT = TIME_DT_UNIT
       endif
       ! OCEAN RESTART
       if ( TIME_DT_OCEAN_RESTART == UNDEF8 ) then
          if( IO_L ) write(IO_FID_LOG,*) '*** Not found TIME_DT_OCEAN_RESTART. TIME_DURATION is used.'
          TIME_DT_OCEAN_RESTART = TIME_DURATION
       endif
       if ( TIME_DT_OCEAN_RESTART_UNIT == '' ) then
          if( IO_L ) write(IO_FID_LOG,*) '*** Not found TIME_DT_OCEAN_RESTART_UNIT. TIME_DURATION_UNIT is used.'
          TIME_DT_OCEAN_RESTART_UNIT = TIME_DURATION_UNIT
       endif
       ! LAND
       if ( TIME_DT_LAND == UNDEF8 ) then
          if( IO_L ) write(IO_FID_LOG,*) '*** Not found TIME_DT_LAND. TIME_DT is used.'
          TIME_DT_LAND = TIME_DT
       endif
       if ( TIME_DT_LAND_UNIT == '' ) then
          if( IO_L ) write(IO_FID_LOG,*) '*** Not found TIME_DT_LAND_UNIT. TIME_DT_UNIT is used.'
          TIME_DT_LAND_UNIT = TIME_DT_UNIT
       endif
       ! LAND RESTART
       if ( TIME_DT_LAND_RESTART == UNDEF8 ) then
          if( IO_L ) write(IO_FID_LOG,*) '*** Not found TIME_DT_LAND_RESTART. TIME_DURATION is used.'
          TIME_DT_LAND_RESTART = TIME_DURATION
       endif
       if ( TIME_DT_LAND_RESTART_UNIT == '' ) then
          if( IO_L ) write(IO_FID_LOG,*) '*** Not found TIME_DT_LAND_RESTART_UNIT. TIME_DURATION_UNIT is used.'
          TIME_DT_LAND_RESTART_UNIT = TIME_DURATION_UNIT
       endif
       ! URBAN
       if ( TIME_DT_URBAN == UNDEF8 ) then
          if( IO_L ) write(IO_FID_LOG,*) '*** Not found TIME_DT_URBAN. TIME_DT is used.'
          TIME_DT_URBAN = TIME_DT
       endif
       if ( TIME_DT_URBAN_UNIT == '' ) then
          if( IO_L ) write(IO_FID_LOG,*) '*** Not found TIME_DT_URBAN_UNIT. TIME_DT_UNIT is used.'
          TIME_DT_URBAN_UNIT = TIME_DT_UNIT
       endif
       ! URBAN RESTART
       if ( TIME_DT_URBAN_RESTART == UNDEF8 ) then
          if( IO_L ) write(IO_FID_LOG,*) '*** Not found TIME_DT_URBAN_RESTART. TIME_DURATION is used.'
          TIME_DT_URBAN_RESTART = TIME_DURATION
       endif
       if ( TIME_DT_URBAN_RESTART_UNIT == '' ) then
          if( IO_L ) write(IO_FID_LOG,*) '*** Not found TIME_DT_URBAN_RESTART_UNIT. TIME_DURATION_UNIT is used.'
          TIME_DT_URBAN_RESTART_UNIT = TIME_DURATION_UNIT
       endif
    endif

    !--- calculate time
    TIME_STARTMS      = TIME_STARTMS * 1.E-3_DP
    TIME_OFFSET_YEAR  = TIME_STARTDATE(1)
    TIME_STARTDATE(1) = 0
    call CALENDAR_date2daysec( TIME_STARTDAY,     & ! [OUT]
                               TIME_STARTSEC,     & ! [OUT]
                               TIME_STARTDATE(:), & ! [IN]
                               TIME_STARTMS,      & ! [IN]
                               TIME_OFFSET_YEAR   ) ! [IN]

    call CALENDAR_date2char( startchardate,     & ! [OUT]
                             TIME_STARTDATE(:), & ! [IN]
                             TIME_STARTMS,      & ! [IN]
                             TIME_OFFSET_YEAR   ) ! [IN]

    TIME_STARTDAYSEC  = CALENDAR_combine_daysec( TIME_STARTDAY, TIME_STARTSEC )

    TIME_NOWDATE(:)   = TIME_STARTDATE(:)
    TIME_NOWMS        = TIME_STARTMS
    TIME_NOWDAY       = TIME_STARTDAY
    TIME_NOWSEC       = TIME_STARTSEC
    TIME_NOWDAYSEC    = CALENDAR_combine_daysec( TIME_NOWDAY, TIME_NOWSEC )

    TIME_ENDDAY       = TIME_STARTDAY

    if ( setup_TimeIntegration ) then
       call CALENDAR_unit2sec( TIME_DURATIONSEC, TIME_DURATION, TIME_DURATION_UNIT )
       TIME_ENDSEC = TIME_STARTSEC + TIME_DURATIONSEC
    else
       TIME_ENDSEC = TIME_STARTSEC
    endif

    call CALENDAR_adjust_daysec( TIME_ENDDAY, TIME_ENDSEC ) ! [INOUT]

    call CALENDAR_daysec2date( TIME_ENDDATE(:), & ! [OUT]
                               TIME_ENDMS,      & ! [OUT]
                               TIME_ENDDAY,     & ! [IN]
                               TIME_ENDSEC,     & ! [IN]
                               TIME_OFFSET_YEAR ) ! [IN]

    call CALENDAR_date2char( endchardate,     & ! [OUT]
                             TIME_ENDDATE(:), & ! [IN]
                             TIME_ENDMS,      & ! [IN]
                             TIME_OFFSET_YEAR ) ! [IN]

    if( IO_L ) write(IO_FID_LOG,*)
    if( IO_L ) write(IO_FID_LOG,*) '*** Date/time setting ***'
    if( IO_L ) write(IO_FID_LOG,'(1x,A,A)') '*** START Date     : ', startchardate
    if( IO_L ) write(IO_FID_LOG,'(1x,A,A)') '*** END   Date     : ', endchardate

    if ( setup_TimeIntegration ) then

       call CALENDAR_unit2sec( TIME_DTSEC, TIME_DT, TIME_DT_UNIT )

       TIME_NSTEP   = int( TIME_DURATIONSEC / TIME_DTSEC )
       TIME_NOWSTEP = 1

       if( IO_L ) write(IO_FID_LOG,'(1x,A,F10.3)') '*** delta t (sec.) :', TIME_DTSEC
       if( IO_L ) write(IO_FID_LOG,'(1x,A,I10)'  ) '*** No. of steps   :', TIME_NSTEP

       !--- calculate intervals for atmosphere
       call CALENDAR_unit2sec( TIME_DTSEC_ATMOS_DYN,     TIME_DT_ATMOS_DYN,     TIME_DT_ATMOS_DYN_UNIT     )
       call CALENDAR_unit2sec( TIME_DTSEC_ATMOS_PHY_CP,  TIME_DT_ATMOS_PHY_CP,  TIME_DT_ATMOS_PHY_CP_UNIT  )
       call CALENDAR_unit2sec( TIME_DTSEC_ATMOS_PHY_MP,  TIME_DT_ATMOS_PHY_MP,  TIME_DT_ATMOS_PHY_MP_UNIT  )
       call CALENDAR_unit2sec( TIME_DTSEC_ATMOS_PHY_RD,  TIME_DT_ATMOS_PHY_RD,  TIME_DT_ATMOS_PHY_RD_UNIT  )
       call CALENDAR_unit2sec( TIME_DTSEC_ATMOS_PHY_SF,  TIME_DT_ATMOS_PHY_SF,  TIME_DT_ATMOS_PHY_SF_UNIT  )
       call CALENDAR_unit2sec( TIME_DTSEC_ATMOS_PHY_TB,  TIME_DT_ATMOS_PHY_TB,  TIME_DT_ATMOS_PHY_TB_UNIT  )
       call CALENDAR_unit2sec( TIME_DTSEC_ATMOS_PHY_CH,  TIME_DT_ATMOS_PHY_CH,  TIME_DT_ATMOS_PHY_CH_UNIT  )
       call CALENDAR_unit2sec( TIME_DTSEC_ATMOS_PHY_AE,  TIME_DT_ATMOS_PHY_AE,  TIME_DT_ATMOS_PHY_AE_UNIT  )
       call CALENDAR_unit2sec( TIME_DTSEC_ATMOS_RESTART, TIME_DT_ATMOS_RESTART, TIME_DT_ATMOS_RESTART_UNIT )
       call CALENDAR_unit2sec( TIME_DTSEC_OCEAN,         TIME_DT_OCEAN,         TIME_DT_OCEAN_UNIT         )
       call CALENDAR_unit2sec( TIME_DTSEC_OCEAN_RESTART, TIME_DT_OCEAN_RESTART, TIME_DT_OCEAN_RESTART_UNIT )
       call CALENDAR_unit2sec( TIME_DTSEC_LAND,          TIME_DT_LAND,          TIME_DT_LAND_UNIT          )
       call CALENDAR_unit2sec( TIME_DTSEC_LAND_RESTART,  TIME_DT_LAND_RESTART,  TIME_DT_LAND_RESTART_UNIT  )
       call CALENDAR_unit2sec( TIME_DTSEC_URBAN,         TIME_DT_URBAN,         TIME_DT_URBAN_UNIT         )
       call CALENDAR_unit2sec( TIME_DTSEC_URBAN_RESTART, TIME_DT_URBAN_RESTART, TIME_DT_URBAN_RESTART_UNIT )

       TIME_NSTEP_ATMOS_DYN = max( nint( TIME_DTSEC / TIME_DTSEC_ATMOS_DYN ), 1 )

       TIME_DTSEC_ATMOS_DYN     = max( TIME_DTSEC_ATMOS_DYN,     TIME_DTSEC          /TIME_NSTEP_ATMOS_DYN )
       TIME_DTSEC_ATMOS_PHY_CP  = max( TIME_DTSEC_ATMOS_PHY_CP,  TIME_DTSEC_ATMOS_DYN*TIME_NSTEP_ATMOS_DYN )
       TIME_DTSEC_ATMOS_PHY_MP  = max( TIME_DTSEC_ATMOS_PHY_MP,  TIME_DTSEC_ATMOS_DYN*TIME_NSTEP_ATMOS_DYN )
       TIME_DTSEC_ATMOS_PHY_RD  = max( TIME_DTSEC_ATMOS_PHY_RD,  TIME_DTSEC_ATMOS_DYN*TIME_NSTEP_ATMOS_DYN )
       TIME_DTSEC_ATMOS_PHY_SF  = max( TIME_DTSEC_ATMOS_PHY_SF,  TIME_DTSEC_ATMOS_DYN*TIME_NSTEP_ATMOS_DYN )
       TIME_DTSEC_ATMOS_PHY_TB  = max( TIME_DTSEC_ATMOS_PHY_TB,  TIME_DTSEC_ATMOS_DYN*TIME_NSTEP_ATMOS_DYN )
       TIME_DTSEC_ATMOS_PHY_CH  = max( TIME_DTSEC_ATMOS_PHY_CH,  TIME_DTSEC_ATMOS_DYN*TIME_NSTEP_ATMOS_DYN )
       TIME_DTSEC_ATMOS_PHY_AE  = max( TIME_DTSEC_ATMOS_PHY_AE,  TIME_DTSEC_ATMOS_DYN*TIME_NSTEP_ATMOS_DYN )
       TIME_DTSEC_ATMOS_RESTART = max( TIME_DTSEC_ATMOS_RESTART, TIME_DTSEC_ATMOS_DYN*TIME_NSTEP_ATMOS_DYN )
       TIME_DTSEC_OCEAN         = max( TIME_DTSEC_OCEAN,         TIME_DTSEC_ATMOS_DYN*TIME_NSTEP_ATMOS_DYN )
       TIME_DTSEC_OCEAN_RESTART = max( TIME_DTSEC_OCEAN_RESTART, TIME_DTSEC_ATMOS_DYN*TIME_NSTEP_ATMOS_DYN )
       TIME_DTSEC_LAND          = max( TIME_DTSEC_LAND,          TIME_DTSEC_ATMOS_DYN*TIME_NSTEP_ATMOS_DYN )
       TIME_DTSEC_LAND_RESTART  = max( TIME_DTSEC_LAND_RESTART,  TIME_DTSEC_ATMOS_DYN*TIME_NSTEP_ATMOS_DYN )
       TIME_DTSEC_URBAN         = max( TIME_DTSEC_URBAN,         TIME_DTSEC_ATMOS_DYN*TIME_NSTEP_ATMOS_DYN )
       TIME_DTSEC_URBAN_RESTART = max( TIME_DTSEC_URBAN_RESTART, TIME_DTSEC_ATMOS_DYN*TIME_NSTEP_ATMOS_DYN )

       TIME_DSTEP_ATMOS_DYN     = int( TIME_DTSEC_ATMOS_DYN*TIME_NSTEP_ATMOS_DYN / TIME_DTSEC )
       TIME_DSTEP_ATMOS_PHY_CP  = int( TIME_DTSEC_ATMOS_PHY_CP  / TIME_DTSEC )
       TIME_DSTEP_ATMOS_PHY_MP  = int( TIME_DTSEC_ATMOS_PHY_MP  / TIME_DTSEC )
       TIME_DSTEP_ATMOS_PHY_RD  = int( TIME_DTSEC_ATMOS_PHY_RD  / TIME_DTSEC )
       TIME_DSTEP_ATMOS_PHY_SF  = int( TIME_DTSEC_ATMOS_PHY_SF  / TIME_DTSEC )
       TIME_DSTEP_ATMOS_PHY_TB  = int( TIME_DTSEC_ATMOS_PHY_TB  / TIME_DTSEC )
       TIME_DSTEP_ATMOS_PHY_CH  = int( TIME_DTSEC_ATMOS_PHY_CH  / TIME_DTSEC )
       TIME_DSTEP_ATMOS_PHY_AE  = int( TIME_DTSEC_ATMOS_PHY_AE  / TIME_DTSEC )
       TIME_DSTEP_OCEAN         = int( TIME_DTSEC_OCEAN         / TIME_DTSEC )
       TIME_DSTEP_LAND          = int( TIME_DTSEC_LAND          / TIME_DTSEC )
       TIME_DSTEP_URBAN         = int( TIME_DTSEC_URBAN         / TIME_DTSEC )
       TIME_DSTEP_ATMOS_RESTART = int( TIME_DTSEC_ATMOS_RESTART / TIME_DTSEC )
       TIME_DSTEP_OCEAN_RESTART = int( TIME_DTSEC_OCEAN_RESTART / TIME_DTSEC )
       TIME_DSTEP_LAND_RESTART  = int( TIME_DTSEC_LAND_RESTART  / TIME_DTSEC )
       TIME_DSTEP_URBAN_RESTART = int( TIME_DTSEC_URBAN_RESTART / TIME_DTSEC )

       if ( abs( real(TIME_NSTEP_ATMOS_DYN,kind=DP)*TIME_DTSEC_ATMOS_DYN &
               - real(TIME_DSTEP_ATMOS_DYN,kind=DP)*TIME_DTSEC            ) > 0.D0 ) then
          write(*,*) 'xxx delta t(ATMOS_DYN) must be a multiple of delta t ', &
                     TIME_DTSEC_ATMOS_DYN, real(TIME_DSTEP_ATMOS_DYN,kind=DP)*TIME_DTSEC
          call PRC_MPIstop
       endif
       if ( abs(TIME_DTSEC_ATMOS_PHY_CP-real(TIME_DSTEP_ATMOS_PHY_CP,kind=DP)*TIME_DTSEC) > 0.D0 ) then
          write(*,*) 'xxx delta t(ATMOS_PHY_CP) must be a multiple of delta t ', &
                     TIME_DTSEC_ATMOS_PHY_CP, real(TIME_DSTEP_ATMOS_PHY_CP,kind=DP)*TIME_DTSEC
          call PRC_MPIstop
       endif
       if ( abs(TIME_DTSEC_ATMOS_PHY_MP-real(TIME_DSTEP_ATMOS_PHY_MP,kind=DP)*TIME_DTSEC) > 0.D0 ) then
          write(*,*) 'xxx delta t(ATMOS_PHY_MP) must be a multiple of delta t ', &
                     TIME_DTSEC_ATMOS_PHY_MP, real(TIME_DSTEP_ATMOS_PHY_MP,kind=DP)*TIME_DTSEC
          call PRC_MPIstop
       endif
       if ( abs(TIME_DTSEC_ATMOS_PHY_RD-real(TIME_DSTEP_ATMOS_PHY_RD,kind=DP)*TIME_DTSEC) > 0.D0 ) then
          write(*,*) 'xxx delta t(ATMOS_PHY_RD) must be a multiple of delta t ', &
                     TIME_DTSEC_ATMOS_PHY_RD, real(TIME_DSTEP_ATMOS_PHY_RD,kind=DP)*TIME_DTSEC
          call PRC_MPIstop
       endif
       if ( abs(TIME_DTSEC_ATMOS_PHY_SF-real(TIME_DSTEP_ATMOS_PHY_SF,kind=DP)*TIME_DTSEC) > 0.D0 ) then
          write(*,*) 'xxx delta t(ATMOS_PHY_SF) must be a multiple of delta t ', &
                     TIME_DTSEC_ATMOS_PHY_SF, real(TIME_DSTEP_ATMOS_PHY_SF,kind=DP)*TIME_DTSEC
          call PRC_MPIstop
       endif
       if ( abs(TIME_DTSEC_ATMOS_PHY_TB-real(TIME_DSTEP_ATMOS_PHY_TB,kind=DP)*TIME_DTSEC) > 0.D0 ) then
          write(*,*) 'xxx delta t(ATMOS_PHY_TB) must be a multiple of delta t ', &
                     TIME_DTSEC_ATMOS_PHY_TB, real(TIME_DSTEP_ATMOS_PHY_TB,kind=DP)*TIME_DTSEC
          call PRC_MPIstop
       endif
       if ( abs(TIME_DTSEC_ATMOS_PHY_CH-real(TIME_DSTEP_ATMOS_PHY_CH,kind=DP)*TIME_DTSEC) > 0.D0 ) then
          write(*,*) 'xxx delta t(ATMOS_PHY_CH) must be a multiple of delta t ', &
                     TIME_DTSEC_ATMOS_PHY_CH, real(TIME_DSTEP_ATMOS_PHY_CH,kind=DP)*TIME_DTSEC
          call PRC_MPIstop
       endif
       if ( abs(TIME_DTSEC_ATMOS_PHY_AE-real(TIME_DSTEP_ATMOS_PHY_AE,kind=DP)*TIME_DTSEC) > 0.D0 ) then
          write(*,*) 'xxx delta t(ATMOS_PHY_AE) must be a multiple of delta t ', &
                     TIME_DTSEC_ATMOS_PHY_AE, real(TIME_DSTEP_ATMOS_PHY_AE,kind=DP)*TIME_DTSEC
          call PRC_MPIstop
       endif
       if ( abs(TIME_DTSEC_OCEAN-real(TIME_DSTEP_OCEAN,kind=DP)*TIME_DTSEC) > 0.D0 ) then
          write(*,*) 'xxx delta t(OCEAN) must be a multiple of delta t ', &
                     TIME_DTSEC_OCEAN, real(TIME_DSTEP_OCEAN,kind=DP)*TIME_DTSEC
          call PRC_MPIstop
       endif
       if ( abs(TIME_DTSEC_LAND-real(TIME_DSTEP_LAND,kind=DP)*TIME_DTSEC) > 0.D0 ) then
          write(*,*) 'xxx delta t(LAND) must be a multiple of delta t ', &
                     TIME_DTSEC_LAND, real(TIME_DSTEP_LAND,kind=DP)*TIME_DTSEC
          call PRC_MPIstop
       endif
       if ( abs(TIME_DTSEC_URBAN-real(TIME_DSTEP_URBAN,kind=DP)*TIME_DTSEC) > 0.D0 ) then
          write(*,*) 'xxx delta t(URBAN) must be a multiple of delta t ', &
                     TIME_DTSEC_URBAN, real(TIME_DSTEP_URBAN,kind=DP)*TIME_DTSEC
          call PRC_MPIstop
       endif
       if ( abs(TIME_DTSEC_ATMOS_RESTART-real(TIME_DSTEP_ATMOS_RESTART,kind=DP)*TIME_DTSEC) > 0.D0 ) then
          write(*,*) 'xxx delta t(ATMOS_RESTART) must be a multiple of delta t ', &
                     TIME_DTSEC_ATMOS_RESTART, real(TIME_DSTEP_ATMOS_RESTART,kind=DP)*TIME_DTSEC
          call PRC_MPIstop
       endif
       if ( abs(TIME_DTSEC_OCEAN_RESTART-real(TIME_DSTEP_OCEAN_RESTART,kind=DP)*TIME_DTSEC) > 0.D0 ) then
          write(*,*) 'xxx delta t(OCEAN_RESTART) must be a multiple of delta t ', &
                     TIME_DTSEC_OCEAN_RESTART, real(TIME_DSTEP_OCEAN_RESTART,kind=DP)*TIME_DTSEC
          call PRC_MPIstop
       endif
       if ( abs(TIME_DTSEC_LAND_RESTART-real(TIME_DSTEP_LAND_RESTART,kind=DP)*TIME_DTSEC) > 0.D0 ) then
          write(*,*) 'xxx delta t(LAND_RESTART) must be a multiple of delta t ', &
                     TIME_DTSEC_LAND_RESTART, real(TIME_DSTEP_LAND_RESTART,kind=DP)*TIME_DTSEC
          call PRC_MPIstop
       endif
       if ( abs(TIME_DTSEC_URBAN_RESTART-real(TIME_DSTEP_URBAN_RESTART,kind=DP)*TIME_DTSEC) > 0.D0 ) then
          write(*,*) 'xxx delta t(URBAN_RESTART) must be a multiple of delta t ', &
                     TIME_DTSEC_URBAN_RESTART, real(TIME_DSTEP_URBAN_RESTART,kind=DP)*TIME_DTSEC
          call PRC_MPIstop
       endif
       if ( abs(TIME_DTSEC_URBAN_RESTART-real(TIME_DSTEP_URBAN_RESTART,kind=DP)*TIME_DTSEC) > 0.D0 ) then
          write(*,*) 'xxx delta t(URBAN_RESTART) must be a multiple of delta t ', &
                     TIME_DTSEC_URBAN_RESTART, real(TIME_DSTEP_URBAN_RESTART,kind=DP)*TIME_DTSEC
          call PRC_MPIstop
       endif

       if( IO_L ) write(IO_FID_LOG,*)
       if( IO_L ) write(IO_FID_LOG,*)                     '*** Time interval for each processes (sec.)'
       if( IO_L ) write(IO_FID_LOG,*)                     '*** Atmosphere'
       if( IO_L ) write(IO_FID_LOG,'(1x,A,F10.3)')        '*** Dynamics (time)             : ', TIME_DTSEC_ATMOS_DYN
       if( IO_L ) write(IO_FID_LOG,'(1x,A,I10,A,I8,A)')   '***          (step)             : ', TIME_NSTEP_ATMOS_DYN, &
                                                          ' (steps=', TIME_DSTEP_ATMOS_DYN, ')'
       if( IO_L ) write(IO_FID_LOG,'(1x,A,F10.3,A,I8,A)') '*** Physics, Cumulus            : ', TIME_DTSEC_ATMOS_PHY_CP, &
                                                          ' (steps=', TIME_DSTEP_ATMOS_PHY_CP, ')'
       if( IO_L ) write(IO_FID_LOG,'(1x,A,F10.3,A,I8,A)') '*** Physics, Cloud Microphysics : ', TIME_DTSEC_ATMOS_PHY_MP, &
                                                          ' (steps=', TIME_DSTEP_ATMOS_PHY_MP, ')'
       if( IO_L ) write(IO_FID_LOG,'(1x,A,F10.3,A,I8,A)') '*** Physics, Radiation          : ', TIME_DTSEC_ATMOS_PHY_RD, &
                                                          ' (steps=', TIME_DSTEP_ATMOS_PHY_RD, ')'
       if( IO_L ) write(IO_FID_LOG,'(1x,A,F10.3,A,I8,A)') '*** Physics, Surface Flux       : ', TIME_DTSEC_ATMOS_PHY_SF, &
                                                          ' (steps=', TIME_DSTEP_ATMOS_PHY_SF, ')'
       if( IO_L ) write(IO_FID_LOG,'(1x,A,F10.3,A,I8,A)') '*** Physics, Turbulence         : ', TIME_DTSEC_ATMOS_PHY_TB, &
                                                          ' (steps=', TIME_DSTEP_ATMOS_PHY_TB, ')'
       if( IO_L ) write(IO_FID_LOG,'(1x,A,F10.3,A,I8,A)') '*** Physics, Chemistry          : ', TIME_DTSEC_ATMOS_PHY_CH, &
                                                          ' (steps=', TIME_DSTEP_ATMOS_PHY_CH, ')'
       if( IO_L ) write(IO_FID_LOG,'(1x,A,F10.3,A,I8,A)') '*** Physics, Aerosol            : ', TIME_DTSEC_ATMOS_PHY_AE, &
                                                          ' (steps=', TIME_DSTEP_ATMOS_PHY_AE, ')'
       if( IO_L ) write(IO_FID_LOG,'(1x,A,F10.3,A,I8,A)') '*** Ocean                       : ', TIME_DTSEC_OCEAN, &
                                                          ' (steps=', TIME_DSTEP_OCEAN, ')'
       if( IO_L ) write(IO_FID_LOG,'(1x,A,F10.3,A,I8,A)') '*** Land                        : ', TIME_DTSEC_LAND, &
                                                          ' (steps=', TIME_DSTEP_LAND, ')'
       if( IO_L ) write(IO_FID_LOG,'(1x,A,F10.3,A,I8,A)') '*** Urban                       : ', TIME_DTSEC_URBAN, &
                                                          ' (steps=', TIME_DSTEP_URBAN, ')'
       if( IO_L ) write(IO_FID_LOG,*)
       if( IO_L ) write(IO_FID_LOG,*)                     '*** Time interval for restart (sec.)'
       if( IO_L ) write(IO_FID_LOG,'(1x,A,F10.3,A,I8,A)') '*** Atmospheric Variables       : ', TIME_DTSEC_ATMOS_RESTART, &
                                                          ' (steps=', TIME_DSTEP_ATMOS_RESTART, ')'
       if( IO_L ) write(IO_FID_LOG,'(1x,A,F10.3,A,I8,A)') '*** Ocean Variables             : ', TIME_DTSEC_OCEAN_RESTART, &
                                                          ' (steps=', TIME_DSTEP_OCEAN_RESTART, ')'
       if( IO_L ) write(IO_FID_LOG,'(1x,A,F10.3,A,I8,A)') '*** Land Variables              : ', TIME_DTSEC_LAND_RESTART, &
                                                          ' (steps=', TIME_DSTEP_LAND_RESTART, ')'
       if( IO_L ) write(IO_FID_LOG,'(1x,A,F10.3,A,I8,A)') '*** Urban Variables             : ', TIME_DTSEC_URBAN_RESTART, &
                                                          ' (steps=', TIME_DSTEP_URBAN_RESTART, ')'

    endif

    ! WALLCLOCK TERMINATOR SETUP
    if ( TIME_WALLCLOCK_LIMIT > 0.0_DP ) then
       if( IO_L ) write(IO_FID_LOG,*)
       if( IO_L ) write(IO_FID_LOG,*)                     '*** Wall clock time limit of execution is specified.'

       if ( TIME_DT_WALLCLOCK_CHECK == UNDEF8 ) then
          if( IO_L ) write(IO_FID_LOG,*) '*** Not found TIME_DT_WALLCLOCK_CHECK. largest time step interval is used.'
          TIME_DTSEC_WALLCLOCK_CHECK = max( TIME_DTSEC_ATMOS_DYN*TIME_NSTEP_ATMOS_DYN, &
                                            TIME_DTSEC_ATMOS_PHY_CP,                   &
                                            TIME_DTSEC_ATMOS_PHY_MP,                   &
                                            TIME_DTSEC_ATMOS_PHY_RD,                   &
                                            TIME_DTSEC_ATMOS_PHY_SF,                   &
                                            TIME_DTSEC_ATMOS_PHY_TB,                   &
                                            TIME_DTSEC_ATMOS_PHY_CH,                   &
                                            TIME_DTSEC_ATMOS_PHY_AE,                   &
                                            TIME_DTSEC_OCEAN,                          &
                                            TIME_DTSEC_LAND,                           &
                                            TIME_DTSEC_URBAN                           )
       else
          if ( TIME_DT_WALLCLOCK_CHECK_UNIT == '' ) then
             if( IO_L ) write(IO_FID_LOG,*) '*** Not found TIME_DT_WALLCLOCK_CHECK_UNIT. TIME_DURATION_UNIT is used.'
             TIME_DT_WALLCLOCK_CHECK_UNIT = TIME_DURATION_UNIT
          endif
          call CALENDAR_unit2sec( TIME_DTSEC_WALLCLOCK_CHECK, TIME_DT_WALLCLOCK_CHECK, TIME_DT_WALLCLOCK_CHECK_UNIT )
          TIME_DTSEC_WALLCLOCK_CHECK = max( TIME_DTSEC_WALLCLOCK_CHECK, TIME_DTSEC_ATMOS_DYN*TIME_NSTEP_ATMOS_DYN )
       endif

       TIME_DSTEP_WALLCLOCK_CHECK = int( TIME_DTSEC_WALLCLOCK_CHECK / TIME_DTSEC )

       TIME_WALLCLOCK_SAFE  = max( min( TIME_WALLCLOCK_SAFE, 1.0_DP ), 0.0_DP )
       TIME_WALLCLOCK_START = PRC_MPItime()

       if( IO_L ) write(IO_FID_LOG,'(1x,A,F10.1,A)')      '*** This job stops after ', &
                                                          TIME_WALLCLOCK_LIMIT * TIME_WALLCLOCK_SAFE, ' seconds.'
       if( IO_L ) write(IO_FID_LOG,'(1x,A,F10.3,A,I8,A)') '*** Step interval for check     : ', TIME_DTSEC_WALLCLOCK_CHECK, &
                                                          ' (steps=', TIME_DSTEP_WALLCLOCK_CHECK, ')'
    endif

    return
  end subroutine ADMIN_TIME_setup

  !-----------------------------------------------------------------------------
  !> Evaluate component execution
  subroutine ADMIN_TIME_checkstate
    use scale_process, only: &
       PRC_MPItime
    use scale_calendar, only: &
       CALENDAR_date2char
    use scale_time, only: &
       TIME_NOWDATE,            &
       TIME_NOWMS,              &
       TIME_NOWSTEP,            &
       TIME_NSTEP,              &
       TIME_DSTEP_ATMOS_DYN,    &
       TIME_DSTEP_ATMOS_PHY_CP, &
       TIME_DSTEP_ATMOS_PHY_MP, &
       TIME_DSTEP_ATMOS_PHY_RD, &
       TIME_DSTEP_ATMOS_PHY_SF, &
       TIME_DSTEP_ATMOS_PHY_TB, &
       TIME_DSTEP_ATMOS_PHY_CH, &
       TIME_DSTEP_ATMOS_PHY_AE, &
       TIME_DSTEP_OCEAN,        &
       TIME_DSTEP_LAND,         &
       TIME_DSTEP_URBAN,        &
       TIME_OFFSET_YEAR
    implicit none

    real(DP)          :: WALLCLOCK_elapse
    character(len=27) :: nowchardate
    !---------------------------------------------------------------------------

    TIME_DOATMOS_step      = .false.
    TIME_DOATMOS_DYN       = .false.
    TIME_DOATMOS_PHY_CP    = .false.
    TIME_DOATMOS_PHY_MP    = .false.
    TIME_DOATMOS_PHY_RD    = .false.
    TIME_DOATMOS_PHY_SF    = .false.
    TIME_DOATMOS_PHY_TB    = .false.
    TIME_DOATMOS_PHY_CH    = .false.
    TIME_DOATMOS_PHY_AE    = .false.
    TIME_DOOCEAN_step      = .false.
    TIME_DOLAND_step       = .false.
    TIME_DOURBAN_step      = .false.

    TIME_RES_ATMOS_DYN    = TIME_RES_ATMOS_DYN    + 1
    TIME_RES_ATMOS_PHY_CP = TIME_RES_ATMOS_PHY_CP + 1
    TIME_RES_ATMOS_PHY_MP = TIME_RES_ATMOS_PHY_MP + 1
    TIME_RES_ATMOS_PHY_RD = TIME_RES_ATMOS_PHY_RD + 1
    TIME_RES_ATMOS_PHY_SF = TIME_RES_ATMOS_PHY_SF + 1
    TIME_RES_ATMOS_PHY_TB = TIME_RES_ATMOS_PHY_TB + 1
    TIME_RES_ATMOS_PHY_CH = TIME_RES_ATMOS_PHY_CH + 1
    TIME_RES_ATMOS_PHY_AE = TIME_RES_ATMOS_PHY_AE + 1
    TIME_RES_OCEAN        = TIME_RES_OCEAN        + 1
    TIME_RES_LAND         = TIME_RES_LAND         + 1
    TIME_RES_URBAN        = TIME_RES_URBAN        + 1

    if ( TIME_RES_ATMOS_DYN    == TIME_DSTEP_ATMOS_DYN ) then
       TIME_DOATMOS_step  = .true.
       TIME_DOATMOS_DYN   = .true.
       TIME_RES_ATMOS_DYN = 0
    endif
    if ( TIME_RES_ATMOS_PHY_CP == TIME_DSTEP_ATMOS_PHY_CP ) then
       TIME_DOATMOS_step     = .true.
       TIME_DOATMOS_PHY_CP   = .true.
       TIME_RES_ATMOS_PHY_CP = 0
    endif
    if ( TIME_RES_ATMOS_PHY_MP == TIME_DSTEP_ATMOS_PHY_MP ) then
       TIME_DOATMOS_step     = .true.
       TIME_DOATMOS_PHY_MP   = .true.
       TIME_RES_ATMOS_PHY_MP = 0
    endif
    if ( TIME_RES_ATMOS_PHY_RD == TIME_DSTEP_ATMOS_PHY_RD ) then
       TIME_DOATMOS_step     = .true.
       TIME_DOATMOS_PHY_RD   = .true.
       TIME_RES_ATMOS_PHY_RD = 0
    endif
    if ( TIME_RES_ATMOS_PHY_SF == TIME_DSTEP_ATMOS_PHY_SF ) then
       TIME_DOATMOS_step     = .true.
       TIME_DOATMOS_PHY_SF   = .true.
       TIME_RES_ATMOS_PHY_SF = 0
    endif
    if ( TIME_RES_ATMOS_PHY_TB == TIME_DSTEP_ATMOS_PHY_TB ) then
       TIME_DOATMOS_step     = .true.
       TIME_DOATMOS_PHY_TB   = .true.
       TIME_RES_ATMOS_PHY_TB = 0
    endif
    if ( TIME_RES_ATMOS_PHY_CH == TIME_DSTEP_ATMOS_PHY_CH ) then
       TIME_DOATMOS_step     = .true.
       TIME_DOATMOS_PHY_CH   = .true.
       TIME_RES_ATMOS_PHY_CH = 0
    endif
    if ( TIME_RES_ATMOS_PHY_AE == TIME_DSTEP_ATMOS_PHY_AE ) then
       TIME_DOATMOS_step     = .true.
       TIME_DOATMOS_PHY_AE   = .true.
       TIME_RES_ATMOS_PHY_AE = 0
    endif

    if ( TIME_RES_OCEAN == TIME_DSTEP_OCEAN ) then
       TIME_DOOCEAN_step = .true.
       TIME_RES_OCEAN    = 0
    endif
    if ( TIME_RES_LAND  == TIME_DSTEP_LAND  ) then
       TIME_DOLAND_step  = .true.
       TIME_RES_LAND     = 0
    endif
    if ( TIME_RES_URBAN == TIME_DSTEP_URBAN ) then
       TIME_DOURBAN_step = .true.
       TIME_RES_URBAN    = 0
    endif

    call CALENDAR_date2char( nowchardate,     & ! [OUT]
                             TIME_NOWDATE(:), & ! [IN]
                             TIME_NOWMS,      & ! [IN]
                             TIME_OFFSET_YEAR ) ! [IN]

    if ( TIME_WALLCLOCK_LIMIT > 0.0_DP ) then
       WALLCLOCK_elapse = PRC_MPItime() - TIME_WALLCLOCK_START
       if( IO_L ) write(IO_FID_LOG,'(1x,3A,I6,A,I6,A,F10.1)') '*** TIME: ', nowchardate,' STEP:',TIME_NOWSTEP, '/', TIME_NSTEP, &
                                                              ' WCLOCK:', WALLCLOCK_elapse
    else
       if( IO_L ) write(IO_FID_LOG,'(1x,3A,I6,A,I6)') '*** TIME: ', nowchardate,' STEP:',TIME_NOWSTEP, '/', TIME_NSTEP
    endif

    return
  end subroutine ADMIN_TIME_checkstate

  !-----------------------------------------------------------------------------
  !> Advance the time & evaluate restart & stop
  subroutine ADMIN_TIME_advance
    use scale_process, only: &
       PRC_IsMaster, &
       PRC_MPItime
    use scale_calendar, only: &
       CALENDAR_daysec2date,   &
       CALENDAR_adjust_daysec, &
       CALENDAR_combine_daysec
    use scale_time, only: &
       TIME_DTSEC,                &
       TIME_NOWDATE,              &
       TIME_NOWMS,                &
       TIME_NOWDAY,               &
       TIME_NOWSEC,               &
       TIME_NOWDAYSEC,            &
       TIME_NOWSTEP,              &
       TIME_NSTEP,                &
       TIME_OFFSET_YEAR,          &
       TIME_STARTDAYSEC,          &
       TIME_DSTEP_WALLCLOCK_CHECK
    implicit none

    real(DP) :: WALLCLOCK_elapse
    logical  :: exists
    !---------------------------------------------------------------------------

    TIME_DOend = .false.

    TIME_NOWSTEP = TIME_NOWSTEP + 1
    TIME_NOWDAY  = TIME_STARTDAY
    TIME_NOWSEC  = TIME_STARTSEC + real(TIME_NOWSTEP-1,kind=DP) * TIME_DTSEC

    ! reallocate day & sub-day
    call CALENDAR_adjust_daysec( TIME_NOWDAY, TIME_NOWSEC ) ! [INOUT]

    call CALENDAR_daysec2date( TIME_NOWDATE(:), & ! [OUT]
                               TIME_NOWMS,      & ! [OUT]
                               TIME_NOWDAY,     & ! [IN]
                               TIME_NOWSEC,     & ! [IN]
                               TIME_OFFSET_YEAR ) ! [IN]

    TIME_NOWDAYSEC = CALENDAR_combine_daysec( TIME_NOWDAY, TIME_NOWSEC )

    if ( TIME_NOWSTEP > TIME_NSTEP ) then
       TIME_DOend = .true.
    endif

    if (       TIME_WALLCLOCK_LIMIT > 0.0_DP                     &
         .AND. mod(TIME_NOWSTEP-1,TIME_DSTEP_WALLCLOCK_CHECK) == 0 ) then
       WALLCLOCK_elapse = PRC_MPItime() - TIME_WALLCLOCK_START

       if ( WALLCLOCK_elapse > TIME_WALLCLOCK_LIMIT * TIME_WALLCLOCK_SAFE ) then
          if( IO_L ) write(IO_FID_LOG,*) '*** Elapse time limit is detected. Termination operation starts.'
          TIME_DOend = .true.
       endif
    endif

    ! QUIT file control
    if ( PRC_IsMaster ) then ! master node
       inquire(file='QUIT', exist=exists)

       if( exists ) then
          if( IO_L ) write(IO_FID_LOG,*) '*** QUIT file is found. Termination operation starts.'
          TIME_DOend = .true.
       endif
    endif

    TIME_DOATMOS_restart = .false.
    TIME_DOOCEAN_restart = .false.
    TIME_DOLAND_restart  = .false.
    TIME_DOURBAN_restart = .false.

    TIME_RES_ATMOS_RESTART = TIME_RES_ATMOS_RESTART + 1
    TIME_RES_OCEAN_RESTART = TIME_RES_OCEAN_RESTART + 1
    TIME_RES_LAND_RESTART  = TIME_RES_LAND_RESTART  + 1
    TIME_RES_URBAN_RESTART = TIME_RES_URBAN_RESTART + 1

    if ( TIME_RES_ATMOS_RESTART == TIME_DSTEP_ATMOS_RESTART ) then
       TIME_DOATMOS_restart   = .true.
       TIME_RES_ATMOS_RESTART = 0
    elseif( TIME_DOend ) then
       TIME_DOATMOS_restart   = .true.
    endif

    if ( TIME_RES_OCEAN_RESTART == TIME_DSTEP_OCEAN_RESTART ) then
       TIME_DOOCEAN_restart   = .true.
       TIME_RES_OCEAN_RESTART = 0
    elseif( TIME_DOend ) then
       TIME_DOOCEAN_restart   = .true.
    endif

    if ( TIME_RES_LAND_RESTART  == TIME_DSTEP_LAND_RESTART  ) then
       TIME_DOLAND_restart    = .true.
       TIME_RES_LAND_RESTART  = 0
    elseif( TIME_DOend ) then
       TIME_DOLAND_restart    = .true.
    endif

    if ( TIME_RES_URBAN_RESTART == TIME_DSTEP_URBAN_RESTART ) then
       TIME_DOURBAN_restart   = .true.
       TIME_RES_URBAN_RESTART = 0
    elseif( TIME_DOend ) then
       TIME_DOURBAN_restart   = .true.
    endif

    return
  end subroutine ADMIN_TIME_advance

end module mod_admin_time
!-------------------------------------------------------------------------------