PageRenderTime 66ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 2ms

/wrfv2_fire/dyn_em/module_initialize_real.F

http://github.com/jbeezley/wrf-fire
FORTRAN Legacy | 6042 lines | 3975 code | 1083 blank | 984 comment | 36 complexity | 0c1a13b5e2da8ab3fb4da9ef56917932 MD5 | raw file
Possible License(s): AGPL-1.0

Large files files are truncated, but you can click here to view the full file

  1. !REAL:MODEL_LAYER:INITIALIZATION
  2. #ifndef VERT_UNIT
  3. ! This MODULE holds the routines which are used to perform various initializations
  4. ! for the individual domains, specifically for the Eulerian, mass-based coordinate.
  5. !-----------------------------------------------------------------------
  6. MODULE module_initialize_real
  7. USE module_bc
  8. USE module_configure
  9. USE module_domain
  10. USE module_io_domain
  11. USE module_model_constants
  12. USE module_state_description
  13. USE module_timing
  14. USE module_soil_pre
  15. USE module_date_time
  16. USE module_llxy
  17. #ifdef DM_PARALLEL
  18. USE module_dm
  19. USE module_comm_dm, ONLY : &
  20. HALO_EM_INIT_1_sub &
  21. ,HALO_EM_INIT_2_sub &
  22. ,HALO_EM_INIT_3_sub &
  23. ,HALO_EM_INIT_4_sub &
  24. ,HALO_EM_INIT_5_sub &
  25. ,HALO_EM_VINTERP_UV_1_sub
  26. #endif
  27. REAL , SAVE :: p_top_save
  28. INTEGER :: internal_time_loop
  29. CONTAINS
  30. !-------------------------------------------------------------------
  31. SUBROUTINE init_domain ( grid )
  32. IMPLICIT NONE
  33. ! Input space and data. No gridded meteorological data has been stored, though.
  34. ! TYPE (domain), POINTER :: grid
  35. TYPE (domain) :: 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. USE module_optional_input
  52. IMPLICIT NONE
  53. ! Input space and data. No gridded meteorological data has been stored, though.
  54. ! TYPE (domain), POINTER :: grid
  55. TYPE (domain) :: grid
  56. #include "dummy_new_decl.inc"
  57. TYPE (grid_config_rec_type) :: config_flags
  58. ! Local domain indices and counters.
  59. INTEGER :: num_veg_cat , num_soil_top_cat , num_soil_bot_cat
  60. INTEGER :: loop , num_seaice_changes
  61. INTEGER :: ids, ide, jds, jde, kds, kde, &
  62. ims, ime, jms, jme, kms, kme, &
  63. its, ite, jts, jte, kts, kte, &
  64. ips, ipe, jps, jpe, kps, kpe, &
  65. i, j, k
  66. INTEGER :: imsx, imex, jmsx, jmex, kmsx, kmex, &
  67. ipsx, ipex, jpsx, jpex, kpsx, kpex, &
  68. imsy, imey, jmsy, jmey, kmsy, kmey, &
  69. ipsy, ipey, jpsy, jpey, kpsy, kpey
  70. INTEGER :: ns
  71. ! Local data
  72. INTEGER :: error
  73. INTEGER :: im, num_3d_m, num_3d_s
  74. REAL :: p_surf, p_level
  75. REAL :: cof1, cof2
  76. REAL :: qvf , qvf1 , qvf2 , pd_surf
  77. REAL :: p00 , t00 , a , tiso
  78. REAL :: hold_znw , ptemp
  79. REAL :: vap_pres_mb , sat_vap_pres_mb
  80. LOGICAL :: were_bad
  81. LOGICAL :: stretch_grid, dry_sounding, debug
  82. INTEGER IICOUNT
  83. REAL :: p_top_requested , temp
  84. INTEGER :: num_metgrid_levels
  85. REAL , DIMENSION(max_eta) :: eta_levels
  86. REAL :: max_dz
  87. ! INTEGER , PARAMETER :: nl_max = 1000
  88. ! REAL , DIMENSION(nl_max) :: grid%dn
  89. integer::oops1,oops2
  90. REAL :: zap_close_levels
  91. INTEGER :: force_sfc_in_vinterp
  92. INTEGER :: interp_type , lagrange_order , extrap_type , t_extrap_type
  93. LOGICAL :: lowest_lev_from_sfc , use_levels_below_ground , use_surface
  94. LOGICAL :: we_have_tavgsfc , we_have_tsk
  95. INTEGER :: lev500 , loop_count
  96. REAL :: zl , zu , pl , pu , z500 , dz500 , tvsfc , dpmu
  97. REAL :: pfu, pfd, phm
  98. LOGICAL , PARAMETER :: want_full_levels = .TRUE.
  99. LOGICAL , PARAMETER :: want_half_levels = .FALSE.
  100. CHARACTER (LEN=80) :: a_message
  101. REAL :: max_mf
  102. ! Excluded middle.
  103. LOGICAL :: any_valid_points
  104. INTEGER :: i_valid , j_valid
  105. !-- Carsel and Parrish [1988]
  106. REAL , DIMENSION(100) :: lqmi
  107. REAL :: t_start , t_end
  108. ! Dimension information stored in grid data structure.
  109. CALL cpu_time(t_start)
  110. CALL get_ijk_from_grid ( grid , &
  111. ids, ide, jds, jde, kds, kde, &
  112. ims, ime, jms, jme, kms, kme, &
  113. ips, ipe, jps, jpe, kps, kpe, &
  114. imsx, imex, jmsx, jmex, kmsx, kmex, &
  115. ipsx, ipex, jpsx, jpex, kpsx, kpex, &
  116. imsy, imey, jmsy, jmey, kmsy, kmey, &
  117. ipsy, ipey, jpsy, jpey, kpsy, kpey )
  118. its = ips ; ite = ipe ; jts = jps ; jte = jpe ; kts = kps ; kte = kpe
  119. CALL model_to_grid_config_rec ( grid%id , model_config_rec , config_flags )
  120. ! Send out a quick message about the time steps based on the map scale factors.
  121. IF ( ( internal_time_loop .EQ. 1 ) .AND. ( grid%id .EQ. 1 ) .AND. &
  122. ( .NOT. config_flags%map_proj .EQ. PROJ_CASSINI ) ) THEN
  123. max_mf = grid%msft(its,jts)
  124. DO j=jts,MIN(jde-1,jte)
  125. DO i=its,MIN(ide-1,ite)
  126. max_mf = MAX ( max_mf , grid%msft(i,j) )
  127. END DO
  128. END DO
  129. #if ( defined(DM_PARALLEL) && ! defined(STUBMPI) )
  130. max_mf = wrf_dm_max_real ( max_mf )
  131. #endif
  132. WRITE ( a_message , FMT='(A,F5.2,A)' ) 'Max map factor in domain 1 = ',max_mf, &
  133. '. Scale the dt in the model accordingly.'
  134. CALL wrf_message ( a_message )
  135. END IF
  136. ! Check to see if the boundary conditions are set properly in the namelist file.
  137. ! This checks for sufficiency and redundancy.
  138. CALL boundary_condition_check( config_flags, bdyzone, error, grid%id )
  139. ! Some sort of "this is the first time" initialization. Who knows.
  140. grid%step_number = 0
  141. grid%itimestep=0
  142. ! Pull in the info in the namelist to compare it to the input data.
  143. grid%real_data_init_type = model_config_rec%real_data_init_type
  144. ! To define the base state, we call a USER MODIFIED routine to set the three
  145. ! necessary constants: p00 (sea level pressure, Pa), t00 (sea level temperature, K),
  146. ! and A (temperature difference, from 1000 mb to 300 mb, K).
  147. CALL const_module_initialize ( p00 , t00 , a , tiso )
  148. ! Save these constants to write out in model output file
  149. grid%t00 = t00
  150. grid%p00 = p00
  151. grid%tlp = a
  152. grid%tiso = tiso
  153. ! Are there any hold-ups to us bypassing the middle of the domain? These
  154. ! holdups would be situations where we need data in the middle of the domain.
  155. ! FOr example, if this si the first time period, we need the full domain
  156. ! processed for ICs. Also, if there is some sort of gridded FDDA turned on, or
  157. ! if the SST update is activated, then we can't just blow off the middle of the
  158. ! domain all willy-nilly. Other cases of these hold-ups? Sure - what if the
  159. ! user wants to smooth the CG topo, we need several rows and columns available.
  160. ! What if the lat/lon proj is used, then we need to run a spectral filter on
  161. ! the topo. Both are killers when trying to ignore data in the middle of the
  162. ! domain.
  163. ! If hold_ups = .F., then there are no hold-ups to excluding the middle
  164. ! domain processing. If hold_ups = .T., then there are hold-ups, and we
  165. ! must process the middle of the domain.
  166. hold_ups = ( internal_time_loop .EQ. 1 ) .OR. &
  167. ( config_flags%grid_fdda .NE. 0 ) .OR. &
  168. ( config_flags%sst_update .EQ. 1 ) .OR. &
  169. ( config_flags%all_ic_times ) .OR. &
  170. ( config_flags%smooth_cg_topo ) .OR. &
  171. ( config_flags%map_proj .EQ. PROJ_CASSINI )
  172. ! There are a few checks that we need to do when the input data comes in with the middle
  173. ! excluded by WPS.
  174. IF ( flag_excluded_middle .NE. 0 ) THEN
  175. ! If this time period of data from WPS has the middle excluded, it had better be OK for
  176. ! us to have a hole.
  177. IF ( hold_ups ) THEN
  178. WRITE ( a_message,* ) 'None of the following are allowed to be TRUE : '
  179. CALL wrf_message ( a_message )
  180. WRITE ( a_message,* ) ' ( internal_time_loop .EQ. 1 ) ', ( internal_time_loop .EQ. 1 )
  181. CALL wrf_message ( a_message )
  182. WRITE ( a_message,* ) ' ( config_flags%grid_fdda .NE. 0 ) ', ( config_flags%grid_fdda .NE. 0 )
  183. CALL wrf_message ( a_message )
  184. WRITE ( a_message,* ) ' ( config_flags%sst_update .EQ. 1 ) ', ( config_flags%sst_update .EQ. 1 )
  185. CALL wrf_message ( a_message )
  186. WRITE ( a_message,* ) ' ( config_flags%all_ic_times ) ', ( config_flags%all_ic_times )
  187. CALL wrf_message ( a_message )
  188. WRITE ( a_message,* ) ' ( config_flags%smooth_cg_topo ) ', ( config_flags%smooth_cg_topo )
  189. CALL wrf_message ( a_message )
  190. WRITE ( a_message,* ) ' ( config_flags%map_proj .EQ. PROJ_CASSINI ) ', ( config_flags%map_proj .EQ. PROJ_CASSINI )
  191. CALL wrf_message ( a_message )
  192. WRITE ( a_message,* ) 'Problems, we cannot have excluded middle data from WPS'
  193. CALL wrf_error_fatal ( a_message )
  194. END IF
  195. ! Make sure that the excluded middle data from metgrid is "wide enough". We only have to check
  196. ! when the excluded middle was actually used in WPS.
  197. IF ( config_flags%spec_bdy_width .GT. flag_excluded_middle ) THEN
  198. WRITE ( a_message,* ) 'The WRF &bdy_control namelist.input spec_bdy_width = ', config_flags%spec_bdy_width
  199. CALL wrf_message ( a_message )
  200. WRITE ( a_message,* ) 'The WPS &metgrid namelist.wps process_only_bdy width = ',flag_excluded_middle
  201. CALL wrf_message ( a_message )
  202. WRITE ( a_message,* ) 'WPS process_only_bdy must be >= WRF spec_bdy_width'
  203. CALL wrf_error_fatal ( a_message )
  204. END IF
  205. END IF
  206. em_width = config_flags%spec_bdy_width
  207. ! We need to find if there are any valid non-excluded-middle points in this
  208. ! tile. If so, then we need to hang on to a valid i,j location.
  209. any_valid_points = .false.
  210. find_valid : DO j = jts,jte
  211. DO i = its,ite
  212. IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
  213. any_valid_points = .true.
  214. i_valid = i
  215. j_valid = j
  216. EXIT find_valid
  217. END DO
  218. END DO find_valid
  219. ! Replace traditional seaice field with optional seaice (AFWA source)
  220. IF ( flag_icefrac .EQ. 1 ) THEN
  221. DO j=jts,MIN(jde-1,jte)
  222. DO i=its,MIN(ide-1,ite)
  223. IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
  224. grid%xice(i,j) = grid%icefrac_gc(i,j)
  225. END DO
  226. END DO
  227. END IF
  228. ! Fix the snow (water equivalent depth, kg/m^2) and the snowh (physical snow
  229. ! depth, m) fields.
  230. IF ( ( flag_snow .EQ. 0 ) .AND. ( flag_snowh .EQ. 0 ) ) THEN
  231. DO j=jts,MIN(jde-1,jte)
  232. DO i=its,MIN(ide-1,ite)
  233. IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
  234. grid%snow(i,j) = 0.
  235. grid%snowh(i,j) = 0.
  236. END DO
  237. END DO
  238. ELSE IF ( ( flag_snow .EQ. 0 ) .AND. ( flag_snowh .EQ. 1 ) ) THEN
  239. DO j=jts,MIN(jde-1,jte)
  240. DO i=its,MIN(ide-1,ite)
  241. ! ( m -> kg/m^2 ) & ( reduce to liquid, 5:1 ratio )
  242. IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
  243. grid%snow(i,j) = grid%snowh(i,j) * 1000. / 5.
  244. END DO
  245. END DO
  246. ELSE IF ( ( flag_snow .EQ. 1 ) .AND. ( flag_snowh .EQ. 0 ) ) THEN
  247. DO j=jts,MIN(jde-1,jte)
  248. DO i=its,MIN(ide-1,ite)
  249. ! ( kg/m^2 -> m) & ( liquid to snow depth, 5:1 ratio )
  250. IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
  251. grid%snowh(i,j) = grid%snow(i,j) / 1000. * 5.
  252. END DO
  253. END DO
  254. END IF
  255. ! For backward compatibility, we might need to assign the map factors from
  256. ! what they were, to what they are.
  257. IF ( ( config_flags%polar ) .AND. ( flag_mf_xy .EQ. 1 ) ) THEN
  258. DO j=max(jds+1,jts),min(jde-1,jte)
  259. DO i=its,min(ide-1,ite)
  260. IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
  261. grid%msfvx_inv(i,j) = 1./grid%msfvx(i,j)
  262. END DO
  263. END DO
  264. IF(jts == jds) THEN
  265. DO i=its,ite
  266. IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
  267. grid%msfvx(i,jts) = 0.
  268. grid%msfvx_inv(i,jts) = 0.
  269. END DO
  270. END IF
  271. IF(jte == jde) THEN
  272. DO i=its,ite
  273. IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
  274. grid%msfvx(i,jte) = 0.
  275. grid%msfvx_inv(i,jte) = 0.
  276. END DO
  277. END IF
  278. ELSE IF ( ( config_flags%map_proj .EQ. PROJ_CASSINI ) .AND. ( flag_mf_xy .EQ. 1 ) ) THEN
  279. DO j=jts,jte
  280. DO i=its,min(ide-1,ite)
  281. IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
  282. grid%msfvx_inv(i,j) = 1./grid%msfvx(i,j)
  283. END DO
  284. END DO
  285. ELSE IF ( ( .NOT. config_flags%map_proj .EQ. PROJ_CASSINI ) .AND. ( flag_mf_xy .NE. 1 ) ) THEN
  286. DO j=jts,jte
  287. DO i=its,ite
  288. IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
  289. grid%msfvx(i,j) = grid%msfv(i,j)
  290. grid%msfvy(i,j) = grid%msfv(i,j)
  291. grid%msfux(i,j) = grid%msfu(i,j)
  292. grid%msfuy(i,j) = grid%msfu(i,j)
  293. grid%msftx(i,j) = grid%msft(i,j)
  294. grid%msfty(i,j) = grid%msft(i,j)
  295. ENDDO
  296. ENDDO
  297. DO j=jts,min(jde,jte)
  298. DO i=its,min(ide-1,ite)
  299. IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
  300. grid%msfvx_inv(i,j) = 1./grid%msfvx(i,j)
  301. END DO
  302. END DO
  303. ELSE IF ( ( .NOT. config_flags%map_proj .EQ. PROJ_CASSINI ) .AND. ( flag_mf_xy .EQ. 1 ) ) THEN
  304. IF ( grid%msfvx(its,jts) .EQ. 0 ) THEN
  305. CALL wrf_error_fatal ( 'Maybe you do not have the new map factors, try re-running geogrid' )
  306. END IF
  307. DO j=jts,min(jde,jte)
  308. DO i=its,min(ide-1,ite)
  309. IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
  310. grid%msfvx_inv(i,j) = 1./grid%msfvx(i,j)
  311. END DO
  312. END DO
  313. ELSE IF ( ( config_flags%map_proj .EQ. PROJ_CASSINI ) .AND. ( flag_mf_xy .NE. 1 ) ) THEN
  314. CALL wrf_error_fatal ( 'Neither SI data nor older metgrid data can initialize a global domain' )
  315. ENDIF
  316. ! Check to see what available surface temperatures we have.
  317. IF ( flag_tavgsfc .EQ. 1 ) THEN
  318. we_have_tavgsfc = .TRUE.
  319. ELSE
  320. we_have_tavgsfc = .FALSE.
  321. END IF
  322. IF ( flag_tsk .EQ. 1 ) THEN
  323. we_have_tsk = .TRUE.
  324. ELSE
  325. we_have_tsk = .FALSE.
  326. END IF
  327. IF ( config_flags%use_tavg_for_tsk ) THEN
  328. IF ( we_have_tsk .OR. we_have_tavgsfc ) THEN
  329. ! we are OK
  330. ELSE
  331. CALL wrf_error_fatal ( 'We either need TSK or TAVGSFC, verify these fields are coming from WPS' )
  332. END IF
  333. ! Since we require a skin temperature in the model, we can use the average 2-m temperature if provided.
  334. IF ( we_have_tavgsfc ) THEN
  335. DO j=jts,min(jde,jte)
  336. DO i=its,min(ide-1,ite)
  337. IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
  338. grid%tsk(i,j) = grid%tavgsfc(i,j)
  339. END DO
  340. END DO
  341. END IF
  342. END IF
  343. ! Is there any vertical interpolation to do? The "old" data comes in on the correct
  344. ! vertical locations already.
  345. IF ( flag_metgrid .EQ. 1 ) THEN ! <----- START OF VERTICAL INTERPOLATION PART ---->
  346. ! If this is data from the PINTERP program, it is emulating METGRID output.
  347. ! One of the caveats of this data is the way that the vertical structure is
  348. ! handled. We take the k=1 level and toss it (it is disposable), and we
  349. ! swap in the surface data. This is done for all of the 3d fields about
  350. ! which we show some interest: u, v, t, rh, ght, and p. For u, v, and rh,
  351. ! we assume no interesting vertical structure, and just assign the 1000 mb
  352. ! data. We directly use the 2-m temp for surface temp. We use the surface
  353. ! pressure field and the topography elevation for the lowest level of
  354. ! pressure and height, respectively.
  355. IF ( flag_pinterp .EQ. 1 ) THEN
  356. WRITE ( a_message , * ) 'Data from P_INTERP program, filling k=1 level with artificial surface fields.'
  357. CALL wrf_message ( a_message )
  358. DO j=jts,jte
  359. DO i=its,ite
  360. IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
  361. grid%u_gc(i,1,j) = grid%u_gc(i,2,j)
  362. grid%v_gc(i,1,j) = grid%v_gc(i,2,j)
  363. grid%rh_gc(i,1,j) = grid%rh_gc(i,2,j)
  364. grid%t_gc(i,1,j) = grid%t2(i,j)
  365. grid%ght_gc(i,1,j) = grid%ht(i,j)
  366. grid%p_gc(i,1,j) = grid%psfc(i,j)
  367. END DO
  368. END DO
  369. flag_psfc = 0
  370. END IF
  371. ! Variables that are named differently between SI and WPS.
  372. DO j = jts, MIN(jte,jde-1)
  373. DO i = its, MIN(ite,ide-1)
  374. IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
  375. grid%tsk(i,j) = grid%tsk_gc(i,j)
  376. grid%tmn(i,j) = grid%tmn_gc(i,j)
  377. grid%xlat(i,j) = grid%xlat_gc(i,j)
  378. grid%xlong(i,j) = grid%xlong_gc(i,j)
  379. grid%ht(i,j) = grid%ht_gc(i,j)
  380. END DO
  381. END DO
  382. ! A user could request that the most coarse grid has the
  383. ! topography along the outer boundary smoothed. This smoothing
  384. ! is similar to the coarse/nest interface. The outer rows and
  385. ! cols come from the existing large scale topo, and then the
  386. ! next several rows/cols are a linear ramp of the large scale
  387. ! model and the hi-res topo from WPS. We only do this for the
  388. ! coarse grid since we are going to make the interface consistent
  389. ! in the model betwixt the CG and FG domains.
  390. IF ( ( config_flags%smooth_cg_topo ) .AND. &
  391. ( grid%id .EQ. 1 ) .AND. &
  392. ( flag_soilhgt .EQ. 1) ) THEN
  393. CALL blend_terrain ( grid%toposoil , grid%ht , &
  394. ids , ide , jds , jde , 1 , 1 , &
  395. ims , ime , jms , jme , 1 , 1 , &
  396. ips , ipe , jps , jpe , 1 , 1 )
  397. END IF
  398. ! Filter the input topography if this is a polar projection.
  399. IF ( ( config_flags%polar ) .AND. ( grid%fft_filter_lat .GT. 90 ) ) THEN
  400. CALL wrf_error_fatal ( 'If the polar boundary condition is used, then fft_filter_lat must be set in namelist.input' )
  401. END IF
  402. IF ( config_flags%map_proj .EQ. PROJ_CASSINI ) THEN
  403. #if ( defined( DM_PARALLEL ) && ( ! defined( STUBMPI ) ) )
  404. ! We stick the topo and map fac in an unused 3d array. The map scale
  405. ! factor and computational latitude are passed along for the ride
  406. ! (part of the transpose process - we only do 3d arrays) to determine
  407. ! "how many" values are used to compute the mean. We want a number
  408. ! that is consistent with the original grid resolution.
  409. DO j = jts, MIN(jte,jde-1)
  410. DO k = kts, kte
  411. DO i = its, MIN(ite,ide-1)
  412. grid%t_init(i,k,j) = 1.
  413. END DO
  414. END DO
  415. DO i = its, MIN(ite,ide-1)
  416. grid%t_init(i,1,j) = grid%ht(i,j)
  417. grid%t_init(i,2,j) = grid%msftx(i,j)
  418. grid%t_init(i,3,j) = grid%clat(i,j)
  419. END DO
  420. END DO
  421. # include "XPOSE_POLAR_FILTER_TOPO_z2x.inc"
  422. ! Retrieve the 2d arrays for topo, map factors, and the
  423. ! computational latitude.
  424. DO j = jpsx, MIN(jpex,jde-1)
  425. DO i = ipsx, MIN(ipex,ide-1)
  426. grid%ht_xxx(i,j) = grid%t_xxx(i,1,j)
  427. grid%mf_xxx(i,j) = grid%t_xxx(i,2,j)
  428. grid%clat_xxx(i,j) = grid%t_xxx(i,3,j)
  429. END DO
  430. END DO
  431. ! Get a mean topo field that is consistent with the grid
  432. ! distance on each computational latitude loop.
  433. CALL filter_topo ( grid%ht_xxx , grid%clat_xxx , grid%mf_xxx , &
  434. grid%fft_filter_lat , &
  435. ids, ide, jds, jde, 1 , 1 , &
  436. imsx, imex, jmsx, jmex, 1, 1, &
  437. ipsx, ipex, jpsx, jpex, 1, 1 )
  438. ! Stick the filtered topo back into the dummy 3d array to
  439. ! transpose it back to "all z on a patch".
  440. DO j = jpsx, MIN(jpex,jde-1)
  441. DO i = ipsx, MIN(ipex,ide-1)
  442. grid%t_xxx(i,1,j) = grid%ht_xxx(i,j)
  443. END DO
  444. END DO
  445. # include "XPOSE_POLAR_FILTER_TOPO_x2z.inc"
  446. ! Get the un-transposed topo data.
  447. DO j = jts, MIN(jte,jde-1)
  448. DO i = its, MIN(ite,ide-1)
  449. grid%ht(i,j) = grid%t_init(i,1,j)
  450. END DO
  451. END DO
  452. #else
  453. CALL filter_topo ( grid%ht , grid%clat , grid%msftx , &
  454. grid%fft_filter_lat , &
  455. ids, ide, jds, jde, 1,1, &
  456. ims, ime, jms, jme, 1,1, &
  457. its, ite, jts, jte, 1,1 )
  458. #endif
  459. END IF
  460. ! If we have any input low-res surface pressure, we store it.
  461. IF ( flag_psfc .EQ. 1 ) THEN
  462. DO j = jts, MIN(jte,jde-1)
  463. DO i = its, MIN(ite,ide-1)
  464. IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
  465. grid%psfc_gc(i,j) = grid%psfc(i,j)
  466. grid%p_gc(i,1,j) = grid%psfc(i,j)
  467. END DO
  468. END DO
  469. END IF
  470. ! If we have the low-resolution surface elevation, stick that in the
  471. ! "input" locations of the 3d height. We still have the "hi-res" topo
  472. ! stuck in the grid%ht array. The grid%landmask if test is required as some sources
  473. ! have ZERO elevation over water (thank you very much).
  474. IF ( flag_soilhgt .EQ. 1) THEN
  475. DO j = jts, MIN(jte,jde-1)
  476. DO i = its, MIN(ite,ide-1)
  477. ! IF ( grid%landmask(i,j) .GT. 0.5 ) THEN
  478. IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
  479. grid%ght_gc(i,1,j) = grid%toposoil(i,j)
  480. grid%ht_gc(i,j)= grid%toposoil(i,j)
  481. ! END IF
  482. END DO
  483. END DO
  484. END IF
  485. ! The number of vertical levels in the input data. There is no staggering for
  486. ! different variables.
  487. num_metgrid_levels = grid%num_metgrid_levels
  488. ! For UM data, swap incoming extra (theta-based) pressure with the standardly
  489. ! named (rho-based) pressure.
  490. IF ( flag_ptheta .EQ. 1 ) THEN
  491. DO j = jts, MIN(jte,jde-1)
  492. DO k = 1 , num_metgrid_levels
  493. DO i = its, MIN(ite,ide-1)
  494. IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
  495. ptemp = grid%p_gc(i,k,j)
  496. grid%p_gc(i,k,j) = grid%prho_gc(i,k,j)
  497. grid%prho_gc(i,k,j) = ptemp
  498. END DO
  499. END DO
  500. END DO
  501. ! For UM data, the "surface" and the "first hybrid" level for the theta-level data fields are the same.
  502. ! Average the surface (k=1) and the second hybrid level (k=num_metgrid_levels-1) to get the first hybrid
  503. ! layer. We only do this for the theta-level data: pressure, temperature, specific humidity, and
  504. ! geopotential height (i.e. we do not modify u, v, or the rho-based pressure).
  505. DO j = jts, MIN(jte,jde-1)
  506. DO i = its, MIN(ite,ide-1)
  507. IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
  508. grid% p_gc(i,num_metgrid_levels,j) = ( grid% p_gc(i,1,j) + grid% p_gc(i,num_metgrid_levels-1,j) ) * 0.5
  509. grid% t_gc(i,num_metgrid_levels,j) = ( grid% t_gc(i,1,j) + grid% t_gc(i,num_metgrid_levels-1,j) ) * 0.5
  510. grid% sh_gc(i,num_metgrid_levels,j) = ( grid% sh_gc(i,1,j) + grid% sh_gc(i,num_metgrid_levels-1,j) ) * 0.5
  511. grid%ght_gc(i,num_metgrid_levels,j) = ( grid%ght_gc(i,1,j) + grid%ght_gc(i,num_metgrid_levels-1,j) ) * 0.5
  512. END DO
  513. END DO
  514. END IF
  515. IF ( any_valid_points ) THEN
  516. ! Check for and semi-fix missing surface fields.
  517. IF ( grid%p_gc(i_valid,num_metgrid_levels,j_valid) .LT. grid%p_gc(i_valid,2,j_valid) ) THEN
  518. k = 2
  519. ELSE
  520. k = num_metgrid_levels
  521. END IF
  522. IF ( grid%t_gc(i_valid,1,j_valid) .EQ. -1.E30 ) THEN
  523. DO j = jts, MIN(jte,jde-1)
  524. DO i = its, MIN(ite,ide-1)
  525. IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
  526. grid%t_gc(i,1,j) = grid%t_gc(i,k,j)
  527. END DO
  528. END DO
  529. config_flags%use_surface = .FALSE.
  530. grid%use_surface = .FALSE.
  531. WRITE ( a_message , * ) 'Missing surface temp, replaced with closest level, use_surface set to false.'
  532. CALL wrf_message ( a_message )
  533. END IF
  534. IF ( grid%rh_gc(i_valid,1,j_valid) .EQ. -1.E30 ) THEN
  535. DO j = jts, MIN(jte,jde-1)
  536. DO i = its, MIN(ite,ide-1)
  537. IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
  538. grid%rh_gc(i,1,j) = grid%rh_gc(i,k,j)
  539. END DO
  540. END DO
  541. config_flags%use_surface = .FALSE.
  542. grid%use_surface = .FALSE.
  543. WRITE ( a_message , * ) 'Missing surface RH, replaced with closest level, use_surface set to false.'
  544. CALL wrf_message ( a_message )
  545. END IF
  546. IF ( grid%u_gc(i_valid,1,j_valid) .EQ. -1.E30 ) THEN
  547. DO j = jts, MIN(jte,jde-1)
  548. DO i = its, ite
  549. IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
  550. grid%u_gc(i,1,j) = grid%u_gc(i,k,j)
  551. END DO
  552. END DO
  553. config_flags%use_surface = .FALSE.
  554. grid%use_surface = .FALSE.
  555. WRITE ( a_message , * ) 'Missing surface u wind, replaced with closest level, use_surface set to false.'
  556. CALL wrf_message ( a_message )
  557. END IF
  558. IF ( grid%v_gc(i_valid,1,j_valid) .EQ. -1.E30 ) THEN
  559. DO j = jts, jte
  560. DO i = its, MIN(ite,ide-1)
  561. IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
  562. grid%v_gc(i,1,j) = grid%v_gc(i,k,j)
  563. END DO
  564. END DO
  565. config_flags%use_surface = .FALSE.
  566. grid%use_surface = .FALSE.
  567. WRITE ( a_message , * ) 'Missing surface v wind, replaced with closest level, use_surface set to false.'
  568. CALL wrf_message ( a_message )
  569. END IF
  570. ! Compute the mixing ratio from the input relative humidity.
  571. IF ( ( flag_qv .NE. 1 ) .AND. ( flag_sh .NE. 1 ) ) THEN
  572. IF ( grid%p_gc(i_valid,num_metgrid_levels,j_valid) .LT. grid%p_gc(i_valid,2,j_valid) ) THEN
  573. k = 2
  574. ELSE
  575. k = num_metgrid_levels
  576. END IF
  577. IF ( config_flags%rh2qv_method .eq. 1 ) THEN
  578. CALL rh_to_mxrat1(grid%rh_gc, grid%t_gc, grid%p_gc, grid%qv_gc , &
  579. config_flags%rh2qv_wrt_liquid , &
  580. config_flags%qv_max_p_safe , &
  581. config_flags%qv_max_flag , config_flags%qv_max_value , &
  582. config_flags%qv_min_p_safe , &
  583. config_flags%qv_min_flag , config_flags%qv_min_value , &
  584. ids , ide , jds , jde , 1 , num_metgrid_levels , &
  585. ims , ime , jms , jme , 1 , num_metgrid_levels , &
  586. its , ite , jts , jte , 1 , num_metgrid_levels )
  587. ELSE IF ( config_flags%rh2qv_method .eq. 2 ) THEN
  588. CALL rh_to_mxrat2(grid%rh_gc, grid%t_gc, grid%p_gc, grid%qv_gc , &
  589. config_flags%rh2qv_wrt_liquid , &
  590. config_flags%qv_max_p_safe , &
  591. config_flags%qv_max_flag , config_flags%qv_max_value , &
  592. config_flags%qv_min_p_safe , &
  593. config_flags%qv_min_flag , config_flags%qv_min_value , &
  594. ids , ide , jds , jde , 1 , num_metgrid_levels , &
  595. ims , ime , jms , jme , 1 , num_metgrid_levels , &
  596. its , ite , jts , jte , 1 , num_metgrid_levels )
  597. END IF
  598. ELSE IF ( flag_sh .EQ. 1 ) THEN
  599. IF ( grid%p_gc(i_valid,num_metgrid_levels,j_valid) .LT. grid%p_gc(i_valid,2,j_valid) ) THEN
  600. k = 2
  601. ELSE
  602. k = num_metgrid_levels
  603. END IF
  604. IF ( grid%sh_gc(i_valid,kts,j_valid) .LT. 1.e-6 ) THEN
  605. DO j = jts, MIN(jte,jde-1)
  606. DO i = its, MIN(ite,ide-1)
  607. IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
  608. grid%sh_gc(i,1,j) = grid%sh_gc(i,k,j)
  609. END DO
  610. END DO
  611. END IF
  612. DO j = jts, MIN(jte,jde-1)
  613. DO k = 1 , num_metgrid_levels
  614. DO i = its, MIN(ite,ide-1)
  615. IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
  616. grid%qv_gc(i,k,j) = grid%sh_gc(i,k,j) /( 1. - grid%sh_gc(i,k,j) )
  617. sat_vap_pres_mb = 0.6112*10.*EXP(17.67*(grid%t_gc(i,k,j)-273.15)/(grid%t_gc(i,k,j)-29.65))
  618. vap_pres_mb = grid%qv_gc(i,k,j) * grid%p_gc(i,k,j)/100. / (grid%qv_gc(i,k,j) + 0.622 )
  619. IF ( sat_vap_pres_mb .GT. 0 ) THEN
  620. grid%rh_gc(i,k,j) = ( vap_pres_mb / sat_vap_pres_mb ) * 100.
  621. ELSE
  622. grid%rh_gc(i,k,j) = 0.
  623. END IF
  624. END DO
  625. END DO
  626. END DO
  627. END IF
  628. ! Some data sets do not provide a 3d geopotential height field.
  629. IF ( grid%ght_gc(i_valid,grid%num_metgrid_levels/2,j_valid) .LT. 1 ) THEN
  630. DO j = jts, MIN(jte,jde-1)
  631. DO k = kts+1 , grid%num_metgrid_levels
  632. DO i = its, MIN(ite,ide-1)
  633. IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
  634. grid%ght_gc(i,k,j) = grid%ght_gc(i,k-1,j) - &
  635. R_d / g * 0.5 * ( grid%t_gc(i,k ,j) * ( 1 + 0.608 * grid%qv_gc(i,k ,j) ) + &
  636. grid%t_gc(i,k-1,j) * ( 1 + 0.608 * grid%qv_gc(i,k-1,j) ) ) * &
  637. LOG ( grid%p_gc(i,k,j) / grid%p_gc(i,k-1,j) )
  638. END DO
  639. END DO
  640. END DO
  641. END IF
  642. ! If the pressure levels in the middle of the atmosphere are upside down, then
  643. ! this is hybrid data. Computing the new surface pressure should use sfcprs2.
  644. IF ( grid%p_gc(i_valid,num_metgrid_levels/2,j_valid) .LT. grid%p_gc(i_valid,num_metgrid_levels/2+1,j_valid) ) THEN
  645. config_flags%sfcp_to_sfcp = .TRUE.
  646. END IF
  647. END IF
  648. ! Assign surface fields with original input values. If this is hybrid data,
  649. ! the values are not exactly representative. However - this is only for
  650. ! plotting purposes and such at the 0h of the forecast, so we are not all that
  651. ! worried.
  652. DO j = jts, min(jde-1,jte)
  653. DO i = its, min(ide,ite)
  654. IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
  655. grid%u10(i,j)=grid%u_gc(i,1,j)
  656. END DO
  657. END DO
  658. DO j = jts, min(jde,jte)
  659. DO i = its, min(ide-1,ite)
  660. IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
  661. grid%v10(i,j)=grid%v_gc(i,1,j)
  662. END DO
  663. END DO
  664. DO j = jts, min(jde-1,jte)
  665. DO i = its, min(ide-1,ite)
  666. IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
  667. grid%t2(i,j)=grid%t_gc(i,1,j)
  668. END DO
  669. END DO
  670. IF ( flag_qv .EQ. 1 ) THEN
  671. DO j = jts, min(jde-1,jte)
  672. DO i = its, min(ide-1,ite)
  673. IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
  674. grid%q2(i,j)=grid%qv_gc(i,1,j)
  675. END DO
  676. END DO
  677. END IF
  678. ! The requested ptop for real data cases.
  679. p_top_requested = grid%p_top_requested
  680. ! Compute the top pressure, grid%p_top. For isobaric data, this is just the
  681. ! top level. For the generalized vertical coordinate data, we find the
  682. ! max pressure on the top level. We have to be careful of two things:
  683. ! 1) the value has to be communicated, 2) the value can not increase
  684. ! at subsequent times from the initial value.
  685. IF ( internal_time_loop .EQ. 1 ) THEN
  686. CALL find_p_top ( grid%p_gc , grid%p_top , &
  687. ids , ide , jds , jde , 1 , num_metgrid_levels , &
  688. ims , ime , jms , jme , 1 , num_metgrid_levels , &
  689. its , ite , jts , jte , 1 , num_metgrid_levels )
  690. #if ( defined( DM_PARALLEL ) && ( ! defined( STUBMPI ) ) )
  691. grid%p_top = wrf_dm_max_real ( grid%p_top )
  692. #endif
  693. ! Compare the requested grid%p_top with the value available from the input data.
  694. IF ( p_top_requested .LT. grid%p_top ) THEN
  695. print *,'p_top_requested = ',p_top_requested
  696. print *,'allowable grid%p_top in data = ',grid%p_top
  697. CALL wrf_error_fatal ( 'p_top_requested < grid%p_top possible from data' )
  698. END IF
  699. ! The grid%p_top valus is the max of what is available from the data and the
  700. ! requested value. We have already compared <, so grid%p_top is directly set to
  701. ! the value in the namelist.
  702. grid%p_top = p_top_requested
  703. ! For subsequent times, we have to remember what the grid%p_top for the first
  704. ! time was. Why? If we have a generalized vert coordinate, the grid%p_top value
  705. ! could fluctuate.
  706. p_top_save = grid%p_top
  707. ELSE
  708. CALL find_p_top ( grid%p_gc , grid%p_top , &
  709. ids , ide , jds , jde , 1 , num_metgrid_levels , &
  710. ims , ime , jms , jme , 1 , num_metgrid_levels , &
  711. its , ite , jts , jte , 1 , num_metgrid_levels )
  712. #if ( defined( DM_PARALLEL ) && ( ! defined( STUBMPI ) ) )
  713. grid%p_top = wrf_dm_max_real ( grid%p_top )
  714. #endif
  715. IF ( grid%p_top .GT. p_top_save ) THEN
  716. print *,'grid%p_top from last time period = ',p_top_save
  717. print *,'grid%p_top from this time period = ',grid%p_top
  718. CALL wrf_error_fatal ( 'grid%p_top > previous value' )
  719. END IF
  720. grid%p_top = p_top_save
  721. ENDIF
  722. ! Get the monthly values interpolated to the current date for the traditional monthly
  723. ! fields of green-ness fraction and background albedo.
  724. CALL monthly_interp_to_date ( grid%greenfrac , current_date , grid%vegfra , &
  725. ids , ide , jds , jde , kds , kde , &
  726. ims , ime , jms , jme , kms , kme , &
  727. its , ite , jts , jte , kts , kte )
  728. CALL monthly_interp_to_date ( grid%albedo12m , current_date , grid%albbck , &
  729. ids , ide , jds , jde , kds , kde , &
  730. ims , ime , jms , jme , kms , kme , &
  731. its , ite , jts , jte , kts , kte )
  732. ! Get the min/max of each i,j for the monthly green-ness fraction.
  733. CALL monthly_min_max ( grid%greenfrac , grid%shdmin , grid%shdmax , &
  734. ids , ide , jds , jde , kds , kde , &
  735. ims , ime , jms , jme , kms , kme , &
  736. its , ite , jts , jte , kts , kte )
  737. ! The model expects the green-ness values in percent, not fraction.
  738. DO j = jts, MIN(jte,jde-1)
  739. DO i = its, MIN(ite,ide-1)
  740. grid%vegfra(i,j) = grid%vegfra(i,j) * 100.
  741. grid%shdmax(i,j) = grid%shdmax(i,j) * 100.
  742. grid%shdmin(i,j) = grid%shdmin(i,j) * 100.
  743. END DO
  744. END DO
  745. ! The model expects the albedo fields as a fraction, not a percent. Set the
  746. ! water values to 8%.
  747. DO j = jts, MIN(jte,jde-1)
  748. DO i = its, MIN(ite,ide-1)
  749. IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
  750. grid%albbck(i,j) = grid%albbck(i,j) / 100.
  751. grid%snoalb(i,j) = grid%snoalb(i,j) / 100.
  752. IF ( grid%landmask(i,j) .LT. 0.5 ) THEN
  753. grid%albbck(i,j) = 0.08
  754. grid%snoalb(i,j) = 0.08
  755. END IF
  756. END DO
  757. END DO
  758. ! Two ways to get the surface pressure. 1) If we have the low-res input surface
  759. ! pressure and the low-res topography, then we can do a simple hydrostatic
  760. ! relation. 2) Otherwise we compute the surface pressure from the sea-level
  761. ! pressure.
  762. ! Note that on output, grid%psfc is now hi-res. The low-res surface pressure and
  763. ! elevation are grid%psfc_gc and grid%ht_gc (same as grid%ght_gc(k=1)).
  764. IF ( ( flag_psfc .EQ. 1 ) .AND. &
  765. ( flag_soilhgt .EQ. 1 ) .AND. &
  766. ( flag_slp .EQ. 1 ) .AND. &
  767. ( .NOT. config_flags%sfcp_to_sfcp ) ) THEN
  768. WRITE(a_message,FMT='(A)') 'Using sfcprs3 to compute psfc'
  769. CALL wrf_message ( a_message )
  770. CALL sfcprs3(grid%ght_gc, grid%p_gc, grid%ht, &
  771. grid%pslv_gc, grid%psfc, &
  772. ids , ide , jds , jde , 1 , num_metgrid_levels , &
  773. ims , ime , jms , jme , 1 , num_metgrid_levels , &
  774. its , ite , jts , jte , 1 , num_metgrid_levels )
  775. ELSE IF ( ( flag_psfc .EQ. 1 ) .AND. &
  776. ( flag_soilhgt .EQ. 1 ) .AND. &
  777. ( config_flags%sfcp_to_sfcp ) ) THEN
  778. WRITE(a_message,FMT='(A)') 'Using sfcprs2 to compute psfc'
  779. CALL wrf_message ( a_message )
  780. CALL sfcprs2(grid%t_gc, grid%qv_gc, grid%ght_gc, grid%psfc_gc, grid%ht, &
  781. grid%tavgsfc, grid%p_gc, grid%psfc, we_have_tavgsfc, &
  782. ids , ide , jds , jde , 1 , num_metgrid_levels , &
  783. ims , ime , jms , jme , 1 , num_metgrid_levels , &
  784. its , ite , jts , jte , 1 , num_metgrid_levels )
  785. ELSE IF ( flag_slp .EQ. 1 ) THEN
  786. WRITE(a_message,FMT='(A)') 'Using sfcprs to compute psfc'
  787. CALL wrf_message ( a_message )
  788. CALL sfcprs (grid%t_gc, grid%qv_gc, grid%ght_gc, grid%pslv_gc, grid%ht, &
  789. grid%tavgsfc, grid%p_gc, grid%psfc, we_have_tavgsfc, &
  790. ids , ide , jds , jde , 1 , num_metgrid_levels , &
  791. ims , ime , jms , jme , 1 , num_metgrid_levels , &
  792. its , ite , jts , jte , 1 , num_metgrid_levels )
  793. ELSE
  794. WRITE(a_message,FMT='(3(A,I2),A,L1)') 'ERROR in psfc: flag_psfc = ',flag_psfc, &
  795. ', flag_soilhgt = ',flag_soilhgt , &
  796. ', flag_slp = ',flag_slp , &
  797. ', sfcp_to_sfcp = ',config_flags%sfcp_to_sfcp
  798. CALL wrf_message ( a_message )
  799. CALL wrf_error_fatal ( 'not enough info for a p sfc computation' )
  800. END IF
  801. ! If we have no input surface pressure, we'd better stick something in there.
  802. IF ( flag_psfc .NE. 1 ) THEN
  803. DO j = jts, MIN(jte,jde-1)
  804. DO i = its, MIN(ite,ide-1)
  805. IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
  806. grid%psfc_gc(i,j) = grid%psfc(i,j)
  807. grid%p_gc(i,1,j) = grid%psfc(i,j)
  808. END DO
  809. END DO
  810. END IF
  811. ! Integrate the mixing ratio to get the vapor pressure.
  812. CALL integ_moist ( grid%qv_gc , grid%p_gc , grid%pd_gc , grid%t_gc , grid%ght_gc , grid%intq_gc , &
  813. ids , ide , jds , jde , 1 , num_metgrid_levels , &
  814. ims , ime , jms , jme , 1 , num_metgrid_levels , &
  815. its , ite , jts , jte , 1 , num_metgrid_levels )
  816. ! If this is UM data, the same moisture removed from the "theta" level pressure data can
  817. ! be removed from the "rho" level pressures. This is an approximation. We'll revisit to
  818. ! see if this is a bad idea.
  819. IF ( flag_ptheta .EQ. 1 ) THEN
  820. DO j = jts, MIN(jte,jde-1)
  821. DO k = num_metgrid_levels-1 , 1 , -1
  822. DO i = its, MIN(ite,ide-1)
  823. IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
  824. ptemp = ((grid%p_gc(i,k,j) - grid%pd_gc(i,k,j)) + (grid%p_gc(i,k+1,j) - grid%pd_gc(i,k+1,j)))/2
  825. grid%pdrho_gc(i,k,j) = grid%prho_gc(i,k,j) - ptemp
  826. END DO
  827. END DO
  828. END DO
  829. END IF
  830. ! Compute the difference between the dry, total surface pressure (input) and the
  831. ! dry top pressure (constant).
  832. CALL p_dts ( grid%mu0 , grid%intq_gc , grid%psfc , grid%p_top , &
  833. ids , ide , jds , jde , 1 , num_metgrid_levels , &
  834. ims , ime , jms , jme , 1 , num_metgrid_levels , &
  835. its , ite , jts , jte , 1 , num_metgrid_levels )
  836. ! Compute the dry, hydrostatic surface pressure.
  837. CALL p_dhs ( grid%pdhs , grid%ht , p00 , t00 , a , &
  838. ids , ide , jds , jde , kds , kde , &
  839. ims , ime , jms , jme , kms , kme , &
  840. its , ite , jts , jte , kts , kte )
  841. ! Compute the eta levels if not defined already.
  842. IF ( grid%znw(1) .NE. 1.0 ) THEN
  843. eta_levels(1:kde) = model_config_rec%eta_levels(1:kde)
  844. max_dz = model_config_rec%max_dz
  845. CALL compute_eta ( grid%znw , &
  846. eta_levels , max_eta , max_dz , &
  847. grid%p_top , g , p00 , cvpm , a , r_d , cp , t00 , p1000mb , t0 , tiso , &
  848. ids , ide , jds , jde , kds , kde , &
  849. ims , ime , jms , jme , kms , kme , &
  850. its , ite , jts , jte , kts , kte )
  851. END IF
  852. IF ( config_flags%interp_theta ) THEN
  853. ! The input field is temperature, we want potential temp.
  854. CALL t_to_theta ( grid%t_gc , grid%p_gc , p00 , &
  855. ids , ide , jds , jde , 1 , num_metgrid_levels , &
  856. ims , ime , jms , jme , 1 , num_metgrid_levels , &
  857. its , ite , jts , jte , 1 , num_metgrid_levels )
  858. END IF
  859. IF ( flag_slp .EQ. 1 ) THEN
  860. ! On the eta surfaces, compute the dry pressure = mu eta, stored in
  861. ! grid%pb, since it is a pressure, and we don't need another kms:kme 3d
  862. ! array floating around. The grid%pb array is re-computed as the base pressure
  863. ! later after the vertical interpolations are complete.
  864. CALL p_dry ( grid%mu0 , grid%znw , grid%p_top , grid%pb , want_full_levels , &
  865. ids , ide , jds , jde , kds , kde , &
  866. ims , ime , jms , jme , kms , kme , &
  867. its , ite , jts , jte , kts , kte )
  868. ! All of the vertical interpolations are done in dry-pressure space. The
  869. ! input data has had the moisture removed (grid%pd_gc). The target levels (grid%pb)
  870. ! had the vapor pressure removed from the surface pressure, then they were
  871. ! scaled by the eta levels.
  872. interp_type = 2
  873. lagrange_order = grid%lagrange_order
  874. lowest_lev_from_sfc = .FALSE.
  875. use_levels_below_ground = .TRUE.
  876. use_surface = .TRUE.
  877. zap_close_levels = grid%zap_close_levels
  878. force_sfc_in_vinterp = 0
  879. t_extrap_type = grid%t_extrap_type
  880. extrap_type = 1
  881. ! For the height field, the lowest level pressure is the slp (approximately "dry"). The
  882. ! lowest level of the input height field (to be associated with slp) then is an array
  883. ! of zeros.
  884. DO j = jts, MIN(jte,jde-1)
  885. DO i = its, MIN(ite,ide-1)
  886. grid%psfc_gc(i,j) = grid%pd_gc(i,1,j)
  887. grid%pd_gc(i,1,j) = grid%pslv_gc(i,j) - ( grid%p_gc(i,1,j) - grid%pd_gc(i,1,j) )
  888. grid%ht_gc(i,j) = grid%ght_gc(i,1,j)
  889. grid%ght_gc(i,1,j) = 0.
  890. END DO
  891. END DO
  892. CALL vert_interp ( grid%ght_gc , grid%pd_gc , grid%ph0 , grid%pb , &
  893. num_metgrid_levels , 'Z' , &
  894. interp_type , lagrange_order , extrap_type , &
  895. lowest_lev_from_sfc , use_levels_below_ground , use_surface , &
  896. zap_close_levels , force_sfc_in_vinterp , &
  897. ids , ide , jds , jde , kds , kde , &
  898. ims , ime , jms , jme , kms , kme , &
  899. its , ite , jts , jte , kts , kte )
  900. ! Put things back to normal.
  901. DO j = jts, MIN(jte,jde-1)
  902. DO i = its, MIN(ite,ide-1)
  903. IF ( skip_middle_points_t ( ids , ide , jds , jde , i , j , em_width , hold_ups ) ) CYCLE
  904. grid%pd_gc(i,1,j) = grid%psfc_gc(i,j)
  905. grid%ght_gc(i,1,j) = grid%ht_gc(i,j)
  906. END DO
  907. END DO
  908. END IF
  909. ! Now the rest of the variables on half-levels to inteprolate.
  910. CALL p_dry ( grid%mu0 , grid%znw , grid%p_top , grid%pb , want_half_levels , &
  911. ids , ide , jds , jde , kds , kde , &
  912. ims , ime , jms , jme , kms , kme , &
  913. its , ite , jts , jte , kts , kte )
  914. interp_type = grid%interp_type
  915. lagrange_order = grid%lagrange_order
  916. lowest_lev_from_sfc = grid%lowest_lev_from_sfc
  917. use_levels_below_ground = grid%use_levels_below_ground
  918. use_surface = grid%use_surface
  919. zap_close_levels = grid%zap_close_levels
  920. force_sfc_in_vinterp = grid%force_sfc_in_vinterp
  921. t_extrap_type = grid%t_extrap_type
  922. extrap_type = grid%extrap_type
  923. ! Interpolate RH, diagnose Qv later when have temp and pressure. Tempo

Large files files are truncated, but you can click here to view the full file