phys_humidity.F90 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. !
  2. ! Humidity functions.
  3. !
  4. ! Copied from TMPP module 'msub_subg' (tmpp_sub_subg.f90)
  5. !
  6. ! Note by Bas Henzing:
  7. ! Do not change the constants Rgas etc !
  8. ! Thus, do not use them from Binas for example.
  9. ! Reason: the constants c1 etc in the parameterisation are fits
  10. ! given the coded values of Rgas etc .
  11. !
  12. module phys_humidity
  13. implicit none
  14. ! --- in/out ------------------------------------
  15. private
  16. public :: QSat
  17. public :: dQSat_dT
  18. public :: QH2O
  19. contains
  20. !
  21. ! calculate saturation specific humidity
  22. !
  23. real function QSat( T, p )
  24. ! --- in/out ----------------------------
  25. real, intent(in) :: T ! temperature (K)
  26. real, intent(in) :: p ! pressure (Pa)
  27. ! --- const ----------------------------
  28. real, parameter :: rgasd = 287.05
  29. real, parameter :: rgasv = 461.51
  30. real, parameter :: eps = rgasd/rgasv
  31. real, parameter :: T0 = 273.16
  32. real, parameter :: c1 = 610.78
  33. real, parameter :: c3a = 17.269
  34. real, parameter :: c3b = 21.875
  35. real, parameter :: c4a = 35.86
  36. real, parameter :: c4b = 7.66
  37. ! --- local -------------------------------
  38. real :: es
  39. ! --- begin -----------------------------
  40. if ( p <= 0.0 ) then
  41. QSat = 0.0
  42. return
  43. end if
  44. ! set function 'qsat' equal 0 for temperatures t < 9K
  45. ! to ensure numerical stability
  46. ! (the argument of the following exponential
  47. ! function would otherwise exceeds maximum)
  48. if ( T < 9.0 ) then
  49. QSat = 0.
  50. return
  51. end if
  52. if ( T >= t0 ) then
  53. es = c1*exp(c3a*(T-T0)/(T-c4a))
  54. else
  55. es = c1*exp(c3b*(T-T0)/(T-c4b))
  56. end if
  57. QSat = eps / ( (p/es) - (1.0-eps) )
  58. end function QSat
  59. !
  60. ! calculate derivative of saturation specific humidity with
  61. ! respect to temperature
  62. !
  63. real function dQSat_dT( T, p )
  64. ! --- in/out -------------------------------
  65. real, intent(in) :: T ! temperature (K)
  66. real, intent(in) :: p ! pressure (Pa)
  67. ! --- const --------------------------------
  68. real, parameter :: rgasd = 287.05
  69. real, parameter :: rgasv = 461.51
  70. real, parameter :: eps = rgasd/rgasv
  71. real, parameter :: T0 = 273.16
  72. real, parameter :: c1 = 610.78
  73. real, parameter :: c3a = 17.269
  74. real, parameter :: c3b = 21.875
  75. real, parameter :: c4a = 35.86
  76. real, parameter :: c4b = 7.66
  77. ! --- local ------------------------------
  78. real :: es
  79. real :: qsat
  80. ! --- begin -------------------------------
  81. if ( p < 0.0 ) then
  82. dQSat_dT = 0.0
  83. return
  84. endif
  85. ! set function 'dqsatdt' equal 0 for temperatures t less than 9K to ensure
  86. ! numerical stability (the argument of the following exponential
  87. ! function would otherwise exceeds maximum)
  88. if ( t < 9.0 ) then
  89. dQSat_dT = 0.0
  90. return
  91. end if
  92. if ( T >= T0 ) then
  93. es = c1*exp(c3a*(T-T0)/(T-c4a))
  94. qsat = eps/((p/es)-(1-eps))
  95. dQSat_dT = c3a*(T0-c4a)*qsat/((T-c4a)*(T-c4a)*(1.0-(1.0-eps)*es/p))
  96. else
  97. es = c1*exp(c3b*(T-T0)/(T-c4b))
  98. qsat = eps/((p/es)-(1-eps))
  99. dQSat_dT = c3a*(T0-c4a)*qsat/((T-c4a)*(T-c4a)*(1.0-(1.0-eps)*es/p))
  100. end if
  101. end function dQSat_dT
  102. !
  103. ! calculate specific humidity
  104. !
  105. real function QH2O( r, T, p )
  106. ! --- in/out -------------------------------
  107. real, intent(in) :: R ! rel. humidity (%)
  108. real, intent(in) :: T ! temperature (in K)
  109. real, intent(in) :: p ! pressure (Pa)
  110. ! --- const --------------------------------
  111. real, parameter :: rgasd = 287.05
  112. real, parameter :: rgasv = 461.51
  113. real, parameter :: eps = rgasd/rgasv
  114. real, parameter :: T0 = 273.16
  115. real, parameter :: c1 = 610.78
  116. real, parameter :: c3a = 17.269
  117. real, parameter :: c3b = 21.875
  118. real, parameter :: c4a = 35.86
  119. real, parameter :: c4b = 7.66
  120. ! --- local ------------------------------
  121. real :: es
  122. ! --- begin -------------------------------
  123. if ( p <= 0.0 ) then
  124. QH2O = 0.0
  125. return
  126. endif
  127. ! set function 'qh2o' equal 0 for temperatures t less than 9K to ensure
  128. ! numerical stability (the argument of the following exponential
  129. ! function would otherwise exceeds maximum)
  130. if ( T < 9.0 ) then
  131. qh2o = 0.0
  132. return
  133. endif
  134. if ( T >= T0 ) then
  135. es = c1*exp(c3a*(T-T0)/(T-c4a))
  136. else
  137. es = c1*exp(c3b*(T-T0)/(T-c4b))
  138. endif
  139. QH2O = (R/100.0)*eps / ((p/es)-(1.0-eps))
  140. end function QH2O
  141. end module phys_humidity