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