PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/wrfv2_fire/dyn_em/module_initialize_hill2d_x.F

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