chgres_cube  1.7.0
 All Data Structures Files Functions Variables
grib2_util.F90
Go to the documentation of this file.
1 
4 
12 module grib2_util
13 
14 use esmf
15 
16 use model_grid, only : i_input, j_input
17 
18 implicit none
19 
20 public :: rh2spfh
21 public :: convert_omega
22 public :: rh2spfh_gfs
23 public :: fpvsnew
24 
25 contains
26 
37  subroutine rh2spfh(rh_sphum,p,t)
38 
39  implicit none
40  real,parameter :: alpha=-9.477e-4 , & !K^-1,
41  tnot=273.15, & !K
42  lnot=2.5008e6, & !JKg^-1
43  rv=461.51, & !JKg^-1K^-1
44  esnot=611.21 !Pa
45 
46  real(esmf_kind_r4), intent(inout), dimension(i_input,j_input) ::rh_sphum
47  real(esmf_kind_r8), intent(in) :: p, t(i_input,j_input)
48 
49  real, dimension(i_input,j_input) :: es, e, rh
50 
51  print*,"- CONVERT RH TO SPFH AT LEVEL ", p
52 
53  rh = rh_sphum
54  !print *, 'T = ', T, ' RH = ', RH, ' P = ', P
55  es = esnot * exp( lnot/rv * ((t-tnot)/(t*tnot) + alpha * log(t/tnot) - alpha * (t-tnot)/ t))
56  !print *, 'es = ', es
57  e = rh * es / 100.0
58  !print *, 'e = ', e
59  rh_sphum = 0.622 * e / p
60  !print *, 'q = ', sphum
61 
62  !if (P .eq. 100000.0) THEN
63  !print *, 'T = ', t, ' RH = ', rh, ' P = ', p, ' es = ', es, ' e = ', e, ' q = ', rh_sphum
64  !end if
65 
66 end subroutine rh2spfh
67 
80  subroutine rh2spfh_gfs(rh_sphum,p,t)
81 
82  implicit none
83 
84  integer kind_phys
85 
86  parameter(kind_phys = selected_real_kind(13,60)) ! the '60' maps to 64-bit real
87 
88 
89  real(kind=kind_phys),parameter:: con_rd =2.8705e+2 ! gas constant air (J/kg/K)
90  real(kind=kind_phys),parameter:: con_rv =4.6150e+2 ! gas constant H2O (J/kg/K)
91 
92  real(kind=kind_phys),parameter:: con_eps =con_rd/con_rv
93  real(kind=kind_phys),parameter:: con_epsm1 =con_rd/con_rv-1.
94 
95 
96 
97 
98  real(esmf_kind_r4), intent(inout), dimension(i_input,j_input) ::rh_sphum
99  real(esmf_kind_r8), intent(in) :: p, t(i_input,j_input)
100 
101  real, dimension(i_input,j_input) :: qc, rh
102  real :: es
103  integer :: i,j
104 
105  print*,"- CONVERT RH TO SPFH AT LEVEL ", p
106 
107  rh = rh_sphum
108 
109 do j=1,j_input
110  do i=1,i_input
111  es = min(fpvsnew(t(i,j)),p)
112  qc(i,j) = con_eps*es/(p+con_epsm1*es)
113  rh_sphum(i,j) = rh(i,j)*qc(i,j)/100.0
114  end do
115 end do
116 
117 
118  !print *, 'T = ', T, ' RH = ', RH, ' P = ', P
119  !print *, 'q = ', sphum
120 
121 
122 end subroutine rh2spfh_gfs
123 
124 
131 
132 !
133 !-------------------------------------------------------------------------------------
134 !
135  elemental function fpvsnew(t)
136 !
137  implicit none
138  integer,parameter:: nxpvs=7501
139  real,parameter:: con_ttp =2.7316e+2 ! temp at H2O 3pt
140  real,parameter:: con_psat =6.1078e+2 ! pres at H2O 3pt
141  real,parameter:: con_cvap =1.8460e+3 ! spec heat H2O gas (J/kg/K)
142  real,parameter:: con_cliq =4.1855e+3 ! spec heat H2O liq
143  real,parameter:: con_hvap =2.5000e+6 ! lat heat H2O cond
144  real,parameter:: con_rv =4.6150e+2 ! gas constant H2O
145  real,parameter:: con_csol =2.1060e+3 ! spec heat H2O ice
146  real,parameter:: con_hfus =3.3358e+5 ! lat heat H2O fusion
147  real,parameter:: tliq=con_ttp
148  real,parameter:: tice=con_ttp-20.0
149  real,parameter:: dldtl=con_cvap-con_cliq
150  real,parameter:: heatl=con_hvap
151  real,parameter:: xponal=-dldtl/con_rv
152  real,parameter:: xponbl=-dldtl/con_rv+heatl/(con_rv*con_ttp)
153  real,parameter:: dldti=con_cvap-con_csol
154  real,parameter:: heati=con_hvap+con_hfus
155  real,parameter:: xponai=-dldti/con_rv
156  real,parameter:: xponbi=-dldti/con_rv+heati/(con_rv*con_ttp)
157  real tr,w,pvl,pvi
158  real fpvsnew
159  real(esmf_kind_r8),intent(in):: t
160  integer jx
161  real xj,x,tbpvs(nxpvs),xp1
162  real xmin,xmax,xinc,c2xpvs,c1xpvs
163 ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
164  xmin=180.0
165  xmax=330.0
166  xinc=(xmax-xmin)/(nxpvs-1)
167 ! c1xpvs=1.-xmin/xinc
168  c2xpvs=1./xinc
169  c1xpvs=1.-xmin*c2xpvs
170 ! xj=min(max(c1xpvs+c2xpvs*t,1.0),real(nxpvs,krealfp))
171  xj=min(max(c1xpvs+c2xpvs*t,1.0),float(nxpvs))
172  jx=min(xj,float(nxpvs)-1.0)
173  x=xmin+(jx-1)*xinc
174 
175  tr=con_ttp/x
176  if(x>=tliq) then
177  tbpvs(jx)=con_psat*(tr**xponal)*exp(xponbl*(1.-tr))
178  elseif(x<tice) then
179  tbpvs(jx)=con_psat*(tr**xponai)*exp(xponbi*(1.-tr))
180  else
181  w=(t-tice)/(tliq-tice)
182  pvl=con_psat*(tr**xponal)*exp(xponbl*(1.-tr))
183  pvi=con_psat*(tr**xponai)*exp(xponbi*(1.-tr))
184  tbpvs(jx)=w*pvl+(1.-w)*pvi
185  endif
186 
187  xp1=xmin+(jx-1+1)*xinc
188 
189  tr=con_ttp/xp1
190  if(xp1>=tliq) then
191  tbpvs(jx+1)=con_psat*(tr**xponal)*exp(xponbl*(1.-tr))
192  elseif(xp1<tice) then
193  tbpvs(jx+1)=con_psat*(tr**xponai)*exp(xponbi*(1.-tr))
194  else
195  w=(t-tice)/(tliq-tice)
196  pvl=con_psat*(tr**xponal)*exp(xponbl*(1.-tr))
197  pvi=con_psat*(tr**xponai)*exp(xponbi*(1.-tr))
198  tbpvs(jx+1)=w*pvl+(1.-w)*pvi
199  endif
200 
201  fpvsnew=tbpvs(jx)+(xj-jx)*(tbpvs(jx+1)-tbpvs(jx))
202 ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
203  end function fpvsnew
204 
205 
206 
217 subroutine convert_omega(omega,p,t,q,clb,cub)
218 
219  implicit none
220  real(esmf_kind_r8), pointer :: omega(:,:,:), p(:,:,:), t(:,:,:), q(:,:,:),omtmp,ptmp
221 
222  integer :: clb(3), cub(3), i ,j, k
223 
224  real, parameter :: rd = 287.15_esmf_kind_r8, & !JKg^-1K^-1
225  rv=461.51_esmf_kind_r8, & !JKg^-1K^-1
226  g = 9.81_esmf_kind_r8 ! ms^-2
227 
228  real(esmf_kind_r8) :: tv, w
229 
230  do k = clb(3),cub(3)
231  do j = clb(2),cub(2)
232  do i = clb(1),cub(1)
233  tv = t(i,j,k)*(1+rd/rv*q(i,j,k))
234  omtmp=>omega(i,j,k)
235  ptmp=>p(i,j,k)
236 
237  w = -1 * omtmp * rd * tv / (ptmp * g)
238  omega(i,j,k)=w
239  enddo
240  enddo
241  enddo
242 
243 end subroutine convert_omega
244 
245  end module grib2_util
subroutine, public convert_omega(omega, p, t, q, clb, cub)
Convert omega to vertical velocity.
Definition: grib2_util.F90:217
subroutine, public rh2spfh(rh_sphum, p, t)
Convert relative humidity to specific humidity.
Definition: grib2_util.F90:37
elemental real function, public fpvsnew(t)
Compute saturation vapor pressure.
Definition: grib2_util.F90:135
Sets up the ESMF grid objects for the input data grid and target FV3 grid.
Definition: model_grid.F90:9
subroutine, public rh2spfh_gfs(rh_sphum, p, t)
Convert relative humidity to specific humidity (GFS formula) Calculation of saturation water vapor pr...
Definition: grib2_util.F90:80
Utilities for use when reading grib2 data.
Definition: grib2_util.F90:12