Merge remote-tracking branch 'origin/release-v4.6.1'
[WRF.git] / phys / module_physics_init.F
blob9d419edf7d55e3f4d9763178fe89aab8187ba1e4
1 !WRF:MODEL_LAYER:INITIALIZATION
4 !  This MODULE holds the routines which are used to perform model start-up operations
5 !  for the individual domains.  This is the stage after inputting wrfinput and before
6 !  calling 'integrate'.
8 !  This MODULE CONTAINS the following routines:
10 MODULE module_physics_init
12    USE module_state_description
13    USE module_model_constants
14    USE module_configure, ONLY : grid_config_rec_type
15 #if ( defined( DM_PARALLEL ) && ( ! defined( STUBMPI ) ) )
16    USE module_dm, ONLY : wrf_dm_max_real
17 #endif
18    USE module_ra_clWRF_support
20 !  USE module_ssib_veg , ONLY : init_module_ssib_veg !fds (SSiB constants)
21    !Local data for CAM's MG MP scheme
22    integer  :: ixcldliq, ixcldice, ixnumliq, ixnumice
23    LOGICAL  :: CAM_INITIALIZED = .FALSE.
24    LOGICAL  :: WINDFARM_INITIALIZED = .FALSE.
27 CONTAINS
30 !=================================================================
31    SUBROUTINE phy_init ( id, config_flags, DT, restart, zfull, zhalf,     &
32                          p_top, TSK,RADT,BLDT,CUDT,MPDT,         &
33                          RUCUTEN, RVCUTEN,                       &
34                          RTHCUTEN, RQVCUTEN, RQRCUTEN,           &
35                          RQCCUTEN, RQSCUTEN, RQICUTEN,           &
36                          RUSHTEN,  RVSHTEN,  RTHSHTEN,           &
37                          RQVSHTEN, RQRSHTEN, RQCSHTEN,           &
38                          RQSSHTEN, RQISHTEN, RQGSHTEN,           &
39                          RUBLTEN,RVBLTEN,RTHBLTEN,               &
40                          RQVBLTEN,RQCBLTEN,RQIBLTEN,             &
41                          RTHRATEN,RTHRATENLW,RTHRATENSW,         &
42                          this_is_an_ideal_run,                   &
43 #if ( EM_CORE == 1 )
44                          !BSINGH - For WRFCuP scheme(11/12/2013)
45                          cupflag,cldfra_cup,cldfratend_cup,      & !wig, 18-Sep-2006
46                          shall,                                  & !wig, 18-Sep-2006
47                          tcloud_cup,                             & !rce, 18-apr-2012
48                          !BSINGH - ENDS
49 #endif
50                          STEPBL,STEPRA,STEPCU,                   &
51                          W0AVG, RAINNC, RAINC, RAINCV, RAINNCV,  &
52                          SNOWNC, SNOWNCV, GRAUPELNC, GRAUPELNCV, &
53                          z_at_q, inv_dens, qnwfa2d, qnbca2d,     & ! G. Thompson
54                          scalar, num_sc,                         & ! G. Thompson
55                          re_cloud, re_ice, re_snow,              & ! G. Thompson
56                          has_reqc, has_reqi, has_reqs,           & ! G. Thompson
57 #if ( EM_CORE == 1 )
58                          PHB,PH,P,PB,QV,CCNTY,QDCN,QTCN,QCCN,    & ! for ntu3m
59                          QRCN,QNIN,                              & ! for ntu3m
60                          re_cloud_gsfc, re_ice_gsfc,             & 
61                          re_snow_gsfc,                           & ! Goddard
62                          re_graupel_gsfc, re_hail_gsfc,          &
63                          re_rain_gsfc,                           & ! Goddard
64 #endif
65                          NCA,swrad_scat,                         &
66                          CLDEFI,LOWLYR,                          &
67                          MASS_FLUX,                              &
68                          RTHFTEN, RQVFTEN,                       &
69 #if (WRF_USE_CLM == 1) && ( WRF_CHEM == 1 )
70                          megan_specifier, megan_factors_file,    &
71                          megan_mapped_emisfctrs,                 &
72 #endif
73                          CLDFRA,CLDFRA_OLD,GLW,GSW,EMISS,EMBCK,  & !EMBCK new
74                          LU_INDEX,                               &
75                          landuse_ISICE, landuse_LUCATS,          &
76                          landuse_LUSEAS, landuse_ISN,            &
77                          lu_state,                               &
78                          XLAT,XLONG,xlong_u,xlat_v,ALBEDO,ALBBCK,GMT,JULYR,JULDAY,&
79                          levsiz, n_ozmixm, n_aerosolc, paerlev,  &
80                          alevsiz, no_src_types,                  &
81                          TMN,XLAND,ZNT,Z0,UST,MOL,PBLH,TKE_PBL,  &
82                          EXCH_H,THC,SNOWC,MAVAIL,HFX,QFX,RAINBL, &
83                          TSLB,ZS,DZS,num_soil_layers,warm_rain,  &
84                          adv_moist_cond,is_CAMMGMP_used,         &
85                          APR_GR,APR_W,APR_MC,APR_ST,APR_AS,      &
86                          APR_CAPMA,APR_CAPME,APR_CAPMI,          &
87                          XICE,XICEM,VEGFRA,SNOW,CANWAT,SMSTAV,   &
88                          SMSTOT, SFCRUNOFF,UDRUNOFF,GRDFLX,ACSNOW,&
89                          ACSNOM,IVGTYP,ISLTYP, SFCEVP, SMOIS,    &
90                          SH2O, SNOWH, SMFR3D,                    &  ! temporary
91                          SNOALB,                                 &
92                          DX,DY,DX2D,AREA2D,                      &
93                          F_ICE_PHY,F_RAIN_PHY,F_RIMEF_PHY,       &
94                          mp_restart_state,tbpvs_state,tbpvs0_state,&
95                          allowed_to_read, moved, start_of_simulation,&
96                          LAGDAY,                                 &
97                          u10,v10,u10e,v10e,                      &
98                          ids, ide, jds, jde, kds, kde,           &
99                          ims, ime, jms, jme, kms, kme,           &
100                          its, ite, jts, jte, kts, kte,           &
101                          num_urban_ndm,                          &
102                          urban_map_zrd,                          &
103                          urban_map_zwd,                          &
104                          urban_map_gd,                           &
105                          urban_map_zd,                           &
106                          urban_map_zdf,                          &
107                          urban_map_bd,                           &
108                          urban_map_wd,                           &
109                          urban_map_gbd,                          &
110                          urban_map_fbd,                          &
111                          urban_map_zgrd,                         &
112                          NUM_URBAN_HI,                           &
113                          raincv_a,raincv_b,                      &
114                          gd_cloud,gd_cloud2,                     & 
115                          gd_cloud_a,gd_cloud2_a,                 &
116                          QC_CU,QI_CU,                            &
117                          ozmixm,pin,                             &    ! Optional
118                          aerodm,pina,                            &    ! Optional
119                          m_ps_1,m_ps_2,m_hybi,aerosolc_1,aerosolc_2,& ! Optional
120                          RUNDGDTEN,RVNDGDTEN,RTHNDGDTEN,         &    ! Optional
121                          RPHNDGDTEN,RQVNDGDTEN,RMUNDGDTEN,       &    ! Optional
122                          SDA_HFX, SDA_QFX, QNORM, HFX_BOTH, QFX_BOTH, & ! fasdas
123                          HFX_FDDA,                                    & ! fasdas
124                          FGDT,STEPFG,                            &    ! Optional
125                          cugd_tten,cugd_ttens,cugd_qvten,        &    ! Optional
126                          cugd_qvtens,cugd_qcten,                 &    ! Optional
127                          ISNOWXY, ZSNSOXY, TSNOXY,                        & ! Optional Noah-MP
128                          SNICEXY, SNLIQXY, TVXY, TGXY, CANICEXY,          & ! Optional Noah-MP
129                          CANLIQXY, EAHXY, TAHXY, CMXY,                    & ! Optional Noah-MP
130                          CHXY, FWETXY, SNEQVOXY, ALBOLDXY,QSNOWXY,QRAINXY,& ! Optional Noah-MP
131                          WSLAKEXY, ZWTXY, WAXY, WTXY, LFMASSXY, RTMASSXY, & ! Optional Noah-MP
132                          STMASSXY, WOODXY, STBLCPXY, FASTCPXY,            & ! Optional Noah-MP
133                          GRAINXY, GDDXY,                                  & ! Optional Noah-MP
134                          croptype, cropcat,                               & ! Noah-MP Crop model
135                          iopt_crop,                                       & 
136                          iopt_irr, iopt_irrm,                             &   
137                          IRNUMSI, IRNUMMI, IRNUMFI, IRWATSI, IRWATMI,     &   ! Optional Noah-MP
138                          IRWATFI, IRELOSS, IRSIVOL, IRMIVOL, IRFIVOL,     &   ! Optional Noah-MP
139                          IRRSPLH, qtdrain,                                &
140                          gecros_state,                                    & ! Optional gecros crop
141                          XSAIXY, LAI,                                     & ! Optional Noah-MP
142                          T2MVXY, T2MBXY, CHSTARXY ,                       & ! Optional Noah-MP
143                          SMOISEQ  ,SMCWTDXY ,RECHXY, DEEPRECHXY, AREAXY,  & ! Optional Noah-MP 
144                          WTDDT , STEPWTD ,QRFSXY ,QSPRINGSXY ,QSLATXY,    & ! Optional Noah-MP
145                          FDEPTHXY, RIVERBEDXY, EQZWT, RIVERCONDXY, PEXPXY, & ! Optional Noah-MP
146                          rechclim  ,                                       & ! Optional Noah-MP
147                          msftx, msfty,                           &           ! Optional Noah-MP
148 !                        num_roof_layers,num_wall_layers,        & !Optional urban
149 !                        num_road_layers,                        & !Optional urban
150                          DZR, DZB, DZG,                          & !Optional urban
151                          TR_URB2D,TB_URB2D,TG_URB2D,TC_URB2D,    & !Optional urban
152                          QC_URB2D, XXXR_URB2D,XXXB_URB2D,        & !Optional urban
153                          XXXG_URB2D, XXXC_URB2D,                 & !Optional urban
154                          TRL_URB3D, TBL_URB3D, TGL_URB3D,        & !Optional urban
155                          SH_URB2D, LH_URB2D, G_URB2D, RN_URB2D,  & !Optional urban
156                          TS_URB2D, FRC_URB2D, UTYPE_URB2D,       & !Optional urban
157                          CMCR_URB2D,TGR_URB2D,TGRL_URB3D,SMR_URB3D, & !Optional urban
158                          DRELR_URB2D,DRELB_URB2D,DRELG_URB2D,    & !Optional urban
159                          FLXHUMR_URB2D,FLXHUMB_URB2D,            & !Optional urban
160                          FLXHUMG_URB2D,                          & !Optional urban
161                          TRB_URB4D,TW1_URB4D,TW2_URB4D,          & !Optional multi-layer urban
162                          TGB_URB4D,TLEV_URB3D,QLEV_URB3D,        & !Optional multi-layer urban
163                          TW1LEV_URB3D,TW2LEV_URB3D,              & !Optional multi-layer urban
164                          TGLEV_URB3D,TFLEV_URB3D,                & !Optional multi-layer urban
165                          SF_AC_URB3D,LF_AC_URB3D,CM_AC_URB3D,    & !Optional multi-layer urban
166                          SFVENT_URB3D,LFVENT_URB3D,              & !Optional multi-layer urban
167                          SFWIN1_URB3D,SFWIN2_URB3D,              & !Optional multi-layer urban
168                          SFW1_URB3D,SFW2_URB3D,                  & !Optional multi-layer urban
169                          SFR_URB3D,SFG_URB3D,                    & !Optional multi-layer urban
170                          EP_PV_URB3D,T_PV_URB3D,                         & !GRZ
171                          TRV_URB4D,QR_URB4D,QGR_URB3D,TGR_URB3D,         & !GRZ
172                          DRAIN_URB4D,DRAINGR_URB3D,SFRV_URB3D,           & !GRZ
173                          LFRV_URB3D,DGR_URB3D,DG_URB3D,LFR_URB3D,LFG_URB3D,&!GRZ
174                          LP_URB2D,HI_URB2D,LB_URB2D,             & !Optional multi-layer urban
175                          HGT_URB2D,MH_URB2D,STDH_URB2D,          & !Optional multi-layer urban
176                          LF_URB2D,                               & !Optional multi-layer urban
177                          A_U_BEP,A_V_BEP,A_T_BEP,A_Q_BEP,        & !Optional multi-layer urban
178                          A_E_BEP,B_U_BEP,B_V_BEP,                & !Optional multi-layer urban
179                          B_T_BEP,B_Q_BEP,B_E_BEP,DLG_BEP,        & !Optional multi-layer urban
180                          DL_U_BEP,SF_BEP,VL_BEP,                 & !Optional multi-layer urban
181                          TML,T0ML,HML,H0ML,HUML,HVML,TMOML,      & !Optional oml
182                          lakedepth2d,  savedtke12d,  snowdp2d,   h2osno2d,       & !lake
183                          snl2d,        t_grnd2d,     t_lake3d,   lake_icefrac3d, & !lake
184                          z_lake3d,     dz_lake3d,    t_soisno3d, h2osoi_ice3d,   & !lake
185                          h2osoi_liq3d, h2osoi_vol3d, z3d,        dz3d,           & !lake
186                          zi3d,         watsat3d,     csol3d,     tkmg3d,         & !lake
187                          tkdry3d,      tksatu3d,     lake2d,     lakedepth_default, & !lake
188                          lake_min_elev,   lake_depth,                               & !lake
189 #if ( EM_CORE == 1 )
190                          lakemask,   lakeflag,                                   & !lake
191 #endif
192                          lake_depth_flag, use_lakedepth,                         & !lake
193                          water_depth, bathymetry_flag, shalwater_z0,         & ! bathymetry
194                          shalwater_depth,                                    & ! bathymetry
195                          sf_surface_mosaic, mosaic_cat, NLCAT,               & ! Noah tiling
196 !CLM variables
197                          maxpatch,                                           &
198                          numc,nump,snl,                                      &
199                          snowdp,wtc,wtp,h2osno,t_grnd,t_veg,                 &
200                          h2ocan,h2ocan_col,t2m_max,t2m_min,t_ref2m,          &
201                          h2osoi_liq_s1,                                      &
202                          h2osoi_liq_s2,h2osoi_liq_s3,h2osoi_liq_s4,          &
203                          h2osoi_liq_s5,h2osoi_liq1,h2osoi_liq2,              &
204                          h2osoi_liq3,h2osoi_liq4,h2osoi_liq5,h2osoi_liq6,    &
205                          h2osoi_liq7,h2osoi_liq8,h2osoi_liq9,h2osoi_liq10,   &
206                          h2osoi_ice_s1,h2osoi_ice_s2,                        &
207                          h2osoi_ice_s3,h2osoi_ice_s4,h2osoi_ice_s5,          &
208                          h2osoi_ice1,h2osoi_ice2,h2osoi_ice3,h2osoi_ice4,    &
209                          h2osoi_ice5,h2osoi_ice6,h2osoi_ice7,                &
210                          h2osoi_ice8,h2osoi_ice9,h2osoi_ice10,               &
211                          t_soisno_s1,t_soisno_s2,t_soisno_s3,t_soisno_s4,    &
212                          t_soisno_s5,t_soisno1,t_soisno2,t_soisno3,          &
213                          t_soisno4,t_soisno5,t_soisno6,t_soisno7,            &
214                          t_soisno8,t_soisno9,t_soisno10,                     &
215                          dzsnow1,dzsnow2,dzsnow3,dzsnow4,dzsnow5,            &
216                          snowrds1,snowrds2,snowrds3,snowrds4,snowrds5,       &
217                          t_lake1,t_lake2,t_lake3,t_lake4,t_lake5,            &
218                          t_lake6,t_lake7,t_lake8,t_lake9,t_lake10,           &
219                          h2osoi_vol1,h2osoi_vol2,h2osoi_vol3,                &
220                          h2osoi_vol4,h2osoi_vol5,h2osoi_vol6,                &
221                          h2osoi_vol7,h2osoi_vol8,                            &
222                          h2osoi_vol9,h2osoi_vol10,                           &
223                          ht,                                                 &
224                          ALBEDOsubgrid,LHsubgrid,HFXsubgrid,LWUPsubgrid,     &
225                          Q2subgrid,SABVsubgrid,SABGsubgrid,NRAsubgrid,       &
226                          SWUPsubgrid,lhsoi,lhveg,lhtran,                     &
227 ! end of CLM variables
228                          TSK_SAVE,                               & !Optional for fractional seaice
229                          itimestep,                              & !Optional obs fdda
230 #if ( EM_CORE == 1 )
231                          fdob,                                   & !Optional obs fdda
232 #endif
233                          t00, p00, tlp,                          & !for obs-nudging
234                          TYR,TYRA,TDLY,TLAG,NYEAR,NDAY,tmn_update,   &
235                          ACHFX,ACLHF,ACGRDFLX,                   &
236    ! OPTIONAL 
237                          RQCNCUTEN, RQINCUTEN,                   &
238                          rliq,                                   &  !BSINGH:01/31/2013 - Added rliq and is_CAMMGMP_used for CAM5 physics
239                          cldfra_dp,cldfra_sh                     & !ckay for subgrid cloud
240                          ,te_temf                                & ! WA 12/21/09
241                          ,cf3d_temf                              & ! WA 9/27/10
242                          ,wm_temf                                & ! WA 2/22/11
243                          ,massflux_EDKF, entr_EDKF, detr_EDKF  & ! Optional for qnse
244                          ,thl_up, thv_up, rt_up                & ! Optional for qnse
245                          ,rv_up, rc_up, u_up, v_up, frac_up    & ! Optional for qnse
246                          ,RDCASHTEN, RQCDCSHTEN                 &
247                          ,cldareaa, cldareab, cldliqa, cldliqb  &
248                          ,ca_rad, cw_rad                        &
249                          ,pblmax, wub, ltopb, clddpthb, cldtopb &
250                          ,capesave, ainckfsa, radsave           &
251                          ,rainsh, rainshvb, kdcldtop, kdcldbas  & 
252                          ,xtime1, PBLHAVG, TKEAVG               &
253                          ,ccn_conc                             & ! RAS
254                          ,QKE                                  & !for MYNN
255                          ,pek,pep                              & ! EEPS
256                          ,ghi_accum                            & ! Solar diagnostics
257                          ,landusef,landusef2,mosaic_cat_index                                                 & ! danli mosaic
258                          ,TSK_mosaic,TSLB_mosaic,SMOIS_mosaic,SH2O_mosaic                                     & ! danli mosaic
259                          ,CANWAT_mosaic,SNOW_mosaic,SNOWH_mosaic,SNOWC_mosaic                                 & ! danli mosaic
260                          ,ALBEDO_mosaic,ALBBCK_mosaic, EMISS_mosaic, EMBCK_mosaic, ZNT_mosaic, Z0_mosaic      & ! danli mosaic
261                          ,TR_URB2D_mosaic,TB_URB2D_mosaic                                                     & ! danli mosaic 
262                          ,TG_URB2D_mosaic,TC_URB2D_mosaic                                                     & ! danli mosaic 
263                          ,QC_URB2D_mosaic                                                                     & ! danli mosaic
264                          ,TRL_URB3D_mosaic,TBL_URB3D_mosaic                                                   & ! danli mosaic 
265                          ,TGL_URB3D_mosaic                                                                    & ! danli mosaic 
266                          ,SH_URB2D_mosaic,LH_URB2D_mosaic                                                     & ! danli mosaic 
267                          ,G_URB2D_mosaic,RN_URB2D_mosaic                                                      & ! danli mosaic 
268                          ,TS_URB2D_mosaic                                                                     & ! danli mosaic 
269                          ,TS_RUL2D_mosaic                                                                     & ! danli mosaic
270                          ,irr_rand_field,irr_ph,irr_freq                                                      &
271 #if ( EM_CORE == 1 )
272                          ,QR_CU,QS_CU,NC_CU,NI_CU,NR_CU,NS_CU,CCN_CU              & ! TWG
273                          ,alevsiz_cu,num_months,no_src_types_cu,aeromcu,aeropcu   & ! PSH/TWG 06/10/16                         
274                          ,EFCG,EFCS,EFIG,EFIS,EFSG,EFSS                           & ! TWG
275 #endif
276                           )
278 !-----------------------------------------------------------------
279    USE module_domain
280    USE module_wrf_error
281    use module_sf_lake, only : nlevsoil,nlevsnow,nlevlake
282 #if ( WRF_CHEM == 1 )
283    USE module_gocart_coupling, ONLY : makelut_ccn_icn
284    USE module_cam_support,     ONLY : cam_mam_aerosols
285 #endif
286    USE module_wind_fitch
287    USE module_wind_mav  ! Yulong add for WLM
288    IMPLICIT NONE
289 !-----------------------------------------------------------------
290    TYPE (grid_config_rec_type)              :: config_flags
292    INTEGER , INTENT(IN)        :: id
293    INTEGER , INTENT(IN) ,OPTIONAL       :: tmn_update
294    LOGICAL , INTENT(OUT)       :: warm_rain,adv_moist_cond
295    LOGICAL , INTENT(OUT)       :: is_CAMMGMP_used !BSINGH:01/31/2013 - Added for CAM5 physics
296 !   LOGICAL , INTENT (IN)       :: FNDSOILW, FNDSNOWH
297    LOGICAL, PARAMETER          :: FNDSOILW=.true., FNDSNOWH=.true.
298    INTEGER , INTENT(IN)        :: ids, ide, jds, jde, kds, kde,  &
299                                   ims, ime, jms, jme, kms, kme,  &
300                                   its, ite, jts, jte, kts, kte
302    INTEGER , INTENT(IN)        :: num_soil_layers
303    INTEGER , INTENT(IN)        :: lagday
304    INTEGER , INTENT(OUT) ,OPTIONAL      :: nyear
305    REAL    , INTENT(OUT) ,OPTIONAL      :: nday
307    LOGICAL,  INTENT(IN)        :: start_of_simulation, this_is_an_ideal_run
308    REAL,     INTENT(IN)        :: DT, p_top, DX, DY
309    REAL, DIMENSION(ims:ime,jms:jme), INTENT(INOUT), OPTIONAL :: DX2D, AREA2D
310    LOGICAL,  INTENT(IN)        :: restart
311    REAL,     INTENT(IN)        :: RADT,BLDT,CUDT,MPDT
312    REAL,     INTENT(IN)        :: swrad_scat
314    REAL,     DIMENSION( kms:kme ) , INTENT(IN) :: zfull, zhalf
315    REAL,     DIMENSION( ims:ime , jms:jme ) , INTENT(IN) :: TSK, XLAT, XLONG,xlong_u,xlat_v
316    REAL,  DIMENSION(ims:ime,jms:jme), INTENT(IN) , OPTIONAL :: msftx,msfty
318    INTEGER,      INTENT(IN   )    ::   levsiz, n_ozmixm
319    INTEGER,      INTENT(IN   )    ::   paerlev, n_aerosolc
320    INTEGER,      INTENT(IN   )    ::   alevsiz, no_src_types
322    REAL,  DIMENSION( ims:ime, levsiz, jms:jme, n_ozmixm ), OPTIONAL, &
323           INTENT(INOUT) ::                                  OZMIXM
324    REAL,  DIMENSION( ims:ime, alevsiz, jms:jme, n_ozmixm-1, no_src_types ), OPTIONAL, &
325           INTENT(INOUT) ::                                  aerodm
327 #if ( EM_CORE == 1 )
328   !PSH/TWG 06/10/16
329    INTEGER,      INTENT(IN   )    ::   alevsiz_cu, num_months, no_src_types_cu !PSH/TWG 06/10/16
330    REAL,  DIMENSION( ims:ime, alevsiz_cu, jms:jme, num_months, no_src_types_cu), OPTIONAL, &
331           INTENT(INOUT) ::                                  aeromcu 
332    REAL,  DIMENSION( ims:ime, alevsiz_cu, jms:jme, num_months), OPTIONAL,INTENT(INOUT)  :: aeropcu 
334    REAL,  DIMENSION( ims:ime , kms:kme , jms:jme )         ,         &
335           OPTIONAL, INTENT(INOUT   ) ::                              &
336                                QR_CU, QS_CU,                         & !TWG
337                                NC_CU, NI_CU, NR_CU, NS_CU,           & !TWG
338                                CCN_CU, EFCG, EFCS, EFIG,             & !TWG
339                                EFIS, EFSG, EFSS
340   !PSH/TWG END
341 #endif
343    REAL,  DIMENSION(levsiz), OPTIONAL, INTENT(INOUT)  ::        PIN
344    REAL,  DIMENSION(alevsiz), OPTIONAL, INTENT(INOUT)  ::       PINA
346    REAL,  DIMENSION(ims:ime,jms:jme), OPTIONAL, INTENT(INOUT)  :: m_ps_1,m_ps_2
347    REAL,  DIMENSION(paerlev), OPTIONAL,INTENT(INOUT)  ::          m_hybi
348    REAL,  DIMENSION( ims:ime, paerlev, jms:jme, n_aerosolc ), OPTIONAL, &
349           INTENT(INOUT) ::                    aerosolc_1, aerosolc_2
351    REAL,     DIMENSION( ims:ime , 1:num_soil_layers , jms:jme ),&
352                  INTENT(INOUT) :: SMOIS, SH2O,TSLB
353    REAL,     DIMENSION( ims:ime , 1:num_soil_layers , jms:jme ), INTENT(OUT) :: SMFR3D
355    REAL,    DIMENSION( ims:ime, jms:jme )                     , &
356             INTENT(INOUT)    ::                           SNOW, &
357                                                          SNOWC, &
358                                                          SNOWH, &
359                                                         CANWAT, &
360                                                         SMSTAV, &
361                                                         SMSTOT, &
362                                                      SFCRUNOFF, &
363                                                       UDRUNOFF, &
364                                                         SFCEVP, &
365                                                         GRDFLX, &
366                                                         ACSNOW, &
367                                                           XICE, &
368                                                          XICEM, &
369                                                         VEGFRA, &
370                                                         ACSNOM
371    REAL,    DIMENSION( ims:ime, jms:jme ), OPTIONAL, INTENT(INOUT) ::   rliq    
373    REAL,    DIMENSION( ims:ime, jms:jme )                     , &
374             OPTIONAL, INTENT(INOUT)    ::                ACHFX, &
375                                                          ACLHF, &
376                                                       ACGRDFLX
378    INTEGER, DIMENSION( ims:ime, jms:jme )                     , &
379             INTENT(INOUT)    ::                         IVGTYP, &
380                                                         ISLTYP
381    REAL,    DIMENSION( ims:ime, jms:jme )                     , &
382             OPTIONAL, INTENT(IN)    ::                     U10, &
383                                                            V10
384    REAL,    DIMENSION( ims:ime, jms:jme )                     , &
385             OPTIONAL, INTENT(OUT)    ::                   U10E, &
386                                                           V10E
387 #if ( EM_CORE == 1 )
388    !BSINGH - For WRFCuP scheme
389    REAL, DIMENSION( ims:ime, jms:jme )                        , &
390         INTENT(INOUT)    ::                          shall, & !CuP, wig 18-Sep-2006
391                                                     tcloud_cup    !CuP, rce 18-apr-2012
392    !BSINGH - ENDS
393 #endif
394 ! rad
396 !..Added by G. Thompson to couple cloud physics variables with RRTMG radiation.
397    REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: re_cloud, &
398              re_ice, re_snow
399    INTEGER, INTENT(INOUT):: has_reqc, has_reqi, has_reqs
400 #if ( EM_CORE == 1 )
401    REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: re_cloud_gsfc, &
402              re_ice_gsfc, re_snow_gsfc, re_graupel_gsfc, re_hail_gsfc, re_rain_gsfc
403 #endif
405    REAL,     DIMENSION( ims:ime , kms:kme , jms:jme ) , INTENT(INOUT) ::    &!BSINGH(PNNL)- should be declared inout
406              RTHRATEN, RTHRATENLW, RTHRATENSW, CLDFRA
408    REAL,     DIMENSION( ims:ime , kms:kme , jms:jme ) , OPTIONAL, INTENT(INOUT) :: &!BSINGH(PNNL)- should be declared inout
409              CLDFRA_OLD
411    REAL,     DIMENSION( ims:ime , kms:kme , jms:jme ) , OPTIONAL, INTENT(INOUT) :: & ! ckay for subgrid cloud
412              cldfra_dp, cldfra_sh
414    REAL,     DIMENSION( ims:ime , jms:jme ) , INTENT(INOUT) ::         &
415              GSW,ALBEDO,ALBBCK,GLW,EMISS,EMBCK                          !EMBCK new
416    REAL,     DIMENSION( ims:ime , jms:jme ) , INTENT(INOUT) ::   SNOALB
419    REAL,     INTENT(IN) :: GMT
421    INTEGER , INTENT(OUT) :: STEPRA, STEPBL, STEPCU
422    INTEGER , INTENT(IN) :: JULYR, JULDAY
424 ! cps
426    REAL,     DIMENSION( ims:ime , kms:kme , jms:jme ) , INTENT(INOUT) :: & !BSINGH(PNNL)- should be declared inout
427              RUCUTEN, RVCUTEN, RTHCUTEN, RQVCUTEN, RQRCUTEN, RQCCUTEN, &
428              RQSCUTEN, RQICUTEN,                                       &
429              RUSHTEN, RVSHTEN, RTHSHTEN, RQVSHTEN, RQRSHTEN, RQCSHTEN, &
430              RQSSHTEN, RQISHTEN, RQGSHTEN
431 #if ( EM_CORE == 1 )
432    !BSINGH - For WRFCuP scheme
433    REAL,     DIMENSION( ims:ime , kms:kme , jms:jme ) , INTENT(INOUT) :: &
434         cldfra_cup,cldfratend_cup                              !CuP, wig 18-Sep-2006
436    LOGICAL,  DIMENSION( ims:ime , jms:jme ) , INTENT(OUT) :: cupflag !CuP, wig 9-Oct-2006
437    !BSINGH -ENDS
438 #endif
440    REAL,     DIMENSION( ims:ime , kms:kme , jms:jme ) , INTENT(INOUT), OPTIONAL :: RQCNCUTEN, RQINCUTEN 
442    REAL,     DIMENSION( ims:ime , kms:kme , jms:jme ) , INTENT(OUT) :: W0AVG
444    REAL,     DIMENSION( ims:ime , jms:jme ) , INTENT(OUT) :: MASS_FLUX,   &
445                       APR_GR,APR_W,APR_MC,APR_ST,APR_AS,          &
446                       APR_CAPMA,APR_CAPME,APR_CAPMI
448    REAL,     DIMENSION( ims:ime , kms:kme , jms:jme ) , INTENT(INOUT) ::    & !BSINGH(PNNL)- should be declared inout
449              RTHFTEN, RQVFTEN
451    REAL,     DIMENSION( ims:ime , jms:jme ) , INTENT(OUT) ::           &
452              RAINNC, RAINC, RAINCV, RAINNCV,  &
453              SNOWNC, SNOWNCV, GRAUPELNC, GRAUPELNCV
454    REAL,     DIMENSION(ims:ime,kms:kme,jms:jme), INTENT(IN) :: z_at_q            !  G. Thompson
455    REAL,     DIMENSION(ims:ime,kms:kme,jms:jme), INTENT(IN) :: inv_dens          !  G. Thompson
456    REAL,     DIMENSION(ims:ime,jms:jme), INTENT(INOUT) :: qnwfa2d, qnbca2d       !  G. Thompson
457    INTEGER,  INTENT(IN) :: num_sc                                                !  G. Thompson
458    REAL,     DIMENSION(ims:ime,kms:kme,jms:jme,num_sc), INTENT(INOUT) :: scalar  !  G. Thompson
460    REAL,     DIMENSION( ims:ime , jms:jme ) , INTENT(OUT) :: CLDEFI, NCA
462    INTEGER,  DIMENSION( ims:ime , jms:jme ) , INTENT(OUT) :: LOWLYR
464 !pbl
466    ! soil layer
468    REAL,     DIMENSION(1:num_soil_layers),      INTENT(INOUT) :: ZS,DZS
470   REAL,     DIMENSION( ims:ime , kms:kme , jms:jme ) , INTENT(INOUT) ::    & !BSINGH(PNNL)- should be declared inout
471              RUBLTEN,RVBLTEN,RTHBLTEN,RQVBLTEN,RQCBLTEN,RQIBLTEN,EXCH_H,TKE_PBL
472   REAL,     DIMENSION( ims:ime , kms:kme , jms:jme ) , INTENT(INOUT), OPTIONAL :: QKE,pek,pep
474   REAL,     DIMENSION( ims:ime , kms:kme , jms:jme ) , INTENT(OUT), OPTIONAL :: &
475                                             massflux_EDKF, entr_EDKF, detr_EDKF & 
476                                                    ,thl_up, thv_up, rt_up       &
477                                                    ,rv_up, rc_up, u_up, v_up    &
478                                                    ,frac_up
480 ! Solar diagnostics
481    REAL,     DIMENSION(ims:ime,jms:jme), OPTIONAL, INTENT(INOUT) :: ghi_accum
483    REAL,     DIMENSION( ims:ime , kms:kme , jms:jme ) , OPTIONAL, INTENT(OUT) ::    &
484              cugd_tten,cugd_ttens,cugd_qvten,                &
485              cugd_qvtens,cugd_qcten
486    REAL,     DIMENSION( ims:ime , jms:jme ) , INTENT(INOUT) ::         &
487              XLAND,ZNT,Z0,UST,MOL,LU_INDEX,                         &
488              PBLH,THC,MAVAIL,HFX,QFX,RAINBL
489    INTEGER , INTENT(INOUT)  :: landuse_ISICE, landuse_LUCATS
490    INTEGER , INTENT(INOUT)  :: landuse_LUSEAS, landuse_ISN
491    REAL    , INTENT(INOUT)  , DIMENSION( : ) :: lu_state
493    REAL,     DIMENSION( ims:ime , jms:jme ) , INTENT(INOUT) :: TMN
494    REAL,     DIMENSION( ims:ime , jms:jme ) , INTENT(INOUT),OPTIONAL :: TYR
495    REAL,     DIMENSION( ims:ime , jms:jme ) , INTENT(INOUT),OPTIONAL :: TYRA
496    REAL,     DIMENSION( ims:ime , jms:jme ) , INTENT(INOUT),OPTIONAL :: TDLY
497    REAL,     DIMENSION( ims:ime , 1:lagday , jms:jme ) , INTENT(INOUT),OPTIONAL :: TLAG
499    REAL,  DIMENSION( ims:ime , kms:kme , jms:jme )         ,         &
500           OPTIONAL, INTENT(INOUT   ) ::                              &
501                                gd_cloud, gd_cloud2,                  &
502                                gd_cloud_a, gd_cloud2_a,              &
503                                QC_CU, QI_CU
505    REAL,  DIMENSION( ims:ime ,  jms:jme )         ,         &
506           INTENT(INOUT   ) ::                                        &
507                                raincv_a,raincv_b
509 !Noah-MP
511    INTEGER, OPTIONAL, DIMENSION(ims:ime,jms:jme) :: ISNOWXY
512    REAL,    OPTIONAL, DIMENSION(ims:ime,-2:num_soil_layers, jms:jme) :: ZSNSOXY
513    REAL,    OPTIONAL, DIMENSION(ims:ime,-2:0, jms:jme) :: TSNOXY
514    REAL,    OPTIONAL, DIMENSION(ims:ime,-2:0, jms:jme) :: SNICEXY
515    REAL,    OPTIONAL, DIMENSION(ims:ime,-2:0, jms:jme) :: SNLIQXY
516    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: TVXY
517    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: TGXY
518    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: CANICEXY
519    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: CANLIQXY
520    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: EAHXY
521    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: TAHXY
522    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: CMXY
523    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: CHXY
524    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: FWETXY
525    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: SNEQVOXY
526    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: ALBOLDXY
527    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: QSNOWXY
528    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: QRAINXY
529    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: WSLAKEXY
530    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: ZWTXY
531    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: WAXY
532    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: WTXY
533    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: LFMASSXY
534    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: RTMASSXY
535    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: STMASSXY
536    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: WOODXY
537    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: GRAINXY
538    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: GDDXY
539    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: STBLCPXY
540    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: FASTCPXY
541    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: XSAIXY
542    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: LAI
543    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: T2MVXY
544    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: T2MBXY
545    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: CHSTARXY
546    REAL,    OPTIONAL, DIMENSION(ims:ime,1:num_soil_layers,jms:jme) :: SMOISEQ 
547    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: SMCWTDXY   
548    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: DEEPRECHXY
549    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: RECHXY
550    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: QRFSXY       
551    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: QSPRINGSXY
552    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: QSLATXY 
553    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: AREAXY
554    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme), INTENT(IN) :: FDEPTHXY
555    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme), INTENT(IN) :: RIVERBEDXY
556    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme), INTENT(IN) :: EQZWT
557    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: RIVERCONDXY
558    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: PEXPXY
559    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme), INTENT(IN) :: rechclim
560    INTEGER, OPTIONAL, DIMENSION(ims:ime,  jms:jme), INTENT(OUT) :: CROPCAT
561    REAL,    OPTIONAL, DIMENSION(ims:ime,5,jms:jme), INTENT(IN ) :: CROPTYPE
562    INTEGER, INTENT(IN ) :: iopt_crop, iopt_irr, iopt_irrm 
563    REAL,    OPTIONAL, DIMENSION(ims:ime,60,jms:jme) :: gecros_state      ! Optional gecros crop
565 !  Irrigation
566    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: IRWATSI 
567    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: IRWATMI
568    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: IRWATFI
569    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: IRELOSS
570    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: IRSIVOL
571    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: IRMIVOL
572    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: IRFIVOL
573    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: IRRSPLH
574    INTEGER, OPTIONAL, DIMENSION(ims:ime,jms:jme) :: IRNUMSI
575    INTEGER, OPTIONAL, DIMENSION(ims:ime,jms:jme) :: IRNUMMI
576    INTEGER, OPTIONAL, DIMENSION(ims:ime,jms:jme) :: IRNUMFI
577 ! tile drainage
578    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: qtdrain
579                                                                 
580 !   REAL, DIMENSION( ims:ime, kms:kme, jms:jme ),  OPTIONAL,  INTENT(INOUT ) ::   qnn_curr
582    INTEGER , OPTIONAL,  INTENT(OUT) :: STEPWTD
583    REAL , OPTIONAL, INTENT(IN) :: WTDDT
586    REAL,     DIMENSION( ims:ime , kms:kme , jms:jme ) , INTENT(OUT) ::   &
587              F_ICE_PHY,F_RAIN_PHY,F_RIMEF_PHY
588    REAL, DIMENSION(:), INTENT(INOUT)   :: mp_restart_state,tbpvs_state,tbpvs0_state
589    LOGICAL,  INTENT(IN)  :: allowed_to_read, moved
590    REAL, INTENT(INOUT) :: ccn_conc ! RAS
593 ! ocean mixed layer
594    REAL,     DIMENSION( ims:ime , jms:jme ) , OPTIONAL, INTENT(INOUT) ::    &
595              TML,T0ML,HML,H0ML,HUML,HVML,TMOML
596 ! fractional seaice
597    REAL,     DIMENSION( ims:ime , jms:jme ) , OPTIONAL, INTENT(INOUT) ::    &
598              TSK_SAVE
599 !fdda
600    REAL,     OPTIONAL, INTENT(IN) :: FGDT
601    INTEGER , OPTIONAL, INTENT(OUT) :: STEPFG
602    REAL,     DIMENSION( ims:ime , kms:kme , jms:jme ) , OPTIONAL, INTENT(INOUT) ::    &!BSINGH(PNNL)- should be declared inout
603              RUNDGDTEN, RVNDGDTEN, RTHNDGDTEN, RPHNDGDTEN, RQVNDGDTEN
605 ! FASDAS
607    REAL,     DIMENSION( ims:ime , jms:jme ) , INTENT(INOUT), OPTIONAL ::  &
608              SDA_HFX, SDA_QFX, QNORM, HFX_BOTH, QFX_BOTH
609 !  INTEGER,  INTENT(IN   )                                            ::  fasdas
610    REAL,     DIMENSION( ims:ime , kms:kme , jms:jme ) , OPTIONAL, INTENT(INOUT) ::    &
611              HFX_FDDA
613    REAL,     DIMENSION( ims:ime , jms:jme ) , OPTIONAL, INTENT(INOUT) ::    &
614              RMUNDGDTEN
616 !URBAN
617 !   REAL, DIMENSION(1:num_roof_layers), INTENT(INOUT) :: DZR   !urban
618 !   REAL, DIMENSION(1:num_wall_layers), INTENT(INOUT) :: DZB   !urban
619 !   REAL, DIMENSION(1:num_road_layers), INTENT(INOUT) :: DZG   !urban
620    REAL, OPTIONAL, DIMENSION(1:num_soil_layers), INTENT(INOUT) :: DZR    !urban
621    REAL, OPTIONAL, DIMENSION(1:num_soil_layers), INTENT(INOUT) :: DZB    !urban
622    REAL, OPTIONAL, DIMENSION(1:num_soil_layers), INTENT(INOUT) :: DZG    !urban
624    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: TR_URB2D !urban
625    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: TB_URB2D !urban
626    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: TG_URB2D !urban
627    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: TC_URB2D !urban
628    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: QC_URB2D !urban
629    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: XXXR_URB2D !urban
630    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: XXXB_URB2D !urban
631    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: XXXG_URB2D !urban
632    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: XXXC_URB2D !urban
634    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: DRELR_URB2D
635    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: DRELB_URB2D
636    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: DRELG_URB2D
637    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: FLXHUMR_URB2D
638    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: FLXHUMB_URB2D
639    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: FLXHUMG_URB2D
640    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: CMCR_URB2D
641    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: TGR_URB2D
643 !   REAL, DIMENSION(ims:ime, 1:num_roof_layers, jms:jme), INTENT(INOUT) :: TRL_URB3D !urban
644 !   REAL, DIMENSION(ims:ime, 1:num_wall_layers, jms:jme), INTENT(INOUT) :: TBL_URB3D !urban
645 !   REAL, DIMENSION(ims:ime, 1:num_road_layers, jms:jme), INTENT(INOUT) :: TGL_URB3D !urban
646    REAL, OPTIONAL, DIMENSION(ims:ime, 1:num_soil_layers, jms:jme), INTENT(INOUT) :: TRL_URB3D  !urban
647    REAL, OPTIONAL, DIMENSION(ims:ime, 1:num_soil_layers, jms:jme), INTENT(INOUT) :: TBL_URB3D  !urban
648    REAL, OPTIONAL, DIMENSION(ims:ime, 1:num_soil_layers, jms:jme), INTENT(INOUT) :: TGL_URB3D  !urban
649    REAL, OPTIONAL, DIMENSION(ims:ime, 1:num_soil_layers, jms:jme), INTENT(INOUT) :: TGRL_URB3D  !urban
650    REAL, OPTIONAL, DIMENSION(ims:ime, 1:num_soil_layers, jms:jme), INTENT(INOUT) :: SMR_URB3D  !urban
652    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: SH_URB2D !urban
653    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: LH_URB2D !urban
654    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: G_URB2D !urban
655    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: RN_URB2D !urban
656    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: TS_URB2D !urban
657    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: FRC_URB2D !urban
658    INTEGER, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: UTYPE_URB2D !urban
660    INTEGER , INTENT(IN)        :: num_urban_ndm
661    INTEGER , INTENT(IN)        :: urban_map_zrd
662    INTEGER , INTENT(IN)        :: urban_map_zwd
663    INTEGER , INTENT(IN)        :: urban_map_gd
664    INTEGER , INTENT(IN)        :: urban_map_zd
665    INTEGER , INTENT(IN)        :: urban_map_zdf
666    INTEGER , INTENT(IN)        :: urban_map_bd
667    INTEGER , INTENT(IN)        :: urban_map_wd
668    INTEGER , INTENT(IN)        :: urban_map_gbd
669    INTEGER , INTENT(IN)        :: urban_map_fbd
670    INTEGER , INTENT(IN)        :: urban_map_zgrd
671    INTEGER , INTENT(IN)        :: num_urban_hi
672    REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_zrd, jms:jme ), INTENT(INOUT) :: TRB_URB4D ! multi-layer UCM
673    REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_zwd, jms:jme ), INTENT(INOUT) :: TW1_URB4D ! multi-layer UCM
674    REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_zwd, jms:jme ), INTENT(INOUT) :: TW2_URB4D ! multi-layer UCM
675    REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_gd , jms:jme ), INTENT(INOUT) :: TGB_URB4D ! multi-layer UCM
676    REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_bd , jms:jme ), INTENT(INOUT) :: TLEV_URB3D ! multi-layer UCM
677    REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_bd , jms:jme ), INTENT(INOUT) :: QLEV_URB3D ! multi-layer UCM
678    REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_wd , jms:jme ), INTENT(INOUT) :: TW1LEV_URB3D ! multi-layer UCM
679    REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_wd , jms:jme ), INTENT(INOUT) :: TW2LEV_URB3D ! multi-layer UCM
680    REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_gbd, jms:jme ), INTENT(INOUT) :: TGLEV_URB3D ! multi-layer UCM
681    REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_fbd, jms:jme ), INTENT(INOUT) :: TFLEV_URB3D ! multi-layer UCM
682    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: LF_AC_URB3D !multi-layer UCM
683    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: SF_AC_URB3D !multi-layer UCM
684    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: CM_AC_URB3D !multi-layer UCM
685    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: SFVENT_URB3D !multi-layer UCM
686    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: LFVENT_URB3D !multi-layer UCM
687    REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_wd , jms:jme ), INTENT(INOUT) :: SFWIN1_URB3D ! multi-layer UCM
688    REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_wd , jms:jme ), INTENT(INOUT) :: SFWIN2_URB3D ! multi-layer UCM
689    REAL, OPTIONAL, DIMENSION( ims:ime, 1:num_urban_ndm, jms:jme ), INTENT(INOUT) :: SFG_URB3D ! multi-layer UCM
690    REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_zdf, jms:jme ), INTENT(INOUT) :: SFR_URB3D ! multi-layer UCM
691    REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_zd , jms:jme ), INTENT(INOUT) :: SFW1_URB3D ! multi-layer UCM
692    REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_zd , jms:jme ), INTENT(INOUT) :: SFW2_URB3D ! multi-layer UCM
693    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: EP_PV_URB3D!GRZ
694    REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_zdf,jms:jme ), INTENT(INOUT) :: T_PV_URB3D!GRZ
695    REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_zgrd, jms:jme),INTENT(INOUT) :: TRV_URB4D ! GRZ
696    REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_zgrd, jms:jme),INTENT(INOUT) :: QR_URB4D ! GRZ
697    REAL, OPTIONAL, DIMENSION( ims:ime,jms:jme), INTENT(INOUT) :: QGR_URB3D ! GRZ
698    REAL, OPTIONAL, DIMENSION( ims:ime,jms:jme), INTENT(INOUT) :: TGR_URB3D ! GRZ
699    REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_zdf, jms:jme),INTENT(INOUT) :: DRAIN_URB4D !GRZ
700    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: DRAINGR_URB3D   !GRZ
701    REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_zdf, jms:jme),INTENT(INOUT) :: SFRV_URB3D !GRZ
702    REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_zdf, jms:jme),INTENT(INOUT) :: LFRV_URB3D ! GRZ
703    REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_zdf, jms:jme ),INTENT(INOUT) :: DGR_URB3D !GRZ
704    REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_zdf, jms:jme ),INTENT(INOUT) :: DG_URB3D !GRZ
705    REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_zdf, jms:jme ),INTENT(INOUT) :: LFR_URB3D !GRZ
706    REAL, OPTIONAL, DIMENSION( ims:ime, 1:num_urban_ndm, jms:jme ), INTENT(INOUT) :: LFG_URB3D !GRZ
707    REAL, OPTIONAL, DIMENSION( ims:ime,1:num_urban_hi, jms:jme), INTENT(INOUT) :: HI_URB2D  !multi-layer UCM
708    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: LP_URB2D  !multi-layer UCM
709    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: LB_URB2D  !multi-layer UCM
710    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: HGT_URB2D !multi-layer UCM
711    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: MH_URB2D  !SLUCM
712    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: STDH_URB2D !SLUCM
713    REAL, OPTIONAL, DIMENSION( ims:ime, 4, jms:jme ), INTENT(INOUT) :: LF_URB2D  !SLUCM 
714    REAL, OPTIONAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: A_U_BEP
715    REAL, OPTIONAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: A_V_BEP
716    REAL, OPTIONAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: A_T_BEP
717    REAL, OPTIONAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: A_Q_BEP
718    REAL, OPTIONAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: A_E_BEP
719    REAL, OPTIONAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: B_U_BEP
720    REAL, OPTIONAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: B_V_BEP
721    REAL, OPTIONAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: B_T_BEP
722    REAL, OPTIONAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: B_Q_BEP
723    REAL, OPTIONAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: B_E_BEP
724    REAL, OPTIONAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: VL_BEP
725    REAL, OPTIONAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: DLG_BEP
726    REAL, OPTIONAL, DIMENSION(ims:ime, kms:kme,jms:jme), INTENT(INOUT) :: SF_BEP
727    REAL, OPTIONAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: DL_U_BEP
728 #if ( EM_CORE == 1 )
729    INTEGER, OPTIONAL, INTENT(IN) :: CCNTY                                               ! for ntu3m
730    REAL, OPTIONAL, INTENT(IN), DIMENSION(ims:ime,kms:kme,jms:jme) :: PHB,PH,P,PB,QV     ! for ntu3m
731    REAL, INTENT(INOUT), DIMENSION(ims:ime,kms:kme,jms:jme) :: QDCN,QTCN,QCCN,QRCN,QNIN  ! for ntu3m
732 #endif
733 ! lake varibles:
734   real,    dimension(ims:ime,jms:jme ),intent(out)                        :: lakedepth2d,    &
735                                                                              savedtke12d
736   real,    dimension(ims:ime,jms:jme ),intent(inout)                      :: snowdp2d,       &
737                                                                              h2osno2d,       &
738                                                                              snl2d,          &
739                                                                              t_grnd2d
741   real,    dimension( ims:ime,1:nlevlake, jms:jme ),INTENT(out)            :: t_lake3d,       &
742                                                                              lake_icefrac3d, &
743                                                                              z_lake3d,       &
744                                                                              dz_lake3d
745   real,    dimension( ims:ime,-nlevsnow+1:nlevsoil, jms:jme ),INTENT(inout) :: t_soisno3d,     &
746                                                                              h2osoi_ice3d,   &
747                                                                              h2osoi_liq3d,   &
748                                                                              h2osoi_vol3d,   &
749                                                                              z3d,            &
750                                                                              dz3d
751   real,    dimension( ims:ime,1:nlevsoil, jms:jme ),INTENT(out)            :: watsat3d,       &
752                                                                              csol3d,         &
753                                                                              tkmg3d,         &
754                                                                              tkdry3d,        &
755                                                                              tksatu3d
756   real,    dimension( ims:ime,-nlevsnow+0:nlevsoil, jms:jme ),INTENT(inout) :: zi3d
757   LOGICAL, DIMENSION( ims:ime, jms:jme ),intent(out)                      :: lake2d
758 !  REAL,    DIMENSION( ims:ime, jms:jme ), INTENT(IN)                      ::  HT
759   REAL, OPTIONAL,    DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) ::  lake_depth
760   REAL,              DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) ::  water_depth 
761   real, intent(in)      ::      lakedepth_default, lake_min_elev
762 #if ( EM_CORE == 1 )
763   REAL,              dimension(ims:ime,jms:jme )      ::  lakemask
764   INTEGER, INTENT(IN)      ::  lakeflag
765 #endif
766   INTEGER, INTENT(INOUT)      ::   lake_depth_flag
767   INTEGER, INTENT(IN)      ::   use_lakedepth
768   INTEGER, INTENT(INOUT)   ::   bathymetry_flag 
769   INTEGER, INTENT(IN)      ::   shalwater_z0  
770   REAL,    INTENT(IN)      ::   shalwater_depth  
773 !CLM
774    INTEGER, INTENT(IN) ::       maxpatch
775    REAL, OPTIONAL,    DIMENSION( ims:ime, jms:jme ), INTENT(IN)    ::  HT
776   integer, OPTIONAL,   dimension(ims:ime,jms:jme ),intent(inout) :: numc,nump
777   integer, OPTIONAL,   dimension(ims:ime,1:maxpatch,jms:jme ),intent(inout) :: snl
778   real, OPTIONAL,  dimension(ims:ime,1:maxpatch,jms:jme ),intent(inout) ::  &
779                 snowdp,wtc,wtp,h2osno,t_grnd,t_veg,         &
780                 h2ocan,h2ocan_col,t2m_max,t2m_min,     &
781                 t_ref2m,h2osoi_liq_s1,              &
782                 h2osoi_liq_s2,h2osoi_liq_s3,h2osoi_liq_s4,          &
783                 h2osoi_liq_s5,h2osoi_liq1,h2osoi_liq2,              &
784                 h2osoi_liq3,h2osoi_liq4,h2osoi_liq5,h2osoi_liq6,    &
785                 h2osoi_liq7,h2osoi_liq8,h2osoi_liq9,h2osoi_liq10,   &
786                 h2osoi_ice_s1,h2osoi_ice_s2,                        &
787                 h2osoi_ice_s3,h2osoi_ice_s4,h2osoi_ice_s5,          &
788                 h2osoi_ice1,h2osoi_ice2,h2osoi_ice3,h2osoi_ice4,    &
789                 h2osoi_ice5,h2osoi_ice6,h2osoi_ice7,                &
790                 h2osoi_ice8,h2osoi_ice9,h2osoi_ice10,               &
791                 t_soisno_s1,t_soisno_s2,t_soisno_s3,t_soisno_s4,    &
792                 t_soisno_s5,t_soisno1,t_soisno2,t_soisno3,          &
793                 t_soisno4,t_soisno5,t_soisno6,t_soisno7,            &
794                 t_soisno8,t_soisno9,t_soisno10,                     &
795                 dzsnow1,dzsnow2,dzsnow3,dzsnow4,dzsnow5,            &
796                 snowrds1,snowrds2,snowrds3,snowrds4,snowrds5,       &
797                 t_lake1,t_lake2,t_lake3,t_lake4,t_lake5,            &
798                 t_lake6,t_lake7,t_lake8,t_lake9,t_lake10,           &
799                 h2osoi_vol1,h2osoi_vol2,h2osoi_vol3,                &
800                 h2osoi_vol4,h2osoi_vol5,h2osoi_vol6,                &
801                 h2osoi_vol7,h2osoi_vol8,                            &
802                 h2osoi_vol9,h2osoi_vol10,                           &
803                 ALBEDOsubgrid,LHsubgrid,HFXsubgrid,LWUPsubgrid,     &
804                 Q2subgrid,SABVsubgrid,SABGsubgrid,NRAsubgrid,       &
805                 SWUPsubgrid,lhsoi,lhtran,lhveg
806 #if (WRF_USE_CLM == 1) && ( WRF_CHEM == 1 )
807    LOGICAL, INTENT(IN)          :: megan_mapped_emisfctrs
808    CHARACTER(LEN=*), INTENT(IN) :: megan_factors_file
809    CHARACTER(LEN=*), INTENT(IN) :: megan_specifier(:)
810 #endif
814 !obs fdda
815    INTEGER, OPTIONAL, INTENT(IN) :: itimestep
816 #if ( EM_CORE == 1 )
817    TYPE(fdob_type), OPTIONAL, INTENT(INOUT) :: fdob
818 #endif
819    REAL, OPTIONAL, INTENT(IN) :: p00, t00, tlp   ! for obs-nudging base-state calcn
821 ! WA 12/21/09
822    REAL,OPTIONAL, DIMENSION( ims:ime , kms:kme , jms:jme ) , &
823           INTENT(OUT) ::    te_temf, cf3d_temf    
824 ! WA 2/22/11
825    REAL,OPTIONAL, DIMENSION( ims:ime , jms:jme ) , &
826           INTENT(OUT) ::    wm_temf
828    REAL, OPTIONAL, DIMENSION( ims:ime , jms:jme ) , &
829           INTENT(  OUT) ::    pblmax, clddpthb, cldtopb, rainsh, rainshvb, &
830                               capesave, radsave, xtime1, PBLHAVG
832    REAL, OPTIONAL, DIMENSION( ims:ime , 1:100, jms:jme ) , &
833           INTENT(  OUT) ::    ainckfsa
835    INTEGER, OPTIONAL, DIMENSION( ims:ime , jms:jme ) , &
836           INTENT(  OUT) ::    kdcldtop, kdcldbas, ltopb
838    REAL, OPTIONAL, DIMENSION( ims:ime , kms:kme , jms:jme ) ,                &
839           INTENT(  OUT) ::    wub, cldareaa,  cldareab,            &
840                                    cldliqa,   cldliqb,   TKEAVG,   &
841                                    ca_rad, cw_rad
843    REAL, OPTIONAL, DIMENSION( ims:ime , kms:kme , jms:jme ) , INTENT(OUT) :: &
844              RDCASHTEN, RQCDCSHTEN
846 ! Local data
848    REAL    :: ALBLND,ZZLND,ZZWTR,THINLD,XMAVA,CEN_LAT,pptop
849    REAL,     DIMENSION( kms:kme )  :: sfull, shalf
850    REAL :: obs_twindo_cg, obs_twindo
852    CHARACTER*256 :: MMINLU_loc
853    CHARACTER*80 :: message
854    INTEGER :: ISWATER
855    INTEGER :: ISICE
856    INTEGER :: ISURBAN
857    INTEGER :: sf_urban_physics
858    INTEGER :: sf_ocean_physics
859    REAL    :: oml_hml0
860    INTEGER :: LakeModel
861    LOGICAL :: usemonalb
862    LOGICAL :: rdmaxalb
863    INTEGER :: mfshconv
864    INTEGER :: icloud_cu
865    INTEGER :: iopt_run
866    INTEGER :: aercu_opt !PSH/TWG 
867    REAL    :: aercu_fct !PSH/TWG 
870    INTEGER :: i, j, k, itf, jtf, ktf, n
871    INTEGER :: myproc
873 !-------------------------------------------------
874 ! Noah-mosaic related variables are added to declaration  (danli)
875 !-------------------------------------------------
876   
877   INTEGER, INTENT(IN) :: sf_surface_mosaic, NLCAT   
878   INTEGER, INTENT(IN) :: mosaic_cat
879   REAL, DIMENSION( ims:ime, NLCAT, jms:jme ) , INTENT(IN) , OPTIONAL::   LANDUSEF
880   REAL, DIMENSION( ims:ime, NLCAT, jms:jme ) , INTENT(INOUT) , OPTIONAL::   LANDUSEF2 
881   INTEGER, DIMENSION( ims:ime, NLCAT, jms:jme ), INTENT(INOUT), OPTIONAL :: mosaic_cat_index 
883   REAL, DIMENSION( ims:ime, 1:mosaic_cat, jms:jme ) , OPTIONAL, INTENT(INOUT):: &
884         TSK_mosaic, CANWAT_mosaic, SNOW_mosaic,SNOWH_mosaic, SNOWC_mosaic
885   REAL, DIMENSION( ims:ime, 1:mosaic_cat, jms:jme ) , OPTIONAL, INTENT(INOUT)::                &
886         ALBEDO_mosaic,ALBBCK_mosaic, EMISS_mosaic, EMBCK_mosaic, ZNT_mosaic, Z0_mosaic
887   REAL, DIMENSION( ims:ime, 1:num_soil_layers*mosaic_cat, jms:jme ), OPTIONAL, INTENT(INOUT):: &
888         TSLB_mosaic,SMOIS_mosaic,SH2O_mosaic
889   REAL, DIMENSION( ims:ime, 1:mosaic_cat, jms:jme ) , OPTIONAL, INTENT(INOUT)::                &
890         TR_URB2D_mosaic, TB_URB2D_mosaic, TG_URB2D_mosaic, TC_URB2D_mosaic,QC_URB2D_mosaic,    &
891         SH_URB2D_mosaic,LH_URB2D_mosaic,G_URB2D_mosaic,RN_URB2D_mosaic,TS_URB2D_mosaic, TS_RUL2D_mosaic  
892                   
893    REAL, OPTIONAL, DIMENSION( ims:ime, 1:num_soil_layers*mosaic_cat, jms:jme ), INTENT(INOUT) :: TRL_URB3D_mosaic
894    REAL, OPTIONAL, DIMENSION( ims:ime, 1:num_soil_layers*mosaic_cat, jms:jme ), INTENT(INOUT) :: TBL_URB3D_mosaic
895    REAL, OPTIONAL, DIMENSION( ims:ime, 1:num_soil_layers*mosaic_cat, jms:jme ), INTENT(INOUT) :: TGL_URB3D_mosaic  
896    LOGICAL :: IPRINT
897    REAL :: max_utype_urb2d
899 !-------------------------------------------------
900 ! End of Noah-mosaic 
901 !-------------------------------------------------  
902    
903 ! IRRIGATION
904   INTEGER,OPTIONAL,INTENT(OUT), DIMENSION( ims:ime,jms:jme):: irr_rand_field 
905   INTEGER, OPTIONAL :: irr_ph,irr_freq 
906 !-----------------------------------------------------------------
908 ! Climate GHG file read for radiation
909 REAL(KIND=8) :: co2dum,n2odum,ch4dum,f11dum,f12dum
910 CHARACTER(LEN=8) :: name
911 !-----------------------------------------------------------------
913 #if ( EM_CORE == 1 )
915    !  Compute 2d grid distance and 2d grid cell area. For use with
916    !  physics schemes that have a grid distance (area) as input for
917    !  scale-aware capability.
919    if ( .not. restart) then
920      if ( present(dx2d) .and. present(area2d) ) then
921         call compute_2d_dx_area(dx, dy, msftx, msfty, dx2d, area2d, &
922                               ids, ide, jds, jde, kds, kde,       &
923                               ims, ime, jms, jme, kms, kme,       &
924                               its, ite, jts, jte, kts, kte)
925       end if
926    end if
927 #endif
929    name = "        "
930    IF ( ( config_flags%ghg_input .EQ. 1 ) .AND. &
931         ( .NOT. this_is_an_ideal_run ) )   THEN
932       IF      ( config_flags%ra_lw_physics .EQ. RRTMSCHEME          ) THEN
933          name = "RRTM"
934       ELSE IF ( config_flags%ra_lw_physics .EQ. CAMLWSCHEME         ) THEN
935          name = "CAM"
936       ELSE IF ( config_flags%ra_lw_physics .EQ. RRTMG_LWSCHEME      ) THEN
937          name = "RRTMG"
938       ELSE IF ( config_flags%ra_lw_physics .EQ. RRTMG_LWSCHEME_FAST ) THEN
939          name = "RRTMG"
940       END IF
941       CALL read_CAMgases(julyr,float(julday),.true.,TRIM(name),co2dum,n2odum,ch4dum,f11dum,f12dum)
942       WRITE(message,*) 'GHG annual values from CAM trace gas file'
943       CALL wrf_message(TRIM(message))
944       WRITE(message,*) 'Year = ',julyr,', Julian day = ',julday
945       CALL wrf_message(TRIM(message))
946       WRITE(message,*) 'CO2   = ',co2dum,' volume mixing ratio'
947       CALL wrf_message(TRIM(message))
948       WRITE(message,*) 'N2O   = ',n2odum,' volume mixing ratio'
949       CALL wrf_message(TRIM(message))
950       WRITE(message,*) 'CH4   = ',ch4dum,' volume mixing ratio'
951       CALL wrf_message(TRIM(message))
952       WRITE(message,*) 'CFC11 = ',f11dum,' volume mixing ratio'
953       CALL wrf_message(TRIM(message))
954       WRITE(message,*) 'CFC12 = ',f12dum,' volume mixing ratio'
955       CALL wrf_message(TRIM(message))
956    END IF
958    aercu_opt=config_flags%aercu_opt !PSH/TWG 06/10/16
959    aercu_fct=config_flags%aercu_fct !PSH/TWG 06/10/16
960    sf_urban_physics=config_flags%sf_urban_physics
961    usemonalb=config_flags%usemonalb
962    rdmaxalb=config_flags%rdmaxalb
963    LakeModel = config_flags%sf_lake_physics
964    mfshconv=config_flags%mfshconv
965    IF(PRESENT(SMOISEQ)) THEN
966       iopt_run=config_flags%opt_run
967    ELSE
968       iopt_run=-1
969    END IF
970 #if ( EM_CORE == 1 )
971    obs_twindo_cg=model_config_rec%obs_twindo(1)
972    obs_twindo=config_flags%obs_twindo
973    oml_hml0=config_flags%oml_hml0
974    sf_ocean_physics=config_flags%sf_ocean_physics
975 #else
976    obs_twindo_cg=0
977    obs_twindo=0
978    oml_hml0=0
979 #endif
981 !..Added G. Thompson to determine if we will compute and pass radiative
982 !.. effective radii of cloud water, ice, and snow.  Currently ONLY properly
983 !.. connected if using Physics options Thompson-MP and RRTMG-LW/SW.
984 ! 10/2014: T. Mansell added support for NSSL_2MOM options
985    has_reqc = 0
986    has_reqi = 0
987    has_reqs = 0
988    IF ( config_flags%use_mp_re .EQ. 1 ) THEN
989    if (( (config_flags%ra_lw_physics .eq. RRTMG_LWSCHEME ) .or. &
990 #if( BUILD_RRTMG_FAST == 1)
991          (config_flags%ra_lw_physics .eq. RRTMG_LWSCHEME_FAST ) .or. &
992 #endif
993 #if( BUILD_RRTMK == 1)
994          (config_flags%ra_lw_physics .eq. RRTMK_LWSCHEME  ) .or. &
995 #endif
996          (config_flags%ra_lw_physics .eq. goddardlwscheme ) ) .and. &
997        ( (config_flags%ra_sw_physics .eq. RRTMG_SWSCHEME ) .or. &
998 #if( BUILD_RRTMG_FAST == 1)
999          (config_flags%ra_sw_physics .eq. RRTMG_SWSCHEME_FAST ) .or. &
1000 #endif
1001 #if( BUILD_RRTMK == 1)
1002          (config_flags%ra_sw_physics .eq. RRTMK_SWSCHEME ) .or. &
1003 #endif
1004          (config_flags%ra_sw_physics .eq. goddardswscheme ) ) .and. &
1005         (config_flags%mp_physics  .eq. THOMPSON .or.        &
1006          config_flags%mp_physics  .eq. THOMPSONAERO .or.    &
1007          (config_flags%mp_physics .eq. NSSL_2MOM .and. config_flags%nssl_2moment_on == 1) .or. &
1008          config_flags%mp_physics  .eq. WSM3SCHEME .or.      &
1009          config_flags%mp_physics  .eq. WSM5SCHEME .or.      &
1010          config_flags%mp_physics  .eq. WSM6SCHEME .or.      &
1011          config_flags%mp_physics  .eq. WSM7SCHEME .or.      &
1012          config_flags%mp_physics  .eq. WDM5SCHEME .or.      &
1013          config_flags%mp_physics  .eq. WDM6SCHEME .or.      &
1014          config_flags%mp_physics  .eq. WDM7SCHEME .or.      &
1015          config_flags%mp_physics  .eq. nuwrf4icescheme .or. &
1016          config_flags%mp_physics  .eq. JENSEN_ISHMAEL .or.  &
1017          config_flags%mp_physics  .eq. P3_1CATEGORY .or.    &
1018          config_flags%mp_physics  .eq. P3_1CATEGORY_NC .or. &
1019          config_flags%mp_physics  .eq. P3_2CATEGORY .or.    &    
1020          config_flags%mp_physics  .eq. P3_1CAT_3MOM   ) ) then    ! P3
1021       has_reqc = 1
1022       has_reqi = 1
1023       has_reqs = 1
1024    endif
1026 ! for P3, to ensure correct coupling with predicted effective radii
1027    if (config_flags%mp_physics .eq. P3_1CATEGORY .or.       &
1028        config_flags%mp_physics .eq. P3_1CATEGORY_NC .or.    &
1029        config_flags%mp_physics .eq. JENSEN_ISHMAEL .or.    &
1030        config_flags%mp_physics .eq. P3_1CAT_3MOM .or.      &
1031        config_flags%mp_physics .eq. P3_2CATEGORY      ) then
1032       has_reqs = 0
1033    end if
1035 ! If using FARMS (swint_opt==2), we need both effective radii and the mass
1036 ! for cloud, ice, and snow.
1038    IF ( config_flags%swint_opt .eq. 2 ) THEN
1039       IF ((   config_flags%mp_physics == THOMPSON .OR.        &
1040               config_flags%mp_physics == THOMPSONAERO .OR.    &
1041               config_flags%mp_physics == WSM3SCHEME .OR.    &
1042               config_flags%mp_physics == WSM5SCHEME .OR.    &
1043               config_flags%mp_physics == WSM6SCHEME .OR.    &
1044               config_flags%mp_physics == WSM7SCHEME .OR.    &
1045               config_flags%mp_physics == WDM5SCHEME .OR.    &
1046               config_flags%mp_physics == WDM6SCHEME .OR.    &
1047               config_flags%mp_physics == WDM7SCHEME ).OR.     &
1048           (( has_reqc .EQ. 0 .AND. has_reqi .EQ. 0 .and. has_reqs .EQ. 0 ) .AND. &
1049            ( f_qc            ) .AND. &
1050            ( f_qi            ) .AND. &
1051            ( f_qs            ))) THEN
1052          !  everything is A-OK for FARMS
1053       ELSE
1054          CALL wrf_error_fatal ('--- ERROR: FARMS (swint_opt==2) requires a different MP scheme (Please see the module_physics_init')
1055       END IF
1056    END IF
1058    ENDIF ! use_mp_re .EQ. 1
1060 !-- should be from the namelist
1062    sfull = 0.
1063    shalf = 0.
1065    CALL wrf_debug(100,'top of phy_init')
1067    WRITE(wrf_err_message,*) 'phy_init:  start_of_simulation = ',start_of_simulation
1068    CALL wrf_debug ( 100, TRIM(wrf_err_message) )
1070    itf=min0(ite,ide-1)
1071    jtf=min0(jte,jde-1)
1072    ktf=min0(kte,kde-1)
1074    ZZLND=0.1
1075    ZZWTR=0.0001
1076    THINLD=0.04
1077    ALBLND=0.2
1078    XMAVA=0.3
1080 #if (NMM_CORE == 1)
1081    if (.not.usemonalb) CALL wrf_error_fatal('usemonalb should always be true for NMM')
1082 #endif
1084    CALL nl_get_cen_lat(id,cen_lat)
1085    CALL wrf_debug(100,'calling nl_get_iswater, nl_get_isice, nl_get_mminlu_loc')
1086    CALL nl_get_iswater(id,iswater)
1087    CALL nl_get_isice(id,isice)
1088    CALL nl_get_isurban(id,isurban)
1089 !jm   CALL nl_get_mminlu( 1, mminlu_loc )
1090    CALL nl_get_mminlu( id, mminlu_loc )
1091 #if (NMM_CORE == 1 && HWRF == 1 )
1092    IF ( trim(mminlu_loc) .eq. "" ) THEN
1093      CALL wrf_message('WARNING:   MMINLU NOT SET, USING USGS')
1094      MMINLU_LOC = 'USGS'
1095    ENDIF
1096 #endif
1097    CALL wrf_debug(100,'after nl_get_iswater, nl_get_isice, nl_get_mminlu_loc')
1098 !-- temporary fix by ww
1099    landuse_ISICE = isice
1101 !..Determine which cu_rad_feedback option to use
1103    icloud_cu = 0
1104    IF ( config_flags%cu_rad_feedback ) THEN
1105       IF ( config_flags%cu_physics == kfetascheme ) THEN
1106          icloud_cu = 2
1107       ELSE IF ( config_flags%cu_physics == gfscheme .OR. &
1108                 config_flags%cu_physics == g3scheme .OR. &
1109                 config_flags%cu_physics == gdscheme ) THEN
1110          icloud_cu = 1
1111       END IF
1112    END IF
1113 #if (EM_CORE == 1)
1114    IF ( config_flags%cu_physics == mskfscheme) THEN
1115         icloud_cu = 2
1116    END IF
1118 !--------------------INPUT FOR AEROSOL DATA-----------------------
1119 !-----------------------------PSH/TWG-----------------------------
1120    IF ( aercu_opt .GT. 0 .AND. id .EQ. 1 ) THEN
1121       CALL aerosol_in_cu(aeromcu,alevsiz_cu,num_months,no_src_types_cu,XLAT,XLONG,aeropcu,&
1122                      ids, ide, jds, jde, kds, kde,                  &
1123                      ims, ime, jms, jme, kms, kme,                  &
1124                      its, ite, jts, jte, kts, kte)
1125    ENDIF
1126 !-----------------------------PSH/TWG-----------------------------
1128 ! Initialize Cumulus Hydrometeors
1129     if (config_flags%aercu_opt == 1 )then
1130      do j=jts,jtf
1131        do k=kts,ktf
1132           do i=its,itf
1133             QC_CU(i,k,j) = 0.
1134             QI_CU(i,k,j) = 0.
1135             QR_CU(i,k,j) = 0.
1136             QS_CU(i,k,j) = 0.
1137             NC_CU(i,k,j) = 0.
1138             NI_CU(i,k,j) = 0.
1139             NR_CU(i,k,j) = 0.
1140             NS_CU(i,k,j) = 0.
1141             CCN_CU(i,k,j) = 0.
1142             EFCG(i,k,j) = 2.51
1143             EFCS(i,k,j) = 2.51
1144             EFIS(i,k,j) = 5.01
1145             EFIG(i,k,j) = 5.01
1146             EFSG(i,k,j) = 10.01
1147             EFSS(i,k,j) = 10.01
1148           end do
1149        end do
1150      end do
1151     endif
1153 #endif
1154    CALL nl_set_icloud_cu ( id , icloud_cu )
1156   IF(.not.restart)THEN !{
1157 !-- initialize common variables
1158      !BSINGH - When all the CAM parameterizations are not executed in WRF,
1159      !rliq can have undefined behaviour
1160  IF (config_flags%cu_physics == CAMZMSCHEME .or. config_flags%shcu_physics == CAMUWSHCUSCHEME ) THEN
1161      IF(PRESENT(rliq)) THEN
1162         rliq(:,:) = 0.0 
1163      ENDIF
1164  ENDIF
1165    IF ( .NOT. moved ) THEN
1166    DO j=jts,jtf
1167    DO i=its,itf
1168       XLAND(i,j)=float(config_flags%ideal_xland)
1169       GSW(i,j)=0.
1170       GLW(i,j)=0.
1171 !-- initialize ust to a small value
1172       UST(i,j)=0.0001
1173       MOL(i,j)=0.0
1174       PBLH(i,j)=0.0
1175       HFX(i,j)=0.
1176       QFX(i,j)=0.
1177       RAINBL(i,j)=0.
1178       RAINNCV(i,j)=0.
1179       SNOWNCV(i,j)=0.
1180       GRAUPELNCV(i,j)=0.
1181       ACSNOW(i,j)=0.
1182       DO k=kms,kme  !wig, 17-May-2006: Added for idealized chem. runs
1183          EXCH_H(i,k,j) = 0.
1184       END DO
1185    ENDDO
1186    ENDDO
1187    ENDIF
1189    DO j=jts,jtf
1190    DO i=its,itf
1191      IVGTYP(i,j) = NINT(LU_INDEX(i,j))
1192    ENDDO
1193    ENDDO
1196    IF(PRESENT(TMN_UPDATE))THEN
1197    if(tmn_update.eq.1) then
1198    nyear=1
1199    nday=0.
1200    DO j=jts,jtf
1201    DO i=its,itf
1202       TYR(i,j)=TMN(i,j)
1203       TYRA(i,j)=0.0
1204       TDLY(i,j)=0.0
1205     DO n=1,lagday
1206       TLAG(i,n,j)=TMN(i,j)
1207     ENDDO
1208    ENDDO
1209    ENDDO
1210    endif
1211    ENDIF
1215    DO j=jts,jtf
1216    DO i=its,itf
1217      IF(XLAND(i,j) .LT. 1.5)THEN
1218        IF(mminlu_loc .EQ. '    ') ALBBCK(i,j)=ALBLND
1219        EMBCK(i,j)=0.85
1220        ALBEDO(i,j)=ALBBCK(i,j)
1221        EMISS(i,j)=EMBCK(i,j)
1222        THC(i,j)=THINLD
1223        ZNT(i,j)=ZZLND
1224 #if  ! ( NMM_CORE == 1 )
1225        Z0(i,j)=ZZLND
1226 #endif
1227        MAVAIL(i,j)=XMAVA
1228      ELSE
1229        IF(mminlu_loc .EQ. '    ') ALBBCK(i,j)=0.08
1230        ALBEDO(i,j)=ALBBCK(i,j)
1231        EMBCK(i,j)=0.98
1232        EMISS(i,j)=EMBCK(i,j)
1233        THC(i,j)=THINLD
1234        ZNT(i,j)=ZZWTR
1235 #if  ! ( NMM_CORE == 1 )
1236        Z0(i,j)=ZZWTR
1237 #endif
1238        MAVAIL(i,j)=1.0
1239      ENDIF
1241    ENDDO
1242    ENDDO
1244     if (config_flags%cu_diag == 1 )then
1245     do j=jts,jtf
1246        do k=kts,ktf
1247           do i=its,itf
1248              gd_cloud(i,k,j) = 0.
1249              gd_cloud2(i,k,j) = 0.
1250              gd_cloud_a(i,k,j) = 0.
1251              gd_cloud2_a(i,k,j) = 0.
1252              QC_CU(i,k,j) = 0.
1253              QI_CU(i,k,j) = 0.
1254           end do
1255        end do
1256     end do
1257     endif
1259     do j=jts,jtf
1260          do i=its,itf
1261            raincv_a(i,j)=0.
1262            raincv_b(i,j)=0.
1263       end do
1264     end do
1266 !..Fill initial starting values of radiative effective radii for
1267 !.. cloud water (2.49 microns), cloud ice (4.99 microns), and
1268 !.. snow (9.99 microns).
1269     if (has_reqc.ne.0) then
1270        do j=jts,jtf
1271           do k=kts,ktf
1272           do i=its,itf
1273              re_cloud(i,k,j) = RE_QC_BG
1274           end do
1275           end do
1276        end do
1277     endif
1278     if (has_reqi.ne.0) then
1279        do j=jts,jtf
1280           do k=kts,ktf
1281           do i=its,itf
1282              re_ice(i,k,j) = RE_QI_BG
1283           end do
1284           end do
1285        end do
1286     endif
1287     if (has_reqs.ne.0) then
1288        do j=jts,jtf
1289           do k=kts,ktf
1290           do i=its,itf
1291              re_snow(i,k,j) = RE_QS_BG
1292           end do
1293           end do
1294        end do
1295     endif
1297 !  Initialize cloud droplet effective radii for Goddard MP and/or Radiation
1298 #if ( EM_CORE == 1 )
1300    if ( config_flags%ra_lw_physics .EQ. GODDARDLWSCHEME .OR. &
1301         config_flags%ra_sw_physics .EQ. GODDARDSWSCHEME .OR. &
1302         config_flags%mp_physics    .EQ. NUWRF4ICESCHEME ) THEN
1303       do j=jts,jtf
1304          do k=kts,ktf
1305             do i=its,itf
1306                re_cloud_gsfc(i,k,j)   = 0.
1307                re_rain_gsfc(i,k,j)    = 0.
1308                re_snow_gsfc(i,k,j)    = 0.
1309                re_ice_gsfc(i,k,j)     = 0.
1310                re_graupel_gsfc(i,k,j) = 0.
1311                re_hail_gsfc(i,k,j)    = 0.
1312             end do
1313          end do
1314       end do
1315    end if
1316 #endif
1318 !  Initializing special output from myjsfc and qnsesfc
1320    if ( config_flags%sf_sfclay_physics .EQ. MYJSFCSCHEME .OR. &
1321         config_flags%sf_sfclay_physics .EQ. QNSESFCSCHEME ) THEN
1322       do j=jts,jtf
1323          do i=its,itf
1324             u10e(i,j) = u10(i,j)
1325             v10e(i,j) = v10(i,j)
1326          end do
1327       end do
1328    end if
1330    CALL wrf_debug ( 200 , 'module_start: phy_init: Before call to landuse_init' )
1332    IF(mminlu_loc .ne. '    ')THEN
1333 !-- initialize surface properties
1335      CALL landuse_init(lu_index, snowc, albedo, albbck, snoalb, mavail, emiss, embck, &
1336                 znt, Z0, thc, xland, xice, xicem, julday, cen_lat, iswater, &
1337                 TRIM ( mminlu_loc ) ,                               &
1338                 landuse_ISICE, landuse_LUCATS,                      &
1339                 landuse_LUSEAS, landuse_ISN,                        &
1340                 config_flags%fractional_seaice,                      &
1341                 lu_state,                                           &
1342                 allowed_to_read , usemonalb ,                       &
1343                 ids, ide, jds, jde, kds, kde,                       &
1344                 ims, ime, jms, jme, kms, kme,                       &
1345                 its, ite, jts, jte, kts, kte                       )
1346    ENDIF
1348   ENDIF !}
1350 !-- convert zfull and zhalf to sigma values for ra_init (Eta CO2 needs these)
1351 !-- zfull/zhalf may be either zeta or eta
1352 !-- what is done here depends on coordinate (check this code if adding new coordinates)
1353    CALL z2sigma(zfull,zhalf,sfull,shalf,p_top,pptop,config_flags, &
1354                 allowed_to_read,                                  &
1355                 kds,kde,kms,kme,kts,kte)
1357    ! CAM parameterizations specific initializations [Currently incorporates initializations for CAMZM, CAMUWPBL, CAMUWSHCU and CAMMGMP parameterizations]
1359    !Findout whether CAMMGMP scheme is used used or not in this simulation
1360    is_CAMMGMP_used = .FALSE.
1361 # if (EM_CORE == 1)
1362    if(config_flags%mp_physics == CAMMGMPSCHEME) is_CAMMGMP_used = .TRUE.
1363 # endif
1365 #if ( WRF_CHEM == 1 )
1366    !BSINGH:02/01/2013 - For WRF_CHEM simulations, initialize cam_mam_aerosols variable
1367    cam_mam_aerosols = .FALSE.
1368    if(config_flags%chem_opt == CBMZ_CAM_MAM3_NOAQ .OR. config_flags%chem_opt == CBMZ_CAM_MAM3_AQ &
1369         .OR. config_flags%chem_opt == CBMZ_CAM_MAM7_NOAQ .OR. config_flags%chem_opt == CBMZ_CAM_MAM7_AQ) cam_mam_aerosols = .TRUE.
1370       
1371 #endif
1374    if(       config_flags%bl_pbl_physics == CAMUWPBLSCHEME     .OR. config_flags%cu_physics == CAMZMSCHEME      &
1375         .OR. config_flags%shcu_physics   == CAMUWSHCUSCHEME                                                     & 
1376 # if (EM_CORE == 1)
1377         .OR. config_flags%mp_physics == CAMMGMPSCHEME                                                           &
1378 # endif
1379 #if ( WRF_CHEM == 1 )
1380         !For WRF_CHEM simulations, first five constituents are added in CAM_INIT and rest are added in the MODULE_CAM_MAM_INIT in chem/
1381         .OR. config_flags%chem_opt       == CBMZ_CAM_MAM3_NOAQ .OR. config_flags%chem_opt   == CBMZ_CAM_MAM3_AQ &
1382         .OR. config_flags%chem_opt       == CBMZ_CAM_MAM7_NOAQ .OR. config_flags%chem_opt   == CBMZ_CAM_MAM7_AQ &
1383 #endif
1384       ) THEN
1385       CALL CAM_INIT(ixcldliq, ixcldice, ixnumliq, ixnumice, config_flags)
1386    ENDIF
1387 !-- initialize physics
1388 !-- ra: radiation
1389 !-- bl: pbl
1390 !-- cu: cumulus
1391 !-- mp: microphysics
1394 ! .... paj ... initialize wind farm ...
1396   IF ( config_flags%windfarm_opt .EQ. 1 ) THEN
1397     CALL init_module_wind_fitch(id,config_flags,xlong,xlat,windfarm_initialized,ims,ime,jms,jme,its,ite,jts,jte,ids,ide,jds,jde)
1398   ! --- Yulong ---
1399   ELSEIF ( config_flags%windfarm_opt .EQ. 2 ) THEN
1400     CALL init_module_wind_mav(id,config_flags,xlong,xlat,windfarm_initialized, &
1401                               dx,ims,ime,jms,jme,its,ite,jts,jte,ids,ide,jds,jde)
1402   ENDIF
1404    CALL wrf_debug ( 200 , 'module_start: phy_init: Before call to ra_init' )
1406    CALL ra_init(id=id,STEPRA=STEPRA,RADT=RADT,DT=DT,RTHRATEN=RTHRATEN,RTHRATENLW=RTHRATENLW,             &
1407                 RTHRATENSW=RTHRATENSW,CLDFRA=CLDFRA,EMISS=EMISS,cen_lat=cen_lat,JULYR=JULYR,JULDAY=JULDAY,GMT=GMT,    &
1408                 levsiz=levsiz,XLAT=XLAT,XLONG=XLONG,n_ozmixm=n_ozmixm,     &
1409                 alevsiz=alevsiz,no_src_types=no_src_types,                 &
1410                 cldfra_dp=cldfra_dp,cldfra_sh=cldfra_sh,                   & ! optional for subgrid cloud by ckay
1411                 cldfra_old=cldfra_old,                                     & ! Optional
1412                 ozmixm=ozmixm,pin=pin,                                     & ! Optional
1413                 aerodm=aerodm,pina=pina,                                   & ! Optional
1414                 m_ps_1=m_ps_1,m_ps_2=m_ps_2,m_hybi=m_hybi,aerosolc_1=aerosolc_1,aerosolc_2=aerosolc_2,     & ! Optional
1415                 paerlev=paerlev,n_aerosolc=n_aerosolc,                             &
1416                 sfull=sfull,shalf=shalf,pptop=pptop,swrad_scat=swrad_scat,p_top=p_top,       &
1417                 config_flags=config_flags,restart=restart,                           &
1418                 allowed_to_read=allowed_to_read, start_of_simulation=start_of_simulation,           &
1419                 ids=ids, ide=ide, jds=jds, jde=jde, kds=kds, kde=kde,                   &
1420                 ims=ims, ime=ime, jms=jms, jme=jme, kms=kms, kme=kme,                   &
1421                 its=its, ite=ite, jts=jts, jte=jte, kts=kts, kte=kte                    )
1423    CALL wrf_debug ( 200 , 'module_start: phy_init: Before call to bl_init' )
1424    CALL bl_init(STEPBL,BLDT,DT,RUBLTEN,RVBLTEN,RTHBLTEN,        &
1425                 RQVBLTEN,RQCBLTEN,RQIBLTEN,TSK,TMN,             &
1426                 config_flags,restart,UST,LOWLYR,TSLB,ZS,DZS,    &
1427                 num_soil_layers,TKE_PBL,mfshconv,pek,pep,       &
1428                 massflux_EDKF, entr_EDKF, detr_EDKF, & 
1429                 thl_up, thv_up, rt_up,       &
1430                 rv_up, rc_up, u_up, v_up,    &
1431                 frac_up, itimestep,id,                          &
1432                 EXCH_H,VEGFRA,                                  &
1433                 SNOW,SNOWC, CANWAT,SMSTAV,                      &
1434                 SMSTOT, SFCRUNOFF,UDRUNOFF,ACSNOW,ACSNOM,       &
1435                 IVGTYP,ISLTYP,ISURBAN,SMOIS,SMFR3D,MAVAIL,      &
1436                 SNOWH,SH2O,SNOALB,FNDSOILW,FNDSNOWH,RDMAXALB,   &
1437 #if (NMM_CORE == 1)
1438                 Z0,XLAND,XICE,                                  &
1439                 DX,DY,                                          &
1440 #else
1441                 ZNT,XLAND,XICE,                                 &
1442                 DX, DY, MSFTX, MSFTY,                           &
1443 #endif
1444                 QKE,                                            &
1445                 SFCEVP,GRDFLX,                                  &
1446                 TRIM (MMINLU_LOC),                              &
1447                 XLAT, XLONG,                                    &
1448                 ISNOWXY, ZSNSOXY, TSNOXY,                       &
1449                 SNICEXY, SNLIQXY, TVXY, TGXY, CANICEXY,         &
1450                 CANLIQXY, EAHXY, TAHXY, CMXY,                   &
1451                 CHXY, FWETXY, SNEQVOXY,ALBOLDXY,QSNOWXY,QRAINXY,&
1452                 WSLAKEXY, ZWTXY, WAXY, WTXY, LFMASSXY, RTMASSXY,&
1453                 STMASSXY, WOODXY, STBLCPXY, FASTCPXY,           &
1454                 GRAINXY, GDDXY,                                 & ! Noah-MP Crop model
1455                 croptype, cropcat,                              & ! Noah-MP Crop model
1456                 iopt_crop,                                      & 
1457                 iopt_irr, iopt_irrm,                            &
1458                 IRNUMSI, IRNUMMI, IRNUMFI, IRWATSI, IRWATMI,    & ! Noah-MP Irrigation
1459                 IRWATFI, IRELOSS, IRSIVOL, IRMIVOL, IRFIVOL,    & ! Noah-MP Irrigation
1460                 IRRSPLH, qtdrain,                               & ! Noah-MP Irrigation
1461                 gecros_state,                                   & ! Optional gecros crop
1462                 XSAIXY, LAI,                                    &
1463                 SMOISEQ, SMCWTDXY, RECHXY, DEEPRECHXY, AREAXY,  &
1464                 WTDDT, STEPWTD, QRFSXY ,QSPRINGSXY ,QSLATXY,   &
1465                 FDEPTHXY, RIVERBEDXY, EQZWT, RIVERCONDXY, PEXPXY, & 
1466                 rechclim  ,                                     &
1467                 ISICE,                                 &
1468                 T2MVXY,T2MBXY,CHSTARXY ,                        &
1469                 allowed_to_read , iopt_run ,                    &
1470                 start_of_simulation ,                           &
1471                 lakedepth2d,  savedtke12d,  snowdp2d,   h2osno2d,       & !lake
1472                 snl2d,        t_grnd2d,     t_lake3d,   lake_icefrac3d, & !lake
1473                 z_lake3d,     dz_lake3d,    t_soisno3d, h2osoi_ice3d,   & !lake
1474                 h2osoi_liq3d, h2osoi_vol3d, z3d,        dz3d,           & !lake
1475                 zi3d,         watsat3d,     csol3d,     tkmg3d,         & !lake
1476                 tkdry3d,      tksatu3d,     LakeModel,  lake2d,           & !lake
1477                 lakedepth_default,            lake_min_elev, lake_depth,       & !lake
1478 #if (EM_CORE == 1)
1479                 lakemask, lakeflag,                                    & !lake
1480 #endif
1481                 lake_depth_flag, use_lakedepth,                        & !lake
1482                 water_depth, bathymetry_flag, shalwater_z0,     & 
1483                 shalwater_depth,                                & 
1484                 te_temf,cf3d_temf,wm_temf,                      & ! WA
1485                 DZR, DZB, DZG,                                  & !Optional urban
1486                 TR_URB2D,TB_URB2D,TG_URB2D,TC_URB2D,QC_URB2D,   & !Optional urban
1487                 XXXR_URB2D,XXXB_URB2D,XXXG_URB2D,XXXC_URB2D,    & !Optional urban
1488                 TRL_URB3D, TBL_URB3D, TGL_URB3D,                & !Optional urban
1489                 SH_URB2D, LH_URB2D, G_URB2D, RN_URB2D,          & !Optional urban
1490                 TS_URB2D, FRC_URB2D, UTYPE_URB2D,               & 
1491                 SF_URBAN_PHYSICS,                               & !Optional urban
1492                 CMCR_URB2D,TGR_URB2D,TGRL_URB3D,SMR_URB3D,      & !Optional urban
1493                 DRELR_URB2D,DRELB_URB2D,DRELG_URB2D,            & !Optional urban
1494                 FLXHUMR_URB2D,FLXHUMB_URB2D,FLXHUMG_URB2D,      & !Optional urban
1495                 num_urban_ndm,                                  & !Optional multi-layer urban
1496                 urban_map_zrd,                                  & !Optional multi-layer urban
1497                 urban_map_zwd,                                  & !Optional multi-layer urban
1498                 urban_map_gd ,                                  & !Optional multi-layer urban
1499                 urban_map_zd ,                                  & !Optional multi-layer urban
1500                 urban_map_zdf,                                  & !Optional multi-layer urban
1501                 urban_map_bd ,                                  & !Optional multi-layer urban
1502                 urban_map_wd ,                                  & !Optional multi-layer urban
1503                 urban_map_gbd,                                  & !Optional multi-layer urban
1504                 urban_map_fbd,                                  & !Optional multi-layer urban
1505                 urban_map_zgrd,                                 & !Optional multi-layer urban
1506                 NUM_URBAN_HI,                                   & !Optional multi-layer urban
1507                 TRB_URB4D,TW1_URB4D,TW2_URB4D,                  & !Optional multi-layer urban
1508                 TGB_URB4D,TLEV_URB3D,QLEV_URB3D,                & !Optional multi-layer urban
1509                 TW1LEV_URB3D,TW2LEV_URB3D,                      & !Optional multi-layer urban
1510                 TGLEV_URB3D,TFLEV_URB3D,                        & !Optional multi-layer urban
1511                 SF_AC_URB3D,LF_AC_URB3D,CM_AC_URB3D,            & !Optional multi-layer urban
1512                 SFVENT_URB3D,LFVENT_URB3D,                      & !Optional multi-layer urban
1513                 SFWIN1_URB3D,SFWIN2_URB3D,                      & !Optional multi-layer urban
1514                 SFW1_URB3D,SFW2_URB3D,                          & !Optional multi-layer urban
1515                 SFR_URB3D,SFG_URB3D,                            & !Optional multi-layer urban
1516                 EP_PV_URB3D,T_PV_URB3D,                         & !GRZ
1517                 TRV_URB4D,QR_URB4D,QGR_URB3D,TGR_URB3D,         & !GRZ
1518                 DRAIN_URB4D,DRAINGR_URB3D,SFRV_URB3D,           & !GRZ
1519                 LFRV_URB3D,DGR_URB3D,DG_URB3D,LFR_URB3D,LFG_URB3D,&!GRZ
1520                 LP_URB2D,HI_URB2D,LB_URB2D,                     & !Optional multi-layer urban
1521                 HGT_URB2D,MH_URB2D,STDH_URB2D,                  & !Optional multi-layer urban
1522                 LF_URB2D,                                       & !Optional multi-layer urban
1523                 A_U_BEP,A_V_BEP,A_T_BEP,A_Q_BEP,                & !Optional multi-layer urban
1524                 A_E_BEP,B_U_BEP,B_V_BEP,                        & !Optional multi-layer urban
1525                 B_T_BEP,B_Q_BEP,B_E_BEP,DLG_BEP,                & !Optional multi-layer urban
1526                 DL_U_BEP,SF_BEP,VL_BEP,                         & !Optional multi-layer urban
1527                 ids, ide, jds, jde, kds, kde,                   &
1528                 ims, ime, jms, jme, kms, kme,                   &
1529                 its, ite, jts, jte, kts, kte,                   &
1530                 ACHFX,ACLHF,ACGRDFLX,                           &
1531                 oml_hml0, sf_ocean_physics,                     & !Optional oml
1532                 TML,T0ML,HML,H0ML,HUML,HVML,TMOML,              & !Optional oml
1533                 is_CAMMGMP_used                                 &
1534                ,TSK_SAVE                                        & !Optional fractional seaice
1535 ! CLM vraiables 
1536                ,numc,nump,snl,                                      &
1537                 snowdp,wtc,wtp,h2osno,t_grnd,t_veg,         &
1538                 h2ocan,h2ocan_col,t2m_max,t2m_min,t_ref2m,          &
1539                 h2osoi_liq_s1,              &
1540                 h2osoi_liq_s2,h2osoi_liq_s3,h2osoi_liq_s4,          &
1541                 h2osoi_liq_s5,h2osoi_liq1,h2osoi_liq2,              &
1542                 h2osoi_liq3,h2osoi_liq4,h2osoi_liq5,h2osoi_liq6,    &
1543                 h2osoi_liq7,h2osoi_liq8,h2osoi_liq9,h2osoi_liq10,   &
1544                 h2osoi_ice_s1,h2osoi_ice_s2,                        &
1545                 h2osoi_ice_s3,h2osoi_ice_s4,h2osoi_ice_s5,          &
1546                 h2osoi_ice1,h2osoi_ice2,h2osoi_ice3,h2osoi_ice4,    &
1547                 h2osoi_ice5,h2osoi_ice6,h2osoi_ice7,                &
1548                 h2osoi_ice8,h2osoi_ice9,h2osoi_ice10,               &
1549                 t_soisno_s1,t_soisno_s2,t_soisno_s3,t_soisno_s4,    &
1550                 t_soisno_s5,t_soisno1,t_soisno2,t_soisno3,          &
1551                 t_soisno4,t_soisno5,t_soisno6,t_soisno7,            &
1552                 t_soisno8,t_soisno9,t_soisno10,                     &
1553                 dzsnow1,dzsnow2,dzsnow3,dzsnow4,dzsnow5,            &
1554                 snowrds1,snowrds2,snowrds3,snowrds4,snowrds5,       &
1555                 t_lake1,t_lake2,t_lake3,t_lake4,t_lake5,            &
1556                 t_lake6,t_lake7,t_lake8,t_lake9,t_lake10,           &
1557                 h2osoi_vol1,h2osoi_vol2,h2osoi_vol3,                &
1558                 h2osoi_vol4,h2osoi_vol5,h2osoi_vol6,                &
1559                 h2osoi_vol7,h2osoi_vol8,                            &
1560                 h2osoi_vol9,h2osoi_vol10,                           &
1561                 ht,maxpatch,                                        &
1562                 ALBEDOsubgrid,LHsubgrid,HFXsubgrid,LWUPsubgrid,     &
1563                 Q2subgrid,SABVsubgrid,SABGsubgrid,NRAsubgrid,       &
1564                 SWUPsubgrid,lhsoi,lhveg,lhtran                      &
1565 #if (WRF_USE_CLM == 1) && ( WRF_CHEM == 1)
1566                 ,megan_specifier, megan_factors_file                &
1567                 ,megan_mapped_emisfctrs                             &
1568 #endif
1569 ! end of CLM vraiables 
1570                 ,landusef,landusef2,NLCAT                       & ! danli mosaic
1571                 ,sf_surface_mosaic, mosaic_cat                  & ! danli mosaic
1572                 ,mosaic_cat_index                               & ! danli mosaic  
1573                 ,TSK_mosaic,TSLB_mosaic                         & ! danli mosaic
1574                 ,SMOIS_mosaic,SH2O_mosaic                       & ! danli mosaic 
1575                 ,CANWAT_mosaic,SNOW_mosaic                      & ! danli mosaic
1576                 ,SNOWH_mosaic,SNOWC_mosaic                      & ! danli mosaic
1577                 ,ALBEDO,ALBBCK, EMISS, EMBCK                    & ! danli mosaic          
1578                 ,ALBEDO_mosaic,ALBBCK_mosaic, EMISS_mosaic, EMBCK_mosaic, ZNT_mosaic, Z0_mosaic   &         ! danli mosaic
1579                 ,TR_URB2D_mosaic,TB_URB2D_mosaic                &  !danli mosaic 
1580                 ,TG_URB2D_mosaic,TC_URB2D_mosaic                &  !danli mosaic 
1581                 ,QC_URB2D_mosaic                                &  !danli mosaic                  
1582                 ,TRL_URB3D_mosaic,TBL_URB3D_mosaic              &  !danli mosaic 
1583                 ,TGL_URB3D_mosaic                               &  !danli mosaic 
1584                 ,SH_URB2D_mosaic,LH_URB2D_mosaic                &  !danli mosaic 
1585                 ,G_URB2D_mosaic,RN_URB2D_mosaic                 &  !danli mosaic 
1586                 ,TS_URB2D_mosaic                                &  !danli mosaic 
1587                 ,TS_RUL2D_mosaic                                &  !danli mosaic 
1588                 ,irr_rand_field,irr_ph,irr_freq                 &
1589                ) 
1591    CALL wrf_debug ( 200 , 'module_start: phy_init: Before call to cu_init' )
1593    CALL cu_init(DX,STEPCU,CUDT,DT,RUCUTEN,RVCUTEN,RTHCUTEN,     &
1594                 RQVCUTEN,RQRCUTEN,RQCCUTEN,RQSCUTEN,RQICUTEN,   &
1595                 NCA,RAINC,RAINCV,W0AVG,config_flags,restart,    &
1596                 CLDEFI,LOWLYR,                                  &
1597                 MASS_FLUX,RTHFTEN,RQVFTEN,                      &
1598 #if ( EM_CORE == 1 )
1599                 !BSINGH - For WRFCuP Scheme
1600                 cupflag,cldfra_cup,cldfratend_cup,              & !CuP, wig 18-Sep-2006
1601                 shall,                                          & !CuP, wig 18-Sep-2006
1602                 tcloud_cup,                                     & !CuP, rce 18-apr-2012
1603                 !BSINGH -ENDS
1604 #endif
1605                 APR_GR,APR_W,APR_MC,APR_ST,APR_AS,              &
1606                 APR_CAPMA,APR_CAPME,APR_CAPMI,                  &
1607                 cugd_tten,cugd_ttens,cugd_qvten,                &
1608                 cugd_qvtens,cugd_qcten,                         &
1609                 allowed_to_read, start_of_simulation,           &
1610                 ids, ide, jds, jde, kds, kde,                   &
1611                 ims, ime, jms, jme, kms, kme,                   &
1612                 its, ite, jts, jte, kts, kte,                   &
1613                 RQCNCUTEN,RQINCUTEN)
1615    CALL wrf_debug ( 200 , 'module_start: phy_init: Before call to shcu_init' )
1617    CALL shcu_init(STEPCU,CUDT,DT,RUSHTEN,RVSHTEN,RTHSHTEN,      &
1618                 RQVSHTEN,RQRSHTEN,RQCSHTEN,                     &
1619                 RQSSHTEN,RQISHTEN,RQGSHTEN,                     &
1620                 NCA,RAINC,RAINCV,config_flags,restart,          &
1621                 allowed_to_read, start_of_simulation,           &
1622                 RDCASHTEN, RQCDCSHTEN, W0AVG          &
1623                ,cldareaa, cldareab, cldliqa, cldliqb  &
1624                ,ca_rad, cw_rad                  &
1625                ,pblmax, wub, ltopb, clddpthb, cldtopb &
1626                ,capesave, ainckfsa, radsave           &
1627                ,rainsh, rainshvb, kdcldtop, kdcldbas          &
1628                 ,xtime1, PBLHAVG, TKEAVG,             &
1629                 ids, ide, jds, jde, kds, kde,                   &
1630                 ims, ime, jms, jme, kms, kme,                   &
1631                 its, ite, jts, jte, kts, kte                    )
1633    CALL wrf_debug ( 200 , 'module_start: phy_init: Before call to mp_init' )
1635    CALL mp_init(RAINNC,SNOWNC,GRAUPELNC,config_flags,restart,warm_rain,          &
1636                 adv_moist_cond,                                 &
1637                 MPDT, DT, DX, DY, LOWLYR,                       &
1638                 F_ICE_PHY,F_RAIN_PHY,F_RIMEF_PHY,               &
1639 #if ( EM_CORE == 1 )
1640                 PHB,PH,P,PB,QV,XLAND,CCNTY,QDCN,QTCN,QCCN,QRCN, & ! for ntu3m
1641                 QNIN,                                           & ! for ntu3m
1642 #endif
1643                 mp_restart_state,tbpvs_state,tbpvs0_state,      &
1644                 allowed_to_read, start_of_simulation,           &
1645 !CAMMGMP specific variables
1646                 ixcldliq, ixcldice, ixnumliq, ixnumice,         &
1647                 ccn_conc,                                        & ! RAS
1648                 z_at_q, inv_dens, qnwfa2d, qnbca2d,             &  ! G. Thompson
1649                 frc_urb2d, scalar, num_sc,                      &  ! G. Thompson
1650                 ids, ide, jds, jde, kds, kde,                   &
1651                 ims, ime, jms, jme, kms, kme,                   &
1652                 its, ite, jts, jte, kts, kte                    )
1654 #if  ( EM_CORE == 1 )
1655    CALL wrf_debug ( 200 , 'module_start: phy_init: Before call to fg_init' )
1657    CALL fg_init(STEPFG,FGDT,DT,id,RUNDGDTEN,RVNDGDTEN,          &
1658                 RTHNDGDTEN,RPHNDGDTEN,RQVNDGDTEN,RMUNDGDTEN,    &
1659                 SDA_HFX, SDA_QFX, QNORM, HFX_BOTH, QFX_BOTH,    & ! fasdas
1660                 HFX_FDDA,                                       & ! fasdas
1661                 config_flags,restart,                           &
1662                 allowed_to_read ,                               &
1663                 ids, ide, jds, jde, kds, kde,                   &
1664                 ims, ime, jms, jme, kms, kme,                   &
1665                 its, ite, jts, jte, kts, kte                    )
1667    CALL wrf_debug ( 200 , 'module_start: phy_init: Before call to fdob_init' )
1669    CALL fdob_init(model_config_rec%obs_nudge_opt,               &
1670                   model_config_rec%max_dom,                     &
1671                   id,                                           &
1672                   model_config_rec%parent_id,                   &
1673                   model_config_rec%obs_idynin,                  &
1674                   model_config_rec%obs_dtramp,                  &
1675                   model_config_rec%fdda_end,                    &
1676                   model_config_rec%restart,                     &
1677                   obs_twindo_cg, obs_twindo,                    &
1678                   itimestep,                                    &
1679                   model_config_rec%obs_no_pbl_nudge_uv,         &
1680                   model_config_rec%obs_no_pbl_nudge_t,          &
1681                   model_config_rec%obs_no_pbl_nudge_q,          &
1682                   model_config_rec%obs_sfc_scheme_horiz,        &
1683                   model_config_rec%obs_sfc_scheme_vert,         &
1684                   model_config_rec%obs_max_sndng_gap,           &
1685                   model_config_rec%obs_sfcfact,                 &
1686                   model_config_rec%obs_sfcfacr,                 &
1687                   model_config_rec%obs_dpsmx,                   &
1688                   model_config_rec%obs_nudge_wind,              &
1689                   model_config_rec%obs_nudge_temp,              &
1690                   model_config_rec%obs_nudge_mois,              &
1691                   model_config_rec%obs_nudgezfullr1_uv,         &
1692                   model_config_rec%obs_nudgezrampr1_uv,         &
1693                   model_config_rec%obs_nudgezfullr2_uv,         &
1694                   model_config_rec%obs_nudgezrampr2_uv,         &
1695                   model_config_rec%obs_nudgezfullr4_uv,         &
1696                   model_config_rec%obs_nudgezrampr4_uv,         &
1697                   model_config_rec%obs_nudgezfullr1_t,          &
1698                   model_config_rec%obs_nudgezrampr1_t,          &
1699                   model_config_rec%obs_nudgezfullr2_t,          &
1700                   model_config_rec%obs_nudgezrampr2_t,          &
1701                   model_config_rec%obs_nudgezfullr4_t,          &
1702                   model_config_rec%obs_nudgezrampr4_t,          &
1703                   model_config_rec%obs_nudgezfullr1_q,          &
1704                   model_config_rec%obs_nudgezrampr1_q,          &
1705                   model_config_rec%obs_nudgezfullr2_q,          &
1706                   model_config_rec%obs_nudgezrampr2_q,          &
1707                   model_config_rec%obs_nudgezfullr4_q,          &
1708                   model_config_rec%obs_nudgezrampr4_q,          &
1709                   model_config_rec%obs_nudgezfullmin,           &
1710                   model_config_rec%obs_nudgezrampmin,           &
1711                   model_config_rec%obs_nudgezmax,               &
1712                   xlat,                                         &
1713                   xlong,                                        &
1714                   model_config_rec%start_year(id),              &
1715                   model_config_rec%start_month(id),             &
1716                   model_config_rec%start_day(id),               &
1717                   model_config_rec%start_hour(id),              &
1718                   model_config_rec%start_minute(id),            &
1719                   model_config_rec%start_second(id),            &
1720                   p00, t00, tlp,                                &
1721                   zhalf, p_top,                                 &
1722                   fdob,                                         &
1723                   model_config_rec%obs_ipf_init,                &
1724                   ids, ide, jds, jde, kds, kde,                 &
1725                   ims, ime, jms, jme, kms, kme,                 &
1726                   its, ite, jts, jte, kts, kte                  )
1728 #endif
1729 #if ( WRF_CHEM == 1)
1730    if ((config_flags%chem_opt == gocart_simple .or. &
1731         config_flags%chem_opt == gocartracm_kpp .or. &
1732         config_flags%chem_opt == 302 .or. &
1733         config_flags%chem_opt == gocartradm2) .and. &
1734         config_flags%gsfcgce_gocart_coupling == 1) then
1735       CALL wrf_debug(200 , 'phy_init: Before call to makelut_ccn_icn')
1736       call makelut_ccn_icn
1737    end if
1738 #endif
1740    END SUBROUTINE phy_init
1742 !=====================================================================
1743    SUBROUTINE landuse_init(lu_index, snowc, albedo, albbck, snoalb, mavail, emiss, embck, &
1744                 znt,Z0,thc,xland, xice, xicem, julday, cen_lat, iswater, mminlu,  &
1745                 ISICE, LUCATS, LUSEAS, ISN,                         &
1746                 fractional_seaice,                                  &
1747                 lu_state,                                           &
1748                 allowed_to_read , usemonalb ,                       &
1749                 ids, ide, jds, jde, kds, kde,                       &
1750                 ims, ime, jms, jme, kms, kme,                       &
1751                 its, ite, jts, jte, kts, kte                       )
1753    USE module_wrf_error
1754    IMPLICIT NONE
1756 !---------------------------------------------------------------------
1757    INTEGER , INTENT(IN)           :: ids, ide, jds, jde, kds, kde,   &
1758                                      ims, ime, jms, jme, kms, kme,   &
1759                                      its, ite, jts, jte, kts, kte
1761    INTEGER , INTENT(IN)           :: iswater, julday
1762    REAL    , INTENT(IN)           :: cen_lat
1763    CHARACTER(LEN=*), INTENT(IN)        :: mminlu
1764    LOGICAL,  INTENT(IN)           :: allowed_to_read , usemonalb
1765    REAL,     DIMENSION( ims:ime , jms:jme ) , INTENT(IN   ) :: lu_index, snowc, xice, snoalb 
1766    REAL,     DIMENSION( ims:ime , jms:jme ) , INTENT(OUT  ) :: albedo, albbck, mavail, emiss, &
1767                                                                embck,                         &
1768                                                                znt, Z0, thc, xland, xicem
1769    INTEGER , INTENT(INOUT)  :: ISICE, LUCATS, LUSEAS, ISN, fractional_seaice
1770    REAL    , INTENT(INOUT)  , DIMENSION( : ) :: lu_state
1772    REAL :: xice_threshold
1773 !---------------------------------------------------------------------
1775 ! Input Variable Description:
1776 !  ALBD: Surface albedo
1777 !  SLMO: Moisture availability
1778 !  SFEM: Emissivity
1779 !  SFZ0: Roughness length
1780 !  THERIN: Thermal inertia (only used in SLAB)
1781 !  SFHC: Soil heat capacity (not used)
1782 !  SCFX: Snow cover effect (dependent on SNOWC)
1784 ! Local
1785    CHARACTER*256 LUTYPE
1786    CHARACTER*512 :: message
1787    INTEGER  :: landuse_unit, LS, LC, LI, LUN, NSN
1788    INTEGER  :: i, j, itf, jtf, is, cats, seas, curs
1789    INTEGER , PARAMETER :: OPEN_OK = 0
1790    INTEGER :: ierr
1791    INTEGER , PARAMETER :: max_cats = 100 , max_seas = 12
1792    REAL    , DIMENSION( max_cats, max_seas ) :: ALBD, SLMO, SFEM, SFZ0, THERIN, SFHC
1793    REAL    , DIMENSION( max_cats )     :: SCFX
1794 ! save these fields in case nest moves or has to be reinitialized
1795 ! and this routine is called with allowed_to_read set to false
1796 ! note that by saving these, we're locking in the same landuse for
1797 ! the duration of a run; possible implications for long climate runs
1798    LOGICAL :: found_lu, end_of_file
1799    LOGICAL, EXTERNAL :: wrf_dm_on_monitor
1801 !---------------------------------------------------------------------
1803    CALL wrf_debug( 100 , 'top of landuse_init' )
1805    NSN=-1  ! set this to suppress uninitalized data messages from tools
1807   if ( fractional_seaice == 0 ) then
1808      xice_threshold = 0.5
1809   else if ( fractional_seaice == 1 ) then
1810      xice_threshold = 0.02
1811   endif
1813 ! recover LU variables from state
1814    IF ( 6*(max_cats*max_seas)+1*max_cats .GT. 7501 ) THEN
1815       WRITE(message,*)'landuse_init: lu_state overflow. Make Registry dimspec p > ',6*(max_cats*max_seas)+1*max_cats
1816    ENDIF
1817    curs = 1
1818    DO cats = 1, max_cats
1819      SCFX(cats) =           lu_state(curs)         ; curs = curs + 1
1820      DO seas = 1, max_seas
1821        ALBD(cats,seas) =    lu_state(curs)         ; curs = curs + 1
1822        SLMO(cats,seas) =    lu_state(curs)         ; curs = curs + 1
1823        SFEM(cats,seas) =    lu_state(curs)         ; curs = curs + 1
1824        SFZ0(cats,seas) =    lu_state(curs)         ; curs = curs + 1
1825        SFHC(cats,seas) =    lu_state(curs)         ; curs = curs + 1
1826        THERIN(cats,seas) =  lu_state(curs)         ; curs = curs + 1
1827      ENDDO
1828    ENDDO
1830 ! Determine season (summer=1, winter=2)
1831    ISN=1
1832    IF(JULDAY.LT.105.OR.JULDAY.GT.288)ISN=2
1833    IF(CEN_LAT.LT.0.0)ISN=3-ISN
1835    FOUND_LU = .TRUE.
1836    IF ( allowed_to_read ) THEN
1837       landuse_unit = 29
1838       IF ( wrf_dm_on_monitor() ) THEN
1839         OPEN(landuse_unit, FILE='LANDUSE.TBL',FORM='FORMATTED',STATUS='OLD',IOSTAT=ierr)
1840         IF ( ierr .NE. OPEN_OK ) THEN
1841           WRITE(message,FMT='(A)') &
1842           'module_physics_init.F: LANDUSE_INIT: open failure for LANDUSE.TBL'
1843           CALL wrf_error_fatal ( message )
1844         END IF
1845         REWIND(landuse_unit)
1846       ENDIF
1848 ! Read info from file LANDUSE.TBL
1849 !     IF(MMINLU.EQ.'OLD ')THEN
1850 !       ISWATER=7
1851 !       ISICE=11
1852 !     ELSE IF(MMINLU.EQ.'USGS')THEN
1853 !       ISWATER=16
1854 !       ISICE=24
1855 !     ELSE IF(MMINLU.EQ.'SiB ')THEN
1856 !       ISWATER=15
1857 !       ISICE=16
1858 !     ELSE IF(MMINLU.EQ.'LW12')THEN
1859 !       ISWATER=15
1860 !       ISICE=3
1861 !     ELSE IF (MMINLU .EQ. 'MODIFIED_IGBP_MODIS_NOAH') THEN
1862 !       ISICE = 15
1863 !     ELSE
1864 !        call wrf_error_fatal ("INPUT LandUse not found: "//TRIM(MMINLU))
1865 !     ENDIF
1866       call wrf_message ( 'INPUT LandUse = "' // TRIM(MMINLU) // '"' )
1867       FOUND_LU = .FALSE.
1868       end_of_file = .FALSE.
1869 !!! BEGINNING OF 1999 LOOP
1870  1999 CONTINUE
1871       IF ( wrf_dm_on_monitor() ) THEN
1872         READ (landuse_unit,*,END=2002)LUTYPE
1873         GOTO 2003
1874  2002   CONTINUE
1875         CALL wrf_message( 'INPUT FILE FOR LANDUSE REACHED END OF FILE' )
1876         end_of_file = .TRUE.
1877  2003   CONTINUE
1878         IF ( .NOT. end_of_file ) READ (landuse_unit,*)LUCATS,LUSEAS
1879         FOUND_LU = LUTYPE.EQ.MMINLU
1880       ENDIF
1881       CALL wrf_dm_bcast_bytes (end_of_file, LWORDSIZE )
1882       IF ( .NOT. end_of_file ) THEN
1883         CALL wrf_dm_bcast_string(lutype, 256)
1884         CALL wrf_dm_bcast_bytes (lucats,  IWORDSIZE )
1885         CALL wrf_dm_bcast_bytes (luseas,  IWORDSIZE )
1886         CALL wrf_dm_bcast_bytes (found_lu,  LWORDSIZE )
1887         IF(FOUND_LU)THEN
1888           LUN=LUCATS
1889           NSN=LUSEAS
1890             IF(LUTYPE.NE.'SSIB') THEN !this is not really true for ssib lsm (fds)
1891             write(message,*) 'LANDUSE TYPE = "' // TRIM (LUTYPE) // '" FOUND',        &
1892                    LUCATS,' CATEGORIES',LUSEAS,' SEASONS',     &
1893                    ' WATER CATEGORY = ',ISWATER,               &
1894                    ' SNOW CATEGORY = ',ISICE
1895             call wrf_message(message)
1896             ENDIF
1897         ENDIF
1898         DO ls=1,luseas
1899           if ( wrf_dm_on_monitor() ) then
1900             READ (landuse_unit,*)
1901           endif
1902           DO LC=1,LUCATS
1903             IF(found_lu)THEN
1904               IF ( wrf_dm_on_monitor() ) THEN
1905                 READ (landuse_unit,*)LI,ALBD(LC,LS),SLMO(LC,LS),SFEM(LC,LS),        &
1906                            SFZ0(LC,LS),THERIN(LC,LS),SCFX(LC),SFHC(LC,LS)
1907               ENDIF
1908               CALL wrf_dm_bcast_bytes (LI,  IWORDSIZE )
1909               IF(LC.NE.LI)CALL wrf_error_fatal ( 'module_start: MISSING LANDUSE UNIT ' )
1910             ELSE
1911               IF ( wrf_dm_on_monitor() ) THEN
1912                 READ (landuse_unit,*)
1913               ENDIF
1914             ENDIF
1915           ENDDO
1916         ENDDO
1917         IF(NSN.EQ.1.AND.FOUND_LU) THEN
1918            ISN = 1
1919         END IF
1920         CALL wrf_dm_bcast_bytes (albd,   max_cats * max_seas * RWORDSIZE )
1921         CALL wrf_dm_bcast_bytes (slmo,   max_cats * max_seas * RWORDSIZE )
1922         CALL wrf_dm_bcast_bytes (sfem,   max_cats * max_seas * RWORDSIZE )
1923         CALL wrf_dm_bcast_bytes (sfz0,   max_cats * max_seas * RWORDSIZE )
1924         CALL wrf_dm_bcast_bytes (therin, max_cats * max_seas * RWORDSIZE )
1925         CALL wrf_dm_bcast_bytes (sfhc,   max_cats * max_seas * RWORDSIZE )
1926         CALL wrf_dm_bcast_bytes (scfx,   max_cats *            RWORDSIZE )
1927       ENDIF
1929       IF(.NOT. found_lu .AND. .NOT. end_of_file ) GOTO 1999
1930 !!! END OF 1999 LOOP
1932       IF(.NOT. found_lu .OR. end_of_file )THEN
1933         CALL wrf_message ( 'LANDUSE IN INPUT FILE DOES NOT MATCH LUTABLE: TABLE NOT USED' )
1934       ENDIF
1935     ENDIF  ! allowed_to_read
1937     IF(FOUND_LU)THEN
1938 ! Set arrays according to lu_index
1939       itf = min0(ite, ide-1)
1940       jtf = min0(jte, jde-1)
1941       IF(usemonalb)CALL wrf_message ( 'Climatological albedo is used instead of table values' )
1942       DO j = jts, jtf
1943         DO i = its, itf
1944           IS=nint(lu_index(i,j))
1945           ! only do this check on read-in data
1946           IF(allowed_to_read)THEN
1947              IF(IS.LT.0.OR.IS.GT.LUN)THEN
1948                WRITE ( wrf_err_message , * ) 'ERROR: LANDUSE OUTSIDE RANGE =',IS,' AT ',I,J,' LUN= ',LUN
1949                CALL wrf_error_fatal ( TRIM ( wrf_err_message ) )
1950              ENDIF
1951           ENDIF
1952 !   SET NO-DATA POINTS (IS=0) TO WATER
1953           IF(IS.EQ.0)THEN
1954             IS=ISWATER
1955           ENDIF
1956           IF(.NOT.usemonalb)ALBBCK(I,J)=ALBD(IS,ISN)/100.
1957           ALBEDO(I,J)=ALBBCK(I,J)
1958           IF(SNOWC(I,J) .GT. 0.5) THEN 
1959              IF (usemonalb) THEN
1960                  ALBEDO(I,J)=SNOALB(I,J)
1961              ELSE
1962                  ALBEDO(I,J)=ALBBCK(I,J)*(1.+SCFX(IS))
1963              ENDIF
1964           ENDIF
1965           THC(I,J)=THERIN(IS,ISN)/100.
1966           Z0(I,J)=SFZ0(IS,ISN)/100.
1967           ZNT(I,J)=Z0(I,J)
1968           EMBCK(I,J)=SFEM(IS,ISN)
1969           EMISS(I,J)=EMBCK(I,J)
1970           MAVAIL(I,J)=SLMO(IS,ISN)
1971           IF(IS.NE.ISWATER)THEN
1972             XLAND(I,J)=1.0
1973           ELSE
1974             XLAND(I,J)=2.0
1975           ENDIF
1976 !    SET SEA-ICE POINTS TO LAND WITH ICE/SNOW SURFACE PROPERTIES
1977           XICEM(I,J)=XICE(I,J)
1978           IF(XICE(I,J).GE.xice_threshold)THEN
1979             XLAND(I,J)=1.0
1980             ALBBCK(I,J)=ALBD(ISICE,ISN)/100.
1981             EMBCK(I,J)=SFEM(ISICE,ISN)
1982             IF (FRACTIONAL_SEAICE == 1) THEN
1983                ! The 0.08 value is the albedo over open water.
1984                ! The 0.98 value is the emissivity over open water.
1985                ALBEDO(I,J) = ( XICE(I,J) * ALBBCK(I,J) ) + ( (1.0-XICE(I,J)) * 0.08 )
1986                EMISS(I,J)  = ( XICE(I,J) * EMBCK(I,J)  ) + ( (1.0-XICE(I,J)) * 0.98 )
1987             ELSE
1988                ALBEDO(I,J)=ALBBCK(I,J)
1989                EMISS(I,J)=EMBCK(I,J)
1990             ENDIF
1991             THC(I,J)=THERIN(ISICE,ISN)/100.
1992             Z0(I,J)=SFZ0(ISICE,ISN)/100.
1993             ZNT(I,J)=Z0(I,J)
1994             MAVAIL(I,J)=SLMO(ISICE,ISN)
1995           ENDIF
1996         ENDDO
1997       ENDDO
1998     ENDIF
1999     if ( wrf_dm_on_monitor() .and. allowed_to_read ) then
2000       CLOSE (landuse_unit)
2001     endif
2002     CALL wrf_debug( 100 , 'returning from of landuse_init' )
2004 ! restore LU variables from state
2005     curs = 1
2006     DO cats = 1, max_cats
2007       lu_state(curs) = SCFX(cats)                 ; curs = curs + 1
2008       DO seas = 1, max_seas
2009         lu_state(curs) = ALBD(cats,seas)          ; curs = curs + 1
2010         lu_state(curs) = SLMO(cats,seas)          ; curs = curs + 1
2011         lu_state(curs) = SFEM(cats,seas)          ; curs = curs + 1
2012         lu_state(curs) = SFZ0(cats,seas)          ; curs = curs + 1
2013         lu_state(curs) = SFHC(cats,seas)          ; curs = curs + 1
2014         lu_state(curs) = THERIN(cats,seas)        ; curs = curs + 1
2015       ENDDO
2016     ENDDO
2018 !-- fds (07/2010)
2019 !-- SSIB's 12-category vegetation parameters are defined in module_ssib_veg
2020 !-- Data in LANDUSE.TBL is only used temporarily until the first
2021 !-- call to SSIB, and also to set water/ice points properties
2022 !    IF(MMINLU.EQ.'SSIB')THEN
2023 !       CALL init_module_ssib_veg
2024 !       CALL wrf_message ( 'READING SSIB VEGETATION PARAMETERS' )
2025 !    ENDIF
2028    END SUBROUTINE landuse_init
2030 !=====================================================================
2031    SUBROUTINE ra_init(id,STEPRA,RADT,DT,RTHRATEN,RTHRATENLW,       &
2032                       RTHRATENSW,CLDFRA,EMISS,cen_lat,JULYR,JULDAY,GMT,    &
2033                       levsiz,XLAT,XLONG,n_ozmixm,                     &
2034                       alevsiz,no_src_types,                           &
2035                       cldfra_dp,cldfra_sh,                            & ! Optional for subgrid cloud by ckay
2036                       cldfra_old,                                     & ! Optional
2037                       ghi_accum,                                      & ! Optional
2038                       ozmixm,pin,                                     & ! Optional
2039                       aerodm,pina,                                    & ! Optional
2040                       m_ps_1,m_ps_2,m_hybi,aerosolc_1,aerosolc_2,     & ! Optional
2041                       paerlev,n_aerosolc,                             &
2042                       sfull,shalf,pptop,swrad_scat,p_top,            &
2043                       config_flags,restart,                          &
2044                       allowed_to_read, start_of_simulation,          &
2045                       ids, ide, jds, jde, kds, kde,                  &
2046                       ims, ime, jms, jme, kms, kme,                  &
2047                       its, ite, jts, jte, kts, kte                   )
2048 !---------------------------------------------------------------------
2049    USE module_ra_rrtm      , ONLY : rrtminit
2050    USE module_ra_rrtmg_lw  , ONLY : rrtmg_lwinit
2051    USE module_ra_rrtmg_sw  , ONLY : rrtmg_swinit
2052 #if( BUILD_RRTMG_FAST == 1)
2053    USE module_ra_rrtmg_lwf  , ONLY : rrtmg_lwinit_fast
2054    USE module_ra_rrtmg_swf  , ONLY : rrtmg_swinit_fast
2055 #endif
2056 #if (EM_CORE == 1)
2057 # if( BUILD_RRTMK == 1)
2058    USE module_ra_rrtmg_lwk  , ONLY : rrtmg_lwinit_k
2059    USE module_ra_rrtmg_swk  , ONLY : rrtmg_swinit_k
2060 # endif
2061 #endif
2062    USE module_ra_cam       , ONLY : camradinit
2063    USE module_ra_cam_support , ONLY : oznini
2064    USE module_ra_sw        , ONLY : swinit
2065    USE module_ra_gsfcsw    , ONLY : gsfc_swinit
2066    USE module_ra_gfdleta   , ONLY : gfdletainit
2067    USE module_ra_goddard   , ONLY : init_goddardrad
2068 #if(NMM_CORE==1)
2069    USE module_ra_hwrf      , ONLY : hwrfrainit
2070 #endif
2071    USE module_ra_hs        , ONLY : hsinit
2072    USE module_domain
2073 !---------------------------------------------------------------------
2074    IMPLICIT NONE
2075 !---------------------------------------------------------------------
2076    INTEGER,  INTENT(IN)           :: id
2077    TYPE (grid_config_rec_type)    :: config_flags
2078    LOGICAL , INTENT(IN)           :: restart
2079    LOGICAL,  INTENT(IN)           :: allowed_to_read
2081    INTEGER , INTENT(IN)           :: ids, ide, jds, jde, kds, kde,   &
2082                                      ims, ime, jms, jme, kms, kme,   &
2083                                      its, ite, jts, jte, kts, kte
2085    INTEGER , INTENT(IN)           :: JULDAY,JULYR
2086    REAL ,    INTENT(IN)           :: DT, RADT, cen_lat, GMT, pptop,  &
2087                                      swrad_scat, p_top
2088    LOGICAL,  INTENT(IN)           :: start_of_simulation
2090    INTEGER,      INTENT(IN   )    ::   levsiz, n_ozmixm
2091    INTEGER,      INTENT(IN   )    ::   paerlev, n_aerosolc
2092    INTEGER,      INTENT(IN   )    ::   alevsiz, no_src_types
2094    REAL,     DIMENSION( ims:ime , jms:jme ) , INTENT(IN) ::  XLAT, XLONG
2096    REAL,  DIMENSION( ims:ime, levsiz, jms:jme, n_ozmixm ), OPTIONAL,      &
2097           INTENT(INOUT) ::                                  OZMIXM
2098    REAL,  DIMENSION( ims:ime, alevsiz, jms:jme, n_ozmixm-1, no_src_types ), OPTIONAL,      &
2099           INTENT(INOUT) ::                                  aerodm
2101    REAL,  DIMENSION(ims:ime,jms:jme), OPTIONAL, INTENT(INOUT)  :: m_ps_1,m_ps_2
2102    REAL,  DIMENSION(paerlev), OPTIONAL, INTENT(INOUT)  ::         m_hybi
2103    REAL,  DIMENSION( ims:ime, paerlev, jms:jme, n_aerosolc ), OPTIONAL,     &
2104           INTENT(INOUT) ::                      aerosolc_1, aerosolc_2
2106    REAL,  DIMENSION(levsiz), OPTIONAL, INTENT(INOUT)  ::          PIN
2107    REAL,  DIMENSION(alevsiz), OPTIONAL, INTENT(INOUT)  ::         PINA
2109    INTEGER , INTENT(INOUT)        :: STEPRA
2110    INTEGER :: isn
2112    REAL , DIMENSION( kms:kme ) , INTENT(IN) :: sfull, shalf
2113    REAL , DIMENSION( ims:ime , kms:kme , jms:jme ) , INTENT(INOUT) ::           &!BSINGH(PNNL)- should be declared inout
2114                                                            RTHRATEN, &
2115                                                          RTHRATENLW, &
2116                                                          RTHRATENSW, &
2117                                                              CLDFRA
2119    REAL , DIMENSION( ims:ime , kms:kme , jms:jme ) , INTENT(INOUT) , & ! ckay for subgrid cloud
2120                                                          OPTIONAL :: &
2121                                                           cldfra_dp, &
2122                                                           cldfra_sh
2124    REAL , DIMENSION( ims:ime ,jms:jme ) , OPTIONAL, INTENT(INOUT) :: ghi_accum  ! Solar diagnostics
2126    REAL , DIMENSION( ims:ime , kms:kme , jms:jme ) , OPTIONAL, INTENT(INOUT) :: &!BSINGH(PNNL)- should be declared inout
2127                                                          CLDFRA_OLD
2129    REAL , DIMENSION( ims:ime , jms:jme ) , INTENT(INOUT) :: EMISS
2130    LOGICAL :: etalw = .false.
2131    LOGICAL :: hwrflw= .false.
2132    LOGICAL :: camlw = .false.
2133 !   LOGICAL :: etamp = .false.
2134    LOGICAL :: acswalloc = .false.
2135    LOGICAL :: aclwalloc = .false.
2136    integer :: month,iday
2137    INTEGER :: i, j, k, itf, jtf, ktf
2138 !---------------------------------------------------------------------
2140    jtf=min0(jte,jde-1)
2141    ktf=min0(kte,kde-1)
2142    itf=min0(ite,ide-1)
2144 !---------------------------------------------------------------------
2146 !-- calculate radiation time step
2148     STEPRA = nint(RADT*60./DT)
2149     STEPRA = max(STEPRA,1)
2151 !-- initialization
2153    IF(start_of_simulation)THEN
2154      DO j=jts,jtf
2155      DO k=kts,ktf
2156      DO i=its,itf
2157         RTHRATEN(i,k,j)=0.
2158         RTHRATENLW(i,k,j)=0.
2159         RTHRATENSW(i,k,j)=0.
2160         CLDFRA(i,k,j)=0.
2161      ENDDO
2162      ENDDO
2163      ENDDO
2165      IF( PRESENT(cldfra_dp) ) THEN
2166         DO j=jts,jtf
2167         DO k=kts,ktf
2168         DO i=its,itf
2169            cldfra_dp(i,k,j)=0.
2170            cldfra_sh(i,k,j)=0.
2171         ENDDO
2172         ENDDO
2173         ENDDO
2174      ENDIF
2176      if( present(cldfra_old) ) then
2177         DO j=jts,jtf
2178         DO k=kts,ktf
2179         DO i=its,itf
2180            cldfra_old(i,k,j) = 0.
2181         ENDDO
2182         ENDDO
2183         ENDDO
2184      end if
2186      IF( PRESENT(ghi_accum) ) THEN
2187         DO j=jts,jtf
2188         DO i=its,itf
2189            ghi_accum(i,j) = 0.
2190         ENDDO
2191         ENDDO
2192      ENDIF
2193    ENDIF
2195 !-- ww: attempt to use CAM ozone and some aerosol profiles in all rad schemes
2196 !   note that CAM option will still do the same. 
2197 !   n_ozmixm: no of months; levsiz: = 59, vertical dim
2198 !   Read in CAM ozone data, and interpolate data to model grid
2199 !   Interpolation is done on domain 1 only
2201 #if (EM_CORE==1) 
2202    IF ( config_flags%o3input .EQ. 2 .AND. id .EQ. 1 ) THEN
2203 #else
2204    IF ( config_flags%o3input .EQ. 2 ) THEN
2205 #endif
2206       CALL oznini(ozmixm,pin,levsiz,n_ozmixm,XLAT,                &
2207                      ids, ide, jds, jde, kds, kde,                  &
2208                      ims, ime, jms, jme, kms, kme,                  &
2209                      its, ite, jts, jte, kts, kte)
2210    ENDIF
2212    IF ( config_flags%aer_opt .EQ. 1 .AND. id .EQ. 1 ) THEN
2213       CALL aerosol_in(aerodm,pina,alevsiz,n_ozmixm-1,no_src_types,XLAT,XLONG,   &
2214                      ids, ide, jds, jde, kds, kde,                  &
2215                      ims, ime, jms, jme, kms, kme,                  &
2216                      its, ite, jts, jte, kts, kte)
2217    ENDIF
2219 !-- find out which microphysics option is used first
2221 !   mp_select: SELECT CASE(config_flags%mp_physics)
2223 !        CASE (ETAMPNEW)
2224 !             etamp = .true.
2226 !   END SELECT mp_select
2228 !-- chose long wave radiation scheme
2230    lwrad_select: SELECT CASE(config_flags%ra_lw_physics)
2232         CASE (goddardlwscheme)
2233              CALL init_goddardrad(                          &
2234                            allowed_to_read ,                &
2235                            ids, ide, jds, jde, kds, kde,    &
2236                            ims, ime, jms, jme, kms, kme,    &
2237                            its, ite, jts, jte, kts, kte     )
2239               
2240         CASE (RRTMSCHEME)
2241              CALL rrtminit(                                 &
2242                            p_top, allowed_to_read ,         &
2243                            ids, ide, jds, jde, kds, kde,    &
2244                            ims, ime, jms, jme, kms, kme,    &
2245                            its, ite, jts, jte, kts, kte     )
2247         CASE (CAMLWSCHEME)
2248 #ifdef MAC_KLUDGE
2249              CALL wrf_error_fatal ( 'CAM radiation scheme not supported under the chosen build configuration' )
2250 #endif
2251              IF ( PRESENT( OZMIXM ) .AND. PRESENT( PIN ) .AND. &
2252                   PRESENT(M_PS_1) .AND. PRESENT(M_PS_2) .AND.  &
2253                   PRESENT(M_HYBI) .AND. PRESENT(AEROSOLC_1)    &
2254                   .AND. PRESENT(AEROSOLC_2)) THEN
2255              CALL camradinit(                                  &
2256                          R_D,R_V,CP,G,STBOLT,EP_2,shalf,pptop, &
2257                          ozmixm,pin,levsiz,XLAT,n_ozmixm,      &
2258                          m_ps_1,m_ps_2,m_hybi,aerosolc_1,aerosolc_2,&
2259                          paerlev, n_aerosolc,              &
2260                          ids, ide, jds, jde, kds, kde,     &
2261                          ims, ime, jms, jme, kms, kme,     &
2262                          its, ite, jts, jte, kts, kte      )
2263              ELSE
2264                 CALL wrf_error_fatal ( 'arguments not present for calling cam radiation' )
2265              ENDIF
2267              camlw = .true.
2268              aclwalloc = .true.
2270         CASE (RRTMG_LWSCHEME)
2271              CALL rrtmg_lwinit(                             &
2272                            p_top, allowed_to_read ,         &
2273                            ids, ide, jds, jde, kds, kde,    &
2274                            ims, ime, jms, jme, kms, kme,    &
2275                            its, ite, jts, jte, kts, kte     )
2277             aclwalloc = .true.
2278 #if ( EM_CORE == 1 )
2279 # if( BUILD_RRTMK == 1)
2280         CASE (RRTMK_LWSCHEME)  
2282              CALL rrtmg_lwinit_k(                           &
2283                            allowed_to_read ,                &
2284                            ids, ide, jds, jde, kds, kde,    &
2285                            ims, ime, jms, jme, kms, kme,    &
2286                            its, ite, jts, jte, kts, kte     )
2288              aclwalloc = .true.
2289 # endif
2290 #endif
2292 #if( BUILD_RRTMG_FAST == 1)
2293         CASE (RRTMG_LWSCHEME_FAST)
2294              CALL rrtmg_lwinit_fast(                             &
2295                            p_top, allowed_to_read ,         &
2296                            ids, ide, jds, jde, kds, kde,    &
2297                            ims, ime, jms, jme, kms, kme,    &
2298                            its, ite, jts, jte, kts, kte     )
2300              aclwalloc = .true.
2301 #endif
2303         CASE (GFDLLWSCHEME)
2304              CALL nl_get_start_month(id,month)
2305              CALL nl_get_start_day(id,iday)
2306              CALL gfdletainit(emiss,sfull,shalf,pptop,      &
2307                               julyr,month,iday,gmt,         &
2308                               config_flags,allowed_to_read, &
2309                               ids, ide, jds, jde, kds, kde, &
2310                               ims, ime, jms, jme, kms, kme, &
2311                               its, ite, jts, jte, kts, kte  )
2312              etalw = .true.
2313 #if(NMM_CORE==1)
2314         CASE (HWRFLWSCHEME)
2315              CALL nl_get_start_month(id,month)
2316              CALL nl_get_start_day(id,iday)
2317 ! test this with standard jul-day calls
2318 !     CALL nl_get_start_year(id,start_year)
2319 !     CALL nl_get_start_month(id,start_month)
2320 !     CALL nl_get_start_day(id,start_day)
2321 !     CALL nl_get_start_hour(id,start_hour)
2322 !     CALL nl_get_start_minute(id,start_minute)
2323 !     CALL nl_get_start_second(id,start_second)
2324 !     CALL jdn_sec(day_in_sec,start_year,start_month,start_day,0,0,0)
2325 !     CALL jdn_sec(day_in_sec_ref,start_year,1,1,0,0,0)
2326 !     julyr_start=start_year
2327 !     julday_start=(day_in_sec-day_in_sec_ref)/(3600.*24.)+1
2328 !     gmt_start=start_hour+real(start_minute)/60.+real(start_second)/3600.
2329               CALL hwrfrainit(sfull,shalf,pptop,JULYR,MONTH,IDAY,GMT,&
2330 !             CALL hwrfrainit(sfull,shalf,pptop,JULYR_start,MONTH,IDAY,GMT_start,&
2331                             config_flags,allowed_to_read ,                         &
2332                            kds, kde, kms, kme, kts, kte     )
2333              hwrflw = .true.
2334 #endif
2335         CASE (HELDSUAREZ)
2336              CALL hsinit(RTHRATEN,restart,             &
2337                          ids, ide, jds, jde, kds, kde, &
2338                          ims, ime, jms, jme, kms, kme, &
2339                          its, ite, jts, jte, kts, kte )
2341         CASE (FLGLWSCHEME)
2343         CASE DEFAULT
2345    END SELECT lwrad_select
2346 !-- initialize short wave radiation scheme
2348    swrad_select: SELECT CASE(config_flags%ra_sw_physics)
2350         CASE (goddardswscheme)
2351              CALL init_goddardrad(                          &
2352                            allowed_to_read ,                &
2353                            ids, ide, jds, jde, kds, kde,    &
2354                            ims, ime, jms, jme, kms, kme,    &
2355                            its, ite, jts, jte, kts, kte     )
2357         CASE (SWRADSCHEME)
2358              CALL swinit(                                  &
2359                          swrad_scat,                       &
2360                          allowed_to_read ,                 &
2361                          ids, ide, jds, jde, kds, kde,     &
2362                          ims, ime, jms, jme, kms, kme,     &
2363                          its, ite, jts, jte, kts, kte      )
2365         CASE (CAMSWSCHEME)
2366 #ifdef MAC_KLUDGE
2367              CALL wrf_error_fatal ( 'CAM radiation scheme not supported under the chosen build configuration' )
2368 #endif
2369              IF(.not.camlw)THEN
2370              CALL camradinit(                              &
2371                          R_D,R_V,CP,G,STBOLT,EP_2,shalf,pptop,               &
2372                          ozmixm,pin,levsiz,XLAT,n_ozmixm,     &
2373                          m_ps_1,m_ps_2,m_hybi,aerosolc_1,aerosolc_2,&
2374                          paerlev, n_aerosolc,              &
2375                          ids, ide, jds, jde, kds, kde,     &
2376                          ims, ime, jms, jme, kms, kme,     &
2377                          its, ite, jts, jte, kts, kte      )
2378              ENDIF
2379              acswalloc = .true.
2381         CASE (GSFCSWSCHEME)
2382              CALL gsfc_swinit(cen_lat, allowed_to_read )
2384         CASE (RRTMG_SWSCHEME)
2385              CALL rrtmg_swinit(                             &
2386                            allowed_to_read ,                &
2387                            ids, ide, jds, jde, kds, kde,    &
2388                            ims, ime, jms, jme, kms, kme,    &
2389                            its, ite, jts, jte, kts, kte     )
2391              acswalloc = .true.
2393 #if ( EM_CORE == 1 )
2394 # if( BUILD_RRTMK == 1)
2395         CASE (RRTMK_SWSCHEME)
2397              CALL rrtmg_swinit_k(                           &
2398                            allowed_to_read ,                &
2399                           ids, ide, jds, jde, kds, kde,    &
2400                            ims, ime, jms, jme, kms, kme,    &
2401                            its, ite, jts, jte, kts, kte     )
2403              acswalloc = .true.
2404 # endif
2405 #endif
2408 #if( BUILD_RRTMG_FAST == 1)
2409         CASE (RRTMG_SWSCHEME_FAST)
2410              CALL rrtmg_swinit_fast(                             &
2411                            allowed_to_read ,                &
2412                            ids, ide, jds, jde, kds, kde,    &
2413                            ims, ime, jms, jme, kms, kme,    &
2414                            its, ite, jts, jte, kts, kte     )
2416              acswalloc = .true.
2417 #endif
2420         CASE (GFDLSWSCHEME)
2421              IF(.not.etalw)THEN
2422              CALL nl_get_start_month(id,month)
2423              CALL nl_get_start_day(id,iday)
2424              CALL gfdletainit(emiss,sfull,shalf,pptop,      &
2425                               julyr,month,iday,gmt,         &
2426                               config_flags,allowed_to_read, &
2427                               ids, ide, jds, jde, kds, kde, &
2428                               ims, ime, jms, jme, kms, kme, &
2429                               its, ite, jts, jte, kts, kte  )
2430              ENDIF
2431 #if(NMM_CORE==1)
2432         CASE (HWRFSWSCHEME)
2433              IF(.not.hwrflw)THEN
2434              CALL nl_get_start_month(id,month)
2435              CALL nl_get_start_day(id,iday)
2436              CALL hwrfrainit(sfull,shalf,pptop,JULYR,MONTH,IDAY,GMT,&
2437                             config_flags,allowed_to_read,                          &
2438                            kds, kde, kms, kme, kts, kte     )
2439              ENDIF
2440 #endif
2441         CASE (FLGSWSCHEME)
2443         CASE DEFAULT
2445    END SELECT swrad_select
2447 #if ( EM_CORE == 1 ) 
2448    ! test for conditionally allocated arrays when using bucket_J
2450    IF(config_flags%bucket_J .gt. 0.0)THEN
2451      IF(.not. (acswalloc .and. aclwalloc))THEN
2452            CALL wrf_error_fatal ( 'Need CAM or RRTMG radiation for bucket_J option')
2453      ENDIF
2454    ENDIF
2455 #endif
2457    END SUBROUTINE ra_init
2459    SUBROUTINE bl_init(STEPBL,BLDT,DT,RUBLTEN,RVBLTEN,RTHBLTEN,  &
2460                 RQVBLTEN,RQCBLTEN,RQIBLTEN,TSK,TMN,             &
2461                 config_flags,restart,UST,LOWLYR,TSLB,ZS,DZS,    &
2462                 num_soil_layers,TKE_PBL,mfshconv,pek,pep,       &
2463                 massflux_EDKF, entr_EDKF, detr_EDKF, & 
2464                 thl_up, thv_up, rt_up,       &
2465                 rv_up, rc_up, u_up, v_up,    &
2466                 frac_up, itimestep, id,                         &
2467                 EXCH_H,VEGFRA,                                  &
2468                 SNOW,SNOWC, CANWAT,SMSTAV,                      &
2469                 SMSTOT, SFCRUNOFF,UDRUNOFF,ACSNOW,ACSNOM,       &
2470                 IVGTYP,ISLTYP,ISURBAN,SMOIS,SMFR3D,mavail,      &
2471                 SNOWH,SH2O,SNOALB,FNDSOILW,FNDSNOWH,RDMAXALB,   &
2472 #if  ( NMM_CORE == 1 )
2473                 Z0,XLAND,XICE,DX,DY,                            &
2474 #else
2475                 ZNT,XLAND,XICE,DX, DY, MSFTX, MSFTY,            &
2476 #endif
2477                 QKE, SFCEVP,GRDFLX,                             &
2478                 MMINLU,                                         &
2479                 XLAT, XLONG,                                    &
2480                 ISNOWXY, ZSNSOXY, TSNOXY,                       &
2481                 SNICEXY, SNLIQXY, TVXY, TGXY, CANICEXY,         &
2482                 CANLIQXY, EAHXY, TAHXY, CMXY,                   &
2483                 CHXY, FWETXY, SNEQVOXY,ALBOLDXY,QSNOWXY,QRAINXY,&
2484                 WSLAKEXY, ZWTXY, WAXY, WTXY, LFMASSXY, RTMASSXY,&
2485                 STMASSXY, WOODXY, STBLCPXY, FASTCPXY,           &
2486                 GRAINXY, GDDXY,                                 & ! Noah-MP Crop model
2487                 croptype, cropcat,                              & ! Noah-MP Crop model
2488                 iopt_crop,                                      &
2489                 iopt_irr, iopt_irrm,                            &
2490                 IRNUMSI, IRNUMMI, IRNUMFI, IRWATSI, IRWATMI,    & ! Noah-MP Irrigation
2491                 IRWATFI, IRELOSS, IRSIVOL, IRMIVOL, IRFIVOL,    & ! Noah-MP Irrigation
2492                 IRRSPLH, qtdrain,                               &
2493                 gecros_state,                                   & ! Optional gecros crop
2494                 XSAIXY, LAI,                                    &
2495                 SMOISEQ, SMCWTDXY, RECHXY, DEEPRECHXY, AREAXY,  &
2496                 WTDDT, STEPWTD,QRFSXY ,QSPRINGSXY ,QSLATXY,     &
2497                 FDEPTHXY, RIVERBEDXY, EQZWT, RIVERCONDXY, PEXPXY, & 
2498                 rechclim  ,                                     &
2499                 ISICE,                                 &
2500                 T2MVXY, T2MBXY ,CHSTARXY,                       &
2501                 allowed_to_read, iopt_run ,                     &
2502                 start_of_simulation,                            &
2503                 lakedepth2d,  savedtke12d,  snowdp2d,   h2osno2d,       & !lake
2504                 snl2d,        t_grnd2d,     t_lake3d,   lake_icefrac3d, & !lake
2505                 z_lake3d,     dz_lake3d,    t_soisno3d, h2osoi_ice3d,   & !lake
2506                 h2osoi_liq3d, h2osoi_vol3d, z3d,        dz3d,           & !lake
2507                 zi3d,         watsat3d,     csol3d,     tkmg3d,         & !lake
2508                 tkdry3d,      tksatu3d,     LakeModel,  lake2d,           & !lake
2509                 lakedepth_default,            lake_min_elev, lake_depth,       & !lake
2510 #if (EM_CORE == 1)
2511                 lakemask, lakeflag,                                      & !lake
2512 #endif
2513                 lake_depth_flag, use_lakedepth,                          & !lake
2514                 water_depth,bathymetry_flag, shalwater_z0,      & 
2515                 shalwater_depth,                                & 
2516                 te_temf,cf3d_temf,wm_temf,                      & ! WA
2517 !                num_roof_layers,num_wall_layers,num_road_layers,& !Optional urban
2518                 DZR, DZB, DZG,                                  & !Optional urban
2519                 TR_URB2D,TB_URB2D,TG_URB2D,TC_URB2D,QC_URB2D,   & !Optional urban
2520                 XXXR_URB2D,XXXB_URB2D,XXXG_URB2D,XXXC_URB2D,    & !Optional urban
2521                 TRL_URB3D, TBL_URB3D, TGL_URB3D,                & !Optional urban
2522                 SH_URB2D,LH_URB2D,G_URB2D,RN_URB2D,             & !Optional urban
2523                 TS_URB2D, FRC_URB2D, UTYPE_URB2D,               &
2524                 SF_URBAN_PHYSICS,                               & !Optional urban
2525                 CMCR_URB2D,TGR_URB2D,TGRL_URB3D,SMR_URB3D,      & !Optional urban
2526                 DRELR_URB2D,DRELB_URB2D,DRELG_URB2D,            & !Optional urban
2527                 FLXHUMR_URB2D,FLXHUMB_URB2D,FLXHUMG_URB2D,      & !Optional urban
2528                 num_urban_ndm,                                  & !Optional multi-layer urban
2529                 urban_map_zrd,                                  & !Optional multi-layer urban
2530                 urban_map_zwd,                                  & !Optional multi-layer urban
2531                 urban_map_gd,                                   & !Optional multi-layer urban
2532                 urban_map_zd,                                   & !Optional multi-layer urban
2533                 urban_map_zdf,                                  & !Optional multi-layer urban
2534                 urban_map_bd,                                   & !Optional multi-layer urban
2535                 urban_map_wd,                                   & !Optional multi-layer urban
2536                 urban_map_gbd,                                  & !Optional multi-layer urban
2537                 urban_map_fbd,                                  & !Optional multi-layer urban
2538                 urban_map_zgrd,                                 & !Optional multi-layer urban
2539                 NUM_URBAN_HI,                                   & !Optional multi-layer urban
2540                 TRB_URB4D,TW1_URB4D,TW2_URB4D,                  & !Optional multi-layer urban
2541                 TGB_URB4D,TLEV_URB3D,QLEV_URB3D,                & !Optional multi-layer urban
2542                 TW1LEV_URB3D,TW2LEV_URB3D,                      & !Optional multi-layer urban
2543                 TGLEV_URB3D,TFLEV_URB3D,                        & !Optional multi-layer urban
2544                 SF_AC_URB3D,LF_AC_URB3D,CM_AC_URB3D,            & !Optional multi-layer urban
2545                 SFVENT_URB3D,LFVENT_URB3D,                      & !Optional multi-layer urban
2546                 SFWIN1_URB3D,SFWIN2_URB3D,                      & !Optional multi-layer urban
2547                 SFW1_URB3D,SFW2_URB3D,                          & !Optional multi-layer urban
2548                 SFR_URB3D,SFG_URB3D,                            & !Optional multi-layer urban
2549                 EP_PV_URB3D,T_PV_URB3D,                         & !GRZ
2550                 TRV_URB4D,QR_URB4D,QGR_URB3D,TGR_URB3D,         & !GRZ
2551                 DRAIN_URB4D,DRAINGR_URB3D,SFRV_URB3D,           & !GRZ
2552                 LFRV_URB3D,DGR_URB3D,DG_URB3D,LFR_URB3D,LFG_URB3D,&!GRZ
2553                 LP_URB2D,HI_URB2D,LB_URB2D,                     & !Optional multi-layer urban
2554                 HGT_URB2D,MH_URB2D,STDH_URB2D,                  & !Optional multi-layer urban
2555                 LF_URB2D,                                       & !Optional multi-layer urban
2556                 A_U_BEP,A_V_BEP,A_T_BEP,A_Q_BEP,                & !Optional multi-layer urban
2557                 A_E_BEP,B_U_BEP,B_V_BEP,                        & !Optional multi-layer urban
2558                 B_T_BEP,B_Q_BEP,B_E_BEP,DLG_BEP,                & !Optional multi-layer urban
2559                 DL_U_BEP,SF_BEP,VL_BEP,                         & !Optional multi-layer urban
2560                 ids, ide, jds, jde, kds, kde,                   &
2561                 ims, ime, jms, jme, kms, kme,                   &
2562                 its, ite, jts, jte, kts, kte,                   &
2563                 ACHFX,ACLHF,ACGRDFLX,                           &
2564                 oml_hml0, sf_ocean_physics,                     & !Optional oml
2565                 TML,T0ML,HML,H0ML,HUML,HVML,TMOML,              &
2566                 is_CAMMGMP_used                                 &
2567                ,TSK_SAVE                                        & !Optional fractional seaice
2568 ! CLM vraiables 
2569                ,numc,nump,snl,                                      &
2570                 snowdp,wtc,wtp,h2osno,t_grnd,t_veg,         &
2571                 h2ocan,h2ocan_col,t2m_max,t2m_min,t_ref2m,          &
2572                 h2osoi_liq_s1,              &
2573                 h2osoi_liq_s2,h2osoi_liq_s3,h2osoi_liq_s4,          &
2574                 h2osoi_liq_s5,h2osoi_liq1,h2osoi_liq2,              &
2575                 h2osoi_liq3,h2osoi_liq4,h2osoi_liq5,h2osoi_liq6,    &
2576                 h2osoi_liq7,h2osoi_liq8,h2osoi_liq9,h2osoi_liq10,   &
2577                 h2osoi_ice_s1,h2osoi_ice_s2,                        &
2578                 h2osoi_ice_s3,h2osoi_ice_s4,h2osoi_ice_s5,          &
2579                 h2osoi_ice1,h2osoi_ice2,h2osoi_ice3,h2osoi_ice4,    &
2580                 h2osoi_ice5,h2osoi_ice6,h2osoi_ice7,                &
2581                 h2osoi_ice8,h2osoi_ice9,h2osoi_ice10,               &
2582                 t_soisno_s1,t_soisno_s2,t_soisno_s3,t_soisno_s4,    &
2583                 t_soisno_s5,t_soisno1,t_soisno2,t_soisno3,          &
2584                 t_soisno4,t_soisno5,t_soisno6,t_soisno7,            &
2585                 t_soisno8,t_soisno9,t_soisno10,                     &
2586                 dzsnow1,dzsnow2,dzsnow3,dzsnow4,dzsnow5,            &
2587                 snowrds1,snowrds2,snowrds3,snowrds4,snowrds5,       &
2588                 t_lake1,t_lake2,t_lake3,t_lake4,t_lake5,            &
2589                 t_lake6,t_lake7,t_lake8,t_lake9,t_lake10,           &
2590                 h2osoi_vol1,h2osoi_vol2,h2osoi_vol3,                &
2591                 h2osoi_vol4,h2osoi_vol5,h2osoi_vol6,                &
2592                 h2osoi_vol7,h2osoi_vol8,                            &
2593                 h2osoi_vol9,h2osoi_vol10,                           &
2594                 ht,maxpatch,                                        &
2595                 ALBEDOsubgrid,LHsubgrid,HFXsubgrid,LWUPsubgrid,     &
2596                 Q2subgrid,SABVsubgrid,SABGsubgrid,NRAsubgrid,       &
2597                 SWUPsubgrid,lhsoi,lhveg,lhtran                      &
2598 #if (WRF_USE_CLM == 1) && ( WRF_CHEM == 1 )
2599                 ,megan_specifier, megan_factors_file     &
2600                 ,megan_mapped_emisfctrs                  &
2601 #endif
2602 ! end of CLM vraiables 
2603                 ,landusef,landusef2,NLCAT                       & ! danli mosaic
2604                 ,sf_surface_mosaic, mosaic_cat                  & ! danli mosaic
2605                 ,mosaic_cat_index                               & ! danli mosaic  
2606                 ,TSK_mosaic,TSLB_mosaic                         & ! danli mosaic
2607                 ,SMOIS_mosaic,SH2O_mosaic                       & ! danli mosaic
2608                 ,CANWAT_mosaic,SNOW_mosaic                      & ! danli mosaic
2609                 ,SNOWH_mosaic,SNOWC_mosaic                      & ! danli mosaic
2610                 ,ALBEDO,ALBBCK, EMISS, EMBCK                    & ! danli mosaic 
2611                 ,ALBEDO_mosaic,ALBBCK_mosaic, EMISS_mosaic, EMBCK_mosaic, ZNT_mosaic, Z0_mosaic   &         ! danli mosaic
2612                 ,TR_URB2D_mosaic,TB_URB2D_mosaic                &  !danli mosaic 
2613                 ,TG_URB2D_mosaic,TC_URB2D_mosaic                &  !danli mosaic 
2614                 ,QC_URB2D_mosaic                                &  !danli mosaic                  
2615                 ,TRL_URB3D_mosaic,TBL_URB3D_mosaic              &  !danli mosaic 
2616                 ,TGL_URB3D_mosaic                               &  !danli mosaic 
2617                 ,SH_URB2D_mosaic,LH_URB2D_mosaic                &  !danli mosaic 
2618                 ,G_URB2D_mosaic,RN_URB2D_mosaic                 &  !danli mosaic 
2619                 ,TS_URB2D_mosaic                                &  !danli mosaic 
2620                 ,TS_RUL2D_mosaic                                &  !danli mosaic  
2621                 ,irr_rand_field,irr_ph,irr_freq                 &
2622                                                                 ) !Optional oml
2623 !--------------------------------------------------------------------
2624    USE module_sf_sfclay
2625    USE sf_sfclayrev
2626    USE module_sf_slab
2627    USE module_sf_pxsfclay
2628    USE module_bl_ysu
2629    USE module_bl_shinhong
2630    USE module_bl_mrf
2631    USE module_bl_gfs
2632 #if (HWRF==1)
2633    USE module_bl_gfsedmf, only : gfsedmfinit
2634 #endif
2635    USE module_bl_acm
2636    USE module_sf_myjsfc
2637    USE module_sf_qnsesfc
2638    USE module_sf_noahdrv
2639    USE module_sf_noahlsm, only : LCZ_1,LCZ_2,LCZ_3,LCZ_4,LCZ_5,LCZ_6,LCZ_7,LCZ_8,LCZ_9,LCZ_10,LCZ_11
2640    USE module_sf_noahmpdrv
2641    USE noahmp_tables, ONLY: LCZ_1_TABLE,LCZ_2_TABLE,LCZ_3_TABLE,LCZ_4_TABLE,LCZ_5_TABLE,LCZ_6_TABLE,LCZ_7_TABLE,LCZ_8_TABLE,LCZ_9_TABLE,LCZ_10_TABLE,LCZ_11_TABLE
2642 #ifdef WRF_USE_CLM
2643    USE module_sf_clm, only : clminit
2644 #endif
2645 #ifdef WRF_USE_CTSM
2646    USE module_sf_ctsm, only : ctsm_init
2647 #endif
2648    USE module_sf_urban
2649    USE module_sf_bep                                  !BEP
2650    USE module_sf_bep_bem
2651    USE module_sf_ruclsm
2652    USE module_sf_pxlsm
2653    USE module_sf_oml
2654    USE module_bl_myjpbl
2655    USE module_bl_myjurb
2656    USE module_bl_boulac
2657    USE module_bl_camuwpbl_driver, ONLY :  camuwpblinit
2658    USE module_bl_qnsepbl
2659    USE module_sf_lake
2660    USE module_bl_mfshconvpbl
2661    USE module_bl_gbmpbl
2662 #if ( EM_CORE == 1 )
2663    USE module_bl_mynn_wrapper
2664    USE module_bl_eeps
2665    USE module_bl_temf
2666 #if ( WRFPLUS == 1 )
2667    USE module_bl_surface_drag
2668 #endif
2669    USE module_sf_temfsfclay
2670    USE module_sf_mynn
2671 #endif
2673 #if (NMM_CORE == 1)
2674    USE module_sf_gfdl
2675 #endif
2676 !--------------------------------------------------------------------
2677    IMPLICIT NONE
2678 !--------------------------------------------------------------------
2679    TYPE (grid_config_rec_type) ::     config_flags
2680    LOGICAL , INTENT(IN)        :: restart
2681    LOGICAL, INTENT(IN)         ::   FNDSOILW, FNDSNOWH
2682    LOGICAL, INTENT(IN)         ::   RDMAXALB
2683    LOGICAL, INTENT(IN)         :: is_CAMMGMP_used !BSINGH:02/01/2013: For CAMUWPBL scheme
2685    INTEGER , INTENT(IN)        ::     id
2686    INTEGER , INTENT(IN)        ::     ids, ide, jds, jde, kds, kde, &
2687                                       ims, ime, jms, jme, kms, kme, &
2688                                       its, ite, jts, jte, kts, kte
2689    INTEGER , INTENT(IN)        ::     num_soil_layers
2690    INTEGER , INTENT(IN)        ::     SF_URBAN_PHYSICS 
2691    INTEGER , INTENT(IN)        ::     IOPT_RUN
2692    INTEGER , INTENT(IN)        ::     itimestep
2694 !   INTEGER , INTENT(IN)        ::     LakeModel
2695    INTEGER         ::     LakeModel
2696    real, intent(in)            ::      lakedepth_default,lake_min_elev
2697    REAL ,    INTENT(IN)        ::     DT, BLDT
2698    REAL ,    INTENT(IN)        ::     DX, DY
2699 #if (EM_CORE == 1)
2700    REAL,    DIMENSION( ims:ime, jms:jme ) ,  INTENT(IN) :: MSFTX,MSFTY
2701 #endif
2702    INTEGER , INTENT(INOUT)     ::     STEPBL
2704    REAL,     DIMENSION( ims:ime , 1:num_soil_layers , jms:jme ),    &
2705              INTENT(OUT) :: SMFR3D
2707    REAL,     DIMENSION( ims:ime , 1:num_soil_layers , jms:jme ),&
2708                    INTENT(INOUT) :: SMOIS,SH2O,TSLB
2710    REAL,    DIMENSION( ims:ime, jms:jme )                     , &
2711             INTENT(INOUT)    ::                           SNOW, &
2712                                                          SNOWH, &
2713                                                          SNOWC, &
2714                                                         SNOALB, &
2715                                                         CANWAT, &
2716                                                         MAVAIL, &
2717                                                         SMSTAV, &
2718                                                         SMSTOT, &
2719                                                      SFCRUNOFF, &
2720                                                       UDRUNOFF, &
2721                                                         ACSNOW, &
2722                                                         VEGFRA, &
2723                                                         ACSNOM, &
2724                                                         SFCEVP, &
2725                                                         GRDFLX, &
2726                                                            UST, &
2727 #if ( NMM_CORE == 1 )
2728                                                             Z0, &
2729 #else
2730                                                            ZNT, &
2731 #endif
2732                                                          XLAND, &
2733                                                          XICE
2735    INTEGER, DIMENSION( ims:ime, jms:jme )                     , &
2736             INTENT(INOUT)    ::                         IVGTYP, &
2737                                                         ISLTYP, &
2738                                                         LOWLYR
2741    REAL,     DIMENSION(1:num_soil_layers), INTENT(INOUT)  ::  ZS,DZS
2743    REAL,     DIMENSION( ims:ime , kms:kme , jms:jme ) , INTENT(INOUT) ::       &!BSINGH(PNNL)- should be declared inout
2744                                                            RUBLTEN, &
2745                                                            RVBLTEN, &
2746                                                           EXCH_H,   &
2747                                                           RTHBLTEN, &
2748                                                           RQVBLTEN, &
2749                                                           RQCBLTEN, &
2750                                                           RQIBLTEN, &
2751                                                           TKE_PBL
2753    REAL,     DIMENSION( ims:ime , kms:kme , jms:jme ) , INTENT(INOUT), OPTIONAL :: QKE, pek, pep
2755    REAL,     DIMENSION( ims:ime , kms:kme , jms:jme ) , INTENT(OUT), OPTIONAL :: &
2756                               massflux_EDKF, entr_EDKF, detr_EDKF & 
2757                                      ,thl_up, thv_up, rt_up       &
2758                                      ,rv_up, rc_up, u_up, v_up    &
2759                                      ,frac_up
2761    INTEGER, INTENT(IN)           ::  mfshconv ! WRF JP
2763    REAL,  DIMENSION( ims:ime , jms:jme ) , INTENT(IN) ::     TSK
2764    REAL,  DIMENSION( ims:ime , jms:jme ) , INTENT(INOUT) ::  TMN
2765    CHARACTER(LEN=*), INTENT(IN)   :: MMINLU
2766    LOGICAL,  INTENT(IN)           :: allowed_to_read
2767    INTEGER,  INTENT(IN)           :: ISURBAN
2768    INTEGER :: isn, isfc
2769    INTEGER :: k
2771    REAL, OPTIONAL, DIMENSION( ims:ime , kms:kme , jms:jme ) , &
2772             INTENT(OUT) :: te_temf, cf3d_temf !WA 
2773    REAL, OPTIONAL, DIMENSION( ims:ime , jms:jme ) , &
2774             INTENT(OUT) :: wm_temf
2776 !Noah-MP
2778    REAL,    DIMENSION(ims:ime, jms:jme) :: XLAT
2779    REAL,    DIMENSION(ims:ime, jms:jme) :: XLONG
2780    INTEGER, OPTIONAL, DIMENSION(ims:ime,jms:jme) :: ISNOWXY
2781    REAL,    OPTIONAL, DIMENSION(ims:ime,-2:num_soil_layers, jms:jme) :: ZSNSOXY
2782    REAL,    OPTIONAL, DIMENSION(ims:ime,-2:0, jms:jme) :: TSNOXY
2783    REAL,    OPTIONAL, DIMENSION(ims:ime,-2:0, jms:jme) :: SNICEXY
2784    REAL,    OPTIONAL, DIMENSION(ims:ime,-2:0, jms:jme) :: SNLIQXY
2785    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: TVXY
2786    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: TGXY
2787    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: CANICEXY
2788    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: CANLIQXY
2789    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: EAHXY
2790    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: TAHXY
2791    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: CMXY
2792    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: CHXY
2793    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: FWETXY
2794    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: SNEQVOXY
2795    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: ALBOLDXY
2796    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: QSNOWXY
2797    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: QRAINXY
2798    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: WSLAKEXY
2799    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: ZWTXY
2800    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: WAXY
2801    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: WTXY
2802    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: LFMASSXY
2803    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: RTMASSXY
2804    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: STMASSXY
2805    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: WOODXY
2806    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: GRAINXY
2807    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: GDDXY
2808    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: STBLCPXY
2809    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: FASTCPXY
2810    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: XSAIXY
2811    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: LAI
2812    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: T2MVXY
2813    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: T2MBXY
2814    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: CHSTARXY
2815    REAL,    OPTIONAL, DIMENSION(ims:ime,1:num_soil_layers,jms:jme) :: SMOISEQ
2816    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: SMCWTDXY
2817    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: DEEPRECHXY
2818    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: RECHXY
2819    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: QRFSXY  
2820    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: QSPRINGSXY
2821    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: QSLATXY
2822    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: AREAXY
2823    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme), INTENT(IN) :: FDEPTHXY
2824    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: RIVERBEDXY
2825    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: EQZWT
2826    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: RIVERCONDXY
2827    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: PEXPXY
2828    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme), INTENT(IN) :: rechclim
2829    INTEGER, OPTIONAL, DIMENSION(ims:ime,  jms:jme), INTENT(OUT) :: CROPCAT
2830    REAL,    OPTIONAL, DIMENSION(ims:ime,5,jms:jme), INTENT(IN ) :: CROPTYPE
2831    INTEGER , INTENT(IN)        ::     iopt_crop, iopt_irr, iopt_irrm
2832    REAL,    OPTIONAL, DIMENSION(ims:ime,60,jms:jme) :: gecros_state                  ! Optional gecros crop
2833    INTEGER, OPTIONAL, INTENT(IN)  ::  ISICE
2834    INTEGER , OPTIONAL,  INTENT(OUT) :: STEPWTD
2835    REAL , OPTIONAL, INTENT(IN) :: WTDDT
2837 !Irrigation
2838    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: IRWATSI
2839    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: IRWATMI
2840    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: IRWATFI
2841    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: IRELOSS
2842    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: IRSIVOL
2843    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: IRMIVOL
2844    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: IRFIVOL
2845    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: IRRSPLH
2846    INTEGER, OPTIONAL, DIMENSION(ims:ime,jms:jme) :: IRNUMSI
2847    INTEGER, OPTIONAL, DIMENSION(ims:ime,jms:jme) :: IRNUMMI
2848    INTEGER, OPTIONAL, DIMENSION(ims:ime,jms:jme) :: IRNUMFI 
2849 ! tile drainage
2850    REAL,    OPTIONAL, DIMENSION(ims:ime,jms:jme) :: qtdrain
2852 !URBAN
2853 !   REAL, DIMENSION(1:num_roof_layers), INTENT(INOUT) :: DZR  !Optional urban
2854 !   REAL, DIMENSION(1:num_wall_layers), INTENT(INOUT) :: DZB  !Optional urban
2855 !   REAL, DIMENSION(1:num_road_layers), INTENT(INOUT) :: DZG  !Optional urban
2856     REAL, OPTIONAL, DIMENSION(1:num_soil_layers), INTENT(INOUT) :: DZR  !Optional urban
2857     REAL, OPTIONAL, DIMENSION(1:num_soil_layers), INTENT(INOUT) :: DZB  !Optional urban
2858     REAL, OPTIONAL, DIMENSION(1:num_soil_layers), INTENT(INOUT) :: DZG  !Optional urban
2859     REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: TR_URB2D !Optional urban
2860     REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: TB_URB2D !Optional urban
2861     REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: TG_URB2D !Optional urban
2862     REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: TC_URB2D !Optional urban
2863     REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: QC_URB2D !Optional urban
2864     REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: XXXR_URB2D !Optional urban
2865     REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: XXXB_URB2D !Optional urban
2866     REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: XXXG_URB2D !Optional urban
2867     REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: XXXC_URB2D !Optional urban
2868     REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: DRELR_URB2D !Optional urban
2869     REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: DRELB_URB2D !Optional urban
2870     REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: DRELG_URB2D !Optional urban
2871     REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: FLXHUMR_URB2D !Optional urban
2872     REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: FLXHUMB_URB2D !Optional urban
2873     REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: FLXHUMG_URB2D !Optional urban
2874     REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: CMCR_URB2D    !Optional urban
2875     REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: TGR_URB2D     !Optional urban
2876     REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: SH_URB2D !Optional urban
2877     REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: LH_URB2D !Optional urban
2878     REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: G_URB2D !Optional urban
2879     REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: RN_URB2D !Optional urban
2880     REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: TS_URB2D !Optional urban
2881     REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: FRC_URB2D !Optional urban
2882     INTEGER, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: UTYPE_URB2D !Optional urban
2883 !    REAL, DIMENSION( ims:ime, 1:num_roof_layers, jms:jme ), INTENT(INOUT) :: TRL_URB3D !Optional urban
2884 !    REAL, DIMENSION( ims:ime, 1:num_wall_layers, jms:jme ), INTENT(INOUT) :: TBL_URB3D !Optional urban
2885 !    REAL, DIMENSION( ims:ime, 1:num_road_layers, jms:jme ), INTENT(INOUT) :: TGL_URB3D !Optional urban
2886     REAL, OPTIONAL, DIMENSION( ims:ime, 1:num_soil_layers, jms:jme ), INTENT(INOUT) :: TRL_URB3D !Optional urban
2887     REAL, OPTIONAL, DIMENSION( ims:ime, 1:num_soil_layers, jms:jme ), INTENT(INOUT) :: TBL_URB3D !Optional urban
2888     REAL, OPTIONAL, DIMENSION( ims:ime, 1:num_soil_layers, jms:jme ), INTENT(INOUT) :: TGL_URB3D !Optional urban
2889     REAL, OPTIONAL, DIMENSION( ims:ime, 1:num_soil_layers, jms:jme ), INTENT(INOUT) :: TGRL_URB3D !Optional urban
2890     REAL, OPTIONAL, DIMENSION( ims:ime, 1:num_soil_layers, jms:jme ), INTENT(INOUT) :: SMR_URB3D !Optional urban
2892     INTEGER , INTENT(IN)        ::     num_urban_ndm
2893     INTEGER , INTENT(IN)        ::     urban_map_zrd
2894     INTEGER , INTENT(IN)        ::     urban_map_zwd
2895     INTEGER , INTENT(IN)        ::     urban_map_gd
2896     INTEGER , INTENT(IN)        ::     urban_map_zd
2897     INTEGER , INTENT(IN)        ::     urban_map_zdf
2898     INTEGER , INTENT(IN)        ::     urban_map_bd
2899     INTEGER , INTENT(IN)        ::     urban_map_wd
2900     INTEGER , INTENT(IN)        ::     urban_map_gbd
2901     INTEGER , INTENT(IN)        ::     urban_map_fbd
2902     INTEGER , INTENT(IN)        ::     urban_map_zgrd
2903     INTEGER , INTENT(IN)        ::     num_urban_hi
2904     REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_zrd, jms:jme ), INTENT(INOUT) :: TRB_URB4D !Optional UCM
2905     REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_zwd, jms:jme ), INTENT(INOUT) :: TW1_URB4D !Optional UCM
2906     REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_zwd, jms:jme ), INTENT(INOUT) :: TW2_URB4D !Optional UCM
2907     REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_gd , jms:jme ), INTENT(INOUT) :: TGB_URB4D !Optional UCM
2908     REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_bd , jms:jme ), INTENT(INOUT) :: TLEV_URB3D !Optional UCM
2909     REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_bd , jms:jme ), INTENT(INOUT) :: QLEV_URB3D !Optional UCM
2910     REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_wd , jms:jme ), INTENT(INOUT) :: TW1LEV_URB3D ! multi-layer UCM
2911     REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_wd , jms:jme ), INTENT(INOUT) :: TW2LEV_URB3D ! multi-layer UCM
2912     REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_gbd, jms:jme ), INTENT(INOUT) :: TGLEV_URB3D ! multi-layer UCM
2913     REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_fbd, jms:jme ), INTENT(INOUT) :: TFLEV_URB3D ! multi-layer UCM
2914     REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: LF_AC_URB3D  !multi-layer UCM
2915     REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: SF_AC_URB3D  !multi-layer UCM
2916     REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: CM_AC_URB3D  !multi-layer UCM
2917     REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: SFVENT_URB3D !multi-layer UCM
2918     REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: LFVENT_URB3D !multi-layer UCM
2919     REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_wd , jms:jme ), INTENT(INOUT) :: SFWIN1_URB3D ! multi-layer UCM
2920     REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_wd , jms:jme ), INTENT(INOUT) :: SFWIN2_URB3D ! multi-layer UCM
2921     REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_zd , jms:jme ), INTENT(INOUT) :: SFW1_URB3D !Optional UCM
2922     REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_zd , jms:jme ), INTENT(INOUT) :: SFW2_URB3D !Optional UCM
2923     REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_zdf, jms:jme ), INTENT(INOUT) :: SFR_URB3D !Optional UCM
2924     REAL, OPTIONAL, DIMENSION( ims:ime, 1:num_urban_ndm, jms:jme ), INTENT(INOUT) :: SFG_URB3D !Optional UCM
2925     REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: EP_PV_URB3D!GRZ
2926    REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_zdf,jms:jme ), INTENT(INOUT) :: T_PV_URB3D!GRZ
2927    REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_zgrd, jms:jme),INTENT(INOUT) :: TRV_URB4D ! GRZ
2928    REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_zgrd, jms:jme),INTENT(INOUT) :: QR_URB4D ! GRZ
2929    REAL, OPTIONAL, DIMENSION( ims:ime,jms:jme), INTENT(INOUT) :: QGR_URB3D ! GRZ
2930    REAL, OPTIONAL, DIMENSION( ims:ime,jms:jme), INTENT(INOUT) :: TGR_URB3D ! GRZ
2931    REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_zdf, jms:jme),INTENT(INOUT) :: DRAIN_URB4D !GRZ
2932    REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: DRAINGR_URB3D   !GRZ
2933    REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_zdf, jms:jme),INTENT(INOUT) :: SFRV_URB3D !GRZ
2934    REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_zdf, jms:jme),INTENT(INOUT) :: LFRV_URB3D ! GRZ
2935    REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_zdf, jms:jme ),INTENT(INOUT) :: DGR_URB3D !GRZ
2936    REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_zdf, jms:jme ),INTENT(INOUT) :: DG_URB3D !GRZ
2937    REAL, OPTIONAL, DIMENSION( ims:ime, 1:urban_map_zdf, jms:jme ),INTENT(INOUT) :: LFR_URB3D !GRZ
2938    REAL, OPTIONAL, DIMENSION( ims:ime, 1:num_urban_ndm, jms:jme ), INTENT(INOUT) :: LFG_URB3D !GRZ
2939     REAL, OPTIONAL, DIMENSION( ims:ime,1:num_urban_hi, jms:jme ), INTENT(INOUT) :: HI_URB2D  !multi-layer UCM
2940     REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: LP_URB2D  !multi-layer UCM
2941     REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: LB_URB2D  !multi-layer UCM
2942     REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: HGT_URB2D !multi-layer UCM
2943     REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: MH_URB2D !SLUCM
2944     REAL, OPTIONAL, DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) :: STDH_URB2D !SLUCM
2945     REAL, OPTIONAL, DIMENSION( ims:ime, 4, jms:jme ), INTENT(INOUT) :: LF_URB2D !SLUCM
2946    REAL, OPTIONAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: A_U_BEP 
2947    REAL, OPTIONAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: A_V_BEP 
2948    REAL, OPTIONAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: A_T_BEP 
2949    REAL, OPTIONAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: A_Q_BEP 
2950    REAL, OPTIONAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: A_E_BEP 
2951    REAL, OPTIONAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: B_U_BEP 
2952    REAL, OPTIONAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: B_V_BEP 
2953    REAL, OPTIONAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: B_T_BEP 
2954    REAL, OPTIONAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: B_Q_BEP 
2955    REAL, OPTIONAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: B_E_BEP 
2956    REAL, OPTIONAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: VL_BEP
2957    REAL, OPTIONAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: DLG_BEP 
2958    REAL, OPTIONAL, DIMENSION(ims:ime, kms:kme,jms:jme),INTENT(INOUT) :: SF_BEP
2959    REAL, OPTIONAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: DL_U_BEP
2960 ! lake varibles:
2961   real,    dimension(ims:ime,jms:jme ),intent(out)                        :: lakedepth2d,    &
2962                                                                              savedtke12d
2963   real,    dimension(ims:ime,jms:jme ),intent(inout)                      :: snowdp2d,       &
2964                                                                              h2osno2d,       &
2965                                                                              snl2d,          &
2966                                                                              t_grnd2d
2968   real,    dimension( ims:ime,1:nlevlake, jms:jme ),INTENT(out)            :: t_lake3d,       &
2969                                                                              lake_icefrac3d, &
2970                                                                              z_lake3d,       &
2971                                                                              dz_lake3d
2972   real,    dimension( ims:ime,-nlevsnow+1:nlevsoil, jms:jme ),INTENT(inout) :: t_soisno3d,     &
2973                                                                              h2osoi_ice3d,   &
2974                                                                              h2osoi_liq3d,   &
2975                                                                              h2osoi_vol3d,   &
2976                                                                              z3d,            &
2977                                                                              dz3d
2978   real,    dimension( ims:ime,1:nlevsoil, jms:jme ),INTENT(out)            :: watsat3d,       &
2979                                                                              csol3d,         &
2980                                                                              tkmg3d,         &
2981                                                                              tkdry3d,        &
2982                                                                              tksatu3d
2983   real,    dimension( ims:ime,-nlevsnow+0:nlevsoil, jms:jme ),INTENT(inout) :: zi3d
2985   logical,    dimension(ims:ime,jms:jme ),intent(out)                        :: lake2d
2986   REAL, OPTIONAL,    DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) ::  lake_depth
2987   REAL,              DIMENSION( ims:ime, jms:jme ), INTENT(INOUT) ::  water_depth 
2988 #if ( EM_CORE == 1 )
2989   REAL,              dimension(ims:ime,jms:jme ),intent(inout)      ::  lakemask
2990   INTEGER, INTENT(IN)      ::  lakeflag
2991 #endif
2992   INTEGER, INTENT(IN)      ::   use_lakedepth
2993   INTEGER, INTENT(INOUT)      ::   lake_depth_flag
2994   INTEGER, INTENT(IN)      ::   shalwater_z0  
2995   REAL,    INTENT(IN)      ::   shalwater_depth  
2996   INTEGER, INTENT(INOUT)   ::   bathymetry_flag 
2997 !  REAL,    DIMENSION( ims:ime, jms:jme ), INTENT(IN)                         ::  HT
2999    REAL,  DIMENSION( ims:ime , jms:jme ) , OPTIONAL, INTENT(INOUT) ::    &
3000                                         ACHFX,ACLHF,ACGRDFLX
3001 ! Optional OML variables
3002    REAL,  DIMENSION( ims:ime , jms:jme ) , OPTIONAL, INTENT(INOUT) ::    &
3003                                         TML,T0ML,HML,H0ML,HUML,HVML,TMOML
3004    INTEGER,  OPTIONAL,  INTENT(IN) :: sf_ocean_physics
3005    REAL,  OPTIONAL,  INTENT(IN) :: oml_hml0
3006    REAL,  DIMENSION( ims:ime , jms:jme ) , OPTIONAL, INTENT(INOUT) ::    &
3007                                         TSK_SAVE
3008    LOGICAL,  INTENT(IN) :: start_of_simulation
3009    INTEGER :: i,j,patch
3011 ! CLM varaibles
3012    INTEGER , INTENT(IN)        ::     maxpatch
3013    REAL, OPTIONAL,    DIMENSION( ims:ime, jms:jme ), INTENT(IN)    ::  HT
3014   integer, OPTIONAL,   dimension(ims:ime,jms:jme ),intent(inout) :: numc,nump
3015   integer, OPTIONAL,   dimension(ims:ime,1:maxpatch,jms:jme ),intent(inout) :: snl
3016   real, OPTIONAL,  dimension(ims:ime,1:maxpatch,jms:jme ),intent(inout) ::  &
3017                 snowdp,wtc,wtp,h2osno,t_grnd,t_veg,         &
3018                 h2ocan,h2ocan_col,t2m_max,t2m_min,t_ref2m,          &
3019                 h2osoi_liq_s1,              &
3020                 h2osoi_liq_s2,h2osoi_liq_s3,h2osoi_liq_s4,          &
3021                 h2osoi_liq_s5,h2osoi_liq1,h2osoi_liq2,              &
3022                 h2osoi_liq3,h2osoi_liq4,h2osoi_liq5,h2osoi_liq6,    &
3023                 h2osoi_liq7,h2osoi_liq8,h2osoi_liq9,h2osoi_liq10,   &
3024                 h2osoi_ice_s1,h2osoi_ice_s2,                        &
3025                 h2osoi_ice_s3,h2osoi_ice_s4,h2osoi_ice_s5,          &
3026                 h2osoi_ice1,h2osoi_ice2,h2osoi_ice3,h2osoi_ice4,    &
3027                 h2osoi_ice5,h2osoi_ice6,h2osoi_ice7,                &
3028                 h2osoi_ice8,h2osoi_ice9,h2osoi_ice10,               &
3029                 t_soisno_s1,t_soisno_s2,t_soisno_s3,t_soisno_s4,    &
3030                 t_soisno_s5,t_soisno1,t_soisno2,t_soisno3,          &
3031                 t_soisno4,t_soisno5,t_soisno6,t_soisno7,            &
3032                 t_soisno8,t_soisno9,t_soisno10,                     &
3033                 dzsnow1,dzsnow2,dzsnow3,dzsnow4,dzsnow5,            &
3034                 snowrds1,snowrds2,snowrds3,snowrds4,snowrds5,       &
3035                 t_lake1,t_lake2,t_lake3,t_lake4,t_lake5,            &
3036                 t_lake6,t_lake7,t_lake8,t_lake9,t_lake10,           &
3037                 h2osoi_vol1,h2osoi_vol2,h2osoi_vol3,                &
3038                 h2osoi_vol4,h2osoi_vol5,h2osoi_vol6,                &
3039                 h2osoi_vol7,h2osoi_vol8,                            &
3040                 h2osoi_vol9,h2osoi_vol10,                           &
3041                 ALBEDOsubgrid,LHsubgrid,HFXsubgrid,LWUPsubgrid,     &
3042                 Q2subgrid,SABVsubgrid,SABGsubgrid,NRAsubgrid,       &
3043                 SWUPsubgrid,lhsoi,lhtran,lhveg
3044 #if (WRF_USE_CLM == 1) && ( WRF_CHEM == 1 )
3045    LOGICAL, INTENT(IN)          :: megan_mapped_emisfctrs
3046    CHARACTER(LEN=*), INTENT(IN) :: megan_factors_file
3047    CHARACTER(LEN=*), INTENT(IN) :: megan_specifier(:)
3048 #endif
3051 !  Added flag to read MEGANv2.1 file initially  BJG 3/28/19
3052    LOGICAL :: do_readmeganfile
3053 !  End modification
3056 !-------------------------------------------------
3057 ! Noah-mosaic related variables are added to declaration  (danli)
3058 !-------------------------------------------------
3059   
3060   INTEGER, INTENT(IN) :: sf_surface_mosaic, NLCAT   
3061   INTEGER, INTENT(IN) :: mosaic_cat
3062   REAL, DIMENSION( ims:ime, NLCAT, jms:jme ) , INTENT(IN)::   LANDUSEF
3063   REAL, DIMENSION( ims:ime, NLCAT, jms:jme ) , INTENT(INOUT)::   LANDUSEF2
3064   INTEGER, DIMENSION( ims:ime, NLCAT, jms:jme ), INTENT(INOUT) :: mosaic_cat_index 
3066   REAL, DIMENSION( ims:ime, 1:mosaic_cat, jms:jme ) , OPTIONAL, INTENT(INOUT)::   TSK_mosaic, CANWAT_mosaic, SNOW_mosaic,SNOWH_mosaic, SNOWC_mosaic 
3067   REAL, DIMENSION( ims:ime, jms:jme ) , INTENT(INOUT)::   ALBEDO,ALBBCK, EMISS, EMBCK 
3069   REAL, DIMENSION( ims:ime, 1:mosaic_cat, jms:jme ) , OPTIONAL, INTENT(INOUT)::   ALBEDO_mosaic,ALBBCK_mosaic, EMISS_mosaic, EMBCK_mosaic, ZNT_mosaic, Z0_mosaic
3070   
3071   REAL, DIMENSION( ims:ime, 1:num_soil_layers*mosaic_cat, jms:jme ), OPTIONAL, INTENT(INOUT)::   TSLB_mosaic,SMOIS_mosaic,SH2O_mosaic
3072   
3073   REAL, DIMENSION( ims:ime, 1:mosaic_cat, jms:jme ) , OPTIONAL, INTENT(INOUT)::   TR_URB2D_mosaic, TB_URB2D_mosaic, TG_URB2D_mosaic, TC_URB2D_mosaic,QC_URB2D_mosaic,  &
3074                                                                                      SH_URB2D_mosaic,LH_URB2D_mosaic,G_URB2D_mosaic,RN_URB2D_mosaic,TS_URB2D_mosaic, TS_RUL2D_mosaic  
3075                     
3076   REAL, OPTIONAL, DIMENSION( ims:ime, 1:num_soil_layers*mosaic_cat, jms:jme ), INTENT(INOUT) :: TRL_URB3D_mosaic
3077   REAL, OPTIONAL, DIMENSION( ims:ime, 1:num_soil_layers*mosaic_cat, jms:jme ), INTENT(INOUT) :: TBL_URB3D_mosaic
3078   REAL, OPTIONAL, DIMENSION( ims:ime, 1:num_soil_layers*mosaic_cat, jms:jme ), INTENT(INOUT) :: TGL_URB3D_mosaic  
3079    
3080   REAL :: xice_threshold   ! lake input
3081   REAL :: max_utype_urb2d   
3082   LOGICAL :: IPRINT
3083   
3084 !-------------------------------------------------
3085 ! End of Noah-mosaic related variables 
3086 !-------------------------------------------------  
3088 ! IRRIGATION
3089   INTEGER,OPTIONAL,INTENT(OUT), DIMENSION( ims:ime,jms:jme):: irr_rand_field  
3090   INTEGER,OPTIONAL :: irr_ph,irr_freq  
3092 ! To accommodate shared physics
3093    character*256 :: errmsg
3094    integer :: errflg
3096 #if ( EM_CORE == 1 )
3097 !local mynn 
3098    INTEGER :: mynn_closure_level
3099 #endif
3101   if ( config_flags%fractional_seaice == 0 ) then
3102      xice_threshold = 0.5
3103   else if ( config_flags%fractional_seaice == 1 ) then
3104      xice_threshold = 0.02
3105   endif
3107 !-- calculate pbl time step
3109    STEPBL = nint(BLDT*60./DT)
3110    STEPBL = max(STEPBL,1)
3111 !-- initialization
3113    IF(PRESENT(ACHFX))THEN
3114    IF(.not.restart)THEN
3115      DO j=jts,jte
3116      DO i=its,ite
3117         ACHFX(i,j)=0.
3118         ACLHF(i,j)=0.
3119         ACGRDFLX(i,j)=0.
3120         SFCEVP(i,j)=0.
3121      ENDDO
3122      ENDDO
3123    ENDIF
3124    ENDIF
3126    IF(PRESENT(TSK_SAVE))THEN
3127    IF(.NOT.restart .AND. config_flags%fractional_seaice.EQ.1)THEN
3128      DO j=jts,jte
3129      DO i=its,ite
3130         TSK_SAVE(i,j)=TSK(i,j)
3131      ENDDO
3132      ENDDO
3133    ENDIF
3134    ENDIF
3136 !-- initialize surface layer scheme
3138    sfclay_select: SELECT CASE(config_flags%sf_sfclay_physics)
3140       CASE (SFCLAYSCHEME)
3141            CALL sfclayinit( allowed_to_read )
3142            isfc = 1
3143       CASE (SFCLAYREVSCHEME)
3144            CALL sf_sfclayrev_init(errmsg,errflg)
3145            IF ( shalwater_z0 .EQ. 1 ) THEN
3146               CALL shalwater_init(ims,ime,jms,jme,            &  
3147                         its,ite,jts,jte,                      &  
3148                         bathymetry_flag, shalwater_z0,        &  
3149                         shalwater_depth, water_depth,         &  
3150                         xland,LakeModel,lake_depth,lakemask   )
3151            END IF
3152            isfc = 1
3153       CASE (PXSFCSCHEME)
3154            CALL pxsfclayinit( allowed_to_read )
3155            isfc = 7
3156       CASE (MYJSFCSCHEME)
3157            CALL myjsfcinit(LOWLYR,UST,                         &
3158 #if ( NMM_CORE == 1 )
3159                                       Z0,                      &
3160 #else
3161                                       ZNT,                     &
3162 #endif
3163                                           XLAND,XICE,          &
3164                          IVGTYP,restart,                       &
3165                          allowed_to_read ,                     &
3166                          ids, ide, jds, jde, kds, kde,         &
3167                          ims, ime, jms, jme, kms, kme,         &
3168                          its, ite, jts, jte, kts, kte          )
3169            isfc = 2
3171       CASE (QNSESFCSCHEME)
3172            CALL qnsesfcinit(LOWLYR,UST,                         &
3173 #if ( NMM_CORE == 1 )
3174                                       Z0,                      &
3175 #else
3176                                       ZNT,                     &
3177 #endif
3178                                           XLAND,XICE,          &
3179                          IVGTYP,restart,                       &
3180                          allowed_to_read ,                     &
3181                          ids, ide, jds, jde, kds, kde,         &
3182                          ims, ime, jms, jme, kms, kme,         &
3183                          its, ite, jts, jte, kts, kte          )
3184            isfc = 4
3186       CASE (GFSSFCSCHEME)
3187            CALL myjsfcinit(LOWLYR,UST,                         &
3188 #if ( NMM_CORE == 1 )
3189                                       Z0,                      &
3190 #else
3191                                       ZNT,                     &
3192 #endif
3193                                           XLAND,XICE,          &
3194                          IVGTYP,restart,                       &
3195                          allowed_to_read ,                     &
3196                          ids, ide, jds, jde, kds, kde,         &
3197                          ims, ime, jms, jme, kms, kme,         &
3198                          its, ite, jts, jte, kts, kte          )
3199            isfc = 2
3200 #if (NMM_CORE==1)
3201       CASE (GFDLSFCSCHEME)
3202            CALL myjsfcinit(LOWLYR,UST,                         &
3203                                       Z0,                      &
3204                                           XLAND,XICE,          &
3205                          IVGTYP,restart,                       &
3206                          allowed_to_read ,                     &
3207                          ids, ide, jds, jde, kds, kde,         &
3208                          ims, ime, jms, jme, kms, kme,         &
3209                          its, ite, jts, jte, kts, kte          )
3210            isfc = 2
3211 #endif
3213 #if ( EM_CORE == 1 )
3214 !mynn 
3216         CASE (MYNNSFCSCHEME)
3218            CALL mynn_sf_init_driver(allowed_to_read)
3219            isfc=5
3220 !          isfc=3
3222       CASE (TEMFSFCSCHEME)
3223            CALL wrf_debug( 100, 'calling temfsfclayinit' )
3224            CALL temfsfclayinit( restart, allowed_to_read ,        &
3225                              wm_temf,                          &
3226                          ids, ide, jds, jde, kds, kde,         &
3227                          ims, ime, jms, jme, kms, kme,         &
3228                          its, ite, jts, jte, kts, kte          )
3229 #endif
3231       CASE DEFAULT
3233    END SELECT sfclay_select
3236 !-- initialize surface scheme
3238    sfc_select: SELECT CASE(config_flags%sf_surface_physics)
3240       CASE (SLABSCHEME)
3242            CALL slabinit(TSK,TMN,                              &
3243                          TSLB,ZS,DZS,num_soil_layers,          &
3244                          allowed_to_read ,start_of_simulation ,&
3245                          ids, ide, jds, jde, kds, kde,         &
3246                          ims, ime, jms, jme, kms, kme,         &
3247                          its, ite, jts, jte, kts, kte          )
3249 #if (NMM_CORE == 1)
3250      CASE (GFDLSLAB)
3251            CALL hwrfsfcinit(isn,XICE,VEGFRA,SNOW,SNOWC, CANWAT,SMSTAV, &
3252                      SMSTOT, SFCRUNOFF,UDRUNOFF,GRDFLX,ACSNOW,     &
3253                      ACSNOM,IVGTYP,ISLTYP,TSLB,SMOIS,DZS,SFCEVP,   &
3254                      TMN,                                          &
3255                      num_soil_layers,                              &
3256                      allowed_to_read ,                             &
3257                      ids,ide, jds,jde, kds,kde,                    &
3258                      ims,ime, jms,jme, kms,kme,                    &
3259                      its,ite, jts,jte, kts,kte                     )
3261 #endif
3262       CASE (LSMSCHEME)
3263           
3264           IF(TRIM(mminlu) .EQ. 'NLCD40')THEN
3265             CALL wrf_message('Using NLCD40 for Noah, redefine urban categories ')
3266             DO j=jts,jte
3267             DO i=its,ite
3268                IF(IVGTYP(i,j)==23) IVGTYP(i,j) = 24
3269                IF(IVGTYP(i,j)==25) IVGTYP(i,j) = 24
3270             ENDDO
3271             ENDDO
3272           ENDIF
3274           CALL LSMINIT(VEGFRA,SNOW,SNOWC,SNOWH,CANWAT,SMSTAV,  &
3275                      SMSTOT, SFCRUNOFF,UDRUNOFF,ACSNOW,        &
3276                      ACSNOM,IVGTYP,ISLTYP,TSLB,SMOIS,SH2O,ZS,DZS, &
3277                      MMINLU,                                   &
3278                      SNOALB, FNDSOILW, FNDSNOWH, RDMAXALB,     &
3279                      num_soil_layers, restart,                 &
3280                      allowed_to_read ,                         &
3281                      irr_rand_field,irr_ph,irr_freq,           &
3282                      ids,ide, jds,jde, kds,kde,                &
3283                      ims,ime, jms,jme, kms,kme,                &
3284                      its,ite, jts,jte, kts,kte                 &
3285                      )
3288 !URBAN
3289           IF ((SF_URBAN_PHYSICS.eq.1).OR.(SF_URBAN_PHYSICS.EQ.2).OR.(SF_URBAN_PHYSICS.EQ.3)) THEN
3291              IF ( PRESENT( FRC_URB2D ) .AND. PRESENT( UTYPE_URB2D )) THEN
3292                 CALL urban_param_init(DZR,DZB,DZG,num_soil_layers,             & !urban
3293                                 sf_urban_physics,config_flags%use_wudapt_lcz,  &
3294                                 config_flags%slucm_distributed_drag) 
3295                 
3296                 CALL urban_var_init(ISURBAN,TSK,TSLB,TMN,IVGTYP,               & !urban
3297                               ims,ime,jms,jme,kms,kme,num_soil_layers,         & !urban
3298                               LCZ_1,LCZ_2,LCZ_3,LCZ_4,LCZ_5,                   &
3299                               LCZ_6,LCZ_7,LCZ_8,LCZ_9,LCZ_10,LCZ_11,           &
3300                               restart,sf_urban_physics,                        & !urban
3301                               XXXR_URB2D,XXXB_URB2D,XXXG_URB2D,XXXC_URB2D,     & !urban
3302                               TR_URB2D,TB_URB2D,TG_URB2D,TC_URB2D,QC_URB2D,    & !urban
3303                               TRL_URB3D,TBL_URB3D,TGL_URB3D,                   & !urban
3304                               SH_URB2D,LH_URB2D,G_URB2D,RN_URB2D, TS_URB2D,    & !urban
3305                               num_urban_ndm,                                   & !urban
3306                               urban_map_zrd,                                   & !urban
3307                               urban_map_zwd,                                   & !urban
3308                               urban_map_gd,                                    & !urban
3309                               urban_map_zd,                                    & !urban
3310                               urban_map_zdf,                                   & !urban
3311                               urban_map_bd,                                    & !urban
3312                               urban_map_wd,                                    & !urban
3313                               urban_map_gbd,                                   & !urban
3314                               urban_map_fbd,                                   & !urban
3315                               urban_map_zgrd,                                  & !urban
3316                               num_urban_hi,                                    & !urban
3317                               TRB_URB4D,TW1_URB4D,TW2_URB4D,TGB_URB4D,         & !urban
3318                               TLEV_URB3D,QLEV_URB3D,                           & !urban
3319                               TW1LEV_URB3D,TW2LEV_URB3D,                       & !urban
3320                               TGLEV_URB3D,TFLEV_URB3D,                         & !urban
3321                               SF_AC_URB3D,LF_AC_URB3D,CM_AC_URB3D,             & !urban
3322                               SFVENT_URB3D,LFVENT_URB3D,                       & !urban
3323                               SFWIN1_URB3D,SFWIN2_URB3D,                       & !urban
3324                               SFW1_URB3D,SFW2_URB3D,SFR_URB3D,SFG_URB3D,       & !urban
3325                               EP_PV_URB3D,T_PV_URB3D,                          & !GRZ
3326                               TRV_URB4D,QR_URB4D,QGR_URB3D,TGR_URB3D,          & !GRZ
3327                               DRAIN_URB4D,DRAINGR_URB3D,SFRV_URB3D,            & !GRZ
3328                               LFRV_URB3D,DGR_URB3D,DG_URB3D,LFR_URB3D,LFG_URB3D,&!GRZ
3329                               SMOIS,                                           & !GRZ
3330                               LP_URB2D,HI_URB2D,LB_URB2D,                      & !urban
3331                               HGT_URB2D,MH_URB2D,STDH_URB2D,                   & !urban
3332                               LF_URB2D,                                        & !urban
3333                               CMCR_URB2D,TGR_URB2D,TGRL_URB3D,SMR_URB3D,       & !urban
3334                               DRELR_URB2D,DRELB_URB2D,DRELG_URB2D,             & !urban
3335                               FLXHUMR_URB2D, FLXHUMB_URB2D, FLXHUMG_URB2D,     & !urban
3336                               A_U_BEP,A_V_BEP,A_T_BEP,A_Q_BEP,                 & !multi-layer urban
3337                               A_E_BEP,B_U_BEP,B_V_BEP,                         & !multi-layer urban
3338                               B_T_BEP,B_Q_BEP,B_E_BEP,DLG_BEP,                 & !multi-layer urban
3339                               DL_U_BEP,SF_BEP,VL_BEP,                          & !multi-layer urban
3340                               FRC_URB2D, UTYPE_URB2D,config_flags%use_wudapt_lcz)  !urban
3341           
3343                max_utype_urb2d = maxval(UTYPE_URB2D)*1.0
3344 #if ( defined( DM_PARALLEL ) && ( ! defined( STUBMPI ) ) )
3345                max_utype_urb2d = wrf_dm_max_real(max_utype_urb2d)
3346 #endif
3347                IF (config_flags%use_wudapt_lcz.eq.0 .and. max_utype_urb2d.gt.3.0) THEN  !new LCZ
3348                  CALL wrf_error_fatal &
3349                  ('USING 10 WUDAPT LCZ WITHOUT URBPARM_LCZ.TBL. SET USE_WUDAPT_LCZ=1')
3350                ENDIF
3351                IF (config_flags%use_wudapt_lcz.eq.1 .and. max_utype_urb2d.le.3.0) THEN  ! new LCZ
3352                  CALL wrf_error_fatal &
3353                  ('USING URBPARM_LCZ.TBL WITH OLD 3 URBAN CLASSES. SET USE_WUDAPT_LCZ=0')
3354                ENDIF
3357              ELSE
3358                 CALL wrf_error_fatal ( 'arguments not present for calling urban model' )
3359              ENDIF
3360           ENDIF
3362 !danli mosaic
3364           IF (SF_surface_mosaic.eq.1) THEN
3366 CALL lsm_mosaic_init(IVGTYP,config_flags%ISWATER,config_flags%ISURBAN,config_flags%ISICE, XLAND, XICE,config_flags%fractional_seaice,TSK,TSLB,SMOIS,SH2O,SNOW,SNOWC,SNOWH,CANWAT,  &                
3367                   ids,ide, jds,jde, kds,kde,  &
3368                   ims,ime, jms,jme, kms,kme,  &
3369                   its,ite, jts,jte, kts,kte, restart,             &
3370                   landusef,landusef2,NLCAT,num_soil_layers                  & 
3371                   ,sf_surface_mosaic, mosaic_cat                    & 
3372                   , mosaic_cat_index                              &   
3373                   ,TSK_mosaic,TSLB_mosaic                         &
3374                   ,SMOIS_mosaic,SH2O_mosaic                       & 
3375                   ,CANWAT_mosaic,SNOW_mosaic                      &
3376                   ,SNOWH_mosaic,SNOWC_mosaic                      &
3377                   ,ALBEDO,ALBBCK, EMISS, EMBCK,                    &         !danli  
3378 #if ( NMM_CORE == 1 )
3379                                                             Z0, &
3380 #else
3381                                                            ZNT, &
3382 #endif  
3383                   ALBEDO_mosaic,ALBBCK_mosaic, EMISS_mosaic, EMBCK_mosaic, ZNT_mosaic, Z0_mosaic   &         !danli
3384                  ,TR_URB2D_mosaic,TB_URB2D_mosaic                &  !danli mosaic 
3385                  ,TG_URB2D_mosaic,TC_URB2D_mosaic                &  !danli mosaic 
3386                  ,QC_URB2D_mosaic                                &  !danli mosaic                  
3387                  ,TRL_URB3D_mosaic,TBL_URB3D_mosaic              &  !danli mosaic 
3388                  ,TGL_URB3D_mosaic                               &  !danli mosaic 
3389                  ,SH_URB2D_mosaic,LH_URB2D_mosaic                &  !danli mosaic 
3390                  ,G_URB2D_mosaic,RN_URB2D_mosaic                 &  !danli mosaic 
3391                  ,TS_URB2D_mosaic                                &  !danli mosaic 
3392                  ,TS_RUL2D_mosaic                                &  !danli mosaic                        
3393                    )
3395           ENDIF               
3396           
3399       CASE (NOAHMPSCHEME)
3400           IF ( TRIM(mminlu) .EQ. 'NLCD40' ) THEN
3401              CALL wrf_error_fatal ( 'NoahMP does not work with NLCD data. Stop.' )
3402           ENDIF
3404           CALL NOAHMP_INIT(MMINLU, SNOW,SNOWH,CANWAT,ISLTYP,IVGTYP,XLAT,                 &
3405                      TSLB,SMOIS,SH2O,DZS, FNDSOILW, FNDSNOWH,          &
3406                      TSK,isnowxy  ,tvxy     ,tgxy     ,canicexy ,TMN,XICE,                  &
3407                      canliqxy ,eahxy    ,tahxy    ,cmxy     ,chxy     ,                     &
3408                      fwetxy   ,sneqvoxy ,alboldxy ,qsnowxy  ,qrainxy, wslakexy, zwtxy, waxy,&
3409                      wtxy     ,tsnoxy   ,zsnsoxy  ,snicexy  ,snliqxy  ,lfmassxy ,rtmassxy , &
3410                      stmassxy ,woodxy   ,stblcpxy ,fastcpxy ,xsaixy   ,lai      ,           &
3411                      grainxy  ,gddxy    ,                                                   &
3412                      croptype ,cropcat  ,                      &
3413                      irnumsi  ,irnummi  ,irnumfi  ,irwatsi,    &
3414                      irwatmi  ,irwatfi  ,ireloss  ,irsivol,    &
3415                      irmivol  ,irfivol  ,irrsplh  ,            &
3416                      t2mvxy   ,t2mbxy   ,chstarxy ,            &
3417                      num_soil_layers, restart,                 &
3418                      allowed_to_read, iopt_run , iopt_crop,    &
3419                      iopt_irr, iopt_irrm,                      &
3420                      sf_urban_physics,                         &  ! urban scheme
3421                      ids,ide, jds,jde, kds,kde,                &
3422                      ims,ime, jms,jme, kms,kme,                &
3423                      its,ite, jts,jte, kts,kte                 &
3424 #if (EM_CORE == 1)
3425                      ,smoiseq  ,smcwtdxy ,rechxy   ,deeprechxy, qtdrain, areaxy ,dx, dy, msftx, msfty,&
3426                      wtddt    ,stepwtd  ,dt  ,qrfsxy ,qspringsxy  ,qslatxy,                  &
3427                      fdepthxy ,ht       ,riverbedxy ,eqzwt ,rivercondxy ,pexpxy,              &
3428                      rechclim,                  &
3429                      gecros_state                              & ! Optional gecros crop
3430 #endif
3431                      )
3433           IF ((SF_URBAN_PHYSICS.eq.1).OR.(SF_URBAN_PHYSICS.EQ.2).OR.(SF_URBAN_PHYSICS.EQ.3)) THEN
3434              IF ( PRESENT( FRC_URB2D ) .AND. PRESENT( UTYPE_URB2D )) THEN
3435                 CALL urban_param_init(DZR,DZB,DZG,num_soil_layers,                   & !urban
3436                                 sf_urban_physics,config_flags%use_wudapt_lcz,        &
3437                                 config_flags%slucm_distributed_drag)
3438                 CALL urban_var_init(ISURBAN,TSK,TSLB,TMN,IVGTYP,               & !urban
3439                               ims,ime,jms,jme,kms,kme,num_soil_layers,         & !urban
3440                               LCZ_1_TABLE,LCZ_2_TABLE,LCZ_3_TABLE,LCZ_4_TABLE, & !urban
3441                               LCZ_5_TABLE,LCZ_6_TABLE,LCZ_7_TABLE,LCZ_8_TABLE, & !urban
3442                               LCZ_9_TABLE,LCZ_10_TABLE,LCZ_11_TABLE,           & !urban
3443                               restart,sf_urban_physics,                        & !urban
3444                               XXXR_URB2D,XXXB_URB2D,XXXG_URB2D,XXXC_URB2D,     & !urban
3445                               TR_URB2D,TB_URB2D,TG_URB2D,TC_URB2D,QC_URB2D,    & !urban
3446                               TRL_URB3D,TBL_URB3D,TGL_URB3D,                   & !urban
3447                               SH_URB2D,LH_URB2D,G_URB2D,RN_URB2D, TS_URB2D,    & !urban
3448                               num_urban_ndm,                                   & !urban
3449                               urban_map_zrd,                                   & !urban
3450                               urban_map_zwd,                                   & !urban
3451                               urban_map_gd,                                    & !urban
3452                               urban_map_zd,                                    & !urban
3453                               urban_map_zdf,                                   & !urban
3454                               urban_map_bd,                                    & !urban
3455                               urban_map_wd,                                    & !urban
3456                               urban_map_gbd,                                   & !urban
3457                               urban_map_fbd,                                   & !urban
3458                               urban_map_zgrd,                                  & !urban
3459                               num_urban_hi,                                    & !urban
3460                               TRB_URB4D,TW1_URB4D,TW2_URB4D,TGB_URB4D,         & !urban
3461                               TLEV_URB3D,QLEV_URB3D,                           & !urban
3462                               TW1LEV_URB3D,TW2LEV_URB3D,                       & !urban
3463                               TGLEV_URB3D,TFLEV_URB3D,                         & !urban
3464                               SF_AC_URB3D,LF_AC_URB3D,CM_AC_URB3D,             & !urban
3465                               SFVENT_URB3D,LFVENT_URB3D,                       & !urban
3466                               SFWIN1_URB3D,SFWIN2_URB3D,                       & !urban
3467                               SFW1_URB3D,SFW2_URB3D,SFR_URB3D,SFG_URB3D,       & !urban
3468                               EP_PV_URB3D,T_PV_URB3D,                          & !GRZ
3469                               TRV_URB4D,QR_URB4D,QGR_URB3D,TGR_URB3D,          & !GRZ
3470                               DRAIN_URB4D,DRAINGR_URB3D,SFRV_URB3D,            & !GRZ
3471                               LFRV_URB3D,DGR_URB3D,DG_URB3D,LFR_URB3D,LFG_URB3D,&!GRZ
3472                               SMOIS,                                           & 
3473                               LP_URB2D,HI_URB2D,LB_URB2D,                      & !urban
3474                               HGT_URB2D,MH_URB2D,STDH_URB2D,                   & !urban
3475                               LF_URB2D,                                        & !urban
3476                               CMCR_URB2D,TGR_URB2D,TGRL_URB3D,SMR_URB3D,       & !urban
3477                               DRELR_URB2D,DRELB_URB2D,DRELG_URB2D,             & !urban
3478                               FLXHUMR_URB2D, FLXHUMB_URB2D, FLXHUMG_URB2D,     & !urban
3479                               A_U_BEP,A_V_BEP,A_T_BEP,A_Q_BEP,                 & !multi-layer urban
3480                               A_E_BEP,B_U_BEP,B_V_BEP,                         & !multi-layer urban
3481                               B_T_BEP,B_Q_BEP,B_E_BEP,DLG_BEP,                 & !multi-layer urban
3482                               DL_U_BEP,SF_BEP,VL_BEP,                          & !multi-layer urban
3483                               FRC_URB2D, UTYPE_URB2D,config_flags%use_wudapt_lcz)!urban
3485                max_utype_urb2d = maxval(UTYPE_URB2D)*1.0
3486 #if ( defined( DM_PARALLEL ) && ( ! defined( STUBMPI ) ) )
3487                max_utype_urb2d = wrf_dm_max_real(max_utype_urb2d)
3488 #endif
3490                IF (config_flags%use_wudapt_lcz.eq.0 .and. max_utype_urb2d.gt.3.) THEN  !new LCZ
3491                  CALL wrf_error_fatal &
3492                  ('USING 10 WUDAPT LCZ WITHOUT URBPARM_LCZ.TBL. SET USE_WUDAPT_LCZ=1')
3493                ENDIF
3494                IF (config_flags%use_wudapt_lcz.eq.1 .and. max_utype_urb2d.le.3.) THEN  ! new LCZ
3495                  CALL wrf_error_fatal &
3496                  ('USING URBPARM_LCZ.TBL WITH OLD 3 URBAN CLASSES. SET USE_WUDAPT_LCZ=0')
3497                ENDIF
3500              ELSE
3501                 CALL wrf_error_fatal ( 'arguments not present for calling urban model' )
3502              ENDIF
3503           ENDIF
3505       CASE (RUCLSMSCHEME)
3506 !          if(isfc .ne. 2)CALL wrf_error_fatal &
3507 !           ( 'module_physics_init: use myjsfc and myjpbl scheme for this lsm option' )
3508            CALL ruclsminit( SH2O,SMFR3D,TSLB,SMOIS,ISLTYP,IVGTYP,MMINLU,XICE,  &
3509                      mavail,num_soil_layers, config_flags%iswater,      &
3510 #if (NMM_CORE == 1)
3511                      config_flags%isice, z0, restart,                  &
3512 #else
3513                      config_flags%isice, znt, restart,                  &
3514 #endif
3515                      allowed_to_read ,                             &
3516                      ids,ide, jds,jde, kds,kde,                    &
3517                      ims,ime, jms,jme, kms,kme,                    &
3518                      its,ite, jts,jte, kts,kte                     )
3520       CASE (PXLSMSCHEME)
3521           if(config_flags%num_land_cat .ne. 20 .and. config_flags%num_land_cat .ne. 21 .and. & ! MODIS
3522              config_flags%num_land_cat .ne. 24 .and. config_flags%num_land_cat .ne. 28 .and. & ! USGS
3523              config_flags%num_land_cat .ne. 40 .and. config_flags%num_land_cat .ne. 50 .and. & ! NLCD
3524              config_flags%num_land_cat .ne. 61 )                                             & ! MODIS W/LCZ 
3525           CALL wrf_error_fatal ( 'module_physics_init: PX LSM option requires USGS, MODIS, or NLCD' )
3526           CALL LSMINIT(VEGFRA,SNOW,SNOWC,SNOWH,CANWAT,SMSTAV,  &
3527                      SMSTOT, SFCRUNOFF,UDRUNOFF,ACSNOW,        &
3528                      ACSNOM,IVGTYP,ISLTYP,TSLB,SMOIS,SH2O,ZS,DZS, &
3529                      MMINLU,                                   &
3530                      SNOALB, FNDSOILW, FNDSNOWH, RDMAXALB,     &
3531                      num_soil_layers, restart,                 &
3532                      allowed_to_read ,                         &
3533                      irr_rand_field,irr_ph,irr_freq,           &
3534                      ids,ide, jds,jde, kds,kde,                &
3535                      ims,ime, jms,jme, kms,kme,                &
3536                      its,ite, jts,jte, kts,kte                 )
3538 !--------------fds (06/2010)-----------------------------------
3539      CASE  (SSIBSCHEME)
3540 !SSiB only works with sfclay and YSU schemes. Check this here!
3541           if(isfc .ne. 1)CALL wrf_error_fatal &
3542            ( 'module_physics_init: use sfclay scheme with SSiB' )
3543           if(config_flags%bl_pbl_physics .ne. 1)CALL wrf_error_fatal &
3544            ( 'module_physics_init: use ysu scheme with SSiB' )
3545 ! Add radiation scheme 4 (RRTMg) for SSiB, By Zhenxin 2011-06-20 ************************
3546           if(config_flags%ra_lw_physics .eq. 2 .or. config_flags%ra_lw_physics .gt. 4)CALL wrf_error_fatal &
3547            ( 'module_physics_init: SSiB only works with rrtm, cam scheme or rrtmg scheme (lw_phys=1,3,4)' )
3548           if(config_flags%ra_sw_physics .eq. 2 .or. config_flags%ra_sw_physics .gt. 4)CALL wrf_error_fatal &
3549            ( 'module_physics_init: SSiB only works with rrtm, cam scheme or rrtmg scheme (sw_phys=1,3,4)' )
3550 ! End of Adding radiation scheme 4 (RRTMg) for SSiB, By Zhenxin 2011-06-20 **************
3551           IF ( TRIM(mminlu) .EQ. 'NLCD40' ) THEN
3552              CALL wrf_error_fatal ( 'SSIB does not work with NLCD data. Stop.' )
3553           ENDIF
3554 !--------------------------------------------------------------
3555 ! CLM Init Coupling
3556       CASE (CLMSCHEME)
3557         IF ((SF_URBAN_PHYSICS.eq.1).OR.(SF_URBAN_PHYSICS.EQ.2).OR.(SF_URBAN_PHYSICS.EQ.3)) THEN
3558                 CALL wrf_error_fatal ( 'CLM DOES NOT WORK WITH URBAN SCHEME' ) 
3559         ENDIF
3560         IF ( TRIM(mminlu) .EQ. 'NLCD40' ) THEN
3561            CALL wrf_error_fatal ( 'CLM does not work with NLCD input. Stop' )
3562         ENDIF
3565 !  Test here to see if MEGANv2.1 file should be read.  bio_emiss_opt should only
3566 !  be referenced if WRF_CHEM is compiled.    BJG 3/29/19
3568         do_readmeganfile = .false.
3569 #ifdef WRF_USE_CLM
3570         IF(PRESENT(numc))THEN
3571         ! added by Jiming Jin 10/14/2012 ; modified to use MODIS data 3/6/2014
3572         if((config_flags%num_land_cat .ne. 24) .AND. &
3573            (config_flags%num_land_cat .ne. 28) .AND. &
3574            (config_flags%num_land_cat .ne. 21) .AND. &
3575            (config_flags%num_land_cat .ne. 20)) CALL wrf_error_fatal &
3576             ('module_physics_init: USGS or MODIS must be used with CLM option')
3578 #if ( WRF_CHEM == 1 )
3579         if( config_flags%bio_emiss_opt == MEGAN2_CLM ) then
3580             do_readmeganfile = .true.
3581         endif
3582 #endif
3584             CALL CLMINIT(VEGFRA,SNOW,SNOWC,SNOWH,CANWAT,SMSTAV,    &
3585                      SMSTOT, SFCRUNOFF,UDRUNOFF,ACSNOW,            &
3586                      ACSNOM,IVGTYP,ISLTYP,TSLB,SMOIS,SH2O,ZS,DZS,  &
3587                      FNDSOILW, FNDSNOWH,                           &
3588                      num_soil_layers, restart,                     &
3589                      allowed_to_read, id, do_readmeganfile, &
3590                      ids,ide, jds,jde, kds,kde,                    &
3591                      ims,ime, jms,jme, kms,kme,                    &
3592                      its,ite, jts,jte, kts,kte,                    &
3593 #if ( WRF_CHEM == 1 )
3594                      megan_specifier,                              &
3595                      megan_mapped_emisfctrs,                       &
3596                      megan_factors_file,                           &
3597 #endif
3598                      dt,maxpatch                                         &
3599                     ,numc,nump,snl,                                      &
3600                      snowdp,wtc,wtp,h2osno,t_grnd,t_veg,         &
3601                      h2ocan,h2ocan_col,t2m_max,t2m_min,t_ref2m,          &
3602                      h2osoi_liq_s1,              &
3603                      h2osoi_liq_s2,h2osoi_liq_s3,h2osoi_liq_s4,          &
3604                      h2osoi_liq_s5,h2osoi_liq1,h2osoi_liq2,              &
3605                      h2osoi_liq3,h2osoi_liq4,h2osoi_liq5,h2osoi_liq6,    &
3606                      h2osoi_liq7,h2osoi_liq8,h2osoi_liq9,h2osoi_liq10,   &
3607                      h2osoi_ice_s1,h2osoi_ice_s2,                        &
3608                      h2osoi_ice_s3,h2osoi_ice_s4,h2osoi_ice_s5,          &
3609                      h2osoi_ice1,h2osoi_ice2,h2osoi_ice3,h2osoi_ice4,    &
3610                      h2osoi_ice5,h2osoi_ice6,h2osoi_ice7,                &
3611                      h2osoi_ice8,h2osoi_ice9,h2osoi_ice10,               &
3612                      t_soisno_s1,t_soisno_s2,t_soisno_s3,t_soisno_s4,    &
3613                      t_soisno_s5,t_soisno1,t_soisno2,t_soisno3,          &
3614                      t_soisno4,t_soisno5,t_soisno6,t_soisno7,            &
3615                      t_soisno8,t_soisno9,t_soisno10,                     &
3616                      dzsnow1,dzsnow2,dzsnow3,dzsnow4,dzsnow5,            &
3617                      snowrds1,snowrds2,snowrds3,snowrds4,snowrds5,       &
3618                      t_lake1,t_lake2,t_lake3,t_lake4,t_lake5,            &
3619                      t_lake6,t_lake7,t_lake8,t_lake9,t_lake10,           &
3620                      h2osoi_vol1,h2osoi_vol2,h2osoi_vol3,                &
3621                      h2osoi_vol4,h2osoi_vol5,h2osoi_vol6,                &
3622                      h2osoi_vol7,h2osoi_vol8,                            &
3623                      h2osoi_vol9,h2osoi_vol10,                           &
3624                      ht,XLAND,XICE                                       &
3625                     ,ALBEDOsubgrid,LHsubgrid,HFXsubgrid,LWUPsubgrid,     &
3626                      Q2subgrid,SABVsubgrid,SABGsubgrid,NRAsubgrid,       &
3627                      SWUPsubgrid,lhsoi,lhveg,lhtran,config_flags%chem_opt  &
3628                     )
3629         ELSE
3630                 CALL wrf_error_fatal ( 'arguments not present for calling CLM' )
3631         ENDIF
3632 !--------------------------------------------------------------
3633 !   check that t_veg /= 0
3634 !--------------------------------------------------------------
3635         if( itimestep == 0 ) then
3636           do patch = 1,maxpatch
3637             do j = jts,jte
3638               where( t_veg(its:ite,patch,j) == 0.)
3639                 t_veg(its:ite,patch,j) = tslb(its:ite,1,j)
3640               endwhere
3641             end do
3642           end do
3643         endif
3644 #else
3645         CALL wrf_error_fatal ( "SF CLM CURRENTLY ifdef'ed out, set -DWRF_USE_CLM in configure.wrf in ARCH_LOCAL" )
3646 #endif
3648 #ifdef WRF_USE_CTSM
3649       CASE (CTSMSCHEME)
3651          CALL ctsm_init( &
3652               ids=ids, ide=ide, jds=jds, jde=jde, &
3653               ims=ims, ime=ime, jms=jms, jme=jme, &
3654               its=its, ite=ite, jts=jts, jte=jte, &
3655               dt=DT, xlat=XLAT, xlong=XLONG,      &
3656               atm_restart = restart)
3657 #endif
3659       CASE DEFAULT
3661    END SELECT sfc_select
3663 #if ( EM_CORE == 1 )
3664    IF(PRESENT(SF_OCEAN_PHYSICS))THEN
3665      IF ( ( sf_ocean_physics .EQ. OMLSCHEME   ) .OR. &
3666           ( sf_ocean_physics .EQ. PWP3DSCHEME ) ) THEN
3667         CALL omlinit(oml_hml0, tsk,                           &
3668                      tml,t0ml,hml,h0ml,huml,hvml,tmoml,       &
3669                      allowed_to_read, start_of_simulation,    &
3670                      ids,ide, jds,jde, kds,kde,               &
3671                      ims,ime, jms,jme, kms,kme,               &
3672                      its,ite, jts,jte, kts,kte                )
3673      ENDIF
3674    ENDIF
3675 #endif
3677      IF ( LakeModel == 1 ) THEN
3679              call  lakeini(IVGTYP,         ISLTYP,          HT,              SNOW,           & !i
3680                            lake_min_elev,     restart,         lakedepth_default, lake_depth,     &
3681                            lakedepth2d,    savedtke12d,     snowdp2d,        h2osno2d,       & !o
3682                            snl2d,          t_grnd2d,        t_lake3d,        lake_icefrac3d, &
3683                            z_lake3d,       dz_lake3d,       t_soisno3d,      h2osoi_ice3d,   &
3684                            h2osoi_liq3d,   h2osoi_vol3d,    z3d,             dz3d,           &
3685                            zi3d,           watsat3d,        csol3d,          tkmg3d,         &
3686                            config_flags%ISWATER,  xice,     xice_threshold,  xland,  tsk,    &
3687 #if (EM_CORE == 1)
3688                            lakemask,  lakeflag,                                              &
3689 #endif
3690                            lake_depth_flag, use_lakedepth,              &
3691                            tkdry3d,        tksatu3d,        lake2d,          its, ite, jts, jte, &
3692                            ims,ime, jms,jme)
3693      ENDIF
3695 !-- initialize pbl scheme
3697    pbl_select: SELECT CASE(config_flags%bl_pbl_physics)
3699       CASE (YSUSCHEME)
3700            if(isfc .ne. 1)CALL wrf_error_fatal &
3701             ( 'module_physics_init: Use sf_sfclay_physics= 1 or 91 for this pbl option' )
3702       CASE (SHINHONGSCHEME)
3703            if(isfc .ne. 1)CALL wrf_error_fatal &
3704             ( 'module_physics_init: Use sf_sfclay_physics= 1 or 91 for this pbl option' )
3705            IF ((SF_URBAN_PHYSICS.eq.2).OR.(SF_URBAN_PHYSICS.EQ.3)) CALL wrf_error_fatal &
3706             ( 'module_physics_init: use ysu (option1), myj (option 2), or boulac (option 8) with BEP/BEM urban scheme' )
3707            CALL shinhonginit(RUBLTEN,RVBLTEN,RTHBLTEN,RQVBLTEN,&
3708                         RQCBLTEN,RQIBLTEN,TKE_PBL,P_QI,       &
3709                         PARAM_FIRST_SCALAR,                   &
3710                         restart,                              &
3711                         allowed_to_read ,                     &
3712                         ids, ide, jds, jde, kds, kde,         &
3713                         ims, ime, jms, jme, kms, kme,         &
3714                         its, ite, jts, jte, kts, kte          )
3715       CASE (MRFSCHEME)
3716            if(isfc .ne. 1)CALL wrf_error_fatal &
3717             ( 'module_physics_init: Use sf_sfclay_physics= 1 or 91 for this pbl option' )
3718            IF ((SF_URBAN_PHYSICS.eq.2).OR.(SF_URBAN_PHYSICS.EQ.3)) CALL wrf_error_fatal &
3719             ( 'module_physics_init: use ysu (option1), myj (option 2), or boulac (option 8) with BEP/BEM urban scheme' )
3720            CALL mrfinit(RUBLTEN,RVBLTEN,RTHBLTEN,RQVBLTEN,    &
3721                         RQCBLTEN,RQIBLTEN,P_QI,               &
3722                         PARAM_FIRST_SCALAR,                   &
3723                         restart,                              &
3724                         allowed_to_read ,                     &
3725                         ids, ide, jds, jde, kds, kde,         &
3726                         ims, ime, jms, jme, kms, kme,         &
3727                         its, ite, jts, jte, kts, kte          )
3728       CASE (ACMPBLSCHEME)
3729            if(isfc .ne. 1 .and. isfc .ne. 7)CALL wrf_error_fatal &
3730             ( 'module_physics_init: use sfclay or pxsfc scheme for this pbl option' )
3731            IF ((SF_URBAN_PHYSICS.eq.2).OR.(SF_URBAN_PHYSICS.EQ.3)) CALL wrf_error_fatal &
3732             ( 'module_physics_init: use ysu (option1), myj (option 2), or boulac (option 8) with BEP/BEM urban scheme' )
3733            CALL acminit(RUBLTEN,RVBLTEN,RTHBLTEN,RQVBLTEN,    &
3734                         RQCBLTEN,RQIBLTEN,P_QI,               &
3735                         PARAM_FIRST_SCALAR,                   &
3736                         restart,                              &
3737                         allowed_to_read ,                     &
3738                         ids, ide, jds, jde, kds, kde,         &
3739                         ims, ime, jms, jme, kms, kme,         &
3740                         its, ite, jts, jte, kts, kte          )
3741       CASE (GFSSCHEME)
3742            if(isfc .ne. 2)CALL wrf_error_fatal &
3743             ( 'module_physics_init: use myjsfc scheme for this pbl option' )
3744            IF ((SF_URBAN_PHYSICS.eq.2).OR.(SF_URBAN_PHYSICS.EQ.3)) CALL wrf_error_fatal &
3745             ( 'module_physics_init: use ysu (option1), myj (option 2), or boulac (option 8) with BEP/BEM urban scheme' )
3746            CALL gfsinit(RUBLTEN,RVBLTEN,RTHBLTEN,RQVBLTEN,    &
3747                         RQCBLTEN,RQIBLTEN,P_QI,               &
3748                         PARAM_FIRST_SCALAR,                   &
3749                         restart,                              &
3750                         allowed_to_read ,                     &
3751                         ids, ide, jds, jde, kds, kde,         &
3752                         ims, ime, jms, jme, kms, kme,         &
3753                         its, ite, jts, jte, kts, kte          )
3754 #if (HWRF == 1)
3755       CASE (GFSEDMFSCHEME)
3756            if(isfc .ne. 2)CALL wrf_error_fatal &
3757             ( 'module_physics_init: use myjsfc scheme for this pbl option' )
3758            IF ((SF_URBAN_PHYSICS.eq.2).OR.(SF_URBAN_PHYSICS.EQ.3)) CALL wrf_error_fatal &
3759             ( 'module_physics_init: use ysu (option1), myj (option 2), or boulac (option 8) with BEP/BEM urban scheme' )
3760            CALL gfsedmfinit(RUBLTEN,RVBLTEN,RTHBLTEN,RQVBLTEN,&
3761                         RQCBLTEN,RQIBLTEN,P_QI,               &
3762                         PARAM_FIRST_SCALAR,                   &
3763                         restart,                              &
3764                         allowed_to_read ,                     &
3765                         ids, ide, jds, jde, kds, kde,         &
3766                         ims, ime, jms, jme, kms, kme,         &
3767                         its, ite, jts, jte, kts, kte          )
3769 #endif
3770       CASE (MYJPBLSCHEME)
3771            if(isfc .ne. 2)CALL wrf_error_fatal &
3772             ( 'module_physics_init: use myjsfc scheme for this pbl option' )
3773           IF ((SF_URBAN_PHYSICS.eq.2).OR.(SF_URBAN_PHYSICS.EQ.3)) THEN
3774            CALL myjurbinit(RUBLTEN,RVBLTEN,RTHBLTEN,RQVBLTEN, &
3775                         TKE_PBL,EXCH_H,restart,               &
3776                         allowed_to_read ,                     &
3777                         ids, ide, jds, jde, kds, kde,         &
3778                         ims, ime, jms, jme, kms, kme,         &
3779                         its, ite, jts, jte, kts, kte          )
3780           ELSE
3782            CALL myjpblinit(RUBLTEN,RVBLTEN,RTHBLTEN,RQVBLTEN, &
3783                         TKE_PBL,EXCH_H,restart,               &
3784                         allowed_to_read ,                     &
3785                         ids, ide, jds, jde, kds, kde,         &
3786                         ims, ime, jms, jme, kms, kme,         &
3787                         its, ite, jts, jte, kts, kte          )
3788           END IF
3789       CASE (QNSEPBLSCHEME)
3790            if(isfc .ne. 4)CALL wrf_error_fatal &
3791             ( 'module_physics_init: use qnsesfc scheme for this pbl option' )
3792            IF ((SF_URBAN_PHYSICS.eq.2).OR.(SF_URBAN_PHYSICS.EQ.3)) CALL wrf_error_fatal &
3793             ( 'module_physics_init: use ysu (option1), myj (option 2), or boulac (option 8) with BEP/BEM urban scheme' )
3794            CALL qnsepblinit(RUBLTEN,RVBLTEN,RTHBLTEN,RQVBLTEN, &
3795                         TKE_PBL,EXCH_H,restart,               &
3796                         allowed_to_read ,                     &
3797                         ids, ide, jds, jde, kds, kde,         &
3798                         ims, ime, jms, jme, kms, kme,         &
3799                         its, ite, jts, jte, kts, kte          )
3800            
3801 !          IF ( PRESENT (mfshconv) ) THEN
3802               if (mfshconv.EQ.1) &
3803               CALL mfshconvpblinit( massflux_EDKF, entr_EDKF, detr_EDKF & 
3804                                     ,thl_up, thv_up, rt_up              &
3805                                     ,rv_up, rc_up, u_up, v_up           &
3806                                     ,frac_up, restart,                  &
3807                                     allowed_to_read ,                   &
3808                                     ids, ide, jds, jde, kds, kde,       &
3809                                     ims, ime, jms, jme, kms, kme,       &
3810                                     its, ite, jts, jte, kts, kte   )  
3811 !          ENDIF
3813 #if (NMM_CORE != 1)
3814       CASE (BOULACSCHEME)
3815            if(isfc .ne. 1 .and. isfc .ne. 2)CALL wrf_error_fatal &
3816             ( 'module_physics_init: use sfclay or myjsfc scheme for this pbl option' )
3817            CALL boulacinit(RUBLTEN,RVBLTEN,RTHBLTEN,RQVBLTEN,RQCBLTEN, &
3818                          TKE_PBL,EXCH_H,restart,               &
3819                          allowed_to_read ,                     &
3820                          ids, ide, jds, jde, kds, kde,         &
3821                          ims, ime, jms, jme, kms, kme,         &
3822                          its, ite, jts, jte, kts, kte          )
3823         CASE (CAMUWPBLSCHEME)
3824            IF ((SF_URBAN_PHYSICS.eq.2).OR.(SF_URBAN_PHYSICS.EQ.3)) CALL wrf_error_fatal &
3825             ( 'module_physics_init: use ysu (option1), myj (option 2), or boulac (option 8) with BEP/BEM urban scheme' )
3826            CALL camuwpblinit(RUBLTEN,RVBLTEN,RTHBLTEN,RQVBLTEN,        &
3827                 restart,TKE_PBL,is_CAMMGMP_used, &
3828                 ids, ide, jds, jde, kds, kde,                          &
3829                 ims, ime, jms, jme, kms, kme,                          &
3830                 its, ite, jts, jte, kts, kte                           )
3831 #endif
3833 #if ( EM_CORE == 1 )
3835 !mynn 
3836            
3837         CASE (MYNNPBLSCHEME)
3838            IF(isfc .NE. 5 .AND. isfc .NE. 1 .AND. isfc .NE. 2) CALL wrf_error_fatal &
3839                 ( 'module_physics_init: use mynnsfc or sfclay or myjsfc scheme for this pbl option')
3840            IF ((SF_URBAN_PHYSICS.eq.2).OR.(SF_URBAN_PHYSICS.EQ.3)) CALL wrf_error_fatal &
3841             ( 'module_physics_init: use ysu (option1), myj (option 2), or boulac (option 8) with BEP/BEM urban scheme' )
3843                 CALL mynnedmf_wrapper_init(                  &
3844                 &RUBLTEN,RVBLTEN,RTHBLTEN,RQVBLTEN,RQCBLTEN, &
3845                 &RQIBLTEN,QKE,                               &
3846                 &restart,allowed_to_read,                    &
3847                 &P_QC,P_QI,PARAM_FIRST_SCALAR,               &
3848                 &IDS,IDE,JDS,JDE,KDS,KDE,                    &
3849                 &IMS,IME,JMS,JME,KMS,KME,                    &
3850                 &ITS,ITE,JTS,JTE,KTS,KTE                     )
3852       CASE (TEMFPBLSCHEME)
3853            ! if(isfc .ne. 0)CALL wrf_error_fatal &
3854            !  ( 'module_physics_init: use sfclay scheme = 0 for this pbl option' )
3855            IF ((SF_URBAN_PHYSICS.eq.2).OR.(SF_URBAN_PHYSICS.EQ.3)) CALL wrf_error_fatal &
3856             ( 'module_physics_init: use ysu (option1), myj (option 2), or boulac (option 8) with BEP/BEM urban scheme' )
3857          IF ( PRESENT( te_temf ) .AND. PRESENT( cf3d_temf )) THEN
3858            CALL temfinit(RUBLTEN,RVBLTEN,RTHBLTEN,RQVBLTEN,    &
3859                         RQCBLTEN,RQIBLTEN,P_QI,               &
3860                         PARAM_FIRST_SCALAR,                   &
3861                         restart,                              &
3862                         allowed_to_read ,                     &
3863                         te_temf,cf3d_temf,                    & ! WA
3864                         ids, ide, jds, jde, kds, kde,         &
3865                         ims, ime, jms, jme, kms, kme,         &
3866                         its, ite, jts, jte, kts, kte          )
3867              ELSE
3868                 CALL wrf_error_fatal ( 'arguments not present for calling TEMF scheme' )
3869          ENDIF
3871       CASE (EEPSSCHEME)
3872            IF(isfc .ne. 1 .and. isfc .ne. 2 .and. isfc .ne. 5 .and. isfc .ne. 91) CALL wrf_error_fatal &
3873                 ( 'module_physics_init: use mynnsfc or sfclay or myjsfc schemefor this pbl option')
3874            IF ((SF_URBAN_PHYSICS.eq.2).OR.(SF_URBAN_PHYSICS.EQ.3)) CALL wrf_error_fatal &
3875             ( 'module_physics_init: use myj (option 2) or boulac (option 8) with BEP/BEM urban scheme' )
3876           IF ( PRESENT( pek ) .AND. PRESENT( pep ) ) THEN
3877            CALL eepsinit(RUBLTEN,RVBLTEN,RTHBLTEN,RQVBLTEN,    &
3878                         RQCBLTEN,RQIBLTEN,P_QI,               &
3879                         PARAM_FIRST_SCALAR,pek,pep,           &
3880                         restart,                              &
3881                         allowed_to_read ,                     &
3882                         ids, ide, jds, jde, kds, kde,         &
3883                         ims, ime, jms, jme, kms, kme,         &
3884                         its, ite, jts, jte, kts, kte          )
3885           ELSE
3886             CALL wrf_error_fatal ( 'arguments not present for calling EEPS scheme' )
3887          ENDIF
3889 #endif
3891       CASE (GBMPBLSCHEME) 
3892            if(isfc .ne. 1)CALL wrf_error_fatal &
3893             ( 'module_physics_init: Use sf_sfclay_physics= 1 or 91 for this pbl option' )
3894          CALL gbmpblinit(RUBLTEN,RVBLTEN,RTHBLTEN,RQVBLTEN,   &
3895                         RQCBLTEN,RQIBLTEN,P_QI,               &
3896                         PARAM_FIRST_SCALAR,TKE_PBL,           &
3897                         EXCH_H,                               &
3898                         restart,allowed_to_read ,             &
3899                         ids, ide, jds, jde, kds, kde,         &
3900                         ims, ime, jms, jme, kms, kme,         &
3901                         its, ite, jts, jte, kts, kte          )
3903 #if ( WRFPLUS == 1 )
3904       CASE (SURFDRAGSCHEME)
3905          CALL surface_drag_init(RUBLTEN,RVBLTEN,RTHBLTEN,   &
3906                         RQVBLTEN,restart,                     &
3907                         ids, ide, jds, jde, kds, kde,         &
3908                         ims, ime, jms, jme, kms, kme,         &
3909                         its, ite, jts, jte, kts, kte          )
3910 #endif
3913       CASE DEFAULT
3915    END SELECT pbl_select
3918    END SUBROUTINE bl_init
3920 !==================================================================
3921    SUBROUTINE cu_init(DX,STEPCU,CUDT,DT,RUCUTEN,RVCUTEN,RTHCUTEN,  &
3922                       RQVCUTEN,RQRCUTEN,RQCCUTEN,RQSCUTEN,RQICUTEN,&
3923                       NCA,RAINC,RAINCV,W0AVG,config_flags,restart, &
3924                       CLDEFI,LOWLYR,                               &
3925                       MASS_FLUX, RTHFTEN, RQVFTEN,                 &
3926 #if ( EM_CORE == 1 )
3927                       !BSINGH - For WRFCuP Scheme
3928                       cupflag,cldfra_cup,cldfratend_cup,          & !CuP, wig 18-Sep-2006
3929                       shall,                                      & !CuP, wig 18-Sep-2006
3930                       tcloud_cup,                                 & !CuP, rce 18-apr-2012
3931                       !BSINGH -ENDS
3932 #endif
3933                       APR_GR,APR_W,APR_MC,APR_ST,APR_AS,           &
3934                       APR_CAPMA,APR_CAPME,APR_CAPMI,               &
3935                       cugd_tten,cugd_ttens,cugd_qvten,             &
3936                       cugd_qvtens,cugd_qcten,                      &
3937                       allowed_to_read, start_of_simulation,        &
3938                       ids, ide, jds, jde, kds, kde,                &
3939                       ims, ime, jms, jme, kms, kme,                &
3940                       its, ite, jts, jte, kts, kte,                &
3941                       RQCNCUTEN,RQINCUTEN)
3942 !------------------------------------------------------------------
3943    USE module_cu_kf
3944    USE module_cu_kfeta
3945    USE module_cu_mskf
3946    USE MODULE_CU_BMJ
3947    USE module_cu_gd,  ONLY : GDINIT
3948    USE module_cu_g3,  ONLY : G3INIT
3949    USE module_cu_sas
3950    USE module_cu_scalesas
3951    USE module_cu_osas
3952    USE module_cu_camzm_driver, ONLY : zm_conv_init
3953    USE module_cu_nsas
3954    USE module_cu_tiedtke
3955    USE module_cu_ntiedtke
3956 #if ( EM_CORE == 1 )
3957    USE module_cu_kfcup !BSINGH - For WRFCuP Scheme
3958 #endif
3959 #if ( WRFPLUS == 1 )
3960    USE module_cu_du, ONLY : ducuinit
3961 #endif
3962 !------------------------------------------------------------------
3963    IMPLICIT NONE 
3964 !------------------------------------------------------------------
3965    TYPE (grid_config_rec_type) ::     config_flags
3966    LOGICAL , INTENT(IN)        :: restart
3968    INTEGER , INTENT(IN)        :: ids, ide, jds, jde, kds, kde,   &
3969                                   ims, ime, jms, jme, kms, kme,   &
3970                                   its, ite, jts, jte, kts, kte
3972    REAL ,    INTENT(IN)        :: DT, CUDT, DX
3973    LOGICAL , INTENT(IN)        :: start_of_simulation
3974    LOGICAL , INTENT(IN)        :: allowed_to_read
3975    INTEGER , INTENT(INOUT)     :: STEPCU
3977    REAL ,   DIMENSION( ims:ime , kms:kme , jms:jme ) , INTENT(INOUT) ::    &    
3978             RUCUTEN, RVCUTEN, RTHCUTEN, RQVCUTEN, RQCCUTEN,                &
3979             RQRCUTEN, RQICUTEN, RQSCUTEN
3980 #if ( EM_CORE == 1 )
3981    !BSINGH - For WRFCuP Scheme
3982    REAL ,   DIMENSION( ims:ime , kms:kme , jms:jme ) , INTENT(INOUT) ::    &    
3983         cldfra_cup,cldfratend_cup                               !CuP, wig 18-Sep-2006
3984    !BSINGH -ENDS
3985 #endif
3987    REAL ,   DIMENSION( ims:ime , kms:kme , jms:jme ) , OPTIONAL, INTENT(INOUT) ::    &    
3988                         cugd_tten,cugd_ttens,cugd_qvten,            &    
3989                         cugd_qvtens,cugd_qcten, RQCNCUTEN, RQINCUTEN
3991    REAL ,   DIMENSION( ims:ime , kms:kme , jms:jme ) , INTENT(OUT) :: W0AVG
3993    REAL,    DIMENSION( ims:ime , kms:kme , jms:jme ) , INTENT(INOUT) ::    &!BSINGH(PNNL)- should be declared inout
3994             RTHFTEN, RQVFTEN
3996    REAL ,   DIMENSION( ims:ime , jms:jme ), INTENT(OUT):: RAINC, RAINCV
3998    REAL ,   DIMENSION( ims:ime , jms:jme ), INTENT(OUT):: CLDEFI
3999 #if ( EM_CORE == 1 )
4000    !BSINGH - For WRFCuP Scheme
4001    REAL ,   DIMENSION( ims:ime , jms:jme ), INTENT(OUT):: shall, & !CuP, wig 18-Sep-2006
4002                                                      tcloud_cup    !CuP, rce 18-apr-2012
4003    LOGICAL, DIMENSION( ims:ime , jms:jme ), INTENT(OUT):: cupflag  !CuP, wig 9-Oct-2006 !BSINGH - For WRFCuP Scheme
4004    !BSINGH -ENDS
4005 #endif
4007    REAL ,   DIMENSION( ims:ime , jms:jme ), INTENT(INOUT):: NCA
4009    REAL ,   DIMENSION( ims:ime , jms:jme ), INTENT(INOUT):: MASS_FLUX,   &
4010                                    APR_GR,APR_W,APR_MC,APR_ST,APR_AS,    &    
4011                                    APR_CAPMA,APR_CAPME,APR_CAPMI
4012    INTEGER, DIMENSION( ims:ime , jms:jme ), INTENT(INOUT):: LOWLYR
4014 ! LOCAL VAR
4016   INTEGER :: i,j,itf,jtf
4018 !--------------------------------------------------------------------
4020 !-- calculate cumulus parameterization time step
4022    itf=min0(ite,ide-1)
4023    jtf=min0(jte,jde-1)
4025    STEPCU = nint(CUDT*60./DT)
4026    STEPCU = max(STEPCU,1)
4028 !-- initialization
4030    IF(start_of_simulation)THEN
4031      DO j=jts,jtf
4032      DO i=its,itf
4033         RAINC(i,j)=0.
4034         RAINCV(i,j)=0.
4035      ENDDO
4036      ENDDO
4037    ENDIF
4039 !-- deep convection and hybrid deep-shallow convection schemes
4040    cps_select: SELECT CASE(config_flags%cu_physics)
4042      CASE (KFSCHEME)
4043           CALL kfinit(RTHCUTEN,RQVCUTEN,RQCCUTEN,RQRCUTEN,        &
4044                       RQICUTEN,RQSCUTEN,NCA,W0AVG,P_QI,P_QS,      &
4045                       PARAM_FIRST_SCALAR,restart,                 &
4046                       allowed_to_read ,                           &
4047                       ids, ide, jds, jde, kds, kde,               &
4048                       ims, ime, jms, jme, kms, kme,               &
4049                       its, ite, jts, jte, kts, kte                )
4051      CASE (BMJSCHEME)
4052           CALL bmjinit(RTHCUTEN,RQVCUTEN,RQCCUTEN,RQRCUTEN,       &
4053                       CLDEFI,LOWLYR,cp,r_d,restart,               &
4054                       allowed_to_read,                            &
4055                       ids, ide, jds, jde, kds, kde,               &
4056                       ims, ime, jms, jme, kms, kme,               &
4057                       its, ite, jts, jte, kts, kte                )
4059      CASE (KFETASCHEME)
4060           CALL kf_eta_init(RTHCUTEN,RQVCUTEN,RQCCUTEN,RQRCUTEN,   &
4061                       RQICUTEN,RQSCUTEN,NCA,W0AVG,P_QI,P_QS,      &
4062                       SVP1,SVP2,SVP3,SVPT0,                       &
4063                       PARAM_FIRST_SCALAR,restart,                 &
4064                       allowed_to_read ,                           &
4065                       ids, ide, jds, jde, kds, kde,               &
4066                       ims, ime, jms, jme, kms, kme,               &
4067                       its, ite, jts, jte, kts, kte                )
4069 #if ( EM_CORE == 1 )
4070      CASE (MSKFSCHEME)
4071           CALL mskf_init(RTHCUTEN,RQVCUTEN,RQCCUTEN,RQRCUTEN,     &
4072                       RQICUTEN,RQSCUTEN,NCA,W0AVG,P_QI,P_QS,      &
4073                       SVP1,SVP2,SVP3,SVPT0,                       &
4074                       PARAM_FIRST_SCALAR,restart,                 &
4075                       allowed_to_read ,                           &
4076                       ids, ide, jds, jde, kds, kde,               &
4077                       ims, ime, jms, jme, kms, kme,               &
4078                       its, ite, jts, jte, kts, kte,               &
4079                       RUCUTEN, RVCUTEN)                              !JTR
4080 #endif
4082      CASE (GDSCHEME)
4083           CALL gdinit(RTHCUTEN,RQVCUTEN,RQCCUTEN,RQICUTEN,        &
4084                       MASS_FLUX,cp,restart,                       &
4085                       P_QC,P_QI,PARAM_FIRST_SCALAR,               &
4086                       RTHFTEN, RQVFTEN,                           &
4087                       APR_GR,APR_W,APR_MC,APR_ST,APR_AS,          &
4088                       APR_CAPMA,APR_CAPME,APR_CAPMI,              &
4089                       allowed_to_read ,                           &
4090                       ids, ide, jds, jde, kds, kde,               &
4091                       ims, ime, jms, jme, kms, kme,               &
4092                       its, ite, jts, jte, kts, kte                )
4093      CASE (KSASSCHEME,NSASSCHEME)
4094          CALL nsasinit(RTHCUTEN,RQVCUTEN,RQCCUTEN,RQICUTEN,       &
4095                       RUCUTEN,RVCUTEN,                            & 
4096                       restart,P_QC,P_QI,PARAM_FIRST_SCALAR,       &
4097                       allowed_to_read ,                           &
4098                       ids, ide, jds, jde, kds, kde,               &
4099                       ims, ime, jms, jme, kms, kme,               &
4100                       its, ite, jts, jte, kts, kte                )
4102 #if ( EM_CORE == 1 )
4103      CASE (G3SCHEME,GFSCHEME)
4104           CALL g3init(RTHCUTEN,RQVCUTEN,RQCCUTEN,RQICUTEN,        &
4105                       MASS_FLUX,cp,restart,                       &
4106                       P_QC,P_QI,PARAM_FIRST_SCALAR,               &
4107                       RTHFTEN, RQVFTEN,                           &
4108                       APR_GR,APR_W,APR_MC,APR_ST,APR_AS,          &
4109                       APR_CAPMA,APR_CAPME,APR_CAPMI,              &
4110                       cugd_tten,cugd_ttens,cugd_qvten,            &
4111                       cugd_qvtens,cugd_qcten,                     &
4112                       allowed_to_read ,                           &
4113                       ids, ide, jds, jde, kds, kde,               &
4114                       ims, ime, jms, jme, kms, kme,               &
4115                       its, ite, jts, jte, kts, kte                )
4116 #endif
4117      CASE (SASSCHEME)
4118           CALL sasinit(RTHCUTEN,RQVCUTEN,RQCCUTEN,RQICUTEN,       &
4119                       RUCUTEN,RVCUTEN,                            &   ! gopal's doing for SAS
4120                       restart,P_QC,P_QI,PARAM_FIRST_SCALAR,       &
4121                       allowed_to_read ,                           &
4122                       ids, ide, jds, jde, kds, kde,               &
4123                       ims, ime, jms, jme, kms, kme,               &
4124                       its, ite, jts, jte, kts, kte                )
4126      CASE (SCALESASSCHEME)
4127           CALL scalesasinit(RTHCUTEN,RQVCUTEN,RQCCUTEN,RQICUTEN,  &
4128                       RUCUTEN,RVCUTEN,                            &   
4129                       restart,P_QC,P_QI,PARAM_FIRST_SCALAR,       &
4130                       allowed_to_read ,                           &
4131                       ids, ide, jds, jde, kds, kde,               &
4132                       ims, ime, jms, jme, kms, kme,               &
4133                       its, ite, jts, jte, kts, kte                )
4135 #if ( EM_CORE == 1 )
4136           !BSINGH - For WRFCuP Scheme
4137     CASE (KFCUPSCHEME)  !wig: 18-Sep-2006
4138        CALL kf_cup_init(RTHCUTEN,RQVCUTEN,RQCCUTEN,RQRCUTEN,   &
4139                       RQICUTEN,RQSCUTEN,NCA,W0AVG,P_QI,P_QS,      &
4140                       SVP1,SVP2,SVP3,SVPT0,                       &
4141                       cupflag,cldfra_cup,cldfratend_cup,          &
4142                       shall,                                      &
4143                       tcloud_cup,                                 &
4144                       PARAM_FIRST_SCALAR,restart,                 &
4145                       allowed_to_read ,                           &
4146                       ids, ide, jds, jde, kds, kde,               &
4147                       ims, ime, jms, jme, kms, kme,               &
4148                       its, ite, jts, jte, kts, kte                )
4150     !BSINGH - ENDS
4151 #endif
4153      CASE (OSASSCHEME)
4154           CALL osasinit(RTHCUTEN,RQVCUTEN,RQCCUTEN,RQICUTEN,      &
4155                       RUCUTEN,RVCUTEN,                            &   ! gopal's doing for SAS
4156                       restart,P_QC,P_QI,PARAM_FIRST_SCALAR,       &
4157                       allowed_to_read ,                           &
4158                       ids, ide, jds, jde, kds, kde,               &
4159                       ims, ime, jms, jme, kms, kme,               &
4160                       its, ite, jts, jte, kts, kte                )
4162      CASE (CAMZMSCHEME)
4163           IF (PRESENT(RQCNCUTEN)) THEN
4164           CALL zm_conv_init(DT, DX, rucuten, rvcuten, rthcuten, rqvcuten, &
4165                       rqccuten, rqicuten, rqcncuten, rqincuten,         &
4166                       p_qc, p_qi, p_qnc, p_qni, param_first_scalar,     &
4167                       restart,                                          &
4168                       ids, ide, jds, jde, kds, kde,                     &
4169                       ims, ime, jms, jme, kms, kme,                     &
4170                       its, ite, jts, jte, kts, kte                      )
4171           ELSE
4172           CALL wrf_error_fatal ( 'arguments not present for calling camzmscheme' )
4173           ENDIF
4175 ! Tiedtke Scheme - ZCX&YQW
4176       CASE (TIEDTKESCHEME)
4177           CALL tiedtkeinit(RTHCUTEN,RQVCUTEN,RQCCUTEN,RQICUTEN,   &
4178                       RUCUTEN,RVCUTEN,                            & 
4179                       restart,P_QC,P_QI,PARAM_FIRST_SCALAR,       &
4180                       allowed_to_read ,                           &
4181                       ids, ide, jds, jde, kds, kde,               &
4182                       ims, ime, jms, jme, kms, kme,               &
4183                       its, ite, jts, jte, kts, kte                )
4185       CASE (NTIEDTKESCHEME)
4186           CALL ntiedtkeinit(RTHCUTEN,RQVCUTEN,RQCCUTEN,RQICUTEN,  &
4187                       RUCUTEN,RVCUTEN,                            &
4188                       RTHFTEN, RQVFTEN,                           &
4189                       restart,P_QC,P_QI,PARAM_FIRST_SCALAR,       &
4190                       allowed_to_read ,                           &
4191                       ids, ide, jds, jde, kds, kde,               &
4192                       ims, ime, jms, jme, kms, kme,               &
4193                       its, ite, jts, jte, kts, kte                )
4195 #if ( WRFPLUS == 1 )
4196 ! this is for WRFPlus only
4197       CASE (DUCUSCHEME)
4198           CALL ducuinit(RTHCUTEN,RQVCUTEN,RQCCUTEN,RQRCUTEN,      &
4199                       RQICUTEN,RQSCUTEN,NCA,W0AVG,P_QC,P_QR,      &
4200                       SVP1,SVP2,SVP3,SVPT0,                       &
4201                       PARAM_FIRST_SCALAR,restart,                 &
4202                       allowed_to_read ,                           &
4203                       ids, ide, jds, jde, kds, kde,               &
4204                       ims, ime, jms, jme, kms, kme,               &
4205                       its, ite, jts, jte, kts, kte                )
4206 #endif
4208       CASE DEFAULT
4210    END SELECT cps_select
4212    END SUBROUTINE cu_init
4214 !==================================================================
4215    SUBROUTINE shcu_init(STEPCU,CUDT,DT,RUSHTEN,RVSHTEN,RTHSHTEN,   &
4216                       RQVSHTEN,RQRSHTEN,RQCSHTEN,                  &
4217                       RQSSHTEN,RQISHTEN,RQGSHTEN,                  &
4218                       NCA,RAINC,RAINCV,config_flags,restart,       &
4219                       allowed_to_read, start_of_simulation,        &
4220                       RDCASHTEN, RQCDCSHTEN, W0AVG,                &
4221                       cldareaa, cldareab, cldliqa,  cldliqb,       &
4222                       ca_rad, cw_rad,                              &
4223                       pblmax, wub, ltopb, clddpthb, cldtopb,       &
4224                       capesave, ainckfsa, radsave,                 &
4225                       rainsh, rainshvb, kdcldtop, kdcldbas, xtime1,&
4226                       PBLHAVG, TKEAVG,                             &
4227                       ids, ide, jds, jde, kds, kde,                &
4228                       ims, ime, jms, jme, kms, kme,                &
4229                       its, ite, jts, jte, kts, kte                 )
4230 !------------------------------------------------------------------
4231    USE uwshcu,        ONLY: init_uwshcu
4232    USE module_shcu_grims, ONLY: grimsinit
4233    USE module_shcu_nscv , ONLY: nscvinit
4234    USE module_shcu_deng , ONLY: deng_shcu_init
4235    USE physconst,     ONLY: cpair, gravit, latice, latvap, mwdry, mwh2o, &
4236                             rair, zvir
4237    USE shr_kind_mod,  ONLY: r8 => shr_kind_r8
4239 !------------------------------------------------------------------
4240    IMPLICIT NONE
4241 !------------------------------------------------------------------
4242    TYPE (grid_config_rec_type) :: config_flags
4243    LOGICAL , INTENT(IN)        :: restart
4246    INTEGER , INTENT(IN)        :: ids, ide, jds, jde, kds, kde,   &
4247                                   ims, ime, jms, jme, kms, kme,   &
4248                                   its, ite, jts, jte, kts, kte
4250    REAL ,    INTENT(IN)        :: DT, CUDT
4251    LOGICAL , INTENT(IN)        :: start_of_simulation
4252    LOGICAL , INTENT(IN)        :: allowed_to_read
4253    INTEGER , INTENT(INOUT)     :: STEPCU
4255    REAL ,   DIMENSION( ims:ime , kms:kme , jms:jme ) , INTENT(INOUT) ::    &
4256             RUSHTEN, RVSHTEN, RTHSHTEN, &
4257             RQVSHTEN, RQCSHTEN, RQRSHTEN, RQISHTEN, RQSSHTEN, RQGSHTEN
4259    REAL ,   DIMENSION( ims:ime , jms:jme ), INTENT(OUT):: RAINC, RAINCV
4261    REAL ,   DIMENSION( ims:ime , jms:jme ), INTENT(INOUT):: NCA
4263    REAL, OPTIONAL, DIMENSION( ims:ime , jms:jme ) , &
4264           INTENT(  OUT) ::    pblmax, clddpthb, cldtopb, rainsh, rainshvb, &
4265                               capesave, radsave, xtime1, PBLHAVG
4267    REAL, OPTIONAL, DIMENSION( ims:ime , 1:100, jms:jme ) , &
4268           INTENT(  OUT) ::    ainckfsa
4270    INTEGER, OPTIONAL, DIMENSION( ims:ime , jms:jme ) , &
4271           INTENT(  OUT) ::    kdcldtop, kdcldbas, ltopb
4273    REAL, OPTIONAL, DIMENSION( ims:ime , kms:kme , jms:jme ) , &
4274           INTENT(  OUT) ::    wub, cldareaa,  cldareab,                &
4275                                    cldliqa,   cldliqb,  W0AVG, TKEAVG, &
4276                                    ca_rad, cw_rad
4278    REAL, OPTIONAL, DIMENSION( ims:ime , kms:kme , jms:jme ) , INTENT(INOUT) :: &
4279              RDCASHTEN, RQCDCSHTEN
4281 ! LOCAL VAR
4283   INTEGER :: i,j,itf,jtf
4285 !--------------------------------------------------------------------
4287 ! Some of this stuff is redundant with deep convection, but redo it
4288 ! in case deep is turned off...
4290 !-- calculate cumulus parameterization time step
4292    itf=min0(ite,ide-1)
4293    jtf=min0(jte,jde-1)
4295    STEPCU = nint(CUDT*60./DT)
4296    STEPCU = max(STEPCU,1)
4298 !-- initialization
4300    IF(start_of_simulation)THEN
4301      DO j=jts,jtf
4302      DO i=its,itf
4303         RAINC(i,j)=0.
4304         RAINCV(i,j)=0.
4305      ENDDO
4306      ENDDO
4307    ENDIF
4309 !-- independent shallow convection schemes
4310    shcu_select: SELECT CASE(config_flags%shcu_physics)
4312    CASE (CAMUWSHCUSCHEME)
4313       CALL init_uwshcu(r8,latvap,cpair,latice,zvir,rair,gravit,      &
4314            mwh2o/mwdry,                                              &
4315            rushten, rvshten, rthshten, rqvshten,                     &
4316            rqcshten, rqrshten, rqishten, rqsshten, rqgshten,         &
4317            p_qc, p_qr, p_qi, p_qs, p_qg,                             &
4318            config_flags%bl_pbl_physics, param_first_scalar, restart, &
4319            ids, ide, jds, jde, kds, kde,                             &
4320            ims, ime, jms, jme, kms, kme,                             &
4321            its, ite, jts, jte, kts, kte                              )
4323    CASE (GRIMSSHCUSCHEME)
4324       CALL grimsinit(rthshten,rqvshten,                              &
4325            restart,                                                  &
4326            ids, ide, jds, jde, kds, kde,                             &
4327            ims, ime, jms, jme, kms, kme,                             &
4328            its, ite, jts, jte, kts, kte                              )
4330    CASE (NSCVSHCUSCHEME)
4331       CALL nscvinit(rthshten,rqvshten,rqcshten,rqishten,             &
4332            rushten,rvshten,                                          &
4333            restart,p_qc,p_qi,param_first_scalar,                     &
4334            allowed_to_read ,                                         &
4335            ids, ide, jds, jde, kds, kde,                             &
4336            ims, ime, jms, jme, kms, kme,                             &
4337            its, ite, jts, jte, kts, kte                              )
4339 #if ( EM_CORE == 1 )
4340    CASE (DENGSHCUSCHEME)
4341       CALL deng_shcu_init(RTHSHTEN,RQVSHTEN,RQCSHTEN,RQRSHTEN,      &
4342                      RUSHTEN,RVSHTEN,RDCASHTEN,RQCDCSHTEN,W0AVG,    &
4343                      PBLHAVG, TKEAVG,                               &
4344                      cldareaa, cldareab, cldliqa,  cldliqb,         &
4345                      ca_rad, cw_rad,                          &
4346                      wub, pblmax, ltopb, clddpthb, cldtopb,         &
4347                      capesave, ainckfsa, radsave,                   &
4348                      rainsh, rainshvb, kdcldtop, kdcldbas,                  &
4349                      xtime1, restart,                               &
4350                      SVP1,SVP2,SVP3,SVPT0,                          &
4351                      ids, ide, jds, jde, kds, kde,                  &
4352                      ims, ime, jms, jme, kms, kme,                  &
4353                      its, ite, jts, jte, kts, kte                   )
4354 #endif
4356    CASE DEFAULT
4358    END SELECT shcu_select
4360    END SUBROUTINE shcu_init
4362 !==================================================================
4363    SUBROUTINE mp_init(RAINNC,SNOWNC,GRAUPELNC,config_flags,restart,warm_rain,      &
4364                       adv_moist_cond,                             &
4365                       MPDT, DT, DX, DY, LOWLYR,                   & ! for eta mp
4366                       F_ICE_PHY,F_RAIN_PHY,F_RIMEF_PHY,           & ! for eta mp
4367 #if ( EM_CORE == 1 )
4368                       PHB,PH,P,PB,QV,XLAND,CCNTY,QDCN,QTCN,QCCN,  & ! for ntu3m
4369                       QRCN,QNIN,                                  & ! for ntu3m
4370 #endif
4371                       mp_restart_state,tbpvs_state,tbpvs0_state,   & ! eta mp
4372                       allowed_to_read, start_of_simulation,       &
4373 !CAMMGMP specific variables
4374                       ixcldliq, ixcldice, ixnumliq, ixnumice,     &       
4375                       ccn_conc,                                  & ! RAS
4376                       z_at_q, inv_dens, qnwfa2d, qnbca2d,        &  ! G. Thompson
4377                       frc_urb2d, scalar, num_sc,                 &  ! G. Thompson
4378                       ids, ide, jds, jde, kds, kde,               &
4379                       ims, ime, jms, jme, kms, kme,               &
4380                       its, ite, jts, jte, kts, kte                )
4381 !------------------------------------------------------------------
4382    USE module_mp_wsm3
4383    USE module_mp_wsm5
4384    USE mp_wsm6
4385    USE module_mp_wsm7
4386    USE module_mp_etanew
4387    USE module_mp_fer_hires
4388 #if (NMM_CORE == 1)
4389    USE module_mp_HWRF
4390 #endif
4391    USE module_mp_thompson
4392    USE module_mp_full_sbm
4393 #if (BUILD_SBM_FAST == 1)
4394    USE module_mp_fast_sbm
4395 #endif
4396    USE module_mp_morr_two_moment
4397    USE microphy_p3
4398    USE module_mp_jensen_ishmael
4399    USE module_mp_milbrandt2mom
4400 !  USE module_mp_milbrandt3mom
4401    USE module_mp_wdm5
4402    USE module_mp_wdm6
4403    USE module_mp_wdm7
4404 #if (WRFPLUS != 1) & !defined( VAR4D )
4405    USE module_mp_nssl_2mom, only: nssl_2mom_init
4406 #endif
4407 #if (EM_CORE==1)
4408    USE module_mp_cammgmp_driver, ONLY:CAMMGMP_INIT !CAM5's microphysics
4409    USE module_mp_morr_two_moment_aero              !TWG2017
4410    USE module_mp_ntu
4411 #endif
4412 !------------------------------------------------------------------
4413    IMPLICIT NONE
4414 !------------------------------------------------------------------
4415 ! Arguments
4416    TYPE (grid_config_rec_type) ::     config_flags
4417    LOGICAL , INTENT(IN)        :: restart
4418    LOGICAL , INTENT(OUT)       :: warm_rain,adv_moist_cond
4419    REAL    , INTENT(IN)        :: MPDT, DT, DX, DY
4421    LOGICAL , INTENT(IN)        :: start_of_simulation
4422    INTEGER , INTENT(IN)        :: ixcldliq, ixcldice, ixnumliq, ixnumice ! CAMMGMP specific variables
4424    INTEGER , INTENT(IN)        :: ids, ide, jds, jde, kds, kde,   &
4425                                   ims, ime, jms, jme, kms, kme,   &
4426                                   its, ite, jts, jte, kts, kte
4428    INTEGER , DIMENSION( ims:ime , jms:jme ) ,INTENT(INOUT)  :: LOWLYR
4429    REAL,     DIMENSION( ims:ime , jms:jme ) , INTENT(INOUT) :: RAINNC,SNOWNC,GRAUPELNC
4430    REAL,     DIMENSION( ims:ime , kms:kme, jms:jme ) , INTENT(INOUT) :: &
4431                                   F_ICE_PHY,F_RAIN_PHY,F_RIMEF_PHY
4432 #if ( EM_CORE == 1 )
4433    INTEGER, OPTIONAL, INTENT(IN) :: CCNTY                                              ! for ntu3m
4434    REAL, OPTIONAL, DIMENSION(ims:ime,jms:jme), INTENT(IN) :: XLAND                     ! for ntu3m
4435    REAL, OPTIONAL, INTENT(IN), DIMENSION(ims:ime,kms:kme,jms:jme) :: PHB,PH,P,PB,QV    ! for ntu3m
4436    REAL, INTENT(INOUT), DIMENSION(ims:ime,kms:kme,jms:jme) :: QDCN,QTCN,QCCN,QRCN,QNIN ! for ntu3m
4437 #endif
4438    REAL , DIMENSION(:) ,INTENT(INOUT)  :: mp_restart_state,tbpvs_state,tbpvs0_state
4439    LOGICAL , INTENT(IN)  :: allowed_to_read
4440    REAL, INTENT(INOUT) :: ccn_conc ! RAS
4441    REAL, DIMENSION(ims:ime,jms:jme), INTENT(INOUT):: qnwfa2d, qnbca2d              !  G. Thompson
4442    REAL, DIMENSION(ims:ime,jms:jme), INTENT(IN):: frc_urb2d
4443    REAL, DIMENSION(ims:ime,kms:kme,jms:jme), INTENT(IN):: z_at_q                   !  G. Thompson
4444    REAL, DIMENSION(ims:ime,kms:kme,jms:jme), INTENT(IN):: inv_dens                 !  G. Thompson
4445    INTEGER, INTENT(IN) :: num_sc                                               !  G. Thompson
4446    REAL, DIMENSION(ims:ime,kms:kme,jms:jme, num_sc), INTENT(INOUT):: scalar    !  G. Thompson
4448 ! Local
4449    INTEGER :: i, j, itf, jtf
4450    REAL, DIMENSION(20) :: nssl_params
4451    INTEGER    :: nssl_ipelec_tmp, nssl_ipconc
4452    logical :: nssl_density_on
4453    INTEGER    :: i_err
4455 ! To accommodate shared physics
4456    character*256 :: errmsg
4457    integer :: errflg
4459    warm_rain = .false.
4460    adv_moist_cond = .true.
4461    itf=min0(ite,ide-1)
4462    jtf=min0(jte,jde-1)
4464    IF(start_of_simulation)THEN
4465      DO j=jts,jtf
4466      DO i=its,itf
4467         RAINNC(i,j) = 0.
4468         SNOWNC(i,j) = 0.
4469         GRAUPELNC(i,j) = 0.
4470      ENDDO
4471      ENDDO
4472    ENDIF
4473    
4474    mp_select: SELECT CASE(config_flags%mp_physics)
4476      CASE (KESSLERSCHEME)
4477           warm_rain = .true.
4478 #if ( WRFPLUS == 1 )
4479      CASE (MKESSLERSCHEME)
4480           warm_rain = .true.
4481 #endif
4482      CASE (WSM3SCHEME)
4483           CALL wsm3init(rhoair0,rhowater,rhosnow,cliq,cpv, allowed_to_read )
4484      CASE (WSM5SCHEME)
4485           CALL wsm5init(rhoair0,rhowater,rhosnow,cliq,cpv, allowed_to_read )
4486      CASE (WSM6SCHEME)
4487           CALL mp_wsm6_init(rhoair0,rhowater,rhosnow,cliq,cpv,config_flags%hail_opt,errmsg,errflg)
4488      CASE (WSM7SCHEME)
4489           CALL wsm7init(rhoair0,rhowater,rhosnow,cliq,cpv, allowed_to_read )
4490      CASE (ETAMPNEW)
4491          adv_moist_cond = .false.
4492          CALL etanewinit (MPDT,DT,DX,DY,LOWLYR,restart,           &
4493                           F_ICE_PHY,F_RAIN_PHY,F_RIMEF_PHY,       &
4494                           mp_restart_state,tbpvs_state,tbpvs0_state,&
4495                           allowed_to_read,                        &
4496                           ids, ide, jds, jde, kds, kde,           &
4497                           ims, ime, jms, jme, kms, kme,           &
4498                           its, ite, jts, jte, kts, kte            )
4499      CASE (FER_MP_HIRES,FER_MP_HIRES_ADVECT)
4500                CALL fer_hires_init (MPDT,DT,DX,DY,LOWLYR,restart,         &
4501                             allowed_to_read,                        &
4502                             ids, ide, jds, jde, kds, kde,           &
4503                             ims, ime, jms, jme, kms, kme,           &
4504                             its, ite, jts, jte, kts, kte,           &
4505                             F_ICE_PHY,F_RAIN_PHY,F_RIMEF_PHY)
4506 #if(NMM_CORE==1)
4507      CASE (etamp_HWRF)
4508          CALL etanewinit_HWRF (MPDT,DT,DX,DY,LOWLYR,restart,           &
4509                           F_ICE_PHY,F_RAIN_PHY,F_RIMEF_PHY,       &
4510                           allowed_to_read,                        &
4511                           ids, ide, jds, jde, kds, kde,           &
4512                           ims, ime, jms, jme, kms, kme,           &
4513                           its, ite, jts, jte, kts, kte            )
4514 #endif 
4515      CASE (THOMPSON)
4516          IF(start_of_simulation.or.restart.or.config_flags%cycling)     &
4517             CALL thompson_init(HGT=z_at_q,                              &
4518                           IDS=ids, IDE=ide, JDS=jds, JDE=jde, KDS=kds, KDE=kde,   &
4519                           IMS=ims, IME=ime, JMS=jms, JME=jme, KMS=kms, KME=kme,   &
4520                           ITS=its, ITE=ite, JTS=jts, JTE=jte, KTS=kts, KTE=kte)
4522      CASE (THOMPSONAERO)
4523 ! Cycling the WRF forecast with moving nests will cause this initialization to be
4524 ! called for each nest move. This is potentially very computationally expensive.
4525          IF(start_of_simulation.or.restart.or.config_flags%cycling)     &
4526             CALL thompson_init(HGT=z_at_q,                              &
4527                           ORHO=inv_dens,                                &
4528                           NWFA2D=qnwfa2d, NBCA2D=qnbca2d,               &
4529                           NWFA=scalar(ims,kms,jms,P_QNWFA),             &
4530                           NIFA=scalar(ims,kms,jms,P_QNIFA),             &
4531                           NBCA=scalar(ims,kms,jms,P_QNBCA),             &
4532                           wif_input_opt=config_flags%wif_input_opt,     &
4533                           FRC_URB2D=frc_urb2d,                          &
4534                           DX=DX, DY=DY,                                 &
4535                           is_start=start_of_simulation,                 &
4536                           IDS=ids, IDE=ide, JDS=jds, JDE=jde, KDS=kds, KDE=kde,   &
4537                           IMS=ims, IME=ime, JMS=jms, JME=jme, KMS=kms, KME=kme,   &
4538                           ITS=its, ITE=ite, JTS=jts, JTE=jte, KTS=kts, KTE=kte)
4540      CASE (THOMPSONGH)
4541 ! Cycling the WRF forecast with moving nests will cause this initialization to be
4542 ! called for each nest move. This is potentially very computationally expensive.
4543          IF(start_of_simulation.or.restart.or.config_flags%cycling)     &
4544             CALL thompson_init(HGT=z_at_q,                              &
4545                           ORHO=inv_dens,                                &
4546                           NWFA2D=qnwfa2d,                               &
4547                           NWFA=scalar(ims,kms,jms,P_QNWFA),             &
4548                           NIFA=scalar(ims,kms,jms,P_QNIFA),             &
4549                           NBCA=scalar(ims,kms,jms,P_QNBCA),             &
4550                           wif_input_opt=config_flags%wif_input_opt,     &
4551                           FRC_URB2D=frc_urb2d,                          &
4552                           NG=scalar(ims,kms,jms,P_QNG),                 &
4553                           DX=DX, DY=DY,                                 &
4554                           is_start=start_of_simulation,                 &
4555                           IDS=ids, IDE=ide, JDS=jds, JDE=jde, KDS=kds, KDE=kde,   &
4556                           IMS=ims, IME=ime, JMS=jms, JME=jme, KMS=kms, KME=kme,   &
4557                           ITS=its, ITE=ite, JTS=jts, JTE=jte, KTS=kts, KTE=kte)
4559      CASE (MORR_TWO_MOMENT)
4560          CALL morr_two_moment_init( config_flags%morr_rimed_ice )
4561 #if (EM_CORE==1)
4562      CASE (MORR_TM_AERO)
4563          CALL morr_two_moment_init_aero( config_flags%morr_rimed_ice )
4564 #endif
4565      CASE (JENSEN_ISHMAEL)
4566         CALL jensen_ishmael_init()
4568      CASE (P3_1CATEGORY)
4569          CALL p3_init('.',1,.false.,'WRF',i_err,.false.)
4570      CASE (P3_1CATEGORY_NC)
4571          CALL p3_init('.',1,.false.,'WRF',i_err,.false.)
4572      CASE (P3_2CATEGORY)
4573          CALL p3_init('.',2,.false.,'WRF',i_err,.false.)
4574      CASE (P3_1CAT_3MOM)
4575          CALL p3_init('.',1,.true.,'WRF',i_err,.false.)
4576      CASE (MILBRANDT2MOM)
4577          CALL milbrandt2mom_init
4578 !      CASE (MILBRANDT3MOM)
4579 !          CALL milbrandt3mom_init
4580      CASE (WDM5SCHEME)
4581           CALL wdm5init(rhoair0,rhowater,rhosnow,cliq,cpv,ccn_conc,allowed_to_read )
4582      CASE (WDM6SCHEME)
4583           CALL wdm6init(rhoair0,rhowater,rhosnow,cliq,cpv,ccn_conc, &
4584                         config_flags%hail_opt, allowed_to_read )
4585      CASE (WDM7SCHEME)
4586           CALL wdm7init(rhoair0,rhowater,rhosnow,cliq,cpv,ccn_conc, allowed_to_read )
4587 #if (EM_CORE==1)
4588      CASE (NTU)
4589           CALL ntu_init(PHB,PH,P,PB,inv_dens,QV,QDCN,QTCN,QCCN,QRCN,   &
4590                         QNIN,XLAND,CCNTY,restart,ids,ide,jds,jde,kds,  &
4591                         kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,   &
4592                         kts,kte)
4593 #endif
4594 #if (EM_CORE==1)
4595     CASE (FULL_KHAIN_LYNN)
4596      IF(start_of_simulation.or.restart)THEN
4597           CALL full_hucminit(dt)
4598      END IF
4599 # if (BUILD_SBM_FAST == 1)
4600     CASE (FAST_KHAIN_LYNN_SHPUND)
4601      IF(start_of_simulation.or.restart)THEN
4602           CALL fast_hucminit(dt)
4603      END IF
4604 # endif
4605 #endif
4606      CASE (NSSL_2MOM)
4607 !   Single generalized case (mp_physics=18) replaces previously separate mp_physics values of 17,18,19,20,22
4608 #if (WRFPLUS != 1) & !defined( VAR4D )
4610         IF ( config_flags%elec_physics > 0 ) THEN
4611           nssl_ipelec_tmp = config_flags%nssl_ipelec
4612         ELSE
4613           nssl_ipelec_tmp = 0.0
4614         ENDIF
4616        nssl_params(:)  = 0
4617        nssl_params(1)  = config_flags%nssl_cccn
4618        nssl_params(2)  = config_flags%nssl_alphah
4619        nssl_params(3)  = config_flags%nssl_alphahl
4620        nssl_params(4)  = config_flags%nssl_cnoh
4621        nssl_params(5)  = config_flags%nssl_cnohl
4622        nssl_params(6)  = config_flags%nssl_cnor
4623        nssl_params(7)  = config_flags%nssl_cnos
4624        nssl_params(8)  = config_flags%nssl_rho_qh
4625        nssl_params(9)  = config_flags%nssl_rho_qhl
4626        nssl_params(10) = config_flags%nssl_rho_qs
4627        nssl_params(11) = nssl_ipelec_tmp
4628        nssl_params(12) = config_flags%nssl_isaund
4629        nssl_params(13) = 0 ! reserved
4630        nssl_params(14) = 0 ! reserved
4631        nssl_params(15) = 0 ! reserved
4632        
4633        IF ( config_flags%nssl_2moment_on == 0 ) THEN
4634          nssl_ipconc = 0
4635        ELSE
4636          IF ( config_flags%nssl_3moment > 0 ) THEN
4637            nssl_ipconc = 8
4638          ELSE
4639            nssl_ipconc = 5
4640          ENDIF
4641        ENDIF
4643          IF ( config_flags % nssl_ccn_on > 0 ) THEN
4644             ccn_conc = config_flags%nssl_cccn/1.225 ! set this to have correct boundary conditions
4645          ENDIF
4646          CALL nssl_2mom_init(nssl_params=nssl_params,ipctmp=nssl_ipconc,mixphase=0, &
4647            nssl_density_on=(config_flags%nssl_density_on > 0), &
4648            nssl_hail_on=config_flags%nssl_hail_on > 0, &
4649            nssl_ccn_on=(config_flags%nssl_ccn_on > 0), &
4650            nssl_icdx=config_flags%nssl_icdx, &
4651            nssl_icdxhl=config_flags%nssl_icdxhl,ccn_is_ccna=config_flags%nssl_ccn_is_ccna)
4652 #endif
4653 #if (EM_CORE==1)
4654      CASE (CAMMGMPSCHEME) ! CAM5's microphysics
4655           CALL CAMMGMP_INIT(ixcldliq, ixcldice, ixnumliq, ixnumice &
4656              ,config_flags%chem_opt                          &
4657              ,ids, ide, jds, jde, kds, kde                   & 
4658              ,ims, ime, jms, jme, kms, kme                   &
4659              ,its, ite, jts, jte, kts, kte                   )
4660 #endif
4662      CASE DEFAULT
4664    END SELECT mp_select
4666    if (config_flags%madwrf_opt == 2 .and. (.not. f_qc .or. .not. f_qi .or. .not. f_qs)) &
4667         call wrf_error_fatal('madwrf_opt = 2 requires a mp_physics option with qc, qi, and qs')
4669    END SUBROUTINE mp_init
4671 #if  ( EM_CORE == 1 )
4672 !==========================================================
4673    SUBROUTINE fg_init(STEPFG,FGDT,DT,id,RUNDGDTEN,RVNDGDTEN,    &
4674                 RTHNDGDTEN,RPHNDGDTEN,RQVNDGDTEN,RMUNDGDTEN,    &
4675                 SDA_HFX, SDA_QFX, QNORM, HFX_BOTH, QFX_BOTH,    & ! fasdas
4676                 HFX_FDDA,                                       & ! fasdas
4677                 config_flags,restart,                           &
4678                 allowed_to_read ,                               &
4679                 ids, ide, jds, jde, kds, kde,                   &
4680                 ims, ime, jms, jme, kms, kme,                   &
4681                 its, ite, jts, jte, kts, kte                    )
4684 !--------------------------------------------------------------------
4685    USE module_fdda_psufddagd
4686    USE module_fdda_spnudging, ONLY : fddaspnudginginit
4687 !--------------------------------------------------------------------
4688    IMPLICIT NONE
4689 !--------------------------------------------------------------------
4690    TYPE (grid_config_rec_type) ::     config_flags
4691    LOGICAL , INTENT(IN)        :: restart
4693    INTEGER , INTENT(IN)        ::     ids, ide, jds, jde, kds, kde, &
4694                                       ims, ime, jms, jme, kms, kme, &
4695                                       its, ite, jts, jte, kts, kte
4697    REAL ,    INTENT(IN)        ::     DT, FGDT
4698    INTEGER , INTENT(IN)        ::     id
4699    INTEGER , INTENT(INOUT)     ::     STEPFG
4700    REAL,     DIMENSION( ims:ime , kms:kme , jms:jme ) , INTENT(INOUT) ::       &!BSINGH(PNNL)- should be declared inout
4701                                                            RUNDGDTEN, &
4702                                                            RVNDGDTEN, &
4703                                                           RTHNDGDTEN, &
4704                                                           RPHNDGDTEN, &
4705                                                           RQVNDGDTEN
4707 ! FASDAS
4709    REAL ,    DIMENSION( ims:ime , jms:jme ) , INTENT(INOUT)           ::    &
4710                                                              SDA_HFX, &
4711                                                              SDA_QFX, &
4712                                                              QNORM,HFX_BOTH,QFX_BOTH
4713 !  INTEGER , INTENT(IN   )                                  ::  fasdas
4714    REAL ,    DIMENSION( ims:ime , kms:kme , jms:jme ) , INTENT(INOUT) :: &
4715                                                             HFX_FDDA
4717    REAL,     DIMENSION( ims:ime , jms:jme ) , INTENT(INOUT) :: RMUNDGDTEN !BSINGH(PNNL)- should be declared inout
4719    LOGICAL,  INTENT(IN)           :: allowed_to_read
4720 !--------------------------------------------------------------------
4722 !-- calculate pbl time step
4724    STEPFG = nint(FGDT*60./DT)
4725    STEPFG = max(STEPFG,1)
4728 !-- initialize fdda scheme
4730    fdda_select: SELECT CASE(config_flags%grid_fdda)
4732       CASE (PSUFDDAGD)
4733            CALL fddagdinit(id,rundgdten,rvndgdten,rthndgdten,rqvndgdten,rmundgdten,&
4734                SDA_HFX, SDA_QFX, QNORM, HFX_BOTH, QFX_BOTH, config_flags%fasdas,& ! fasdas
4735                HFX_FDDA,                                                        & ! fasdas
4736                config_flags%run_hours, &
4737                config_flags%if_no_pbl_nudging_uv, &
4738                config_flags%if_no_pbl_nudging_t, &
4739                config_flags%if_no_pbl_nudging_q, &
4740                config_flags%if_zfac_uv, &
4741                config_flags%k_zfac_uv, &
4742                config_flags%if_zfac_t, &
4743                config_flags%k_zfac_t, &
4744                config_flags%if_zfac_q, &
4745                config_flags%k_zfac_q, &
4746                config_flags%guv, &
4747                config_flags%gt, config_flags%gq, &
4748                config_flags%if_ramping, config_flags%dtramp_min, &
4749                config_flags%auxinput10_end_h, &
4750                config_flags%grid_sfdda, &
4751                config_flags%guv_sfc, &
4752                config_flags%gt_sfc, &
4753                config_flags%gq_sfc, &
4754                       restart, allowed_to_read,                    &
4755                       ids, ide, jds, jde, kds, kde,                &
4756                       ims, ime, jms, jme, kms, kme,                &
4757                       its, ite, jts, jte, kts, kte                 )
4759       CASE (SPNUDGING)
4760            CALL fddaspnudginginit(id,rundgdten,rvndgdten,rthndgdten,rphndgdten,rqvndgdten,&
4761                config_flags%run_hours, &
4762                config_flags%if_no_pbl_nudging_uv, &
4763                config_flags%if_no_pbl_nudging_t, &
4764                config_flags%if_no_pbl_nudging_ph, &
4765                config_flags%if_no_pbl_nudging_q, &
4766                config_flags%if_zfac_uv, &
4767                config_flags%k_zfac_uv, &
4768                config_flags%dk_zfac_uv, &
4769                config_flags%if_zfac_t, &
4770                config_flags%k_zfac_t, &
4771                config_flags%dk_zfac_t, &
4772                config_flags%if_zfac_ph, &
4773                config_flags%k_zfac_ph, &
4774                config_flags%dk_zfac_ph, &
4775                config_flags%if_zfac_q, &
4776                config_flags%k_zfac_q, &
4777                config_flags%dk_zfac_q, &
4778                config_flags%ktrop, &
4779                config_flags%guv, &
4780                config_flags%gt, config_flags%gph, config_flags%gq, &
4781                config_flags%if_ramping, config_flags%dtramp_min, &
4782                config_flags%auxinput9_end_h, &
4783                config_flags%xwavenum,config_flags%ywavenum, &
4784                       restart, allowed_to_read,                    &
4785                       ids, ide, jds, jde, kds, kde,                &
4786                       ims, ime, jms, jme, kms, kme,                &
4787                       its, ite, jts, jte, kts, kte                 )
4789       CASE DEFAULT
4791    END SELECT fdda_select
4793    END SUBROUTINE fg_init
4795 !-------------------------------------------------------------------
4796    SUBROUTINE fdob_init(obs_nudge_opt, maxdom, inest, parid,       &
4797                         idynin, dtramp, fdaend, restart,           &
4798                         obs_twindo_cg, obs_twindo, itimestep,      &
4799                         no_pbl_nudge_uv,                           &
4800                         no_pbl_nudge_t,                            &
4801                         no_pbl_nudge_q,                            &
4802                         sfc_scheme_horiz, sfc_scheme_vert,         &
4803                         maxsnd_gap,                                &
4804                         sfcfact, sfcfacr, dpsmx,                   &
4805                         nudge_wind, nudge_temp, nudge_mois,        &
4806                         nudgezfullr1_uv, nudgezrampr1_uv,          &
4807                         nudgezfullr2_uv, nudgezrampr2_uv,          &
4808                         nudgezfullr4_uv, nudgezrampr4_uv,          &
4809                         nudgezfullr1_t,  nudgezrampr1_t,           &
4810                         nudgezfullr2_t,  nudgezrampr2_t,           &
4811                         nudgezfullr4_t,  nudgezrampr4_t,           &
4812                         nudgezfullr1_q,  nudgezrampr1_q,           &
4813                         nudgezfullr2_q,  nudgezrampr2_q,           &
4814                         nudgezfullr4_q,  nudgezrampr4_q,           &
4815                         nudgezfullmin, nudgezrampmin, nudgezmax,   &
4816                         xlat, xlong,                               &
4817                         start_year, start_month, start_day,        &
4818                         start_hour, start_minute, start_second,    &
4819                         p00, t00, tlp,                             &
4820                         znu, p_top,                                &
4821                         fdob, ipf_init,                            &
4822                         ids, ide, jds, jde, kds, kde,              &
4823                         ims, ime, jms, jme, kms, kme,              &
4824                         its, ite, jts, jte, kts, kte               )
4826 !--------------------------------------------------------------------
4827    USE module_domain
4828    USE module_fddaobs_rtfdda
4829    USE module_llxy
4830 !--------------------------------------------------------------------
4831    IMPLICIT NONE
4832 !--------------------------------------------------------------------
4833    INTEGER , INTENT(IN)    :: maxdom
4834    INTEGER , INTENT(IN)    :: obs_nudge_opt(maxdom)
4835    INTEGER , INTENT(IN)    :: ids,ide, jds,jde, kds,kde,           &
4836                               ims,ime, jms,jme, kms,kme,           &
4837                               its,ite, jts,jte, kts,kte
4838    INTEGER , INTENT(IN)    :: inest
4839    INTEGER , INTENT(IN)    :: parid(maxdom)
4840    INTEGER , INTENT(IN)    :: idynin          ! flag for dynamic initialization
4841    REAL    , INTENT(IN)    :: dtramp          ! time period for ramping (idynin)
4842    REAL    , INTENT(IN)    :: fdaend(maxdom)  ! nudging end time for domain (min)
4843    LOGICAL , INTENT(IN)    :: restart
4844    REAL    , INTENT(IN)    :: obs_twindo_cg   ! twindo on course grid
4845    REAL    , INTENT(IN)    :: obs_twindo
4846    INTEGER , INTENT(IN)    :: itimestep
4847    INTEGER , INTENT(IN)    :: no_pbl_nudge_uv(maxdom)  ! flags for no wind nudging in pbl
4848    INTEGER , INTENT(IN)    :: no_pbl_nudge_t(maxdom)   ! flags for no temperature nudging in pbl
4849    INTEGER , INTENT(IN)    :: no_pbl_nudge_q(maxdom)   ! flags for no moisture nudging in pbl
4850    INTEGER , INTENT(IN)    :: sfc_scheme_horiz ! horizontal spreading scheme for surf obs (wrf or orig mm5)
4851    INTEGER , INTENT(IN)    :: sfc_scheme_vert  ! vertical   spreading scheme for surf obs (orig or regime vif)
4852    REAL    , INTENT(IN)    :: maxsnd_gap       ! max allowed pressure gap in soundings for interp (centibars) 
4853    REAL    , INTENT(IN)    :: sfcfact      ! scale factor applied to time window for surface obs
4854    REAL    , INTENT(IN)    :: sfcfacr      ! scale fac applied to horiz rad of infl for sfc obs
4855    REAL    , INTENT(IN)    :: dpsmx        ! max pressure change allowed within horiz. infl. range
4856    INTEGER , INTENT(IN)    :: nudge_wind(maxdom)       ! wind-nudging flag
4857    INTEGER , INTENT(IN)    :: nudge_temp(maxdom)       ! temperature-nudging flag
4858    INTEGER , INTENT(IN)    :: nudge_mois(maxdom)       ! moisture-nudging flag
4859    REAL    , INTENT(IN)    :: nudgezfullr1_uv  ! vert infl fcn, regime=1 full-wt   hght, winds
4860    REAL    , INTENT(IN)    :: nudgezrampr1_uv  ! vert infl fcn, regime=1 ramp down hght, winds
4861    REAL    , INTENT(IN)    :: nudgezfullr2_uv  ! vert infl fcn, regime=2 full-wt   hght, winds
4862    REAL    , INTENT(IN)    :: nudgezrampr2_uv  ! vert infl fcn, regime=2 ramp down hght, winds
4863    REAL    , INTENT(IN)    :: nudgezfullr4_uv  ! vert infl fcn, regime=4 full-wt   hght, winds
4864    REAL    , INTENT(IN)    :: nudgezrampr4_uv  ! vert infl fcn, regime=4 ramp down hght, winds
4865    REAL    , INTENT(IN)    :: nudgezfullr1_t   ! vert infl fcn, regime=1 full-wt   hght, temp
4866    REAL    , INTENT(IN)    :: nudgezrampr1_t   ! vert infl fcn, regime=1 ramp down hght, temp
4867    REAL    , INTENT(IN)    :: nudgezfullr2_t   ! vert infl fcn, regime=2 full-wt   hght, temp
4868    REAL    , INTENT(IN)    :: nudgezrampr2_t   ! vert infl fcn, regime=2 ramp down hght, temp
4869    REAL    , INTENT(IN)    :: nudgezfullr4_t   ! vert infl fcn, regime=4 full-wt   hght, temp
4870    REAL    , INTENT(IN)    :: nudgezrampr4_t   ! vert infl fcn, regime=4 ramp down hght, temp
4871    REAL    , INTENT(IN)    :: nudgezfullr1_q   ! vert infl fcn, regime=1 full-wt   hght, mois
4872    REAL    , INTENT(IN)    :: nudgezrampr1_q   ! vert infl fcn, regime=1 ramp down hght, mois
4873    REAL    , INTENT(IN)    :: nudgezfullr2_q   ! vert infl fcn, regime=2 full-wt   hght, mois
4874    REAL    , INTENT(IN)    :: nudgezrampr2_q   ! vert infl fcn, regime=2 ramp down hght, mois
4875    REAL    , INTENT(IN)    :: nudgezfullr4_q   ! vert infl fcn, regime=4 full-wt   hght, mois
4876    REAL    , INTENT(IN)    :: nudgezrampr4_q   ! vert infl fcn, regime=4 ramp down hght, mois
4877    REAL    , INTENT(IN)    :: nudgezfullmin    ! min dpth thru which vert infl fcn remains 1.0 (m)
4878    REAL    , INTENT(IN)    :: nudgezrampmin    ! min dpth thru which vif decreases 1.0 to 0.0 (m)
4879    REAL    , INTENT(IN)    :: nudgezmax        ! max dpth in which vif is nonzero (m)
4880    REAL    , INTENT(IN)    :: xlat ( ims:ime, jms:jme )        ! latitudes on mass-point grid
4881    REAL    , INTENT(IN)    :: xlong( ims:ime, jms:jme )        ! longitudes on mass-point grid
4882    INTEGER , INTENT(INOUT) :: start_year
4883    INTEGER , INTENT(INOUT) :: start_month
4884    INTEGER , INTENT(INOUT) :: start_day
4885    INTEGER , INTENT(INOUT) :: start_hour
4886    INTEGER , INTENT(INOUT) :: start_minute
4887    INTEGER , INTENT(INOUT) :: start_second
4888    REAL    , INTENT(IN)    :: p00                      ! base state pressure
4889    REAL    , INTENT(IN)    :: t00                      ! base state temperature
4890    REAL    , INTENT(IN)    :: tlp                      ! base state lapse rate
4891    REAL    , INTENT(IN)    :: znu( kms:kme )           ! eta values on half (mass) levels
4892    REAL    , INTENT(IN)    :: p_top                    ! pressure at top of model
4893    TYPE(fdob_type), INTENT(INOUT)  :: fdob
4895    INTEGER                 :: e_sn         ! ending   north-south grid index
4896    LOGICAL                 :: ipf_init     ! print warnings detected at initialzn
4897 !--------------------------------------------------------------------
4898 !-- initialize fdda obs-nudging scheme
4900       IF ( obs_nudge_opt(inest) .eq. 0 ) RETURN
4902       e_sn = jde
4903       CALL fddaobs_init(obs_nudge_opt, maxdom, inest, parid,       &
4904                         idynin, dtramp, fdaend, restart,           &
4905                         obs_twindo_cg,                             &
4906                         obs_twindo, itimestep,                     &
4907                         no_pbl_nudge_uv,                           &
4908                         no_pbl_nudge_t,                            &
4909                         no_pbl_nudge_q,                            &
4910                         sfc_scheme_horiz, sfc_scheme_vert,         &
4911                         maxsnd_gap,                                &
4912                         sfcfact, sfcfacr, dpsmx,                   &
4913                         nudge_wind, nudge_temp, nudge_mois,        &
4914                         nudgezfullr1_uv, nudgezrampr1_uv,          &
4915                         nudgezfullr2_uv, nudgezrampr2_uv,          &
4916                         nudgezfullr4_uv, nudgezrampr4_uv,          &
4917                         nudgezfullr1_t,  nudgezrampr1_t,           &
4918                         nudgezfullr2_t,  nudgezrampr2_t,           &
4919                         nudgezfullr4_t,  nudgezrampr4_t,           &
4920                         nudgezfullr1_q,  nudgezrampr1_q,           &
4921                         nudgezfullr2_q,  nudgezrampr2_q,           &
4922                         nudgezfullr4_q,  nudgezrampr4_q,           &
4923                         nudgezfullmin,  nudgezrampmin, nudgezmax,  &
4924                         xlat, xlong,                               &
4925                         start_year, start_month, start_day,        &
4926                         start_hour, start_minute, start_second,    &
4927                         p00, t00, tlp,                             &
4928                         znu, p_top,                                &
4929                         fdob, ipf_init,                            &
4930                         ids,ide, jds,jde, kds,kde,                 &
4931                         ims,ime, jms,jme, kms,kme,                 &
4932                         its,ite, jts,jte, kts,kte)
4934    END SUBROUTINE fdob_init
4935 #endif
4937 !--------------------------------------------------------------------
4938    SUBROUTINE z2sigma(zf,zh,sf,sh,p_top,pptop,config_flags, &
4939                 allowed_to_read , &
4940                 kds,kde,kms,kme,kts,kte)
4941    IMPLICIT NONE
4942 ! Arguments
4943    INTEGER, INTENT(IN) :: kds,kde,kms,kme,kts,kte
4944    REAL , DIMENSION( kms:kme ), INTENT(IN) :: zf,zh
4945    REAL , DIMENSION( kms:kme ), INTENT(OUT):: sf,sh
4946    REAL , INTENT(IN) :: p_top
4947    REAL , INTENT(OUT) :: pptop
4948    TYPE (grid_config_rec_type)              :: config_flags
4949    LOGICAL , INTENT(IN) :: allowed_to_read
4950 ! Local
4951    REAL R, G, TS, GAMMA, PS, ZTROP, TSTRAT, PTROP, Z, T, P, ZTOP, PTOP
4952    INTEGER K
4954    IF(zf(kde/2) .GT. 1.0)THEN
4955 ! Height levels assumed (zeta coordinate)
4956 ! Convert to sigma using standard atmosphere for pressure-height relation
4957 ! constants for standard atmosphere definition
4958       r=287.05
4959       g=9.80665
4960       ts=288.15
4961       gamma=-6.5/1000.
4962       ps=1013.25
4963       ztrop=11000.
4964       tstrat=ts+gamma*ztrop
4965       ptrop=ps*(tstrat/ts)**(-g/(gamma*r))
4967       do k=kde,kds,-1
4968 ! full levels
4969         z=zf(k)
4970         if(z.le.ztrop)then
4971           t=ts+gamma*z
4972           p=ps*(t/ts)**(-g/(gamma*r))
4973         else
4974           t=tstrat
4975           p=ptrop*exp(-g*(z-ztrop)/(r*tstrat))
4976         endif
4977         if(k.eq.kde)then
4978           ztop=zf(k)
4979           ptop=p
4980         endif
4981         sf(k)=(p-ptop)/(ps-ptop)
4982 ! half levels
4983         if(k.ne.kds)then
4984         z=0.5*(zf(k)+zf(k-1))
4985         if(z.le.ztrop)then
4986           t=ts+gamma*z
4987           p=ps*(t/ts)**(-g/(gamma*r))
4988         else
4989           t=tstrat
4990           p=ptrop*exp(-g*(z-ztrop)/(r*tstrat))
4991         endif
4992         sh(k-1)=(p-ptop)/(ps-ptop)
4993         endif
4994       enddo
4995       pptop=ptop/10.
4996    ELSE
4997 !  Levels are already sigma/eta
4998       do k=kde,kds,-1
4999 !        sf(k)=zf(kde-k+kds)
5000 !        if(k .ne. kde)sh(k)=zh(kde-1-k+kds)
5001          sf(k)=zf(k)
5002          if(k .ne. kde)sh(k)=zh(k)
5003       enddo
5004       pptop=p_top/1000.
5006    ENDIF
5008    END SUBROUTINE z2sigma
5010 !--------------------------------------------------------------------
5011    SUBROUTINE CAM_INIT (ixcldliq, ixcldice, ixnumliq, ixnumice,config_flags)
5012 !  Purpose: To initialize a set of variables and arrays required by 
5013 !           the CAM Parameterizations ported to WRF
5015 !  Called by: Phy_init
5017 !  Author:Balwinder.Singh@pnl.gov
5018 !--------------------------------------------------------------------
5019      USE shr_kind_mod,               ONLY : r8 => shr_kind_r8
5020      USE module_cam_esinti,          ONLY : esinti
5021      USE physconst,                  ONLY : mwh2o, cpwv, epsilo, latvap, latice &
5022           , rh2o, cpair, tmelt,mwdry
5023      USE constituents,               ONLY : cnst_add
5024      USE module_cam_support,         ONLY : pcnst =>pcnst_runtime, pcnst_mp
5025      USE modal_aero_initialize_data_phys, ONLY : modal_aero_initialize_phys
5026      
5027      implicit none
5029      TYPE (grid_config_rec_type)              :: config_flags
5031      integer, intent(out) :: ixcldliq, ixcldice, ixnumliq, ixnumice
5033      !Local variables
5034      !Following variable declarations are from CAM's stratiform.F90 module
5035      integer, parameter  :: ncnstmax = 4                    ! Number of constituents     
5036      integer             :: mm
5037      character(len=8), dimension(ncnstmax), parameter :: cnst_names = & 
5038           (/'CLDLIQ', 'CLDICE','NUMLIQ','NUMICE'/)         ! Constituent names
5039      !Variables with dummy values
5040      integer  :: dumind 
5041      real(r8) :: one
5043      !set dynamic (runtime)pcnst
5044      pcnst = 5                                               !For [water vap, cld liq, cld ice, liq num and ice num]
5045 #if ( EM_CORE == 1 )
5046      IF(config_flags%mp_physics == CAMMGMPSCHEME) pcnst = 12 !Additional storage for prescribed aerosols
5047 # endif
5049      !pcnst for microphysics (pcnst_mp is different from pcnst ONLY if CAM MAM package amd CAMMGMP schemes are decoupled)
5050      pcnst_mp = pcnst
5052 #if ( WRF_CHEM == 1 )
5053      !If CAM MAM package is selected
5054      !BSINGH (01/23/2014):Please make sure pcnst is equal to cam_mam_nspec in chem/module_cam_mam_init.F and registry.chem
5055      IF(config_flags%chem_opt == CBMZ_CAM_MAM3_NOAQ .OR. config_flags%chem_opt==CBMZ_CAM_MAM3_AQ) then
5056         pcnst = 85 !For 3 modes of aerosols [adjusted for DMS species-BSINGH (01/20/2014) suggested by PMA]
5057      else if(config_flags%chem_opt == CBMZ_CAM_MAM7_NOAQ .OR. config_flags%chem_opt == CBMZ_CAM_MAM7_AQ) then
5058         pcnst = 90 !For 7 modes of aerosols
5059      endif
5060      !If CAM MAM package is NOT selected then pcnst presumes its default value set above
5061      !*NOTE* : the value of pcnst is 'hardwired' here as it was a quick solution. The dynamic value
5062      !of pcnst is computed in module_cam_mam_init.F. In module_cam_mam_init.F, the value of PCNST set here
5063      !is tested for its accuracy. If the value computed in module_cam_mam_init.F differs from value mentioned
5064      !above, then the above values for pcnst should be adjusted accordingly
5066      !CAMMGMP Scheme is supposed to run with MODAL treatment of AEROSOLS only
5067      IF((config_flags%chem_opt .NE. CBMZ_CAM_MAM3_NOAQ .AND. config_flags%chem_opt .NE. CBMZ_CAM_MAM3_AQ &
5068           .AND. config_flags%chem_opt .NE. CBMZ_CAM_MAM7_NOAQ .AND. config_flags%chem_opt .NE. CBMZ_CAM_MAM7_AQ &
5069           .AND. config_flags%chem_opt .NE. 0) .AND. config_flags%mp_physics == CAMMGMPSCHEME) THEN
5070         call wrf_error_fatal('CAMMGMP (mp_physics=17) ONLY works with CAM MAM package (chem_opt =501,502,503 or 504)')
5071      ENDIF
5074      !For assisting decoupled microphysics (MP) CAM MAM simulations (simulations, where MAM package is coupled with 
5075      !radiation but uncoupled with MP- i.e. MP runs with 'prescribed' aerosols) 'pcnst_mp' is defined.'pcnst_mp' will
5076      !only be used in the CAMMGMP driver and its supporting modules (ndrop and microp_aero)
5077      pcnst_mp = pcnst
5078      if(.NOT.config_flags%CAM_MP_MAM_cpled)pcnst_mp = 12
5079 #endif
5081      ! Initialize the saturation vapor pressure look-up table...      
5082      call esinti(epsilo, latvap, latice, rh2o, cpair, tmelt)
5083      
5084      IF(.NOT.CAM_INITIALIZED) THEN
5085         
5086         !Allocate module level CAM arrays
5087         call ALLOCATE_CAM_ARRAYS()     
5088         
5089         !-------------------------------------------------------------------------------------!
5090         !Calls to add constituents (these calls are imported from in initindx.F90 in CAM)     !
5091         !                                                                                     !
5092         ! Register water vapor.                                                               !
5093         ! ** This must be the first call to cnst_add so that water vapor is constituent 1.**  !
5094         !-------------------------------------------------------------------------------------!
5095         
5096         call cnst_add('Q', mwh2o, cpwv, 1.E-12_r8, mm, &
5097              longname='Specific humidity', readiv=.true. )
5098         
5099         
5100         !Following add constituent calls are imported from the stratiform.F90 in CAM
5101         
5102         call cnst_add(cnst_names(1), mwdry, cpair, 0._r8, ixcldliq, &
5103              longname='Grid box averaged cloud liquid amount')
5104         call cnst_add(cnst_names(2), mwdry, cpair, 0._r8, ixcldice, &
5105              longname='Grid box averaged cloud ice amount'   )
5106         call cnst_add(cnst_names(3), mwdry, cpair, 0._r8, ixnumliq, &
5107              longname='Grid box averaged cloud liquid number')
5108         call cnst_add(cnst_names(4), mwdry, cpair, 0._r8, ixnumice, &
5109              longname='Grid box averaged cloud ice number'   )
5111         !For prescribed aerosols
5112 #if ( EM_CORE == 1 )
5113         IF(config_flags%mp_physics .EQ. CAMMGMPSCHEME &
5114 #if ( WRF_CHEM == 1 )
5115              .AND.  config_flags%chem_opt .EQ. 0    &
5116 #endif
5117              )THEN
5118            one = 1.0_r8
5119            call cnst_add('ACCUM_MASS', one, cpair, 0._r8, dumind, &
5120                 longname='Grid box averaged accumulation mode mass')
5121            call cnst_add('ACCUM_NUM' , one, cpair, 0._r8, dumind, &
5122                 longname='Grid box averaged accumulation mode number')
5123            call cnst_add('AITKEN_MASS', one, cpair, 0._r8, dumind, &
5124                 longname='Grid box averaged aitken mode mass')
5125            call cnst_add('AITKEN_NUM' , one, cpair, 0._r8, dumind, &
5126                 longname='Grid box averaged aitken mode number')
5127            call cnst_add('COARSE_MASS_1', one, cpair, 0._r8, dumind, &
5128                 longname='Grid box averaged coarse mode1 mass')
5129            call cnst_add('COARSE_MASS_2', one, cpair, 0._r8, dumind, &
5130                 longname='Grid box averaged coarse mode2 mass')
5131            call cnst_add('COARSE_NUM' , one, cpair, 0._r8, dumind, &
5132                 longname='Grid box averaged coarse mode number')
5133            
5134         ENDIF
5135 #endif
5136         
5137         CAM_INITIALIZED = .TRUE.
5138      ENDIF
5139      
5140 #if ( EM_CORE == 1 )
5141      IF(config_flags%mp_physics == CAMMGMPSCHEME)THEN
5142 #if ( WRF_CHEM != 1 )
5143         !Aerosols must be initialized after adding the constituents otherwise the code may crash in WRF-Chem simulations     
5144         CALL modal_aero_initialize_phys
5145 #else
5146         if(config_flags%chem_opt==0) then
5147            CALL modal_aero_initialize_phys
5148         endif
5149 #endif
5150      ENDIF
5151 #endif
5152    END SUBROUTINE CAM_INIT
5155 !--------------------------------------------------------------------
5156  SUBROUTINE ALLOCATE_CAM_ARRAYS ()
5157 !  Purpose: To allocate module level CAM arrays for CAM modules which
5158 !           doesn't have an 'initialization' subroutine
5160 !  Called by: CAM_INIT
5162 !  Author:Balwinder.Singh@pnl.gov
5163 !--------------------------------------------------------------------
5164    USE constituents,         ONLY : cnst_name,cnst_longname,cnst_cp,&
5165         cnst_cv,cnst_mw,cnst_type,cnst_rgas,qmin,qmincg,            &
5166         cnst_fixed_ubc,apcnst,bpcnst,hadvnam,vadvnam,dcconnam,      &
5167         fixcnam,tendnam,ptendnam,dmetendnam,sflxnam,tottnam  
5169    USE module_cam_support,   ONLY : pcnst =>pcnst_runtime, pcnst_mp
5171    USE modal_aero_data,      ONLY : cnst_name_cw,species_class,     &
5172         qneg3_worst_thresh_amode,cnst_name_cw_mp
5174    implicit none
5176    !Allocate module_cam_constituents.F arrays
5177    Allocate(cnst_name(pcnst),cnst_longname(pcnst),cnst_cp(pcnst),   &
5178         cnst_cv(pcnst),cnst_mw(pcnst),cnst_type(pcnst),             &
5179         cnst_rgas(pcnst),qmin(pcnst),qmincg(pcnst),                 &
5180         cnst_fixed_ubc(pcnst),apcnst(pcnst),bpcnst(pcnst),          &
5181         hadvnam(pcnst),vadvnam(pcnst),dcconnam(pcnst),              &
5182         fixcnam(pcnst),tendnam(pcnst),ptendnam(pcnst),              &
5183         dmetendnam(pcnst),sflxnam(pcnst),tottnam(pcnst)             )
5185    !Initialize module_cam_constituents.F variables
5186    cnst_fixed_ubc(:) = .false.
5188    !Allocate module_cam_mp_modal_aero_data_phys.F arrays
5189    Allocate(cnst_name_cw(pcnst),cnst_name_cw_mp(pcnst_mp),          &
5190         species_class(pcnst),qneg3_worst_thresh_amode(pcnst)        )
5191    
5192  END SUBROUTINE ALLOCATE_CAM_ARRAYS
5194 subroutine aerosol_in(aerodm,pina,alevsiz,no_months,no_src_types,XLAT,XLONG,   &
5195                      ids, ide, jds, jde, kds, kde,                  &
5196                      ims, ime, jms, jme, kms, kme,                  &
5197                      its, ite, jts, jte, kts, kte)
5199 ! Adaped from oznini in CAM 
5200 ! It should be replaced by monthly climatology that varies latitudinally and vertically
5202    IMPLICIT NONE
5204    INTEGER,      INTENT(IN   )    ::   ids,ide, jds,jde, kds,kde, &
5205                                        ims,ime, jms,jme, kms,kme, &
5206                                        its,ite, jts,jte, kts,kte   
5208    INTEGER,      INTENT(IN   )    ::   alevsiz, no_months, no_src_types
5210    REAL,  DIMENSION( ims:ime, jms:jme ), INTENT(IN   )  ::     XLAT, XLONG
5212    REAL,  DIMENSION( ims:ime, alevsiz, jms:jme, no_months, no_src_types ),      &
5213           INTENT(OUT   ) ::                                  aerodm
5215    REAL,  DIMENSION(alevsiz), INTENT(OUT )  ::                   pina
5217 ! Local
5218 !  Data from Ryan Torn, computed from EC 6 types of aerosol data:
5219 !    organic carbon, sea salt, dust, black carbon, sulfalte 
5220 !    and stratospheric aerosol (volcanic ashes)
5221 !  The data dimensions are 46 x 72 x 12 (pressure levels), and in unit of AOD per Pa
5223    INTEGER, PARAMETER :: latsiz = 46
5224    INTEGER, PARAMETER :: lonsiz = 72
5225    INTEGER :: i, j, k, itf, jtf, ktf, m, pin_unit, lat_unit, lon_unit, od_unit, ks, il, jl
5226    INTEGER :: ilon1, ilon2, jlat1, jlat2
5227    REAL    :: interp_pt, interp_pt_lat, interp_pt_lon, wlat1, wlat2, wlon1, wlon2
5228    CHARACTER*256 :: message
5230    REAL,  DIMENSION( lonsiz, alevsiz, latsiz, no_months, no_src_types )    ::   &
5231                                                             aerodin
5233    REAL,  DIMENSION(latsiz)                ::             lat_od, aertmp1
5234    REAL,  DIMENSION(lonsiz)                ::             lon_od, aertmp2
5236    jtf=min0(jte,jde-1)
5237    ktf=min0(kte,kde-1)
5238    itf=min0(ite,ide-1)
5240 !-- read in aerosol optical depth pressure data
5242      WRITE(message,*)'no_months = ',no_months
5243      CALL wrf_debug(1,message)
5245 ! pressure in mb
5246       pin_unit = 27
5247         OPEN(pin_unit, FILE='aerosol_plev.formatted',FORM='FORMATTED',STATUS='OLD')
5248         do k = 1,alevsiz
5249         READ (pin_unit,*) pina(k)
5250         end do
5251       close(27)
5253 !     do k=1,alevsiz
5254 !       pina(k) = pina(k)*100.
5255 !     end do
5257 !-- read in aerosol optical depth lat data
5259       lat_unit = 28
5260         OPEN(lat_unit, FILE='aerosol_lat.formatted',FORM='FORMATTED',STATUS='OLD')
5261         do j = 1,latsiz
5262         READ (lat_unit,*) lat_od(j)
5263         end do
5264       close(28)
5266 !-- read in aerosol optical depth lon data
5268       lon_unit = 29
5269         OPEN(lon_unit, FILE='aerosol_lon.formatted',FORM='FORMATTED',STATUS='OLD')
5270         do j = 1,lonsiz
5271         READ (lon_unit,*) lon_od(j)
5272         end do
5273       close(29)
5275 !-- read in ozone data
5277       od_unit = 30
5278       OPEN(od_unit, FILE='aerosol.formatted',FORM='FORMATTED',STATUS='OLD')
5280       do ks=1,no_src_types
5281       do m=1,no_months
5282       do j=1,latsiz  ! latsiz=46
5283       do k=1,alevsiz ! alevsiz=12
5284       do i=1,lonsiz  ! lonsiz=72
5285          READ (od_unit,*) aerodin(i,k,j,m,ks)
5286       enddo
5287       enddo
5288       enddo
5289       enddo
5290       enddo
5291       close(30)
5293 !-- latitudinally interpolate ozone data (and extend longitudinally)
5294 !-- using function lin_interpol2(x, f, y) result(g)
5295 ! Purpose:
5296 !   interpolates f(x) to point y
5297 !   assuming f(x) = f(x0) + a * (x - x0)
5298 !   where a = ( f(x1) - f(x0) ) / (x1 - x0)
5299 !   x0 <= x <= x1
5300 !   assumes x is monotonically increasing
5301 !    real, intent(in), dimension(:) :: x  ! grid points
5302 !    real, intent(in), dimension(:) :: f  ! grid function values
5303 !    real, intent(in) :: y                ! interpolation point
5304 !    real :: g                            ! interpolated function value
5305 !---------------------------------------------------------------------------
5307       do j=jts,jtf
5308       do i=its,itf
5309         interp_pt_lat=XLAT(i,j)
5310         interp_pt_lon=XLONG(i,j)
5311         call interp_vec(lat_od,interp_pt_lat,.true.,jlat1,jlat2,wlat1,wlat2)
5312         call interp_vec(lon_od,interp_pt_lon,.true.,ilon1,ilon2,wlon1,wlon2)
5314         do ks = 1,no_src_types
5315         do m  = 1,no_months
5316         do k  = 1,alevsiz
5317           aerodm(i,k,j,m,ks) = wlon1 * (wlat1 * aerodin(ilon1,k,jlat1,m,ks)  + &
5318                                         wlat2 * aerodin(ilon1,k,jlat2,m,ks)) + &
5319                                wlon2 * (wlat1 * aerodin(ilon2,k,jlat1,m,ks)  + &
5320                                         wlat2 * aerodin(ilon2,k,jlat2,m,ks))
5321         end do
5322         end do
5323         end do
5325       end do
5326       end do
5328 !     do j=jts,jtf
5329 !     do i=its,itf
5330 !        onefld(i,j) = aerodm(i,12,j,1,1)
5331 !     enddo
5332 !     enddo
5334 END SUBROUTINE aerosol_in
5336   function lin_interp(x, f, y) result(g)
5338     ! Purpose:
5339     !   interpolates f(x) to point y
5340     !   assuming f(x) = f(x0) + a * (x - x0)
5341     !   where a = ( f(x1) - f(x0) ) / (x1 - x0)
5342     !   x0 <= x <= x1
5343     !   assumes x is monotonically increasing
5345     ! Author: D. Fillmore ::  J. Done changed from r8 to r4
5347     implicit none
5349     real, intent(in), dimension(:) :: x  ! grid points
5350     real, intent(in), dimension(:) :: f  ! grid function values
5351     real, intent(in) :: y                ! interpolation point
5352     real :: g                            ! interpolated function value
5354     integer :: k  ! interpolation point index
5355     integer :: n  ! length of x
5356     real    :: a
5358     n = size(x)
5360     ! find k such that x(k) < y =< x(k+1)
5361     ! set k = 1 if y <= x(1)  and  k = n-1 if y > x(n)
5363     if (y <= x(1)) then
5364       k = 1
5365     else if (y >= x(n)) then
5366       k = n - 1
5367     else
5368       k = 1
5369       do while (y > x(k+1) .and. k < n)
5370         k = k + 1
5371       end do
5372     end if
5374     ! interpolate
5375     a = (  f(k+1) - f(k) ) / ( x(k+1) - x(k) )
5376     g = f(k) + a * (y - x(k))
5378   end function lin_interp
5380   subroutine interp_vec(locvec,locwant,periodic,loc1,loc2,wght1,wght2)
5382   implicit none
5384   real, intent(in), dimension(:) :: locvec
5385   real, intent(in)               :: locwant
5386   logical, intent(in)            :: periodic
5387   integer, intent(out)           :: loc1, loc2
5388   real, intent(out)              :: wght1, wght2
5390   integer :: vsize, n
5391   real    :: locv1, locv2
5393   vsize = size(locvec)
5395   loc1 = -1
5396   loc2 = -1
5398   do n = 1, vsize-1
5399     if ( locvec(n) <= locwant .and. locvec(n+1) > locwant ) then
5400       loc1  = n
5401       loc2  = n+1
5402       locv1 = locvec(n)
5403       locv2 = locvec(n+1)
5404       exit
5405     end if
5406   end do
5408   if ( loc1 < 0 .and. loc2 < 0 ) then
5409     if ( periodic ) then
5410       if ( locwant < locvec(1) ) then
5411         loc1  = vsize
5412         loc2  = 1
5413         locv1 = locvec(vsize)-360.0
5414         locv2 = locvec(1)
5415       else
5416         loc1  = vsize
5417         loc2  = 1
5418         locv1 = locvec(vsize)
5419         locv2 = locvec(1)+360.0
5420       end if
5421     else
5422       if ( locwant < locvec(1) ) then
5423         loc1  = 1
5424         loc2  = 1
5425         locv1 = locvec(1)
5426         locv2 = locvec(1)
5427       else
5428         loc1  = vsize
5429         loc2  = vsize
5430         locv1 = locvec(vsize)
5431         locv2 = locvec(vsize)
5432       end if
5433     end if
5434   end if
5436   wght2 = (locwant-locv1) / (locv2-locv1)
5437   wght1 = 1.0 - wght2
5439   return
5440   end subroutine interp_vec
5442 !!--------------------START   PSH/TWG   CHANGES-----------------------
5443 !--------------------INPUT FOR AEROSOL DATA---------------------------
5444 subroutine aerosol_in_cu(aeromcu,alevsiz,no_months,no_src_types,XLAT,XLONG,aeropcu, &
5445                      ids, ide, jds, jde, kds, kde,                  &
5446                      ims, ime, jms, jme, kms, kme,                  &
5447                      its, ite, jts, jte, kts, kte)
5449 ! This module was taken from the radiation driver and modified for the
5450 ! cumulus aerosol input. - PSH
5452    IMPLICIT NONE
5454    INTEGER,      INTENT(IN   )    ::   ids,ide, jds,jde, kds,kde, &
5455                                        ims,ime, jms,jme, kms,kme, &
5456                                        its,ite, jts,jte, kts,kte
5458    INTEGER,      INTENT(IN   )    ::   alevsiz, no_months, no_src_types
5460    REAL,  DIMENSION( ims:ime, jms:jme ), INTENT(IN   )  ::     XLAT, XLONG
5462    INTEGER :: i, j, k, itf, jtf, ktf, m, pin_unit, lat_unit,lon_unit,od_unit,ks,il, jl
5463    INTEGER :: ilon1cu, ilon2cu, jlat1cu, jlat2cu
5464    REAL    :: interp_ptcu, interp_pt_latcu, interp_pt_loncu,wlat1cu,wlat2cu,wlon1cu,wlon2cu
5465    CHARACTER*256 :: message
5467    integer                               :: numLons, numLats, numLevs
5469    REAL,  DIMENSION( ims:ime, alevsiz, jms:jme, no_months, no_src_types ),&
5470           INTENT(OUT   ) ::                                  aeromcu !PSH
5471    REAL,  DIMENSION( ims:ime, alevsiz, jms:jme, no_months), OPTIONAL, &
5472    INTENT(OUT)  :: aeropcu !PSH
5473    real, dimension(:, :, :, :, :), allocatable  :: aeroin !PSH
5474    real, dimension(:, :, :, :), allocatable  :: aeropin !PSH
5475    CHARACTER (len=10), dimension(no_src_types) :: species !PSH
5476    CHARACTER (len=100) :: fname !PSH
5477    CHARACTER (len=8) :: frmt !PSH
5478    CHARACTER (len=2) :: mons !PSH
5479    integer :: v, mi !PSH
5480    REAL, dimension(:), ALLOCATABLE :: lon_aer, lat_aer !, lev_aer !PSH
5481    LOGICAL           :: exists
5482    INTEGER, EXTERNAL :: get_unused_unit
5483    LOGICAL, EXTERNAL :: wrf_dm_on_monitor
5484    INTEGER :: istatus, iunit
5485    jtf=min0(jte,jde-1)
5486    ktf=min0(kte,kde-1)
5487    itf=min0(ite,ide-1)
5489 ! - - - - SPECIES OF INTEREST - - - - -
5490    species = (/"DUST1   ","DUST2   ","DUST3   ","DUST4   ","SEASALT2", &
5491                "SULFATE ","BCPHO   ","BCPHI   ","OCPHO   ","OCPHI   "/)
5492    frmt = '(I0.2)'
5494       INQUIRE(FILE='./CESM_RCP4.5_Aerosol_Data.dat', EXIST=exists)
5496       IF (exists) THEN
5497           iunit = get_unused_unit()
5498           IF ( iunit <= 0 ) THEN
5499              IF ( wrf_dm_on_monitor() ) THEN
5500                 CALL wrf_error_fatal('Error in aerosol_in_cu: could not find a free Fortran unit.')
5501              END IF
5502           END IF
5504           ! Read aerosol information 
5505           OPEN(UNIT=iunit, FILE='CESM_RCP4.5_Aerosol_Data.dat', FORM='unformatted', &
5506                STATUS='old', IOSTAT=istatus)
5507             IF (istatus == 0) THEN
5508                READ(UNIT=iunit)  numLons, numLats,numLevs
5509                allocate(aeroin(numLons, numLats, numLevs, no_months, no_src_types))
5510                allocate(aeropin(numLons, numLats, numLevs, no_months))
5511                allocate(lon_aer(numLons))
5512                allocate(lat_aer(numLats))
5513                READ(UNIT=iunit)  lat_aer
5514                READ(UNIT=iunit)  lon_aer
5515                READ(UNIT=iunit)  aeropin
5516                READ(UNIT=iunit)  aeroin
5517             ELSE
5518                CALL wrf_error_fatal('Unable to open file "CESM_RCP4.5_Aerosol_Data.dat" (required for aercu_opt = 1 or 2). ' // &
5519                   'Please refer to the run/README.namelist file for more information.')
5520             END IF
5521           CLOSE(iunit)
5522       ELSE
5523           CALL wrf_error_fatal('Missing file "CESM_RCP4.5_Aerosol_Data.dat" (required for aercu_opt = 1 or 2). ' // &
5524               'Please refer to the run/README.namelist file for more information.')
5525       END IF
5526 !---------------------------------------------------------------------------
5527 !-- latitudinally interpolate ozone data (and extend longitudinally)
5528 !-- using function lin_interpol2(x, f, y) result(g)
5529 ! Purpose:
5530 !   interpolates f(x) to point y
5531 !   assuming f(x) = f(x0) + a * (x - x0)
5532 !   where a = ( f(x1) - f(x0) ) / (x1 - x0)
5533 !   x0 <= x <= x1
5534 !   assumes x is monotonically increasing
5535 !    real, intent(in), dimension(:) :: x  ! grid points
5536 !    real, intent(in), dimension(:) :: f  ! grid function values
5537 !    real, intent(in) :: y                ! interpolation point
5538 !    real :: g                            ! interpolated function value
5539 !---------------------------------------------------------------------------
5541       do j=jts,jtf
5542       do i=its,itf
5543         interp_pt_latcu=XLAT(i,j)
5544         interp_pt_loncu=XLONG(i,j)
5545         call interp_vec_cu(lat_aer,interp_pt_latcu,.true.,jlat1cu,jlat2cu,wlat1cu,wlat2cu)
5546         call interp_vec_cu(lon_aer,interp_pt_loncu,.true.,ilon1cu,ilon2cu,wlon1cu,wlon2cu)
5548         do m  = 1,no_months
5549         do k  = 1,alevsiz
5550           aeropcu(i,k,j,m) = wlon1cu * (wlat1cu * aeropin(ilon1cu,jlat1cu,k,m)+&
5551                                            wlat2cu*aeropin(ilon1cu,jlat2cu,k,m))+&
5552                                 wlon2cu * (wlat1cu*aeropin(ilon2cu,jlat1cu,k,m)+&
5553                                            wlat2cu*aeropin(ilon2cu,jlat2cu,k,m))
5554         do ks = 1,no_src_types
5555           aeromcu(i,k,j,m,ks) = wlon1cu * (wlat1cu*aeroin(ilon1cu,jlat1cu,k,m,ks)  + &
5556                                            wlat2cu*aeroin(ilon1cu,jlat2cu,k,m,ks))+ &
5557                                 wlon2cu * (wlat1cu*aeroin(ilon2cu,jlat1cu,k,m,ks)  + &
5558                                            wlat2cu*aeroin(ilon2cu,jlat2cu,k,m,ks))
5560         end do
5561         end do
5562         end do
5563       end do
5564       end do
5566 END SUBROUTINE aerosol_in_cu
5568 subroutine interp_vec_cu(locvec,locwant,periodic,loc1,loc2,wght1,wght2)
5569 ! This subroutine was taken and modified from the radiation driver. -PSH
5570   implicit none
5572   real, intent(in), dimension(:) :: locvec
5573   real, intent(in)               :: locwant
5574   logical, intent(in)            :: periodic
5575   integer, intent(out)           :: loc1, loc2
5576   real, intent(out)              :: wght1, wght2
5578   integer :: vsize, n
5579   real    :: locv1, locv2
5581   vsize = size(locvec)
5583   loc1 = -1
5584   loc2 = -1
5586   do n = 1, vsize-1
5587     if ( locvec(n) <= locwant .and. locvec(n+1) > locwant ) then
5588       loc1  = n
5589       loc2  = n+1
5590       locv1 = locvec(n)
5591       locv2 = locvec(n+1)
5592       exit
5593     end if
5594   end do
5596   if ( loc1 < 0 .and. loc2 < 0 ) then
5597     if ( periodic ) then
5598       if ( locwant < locvec(1) ) then
5599         loc1  = vsize
5600         loc2  = 1
5601         locv1 = locvec(vsize)-360.0
5602         locv2 = locvec(1)
5603       else
5604         loc1  = vsize
5605         loc2  = 1
5606         locv1 = locvec(vsize)
5607         locv2 = locvec(1)+360.0
5608       end if
5609     else
5610       if ( locwant < locvec(1) ) then
5611         loc1  = 1
5612         loc2  = 1
5613         locv1 = locvec(1)
5614         locv2 = locvec(1)
5615       else
5616         loc1  = vsize
5617         loc2  = vsize
5618         locv1 = locvec(vsize)
5619         locv2 = locvec(vsize)
5620       end if
5621     end if
5622   end if
5624   wght2 = (locwant-locv1) / (locv2-locv1)
5625   wght1 = 1.0 - wght2
5627   return
5628   end subroutine interp_vec_cu
5629 !---------------------END   PSH/TWG  CHANGES----------------
5631   subroutine compute_2d_dx_area(dx, dy, msftx, msfty, dx2d, area2d, &
5632                                 ids, ide, jds, jde, kds, kde,       &
5633                                 ims, ime, jms, jme, kms, kme,       &
5634                                 its, ite, jts, jte, kts, kte)
5636      implicit none
5638      integer , intent(in) :: ids, ide, jds, jde, kds, kde,       &
5639                              ims, ime, jms, jme, kms, kme,       &
5640                              its, ite, jts, jte, kts, kte
5642      real,                             intent(in)  :: dx, dy
5643      real, dimension(ims:ime,jms:jme), intent(in)  :: msftx, msfty
5644      real, dimension(ims:ime,jms:jme), intent(out) :: dx2d, area2d
5646      integer :: i, j
5648 #if 0
5649      do j = jts, min(jde-1,jte)
5650         do i = its, min(ide-1,ite)
5651            area2d(i,j) = dx/msftx(i,j) * dy/msfty(i,j)
5652            dx2d  (i,j) = sqrt ( area2d(i,j) )
5653         end do
5654      end do
5655 #else
5656      do j = jts, min(jde-1,jte)
5657         do i = its, min(ide-1,ite)
5658            area2d(i,j) = dx * dy
5659            dx2d  (i,j) = dx
5660         end do
5661      end do
5662 #endif
5664   end subroutine compute_2d_dx_area
5666   SUBROUTINE shalwater_init(ims,ime,jms,jme,                     &
5667                              its,ite,jts,jte,                    &
5668                              bathymetry_flag, shalwater_z0,      &
5669                              shalwater_depth, water_depth,       &
5670                              xland,LakeModel,lake_depth,lakemask )
5672    INTEGER, INTENT(IN)      ::   ims,ime,jms,jme,its,ite,jts,jte
5673    INTEGER, INTENT(IN)      ::   shalwater_z0
5674    REAL,    INTENT(IN)      ::   shalwater_depth
5675    INTEGER, INTENT(IN)      ::   bathymetry_flag
5676    REAL,    DIMENSION( ims:ime, jms:jme ), INTENT(INOUT)    ::  water_depth
5677    REAL,    DIMENSION( ims:ime, jms:jme ), INTENT(IN   )    ::  xland
5678    INTEGER         ::     LakeModel
5679    REAL,    DIMENSION( ims:ime, jms:jme ), INTENT(IN   )    ::  lake_depth
5680    REAL,    DIMENSION( ims:ime, jms:jme )                   ::  lakemask
5681                
5682    ! Local  
5683    LOGICAL :: overwrite_water_depth
5684    overwrite_water_depth = .False.
5685    
5686    IF ( bathymetry_flag .eq. 1 ) THEN
5687       IF ( shalwater_depth .LE. 0.0 ) THEN
5688          IF ( LakeModel .ge. 1 ) THEN
5690             DO j = jts,jte
5691                DO i = its,ite
5692                   IF ( lakemask(i,j) .EQ. 1 ) THEN
5693                      water_depth(i,j) = lake_depth(i,j)
5694                   END IF
5695                END DO
5696             END DO
5697          END IF
5698       ELSE
5699          overwrite_water_depth = .True.
5700       END IF
5701    ELSE
5702       IF ( shalwater_depth .GT. 0.0 ) THEN
5703          overwrite_water_depth = .True.
5704       ELSE
5705          CALL wrf_error_fatal('No bathymetry data detected and shalwater_depth not greater than 0.0. Re-run WPS to get bathymetry data or set shalwater_depth > 0.0')
5706       END IF
5707    END IF
5709    IF (overwrite_water_depth) THEN
5710       DO j = jts,jte
5711          DO i = its,ite
5712             IF((XLAND(i,j)-1.5).GE.0)THEN
5713                water_depth(i,j) = shalwater_depth
5714             ELSE
5715                water_depth(i,j) = -2.0
5716             END IF
5717          END DO
5718       END DO
5719    END IF
5721   END SUBROUTINE shalwater_init
5723 END MODULE module_physics_init