35   public :: atmos_saturation_alpha
 
   37   public :: atmos_saturation_psat_all
 
   38   public :: atmos_saturation_psat_liq
 
   39   public :: atmos_saturation_psat_ice
 
   41   public :: atmos_saturation_psat2qsat_pres
 
   42   public :: atmos_saturation_psat2qsat_dens
 
   44   public :: atmos_saturation_pres2qsat_all
 
   45   public :: atmos_saturation_pres2qsat_liq
 
   46   public :: atmos_saturation_pres2qsat_ice
 
   48   public :: atmos_saturation_dens2qsat_all
 
   49   public :: atmos_saturation_dens2qsat_liq
 
   50   public :: atmos_saturation_dens2qsat_ice
 
   52   public :: atmos_saturation_dalphadt
 
   54   public :: atmos_saturation_dqs_dtem_dens_liq
 
   55   public :: atmos_saturation_dqs_dtem_dens_ice
 
   56   public :: atmos_saturation_dqs_dtem_dpre_liq
 
   57   public :: atmos_saturation_dqs_dtem_dpre_ice
 
   59   public :: atmos_saturation_tdew_liq
 
   61   public :: atmos_saturation_pote
 
   63   public :: atmos_saturation_moist_conversion_dens_liq
 
   64   public :: atmos_saturation_moist_conversion_dens_all
 
   65   public :: atmos_saturation_moist_conversion_pres_liq
 
   67   interface atmos_saturation_alpha
 
   69      module procedure atmos_saturation_alpha_1d
 
   70      module procedure atmos_saturation_alpha_3d
 
   71   end interface atmos_saturation_alpha
 
   73   interface atmos_saturation_psat_all
 
   74      module procedure atmos_saturation_psat_all_0d
 
   75      module procedure atmos_saturation_psat_all_1d
 
   76      module procedure atmos_saturation_psat_all_2d
 
   77      module procedure atmos_saturation_psat_all_3d
 
   78   end interface atmos_saturation_psat_all
 
   79   interface atmos_saturation_psat_liq
 
   80      module procedure atmos_saturation_psat_liq_0d
 
   81      module procedure atmos_saturation_psat_liq_1d
 
   82      module procedure atmos_saturation_psat_liq_2d
 
   83      module procedure atmos_saturation_psat_liq_3d
 
   84   end interface atmos_saturation_psat_liq
 
   85   interface atmos_saturation_psat_ice
 
   86      module procedure atmos_saturation_psat_ice_0d
 
   87      module procedure atmos_saturation_psat_ice_1d
 
   88      module procedure atmos_saturation_psat_ice_2d
 
   89      module procedure atmos_saturation_psat_ice_3d
 
   90   end interface atmos_saturation_psat_ice
 
   92   interface atmos_saturation_psat2qsat_pres
 
   93      module procedure atmos_saturation_psat2qsat_pres_0d
 
   94   end interface atmos_saturation_psat2qsat_pres
 
   95   interface atmos_saturation_psat2qsat_dens
 
   96      module procedure atmos_saturation_psat2qsat_dens_0d
 
   97   end interface atmos_saturation_psat2qsat_dens
 
   99   interface atmos_saturation_pres2qsat_all
 
  100      module procedure atmos_saturation_pres2qsat_all_0d
 
  101      module procedure atmos_saturation_pres2qsat_all_1d
 
  102      module procedure atmos_saturation_pres2qsat_all_2d
 
  103      module procedure atmos_saturation_pres2qsat_all_3d
 
  104   end interface atmos_saturation_pres2qsat_all
 
  105   interface atmos_saturation_pres2qsat_liq
 
  106      module procedure atmos_saturation_pres2qsat_liq_0d
 
  107      module procedure atmos_saturation_pres2qsat_liq_1d
 
  108      module procedure atmos_saturation_pres2qsat_liq_3d
 
  109   end interface atmos_saturation_pres2qsat_liq
 
  110   interface atmos_saturation_pres2qsat_ice
 
  111      module procedure atmos_saturation_pres2qsat_ice_0d
 
  112      module procedure atmos_saturation_pres2qsat_ice_1d
 
  113      module procedure atmos_saturation_pres2qsat_ice_3d
 
  114   end interface atmos_saturation_pres2qsat_ice
 
  116   interface atmos_saturation_dens2qsat_all
 
  117      module procedure atmos_saturation_dens2qsat_all_0d
 
  118      module procedure atmos_saturation_dens2qsat_all_1d
 
  119      module procedure atmos_saturation_dens2qsat_all_3d
 
  120   end interface atmos_saturation_dens2qsat_all
 
  121   interface atmos_saturation_dens2qsat_liq
 
  122      module procedure atmos_saturation_dens2qsat_liq_0d
 
  123      module procedure atmos_saturation_dens2qsat_liq_1d
 
  124      module procedure atmos_saturation_dens2qsat_liq_3d
 
  125   end interface atmos_saturation_dens2qsat_liq
 
  126   interface atmos_saturation_dens2qsat_ice
 
  127      module procedure atmos_saturation_dens2qsat_ice_0d
 
  128      module procedure atmos_saturation_dens2qsat_ice_1d
 
  129      module procedure atmos_saturation_dens2qsat_ice_3d
 
  130   end interface atmos_saturation_dens2qsat_ice
 
  132   interface atmos_saturation_dalphadt
 
  133      module procedure atmos_saturation_dalphadt_0d
 
  134      module procedure atmos_saturation_dalphadt_1d
 
  135      module procedure atmos_saturation_dalphadt_3d
 
  136   end interface atmos_saturation_dalphadt
 
  138   interface atmos_saturation_dqs_dtem_dens_liq
 
  139      module procedure atmos_saturation_dqs_dtem_dens_liq_0d
 
  141      module procedure atmos_saturation_dqs_dtem_dens_liq_3d
 
  142   end interface atmos_saturation_dqs_dtem_dens_liq
 
  143   interface atmos_saturation_dqs_dtem_dens_ice
 
  144      module procedure atmos_saturation_dqs_dtem_dens_ice_0d
 
  146      module procedure atmos_saturation_dqs_dtem_dens_ice_3d
 
  147   end interface atmos_saturation_dqs_dtem_dens_ice
 
  148   interface atmos_saturation_dqs_dtem_dpre_liq
 
  149      module procedure atmos_saturation_dqs_dtem_dpre_liq_0d
 
  151      module procedure atmos_saturation_dqs_dtem_dpre_liq_3d
 
  152   end interface atmos_saturation_dqs_dtem_dpre_liq
 
  153   interface atmos_saturation_dqs_dtem_dpre_ice
 
  154      module procedure atmos_saturation_dqs_dtem_dpre_ice_0d
 
  156      module procedure atmos_saturation_dqs_dtem_dpre_ice_3d
 
  157   end interface atmos_saturation_dqs_dtem_dpre_ice
 
  159   interface atmos_saturation_tdew_liq
 
  160      module procedure atmos_saturation_tdew_liq_0d
 
  162      module procedure atmos_saturation_tdew_liq_3d
 
  163   end interface atmos_saturation_tdew_liq
 
  165   interface atmos_saturation_pote
 
  168      module procedure atmos_saturation_pote_3d
 
  169   end interface atmos_saturation_pote
 
  171   interface atmos_saturation_moist_conversion_dens_liq
 
  172      module procedure atmos_saturation_moist_conversion_dens_liq_0d
 
  173   end interface atmos_saturation_moist_conversion_dens_liq
 
  174   interface atmos_saturation_moist_conversion_dens_all
 
  176   end interface atmos_saturation_moist_conversion_dens_all
 
  177   interface atmos_saturation_moist_conversion_pres_liq
 
  179   end interface atmos_saturation_moist_conversion_pres_liq
 
  193   real(RP), 
private, 
parameter :: TEM_MIN = 10.0_rp
 
  195   real(RP), 
private :: ATMOS_SATURATION_ULIMIT_TEMP = 273.15_rp 
 
  196   real(RP), 
private :: ATMOS_SATURATION_LLIMIT_TEMP = 233.15_rp 
 
  198   real(RP), 
private :: RTEM00
 
  199   real(RP), 
private :: dalphadT_const
 
  200   real(RP), 
private :: psat_min_liq
 
  201   real(RP), 
private :: psat_min_ice
 
  203   real(RP), 
private :: CPovR_liq
 
  204   real(RP), 
private :: CPovR_ice
 
  205   real(RP), 
private :: CVovR_liq
 
  206   real(RP), 
private :: CVovR_ice
 
  207   real(RP), 
private :: LovR_liq
 
  208   real(RP), 
private :: LovR_ice
 
  231     namelist / param_atmos_saturation / &
 
  232        atmos_saturation_ulimit_temp, &
 
  233        atmos_saturation_llimit_temp
 
  239     log_info(
"ATMOS_SATURATION_setup",*) 
'Setup' 
  243     read(
io_fid_conf,nml=param_atmos_saturation,iostat=ierr)
 
  245        log_info(
"ATMOS_SATURATION_setup",*) 
'Not found namelist. Default used.' 
  246     elseif( ierr > 0 ) 
then  
  247        log_error(
"ATMOS_SATURATION_setup",*) 
'Not appropriate names in namelist PARAM_ATMOS_SATURATION. Check!' 
  250     log_nml(param_atmos_saturation)
 
  252     rtem00 = 1.0_rp / tem00
 
  256        cpovr_liq = ( cpvap - cl ) / rvap
 
  257        cpovr_ice = ( cpvap - ci ) / rvap
 
  258        cvovr_liq = ( cvvap - cl ) / rvap
 
  259        cvovr_ice = ( cvvap - ci ) / rvap
 
  261        lovr_liq  = lhv00 / rvap
 
  262        lovr_ice  = lhs00 / rvap
 
  271        lovr_liq  = lhv0 / rvap
 
  272        lovr_ice  = lhs0 / rvap
 
  276     dalphadt_const = 1.0_rp / ( atmos_saturation_ulimit_temp - atmos_saturation_llimit_temp )
 
  279     log_info(
"ATMOS_SATURATION_setup",
'(1x,A,F7.2,A,F7.2)') 
'Temperature range for liquid/ice mixture : ', &
 
  280                                                       atmos_saturation_llimit_temp, 
' - ', &
 
  281                                                       atmos_saturation_ulimit_temp
 
  285     call atmos_saturation_psat_liq( tem_min, psat_min_liq ) 
 
  286     call atmos_saturation_psat_ice( tem_min, psat_min_ice ) 
 
  298     real(RP), 
intent(in)  :: temp
 
  299     real(RP), 
intent(out) :: alpha
 
  302     alpha = ( temp                         - atmos_saturation_llimit_temp ) &
 
  303           / ( atmos_saturation_ulimit_temp - atmos_saturation_llimit_temp )
 
  305     alpha = min( max( alpha, 0.0_rp ), 1.0_rp )
 
  313   subroutine atmos_saturation_alpha_1d( &
 
  318     integer,  
intent(in)  :: KA, KS, KE
 
  320     real(RP), 
intent(in)  :: temp (KA)
 
  322     real(RP), 
intent(out) :: alpha(KA)
 
  333   end subroutine atmos_saturation_alpha_1d
 
  337   subroutine atmos_saturation_alpha_3d( &
 
  338        KA, KS, KE, IA, IS, IE, JA, JS, JE, &
 
  342     integer, 
intent(in) :: KA, KS, KE
 
  343     integer, 
intent(in) :: IA, IS, IE
 
  344     integer, 
intent(in) :: JA, JS, JE
 
  346     real(RP), 
intent(in)  :: temp (KA,IA,JA)
 
  347     real(RP), 
intent(out) :: alpha(KA,IA,JA)
 
  364   end subroutine atmos_saturation_alpha_3d
 
  368   subroutine atmos_saturation_psat_all_0d( &
 
  373     real(RP), 
intent(in)  :: temp
 
  374     real(RP), 
intent(out) :: psat
 
  376     real(RP) :: alpha, psatl, psati
 
  379     call atmos_saturation_alpha   ( temp, alpha )
 
  380     call atmos_saturation_psat_liq( temp, psatl )
 
  381     call atmos_saturation_psat_ice( temp, psati )
 
  383     psat = psatl * (          alpha ) &
 
  384          + psati * ( 1.0_rp - alpha )
 
  387   end subroutine atmos_saturation_psat_all_0d
 
  392   subroutine atmos_saturation_psat_all_1d( &
 
  397     integer,  
intent(in)  :: KA, KS, KE
 
  399     real(RP), 
intent(in)  :: temp(KA)
 
  400     real(RP), 
intent(out) :: psat(KA)
 
  406        call atmos_saturation_psat_all_0d( temp(k), & 
 
  411   end subroutine atmos_saturation_psat_all_1d
 
  415   subroutine atmos_saturation_psat_all_2d( &
 
  421     integer,  
intent(in)  :: IA, IS, IE
 
  422     integer,  
intent(in)  :: JA, JS, JE
 
  424     real(RP), 
intent(in)  :: temp(IA,JA)
 
  426     real(RP), 
intent(out) :: psat(IA,JA)
 
  434        call atmos_saturation_psat_all_0d( temp(i,j), & 
 
  440   end subroutine atmos_saturation_psat_all_2d
 
  444   subroutine atmos_saturation_psat_all_3d( &
 
  452     integer,  
intent(in)  :: KA, KS, KE
 
  453     integer,  
intent(in)  :: IA, IS, IE
 
  454     integer,  
intent(in)  :: JA, JS, JE
 
  456     real(RP), 
intent(in)  :: temp(KA,IA,JA)
 
  457     real(RP), 
intent(out) :: psat(KA,IA,JA)
 
  466        call atmos_saturation_psat_all_0d( temp(k,i,j), & 
 
  473   end subroutine atmos_saturation_psat_all_3d
 
  477   subroutine atmos_saturation_psat_liq_0d( &
 
  482     real(RP), 
intent(in)  :: temp
 
  483     real(RP), 
intent(out) :: psat
 
  486     psat = psat0 * ( temp * rtem00 )**cpovr_liq             &
 
  487                  * exp( lovr_liq * ( rtem00 - 1.0_rp/temp ) )
 
  490   end subroutine atmos_saturation_psat_liq_0d
 
  495   subroutine atmos_saturation_psat_liq_1d( &
 
  500     integer,  
intent(in)  :: KA, KS, KE
 
  502     real(RP), 
intent(in)  :: temp(KA)
 
  503     real(RP), 
intent(out) :: psat(KA)
 
  509        call atmos_saturation_psat_liq_0d( temp(k), &
 
  514   end subroutine atmos_saturation_psat_liq_1d
 
  518   subroutine atmos_saturation_psat_liq_2d( &
 
  525     integer,  
intent(in)  :: IA, IS, IE
 
  526     integer,  
intent(in)  :: JA, JS, JE
 
  528     real(RP), 
intent(in)  :: temp(IA,JA)
 
  529     real(RP), 
intent(out) :: psat(IA,JA)
 
  537        call atmos_saturation_psat_liq_0d( temp(i,j), & 
 
  543   end subroutine atmos_saturation_psat_liq_2d
 
  547   subroutine atmos_saturation_psat_liq_3d( &
 
  555     integer,  
intent(in)  :: KA, KS, KE
 
  556     integer,  
intent(in)  :: IA, IS, IE
 
  557     integer,  
intent(in)  :: JA, JS, JE
 
  559     real(RP), 
intent(in)  :: temp(KA,IA,JA)
 
  560     real(RP), 
intent(out) :: psat(KA,IA,JA)
 
  569        call atmos_saturation_psat_liq_0d( temp(k,i,j), & 
 
  576   end subroutine atmos_saturation_psat_liq_3d
 
  580   subroutine atmos_saturation_psat_ice_0d( &
 
  585     real(RP), 
intent(in)  :: temp
 
  587     real(RP), 
intent(out) :: psat
 
  590     psat = psat0 * ( temp * rtem00 )**cpovr_ice             &
 
  591                  * exp( lovr_ice * ( rtem00 - 1.0_rp/temp ) )
 
  594   end subroutine atmos_saturation_psat_ice_0d
 
  599   subroutine atmos_saturation_psat_ice_1d( &
 
  604     integer,  
intent(in)  :: KA, KS, KE
 
  606     real(RP), 
intent(in)  :: temp(KA)
 
  607     real(RP), 
intent(out) :: psat(KA)
 
  613        call atmos_saturation_psat_ice_0d( temp(k), & 
 
  618   end subroutine atmos_saturation_psat_ice_1d
 
  622   subroutine atmos_saturation_psat_ice_2d( &
 
  629     integer,  
intent(in)  :: IA, IS, IE
 
  630     integer,  
intent(in)  :: JA, JS, JE
 
  632     real(RP), 
intent(in)  :: temp(IA,JA)
 
  633     real(RP), 
intent(out) :: psat(IA,JA)
 
  641        call atmos_saturation_psat_ice_0d( temp(i,j), & 
 
  647   end subroutine atmos_saturation_psat_ice_2d
 
  651   subroutine atmos_saturation_psat_ice_3d( &
 
  659     integer,  
intent(in)  :: KA, KS, KE
 
  660     integer,  
intent(in)  :: IA, IS, IE
 
  661     integer,  
intent(in)  :: JA, JS, JE
 
  663     real(RP), 
intent(in)  :: temp(KA,IA,JA)
 
  664     real(RP), 
intent(out) :: psat(KA,IA,JA)
 
  673        call atmos_saturation_psat_ice_0d( temp(k,i,j), & 
 
  680   end subroutine atmos_saturation_psat_ice_3d
 
  685   subroutine atmos_saturation_psat2qsat_pres_0d( &
 
  690     real(RP), 
intent(in)  :: psat
 
  691     real(RP), 
intent(in)  :: pres
 
  692     real(RP), 
intent(in)  :: qdry
 
  694     real(RP), 
intent(out) :: qsat
 
  699     qsat = epsvap * qdry * psat / ( pres - psat )
 
  702   end subroutine atmos_saturation_psat2qsat_pres_0d
 
  705   subroutine atmos_saturation_pres2qsat_all_0d( &
 
  710     real(RP), 
intent(in)  :: temp
 
  711     real(RP), 
intent(in)  :: pres
 
  712     real(RP), 
intent(in)  :: qdry
 
  714     real(RP), 
intent(out) :: qsat
 
  719     call atmos_saturation_psat_all_0d( temp, psat ) 
 
  720     call atmos_saturation_psat2qsat_pres_0d( psat, pres, qdry, & 
 
  724   end subroutine atmos_saturation_pres2qsat_all_0d
 
  729   subroutine atmos_saturation_pres2qsat_all_1d( &
 
  734     integer, 
intent(in) :: KA, KS, KE
 
  736     real(RP), 
intent(in)  :: temp(KA)
 
  737     real(RP), 
intent(in)  :: pres(KA)
 
  738     real(RP), 
intent(in)  :: qdry(KA)
 
  740     real(RP), 
intent(out) :: qsat(KA)
 
  746        call atmos_saturation_pres2qsat_all_0d( temp(k), pres(k), qdry(k), & 
 
  751   end subroutine atmos_saturation_pres2qsat_all_1d
 
  755   subroutine atmos_saturation_pres2qsat_all_2d( &
 
  756        IA, IS, IE, JA, JS, JE, &
 
  760     integer, 
intent(in) :: IA, IS, IE
 
  761     integer, 
intent(in) :: JA, JS, JE
 
  763     real(RP), 
intent(in)  :: temp(IA,JA)
 
  764     real(RP), 
intent(in)  :: pres(IA,JA)
 
  765     real(RP), 
intent(in)  :: qdry(IA,JA)
 
  767     real(RP), 
intent(out) :: qsat(IA,JA)
 
  775        call atmos_saturation_pres2qsat_all_0d( temp(i,j), pres(i,j), qdry(i,j), &
 
  781   end subroutine atmos_saturation_pres2qsat_all_2d
 
  785   subroutine atmos_saturation_pres2qsat_all_3d( &
 
  786        KA, KS, KE, IA, IS, IE, JA, JS, JE, &
 
  790     integer, 
intent(in) :: KA, KS, KE
 
  791     integer, 
intent(in) :: IA, IS, IE
 
  792     integer, 
intent(in) :: JA, JS, JE
 
  794     real(RP), 
intent(in)  :: temp(KA,IA,JA)
 
  795     real(RP), 
intent(in)  :: pres(KA,IA,JA)
 
  796     real(RP), 
intent(in)  :: qdry(KA,IA,JA)
 
  798     real(RP), 
intent(out) :: qsat(KA,IA,JA)
 
  807        call atmos_saturation_pres2qsat_all_0d( temp(k,i,j), pres(k,i,j), qdry(k,i,j), & 
 
  814   end subroutine atmos_saturation_pres2qsat_all_3d
 
  818   subroutine atmos_saturation_pres2qsat_liq_0d( &
 
  823     real(RP), 
intent(in)  :: temp
 
  824     real(RP), 
intent(in)  :: pres
 
  825     real(RP), 
intent(in)  :: qdry
 
  827     real(RP), 
intent(out) :: qsat
 
  832     call atmos_saturation_psat_liq( temp, psat ) 
 
  833     call atmos_saturation_psat2qsat_pres( psat, pres, qdry, & 
 
  837   end subroutine atmos_saturation_pres2qsat_liq_0d
 
  842   subroutine atmos_saturation_pres2qsat_liq_1d( &
 
  847     integer, 
intent(in) :: KA, KS, KE
 
  849     real(RP), 
intent(in)  :: temp(KA)
 
  850     real(RP), 
intent(in)  :: pres(KA)
 
  851     real(RP), 
intent(in)  :: qdry(KA)
 
  853     real(RP), 
intent(out) :: qsat(KA)
 
  859        call atmos_saturation_pres2qsat_liq_0d( temp(k), pres(k), qdry(k), & 
 
  864   end subroutine atmos_saturation_pres2qsat_liq_1d
 
  868   subroutine atmos_saturation_pres2qsat_liq_3d( &
 
  869        KA, KS, KE, IA, IS, IE, JA, JS, JE, &
 
  873     integer, 
intent(in) :: KA, KS, KE
 
  874     integer, 
intent(in) :: IA, IS, IE
 
  875     integer, 
intent(in) :: JA, JS, JE
 
  877     real(RP), 
intent(in)  :: temp(KA,IA,JA)
 
  878     real(RP), 
intent(in)  :: pres(KA,IA,JA)
 
  879     real(RP), 
intent(in)  :: qdry(KA,IA,JA)
 
  881     real(RP), 
intent(out) :: qsat(KA,IA,JA)
 
  890        call atmos_saturation_pres2qsat_liq_0d( temp(k,i,j), pres(k,i,j), qdry(k,i,j), & 
 
  897   end subroutine atmos_saturation_pres2qsat_liq_3d
 
  901   subroutine atmos_saturation_pres2qsat_ice_0d( &
 
  906     real(RP), 
intent(in)  :: temp
 
  907     real(RP), 
intent(in)  :: pres
 
  908     real(RP), 
intent(in)  :: qdry
 
  910     real(RP), 
intent(out) :: qsat
 
  915     call atmos_saturation_psat_ice( temp, psat ) 
 
  916     call atmos_saturation_psat2qsat_pres( psat, pres, qdry, & 
 
  920   end subroutine atmos_saturation_pres2qsat_ice_0d
 
  925   subroutine atmos_saturation_pres2qsat_ice_1d( &
 
  930     integer, 
intent(in) :: KA, KS, KE
 
  932     real(RP), 
intent(in)  :: temp(KA)
 
  933     real(RP), 
intent(in)  :: pres(KA)
 
  934     real(RP), 
intent(in)  :: qdry(KA)
 
  936     real(RP), 
intent(out) :: qsat(KA)
 
  942        call atmos_saturation_pres2qsat_ice_0d( temp(k), pres(k), qdry(k), & 
 
  947   end subroutine atmos_saturation_pres2qsat_ice_1d
 
  951   subroutine atmos_saturation_pres2qsat_ice_3d( &
 
  952        KA, KS, KE, IA, IS, IE, JA, JS, JE, &
 
  956     integer, 
intent(in) :: KA, KS, KE
 
  957     integer, 
intent(in) :: IA, IS, IE
 
  958     integer, 
intent(in) :: JA, JS, JE
 
  960     real(RP), 
intent(in)  :: temp(KA,IA,JA)
 
  961     real(RP), 
intent(in)  :: pres(KA,IA,JA)
 
  962     real(RP), 
intent(in)  :: qdry(KA,IA,JA)
 
  964     real(RP), 
intent(out) :: qsat(KA,IA,JA)
 
  973        call atmos_saturation_pres2qsat_ice_0d( temp(k,i,j), pres(k,i,j), qdry(k,i,j), & 
 
  980   end subroutine atmos_saturation_pres2qsat_ice_3d
 
  984   subroutine atmos_saturation_psat2qsat_dens_0d( &
 
  988     real(RP), 
intent(in)  :: psat
 
  989     real(RP), 
intent(in)  :: temp
 
  990     real(RP), 
intent(in)  :: dens
 
  992     real(RP), 
intent(out) :: qsat
 
  994     qsat = psat / ( dens * rvap * temp )
 
  997   end subroutine atmos_saturation_psat2qsat_dens_0d
 
 1001   subroutine atmos_saturation_dens2qsat_all_0d( &
 
 1006     real(RP), 
intent(in)  :: temp
 
 1007     real(RP), 
intent(in)  :: dens
 
 1009     real(RP), 
intent(out) :: qsat
 
 1014     call atmos_saturation_psat_all( temp, psat ) 
 
 1015     call atmos_saturation_psat2qsat_dens_0d( psat, temp, dens, & 
 
 1019   end subroutine atmos_saturation_dens2qsat_all_0d
 
 1024   subroutine atmos_saturation_dens2qsat_all_1d( &
 
 1029     integer,  
intent(in)  :: KA, KS, KE
 
 1031     real(RP), 
intent(in)  :: temp(KA)
 
 1032     real(RP), 
intent(in)  :: dens(KA)
 
 1034     real(RP), 
intent(out) :: qsat(KA)
 
 1040        call atmos_saturation_dens2qsat_all_0d( temp(k), dens(k), & 
 
 1045   end subroutine atmos_saturation_dens2qsat_all_1d
 
 1049   subroutine atmos_saturation_dens2qsat_all_3d( &
 
 1057     integer,  
intent(in)  :: KA, KS, KE
 
 1058     integer,  
intent(in)  :: IA, IS, IE
 
 1059     integer,  
intent(in)  :: JA, JS, JE
 
 1061     real(RP), 
intent(in)  :: temp(KA,IA,JA)
 
 1062     real(RP), 
intent(in)  :: dens(KA,IA,JA)
 
 1064     real(RP), 
intent(out) :: qsat(KA,IA,JA)
 
 1073        call atmos_saturation_dens2qsat_all_0d( temp(k,i,j), dens(k,i,j), & 
 
 1080   end subroutine atmos_saturation_dens2qsat_all_3d
 
 1084   subroutine atmos_saturation_dens2qsat_liq_0d( &
 
 1089     real(RP), 
intent(in)  :: temp
 
 1090     real(RP), 
intent(in)  :: dens
 
 1092     real(RP), 
intent(out) :: qsat
 
 1097     call atmos_saturation_psat_liq_0d( temp, psat ) 
 
 1098     call atmos_saturation_psat2qsat_dens_0d( psat, temp, dens, & 
 
 1102   end subroutine atmos_saturation_dens2qsat_liq_0d
 
 1107   subroutine atmos_saturation_dens2qsat_liq_1d( &
 
 1112     integer, 
intent(in) :: KA, KS, KE
 
 1114     real(RP), 
intent(in)  :: temp(KA)
 
 1115     real(RP), 
intent(in)  :: dens(KA)
 
 1117     real(RP), 
intent(out) :: qsat(KA)
 
 1123        call atmos_saturation_dens2qsat_liq_0d( temp(k), dens(k), & 
 
 1128   end subroutine atmos_saturation_dens2qsat_liq_1d
 
 1132   subroutine atmos_saturation_dens2qsat_liq_3d( &
 
 1133        KA, KS, KE, IA, IS, IE, JA, JS, JE, &
 
 1137     integer, 
intent(in) :: KA, KS, KE
 
 1138     integer, 
intent(in) :: IA, IS, IE
 
 1139     integer, 
intent(in) :: JA, JS, JE
 
 1141     real(RP), 
intent(in)  :: temp(KA,IA,JA)
 
 1142     real(RP), 
intent(in)  :: dens(KA,IA,JA)
 
 1144     real(RP), 
intent(out) :: qsat(KA,IA,JA)
 
 1153        call atmos_saturation_dens2qsat_liq_0d( temp(k,i,j), dens(k,i,j), & 
 
 1160   end subroutine atmos_saturation_dens2qsat_liq_3d
 
 1164   subroutine atmos_saturation_dens2qsat_ice_0d( &
 
 1169     real(RP), 
intent(in)  :: temp
 
 1170     real(RP), 
intent(in)  :: dens
 
 1172     real(RP), 
intent(out) :: qsat
 
 1177     call atmos_saturation_psat_ice( temp, psat ) 
 
 1178     call atmos_saturation_psat2qsat_dens( psat, temp, dens, & 
 
 1181   end subroutine atmos_saturation_dens2qsat_ice_0d
 
 1186   subroutine atmos_saturation_dens2qsat_ice_1d( &
 
 1191     integer, 
intent(in) :: KA, KS, KE
 
 1193     real(RP), 
intent(in)  :: temp(KA)
 
 1194     real(RP), 
intent(in)  :: dens(KA)
 
 1196     real(RP), 
intent(out) :: qsat(KA)
 
 1202        call atmos_saturation_dens2qsat_ice_0d( temp(k), dens(k), & 
 
 1207   end subroutine atmos_saturation_dens2qsat_ice_1d
 
 1211   subroutine atmos_saturation_dens2qsat_ice_3d( &
 
 1212        KA, KS, KE, IA, IS, IE, JA, JS, JE, &
 
 1216     integer, 
intent(in) :: KA, KS, KE
 
 1217     integer, 
intent(in) :: IA, IS, IE
 
 1218     integer, 
intent(in) :: JA, JS, JE
 
 1220     real(RP), 
intent(in)  :: temp(KA,IA,JA)
 
 1221     real(RP), 
intent(in)  :: dens(KA,IA,JA)
 
 1223     real(RP), 
intent(out) :: qsat(KA,IA,JA)
 
 1232        call atmos_saturation_dens2qsat_ice_0d( temp(k,i,j), dens(k,i,j), & 
 
 1239   end subroutine atmos_saturation_dens2qsat_ice_3d
 
 1243   subroutine atmos_saturation_dalphadt_0d( &
 
 1247     real(RP), 
intent(in)  :: temp
 
 1249     real(RP), 
intent(out) :: dalpha_dT
 
 1251     real(RP) :: lim1, lim2
 
 1255     lim1 = 0.5_rp + sign( 0.5_rp, atmos_saturation_ulimit_temp - temp )
 
 1257     lim2 = 0.5_rp + sign( 0.5_rp, temp - atmos_saturation_llimit_temp )
 
 1259     dalpha_dt = dalphadt_const * lim1 * lim2
 
 1262   end subroutine atmos_saturation_dalphadt_0d
 
 1267   subroutine atmos_saturation_dalphadt_1d( &
 
 1272     integer, 
intent(in) :: KA, KS, KE
 
 1274     real(RP), 
intent(in)  :: temp     (KA)
 
 1276     real(RP), 
intent(out) :: dalpha_dT(KA)
 
 1282        call atmos_saturation_dalphadt_0d( temp(k), dalpha_dt(k) ) 
 
 1286   end subroutine atmos_saturation_dalphadt_1d
 
 1290   subroutine atmos_saturation_dalphadt_3d( &
 
 1291        KA, KS, KE, IA, IS, IE, JA, JS, JE, &
 
 1295     integer, 
intent(in) :: KA, KS, KE
 
 1296     integer, 
intent(in) :: IA, IS, IE
 
 1297     integer, 
intent(in) :: JA, JS, JE
 
 1299     real(RP), 
intent(in)  :: temp     (KA,IA,JA)
 
 1301     real(RP), 
intent(out) :: dalpha_dT(KA,IA,JA)
 
 1310        call atmos_saturation_dalphadt_0d( temp(k,i,j), dalpha_dt(k,i,j) ) 
 
 1316   end subroutine atmos_saturation_dalphadt_3d
 
 1320   subroutine atmos_saturation_dqs_dtem_dens_liq_0d( &
 
 1324        hydrometeor_lhv => atmos_hydrometeor_lhv
 
 1327     real(RP), 
intent(in)  :: temp
 
 1328     real(RP), 
intent(in)  :: dens
 
 1330     real(RP), 
intent(out) :: dqsdtem
 
 1331     real(RP), 
intent(out), 
optional :: qsat
 
 1337     call hydrometeor_lhv( temp, lhv )
 
 1338     call atmos_saturation_psat_liq( temp, psat ) 
 
 1340     dqsdtem = psat / ( dens* rvap * temp**2 ) &
 
 1341             * ( lhv / ( rvap * temp ) - 1.0_rp )
 
 1343     if ( 
present(qsat) ) &
 
 1344          call atmos_saturation_psat2qsat_dens( psat, temp, dens, & 
 
 1348   end subroutine atmos_saturation_dqs_dtem_dens_liq_0d
 
 1357     integer, 
intent(in) :: KA, KS, KE
 
 1359     real(RP), 
intent(in)  :: temp   (KA)
 
 1360     real(RP), 
intent(in)  :: dens   (KA)
 
 1362     real(RP), 
intent(out) :: dqsdtem(KA)
 
 1368        call atmos_saturation_dqs_dtem_dens_liq_0d( temp(k), dens(k), & 
 
 1377   subroutine atmos_saturation_dqs_dtem_dens_liq_3d( &
 
 1378        KA, KS, KE, IA, IS, IE, JA, JS, JE, &
 
 1382     integer, 
intent(in) :: KA, KS, KE
 
 1383     integer, 
intent(in) :: IA, IS, IE
 
 1384     integer, 
intent(in) :: JA, JS, JE
 
 1386     real(RP), 
intent(in)  :: temp   (KA,IA,JA)
 
 1387     real(RP), 
intent(in)  :: dens   (KA,IA,JA)
 
 1389     real(RP), 
intent(out) :: dqsdtem(KA,IA,JA)
 
 1398        call atmos_saturation_dqs_dtem_dens_liq_0d( temp(k,i,j), dens(k,i,j), & 
 
 1405   end subroutine atmos_saturation_dqs_dtem_dens_liq_3d
 
 1409   subroutine atmos_saturation_dqs_dtem_dens_ice_0d( &
 
 1413        hydrometeor_lhs => atmos_hydrometeor_lhs
 
 1416     real(RP), 
intent(in)  :: temp
 
 1417     real(RP), 
intent(in)  :: dens
 
 1419     real(RP), 
intent(out) :: dqsdtem
 
 1420     real(RP), 
intent(out), 
optional :: qsat
 
 1427     call hydrometeor_lhs( temp, lhs ) 
 
 1428     call atmos_saturation_psat_ice( temp, psat ) 
 
 1430     dqsdtem = psat / ( dens * rvap * temp**2 ) &
 
 1431             * ( lhs / ( rvap * temp ) - 1.0_rp )
 
 1433     if ( 
present(qsat) ) &
 
 1434          call atmos_saturation_psat2qsat_dens( psat, temp, dens, & 
 
 1438   end subroutine atmos_saturation_dqs_dtem_dens_ice_0d
 
 1447     integer, 
intent(in) :: KA, KS, KE
 
 1449     real(RP), 
intent(in)  :: temp   (KA)
 
 1450     real(RP), 
intent(in)  :: dens   (KA)
 
 1452     real(RP), 
intent(out) :: dqsdtem(KA)
 
 1458        call atmos_saturation_dqs_dtem_dens_ice_0d( temp(k), dens(k), & 
 
 1467   subroutine atmos_saturation_dqs_dtem_dens_ice_3d( &
 
 1468        KA, KS, KE, IA, IS, IE, JA, JS, JE, &
 
 1472     integer, 
intent(in) :: KA, KS, KE
 
 1473     integer, 
intent(in) :: IA, IS, IE
 
 1474     integer, 
intent(in) :: JA, JS, JE
 
 1476     real(RP), 
intent(in)  :: temp   (KA,IA,JA)
 
 1477     real(RP), 
intent(in)  :: dens   (KA,IA,JA)
 
 1479     real(RP), 
intent(out) :: dqsdtem(KA,IA,JA)
 
 1488        call atmos_saturation_dqs_dtem_dens_ice_0d( temp(k,i,j), dens(k,i,j), & 
 
 1495   end subroutine atmos_saturation_dqs_dtem_dens_ice_3d
 
 1499   subroutine atmos_saturation_dqs_dtem_dens_all_0d( &
 
 1502        qsat, qsat_liq, qsat_ice, &
 
 1506     real(RP), 
intent(in)  :: temp
 
 1507     real(RP), 
intent(in)  :: dens
 
 1509     real(RP), 
intent(out) :: dqsat_dT
 
 1511     real(RP), 
intent(out), 
optional :: qsat
 
 1512     real(RP), 
intent(out), 
optional :: qsat_liq
 
 1513     real(RP), 
intent(out), 
optional :: qsat_ice
 
 1514     real(RP), 
intent(out), 
optional :: alpha
 
 1516     real(RP) :: qsat_liq_, qsat_ice_, alpha_
 
 1517     real(RP) :: dqsat_dT_liq, dqsat_dT_ice, dalpha_dT
 
 1521     call atmos_saturation_dqs_dtem_dens_liq_0d( temp, dens,             & 
 
 1522                                                 dqsat_dt_liq, qsat_liq_ ) 
 
 1523     call atmos_saturation_dqs_dtem_dens_ice_0d( temp, dens,             & 
 
 1524                                                 dqsat_dt_ice, qsat_ice_ ) 
 
 1525     call atmos_saturation_alpha   ( temp, alpha_    ) 
 
 1526     call atmos_saturation_dalphadt( temp, dalpha_dt ) 
 
 1528     dqsat_dt  = qsat_liq_ * dalpha_dt + dqsat_dt_liq * (        alpha_ ) &
 
 1529               - qsat_ice_ * dalpha_dt + dqsat_dt_ice * ( 1.0_rp-alpha_ )
 
 1531     if ( 
present(qsat)     ) qsat = qsat_liq_ * alpha_ + qsat_ice_ * ( 1.0_rp-alpha_ )
 
 1532     if ( 
present(qsat_liq) ) qsat_liq = qsat_liq_
 
 1533     if ( 
present(qsat_ice) ) qsat_ice = qsat_ice_
 
 1534     if ( 
present(alpha   ) ) alpha    = alpha_
 
 1537   end subroutine atmos_saturation_dqs_dtem_dens_all_0d
 
 1541   subroutine atmos_saturation_dqs_dtem_dpre_liq_0d( &
 
 1543        dqsat_dT, dqsat_dP, &
 
 1546        hydrometeor_lhv => atmos_hydrometeor_lhv
 
 1549     real(RP), 
intent(in)  :: temp
 
 1550     real(RP), 
intent(in)  :: pres
 
 1551     real(RP), 
intent(in)  :: qdry
 
 1553     real(RP), 
intent(out) :: dqsat_dT
 
 1554     real(RP), 
intent(out) :: dqsat_dP
 
 1556     real(RP), 
intent(out), 
optional :: qsat
 
 1557     real(RP), 
intent(out), 
optional :: psat
 
 1561     real(RP) :: den1, den2 
 
 1565     call hydrometeor_lhv( temp, lhv )
 
 1566     call atmos_saturation_psat_liq( temp, psat_ ) 
 
 1568     den1 = ( pres - (1.0_rp-epsvap) * psat_ )**2
 
 1569     den2 = den1 * rvap * temp**2
 
 1571     dqsat_dp = - epsvap * psat_ / den1
 
 1572     dqsat_dt =   epsvap * psat_ / den2 * lhv * pres
 
 1574     if ( 
present(qsat) ) &
 
 1575          call atmos_saturation_psat2qsat_pres( psat_, pres, qdry, & 
 
 1577     if ( 
present(psat) ) psat = psat_
 
 1580   end subroutine atmos_saturation_dqs_dtem_dpre_liq_0d
 
 1587        dqsat_dT, dqsat_dP )
 
 1589     integer, 
intent(in) :: KA, KS, KE
 
 1591     real(RP), 
intent(in)  :: temp   (KA)
 
 1592     real(RP), 
intent(in)  :: pres   (KA)
 
 1593     real(RP), 
intent(in)  :: qdry   (KA)
 
 1595     real(RP), 
intent(out) :: dqsat_dT(KA)
 
 1596     real(RP), 
intent(out) :: dqsat_dP(KA)
 
 1602        call atmos_saturation_dqs_dtem_dpre_liq_0d( temp(k), pres(k), qdry(k), & 
 
 1603                                                    dqsat_dt(k), dqsat_dp(k)   ) 
 
 1611   subroutine atmos_saturation_dqs_dtem_dpre_liq_3d( &
 
 1612        KA, KS, KE, IA, IS, IE, JA, JS, JE, &
 
 1614        dqsat_dT, dqsat_dP )
 
 1616     integer, 
intent(in) :: KA, KS, KE
 
 1617     integer, 
intent(in) :: IA, IS, IE
 
 1618     integer, 
intent(in) :: JA, JS, JE
 
 1620     real(RP), 
intent(in)  :: temp   (KA,IA,JA)
 
 1621     real(RP), 
intent(in)  :: pres   (KA,IA,JA)
 
 1622     real(RP), 
intent(in)  :: qdry   (KA,IA,JA)
 
 1624     real(RP), 
intent(out) :: dqsat_dT(KA,IA,JA)
 
 1625     real(RP), 
intent(out) :: dqsat_dP(KA,IA,JA)
 
 1634        call atmos_saturation_dqs_dtem_dpre_liq_0d( temp(k,i,j), pres(k,i,j), qdry(k,i,j), & 
 
 1635                                                    dqsat_dt(k,i,j), dqsat_dp(k,i,j)       ) 
 
 1641   end subroutine atmos_saturation_dqs_dtem_dpre_liq_3d
 
 1646   subroutine atmos_saturation_dqs_dtem_dpre_ice_0d( &
 
 1648        dqsat_dT, dqsat_dP, &
 
 1651        hydrometeor_lhs => atmos_hydrometeor_lhs
 
 1654     real(RP), 
intent(in)  :: temp
 
 1655     real(RP), 
intent(in)  :: pres
 
 1656     real(RP), 
intent(in)  :: qdry
 
 1658     real(RP), 
intent(out) :: dqsat_dT
 
 1659     real(RP), 
intent(out) :: dqsat_dP
 
 1661     real(RP), 
intent(out), 
optional :: qsat
 
 1665     real(RP) :: den1, den2 
 
 1669     call hydrometeor_lhs( temp, lhs ) 
 
 1670     call atmos_saturation_psat_ice( temp, psat ) 
 
 1672     den1 = ( pres - (1.0_rp-epsvap) * psat )**2
 
 1673     den2 = den1 * rvap * temp**2
 
 1675     dqsat_dp = - epsvap * psat / den1
 
 1676     dqsat_dt =   epsvap * psat / den2 * lhs * pres
 
 1678     if ( 
present(qsat) ) &
 
 1679          call atmos_saturation_psat2qsat_pres( psat, pres, qdry, & 
 
 1682   end subroutine atmos_saturation_dqs_dtem_dpre_ice_0d
 
 1689        dqsat_dT, dqsat_dP )
 
 1691     integer, 
intent(in) :: KA, KS, KE
 
 1693     real(RP), 
intent(in)  :: temp   (KA)
 
 1694     real(RP), 
intent(in)  :: pres   (KA)
 
 1695     real(RP), 
intent(in)  :: qdry   (KA)
 
 1697     real(RP), 
intent(out) :: dqsat_dT(KA)
 
 1698     real(RP), 
intent(out) :: dqsat_dP(KA)
 
 1704        call atmos_saturation_dqs_dtem_dpre_ice( temp(k), pres(k), qdry(k), & 
 
 1705                                                 dqsat_dt(k), dqsat_dp(k)   ) 
 
 1714   subroutine atmos_saturation_dqs_dtem_dpre_ice_3d( &
 
 1715        KA, KS, KE, IA, IS, IE, JA, JS, JE, &
 
 1717        dqsat_dT, dqsat_dP )
 
 1719     integer, 
intent(in) :: KA, KS, KE
 
 1720     integer, 
intent(in) :: IA, IS, IE
 
 1721     integer, 
intent(in) :: JA, JS, JE
 
 1723     real(RP), 
intent(in)  :: temp   (KA,IA,JA)
 
 1724     real(RP), 
intent(in)  :: pres   (KA,IA,JA)
 
 1725     real(RP), 
intent(in)  :: qdry   (KA,IA,JA)
 
 1727     real(RP), 
intent(out) :: dqsat_dT(KA,IA,JA)
 
 1728     real(RP), 
intent(out) :: dqsat_dP(KA,IA,JA)
 
 1737        call atmos_saturation_dqs_dtem_dpre_ice( temp(k,i,j), pres(k,i,j), qdry(k,i,j), & 
 
 1738                                                 dqsat_dt(k,i,j), dqsat_dp(k,i,j)       ) 
 
 1744   end subroutine atmos_saturation_dqs_dtem_dpre_ice_3d
 
 1749   subroutine atmos_saturation_dqs_dtem_dpre_all_0d( &
 
 1751        dqsat_dT, dqsat_dP,       &
 
 1752        qsat, qsat_liq, qsat_ice, &
 
 1756     real(RP), 
intent(in)  :: temp
 
 1757     real(RP), 
intent(in)  :: pres
 
 1758     real(RP), 
intent(in)  :: qdry
 
 1760     real(RP), 
intent(out) :: dqsat_dT
 
 1761     real(RP), 
intent(out) :: dqsat_dP
 
 1763     real(RP), 
intent(out), 
optional :: qsat
 
 1764     real(RP), 
intent(out), 
optional :: qsat_liq
 
 1765     real(RP), 
intent(out), 
optional :: qsat_ice
 
 1766     real(RP), 
intent(out), 
optional :: alpha
 
 1768     real(RP) :: qsat_liq_, qsat_ice_, alpha_
 
 1769     real(RP) :: dqsat_dT_liq, dqsat_dT_ice
 
 1770     real(RP) :: dqsat_dP_liq, dqsat_dP_ice
 
 1771     real(RP) :: dalpha_dT
 
 1775     call atmos_saturation_dqs_dtem_dpre_liq_0d( temp, pres, qdry,           & 
 
 1776                                                 dqsat_dt_liq, dqsat_dp_liq, & 
 
 1778     call atmos_saturation_dqs_dtem_dpre_ice_0d( temp, pres, qdry,           & 
 
 1779                                                 dqsat_dt_ice, dqsat_dp_ice, & 
 
 1781     call atmos_saturation_alpha   ( temp, alpha_    ) 
 
 1782     call atmos_saturation_dalphadt( temp, dalpha_dt ) 
 
 1784     dqsat_dt  = qsat_liq_ * dalpha_dt + dqsat_dt_liq * (        alpha_ ) &
 
 1785               - qsat_ice_ * dalpha_dt + dqsat_dt_ice * ( 1.0_rp-alpha_ )
 
 1786     dqsat_dp  = dqsat_dp_liq * (        alpha_ ) &
 
 1787               + dqsat_dp_ice * ( 1.0_rp-alpha_ )
 
 1789     if ( 
present(qsat)     ) qsat = qsat_liq * alpha_ + qsat_ice * ( 1.0_rp-alpha_ )
 
 1790     if ( 
present(qsat_liq) ) qsat_liq = qsat_liq_
 
 1791     if ( 
present(qsat_ice) ) qsat_ice = qsat_ice_
 
 1792     if ( 
present(alpha   ) ) alpha    = alpha_
 
 1795   end subroutine atmos_saturation_dqs_dtem_dpre_all_0d
 
 1800   subroutine atmos_saturation_tdew_liq_0d( &
 
 1807        atmos_hydrometeor_lhv
 
 1808     real(RP), 
intent(in) :: DENS
 
 1809     real(RP), 
intent(in) :: TEMP
 
 1810     real(RP), 
intent(in) :: QV
 
 1812     real(RP), 
intent(out) :: Tdew
 
 1813     logical,  
intent(out) :: converged
 
 1815     real(RP), 
parameter :: A = 17.625_rp
 
 1816     real(RP), 
parameter :: B = 243.04_rp
 
 1817     real(RP), 
parameter :: C = 610.94_rp
 
 1818     integer,  
parameter :: itelim = 100
 
 1819     real(RP), 
parameter :: criteria = 0.1_rp**(2+rp/2)
 
 1822     real(RP) :: pvap, psat
 
 1823     real(RP) :: dpsat_dT
 
 1829     pvap = dens * qv * rvap * temp
 
 1831     if ( pvap < psat_min_liq ) 
then 
 1839     tdew = b * log( pvap / c ) / ( a - log( pvap / c ) ) + tem00
 
 1843        call atmos_saturation_psat_liq( tdew, psat ) 
 
 1844        call atmos_hydrometeor_lhv( tdew, lhv )
 
 1846        dpsat_dt = psat * lhv / ( rvap * tdew**2 )
 
 1847        dtdew = ( psat - pvap ) / dpsat_dt
 
 1848        if ( dtdew < criteria ) 
then 
 1855     if( .not. converged ) 
then 
 1856        log_warn(
"ATMOS_SATURATION_tdew_liq_0D",*) dens, temp, qv, pvap, tdew, dtdew, dpsat_dt
 
 1860   end subroutine atmos_saturation_tdew_liq_0d
 
 1868     integer, 
intent(in) :: KA, KS, KE
 
 1870     real(RP), 
intent(in) :: DENS(KA)
 
 1871     real(RP), 
intent(in) :: TEMP(KA)
 
 1872     real(RP), 
intent(in) :: QV  (KA)
 
 1874     real(RP), 
intent(out) :: Tdew(KA)
 
 1875     logical,  
intent(out) :: converged
 
 1881        call atmos_saturation_tdew_liq_0d( dens(k), temp(k), qv(k), & 
 
 1882                                           tdew(k), converged       ) 
 
 1883        if ( .not. converged ) 
exit 
 1888   subroutine atmos_saturation_tdew_liq_3d( &
 
 1889        KA, KS, KE, IA, IS, IE, JA, JS, JE, &
 
 1894     integer, 
intent(in) :: KA, KS, KE
 
 1895     integer, 
intent(in) :: IA, IS, IE
 
 1896     integer, 
intent(in) :: JA, JS, JE
 
 1898     real(RP), 
intent(in) :: DENS(KA,IA,JA)
 
 1899     real(RP), 
intent(in) :: TEMP(KA,IA,JA)
 
 1900     real(RP), 
intent(in) :: QV  (KA,IA,JA)
 
 1902     real(RP), 
intent(out) :: Tdew(KA,IA,JA)
 
 1904     logical :: converged, error
 
 1914        call atmos_saturation_tdew_liq_0d( dens(k,i,j), temp(k,i,j), qv(k,i,j), & 
 
 1915                                           tdew(k,i,j), converged               ) 
 
 1916        if ( .not. converged ) 
then 
 1917           log_error(
"ATMOS_SATURATION_tdew_liq_3D",*) 
'not converged! ', k,i,j
 
 1927   end subroutine atmos_saturation_tdew_liq_3d
 
 1938        DENS, POTT, TEMP, QV, &
 
 1944        atmos_hydrometeor_lhv
 
 1945     real(RP), 
intent(in) :: DENS
 
 1946     real(RP), 
intent(in) :: POTT
 
 1947     real(RP), 
intent(in) :: TEMP
 
 1948     real(RP), 
intent(in) :: QV
 
 1950     real(RP), 
intent(out) :: POTE
 
 1956     pv = dens * qv * rvap * temp
 
 1957     tl = 55.0_rp + 2840.0_rp / ( cpdry / rdry * log(temp) - log(pv) - 4.805_rp )
 
 1958     call atmos_hydrometeor_lhv( temp, lhv ) 
 
 1960     pote = pott * exp( lhv * qv / ( cpdry * temp ) &
 
 1961                      * 1.0784_rp * ( 1.0_rp + 0.810_rp * qv ) )
 
 1969        DENS, POTT, TEMP, QV, &
 
 1971     integer, 
intent(in) :: KA, KS, KE
 
 1973     real(RP), 
intent(in) :: DENS(KA)
 
 1974     real(RP), 
intent(in) :: POTT(KA)
 
 1975     real(RP), 
intent(in) :: TEMP(KA)
 
 1976     real(RP), 
intent(in) :: QV  (KA)
 
 1978     real(RP), 
intent(out) :: POTE(KA)
 
 1990   subroutine atmos_saturation_pote_3d( &
 
 1991        KA, KS, KE, IA, IS, IE, JA, JS, JE, &
 
 1992        DENS, POTT, TEMP, QV, &
 
 1994     integer, 
intent(in) :: KA, KS, KE
 
 1995     integer, 
intent(in) :: IA, IS, IE
 
 1996     integer, 
intent(in) :: JA, JS, JE
 
 1998     real(RP), 
intent(in) :: DENS(KA,IA,JA)
 
 1999     real(RP), 
intent(in) :: POTT(KA,IA,JA)
 
 2000     real(RP), 
intent(in) :: TEMP(KA,IA,JA)
 
 2001     real(RP), 
intent(in) :: QV  (KA,IA,JA)
 
 2003     real(RP), 
intent(out) :: POTE(KA,IA,JA)
 
 2012             dens(k,i,j), pott(k,i,j), temp(k,i,j), qv(k,i,j), & 
 
 2019   end subroutine atmos_saturation_pote_3d
 
 2025   subroutine atmos_saturation_moist_conversion_dens_liq_0d( &
 
 2027        TEMP, QV, QC, CPtot, CVtot, &
 
 2039     real(RP), 
intent(in)    :: DENS
 
 2040     real(RP), 
intent(in)    :: Emoist0
 
 2042     real(RP), 
intent(inout) :: TEMP
 
 2043     real(RP), 
intent(inout) :: QV
 
 2044     real(RP), 
intent(inout) :: QC
 
 2045     real(RP), 
intent(inout) :: CPtot
 
 2046     real(RP), 
intent(inout) :: CVtot
 
 2048     logical,  
intent(out)   :: converged
 
 2057     real(RP) :: dqsatl_dT
 
 2059     real(RP) :: dCVtot_dT
 
 2060     real(RP) :: dEmoist_dT
 
 2063     integer,  
parameter :: itelim = 100
 
 2064     real(RP), 
parameter :: dtemp_criteria = 0.1_rp**(2+rp/2)
 
 2070     call atmos_saturation_dens2qsat_liq( temp, dens, & 
 
 2073     if ( qsum <= qsat ) 
then 
 2078        temp = ( emoist0 - 
lhv * qv ) / cvtot
 
 2089        call atmos_saturation_dqs_dtem_dens_liq_0d( temp, dens,     & 
 
 2092        dqc_dt = - dqsatl_dt
 
 2097        demoist_dt = temp * dcvtot_dt + cvtot + dqsatl_dt * 
lhv 
 2102        emoist = temp * cvtot + qsat * 
lhv 
 2106        dtemp = ( emoist - emoist0 ) / demoist_dt
 
 2109        if ( abs(dtemp) < dtemp_criteria ) 
then 
 2114        if( temp*0.0_rp /= 0.0_rp ) 
exit 
 2122   end subroutine atmos_saturation_moist_conversion_dens_liq_0d
 
 2130        TEMP, QV, QC, QI, CPtot, CVtot, &
 
 2145     real(RP), 
intent(in)    :: DENS
 
 2146     real(RP), 
intent(in)    :: Emoist0
 
 2148     real(RP), 
intent(inout) :: TEMP
 
 2149     real(RP), 
intent(inout) :: QV
 
 2150     real(RP), 
intent(inout) :: QC
 
 2151     real(RP), 
intent(inout) :: QI
 
 2152     real(RP), 
intent(inout) :: CPtot
 
 2153     real(RP), 
intent(inout) :: CVtot
 
 2155     logical,  
intent(out)   :: converged
 
 2160     real(RP) :: QV0, QC0, QI0
 
 2167     real(RP) :: dalpha_dT
 
 2168     real(RP) :: dqsat_dT
 
 2169     real(RP) :: dqc_dT, dqi_dT
 
 2170     real(RP) :: dCVtot_dT
 
 2171     real(RP) :: dEmoist_dT
 
 2174     integer,  
parameter :: itelim = 100
 
 2175     real(RP), 
parameter :: dtemp_criteria = 0.1_rp**(2+rp/2)
 
 2186     call atmos_saturation_dens2qsat_all( temp, dens, & 
 
 2189     if ( qsum <= qsat ) 
then 
 2195        temp = ( emoist0 - 
lhv * qv ) / cvtot
 
 2204        call atmos_saturation_dqs_dtem_dens_all_0d( temp, dens,            & 
 
 2206                                                    qsat=qsat, alpha=alpha ) 
 
 2207        call atmos_saturation_dalphadt( temp, dalpha_dt ) 
 
 2209        dqc_dt =  ( qsum - qv ) * dalpha_dt - dqsat_dt * (        alpha )
 
 2210        dqi_dt = -( qsum - qv ) * dalpha_dt - dqsat_dt * ( 1.0_rp-alpha )
 
 2216        demoist_dt = temp * dcvtot_dt + cvtot + dqsat_dt * 
lhv - dqi_dt * 
lhf 
 2220        qc = ( qsum - qsat ) * (          alpha )
 
 2221        qi = ( qsum - qsat ) * ( 1.0_rp - alpha )
 
 2228        emoist = temp * cvtot + qv * 
lhv - qi * 
lhf 
 2231        dtemp = ( emoist - emoist0 ) / demoist_dt
 
 2234        if ( abs(dtemp) < dtemp_criteria ) 
then 
 2239        if( temp*0.0_rp /= 0.0_rp ) 
exit 
 2263        atmos_hydrometeor_entr, &
 
 2264        atmos_hydrometeor_entr2temp, &
 
 2268     real(RP), 
intent(in)    :: PRES
 
 2269     real(RP), 
intent(in)    :: ENTR
 
 2270     real(RP), 
intent(in)    :: Qdry
 
 2272     real(RP), 
intent(inout) :: QV
 
 2273     real(RP), 
intent(inout) :: QC
 
 2274     real(RP), 
intent(inout) :: CPtot
 
 2275     real(RP), 
intent(inout) :: Rtot
 
 2277     real(RP), 
intent(out)   :: TEMP
 
 2278     logical,  
intent(out)   :: converged
 
 2280     real(RP), 
parameter :: TEMMIN = 0.1_rp
 
 2281     real(RP), 
parameter :: criteria = 1.e-8_rp
 
 2282     integer,  
parameter :: itelim   = 100
 
 2286     real(RP) :: qsat, psat
 
 2288     real(RP) :: TEMP_ite
 
 2290     real(RP) :: ENTR_ite
 
 2291     real(RP) :: Rtot_ite
 
 2292     real(RP) :: CPtot_ite
 
 2294     real(RP) :: dqsat_dT, dqsat_dP
 
 2296     real(RP) :: TEMP_prev
 
 2297     real(RP) :: dENTR_dT
 
 2303     rtot  = rtot  + qc * rvap
 
 2308     call atmos_hydrometeor_entr2temp( entr, pres, qsum, 0.0_rp, qdry, & 
 
 2312     call atmos_saturation_pres2qsat_liq( temp, pres, qdry, & 
 
 2314     if ( qsum <= qsat ) 
then 
 2328           call atmos_saturation_dqs_dtem_dpre_liq_0d( temp_ite, pres, qdry, & 
 
 2329                                                       dqsat_dt, dqsat_dp,   & 
 
 2330                                                       qsat=qsat, psat=psat  ) 
 
 2332           qv_ite = min( qsum, qsat )
 
 2334           rtot_ite  = rtot  - ( qsum - qv_ite ) * rvap
 
 2337           dentr_dt = cptot_ite / temp_ite &
 
 2339                      - rvap * log( psat/ psat0 ) &
 
 2343           call atmos_hydrometeor_entr( temp_ite, pres,       & 
 
 2344                                        qv_ite, 0.0_rp, qdry, & 
 
 2345                                        rtot_ite, cptot_ite,  & 
 
 2348           temp_prev = temp_ite
 
 2349           temp_ite  = temp_ite - ( entr_ite - entr ) / max( dentr_dt, eps )
 
 2350           temp_ite  = max( temp_ite, temmin )
 
 2352           if( abs(temp_ite-temp_prev) < criteria ) 
then