1 MODULE module_chem_utilities
3 USE module_model_constants
4 USE module_state_description
8 SUBROUTINE chem_prep ( config_flags, & ! input
9 u, v, p, pb, alt, ph, & ! input
10 phb, t, moist, n_moist, & ! input
11 rho, p_phy , & ! output
12 u_phy, v_phy, p8w, t_phy, t8w, & ! output
13 z, z_at_w, dz8w,rh, & ! output
15 ids, ide, jds, jde, kds, kde, &
16 ims, ime, jms, jme, kms, kme, &
17 its, ite, jts, jte, kts, kte )
18 !----------------------------------------------------------------------
20 !----------------------------------------------------------------------
22 TYPE(grid_config_rec_type) , INTENT(IN ) :: config_flags
23 INTEGER , INTENT(IN ) :: ids, ide, jds, jde, kds, kde, &
24 ims, ime, jms, jme, kms, kme, &
25 its, ite, jts, jte, kts, kte
26 INTEGER , INTENT(IN ) :: n_moist
28 REAL, DIMENSION( ims:ime, kms:kme , jms:jme , n_moist ), INTENT(IN) :: moist
32 REAL , DIMENSION( ims:ime , kms:kme , jms:jme ) , &
33 INTENT( OUT) :: u_phy, &
44 REAL , DIMENSION( ims:ime , kms:kme , jms:jme ) , &
55 REAL , DIMENSION( kms:kme ) , INTENT(IN ) :: fzm, &
58 INTEGER :: i_start, i_end, j_start, j_end, k_start, k_end
60 REAL :: w1, w2, z0, z1, z2
62 !-----------------------------------------------------------------------
64 ! set up loop bounds for this grid's boundary conditions
67 i_end = min( ite,ide-1 )
69 j_end = min( jte,jde-1 )
72 k_end = min( kte, kde-1 )
74 ! compute thermodynamics and velocities at pressure points
79 p_phy(i,k,j) = p(i,k,j) + pb(i,k,j)
80 t_phy(i,k,j) = (t(i,k,j)+t0)*(p_phy(i,k,j)/p1000mb)**rcp
81 rho(i,k,j) = 1./alt(i,k,j)*(1.+moist(i,k,j,P_QV))
82 u_phy(i,k,j) = 0.5*(u(i,k,j)+u(i+1,k,j))
83 v_phy(i,k,j) = 0.5*(v(i,k,j)+v(i,k,j+1))
89 ! wig: added to make sure there is no junk in the top level even
90 ! though it should not be used
93 p_phy(i,kte,j) = p_phy(i,k_end,j)
94 t_phy(i,kte,j) = t_phy(i,k_end,j)
95 rho(i,kte,j) = rho(i,k_end,j)
96 u_phy(i,kte,j) = u_phy(i,k_end,j)
97 v_phy(i,kte,j) = v_phy(i,k_end,j)
101 ! compute z at w points
105 do i = i_start, i_end
106 z_at_w(i,k,j) = (phb(i,k,j)+ph(i,k,j))/g
112 do k = k_start, kte-1
113 do i = i_start, i_end
114 dz8w(i,k,j) = z_at_w(i,k+1,j)-z_at_w(i,k,j)
120 do i = i_start, i_end
125 ! compute z at p points (average of z at w points)
127 do k = k_start, k_end
128 do i = i_start, i_end
129 z(i,k,j) = 0.5*(z_at_w(i,k,j) +z_at_w(i,k+1,j) )
130 rh(i,k,j) = max(.1,MIN( .95, moist(i,k,j,p_qv) / &
131 (3.80*exp(17.27*(t_phy(i,k,j)-273.)/ &
132 (t_phy(i,k,j)-36.))/(.01*p_phy(i,k,j)))))
133 ! rh(i,k,j)=max(.1,rh(i,k,j))
139 ! interp t and p at w points
143 do i = i_start, i_end
144 p8w(i,k,j) = fzm(k)*p_phy(i,k,j)+fzp(k)*p_phy(i,k-1,j)
145 t8w(i,k,j) = fzm(k)*t_phy(i,k,j)+fzp(k)*t_phy(i,k-1,j)
150 ! extrapolate p and t to surface and top.
151 ! we'll use an extrapolation in z for now
154 do i = i_start, i_end
161 w1 = (z0 - z2)/(z1 - z2)
163 p8w(i,1,j) = w1*p_phy(i,1,j)+w2*p_phy(i,2,j)
164 t8w(i,1,j) = w1*t_phy(i,1,j)+w2*t_phy(i,2,j)
171 w1 = (z0 - z2)/(z1 - z2)
174 ! p8w(i,kde,j) = w1*p_phy(i,kde-1,j)+w2*p_phy(i,kde-2,j)
175 !!! bug fix extrapolate ln(p) so p is positive definite
176 p8w(i,kde,j) = exp(w1*log(p_phy(i,kde-1,j))+w2*log(p_phy(i,kde-2,j)))
177 t8w(i,kde,j) = w1*t_phy(i,kde-1,j)+w2*t_phy(i,kde-2,j)
181 END SUBROUTINE chem_prep
183 subroutine UPCASE( lstring )
184 !----------------------------------------------------------------------
185 ! ... Convert character string lstring to upper case
186 !----------------------------------------------------------------------
189 !-----------------------------------------------------------------------
191 !-----------------------------------------------------------------------
192 character(len=*), intent(inout) :: lstring
194 !-----------------------------------------------------------------------
195 ! ... Local variables
196 !-----------------------------------------------------------------------
199 do i = 1,LEN_TRIM( lstring )
200 if( ICHAR(lstring(i:i)) >= 97 .and. ICHAR(lstring(i:i)) <= 122 ) then
201 lstring(i:i) = CHAR(ICHAR(lstring(i:i)) - 32)
205 end subroutine UPCASE
207 END MODULE module_chem_utilities