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