PageRenderTime 50ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/wrfv2_fire/dyn_em/module_initialize_seabreeze2d_x.F

http://github.com/jbeezley/wrf-fire
FORTRAN Legacy | 832 lines | 494 code | 179 blank | 159 comment | 15 complexity | b1f7ff228d00817274a1f37a4d6e2d90 MD5 | raw file
Possible License(s): AGPL-1.0
  1. !IDEAL:MODEL_LAYER:INITIALIZATION
  2. !
  3. ! This MODULE holds the routines which are used to perform various initializations
  4. ! for the individual domains.
  5. ! This MODULE CONTAINS the following routines:
  6. ! initialize_field_test - 1. Set different fields to different constant
  7. ! values. This is only a test. If the correct
  8. ! domain is not found (based upon the "id")
  9. ! then a fatal error is issued.
  10. !-----------------------------------------------------------------------
  11. MODULE module_initialize_ideal
  12. USE module_domain
  13. USE module_io_domain
  14. USE module_state_description
  15. USE module_model_constants
  16. USE module_bc
  17. USE module_timing
  18. USE module_configure
  19. USE module_init_utilities
  20. USE module_soil_pre
  21. #ifdef DM_PARALLEL
  22. USE module_dm
  23. #endif
  24. CONTAINS
  25. !-------------------------------------------------------------------
  26. ! this is a wrapper for the solver-specific init_domain routines.
  27. ! Also dereferences the grid variables and passes them down as arguments.
  28. ! This is crucial, since the lower level routines may do message passing
  29. ! and this will get fouled up on machines that insist on passing down
  30. ! copies of assumed-shape arrays (by passing down as arguments, the
  31. ! data are treated as assumed-size -- ie. f77 -- arrays and the copying
  32. ! business is avoided). Fie on the F90 designers. Fie and a pox.
  33. ! NOTE: Modified to remove all but arrays of rank 4 or more from the
  34. ! argument list. Arrays with rank>3 are still problematic due to the
  35. ! above-noted fie- and pox-ities. TBH 20061129.
  36. SUBROUTINE init_domain ( grid )
  37. IMPLICIT NONE
  38. ! Input data.
  39. TYPE (domain), POINTER :: grid
  40. ! Local data.
  41. INTEGER :: idum1, idum2
  42. CALL set_scalar_indices_from_config ( head_grid%id , idum1, idum2 )
  43. CALL init_domain_rk( grid &
  44. !
  45. #include <actual_new_args.inc>
  46. !
  47. )
  48. END SUBROUTINE init_domain
  49. !-------------------------------------------------------------------
  50. SUBROUTINE init_domain_rk ( grid &
  51. !
  52. # include <dummy_new_args.inc>
  53. !
  54. )
  55. IMPLICIT NONE
  56. ! Input data.
  57. TYPE (domain), POINTER :: grid
  58. # include <dummy_new_decl.inc>
  59. TYPE (grid_config_rec_type) :: config_flags
  60. ! Local data
  61. INTEGER :: &
  62. ids, ide, jds, jde, kds, kde, &
  63. ims, ime, jms, jme, kms, kme, &
  64. its, ite, jts, jte, kts, kte, &
  65. i, j, k
  66. INTEGER, PARAMETER :: nl_max = 1000
  67. REAL, DIMENSION(nl_max) :: zk, p_in, theta, rho, u, v, qv, pd_in
  68. INTEGER :: nl_in
  69. INTEGER :: icm,jcm, ii, im1, jj, jm1, loop, error, fid, nxc, nyc, lm
  70. REAL :: u_mean,v_mean, f0, p_surf, p_level, qvf, z_at_v, z_at_u
  71. REAL :: z_scale, xrad, yrad, zrad, rad, delt, cof1, cof2
  72. ! REAL, EXTERNAL :: interp_0
  73. REAL :: pi, rnd
  74. ! stuff from original initialization that has been dropped from the Registry
  75. REAL :: vnu, xnu, xnus, dinit0, cbh, p0_temp, t0_temp, zd, zt
  76. REAL :: qvf1, qvf2, pd_surf
  77. INTEGER :: it
  78. real :: thtmp, ptmp, temp(3)
  79. LOGICAL :: moisture_init
  80. LOGICAL :: stretch_grid, dry_sounding
  81. character (len=256) :: mminlu2
  82. #ifdef DM_PARALLEL
  83. # include <data_calls.inc>
  84. #endif
  85. SELECT CASE ( model_data_order )
  86. CASE ( DATA_ORDER_ZXY )
  87. kds = grid%sd31 ; kde = grid%ed31 ;
  88. ids = grid%sd32 ; ide = grid%ed32 ;
  89. jds = grid%sd33 ; jde = grid%ed33 ;
  90. kms = grid%sm31 ; kme = grid%em31 ;
  91. ims = grid%sm32 ; ime = grid%em32 ;
  92. jms = grid%sm33 ; jme = grid%em33 ;
  93. kts = grid%sp31 ; kte = grid%ep31 ; ! note that tile is entire patch
  94. its = grid%sp32 ; ite = grid%ep32 ; ! note that tile is entire patch
  95. jts = grid%sp33 ; jte = grid%ep33 ; ! note that tile is entire patch
  96. CASE ( DATA_ORDER_XYZ )
  97. ids = grid%sd31 ; ide = grid%ed31 ;
  98. jds = grid%sd32 ; jde = grid%ed32 ;
  99. kds = grid%sd33 ; kde = grid%ed33 ;
  100. ims = grid%sm31 ; ime = grid%em31 ;
  101. jms = grid%sm32 ; jme = grid%em32 ;
  102. kms = grid%sm33 ; kme = grid%em33 ;
  103. its = grid%sp31 ; ite = grid%ep31 ; ! note that tile is entire patch
  104. jts = grid%sp32 ; jte = grid%ep32 ; ! note that tile is entire patch
  105. kts = grid%sp33 ; kte = grid%ep33 ; ! note that tile is entire patch
  106. CASE ( DATA_ORDER_XZY )
  107. ids = grid%sd31 ; ide = grid%ed31 ;
  108. kds = grid%sd32 ; kde = grid%ed32 ;
  109. jds = grid%sd33 ; jde = grid%ed33 ;
  110. ims = grid%sm31 ; ime = grid%em31 ;
  111. kms = grid%sm32 ; kme = grid%em32 ;
  112. jms = grid%sm33 ; jme = grid%em33 ;
  113. its = grid%sp31 ; ite = grid%ep31 ; ! note that tile is entire patch
  114. kts = grid%sp32 ; kte = grid%ep32 ; ! note that tile is entire patch
  115. jts = grid%sp33 ; jte = grid%ep33 ; ! note that tile is entire patch
  116. END SELECT
  117. stretch_grid = .true.
  118. delt = 6.
  119. ! z_scale = .50
  120. z_scale = .40
  121. pi = 2.*asin(1.0)
  122. write(6,*) ' pi is ',pi
  123. nxc = (ide-ids)/2
  124. nyc = jde/2
  125. icm = ide/2
  126. ! lm is the half width of the land in terms of grid points
  127. lm = 25
  128. write(6,*) 'lm,icm-lm,icm+lm = ', lm,icm-lm,icm+lm
  129. CALL model_to_grid_config_rec ( grid%id , model_config_rec , config_flags )
  130. ! here we check to see if the boundary conditions are set properly
  131. CALL boundary_condition_check( config_flags, bdyzone, error, grid%id )
  132. moisture_init = .true.
  133. grid%itimestep=0
  134. #ifdef DM_PARALLEL
  135. CALL wrf_dm_bcast_bytes( icm , IWORDSIZE )
  136. CALL wrf_dm_bcast_bytes( jcm , IWORDSIZE )
  137. #endif
  138. mminlu2 = ' '
  139. mminlu2(1:4) = 'USGS'
  140. CALL nl_set_mminlu(1, mminlu2)
  141. ! CALL nl_set_mminlu(1, 'USGS')
  142. CALL nl_set_iswater(1,16)
  143. CALL nl_set_isice(1,3)
  144. CALL nl_set_cen_lat(1,20.)
  145. CALL nl_set_cen_lon(1,-105.)
  146. CALL nl_set_truelat1(1,0.)
  147. CALL nl_set_truelat2(1,0.)
  148. CALL nl_set_moad_cen_lat (1,0.)
  149. CALL nl_set_stand_lon (1,0.)
  150. CALL nl_set_pole_lon (1,0.)
  151. CALL nl_set_pole_lat (1,90.)
  152. CALL nl_set_map_proj(1,0)
  153. ! CALL model_to_grid_config_rec(1,model_config_rec,config_flags)
  154. CALL nl_get_iswater(1,grid%iswater)
  155. ! here we initialize data that currently is not initialized
  156. ! in the input data
  157. DO j = jts, jte
  158. DO i = its, ite
  159. grid%msft(i,j) = 1.
  160. grid%msfu(i,j) = 1.
  161. grid%msfv(i,j) = 1.
  162. grid%msftx(i,j) = 1.
  163. grid%msfty(i,j) = 1.
  164. grid%msfux(i,j) = 1.
  165. grid%msfuy(i,j) = 1.
  166. grid%msfvx(i,j) = 1.
  167. grid%msfvy(i,j) = 1.
  168. grid%msfvx_inv(i,j)= 1.
  169. grid%sina(i,j) = 0.
  170. grid%cosa(i,j) = 1.
  171. grid%e(i,j) = 0.
  172. grid%f(i,j) = 0.
  173. grid%xlat(i,j) = 30.
  174. grid%xlong(i,j) = 0.
  175. ! Hard-wire the ocean-land configuration
  176. if (i .ge. (icm-lm) .and. i .lt. (icm+lm)) then
  177. grid%xland(i,j) = 1.
  178. grid%lu_index(i,j) = 18
  179. grid%tsk(i,j) = 280.0
  180. grid%tmn(i,j) = 280.0
  181. else
  182. grid%xland(i,j) = 2.
  183. grid%lu_index(i,j) = 16
  184. grid%tsk(i,j) = 287.0
  185. grid%tmn(i,j) = 280.0
  186. end if
  187. END DO
  188. END DO
  189. ! for Noah LSM, additional variables need to be initialized
  190. other_masked_fields : SELECT CASE ( model_config_rec%sf_surface_physics(grid%id) )
  191. CASE (SLABSCHEME)
  192. CASE (LSMSCHEME)
  193. DO j = jts , MIN(jde-1,jte)
  194. DO i = its , MIN(ide-1,ite)
  195. IF (grid%xland(i,j) .lt. 1.5) THEN
  196. grid%vegfra(i,j) = 0.5
  197. grid%canwat(i,j) = 0.
  198. grid%ivgtyp(i,j) = 18
  199. grid%isltyp(i,j) = 8
  200. grid%xice(i,j) = 0.
  201. grid%snow(i,j) = 0.
  202. ELSE
  203. grid%vegfra(i,j) = 0.
  204. grid%canwat(i,j) = 0.
  205. grid%ivgtyp(i,j) = 16
  206. grid%isltyp(i,j) = 14
  207. grid%xice(i,j) = 0.
  208. grid%snow(i,j) = 0.
  209. ENDIF
  210. END DO
  211. END DO
  212. CASE (RUCLSMSCHEME)
  213. END SELECT other_masked_fields
  214. DO j = jts, jte
  215. DO k = kts, kte
  216. DO i = its, ite
  217. grid%ww(i,k,j) = 0.
  218. END DO
  219. END DO
  220. END DO
  221. grid%step_number = 0
  222. ! Process the soil; note that there are some things hard-wired into share/module_soil_pre.F
  223. CALL process_soil_ideal(grid%xland,grid%xice,grid%vegfra,grid%snow,grid%canwat, &
  224. grid%ivgtyp,grid%isltyp,grid%tslb,grid%smois, &
  225. grid%tsk,grid%tmn,grid%zs,grid%dzs,model_config_rec%num_soil_layers, &
  226. model_config_rec%sf_surface_physics(grid%id), &
  227. ids,ide, jds,jde, kds,kde,&
  228. ims,ime, jms,jme, kms,kme,&
  229. its,ite, jts,jte, kts,kte )
  230. ! set up the grid
  231. IF (stretch_grid) THEN ! exponential stretch for eta (nearly constant dz)
  232. DO k=1, kde
  233. grid%znw(k) = (exp(-(k-1)/float(kde-1)/z_scale) - exp(-1./z_scale))/ &
  234. (1.-exp(-1./z_scale))
  235. ENDDO
  236. ELSE
  237. DO k=1, kde
  238. grid%znw(k) = 1. - float(k-1)/float(kde-1)
  239. ENDDO
  240. ENDIF
  241. DO k=1, kde-1
  242. grid%dnw(k) = grid%znw(k+1) - grid%znw(k)
  243. grid%rdnw(k) = 1./grid%dnw(k)
  244. grid%znu(k) = 0.5*(grid%znw(k+1)+grid%znw(k))
  245. ENDDO
  246. DO k=2, kde-1
  247. grid%dn(k) = 0.5*(grid%dnw(k)+grid%dnw(k-1))
  248. grid%rdn(k) = 1./grid%dn(k)
  249. grid%fnp(k) = .5* grid%dnw(k )/grid%dn(k)
  250. grid%fnm(k) = .5* grid%dnw(k-1)/grid%dn(k)
  251. ENDDO
  252. cof1 = (2.*grid%dn(2)+grid%dn(3))/(grid%dn(2)+grid%dn(3))*grid%dnw(1)/grid%dn(2)
  253. cof2 = grid%dn(2) /(grid%dn(2)+grid%dn(3))*grid%dnw(1)/grid%dn(3)
  254. grid%cf1 = grid%fnp(2) + cof1
  255. grid%cf2 = grid%fnm(2) - cof1 - cof2
  256. grid%cf3 = cof2
  257. grid%cfn = (.5*grid%dnw(kde-1)+grid%dn(kde-1))/grid%dn(kde-1)
  258. grid%cfn1 = -.5*grid%dnw(kde-1)/grid%dn(kde-1)
  259. grid%rdx = 1./config_flags%dx
  260. grid%rdy = 1./config_flags%dy
  261. ! get the sounding from the ascii sounding file, first get dry sounding and
  262. ! calculate base state
  263. write(6,*) ' getting dry sounding for base state '
  264. dry_sounding = .true.
  265. CALL get_sounding( zk, p_in, pd_in, theta, rho, u, v, qv, dry_sounding, nl_max, nl_in )
  266. write(6,*) ' returned from reading sounding, nl_in is ',nl_in
  267. ! find ptop for the desired ztop (ztop is input from the namelist),
  268. ! and find surface pressure
  269. grid%p_top = interp_0( p_in, zk, config_flags%ztop, nl_in )
  270. DO j=jts,jte
  271. DO i=its,ite ! flat surface
  272. grid%phb(i,1,j) = 0.
  273. grid%php(i,1,j) = 0.
  274. grid%ph0(i,1,j) = 0.
  275. grid%ht(i,j) = 0.
  276. ENDDO
  277. ENDDO
  278. DO J = jts, jte
  279. DO I = its, ite
  280. p_surf = interp_0( p_in, zk, grid%phb(i,1,j)/g, nl_in )
  281. grid%mub(i,j) = p_surf-grid%p_top
  282. ! this is dry hydrostatic sounding (base state), so given grid%p (coordinate),
  283. ! interp theta (from interp) and compute 1/rho from eqn. of state
  284. DO K = 1, kte-1
  285. p_level = grid%znu(k)*(p_surf - grid%p_top) + grid%p_top
  286. grid%pb(i,k,j) = p_level
  287. grid%t_init(i,k,j) = interp_0( theta, p_in, p_level, nl_in ) - t0
  288. grid%alb(i,k,j) = (r_d/p1000mb)*(grid%t_init(i,k,j)+t0)*(grid%pb(i,k,j)/p1000mb)**cvpm
  289. ENDDO
  290. ! calc hydrostatic balance (alternatively we could interp the geopotential from the
  291. ! sounding, but this assures that the base state is in exact hydrostatic balance with
  292. ! respect to the model eqns.
  293. DO k = 2,kte
  294. 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)
  295. ENDDO
  296. ENDDO
  297. ENDDO
  298. write(6,*) ' ptop is ',grid%p_top
  299. write(6,*) ' base state grid%mub(1,1), p_surf is ',grid%mub(1,1),grid%mub(1,1)+grid%p_top
  300. ! calculate full state for each column - this includes moisture.
  301. write(6,*) ' getting moist sounding for full state '
  302. dry_sounding = .false.
  303. CALL get_sounding( zk, p_in, pd_in, theta, rho, u, v, qv, dry_sounding, nl_max, nl_in )
  304. DO J = jts, min(jde-1,jte)
  305. DO I = its, min(ide-1,ite)
  306. ! At this point grid%p_top is already set. find the DRY mass in the column
  307. ! by interpolating the DRY pressure.
  308. pd_surf = interp_0( pd_in, zk, grid%phb(i,1,j)/g, nl_in )
  309. ! compute the perturbation mass and the full mass
  310. grid%mu_1(i,j) = pd_surf-grid%p_top - grid%mub(i,j)
  311. grid%mu_2(i,j) = grid%mu_1(i,j)
  312. grid%mu0(i,j) = grid%mu_1(i,j) + grid%mub(i,j)
  313. ! given the dry pressure and coordinate system, interp the potential
  314. ! temperature and qv
  315. do k=1,kde-1
  316. p_level = grid%znu(k)*(pd_surf - grid%p_top) + grid%p_top
  317. moist(i,k,j,P_QV) = interp_0( qv, pd_in, p_level, nl_in )
  318. grid%t_1(i,k,j) = interp_0( theta, pd_in, p_level, nl_in ) - t0
  319. grid%t_2(i,k,j) = grid%t_1(i,k,j)
  320. enddo
  321. ! integrate the hydrostatic equation (from the RHS of the bigstep
  322. ! vertical momentum equation) down from the top to get grid%p.
  323. ! first from the top of the model to the top pressure
  324. k = kte-1 ! top level
  325. qvf1 = 0.5*(moist(i,k,j,P_QV)+moist(i,k,j,P_QV))
  326. qvf2 = 1./(1.+qvf1)
  327. qvf1 = qvf1*qvf2
  328. ! grid%p(i,k,j) = - 0.5*grid%mu_1(i,j)/grid%rdnw(k)
  329. grid%p(i,k,j) = - 0.5*(grid%mu_1(i,j)+qvf1*grid%mub(i,j))/grid%rdnw(k)/qvf2
  330. qvf = 1. + rvovrd*moist(i,k,j,P_QV)
  331. grid%alt(i,k,j) = (r_d/p1000mb)*(grid%t_1(i,k,j)+t0)*qvf* &
  332. (((grid%p(i,k,j)+grid%pb(i,k,j))/p1000mb)**cvpm)
  333. grid%al(i,k,j) = grid%alt(i,k,j) - grid%alb(i,k,j)
  334. ! down the column
  335. do k=kte-2,1,-1
  336. qvf1 = 0.5*(moist(i,k,j,P_QV)+moist(i,k+1,j,P_QV))
  337. qvf2 = 1./(1.+qvf1)
  338. qvf1 = qvf1*qvf2
  339. 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)
  340. qvf = 1. + rvovrd*moist(i,k,j,P_QV)
  341. grid%alt(i,k,j) = (r_d/p1000mb)*(grid%t_1(i,k,j)+t0)*qvf* &
  342. (((grid%p(i,k,j)+grid%pb(i,k,j))/p1000mb)**cvpm)
  343. grid%al(i,k,j) = grid%alt(i,k,j) - grid%alb(i,k,j)
  344. enddo
  345. ! this is the hydrostatic equation used in the model after the
  346. ! small timesteps. In the model, grid%al (inverse density)
  347. ! is computed from the geopotential.
  348. grid%ph_1(i,1,j) = 0.
  349. DO k = 2,kte
  350. grid%ph_1(i,k,j) = grid%ph_1(i,k-1,j) - (1./grid%rdnw(k-1))*( &
  351. (grid%mub(i,j)+grid%mu_1(i,j))*grid%al(i,k-1,j)+ &
  352. grid%mu_1(i,j)*grid%alb(i,k-1,j) )
  353. grid%ph_2(i,k,j) = grid%ph_1(i,k,j)
  354. grid%ph0(i,k,j) = grid%ph_1(i,k,j) + grid%phb(i,k,j)
  355. ENDDO
  356. if((i==2) .and. (j==2)) then
  357. write(6,*) ' grid%ph_1 calc ',grid%ph_1(2,1,2),grid%ph_1(2,2,2),&
  358. grid%mu_1(2,2)+grid%mub(2,2),grid%mu_1(2,2), &
  359. grid%alb(2,1,2),grid%al(1,2,1),grid%rdnw(1)
  360. endif
  361. ENDDO
  362. ENDDO
  363. if (0.gt.1) then
  364. !#if 0
  365. ! The seabreeze case is adapted from the squall line case
  366. ! so we just turn off the thermal perturbation
  367. ! thermal perturbation to kick off convection
  368. call random_seed
  369. write(6,*) ' nxc, nyc for perturbation ',nxc,nyc
  370. write(6,*) ' delt for perturbation ',delt
  371. DO J = jts, min(jde-1,jte)
  372. ! yrad = config_flags%dy*float(j-nyc)/4000.
  373. yrad = 0.
  374. DO I = its, min(ide-1,ite)
  375. xrad = config_flags%dx*float(i-nxc)/10000.
  376. ! xrad = 0.
  377. DO K = 1, 35
  378. ! put in preturbation theta (bubble) and recalc density. note,
  379. ! the mass in the column is not changing, so when theta changes,
  380. ! we recompute density and geopotential
  381. zrad = 0.5*(grid%ph_1(i,k,j)+grid%ph_1(i,k+1,j) &
  382. +grid%phb(i,k,j)+grid%phb(i,k+1,j))/g
  383. zrad = (zrad-1500.)/1500.
  384. RAD=SQRT(xrad*xrad+yrad*yrad+zrad*zrad)
  385. ! IF(RAD <= 1.) THEN
  386. call RANDOM_NUMBER(rnd)
  387. grid%t_1(i,k,j)=grid%t_1(i,k,j)+delt*(rnd-0.5)
  388. ! grid%t_1(i,k,j)=grid%t_1(i,k,j)+delt*COS(.5*PI*RAD)**2
  389. grid%t_2(i,k,j)=grid%t_1(i,k,j)
  390. qvf = 1. + rvovrd*moist(i,k,j,P_QV)
  391. grid%alt(i,k,j) = (r_d/p1000mb)*(grid%t_1(i,k,j)+t0)*qvf* &
  392. (((grid%p(i,k,j)+grid%pb(i,k,j))/p1000mb)**cvpm)
  393. grid%al(i,k,j) = grid%alt(i,k,j) - grid%alb(i,k,j)
  394. ! ENDIF
  395. ENDDO
  396. ! rebalance hydrostatically
  397. DO k = 2,kte
  398. grid%ph_1(i,k,j) = grid%ph_1(i,k-1,j) - (1./grid%rdnw(k-1))*( &
  399. (grid%mub(i,j)+grid%mu_1(i,j))*grid%al(i,k-1,j)+ &
  400. grid%mu_1(i,j)*grid%alb(i,k-1,j) )
  401. grid%ph_2(i,k,j) = grid%ph_1(i,k,j)
  402. grid%ph0(i,k,j) = grid%ph_1(i,k,j) + grid%phb(i,k,j)
  403. ENDDO
  404. ENDDO
  405. ENDDO
  406. endif
  407. !#endif
  408. write(6,*) ' grid%mu_1 from comp ', grid%mu_1(1,1)
  409. write(6,*) ' full state sounding from comp, ph, grid%p, grid%al, grid%t_1, qv '
  410. do k=1,kde-1
  411. write(6,'(i3,1x,5(1x,1pe10.3))') k, grid%ph_1(1,k,1)+grid%phb(1,k,1), &
  412. grid%p(1,k,1)+grid%pb(1,k,1), grid%alt(1,k,1), &
  413. grid%t_1(1,k,1)+t0, moist(1,k,1,P_QV)
  414. enddo
  415. write(6,*) ' pert state sounding from comp, grid%ph_1, pp, alp, grid%t_1, qv '
  416. do k=1,kde-1
  417. write(6,'(i3,1x,5(1x,1pe10.3))') k, grid%ph_1(1,k,1), &
  418. grid%p(1,k,1), grid%al(1,k,1), &
  419. grid%t_1(1,k,1), moist(1,k,1,P_QV)
  420. enddo
  421. ! interp v
  422. DO J = jts, jte
  423. DO I = its, min(ide-1,ite)
  424. IF (j == jds) THEN
  425. z_at_v = grid%phb(i,1,j)/g
  426. ELSE IF (j == jde) THEN
  427. z_at_v = grid%phb(i,1,j-1)/g
  428. ELSE
  429. z_at_v = 0.5*(grid%phb(i,1,j)+grid%phb(i,1,j-1))/g
  430. END IF
  431. p_surf = interp_0( p_in, zk, z_at_v, nl_in )
  432. DO K = 1, kte
  433. p_level = grid%znu(k)*(p_surf - grid%p_top) + grid%p_top
  434. grid%v_1(i,k,j) = interp_0( v, p_in, p_level, nl_in )
  435. grid%v_2(i,k,j) = grid%v_1(i,k,j)
  436. ENDDO
  437. ENDDO
  438. ENDDO
  439. ! interp u
  440. DO J = jts, min(jde-1,jte)
  441. DO I = its, ite
  442. IF (i == ids) THEN
  443. z_at_u = grid%phb(i,1,j)/g
  444. ELSE IF (i == ide) THEN
  445. z_at_u = grid%phb(i-1,1,j)/g
  446. ELSE
  447. z_at_u = 0.5*(grid%phb(i,1,j)+grid%phb(i-1,1,j))/g
  448. END IF
  449. p_surf = interp_0( p_in, zk, z_at_u, nl_in )
  450. DO K = 1, kte
  451. p_level = grid%znu(k)*(p_surf - grid%p_top) + grid%p_top
  452. grid%u_1(i,k,j) = interp_0( u, p_in, p_level, nl_in )
  453. grid%u_2(i,k,j) = grid%u_1(i,k,j)
  454. ENDDO
  455. ENDDO
  456. ENDDO
  457. ! set w
  458. DO J = jts, min(jde-1,jte)
  459. DO K = kts, kte
  460. DO I = its, min(ide-1,ite)
  461. grid%w_1(i,k,j) = 0.
  462. grid%w_2(i,k,j) = 0.
  463. ENDDO
  464. ENDDO
  465. ENDDO
  466. ! set a few more things
  467. DO J = jts, min(jde-1,jte)
  468. DO K = kts, kte-1
  469. DO I = its, min(ide-1,ite)
  470. grid%h_diabatic(i,k,j) = 0.
  471. ENDDO
  472. ENDDO
  473. ENDDO
  474. DO k=1,kte-1
  475. grid%t_base(k) = grid%t_1(1,k,1)
  476. grid%qv_base(k) = moist(1,k,1,P_QV)
  477. grid%u_base(k) = grid%u_1(1,k,1)
  478. grid%v_base(k) = grid%v_1(1,k,1)
  479. 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
  480. ENDDO
  481. DO J = jts, min(jde-1,jte)
  482. DO I = its, min(ide-1,ite)
  483. thtmp = grid%t_2(i,1,j)+t0
  484. ptmp = grid%p(i,1,j)+grid%pb(i,1,j)
  485. temp(1) = thtmp * (ptmp/p1000mb)**rcp
  486. thtmp = grid%t_2(i,2,j)+t0
  487. ptmp = grid%p(i,2,j)+grid%pb(i,2,j)
  488. temp(2) = thtmp * (ptmp/p1000mb)**rcp
  489. thtmp = grid%t_2(i,3,j)+t0
  490. ptmp = grid%p(i,3,j)+grid%pb(i,3,j)
  491. temp(3) = thtmp * (ptmp/p1000mb)**rcp
  492. ! grid%tsk(I,J)=grid%cf1*temp(1)+grid%cf2*temp(2)+grid%cf3*temp(3)
  493. grid%tmn(I,J)=grid%tsk(I,J)-0.5
  494. ENDDO
  495. ENDDO
  496. RETURN
  497. END SUBROUTINE init_domain_rk
  498. SUBROUTINE init_module_initialize
  499. END SUBROUTINE init_module_initialize
  500. !---------------------------------------------------------------------
  501. ! test driver for get_sounding
  502. !
  503. ! implicit none
  504. ! integer n
  505. ! parameter(n = 1000)
  506. ! real zk(n),p(n),theta(n),rho(n),u(n),v(n),qv(n),pd(n)
  507. ! logical dry
  508. ! integer nl,k
  509. !
  510. ! dry = .false.
  511. ! dry = .true.
  512. ! call get_sounding( zk, p, pd, theta, rho, u, v, qv, dry, n, nl )
  513. ! write(6,*) ' input levels ',nl
  514. ! write(6,*) ' sounding '
  515. ! write(6,*) ' k height(m) press (Pa) pd(Pa) theta (K) den(kg/m^3) u(m/s) v(m/s) qv(g/g) '
  516. ! do k=1,nl
  517. ! 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)
  518. ! enddo
  519. ! end
  520. !
  521. !---------------------------------------------------------------------------
  522. subroutine get_sounding( zk, p, p_dry, theta, rho, &
  523. u, v, qv, dry, nl_max, nl_in )
  524. implicit none
  525. integer nl_max, nl_in
  526. real zk(nl_max), p(nl_max), theta(nl_max), rho(nl_max), &
  527. u(nl_max), v(nl_max), qv(nl_max), p_dry(nl_max)
  528. logical dry
  529. integer n
  530. parameter(n=3000)
  531. logical debug
  532. parameter( debug = .true.)
  533. ! input sounding data
  534. real p_surf, th_surf, qv_surf
  535. real pi_surf, pi(n)
  536. real h_input(n), th_input(n), qv_input(n), u_input(n), v_input(n)
  537. ! diagnostics
  538. real rho_surf, p_input(n), rho_input(n)
  539. real pm_input(n) ! this are for full moist sounding
  540. ! local data
  541. real r
  542. parameter (r = r_d)
  543. integer k, it, nl
  544. real qvf, qvf1, dz
  545. ! first, read the sounding
  546. call read_sounding( p_surf, th_surf, qv_surf, &
  547. h_input, th_input, qv_input, u_input, v_input,n, nl, debug )
  548. if(dry) then
  549. do k=1,nl
  550. qv_input(k) = 0.
  551. enddo
  552. endif
  553. if(debug) write(6,*) ' number of input levels = ',nl
  554. nl_in = nl
  555. if(nl_in .gt. nl_max ) then
  556. write(6,*) ' too many levels for input arrays ',nl_in,nl_max
  557. call wrf_error_fatal ( ' too many levels for input arrays ' )
  558. end if
  559. ! compute diagnostics,
  560. ! first, convert qv(g/kg) to qv(g/g)
  561. do k=1,nl
  562. qv_input(k) = 0.001*qv_input(k)
  563. enddo
  564. p_surf = 100.*p_surf ! convert to pascals
  565. qvf = 1. + rvovrd*qv_input(1)
  566. rho_surf = 1./((r/p1000mb)*th_surf*qvf*((p_surf/p1000mb)**cvpm))
  567. pi_surf = (p_surf/p1000mb)**(r/cp)
  568. if(debug) then
  569. write(6,*) ' surface density is ',rho_surf
  570. write(6,*) ' surface pi is ',pi_surf
  571. end if
  572. ! integrate moist sounding hydrostatically, starting from the
  573. ! specified surface pressure
  574. ! -> first, integrate from surface to lowest level
  575. qvf = 1. + rvovrd*qv_input(1)
  576. qvf1 = 1. + qv_input(1)
  577. rho_input(1) = rho_surf
  578. dz = h_input(1)
  579. do it=1,10
  580. pm_input(1) = p_surf &
  581. - 0.5*dz*(rho_surf+rho_input(1))*g*qvf1
  582. rho_input(1) = 1./((r/p1000mb)*th_input(1)*qvf*((pm_input(1)/p1000mb)**cvpm))
  583. enddo
  584. ! integrate up the column
  585. do k=2,nl
  586. rho_input(k) = rho_input(k-1)
  587. dz = h_input(k)-h_input(k-1)
  588. qvf1 = 0.5*(2.+(qv_input(k-1)+qv_input(k)))
  589. qvf = 1. + rvovrd*qv_input(k) ! qv is in g/kg here
  590. do it=1,10
  591. pm_input(k) = pm_input(k-1) &
  592. - 0.5*dz*(rho_input(k)+rho_input(k-1))*g*qvf1
  593. rho_input(k) = 1./((r/p1000mb)*th_input(k)*qvf*((pm_input(k)/p1000mb)**cvpm))
  594. enddo
  595. enddo
  596. ! we have the moist sounding
  597. ! next, compute the dry sounding using p at the highest level from the
  598. ! moist sounding and integrating down.
  599. p_input(nl) = pm_input(nl)
  600. do k=nl-1,1,-1
  601. dz = h_input(k+1)-h_input(k)
  602. p_input(k) = p_input(k+1) + 0.5*dz*(rho_input(k)+rho_input(k+1))*g
  603. enddo
  604. do k=1,nl
  605. ! For the seabreeze case, we can hard-wire the winds and qv fields
  606. zk(k) = h_input(k)
  607. p(k) = pm_input(k)
  608. p_dry(k) = p_input(k)
  609. theta(k) = th_input(k)
  610. rho(k) = rho_input(k)
  611. u(k) = u_input(k)
  612. v(k) = v_input(k)
  613. qv(k) = qv_input(k)
  614. enddo
  615. if(debug) then
  616. write(6,*) ' sounding '
  617. write(6,*) ' k height(m) press (Pa) pd(Pa) theta (K) den(kg/m^3) u(m/s) v(m/s) qv(g/g) '
  618. do k=1,nl
  619. 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)
  620. enddo
  621. end if
  622. end subroutine get_sounding
  623. !-------------------------------------------------------
  624. subroutine read_sounding( ps,ts,qvs,h,th,qv,u,v,n,nl,debug )
  625. implicit none
  626. integer n,nl
  627. real ps,ts,qvs,h(n),th(n),qv(n),u(n),v(n)
  628. logical end_of_file
  629. logical debug
  630. integer k
  631. open(unit=10,file='input_sounding',form='formatted',status='old')
  632. rewind(10)
  633. read(10,*) ps, ts, qvs
  634. if(debug) then
  635. write(6,*) ' input sounding surface parameters '
  636. write(6,*) ' surface pressure (mb) ',ps
  637. write(6,*) ' surface pot. temp (K) ',ts
  638. write(6,*) ' surface mixing ratio (g/kg) ',qvs
  639. end if
  640. end_of_file = .false.
  641. k = 0
  642. do while (.not. end_of_file)
  643. read(10,*,end=100) h(k+1), th(k+1), qv(k+1), u(k+1), v(k+1)
  644. k = k+1
  645. if(debug) write(6,'(1x,i3,5(1x,e10.3))') k, h(k), th(k), qv(k), u(k), v(k)
  646. go to 110
  647. 100 end_of_file = .true.
  648. 110 continue
  649. enddo
  650. nl = k
  651. close(unit=10,status = 'keep')
  652. end subroutine read_sounding
  653. END MODULE module_initialize_ideal