PageRenderTime 57ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/wrfv2_fire/dyn_em/module_initialize_squall2d_y.F

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