40   public :: atmos_hydrostatic_buildrho
 
   41   public :: atmos_hydrostatic_buildrho_real
 
   42   public :: atmos_hydrostatic_buildrho_atmos
 
   43   public :: atmos_hydrostatic_buildrho_atmos_rev
 
   44   public :: atmos_hydrostatic_buildrho_bytemp
 
   45   public :: atmos_hydrostatic_buildrho_bytemp_atmos
 
   47   public :: atmos_hydrostatic_barometric_law_mslp
 
   48   public :: atmos_hydrostatic_barometric_law_pres
 
   50   interface atmos_hydrostatic_buildrho
 
   52      module procedure atmos_hydrostatic_buildrho_1d_cpu
 
   56   end interface atmos_hydrostatic_buildrho
 
   58   interface atmos_hydrostatic_buildrho_real
 
   60   end interface atmos_hydrostatic_buildrho_real
 
   62   interface atmos_hydrostatic_buildrho_atmos
 
   66   end interface atmos_hydrostatic_buildrho_atmos
 
   68   interface atmos_hydrostatic_buildrho_atmos_rev
 
   72   end interface atmos_hydrostatic_buildrho_atmos_rev
 
   74   interface atmos_hydrostatic_buildrho_bytemp
 
   77   end interface atmos_hydrostatic_buildrho_bytemp
 
   79   interface atmos_hydrostatic_buildrho_bytemp_atmos
 
   82   end interface atmos_hydrostatic_buildrho_bytemp_atmos
 
   84   interface atmos_hydrostatic_barometric_law_mslp
 
   86      module procedure atmos_hydrostatic_barometric_law_mslp_2d
 
   87   end interface atmos_hydrostatic_barometric_law_mslp
 
   89   interface atmos_hydrostatic_barometric_law_pres
 
   90      module procedure atmos_hydrostatic_barometric_law_pres_0d
 
   91      module procedure atmos_hydrostatic_barometric_law_pres_2d
 
   92   end interface atmos_hydrostatic_barometric_law_pres
 
  102   private :: atmos_hydrostatic_buildrho_atmos_2d
 
  108   integer,  
private, 
parameter :: itelim = 100
 
  109   real(RP), 
private            :: criteria
 
  110   logical,  
private            :: HYDROSTATIC_uselapserate  = .false. 
 
  111   integer,  
private            :: HYDROSTATIC_buildrho_real_kref = 1
 
  112   integer,  
private            :: HYDROSTATIC_barometric_law_mslp_kref = 1
 
  126     namelist / param_atmos_hydrostatic / &
 
  127        hydrostatic_uselapserate, &
 
  128        hydrostatic_buildrho_real_kref, &
 
  129        hydrostatic_barometric_law_mslp_kref
 
  135     log_info(
"ATMOS_HYDROSTATIC_setup",*) 
'Setup' 
  139     read(
io_fid_conf,nml=param_atmos_hydrostatic,iostat=ierr)
 
  141        log_info(
"ATMOS_HYDROSTATIC_setup",*) 
'Not found namelist. Default used.' 
  142     elseif( ierr > 0 ) 
then  
  143        log_error(
"ATMOS_HYDROSTATIC_setup",*) 
'Not appropriate names in namelist PARAM_ATMOS_HYDROSTATIC. Check!' 
  146     log_nml(param_atmos_hydrostatic)
 
  151     log_info(
"ATMOS_HYDROSTATIC_setup",*) 
'Use lapse rate for estimation of surface temperature? : ', hydrostatic_uselapserate
 
  152     log_info(
"ATMOS_HYDROSTATIC_setup",*) 
'Buildrho conversion criteria                          : ', criteria
 
  163   subroutine atmos_hydrostatic_buildrho_1d_cpu( &
 
  166        pres_sfc, pott_sfc, qv_sfc, qc_sfc, &
 
  173     integer,  
intent(in)  :: 
ka, 
ks, 
ke 
  174     real(rp), 
intent(in)  :: pott(
ka)
 
  175     real(rp), 
intent(in)  :: qv  (
ka)
 
  176     real(rp), 
intent(in)  :: qc  (
ka)
 
  177     real(rp), 
intent(in)  :: pres_sfc
 
  178     real(rp), 
intent(in)  :: pott_sfc
 
  179     real(rp), 
intent(in)  :: qv_sfc
 
  180     real(rp), 
intent(in)  :: qc_sfc
 
  181     real(rp), 
intent(in)  :: cz  (
ka)
 
  182     real(rp), 
intent(in)  :: fz  (0:
ka)
 
  183     real(rp), 
intent(out) :: dens(
ka)
 
  184     real(rp), 
intent(out) :: temp(
ka)
 
  185     real(rp), 
intent(out) :: pres(
ka)
 
  186     real(rp), 
intent(out) :: temp_sfc
 
  187     logical,  
intent(out) :: converged
 
  190     real(rp) :: work1(
ka)
 
  191     real(rp) :: work2(
ka)
 
  196          pres_sfc, pott_sfc, qv_sfc, qc_sfc, &
 
  204   end subroutine atmos_hydrostatic_buildrho_1d_cpu
 
  210        pres_sfc, pott_sfc, qv_sfc, qc_sfc, &
 
  228     integer,  
intent(in)  :: KA, KS, KE
 
  229     real(RP), 
intent(in)  :: pott(KA)
 
  230     real(RP), 
intent(in)  :: qv  (KA)
 
  231     real(RP), 
intent(in)  :: qc  (KA)
 
  232     real(RP), 
intent(in)  :: pres_sfc
 
  233     real(RP), 
intent(in)  :: pott_sfc
 
  234     real(RP), 
intent(in)  :: qv_sfc
 
  235     real(RP), 
intent(in)  :: qc_sfc
 
  236     real(RP), 
intent(in)  :: cz  (KA)
 
  237     real(RP), 
intent(in)  :: fz  (0:KA)
 
  238     real(RP), 
intent(out) :: dens(KA)
 
  239     real(RP), 
intent(out) :: temp(KA)
 
  240     real(RP), 
intent(out) :: pres(KA)
 
  241     real(RP), 
intent(out) :: temp_sfc
 
  242     logical,  
intent(out) :: converged
 
  245     real(RP), 
intent(out) :: dz(KA)
 
  246     real(RP), 
intent(out) :: work1(KA)
 
  247     real(RP), 
intent(out) :: work2(KA)
 
  254     real(RP) :: CVtot_sfc
 
  255     real(RP) :: CPtot_sfc
 
  256     real(RP) :: CPovCV_sfc
 
  267     rtot_sfc   = rdry  * ( 1.0_rp - qv_sfc - qc_sfc ) &
 
  269     cvtot_sfc  = cvdry * ( 1.0_rp - qv_sfc - qc_sfc ) &
 
  272     cptot_sfc  = cpdry * ( 1.0_rp - qv_sfc - qc_sfc ) &
 
  275     cpovcv_sfc = cptot_sfc / cvtot_sfc
 
  277     rtot   = rdry  * ( 1.0_rp - qv(ks) - qc(ks) ) &
 
  279     cvtot  = cvdry * ( 1.0_rp - qv(ks) - qc(ks) ) &
 
  282     cptot  = cpdry * ( 1.0_rp - qv(ks) - qc(ks) ) &
 
  285     cpovcv = cptot / cvtot
 
  288     dens_sfc   = p00 / rtot_sfc / pott_sfc * ( pres_sfc/p00 )**(cvtot_sfc/cptot_sfc)
 
  289     temp_sfc   = pres_sfc / ( dens_sfc * rtot_sfc )
 
  291     dz(ks-1) = cz(ks) - fz(ks-1)
 
  293        dz(k) = cz(k+1) - cz(k)
 
  297     if ( hydrostatic_uselapserate ) 
then 
  299        temp(ks) = pott_sfc - lapsdry * dz(ks-1) 
 
  300        pres(ks) = p00 * ( temp(ks)/pott(ks) )**(cptot/rtot)
 
  301        dens(ks) = p00 / rtot / pott(ks) * ( pres(ks)/p00 )**(cvtot/cptot)
 
  308                                                  dens_sfc, pott_sfc, qv_sfc, qc_sfc, & 
 
  310                                                  dens(ks), temp(ks), pres(ks),       & 
 
  315     if ( converged ) 
then 
  318                                                  pott(:), qv(:), qc(:), & 
 
  321                                                  work1(:), work2(:),    & 
 
  326        if ( converged ) 
then 
  328           dens(   1:ks-1) = 0.0_rp
 
  329           dens(ke+1:ka  ) = 0.0_rp
 
  339        KA, KS, KE, IA, IS, IE, JA, JS, JE, &
 
  341        pres_sfc, pott_sfc, &
 
  349        statistics_horizontal_mean
 
  352     integer, 
intent(in) :: KA, KS, KE
 
  353     integer, 
intent(in) :: IA, IS, IE
 
  354     integer, 
intent(in) :: JA, JS, JE
 
  356     real(RP), 
intent(in)  :: pott(KA,IA,JA)
 
  357     real(RP), 
intent(in)  :: qv  (KA,IA,JA)
 
  358     real(RP), 
intent(in)  :: qc  (KA,IA,JA)
 
  359     real(RP), 
intent(in)  :: pres_sfc(IA,JA)
 
  360     real(RP), 
intent(in)  :: pott_sfc(IA,JA)
 
  361     real(RP), 
intent(in)  :: qv_sfc  (IA,JA)
 
  362     real(RP), 
intent(in)  :: qc_sfc  (IA,JA)
 
  363     real(RP), 
intent(in)  :: cz(  KA,IA,JA)
 
  364     real(RP), 
intent(in)  :: fz(0:KA,IA,JA)
 
  365     real(RP), 
intent(in)  :: area(IA,JA)
 
  367     real(RP), 
intent(out) :: dens(KA,IA,JA)
 
  368     real(RP), 
intent(out) :: temp(KA,IA,JA)
 
  369     real(RP), 
intent(out) :: pres(KA,IA,JA)
 
  370     real(RP), 
intent(out) :: temp_sfc(IA,JA)
 
  372     real(RP) :: dz(KA,IA,JA), dz_top(IA,JA)
 
  375     real(RP) :: pott_toa(IA,JA)
 
  376     real(RP) :: qv_toa  (IA,JA)
 
  377     real(RP) :: qc_toa  (IA,JA)
 
  378     real(RP) :: dens_toa(IA,JA)
 
  379     real(RP) :: temp_toa(IA,JA)
 
  380     real(RP) :: pres_toa(IA,JA)
 
  382     real(RP) :: pott_ke(IA,JA)
 
  383     real(RP) :: qv_ke  (IA,JA)
 
  384     real(RP) :: qc_ke  (IA,JA)
 
  385     real(RP) :: dens_ke(IA,JA)
 
  386     real(RP) :: temp_ke(IA,JA)
 
  387     real(RP) :: pres_ke(IA,JA)
 
  389     real(RP) :: dens_mean
 
  392     real(RP) :: work1(KA,IA,JA)
 
  393     real(RP) :: work2(KA,IA,JA)
 
  394     real(RP) :: work3(KA,IA,JA)
 
  397     logical  :: converged, flag
 
  416                                            pott(:,i,j), qv(:,i,j), qc(:,i,j),                      & 
 
  417                                            pres_sfc(i,j), pott_sfc(i,j), qv_sfc(i,j), qc_sfc(i,j), & 
 
  418                                            cz(:,i,j), fz(:,i,j),                                   & 
 
  420                                            work1(:,i,j), work2(:,i,j), work3(:,i,j),               & 
 
  422                                            dens(:,i,j), temp(:,i,j), pres(:,i,j),                  & 
 
  425        converged = converged .and. flag
 
  430     if ( .not. converged ) 
then 
  431        log_error(
"ATMOS_HYDROSTATIC_buildrho_3D",*) 
"not converged" 
  440           dz(k,i,j) = cz(k+1,i,j) - cz(k,i,j)
 
  442        dz_top(i,j) = fz(ke,i,j) - cz(ke,i,j) 
 
  445        pott_toa(i,j) = pott(ke,i,j)
 
  446        qv_toa(i,j) = qv(ke,i,j)
 
  447        qc_toa(i,j) = qc(ke,i,j)
 
  449        dens_ke(i,j) = dens(ke,i,j)
 
  450        pott_ke(i,j) = pott(ke,i,j)
 
  451        qv_ke(i,j) = qv(ke,i,j)
 
  452        qc_ke(i,j) = qc(ke,i,j)
 
  457     call atmos_hydrostatic_buildrho_atmos_2d( ia, is, ie, ja, js, je, &
 
  458                                               pott_toa(:,:), qv_toa(:,:), qc_toa(:,:),            & 
 
  459                                               dens_ke(:,:), pott_ke(:,:), qv_ke(:,:), qc_ke(:,:), & 
 
  461                                               dens_toa(:,:), temp_toa(:,:), pres_toa(:,:)         ) 
 
  463     call statistics_horizontal_mean( ia, is, ie, ja, js, je, &
 
  464                                      dens_toa(:,:), area(:,:), & 
 
  471        dens_toa(i,j) = dens_mean
 
  477                                                   pott_ke(:,:), qv_ke(:,:), qc_ke(:,:),                   & 
 
  478                                                   dens_toa(:,:), pott_toa(:,:), qv_toa(:,:), qc_toa(:,:), & 
 
  480                                                   dens_ke(:,:), temp_ke(:,:), pres_ke(:,:)                ) 
 
  486        dens(ke,i,j) = dens_ke(i,j)
 
  493                                                   pott(:,:,:), qv(:,:,:), qc(:,:,:), & 
 
  496                                                   temp(:,:,:), pres(:,:,:)           ) 
 
  506        KA, KS, KE, IA, IS, IE, JA, JS, JE, &
 
  519     integer, 
intent(in) :: KA, KS, KE
 
  520     integer, 
intent(in) :: IA, IS, IE
 
  521     integer, 
intent(in) :: JA, JS, JE
 
  523     real(RP), 
intent(in)    :: pott(KA,IA,JA)
 
  524     real(RP), 
intent(in)    :: qv  (KA,IA,JA)
 
  525     real(RP), 
intent(in)    :: qc  (KA,IA,JA)
 
  526     real(RP), 
intent(in)    :: cz  (KA,IA,JA)
 
  528     real(RP), 
intent(inout) :: pres(KA,IA,JA)
 
  530     real(RP), 
intent(out)   :: dens(KA,IA,JA)
 
  531     real(RP), 
intent(out)   :: temp(KA,IA,JA)
 
  533     real(RP) :: dz(KA,IA,JA)
 
  535     real(RP) :: pott_toa(IA,JA)
 
  536     real(RP) :: qv_toa  (IA,JA)
 
  537     real(RP) :: qc_toa  (IA,JA)
 
  543     integer  :: kref(IA,JA)
 
  556           dz(k,i,j) = cz(k+1,i,j) - cz(k,i,j) 
 
  566        pott_toa(i,j) = pott(ke,i,j)
 
  567        qv_toa(i,j) = qv(ke,i,j)
 
  568        qc_toa(i,j) = qc(ke,i,j)
 
  577        kref(i,j) = hydrostatic_buildrho_real_kref + ks - 1
 
  580           if ( pres(k,i,j) .ne. undef ) 
then 
  596        rtot = rdry  * ( 1.0_rp - qv(k,i,j) - qc(k,i,j) ) &
 
  598        cvtot = cvdry * ( 1.0_rp - qv(k,i,j) - qc(k,i,j) ) &
 
  601        cptot = cpdry * ( 1.0_rp - qv(k,i,j) - qc(k,i,j) ) &
 
  604        dens(k,i,j) = p00 / ( rtot * pott(k,i,j) ) * ( pres(k,i,j)/p00 )**(cvtot/cptot)
 
  611                                               pott(:,:,:), qv(:,:,:), qc(:,:,:), & 
 
  614                                               temp(:,:,:), pres(:,:,:),          & 
 
  617                                                   pott(:,:,:), qv(:,:,:), qc(:,:,:), & 
 
  620                                                   temp(:,:,:), pres(:,:,:),          & 
 
  632     dens(   1:ks-1,:,:) = 0.0_rp 
 
  634     dens(ke+1:ka  ,:,:) = 0.0_rp 
 
  647        pott_L2, qv_L2, qc_L2,          &
 
  648        dens_L1, pott_L1, qv_L1, qc_L1, &
 
  650        dens_L2, temp_L2, pres_L2,      &
 
  661     real(RP), 
intent(in)  :: pott_L2
 
  662     real(RP), 
intent(in)  :: qv_L2
 
  663     real(RP), 
intent(in)  :: qc_L2
 
  664     real(RP), 
intent(in)  :: dens_L1
 
  665     real(RP), 
intent(in)  :: pott_L1
 
  666     real(RP), 
intent(in)  :: qv_L1
 
  667     real(RP), 
intent(in)  :: qc_L1
 
  668     real(RP), 
intent(in)  :: dz
 
  669     integer,  
intent(in)  :: k
 
  671     real(RP), 
intent(out) :: dens_L2
 
  672     real(RP), 
intent(out) :: temp_L2
 
  673     real(RP), 
intent(out) :: pres_L2
 
  674     logical,  
intent(out) :: converged
 
  676     real(RP) :: Rtot_L1  , Rtot_L2
 
  677     real(RP) :: CVtot_L1 , CVtot_L2
 
  678     real(RP) :: CPtot_L1 , CPtot_L2
 
  679     real(RP) :: CPovCV_L1, CPovCV_L2
 
  682     real(RP) :: dens_s, dhyd, dgrd
 
  686     rtot_l1   = rdry  * ( 1.0_rp - qv_l1 - qc_l1 ) &
 
  688     cvtot_l1  = cvdry * ( 1.0_rp - qv_l1 - qc_l1 ) &
 
  691     cptot_l1  = cpdry * ( 1.0_rp - qv_l1 - qc_l1 ) &
 
  694     cpovcv_l1 = cptot_l1 / cvtot_l1
 
  696     rtot_l2   = rdry  * ( 1.0_rp - qv_l2 - qc_l2 ) &
 
  698     cvtot_l2  = cvdry * ( 1.0_rp - qv_l2 - qc_l2 ) &
 
  701     cptot_l2  = cpdry * ( 1.0_rp - qv_l2 - qc_l2 ) &
 
  704     cpovcv_l2 = cptot_l2 / cvtot_l2
 
  709     pres_l1 = p00 * ( dens_l1 * rtot_l1 * pott_l1 / p00 )**cpovcv_l1
 
  713        if ( abs(dens_l2-dens_s) <= criteria ) 
then 
  719        pres_l2 = p00 * ( dens_s  * rtot_l2 * pott_l2 / p00 )**cpovcv_l2
 
  721        dhyd = + ( pres_l1 - pres_l2 ) / dz           & 
 
  722               - grav * 0.5_rp * ( dens_l1 + dens_s )   
 
  724        dgrd = - pres_l2  * cpovcv_l2  / dens_s / dz &
 
  727        dens_l2 = max( dens_s - dhyd/dgrd, dens_s * 0.1_rp )
 
  729        if ( dens_l2*0.0_rp /= 0.0_rp ) 
exit 
  732     if ( converged ) 
then 
  733        pres_l2 = p00 * ( dens_l2 * rtot_l2 * pott_l2 / p00 )**cpovcv_l2
 
  734        temp_l2 = pres_l2 / ( dens_l2 * rtot_l2 )
 
  737        log_error(
"ATMOS_HYDROSTATIC_buildrho_atmos_0D",*) 
'iteration not converged!', &
 
  738                   k,dens_l2,ite,dens_s,dhyd,dgrd
 
  771     integer, 
intent(in) :: KA, KS, KE
 
  773     real(RP), 
intent(in)    :: pott(KA)
 
  774     real(RP), 
intent(in)    :: qv  (KA)
 
  775     real(RP), 
intent(in)    :: qc  (KA)
 
  776     real(RP), 
intent(in)    :: dz  (KA)
 
  778     real(RP), 
intent(inout) :: dens(KA)
 
  780     real(RP), 
intent(inout) :: temp(KA)
 
  781     real(RP), 
intent(inout) :: pres(KA)
 
  782     logical,  
intent(out)   :: converged
 
  785     real(RP), 
intent(out) :: Rtot  (KA)
 
  786     real(RP), 
intent(out) :: CPovCV(KA)
 
  788     real(RP) :: Rtot  (KA)
 
  789     real(RP) :: CPovCV(KA)
 
  794     real(RP) :: dens_s, dhyd, dgrd
 
  801        rtot(k) = rdry  * ( 1.0_rp - qv(k) - qc(k) ) &
 
  803        cvtot     = cvdry * ( 1.0_rp - qv(k) - qc(k) ) &
 
  806        cptot     = cpdry * ( 1.0_rp - qv(k) - qc(k) ) &
 
  809        cpovcv(k) = cptot / cvtot
 
  812     pres(ks) = p00 * ( dens(ks) * rtot(ks) * pott(ks) / p00 )**cpovcv(ks)
 
  821           if ( abs(dens(k)-dens_s) <= criteria ) 
then 
  827           pres(k) = p00 * ( dens_s * rtot(k) * pott(k) / p00 )**cpovcv(k)
 
  829           dhyd = + ( pres(k-1) - pres(k) ) / dz(k-1)    & 
 
  830                  - grav * 0.5_rp * ( dens(k-1) + dens_s ) 
 
  832           dgrd = - cpovcv(k) * pres(k) / dens_s / dz(k-1) &
 
  835           dens(k) = max( dens_s - dhyd/dgrd, dens(k-1) * eps )
 
  837           if ( dens(k)*0.0_rp /= 0.0_rp ) 
exit 
  840        if ( .NOT. converged ) 
then 
  842           log_error(
"ATMOS_HYDROSTATIC_buildrho_atmos_1D",*) 
'iteration not converged!', &
 
  843                      k,dens(k),ite,dens_s,dhyd,dgrd
 
  849        pres(k) = p00 * ( dens(k) * rtot(k) * pott(k) / p00 )**cpovcv(k)
 
  853     if ( converged ) 
then 
  855           temp(k) = pres(k) / ( dens(k) * rtot(k) )
 
  858        dens(ke+1:ka  ) = dens(ke)
 
  859        pres(ke+1:ka  ) = pres(ke)
 
  860        temp(ke+1:ka  ) = temp(ke)
 
  888     integer, 
intent(in) :: KA, KS, KE
 
  890     real(RP), 
intent(in)    :: pott(KA)
 
  891     real(RP), 
intent(in)    :: qv  (KA)
 
  892     real(RP), 
intent(in)    :: qc  (KA)
 
  893     real(RP), 
intent(in)    :: dz  (KA)
 
  895     real(RP), 
intent(inout) :: dens(KA)
 
  897     real(RP), 
intent(inout) :: temp(KA)
 
  898     real(RP), 
intent(inout) :: pres(KA)
 
  899     logical,  
intent(out)   :: converged
 
  902     real(RP), 
intent(out) :: Rtot  (KA)
 
  903     real(RP), 
intent(out) :: CPovCV(KA)
 
  905     real(RP) :: Rtot  (KA)
 
  906     real(RP) :: CPovCV(KA)
 
  911     real(RP) :: dens_s, dhyd, dgrd
 
  918        rtot(k) = rdry  * ( 1.0_rp - qv(k) - qc(k) ) &
 
  920        cvtot     = cvdry * ( 1.0_rp - qv(k) - qc(k) ) &
 
  923        cptot     = cpdry * ( 1.0_rp - qv(k) - qc(k) ) &
 
  926        cpovcv(k) = cptot / cvtot
 
  929     pres(ke) = p00 * ( dens(ke) * rtot(ke) * pott(ke) / p00 )**cpovcv(ke)
 
  938           if ( abs(dens(k)-dens_s) <= criteria ) 
then 
  944           pres(k) = p00 * ( dens_s * rtot(k) * pott(k) / p00 )**cpovcv(k)
 
  946           dhyd = - ( pres(k+1) - pres(k) ) / dz(k)        & 
 
  947                  - grav * 0.5_rp * ( dens(k+1) + dens_s ) 
 
  949           dgrd = + cpovcv(k) * pres(k) / dens_s / dz(k) &
 
  952           dens(k) = dens_s - dhyd/dgrd
 
  954           if ( dens(k)*0.0_rp /= 0.0_rp ) 
exit 
  957        if ( .NOT. converged ) 
then 
  959           log_error(
"ATMOS_HYDROSTATIC_buildrho_atmos_rev_1D",*) 
'iteration not converged!', &
 
  960                      k,dens(k),ite,dens_s,dhyd,dgrd
 
  966        pres(k) = p00 * ( dens(k) * rtot(k) * pott(k) / p00 )**cpovcv(k)
 
  970     if ( converged ) 
then 
  972           temp(k) = pres(k) / ( dens(k) * rtot(k) )
 
  985   subroutine atmos_hydrostatic_buildrho_atmos_2d( &
 
  986        IA, IS, IE, JA, JS, JE, &
 
  987        pott_L2, qv_L2, qc_L2,          &
 
  988        dens_L1, pott_L1, qv_L1, qc_L1, &
 
  990        dens_L2, temp_L2, pres_L2       )
 
  994     integer, 
intent(in) :: IA, IS, IE
 
  995     integer, 
intent(in) :: JA, JS, JE
 
  997     real(RP), 
intent(in)  :: pott_L2(IA,JA)
 
  998     real(RP), 
intent(in)  :: qv_L2  (IA,JA)
 
  999     real(RP), 
intent(in)  :: qc_L2  (IA,JA)
 
 1000     real(RP), 
intent(in)  :: dens_L1(IA,JA)
 
 1001     real(RP), 
intent(in)  :: pott_L1(IA,JA)
 
 1002     real(RP), 
intent(in)  :: qv_L1  (IA,JA)
 
 1003     real(RP), 
intent(in)  :: qc_L1  (IA,JA)
 
 1004     real(RP), 
intent(in)  :: dz     (IA,JA)
 
 1005     integer,  
intent(in)  :: k
 
 1007     real(RP), 
intent(out) :: dens_L2(IA,JA)
 
 1008     real(RP), 
intent(out) :: temp_L2(IA,JA)
 
 1009     real(RP), 
intent(out) :: pres_L2(IA,JA)
 
 1011     logical :: converged, flag
 
 1024             pott_l2(i,j), qv_l2(i,j), qc_l2(i,j),               & 
 
 1025             dens_l1(i,j), pott_l1(i,j), qv_l1(i,j), qc_l1(i,j), & 
 
 1027             dens_l2(i,j), temp_l2(i,j), pres_l2(i,j),           & 
 
 1029        converged = converged .and. flag
 
 1034     if ( .not. converged ) 
then 
 1035        log_error(
"ATMOS_HYDROSTATIC_buildrho_atmos_2D",*) 
"not converged" 
 1040   end subroutine atmos_hydrostatic_buildrho_atmos_2d
 
 1045        IA, IS, IE, JA, JS, JE, &
 
 1046        pott_L1, qv_L1, qc_L1,          &
 
 1047        dens_L2, pott_L2, qv_L2, qc_L2, &
 
 1049        dens_L1, temp_L1, pres_L1       )
 
 1053     integer, 
intent(in) :: IA, IS, IE
 
 1054     integer, 
intent(in) :: JA, JS, JE
 
 1056     real(RP), 
intent(in)  :: pott_L1(IA,JA)
 
 1057     real(RP), 
intent(in)  :: qv_L1  (IA,JA)
 
 1058     real(RP), 
intent(in)  :: qc_L1  (IA,JA)
 
 1059     real(RP), 
intent(in)  :: dens_L2(IA,JA)
 
 1060     real(RP), 
intent(in)  :: pott_L2(IA,JA)
 
 1061     real(RP), 
intent(in)  :: qv_L2  (IA,JA)
 
 1062     real(RP), 
intent(in)  :: qc_L2  (IA,JA)
 
 1063     real(RP), 
intent(in)  :: dz     (IA,JA)
 
 1064     integer,  
intent(in)  :: k
 
 1066     real(RP), 
intent(out) :: dens_L1(IA,JA)
 
 1067     real(RP), 
intent(out) :: temp_L1(IA,JA)
 
 1068     real(RP), 
intent(out) :: pres_L1(IA,JA)
 
 1070     logical :: converged, flag
 
 1083             pott_l1(i,j), qv_l1(i,j), qc_l1(i,j),               & 
 
 1084             dens_l2(i,j), pott_l2(i,j), qv_l2(i,j), qc_l2(i,j), & 
 
 1086             dens_l1(i,j), temp_l1(i,j), pres_l1(i,j),           & 
 
 1088        converged = converged .and. flag
 
 1093     if ( .not. converged ) 
then 
 1094        log_error(
"ATMOS_HYDROSTATIC_buildrho_atmos_rev_2D",*) 
"not converged" 
 1104        KA, KS, KE, IA, IS, IE, JA, JS, JE, &
 
 1113     integer, 
intent(in) :: KA, KS, KE
 
 1114     integer, 
intent(in) :: IA, IS, IE
 
 1115     integer, 
intent(in) :: JA, JS, JE
 
 1117     real(RP), 
intent(in)    :: pott(KA,IA,JA)
 
 1118     real(RP), 
intent(in)    :: qv  (KA,IA,JA)
 
 1119     real(RP), 
intent(in)    :: qc  (KA,IA,JA)
 
 1120     real(RP), 
intent(in)    :: dz  (KA,IA,JA)
 
 1122     real(RP), 
intent(inout) :: dens(KA,IA,JA)
 
 1124     real(RP), 
intent(inout) :: temp(KA,IA,JA)
 
 1125     real(RP), 
intent(inout) :: pres(KA,IA,JA)
 
 1127     integer, 
intent(in), 
optional, 
target :: kref(IA,JA)
 
 1129     integer, 
pointer :: kref_(:,:)
 
 1132     real(RP) :: work1(KA,IA,JA)
 
 1133     real(RP) :: work2(KA,IA,JA)
 
 1136     logical :: converged, flag
 
 1140     if ( 
present(kref) ) 
then 
 1143        allocate( kref_(ia,ja) )
 
 1163        if ( kref_(i,j) < ke ) 
then 
 1165                                                     pott(:,i,j), qv(:,i,j), qc(:,i,j), & 
 
 1168                                                     work1(:,i,j), work2(:,i,j),        & 
 
 1171                                                     temp(:,i,j), pres(:,i,j),          & 
 
 1173           converged = converged .and. flag
 
 1179     if ( .not. converged ) 
then 
 1180        log_error(
"ATMOS_HYDROSTATIC_buildrho_atmos_3D",*) 
"not converged" 
 1184     if ( .not. 
present(kref) ) 
then 
 1195        KA, KS, KE, IA, IS, IE, JA, JS, JE, &
 
 1205     integer,  
intent(in)    :: KA, KS, KE
 
 1206     integer,  
intent(in)    :: IA, IS, IE
 
 1207     integer,  
intent(in)    :: JA, JS, JE
 
 1208     real(RP), 
intent(inout) :: dens(KA,IA,JA)
 
 1209     real(RP), 
intent(inout) :: temp(KA,IA,JA)
 
 1210     real(RP), 
intent(inout) :: pres(KA,IA,JA)
 
 1211     real(RP), 
intent(in)    :: pott(KA,IA,JA)
 
 1212     real(RP), 
intent(in)    :: qv  (KA,IA,JA)
 
 1213     real(RP), 
intent(in)    :: qc  (KA,IA,JA)
 
 1214     real(RP), 
intent(in)    :: dz  (KA,IA,JA)
 
 1215     integer,  
intent(in), 
optional, 
target :: kref(IA,JA)
 
 1217     integer, 
pointer :: kref_(:,:)
 
 1218     logical :: converged, flag
 
 1221     real(RP) :: work1(KA,IA,JA)
 
 1222     real(RP) :: work2(KA,IA,JA)
 
 1228     if ( 
present(kref) ) 
then 
 1237           if ( kref_(i,j) > ks ) 
then 
 1239                                                            pott(:,i,j), qv(:,i,j), qc(:,i,j), & 
 
 1242                                                            work1(:,i,j), work2(:,i,j),        & 
 
 1245                                                            temp(:,i,j), pres(:,i,j),          & 
 
 1247              converged = converged .and. flag
 
 1261                                                         pott(:,i,j), qv(:,i,j), qc(:,i,j), & 
 
 1264                                                         work1(:,i,j), work2(:,i,j),        & 
 
 1267                                                         temp(:,i,j), pres(:,i,j),          & 
 
 1269           converged = converged .and. flag
 
 1275     if ( .not. converged ) 
then 
 1276        log_error(
"ATMOS_HYDROSTATIC_buildrho_atmos_rev_3D",*) 
"not converged" 
 1289        pres_sfc, temp_sfc, qv_sfc, qc_sfc, &
 
 1292        dz, work1, work2, work3,            &
 
 1294        dens, pott, pres, pott_sfc,         &
 
 1305     integer, 
intent(in) :: KA, KS, KE
 
 1307     real(RP), 
intent(in)  :: temp(KA)
 
 1308     real(RP), 
intent(in)  :: qv  (KA)
 
 1309     real(RP), 
intent(in)  :: qc  (KA)
 
 1310     real(RP), 
intent(in)  :: pres_sfc
 
 1311     real(RP), 
intent(in)  :: temp_sfc
 
 1312     real(RP), 
intent(in)  :: qv_sfc
 
 1313     real(RP), 
intent(in)  :: qc_sfc
 
 1314     real(RP), 
intent(in)  :: cz(  KA)
 
 1315     real(RP), 
intent(in)  :: fz(0:KA)
 
 1317     real(RP), 
intent(out) :: dens(KA)
 
 1318     real(RP), 
intent(out) :: pott(KA)
 
 1319     real(RP), 
intent(out) :: pres(KA)
 
 1320     real(RP), 
intent(out) :: pott_sfc
 
 1321     logical,  
intent(out) :: converged
 
 1324     real(RP), 
intent(out) :: dz(KA)
 
 1325     real(RP), 
intent(out) :: work1(KA)
 
 1326     real(RP), 
intent(out) :: work2(KA)
 
 1327     real(RP), 
intent(out) :: work3(KA)
 
 1332     real(RP) :: dens_sfc
 
 1334     real(RP) :: Rtot_sfc
 
 1335     real(RP) :: CVtot_sfc
 
 1336     real(RP) :: CPtot_sfc
 
 1341     real(RP) :: RovCP_sfc
 
 1342     real(RP) :: dens_s, dhyd, dgrd
 
 1350     rtot_sfc   = rdry  * ( 1.0_rp - qv_sfc - qc_sfc ) &
 
 1352     cvtot_sfc  = cvdry * ( 1.0_rp - qv_sfc - qc_sfc ) &
 
 1355     cptot_sfc  = cpdry * ( 1.0_rp - qv_sfc - qc_sfc ) &
 
 1359     rtot   = rdry  * ( 1.0_rp - qv(ks) - qc(ks) ) &
 
 1361     cvtot  = cvdry * ( 1.0_rp - qv(ks) - qc(ks) ) &
 
 1364     cptot  = cpdry * ( 1.0_rp - qv(ks) - qc(ks) ) &
 
 1369     rovcp_sfc = rtot_sfc / cptot_sfc
 
 1370     dens_sfc  = pres_sfc / ( rtot_sfc * temp_sfc )
 
 1371     pott_sfc  = temp_sfc * ( p00/pres_sfc )**rovcp_sfc
 
 1377     dz(ks-1) = cz(ks) - fz(ks-1)
 
 1379        dz(k) = cz(k+1) - cz(k)
 
 1384        if ( abs(dens(ks)-dens_s) <= criteria ) 
then 
 1391        dhyd = + ( pres_sfc - dens_s * rtot * temp(ks) ) / dz(ks-1) & 
 
 1392               - grav * 0.5_rp * ( dens_sfc + dens_s )                
 
 1394        dgrd = - rtot * temp(ks) / dz(ks-1) &
 
 1397        dens(ks) = dens_s - dhyd/dgrd
 
 1399        if ( dens(ks)*0.0_rp /= 0.0_rp ) 
exit 
 1402     if ( converged ) 
then 
 1405                                                         temp(:), qv(:), qc(:), & 
 
 1408                                                         work1(:), work2(:), work3(:), & 
 
 1416     if ( .not. converged ) 
then 
 1417        log_error(
"ATMOS_HYDROSTATIC_buildrho_bytemp_1D",*) 
'iteration not converged!', &
 
 1418                   dens(ks),ite,dens_s,dhyd,dgrd
 
 1429        KA, KS, KE, IA, IS, IE, JA, JS, JE, &
 
 1431        pres_sfc, temp_sfc, qv_sfc, qc_sfc, &
 
 1438     integer, 
intent(in) :: KA, KS, KE
 
 1439     integer, 
intent(in) :: IA, IS, IE
 
 1440     integer, 
intent(in) :: JA, JS, JE
 
 1442     real(RP), 
intent(in)  :: temp(KA,IA,JA)
 
 1443     real(RP), 
intent(in)  :: qv  (KA,IA,JA)
 
 1444     real(RP), 
intent(in)  :: qc  (KA,IA,JA)
 
 1445     real(RP), 
intent(in)  :: pres_sfc(IA,JA)
 
 1446     real(RP), 
intent(in)  :: temp_sfc(IA,JA)
 
 1447     real(RP), 
intent(in)  :: qv_sfc  (IA,JA)
 
 1448     real(RP), 
intent(in)  :: qc_sfc  (IA,JA)
 
 1449     real(RP), 
intent(in)  :: cz(KA,IA,JA)
 
 1450     real(RP), 
intent(in)  :: fz(KA,IA,JA)
 
 1452     real(RP), 
intent(out) :: dens(KA,IA,JA)
 
 1453     real(RP), 
intent(out) :: pott(KA,IA,JA)
 
 1454     real(RP), 
intent(out) :: pres(KA,IA,JA)
 
 1455     real(RP), 
intent(out) :: pott_sfc(IA,JA)
 
 1457     logical :: converged, flag
 
 1460     real(RP) :: work1(KA,IA,JA)
 
 1461     real(RP) :: work2(KA,IA,JA)
 
 1462     real(RP) :: work3(KA,IA,JA)
 
 1463     real(RP) :: work4(KA,IA,JA)
 
 1479                                                   temp(:,i,j), qv(:,i,j), qc(:,i,j),                      & 
 
 1480                                                   pres_sfc(i,j), temp_sfc(i,j), qv_sfc(i,j), qc_sfc(i,j), & 
 
 1481                                                   cz(:,i,j), fz(:,i,j),                                   & 
 
 1483                                                   work1(:,i,j), work2(:,i,j), work3(:,i,j), work4(:,i,j), & 
 
 1485                                                   dens(:,i,j), pott(:,i,j), pres(:,i,j),                  & 
 
 1488        converged = converged .and. flag
 
 1493     if ( .not. converged ) 
then 
 1494        log_error(
"ATMOS_HYDROSTATIC_buildrho_bytemp_3D",*) 
"not converged" 
 1525     integer, 
intent(in) :: KA, KS, KE
 
 1527     real(RP), 
intent(in)    :: temp(KA)
 
 1528     real(RP), 
intent(in)    :: qv  (KA)
 
 1529     real(RP), 
intent(in)    :: qc  (KA)
 
 1530     real(RP), 
intent(in)    :: dz  (KA)
 
 1532     real(RP), 
intent(inout) :: dens(KA)
 
 1534     real(RP), 
intent(out)   :: pott(KA)
 
 1535     real(RP), 
intent(out)   :: pres(KA)
 
 1536     logical,  
intent(out)   :: converged
 
 1539     real(RP), 
intent(out) :: Rtot  (KA)
 
 1540     real(RP), 
intent(out) :: CVtot (KA)
 
 1541     real(RP), 
intent(out) :: CPtot (KA)
 
 1543     real(RP) :: Rtot  (KA)
 
 1544     real(RP) :: CVtot (KA)
 
 1545     real(RP) :: CPtot (KA)
 
 1549     real(RP) :: dens_s, dhyd, dgrd
 
 1556        rtot(k) = rdry  * ( 1.0_rp - qv(k) - qc(k) ) &
 
 1558        cvtot(k) = cvdry * ( 1.0_rp - qv(k) - qc(k) ) &
 
 1561        cptot(k) = cpdry * ( 1.0_rp - qv(k) - qc(k) ) &
 
 1566     pres(ks) = dens(ks) * rtot(ks) * temp(ks)
 
 1575           if ( abs(dens(k)-dens_s) <= criteria ) 
then 
 1582           dhyd = + ( pres(k-1) - dens_s * rtot(k) * temp(k) ) / dz(k-1) & 
 
 1583                  - grav * 0.5_rp * ( dens(k-1) + dens_s )            
 
 1585           dgrd = - rtot(k) * temp(k) / dz(k-1) &
 
 1588           dens(k) = dens_s - dhyd/dgrd
 
 1590           if ( dens(k)*0.0_rp /= 0.0_rp ) 
exit 
 1593        if ( .NOT. converged ) 
then 
 1595           log_error(
"ATMOS_HYDROSTATIC_buildrho_bytemp_atmos_1D",*) 
'iteration not converged!', &
 
 1596                      k,dens(k),ite,dens_s,dhyd,dgrd
 
 1602        pres(k) = dens(k) * rtot(k) * temp(k)
 
 1606     if ( converged ) 
then 
 1608           rovcp   = rtot(k) / cptot(k)
 
 1609           pott(k) = temp(k) * ( p00 / pres(k) )**rovcp
 
 1640     integer, 
intent(in) :: KA, KS, KE
 
 1642     real(RP), 
intent(in)    :: temp(KA)
 
 1643     real(RP), 
intent(in)    :: qv  (KA)
 
 1644     real(RP), 
intent(in)    :: qc  (KA)
 
 1645     real(RP), 
intent(in)    :: dz  (KA)
 
 1647     real(RP), 
intent(inout) :: dens(KA)
 
 1649     real(RP), 
intent(out)   :: pott(KA)
 
 1650     real(RP), 
intent(out)   :: pres(KA)
 
 1651     logical,  
intent(out)   :: converged
 
 1654     real(RP), 
intent(out) :: Rtot  (KA)
 
 1655     real(RP), 
intent(out) :: CVtot (KA)
 
 1656     real(RP), 
intent(out) :: CPtot (KA)
 
 1658     real(RP) :: Rtot  (KA)
 
 1659     real(RP) :: CVtot (KA)
 
 1660     real(RP) :: CPtot (KA)
 
 1664     real(RP) :: dens_s, dhyd, dgrd
 
 1671        rtot(k) = rdry  * ( 1.0_rp - qv(k) - qc(k) ) &
 
 1673        cvtot(k) = cvdry * ( 1.0_rp - qv(k) - qc(k) ) &
 
 1676        cptot(k) = cpdry * ( 1.0_rp - qv(k) - qc(k) ) &
 
 1681     pres(ke) = dens(ke) * rtot(ke) * temp(ke)
 
 1690           if ( abs(dens(k)-dens_s) <= criteria ) 
then 
 1697           dhyd = - ( pres(k+1) - dens_s * rtot(k) * temp(k) ) / dz(k) & 
 
 1698                  - grav * 0.5_rp * ( dens(k+1) + dens_s )               
 
 1700           dgrd = + rtot(k) * temp(k) / dz(k) &
 
 1703           dens(k) = dens_s - dhyd/dgrd
 
 1705           if ( dens(k)*0.0_rp /= 0.0_rp ) 
exit 
 1708        if ( .NOT. converged ) 
then 
 1710           log_error(
"ATMOS_HYDROSTATIC_buildrho_bytemp_atmos_rev_1D",*) 
'iteration not converged!', &
 
 1711                      k,dens(k),ite,dens_s,dhyd,dgrd
 
 1717        pres(k) = dens(k) * rtot(k) * temp(k)
 
 1721     if ( converged ) 
then 
 1723           rovcp   = rtot(k) / cptot(k)
 
 1724           pott(k) = temp(k) * ( p00 / pres(k) )**rovcp
 
 1734        KA, KS, KE, IA, IS, IE, JA, JS, JE, &
 
 1742     integer, 
intent(in) :: KA, KS, KE
 
 1743     integer, 
intent(in) :: IA, IS, IE
 
 1744     integer, 
intent(in) :: JA, JS, JE
 
 1746     real(RP), 
intent(in)    :: temp(KA,IA,JA)
 
 1747     real(RP), 
intent(in)    :: qv  (KA,IA,JA)
 
 1748     real(RP), 
intent(in)    :: qc  (KA,IA,JA)
 
 1749     real(RP), 
intent(in)    :: dz  (KA,IA,JA)
 
 1751     real(RP), 
intent(inout) :: dens(KA,IA,JA)
 
 1752     real(RP), 
intent(out)   :: pott(KA,IA,JA)
 
 1753     real(RP), 
intent(out)   :: pres(KA,IA,JA)
 
 1755     logical :: converged, flag
 
 1758     real(RP) :: work1(KA,IA,JA)
 
 1759     real(RP) :: work2(KA,IA,JA)
 
 1760     real(RP) :: work3(KA,IA,JA)
 
 1774                                                         temp(:,i,j), qv(:,i,j), qc(:,i,j), & 
 
 1777                                                         work1(:,i,j), work2(:,i,j), work3(:,i,j), & 
 
 1780                                                         pott(:,i,j), pres(:,i,j),          & 
 
 1782        converged = converged .and. flag
 
 1787     if ( .not. converged ) 
then 
 1788        log_error(
"ATMOS_HYDROSTATIC_buildrho_bytemp_atmos_3D",*) 
"iteration not converged" 
 1806     integer,  
intent(in)  :: KA, KS, KE
 
 1808     real(RP), 
intent(in)  :: pres(KA)
 
 1809     real(RP), 
intent(in)  :: temp(KA)
 
 1810     real(RP), 
intent(in)  :: qv  (KA)
 
 1811     real(RP), 
intent(in)  :: cz  (KA)
 
 1813     real(RP), 
intent(out) :: mslp
 
 1820     kref = hydrostatic_barometric_law_mslp_kref + ks - 1
 
 1823     vtemp = temp(kref) * (1.0_rp + epstvap * qv(kref) )
 
 1826     mslp = pres(kref) * ( ( vtemp + laps * cz(kref) ) / vtemp ) ** ( grav / ( rdry * laps ) )
 
 1833   subroutine atmos_hydrostatic_barometric_law_mslp_2d( &
 
 1834        KA, KS, KE, IA, IS, IE, JA, JS, JE, &
 
 1839     integer,  
intent(in) :: KA, KS, KE
 
 1840     integer,  
intent(in) :: IA, IS, IE
 
 1841     integer,  
intent(in) :: JA, JS, JE
 
 1843     real(RP), 
intent(in)  :: pres(KA,IA,JA)
 
 1844     real(RP), 
intent(in)  :: temp(KA,IA,JA)
 
 1845     real(RP), 
intent(in)  :: qv  (KA,IA,JA)
 
 1846     real(RP), 
intent(in)  :: cz  (KA,IA,JA)
 
 1848     real(RP), 
intent(out) :: mslp(IA,JA)
 
 1858                                                       pres(:,i,j), temp(:,i,j), qv(:,i,j), & 
 
 1866   end subroutine atmos_hydrostatic_barometric_law_mslp_2d
 
 1872   subroutine atmos_hydrostatic_barometric_law_pres_0d( &
 
 1878     real(RP), 
intent(in)  :: mslp
 
 1879     real(RP), 
intent(in)  :: temp
 
 1880     real(RP), 
intent(in)  :: dz
 
 1882     real(RP), 
intent(out) :: pres
 
 1888     tm = temp + laps * dz * 0.5_rp 
 
 1891     pres = mslp / exp( grav * dz / ( rdry * tm ) )
 
 1894   end subroutine atmos_hydrostatic_barometric_law_pres_0d
 
 1898   subroutine atmos_hydrostatic_barometric_law_pres_2d( &
 
 1899        IA, IS, IE, JA, JS, JE, &
 
 1904     integer, 
intent(in) :: IA, IS, IE
 
 1905     integer, 
intent(in) :: JA, JS, JE
 
 1907     real(RP), 
intent(in)  :: mslp(IA,JA)
 
 1908     real(RP), 
intent(in)  :: temp(IA,JA)
 
 1909     real(RP), 
intent(in)  :: dz  (IA,JA)
 
 1911     real(RP), 
intent(out) :: pres(IA,JA)
 
 1920        call atmos_hydrostatic_barometric_law_pres_0d( mslp(i,j), temp(i,j), dz(i,j), & 
 
 1927   end subroutine atmos_hydrostatic_barometric_law_pres_2d