21 use fckit_log_module,
only : fckit_log
24 use kinds,
only : kind_real
27 use gnssro_mod_transform,
only: geometric2geop
33 use mpas_constants,
only : gravity, rgas, rv, cp
35 use mpas_derived_types
36 use mpas_field_routines
37 use mpas_pool_routines
86 integer,
intent(in) :: type_in
87 integer,
parameter :: n_soil_type = 16
88 integer,
parameter :: wrf_to_crtm_soil(n_soil_type) = &
89 (/ 1, 1, 4, 2, 2, 8, 7, 2, 6, 5, 2, 3, 8, 1, 6, 9 /)
108 integer,
intent(in) :: type_in
109 integer,
parameter :: usgs_n_type = 24
110 integer,
parameter :: igbp_n_type = 20
130 integer,
parameter :: usgs_to_crtm_mw(usgs_n_type) = &
131 (/ 7, 12, 12, 12, 12, 12, 7, 9, 8, 6, &
132 2, 5, 1, 4, 3, 0, 8, 8, 11, 10, &
134 integer,
parameter :: igbp_to_crtm_mw(igbp_n_type) = &
135 (/ 4, 1, 5, 2, 3, 8, 9, 6, 6, 7, &
136 8, 12, 7, 12, 13, 11, 0, 10, 10, 11 /)
190 elemental subroutine w_to_q(mixing_ratio, specific_humidity)
192 real (kind=kind_real),
intent(in) :: mixing_ratio
193 real (kind=kind_real),
intent(out) :: specific_humidity
198 elemental subroutine q_to_w(specific_humidity, mixing_ratio)
200 real (kind=kind_real),
intent(in) :: specific_humidity
201 real (kind=kind_real),
intent(out) :: mixing_ratio
206 elemental subroutine q_to_w_tl(specific_humidity_tl, sh_traj, mixing_ratio_tl)
208 real (kind=kind_real),
intent(in) :: specific_humidity_tl
209 real (kind=kind_real),
intent(in) :: sh_traj
210 real (kind=kind_real),
intent(out) :: mixing_ratio_tl
215 elemental subroutine q_to_w_ad(specific_humidity_ad, sh_traj, mixing_ratio_ad)
217 real (kind=kind_real),
intent(inout) :: specific_humidity_ad
218 real (kind=kind_real),
intent(in) :: sh_traj
219 real (kind=kind_real),
intent(in) :: mixing_ratio_ad
221 specific_humidity_ad = specific_humidity_ad + &
225 elemental subroutine tw_to_tv(temperature,mixing_ratio,virtual_temperature)
227 real (kind=kind_real),
intent(in) :: temperature
228 real (kind=kind_real),
intent(in) :: mixing_ratio
229 real (kind=kind_real),
intent(out) :: virtual_temperature
231 virtual_temperature = temperature * &
235 elemental subroutine tw_to_tv_tl(temperature_tl,mixing_ratio_tl,t_traj,m_traj,virtual_temperature_tl)
237 real (kind=kind_real),
intent(in) :: temperature_tl
238 real (kind=kind_real),
intent(in) :: mixing_ratio_tl
239 real (kind=kind_real),
intent(in) :: t_traj
240 real (kind=kind_real),
intent(in) :: m_traj
241 real (kind=kind_real),
intent(out) :: virtual_temperature_tl
243 virtual_temperature_tl = temperature_tl * &
248 elemental subroutine tw_to_tv_ad(temperature_ad,mixing_ratio_ad,t_traj,m_traj,virtual_temperature_ad)
250 real (kind=kind_real),
intent(inout) :: temperature_ad
251 real (kind=kind_real),
intent(inout) :: mixing_ratio_ad
252 real (kind=kind_real),
intent(in) :: t_traj
253 real (kind=kind_real),
intent(in) :: m_traj
254 real (kind=kind_real),
intent(in) :: virtual_temperature_ad
256 temperature_ad = temperature_ad + virtual_temperature_ad * &
258 mixing_ratio_ad = mixing_ratio_ad + virtual_temperature_ad * &
264 real (kind=kind_real),
intent(in) :: theta
265 real (kind=kind_real),
intent(in) :: pressure
266 real (kind=kind_real),
intent(out) :: temperature
267 temperature = theta / &
296 real (kind=kind_real),
dimension(nV,nC),
intent(in) :: pressure
297 real (kind=kind_real),
dimension(nV+1,nC),
intent(in) :: zgrid
298 real (kind=kind_real),
dimension(nC),
intent(in) :: surface_pressure
299 integer,
intent(in) :: nc, nv
300 real (kind=kind_real),
dimension(nV+1,nC),
intent(out) :: pressure_f
302 real (kind=kind_real),
dimension(nC,nV) :: fzm_p, fzp_p
303 real (kind=kind_real) :: tem1, z0, z1, z2, w1, w2
304 integer :: i, k, its, ite, kts, kte
318 fzm_p(i,k) = ( zgrid(k,i)- zgrid(k-1,i)) * tem1
319 fzp_p(i,k) = ( zgrid(k+1,i)- zgrid(k,i)) * tem1
320 pressure_f(k,i) = fzm_p(i,k)*pressure(k,i) + fzp_p(i,k)*pressure(k-1,i)
331 pressure_f(k,i) = exp( w1*log(pressure(k-1,i)) + w2*log(pressure(k-1,i)) )
335 pressure_f(k,i) = surface_pressure(i)
360 integer,
intent(in) :: ncells, nlevels
361 real (kind=kind_real),
dimension(nlevels+1,ncells),
intent(in) :: zw
362 real (kind=kind_real),
dimension(nlevels,ncells),
intent(in) :: t
363 real (kind=kind_real),
dimension(nlevels,ncells),
intent(in) :: qv
364 real (kind=kind_real),
dimension(ncells),
intent(in) :: ps
365 real (kind=kind_real),
dimension(nlevels,ncells),
intent(out) :: p
366 real (kind=kind_real),
dimension(nlevels,ncells),
intent(out) :: rho
367 real (kind=kind_real),
dimension(nlevels,ncells),
intent(out) :: theta
370 real (kind=kind_real) :: rvordm1
371 real (kind=kind_real),
dimension(nlevels) :: tv_h
372 real (kind=kind_real),
dimension(nlevels+1) :: pf
373 real (kind=kind_real),
dimension(nlevels) :: zu
374 real (kind=kind_real) :: tv_f, tv, w
386 p(k,icell) = pf(k) * exp( -gravity * (zu(k)-zw(k,icell))/(rgas*tv_h(k)) )
388 theta(k,icell) = t(k,icell) * (
mpas_jedi_p0_kr/p(k,icell) )**(rgas/cp)
396 w = ( zu(k) - zw(k,icell) )/( zu(k) - zu(k-1) )
411 pf(k) = p(k-1,icell) * exp( -gravity * (zw(k,icell)-zu(k-1))/(rgas*tv) )
417 p(k,icell) = pf(k) * exp( -gravity * (zu(k)-zw(k,icell))/(rgas*tv) )
424 theta(k,icell) = t(k,icell) * (
mpas_jedi_p0_kr/p(k,icell) )**(rgas/cp)
433 real (kind=kind_real),
dimension(nV+1,nC),
intent(in) :: zgrid_f
434 integer,
intent(in) :: nc, nv
435 real (kind=kind_real),
dimension(nV,nC),
intent(out) :: zgrid
450 character (len=*),
intent(in) :: mqname
451 type (mpas_pool_type),
pointer,
intent(in) :: modelfields
452 type (field2dreal),
pointer,
intent(inout) :: qgeo
453 real (kind=kind_real),
intent(in) :: plevels(nvertlevels+1,ncells)
454 integer,
intent(in) :: ncells
455 integer,
intent(in) :: nvertlevels
457 real (kind=kind_real),
pointer :: qmodel(:,:)
458 real (kind=kind_real) :: kgkg_kgm2
461 call mpas_pool_get_array(modelfields, mqname, qmodel)
464 kgkg_kgm2=( plevels(k,i)-plevels(k+1,i) ) / gravity
465 qgeo % array(k,i) = qmodel(k,i) * kgkg_kgm2
481 subroutine q_fields_tl(mqName, modelFields_tl, qGeo_tl, plevels, nCells, nVertLevels)
485 character (len=*),
intent(in) :: mqname
486 type (mpas_pool_type),
pointer,
intent(in) :: modelfields_tl
487 type (field2dreal),
pointer,
intent(inout) :: qgeo_tl
488 real (kind=kind_real),
intent(in) :: plevels(nvertlevels+1,ncells)
489 integer,
intent(in) :: ncells
490 integer,
intent(in) :: nvertlevels
492 real (kind=kind_real),
pointer :: qmodel_tl(:,:)
493 real (kind=kind_real) :: kgkg_kgm2
496 call mpas_pool_get_array(modelfields_tl, mqname, qmodel_tl)
499 kgkg_kgm2=( plevels(k,i)-plevels(k+1,i) ) / gravity
500 qgeo_tl%array(k,i) = qmodel_tl(k,i) * kgkg_kgm2
506 subroutine q_fields_ad(mqName, modelFields_ad, qGeo_ad, plevels, nCells, nVertLevels)
510 character (len=*),
intent(in) :: mqname
511 type (mpas_pool_type),
pointer,
intent(inout) :: modelfields_ad
512 type (field2dreal),
pointer,
intent(in) :: qgeo_ad
513 real (kind=kind_real),
intent(in) :: plevels(nvertlevels+1,ncells)
514 integer,
intent(in) :: ncells
515 integer,
intent(in) :: nvertlevels
517 real (kind=kind_real),
pointer :: qmodel_ad(:,:)
518 real (kind=kind_real) :: kgkg_kgm2
521 call mpas_pool_get_array(modelfields_ad, mqname, qmodel_ad)
524 kgkg_kgm2=( plevels(k,i)-plevels(k+1,i) ) / gravity
525 qmodel_ad(k,i) = qmodel_ad(k,i) + qgeo_ad % array(k,i) * kgkg_kgm2
533 real(kind=kind_real),
intent(in) :: y
539 real (kind=kind_real) function gammln(xx)
541 real(kind=kind_real),
intent(in) :: xx
542 real(kind=
kind_double),
parameter :: stp = 2.5066282746310005_kind_double
544 cof(6) = (/ 76.18009172947146_kind_double, -86.50532032941677_kind_double, &
545 24.01409824083091_kind_double, -1.231739572450155_kind_double, &
546 0.001208650973866179_kind_double, -0.000005395239384953_kind_double/)
552 tmp=x+5.5_kind_double
553 tmp=(x+0.5_kind_double)*log(tmp)-tmp
554 ser=1.000000000190015_kind_double
559 gammln=real(tmp+log(stp*ser/x),kind_real)
576 real(kind=kind_real),
dimension( nVertLevels, ngrid ),
intent(in) :: qr, rho
577 real(kind=kind_real),
dimension( nVertLevels, ngrid ),
intent(in) :: nr
578 integer,
intent(in) :: ngrid, nvertlevels
579 character(len=StrKIND),
intent(in) :: mp_scheme
580 real(kind=kind_real),
dimension( nVertLevels, ngrid ),
intent(out) :: re_qr
591 real(kind=kind_real),
parameter :: am_r =
mpas_jedi_pii_kr*denr/6.0_kind_real
597 real(kind=kind_real),
dimension( nVertLevels, ngrid ) :: rqr, nr_rho
599 real(kind=kind_real) :: cre2,cre3,crg2,crg3,org2,obmr
612 do k = 1, nvertlevels
613 rqr(k,i) = max(r1, qr(k,i)*rho(k,i))
617 if (any(rqr > r1))
then
619 do k = 1, nvertlevels
621 if (rqr(k,i).le.r1) cycle
622 select case (trim(mp_scheme))
625 re_qr(k,i) = max(99.9d-6,min(1.5_kind_double/lamdar,1999.d-6))
627 nr_rho(k,i) = max(r2, nr(k,i)*rho(k,i))
628 lamdar = (am_r*crg3*org2*nr_rho(k,i)/rqr(k,i))**obmr
654 real(kind=kind_real),
dimension( nVertLevels, ngrid ),
intent(in) :: qg, rho
655 integer,
intent(in) :: ngrid, nvertlevels
656 character (len=StrKIND),
intent(in) :: mp_scheme
657 real(kind=kind_real),
dimension( nVertLevels, ngrid ),
intent(out):: re_qg
662 real(kind=kind_real) :: n0g, deng
666 real(kind=kind_real),
dimension( nVertLevels, ngrid ):: rqg
668 integer:: hail_opt = 0
671 real(kind=kind_real) :: obmg, cge1,cgg1,oge1,cge3,cgg3,ogg1,cge2,cgg2,ogg2
672 real(kind=kind_real) :: ygra1, zans1
673 real(kind=kind_real),
parameter :: am_g =
mpas_jedi_pii_kr*500.0_kind_real/6.0_kind_real
688 if (hail_opt .eq. 1)
then
690 deng = 700.0_kind_real
693 deng = 500.0_kind_real
697 do k = 1, nvertlevels
698 rqg(k,i) = max(r1, qg(k,i)*rho(k,i))
702 if (any( rqg > r1 ))
then
703 select case (trim(mp_scheme))
707 do k = 1, nvertlevels
708 if (rqg(k,i).le.r1) cycle
710 re_qg(k,i) = max(50.d-6,min(1.5_kind_double/lamdag,9999.d-6))
716 do k = nvertlevels, 1, -1
717 if (rqg(k,i).le.r1) cycle
718 ygra1 = alog10(sngl(max(1.e-9, rqg(k,i))))
719 zans1 = (2.5_kind_real + 2.5_kind_real/7.0_kind_real * (ygra1+7.0_kind_real))
721 n0_exp = 10.0_kind_real**(zans1)
722 lam_exp = (n0_exp*am_g*cgg1/rqg(k,i))**oge1
723 lamdag = lam_exp * (cgg3*ogg2*ogg1)**obmg
elemental subroutine, public q_to_w(specific_humidity, mixing_ratio)
integer function, public convert_type_soil(type_in)
subroutine, public pressure_half_to_full(pressure, zgrid, surface_pressure, nC, nV, pressure_f)
subroutine, public q_fields_tl(mqName, modelFields_tl, qGeo_tl, plevels, nCells, nVertLevels)
subroutine, public q_fields_ad(mqName, modelFields_ad, qGeo_ad, plevels, nCells, nVertLevels)
elemental subroutine, public q_to_w_tl(specific_humidity_tl, sh_traj, mixing_ratio_tl)
elemental subroutine, public q_to_w_ad(specific_humidity_ad, sh_traj, mixing_ratio_ad)
subroutine, public hydrostatic_balance(ncells, nlevels, zw, t, qv, ps, p, rho, theta)
real(kind=kind_real) function gammln(xx)
elemental subroutine, public tw_to_tv_tl(temperature_tl, mixing_ratio_tl, t_traj, m_traj, virtual_temperature_tl)
elemental subroutine, public tw_to_tv(temperature, mixing_ratio, virtual_temperature)
elemental subroutine, public w_to_q(mixing_ratio, specific_humidity)
subroutine, public geometricz_full_to_half(zgrid_f, nC, nV, zgrid)
subroutine, public effectrad_rainwater(qr, rho, nr, re_qr, mp_scheme, ngrid, nVertLevels)
integer, parameter max_string
integer function, public convert_type_veg(type_in)
elemental subroutine, public tw_to_tv_ad(temperature_ad, mixing_ratio_ad, t_traj, m_traj, virtual_temperature_ad)
subroutine, public effectrad_graupel(qg, rho, re_qg, mp_scheme, ngrid, nVertLevels)
subroutine, public q_fields_forward(mqName, modelFields, qGeo, plevels, nCells, nVertLevels)
elemental subroutine, public theta_to_temp(theta, pressure, temperature)
real(kind=kind_real) function wgamma(y)
character(max_string) message
real(kind=kind_real), parameter mpas_jedi_half_kr
real(kind=kind_real), parameter mpas_jedi_two_kr
real(kind=kind_real), parameter mpas_jedi_thousand_kr
real(kind=kind_real), parameter mpas_jedi_three_kr
real(kind=kind_real), parameter mpas_jedi_zero_kr
real(kind=kind_real), parameter mpas_jedi_p0_kr
real(kind=kind_real), parameter mpas_jedi_greaterzero_kr
real(kind=kind_real), parameter mpas_jedi_pii_kr
real(kind=kind_real), parameter mpas_jedi_million_kr
real(kind=kind_real), parameter mpas_jedi_one_kr
integer, parameter, public kind_double