module_initialize_squall2d_x.F
References to this file elsewhere.
1 !IDEAL:MODEL_LAYER:INITIALIZATION
2 !
3
4 ! This MODULE holds the routines which are used to perform various initializations
5 ! for the individual domains.
6
7 ! This MODULE CONTAINS the following routines:
8
9 ! initialize_field_test - 1. Set different fields to different constant
10 ! values. This is only a test. If the correct
11 ! domain is not found (based upon the "id")
12 ! then a fatal error is issued.
13
14 !-----------------------------------------------------------------------
15
16 MODULE module_initialize_ideal
17
18 USE module_domain
19 USE module_io_domain
20 USE module_state_description
21 USE module_model_constants
22 USE module_bc
23 USE module_timing
24 USE module_configure
25 USE module_init_utilities
26 #ifdef DM_PARALLEL
27 USE module_dm
28 #endif
29
30
31 CONTAINS
32
33
34 !-------------------------------------------------------------------
35 ! this is a wrapper for the solver-specific init_domain routines.
36 ! Also dereferences the grid variables and passes them down as arguments.
37 ! This is crucial, since the lower level routines may do message passing
38 ! and this will get fouled up on machines that insist on passing down
39 ! copies of assumed-shape arrays (by passing down as arguments, the
40 ! data are treated as assumed-size -- ie. f77 -- arrays and the copying
41 ! business is avoided). Fie on the F90 designers. Fie and a pox.
42 ! NOTE: Modified to remove all but arrays of rank 4 or more from the
43 ! argument list. Arrays with rank>3 are still problematic due to the
44 ! above-noted fie- and pox-ities. TBH 20061129.
45
46 SUBROUTINE init_domain ( grid )
47
48 IMPLICIT NONE
49
50 ! Input data.
51 TYPE (domain), POINTER :: grid
52 ! Local data.
53 INTEGER :: dyn_opt
54 INTEGER :: idum1, idum2
55
56 CALL nl_get_dyn_opt( 1, dyn_opt )
57
58 CALL set_scalar_indices_from_config ( head_grid%id , idum1, idum2 )
59
60 IF ( dyn_opt .eq. 1 &
61 .or. dyn_opt .eq. 2 &
62 .or. dyn_opt .eq. 3 &
63 ) THEN
64 CALL init_domain_rk( grid &
65 !
66 #include <em_actual_new_args.inc>
67 !
68 )
69
70 ELSE
71 WRITE(0,*)' init_domain: unknown or unimplemented dyn_opt = ',dyn_opt
72 CALL wrf_error_fatal ( ' init_domain: unknown or unimplemented dyn_opt ' )
73 ENDIF
74
75 END SUBROUTINE init_domain
76
77 !-------------------------------------------------------------------
78
79 SUBROUTINE init_domain_rk ( grid &
80 !
81 # include <em_dummy_new_args.inc>
82 !
83 )
84 IMPLICIT NONE
85
86 ! Input data.
87 TYPE (domain), POINTER :: grid
88
89 # include <em_dummy_new_decl.inc>
90
91 TYPE (grid_config_rec_type) :: config_flags
92
93 ! Local data
94 INTEGER :: &
95 ids, ide, jds, jde, kds, kde, &
96 ims, ime, jms, jme, kms, kme, &
97 its, ite, jts, jte, kts, kte, &
98 i, j, k
99
100 ! Local data
101
102 INTEGER, PARAMETER :: nl_max = 1000
103 REAL, DIMENSION(nl_max) :: zk, p_in, theta, rho, u, v, qv, pd_in
104 INTEGER :: nl_in
105
106
107 INTEGER :: icm,jcm, ii, im1, jj, jm1, loop, error, fid, nxc, nyc
108 REAL :: u_mean,v_mean, f0, p_surf, p_level, qvf, z_at_v, z_at_u
109 REAL :: z_scale, xrad, yrad, zrad, rad, delt, cof1, cof2
110 ! REAL, EXTERNAL :: interp_0
111 REAL :: hm
112 REAL :: pi
113
114 ! stuff from original initialization that has been dropped from the Registry
115 REAL :: vnu, xnu, xnus, dinit0, cbh, p0_temp, t0_temp, zd, zt
116 REAL :: qvf1, qvf2, pd_surf
117 INTEGER :: it
118 real :: thtmp, ptmp, temp(3)
119
120 LOGICAL :: moisture_init
121 LOGICAL :: stretch_grid, dry_sounding
122
123
124 #ifdef DM_PARALLEL
125 # include <em_data_calls.inc>
126 #endif
127
128
129 SELECT CASE ( model_data_order )
130 CASE ( DATA_ORDER_ZXY )
131 kds = grid%sd31 ; kde = grid%ed31 ;
132 ids = grid%sd32 ; ide = grid%ed32 ;
133 jds = grid%sd33 ; jde = grid%ed33 ;
134
135 kms = grid%sm31 ; kme = grid%em31 ;
136 ims = grid%sm32 ; ime = grid%em32 ;
137 jms = grid%sm33 ; jme = grid%em33 ;
138
139 kts = grid%sp31 ; kte = grid%ep31 ; ! note that tile is entire patch
140 its = grid%sp32 ; ite = grid%ep32 ; ! note that tile is entire patch
141 jts = grid%sp33 ; jte = grid%ep33 ; ! note that tile is entire patch
142 CASE ( DATA_ORDER_XYZ )
143 ids = grid%sd31 ; ide = grid%ed31 ;
144 jds = grid%sd32 ; jde = grid%ed32 ;
145 kds = grid%sd33 ; kde = grid%ed33 ;
146
147 ims = grid%sm31 ; ime = grid%em31 ;
148 jms = grid%sm32 ; jme = grid%em32 ;
149 kms = grid%sm33 ; kme = grid%em33 ;
150
151 its = grid%sp31 ; ite = grid%ep31 ; ! note that tile is entire patch
152 jts = grid%sp32 ; jte = grid%ep32 ; ! note that tile is entire patch
153 kts = grid%sp33 ; kte = grid%ep33 ; ! note that tile is entire patch
154 CASE ( DATA_ORDER_XZY )
155 ids = grid%sd31 ; ide = grid%ed31 ;
156 kds = grid%sd32 ; kde = grid%ed32 ;
157 jds = grid%sd33 ; jde = grid%ed33 ;
158
159 ims = grid%sm31 ; ime = grid%em31 ;
160 kms = grid%sm32 ; kme = grid%em32 ;
161 jms = grid%sm33 ; jme = grid%em33 ;
162
163 its = grid%sp31 ; ite = grid%ep31 ; ! note that tile is entire patch
164 kts = grid%sp32 ; kte = grid%ep32 ; ! note that tile is entire patch
165 jts = grid%sp33 ; jte = grid%ep33 ; ! note that tile is entire patch
166
167 END SELECT
168
169
170 stretch_grid = .true.
171 delt = 3.
172 ! z_scale = .50
173 z_scale = .40
174 pi = 2.*asin(1.0)
175 write(6,*) ' pi is ',pi
176 nxc = (ide-ids)/2
177 nyc = jde/2
178
179 CALL model_to_grid_config_rec ( grid%id , model_config_rec , config_flags )
180
181 ! here we check to see if the boundary conditions are set properly
182
183 CALL boundary_condition_check( config_flags, bdyzone, error, grid%id )
184
185 moisture_init = .true.
186
187 grid%itimestep=0
188
189 #ifdef DM_PARALLEL
190 CALL wrf_dm_bcast_bytes( icm , IWORDSIZE )
191 CALL wrf_dm_bcast_bytes( jcm , IWORDSIZE )
192 #endif
193
194 CALL nl_set_mminlu(1, ' ')
195 CALL nl_set_iswater(1,0)
196 CALL nl_set_cen_lat(1,40.)
197 CALL nl_set_cen_lon(1,-105.)
198 CALL nl_set_truelat1(1,0.)
199 CALL nl_set_truelat2(1,0.)
200 CALL nl_set_moad_cen_lat (1,0.)
201 CALL nl_set_stand_lon (1,0.)
202 CALL nl_set_map_proj(1,0)
203
204
205 ! here we initialize data we currently is not initialized
206 ! in the input data
207
208 DO j = jts, jte
209 DO i = its, ite
210 grid%msft(i,j) = 1.
211 grid%msfu(i,j) = 1.
212 grid%msfv(i,j) = 1.
213 grid%sina(i,j) = 0.
214 grid%cosa(i,j) = 1.
215 grid%e(i,j) = 0.
216 grid%f(i,j) = 0.
217
218 END DO
219 END DO
220
221 DO j = jts, jte
222 DO k = kts, kte
223 DO i = its, ite
224 grid%em_ww(i,k,j) = 0.
225 END DO
226 END DO
227 END DO
228
229 grid%step_number = 0
230
231 ! set up the grid
232
233 IF (stretch_grid) THEN ! exponential stretch for eta (nearly constant dz)
234 DO k=1, kde
235 grid%em_znw(k) = (exp(-(k-1)/float(kde-1)/z_scale) - exp(-1./z_scale))/ &
236 (1.-exp(-1./z_scale))
237 ENDDO
238 ELSE
239 DO k=1, kde
240 grid%em_znw(k) = 1. - float(k-1)/float(kde-1)
241 ENDDO
242 ENDIF
243
244 DO k=1, kde-1
245 grid%em_dnw(k) = grid%em_znw(k+1) - grid%em_znw(k)
246 grid%em_rdnw(k) = 1./grid%em_dnw(k)
247 grid%em_znu(k) = 0.5*(grid%em_znw(k+1)+grid%em_znw(k))
248 ENDDO
249 DO k=2, kde-1
250 grid%em_dn(k) = 0.5*(grid%em_dnw(k)+grid%em_dnw(k-1))
251 grid%em_rdn(k) = 1./grid%em_dn(k)
252 grid%em_fnp(k) = .5* grid%em_dnw(k )/grid%em_dn(k)
253 grid%em_fnm(k) = .5* grid%em_dnw(k-1)/grid%em_dn(k)
254 ENDDO
255
256 cof1 = (2.*grid%em_dn(2)+grid%em_dn(3))/(grid%em_dn(2)+grid%em_dn(3))*grid%em_dnw(1)/grid%em_dn(2)
257 cof2 = grid%em_dn(2) /(grid%em_dn(2)+grid%em_dn(3))*grid%em_dnw(1)/grid%em_dn(3)
258 grid%cf1 = grid%em_fnp(2) + cof1
259 grid%cf2 = grid%em_fnm(2) - cof1 - cof2
260 grid%cf3 = cof2
261
262 grid%cfn = (.5*grid%em_dnw(kde-1)+grid%em_dn(kde-1))/grid%em_dn(kde-1)
263 grid%cfn1 = -.5*grid%em_dnw(kde-1)/grid%em_dn(kde-1)
264 grid%rdx = 1./config_flags%dx
265 grid%rdy = 1./config_flags%dy
266
267 ! get the sounding from the ascii sounding file, first get dry sounding and
268 ! calculate base state
269
270 write(6,*) ' getting dry sounding for base state '
271 dry_sounding = .true.
272 CALL get_sounding( zk, p_in, pd_in, theta, rho, u, v, qv, dry_sounding, nl_max, nl_in )
273
274 write(6,*) ' returned from reading sounding, nl_in is ',nl_in
275
276 ! find ptop for the desired ztop (ztop is input from the namelist),
277 ! and find surface pressure
278
279 grid%p_top = interp_0( p_in, zk, config_flags%ztop, nl_in )
280
281 DO j=jts,jte
282 DO i=its,ite ! flat surface
283 grid%em_phb(i,1,j) = 0.
284 grid%em_php(i,1,j) = 0.
285 grid%em_ph0(i,1,j) = 0.
286 grid%ht(i,j) = 0.
287 ENDDO
288 ENDDO
289
290 DO J = jts, jte
291 DO I = its, ite
292
293 p_surf = interp_0( p_in, zk, grid%em_phb(i,1,j)/g, nl_in )
294 grid%em_mub(i,j) = p_surf-grid%p_top
295
296 ! this is dry hydrostatic sounding (base state), so given grid%em_p (coordinate),
297 ! interp theta (from interp) and compute 1/rho from eqn. of state
298
299 DO K = 1, kte-1
300 p_level = grid%em_znu(k)*(p_surf - grid%p_top) + grid%p_top
301 grid%em_pb(i,k,j) = p_level
302 grid%em_t_init(i,k,j) = interp_0( theta, p_in, p_level, nl_in ) - t0
303 grid%em_alb(i,k,j) = (r_d/p1000mb)*(grid%em_t_init(i,k,j)+t0)*(grid%em_pb(i,k,j)/p1000mb)**cvpm
304 ENDDO
305
306 ! calc hydrostatic balance (alternatively we could interp the geopotential from the
307 ! sounding, but this assures that the base state is in exact hydrostatic balance with
308 ! respect to the model eqns.
309
310 DO k = 2,kte
311 grid%em_phb(i,k,j) = grid%em_phb(i,k-1,j) - grid%em_dnw(k-1)*grid%em_mub(i,j)*grid%em_alb(i,k-1,j)
312 ENDDO
313
314 ENDDO
315 ENDDO
316
317 write(6,*) ' ptop is ',grid%p_top
318 write(6,*) ' base state grid%em_mub(1,1), p_surf is ',grid%em_mub(1,1),grid%em_mub(1,1)+grid%p_top
319
320 ! calculate full state for each column - this includes moisture.
321
322 write(6,*) ' getting moist sounding for full state '
323 dry_sounding = .false.
324 CALL get_sounding( zk, p_in, pd_in, theta, rho, u, v, qv, dry_sounding, nl_max, nl_in )
325
326 DO J = jts, min(jde-1,jte)
327 DO I = its, min(ide-1,ite)
328
329 ! At this point grid%p_top is already set. find the DRY mass in the column
330 ! by interpolating the DRY pressure.
331
332 pd_surf = interp_0( pd_in, zk, grid%em_phb(i,1,j)/g, nl_in )
333
334 ! compute the perturbation mass and the full mass
335
336 grid%em_mu_1(i,j) = pd_surf-grid%p_top - grid%em_mub(i,j)
337 grid%em_mu_2(i,j) = grid%em_mu_1(i,j)
338 grid%em_mu0(i,j) = grid%em_mu_1(i,j) + grid%em_mub(i,j)
339
340 ! given the dry pressure and coordinate system, interp the potential
341 ! temperature and qv
342
343 do k=1,kde-1
344
345 p_level = grid%em_znu(k)*(pd_surf - grid%p_top) + grid%p_top
346
347 moist(i,k,j,P_QV) = interp_0( qv, pd_in, p_level, nl_in )
348 grid%em_t_1(i,k,j) = interp_0( theta, pd_in, p_level, nl_in ) - t0
349 grid%em_t_2(i,k,j) = grid%em_t_1(i,k,j)
350
351
352 enddo
353
354 ! integrate the hydrostatic equation (from the RHS of the bigstep
355 ! vertical momentum equation) down from the top to get grid%em_p.
356 ! first from the top of the model to the top pressure
357
358 k = kte-1 ! top level
359
360 qvf1 = 0.5*(moist(i,k,j,P_QV)+moist(i,k,j,P_QV))
361 qvf2 = 1./(1.+qvf1)
362 qvf1 = qvf1*qvf2
363
364 ! grid%em_p(i,k,j) = - 0.5*grid%em_mu_1(i,j)/grid%em_rdnw(k)
365 grid%em_p(i,k,j) = - 0.5*(grid%em_mu_1(i,j)+qvf1*grid%em_mub(i,j))/grid%em_rdnw(k)/qvf2
366 qvf = 1. + rvovrd*moist(i,k,j,P_QV)
367 grid%em_alt(i,k,j) = (r_d/p1000mb)*(grid%em_t_1(i,k,j)+t0)*qvf* &
368 (((grid%em_p(i,k,j)+grid%em_pb(i,k,j))/p1000mb)**cvpm)
369 grid%em_al(i,k,j) = grid%em_alt(i,k,j) - grid%em_alb(i,k,j)
370
371 ! down the column
372
373 do k=kte-2,1,-1
374 qvf1 = 0.5*(moist(i,k,j,P_QV)+moist(i,k+1,j,P_QV))
375 qvf2 = 1./(1.+qvf1)
376 qvf1 = qvf1*qvf2
377 grid%em_p(i,k,j) = grid%em_p(i,k+1,j) - (grid%em_mu_1(i,j) + qvf1*grid%em_mub(i,j))/qvf2/grid%em_rdn(k+1)
378 qvf = 1. + rvovrd*moist(i,k,j,P_QV)
379 grid%em_alt(i,k,j) = (r_d/p1000mb)*(grid%em_t_1(i,k,j)+t0)*qvf* &
380 (((grid%em_p(i,k,j)+grid%em_pb(i,k,j))/p1000mb)**cvpm)
381 grid%em_al(i,k,j) = grid%em_alt(i,k,j) - grid%em_alb(i,k,j)
382 enddo
383
384 ! this is the hydrostatic equation used in the model after the
385 ! small timesteps. In the model, grid%em_al (inverse density)
386 ! is computed from the geopotential.
387
388
389 grid%em_ph_1(i,1,j) = 0.
390 DO k = 2,kte
391 grid%em_ph_1(i,k,j) = grid%em_ph_1(i,k-1,j) - (1./grid%em_rdnw(k-1))*( &
392 (grid%em_mub(i,j)+grid%em_mu_1(i,j))*grid%em_al(i,k-1,j)+ &
393 grid%em_mu_1(i,j)*grid%em_alb(i,k-1,j) )
394
395 grid%em_ph_2(i,k,j) = grid%em_ph_1(i,k,j)
396 grid%em_ph0(i,k,j) = grid%em_ph_1(i,k,j) + grid%em_phb(i,k,j)
397 ENDDO
398
399 if((i==2) .and. (j==2)) then
400 write(6,*) ' grid%em_ph_1 calc ',grid%em_ph_1(2,1,2),grid%em_ph_1(2,2,2),&
401 grid%em_mu_1(2,2)+grid%em_mub(2,2),grid%em_mu_1(2,2), &
402 grid%em_alb(2,1,2),grid%em_al(1,2,1),grid%em_rdnw(1)
403 endif
404
405 ENDDO
406 ENDDO
407
408 !#if 0
409
410 ! thermal perturbation to kick off convection
411
412 write(6,*) ' nxc, nyc for perturbation ',nxc,nyc
413 write(6,*) ' delt for perturbation ',delt
414
415 DO J = jts, min(jde-1,jte)
416 ! yrad = config_flags%dy*float(j-nyc)/4000.
417 yrad = 0.
418 DO I = its, min(ide-1,ite)
419 xrad = config_flags%dx*float(i-nxc)/4000.
420 ! xrad = 0.
421 DO K = 1, kte-1
422
423 ! put in preturbation theta (bubble) and recalc density. note,
424 ! the mass in the column is not changing, so when theta changes,
425 ! we recompute density and geopotential
426
427 zrad = 0.5*(grid%em_ph_1(i,k,j)+grid%em_ph_1(i,k+1,j) &
428 +grid%em_phb(i,k,j)+grid%em_phb(i,k+1,j))/g
429 zrad = (zrad-1500.)/1500.
430 RAD=SQRT(xrad*xrad+yrad*yrad+zrad*zrad)
431 IF(RAD <= 1.) THEN
432 grid%em_t_1(i,k,j)=grid%em_t_1(i,k,j)+delt*COS(.5*PI*RAD)**2
433 grid%em_t_2(i,k,j)=grid%em_t_1(i,k,j)
434 qvf = 1. + rvovrd*moist(i,k,j,P_QV)
435 grid%em_alt(i,k,j) = (r_d/p1000mb)*(grid%em_t_1(i,k,j)+t0)*qvf* &
436 (((grid%em_p(i,k,j)+grid%em_pb(i,k,j))/p1000mb)**cvpm)
437 grid%em_al(i,k,j) = grid%em_alt(i,k,j) - grid%em_alb(i,k,j)
438 ENDIF
439 ENDDO
440
441 ! rebalance hydrostatically
442
443 DO k = 2,kte
444 grid%em_ph_1(i,k,j) = grid%em_ph_1(i,k-1,j) - (1./grid%em_rdnw(k-1))*( &
445 (grid%em_mub(i,j)+grid%em_mu_1(i,j))*grid%em_al(i,k-1,j)+ &
446 grid%em_mu_1(i,j)*grid%em_alb(i,k-1,j) )
447
448 grid%em_ph_2(i,k,j) = grid%em_ph_1(i,k,j)
449 grid%em_ph0(i,k,j) = grid%em_ph_1(i,k,j) + grid%em_phb(i,k,j)
450 ENDDO
451
452 ENDDO
453 ENDDO
454
455 !#endif
456
457 write(6,*) ' grid%em_mu_1 from comp ', grid%em_mu_1(1,1)
458 write(6,*) ' full state sounding from comp, ph, grid%em_p, grid%em_al, grid%em_t_1, qv '
459 do k=1,kde-1
460 write(6,'(i3,1x,5(1x,1pe10.3))') k, grid%em_ph_1(1,k,1)+grid%em_phb(1,k,1), &
461 grid%em_p(1,k,1)+grid%em_pb(1,k,1), grid%em_alt(1,k,1), &
462 grid%em_t_1(1,k,1)+t0, moist(1,k,1,P_QV)
463 enddo
464
465 write(6,*) ' pert state sounding from comp, grid%em_ph_1, pp, alp, grid%em_t_1, qv '
466 do k=1,kde-1
467 write(6,'(i3,1x,5(1x,1pe10.3))') k, grid%em_ph_1(1,k,1), &
468 grid%em_p(1,k,1), grid%em_al(1,k,1), &
469 grid%em_t_1(1,k,1), moist(1,k,1,P_QV)
470 enddo
471
472 ! interp v
473
474 DO J = jts, jte
475 DO I = its, min(ide-1,ite)
476
477 IF (j == jds) THEN
478 z_at_v = grid%em_phb(i,1,j)/g
479 ELSE IF (j == jde) THEN
480 z_at_v = grid%em_phb(i,1,j-1)/g
481 ELSE
482 z_at_v = 0.5*(grid%em_phb(i,1,j)+grid%em_phb(i,1,j-1))/g
483 END IF
484
485 p_surf = interp_0( p_in, zk, z_at_v, nl_in )
486
487 DO K = 1, kte
488 p_level = grid%em_znu(k)*(p_surf - grid%p_top) + grid%p_top
489 grid%em_v_1(i,k,j) = interp_0( v, p_in, p_level, nl_in )
490 grid%em_v_2(i,k,j) = grid%em_v_1(i,k,j)
491 ENDDO
492
493 ENDDO
494 ENDDO
495
496 ! interp u
497
498 DO J = jts, min(jde-1,jte)
499 DO I = its, ite
500
501 IF (i == ids) THEN
502 z_at_u = grid%em_phb(i,1,j)/g
503 ELSE IF (i == ide) THEN
504 z_at_u = grid%em_phb(i-1,1,j)/g
505 ELSE
506 z_at_u = 0.5*(grid%em_phb(i,1,j)+grid%em_phb(i-1,1,j))/g
507 END IF
508
509 p_surf = interp_0( p_in, zk, z_at_u, nl_in )
510
511 DO K = 1, kte
512 p_level = grid%em_znu(k)*(p_surf - grid%p_top) + grid%p_top
513 grid%em_u_1(i,k,j) = interp_0( u, p_in, p_level, nl_in )
514 grid%em_u_2(i,k,j) = grid%em_u_1(i,k,j)
515 ENDDO
516
517 ENDDO
518 ENDDO
519
520 ! set w
521
522 DO J = jts, min(jde-1,jte)
523 DO K = kts, kte
524 DO I = its, min(ide-1,ite)
525 grid%em_w_1(i,k,j) = 0.
526 grid%em_w_2(i,k,j) = 0.
527 ENDDO
528 ENDDO
529 ENDDO
530
531 ! set a few more things
532
533 DO J = jts, min(jde-1,jte)
534 DO K = kts, kte-1
535 DO I = its, min(ide-1,ite)
536 grid%h_diabatic(i,k,j) = 0.
537 ENDDO
538 ENDDO
539 ENDDO
540
541 DO k=1,kte-1
542 grid%em_t_base(k) = grid%em_t_1(1,k,1)
543 grid%qv_base(k) = moist(1,k,1,P_QV)
544 grid%u_base(k) = grid%em_u_1(1,k,1)
545 grid%v_base(k) = grid%em_v_1(1,k,1)
546 grid%z_base(k) = 0.5*(grid%em_phb(1,k,1)+grid%em_phb(1,k+1,1)+grid%em_ph_1(1,k,1)+grid%em_ph_1(1,k+1,1))/g
547 ENDDO
548
549 DO J = jts, min(jde-1,jte)
550 DO I = its, min(ide-1,ite)
551 thtmp = grid%em_t_2(i,1,j)+t0
552 ptmp = grid%em_p(i,1,j)+grid%em_pb(i,1,j)
553 temp(1) = thtmp * (ptmp/p1000mb)**rcp
554 thtmp = grid%em_t_2(i,2,j)+t0
555 ptmp = grid%em_p(i,2,j)+grid%em_pb(i,2,j)
556 temp(2) = thtmp * (ptmp/p1000mb)**rcp
557 thtmp = grid%em_t_2(i,3,j)+t0
558 ptmp = grid%em_p(i,3,j)+grid%em_pb(i,3,j)
559 temp(3) = thtmp * (ptmp/p1000mb)**rcp
560
561 grid%tsk(I,J)=grid%cf1*temp(1)+grid%cf2*temp(2)+grid%cf3*temp(3)
562 grid%tmn(I,J)=grid%tsk(I,J)-0.5
563 ENDDO
564 ENDDO
565
566 RETURN
567
568 END SUBROUTINE init_domain_rk
569
570 SUBROUTINE init_module_initialize
571 END SUBROUTINE init_module_initialize
572
573 !---------------------------------------------------------------------
574
575 ! test driver for get_sounding
576 !
577 ! implicit none
578 ! integer n
579 ! parameter(n = 1000)
580 ! real zk(n),p(n),theta(n),rho(n),u(n),v(n),qv(n),pd(n)
581 ! logical dry
582 ! integer nl,k
583 !
584 ! dry = .false.
585 ! dry = .true.
586 ! call get_sounding( zk, p, pd, theta, rho, u, v, qv, dry, n, nl )
587 ! write(6,*) ' input levels ',nl
588 ! write(6,*) ' sounding '
589 ! write(6,*) ' k height(m) press (Pa) pd(Pa) theta (K) den(kg/m^3) u(m/s) v(m/s) qv(g/g) '
590 ! do k=1,nl
591 ! write(6,'(1x,i3,8(1x,1pe10.3))') k, zk(k), p(k), pd(k), theta(k), rho(k), u(k), v(k), qv(k)
592 ! enddo
593 ! end
594 !
595 !---------------------------------------------------------------------------
596
597 subroutine get_sounding( zk, p, p_dry, theta, rho, &
598 u, v, qv, dry, nl_max, nl_in )
599 implicit none
600
601 integer nl_max, nl_in
602 real zk(nl_max), p(nl_max), theta(nl_max), rho(nl_max), &
603 u(nl_max), v(nl_max), qv(nl_max), p_dry(nl_max)
604 logical dry
605
606 integer n
607 parameter(n=1000)
608 logical debug
609 parameter( debug = .true.)
610
611 ! input sounding data
612
613 real p_surf, th_surf, qv_surf
614 real pi_surf, pi(n)
615 real h_input(n), th_input(n), qv_input(n), u_input(n), v_input(n)
616
617 ! diagnostics
618
619 real rho_surf, p_input(n), rho_input(n)
620 real pm_input(n) ! this are for full moist sounding
621
622 ! local data
623
624 real p1000mb,cv,cp,r,cvpm,g
625 parameter (p1000mb = 1.e+05, r = 287, cp = 1003., cv = cp-r, cvpm = -cv/cp, g=9.81 )
626 integer k, it, nl
627 real qvf, qvf1, dz
628
629 ! first, read the sounding
630
631 call read_sounding( p_surf, th_surf, qv_surf, &
632 h_input, th_input, qv_input, u_input, v_input,n, nl, debug )
633
634 if(dry) then
635 do k=1,nl
636 qv_input(k) = 0.
637 enddo
638 endif
639
640 if(debug) write(6,*) ' number of input levels = ',nl
641
642 nl_in = nl
643 if(nl_in .gt. nl_max ) then
644 write(6,*) ' too many levels for input arrays ',nl_in,nl_max
645 call wrf_error_fatal ( ' too many levels for input arrays ' )
646 end if
647
648 ! compute diagnostics,
649 ! first, convert qv(g/kg) to qv(g/g)
650
651 do k=1,nl
652 qv_input(k) = 0.001*qv_input(k)
653 enddo
654
655 p_surf = 100.*p_surf ! convert to pascals
656 qvf = 1. + rvovrd*qv_input(1)
657 rho_surf = 1./((r/p1000mb)*th_surf*qvf*((p_surf/p1000mb)**cvpm))
658 pi_surf = (p_surf/p1000mb)**(r/cp)
659
660 if(debug) then
661 write(6,*) ' surface density is ',rho_surf
662 write(6,*) ' surface pi is ',pi_surf
663 end if
664
665
666 ! integrate moist sounding hydrostatically, starting from the
667 ! specified surface pressure
668 ! -> first, integrate from surface to lowest level
669
670 qvf = 1. + rvovrd*qv_input(1)
671 qvf1 = 1. + qv_input(1)
672 rho_input(1) = rho_surf
673 dz = h_input(1)
674 do it=1,10
675 pm_input(1) = p_surf &
676 - 0.5*dz*(rho_surf+rho_input(1))*g*qvf1
677 rho_input(1) = 1./((r/p1000mb)*th_input(1)*qvf*((pm_input(1)/p1000mb)**cvpm))
678 enddo
679
680 ! integrate up the column
681
682 do k=2,nl
683 rho_input(k) = rho_input(k-1)
684 dz = h_input(k)-h_input(k-1)
685 qvf1 = 0.5*(2.+(qv_input(k-1)+qv_input(k)))
686 qvf = 1. + rvovrd*qv_input(k) ! qv is in g/kg here
687
688 do it=1,10
689 pm_input(k) = pm_input(k-1) &
690 - 0.5*dz*(rho_input(k)+rho_input(k-1))*g*qvf1
691 rho_input(k) = 1./((r/p1000mb)*th_input(k)*qvf*((pm_input(k)/p1000mb)**cvpm))
692 enddo
693 enddo
694
695 ! we have the moist sounding
696
697 ! next, compute the dry sounding using p at the highest level from the
698 ! moist sounding and integrating down.
699
700 p_input(nl) = pm_input(nl)
701
702 do k=nl-1,1,-1
703 dz = h_input(k+1)-h_input(k)
704 p_input(k) = p_input(k+1) + 0.5*dz*(rho_input(k)+rho_input(k+1))*g
705 enddo
706
707
708 do k=1,nl
709
710 zk(k) = h_input(k)
711 p(k) = pm_input(k)
712 p_dry(k) = p_input(k)
713 theta(k) = th_input(k)
714 rho(k) = rho_input(k)
715 u(k) = u_input(k)
716 v(k) = v_input(k)
717 qv(k) = qv_input(k)
718
719 enddo
720
721 if(debug) then
722 write(6,*) ' sounding '
723 write(6,*) ' k height(m) press (Pa) pd(Pa) theta (K) den(kg/m^3) u(m/s) v(m/s) qv(g/g) '
724 do k=1,nl
725 write(6,'(1x,i3,8(1x,1pe10.3))') k, zk(k), p(k), p_dry(k), theta(k), rho(k), u(k), v(k), qv(k)
726 enddo
727
728 end if
729
730 end subroutine get_sounding
731
732 !-------------------------------------------------------
733
734 subroutine read_sounding( ps,ts,qvs,h,th,qv,u,v,n,nl,debug )
735 implicit none
736 integer n,nl
737 real ps,ts,qvs,h(n),th(n),qv(n),u(n),v(n)
738 logical end_of_file
739 logical debug
740
741 integer k
742
743 open(unit=10,file='input_sounding',form='formatted',status='old')
744 rewind(10)
745 read(10,*) ps, ts, qvs
746 if(debug) then
747 write(6,*) ' input sounding surface parameters '
748 write(6,*) ' surface pressure (mb) ',ps
749 write(6,*) ' surface pot. temp (K) ',ts
750 write(6,*) ' surface mixing ratio (g/kg) ',qvs
751 end if
752
753 end_of_file = .false.
754 k = 0
755
756 do while (.not. end_of_file)
757
758 read(10,*,end=100) h(k+1), th(k+1), qv(k+1), u(k+1), v(k+1)
759 k = k+1
760 if(debug) write(6,'(1x,i3,5(1x,e10.3))') k, h(k), th(k), qv(k), u(k), v(k)
761 go to 110
762 100 end_of_file = .true.
763 110 continue
764 enddo
765
766 nl = k
767
768 close(unit=10,status = 'keep')
769
770 end subroutine read_sounding
771
772 END MODULE module_initialize_ideal