PageRenderTime 65ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/wrfv2_fire/dyn_nmm/module_initialize_real.F

http://github.com/jbeezley/wrf-fire
FORTRAN Legacy | 5238 lines | 3350 code | 960 blank | 928 comment | 103 complexity | 132c80bdb132b364e3d5f3f4a821dd15 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. ! This MODULE holds the routines which are used to perform various initializations
  3. ! for individual domains utilizing the NMM dynamical core.
  4. !-----------------------------------------------------------------------
  5. MODULE module_initialize_real
  6. USE module_bc
  7. USE module_configure
  8. USE module_domain
  9. USE module_io_domain
  10. USE module_model_constants
  11. ! USE module_si_io_nmm
  12. USE module_state_description
  13. USE module_timing
  14. USE module_soil_pre
  15. #ifdef DM_PARALLEL
  16. USE module_dm, ONLY : LOCAL_COMMUNICATOR &
  17. ,MYTASK,NTASKS,NTASKS_X &
  18. ,NTASKS_Y
  19. USE module_comm_dm
  20. USE module_ext_internal
  21. #endif
  22. INTEGER :: internal_time_loop
  23. INTEGER:: MPI_COMM_COMP,MYPE
  24. INTEGER:: loopinc, iloopinc
  25. CONTAINS
  26. !-------------------------------------------------------------------
  27. SUBROUTINE init_domain ( grid )
  28. IMPLICIT NONE
  29. ! Input space and data. No gridded meteorological data has been stored, though.
  30. ! TYPE (domain), POINTER :: grid
  31. TYPE (domain) :: grid
  32. ! Local data.
  33. INTEGER :: idum1, idum2
  34. CALL set_scalar_indices_from_config ( head_grid%id , idum1, idum2 )
  35. CALL init_domain_nmm (grid &
  36. !
  37. #include <actual_new_args.inc>
  38. !
  39. )
  40. END SUBROUTINE init_domain
  41. !-------------------------------------------------------------------
  42. !---------------------------------------------------------------------
  43. SUBROUTINE init_domain_nmm ( grid &
  44. !
  45. # include <dummy_new_args.inc>
  46. !
  47. )
  48. USE module_optional_input
  49. IMPLICIT NONE
  50. ! Input space and data. No gridded meteorological data has been stored, though.
  51. ! TYPE (domain), POINTER :: grid
  52. TYPE (domain) :: grid
  53. # include <dummy_new_decl.inc>
  54. TYPE (grid_config_rec_type) :: config_flags
  55. ! Local domain indices and counters.
  56. INTEGER :: num_veg_cat , num_soil_top_cat , num_soil_bot_cat
  57. INTEGER :: &
  58. ids, ide, jds, jde, kds, kde, &
  59. ims, ime, jms, jme, kms, kme, &
  60. its, ite, jts, jte, kts, kte, &
  61. ips, ipe, jps, jpe, kps, kpe, &
  62. i, j, k, NNXP, NNYP
  63. ! Local data
  64. CHARACTER(LEN=19):: start_date
  65. #ifdef DM_PARALLEL
  66. LOGICAL,EXTERNAL :: WRF_DM_ON_MONITOR
  67. logical :: test
  68. ! INTEGER :: DOMDESC
  69. REAL,ALLOCATABLE :: SICE_G(:,:), SM_G(:,:)
  70. INTEGER, ALLOCATABLE:: IHE_G(:),IHW_G(:)
  71. INTEGER, ALLOCATABLE:: ITEMP(:,:)
  72. INTEGER :: my_e,my_n,my_s,my_w,my_ne,my_nw,my_se,my_sw,myi,myj,npe
  73. INTEGER :: istat,inpes,jnpes
  74. #else
  75. integer, allocatable:: ihw(:),ihe(:)
  76. #endif
  77. CHARACTER (LEN=255) :: message
  78. INTEGER :: error
  79. REAL :: p_surf, p_level
  80. REAL :: cof1, cof2
  81. REAL :: qvf , qvf1 , qvf2 , pd_surf
  82. REAL :: p00 , t00 , a
  83. REAL :: hold_znw, rmin,rmax
  84. REAL :: p_top_requested , ptsgm
  85. INTEGER :: num_metgrid_levels, ICOUNT
  86. REAL , DIMENSION(max_eta) :: eta_levels
  87. LOGICAL :: stretch_grid, dry_sounding, debug, log_flag_sst, hyb_coor
  88. REAL, ALLOCATABLE,DIMENSION(:,:):: ADUM2D,SNOWC,HT,TG_ALT, &
  89. PDVP,PSFC_OUTV
  90. REAL, ALLOCATABLE,DIMENSION(:,:,:):: P3D_OUT,P3DV_OUT,P3DV_IN, &
  91. QTMP,QTMP2
  92. INTEGER, ALLOCATABLE, DIMENSION(:):: KHL2,KVL2,KHH2,KVH2, &
  93. KHLA,KHHA,KVLA,KVHA
  94. ! INTEGER, ALLOCATABLE, DIMENSION(:,:):: grid%lu_index
  95. REAL, ALLOCATABLE, DIMENSION(:):: DXJ,WPDARJ,CPGFUJ,CURVJ, &
  96. FCPJ,FDIVJ,EMJ,EMTJ,FADJ, &
  97. HDACJ,DDMPUJ,DDMPVJ
  98. REAL, ALLOCATABLE,DIMENSION(:),SAVE:: SG1,SG2,DSG1,DSG2, &
  99. SGML1,SGML2
  100. !-- Carsel and Parrish [1988]
  101. REAL , DIMENSION(100) :: lqmi
  102. integer iicount
  103. REAL:: TPH0D,TLM0D
  104. REAL:: TPH0,WB,SB,TDLM,TDPH
  105. REAL:: WBI,SBI,EBI,ANBI,STPH0,CTPH0
  106. REAL:: TSPH,DTAD,DTCF
  107. REAL:: ACDT,CDDAMP,DXP,FP
  108. REAL:: WBD,SBD
  109. REAL:: RSNOW,SNOFAC
  110. REAL, PARAMETER:: SALP=2.60
  111. REAL, PARAMETER:: SNUP=0.040
  112. REAL:: SMCSUM,STCSUM,SEAICESUM,FISX
  113. REAL:: cur_smc, aposs_smc
  114. REAL:: COAC, CODAMP
  115. INTEGER,PARAMETER:: DOUBLE=SELECTED_REAL_KIND(15,300)
  116. REAL(KIND=DOUBLE):: TERM1,APH,TLM,TPH,DLM,DPH,STPH,CTPH
  117. INTEGER:: KHH,KVH,JAM,JA, IHL, IHH, L
  118. INTEGER:: II,JJ,ISRCH,ISUM,ITER,Ilook,Jlook
  119. REAL, PARAMETER:: DTR=0.01745329
  120. REAL, PARAMETER:: W_NMM=0.08
  121. #if defined(HWRF)
  122. REAL, PARAMETER:: DDFC=1.0
  123. #else
  124. REAL, PARAMETER:: DDFC=8.0
  125. #endif
  126. REAL, PARAMETER:: TWOM=.00014584
  127. REAL, PARAMETER:: CP=1004.6
  128. REAL, PARAMETER:: DFC=1.0
  129. REAL, PARAMETER:: ROI=916.6
  130. REAL, PARAMETER:: R=287.04
  131. REAL, PARAMETER:: CI=2060.0
  132. REAL, PARAMETER:: ROS=1500.
  133. REAL, PARAMETER:: CS=1339.2
  134. REAL, PARAMETER:: DS=0.050
  135. REAL, PARAMETER:: AKS=.0000005
  136. REAL, PARAMETER:: DZG=2.85
  137. REAL, PARAMETER:: DI=.1000
  138. REAL, PARAMETER:: AKI=0.000001075
  139. REAL, PARAMETER:: DZI=2.0
  140. REAL, PARAMETER:: THL=210.
  141. REAL, PARAMETER:: PLQ=70000.
  142. REAL, PARAMETER:: ERAD=6371200.
  143. REAL, PARAMETER:: TG0=258.16
  144. REAL, PARAMETER:: TGA=30.0
  145. integer :: numzero,numexamined
  146. #ifdef HWRF
  147. !============================================================================
  148. ! gopal's doing for ocean coupling
  149. !============================================================================
  150. REAL, DIMENSION(:,:), ALLOCATABLE :: NHLAT,NHLON,NVLAT,NVLON,HRES_SM
  151. REAL :: NDLMD,NDPHD,NWBD,NSBD
  152. INTEGER :: NIDE,NJDE,ILOC,JLOC
  153. INTEGER fid, ierr, nprocs
  154. CHARACTER*255 f65name, SysString
  155. !============================================================================
  156. ! end gopal's doing for ocean coupling
  157. !============================================================================
  158. #endif
  159. if (ALLOCATED(ADUM2D)) DEALLOCATE(ADUM2D)
  160. if (ALLOCATED(TG_ALT)) DEALLOCATE(TG_ALT)
  161. !#define COPY_IN
  162. !#include <scalar_derefs.inc>
  163. #ifdef DM_PARALLEL
  164. # include <data_calls.inc>
  165. #endif
  166. SELECT CASE ( model_data_order )
  167. CASE ( DATA_ORDER_ZXY )
  168. kds = grid%sd31 ; kde = grid%ed31 ;
  169. ids = grid%sd32 ; ide = grid%ed32 ;
  170. jds = grid%sd33 ; jde = grid%ed33 ;
  171. kms = grid%sm31 ; kme = grid%em31 ;
  172. ims = grid%sm32 ; ime = grid%em32 ;
  173. jms = grid%sm33 ; jme = grid%em33 ;
  174. kts = grid%sp31 ; kte = grid%ep31 ; ! tile is entire patch
  175. its = grid%sp32 ; ite = grid%ep32 ; ! tile is entire patch
  176. jts = grid%sp33 ; jte = grid%ep33 ; ! tile is entire patch
  177. CASE ( DATA_ORDER_XYZ )
  178. ids = grid%sd31 ; ide = grid%ed31 ;
  179. jds = grid%sd32 ; jde = grid%ed32 ;
  180. kds = grid%sd33 ; kde = grid%ed33 ;
  181. ims = grid%sm31 ; ime = grid%em31 ;
  182. jms = grid%sm32 ; jme = grid%em32 ;
  183. kms = grid%sm33 ; kme = grid%em33 ;
  184. its = grid%sp31 ; ite = grid%ep31 ; ! tile is entire patch
  185. jts = grid%sp32 ; jte = grid%ep32 ; ! tile is entire patch
  186. kts = grid%sp33 ; kte = grid%ep33 ; ! tile is entire patch
  187. CASE ( DATA_ORDER_XZY )
  188. ids = grid%sd31 ; ide = grid%ed31 ;
  189. kds = grid%sd32 ; kde = grid%ed32 ;
  190. jds = grid%sd33 ; jde = grid%ed33 ;
  191. ims = grid%sm31 ; ime = grid%em31 ;
  192. kms = grid%sm32 ; kme = grid%em32 ;
  193. jms = grid%sm33 ; jme = grid%em33 ;
  194. its = grid%sp31 ; ite = grid%ep31 ; ! tile is entire patch
  195. kts = grid%sp32 ; kte = grid%ep32 ; ! tile is entire patch
  196. jts = grid%sp33 ; jte = grid%ep33 ; ! tile is entire patch
  197. END SELECT
  198. #ifdef DM_PARALLEL
  199. CALL WRF_GET_MYPROC(MYPE)
  200. CALL WRF_GET_DM_COMMUNICATOR(MPI_COMM_COMP)
  201. call wrf_get_nprocx(inpes)
  202. call wrf_get_nprocy(jnpes)
  203. !
  204. allocate(itemp(inpes,jnpes),stat=istat)
  205. npe=0
  206. !
  207. do j=1,jnpes
  208. do i=1,inpes
  209. itemp(i,j)=npe
  210. if(npe==mype)then
  211. myi=i
  212. myj=j
  213. endif
  214. npe=npe+1
  215. enddo
  216. enddo
  217. !
  218. my_n=-1
  219. if(myj+1<=jnpes)my_n=itemp(myi,myj+1)
  220. !
  221. my_e=-1
  222. if(myi+1<=inpes)my_e=itemp(myi+1,myj)
  223. !
  224. my_s=-1
  225. if(myj-1>=1)my_s=itemp(myi,myj-1)
  226. !
  227. my_w=-1
  228. if(myi-1>=1)my_w=itemp(myi-1,myj)
  229. !
  230. my_ne=-1
  231. if((myi+1<=inpes).and.(myj+1<=jnpes)) &
  232. my_ne=itemp(myi+1,myj+1)
  233. !
  234. my_se=-1
  235. if((myi+1<=inpes).and.(myj-1>=1)) &
  236. my_se=itemp(myi+1,myj-1)
  237. !
  238. my_sw=-1
  239. if((myi-1>=1).and.(myj-1>=1)) &
  240. my_sw=itemp(myi-1,myj-1)
  241. !
  242. my_nw=-1
  243. if((myi-1>=1).and.(myj+1<=jnpes)) &
  244. my_nw=itemp(myi-1,myj+1)
  245. !
  246. ! my_neb(1)=my_n
  247. ! my_neb(2)=my_e
  248. ! my_neb(3)=my_s
  249. ! my_neb(4)=my_w
  250. ! my_neb(5)=my_ne
  251. ! my_neb(6)=my_se
  252. ! my_neb(7)=my_sw
  253. ! my_neb(8)=my_nw
  254. !
  255. deallocate(itemp)
  256. #endif
  257. NNXP=min(ITE,IDE-1)
  258. NNYP=min(JTE,JDE-1)
  259. write(message,*) 'IDE, JDE: ', IDE,JDE
  260. write(message,*) 'NNXP, NNYP: ', NNXP,NNYP
  261. CALL wrf_message(message)
  262. JAM=6+2*(JDE-JDS-10)
  263. if (internal_time_loop .eq. 1) then
  264. ALLOCATE(ADUM2D(grid%sm31:grid%em31,jms:jme))
  265. ALLOCATE(KHL2(JTS:NNYP),KVL2(JTS:NNYP),KHH2(JTS:NNYP),KVH2(JTS:NNYP))
  266. ALLOCATE(DXJ(JTS:NNYP),WPDARJ(JTS:NNYP),CPGFUJ(JTS:NNYP),CURVJ(JTS:NNYP))
  267. ALLOCATE(FCPJ(JTS:NNYP),FDIVJ(JTS:NNYP),&
  268. FADJ(JTS:NNYP))
  269. ALLOCATE(HDACJ(JTS:NNYP),DDMPUJ(JTS:NNYP),DDMPVJ(JTS:NNYP))
  270. ALLOCATE(KHLA(JAM),KHHA(JAM))
  271. ALLOCATE(KVLA(JAM),KVHA(JAM))
  272. endif
  273. CALL model_to_grid_config_rec ( grid%id , model_config_rec , config_flags )
  274. IF ( CONFIG_FLAGS%FRACTIONAL_SEAICE == 1 ) THEN
  275. CALL WRF_ERROR_FATAL("NMM cannot use FRACTIONAL_SEAICE = 1")
  276. ENDIF
  277. if ( config_flags%bl_pbl_physics == BOULACSCHEME ) then
  278. call wrf_error_fatal("Cannot use BOULAC PBL with NMM")
  279. endif
  280. write(message,*) 'cen_lat: ', config_flags%cen_lat
  281. CALL wrf_debug(100,message)
  282. write(message,*) 'cen_lon: ', config_flags%cen_lon
  283. CALL wrf_debug(100,message)
  284. write(message,*) 'dx: ', config_flags%dx
  285. CALL wrf_debug(100,message)
  286. write(message,*) 'dy: ', config_flags%dy
  287. CALL wrf_debug(100,message)
  288. write(message,*) 'config_flags%start_year: ', config_flags%start_year
  289. CALL wrf_debug(100,message)
  290. write(message,*) 'config_flags%start_month: ', config_flags%start_month
  291. CALL wrf_debug(100,message)
  292. write(message,*) 'config_flags%start_day: ', config_flags%start_day
  293. CALL wrf_debug(100,message)
  294. write(message,*) 'config_flags%start_hour: ', config_flags%start_hour
  295. CALL wrf_debug(100,message)
  296. write(start_date,435) config_flags%start_year, config_flags%start_month, &
  297. config_flags%start_day, config_flags%start_hour
  298. 435 format(I4,'-',I2.2,'-',I2.2,'_',I2.2,':00:00')
  299. grid%dlmd=config_flags%dx
  300. grid%dphd=config_flags%dy
  301. tph0d=config_flags%cen_lat
  302. tlm0d=config_flags%cen_lon
  303. !==========================================================================
  304. !!
  305. ! Check to see if the boundary conditions are set
  306. ! properly in the namelist file.
  307. ! This checks for sufficiency and redundancy.
  308. CALL boundary_condition_check( config_flags, bdyzone, error, grid%id )
  309. ! Some sort of "this is the first time" initialization. Who knows.
  310. grid%itimestep=0
  311. ! Pull in the info in the namelist to compare it to the input data.
  312. grid%real_data_init_type = model_config_rec%real_data_init_type
  313. write(message,*) 'what is flag_metgrid: ', flag_metgrid
  314. CALL wrf_message(message)
  315. IF ( flag_metgrid .EQ. 1 ) THEN ! <----- START OF VERTICAL INTERPOLATION PART ---->
  316. num_metgrid_levels = grid%num_metgrid_levels
  317. IF (grid%ght_gc(its,jts,num_metgrid_levels/2) .lt. grid%ght_gc(its,jts,num_metgrid_levels/2+1)) THEN
  318. write(message,*) 'normal ground up file order'
  319. hyb_coor=.false.
  320. CALL wrf_message(message)
  321. ELSE
  322. hyb_coor=.true.
  323. write(message,*) 'reverse the order of coordinate'
  324. CALL wrf_message(message)
  325. CALL reverse_vert_coord(grid%ght_gc, 2, num_metgrid_levels &
  326. &, IDS,IDE,JDS,JDE,KDS,KDE &
  327. &, IMS,IME,JMS,JME,KMS,KME &
  328. &, ITS,ITE,JTS,JTE,KTS,KTE )
  329. #if defined(HWRF)
  330. if(.not. grid%use_prep_hybrid) then
  331. #endif
  332. CALL reverse_vert_coord(grid%p_gc, 2, num_metgrid_levels &
  333. &, IDS,IDE,JDS,JDE,KDS,KDE &
  334. &, IMS,IME,JMS,JME,KMS,KME &
  335. &, ITS,ITE,JTS,JTE,KTS,KTE )
  336. CALL reverse_vert_coord(grid%t_gc, 2, num_metgrid_levels &
  337. &, IDS,IDE,JDS,JDE,KDS,KDE &
  338. &, IMS,IME,JMS,JME,KMS,KME &
  339. &, ITS,ITE,JTS,JTE,KTS,KTE )
  340. CALL reverse_vert_coord(grid%u_gc, 2, num_metgrid_levels &
  341. &, IDS,IDE,JDS,JDE,KDS,KDE &
  342. &, IMS,IME,JMS,JME,KMS,KME &
  343. &, ITS,ITE,JTS,JTE,KTS,KTE )
  344. CALL reverse_vert_coord(grid%v_gc, 2, num_metgrid_levels &
  345. &, IDS,IDE,JDS,JDE,KDS,KDE &
  346. &, IMS,IME,JMS,JME,KMS,KME &
  347. &, ITS,ITE,JTS,JTE,KTS,KTE )
  348. CALL reverse_vert_coord(grid%rh_gc, 2, num_metgrid_levels &
  349. &, IDS,IDE,JDS,JDE,KDS,KDE &
  350. &, IMS,IME,JMS,JME,KMS,KME &
  351. &, ITS,ITE,JTS,JTE,KTS,KTE )
  352. #if defined(HWRF)
  353. endif
  354. #endif
  355. endif
  356. IF (hyb_coor) THEN
  357. ! limit extreme deviations from source model topography
  358. ! due to potential for nasty extrapolation/interpolation issues
  359. !
  360. write(message,*) 'min, max of grid%ht_gc before adjust: ', minval(grid%ht_gc), maxval(grid%ht_gc)
  361. CALL wrf_debug(100,message)
  362. ICOUNT=0
  363. DO J=JTS,min(JTE,JDE-1)
  364. DO I=ITS,min(ITE,IDE-1)
  365. IF ((grid%ht_gc(I,J) - grid%ght_gc(I,J,2)) .LT. -150.) THEN
  366. grid%ht_gc(I,J)=grid%ght_gc(I,J,2)-150.
  367. IF (ICOUNT .LT. 20) THEN
  368. write(message,*) 'increasing NMM topo toward RUC ', I,J
  369. CALL wrf_debug(100,message)
  370. ICOUNT=ICOUNT+1
  371. ENDIF
  372. ELSEIF ((grid%ht_gc(I,J) - grid%ght_gc(I,J,2)) .GT. 150.) THEN
  373. grid%ht_gc(I,J)=grid%ght_gc(I,J,2)+150.
  374. IF (ICOUNT .LT. 20) THEN
  375. write(message,*) 'decreasing NMM topo toward RUC ', I,J
  376. CALL wrf_debug(100,message)
  377. ICOUNT=ICOUNT+1
  378. ENDIF
  379. ENDIF
  380. END DO
  381. END DO
  382. write(message,*) 'min, max of ht_gc after correct: ', minval(grid%ht_gc), maxval(grid%ht_gc)
  383. CALL wrf_debug(100,message)
  384. ENDIF
  385. CALL boundary_smooth(grid%ht_gc,grid%landmask, grid, 12 , 12 &
  386. &, IDS,IDE,JDS,JDE,KDS,KDE &
  387. &, IMS,IME,JMS,JME,KMS,KME &
  388. &, ITS,ITE,JTS,JTE,KTS,KTE )
  389. DO j = jts, MIN(jte,jde-1)
  390. DO i = its, MIN(ite,ide-1)
  391. if (grid%landmask(I,J) .gt. 0.5) grid%sm(I,J)=0.
  392. if (grid%landmask(I,J) .le. 0.5) grid%sm(I,J)=1.
  393. if (grid%tsk_gc(I,J) .gt. 0.) then
  394. grid%nmm_tsk(I,J)=grid%tsk_gc(I,J)
  395. else
  396. #if defined(HWRF)
  397. if(grid%use_prep_hybrid) then
  398. if(grid%t(I,J,1)<100) then
  399. write(*,*) 'NO VALID SURFACE TEMPERATURE: I,J,TSK_GC(I,J),T(I,J,1) = ', &
  400. I,J,grid%TSK_GC(I,J),grid%T(I,J,1)
  401. else
  402. grid%nmm_tsk(I,J)=grid%t(I,J,1) ! stopgap measure
  403. end if
  404. else
  405. #endif
  406. grid%nmm_tsk(I,J)=grid%t_gc(I,J,1) ! stopgap measure
  407. #if defined(HWRF)
  408. endif
  409. #endif
  410. endif
  411. !
  412. grid%glat(I,J)=grid%hlat_gc(I,J)*DEGRAD
  413. grid%glon(I,J)=grid%hlon_gc(I,J)*DEGRAD
  414. grid%weasd(I,J)=grid%snow(I,J)
  415. grid%xice(I,J)=grid%xice_gc(I,J)
  416. ENDDO
  417. ENDDO
  418. ! First item is to define the target vertical coordinate
  419. num_metgrid_levels = grid%num_metgrid_levels
  420. eta_levels(1:kde) = model_config_rec%eta_levels(1:kde)
  421. ptsgm = model_config_rec%ptsgm
  422. p_top_requested = grid%p_top_requested
  423. grid%pt=p_top_requested
  424. if (internal_time_loop .eq. 1) then
  425. if (eta_levels(1) .ne. 1.0) then
  426. #if defined(HWRF)
  427. if(grid%use_prep_hybrid) then
  428. call wrf_error_fatal('PREP_HYBRID ERROR: eta_levels is not specified, but use_prep_hybrid=.true.')
  429. end if
  430. #endif
  431. write(message,*) '********************************************************************* '
  432. CALL wrf_message(message)
  433. write(message,*) '** eta_levels appears not to be specified in the namelist'
  434. CALL wrf_message(message)
  435. write(message,*) '** We will call compute_nmm_levels to define layer thicknesses.'
  436. CALL wrf_message(message)
  437. write(message,*) '** These levels should be reasonable for running the model, '
  438. CALL wrf_message(message)
  439. write(message,*) '** but may not be ideal for the simulation being made. Consider '
  440. CALL wrf_message(message)
  441. write(message,*) '** defining your own levels by specifying eta_levels in the model '
  442. CALL wrf_message(message)
  443. write(message,*) '** namelist. '
  444. CALL wrf_message(message)
  445. write(message,*) '********************************************************************** '
  446. CALL wrf_message(message)
  447. CALL compute_nmm_levels(KDE,p_top_requested,eta_levels)
  448. DO L=1,KDE
  449. write(message,*) 'L, eta_levels(L) returned :: ', L,eta_levels(L)
  450. CALL wrf_message(message)
  451. ENDDO
  452. endif
  453. write(message,*) 'KDE-1: ', KDE-1
  454. CALL wrf_debug(1,message)
  455. allocate(SG1(1:KDE-1))
  456. allocate(SG2(1:KDE-1))
  457. allocate(DSG1(1:KDE-1))
  458. allocate(DSG2(1:KDE-1))
  459. allocate(SGML1(1:KDE))
  460. allocate(SGML2(1:KDE))
  461. CALL define_nmm_vertical_coord (kde-1, ptsgm, grid%pt,grid%pdtop, eta_levels, &
  462. grid%eta1,grid%deta1,grid%aeta1, &
  463. grid%eta2,grid%deta2,grid%aeta2, grid%dfl, grid%dfrlg )
  464. DO L=KDS,KDE-1
  465. grid%deta(L)=eta_levels(L)-eta_levels(L+1)
  466. ENDDO
  467. endif
  468. write(message,*) 'num_metgrid_levels: ', num_metgrid_levels
  469. CALL wrf_message(message)
  470. DO j = jts, MIN(jte,jde-1)
  471. DO i = its, MIN(ite,ide-1)
  472. grid%fis(I,J)=grid%ht_gc(I,J)*g
  473. !
  474. ! IF ( grid%p_gc(I,J,1) .ne. 200100. .AND. (grid%ht_gc(I,J) .eq. grid%ght_gc(I,J,1)) .AND. grid%ht_gc(I,J) .ne. 0) THEN
  475. IF ( grid%p_gc(I,J,1) .ne. 200100. .AND. (abs(grid%ht_gc(I,J)-grid%ght_gc(I,J,1)) .lt. 0.01) .AND. grid%ht_gc(I,J) .ne. 0) THEN
  476. IF (mod(I,10) .eq. 0 .and. mod(J,10) .eq. 0) THEN
  477. write(message,*) 'grid%ht_gc and grid%toposoil to swap, flag_soilhgt ::: ', &
  478. I,J, grid%ht_gc(I,J),grid%toposoil(I,J),flag_soilhgt
  479. CALL wrf_debug(10,message)
  480. ENDIF
  481. IF ( ( flag_soilhgt.EQ. 1 ) ) THEN
  482. grid%ght_gc(I,J,1)=grid%toposoil(I,J)
  483. ENDIF
  484. ENDIF
  485. ENDDO
  486. ENDDO
  487. numzero=0
  488. numexamined=0
  489. DO j = jts, MIN(jte,jde-1)
  490. DO i = its, MIN(ite,ide-1)
  491. numexamined=numexamined+1
  492. if(grid%fis(i,j)<1e-5 .and. grid%fis(i,j)>-1e5 ) then
  493. numzero=numzero+1
  494. end if
  495. enddo
  496. enddo
  497. write(message,*) 'TOTAL NEAR-ZERO FIS POINTS: ',numzero,' OF ',numexamined
  498. call wrf_debug(10,message)
  499. #if defined(HWRF)
  500. interp_notph: if(.not. grid%use_prep_hybrid) then
  501. #endif
  502. if (.NOT. allocated(PDVP)) allocate(PDVP(IMS:IME,JMS:JME))
  503. if (.NOT. allocated(P3D_OUT)) allocate(P3D_OUT(IMS:IME,JMS:JME,KDS:KDE-1))
  504. if (.NOT. allocated(PSFC_OUTV)) allocate(PSFC_OUTV(IMS:IME,JMS:JME))
  505. if (.NOT. allocated(P3DV_OUT)) allocate(P3DV_OUT(IMS:IME,JMS:JME,KDS:KDE-1))
  506. if (.NOT. allocated(P3DV_IN)) allocate(P3DV_IN(IMS:IME,JMS:JME,num_metgrid_levels))
  507. CALL compute_nmm_surfacep (grid%ht_gc, grid%ght_gc, grid%p_gc , grid%t_gc &
  508. &, grid%psfc_out, num_metgrid_levels &
  509. &, IDS,IDE,JDS,JDE,KDS,KDE &
  510. &, IMS,IME,JMS,JME,KMS,KME &
  511. &, ITS,ITE,JTS,JTE,KTS,KTE ) ! H points
  512. if (internal_time_loop .eq. 1) then
  513. write(message,*) 'psfc points (final combined)'
  514. loopinc=max( (JTE-JTS)/20,1)
  515. iloopinc=max( (ITE-ITS)/10,1)
  516. CALL wrf_message(message)
  517. DO J=min(JTE,JDE-1),JTS,-loopinc
  518. write(message,633) (grid%psfc_out(I,J)/100.,I=its,min(ite,IDE-1),iloopinc)
  519. CALL wrf_message(message)
  520. ENDDO
  521. endif
  522. 633 format(35(f5.0,1x))
  523. CALL compute_3d_pressure (grid%psfc_out,grid%aeta1,grid%aeta2 &
  524. &, grid%pdtop,grid%pt,grid%pd,p3d_out &
  525. &, IDS,IDE,JDS,JDE,KDS,KDE &
  526. &, IMS,IME,JMS,JME,KMS,KME &
  527. &, ITS,ITE,JTS,JTE,KTS,KTE )
  528. #ifdef DM_PARALLEL
  529. ips=its ; ipe=ite ; jps=jts ; jpe=jte ; kps=kts ; kpe=kte
  530. # include "HALO_NMM_MG2.inc"
  531. #endif
  532. #ifdef DM_PARALLEL
  533. # include "HALO_NMM_MG3.inc"
  534. #endif
  535. do K=1,num_metgrid_levels
  536. do J=JTS,min(JTE,JDE-1)
  537. do I=ITS,min(ITE,IDE-1)
  538. IF (K .eq. KTS) THEN
  539. IF (J .eq. JDS .and. I .lt. IDE-1) THEN ! S boundary
  540. PDVP(I,J)=0.5*(grid%pd(I,J)+grid%pd(I+1,J))
  541. PSFC_OUTV(I,J)=0.5*(grid%psfc_out(I,J)+grid%psfc_out(I+1,J))
  542. ELSEIF (J .eq. JDE-1 .and. I .lt. IDE-1) THEN ! N boundary
  543. PDVP(I,J)=0.5*(grid%pd(I,J)+grid%pd(I+1,J))
  544. PSFC_OUTV(I,J)=0.5*(grid%psfc_out(I,J)+grid%psfc_out(I+1,J))
  545. ELSEIF (I .eq. IDS .and. mod(J,2) .eq. 0) THEN ! W boundary
  546. PDVP(I,J)=0.5*(grid%pd(I,J-1)+grid%pd(I,J+1))
  547. PSFC_OUTV(I,J)=0.5*(grid%psfc_out(I,J-1)+grid%psfc_out(I,J+1))
  548. ELSEIF (I .eq. IDE-1 .and. mod(J,2) .eq. 0) THEN ! E boundary
  549. PDVP(I,J)=0.5*(grid%pd(I,J-1)+grid%pd(I,J+1))
  550. PSFC_OUTV(I,J)=0.5*(grid%psfc_out(I,J-1)+grid%psfc_out(I,J+1))
  551. ELSEIF (I .eq. IDE-1 .and. mod(J,2) .eq. 1) THEN ! phantom E boundary
  552. PDVP(I,J)=grid%pd(I,J)
  553. PSFC_OUTV(I,J)=grid%psfc_out(I,J)
  554. ELSEIF (mod(J,2) .eq. 0) THEN ! interior even row
  555. PDVP(I,J)=0.25*(grid%pd(I,J)+grid%pd(I-1,J)+grid%pd(I,J+1)+grid%pd(I,J-1))
  556. PSFC_OUTV(I,J)=0.25*(grid%psfc_out(I,J)+grid%psfc_out(I-1,J)+ &
  557. grid%psfc_out(I,J+1)+grid%psfc_out(I,J-1))
  558. ELSE ! interior odd row
  559. PDVP(I,J)=0.25*(grid%pd(I,J)+grid%pd(I+1,J)+grid%pd(I,J+1)+grid%pd(I,J-1))
  560. PSFC_OUTV(I,J)=0.25*(grid%psfc_out(I,J)+grid%psfc_out(I+1,J)+ &
  561. grid%psfc_out(I,J+1)+grid%psfc_out(I,J-1))
  562. ENDIF
  563. ENDIF
  564. IF (J .eq. JDS .and. I .lt. IDE-1) THEN ! S boundary
  565. P3DV_IN(I,J,K)=0.5*(grid%p_gc(I,J,K)+grid%p_gc(I+1,J,K))
  566. ELSEIF (J .eq. JDE-1 .and. I .lt. IDE-1) THEN ! N boundary
  567. P3DV_IN(I,J,K)=0.5*(grid%p_gc(I,J,K)+grid%p_gc(I+1,J,K))
  568. ELSEIF (I .eq. IDS .and. mod(J,2) .eq. 0) THEN ! W boundary
  569. P3DV_IN(I,J,K)=0.5*(grid%p_gc(I,J-1,K)+grid%p_gc(I,J+1,K))
  570. ELSEIF (I .eq. IDE-1 .and. mod(J,2) .eq. 0) THEN ! E boundary
  571. P3DV_IN(I,J,K)=0.5*(grid%p_gc(I,J-1,K)+grid%p_gc(I,J+1,K))
  572. ELSEIF (I .eq. IDE-1 .and. mod(J,2) .eq. 1) THEN ! phantom E boundary
  573. P3DV_IN(I,J,K)=grid%p_gc(I,J,K)
  574. ELSEIF (mod(J,2) .eq. 0) THEN ! interior even row
  575. P3DV_IN(I,J,K)=0.25*(grid%p_gc(I,J,K)+grid%p_gc(I-1,J,K) + &
  576. grid%p_gc(I,J+1,K)+grid%p_gc(I,J-1,K))
  577. ELSE ! interior odd row
  578. P3DV_IN(I,J,K)=0.25*(grid%p_gc(I,J,K)+grid%p_gc(I+1,J,K) + &
  579. grid%p_gc(I,J+1,K)+grid%p_gc(I,J-1,K))
  580. ENDIF
  581. enddo
  582. enddo
  583. enddo
  584. CALL compute_3d_pressure (psfc_outv,grid%aeta1,grid%aeta2 &
  585. &, grid%pdtop,grid%pt,pdvp,p3dv_out &
  586. &, IDS,IDE,JDS,JDE,KDS,KDE &
  587. &, IMS,IME,JMS,JME,KMS,KME &
  588. &, ITS,ITE,JTS,JTE,KTS,KTE )
  589. CALL interp_press2press_lin(grid%p_gc, p3d_out &
  590. &, grid%t_gc, grid%t,num_metgrid_levels &
  591. &, .TRUE.,.TRUE.,.TRUE. & ! extrap, ignore_lowest, t_field
  592. &, IDS,IDE,JDS,JDE,KDS,KDE &
  593. &, IMS,IME,JMS,JME,KMS,KME &
  594. &, ITS,ITE,JTS,JTE,KTS,KTE, internal_time_loop )
  595. CALL interp_press2press_lin(p3dv_in, p3dv_out &
  596. &, grid%u_gc, grid%u,num_metgrid_levels &
  597. &, .FALSE.,.TRUE.,.FALSE. &
  598. &, IDS,IDE,JDS,JDE,KDS,KDE &
  599. &, IMS,IME,JMS,JME,KMS,KME &
  600. &, ITS,ITE,JTS,JTE,KTS,KTE, internal_time_loop )
  601. CALL interp_press2press_lin(p3dv_in, p3dv_out &
  602. &, grid%v_gc, grid%v,num_metgrid_levels &
  603. &, .FALSE.,.TRUE.,.FALSE. &
  604. &, IDS,IDE,JDS,JDE,KDS,KDE &
  605. &, IMS,IME,JMS,JME,KMS,KME &
  606. &, ITS,ITE,JTS,JTE,KTS,KTE, internal_time_loop )
  607. IF (hyb_coor) THEN
  608. CALL wind_adjust(p3dv_in,p3dv_out,grid%u_gc,grid%v_gc,grid%u,grid%v &
  609. &, num_metgrid_levels,5000. &
  610. &, IDS,IDE,JDS,JDE,KDS,KDE &
  611. &, IMS,IME,JMS,JME,KMS,KME &
  612. &, ITS,ITE,JTS,JTE,KTS,KTE )
  613. ENDIF
  614. ALLOCATE(qtmp(IMS:IME,JMS:JME,num_metgrid_levels))
  615. ALLOCATE(qtmp2(IMS:IME,JMS:JME,num_metgrid_levels))
  616. CALL rh_to_mxrat (grid%rh_gc, grid%t_gc, grid%p_gc, qtmp , .TRUE. , &
  617. ids , ide , jds , jde , 1 , num_metgrid_levels , &
  618. ims , ime , jms , jme , 1 , num_metgrid_levels , &
  619. its , ite , jts , jte , 1 , num_metgrid_levels )
  620. do K=1,num_metgrid_levels
  621. do J=JTS,min(JTE,JDE-1)
  622. do I=ITS,min(ITE,IDE-1)
  623. QTMP2(I,J,K)=QTMP(I,J,K)/(1.0+QTMP(I,J,K))
  624. end do
  625. end do
  626. end do
  627. CALL interp_press2press_log(grid%p_gc, p3d_out &
  628. &, QTMP2, grid%q,num_metgrid_levels &
  629. &, .FALSE.,.TRUE. &
  630. &, IDS,IDE,JDS,JDE,KDS,KDE &
  631. &, IMS,IME,JMS,JME,KMS,KME &
  632. &, ITS,ITE,JTS,JTE,KTS,KTE, internal_time_loop )
  633. IF (ALLOCATED(QTMP)) DEALLOCATE(QTMP)
  634. IF (ALLOCATED(QTMP)) DEALLOCATE(QTMP2)
  635. #if defined(HWRF)
  636. else ! we are using prep_hybrid
  637. ! Compute surface pressure:
  638. grid%psfc_out=grid%pdtop+grid%pd
  639. end if interp_notph
  640. #endif
  641. ! Get the monthly values interpolated to the current date
  642. ! for the traditional monthly
  643. ! fields of green-ness fraction and background grid%albedo.
  644. if (internal_time_loop .eq. 1 .or. config_flags%sst_update .eq. 1) then
  645. CALL monthly_interp_to_date ( grid%greenfrac_gc , current_date , grid%vegfra , &
  646. ids , ide , jds , jde , kds , kde , &
  647. ims , ime , jms , jme , kms , kme , &
  648. its , ite , jts , jte , kts , kte )
  649. CALL monthly_interp_to_date ( grid%albedo12m_gc , current_date , grid%albbck , &
  650. ids , ide , jds , jde , kds , kde , &
  651. ims , ime , jms , jme , kms , kme , &
  652. its , ite , jts , jte , kts , kte )
  653. ! Get the min/max of each i,j for the monthly green-ness fraction.
  654. CALL monthly_min_max ( grid%greenfrac_gc , grid%shdmin , grid%shdmax , &
  655. ids , ide , jds , jde , kds , kde , &
  656. ims , ime , jms , jme , kms , kme , &
  657. its , ite , jts , jte , kts , kte )
  658. ! The model expects the green-ness values in percent, not fraction.
  659. DO j = jts, MIN(jte,jde-1)
  660. DO i = its, MIN(ite,ide-1)
  661. !! grid%vegfra(i,j) = grid%vegfra(i,j) * 100.
  662. grid%shdmax(i,j) = grid%shdmax(i,j) * 100.
  663. grid%shdmin(i,j) = grid%shdmin(i,j) * 100.
  664. grid%vegfrc(I,J)=grid%vegfra(I,J)
  665. END DO
  666. END DO
  667. ! The model expects the albedo fields as
  668. ! a fraction, not a percent. Set the water values to 8%.
  669. DO j = jts, MIN(jte,jde-1)
  670. DO i = its, MIN(ite,ide-1)
  671. if (grid%albbck(i,j) .lt. 5.) then
  672. write(message,*) 'reset albedo to 8%... I,J,albbck:: ', I,J,grid%albbck(I,J)
  673. CALL wrf_debug(10,message)
  674. grid%albbck(I,J)=8.
  675. endif
  676. grid%albbck(i,j) = grid%albbck(i,j) / 100.
  677. grid%snoalb(i,j) = grid%snoalb(i,j) / 100.
  678. IF ( grid%landmask(i,j) .LT. 0.5 ) THEN
  679. grid%albbck(i,j) = 0.08
  680. grid%snoalb(i,j) = 0.08
  681. END IF
  682. grid%albase(i,j)=grid%albbck(i,j)
  683. grid%mxsnal(i,j)=grid%snoalb(i,j)
  684. END DO
  685. END DO
  686. endif
  687. #if defined(HWRF)
  688. if(.not.grid%use_prep_hybrid) then
  689. #endif
  690. ! new deallocs
  691. DEALLOCATE(p3d_out,p3dv_out,p3dv_in)
  692. #if defined(HWRF)
  693. end if
  694. #endif
  695. END IF ! <----- END OF VERTICAL INTERPOLATION PART ---->
  696. !! compute SST at each time if updating SST
  697. if (config_flags%sst_update == 1) then
  698. DO j = jts, MIN(jde-1,jte)
  699. DO i = its, MIN(ide-1,ite)
  700. if (grid%SM(I,J) .lt. 0.5) then
  701. grid%SST(I,J)=0.
  702. endif
  703. if (grid%SM(I,J) .gt. 0.5) then
  704. grid%SST(I,J)=grid%NMM_TSK(I,J)
  705. grid%NMM_TSK(I,J)=0.
  706. endif
  707. IF ( (grid%NMM_TSK(I,J)+grid%SST(I,J)) .lt. 200. .or. &
  708. (grid%NMM_TSK(I,J)+grid%SST(I,J)) .gt. 350. ) THEN
  709. write(message,*) 'TSK, SST trouble at : ', I,J
  710. CALL wrf_message(message)
  711. write(message,*) 'SM, NMM_TSK,SST ', grid%SM(I,J),grid%NMM_TSK(I,J),grid%SST(I,J)
  712. CALL wrf_message(message)
  713. ENDIF
  714. ENDDO
  715. ENDDO
  716. endif ! sst_update test
  717. if (internal_time_loop .eq. 1) then
  718. !!! weasd has "snow water equivalent" in mm
  719. DO j = jts, MIN(jte,jde-1)
  720. DO i = its, MIN(ite,ide-1)
  721. IF(grid%sm(I,J).GT.0.9) THEN
  722. IF (grid%xice(I,J) .gt. 0) then
  723. grid%si(I,J)=1.0
  724. ENDIF
  725. ! SEA
  726. grid%epsr(I,J)=.97
  727. grid%embck(I,J)=.97
  728. grid%gffc(I,J)=0.
  729. grid%albedo(I,J)=.06
  730. grid%albase(I,J)=.06
  731. IF(grid%si (I,J).GT.0. ) THEN
  732. ! SEA-ICE
  733. grid%sm(I,J)=0.
  734. grid%si(I,J)=0.
  735. grid%sice(I,J)=1.
  736. grid%gffc(I,J)=0. ! just leave zero as irrelevant
  737. grid%albedo(I,J)=.60
  738. grid%albase(I,J)=.60
  739. ENDIF
  740. ELSE
  741. grid%si(I,J)=5.0*grid%weasd(I,J)/1000.
  742. ! LAND
  743. grid%epsr(I,J)=1.0
  744. grid%embck(I,J)=1.0
  745. grid%gffc(I,J)=0.0 ! just leave zero as irrelevant
  746. grid%sice(I,J)=0.
  747. grid%sno(I,J)=grid%si(I,J)*.20
  748. ENDIF
  749. ENDDO
  750. ENDDO
  751. ! DETERMINE grid%albedo OVER LAND
  752. DO j = jts, MIN(jte,jde-1)
  753. DO i = its, MIN(ite,ide-1)
  754. IF(grid%sm(I,J).LT.0.9.AND.grid%sice(I,J).LT.0.9) THEN
  755. ! SNOWFREE albedo
  756. IF ( (grid%sno(I,J) .EQ. 0.0) .OR. &
  757. (grid%albase(I,J) .GE. grid%mxsnal(I,J) ) ) THEN
  758. grid%albedo(I,J) = grid%albase(I,J)
  759. ELSE
  760. ! MODIFY albedo IF SNOWCOVER:
  761. ! BELOW SNOWDEPTH THRESHOLD...
  762. IF (grid%sno(I,J) .LT. SNUP) THEN
  763. RSNOW = grid%sno(I,J)/SNUP
  764. SNOFAC = 1. - ( EXP(-SALP*RSNOW) - RSNOW*EXP(-SALP))
  765. ! ABOVE SNOWDEPTH THRESHOLD...
  766. ELSE
  767. SNOFAC = 1.0
  768. ENDIF
  769. ! CALCULATE grid%albedo ACCOUNTING FOR SNOWDEPTH AND VGFRCK
  770. grid%albedo(I,J) = grid%albase(I,J) &
  771. + (1.0-grid%vegfra(I,J))*SNOFAC*(grid%mxsnal(I,J)-grid%albase(I,J))
  772. ENDIF
  773. END IF
  774. grid%si(I,J)=5.0*grid%weasd(I,J)
  775. grid%sno(I,J)=grid%weasd(I,J)
  776. !! convert vegfra
  777. grid%vegfra(I,J)=grid%vegfra(I,J)*100.
  778. !
  779. ENDDO
  780. ENDDO
  781. #ifdef DM_PARALLEL
  782. ALLOCATE(SM_G(IDS:IDE,JDS:JDE),SICE_G(IDS:IDE,JDS:JDE))
  783. CALL WRF_PATCH_TO_GLOBAL_REAL( grid%sice(IMS,JMS) &
  784. &, SICE_G,grid%DOMDESC &
  785. &, 'z','xy' &
  786. &, IDS,IDE-1,JDS,JDE-1,1,1 &
  787. &, IMS,IME,JMS,JME,1,1 &
  788. &, ITS,ITE,JTS,JTE,1,1 )
  789. CALL WRF_PATCH_TO_GLOBAL_REAL( grid%sm(IMS,JMS) &
  790. &, SM_G,grid%DOMDESC &
  791. &, 'z','xy' &
  792. &, IDS,IDE-1,JDS,JDE-1,1,1 &
  793. &, IMS,IME,JMS,JME,1,1 &
  794. &, ITS,ITE,JTS,JTE,1,1 )
  795. IF (WRF_DM_ON_MONITOR()) THEN
  796. 637 format(40(f3.0,1x))
  797. allocate(IHE_G(JDS:JDE-1),IHW_G(JDS:JDE-1))
  798. DO j = JDS, JDE-1
  799. IHE_G(J)=MOD(J+1,2)
  800. IHW_G(J)=IHE_G(J)-1
  801. ENDDO
  802. DO ITER=1,10
  803. DO j = jds+1, (jde-1)-1
  804. DO i = ids+1, (ide-1)-1
  805. ! any sea ice around point in question?
  806. IF (SM_G(I,J) .ge. 0.9) THEN
  807. SEAICESUM=SICE_G(I+IHE_G(J),J+1)+SICE_G(I+IHW_G(J),J+1)+ &
  808. SICE_G(I+IHE_G(J),J-1)+SICE_G(I+IHW_G(J),J-1)
  809. IF (SEAICESUM .ge. 1. .and. SEAICESUM .lt. 3.) THEN
  810. IF ((SICE_G(I+IHE_G(J),J+1).lt.0.1 .and. SM_G(I+IHE_G(J),J+1).lt.0.1) .OR. &
  811. (SICE_G(I+IHW_G(J),J+1).lt.0.1 .and. SM_G(I+IHW_G(J),J+1).lt.0.1) .OR. &
  812. (SICE_G(I+IHE_G(J),J-1).lt.0.1 .and. SM_G(I+IHE_G(J),J-1).lt.0.1) .OR. &
  813. (SICE_G(I+IHW_G(J),J-1).lt.0.1 .and. SM_G(I+IHW_G(J),J-1).lt.0.1)) THEN
  814. ! HAVE SEA ICE AND A SURROUNDING LAND POINT - CONVERT TO SEA ICE
  815. write(message,*) 'making seaice (1): ', I,J
  816. CALL wrf_debug(100,message)
  817. SICE_G(I,J)=1.0
  818. SM_G(I,J)=0.
  819. ENDIF
  820. ELSEIF (SEAICESUM .ge. 3) THEN
  821. ! WATER POINT SURROUNDED BY ICE - CONVERT TO SEA ICE
  822. write(message,*) 'making seaice (2): ', I,J
  823. CALL wrf_debug(100,message)
  824. SICE_G(I,J)=1.0
  825. SM_G(I,J)=0.
  826. ENDIF
  827. ENDIF
  828. ENDDO
  829. ENDDO
  830. ENDDO
  831. ENDIF
  832. CALL WRF_GLOBAL_TO_PATCH_REAL( SICE_G, grid%sice &
  833. &, grid%DOMDESC &
  834. &, 'z','xy' &
  835. &, IDS,IDE-1,JDS,JDE-1,1,1 &
  836. &, IMS,IME,JMS,JME,1,1 &
  837. &, ITS,ITE,JTS,JTE,1,1 )
  838. CALL WRF_GLOBAL_TO_PATCH_REAL( SM_G,grid%sm &
  839. &, grid%DOMDESC &
  840. &, 'z','xy' &
  841. &, IDS,IDE-1,JDS,JDE-1,1,1 &
  842. &, IMS,IME,JMS,JME,1,1 &
  843. &, ITS,ITE,JTS,JTE,1,1 )
  844. IF (WRF_DM_ON_MONITOR()) THEN
  845. #if defined(HWRF)
  846. ! SM_G is still needed for the high-res grid
  847. #else
  848. DEALLOCATE(SM_G)
  849. #endif
  850. deallocate(SICE_G)
  851. DEALLOCATE(IHE_G,IHW_G)
  852. ENDIF
  853. ! write(message,*) 'revised sea ice on patch'
  854. ! CALL wrf_debug(100,message)
  855. ! DO J=JTE,JTS,-(((JTE-JTS)/25)+1)
  856. ! write(message,637) (grid%sice(I,J),I=ITS,ITE,ITE/20)
  857. ! CALL wrf_debug(100,message)
  858. ! END DO
  859. #else
  860. ! serial sea ice reprocessing
  861. allocate(IHE(JDS:JDE-1),IHW(JDS:JDE-1))
  862. DO j = jts, MIN(jte,jde-1)
  863. IHE(J)=MOD(J+1,2)
  864. IHW(J)=IHE(J)-1
  865. ENDDO
  866. DO ITER=1,10
  867. DO j = jts+1, MIN(jte,jde-1)-1
  868. DO i = its+1, MIN(ite,ide-1)-1
  869. ! any sea ice around point in question?
  870. IF (grid%sm(I,J) .gt. 0.9) THEN
  871. SEAICESUM=grid%sice(I+IHE(J),J+1)+grid%sice(I+IHW(J),J+1)+ &
  872. grid%sice(I+IHE(J),J-1)+grid%sice(I+IHW(J),J-1)
  873. IF (SEAICESUM .ge. 1. .and. SEAICESUM .lt. 3.) THEN
  874. IF ((grid%sice(I+IHE(J),J+1).lt.0.1 .and. grid%sm(I+IHE(J),J+1).lt.0.1) .OR. &
  875. (grid%sice(I+IHW(J),J+1).lt.0.1 .and. grid%sm(I+IHW(J),J+1).lt.0.1) .OR. &
  876. (grid%sice(I+IHE(J),J-1).lt.0.1 .and. grid%sm(I+IHE(J),J-1).lt.0.1) .OR. &
  877. (grid%sice(I+IHW(J),J-1).lt.0.1 .and. grid%sm(I+IHW(J),J-1).lt.0.1)) THEN
  878. ! HAVE SEA ICE AND A SURROUNDING LAND POINT - CONVERT TO SEA ICE
  879. grid%sice(I,J)=1.0
  880. grid%sm(I,J)=0.
  881. ENDIF
  882. ELSEIF (SEAICESUM .ge. 3) THEN
  883. ! WATER POINT SURROUNDED BY ICE - CONVERT TO SEA ICE
  884. grid%sice(I,J)=1.0
  885. grid%sm(I,J)=0.
  886. ENDIF
  887. ENDIF
  888. ENDDO
  889. ENDDO
  890. ENDDO
  891. DEALLOCATE(IHE,IHW)
  892. #endif
  893. ! this block meant to guarantee land/sea agreement between sm and landmask
  894. DO j = jts, MIN(jte,jde-1)
  895. DO i = its, MIN(ite,ide-1)
  896. IF (grid%sm(I,J) .gt. 0.5) THEN
  897. grid%landmask(I,J)=0.0
  898. ELSEIF (grid%sm(I,J) .lt. 0.5 .and. grid%sice(I,J) .gt. 0.9) then
  899. grid%landmask(I,J)=0.0
  900. ELSEIF (grid%sm(I,J) .lt. 0.5 .and. grid%sice(I,J) .lt. 0.1) then
  901. grid%landmask(I,J)=1.0
  902. ELSE
  903. write(message,*) 'missed point in grid%landmask definition ' , I,J
  904. CALL wrf_message(message)
  905. grid%landmask(I,J)=0.0
  906. ENDIF
  907. !
  908. IF (grid%sice(I,J) .gt. 0.5 .and. grid%nmm_tsk(I,J) .lt. 0.1 .and. grid%sst(I,J) .gt. 0.) THEN
  909. write(message,*) 'set grid%nmm_tsk to: ', grid%sst(I,J)
  910. CALL wrf_message(message)
  911. grid%nmm_tsk(I,J)=grid%sst(I,J)
  912. grid%sst(I,J)=0.
  913. endif
  914. ENDDO
  915. ENDDO
  916. ! For sf_surface_physics = 1, we want to use close to a 10 cm value
  917. ! for the bottom level of the soil temps.
  918. IF ( ( model_config_rec%sf_surface_physics(grid%id) .EQ. 1 ) .AND. &
  919. ( flag_st000010 .EQ. 1 ) ) THEN
  920. DO j = jts , MIN(jde-1,jte)
  921. DO i = its , MIN(ide-1,ite)
  922. grid%soiltb(i,j) = grid%st000010(i,j)
  923. END DO
  924. END DO
  925. END IF
  926. ! Adjust the various soil temperature values depending on the difference in
  927. ! in elevation between the current model's elevation and the incoming data's
  928. ! orography.
  929. IF ( ( flag_toposoil .EQ. 1 ) ) THEN
  930. ALLOCATE(HT(ims:ime,jms:jme))
  931. DO J=jms,jme
  932. DO I=ims,ime
  933. HT(I,J)=grid%fis(I,J)/9.81
  934. END DO
  935. END DO
  936. ! if (maxval(grid%toposoil) .gt. 100.) then
  937. !
  938. ! Being avoided. Something to revisit eventually.
  939. !
  940. !1219 might be simply a matter of including toposoil
  941. !
  942. ! CODE NOT TESTED AT NCEP USING THIS FUNCTIONALITY,
  943. ! SO TO BE SAFE WILL AVOID FOR RETRO RUNS.
  944. !
  945. ! CALL adjust_soil_temp_new ( grid%soiltb , 2 , &
  946. ! grid%nmm_tsk , ht , grid%toposoil , grid%landmask, flag_toposoil , &
  947. ! grid%st000010 , st010040 , st040100 , st100200 , st010200 , &
  948. ! flag_st000010 , flag_st010040 , flag_st040100 , &
  949. ! flag_st100200 , flag_st010200 , &
  950. ! soilt000 , soilt005 , soilt020 , soilt040 , &
  951. ! soilt160 , soilt300 , &
  952. ! flag_soilt000 , flag_soilt005 , flag_soilt020 , &
  953. ! flag_soilt040 , flag_soilt160 , flag_soilt300 , &
  954. ! ids , ide , jds , jde , kds , kde , &
  955. ! ims , ime , jms , jme , kms , kme , &
  956. ! its , ite , jts , jte , kts , kte )
  957. ! endif
  958. END IF
  959. ! Process the LSM data.
  960. ! surface_input_source=1 => use data from static file
  961. ! (fractional category as input)
  962. ! surface_input_source=2 => use data from grib file
  963. ! (dominant category as input)
  964. IF ( config_flags%surface_input_source .EQ. 1 ) THEN
  965. grid%vegcat (its,jts) = 0
  966. grid%soilcat(its,jts) = 0
  967. END IF
  968. ! Generate the vegetation and soil category information
  969. ! from the fractional input
  970. ! data, or use the existing dominant category fields if they exist.
  971. IF ((grid%soilcat(its,jts) .LT. 0.5) .AND. (grid%vegcat(its,jts) .LT. 0.5)) THEN
  972. num_veg_cat = SIZE ( grid%landusef_gc , DIM=3 )
  973. num_soil_top_cat = SIZE ( grid%soilctop_gc , DIM=3 )
  974. num_soil_bot_cat = SIZE ( grid%soilcbot_gc , DIM=3 )
  975. do J=JMS,JME
  976. do K=1,num_veg_cat
  977. do I=IMS,IME
  978. grid%landusef(I,K,J)=grid%landusef_gc(I,J,K)
  979. enddo
  980. enddo
  981. enddo
  982. do J=JMS,JME
  983. do K=1,num_soil_top_cat
  984. do I=IMS,IME
  985. grid%soilctop(I,K,J)=grid%soilctop_gc(I,J,K)
  986. enddo
  987. enddo
  988. enddo
  989. do J=JMS,JME
  990. do K=1,num_soil_bot_cat
  991. do I=IMS,IME
  992. grid%soilcbot(I,K,J)=grid%soilcbot_gc(I,J,K)
  993. enddo
  994. enddo
  995. enddo
  996. ! grid%sm (1=water, 0=land)
  997. ! grid%landmask(0=water, 1=land)
  998. write(message,*) 'landmask into process_percent_cat_new'
  999. CALL wrf_debug(1,message)
  1000. do J=JTE,JTS,-(((JTE-JTS)/20)+1)
  1001. write(message,641) (grid%landmask(I,J),I=ITS,min(ITE,IDE-1),((ITE-ITS)/15)+1)
  1002. CALL wrf_debug(1,message)
  1003. enddo
  1004. 641 format(25(f3.0,1x))
  1005. CALL process_percent_cat_new ( grid%landmask , &
  1006. grid%landusef , grid%soilctop , grid%soilcbot , &
  1007. grid%isltyp , grid%ivgtyp , &
  1008. num_veg_cat , num_soil_top_cat , num_soil_bot_cat , &
  1009. ids , ide , jds , jde , kds , kde , &
  1010. ims , ime , jms , jme , kms , kme , &
  1011. its , ite , jts , jte , kts , kte , &
  1012. model_config_rec%iswater(grid%id) )
  1013. DO j = jts , MIN(jde-1,jte)
  1014. DO i = its , MIN(ide-1,ite)
  1015. grid%vegcat(i,j) = grid%ivgtyp(i,j)
  1016. grid%soilcat(i,j) = grid%isltyp(i,j)
  1017. END DO
  1018. END DO
  1019. ELSE
  1020. ! Do we have dominant soil and veg data from the input already?
  1021. IF ( grid%soilcat(its,jts) .GT. 0.5 ) THEN
  1022. DO j = jts, MIN(jde-1,jte)
  1023. DO i = its, MIN(ide-1,ite)
  1024. grid%isltyp(i,j) = NINT( grid%soilcat(i,j) )
  1025. END DO
  1026. END DO
  1027. END IF
  1028. IF ( grid%vegcat(its,jts) .GT. 0.5 ) THEN
  1029. DO j = jts, MIN(jde-1,jte)
  1030. DO i = its, MIN(ide-1,ite)
  1031. grid%ivgtyp(i,j) = NINT( grid%vegcat(i,j) )
  1032. END DO
  1033. END DO
  1034. END IF
  1035. ENDIF
  1036. DO j = jts, MIN(jde-1,jte)
  1037. DO i = its, MIN(ide-1,ite)
  1038. IF (grid%sice(I,J) .lt. 0.1) THEN
  1039. IF (grid%landmask(I,J) .gt. 0.5 .and. grid%sm(I,J) .gt. 0.5) THEN
  1040. write(message,*) 'land mask and grid%sm both > 0.5: ', &
  1041. I,J,grid%landmask(I,J),grid%sm(I,J)
  1042. CALL wrf_message(message)
  1043. grid%sm(I,J)=0.
  1044. ELSEIF (grid%landmask(I,J) .lt. 0.5 .and. grid%sm(I,J) .lt. 0.5) THEN
  1045. write(message,*) 'land mask and grid%sm both < 0.5: ', &
  1046. I,J, grid%landmask(I,J),grid%sm(I,J)
  1047. CALL wrf_message(message)
  1048. grid%sm(I,J)=1.
  1049. ENDIF
  1050. ELSE
  1051. IF (grid%landmask(I,J) .gt. 0.5 .and. grid%sm(I,J)+grid%sice(I,J) .gt. 0.9) then
  1052. write(message,*) 'landmask says LAND, sm/sice say SEAICE: ', I,J
  1053. ENDIF
  1054. ENDIF
  1055. ENDDO
  1056. ENDDO
  1057. DO j = jts, MIN(jde-1,jte)
  1058. DO i = its, MIN(ide-1,ite)
  1059. if (grid%sice(I,J) .gt. 0.9) then
  1060. grid%isltyp(I,J)=16
  1061. grid%ivgtyp(I,J)=24
  1062. endif
  1063. ENDDO
  1064. ENDDO
  1065. DO j = jts, MIN(jde-1,jte)
  1066. DO i = its, MIN(ide-1,ite)
  1067. if (grid%sm(I,J) .lt. 0.5) then
  1068. grid%sst(I,J)=0.
  1069. endif
  1070. if (grid%sm(I,J) .gt. 0.5) then
  1071. if (grid%sst(I,J) .lt. 0.1) then
  1072. grid%sst(I,J)=grid%nmm_tsk(I,J)
  1073. endif
  1074. grid%nmm_tsk(I,J)=0.
  1075. endif
  1076. IF ( (grid%nmm_tsk(I,J)+grid%sst(I,J)) .lt. 200. .or. &
  1077. (grid%nmm_tsk(I,J)+grid%sst(I,J)) .gt. 350. ) THEN
  1078. write(message,*) 'TSK, sst trouble at : ', I,J
  1079. CALL wrf_message(message)
  1080. write(message,*) 'sm, nmm_tsk,sst ', grid%sm(I,J),grid%nmm_tsk(I,J),grid%sst(I,J)
  1081. CALL wrf_message(message)
  1082. ENDIF
  1083. ENDDO
  1084. ENDDO
  1085. write(message,*) 'grid%sm'
  1086. CALL wrf_message(message)
  1087. DO J=min(jde-1,jte),jts,-((jte-jts)/15+1)
  1088. write(message,635) (grid%sm(i,J),I=its,ite,((ite-its)/10)+1)
  1089. CALL wrf_message(message)
  1090. END DO
  1091. write(message,*) 'sst/nmm_tsk'
  1092. CALL wrf_debug(10,message)
  1093. DO J=min(jde-1,jte),jts,-((jte-jts)/15+1)
  1094. write(message,635) (grid%sst(I,J)+grid%nmm_tsk(I,J),I=ITS,min(ide-1,ite),((ite-its)/10)+1)
  1095. CALL wrf_debug(10,message)
  1096. END DO
  1097. 635 format(20(f5.1,1x))
  1098. DO j = jts, MIN(jde-1,jte)
  1099. DO i = its, MIN(ide-1,ite)
  1100. IF ( ( grid%landmask(i,j) .LT. 0.5 ) .AND. ( flag_sst .EQ. 1 ) ) THEN
  1101. grid%soiltb(i,j) = grid%sst(i,j)
  1102. ELSE IF ( grid%landmask(i,j) .GT. 0.5 ) THEN
  1103. grid%soiltb(i,j) = grid%nmm_tsk(i,j)
  1104. END IF
  1105. END DO
  1106. END DO
  1107. ! END IF
  1108. ! Land use categories, dominant soil and vegetation types (if available).
  1109. ! allocate(grid%lu_index(ims:ime,jms:jme))
  1110. DO j = jts, MIN(jde-1,jte)
  1111. DO i = its, MIN(ide-1,ite)
  1112. grid%lu_index(i,j) = grid%ivgtyp(i,j)
  1113. END DO
  1114. END DO
  1115. if (flag_sst .eq. 1) log_flag_sst=.true.
  1116. if (flag_sst .eq. 0) log_flag_sst=.false.
  1117. write(message,*) 'st_input dimensions: ', size(st_input,dim=1), &
  1118. size(st_input,dim=2),size(st_input,dim=3)
  1119. CALL wrf_debug(100,message)
  1120. ! write(message,*) 'maxval st_input(1): ', maxval(st_input(:,1,:))
  1121. ! CALL wrf_message(message)
  1122. ! write(message,*) 'maxval st_input(2): ', maxval(st_input(:,2,:))
  1123. ! CALL wrf_message(message)
  1124. ! write(message,*) 'maxval st_input(3): ', maxval(st_input(:,3,:))
  1125. ! CALL wrf_message(message)
  1126. ! write(message,*) 'maxval st_input(4): ', maxval(st_input(:,4,:))
  1127. ! CALL wrf_message(message)
  1128. ! =============================================================
  1129. IF (.NOT. ALLOCATED(TG_ALT))ALLOCATE(TG_ALT(grid%sm31:grid%em31,jms:jme))
  1130. TPH0=TPH0D*DTR
  1131. WBD=-(((ide-1)-1)*grid%dlmd)
  1132. WB= WBD*DTR
  1133. SBD=-(((jde-1)/2)*grid%dphd)
  1134. SB= SBD*DTR
  1135. DLM=grid%dlmd*DTR
  1136. DPH=grid%dp

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