GFS Operational Physics Documentation  gsm/branches/DTC/phys-doc-all phys-doc-all R82971
gbphys.f
Go to the documentation of this file.
1 
2 
6 !at tune step========================================================= !
7 ! description: !
8 !
9 ! !
10 ! usage: !
11 ! !
12 ! call gbphys !
13 ! inputs: !
14 ! ( im,ix,levs,lsoil,lsm,ntrac,ncld,ntoz,ntcw,ntke, !
15 ! ntiw,ntlnc,ntinc, !
16 ! nmtvr,nrcm,ko3,lonr,latr,jcap, !
17 ! num_p3d,num_p2d,npdf3d,ncnvcld3d, !
18 ! kdt,lat,me,pl_coeff,nlons,ncw,flgmin,crtrh,cdmbgwd, !
19 ! ccwf,dlqf,ctei_rm,clstp,cgwf,prslrd0,ral_ts,dtp,dtf,fhour, !
20 ! solhr,slag,sdec,cdec,sinlat,coslat,pgr,ugrs,vgrs, !
21 ! tgrs,qgrs,vvel,prsi,prsl,prslk,prsik,phii,phil, !
22 ! rann,prdoz,poz,dpshc,hprime,xlon,xlat, !
23 ! h2o_phys,levh2o,h2opl,h2o_pres,h2o_coeff, !
24 ! isot,ivegsrc, !
25 ! slope,shdmin,shdmax,snoalb,tg3,slmsk,vfrac, !
26 ! vtype,stype,uustar,oro,oro_uf,coszen,sfcdsw,sfcnsw, !
27 ! sfcnirbmd,sfcnirdfd,sfcvisbmd,sfcvisdfd, !
28 ! sfcnirbmu,sfcnirdfu,sfcvisbmu,sfcvisdfu, !
29 ! slimskin_cpl,ulwsfcin_cpl, !
30 ! dusfcin_cpl,dvsfcin_cpl,dtsfcin_cpl,dqsfcin_cpl, !
31 ! sfcdlw,tsflw,sfcemis,sfalb,swh,swhc,hlw,hlwc,hlwd,lsidea, !
32 ! ras,pre_rad,ldiag3d,lgocart,lssav,lssav_cpl !
33 ! xkzm_m,xkzm_h,xkzm_s,psautco,prautco,evpco,wminco, !
34 ! pdfcld,shcnvcw,sup,redrag,hybedmf,dspheat, !
35 ! flipv,old_monin,cnvgwd,shal_cnv, !
36 ! imfshalcnv,imfdeepcnv,cal_pre,aero_in, !
37 ! mom4ice,mstrat,trans_trac,nstf_name,moist_adj, !
38 ! thermodyn_id, sfcpress_id, gen_coord_hybrid,levr,adjtrc,nnp,!
39 ! cscnv,nctp,do_shoc,shocaftcnv,ntot3d,ntot2d, !
40 ! input/outputs: !
41 ! hice,fice,tisfc,tsea,tprcp,cv,cvb,cvt, !
42 ! srflag,snwdph,weasd,sncovr,zorl,canopy, !
43 ! ffmm,ffhh,f10m,srunoff,evbsa,evcwa,snohfa, !
44 ! transa,sbsnoa,snowca,soilm,tmpmin,tmpmax, !
45 ! dusfc,dvsfc,dtsfc,dqsfc,totprcp,gflux, !
46 ! dlwsfc,ulwsfc,suntim,runoff,ep,cldwrk, !
47 ! dugwd,dvgwd,psmean,cnvprcp,spfhmin,spfhmax,rain,rainc, !
48 ! dt3dt,dq3dt,du3dt,dv3dt,dqdt_v,cnvqc_v,acv,acvb,acvt, !
49 ! slc,smc,stc,upd_mf,dwn_mf,det_mf,phy_f3d,phy_f2d, !
50 ! dusfc_cpl, dvsfc_cpl, dtsfc_cpl, dqsfc_cpl, !
51 ! dlwsfc_cpl,dswsfc_cpl,dnirbm_cpl,dnirdf_cpl, !
52 ! dvisbm_cpl,dvisdf_cpl,rain_cpl, nlwsfc_cpl,nswsfc_cpl, !
53 ! nnirbm_cpl,nnirdf_cpl,nvisbm_cpl,nvisdf_cpl,snow_cpl, !
54 ! xt,xs,xu,xv,xz,zm,xtts,xzts,d_conv,ifd,dt_cool,Qrain, !
55 ! phy_fctd, !
56 ! outputs: !
57 ! gt0,gq0,gu0,gv0,t2m,q2m,u10m,v10m, !
58 ! zlvl,psurf,hpbl,pwat,t1,q1,u1,v1, !
59 ! chh,cmm,dlwsfci,ulwsfci,dswsfci,uswsfci,dusfci,dvsfci, !
60 ! dtsfci,dqsfci,gfluxi,epi,smcwlt2,smcref2,wet1, !
61 ! dusfci_cpl,dvsfci_cpl,dtsfci_cpl,dqsfci_cpl, !
62 ! dlwsfci_cpl,dswsfci_cpl, !
63 ! dnirbmi_cpl,dnirdfi_cpl,dvisbmi_cpl,dvisdfi_cpl, !
64 ! nlwsfci_cpl,nswsfci_cpl, !
65 ! nnirbmi_cpl,nnirdfi_cpl,nvisbmi_cpl,nvisdfi_cpl, !
66 ! t2mi_cpl,q2mi_cpl, !
67 ! u10mi_cpl,v10mi_cpl,tseai_cpl,psurfi_cpl, !
68 ! tref, z_c, c_0, c_d, w_0, w_d, rqtk, !
69 ! hlwd,lsidea ) !
70 ! !
71 ! subprograms called: !
72 ! !
73 ! get_prs, dcyc2t2_pre_rad (testing), dcyc2t3, sfc_diff, !
74 ! sfc_ocean,sfc_drv, sfc_land, sfc_sice, sfc_diag, moninp1, !
75 ! moninp, moninq1, moninq, gwdps, ozphys, get_phi, !
76 ! sascnv, sascnvn, rascnv, cs_convr, gwdc, shalcvt3,shalcv,!
77 ! shalcnv, cnvc90, lrgscl, gsmdrive, gscond, precpd, !
78 ! progt2. !
79 ! !
80 ! !
81 ! program history log: !
82 ! 19xx - ncep mrf/gfs !
83 ! 2002 - s. moorthi modify and restructure and add Ferrier !
84 ! microphysics as an option !
85 ! 200x - h. juang modify (what?) !
86 ! nov 2004 - x. wu modify sea-ice model !
87 ! may 2005 - s. moorthi modify and restructure !
88 ! 2005 - s. lu modify to include noah lsm !
89 ! oct 2006 - h. wei modify lsm options to include both !
90 ! noah and osu lsms. !
91 ! 2006 - s. moorthi added a. johansson's convective gravity !
92 ! wave parameterization code !
93 ! 2007 - s. moorthi added j. han's modified pbl/sas options !
94 ! dec 2007 - xu li modified the operational version for !
95 ! nst model !
96 ! 2008 - s. moorthi applied xu li's nst model to new gfs !
97 ! mar 2008 - y.-t. hou added sunshine duration var (suntim) as !
98 ! an input/output argument. !
99 ! 2008 - jun wang added spfhmax/spfhmin as input/output. !
100 ! apr 2008 - y.-t. hou added lw sfc emissivity var (sfcemis), !
101 ! define the lw sfc dn/up fluxes in two forms: atmos!
102 ! and ground. also changed sw sfc net flux direction!
103 ! (positive) from ground -> atmos to the direction !
104 ! of atmos -> ground. recode the program and add !
105 ! program documentation block.
106 ! 2008/ - s. moorthi and y.t. hou upgraded the code to more !
107 ! 2009 modern form and changed all the inputs to MKS units.!
108 ! feb 2009 - s. moorthi upgraded to add Hochun's gocart changes !
109 ! jul 2009 - s. moorthi added rqtk for sela's semi-lagrangian !
110 ! aug 2009 - s. moorthi added j. han and h. pan updated shallow !
111 ! convection package !
112 ! sep 2009 - s. moorthi updated for the mcica (rrtm3) radiation !
113 ! dec 2010 - sarah lu lgocart added to input arg; !
114 ! compute dqdt_v if inline gocart is on !
115 ! feb 2011 - sarah lu add the option to update surface diag !
116 ! fields (t2m,q2m,u10m,v10m) at the end !
117 ! Jun 2011 - s. moorthi and Xu Li - updated the nst model !
118 ! !
119 ! sep 2011 - sarah lu correct dqdt_v calculations !
120 ! apr 2012 - henry juang add idea !
121 ! sep 2012 - s. moorthi merge with operational version !
122 ! Mar 2013 - Jun Wang set idea heating rate to tmp tendency !
123 ! May 2013 - Jun Wang tmp updated after idea phys !
124 ! Jun 2013 - s. moorthi corrected a bug in 3d diagnostics for T !
125 ! Aug 2013 - s. moorthi updating J. Whitekar's changes related !
126 ! to stochastic physics perturnbation !
127 ! Oct 2013 - Xingren Wu add dusfci/dvsfci !
128 ! Mar 2014 - Xingren Wu add "_cpl" for coupling !
129 ! Mar 2014 - Xingren Wu add "nir/vis beam and nir/vis diff" !
130 ! Apr 2014 - Xingren Wu add "NET LW/SW including nir/vis" !
131 ! Jan 2014 - Jun Wang merge Moorthi's gwdc change and H.Juang !
132 ! and F. Yang's energy conversion from GWD!
133 ! jan 2014 - y-t hou revised sw sfc spectral component fluxes!
134 ! for coupled mdl, added estimation of ocean albedo !
135 ! without ice contamination. !
136 ! Jun 2014 - Xingren Wu update net SW fluxes over the ocean !
137 ! (no ice contamination) !
138 ! Jul 2014 - Xingren Wu add Sea/Land/Ice Mask - slmsk_cpl !
139 ! Jul 2014 - s. moorthi merge with standalone gfs and cleanup !
140 ! Aug 2014 - s. moorthi add tracer fixer !
141 ! Sep 2014 - Sarah Lu disable the option to compute tracer !
142 ! scavenging in GFS phys (set fscav=0.) !
143 ! Dec 2014 - Jun Wang add cnvqc_v for gocart !
144 
145 ! ==================== defination of variables ==================== !
146 ! --- 2014 - D. Dazlich Added Chikira-Sugiyama (CS) convection !
147 ! as an option in opr GFS. !
148 ! Apr 2015 S. Moorthi Added CS scheme to NEMS/GSM !
149 ! Jun 2015 S. Moorthi Added SHOC to NEMS/GSM !
150 ! Aug 2015 - Xu Li change nst_fcst to be nstf_name !
151 ! and introduce depth mean SST !
152 ! Sep 2015 - Xingren Wu remove oro_cpl & slmsk_cpl !
153 ! Sep 2015 - Xingren Wu add sfc_cice !
154 ! Sep 2015 - Xingren Wu connect CICE output to sfc_cice !
155 ! Jan 2016 - P. Tripp NUOPC/GSM merge !
156 ! Mar 2016 - J. Han - add ncnvcld3d integer !
157 ! for convective cloudiness enhancement !
158 ! Mar 2016 - J. Han - change newsas & sashal to imfdeepcnv !
159 ! & imfshalcnv, respectively !
160 ! Mar 2016 F. Yang add pgr to rayleigh damping call !
161 ! Mar 2016 S. Moorthi add ral_ts !
162 ! Mar 2016 Ann Cheng add morrison 2m microphysics (gsfc) !
163 ! May 2016 S. Moorthi cleanup 2m microphysics implementation !
164 ! Jun 2016 X. Li change all nst_fld as inout !
165 ! jul 2016 S. Moorthi fix some bugs in shoc/2m microphysics !
166 !
167 ! ==================== end of description =====================
168 ! ==================== definition of variables ==================== !
169 
745  subroutine gbphys &
746  & ( im,ix,levs,lsoil,lsm,ntrac,ncld,ntoz,ntcw,ntke, &
747  & ntiw,ntlnc,ntinc, &
748  & nmtvr,nrcm,ko3,lonr,latr,jcap, &
749  & num_p3d,num_p2d,npdf3d,ncnvcld3d, &
750  & kdt,lat,me,pl_coeff,nlons,ncw,flgmin,crtrh,cdmbgwd, &
751  & ccwf,dlqf,ctei_rm,clstp,cgwf,prslrd0,ral_ts,dtp,dtf,fhour, &
752  & solhr,slag,sdec,cdec,sinlat,coslat,pgr,ugrs,vgrs, &
753  & tgrs,qgrs,vvel,prsi,prsl,prslk,prsik,phii,phil, &
754  & rann,prdoz,poz,dpshc,fscav,fswtr,hprime,xlon,xlat, &
755  & h2o_phys,levh2o,h2opl,h2o_pres,h2o_coeff, &
756  & isot, ivegsrc, &
757  & slope,shdmin,shdmax,snoalb,tg3,slmsk,vfrac, &
758  & vtype,stype,uustar,oro,oro_uf,coszen,sfcdsw,sfcnsw, &
759  & sfcnirbmd,sfcnirdfd,sfcvisbmd,sfcvisdfd, &
760  & sfcnirbmu,sfcnirdfu,sfcvisbmu,sfcvisdfu, &
761  & slimskin_cpl,ulwsfcin_cpl, &
762  & dusfcin_cpl,dvsfcin_cpl,dtsfcin_cpl,dqsfcin_cpl, &
763  & sfcdlw,tsflw,sfcemis,sfalb,swh,swhc,hlw,hlwc,hlwd,lsidea, &
764  & ras,pre_rad,ldiag3d,lgocart,lssav,lssav_cpl, &
765  & xkzm_m,xkzm_h,xkzm_s,psautco,prautco,evpco,wminco, &
766  & pdfcld,shcnvcw,sup,redrag,hybedmf,dspheat, &
767  & flipv,old_monin,cnvgwd,shal_cnv, &
768  & imfshalcnv,imfdeepcnv,cal_pre,aero_in, &
769  & mom4ice,mstrat,trans_trac,nstf_name,moist_adj, &
770  & thermodyn_id, sfcpress_id, gen_coord_hybrid,levr,adjtrc,nnp,&
771  & cscnv,nctp,do_shoc,shocaftcnv,ntot3d,ntot2d, & ! --- input/outputs:
772  & hice,fice,tisfc,tsea,tprcp,cv,cvb,cvt, &
773  & srflag,snwdph,weasd,sncovr,zorl,canopy, &
774  & ffmm,ffhh,f10m,srunoff,evbsa,evcwa,snohfa, &
775  & transa,sbsnoa,snowca,soilm,tmpmin,tmpmax, &
776  & dusfc,dvsfc,dtsfc,dqsfc,totprcp,gflux, &
777  & dlwsfc,ulwsfc,suntim,runoff,ep,cldwrk, &
778  & dugwd,dvgwd,psmean,cnvprcp,spfhmin,spfhmax,rain,rainc, &
779  & dt3dt,dq3dt,du3dt,dv3dt,dqdt_v,cnvqc_v,acv,acvb,acvt, &
780  & slc,smc,stc,upd_mf,dwn_mf,det_mf,phy_f3d,phy_f2d, &
781  & dusfc_cpl, dvsfc_cpl, dtsfc_cpl, dqsfc_cpl, &
782  & dlwsfc_cpl,dswsfc_cpl,dnirbm_cpl,dnirdf_cpl, &
783  & dvisbm_cpl,dvisdf_cpl,rain_cpl, nlwsfc_cpl,nswsfc_cpl, &
784  & nnirbm_cpl,nnirdf_cpl,nvisbm_cpl,nvisdf_cpl,snow_cpl, &
785  & xt,xs,xu,xv,xz,zm,xtts,xzts,d_conv,ifd,dt_cool,qrain, &
786  & tref, z_c, c_0, c_d, w_0, w_d, &
787  & phy_fctd, & ! --- outputs:
788  & gt0,gq0,gu0,gv0,t2m,q2m,u10m,v10m, &
789  & zlvl,psurf,hpbl,pwat,t1,q1,u1,v1, &
790  & chh,cmm,dlwsfci,ulwsfci,dswsfci,uswsfci,dusfci,dvsfci, &
791  & dtsfci,dqsfci,gfluxi,epi,smcwlt2,smcref2,wet1,sr, &
792  & rqtk, & ! Stochastic physics perturnbation
793  & dtdtr, &
794  & dusfci_cpl, dvsfci_cpl, dtsfci_cpl, dqsfci_cpl, &
795  & dlwsfci_cpl, dswsfci_cpl, &
796  & dnirbmi_cpl, dnirdfi_cpl, dvisbmi_cpl, dvisdfi_cpl, &
797  & nlwsfci_cpl, nswsfci_cpl, &
798  & nnirbmi_cpl, nnirdfi_cpl, nvisbmi_cpl, nvisdfi_cpl, &
799  & t2mi_cpl, q2mi_cpl, u10mi_cpl, v10mi_cpl, &
800  & tseai_cpl, psurfi_cpl &
801  & )
802 !
803  use machine , only : kind_phys
804  use physcons, only : con_cp, con_fvirt, con_g, con_rd, con_rv, &
806  &, rhc_max, dxmin, dxinv, pa2mb, rlapse
807  use module_nst_water_prop, only: get_dtzm_2d
808  use cs_conv, only : cs_convr
809 
810  implicit none
811 !
812 ! --- some constant parameters:
813 
814  real(kind=kind_phys), parameter :: hocp = con_hvap/con_cp
815 ! &, fhourpr = 0.0
816  &, qmin = 1.0e-10
817  &, p850 = 85000.0
818  &, epsq = 1.e-20
819  &, hsub = con_hvap+con_hfus
820  &, czmin = 0.0001 ! cos(89.994)
821 
822 ! --- inputs:
823 
824 ! note: lgocart is the logical flag for in-line gocart;
825 
826  integer, intent(in) :: ix, im, levs, lsoil, lsm, ntrac, &
827  & ncld, ntiw, ntlnc, ntinc, &
828  & ntoz, ntcw, nmtvr, nrcm, ko3, &
829  & lonr, latr, jcap, num_p3d, num_p2d, kdt, &
830  & me, pl_coeff, lat, npdf3d, ncnvcld3d, &
831  & thermodyn_id, sfcpress_id, levr, nnp, nctp,&
832  & ntke, ntot3d, ntot2d, h2o_coeff, levh2o, &
833  & isot, ivegsrc
834 
835 
836  integer, intent(in) :: nlons(im), ncw(2)
837  integer, intent(in) :: nstf_name(5)
838  integer, intent(in) :: imfshalcnv, imfdeepcnv
839 
840  logical, intent(in) :: ras, pre_rad, ldiag3d, flipv, &
841  & old_monin, cnvgwd, aero_in, &
842  & redrag, hybedmf, dspheat, &
843  & lssav, mom4ice, mstrat, &
844  & trans_trac, moist_adj, cal_pre, cscnv, &
845  & shal_cnv, gen_coord_hybrid, lgocart, &
846  & lsidea, lssav_cpl, pdfcld, shcnvcw, &
847  & do_shoc, shocaftcnv, h2o_phys
848 
849  real(kind=kind_phys) :: adjtrc(ntrac)
850 
851  real(kind=kind_phys), dimension(im), intent(in) :: &
852  & sinlat, coslat, pgr, dpshc, xlon, xlat, &
853  & slope, shdmin, shdmax, snoalb, tg3, slmsk, vfrac, &
854  & vtype, stype, uustar, oro, coszen, sfcnsw, sfcdsw, &
855  & sfcnirbmu, sfcnirdfu, sfcvisbmu, sfcvisdfu, &
856  & sfcnirbmd, sfcnirdfd, sfcvisbmd, sfcvisdfd, &
857  & slimskin_cpl, dusfcin_cpl, dvsfcin_cpl, &
858  & dtsfcin_cpl, dqsfcin_cpl, ulwsfcin_cpl, &
859  & sfcdlw, tsflw, sfalb, sfcemis, oro_uf
860 
861  real(kind=kind_phys), dimension(ix,levs), intent(in) :: &
862  & ugrs, vgrs, tgrs, vvel, prsl, prslk, phil, swh, swhc, hlw, hlwc
863 
864 !idea add by hmhj
865  real(kind=kind_phys), intent(in) :: hlwd(ix,levs,6)
866 
867  real(kind=kind_phys), intent(inout) :: qgrs(ix,levs,ntrac)
868 
869  real(kind=kind_phys), dimension(ix,levs+1), intent(in) :: &
870  & prsi, prsik, phii
871 
872  real(kind=kind_phys), intent(in) :: hprime(ix,nmtvr), &
873  & prdoz(ix,ko3,pl_coeff), rann(ix,nrcm), poz(ko3), &
874  & h2opl(ix,levh2o,h2o_coeff), h2o_pres(levh2o)
875 
876  real(kind=kind_phys), intent(in) :: dtp, dtf, fhour, solhr, &
877  & slag, sdec, cdec, ctei_rm(2), clstp, &
878  & ccwf(2), crtrh(3), flgmin(2), dlqf(2), cdmbgwd(2), &
879  & xkzm_m, xkzm_h, xkzm_s, psautco(2), prautco(2), &
880  & evpco, wminco(2), cgwf(2), prslrd0, sup, ral_ts
881 
882 ! --- input/output:
883  real(kind=kind_phys), dimension(im), intent(inout) :: &
884  & hice, fice, tisfc, tsea, tprcp, cv, cvb, cvt, &
885  & srflag, snwdph, weasd, sncovr, zorl, canopy, ffmm, ffhh,&
886  & f10m, srunoff, evbsa, evcwa, snohfa, transa, sbsnoa, &
887  & snowca, soilm, tmpmin, tmpmax, dusfc, dvsfc, dtsfc, &
888  & dqsfc, totprcp, gflux, dlwsfc, ulwsfc, suntim, runoff, ep,&
889  & cldwrk, dugwd, dvgwd, psmean, cnvprcp,spfhmin,spfhmax, &
890  & rain, rainc, acv, acvb, acvt
891  real(kind=kind_phys), dimension(im), optional, intent(inout) :: & ! for A/O/I coupling:
892  & dusfc_cpl, dvsfc_cpl, dtsfc_cpl, dqsfc_cpl, &
893  & dlwsfc_cpl,dswsfc_cpl,rain_cpl, snow_cpl, &
894  & dnirbm_cpl,dnirdf_cpl,dvisbm_cpl,dvisdf_cpl, &
895  & nlwsfc_cpl,nswsfc_cpl, &
896  & nnirbm_cpl,nnirdf_cpl,nvisbm_cpl,nvisdf_cpl, & ! for nst:
897  & xt, xs, xu, xv, xz, zm, xtts, xzts, d_conv, ifd, dt_cool, &
898  & Qrain, tref, z_c, c_0, c_d, w_0, w_d
899 
900 !
901  real(kind=kind_phys), dimension(ix,lsoil), intent(inout) :: &
902  & smc, stc, slc
903 
904  real(kind=kind_phys), dimension(ix,levs), intent(inout) :: &
905  & upd_mf, dwn_mf, det_mf, dqdt_v, cnvqc_v
906 ! & upd_mf, dwn_mf, det_mf, dkh, rnp
907 
908  real(kind=kind_phys), intent(inout) :: &
909  & phy_f3d(ix,levs,ntot3d), phy_f2d(ix,ntot2d), &
910  & dt3dt(ix,levs,6), du3dt(ix,levs,4), dv3dt(ix,levs,4), &
911  & dq3dt(ix,levs,5+pl_coeff)
912 
913  real(kind=kind_phys), intent(inout) :: &
914  & phy_fctd(ix,nctp) &
915  real(kind=kind_phys), dimension(ntrac-ncld+2) :: fscav, fswtr
916 
917 ! --- output:
918  real(kind=kind_phys), dimension(im), intent(out) :: &
919  & t2m, q2m, u10m, v10m, zlvl, psurf, hpbl, &
920  & pwat, t1, q1, u1, v1, chh, cmm, &
921  & dlwsfci, ulwsfci, dswsfci, uswsfci, &
922  & dusfci, dvsfci, dtsfci, dqsfci, &
923  & gfluxi, epi, smcwlt2, smcref2, wet1, sr
924 
925  real(kind=kind_phys), dimension(im), optional, intent(out) :: &
926  & dusfci_cpl,dvsfci_cpl,dtsfci_cpl,dqsfci_cpl, &
927  & dlwsfci_cpl,dswsfci_cpl, &
928  & dnirbmi_cpl,dnirdfi_cpl,dvisbmi_cpl,dvisdfi_cpl, &
929  & nlwsfci_cpl,nswsfci_cpl, &
930  & nnirbmi_cpl,nnirdfi_cpl,nvisbmi_cpl,nvisdfi_cpl, &
931  & t2mi_cpl,q2mi_cpl, &
932  & u10mi_cpl,v10mi_cpl,tseai_cpl,psurfi_cpl, &
933  & rqtk
934 
935  real(kind=kind_phys), dimension(ix,levs), intent(out) :: &
936  & gt0, gu0, gv0
937 
938  real(kind=kind_phys), dimension(ix,levs,ntrac), intent(out) :: &
939  & gq0
940 
941 ! --- local:
942 ! real(kind=kind_phys) :: fscav(ntrac-ncld-1)
943 ! real(kind=kind_phys),allocatable :: fscav(:), fswtr(:)
944  real(kind=kind_phys), dimension(im) :: ccwfac, garea, &
945  & dlength, xncw, cumabs, qmax, cice, zice, tice, &
946 ! & gflx, rain, rainc, rainl, rain1, raincs, evapc, &
947  & gflx, rain1, raincs, &
948  & snowmt, cd, cdq, qss, dusfcg, dvsfcg, dusfc1, &
949  & dvsfc1, dtsfc1, dqsfc1, rb, rhscnpy, drain, cld1d, &
950  & evap, hflx, stress, t850, ep1d, gamt, gamq, &
951  & sigmaf, oc, theta, gamma, sigma, &
952  & elvmax, wind, work1, work2, runof, xmu, &
953 ! & elvmax, wind, work1, work2, runof, xmu, oro_land, &
954  & fm10, fh2, tsurf, tx1, tx2, ctei_r, flgmin_l, &
955  & evbs, evcw, trans, sbsno, snowc, frland, &
956  & adjsfcdsw, adjsfcnsw, adjsfcdlw, adjsfculw,gabsbdlw, &
957  & adjnirbmu, adjnirdfu, adjvisbmu, adjvisdfu, &
958  & adjnirbmd, adjnirdfd, adjvisbmd, adjvisdfd, &
959  & xcosz, tseal, snohf, dlqfac, work3, ctei_rml, cldf, &
960  & domr, domzr, domip, doms, psautco_l, prautco_l
961 
962  real(kind=kind_phys), dimension(im) :: ocalnirbm_cpl, &
963  & ocalnirdf_cpl,ocalvisbm_cpl,ocalvisdf_cpl
964 
965 ! & dswsfc, radsl, &
966 ! & dlwsf1, ulwsf1, xcosz, tseal, snohf, dlqfac, &
967 ! & domr, domzr, domip, doms
968 
969 ! real(kind=kind_phys), dimension(ix,levs) :: ud_mf, dd_mf, &
970 ! & dt_mf, del
971  real(kind=kind_phys), dimension(ix,levs) :: del, dtdtr
972  real(kind=kind_phys), dimension(im,levs-1) :: dkt
973 
974  real(kind=kind_phys), dimension(im,levs) :: rhc, dtdt, &
975  & dudt, dvdt, gwdcu, gwdcv, dtdtc, dmdt, &
976 ! & diagn1, diagn2, cuhr, cumchr, &
977  & qr_col, fc_ice, rainp, ud_mf, dd_mf, dt_mf, prnum
978 ! & qr_col, fc_ice, rainp, ud_mf, dd_mf, dt_mf, shoc_cld, prnum
979 
980  real(kind=kind_phys), dimension(im,lsoil) :: smsoil, stsoil, &
981  & ai, bi, cci, rhsmc, zsoil, slsoil
982 
983  real(kind=kind_phys) :: zsea1,zsea2
984  real(kind=kind_phys), dimension(im) :: dtzm
985 
986  real(kind=kind_phys) :: rhbbot, rhbtop, rhpbl, frain, f_rain, &
987  & f_ice, qi, qw, qr, wc, tem, tem1, tem2, sume, sumr, sumq, &
988  & dqdt(im,levs,ntrac), oa4(im,4), clx(im,4), albbm, xcosz_loc
989  real(kind=kind_phys), parameter :: albdf=0.06
990 
991 
992 ! in clw, the first two varaibles are cloud water and ice.
993 ! from third to ntrac are convective transportable tracers,
994 ! third being the ozone, when ntrac=3 (valid only with ras)
995 
996  real(kind=kind_phys), allocatable :: clw(:,:,:), qpl(:,:),qpi(:,:)
997  &, ncpl(:,:), ncpi(:,:)
998 
999  integer, dimension(im) :: kbot, ktop, kcnv, soiltyp, vegtype, &
1000  & kpbl, slopetyp, kinver, lmh, levshc, islmsk
1001 
1002  integer :: i, nvdiff, kk, ic, k, n, ipr, lv, k1, iter, levshcm, &
1003  & tracers, trc_shft, tottracer, num2, num3 &
1004  &, nshocm, nshoc, ntk, ntln, ntin
1005 
1006  logical, dimension(im) :: flag_iter, flag_guess, invrsn &
1007  &, skip_macro
1008 
1009  real(kind=kind_phys), dimension(im) :: dtsfc_cice, &
1010  & dqsfc_cice, dusfc_cice, dvsfc_cice, ulwsfc_cice, tisfc_cice, &
1011  & tsea_cice, hice_cice, fice_cice
1012 
1013  integer, dimension(im) :: islmsk_cice
1014  logical, dimension(im) :: flag_cice
1015 
1016  logical :: lprnt, revap
1017 
1018  real(kind=kind_phys), allocatable :: cnvc(:,:),cnvw(:,:)
1019  real(kind=kind_phys) eng0, eng1, dtshoc
1020 !
1021 ! for CS-convection
1022 ! real(kind=kind_phys), parameter :: wcbmax1=2.8, wcbmax2=1.4
1023  real(kind=kind_phys), parameter :: wcbmax1=2.5, wcbmax2=1.5
1024 ! real(kind=kind_phys), parameter :: wcbmax1=1.4, wcbmax2=1.4
1025  real(kind=kind_phys) wcbmax(im)
1026 !
1027  real(kind=kind_phys) tf, tcr, tcrf
1028 ! parameter (tf=233.16, tcr=263.16, tcrf=1.0/(tcr-tf))
1029  parameter(tf=258.16, tcr=273.16, tcrf=1.0/(tcr-tf))
1030 !
1031 ! for 2 M microphysics
1032  real(kind=kind_phys), allocatable, dimension(:,:) :: qlcn, qicn
1033  &, w_upi,cf_upi, cnv_mfd, cnv_prc3, cnv_dqldt,clcn, !Acheng
1034  & cnv_fice,cnv_ndrop,cnv_nice
1035  real(kind=kind_phys), allocatable, dimension(:) :: cn_prc,cn_snr
1036 !
1037 !
1038 !===> ... begin here
1039 !
1040 ! The option to compute tracer scavenging in GSM is disabled
1041 ! do i=1, ntrac-ncld-1
1042 ! fscav(i) = 0.
1043 ! enddo
1044 
1045 
1046 ! --- ... set up check print point (for debugging)
1047 !
1048 !*************************************************************************
1049  lprnt = .false.
1050 ! lprnt = me == 0 .and. kdt < 10 .and. lat == 22
1051  ipr = 1
1052 
1053 ! if (me == 0 .and. kdt < 5)
1054 ! &write(0,*)' In gbphys:', im,ix,levs,lsoil,lsm,
1055 ! & ntrac,ncld,ntoz,ntcw,
1056 ! & nmtvr,nrcm,ko3,lonr,latr,jcap,num_p3d,num_p2d,npdf3d,
1057 ! & kdt,lat,me,pl_coeff,ncw,flgmin,crtrh,cdmbgwd
1058 ! &,' ccwf=',ccwf,' dlqf=',dlqf,' ras=',ras,
1059 ! & ' evpco=',evpco,' wminco=',wminco,' levr=',levr
1060 ! do i = 1, im
1061 ! lprnt = kdt >= 256 .and. abs(xlon(i)*57.29578-136.07) < 0.08 &
1062 ! & .and. abs(xlat(i)*57.29578+1.1) < 0.101
1063 ! lprnt = kdt >= 0 .and. abs(xlon(i)*57.29578-13.125) < 0.501 &
1064 ! & .and. abs(xlat(i)*57.29578-79.043) < 0.501
1065 ! lprnt = kdt >= 0 .and. abs(xlon(i)*57.29578-8.4375) < 0.501 &
1066 ! & .and. abs(xlat(i)*57.29578+1.4) < 0.501
1067 ! lprnt = kdt >= 40 .and. abs(xlon(i)*57.29578-288.75) < 1.501 &
1068 ! & .and. abs(xlat(i)*57.29578+12.38) < 1.501
1069 ! lprnt = kdt >= 0 .and. abs(xlon(i)*57.29578-135.0) < 0.201 &
1070 ! & .and. abs(xlat(i)*57.29578-10.476) < 0.201
1071 ! lprnt = kdt >= 0 .and. abs(xlon(i)*57.29578-110.3) < 0.201 &
1072 ! & .and. abs(xlat(i)*57.29578-2.0) < 0.201
1073 ! if (kdt == 10)
1074 ! & print *,' i=',i,' xlon=',xlon(i)*57.29578, &
1075 ! & ' xlat=',xlat(i)*57.29578,' i=',i,' me=',me
1076 ! if (lprnt) then
1077 ! ipr = i
1078 ! exit
1079 ! endif
1080 ! enddo
1081 
1082 ! lprnt = .false.
1083 ! if(lprnt) then
1084 ! write(0,*)' im=',im,' ix=',ix,' levs=',levs,' lsoil=',lsoil, &
1085 ! & ' ntrac=',ntrac,' ntoz=',ntoz,' ntcw=',ntcw,' me=',me, &
1086 ! & ' xlat=',xlat(ipr),' kdt=',kdt,' slmsk=',slmsk(ipr), &
1087 ! & ' ntke=',ntke,' num_p3d=',num_p3d,' xlon=',xlon(ipr)
1088 ! & ' tsea=',tsea(ipr),' tref=',tref(ipr),' dt_cool=',dt_cool(ipr),&
1089 ! & ' dt_warm=',2.0*xt(ipr)/xz(ipr),' nrcm=',nrcm,' xlon=',
1090 ! & xlon(ipr), &
1091 ! & ' dt_warm=',dt_warm(ipr),' nrcm=',nrcm,' xlon=',xlon(ipr), &
1092 ! & ' sfalb=',sfalb(ipr),' kdt=',kdt
1093 ! write(0,*) ' pgr=',pgr(ipr),' kdt=',kdt,' ipr=',ipr
1094 ! write(0,*)' ipr=',ipr,' phy_f2d=',phy_f2d(ipr,1:num_p2d)
1095 ! write(0,*),' ugrs=',ugrs(ipr,:)
1096 ! write(0,*)' vgrs=',vgrs(ipr,:)
1097 ! write(0,*)' tgrs=',tgrs(ipr,:),' kdt=',kdt,' ipr=',ipr
1098 ! &, ' xlon=',xlon(ipr),' xlat=',xlat(ipr)
1099 ! write(0,*)' qgrs=',qgrs(ipr,:,1)
1100 ! write(0,*)' ozg=',qgrs(ipr,:,2)
1101 ! write(0,*)' tke=',qgrs(ipr,:,4)
1102 ! print *,' clwb=',qgrs(ipr,:,ntiw)
1103 ! &, ' xlon=',xlon(ipr),' xlat=',xlat(ipr)
1104 ! endif
1105 !
1106 !*************************************************************************
1107 !
1108  do i = 1, im
1109  if(nint(slmsk(i)) == 1) then
1110  frland(i) = 1.0
1111  else
1112  frland(i) = 0.
1113  endif
1114  enddo
1115 
1116  nvdiff = ntrac ! vertical diffusion of all tracers!
1117 !
1118 ! --- ... figure out number of extra tracers
1119 !
1120  tottracer = 0 ! no convective transport of tracers
1121  if (trans_trac) then
1122  if (ntcw > 0) then
1123  if (ntoz < ntcw) then
1124  trc_shft = ntcw + ncld - 1
1125  else
1126  trc_shft = ntoz
1127  endif
1128  elseif (ntoz > 0) then
1129  trc_shft = ntoz
1130  else
1131  trc_shft = 1
1132  endif
1133 
1134  tracers = ntrac - trc_shft
1135  tottracer = tracers
1136  if (ntoz > 0) tottracer = tottracer + 1 ! ozone is added separately
1137  endif
1138  if (ntke > 0) ntk = ntke - trc_shft + 3
1139 
1140 ! if (lprnt) write(0,*)' trans_trac=',trans_trac,' tottracer=', &
1141 ! write(0,*)' trans_trac=',trans_trac,' tottracer=', &
1142 ! & tottracer,' trc_shft=',trc_shft,' kdt=',kdt
1143 ! &, ntrac-ncld+2,' clstp=',clstp,' kdt=',kdt
1144 ! &,' ntk=',ntk,' lat=',lat
1145 
1146  skip_macro = .false.
1147  allocate ( clw(ix,levs,tottracer+2) )
1148  if (do_shoc) then
1149  allocate (qpl(im,levs), qpi(im,levs)
1150  &, ncpl(im,levs), ncpi(im,levs))
1151  do k=1,levs
1152  do i=1,im
1153  ncpl(i,k) = 0.0
1154  ncpi(i,k) = 0.0
1155  enddo
1156  enddo
1157  endif
1158 
1159  if (.not. ras .or. .not. cscnv) then
1160  allocate ( cnvc(ix,levs), cnvw(ix,levs))
1161  endif
1162 ! allocate (fscav(tottracer+3), fswtr(tottracer+3))
1163 
1164  if (ncld == 2) then ! For MGB double moment microphysics
1165  allocate (qlcn(im,levs), qicn(im,levs), w_upi(im,levs)
1166  &, cf_upi(im,levs), cnv_mfd(im,levs),cnv_prc3(im,levs)
1167  &, cnv_dqldt(im,levs), clcn(im,levs), cnv_fice(im,levs)
1168  &, cnv_ndrop(im,levs), cnv_nice(im,levs))
1169  allocate(cn_prc(im), cn_snr(im))
1170  else
1171  allocate (qlcn(1,1), qicn(1,1), w_upi(1,1)
1172  &, cf_upi(1,1), cnv_mfd(1,1),cnv_prc3(1,1)
1173  &, cnv_dqldt(1,1), clcn(1,1), cnv_fice(1,1)
1174  &, cnv_ndrop(1,1), cnv_nice(1,1))
1175  endif
1176 
1177 ! The option to compute tracer scavenging in GSM is disabled
1178  do i=1, tottracer+3
1179  fscav(i) = 0.
1180  fswtr(i) = 0.
1181  enddo
1182 
1183  if (nnp == 1) then
1184  do n=1,ntrac
1185  if (abs(1.0-adjtrc(n)) > 1.0e-7) then
1186  do k=1,levs
1187  do i=1,im
1188  qgrs(i,k,n) = qgrs(i,k,n) * adjtrc(n)
1189  enddo
1190  enddo
1191  endif
1192  enddo
1193  endif
1194 !
1195  call get_prs(im,ix,levs,ntrac,tgrs,qgrs, &
1196  & thermodyn_id, sfcpress_id, &
1197  & gen_coord_hybrid, &
1198  & prsi,prsik,prsl,prslk,phii,phil,del)
1199 ! & prsi,prsik,prsl,prslk,phii,phil,del,lprnt)
1200 !
1201 ! if (lprnt) then
1202 ! write(0,*)' prsi=',prsi(ipr,:)
1203 ! write(0,*)' prsik=',prsik(ipr,:),' me=',me,' kdt=',kdt
1204 ! write(0,*)' prslk=',prslk(ipr,:),' me=',me,' kdt=',kdt
1205 ! write(0,*)' phil=',phil(ipr,:),' me=',me,' kdt=',kdt,' ipr=',ipr
1206 ! &,' lat=',lat,' prsi=',prsi(ipr,1)
1207 ! write(0,*)' prsl=',prsl(ipr,:),' kdt=',kdt
1208 ! print *,' del=',del(ipr,:)
1209 ! endif
1210 !
1211  rhbbot = crtrh(1)
1212  rhpbl = crtrh(2)
1213  rhbtop = crtrh(3)
1214 !
1215 ! --- ... frain=factor for centered difference scheme correction of rain amount.
1216 
1217  frain = dtf / dtp
1218 
1219  do i = 1, im
1220  sigmaf(i) = max( vfrac(i),0.01 )
1221 ! sigmaf(i) = max( vfrac(i),0.3 )
1222  if (lsm == 0) sigmaf(i) = 0.5 + vfrac(i) * 0.5
1223 
1224  islmsk(i) = nint(slmsk(i))
1225 
1226  if (islmsk(i) == 2) then
1227  if (isot == 1) then
1228  soiltyp(i) = 16
1229  else
1230  soiltyp(i) = 9
1231  endif
1232  if (ivegsrc == 1) then
1233  vegtype(i) = 15
1234  elseif(ivegsrc == 2) then
1235  vegtype(i) = 13
1236  endif
1237  slopetyp(i) = 9 !! clu: qa(slopetyp)
1238  else
1239  soiltyp(i) = int( stype(i)+0.5 )
1240  vegtype(i) = int( vtype(i)+0.5 )
1241  slopetyp(i) = int( slope(i)+0.5 ) !! clu: slope -> slopetyp
1242  endif
1243 ! --- ... xw: transfer ice thickness & concentration from global to local variables
1244  zice(i) = hice(i)
1245  cice(i) = fice(i)
1246  tice(i) = tisfc(i)
1247 
1248  if (lssav_cpl) then
1249  islmsk_cice(i) = nint(slimskin_cpl(i))
1250  flag_cice(i) = (islmsk_cice(i) == 4)
1251 
1252  ulwsfc_cice(i) = ulwsfcin_cpl(i)
1253  dusfc_cice(i) = dusfcin_cpl(i)
1254  dvsfc_cice(i) = dvsfcin_cpl(i)
1255  dtsfc_cice(i) = dtsfcin_cpl(i)
1256  dqsfc_cice(i) = dqsfcin_cpl(i)
1257  tisfc_cice(i) = tisfc(i)
1258  tsea_cice(i) = tsea(i)
1259  fice_cice(i) = fice(i)
1260  hice_cice(i) = hice(i)
1261  endif
1262 
1263  work1(i) = (log(coslat(i) / (nlons(i)*latr)) - dxmin) * dxinv
1264  work1(i) = max(0.0, min(1.0,work1(i)))
1265  work2(i) = 1.0 - work1(i)
1266  psurf(i) = pgr(i)
1267  work3(i) = prsik(i,1) / prslk(i,1)
1268  tem1 = con_rerth * (con_pi+con_pi)*coslat(i)/nlons(i)
1269  tem2 = con_rerth * con_pi / latr
1270  garea(i) = tem1 * tem2
1271  dlength(i) = sqrt( tem1*tem1+tem2*tem2 )
1272  cldf(i) = cgwf(1)*work1(i) + cgwf(2)*work2(i)
1273  wcbmax(i) = wcbmax1*work1(i) + wcbmax2*work2(i)
1274  enddo
1275 
1276 ! if (lprnt) write(0,*)' in gbphys work1&2=',work1(ipr),work2(ipr)
1277 ! &,' dxmin=',dxmin,' dxinv=',dxinv,' dx=',
1278 ! & log(coslat(ipr) / (nlons(ipr)*latr))
1279 ! &,' coslat=',coslat(ipr),' nlons=',nlons(ipr),' latr=',latr
1280 
1281 ! --- ... transfer soil moisture and temperature from global to local variables
1282 
1283  do k = 1, lsoil
1284  do i = 1, im
1285  smsoil(i,k) = smc(i,k)
1286  stsoil(i,k) = stc(i,k)
1287  slsoil(i,k) = slc(i,k) !! clu: slc -> slsoil
1288  enddo
1289  enddo
1290 
1291  do k = 1, levs
1292  do i = 1, im
1293  dudt(i,k) = 0.
1294  dvdt(i,k) = 0.
1295  dtdt(i,k) = 0.
1296  dtdtc(i,k) = 0.
1297  enddo
1298  enddo
1299 
1300  do n = 1, ntrac
1301  do k = 1, levs
1302  do i = 1, im
1303  dqdt(i,k,n) = 0.
1304  enddo
1305  enddo
1306  enddo
1307 
1308 ! --- ... initialize dtdt with heating rate from dcyc2
1309 
1310 ! if (lprnt) then
1311 ! do ipr=1,im
1312 ! write(0,*)' before dcyc2: im=',im,' lsoil=',lsoil,' levs=', &
1313 ! & levs &
1314 ! &, ' sde=',sdec,' cdec=',cdec,' tsea=',tsea(ipr),' ipr=',ipr &
1315 ! &, ' lat=',lat,' me=',me,' kdt=',kdt &
1316 ! &, ' sfcdlw=',sfcdlw(ipr),' sfcnsw=',sfcnsw(ipr)
1317 ! print *,' hlw=',hlw(ipr,:),' me=',me,' lat=',lat,xlon(ipr)
1318 ! print *,' swh=',swh(ipr,:),' me=',me,' lat=',lat,xlon(ipr)
1319 ! enddo
1320 ! endif
1321 
1322 ! --- ... adjust mean radiation fluxes and heating rates to fit for
1323 ! faster model time steps.
1324 ! sw: using cos of zenith angle as scaling factor
1325 ! lw: using surface air skin temperature as scaling factor
1326 
1327  if (pre_rad) then
1328 
1329  call dcyc2t3_pre_rad &
1330 ! --- inputs:
1331  & ( solhr,slag,sdec,cdec,sinlat,coslat, &
1332  & xlon,coszen,tsea,tgrs(1,1),tgrs(1,1), &
1333  & sfcdsw,sfcnsw,sfcdlw,swh,hlw, &
1334  & sfcnirbmu,sfcnirdfu,sfcvisbmu,sfcvisdfu, &
1335  & sfcnirbmd,sfcnirdfd,sfcvisbmd,sfcvisdfd, &
1336  & ix, im, levs, &
1337 ! --- input/output:
1338  & dtdt, &
1339 ! --- outputs:
1340  & adjsfcdsw,adjsfcnsw,adjsfcdlw,adjsfculw,xmu,xcosz, &
1341  & adjnirbmu,adjnirdfu,adjvisbmu,adjvisdfu, &
1342  & adjnirbmd,adjnirdfd,adjvisbmd,adjvisdfd &
1343  & )
1344 
1345  else
1346 
1347  call dcyc2t3 &
1348 ! --- inputs:
1349  & ( solhr,slag,sdec,cdec,sinlat,coslat, &
1350  & xlon,coszen,tsea,tgrs(1,1),tsflw,sfcemis, &
1351  & sfcdsw,sfcnsw,sfcdlw,swh,swhc,hlw,hlwc, &
1352  & sfcnirbmu,sfcnirdfu,sfcvisbmu,sfcvisdfu, &
1353  & sfcnirbmd,sfcnirdfd,sfcvisbmd,sfcvisdfd, &
1354  & ix, im, levs, &
1355 ! --- input/output:
1356  & dtdt,dtdtc, &
1357 ! --- outputs:
1358  & adjsfcdsw,adjsfcnsw,adjsfcdlw,adjsfculw,xmu,xcosz, &
1359  & adjnirbmu,adjnirdfu,adjvisbmu,adjvisdfu, &
1360  & adjnirbmd,adjnirdfd,adjvisbmd,adjvisdfd &
1361  & )
1362 
1363 !
1364 ! save temp change due to radiation - need for sttp stochastic physics
1365 !---------------------------------------------------------------------
1366  do k=1,levs
1367  do i=1,im
1368  dtdtr(i,k) = dtdtr(i,k) + dtdtc(i,k)*dtf
1369  enddo
1370  enddo
1371 
1372  endif
1373 !
1374  if (lsidea) then !idea jw
1375  do k = 1, levs
1376  do i = 1, im
1377 ! dtdt(i,k) = hlwd(i,k,2)
1378  dtdt(i,k) = 0.
1379  enddo
1380  enddo
1381  endif
1382 
1383 ! --- convert lw fluxes for land/ocean/sea-ice models
1384 ! note: for sw: adjsfcdsw and adjsfcnsw are zenith angle adjusted downward/net fluxes.
1385 ! for lw: adjsfcdlw is (sfc temp adjusted) downward fluxe with no emiss effect.
1386 ! adjsfculw is (sfc temp adjusted) upward fluxe including emiss effect.
1387 ! one needs to be aware that that the absorbed downward lw flux (used by land/ocean
1388 ! models as downward flux) is not the same as adjsfcdlw but a value reduced by
1389 ! the factor of emissivity. however, the net effects are the same when seeing
1390 ! it either above the surface interface or below.
1391 !
1392 ! - flux above the interface used by atmosphere model:
1393 ! down: adjsfcdlw; up: adjsfculw = sfcemis*sigma*T**4 + (1-sfcemis)*adjsfcdlw
1394 ! net = up - down = sfcemis * (sigma*T**4 - adjsfcdlw)
1395 ! - flux below the interface used by lnd/oc/ice models:
1396 ! down: sfcemis*adjsfcdlw; up: sfcemis*sigma*T**4
1397 ! net = up - down = sfcemis * (sigma*T**4 - adjsfcdlw)
1398 
1399 ! --- ... define the downward lw flux absorbed by ground
1400 
1401  do i = 1, im
1402  gabsbdlw(i) = sfcemis(i) * adjsfcdlw(i)
1403  enddo
1404 
1405 ! if( lsidea ) then ! idea : moved temp adjust to idea_phys
1406 ! print *,' in gbphys: lsidea is true '
1407 ! DTDT = 0.
1408 ! endif
1409 
1410  if (lssav) then ! --- ... accumulate/save output variables
1411 
1412 ! --- ... sunshine duration time is defined as the length of time (in mdl output
1413 ! interval) that solar radiation falling on a plane perpendicular to the
1414 ! direction of the sun >= 120 w/m2
1415 
1416  do i = 1, im
1417  if ( xcosz(i) >= czmin ) then ! zenth angle > 89.994 deg
1418  tem1 = adjsfcdsw(i) / xcosz(i)
1419 
1420  if ( tem1 >= 120.0 ) then
1421  suntim(i) = suntim(i) + dtf
1422  endif
1423  endif
1424  enddo
1425 
1426 ! --- ... sfc lw fluxes used by atmospheric model are saved for output
1427 
1428  do i = 1, im
1429  dlwsfc(i) = dlwsfc(i) + adjsfcdlw(i)*dtf
1430  if (lssav_cpl) then
1431  if (flag_cice(i)) adjsfculw(i) = ulwsfc_cice(i)
1432  endif
1433  ulwsfc(i) = ulwsfc(i) + adjsfculw(i)*dtf
1434  psmean(i) = psmean(i) + pgr(i)*dtf ! mean surface pressure
1435  enddo
1436 
1437  if (ldiag3d) then
1438  if( lsidea ) then
1439  do k = 1, levs
1440  do i = 1, im
1441  dt3dt(i,k,1) = dt3dt(i,k,1) + hlwd(i,k,1)*dtf
1442  dt3dt(i,k,2) = dt3dt(i,k,2) + hlwd(i,k,2)*dtf
1443  dt3dt(i,k,3) = dt3dt(i,k,3) + hlwd(i,k,3)*dtf
1444  dt3dt(i,k,4) = dt3dt(i,k,4) + hlwd(i,k,4)*dtf
1445  dt3dt(i,k,5) = dt3dt(i,k,5) + hlwd(i,k,5)*dtf
1446  dt3dt(i,k,6) = dt3dt(i,k,6) + hlwd(i,k,6)*dtf
1447  enddo
1448  enddo
1449  else
1450  do k = 1, levs
1451  do i = 1, im
1452  dt3dt(i,k,1) = dt3dt(i,k,1) + hlw(i,k)*dtf
1453  dt3dt(i,k,2) = dt3dt(i,k,2) + swh(i,k)*dtf*xmu(i)
1454  enddo
1455  enddo
1456  endif
1457  endif
1458 
1459  endif ! end if_lssav_block
1460 
1461  do i = 1, im
1462  kcnv(i) = 0
1463  kinver(i) = levs
1464  invrsn(i) = .false.
1465  tx1(i) = 0.0
1466  tx2(i) = 10.0
1467  ctei_r(i) = 10.0
1468  enddo
1469 
1470 ! Only used for old shallow convection with mstrat=.true.
1471 
1472  if (((imfshalcnv == 0 .and. shal_cnv) .or. old_monin) &
1473  & .and. mstrat) then
1474  do i = 1, im
1475  ctei_rml(i) = ctei_rm(1)*work1(i) + ctei_rm(2)*work2(i)
1476  enddo
1477  do k = 1, levs/2
1478  do i = 1, im
1479  if (prsi(i,1)-prsi(i,k+1) < 0.35*prsi(i,1) &
1480  & .and. (.not. invrsn(i))) then
1481  tem = (tgrs(i,k+1)-tgrs(i,k)) / (prsl(i,k)-prsl(i,k+1))
1482 
1483  if ((tem > 0.00010 .and. tx1(i) < 0.0) .or.
1484  & (tem-abs(tx1(i)) > 0.0 .and. tx2(i) < 0.0)) then
1485  invrsn(i) = .true.
1486 
1487  if (qgrs(i,k,1) > qgrs(i,k+1,1)) then
1488  tem1 = tgrs(i,k+1) + hocp*max(qgrs(i,k+1,1),qmin)
1489  tem2 = tgrs(i,k) + hocp*max(qgrs(i,k,1),qmin)
1490 
1491  tem1 = tem1 / prslk(i,k+1) - tem2 / prslk(i,k)
1492 
1493 ! --- ... (cp/l)(deltathetae)/(deltatwater) > ctei_rm -> conditon for CTEI
1494  ctei_r(i) = (1.0/hocp)*tem1/(qgrs(i,k+1,1)-qgrs(i,k,1)&
1495  & + qgrs(i,k+1,ntcw)-qgrs(i,k,ntcw))
1496  else
1497  ctei_r(i) = 10
1498  endif
1499 
1500  if ( ctei_rml(i) > ctei_r(i) ) then
1501  kinver(i) = k
1502  else
1503  kinver(i) = levs
1504  endif
1505  endif
1506 
1507  tx2(i) = tx1(i)
1508  tx1(i) = tem
1509  endif
1510  enddo
1511  enddo
1512  endif
1513 
1514 ! --- ... check print
1515 
1516 ! ipr = 1
1517 ! if (lprnt) then
1518 ! write(0,*)' before progtm: im=',im,' lsoil=',lsoil &
1519 ! &, ' nvdiff=',nvdiff,' adjsfcnsw=',adjsfcnsw(ipr) &
1520 ! &, ' adjsfcdlw=',adjsfcdlw(ipr),'adjsfculw=',adjsfculw(ipr)&
1521 ! &, ' sfcemis=',sfcemis(ipr),' tsea2=',tsea(ipr) &
1522 ! &, ' ipr=',ipr,' me=',me,' lat=',lat,' xlon=',xlon(ipr) &
1523 ! &, ' kdt=',kdt
1524 ! write(0,*)' dtdth=',dtdt(ipr,:),' kdt=',kdt
1525 ! endif
1526 
1527 
1528 ! --- ... lu: initialize flag_guess, flag_iter, tsurf
1529 
1530  do i = 1, im
1531  tsurf(i) = tsea(i)
1532  flag_guess(i) = .false.
1533  flag_iter(i) = .true.
1534  drain(i) = 0.0
1535  ep1d(i) = 0.0
1536  runof(i) = 0.0
1537  hflx(i) = 0.0
1538  evap(i) = 0.0
1539 
1540  evbs(i) = 0.0
1541  evcw(i) = 0.0
1542  trans(i) = 0.0
1543  sbsno(i) = 0.0
1544  snowc(i) = 0.0
1545  snohf(i) = 0.0
1546  zlvl(i) = phil(i,1) / con_g
1547  smcwlt2(i) = 0.0
1548  smcref2(i) = 0.0
1549  enddo
1550 
1551 ! --- ... lu: iter-loop over (sfc_diff,sfc_drv,sfc_ocean,sfc_sice)
1552 
1553  do iter = 1, 2
1554 
1555 ! --- ... surface exchange coefficients
1556 !
1557 ! if (lprnt) write(0,*)' tsea=',tsea(ipr),' tsurf=',tsurf(ipr),iter
1558  call sfc_diff(im,pgr,ugrs,vgrs,tgrs,qgrs,zlvl, &
1559  & snwdph,tsea,zorl,cd,cdq,rb, &
1560  & prsl(1,1),work3,islmsk, &
1561  & stress,ffmm,ffhh, &
1562  & uustar,wind,phy_f2d(1,num_p2d),fm10,fh2, &
1563  & sigmaf,vegtype,shdmax,ivegsrc, &
1564  & tsurf, flag_iter, redrag)
1565 
1566 ! if (lprnt) write(0,*)' cdq=',cdq(ipr),' iter=',iter &
1567 ! &, ' wind=',wind(ipr),'phy_f2d=',phy_f2d(ipr,num_p2d),' ugrs=' &
1568 ! &, ugrs(ipr,1),' vgrs=',vgrs(ipr,1)
1569 
1570 ! --- ... lu: update flag_guess
1571 
1572  do i = 1, im
1573  if (iter == 1 .and. wind(i) < 2.0) then
1574  flag_guess(i) = .true.
1575  endif
1576  enddo
1577 
1578  if ( nstf_name(1) > 0 ) then
1579 
1580  do i = 1, im
1581  if ( islmsk(i) == 0 ) then
1582  tem = (oro(i)-oro_uf(i)) * rlapse
1583  tseal(i) = tsea(i) + tem
1584  tsurf(i) = tsurf(i) + tem
1585  endif
1586  enddo
1587 
1588 ! if (lprnt) write(0,*)' tseaz1=',tsea(ipr),' tref=',tref(ipr)
1589 ! &, ' dt_cool=',dt_cool(ipr),' dt_warm=',2.0*(xt(ipr)/xz(ipr)
1590 ! &, ' kdt=',kdt
1591 ! &, ' tgrs=',tgrs(ipr,1),' prsl=',prsl(ipr,1)
1592 ! &, ' work3=',work3(ipr),' kdt=',kdt
1593 
1594  call sfc_nst &
1595  & ( im,lsoil,pgr,ugrs,vgrs,tgrs,qgrs,tref,cd,cdq, &
1596  & prsl(1,1),work3,islmsk,xlon,sinlat,stress, &
1597  & sfcemis,gabsbdlw,adjsfcnsw,tprcp,dtf,kdt,solhr,xcosz, &
1598  & phy_f2d(1,num_p2d),flag_iter,flag_guess,nstf_name, &
1599  & lprnt,ipr, &
1600 ! --- Input/output
1601  & tseal,tsurf,xt,xs,xu,xv,xz,zm,xtts,xzts,dt_cool, &
1602  & z_c,c_0,c_d,w_0,w_d,d_conv,ifd,qrain, &
1603 ! --- outputs:
1604  & qss, gflx, cmm, chh, evap, hflx, ep1d)
1605 
1606 ! if (lprnt) print *,' tseaz2=',tseal(ipr),' tref=',tref(ipr),
1607 ! & ' dt_cool=',dt_cool(ipr),' dt_warm=',2.0*xt(ipr)/xz(ipr),
1608 ! & ' kdt=',kdt
1609 
1610  do i = 1, im
1611  if ( islmsk(i) == 0 ) then
1612  tsurf(i) = tsurf(i) - (oro(i)-oro_uf(i)) * rlapse
1613  endif
1614  enddo
1615 
1616 ! --- ... run nsst model ... ---
1617 
1618  if ( nstf_name(1) > 1 ) then
1619  zsea1 = 0.001*real(nstf_name(4))
1620  zsea2 = 0.001*real(nstf_name(5))
1621  call get_dtzm_2d(xt,xz,dt_cool,z_c,slmsk,
1622  & zsea1,zsea2,im,1,dtzm)
1623  do i = 1, im
1624  if ( islmsk(i) == 0 ) then
1625  tsea(i) = max(271.2,tref(i) + dtzm(i))
1626  & -(oro(i)-oro_uf(i))*rlapse
1627  endif
1628  enddo
1629  endif
1630 
1631 ! if (lprnt) print *,' tseaz2=',tsea(ipr),' tref=',tref(ipr), &
1632 ! & ' dt_cool=',dt_cool(ipr),' dt_warm=',dt_warm(ipr),' kdt=',kdt
1633 
1634  else
1635 
1636 ! --- ... surface energy balance over ocean
1637 
1638  call sfc_ocean &
1639 ! --- inputs:
1640  & ( im,pgr,ugrs,vgrs,tgrs,qgrs,tsea,cd,cdq, &
1641  & prsl(1,1),work3,islmsk,phy_f2d(1,num_p2d),flag_iter, &
1642 ! --- outputs:
1643  & qss,cmm,chh,gflx,evap,hflx,ep1d &
1644  & )
1645 
1646  endif ! if ( nstf_name(1) > 0 ) then
1647 
1648 ! if (lprnt) write(0,*)' sfalb=',sfalb(ipr),' ipr=',ipr &
1649 ! &, ' weasd=',weasd(ipr),' snwdph=',snwdph(ipr) &
1650 ! &, ' tprcp=',tprcp(ipr),' kdt=',kdt,' iter=',iter
1651 ! &,' tseabefland=',tsea(ipr)
1652 
1653 ! --- ... surface energy balance over land
1654 !
1655  if (lsm == 1) then ! noah lsm call
1656 
1657 ! if (lprnt) write(0,*)' tsead=',tsea(ipr),' tsurf=',tsurf(ipr),iter
1658 ! &,' pgr=',pgr(ipr),' sfcemis=',sfcemis(ipr)
1659 
1660  call sfc_drv &
1661 
1662 ! --- inputs:
1663  & ( im,lsoil,pgr,ugrs,vgrs,tgrs,qgrs,soiltyp,vegtype,sigmaf, &
1664  & sfcemis,gabsbdlw,adjsfcdsw,adjsfcnsw,dtf,tg3,cd,cdq, &
1665  & prsl(1,1),work3,zlvl,islmsk,phy_f2d(1,num_p2d),slopetyp, &
1666  & shdmin,shdmax,snoalb,sfalb,flag_iter,flag_guess, &
1667  & isot,ivegsrc, &
1668 ! --- in/outs:
1669  & weasd,snwdph,tsea,tprcp,srflag,smsoil,stsoil,slsoil, &
1670  & canopy,trans,tsurf,zorl, &
1671 ! --- outputs:
1672  & sncovr,qss,gflx,drain,evap,hflx,ep1d,runof, &
1673  & cmm,chh,evbs,evcw,sbsno,snowc,soilm,snohf, &
1674  & smcwlt2,smcref2,wet1 &
1675  & )
1676 
1677 ! if (lprnt) write(0,*)' tseae=',tsea(ipr),' tsurf=',tsurf(ipr),iter
1678 ! &,' phy_f2d=',phy_f2d(ipr,num_p2d)
1679 
1680  else ! osu lsm call
1681 
1682  call sfc_land &
1683 ! --- inputs:
1684  & ( im,lsoil,pgr,ugrs,vgrs,tgrs,qgrs,smsoil,soiltyp, &
1685  & sigmaf,vegtype,sfcemis,adjsfcdlw,adjsfcnsw,dtf, &
1686  & tg3,cd,cdq,prsl(1,1),work3,islmsk, &
1687 ! & zorl,tg3,cd,cdq,prsl(1,1),work3,islmsk, &
1688  & phy_f2d(1,num_p2d),flag_iter,flag_guess, &
1689 ! --- input/outputs:
1690  & weasd,tsea,tprcp,srflag,stsoil,canopy,tsurf, &
1691 ! --- outputs:
1692  & qss,snowmt,gflx,zsoil,rhscnpy,rhsmc, &
1693  & ai,bi,cci,drain,evap,hflx,ep1d,cmm,chh, &
1694  & evbs,evcw,trans,sbsno,snowc,soilm, &
1695  & snohf,smcwlt2,smcref2 &
1696  & )
1697 
1698  endif
1699 
1700 ! if (lprnt) write(0,*)' tseabeficemodel =',tsea(ipr),' me=',me &
1701 ! &, ' kdt=',kdt
1702 
1703 ! --- ... surface energy balance over seaice
1704 
1705  if (lssav_cpl) then
1706  do i = 1, im
1707  if (flag_cice(i)) then
1708  islmsk(i) = islmsk_cice(i)
1709  endif
1710  enddo
1711  endif
1712 
1713  call sfc_sice &
1714 ! --- inputs:
1715  & ( im,lsoil,pgr,ugrs,vgrs,tgrs,qgrs,dtf, &
1716  & sfcemis,gabsbdlw,adjsfcnsw,adjsfcdsw,srflag, &
1717  & cd,cdq,prsl(1,1),work3,islmsk,phy_f2d(1,num_p2d), &
1718  & flag_iter,mom4ice,lsm, lprnt,ipr, &
1719 ! & flag_iter,mom4ice,lsm, &
1720 ! --- input/outputs:
1721  & zice,cice,tice,weasd,tsea,tprcp,stsoil,ep1d, &
1722 ! --- outputs:
1723  & snwdph,qss,snowmt,gflx,cmm,chh,evap,hflx &
1724  & )
1725 
1726  if (lssav_cpl) then
1727  do i = 1, im
1728  if (flag_cice(i)) then
1729  islmsk(i) = nint(slmsk(i))
1730  endif
1731  enddo
1732 
1733  call sfc_cice &
1734 ! --- inputs:
1735  & ( im,ugrs,vgrs,tgrs,qgrs,cd,cdq,prsl(1,1),work3, &
1736  & islmsk_cice,phy_f2d(1,num_p2d),flag_iter, &
1737  & dqsfc_cice,dtsfc_cice, &
1738 ! --- outputs:
1739  & qss,cmm,chh,evap,hflx &
1740  & )
1741  endif
1742 
1743 ! --- ... lu: update flag_iter and flag_guess
1744 
1745  do i = 1, im
1746  flag_iter(i) = .false.
1747  flag_guess(i) = .false.
1748 
1749  if(islmsk(i) == 1 .and. iter == 1) then
1750  if (wind(i) < 2.0) flag_iter(i) = .true.
1751  elseif (islmsk(i) == 0 .and. iter == 1 &
1752  & .and. nstf_name(1) > 0) then
1753  if (wind(i) < 2.0) flag_iter(i) = .true.
1754  endif
1755  enddo
1756 
1757  enddo ! end iter_loop
1758 
1759  do i = 1, im
1760  epi(i) = ep1d(i)
1761  dlwsfci(i) = adjsfcdlw(i)
1762  ulwsfci(i) = adjsfculw(i)
1763  uswsfci(i) = adjsfcdsw(i) - adjsfcnsw(i)
1764  dswsfci(i) = adjsfcdsw(i)
1765  gfluxi(i) = gflx(i)
1766  t1(i) = tgrs(i,1)
1767  q1(i) = qgrs(i,1,1)
1768  u1(i) = ugrs(i,1)
1769  v1(i) = vgrs(i,1)
1770  enddo
1771 
1772  if (lsm == 0) then ! osu lsm call
1773  do i = 1, im
1774  sncovr(i) = 0.0
1775  if (weasd(i) > 0.0) sncovr(i) = 1.0
1776  enddo
1777  endif
1778 
1779 ! --- ... update near surface fields
1780 
1781  call sfc_diag(im,pgr,ugrs,vgrs,tgrs,qgrs, &
1782  & tsea,qss,f10m,u10m,v10m,t2m,q2m,work3, &
1783  & evap,ffmm,ffhh,fm10,fh2)
1784 
1785  do i = 1, im
1786  phy_f2d(i,num_p2d) = 0.0
1787  enddo
1788 
1789  if (lssav_cpl) then
1790  do i = 1, im
1791  dlwsfci_cpl(i) = adjsfcdlw(i)
1792  dswsfci_cpl(i) = adjsfcdsw(i)
1793  dlwsfc_cpl(i) = dlwsfc_cpl(i) + adjsfcdlw(i)*dtf
1794  dswsfc_cpl(i) = dswsfc_cpl(i) + adjsfcdsw(i)*dtf
1795  dnirbmi_cpl(i) = adjnirbmd(i)
1796  dnirdfi_cpl(i) = adjnirdfd(i)
1797  dvisbmi_cpl(i) = adjvisbmd(i)
1798  dvisdfi_cpl(i) = adjvisdfd(i)
1799  dnirbm_cpl(i) = dnirbm_cpl(i) + adjnirbmd(i)*dtf
1800  dnirdf_cpl(i) = dnirdf_cpl(i) + adjnirdfd(i)*dtf
1801  dvisbm_cpl(i) = dvisbm_cpl(i) + adjvisbmd(i)*dtf
1802  dvisdf_cpl(i) = dvisdf_cpl(i) + adjvisdfd(i)*dtf
1803  nlwsfci_cpl(i) = adjsfcdlw(i) - adjsfculw(i)
1804  nlwsfc_cpl(i) = nlwsfc_cpl(i) + nlwsfci_cpl(i)*dtf
1805  t2mi_cpl(i) = t2m(i)
1806  q2mi_cpl(i) = q2m(i)
1807  u10mi_cpl(i) = u10m(i)
1808  v10mi_cpl(i) = v10m(i)
1809  tseai_cpl(i) = tsea(i)
1810  psurfi_cpl(i) = pgr(i)
1811  enddo
1812 
1813 ! --- estimate mean albedo for ocean point without ice cover and apply
1814 ! them to net SW heat fluxes
1815 
1816  do i = 1, im
1817  if (islmsk(i) /= 1) then ! not a land point
1818 ! --- compute open water albedo
1819  xcosz_loc = max( 0.0, min( 1.0, xcosz(i) ))
1820  ocalnirdf_cpl(i) = 0.06
1821  ocalnirbm_cpl(i) = max(albdf, 0.026/(xcosz_loc**1.7+0.065) &
1822  & + 0.15 * (xcosz_loc-0.1) * (xcosz_loc-0.5) &
1823  & * (xcosz_loc-1.0))
1824  ocalvisdf_cpl(i) = 0.06
1825  ocalvisbm_cpl(i) = ocalnirbm_cpl(i)
1826 
1827  nnirbmi_cpl(i) = adjnirbmd(i)-adjnirbmd(i)*ocalnirbm_cpl(i)
1828  nnirdfi_cpl(i) = adjnirdfd(i)-adjnirdfd(i)*ocalnirdf_cpl(i)
1829  nvisbmi_cpl(i) = adjvisbmd(i)-adjvisbmd(i)*ocalvisbm_cpl(i)
1830  nvisdfi_cpl(i) = adjvisdfd(i)-adjvisdfd(i)*ocalvisdf_cpl(i)
1831  else
1832  nnirbmi_cpl(i) = adjnirbmd(i) - adjnirbmu(i)
1833  nnirdfi_cpl(i) = adjnirdfd(i) - adjnirdfu(i)
1834  nvisbmi_cpl(i) = adjvisbmd(i) - adjvisbmu(i)
1835  nvisdfi_cpl(i) = adjvisdfd(i) - adjvisdfu(i)
1836  endif
1837  nswsfci_cpl(i) = nnirbmi_cpl(i) + nnirdfi_cpl(i) &
1838  & + nvisbmi_cpl(i) + nvisdfi_cpl(i)
1839  nswsfc_cpl(i) = nswsfc_cpl(i) + nswsfci_cpl(i)*dtf
1840  nnirbm_cpl(i) = nnirbm_cpl(i) + nnirbmi_cpl(i)*dtf
1841  nnirdf_cpl(i) = nnirdf_cpl(i) + nnirdfi_cpl(i)*dtf
1842  nvisbm_cpl(i) = nvisbm_cpl(i) + nvisbmi_cpl(i)*dtf
1843  nvisdf_cpl(i) = nvisdf_cpl(i) + nvisdfi_cpl(i)*dtf
1844  enddo
1845  endif
1846 
1847  if (lssav) then
1848  do i = 1, im
1849  gflux(i) = gflux(i) + gflx(i) * dtf
1850  evbsa(i) = evbsa(i) + evbs(i) * dtf
1851  evcwa(i) = evcwa(i) + evcw(i) * dtf
1852  transa(i) = transa(i) + trans(i) * dtf
1853  sbsnoa(i) = sbsnoa(i) + sbsno(i) * dtf
1854  snowca(i) = snowca(i) + snowc(i) * dtf
1855  snohfa(i) = snohfa(i) + snohf(i) * dtf
1856  ep(i) = ep(i) + ep1d(i) * dtf
1857 
1858  tmpmax(i) = max(tmpmax(i),t2m(i))
1859  tmpmin(i) = min(tmpmin(i),t2m(i))
1860 
1861  spfhmax(i) = max(spfhmax(i),q2m(i))
1862  spfhmin(i) = min(spfhmin(i),q2m(i))
1863  enddo
1864  endif
1865 
1866 !!!!!!!!!!!!!!!!!Commented by Moorthi on July 18, 2012 !!!!!!!!!!!!!!!!!!!
1867 ! do i = 1, im
1868 ! --- ... compute coefficient of evaporation in evapc
1869 !
1870 ! if (evapc(i) > 1.0e0) evapc(i) = 1.0e0
1871 ! --- ... over snow cover or ice or sea, coef of evap =1.0e0
1872 ! if (weasd(i) > 0.0 .or. slmsk(i) /= 1.0) evapc(i) = 1.0e0
1873 ! enddo
1874 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1875 
1876 ! --- ... Boundary Layer and Free atmospheic turbulence parameterization
1877 
1878 ! if (lprnt) write(0,*)' tsea3=',tsea(ipr),' slmsk=',slmsk(ipr) &
1879 ! &, ' kdt=',kdt,' evap=',evap(ipr)
1880 ! if (lprnt) write(0,*)' dtdtb=',dtdt(ipr,1:10)
1881 
1882 ! do i = 1, im
1883 ! if (islmsk(i) == 0) then
1884 ! oro_land(i) = 0.0
1885 ! else
1886 ! oro_land(i) = oro(i)
1887 ! endif
1888 ! enddo
1889 
1890 ! write(0,*)' before monin clstp=',clstp,' kdt=',kdt,' lat=',lat
1891 
1892  if (do_shoc) then
1893  call moninshoc(ix,im,levs,ntrac,ntcw,dvdt,dudt,dtdt,dqdt, &
1894  & ugrs,vgrs,tgrs,qgrs,phy_f3d(1,1,ntot3d-1), & ! tkh
1895  & prnum,ntke, &
1896  & prsik(1,1),rb,zorl,u10m,v10m,ffmm,ffhh, &
1897  & tsea,hflx,evap,stress,wind,kpbl, &
1898  & prsi,del,prsl,prslk,phii,phil,dtp, &
1899  & dusfc1,dvsfc1,dtsfc1,dqsfc1,dkt,hpbl, &
1900  & kinver, xkzm_m, xkzm_h, xkzm_s, lprnt, ipr,me)
1901  else
1902 
1903  if (hybedmf) then
1904 
1905  call moninedmf(ix,im,levs,nvdiff,ntcw,dvdt,dudt,dtdt,dqdt, &
1906  & ugrs,vgrs,tgrs,qgrs,swh,hlw,xmu, &
1907  & prsik(1,1),rb,zorl,u10m,v10m,ffmm,ffhh, &
1908  & tsea,qss,hflx,evap,stress,wind,kpbl, &
1909  & prsi,del,prsl,prslk,phii,phil,dtp,dspheat, &
1910  & dusfc1,dvsfc1,dtsfc1,dqsfc1,hpbl,gamt,gamq,dkt, &
1911  & kinver, xkzm_m, xkzm_h, xkzm_s, lprnt, ipr)
1912 
1913  elseif (.not. old_monin) then
1914 
1915  call moninq(ix,im,levs,nvdiff,ntcw,dvdt,dudt,dtdt,dqdt, &
1916  & ugrs,vgrs,tgrs,qgrs,swh,hlw,xmu, &
1917  & prsik(1,1),rb,ffmm,ffhh, &
1918  & tsea,qss,hflx,evap,stress,wind,kpbl, &
1919  & prsi,del,prsl,prslk,phii,phil,dtp,dspheat, &
1920  & dusfc1,dvsfc1,dtsfc1,dqsfc1,hpbl,gamt,gamq,dkt, &
1921  & kinver, xkzm_m, xkzm_h, xkzm_s, lprnt, ipr)
1922 
1923  else
1924 
1925  if (mstrat) then
1926  call moninp1(ix,im,levs,nvdiff,dvdt,dudt,dtdt,dqdt, &
1927  & ugrs,vgrs,tgrs,qgrs, &
1928  & prsik(1,1),rb,ffmm,ffhh,tsea,qss,hflx,evap,stress,wind, &
1929  & kpbl,prsi,del,prsl,prslk,phii,phil,dtp, &
1930  & dusfc1,dvsfc1,dtsfc1,dqsfc1,hpbl,gamt,gamq,dkt, &
1931  & kinver, xkzm_m, xkzm_h)
1932 ! & kinver, oro_land, ctei_r, ctei_rm, xkzm_m, xkzm_h)
1933  else
1934  call moninp(ix,im,levs,nvdiff,dvdt,dudt,dtdt,dqdt, &
1935  & ugrs,vgrs,tgrs,qgrs, &
1936  & prsik(1,1),rb,ffmm,ffhh,tsea,qss,hflx,evap,stress,wind, &
1937  & kpbl,prsi,del,prsl,phii,phil,dtp, &
1938  & dusfc1,dvsfc1,dtsfc1,dqsfc1,hpbl,gamt,gamq,dkt, &
1939  & xkzm_m,xkzm_h)
1940  endif
1941 
1942  endif ! end if_hybedmf
1943  endif ! end if_do_shoc
1944 
1945  if (lssav_cpl) then
1946  do i = 1, im
1947  if (flag_cice(i)) then
1948  cice(i) = fice_cice(i)
1949  tsea(i) = tsea_cice(i)
1950  dusfc1(i) = dusfc_cice(i)
1951  dvsfc1(i) = dvsfc_cice(i)
1952  dqsfc1(i) = dqsfc_cice(i)
1953  dtsfc1(i) = dtsfc_cice(i)
1954  endif
1955  enddo
1956  endif
1957 
1958 ! if (lprnt) then
1959 ! write(0,*) ' dusfc1=',dusfc1(ipr),' kdt=',kdt,' lat=',lat
1960 ! write(0,*)' dtsfc1=',dtsfc1(ipr)
1961 ! write(0,*)' dqsfc1=',dqsfc1(ipr)
1962 ! write(0,*)' dtdt=',dtdt(ipr,1:10)
1963 ! print *,' dudtm=',dudt(ipr,:)
1964 ! endif
1965 
1966 ! --- ... coupling insertion
1967 
1968  if (lssav_cpl) then
1969  do i=1, im
1970  dusfc_cpl(i) = dusfc_cpl(i) + dusfc1(i)*dtf
1971  dvsfc_cpl(i) = dvsfc_cpl(i) + dvsfc1(i)*dtf
1972  dtsfc_cpl(i) = dtsfc_cpl(i) + dtsfc1(i)*dtf
1973  dqsfc_cpl(i) = dqsfc_cpl(i) + dqsfc1(i)*dtf
1974  dusfci_cpl(i) = dusfc1(i)
1975  dvsfci_cpl(i) = dvsfc1(i)
1976  dtsfci_cpl(i) = dtsfc1(i)
1977  dqsfci_cpl(i) = dqsfc1(i)
1978  enddo
1979  endif
1980 !-------------------------------------------------------lssav if loop ----------
1981  if (lssav) then
1982  do i = 1, im
1983  dusfc(i) = dusfc(i) + dusfc1(i)*dtf
1984  dvsfc(i) = dvsfc(i) + dvsfc1(i)*dtf
1985  dtsfc(i) = dtsfc(i) + dtsfc1(i)*dtf
1986  dqsfc(i) = dqsfc(i) + dqsfc1(i)*dtf
1987  dusfci(i) = dusfc1(i)
1988  dvsfci(i) = dvsfc1(i)
1989  dtsfci(i) = dtsfc1(i)
1990  dqsfci(i) = dqsfc1(i)
1991  enddo
1992 ! if (lprnt) then
1993 ! write(0,*)' dusfc=',dusfc(ipr),' dusfc1=',dusfc1(ipr),' dtf=',
1994 ! & dtf,' kdt=',kdt,' lat=',lat
1995 ! endif
1996 
1997  if (ldiag3d) then
1998 
1999  if (lsidea) then
2000  do k = 1, levs
2001  do i = 1, im
2002  dt3dt(i,k,3) = dt3dt(i,k,3) + dtdt(i,k)*dtf
2003  enddo
2004  enddo
2005  else
2006  do k = 1, levs
2007  do i = 1, im
2008  tem = dtdt(i,k) - (hlw(i,k)+swh(i,k)*xmu(i))
2009  dt3dt(i,k,3) = dt3dt(i,k,3) + tem*dtf
2010  enddo
2011  enddo
2012  endif
2013  do k = 1, levs
2014  do i = 1, im
2015  du3dt(i,k,1) = du3dt(i,k,1) + dudt(i,k) * dtf
2016  du3dt(i,k,2) = du3dt(i,k,2) - dudt(i,k) * dtf
2017  dv3dt(i,k,1) = dv3dt(i,k,1) + dvdt(i,k) * dtf
2018  dv3dt(i,k,2) = dv3dt(i,k,2) - dvdt(i,k) * dtf
2019  enddo
2020  enddo
2021 ! update dqdt_v to include moisture tendency due to vertical diffusion
2022 ! if (lgocart) then
2023 ! do k = 1, levs
2024 ! do i = 1, im
2025 ! dqdt_v(i,k) = dqdt(i,k,1) * dtf
2026 ! enddo
2027 ! enddo
2028 ! endif
2029  do k = 1, levs
2030  do i = 1, im
2031  tem = dqdt(i,k,1) * dtf
2032  dq3dt(i,k,1) = dq3dt(i,k,1) + tem
2033 ! dqdt_v(i,k) = tem
2034  enddo
2035  enddo
2036  if (ntoz > 0) then
2037  do k = 1, levs
2038  do i = 1, im
2039  dq3dt(i,k,5) = dq3dt(i,k,5) + dqdt(i,k,ntoz) * dtf
2040  enddo
2041  enddo
2042  endif
2043  endif
2044 
2045  endif ! end if_lssav
2046 !-------------------------------------------------------lssav if loop ----------
2047 !
2048 ! Orographic gravity wave drag parameterization
2049 ! ---------------------------------------------
2050 
2051  if (nmtvr == 14) then ! current operational - as of 2014
2052 
2053  do i = 1, im
2054  oc(i) = hprime(i,2)
2055  enddo
2056  do k = 1, 4
2057  do i = 1, im
2058  oa4(i,k) = hprime(i,k+2)
2059  clx(i,k) = hprime(i,k+6)
2060  enddo
2061  enddo
2062  do i = 1, im
2063  theta(i) = hprime(i,11)
2064  gamma(i) = hprime(i,12)
2065  sigma(i) = hprime(i,13)
2066  elvmax(i) = hprime(i,14)
2067  enddo
2068 
2069  elseif (nmtvr == 10) then
2070 
2071  do i = 1, im
2072  oc(i) = hprime(i,2)
2073  enddo
2074  do k = 1, 4
2075  do i = 1, im
2076  oa4(i,k) = hprime(i,k+2)
2077  clx(i,k) = hprime(i,k+6)
2078  enddo
2079  enddo
2080 
2081  elseif (nmtvr == 6) then
2082 
2083  do i = 1, im
2084  oc(i) = hprime(i,2)
2085  enddo
2086  do k = 1, 4
2087  do i = 1, im
2088  oa4(i,k) = hprime(i,k+2)
2089  clx(i,k) = 0.0
2090  enddo
2091  enddo
2092 
2093  else
2094 
2095  oc = 0 ; oa4 = 0 ; clx = 0 ; theta = 0 ; gamma = 0 ; sigma = 0
2096  elvmax = 0
2097 
2098  endif ! end if_nmtvr
2099 
2100 ! write(0,*)' before gwd clstp=',clstp,' kdt=',kdt,' lat=',lat
2101  call gwdps(im, ix, im, levs, dvdt, dudt, dtdt, &
2102  & ugrs, vgrs, tgrs, qgrs, &
2103  & kpbl, prsi, del, prsl, prslk, &
2104  & phii, phil, dtp, &
2105  & kdt, hprime(1,1), oc, oa4, clx, &
2106  & theta,sigma,gamma,elvmax,dusfcg, dvsfcg, &
2107  & con_g,con_cp,con_rd,con_rv, lonr, nmtvr, cdmbgwd, &
2108  & me, lprnt,ipr)
2109 
2110 ! if (lprnt) print *,' dudtg=',dudt(ipr,:)
2111 
2112  if (lssav) then
2113  do i = 1, im
2114  dugwd(i) = dugwd(i) + dusfcg(i)*dtf
2115  dvgwd(i) = dvgwd(i) + dvsfcg(i)*dtf
2116  enddo
2117 
2118 ! if (lprnt) print *,' dugwd=',dugwd(ipr),' dusfcg=',dusfcg(ipr)
2119 ! if (lprnt) print *,' dvgwd=',dvgwd(ipr),' dvsfcg=',dvsfcg(ipr)
2120 
2121  if (ldiag3d) then
2122  do k = 1, levs
2123  do i = 1, im
2124  du3dt(i,k,2) = du3dt(i,k,2) + dudt(i,k) * dtf
2125  dv3dt(i,k,2) = dv3dt(i,k,2) + dvdt(i,k) * dtf
2126  dt3dt(i,k,2) = dt3dt(i,k,2) + dtdt(i,k) * dtf
2127  enddo
2128  enddo
2129  endif
2130  endif
2131 
2132 ! Rayleigh damping near the model top
2133  if( .not. lsidea .and. ral_ts > 0.0) then
2134 ! call rayleigh_damp_mesopause(im, ix, im, levs, dvdt, dudt, dtdt,
2135 ! & ugrs, vgrs, dtp, con_cp, levr, prsl, prslrd0)
2136 ! else
2137  call rayleigh_damp(im, ix, im, levs, dvdt, dudt, dtdt, ugrs,
2138  & vgrs, dtp, con_cp, levr, pgr, prsl,
2139  & prslrd0, ral_ts)
2140  endif
2141 
2142 ! if (lprnt) then
2143 ! write(0,*)' tgrs1=',tgrs(ipr,1:10)
2144 ! write(0,*)' dtdt=',dtdt(ipr,1:10)
2145 ! endif
2146 
2147  do k = 1, levs
2148  do i = 1, im
2149  gt0(i,k) = tgrs(i,k) + dtdt(i,k) * dtp
2150  gu0(i,k) = ugrs(i,k) + dudt(i,k) * dtp
2151  gv0(i,k) = vgrs(i,k) + dvdt(i,k) * dtp
2152  enddo
2153  enddo
2154 
2155  do n = 1, ntrac
2156  do k = 1, levs
2157  do i = 1, im
2158  gq0(i,k,n) = qgrs(i,k,n) + dqdt(i,k,n) * dtp
2159  enddo
2160  enddo
2161  enddo
2162 ! if(lprnt) write(0,*)' gq0i=',gq0(ipr,:,ntiw)
2163 
2164  if( lsidea ) then ! idea convective adjustment
2165  call ideaca_up(prsi,gt0,ix,im,levs+1)
2166  endif
2167 
2168 ! --- ... check print
2169 
2170 ! if (me == 0) then
2171 ! sumq = 0.0
2172 ! do k = 1, levs
2173 ! do i = 1, im
2174 ! sumq = sumq + (dqdt(i,k,1)+dqdt(i,k,ntcw)) * del(i,k)
2175 ! enddo
2176 ! enddo
2177 
2178 ! sume = 0.0
2179 ! do i = 1, im
2180 ! sume = sume + dqsfc1(i)
2181 ! enddo
2182 
2183 ! sumq = sumq * 1000.0 / con_g
2184 ! sume = sume / con_hvap
2185 ! print *,' after mon: sumq=',sumq,' sume=',sume, ' kdt=',kdt
2186 ! endif
2187 
2188 ! --- ... ozone physics
2189 
2190  if (ntoz > 0 .and. ntrac >= ntoz) then
2191 
2192  if (pl_coeff > 4) then
2193 
2194  call ozphys_2015(ix,im,levs,ko3,dtp,gq0(1,1,ntoz),gq0(1,1,ntoz)&
2195  &, gt0, poz, prsl, prdoz, pl_coeff, del, ldiag3d &
2196  &, dq3dt(1,1,6), me)
2197  else
2198 
2199  call ozphys(ix,im,levs,ko3,dtp,gq0(1,1,ntoz),gq0(1,1,ntoz) &
2200  &, gt0, poz, prsl, prdoz, pl_coeff, del, ldiag3d &
2201  &, dq3dt(1,1,6), me)
2202 
2203  endif
2204  endif
2205 
2206 
2207  if (h2o_phys) then
2208 
2209  call h2ophys(ix,im,levs,levh2o,dtp,gq0(1,1,1),gq0(1,1,1)
2210  &, h2o_pres,prsl,h2opl,h2o_coeff,ldiag3d
2211  &, dq3dt(1,1,1), me)
2212  endif
2213 
2214 ! --- ... to side-step the ozone physics
2215 
2216 ! if (ntrac >= 2) then
2217 ! do k = 1, levs
2218 ! gq0(k,ntoz) = qgrs(k,ntoz)
2219 ! enddo
2220 ! endif
2221 
2222 ! if (lprnt) then
2223 ! write(0,*) ' levs=',levs,' jcap=',jcap,' dtp',dtp &
2224 ! &, ' slmsk=',slmsk(ilon,ilat),' kdt=',kdt
2225 ! print *,' rann=',rann,' ncld=',ncld,' iq=',iq,' lat=',lat
2226 ! print *,' pgr=',pgr
2227 ! print *,' del=',del(ipr,:)
2228 ! print *,' prsl=',prsl(ipr,:)
2229 ! print *,' prslk=',prslk(ipr,:)
2230 ! print *,' rann=',rann(ipr,1)
2231 ! write(0,*)' gt0=',gt0(ipr,:) &
2232 ! &, ' kdt=',kdt,' xlon=',xlon(ipr),' xlat=',xlat(ipr)
2233 ! print *,' dtdt=',dtdt(ipr,:)
2234 ! print *,' gu0=',gu0(ipr,:)
2235 ! print *,' gv0=',gv0(ipr,:)
2236 ! write(0,*)' gq0=',(gq0(ipr,k,1),k=1,levs),' lat=',lat
2237 ! write(0,*)' gq0i2=',(gq0(ipr,k,ntiw),k=1,levs),' lat=',lat
2238 ! print *,' gq1=',(gq0(ipr,k,ntcw),k=1,levs)
2239 ! print *,' vvel=',vvel
2240 ! endif
2241 
2242  if (ldiag3d) then
2243 
2244  do k = 1, levs
2245  do i = 1, im
2246  dtdt(i,k) = gt0(i,k)
2247 ! dqdt(i,k,1) = gq0(i,k,1)
2248  dudt(i,k) = gu0(i,k)
2249  dvdt(i,k) = gv0(i,k)
2250  enddo
2251  enddo
2252 
2253  elseif (cnvgwd) then
2254 
2255  do k = 1, levs
2256  do i = 1, im
2257  dtdt(i,k) = gt0(i,k)
2258  enddo
2259  enddo
2260 
2261  endif ! end if_ldiag3d/cnvgwd
2262 
2263  if (ldiag3d .or. lgocart) then
2264  do k = 1, levs
2265  do i = 1, im
2266  dqdt(i,k,1) = gq0(i,k,1)
2267  enddo
2268  enddo
2269  endif ! end if_ldiag3d/lgocart
2270 
2271  call get_phi(im,ix,levs,ntrac,gt0,gq0, &
2272  & thermodyn_id, sfcpress_id, &
2273  & gen_coord_hybrid, &
2274  & prsi,prsik,prsl,prslk,phii,phil)
2275 
2276 ! if (lprnt) then
2277 ! print *,' phii2=',phii(ipr,:)
2278 ! print *,' phil2=',phil(ipr,:)
2279 ! endif
2280 
2281  do k = 1, levs
2282  do i = 1, im
2283  clw(i,k,1) = 0.0
2284  clw(i,k,2) = -999.9
2285  enddo
2286  enddo
2287  if (.not. ras .or. .not. cscnv) then
2288  do k = 1, levs
2289  do i = 1, im
2290  cnvc(i,k) = 0.0
2291  cnvw(i,k) = 0.0
2292  enddo
2293  enddo
2294  endif
2295 
2296 ! write(0,*)' before cnv clstp=',clstp,' kdt=',kdt,' lat=',lat
2297 
2298 ! --- ... for convective tracer transport (while using ras)
2299 
2300  if (ras .or. cscnv) then
2301  if (tottracer > 0) then
2302 
2303  if (ntoz > 0) then
2304  do k=1,levs
2305  do i=1,im
2306  clw(i,k,3) = gq0(i,k,ntoz)
2307  enddo
2308  enddo
2309 
2310  if (tracers > 0) then
2311  do n = 1, tracers
2312  do k=1,levs
2313  do i=1,im
2314  clw(i,k,3+n) = gq0(i,k,n+trc_shft)
2315  enddo
2316  enddo
2317  enddo
2318  endif
2319  else
2320  do n = 1, tracers
2321  do k=1,levs
2322  do i=1,im
2323  clw(i,k,2+n) = gq0(i,k,n+trc_shft)
2324  enddo
2325  enddo
2326  enddo
2327  endif
2328 
2329  endif
2330  endif ! end if_ras or cfscnv
2331 
2332  do i = 1, im
2333  ktop(i) = 1
2334  kbot(i) = levs
2335  enddo
2336 
2337 ! --- ... calling condensation/precipitation processes
2338 ! --------------------------------------------
2339 
2340  if (ntcw > 0) then
2341 
2342  do k = 1, levs
2343  do i = 1, im
2344  tem = rhbbot - (rhbbot-rhbtop) * (1.0-prslk(i,k))
2345  tem = rhc_max * work1(i) + tem * work2(i)
2346  rhc(i,k) = max(0.0, min(1.0,tem))
2347  enddo
2348  enddo
2349 
2350  if (ncld == 2) then
2351  do k = 1, levs
2352  do i = 1, im
2353  clw(i,k,1) = gq0(i,k,ntiw) ! ice
2354  clw(i,k,2) = gq0(i,k,ntcw) ! water
2355  enddo
2356  enddo
2357  else
2358 
2359  if (num_p3d == 3) then ! brad ferrier's microphysics
2360 
2361 ! --- ... algorithm to separate different hydrometeor species
2362 
2363  do k = 1, levs
2364  do i = 1, im
2365  wc = gq0(i,k,ntcw)
2366  qi = 0.
2367  qr = 0.
2368  qw = 0.
2369  f_ice = max(0.0, min(1.0, phy_f3d(i,k,1)))
2370  f_rain = max(0.0, min(1.0, phy_f3d(i,k,2)))
2371 
2372  qi = f_ice*wc
2373  qw = wc-qi
2374  if (qw > 0.0) then
2375  qr = f_rain*qw
2376  qw = qw-qr
2377  endif
2378 
2379 ! if (f_ice >= 1.0) then
2380 ! qi = wc
2381 ! elseif (f_ice <= 0.0) then
2382 ! qw = wc
2383 ! else
2384 ! qi = f_ice*wc
2385 ! qw = wc-qi
2386 ! endif
2387 
2388 ! if (qw > 0.0 .and. f_rain > 0.0) then
2389 ! if (f_rain >= 1.0) then
2390 ! qr = qw
2391 ! qw = 0.0
2392 ! else
2393 ! qr = f_rain*qw
2394 ! qw = qw-qr
2395 ! endif
2396 ! endif
2397 
2398  qr_col(i,k) = qr
2399 ! clw(i,k) = qi + qw
2400  clw(i,k,1) = qi
2401  clw(i,k,2) = qw
2402 
2403 ! --- ... array to track fraction of "cloud" in the form of ice
2404 
2405 ! if (qi+qw > epsq) then
2406 ! fc_ice(i,k) = qi / (qi+qw)
2407 ! else
2408 ! fc_ice(i,k) = 0.0
2409 ! endif
2410  enddo
2411  enddo
2412 
2413  elseif (num_p3d == 4) then ! zhao-carr microphysics
2414 
2415  do i = 1, im
2416  psautco_l(i) = psautco(1)*work1(i) + psautco(2)*work2(i)
2417  prautco_l(i) = prautco(1)*work1(i) + prautco(2)*work2(i)
2418  enddo
2419  do k = 1, levs
2420  do i = 1, im
2421  clw(i,k,1) = gq0(i,k,ntcw)
2422  enddo
2423  enddo
2424 
2425  endif ! end if_num_p3d
2426  endif ! end if (ncld == 2)
2427 
2428  else ! if_ntcw
2429 
2430  do i = 1, im
2431  psautco_l(i) = psautco(1)*work1(i) + psautco(2)*work2(i)
2432  prautco_l(i) = prautco(1)*work1(i) + prautco(2)*work2(i)
2433  enddo
2434  do k = 1, levs
2435  do i = 1, im
2436  rhc(i,k) = 1.0
2437  enddo
2438  enddo
2439 
2440  endif ! end if_ntcw
2441 !
2442 ! Call SHOC if do_shoc is true and shocaftcnv is false
2443 !
2444  if (do_shoc .and. .not. shocaftcnv) then
2445 
2446  if (ncld == 2) then
2447  skip_macro = do_shoc
2448  do k = 1, levs
2449  do i = 1, im
2450  clw(i,k,1) = gq0(i,k,ntiw) ! ice
2451  clw(i,k,2) = gq0(i,k,ntcw) ! water
2452  ncpl(i,k) = gq0(i,k,ntlnc)
2453  ncpi(i,k) = gq0(i,k,ntinc)
2454  enddo
2455  enddo
2456  elseif (num_p3d == 4) then
2457  do k=1,levs
2458  do i=1,im
2459  qpl(i,k) = 0.0
2460  qpi(i,k) = 0.0
2461  tem = gq0(i,k,ntcw) &
2462  & * max(0.0, min(1.0, (tcr-gt0(i,k))*tcrf))
2463  clw(i,k,1) = tem ! ice
2464  clw(i,k,2) = gq0(i,k,ntcw) - tem ! water
2465  enddo
2466  enddo
2467  endif
2468 
2469 ! dtshoc = 60.0
2470 ! dtshoc = 120.0
2471 ! dtshoc = dtp
2472 ! nshocm = (dtp/dtshoc) + 0.001
2473 ! dtshoc = dtp / nshocm
2474 ! do nshoc=1,nshocm
2475 ! if (lprnt) write(1000+me,*)' before shoc tke=',clw(ipr,:,ntk),
2476 ! &' kdt=',kdt,' lat=',lat,'xlon=',xlon(ipr),' xlat=',xlat(ipr)
2477 
2478 ! phy_f3d(1,1,ntot3d-2) - shoc determined sgs clouds
2479 ! phy_f3d(1,1,ntot3d-1) - shoc determined diffusion coefficients
2480 ! phy_f3d(1,1,ntot3d ) - shoc determined w'theta'
2481 !
2482 ! call shoc(ix, im, 1, levs, levs+1, dtshoc, me, lat, &
2483  call shoc(ix, im, 1, levs, levs+1, dtp, me, lat, &
2484  & prsl(1,1), phii(1,1), phil(1,1), &
2485  & gu0(1,1),gv0(1,1), vvel(1,1), gt0(1,1), gq0(1,1,1), &
2486  & clw(1,1,1), clw(1,1,2), qpi, qpl,rhc, sup, &
2487  & phy_f3d(1,1,ntot3d-2), clw(1,1,ntk), hflx, evap, &
2488  & prnum, phy_f3d(1,1,ntot3d-1), phy_f3d(1,1,ntot3d), &
2489  & lprnt, ipr, ncpl, ncpi)
2490 
2491  if (ntlnc > 0 .and. ntinc > 0 .and. ncld >=2) then
2492  do k=1,levs
2493  do i=1,im
2494  gq0(i,k,ntlnc) = ncpl(i,k)
2495  gq0(i,k,ntinc) = ncpi(i,k)
2496  enddo
2497  enddo
2498  endif
2499 ! do k=1,levs
2500 ! do i=1,im
2501 ! sgs_cld(i,k) = sgs_cld(i,k) + shoc_cld(i,k)
2502 ! enddo
2503 ! enddo
2504 ! if (lprnt) write(0,*)' gt03=',gt0(ipr,1:10)
2505 ! if (lprnt) write(0,*)' tke=',clw(ipr,1:10,ntk)
2506 
2507 ! if (lprnt) write(1000+me,*)' after shoc tke=',clw(1,:,ntk),
2508 ! &' kdt=',kdt
2509 ! enddo
2510 !
2511 ! do k=1,levs
2512 ! write(1000+me,*)' maxcld=',maxval(sgs_cld(1:im,k)),
2513 ! write(1000+me,*)' maxtkh=',maxval(phy_f3d(1:im,k,ntot3d-1)),
2514 ! &' k=',k,' kdt=',kdt,' lat=',lat
2515 ! enddo
2516 
2517 ! write(0,*)' aft shoc gt0=',gt0(1,:),' lat=',lat
2518 ! write(0,*)' aft shoc gq0=',gq0(1,:,1),' lat=',lat
2519 ! write(0,*)' aft shoc gu0=',gu0(1,:),' lat=',lat
2520 !
2521  endif ! if(do_shoc)
2522 
2523 
2524 ! --- ... calling convective parameterization
2525 !
2526  if (.not. ras .and. .not. cscnv) then
2527 
2528  if (imfdeepcnv == 1) then ! no random cloud top
2529  call sascnvn(im,ix,levs,jcap,dtp,del,prsl,pgr,phil, &
2530  & clw,gq0,gt0,gu0,gv0,cld1d, &
2531  & rain1,kbot,ktop,kcnv,islmsk, &
2532  & vvel,ncld,ud_mf,dd_mf,dt_mf,cnvw,cnvc)
2533  elseif (imfdeepcnv == 2) then
2534  call mfdeepcnv(im,ix,levs,dtp,del,prsl,pgr,phil, &
2535  & clw,gq0,gt0,gu0,gv0,cld1d, &
2536  & rain1,kbot,ktop,kcnv,islmsk,garea, &
2537  & vvel,ncld,ud_mf,dd_mf,dt_mf,cnvw,cnvc)
2538 ! if (lprnt) print *,' rain1=',rain1(ipr)
2539  elseif (imfdeepcnv == 0) then ! random cloud top
2540  call sascnv(im,ix,levs,jcap,dtp,del,prsl,pgr,phil, &
2541  & clw,gq0,gt0,gu0,gv0,cld1d, &
2542  & rain1,kbot,ktop,kcnv,islmsk, &
2543  & vvel,rann,ncld,ud_mf,dd_mf,dt_mf,cnvw,cnvc)
2544 ! if (lprnt) print *,' rain1=',rain1(ipr),' rann=',rann(ipr,1)
2545  endif
2546 
2547  else ! ras or cscnv
2548 
2549  if(cscnv) then ! Chikira-Sugiyama convection scheme (via CSU)
2550 
2551 ! fscav(:) = 0.0
2552 ! fswtr(:) = 0.0
2553  call cs_convr( & !DD
2554  & ix ,im ,levs , tottracer+3 , & !DD
2555  & gt0 ,gq0 ,rain1 , clw , & !DD
2556  & phil ,phii , & !DD
2557  & prsl ,prsi , & !DD
2558  & dtp ,dtf , & !DD
2559  & ud_mf ,dd_mf ,dt_mf , & !DD
2560  & gu0 ,gv0 ,fscav, fswtr, & !DD
2561 ! & phy_fctd, me ) !DD & moorthi
2562  & phy_fctd, me, wcbmax ) !DD & moorthi
2563 ! & phy_fctd ) !DD
2564  do i = 1,im !DD
2565  rain1(i) = rain1(i) * (dtp*0.001) !DD
2566  enddo
2567 
2568  else ! ras version 2
2569 
2570  if (ccwf(1) >= 0.0 .or. ccwf(2) >= 0 ) then
2571  do i=1,im
2572  ccwfac(i) = ccwf(1)*work1(i) + ccwf(2)*work2(i)
2573  dlqfac(i) = dlqf(1)*work1(i) + dlqf(2)*work2(i)
2574  lmh(i) = levs
2575  enddo
2576  else
2577  do i=1,im
2578  ccwfac(i) = -999.0
2579  dlqfac(i) = 0.0
2580  lmh(i) = levs
2581  enddo
2582  endif
2583 ! if (lprnt) write(0,*) ' calling ras for kdt=',kdt,' me=',me &
2584 ! &, ' lprnt=',lprnt,' ccwfac=',ccwfac(ipr)
2585 
2586  revap = .true.
2587 ! if (ncld ==2) revap = .false.
2588  call rascnv(im, ix, levs, dtp, dtf, rann &
2589  &, gt0, gq0, gu0, gv0, clw, tottracer, fscav &
2590  &, prsi, prsl, prsik, prslk, phil, phii &
2591  &, kpbl, cd, rain1, kbot, ktop, kcnv &
2592  &, phy_f2d(1,num_p2d), flipv, pa2mb &
2593  &, me, garea, lmh, ccwfac, nrcm, rhc &
2594  &, ud_mf, dd_mf, dt_mf, dlqfac, lprnt, ipr, kdt,revap&
2595  &, qlcn, qicn, w_upi,cf_upi, cnv_mfd, cnv_prc3 &
2596  &, cnv_dqldt,clcn,cnv_fice,cnv_ndrop,cnv_nice,ncld )
2597  endif
2598 
2599 ! if(lprnt) write(0,*)' after ras rain1=',rain1(ipr)
2600 ! &,' cnv_prc3sum=',sum(cnv_prc3(ipr,1:levs))
2601 ! if (lprnt) write(0,*)' gt04=',gt0(ipr,1:10)
2602 
2603  cld1d = 0
2604 
2605  if (lgocart) then
2606  do k = 1, levs
2607  do i = 1, im
2608  upd_mf(i,k) = upd_mf(i,k) + ud_mf(i,k) * frain
2609  dwn_mf(i,k) = dwn_mf(i,k) + dd_mf(i,k) * frain
2610  det_mf(i,k) = det_mf(i,k) + dt_mf(i,k) * frain
2611  cnvqc_v(i,k) = cnvqc_v(i,k) + (clw(i,k,1)+clw(i,k,2)- &
2612  & gq0(i,k,ntcw)) * frain
2613  enddo
2614  enddo
2615  endif ! if (lgocart)
2616 
2617 ! --- ... update the tracers due to convective transport
2618 
2619  if (tottracer > 0) then
2620  if (ntoz > 0) then ! for ozone
2621  do k=1,levs
2622  do i=1,im
2623  gq0(i,k,ntoz) = clw(i,k,3)
2624  enddo
2625  enddo
2626 
2627  if (tracers > 0) then ! for other tracers
2628  do n = 1, tracers
2629  do k=1,levs
2630  do i=1,im
2631  gq0(i,k,n+trc_shft) = clw(i,k,3+n)
2632  enddo
2633  enddo
2634  enddo
2635  endif
2636  else
2637  do n = 1, tracers
2638  do k=1,levs
2639  do i=1,im
2640  gq0(i,k,n+trc_shft) = clw(i,k,2+n)
2641  enddo
2642  enddo
2643  enddo
2644  endif
2645  endif
2646  endif ! end if_not_ras
2647 !
2648  do i = 1, im
2649  rainc(i) = frain * rain1(i)
2650  enddo
2651 
2652 !
2653  if (lssav) then
2654  do i = 1, im
2655  cldwrk(i) = cldwrk(i) + cld1d(i) * dtf
2656  cnvprcp(i) = cnvprcp(i) + rainc(i)
2657  enddo
2658 
2659  if (ldiag3d) then
2660  do k = 1, levs
2661  do i = 1, im
2662  dt3dt(i,k,4) = dt3dt(i,k,4) + (gt0(i,k)-dtdt(i,k)) * frain
2663  dq3dt(i,k,2) = dq3dt(i,k,2) + (gq0(i,k,1)-dqdt(i,k,1)) &
2664  & * frain
2665  du3dt(i,k,3) = du3dt(i,k,3) + (gu0(i,k)-dudt(i,k)) * frain
2666  dv3dt(i,k,3) = dv3dt(i,k,3) + (gv0(i,k)-dvdt(i,k)) * frain
2667 
2668  upd_mf(i,k) = upd_mf(i,k) + ud_mf(i,k) * (con_g*frain)
2669  dwn_mf(i,k) = dwn_mf(i,k) + dd_mf(i,k) * (con_g*frain)
2670  det_mf(i,k) = det_mf(i,k) + dt_mf(i,k) * (con_g*frain)
2671 
2672  enddo
2673  enddo
2674  endif ! if (ldiag3d)
2675 
2676  endif ! end if_lssav
2677 !
2678 ! update dqdt_v to include moisture tendency due to deep convection
2679  if (lgocart) then
2680  do k = 1, levs
2681  do i = 1, im
2682  dqdt_v(i,k) = (gq0(i,k,1)-dqdt(i,k,1)) * frain
2683  upd_mf(i,k) = upd_mf(i,k) + ud_mf(i,k) * frain
2684  dwn_mf(i,k) = dwn_mf(i,k) + dd_mf(i,k) * frain
2685  det_mf(i,k) = det_mf(i,k) + dt_mf(i,k) * frain
2686  cnvqc_v(i,k) = cnvqc_v(i,k) + (clw(i,k,1)+clw(i,k,2))
2687  & *frain
2688  enddo
2689  enddo
2690  endif ! if (lgocart)
2691 !
2692  if(npdf3d == 3 .and. num_p3d == 4) then
2693  num2 = num_p3d + 2
2694  num3 = num2 + 1
2695  do k = 1, levs
2696  do i = 1, im
2697  phy_f3d(i,k,num2) = cnvw(i,k)
2698  phy_f3d(i,k,num3) = cnvc(i,k)
2699  enddo
2700  enddo
2701  else if(npdf3d == 0 .and. ncnvcld3d == 1) then
2702  num2 = num_p3d + 1
2703  do k = 1, levs
2704  do i = 1, im
2705  phy_f3d(i,k,num2) = cnvw(i,k)
2706  enddo
2707  enddo
2708  endif
2709 
2710 !
2711 !----------------Convective gravity wave drag parameterization starting --------
2712 
2713  if (cnvgwd) then ! call convective gravity wave drag
2714 
2715 ! --- ... calculate maximum convective heating rate qmax [k/s]
2716 ! cuhr = temperature change due to deep convection
2717 
2718  do i = 1, im
2719 ! qmax(i) = 0.
2720  cumabs(i) = 0.0
2721  work3(i) = 0.0
2722  enddo
2723 
2724  do k = 1, levs
2725  do i = 1, im
2726 ! cuhr(i,k) = (gt0(i,k)-dtdt(i,k)) / dtf
2727 ! cuhr(i,k) = (gt0(i,k)-dtdt(i,k)) / dtp ! moorthi
2728 
2729 ! cumchr(i,k) = 0.
2730 ! gwdcu(i,k) = 0.
2731 ! gwdcv(i,k) = 0.
2732 ! diagn1(i,k) = 0.
2733 ! diagn2(i,k) = 0.
2734 
2735  if (k >= kbot(i) .and. k <= ktop(i)) then
2736 ! qmax(i) = max(qmax(i),cuhr(i,k))
2737 ! cumabs(i) = cuhr(i,k) + cumabs(i)
2738  cumabs(i) = cumabs(i) + (gt0(i,k)-dtdt(i,k)) * del(i,k)
2739  work3(i) = work3(i) + del(i,k)
2740  endif
2741  enddo
2742  enddo
2743  do i=1,im
2744  if (work3(i) > 0.0) cumabs(i) = cumabs(i) / (dtp*work3(i))
2745  enddo
2746 
2747 ! do i = 1, im
2748 ! do k = kbot(i), ktop(i)
2749 ! do k1 = kbot(i), k
2750 ! cumchr(i,k) = cuhr(i,k1) + cumchr(i,k)
2751 ! enddo
2752 ! cumchr(i,k) = cumchr(i,k) / cumabs(i)
2753 ! enddo
2754 ! enddo
2755 
2756 ! --- ... begin check print ******************************************
2757 
2758 ! if (lprnt) then
2759 ! if (kbot(ipr) <= ktop(ipr)) then
2760 ! write(*,*) 'kbot <= ktop for (lat,lon) = ', &
2761 ! & xlon(ipr)*57.29578,xlat(ipr)*57.29578
2762 ! write(*,*) 'kcnv kbot ktop qmax dlength ',kcnv(ipr), &
2763 ! & kbot(ipr),ktop(ipr),(86400.*qmax(ipr)),dlength(ipr)
2764 ! write(*,9000) kdt
2765 !9000 format(/,3x,'k',5x,'cuhr(k)',4x,'cumchr(k)',5x, &
2766 ! & 'at kdt = ',i4,/)
2767 
2768 ! do k = ktop(ipr), kbot(ipr),-1
2769 ! write(*,9010) k,(86400.*cuhr(ipr,k)),(100.*cumchr(ipr,k))
2770 !9010 format(2x,i2,2x,f8.2,5x,f6.0)
2771 ! enddo
2772 ! endif
2773 
2774 ! if (fhour >= fhourpr) then
2775 ! print *,' before gwdc in gbphys start print'
2776 ! write(*,*) 'fhour ix im levs = ',fhour,ix,im,levs
2777 ! print *,'dtp dtf = ',dtp,dtf
2778 
2779 ! write(*,9100)
2780 !9100 format(//,14x,'pressure levels',// &
2781 ! & ' ilev',7x,'prsi',8x,'prsl',8x,'delp',/)
2782 
2783 ! k = levs + 1
2784 ! write(*,9110) k,(10.*prsi(ipr,k))
2785 !9110 format(i4,2x,f10.3)
2786 
2787 ! do k = levs, 1, -1
2788 ! write(*,9120) k,(10.*prsl(ipr,k)),(10.*del(ipr,k))
2789 ! write(*,9110) k,(10.*prsi(ipr,k))
2790 ! enddo
2791 !9120 format(i4,12x,2(2x,f10.3))
2792 
2793 ! write(*,9130)
2794 !9130 format(//,10x,'before gwdc in gbphys',//,' ilev',6x, &
2795 ! & 'ugrs',9x,'gu0',8x,'vgrs',9x,'gv0',8x, &
2796 ! & 'tgrs',9x,'gt0',8x,'gt0b',8x,'dudt',8x,'dvdt',/)
2797 
2798 ! do k = levs, 1, -1
2799 ! write(*,9140) k,ugrs(ipr,k),gu0(ipr,k), &
2800 ! & vgrs(ipr,k),gv0(ipr,k), &
2801 ! & tgrs(ipr,k),gt0(ipr,k),dtdt(ipr,k), &
2802 ! & dudt(ipr,k),dvdt(ipr,k)
2803 ! enddo
2804 !9140 format(i4,9(2x,f10.3))
2805 
2806 ! print *,' before gwdc in gbphys end print'
2807 ! endif
2808 ! endif ! end if_lprnt
2809 
2810 ! --- ... end check print ********************************************
2811 
2812  call gwdc(im, ix, im, levs, lat, ugrs, vgrs, tgrs, qgrs, &
2813  & prsl, prsi, del, cumabs, ktop, kbot, kcnv,cldf, &
2814  & con_g, con_cp, con_rd, con_fvirt, dlength, &
2815  & lprnt, ipr, fhour, gwdcu, gwdcv, dusfcg, dvsfcg)
2816 
2817 
2818 ! if (lprnt) then
2819 ! if (fhour >= fhourpr) then
2820 ! print *,' after gwdc in gbphys start print'
2821 
2822 ! write(*,9131)
2823 !9131 format(//,10x,'after gwdc in gbphys',//,' ilev',6x, &
2824 ! & 'ugrs',9x,'gu0',8x,'vgrs',9x,'gv0',8x, &
2825 ! & 'tgrs',9x,'gt0',8x,'gt0b',7x,'gwdcu',7x,'gwdcv',/)
2826 
2827 ! do k = levs, 1, -1
2828 ! write(*,9141) k,ugrs(ipr,k),gu0(ipr,k), &
2829 ! & vgrs(ipr,k),gv0(ipr,k), &
2830 ! & tgrs(ipr,k),gt0(ipr,k),dtdt(ipr,k), &
2831 ! & gwdcu(ipr,k),gwdcv(ipr,k)
2832 ! enddo
2833 !9141 format(i4,9(2x,f10.3))
2834 
2835 ! print *,' after gwdc in gbphys end print'
2836 ! endif
2837 ! endif
2838 
2839 ! --- ... write out cloud top stress and wind tendencies
2840 
2841  if (lssav) then
2842  do i = 1, im
2843  dugwd(i) = dugwd(i) + dusfcg(i)*dtf
2844  dvgwd(i) = dvgwd(i) + dvsfcg(i)*dtf
2845  enddo
2846 
2847  if (ldiag3d) then
2848  do k = 1, levs
2849  do i = 1, im
2850  du3dt(i,k,4) = du3dt(i,k,4) + gwdcu(i,k) * dtf
2851  dv3dt(i,k,4) = dv3dt(i,k,4) + gwdcv(i,k) * dtf
2852 ! du3dt(i,k,2) = du3dt(i,k,2) + diagn1(i,k) * dtf
2853 ! dv3dt(i,k,2) = dv3dt(i,k,2) + diagn2(i,k) * dtf
2854  enddo
2855  enddo
2856  endif
2857  endif ! end if_lssav
2858 
2859 ! --- ... update the wind components with gwdc tendencies
2860 
2861  do k = 1, levs
2862  do i = 1, im
2863  eng0 = 0.5*(gu0(i,k)*gu0(i,k)+gv0(i,k)*gv0(i,k))
2864  gu0(i,k) = gu0(i,k) + gwdcu(i,k) * dtp
2865  gv0(i,k) = gv0(i,k) + gwdcv(i,k) * dtp
2866  eng1 = 0.5*(gu0(i,k)*gu0(i,k)+gv0(i,k)*gv0(i,k))
2867  gt0(i,k) = gt0(i,k) + (eng0-eng1)/(dtp*con_cp)
2868  enddo
2869  enddo
2870 
2871 ! if (lprnt) then
2872 ! if (fhour >= fhourpr) then
2873 ! print *,' after tendency gwdc in gbphys start print'
2874 
2875 ! write(*,9132)
2876 !9132 format(//,10x,'after tendency gwdc in gbphys',//,' ilev',6x,&
2877 ! & 'ugrs',9x,'gu0',8x,'vgrs',9x,'gv0',8x, &
2878 ! & 'tgrs',9x,'gt0',8x,'gt0b',7x,'gwdcu',7x,'gwdcv',/)
2879 
2880 ! do k = levs, 1, -1
2881 ! write(*,9142) k,ugrs(ipr,k),gu0(ipr,k),vgrs(ipr,k), &
2882 ! & gv0(ipr,k),tgrs(ipr,k),gt0(ipr,k),dtdt(ipr,k), &
2883 ! & gwdcu(ipr,k),gwdcv(ipr,k)
2884 ! enddo
2885 !9142 format(i4,9(2x,f10.3))
2886 
2887 ! print *,' after tendency gwdc in gbphys end print'
2888 ! endif
2889 ! endif
2890 
2891  endif ! end if_cnvgwd (convective gravity wave drag)
2892 
2893 !----------------Convective gravity wave drag parameterization over --------
2894 
2895  if (ldiag3d) then
2896  do k = 1, levs
2897  do i = 1, im
2898  dtdt(i,k) = gt0(i,k)
2899 ! dqdt(i,k,1) = gq0(i,k,1)
2900  enddo
2901  enddo
2902  endif
2903  if (ldiag3d .or. lgocart) then
2904  do k = 1, levs
2905  do i = 1, im
2906  dqdt(i,k,1) = gq0(i,k,1)
2907  enddo
2908  enddo
2909  endif
2910 
2911 ! write(0,*)' before do_shoc shal clstp=',clstp,' kdt=',kdt,
2912 ! & ' lat=',lat
2913 
2914  if (.not. do_shoc) then
2915 
2916  if (shal_cnv) then ! Shallow convection parameterizations
2917 ! --------------------------------------
2918  if (imfshalcnv == 1) then ! opr option now at 2014
2919  !-----------------------
2920  call shalcnv(im,ix,levs,jcap,dtp,del,prsl,pgr,phil, &
2921  & clw,gq0,gt0,gu0,gv0, &
2922  & rain1,kbot,ktop,kcnv,islmsk, &
2923  & vvel,ncld,hpbl,hflx,evap,ud_mf,dt_mf, &
2924  & cnvw,cnvc)
2925 
2926  if (shcnvcw .and. num_p3d == 4 .and. npdf3d == 3 ) then
2927  do k = 1, levs
2928  do i = 1, im
2929  phy_f3d(i,k,num2) = cnvw(i,k)
2930  phy_f3d(i,k,num3) = cnvc(i,k)
2931 !??? phy_f3d(i,k,num2) = phy_f3d(i,k,num2) + cnvw(i,k)
2932 !??? phy_f3d(i,k,num3) = phy_f3d(i,k,num3) + cnvc(i,k)
2933  enddo
2934  enddo
2935  else if(npdf3d == 0 .and. ncnvcld3d == 1) then
2936  num2 = num_p3d + 1
2937  do k = 1, levs
2938  do i = 1, im
2939  phy_f3d(i,k,num2) = cnvw(i,k)
2940  enddo
2941  enddo
2942  endif
2943  do i = 1, im
2944  raincs(i) = frain * rain1(i)
2945  rainc(i) = rainc(i) + raincs(i)
2946  enddo
2947  if (lssav) then
2948  do i = 1, im
2949  cnvprcp(i) = cnvprcp(i) + raincs(i)
2950  enddo
2951  endif
2952 
2953  elseif (imfshalcnv == 2) then
2954  call mfshalcnv(im,ix,levs,dtp,del,prsl,pgr,phil, &
2955  & clw,gq0,gt0,gu0,gv0, &
2956  & rain1,kbot,ktop,kcnv,islmsk,garea, &
2957  & vvel,ncld,hpbl,ud_mf,dt_mf,cnvw,cnvc)
2958 
2959  if (shcnvcw .and. num_p3d == 4 .and. npdf3d == 3 ) then
2960  do k = 1, levs
2961  do i = 1, im
2962  phy_f3d(i,k,num2) = cnvw(i,k)
2963  phy_f3d(i,k,num3) = cnvc(i,k)
2964 !??? phy_f3d(i,k,num2) = phy_f3d(i,k,num2) + cnvw(i,k)
2965 !??? phy_f3d(i,k,num3) = phy_f3d(i,k,num3) + cnvc(i,k)
2966  enddo
2967  enddo
2968  else if(npdf3d == 0 .and. ncnvcld3d == 1) then
2969  num2 = num_p3d + 1
2970  do k = 1, levs
2971  do i = 1, im
2972  phy_f3d(i,k,num2) = cnvw(i,k)
2973  enddo
2974  enddo
2975  endif
2976  do i = 1, im
2977  raincs(i) = frain * rain1(i)
2978  rainc(i) = rainc(i) + raincs(i)
2979  enddo
2980  if (lssav) then
2981  do i = 1, im
2982  cnvprcp(i) = cnvprcp(i) + raincs(i)
2983  enddo
2984  endif
2985 
2986  elseif (imfshalcnv == 0) then ! modified Tiedtke Shallow convecton
2987  !-----------------------------------
2988  do i = 1, im
2989  levshc(i) = 0
2990  enddo
2991  do k = 2, levs
2992  do i = 1, im
2993  if (prsi(i,1)-prsi(i,k) <= dpshc(i)) levshc(i) = k
2994  enddo
2995  enddo
2996  levshcm = 1
2997  do i = 1, im
2998  levshcm = max(levshcm, levshc(i))
2999  enddo
3000 
3001 ! if (lprnt) print *,' levshcm=',levshcm,' gt0sh=',gt0(ipr,:)
3002 ! &, ' lat=',lat
3003 
3004  if (mstrat) then ! As in CFSv2
3005  call shalcv(im,ix,levshcm,dtp,del,prsi,prsl,prslk,kcnv, &
3006  & gq0,gt0,levshc,phil,kinver,ctei_r,ctei_rml &
3007  &, lprnt,ipr)
3008  else
3009  call shalcvt3(im,ix,levshcm,dtp,del,prsi,prsl,prslk, &
3010  & kcnv,gq0,gt0)
3011  endif
3012 ! if (lprnt) print *,' levshcm=',levshcm,' gt0sha=',gt0(ipr,:)
3013 
3014  endif ! end if_imfshalcnv
3015  endif ! end if_shal_cnv
3016 
3017  if (lssav) then
3018 ! update dqdt_v to include moisture tendency due to shallow convection
3019  if (lgocart) then
3020  do k = 1, levs
3021  do i = 1, im
3022  tem = (gq0(i,k,1)-dqdt(i,k,1)) * frain
3023  dqdt_v(i,k) = dqdt_v(i,k) + tem
3024  enddo
3025  enddo
3026  endif
3027  if (ldiag3d) then
3028  do k = 1, levs
3029  do i = 1, im
3030  dt3dt(i,k,5) = dt3dt(i,k,5) + (gt0(i,k)-dtdt(i,k))
3031  & * frain
3032  dq3dt(i,k,3) = dq3dt(i,k,3) + (gq0(i,k,1)-dqdt(i,k,1)) &
3033  & * frain
3034  dtdt(i,k) = gt0(i,k)
3035  dqdt(i,k,1) = gq0(i,k,1)
3036  enddo
3037  enddo
3038  endif
3039  endif ! end if_lssav
3040 !
3041  do k = 1, levs
3042  do i = 1, im
3043  if (clw(i,k,2) <= -999.0) clw(i,k,2) = 0.0
3044  enddo
3045  enddo
3046 
3047 ! if (lprnt) then
3048 ! write(0,*)' prsl=',prsl(ipr,:)
3049 ! write(0,*) ' del=',del(ipr,:)
3050 ! write(0,*) ' befshgt0=',gt0(ipr,:)
3051 ! write(0,*) ' befshgq0=',gq0(ipr,:,1)
3052 ! endif
3053 
3054  elseif (shocaftcnv) then ! if do_shoc is true and shocaftcnv is true call shoc
3055  if (ncld == 2) then
3056  skip_macro = do_shoc
3057  do k = 1, levs
3058  do i = 1, im
3059 ! clw(i,k,1) = gq0(i,k,ntiw) ! ice
3060 ! clw(i,k,2) = gq0(i,k,ntcw) ! water
3061  ncpl(i,k) = gq0(i,k,ntlnc)
3062  ncpi(i,k) = gq0(i,k,ntinc)
3063  enddo
3064  enddo
3065 
3066 ! else
3067 ! if (clw(1,1,2) < -999.0) then ! if clw is not partitioned to ice and water
3068 ! do k=1,levs
3069 ! do i=1,im
3070 ! tem = gq0(i,k,ntcw) &
3071 ! & * max(0.0, MIN(1.0, (TCR-gt0(i,k))*TCRF))
3072 ! clw(i,k,1) = tem ! ice
3073 ! clw(i,k,2) = gq0(i,k,ntcw) - tem ! water
3074 ! enddo
3075 ! enddo
3076 ! endif ! Anning ncld ==2
3077  endif
3078  do k=1,levs
3079  do i=1,im
3080  qpl(i,k) = 0.0
3081  qpi(i,k) = 0.0
3082  enddo
3083  enddo
3084 ! dtshoc = 60.0
3085 ! nshocm = (dtp/dtshoc) + 0.001
3086 ! dtshoc = dtp / nshocm
3087 ! do nshoc=1,nshocm
3088 ! call shoc(im, 1, levs, levs+1, dtp, me, lat, &
3089 !! call shoc(im, 1, levs, levs+1, dtshoc, me, lat, &
3090 ! & prsl(1:im,:), phii (1:im,:), phil(1:im,:),&
3091 ! & gu0(1:im,:),gv0(1:im,:), vvel(1:im,:), gt0(1:im,:), &
3092 ! & gq0(1:im,:,1), &
3093 ! & clw(1:im,:,1), clw(1:im,:,2), qpi, qpl, sgs_cld(1:im,:)&
3094 ! &, gq0(1:im,:,ntke), &
3095 ! & phy_f3d(1:im,:,ntot3d-1), phy_f3d(1:im,:,ntot3d), &
3096 ! & lprnt, ipr, &
3097 ! & con_cp, con_g, con_hvap, con_hfus, con_hvap+con_hfus, &
3098 ! & con_rv, con_rd, con_pi, con_fvirt)
3099 
3100 ! call shoc(ix, im, 1, levs, levs+1, dtshoc, me, lat, &
3101  call shoc(ix, im, 1, levs, levs+1, dtp, me, lat, &
3102  & prsl(1,1), phii(1,1), phil(1,1), &
3103  & gu0(1,1),gv0(1,1), vvel(1,1), gt0(1,1), gq0(1,1,1), &
3104  & clw(1,1,1), clw(1,1,2), qpi, qpl,rhc, sup, &
3105  & phy_f3d(1,1,ntot3d-2), gq0(1,1,ntke),hflx,evap, &
3106  & prnum, phy_f3d(1,1,ntot3d-1), phy_f3d(1,1,ntot3d), &
3107  & lprnt, ipr, ncpl, ncpi)
3108 
3109  if (ntlnc > 0 .and. ntinc > 0 .and. ncld >=2) then
3110  do k=1,levs
3111  do i=1,im
3112  gq0(i,k,ntlnc) = ncpl(i,k)
3113  gq0(i,k,ntinc) = ncpi(i,k)
3114  enddo
3115  enddo
3116  endif
3117 
3118 !
3119 ! do k=1,levs
3120 ! write(1000+me,*)' maxtkh=',maxval(phy_f3d(1:im,k,ntot3d-1)),
3121 ! &' k=',k,' kdt=',kdt,' lat=',lat
3122 ! enddo
3123 
3124 ! write(0,*)' aft shoc gt0=',gt0(1,:),' lat=',lat
3125 ! write(0,*)' aft shoc gq0=',gq0(1,:,1),' lat=',lat
3126 ! write(0,*)' aft shoc gu0=',gu0(1,:),' lat=',lat
3127 !
3128  endif ! if( .not. do_shoc)
3129 !
3130 ! if (lprnt) then
3131 ! write(0,*)' prsl=',prsl(ipr,:)
3132 ! write(0,*) ' del=',del(ipr,:)
3133 ! write(0,*) ' aftshgt0=',gt0(ipr,:)
3134 ! write(0,*) ' aftshgq0=',gq0(ipr,:,1)
3135 ! endif
3136 
3137  if (ntcw > 0) then
3138 
3139 ! for microphysics
3140 
3141  if (ncld == 2) then ! morrison microphysics
3142  do k = 1, levs
3143  do i = 1, im
3144  gq0(i,k,ntiw) = clw(i,k,1) ! ice
3145  gq0(i,k,ntcw) = clw(i,k,2) ! water
3146  enddo
3147  enddo
3148 
3149  elseif (num_p3d == 3) then ! call brad ferrier's microphysics
3150 
3151  do k = 1, levs
3152  do i = 1, im
3153 ! qi = clw(i,k)*fc_ice(i,k)
3154 ! qw = clw(i,k) - qi
3155  qi = clw(i,k,1)
3156  qw = clw(i,k,2)
3157 
3158 ! --- ... algorithm to combine different hydrometeor species
3159 
3160 ! gq0(i,k,ntcw) = max(epsq, qi+qw+qr_col(i,k))
3161  gq0(i,k,ntcw) = qi + qw + qr_col(i,k)
3162 
3163  if (qi <= epsq) then
3164  phy_f3d(i,k,1) = 0.
3165  else
3166  phy_f3d(i,k,1) = qi/gq0(i,k,ntcw)
3167  endif
3168 
3169  if (qr_col(i,k) <= epsq) then
3170  phy_f3d(i,k,2) = 0.
3171  else
3172  phy_f3d(i,k,2) = qr_col(i,k) / (qw+qr_col(i,k))
3173  endif
3174 
3175  enddo
3176  enddo
3177 
3178  elseif (num_p3d == 4) then ! if_num_p3d
3179 
3180  do k = 1, levs
3181  do i = 1, im
3182  gq0(i,k,ntcw) = clw(i,k,1) + clw(i,k,2)
3183  enddo
3184  enddo
3185 
3186  endif ! end if_num_p3d
3187 
3188  else ! if_ntcw
3189 
3190  do k = 1, levs
3191  do i = 1, im
3192  clw(i,k,1) = clw(i,k,1) + clw(i,k,2)
3193  enddo
3194  enddo
3195 
3196  endif ! end if_ntcw
3197 
3198 ! Legacy routine which determines convectve clouds - should be removed at some point
3199 
3200  call cnvc90(clstp, im, ix, rainc, kbot, ktop, levs, prsi, &
3201  & acv, acvb, acvt, cv, cvb, cvt)
3202 
3203 
3204  if (moist_adj) then ! moist convective adjustment
3205 ! ---------------------------
3206 !
3207 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3208 ! if (me == 0) then
3209 ! sumq = 0.0
3210 ! DO K=1,LEVS
3211 ! do i=1,im
3212 ! sumq = sumq - (gq0(i,k,1)+gq0(i,k,ntcw)) * del(i,k)
3213 ! enddo
3214 ! enddo
3215 ! endif
3216 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3217 !
3218 ! To call moist convective adjustment
3219 !
3220 ! if (lprnt) then
3221 ! print *,' prsl=',prsl(ipr,:)
3222 ! print *,' del=',del(ipr,:)
3223 ! print *,' gt0b=',gt0(ipr,:)
3224 ! print *,' gq0b=',gq0(ipr,:,1)
3225 ! endif
3226 
3227  call mstcnv(im,ix,levs,dtp,gt0,gq0,prsl,del,prslk,rain1
3228  &, gq0(1,1,ntcw), rhc, lprnt,ipr)
3229 
3230 ! if (lprnt) then
3231 ! print *,' rain1=',rain1(ipr),' rainc=',rainc(ipr)
3232 ! print *,' gt0a=',gt0(ipr,:)
3233 ! print *,' gq0a=',gq0(ipr,:,1)
3234 ! endif
3235  do i=1,im
3236  rainc(i) = rainc(i) + frain * rain1(i)
3237  enddo
3238  if(lssav) then
3239  do i=1,im
3240  cnvprcp(i) = cnvprcp(i) + rain1(i) * frain
3241  enddo
3242 
3243 ! update dqdt_v to include moisture tendency due to surface processes
3244 ! dqdt_v : instaneous moisture tendency (kg/kg/sec)
3245 ! if (lgocart) then
3246 ! do k=1,levs
3247 ! do i=1,im
3248 ! tem = (gq0(i,k,1)-dqdt(i,k,1)) * frain
3249 ! dqdt_v(i,k) = dqdt_v(i,k) + tem
3250 ! dqdt_v(i,k) = dqdt_v(i,k) / dtf
3251 ! enddo
3252 ! enddo
3253 ! endif
3254  if (ldiag3d) then
3255  do k=1,levs
3256  do i=1,im
3257  dt3dt(i,k,4) = dt3dt(i,k,4) + (gt0(i,k)-dtdt(i,k))
3258  & * frain
3259  dq3dt(i,k,2) = dq3dt(i,k,2) + (gq0(i,k,1)-dqdt(i,k,1))
3260  & * frain
3261  enddo
3262  enddo
3263  endif
3264  endif
3265 !
3266  if (ldiag3d) then
3267  do k=1,levs
3268  do i=1,im
3269  dtdt(i,k) = gt0(i,k)
3270  dqdt(i,k,1) = gq0(i,k,1)
3271  enddo
3272  enddo
3273  endif
3274 !
3275 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3276 ! if (me == 0) then
3277 ! DO K=1,LEVS
3278 ! do i=1,im
3279 ! sumq = sumq + (gq0(i,k,1)+gq0(i,k,ntcw)) * del(i,k)
3280 ! enddo
3281 ! enddo
3282 ! sumr = 0.0
3283 ! do i=1,im
3284 ! sumr = sumr + rain1(i)
3285 ! enddo
3286 ! sumq = sumq * 1000.0 / grav
3287 ! sumr = sumr *1000
3288 ! print *,' after MCN: sumq=',sumq,' sumr=',sumr, ' kdt=',kdt
3289 ! endif
3290 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3291 !
3292  endif ! moist convective adjustment over
3293 
3294 ! dqdt_v : instaneous moisture tendency (kg/kg/sec)
3295  if (lgocart) then
3296  do k=1,levs
3297  do i=1,im
3298  dqdt_v(i,k) = dqdt_v(i,k) / dtf
3299  enddo
3300  enddo
3301  endif
3302 !
3303 ! grid-scale condensation/precipitations and microphysics parameterization
3304 ! ------------------------------------------------------------------------
3305 
3306  if (ncld == 0) then ! no cloud microphysics
3307 
3308  call lrgscl(ix,im,levs,dtp,gt0,gq0,prsl,del,prslk,rain1,clw)
3309 
3310  elseif (ncld == 1) then ! microphysics with single cloud condensate
3311 
3312  if (num_p3d == 3) then ! brad ferrier's microphysics
3313  ! ---------------------------
3314  do i = 1, im
3315  xncw(i) = ncw(1) * work1(i) + ncw(2) * work2(i)
3316  flgmin_l(i) = flgmin(1)* work1(i) + flgmin(2) * work2(i)
3317  enddo
3318 
3319  if (kdt == 1 .and. abs(xlon(1)) < 0.0001) then
3320  write(0,*)' xncw=',xncw(1),' rhc=',rhc(1,1),' work1=' &
3321  &, work1(1),' work2=',work2(1),' flgmin=',flgmin_l(1) &
3322  &, ' lon=',xlon(1) * 57.29578,' lat=',lat,' me=',me
3323  endif
3324 
3325  call gsmdrive(im, ix, levs, dtp, con_g, con_hvap, hsub, con_cp&
3326  &, me, lprnt, ipr &
3327  &, prsl, del, rhc, xncw, flgmin_l &
3328  &, gt0, gq0(1,1,1), gq0(1,1,ntcw) &
3329  &, phy_f3d(1,1,1), phy_f3d(1,1,2) &
3330  &, phy_f3d(1,1,3), rain1, sr)
3331 
3332  elseif (num_p3d == 4) then ! call zhao/carr/sundqvist microphysics
3333 
3334  if (npdf3d /= 3) then ! without pdf clouds
3335 
3336 ! if (lprnt) then
3337 ! write(0,*)' prsl=',prsl(ipr,:)
3338 ! write(0,*) ' del=',del(ipr,:)
3339 ! write(0,*) ' beflsgt0=',gt0(ipr,:),' kdt=',kdt
3340 ! write(0,*) ' beflsgq0=',gq0(ipr,:,1),' kdt=',kdt
3341 ! endif
3342  ! ------------------
3343  if (do_shoc) then
3344  call precpd_shoc(im, ix, levs, dtp, del, prsl, &
3345  & gq0(1,1,1), gq0(1,1,ntcw), gt0, rain1, sr, &
3346  & rainp, rhc, psautco_l, prautco_l, evpco, &
3347  & wminco, phy_f3d(1,1,ntot3d-2), lprnt, ipr)
3348 ! & wminco, sgs_cld(1:im,1:levs), lprnt, ipr)
3349 ! & wminco, shoc_cld, lprnt, ipr)
3350  else
3351  call gscond(im, ix, levs, dtp, dtf, prsl, pgr, &
3352  & gq0(1,1,1), gq0(1,1,ntcw), gt0, &
3353  & phy_f3d(1,1,1), phy_f3d(1,1,2), phy_f2d(1,1), &
3354  & phy_f3d(1,1,3), phy_f3d(1,1,4), phy_f2d(1,2), &
3355  & rhc,lprnt, ipr)
3356 
3357  call precpd(im, ix, levs, dtp, del, prsl, &
3358  & gq0(1,1,1), gq0(1,1,ntcw), gt0, rain1, sr, &
3359  & rainp, rhc, psautco_l, prautco_l, evpco, &
3360  & wminco, lprnt, ipr)
3361  endif
3362 ! if (lprnt) then
3363 ! write(0,*)' prsl=',prsl(ipr,:)
3364 ! write(0,*) ' del=',del(ipr,:)
3365 ! write(0,*) ' aftlsgt0=',gt0(ipr,:),' kdt=',kdt
3366 ! write(0,*) ' aftlsgq0=',gq0(ipr,:,1),' kdt=',kdt
3367 ! write(0,*)' aft precpd rain1=',rain1(1:3),' lat=',lat
3368 ! endif
3369  else ! with pdf clouds
3370  ! ---------------
3371  call gscondp(im, ix, levs, dtp, dtf, prsl, pgr, &
3372  & gq0(1,1,1), gq0(1,1,ntcw), gt0, &
3373  & phy_f3d(1,1,1), phy_f3d(1,1,2), phy_f2d(1,1), &
3374  & phy_f3d(1,1,3), phy_f3d(1,1,4), phy_f2d(1,2), &
3375  & rhc,phy_f3d(1,1,num_p3d+1),sup,lprnt, &
3376  & ipr,kdt)
3377 
3378  call precpdp(im, ix, levs, dtp, del, prsl, pgr, &
3379  & gq0(1,1,1), gq0(1,1,ntcw), gt0, rain1,sr, &
3380  & rainp, rhc, phy_f3d(1,1,num_p3d+1), &
3381  & psautco_l, prautco_l, evpco, wminco, &
3382  & lprnt, ipr)
3383 
3384  endif ! end of grid-scale precip/microphysics options
3385  endif ! end if_num_p3d
3386 
3387 ! if (lprnt) write(0,*) ' rain1=',rain1(ipr),' rainc=',rainc(ipr)
3388 ! &,' lat=',lat
3389 
3390  elseif (ncld == 2) then ! MGB double-moment microphysics
3391 ! Acheng used clw here for other code to run smoothly and minimum change
3392 ! to make the code work. However, the nc and clw should be treated
3393 ! in other procceses too. August 28/2015; Hope that can be done next
3394 ! year. I believe this will make the physical interaction more reasonable
3395 ! Anning 12/5/2015 changed ntcw hold liquid only
3396  if (do_shoc) then
3397  do k=1,levs
3398  do i=1,im
3399  clw(i,k,1) = gq0(i,k,ntiw) ! ice
3400  clw(i,k,2) = gq0(i,k,ntcw) ! water
3401  phy_f3d(i,k,1) = phy_f3d(i,k,ntot3d-2) ! clouds from shoc
3402  enddo
3403  enddo
3404  else
3405  do k=1,levs
3406  do i=1,im
3407  clw(i,k,1) = gq0(i,k,ntiw) ! ice
3408  clw(i,k,2) = gq0(i,k,ntcw) ! water
3409  phy_f3d(i,k,1) = min(1.0, phy_f3d(i,k,1)+cnvc(i,k))
3410  ! clouds from t-dt and cnvc
3411  enddo
3412  enddo
3413  endif
3414 ! notice clw ix instead of im
3415 ! call m_micro_driver(im,ix,levs,flipv,del,dtp,prsl,prsi,
3416 ! & prslk,prsik,pgr,vvel,clw(1,1,2), QLCN, clw(1,1,1),QICN,
3417 ! if (lprnt) write(0,*)' cnv_mfdbef=',cnv_mfd(ipr,:),' flipv=',flipv
3418 ! if (lprnt) write(0,*)' clw1bef=',clw(ipr,:,1),' kdt=',kdt
3419  call m_micro_driver(im, ix, levs, flipv, dtp,
3420  & prsl, prsi, prslk, prsik,
3421  & vvel, clw(1,1,2), qlcn, clw(1,1,1),qicn,
3422  & hlw, swh, w_upi, cf_upi,
3423  & frland, hpbl, cnv_mfd, cnv_prc3,
3424  & cnv_dqldt, clcn, gu0, gv0,
3425  & dusfc, dvsfc, dusfc1, dvsfc1,
3426  & dusfc1, dvsfc1, cnv_fice,
3427  & cnv_ndrop, cnv_nice, gq0(1,1,1),
3428  & gq0(1,1,ntcw), gq0(1,1,ntiw), gt0,
3429  & rain1, sr, gq0(1,1,ntlnc),
3430  & gq0(1,1,ntinc), phy_f3d(1,1,1), kbot,
3431  & aero_in, skip_macro, cn_prc, cn_snr,
3432  & lprnt, ipr, kdt)
3433 
3434 ! if (lprnt) write(0,*) ' rain1=',rain1(ipr),' rainc=',rainc(ipr)
3435 ! &,' cn_prc=',cn_prc(ipr),' cn_snr=',cn_snr(ipr)
3436 ! if(lprnt) write(0,*) ' aftlsgq0=',gq0(ipr,:,1),' kdt=',kdt
3437 ! if (lprnt) write(0,*)' clw1aft=',gq0(ipr,:,ntiw),' kdt=',kdt
3438 
3439  endif ! end if_ncld
3440 
3441  do i = 1, im
3442  rain(i) = rainc(i) + frain * rain1(i)
3443  enddo
3444 
3445  if (cal_pre) then ! hchuang: add dominant precipitation type algorithm
3446 
3447  i = min(3,num_p3d)
3448  call calpreciptype(kdt,nrcm,im,ix,levs,levs+1,rann,
3449  & xlat,xlon,gt0,gq0,prsl,prsi,rain,
3450  & phii,num_p3d,tsea,sr,phy_f3d(1,1,i), ! input
3451  & domr,domzr,domip,doms) ! output
3452 
3453 !
3454 ! if (lprnt) print*,'debug calpreciptype: DOMR,DOMZR,DOMIP,DOMS '
3455 ! &,DOMR(ipr),DOMZR(ipr),DOMIP(ipr),DOMS(ipr)
3456 ! do i=1,im
3457 ! if (abs(xlon(i)*57.29578-114.0) .lt. 0.2 .and.
3458 ! & abs(xlat(i)*57.29578-40.0) .lt. 0.2)
3459 ! & print*,'debug calpreciptype: DOMR,DOMZR,DOMIP,DOMS ',
3460 ! & DOMR(i),DOMZR(i),DOMIP(i),DOMS(i)
3461 ! end do
3462 ! HCHUANG: use new precipitation type to decide snow flag for LSM snow accumulation
3463 
3464  do i=1,im
3465  if(doms(i) >0.0 .or. domip(i)>0.0)then
3466  srflag(i) = 1.
3467  else
3468  srflag(i) = 0.
3469  end if
3470  enddo
3471  endif
3472 
3473  if (lssav) then
3474  do i = 1, im
3475  totprcp(i) = totprcp(i) + rain(i)
3476 ! cnvprcp(i) = cnvprcp(i) + rainc(i)
3477  enddo
3478 
3479  if (ldiag3d) then
3480  do k = 1, levs
3481  do i = 1, im
3482  dt3dt(i,k,6) = dt3dt(i,k,6) + (gt0(i,k)-dtdt(i,k)) * frain
3483  dq3dt(i,k,4) = dq3dt(i,k,4) + (gq0(i,k,1)-dqdt(i,k,1)) &
3484  & * frain
3485  enddo
3486  enddo
3487  endif
3488  endif
3489 
3490 ! --- ... estimate t850 for rain-snow decision
3491 
3492  do i = 1, im
3493  t850(i) = gt0(i,1)
3494  enddo
3495 
3496  do k = 1, levs-1
3497  do i = 1, im
3498  if (prsl(i,k) > p850 .and. prsl(i,k+1) <= p850) then
3499  t850(i) = gt0(i,k) - (prsl(i,k)-p850) &
3500  & / (prsl(i,k)-prsl(i,k+1)) * (gt0(i,k)-gt0(i,k+1))
3501  endif
3502  enddo
3503  enddo
3504 
3505 ! --- ... lu: snow-rain detection is performed in land/sice module
3506 
3507  if (cal_pre) then ! hchuang: new precip type algorithm defines srflag
3508  do i = 1, im
3509  tprcp(i) = max(0.0, rain(i)) ! clu: rain -> tprcp
3510  enddo
3511  else
3512  do i = 1, im
3513  tprcp(i) = max(0.0, rain(i) )! clu: rain -> tprcp
3514  srflag(i) = 0. ! clu: default srflag as 'rain' (i.e. 0)
3515 
3516  if (t850(i) <= 273.16) then
3517  srflag(i) = 1. ! clu: set srflag to 'snow' (i.e. 1)
3518  endif
3519  enddo
3520  endif
3521 
3522 ! --- ... coupling insertion
3523 
3524  if (lssav_cpl) then
3525  do i = 1, im
3526  if (t850(i) > 273.16) then
3527  rain_cpl(i) = rain_cpl(i) + rain(i)
3528  else
3529  snow_cpl(i) = snow_cpl(i) + rain(i)
3530  endif
3531  enddo
3532  endif
3533 
3534 ! --- ... end coupling insertion
3535 
3536  if (lsm == 0) then ! for OSU land model
3537 
3538 ! --- ... wei: when calling osu lsm update soil moisture and canopy water
3539 ! after precipitation computaion
3540  do i = 1, im
3541  if (t850(i) <= 273.16 .and. islmsk(i) /= 0) then
3542  weasd(i) = weasd(i) + 1.e3*rain(i)
3543  tprcp(i) = 0.
3544  endif
3545  enddo
3546  call progt2(im,lsoil,rhscnpy,rhsmc,ai,bi,cci,smsoil, &
3547  & islmsk,canopy,tprcp,runof,snowmt, &
3548  & zsoil,soiltyp,sigmaf,dtf,me)
3549 
3550 ! --- ... wei: let soil liquid water equal to soil total water
3551 
3552  do k = 1, lsoil ! let soil liquid water equal to soil total water
3553  do i = 1, im
3554  if (islmsk(i) == 1) then
3555  slsoil(i,k) = smsoil(i,k)
3556  endif
3557  enddo
3558  enddo
3559 
3560  endif ! end if_lsm
3561 !!!
3562 !!! update surface diagnosis fields at the end of phys package
3563 !!! this change allows gocart to use filtered wind fields
3564 !!!
3565  if ( lgocart ) then
3566  call sfc_diag(im,pgr,gu0,gv0,gt0,gq0, &
3567  & tsea,qss,f10m,u10m,v10m,t2m,q2m,work3, &
3568  & evap,ffmm,ffhh,fm10,fh2)
3569 
3570  if (lssav) then
3571  do i = 1, im
3572  tmpmax(i) = max(tmpmax(i),t2m(i))
3573  tmpmin(i) = min(tmpmin(i),t2m(i))
3574 
3575  spfhmax(i) = max(spfhmax(i),q2m(i))
3576  spfhmin(i) = min(spfhmin(i),q2m(i))
3577  enddo
3578  endif
3579  endif
3580 
3581 ! --- ... total runoff is composed of drainage into water table and
3582 ! runoff at the surface and is accumulated in unit of meters
3583 
3584  if (lssav) then
3585  tem = dtf * 0.001
3586  do i = 1, im
3587  runoff(i) = runoff(i) + (drain(i)+runof(i)) * tem
3588  srunoff(i) = srunoff(i) + runof(i) * tem
3589  enddo
3590  endif
3591 
3592 ! --- ... xw: return updated ice thickness & concentration to global array
3593 
3594  do i = 1, im
3595  if (islmsk(i) == 2) then
3596  hice(i) = zice(i)
3597  fice(i) = cice(i)
3598  tisfc(i) = tice(i)
3599  else
3600  hice(i) = 0.0
3601  fice(i) = 0.0
3602  tisfc(i) = tsea(i)
3603  endif
3604  enddo
3605 
3606 ! --- ... return updated smsoil and stsoil to global arrays
3607 
3608  do k = 1, lsoil
3609  do i = 1, im
3610  smc(i,k) = smsoil(i,k)
3611  stc(i,k) = stsoil(i,k)
3612  slc(i,k) = slsoil(i,k)
3613  enddo
3614  enddo
3615 
3616 ! --- ... calculate column precipitable water "pwat"
3617 
3618  do i = 1, im
3619  pwat(i) = 0.
3620 ! rqtk(i) = 0.
3621 ! work2(i) = 1.0 / pgr(i)
3622  enddo
3623 
3624  do k = 1, levs
3625  do i = 1, im
3626  work1(i) = 0.0
3627  enddo
3628 
3629  if (ncld > 0) then
3630  do ic = ntcw, ntcw+ncld-1
3631  do i = 1, im
3632  work1(i) = work1(i) + gq0(i,k,ic)
3633  enddo
3634  enddo
3635  endif
3636 
3637  do i = 1, im
3638  pwat(i) = pwat(i) + del(i,k)*(gq0(i,k,1)+work1(i))
3639  rqtk(i) = rqtk(i) + del(i,k)*(gq0(i,k,1)-qgrs(i,k,1))
3640  enddo
3641  enddo
3642 
3643  do i = 1, im
3644  pwat(i) = pwat(i) * (1.0/con_g)
3645 ! rqtk(i) = rqtk(i) * work2(i)
3646  enddo
3647 !
3648 ! if (lat == 45) write(1000+me,*)' pwat=',pwat(1),' kdt=',kdt
3649 ! if (lprnt) then
3650 ! write(0,*) ' endgt0=',gt0(ipr,:),' kdt=',kdt
3651 ! write(0,*) ' endgq0=',gq0(ipr,:,1),' kdt=',kdt
3652 ! endif
3653  deallocate (clw)
3654  if (do_shoc) then
3655  deallocate (qpl, qpi, ncpl, ncpi)
3656  endif
3657  if (.not. ras .or. .not. cscnv) then
3658  deallocate (cnvc, cnvw)
3659  endif
3660 ! deallocate (fscav, fswtr)
3661 !
3662 ! if (lprnt) write(0,*)' end of gbphys at kdt=',kdt,
3663 ! &' rain=',rain(ipr),' rainc=',rainc(ipr)
3664 ! if (lprnt) call mpi_quit(7)
3665 ! if (kdt >2 ) call mpi_quit(7)
3666 ! if (ncld == 2) then ! For MGB double moment microphysics
3667  deallocate (qlcn, qicn, w_upi
3668  &, cf_upi, cnv_mfd, cnv_prc3
3669  &, cnv_dqldt, clcn, cnv_fice
3670  &, cnv_ndrop, cnv_nice)
3671 ! endif
3672 
3673  return
3674 !...................................
3675  end subroutine gbphys
3676 !-----------------------------------
real(kind=kind_phys), parameter con_pi
pi
Definition: physcons.f:48
subroutine sascnvn(im, ix, km, jcap, delt, delp, prslp, psp, phil, ql, q1, t1, u1, v1, cldwrk, rn, kbot, ktop, kcnv, islimsk, dot, ncloud, ud_mf, dd_mf, dt_mf, cnvw, cnvc)
This subroutine contains the entirety of the SAS deep convection scheme.
Definition: sascnvn.f:59
real(kind=kind_phys), parameter con_g
gravity ( )
Definition: physcons.f:59
subroutine moninedmf(ix, im, km, ntrac, ntcw, dv, du, tau, rtg, u1, v1, t1, q1, swh, hlw, xmu, psk, rbsoil, zorl, u10m, v10m, fm, fh, tsea, qss, heat, evap, stress, spd1, kpbl, prsi, del, prsl, prslk, phii, phil, delt, dspheat, dusfc, dvsfc, dtsfc, dqsfc, hpbl, hgamt, hgamq, dkt, kinver, xkzm_m, xkzm_h, xkzm_s, lprnt, ipr)
This subroutine contains all of logic for the Hybrid EDMF PBL scheme except for the calculation of th...
Definition: moninedmf.f:96
subroutine gwdps(IM, IX, IY, KM, A, B, C, U1, V1, T1, Q1, KPBL, PRSI, DEL, PRSL, PRSLK, PHII, PHIL, DELTIM, KDT, HPRIME, OC, OA4, CLX4, THETA, SIGMA, GAMMA, ELVMAX, DUSFC, DVSFC, G, CP, RD, RV, IMX, nmtvr, cdmbgwd, me, lprnt, ipr)
Definition: gwdps.f:188
subroutine gbphys(im, ix, levs, lsoil, lsm, ntrac, ncld, ntoz, ntcw, ntke, ntiw, ntlnc, ntinc, nmtvr, nrcm, ko3, lonr, latr, jcap, num_p3d, num_p2d, npdf3d, ncnvcld3d, kdt, lat, me, pl_coeff, nlons, ncw, flgmin, crtrh, cdmbgwd, ccwf, dlqf, ctei_rm, clstp, cgwf, prslrd0, ral_ts, dtp, dtf, fhour, solhr, slag, sdec, cdec, sinlat, coslat, pgr, ugrs, vgrs, tgrs, qgrs, vvel, prsi, prsl, prslk, prsik, phii, phil, rann, prdoz, poz, dpshc, fscav, fswtr, hprime, xlon, xlat, h2o_phys, levh2o, h2opl, h2o_pres, h2o_coeff, isot, ivegsrc, slope, shdmin, shdmax, snoalb, tg3, slmsk, vfrac, vtype, stype, uustar, oro, oro_uf, coszen, sfcdsw, sfcnsw, sfcnirbmd, sfcnirdfd, sfcvisbmd, sfcvisdfd, sfcnirbmu, sfcnirdfu, sfcvisbmu, sfcvisdfu, slimskin_cpl, ulwsfcin_cpl, dusfcin_cpl, dvsfcin_cpl, dtsfcin_cpl, dqsfcin_cpl, sfcdlw, tsflw, sfcemis, sfalb, swh, swhc, hlw, hlwc, hlwd, lsidea, ras, pre_rad, ldiag3d, lgocart, lssav, lssav_cpl, xkzm_m, xkzm_h, xkzm_s, psautco, prautco, evpco, wminco, pdfcld, shcnvcw, sup, redrag, hybedmf, dspheat, flipv, old_monin, cnvgwd, shal_cnv, imfshalcnv, imfdeepcnv, cal_pre, aero_in, mom4ice, mstrat, trans_trac, nstf_name, moist_adj, thermodyn_id, sfcpress_id, gen_coord_hybrid, levr, adjtrc, nnp, cscnv, nctp, do_shoc, shocaftcnv, ntot3d, ntot2d, hice, fice, tisfc, tsea, tprcp, cv, cvb, cvt, srflag, snwdph, weasd, sncovr, zorl, canopy, ffmm, ffhh, f10m, srunoff, evbsa, evcwa, snohfa, transa, sbsnoa, snowca, soilm, tmpmin, tmpmax, dusfc, dvsfc, dtsfc, dqsfc, totprcp, gflux, dlwsfc, ulwsfc, suntim, runoff, ep, cldwrk, dugwd, dvgwd, psmean, cnvprcp, spfhmin, spfhmax, rain, rainc, dt3dt, dq3dt, du3dt, dv3dt, dqdt_v, cnvqc_v, acv, acvb, acvt, slc, smc, stc, upd_mf, dwn_mf, det_mf, phy_f3d, phy_f2d, dusfc_cpl, dvsfc_cpl, dtsfc_cpl, dqsfc_cpl, dlwsfc_cpl, dswsfc_cpl, dnirbm_cpl, dnirdf_cpl, dvisbm_cpl, dvisdf_cpl, rain_cpl, nlwsfc_cpl, nswsfc_cpl, nnirbm_cpl, nnirdf_cpl, nvisbm_cpl, nvisdf_cpl, snow_cpl, xt, xs, xu, xv, xz, zm, xtts, xzts, d_conv, ifd, dt_cool, Qrain, tref, z_c, c_0, c_d, w_0, w_d, phy_fctd, gt0, gq0, gu0, gv0, t2m, q2m, u10m, v10m, zlvl, psurf, hpbl, pwat, t1, q1, u1, v1, chh, cmm, dlwsfci, ulwsfci, dswsfci, uswsfci, dusfci, dvsfci, dtsfci, dqsfci, gfluxi, epi, smcwlt2, smcref2, wet1, sr, rqtk, dtdtr, dusfci_cpl, dvsfci_cpl, dtsfci_cpl, dqsfci_cpl, dlwsfci_cpl, dswsfci_cpl, dnirbmi_cpl, dnirdfi_cpl, dvisbmi_cpl, dvisdfi_cpl, nlwsfci_cpl, nswsfci_cpl, nnirbmi_cpl, nnirdfi_cpl, nvisbmi_cpl, nvisdfi_cpl, t2mi_cpl, q2mi_cpl, u10mi_cpl, v10mi_cpl, tseai_cpl, psurfi_cpl )
Definition: gbphys.f:802
subroutine precpd(im, ix, km, dt, del, prsl, q, cwm, t, rn, sr , rainp, u00k, psautco, prautco, evpco, wminco , lprnt, jpr)
Definition: precpd.f:80
real(kind=kind_phys), parameter con_rv
gas constant H2O ( )
Definition: physcons.f:78
real(kind=kind_phys), parameter con_hfus
lat heat H2O fusion ( )
Definition: physcons.f:92
subroutine gwdc(im, ix, iy, km, lat, u1, v1, t1, q1, pmid1, pint1, dpmid1, qmax, ktop, kbot, kcnv, cldf, grav, cp, rd, fv, dlength, lprnt, ipr, fhour, utgwc, vtgwc, tauctx, taucty)
Definition: gwdc.f:76
subroutine shalcnv(im, ix, km, jcap, delt, delp, prslp, psp, phil, ql, q1, t1, u1, v1, rn, kbot, ktop, kcnv, islimsk, dot, ncloud, hpbl, heat, evap, ud_mf, dt_mf, cnvw, cnvc)
This subroutine contains the entirety of the SAS shallow convection scheme.
Definition: shalcnv.f:58
real(kind=kind_phys), parameter con_cp
spec heat air at p ( )
Definition: physcons.f:80
real(kind=kind_phys), parameter con_hvap
lat heat H2O cond ( )
Definition: physcons.f:90
subroutine gscond(im, ix, km, dt, dtf, prsl, ps, q, cwm, t , tp, qp, psp, tp1, qp1, psp1, u, lprnt, ipr)
Definition: gscond.f:86
real(kind=kind_phys), parameter con_rd
gas constant air ( )
Definition: physcons.f:76
real(kind=kind_phys), parameter con_rerth
radius of earth (m)
Definition: physcons.f:57