source: lmdz_wrf/WRFV3/dyn_em/module_initialize_tropical_cyclone.F @ 1

Last change on this file since 1 was 1, checked in by lfita, 10 years ago
  • -- --- Opening of the WRF+LMDZ coupling repository --- -- -

WRF: version v3.3
LMDZ: version v1818

More details in:

File size: 37.2 KB
Line 
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
16MODULE 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   USE module_soil_pre
27#ifdef DM_PARALLEL
28   USE module_dm
29#endif
30
31
32CONTAINS
33
34
35!-------------------------------------------------------------------
36! this is a wrapper for the solver-specific init_domain routines.
37! Also dereferences the grid variables and passes them down as arguments.
38! This is crucial, since the lower level routines may do message passing
39! and this will get fouled up on machines that insist on passing down
40! copies of assumed-shape arrays (by passing down as arguments, the
41! data are treated as assumed-size -- ie. f77 -- arrays and the copying
42! business is avoided).  Fie on the F90 designers.  Fie and a pox.
43! NOTE:  Modified to remove all but arrays of rank 4 or more from the
44!        argument list.  Arrays with rank>3 are still problematic due to the
45!        above-noted fie- and pox-ities.  TBH 20061129. 
46
47   SUBROUTINE init_domain ( grid )
48
49   IMPLICIT NONE
50
51   !  Input data.
52   TYPE (domain), POINTER :: grid
53   !  Local data.
54   INTEGER :: idum1, idum2
55
56   CALL set_scalar_indices_from_config ( head_grid%id , idum1, idum2 )
57
58     CALL init_domain_rk( grid &
59!
60#include <actual_new_args.inc>
61!
62                        )
63   END SUBROUTINE init_domain
64
65!-------------------------------------------------------------------
66
67   SUBROUTINE init_domain_rk ( grid &
68!
69# include <dummy_new_args.inc>
70!
71)
72   IMPLICIT NONE
73
74   !  Input data.
75   TYPE (domain), POINTER :: grid
76
77# include <dummy_new_decl.inc>
78
79   TYPE (grid_config_rec_type)              :: config_flags
80
81   !  Local data
82   INTEGER                             ::                       &
83                                  ids, ide, jds, jde, kds, kde, &
84                                  ims, ime, jms, jme, kms, kme, &
85                                  its, ite, jts, jte, kts, kte, &
86                                  i, j, k
87
88   INTEGER, PARAMETER :: nl_max = 1000
89   REAL, DIMENSION(nl_max) :: zk, p_in, theta, rho, u, v, qv, pd_in
90   INTEGER :: nl_in
91
92   INTEGER :: icm,jcm, ii, im1, jj, jm1, loop, error, fid, nxc, nyc, lm
93   REAL    :: u_mean,v_mean, f0, p_surf, p_level, qvf, z_at_v, z_at_u
94   REAL    :: z_scale, xrad, yrad, zrad, rad, delt, cof1, cof2
95!   REAL, EXTERNAL :: interp_0
96   REAL    :: pi, rnd
97
98! variables/arrays for analytic vortex:
99    integer :: nref,kref,nloop,i1,i2
100    real :: r0,zdd,dd1,dd2,xref,vr,fcor,qvs,e1,tx,px,qx,ric,rjc,rr,diff,sst
101    real*8 :: rmax,vmax,frac,angle
102    real, dimension(:), allocatable :: rref,zref,th0,qv0,thv0,prs0,pi0,rh0
103    real, dimension(:,:), allocatable :: vref,piref,pref,thref,thvref,qvref
104
105!  stuff from original initialization that has been dropped from the Registry
106   REAL    :: vnu, xnu, xnus, dinit0, cbh, p0_temp, t0_temp, zd, zt
107   REAL    :: qvf1, qvf2, pd_surf
108   INTEGER :: it
109   real :: thtmp, ptmp, temp(3)
110
111   LOGICAL :: moisture_init
112   LOGICAL :: stretch_grid, dry_sounding
113   character (len=256) :: mminlu2
114   
115#ifdef DM_PARALLEL
116#    include <data_calls.inc>
117#endif
118
119
120   SELECT CASE ( model_data_order )
121         CASE ( DATA_ORDER_ZXY )
122   kds = grid%sd31 ; kde = grid%ed31 ;
123   ids = grid%sd32 ; ide = grid%ed32 ;
124   jds = grid%sd33 ; jde = grid%ed33 ;
125
126   kms = grid%sm31 ; kme = grid%em31 ;
127   ims = grid%sm32 ; ime = grid%em32 ;
128   jms = grid%sm33 ; jme = grid%em33 ;
129
130   kts = grid%sp31 ; kte = grid%ep31 ;   ! note that tile is entire patch
131   its = grid%sp32 ; ite = grid%ep32 ;   ! note that tile is entire patch
132   jts = grid%sp33 ; jte = grid%ep33 ;   ! note that tile is entire patch
133         CASE ( DATA_ORDER_XYZ )
134   ids = grid%sd31 ; ide = grid%ed31 ;
135   jds = grid%sd32 ; jde = grid%ed32 ;
136   kds = grid%sd33 ; kde = grid%ed33 ;
137
138   ims = grid%sm31 ; ime = grid%em31 ;
139   jms = grid%sm32 ; jme = grid%em32 ;
140   kms = grid%sm33 ; kme = grid%em33 ;
141
142   its = grid%sp31 ; ite = grid%ep31 ;   ! note that tile is entire patch
143   jts = grid%sp32 ; jte = grid%ep32 ;   ! note that tile is entire patch
144   kts = grid%sp33 ; kte = grid%ep33 ;   ! note that tile is entire patch
145         CASE ( DATA_ORDER_XZY )
146   ids = grid%sd31 ; ide = grid%ed31 ;
147   kds = grid%sd32 ; kde = grid%ed32 ;
148   jds = grid%sd33 ; jde = grid%ed33 ;
149
150   ims = grid%sm31 ; ime = grid%em31 ;
151   kms = grid%sm32 ; kme = grid%em32 ;
152   jms = grid%sm33 ; jme = grid%em33 ;
153
154   its = grid%sp31 ; ite = grid%ep31 ;   ! note that tile is entire patch
155   kts = grid%sp32 ; kte = grid%ep32 ;   ! note that tile is entire patch
156   jts = grid%sp33 ; jte = grid%ep33 ;   ! note that tile is entire patch
157
158   END SELECT
159
160!-----------------------------------------------------------------------
161!               USER SETTINGS
162
163!  Parameters for analytic vortex:
164!  Reference:  Rotunno and Emanuel, 1987, JAS, p. 549
165
166    r0     =   412500.0     ! outer radius (m)
167    rmax   =    82500.0     ! approximate radius of max winds (m)
168    vmax   =       15.0     ! approximate value of max wind speed (m/s)
169    zdd    =    20000.0     ! depth of vortex (m)
170
171
172! other settings:
173
174    fcor   =  5.0e-5        ! Coriolis parameter (1/s)
175    sst    =  28.0          ! sea-surface temperature (Celsius)
176
177!-----------------------------------------------------------------------
178
179   stretch_grid = .true.
180   delt = 6.
181!   z_scale = .50
182   z_scale = .40
183   pi = 2.*asin(1.0)
184   write(6,*) ' pi is ',pi
185   nxc = (ide-ids)/2
186   nyc = jde/2
187   icm = ide/2
188! lm is the half width of the land in terms of grid points
189   lm = 25
190   write(6,*) 'lm,icm-lm,icm+lm = ', lm,icm-lm,icm+lm
191
192   CALL model_to_grid_config_rec ( grid%id , model_config_rec , config_flags )
193
194! here we check to see if the boundary conditions are set properly
195
196   CALL boundary_condition_check( config_flags, bdyzone, error, grid%id )
197
198   moisture_init = .true.
199
200    grid%itimestep=0
201
202#ifdef DM_PARALLEL
203   CALL wrf_dm_bcast_bytes( icm , IWORDSIZE )
204   CALL wrf_dm_bcast_bytes( jcm , IWORDSIZE )
205#endif
206
207    mminlu2 = ' '
208    mminlu2(1:4) = 'USGS'
209    CALL nl_set_mminlu(1, mminlu2)
210!   CALL nl_set_mminlu(1, 'USGS')
211    CALL nl_set_iswater(1,16)
212    CALL nl_set_isice(1,3)
213    CALL nl_set_cen_lat(1,20.)
214    CALL nl_set_cen_lon(1,-105.)
215    CALL nl_set_truelat1(1,0.)
216    CALL nl_set_truelat2(1,0.)
217    CALL nl_set_moad_cen_lat (1,0.)
218    CALL nl_set_stand_lon (1,0.)
219    CALL nl_set_pole_lon (1,0.)
220    CALL nl_set_pole_lat (1,90.)
221    CALL nl_set_map_proj(1,0)
222!   CALL model_to_grid_config_rec(1,model_config_rec,config_flags)
223    CALL nl_get_iswater(1,grid%iswater)
224
225!  here we initialize data that currently is not initialized
226!  in the input data
227
228
229    DO j = jts, jte
230      DO i = its, ite
231         grid%ht(i,j)       = 0.
232         grid%msft(i,j)     = 1.
233         grid%msfu(i,j)     = 1.
234         grid%msfv(i,j)     = 1.
235         grid%msftx(i,j)    = 1.
236         grid%msfty(i,j)    = 1.
237         grid%msfux(i,j)    = 1.
238         grid%msfuy(i,j)    = 1.
239         grid%msfvx(i,j)    = 1.
240         grid%msfvy(i,j)    = 1.
241         grid%msfvx_inv(i,j)= 1.
242         grid%sina(i,j)     = 0.
243         grid%cosa(i,j)     = 1.
244         grid%xlong(i,j)    = 0.0
245         grid%e(i,j)        = 0.0
246         grid%f(i,j)        = fcor
247         grid%xlat(i,j)     = asin(0.5*fcor/EOMEG)/DEGRAD
248! Hard-wire the ocean configuration
249         grid%xland(i,j)     = 2.
250         grid%lu_index(i,j)  = 16
251         grid%tsk(i,j) = 273.15 + sst
252         ! I think tmn is not used for ocean points, but set a value anyway:
253         grid%tmn(i,j) = grid%tsk(i,j) - 10.0
254      END DO
255   END DO
256
257    print *,'   f = ',grid%f(its,jts)
258    print *,'   lat = ',grid%xlat(its,jts)
259
260! for Noah LSM, additional variables need to be initialized
261
262   other_masked_fields : SELECT CASE ( model_config_rec%sf_surface_physics(grid%id) )
263
264      CASE (SLABSCHEME)
265
266      CASE (LSMSCHEME)
267
268        DO j = jts , MIN(jde-1,jte)
269           DO i = its , MIN(ide-1,ite)
270              IF (grid%xland(i,j) .lt. 1.5) THEN
271                 grid%vegfra(i,j) = 0.5
272                 grid%canwat(i,j) = 0.
273                 grid%ivgtyp(i,j) = 18
274                 grid%isltyp(i,j) = 8
275                 grid%xice(i,j) = 0.
276                 grid%snow(i,j) = 0.
277              ELSE
278                 grid%vegfra(i,j) = 0.
279                 grid%canwat(i,j) = 0.
280                 grid%ivgtyp(i,j) = 16
281                 grid%isltyp(i,j) = 14
282                 grid%xice(i,j) = 0.
283                 grid%snow(i,j) = 0.
284              ENDIF
285           END DO
286        END DO
287
288      CASE (RUCLSMSCHEME)
289
290   END SELECT other_masked_fields
291
292   DO j = jts, jte
293    DO k = kts, kte
294      DO i = its, ite
295         grid%ww(i,k,j)     = 0.
296      END DO
297    END DO
298   END DO
299
300   grid%step_number = 0
301
302! Process the soil; note that there are some things hard-wired into share/module_soil_pre.F
303      CALL process_soil_ideal(grid%xland,grid%xice,grid%vegfra,grid%snow,grid%canwat, &
304                     grid%ivgtyp,grid%isltyp,grid%tslb,grid%smois, &
305                     grid%tsk,grid%tmn,grid%zs,grid%dzs,model_config_rec%num_soil_layers, &
306                     model_config_rec%sf_surface_physics(grid%id), &
307                                   ids,ide, jds,jde, kds,kde,&
308                                   ims,ime, jms,jme, kms,kme,&
309                                   its,ite, jts,jte, kts,kte )
310
311! set up the grid
312
313   IF (stretch_grid) THEN ! exponential stretch for eta (nearly constant dz)
314     DO k=1, kde
315      grid%znw(k) = (exp(-(k-1)/float(kde-1)/z_scale) - exp(-1./z_scale))/ &
316                                (1.-exp(-1./z_scale))
317     ENDDO
318   ELSE
319     DO k=1, kde
320      grid%znw(k) = 1. - float(k-1)/float(kde-1)
321     ENDDO
322   ENDIF
323
324   DO k=1, kde-1
325    grid%dnw(k) = grid%znw(k+1) - grid%znw(k)
326    grid%rdnw(k) = 1./grid%dnw(k)
327    grid%znu(k) = 0.5*(grid%znw(k+1)+grid%znw(k))
328   ENDDO
329   DO k=2, kde-1
330    grid%dn(k) = 0.5*(grid%dnw(k)+grid%dnw(k-1))
331    grid%rdn(k) = 1./grid%dn(k)
332    grid%fnp(k) = .5* grid%dnw(k  )/grid%dn(k)
333    grid%fnm(k) = .5* grid%dnw(k-1)/grid%dn(k)
334   ENDDO
335
336   cof1 = (2.*grid%dn(2)+grid%dn(3))/(grid%dn(2)+grid%dn(3))*grid%dnw(1)/grid%dn(2)
337   cof2 =     grid%dn(2)        /(grid%dn(2)+grid%dn(3))*grid%dnw(1)/grid%dn(3)
338   grid%cf1  = grid%fnp(2) + cof1
339   grid%cf2  = grid%fnm(2) - cof1 - cof2
340   grid%cf3  = cof2       
341
342   grid%cfn  = (.5*grid%dnw(kde-1)+grid%dn(kde-1))/grid%dn(kde-1)
343   grid%cfn1 = -.5*grid%dnw(kde-1)/grid%dn(kde-1)
344   grid%rdx = 1./config_flags%dx
345   grid%rdy = 1./config_flags%dy
346
347!  get the sounding from the ascii sounding file, first get dry sounding and
348!  calculate base state
349
350  write(6,*) ' getting dry sounding for base state '
351  dry_sounding = .true.
352  CALL get_sounding( zk, p_in, pd_in, theta, rho, u, v, qv, dry_sounding, nl_max, nl_in )
353
354  write(6,*) ' returned from reading sounding, nl_in is ',nl_in
355
356!  find ptop for the desired ztop (ztop is input from the namelist),
357!  and find surface pressure
358
359  grid%p_top = interp_0( p_in, zk, config_flags%ztop, nl_in )
360
361  DO j=jts,jte
362  DO i=its,ite  ! flat surface
363    grid%phb(i,1,j) = 0.
364    grid%php(i,1,j) = 0.
365    grid%ph0(i,1,j) = 0.
366    grid%ht(i,j) = 0.
367  ENDDO
368  ENDDO
369
370  DO J = jts, jte
371  DO I = its, ite
372
373    p_surf = interp_0( p_in, zk, grid%phb(i,1,j)/g, nl_in )
374    grid%mub(i,j) = p_surf-grid%p_top
375
376!  this is dry hydrostatic sounding (base state), so given grid%p (coordinate),
377!  interp theta (from interp) and compute 1/rho from eqn. of state
378
379    DO K = 1, kte-1
380      p_level = grid%znu(k)*(p_surf - grid%p_top) + grid%p_top
381      grid%pb(i,k,j) = p_level
382      grid%t_init(i,k,j) = interp_0( theta, p_in, p_level, nl_in ) - t0
383      grid%alb(i,k,j) = (r_d/p1000mb)*(grid%t_init(i,k,j)+t0)*(grid%pb(i,k,j)/p1000mb)**cvpm
384    ENDDO
385
386!  calc hydrostatic balance (alternatively we could interp the geopotential from the
387!  sounding, but this assures that the base state is in exact hydrostatic balance with
388!  respect to the model eqns.
389
390    DO k  = 2,kte
391      grid%phb(i,k,j) = grid%phb(i,k-1,j) - grid%dnw(k-1)*grid%mub(i,j)*grid%alb(i,k-1,j)
392    ENDDO
393
394  ENDDO
395  ENDDO
396
397  write(6,*) ' ptop is ',grid%p_top
398  write(6,*) ' base state grid%mub(1,1), p_surf is ',grid%mub(1,1),grid%mub(1,1)+grid%p_top
399
400!  calculate full state for each column - this includes moisture.
401
402  write(6,*) ' getting moist sounding for full state '
403  dry_sounding = .false.
404  CALL get_sounding( zk, p_in, pd_in, theta, rho, u, v, qv, dry_sounding, nl_max, nl_in )
405
406  DO J = jts, min(jde-1,jte)
407  DO I = its, min(ide-1,ite)
408
409!  At this point grid%p_top is already set. find the DRY mass in the column
410!  by interpolating the DRY pressure. 
411
412   pd_surf = interp_0( pd_in, zk, grid%phb(i,1,j)/g, nl_in )
413
414!  compute the perturbation mass and the full mass
415
416    grid%mu_1(i,j) = pd_surf-grid%p_top - grid%mub(i,j)
417    grid%mu_2(i,j) = grid%mu_1(i,j)
418    grid%mu0(i,j) = grid%mu_1(i,j) + grid%mub(i,j)
419
420! given the dry pressure and coordinate system, interp the potential
421! temperature and qv
422
423    do k=1,kde-1
424
425      p_level = grid%znu(k)*(pd_surf - grid%p_top) + grid%p_top
426
427      moist(i,k,j,P_QV) = interp_0( qv, pd_in, p_level, nl_in )
428      grid%t_1(i,k,j)          = interp_0( theta, pd_in, p_level, nl_in ) - t0
429      grid%t_2(i,k,j)          = grid%t_1(i,k,j)
430     
431
432    enddo
433
434!  integrate the hydrostatic equation (from the RHS of the bigstep
435!  vertical momentum equation) down from the top to get grid%p.
436!  first from the top of the model to the top pressure
437
438    k = kte-1  ! top level
439
440    qvf1 = 0.5*(moist(i,k,j,P_QV)+moist(i,k,j,P_QV))
441    qvf2 = 1./(1.+qvf1)
442    qvf1 = qvf1*qvf2
443
444!    grid%p(i,k,j) = - 0.5*grid%mu_1(i,j)/grid%rdnw(k)
445    grid%p(i,k,j) = - 0.5*(grid%mu_1(i,j)+qvf1*grid%mub(i,j))/grid%rdnw(k)/qvf2
446    qvf = 1. + rvovrd*moist(i,k,j,P_QV)
447    grid%alt(i,k,j) = (r_d/p1000mb)*(grid%t_1(i,k,j)+t0)*qvf* &
448                (((grid%p(i,k,j)+grid%pb(i,k,j))/p1000mb)**cvpm)
449    grid%al(i,k,j) = grid%alt(i,k,j) - grid%alb(i,k,j)
450
451!  down the column
452
453    do k=kte-2,1,-1
454      qvf1 = 0.5*(moist(i,k,j,P_QV)+moist(i,k+1,j,P_QV))
455      qvf2 = 1./(1.+qvf1)
456      qvf1 = qvf1*qvf2
457      grid%p(i,k,j) = grid%p(i,k+1,j) - (grid%mu_1(i,j) + qvf1*grid%mub(i,j))/qvf2/grid%rdn(k+1)
458      qvf = 1. + rvovrd*moist(i,k,j,P_QV)
459      grid%alt(i,k,j) = (r_d/p1000mb)*(grid%t_1(i,k,j)+t0)*qvf* &
460                  (((grid%p(i,k,j)+grid%pb(i,k,j))/p1000mb)**cvpm)
461      grid%al(i,k,j) = grid%alt(i,k,j) - grid%alb(i,k,j)
462    enddo
463
464!  this is the hydrostatic equation used in the model after the
465!  small timesteps.  In the model, grid%al (inverse density)
466!  is computed from the geopotential.
467
468
469    grid%ph_1(i,1,j) = 0.
470    DO k  = 2,kte
471      grid%ph_1(i,k,j) = grid%ph_1(i,k-1,j) - (1./grid%rdnw(k-1))*(       &
472                   (grid%mub(i,j)+grid%mu_1(i,j))*grid%al(i,k-1,j)+ &
473                    grid%mu_1(i,j)*grid%alb(i,k-1,j)  )
474                                                   
475      grid%ph_2(i,k,j) = grid%ph_1(i,k,j)
476      grid%ph0(i,k,j) = grid%ph_1(i,k,j) + grid%phb(i,k,j)
477    ENDDO
478
479    if((i==2) .and. (j==2)) then
480     write(6,*) ' grid%ph_1 calc ',grid%ph_1(2,1,2),grid%ph_1(2,2,2),&
481                              grid%mu_1(2,2)+grid%mub(2,2),grid%mu_1(2,2), &
482                              grid%alb(2,1,2),grid%al(1,2,1),grid%rdnw(1)
483    endif
484
485  ENDDO
486  ENDDO
487
488!-----------------------------------------------------------------------
489!  Analytic vortex.
490!  Reference:  Rotunno and Emanuel, 1987, JAS, p. 549
491
492    dd2 = 2.0 * rmax / ( r0 + rmax )
493
494    nref = 1 + int( float(ide-ids+1)/2.0 )
495    kref = kte-1
496
497    print *,'  ids,ide,kds,kds  = ',ids,ide,kds,kde
498    print *,'  its,ite,kts,kts  = ',its,ite,kts,kte
499    print *,'  nref,fcor        = ',nref,fcor
500    print *,'  r0,rmax,vmax,zdd = ',r0,rmax,vmax,zdd
501
502    allocate(  rref(nref)         )
503    allocate(  zref(0:kref+1)     )
504    allocate(   th0(0:kref+1)     )
505    allocate(   qv0(0:kref+1)     )
506    allocate(  thv0(0:kref+1)     )
507    allocate(  prs0(0:kref+1)     )
508    allocate(   pi0(0:kref+1)     )
509    allocate(   rh0(0:kref+1)     )
510    allocate(  vref(nref,0:kref+1))
511    allocate( piref(nref,0:kref+1))
512    allocate(  pref(nref,0:kref+1))
513    allocate( thref(nref,0:kref+1))
514    allocate(thvref(nref,0:kref+1))
515    allocate( qvref(nref,0:kref+1))
516
517    ! get base state:
518    print *,'  zref,th0,qv0,thv0:'
519    do k=1,kref
520      th0(k) = t0+grid%t_1(1,k,1)
521      qv0(k) = moist(1,k,1,P_QV)
522      thv0(k) = th0(k)*(1.0+(r_v/r_d)*qv0(k))/(1.0+qv0(k))
523      zref(k) = 0.5*(grid%phb(1,k,1)+grid%phb(1,k+1,1)+grid%ph_1(1,k,1)+grid%ph_1(1,k+1,1))/g
524      print *,k,zref(k),th0(k),qv0(k),thv0(k)
525    enddo
526
527    print *,'  prs0,pi0,rh0:'
528    do k=1,kref
529      prs0(k) = grid%p(1,k,1)+grid%pb(1,k,1)
530      pi0(k) = (prs0(k)/p0)**(r_d/cp)
531      E1=1000.0*SVP1*EXP(SVP2*(th0(k)*pi0(k)-SVPT0)/(th0(k)*pi0(k)-SVP3))
532      qvs = EP_2*E1/(prs0(k)-E1)
533      rh0(k) = qv0(k)/qvs
534      print *,k,prs0(k),pi0(k),rh0(k)
535    enddo
536
537    zref(0) = -zref(1)
538    zref(kref+1) = zref(kref)+(zref(kref)-zref(kref-1))
539
540      rref=0.0
541      vref=0.0
542     piref=0.0
543      pref=0.0
544     thref=0.0
545    thvref=0.0
546     qvref=0.0
547
548    do i=1,nref
549      rref(i) = config_flags%dx*(float(i-1)+0.5)
550    enddo
551
552    print *,'  zref:'
553    do k=0,kref+1
554      print *,k,zref(k)
555    enddo
556
557    print *,'  vref:'
558    do k=1,kref
559      do i=1,nref
560        if(rref(i).lt.r0)then
561          dd1 = 2.0 * rmax / ( rref(i) + rmax )
562          vr = sqrt( vmax**2 * (rref(i)/rmax)**2     &
563          * ( dd1 ** 3 - dd2 ** 3 ) + 0.25*fcor*fcor*rref(i)*rref(i) )   &
564                  - 0.5 * fcor * rref(i)
565        else
566          vr = 0.0
567        endif
568        if(zref(k).lt.zdd)then
569          vref(i,k) = vr * (zdd-zref(k))/(zdd-0.0)
570        else
571          vref(i,k) = 0.0
572        endif
573        if(k.eq.1) print *,i,rref(i),vref(i,k)
574      enddo
575    enddo
576
577    print *,'  Iterate:'
578    DO nloop=1,20
579
580      ! get qv and thv from rh and th:
581      do k=1,kref
582      do i=1,nref
583        tx = (pi0(k)+piref(i,k))*(th0(k)+thref(i,k))
584        px = p0*((pi0(k)+piref(i,k))**(cp/r_d))
585        E1 = 1000.0*SVP1*EXP(SVP2*(tx-SVPT0)/(tx-SVP3))
586        qvs = EP_2*E1/(px-E1)
587        qvref(i,k) = rh0(k)*qvs
588        thvref(i,k)=(th0(k)+thref(i,k))*(1.0+(r_v/r_d)*qvref(i,k))   &
589                                           /(1.0+qvref(i,k))
590      enddo
591      enddo
592
593      ! get nondimensional pressure perturbation (piref):
594      do k=1,kref
595        piref(nref,k)=0.0
596        do i=nref,2,-1
597          piref(i-1,k) = piref(i,k)                                       &
598       + (rref(i-1)-rref(i))/(cp*0.5*(thvref(i-1,k)+thvref(i,k))) * 0.5 * &
599           ( vref(i  ,k)*vref(i  ,k)/rref(i)                              &
600            +vref(i-1,k)*vref(i-1,k)/rref(i-1)                            &
601             + fcor * ( vref(i,k) + vref(i-1,k) ) )
602        enddo
603      enddo
604
605      do i=1,nref
606        piref(i,   0) = piref(i, 1)
607        piref(i,kref+1) = piref(i,kref)
608      enddo
609
610      ! get potential temperature perturbation (thref):
611      do k=2,kref
612      do i=1,nref
613        thref(i,k) = 0.5*( cp*0.5*(thvref(i,k)+thvref(i,k+1))*(piref(i,k+1)-piref(i,k))/(zref(k+1)-zref(k))     &
614                          +cp*0.5*(thvref(i,k)+thvref(i,k-1))*(piref(i,k)-piref(i,k-1))/(zref(k)-zref(k-1)) )   &
615                        *thv0(k)/g
616        thref(i,k)=(thv0(k)+thref(i,k))*(1.0+qvref(i,k))/(1.0+(r_v/r_d)*qvref(i,k))-th0(k)
617      enddo
618      enddo
619
620      k=1
621      do i=1,nref
622        thref(i,k) = ( cp*0.5*(thvref(i,k)+thvref(i,k+1))*(piref(i,k+1)-piref(i,k))/(zref(k+1)-zref(k)) )   &
623                        *thv0(k)/g
624        thref(i,k)=(thv0(k)+thref(i,k))*(1.0+qvref(i,k))/(1.0+(r_v/r_d)*qvref(i,k))-th0(k)
625      enddo
626
627      print *,'  th,qv,pi = ',nloop,thref(1,1),qvref(1,1),piref(1,1)
628
629    ENDDO   ! enddo for iteration
630
631    ! reference (total) pressure:
632    do k=1,kref
633    do i=1,nref
634      pref(i,k) = p0*( ( pi0(k)+piref(i1,k)+(piref(i2,k)-piref(i1,k))*frac )**(cp/r_d) )
635    enddo
636    enddo
637
638    ! analytic axisymmetric vortex is ready ... now interpolate to 3D grid:
639    ! (note:  vortex is placed in center of domain)
640
641    ric = float(ide-ids+1)/2.0
642    rjc = float(jde-jds+1)/2.0
643
644    print *,'  ids,ide,jds,jde = ',ids,ide,jds,jde
645    print *,'  ric,rjc = ',ric,rjc
646
647    print *,'  zk:'
648    do k=1,kte
649      zk(k) = zref(k)
650      print *,k,zk(k)
651    enddo
652
653    nl_in = kte-1
654    print *,'  nl_in = ',nl_in
655
656    DO J = jts, min(jde-1,jte)
657    DO I = its, min(ide-1,ite)
658      rr = sqrt( ( (float(i)-ric)*config_flags%dx )**2 + ( (float(j)-rjc)*config_flags%dy )**2 )
659      rr = min( rr , rref(nref) )
660            diff = -1.0e20
661            ii = 0
662            do while( diff.lt.0.0 )
663              ii = ii + 1
664              diff = rref(ii)-rr
665            enddo
666            i2 = max( ii , 2 )
667            i1 = i2-1
668            frac = (      rr-rref(i1))   &
669                  /(rref(i2)-rref(i1))
670            do k=1,kte
671              px = p0*( ( pi0(k)+piref(i1,k)+(piref(i2,k)-piref(i1,k))*frac )**(cp/r_d) )
672              qx = qvref(i1,k)+(qvref(i2,k)-qvref(i1,k))*frac
673              qv(k) = qx
674              theta(k) = th0(k)+thref(i1,k)+(thref(i2,k)-thref(i1,k))*frac
675              pd_in(k) = px/(1.0+((r_v/r_d)*qx))
676            enddo
677
678!  At this point grid%p_top is already set. find the DRY mass in the column
679!  by interpolating the DRY pressure. 
680
681   pd_surf = interp_0( pd_in, zk, grid%phb(i,1,j)/g, nl_in )
682
683!  compute the perturbation mass and the full mass
684
685    grid%mu_1(i,j) = pd_surf-grid%p_top - grid%mub(i,j)
686    grid%mu_2(i,j) = grid%mu_1(i,j)
687    grid%mu0(i,j) = grid%mu_1(i,j) + grid%mub(i,j)
688
689! given the dry pressure and coordinate system, interp the potential
690! temperature and qv
691
692    do k=1,kde-1
693
694      p_level = grid%znu(k)*(pd_surf - grid%p_top) + grid%p_top
695
696      moist(i,k,j,P_QV) = interp_0( qv, pd_in, p_level, nl_in )
697      grid%t_1(i,k,j)          = interp_0( theta, pd_in, p_level, nl_in ) - t0
698      grid%t_2(i,k,j)          = grid%t_1(i,k,j)
699     
700
701    enddo
702
703
704
705!  integrate the hydrostatic equation (from the RHS of the bigstep
706!  vertical momentum equation) down from the top to get grid%p.
707!  first from the top of the model to the top pressure
708
709    k = kte-1  ! top level
710
711    qvf1 = 0.5*(moist(i,k,j,P_QV)+moist(i,k,j,P_QV))
712    qvf2 = 1./(1.+qvf1)
713    qvf1 = qvf1*qvf2
714
715!    grid%p(i,k,j) = - 0.5*grid%mu_1(i,j)/grid%rdnw(k)
716    grid%p(i,k,j) = - 0.5*(grid%mu_1(i,j)+qvf1*grid%mub(i,j))/grid%rdnw(k)/qvf2
717    qvf = 1. + rvovrd*moist(i,k,j,P_QV)
718    grid%alt(i,k,j) = (r_d/p1000mb)*(grid%t_1(i,k,j)+t0)*qvf* &
719                (((grid%p(i,k,j)+grid%pb(i,k,j))/p1000mb)**cvpm)
720    grid%al(i,k,j) = grid%alt(i,k,j) - grid%alb(i,k,j)
721
722!  down the column
723
724    do k=kte-2,1,-1
725      qvf1 = 0.5*(moist(i,k,j,P_QV)+moist(i,k+1,j,P_QV))
726      qvf2 = 1./(1.+qvf1)
727      qvf1 = qvf1*qvf2
728      grid%p(i,k,j) = grid%p(i,k+1,j) - (grid%mu_1(i,j) + qvf1*grid%mub(i,j))/qvf2/grid%rdn(k+1)
729      qvf = 1. + rvovrd*moist(i,k,j,P_QV)
730      grid%alt(i,k,j) = (r_d/p1000mb)*(grid%t_1(i,k,j)+t0)*qvf* &
731                  (((grid%p(i,k,j)+grid%pb(i,k,j))/p1000mb)**cvpm)
732      grid%al(i,k,j) = grid%alt(i,k,j) - grid%alb(i,k,j)
733    enddo
734
735!  this is the hydrostatic equation used in the model after the
736!  small timesteps.  In the model, grid%al (inverse density)
737!  is computed from the geopotential.
738
739
740    grid%ph_1(i,1,j) = 0.
741    DO k  = 2,kte
742      grid%ph_1(i,k,j) = grid%ph_1(i,k-1,j) - (1./grid%rdnw(k-1))*(       &
743                   (grid%mub(i,j)+grid%mu_1(i,j))*grid%al(i,k-1,j)+ &
744                    grid%mu_1(i,j)*grid%alb(i,k-1,j)  )
745                                                   
746      grid%ph_2(i,k,j) = grid%ph_1(i,k,j)
747      grid%ph0(i,k,j) = grid%ph_1(i,k,j) + grid%phb(i,k,j)
748    ENDDO
749
750    ENDDO   ! do loop for i
751    ENDDO   ! do loop for j
752
753!-------------------------------------------
754! Done with mass fields, now get winds:
755
756! interp v
757
758  DO J = jts, jte
759  DO I = its, min(ide-1,ite)
760
761      rr = sqrt( ( (float(i)-ric)*config_flags%dx )**2 + ( (float(j)-0.5-rjc)*config_flags%dy )**2 )
762      rr = min( rr , rref(nref) )
763            diff = -1.0e20
764            ii = 0
765            do while( diff.lt.0.0 )
766              ii = ii + 1
767              diff = rref(ii)-rr
768            enddo
769            i2 = max( ii , 2 )
770            i1 = i2-1
771            frac = (      rr-rref(i1))   &
772                  /(rref(i2)-rref(i1))
773            angle = datan2(dble( (float(j)-0.5-rjc)*config_flags%dy ),   &
774                           dble( (float(i)-ric)*config_flags%dx ) )
775            do k=1,kte
776              v(k) = (vref(i1,k)+( vref(i2,k)- vref(i1,k))*frac )*cos(angle)
777              p_in(k) = pref(i1,k)+(pref(i2,k)-pref(i1,k))*frac
778            enddo
779
780    IF (j == jds) THEN
781      z_at_v = grid%phb(i,1,j)/g
782    ELSE IF (j == jde) THEN
783      z_at_v = grid%phb(i,1,j-1)/g
784    ELSE
785      z_at_v = 0.5*(grid%phb(i,1,j)+grid%phb(i,1,j-1))/g
786    END IF
787
788    p_surf = interp_0( p_in, zk, z_at_v, nl_in )
789
790    DO K = 1, kte
791      p_level = grid%znu(k)*(p_surf - grid%p_top) + grid%p_top
792      grid%v_1(i,k,j) = interp_0( v, p_in, p_level, nl_in )
793      grid%v_2(i,k,j) = grid%v_1(i,k,j)
794    ENDDO
795
796  ENDDO
797  ENDDO
798
799! interp u
800
801  DO J = jts, min(jde-1,jte)
802  DO I = its, ite
803
804      rr = sqrt( ( (float(i)-ric-0.5)*config_flags%dx )**2 + ( (float(j)-rjc)*config_flags%dy )**2 )
805      rr = min( rr , rref(nref) )
806            diff = -1.0e20
807            ii = 0
808            do while( diff.lt.0.0 )
809              ii = ii + 1
810              diff = rref(ii)-rr
811            enddo
812            i2 = max( ii , 2 )
813            i1 = i2-1
814            frac = (      rr-rref(i1))   &
815                  /(rref(i2)-rref(i1))
816            angle = datan2(dble( (float(j)-rjc)*config_flags%dy ),   &
817                           dble( (float(i)-0.5-ric)*config_flags%dx ) )
818            do k=1,kte
819              u(k) = -(vref(i1,k)+( vref(i2,k)- vref(i1,k))*frac )*sin(angle)
820              p_in(k) = pref(i1,k)+(pref(i2,k)-pref(i1,k))*frac
821            enddo
822
823    IF (i == ids) THEN
824      z_at_u = grid%phb(i,1,j)/g
825    ELSE IF (i == ide) THEN
826      z_at_u = grid%phb(i-1,1,j)/g
827    ELSE
828      z_at_u = 0.5*(grid%phb(i,1,j)+grid%phb(i-1,1,j))/g
829    END IF
830
831    p_surf = interp_0( p_in, zk, z_at_u, nl_in )
832
833    DO K = 1, kte
834      p_level = grid%znu(k)*(p_surf - grid%p_top) + grid%p_top
835      grid%u_1(i,k,j) = interp_0( u, p_in, p_level, nl_in )
836      grid%u_2(i,k,j) = grid%u_1(i,k,j)
837    ENDDO
838
839  ENDDO
840  ENDDO
841
842    ! All done ... deallocate arrays:
843
844    deallocate(  rref )
845    deallocate(  zref )
846    deallocate(   th0 )
847    deallocate(   qv0 )
848    deallocate(  thv0 )
849    deallocate(  prs0 )
850    deallocate(   pi0 )
851    deallocate(   rh0 )
852    deallocate(  vref )
853    deallocate( piref )
854    deallocate(  pref )
855    deallocate( thref )
856    deallocate(thvref )
857    deallocate( qvref )
858
859    print *,'  completed vortex init successfully '
860
861!-----------------------------------------------------------------------
862
863   if (0.gt.1) then
864!#if 0
865!  The tropical_cyclone case is adapted from the squall line case
866!  so we just turn off the thermal perturbation
867
868!  thermal perturbation to kick off convection
869        call random_seed
870  write(6,*) ' nxc, nyc for perturbation ',nxc,nyc
871  write(6,*) ' delt for perturbation ',delt
872
873  DO J = jts, min(jde-1,jte)
874!    yrad = config_flags%dy*float(j-nyc)/4000.
875     yrad = 0.
876    DO I = its, min(ide-1,ite)
877      xrad = config_flags%dx*float(i-nxc)/10000.
878!     xrad = 0.
879      DO K = 1, 35
880
881!  put in preturbation theta (bubble) and recalc density.  note,
882!  the mass in the column is not changing, so when theta changes,
883!  we recompute density and geopotential
884        zrad = 0.5*(grid%ph_1(i,k,j)+grid%ph_1(i,k+1,j)  &
885                   +grid%phb(i,k,j)+grid%phb(i,k+1,j))/g
886        zrad = (zrad-1500.)/1500.
887        RAD=SQRT(xrad*xrad+yrad*yrad+zrad*zrad)
888!        IF(RAD <= 1.) THEN
889        call RANDOM_NUMBER(rnd)
890          grid%t_1(i,k,j)=grid%t_1(i,k,j)+delt*(rnd-0.5)
891         !  grid%t_1(i,k,j)=grid%t_1(i,k,j)+delt*COS(.5*PI*RAD)**2
892           grid%t_2(i,k,j)=grid%t_1(i,k,j)
893           qvf = 1. + rvovrd*moist(i,k,j,P_QV)
894           grid%alt(i,k,j) = (r_d/p1000mb)*(grid%t_1(i,k,j)+t0)*qvf* &
895                        (((grid%p(i,k,j)+grid%pb(i,k,j))/p1000mb)**cvpm)
896           grid%al(i,k,j) = grid%alt(i,k,j) - grid%alb(i,k,j)
897!        ENDIF
898      ENDDO
899
900!  rebalance hydrostatically
901
902      DO k  = 2,kte
903        grid%ph_1(i,k,j) = grid%ph_1(i,k-1,j) - (1./grid%rdnw(k-1))*(       &
904                     (grid%mub(i,j)+grid%mu_1(i,j))*grid%al(i,k-1,j)+ &
905                      grid%mu_1(i,j)*grid%alb(i,k-1,j)  )
906                                                   
907        grid%ph_2(i,k,j) = grid%ph_1(i,k,j)
908        grid%ph0(i,k,j) = grid%ph_1(i,k,j) + grid%phb(i,k,j)
909      ENDDO
910
911    ENDDO
912  ENDDO
913        endif
914!#endif
915
916   write(6,*) ' grid%mu_1 from comp ', grid%mu_1(1,1)
917   write(6,*) ' full state sounding from comp, ph, grid%p, grid%al, grid%t_1, qv '
918   do k=1,kde-1
919     write(6,'(i3,1x,5(1x,1pe10.3))') k, grid%ph_1(1,k,1)+grid%phb(1,k,1), &
920                                      grid%p(1,k,1)+grid%pb(1,k,1), grid%alt(1,k,1), &
921                                      grid%t_1(1,k,1)+t0, moist(1,k,1,P_QV)
922   enddo
923
924   write(6,*) ' pert state sounding from comp, grid%ph_1, pp, alp, grid%t_1, qv '
925   do k=1,kde-1
926     write(6,'(i3,1x,5(1x,1pe10.3))') k, grid%ph_1(1,k,1), &
927                                      grid%p(1,k,1), grid%al(1,k,1), &
928                                      grid%t_1(1,k,1), moist(1,k,1,P_QV)
929   enddo
930
931!! interp v
932!
933!  DO J = jts, jte
934!  DO I = its, min(ide-1,ite)
935!
936!    IF (j == jds) THEN
937!      z_at_v = grid%phb(i,1,j)/g
938!    ELSE IF (j == jde) THEN
939!      z_at_v = grid%phb(i,1,j-1)/g
940!    ELSE
941!      z_at_v = 0.5*(grid%phb(i,1,j)+grid%phb(i,1,j-1))/g
942!    END IF
943!
944!    p_surf = interp_0( p_in, zk, z_at_v, nl_in )
945!
946!    DO K = 1, kte
947!      p_level = grid%znu(k)*(p_surf - grid%p_top) + grid%p_top
948!      grid%v_1(i,k,j) = interp_0( v, p_in, p_level, nl_in )
949!      grid%v_2(i,k,j) = grid%v_1(i,k,j)
950!    ENDDO
951!
952!  ENDDO
953!  ENDDO
954!
955!! interp u
956!
957!  DO J = jts, min(jde-1,jte)
958!  DO I = its, ite
959!
960!    IF (i == ids) THEN
961!      z_at_u = grid%phb(i,1,j)/g
962!    ELSE IF (i == ide) THEN
963!      z_at_u = grid%phb(i-1,1,j)/g
964!    ELSE
965!      z_at_u = 0.5*(grid%phb(i,1,j)+grid%phb(i-1,1,j))/g
966!    END IF
967!
968!    p_surf = interp_0( p_in, zk, z_at_u, nl_in )
969!
970!    DO K = 1, kte
971!      p_level = grid%znu(k)*(p_surf - grid%p_top) + grid%p_top
972!      grid%u_1(i,k,j) = interp_0( u, p_in, p_level, nl_in )
973!      grid%u_2(i,k,j) = grid%u_1(i,k,j)
974!    ENDDO
975!
976!  ENDDO
977!  ENDDO
978
979!  set w
980
981  DO J = jts, min(jde-1,jte)
982  DO K = kts, kte
983  DO I = its, min(ide-1,ite)
984    grid%w_1(i,k,j) = 0.
985    grid%w_2(i,k,j) = 0.
986  ENDDO
987  ENDDO
988  ENDDO
989
990!  set a few more things
991
992  DO J = jts, min(jde-1,jte)
993  DO K = kts, kte-1
994  DO I = its, min(ide-1,ite)
995    grid%h_diabatic(i,k,j) = 0.
996  ENDDO
997  ENDDO
998  ENDDO
999
1000  DO k=1,kte-1
1001    grid%t_base(k) = grid%t_1(1,k,1)
1002    grid%qv_base(k) = moist(1,k,1,P_QV)
1003    grid%u_base(k) = grid%u_1(1,k,1)
1004    grid%v_base(k) = grid%v_1(1,k,1)
1005    grid%z_base(k) = 0.5*(grid%phb(1,k,1)+grid%phb(1,k+1,1)+grid%ph_1(1,k,1)+grid%ph_1(1,k+1,1))/g
1006  ENDDO
1007
1008  DO J = jts, min(jde-1,jte)
1009  DO I = its, min(ide-1,ite)
1010     thtmp   = grid%t_2(i,1,j)+t0
1011     ptmp    = grid%p(i,1,j)+grid%pb(i,1,j)
1012     temp(1) = thtmp * (ptmp/p1000mb)**rcp
1013     thtmp   = grid%t_2(i,2,j)+t0
1014     ptmp    = grid%p(i,2,j)+grid%pb(i,2,j)
1015     temp(2) = thtmp * (ptmp/p1000mb)**rcp
1016     thtmp   = grid%t_2(i,3,j)+t0
1017     ptmp    = grid%p(i,3,j)+grid%pb(i,3,j)
1018     temp(3) = thtmp * (ptmp/p1000mb)**rcp
1019
1020!     grid%tsk(I,J)=grid%cf1*temp(1)+grid%cf2*temp(2)+grid%cf3*temp(3)
1021     ! I don't know why this is here, so I have commented it out:
1022!!!     grid%tmn(I,J)=grid%tsk(I,J)-0.5
1023  ENDDO
1024  ENDDO
1025
1026  RETURN
1027
1028 END SUBROUTINE init_domain_rk
1029
1030   SUBROUTINE init_module_initialize
1031   END SUBROUTINE init_module_initialize
1032
1033!---------------------------------------------------------------------
1034
1035!  test driver for get_sounding
1036!
1037!      implicit none
1038!      integer n
1039!      parameter(n = 1000)
1040!      real zk(n),p(n),theta(n),rho(n),u(n),v(n),qv(n),pd(n)
1041!      logical dry
1042!      integer nl,k
1043!
1044!      dry = .false.
1045!      dry = .true.
1046!      call get_sounding( zk, p, pd, theta, rho, u, v, qv, dry, n, nl )
1047!      write(6,*) ' input levels ',nl
1048!      write(6,*) ' sounding '
1049!      write(6,*) '  k  height(m)  press (Pa) pd(Pa) theta (K) den(kg/m^3)  u(m/s)     v(m/s)    qv(g/g) '
1050!      do k=1,nl
1051!        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)
1052!      enddo
1053!      end
1054!
1055!---------------------------------------------------------------------------
1056
1057      subroutine get_sounding( zk, p, p_dry, theta, rho, &
1058                               u, v, qv, dry, nl_max, nl_in )
1059      implicit none
1060
1061      integer nl_max, nl_in
1062      real zk(nl_max), p(nl_max), theta(nl_max), rho(nl_max), &
1063           u(nl_max), v(nl_max), qv(nl_max), p_dry(nl_max)
1064      logical dry
1065
1066      integer n
1067      parameter(n=3000)
1068      logical debug
1069      parameter( debug = .true.)
1070
1071! input sounding data
1072
1073      real p_surf, th_surf, qv_surf
1074      real pi_surf, pi(n)
1075      real h_input(n), th_input(n), qv_input(n), u_input(n), v_input(n)
1076
1077! diagnostics
1078
1079      real rho_surf, p_input(n), rho_input(n)
1080      real pm_input(n)  !  this are for full moist sounding
1081
1082! local data
1083
1084      real r
1085      parameter (r = r_d)
1086      integer k, it, nl
1087      real qvf, qvf1, dz
1088
1089!  first, read the sounding
1090
1091      call read_sounding( p_surf, th_surf, qv_surf, &
1092                          h_input, th_input, qv_input, u_input, v_input,n, nl, debug )
1093
1094      if(dry) then
1095       do k=1,nl
1096         qv_input(k) = 0.
1097       enddo
1098      endif
1099
1100      if(debug) write(6,*) ' number of input levels = ',nl
1101
1102        nl_in = nl
1103        if(nl_in .gt. nl_max ) then
1104          write(6,*) ' too many levels for input arrays ',nl_in,nl_max
1105          call wrf_error_fatal ( ' too many levels for input arrays ' )
1106        end if
1107
1108!  compute diagnostics,
1109!  first, convert qv(g/kg) to qv(g/g)
1110
1111      do k=1,nl
1112        qv_input(k) = 0.001*qv_input(k)
1113      enddo
1114
1115      p_surf = 100.*p_surf  ! convert to pascals
1116      qvf = 1. + rvovrd*qv_input(1)
1117      rho_surf = 1./((r/p1000mb)*th_surf*qvf*((p_surf/p1000mb)**cvpm))
1118      pi_surf = (p_surf/p1000mb)**(r/cp)
1119
1120      if(debug) then
1121        write(6,*) ' surface density is ',rho_surf
1122        write(6,*) ' surface pi is      ',pi_surf
1123      end if
1124
1125
1126!  integrate moist sounding hydrostatically, starting from the
1127!  specified surface pressure
1128!  -> first, integrate from surface to lowest level
1129
1130          qvf = 1. + rvovrd*qv_input(1)
1131          qvf1 = 1. + qv_input(1)
1132          rho_input(1) = rho_surf
1133          dz = h_input(1)
1134          do it=1,10
1135            pm_input(1) = p_surf &
1136                    - 0.5*dz*(rho_surf+rho_input(1))*g*qvf1
1137            rho_input(1) = 1./((r/p1000mb)*th_input(1)*qvf*((pm_input(1)/p1000mb)**cvpm))
1138          enddo
1139
1140! integrate up the column
1141
1142          do k=2,nl
1143            rho_input(k) = rho_input(k-1)
1144            dz = h_input(k)-h_input(k-1)
1145            qvf1 = 0.5*(2.+(qv_input(k-1)+qv_input(k)))
1146            qvf = 1. + rvovrd*qv_input(k)   ! qv is in g/kg here
1147 
1148            do it=1,10
1149              pm_input(k) = pm_input(k-1) &
1150                      - 0.5*dz*(rho_input(k)+rho_input(k-1))*g*qvf1
1151              rho_input(k) = 1./((r/p1000mb)*th_input(k)*qvf*((pm_input(k)/p1000mb)**cvpm))
1152            enddo
1153          enddo
1154
1155!  we have the moist sounding
1156
1157!  next, compute the dry sounding using p at the highest level from the
1158!  moist sounding and integrating down.
1159
1160        p_input(nl) = pm_input(nl)
1161
1162          do k=nl-1,1,-1
1163            dz = h_input(k+1)-h_input(k)
1164            p_input(k) = p_input(k+1) + 0.5*dz*(rho_input(k)+rho_input(k+1))*g
1165          enddo
1166
1167
1168        do k=1,nl
1169          zk(k) = h_input(k)
1170          p(k) = pm_input(k)
1171          p_dry(k) = p_input(k)
1172          theta(k) = th_input(k)
1173          rho(k) = rho_input(k)
1174          u(k) = u_input(k)
1175          v(k) = v_input(k)
1176          qv(k) = qv_input(k)
1177
1178        enddo
1179
1180     if(debug) then
1181      write(6,*) ' sounding '
1182      write(6,*) '  k  height(m)  press (Pa) pd(Pa) theta (K) den(kg/m^3)  u(m/s)     v(m/s)    qv(g/g) '
1183      do k=1,nl
1184        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)
1185      enddo
1186
1187     end if
1188
1189      end subroutine get_sounding
1190
1191!-------------------------------------------------------
1192
1193      subroutine read_sounding( ps,ts,qvs,h,th,qv,u,v,n,nl,debug )
1194      implicit none
1195      integer n,nl
1196      real ps,ts,qvs,h(n),th(n),qv(n),u(n),v(n)
1197      logical end_of_file
1198      logical debug
1199
1200      integer k
1201
1202      open(unit=10,file='input_sounding',form='formatted',status='old')
1203      rewind(10)
1204      read(10,*) ps, ts, qvs
1205      if(debug) then
1206        write(6,*) ' input sounding surface parameters '
1207        write(6,*) ' surface pressure (mb) ',ps
1208        write(6,*) ' surface pot. temp (K) ',ts
1209        write(6,*) ' surface mixing ratio (g/kg) ',qvs
1210      end if
1211
1212      end_of_file = .false.
1213      k = 0
1214
1215      do while (.not. end_of_file)
1216
1217        read(10,*,end=100) h(k+1), th(k+1), qv(k+1), u(k+1), v(k+1)
1218        k = k+1
1219        if(debug) write(6,'(1x,i3,5(1x,e10.3))') k, h(k), th(k), qv(k), u(k), v(k)
1220        go to 110
1221 100    end_of_file = .true.
1222 110    continue
1223      enddo
1224
1225      nl = k
1226
1227      close(unit=10,status = 'keep')
1228
1229      end subroutine read_sounding
1230
1231END MODULE module_initialize_ideal
Note: See TracBrowser for help on using the repository browser.