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

/wrfv2_fire/main/ndown_em.F

http://github.com/jbeezley/wrf-fire
FORTRAN Legacy | 2059 lines | 1235 code | 364 blank | 460 comment | 24 complexity | 8de7c7fb44afcf03ef9273f44114eb38 MD5 | raw file
Possible License(s): AGPL-1.0
  1. !WRF:DRIVER_LAYER:MAIN
  2. !
  3. PROGRAM ndown_em
  4. USE module_machine
  5. USE module_domain, ONLY : domain, head_grid, alloc_and_configure_domain, &
  6. domain_clock_set, domain_clock_get, get_ijk_from_grid
  7. USE module_domain_type, ONLY : program_name
  8. USE module_initialize_real, ONLY : wrfu_initialize, rebalance_driver
  9. USE module_integrate
  10. USE module_driver_constants
  11. USE module_configure, ONLY : grid_config_rec_type, model_config_rec
  12. USE module_io_domain
  13. USE module_utility
  14. USE module_check_a_mundo
  15. USE module_timing
  16. USE module_wrf_error
  17. #ifdef DM_PARALLEL
  18. USE module_dm
  19. #endif
  20. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  21. !new for bc
  22. USE module_bc
  23. USE module_big_step_utilities_em
  24. USE module_get_file_names
  25. #ifdef WRF_CHEM
  26. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  27. ! for chemistry
  28. USE module_input_chem_data
  29. ! USE module_input_chem_bioemiss
  30. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  31. #endif
  32. IMPLICIT NONE
  33. ! interface
  34. INTERFACE
  35. ! mediation-supplied
  36. SUBROUTINE med_read_wrf_chem_bioemiss ( grid , config_flags)
  37. USE module_domain
  38. TYPE (domain) grid
  39. TYPE (grid_config_rec_type) config_flags
  40. END SUBROUTINE med_read_wrf_chem_bioemiss
  41. SUBROUTINE init_domain_constants_em_ptr ( parent , nest )
  42. USE module_domain
  43. USE module_configure
  44. TYPE(domain), POINTER :: parent , nest
  45. END SUBROUTINE init_domain_constants_em_ptr
  46. SUBROUTINE vertical_interp (nested_grid,znw_c,znu_c,cf1_c,cf2_c,cf3_c,cfn_c,cfn1_c,k_dim_c)
  47. USE module_domain
  48. USE module_configure
  49. TYPE(domain), POINTER :: nested_grid
  50. INTEGER , INTENT (IN) :: k_dim_c
  51. REAL , INTENT (IN) :: cf1_c,cf2_c,cf3_c,cfn_c,cfn1_c
  52. REAL , DIMENSION(k_dim_c) , INTENT (IN) :: znw_c,znu_c
  53. END SUBROUTINE vertical_interp
  54. END INTERFACE
  55. INTEGER :: ids , ide , jds , jde , kds , kde
  56. INTEGER :: ims , ime , jms , jme , kms , kme
  57. INTEGER :: ips , ipe , jps , jpe , kps , kpe
  58. INTEGER :: its , ite , jts , jte , kts , kte
  59. INTEGER :: nids, nide, njds, njde, nkds, nkde, &
  60. nims, nime, njms, njme, nkms, nkme, &
  61. nips, nipe, njps, njpe, nkps, nkpe
  62. INTEGER :: spec_bdy_width
  63. INTEGER :: i , j , k , nvchem
  64. INTEGER :: time_loop_max , time_loop
  65. INTEGER :: total_time_sec , file_counter
  66. INTEGER :: julyr , julday , iswater , map_proj
  67. INTEGER :: icnt
  68. REAL :: dt , new_bdy_frq
  69. REAL :: gmt , cen_lat , cen_lon , dx , dy , truelat1 , truelat2 , moad_cen_lat , stand_lon
  70. REAL , DIMENSION(:,:,:) , ALLOCATABLE :: ubdy3dtemp1 , vbdy3dtemp1 , tbdy3dtemp1 , pbdy3dtemp1 , qbdy3dtemp1
  71. REAL , DIMENSION(:,:,:) , ALLOCATABLE :: mbdy2dtemp1
  72. REAL , DIMENSION(:,:,:) , ALLOCATABLE :: ubdy3dtemp2 , vbdy3dtemp2 , tbdy3dtemp2 , pbdy3dtemp2 , qbdy3dtemp2
  73. REAL , DIMENSION(:,:,:) , ALLOCATABLE :: mbdy2dtemp2
  74. REAL , DIMENSION(:,:,:) , ALLOCATABLE :: cbdy3dtemp1 , cbdy3dtemp2
  75. REAL , DIMENSION(:,:,:,:) , ALLOCATABLE :: cbdy3dtemp0
  76. CHARACTER(LEN=19) :: start_date_char , current_date_char , end_date_char
  77. CHARACTER(LEN=19) :: stopTimeStr
  78. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  79. INTEGER :: num_veg_cat , num_soil_top_cat , num_soil_bot_cat
  80. REAL :: time
  81. INTEGER :: rc
  82. INTEGER :: loop , levels_to_process
  83. INTEGER , PARAMETER :: max_sanity_file_loop = 100
  84. TYPE (domain) , POINTER :: keep_grid, grid_ptr, null_domain, parent_grid , nested_grid
  85. TYPE (domain) :: dummy
  86. TYPE (grid_config_rec_type) :: config_flags
  87. INTEGER :: number_at_same_level
  88. INTEGER :: time_step_begin_restart
  89. INTEGER :: max_dom , domain_id , fid , fido, fidb , oid , idum1 , idum2 , ierr
  90. INTEGER :: status_next_var
  91. INTEGER :: debug_level
  92. LOGICAL :: input_from_file , need_new_file
  93. CHARACTER (LEN=19) :: date_string
  94. #ifdef DM_PARALLEL
  95. INTEGER :: nbytes
  96. INTEGER, PARAMETER :: configbuflen = 4* CONFIG_BUF_LEN
  97. INTEGER :: configbuf( configbuflen )
  98. LOGICAL , EXTERNAL :: wrf_dm_on_monitor
  99. #endif
  100. INTEGER :: idsi
  101. CHARACTER (LEN=80) :: inpname , outname , bdyname
  102. CHARACTER (LEN=80) :: si_inpname
  103. character *19 :: temp19
  104. character *24 :: temp24 , temp24b
  105. character(len=24) :: start_date_hold
  106. CHARACTER (LEN=256) :: message
  107. integer :: ii
  108. #include "version_decl"
  109. !!!!!!!!!!!!!!!!!!!!! mousta
  110. integer :: n_ref_m,k_dim_c,k_dim_n
  111. real :: cf1_c,cf2_c,cf3_c,cfn_c,cfn1_c
  112. REAL , DIMENSION(:) , ALLOCATABLE :: znw_c,znu_c
  113. !!!!!!!!!!!!!!!!!!!!!!!!!!11
  114. ! Interface block for routine that passes pointers and needs to know that they
  115. ! are receiving pointers.
  116. INTERFACE
  117. SUBROUTINE med_interp_domain ( parent_grid , nested_grid )
  118. USE module_domain
  119. USE module_configure
  120. TYPE(domain), POINTER :: parent_grid , nested_grid
  121. END SUBROUTINE med_interp_domain
  122. SUBROUTINE Setup_Timekeeping( parent_grid )
  123. USE module_domain
  124. TYPE(domain), POINTER :: parent_grid
  125. END SUBROUTINE Setup_Timekeeping
  126. SUBROUTINE vert_cor(parent_grid,znw_c,k_dim_c)
  127. USE module_domain
  128. TYPE(domain), POINTER :: parent_grid
  129. integer , intent(in) :: k_dim_c
  130. real , dimension(k_dim_c), INTENT(IN) :: znw_c
  131. END SUBROUTINE vert_cor
  132. END INTERFACE
  133. ! Define the name of this program (program_name defined in module_domain)
  134. program_name = "NDOWN_EM " // TRIM(release_version) // " PREPROCESSOR"
  135. #ifdef DM_PARALLEL
  136. CALL disable_quilting
  137. #endif
  138. ! Initialize the modules used by the WRF system. Many of the CALLs made from the
  139. ! init_modules routine are NO-OPs. Typical initializations are: the size of a
  140. ! REAL, setting the file handles to a pre-use value, defining moisture and
  141. ! chemistry indices, etc.
  142. CALL init_modules(1) ! Phase 1 returns after MPI_INIT() (if it is called)
  143. #ifdef NO_LEAP_CALENDAR
  144. CALL WRFU_Initialize( defaultCalKind=WRFU_CAL_NOLEAP, rc=rc )
  145. #else
  146. CALL WRFU_Initialize( defaultCalKind=WRFU_CAL_GREGORIAN, rc=rc )
  147. #endif
  148. CALL init_modules(2) ! Phase 2 resumes after MPI_INIT() (if it is called)
  149. ! Get the NAMELIST data. This is handled in the initial_config routine. All of the
  150. ! NAMELIST input variables are assigned to the model_config_rec structure. Below,
  151. ! note for parallel processing, only the monitor processor handles the raw Fortran
  152. ! I/O, and then broadcasts the info to each of the other nodes.
  153. #ifdef DM_PARALLEL
  154. IF ( wrf_dm_on_monitor() ) THEN
  155. CALL initial_config
  156. ENDIF
  157. CALL get_config_as_buffer( configbuf, configbuflen, nbytes )
  158. CALL wrf_dm_bcast_bytes( configbuf, nbytes )
  159. CALL set_config_as_buffer( configbuf, configbuflen )
  160. CALL wrf_dm_initialize
  161. #else
  162. CALL initial_config
  163. #endif
  164. CALL check_nml_consistency
  165. CALL set_physics_rconfigs
  166. ! If we are running ndown, and that is WHERE we are now, make sure that we account
  167. ! for folks forgetting to say that the aux_input2 stream is in place.
  168. IF ( model_config_rec%io_form_auxinput2 .EQ. 0 ) THEN
  169. CALL wrf_error_fatal( 'ndown: Please set io_form_auxinput2 in the time_control namelist record (probably to 2).')
  170. END IF
  171. !!!!!!!!!!!!!!! mousta
  172. n_ref_m = model_config_rec % vert_refine_fact
  173. k_dim_c = model_config_rec % e_vert(1)
  174. k_dim_n = k_dim_c
  175. if (n_ref_m .ge. 2) k_dim_n = (k_dim_c - 1) * n_ref_m + 1
  176. model_config_rec % e_vert(1) = k_dim_n
  177. model_config_rec % e_vert(2) = k_dim_n
  178. ALLOCATE(znw_c(k_dim_c))
  179. ALLOCATE(znu_c(k_dim_c))
  180. WRITE ( message , FMT = '(A,3I5)' ) 'KDIM_C', k_dim_c , model_config_rec % e_vert(1) , model_config_rec % e_vert(2)
  181. CALL wrf_debug ( 99,message )
  182. !!!!!!!!!!!!!!! mousta
  183. ! And here is an instance of using the information in the NAMELIST.
  184. CALL nl_get_debug_level ( 1, debug_level )
  185. CALL set_wrf_debug_level ( debug_level )
  186. ! Allocated and configure the mother domain. Since we are in the nesting down
  187. ! mode, we know a) we got a nest, and b) we only got 1 nest.
  188. NULLIFY( null_domain )
  189. CALL wrf_message ( program_name )
  190. CALL wrf_debug ( 100 , 'ndown_em: calling alloc_and_configure_domain coarse ' )
  191. CALL alloc_and_configure_domain ( domain_id = 1 , &
  192. grid = head_grid , &
  193. parent = null_domain , &
  194. kid = -1 )
  195. parent_grid => head_grid
  196. ! Set up time initializations.
  197. CALL Setup_Timekeeping ( parent_grid )
  198. CALL domain_clock_set( head_grid, &
  199. time_step_seconds=model_config_rec%interval_seconds )
  200. CALL wrf_debug ( 100 , 'ndown_em: calling model_to_grid_config_rec ' )
  201. CALL model_to_grid_config_rec ( parent_grid%id , model_config_rec , config_flags )
  202. CALL wrf_debug ( 100 , 'ndown_em: calling set_scalar_indices_from_config ' )
  203. CALL set_scalar_indices_from_config ( parent_grid%id , idum1, idum2 )
  204. ! Initialize the I/O for WRF.
  205. CALL wrf_debug ( 100 , 'ndown_em: calling init_wrfio' )
  206. CALL init_wrfio
  207. ! Some of the configuration values may have been modified from the initial READ
  208. ! of the NAMELIST, so we re-broadcast the configuration records.
  209. #ifdef DM_PARALLEL
  210. CALL get_config_as_buffer( configbuf, configbuflen, nbytes )
  211. CALL wrf_dm_bcast_bytes( configbuf, nbytes )
  212. CALL set_config_as_buffer( configbuf, configbuflen )
  213. #endif
  214. ! We need to current and starting dates for the output files. The times need to be incremented
  215. ! so that the lateral BC files are not overwritten.
  216. #ifdef PLANET
  217. WRITE ( start_date_char , FMT = '(I4.4,"-",I5.5,"_",I2.2,":",I2.2,":",I2.2)' ) &
  218. model_config_rec%start_year (parent_grid%id) , &
  219. model_config_rec%start_day (parent_grid%id) , &
  220. model_config_rec%start_hour (parent_grid%id) , &
  221. model_config_rec%start_minute(parent_grid%id) , &
  222. model_config_rec%start_second(parent_grid%id)
  223. WRITE ( end_date_char , FMT = '(I4.4,"-",I5.5,"_",I2.2,":",I2.2,":",I2.2)' ) &
  224. model_config_rec% end_year (parent_grid%id) , &
  225. model_config_rec% end_day (parent_grid%id) , &
  226. model_config_rec% end_hour (parent_grid%id) , &
  227. model_config_rec% end_minute(parent_grid%id) , &
  228. model_config_rec% end_second(parent_grid%id)
  229. #else
  230. WRITE ( start_date_char , FMT = '(I4.4,"-",I2.2,"-",I2.2,"_",I2.2,":",I2.2,":",I2.2)' ) &
  231. model_config_rec%start_year (parent_grid%id) , &
  232. model_config_rec%start_month (parent_grid%id) , &
  233. model_config_rec%start_day (parent_grid%id) , &
  234. model_config_rec%start_hour (parent_grid%id) , &
  235. model_config_rec%start_minute(parent_grid%id) , &
  236. model_config_rec%start_second(parent_grid%id)
  237. WRITE ( end_date_char , FMT = '(I4.4,"-",I2.2,"-",I2.2,"_",I2.2,":",I2.2,":",I2.2)' ) &
  238. model_config_rec% end_year (parent_grid%id) , &
  239. model_config_rec% end_month (parent_grid%id) , &
  240. model_config_rec% end_day (parent_grid%id) , &
  241. model_config_rec% end_hour (parent_grid%id) , &
  242. model_config_rec% end_minute(parent_grid%id) , &
  243. model_config_rec% end_second(parent_grid%id)
  244. #endif
  245. ! Override stop time with value computed above.
  246. CALL domain_clock_set( parent_grid, stop_timestr=end_date_char )
  247. CALL geth_idts ( end_date_char , start_date_char , total_time_sec )
  248. new_bdy_frq = model_config_rec%interval_seconds
  249. time_loop_max = total_time_sec / model_config_rec%interval_seconds + 1
  250. start_date = start_date_char // '.0000'
  251. current_date = start_date_char // '.0000'
  252. start_date_hold = start_date_char // '.0000'
  253. current_date_char = start_date_char
  254. ! Get a list of available file names to try. This fills up the eligible_file_name
  255. ! array with number_of_eligible_files entries. This routine issues a nonstandard
  256. ! call (system).
  257. file_counter = 1
  258. need_new_file = .FALSE.
  259. CALL unix_ls ( 'wrfout' , parent_grid%id )
  260. ! Open the input data (wrfout_d01_xxxxxx) for reading.
  261. CALL wrf_debug ( 100 , 'ndown_em main: calling open_r_dataset for ' // TRIM(eligible_file_name(file_counter)) )
  262. CALL open_r_dataset ( fid, TRIM(eligible_file_name(file_counter)) , head_grid , config_flags , "DATASET=AUXINPUT1", ierr )
  263. IF ( ierr .NE. 0 ) THEN
  264. WRITE( wrf_err_message , FMT='(A,A,A,I8)' ) 'program ndown: error opening ',TRIM(eligible_file_name(file_counter)), &
  265. ' for reading ierr=',ierr
  266. CALL WRF_ERROR_FATAL ( wrf_err_message )
  267. ENDIF
  268. ! We know how many time periods to process, so we begin.
  269. big_time_loop_thingy : DO time_loop = 1 , time_loop_max
  270. ! Which date are we currently soliciting?
  271. CALL geth_newdate ( date_string , start_date_char , ( time_loop - 1 ) * NINT ( new_bdy_frq) )
  272. WRITE ( message , FMT = '(A,I5," ",A,A)' ) '-------->>> Processing data: loop=',time_loop,' date/time = ',date_string
  273. CALL wrf_debug ( 99,message )
  274. current_date_char = date_string
  275. current_date = date_string // '.0000'
  276. start_date = date_string // '.0000'
  277. WRITE ( message , FMT = '(A,I5," ",A,A)' ) 'loopmax = ', time_loop_max, ' ending date = ',end_date_char
  278. CALL wrf_debug ( 99,message )
  279. CALL domain_clock_set( parent_grid, &
  280. current_timestr=current_date(1:19) )
  281. ! Which times are in this file, and more importantly, are any of them the
  282. ! ones that we want? We need to loop over times in each files, loop
  283. ! over files.
  284. get_the_right_time : DO
  285. CALL wrf_get_next_time ( fid , date_string , status_next_var )
  286. WRITE ( message , FMT = '(A,A,A,A,A,I5)' ) 'file date/time = ',date_string,' desired date = ',&
  287. current_date_char,' status = ', status_next_var
  288. CALL wrf_debug ( 99,message )
  289. IF ( status_next_var .NE. 0 ) THEN
  290. CALL wrf_debug ( 100 , 'ndown_em main: calling close_dataset for ' // TRIM(eligible_file_name(file_counter)) )
  291. CALL close_dataset ( fid , config_flags , "DATASET=INPUT" )
  292. file_counter = file_counter + 1
  293. IF ( file_counter .GT. number_of_eligible_files ) THEN
  294. WRITE( wrf_err_message , FMT='(A,A,A,I8)' ) 'program ndown: opening too many files'
  295. CALL WRF_ERROR_FATAL ( wrf_err_message )
  296. END IF
  297. CALL wrf_debug ( 100 , 'ndown_em main: calling open_r_dataset for ' // TRIM(eligible_file_name(file_counter)) )
  298. CALL open_r_dataset ( fid, TRIM(eligible_file_name(file_counter)) , head_grid , config_flags , "DATASET=INPUT", ierr )
  299. IF ( ierr .NE. 0 ) THEN
  300. WRITE( wrf_err_message , FMT='(A,A,A,I8)' ) 'program ndown: error opening ',TRIM(eligible_file_name(file_counter)), &
  301. ' for reading ierr=',ierr
  302. CALL WRF_ERROR_FATAL ( wrf_err_message )
  303. ENDIF
  304. CYCLE get_the_right_time
  305. ELSE IF ( TRIM(date_string) .LT. TRIM(current_date_char) ) THEN
  306. CYCLE get_the_right_time
  307. ELSE IF ( TRIM(date_string) .EQ. TRIM(current_date_char) ) THEN
  308. EXIT get_the_right_time
  309. ELSE IF ( TRIM(date_string) .GT. TRIM(current_date_char) ) THEN
  310. WRITE( wrf_err_message , FMT='(A,A,A,A,A)' ) 'Found ',TRIM(date_string),' before I found ',TRIM(current_date_char),'.'
  311. CALL WRF_ERROR_FATAL ( wrf_err_message )
  312. END IF
  313. END DO get_the_right_time
  314. CALL wrf_debug ( 100 , 'wrf: calling input_history' )
  315. CALL wrf_get_previous_time ( fid , date_string , status_next_var )
  316. WRITE ( message , * ) 'CFB' ,cf1_c,cf2_c,cf3_c,cfn_c,cfn1_c,znw_c(1),znu_c(1)
  317. CALL wrf_debug ( 99,message )
  318. CALL input_history ( fid , head_grid , config_flags, ierr)
  319. !!!!!!!!!!!!!1 mousta
  320. cf1_c = head_grid%cf1
  321. cf2_c = head_grid%cf2
  322. cf3_c = head_grid%cf3
  323. cfn_c = head_grid%cfn
  324. cfn1_c = head_grid%cfn1
  325. do k = 1,k_dim_c
  326. znw_c(k) = head_grid%znw(k)
  327. znu_c(k) = head_grid%znu(k)
  328. enddo
  329. call vert_cor(head_grid,znw_c,k_dim_c)
  330. WRITE ( message , * ) 'CFA' ,cf1_c,cf2_c,cf3_c,cfn_c,cfn1_c,znw_c(1),znu_c(1)
  331. CALL wrf_debug ( 99,message )
  332. WRITE ( message , * ) 'CFV' ,head_grid%cf1,head_grid%cf2,head_grid%cf3,head_grid%cfn,head_grid%cfn1,&
  333. head_grid%znw(1),head_grid%znu(1) , head_grid%e_vert , parent_grid%cf1 , parent_grid%znw(1) , parent_grid%znu(1)
  334. CALL wrf_debug ( 99,message )
  335. !!!!!!!!!!!!!1 mousta
  336. CALL wrf_debug ( 100 , 'wrf: back from input_history' )
  337. ! Get the coarse grid info for later transfer to the fine grid domain.
  338. CALL wrf_get_dom_ti_integer ( fid , 'MAP_PROJ' , map_proj , 1 , icnt , ierr )
  339. CALL wrf_get_dom_ti_real ( fid , 'DX' , dx , 1 , icnt , ierr )
  340. CALL wrf_get_dom_ti_real ( fid , 'DY' , dy , 1 , icnt , ierr )
  341. CALL wrf_get_dom_ti_real ( fid , 'CEN_LAT' , cen_lat , 1 , icnt , ierr )
  342. CALL wrf_get_dom_ti_real ( fid , 'CEN_LON' , cen_lon , 1 , icnt , ierr )
  343. CALL wrf_get_dom_ti_real ( fid , 'TRUELAT1' , truelat1 , 1 , icnt , ierr )
  344. CALL wrf_get_dom_ti_real ( fid , 'TRUELAT2' , truelat2 , 1 , icnt , ierr )
  345. CALL wrf_get_dom_ti_real ( fid , 'MOAD_CEN_LAT' , moad_cen_lat , 1 , icnt , ierr )
  346. CALL wrf_get_dom_ti_real ( fid , 'STAND_LON' , stand_lon , 1 , icnt , ierr )
  347. ! CALL wrf_get_dom_ti_real ( fid , 'GMT' , gmt , 1 , icnt , ierr )
  348. ! CALL wrf_get_dom_ti_integer ( fid , 'JULYR' , julyr , 1 , icnt , ierr )
  349. ! CALL wrf_get_dom_ti_integer ( fid , 'JULDAY' , julday , 1 , icnt , ierr )
  350. CALL wrf_get_dom_ti_integer ( fid , 'ISWATER' , iswater , 1 , icnt , ierr )
  351. ! First time in, do this: allocate sapce for the fine grid, get the config flags, open the
  352. ! wrfinput and wrfbdy files. This COULD be done outside the time loop, I think, so check it
  353. ! out and move it up if you can.
  354. IF ( time_loop .EQ. 1 ) THEN
  355. CALL wrf_message ( program_name )
  356. CALL wrf_debug ( 100 , 'wrf: calling alloc_and_configure_domain fine ' )
  357. CALL alloc_and_configure_domain ( domain_id = 2 , &
  358. grid = nested_grid , &
  359. parent = parent_grid , &
  360. kid = 1 )
  361. CALL wrf_debug ( 100 , 'wrf: calling model_to_grid_config_rec ' )
  362. CALL model_to_grid_config_rec ( nested_grid%id , model_config_rec , config_flags )
  363. CALL wrf_debug ( 100 , 'wrf: calling set_scalar_indices_from_config ' )
  364. CALL set_scalar_indices_from_config ( nested_grid%id , idum1, idum2 )
  365. ! Set up time initializations for the fine grid.
  366. CALL Setup_Timekeeping ( nested_grid )
  367. ! Strictly speaking, nest stop time should come from model_config_rec...
  368. CALL domain_clock_get( parent_grid, stop_timestr=stopTimeStr )
  369. CALL domain_clock_set( nested_grid, &
  370. current_timestr=current_date(1:19), &
  371. stop_timestr=stopTimeStr , &
  372. time_step_seconds= &
  373. model_config_rec%interval_seconds )
  374. ! Generate an output file from this program, which will be an input file to WRF.
  375. CALL nl_set_bdyfrq ( nested_grid%id , new_bdy_frq )
  376. config_flags%bdyfrq = new_bdy_frq
  377. #ifdef WRF_CHEM
  378. nested_grid%chem_opt = parent_grid%chem_opt
  379. nested_grid%chem_in_opt = parent_grid%chem_in_opt
  380. #endif
  381. ! Initialize constants and 1d arrays in fine grid from the parent.
  382. CALL init_domain_constants_em_ptr ( parent_grid , nested_grid )
  383. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  384. CALL wrf_debug ( 100 , 'ndown_em main: calling open_w_dataset for wrfinput' )
  385. CALL construct_filename1( outname , 'wrfinput' , nested_grid%id , 2 )
  386. CALL open_w_dataset ( fido, TRIM(outname) , nested_grid , config_flags , output_input , "DATASET=INPUT", ierr )
  387. IF ( ierr .NE. 0 ) THEN
  388. WRITE( wrf_err_message , FMT='(A,A,A,I8)' ) 'program ndown: error opening ',TRIM(outname),' for reading ierr=',ierr
  389. CALL WRF_ERROR_FATAL ( wrf_err_message )
  390. ENDIF
  391. ! Various sizes that we need to be concerned about.
  392. ids = nested_grid%sd31
  393. ide = nested_grid%ed31
  394. kds = nested_grid%sd32
  395. kde = nested_grid%ed32
  396. jds = nested_grid%sd33
  397. jde = nested_grid%ed33
  398. ims = nested_grid%sm31
  399. ime = nested_grid%em31
  400. kms = nested_grid%sm32
  401. kme = nested_grid%em32
  402. jms = nested_grid%sm33
  403. jme = nested_grid%em33
  404. ips = nested_grid%sp31
  405. ipe = nested_grid%ep31
  406. kps = nested_grid%sp32
  407. kpe = nested_grid%ep32
  408. jps = nested_grid%sp33
  409. jpe = nested_grid%ep33
  410. print *, ids , ide , jds , jde , kds , kde
  411. print *, ims , ime , jms , jme , kms , kme
  412. print *, ips , ipe , jps , jpe , kps , kpe
  413. spec_bdy_width = model_config_rec%spec_bdy_width
  414. print *,'spec_bdy_width=',spec_bdy_width
  415. ! This is the space needed to save the current 3d data for use in computing
  416. ! the lateral boundary tendencies.
  417. ALLOCATE ( ubdy3dtemp1(ims:ime,kms:kme,jms:jme) )
  418. ALLOCATE ( vbdy3dtemp1(ims:ime,kms:kme,jms:jme) )
  419. ALLOCATE ( tbdy3dtemp1(ims:ime,kms:kme,jms:jme) )
  420. ALLOCATE ( pbdy3dtemp1(ims:ime,kms:kme,jms:jme) )
  421. ALLOCATE ( qbdy3dtemp1(ims:ime,kms:kme,jms:jme) )
  422. ALLOCATE ( mbdy2dtemp1(ims:ime,1:1, jms:jme) )
  423. ALLOCATE ( ubdy3dtemp2(ims:ime,kms:kme,jms:jme) )
  424. ALLOCATE ( vbdy3dtemp2(ims:ime,kms:kme,jms:jme) )
  425. ALLOCATE ( tbdy3dtemp2(ims:ime,kms:kme,jms:jme) )
  426. ALLOCATE ( pbdy3dtemp2(ims:ime,kms:kme,jms:jme) )
  427. ALLOCATE ( qbdy3dtemp2(ims:ime,kms:kme,jms:jme) )
  428. ALLOCATE ( mbdy2dtemp2(ims:ime,1:1, jms:jme) )
  429. ALLOCATE ( cbdy3dtemp0(ims:ime,kms:kme,jms:jme,1:num_chem) )
  430. ALLOCATE ( cbdy3dtemp1(ims:ime,kms:kme,jms:jme) )
  431. ALLOCATE ( cbdy3dtemp2(ims:ime,kms:kme,jms:jme) )
  432. END IF
  433. CALL domain_clock_set( nested_grid, &
  434. current_timestr=current_date(1:19), &
  435. time_step_seconds= &
  436. model_config_rec%interval_seconds )
  437. ! Do the horizontal interpolation.
  438. nested_grid%imask_nostag = 1
  439. nested_grid%imask_xstag = 1
  440. nested_grid%imask_ystag = 1
  441. nested_grid%imask_xystag = 1
  442. CALL med_interp_domain ( head_grid , nested_grid )
  443. WRITE ( message , * ) 'MOUSTA_L', nested_grid%mu_2(ips,jps) , nested_grid%u_2(ips,kde-2,jps)
  444. CALL wrf_debug ( 99,message )
  445. CALL vertical_interp (nested_grid,znw_c,znu_c,cf1_c,cf2_c,cf3_c,cfn_c,cfn1_c,k_dim_c)
  446. WRITE ( message , * ) 'MOUSTA_V', nested_grid%mu_2(ips,jps) , nested_grid%u_2(ips,kde-2,jps)
  447. CALL wrf_debug ( 99,message )
  448. nested_grid%ht_int = nested_grid%ht
  449. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  450. IF ( time_loop .EQ. 1 ) THEN
  451. ! Dimension info for fine grid.
  452. CALL get_ijk_from_grid ( nested_grid , &
  453. nids, nide, njds, njde, nkds, nkde, &
  454. nims, nime, njms, njme, nkms, nkme, &
  455. nips, nipe, njps, njpe, nkps, nkpe )
  456. ! Store horizontally interpolated terrain in temp location
  457. CALL copy_3d_field ( nested_grid%ht_fine , nested_grid%ht , &
  458. nids , nide , njds , njde , 1 , 1 , &
  459. nims , nime , njms , njme , 1 , 1 , &
  460. nips , nipe , njps , njpe , 1 , 1 )
  461. ! Open the fine grid SI static file.
  462. CALL construct_filename1( si_inpname , 'wrfndi' , nested_grid%id , 2 )
  463. CALL wrf_debug ( 100 , 'med_sidata_input: calling open_r_dataset for ' // TRIM(si_inpname) )
  464. CALL open_r_dataset ( idsi, TRIM(si_inpname) , nested_grid , config_flags , "DATASET=INPUT", ierr )
  465. IF ( ierr .NE. 0 ) THEN
  466. CALL wrf_error_fatal( 'real: error opening FG input for reading: ' // TRIM (si_inpname) )
  467. END IF
  468. ! Input data.
  469. CALL wrf_debug ( 100 , 'ndown_em: calling input_auxinput2' )
  470. CALL input_auxinput2 ( idsi , nested_grid , config_flags , ierr )
  471. nested_grid%ht_input = nested_grid%ht
  472. ! Close this fine grid static input file.
  473. CALL wrf_debug ( 100 , 'ndown_em: closing fine grid static input' )
  474. CALL close_dataset ( idsi , config_flags , "DATASET=INPUT" )
  475. ! Blend parent and nest field of terrain.
  476. CALL blend_terrain ( nested_grid%ht_fine , nested_grid%ht , &
  477. nids , nide , njds , njde , 1 , 1 , &
  478. nims , nime , njms , njme , 1 , 1 , &
  479. nips , nipe , njps , njpe , 1 , 1 )
  480. nested_grid%ht_input = nested_grid%ht
  481. nested_grid%ht_int = nested_grid%ht_fine
  482. ! We need a fine grid landuse in the interpolation. So we need to generate
  483. ! that field now.
  484. IF ( ( nested_grid%ivgtyp(ips,jps) .GT. 0 ) .AND. &
  485. ( nested_grid%isltyp(ips,jps) .GT. 0 ) ) THEN
  486. DO j = jps, MIN(jde-1,jpe)
  487. DO i = ips, MIN(ide-1,ipe)
  488. nested_grid% vegcat(i,j) = nested_grid%ivgtyp(i,j)
  489. nested_grid%soilcat(i,j) = nested_grid%isltyp(i,j)
  490. END DO
  491. END DO
  492. ELSE IF ( ( nested_grid% vegcat(ips,jps) .GT. 0.5 ) .AND. &
  493. ( nested_grid%soilcat(ips,jps) .GT. 0.5 ) ) THEN
  494. DO j = jps, MIN(jde-1,jpe)
  495. DO i = ips, MIN(ide-1,ipe)
  496. nested_grid%ivgtyp(i,j) = NINT(nested_grid% vegcat(i,j))
  497. nested_grid%isltyp(i,j) = NINT(nested_grid%soilcat(i,j))
  498. END DO
  499. END DO
  500. ELSE
  501. num_veg_cat = SIZE ( nested_grid%landusef , DIM=2 )
  502. num_soil_top_cat = SIZE ( nested_grid%soilctop , DIM=2 )
  503. num_soil_bot_cat = SIZE ( nested_grid%soilcbot , DIM=2 )
  504. CALL land_percentages ( nested_grid%xland , &
  505. nested_grid%landusef , nested_grid%soilctop , nested_grid%soilcbot , &
  506. nested_grid%isltyp , nested_grid%ivgtyp , &
  507. num_veg_cat , num_soil_top_cat , num_soil_bot_cat , &
  508. ids , ide , jds , jde , kds , kde , &
  509. ims , ime , jms , jme , kms , kme , &
  510. ips , ipe , jps , jpe , kps , kpe , &
  511. model_config_rec%iswater(nested_grid%id) )
  512. END IF
  513. DO j = jps, MIN(jde-1,jpe)
  514. DO i = ips, MIN(ide-1,ipe)
  515. nested_grid%lu_index(i,j) = nested_grid%ivgtyp(i,j)
  516. END DO
  517. END DO
  518. #ifndef PLANET
  519. CALL check_consistency ( nested_grid%ivgtyp , nested_grid%isltyp , nested_grid%landmask , &
  520. ids , ide , jds , jde , kds , kde , &
  521. ims , ime , jms , jme , kms , kme , &
  522. ips , ipe , jps , jpe , kps , kpe , &
  523. model_config_rec%iswater(nested_grid%id) )
  524. CALL check_consistency2( nested_grid%ivgtyp , nested_grid%isltyp , nested_grid%landmask , &
  525. nested_grid%tmn , nested_grid%tsk , nested_grid%sst , nested_grid%xland , &
  526. nested_grid%tslb , nested_grid%smois , nested_grid%sh2o , &
  527. config_flags%num_soil_layers , nested_grid%id , &
  528. ids , ide , jds , jde , kds , kde , &
  529. ims , ime , jms , jme , kms , kme , &
  530. ips , ipe , jps , jpe , kps , kpe , &
  531. model_config_rec%iswater(nested_grid%id) )
  532. #endif
  533. END IF
  534. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  535. ! We have 2 terrain elevations. One is from input and the other is from the
  536. ! the horizontal interpolation.
  537. nested_grid%ht_fine = nested_grid%ht_input
  538. nested_grid%ht = nested_grid%ht_int
  539. ! We have both the interpolated fields and the higher-resolution static fields. From these
  540. ! the rebalancing is now done. Note also that the field nested_grid%ht is now from the
  541. ! fine grid input file (after this call is completed).
  542. CALL rebalance_driver ( nested_grid )
  543. ! Different things happen during the different time loops:
  544. ! first loop - write wrfinput file, close data set, copy files to holder arrays
  545. ! middle loops - diff 3d/2d arrays, compute and output bc
  546. ! last loop - diff 3d/2d arrays, compute and output bc, write wrfbdy file, close wrfbdy file
  547. IF ( time_loop .EQ. 1 ) THEN
  548. ! Set the time info.
  549. print *,'current_date = ',current_date
  550. CALL domain_clock_set( nested_grid, &
  551. current_timestr=current_date(1:19) )
  552. #ifdef WRF_CHEM
  553. !
  554. ! Put in chemistry data
  555. !
  556. IF( nested_grid%chem_opt .NE. 0 ) then
  557. ! IF( nested_grid%chem_in_opt .EQ. 0 ) then
  558. ! Read the chemistry data from a previous wrf forecast (wrfout file)
  559. ! Generate chemistry data from a idealized vertical profile
  560. ! message = 'STARTING WITH BACKGROUND CHEMISTRY '
  561. CALL wrf_message ( message )
  562. ! CALL input_chem_profile ( nested_grid )
  563. if(nested_grid%biomass_burn_opt == BIOMASSB) THEN
  564. message = 'READING BIOMASS BURNING EMISSIONS DATA '
  565. CALL wrf_message ( message )
  566. CALL med_read_wrf_chem_emissopt3 ( nested_grid , config_flags)
  567. end if
  568. if(nested_grid%dust_opt == 1 .or. nested_grid%dmsemis_opt == 1 &
  569. .or. nested_grid%chem_opt == 300 .or. nested_grid%chem_opt == 301) then
  570. message = 'READING GOCART BG AND/OR DUST and DMS REF FIELDS'
  571. CALL wrf_message ( message )
  572. CALL med_read_wrf_chem_gocart_bg ( nested_grid , config_flags)
  573. end if
  574. if( nested_grid%bio_emiss_opt .eq. 2 )then
  575. message = 'READING BEIS3.11 EMISSIONS DATA'
  576. CALL wrf_message ( message )
  577. CALL med_read_wrf_chem_bioemiss ( nested_grid , config_flags)
  578. else if( nested_grid%bio_emiss_opt == 3 ) THEN
  579. message = 'READING MEGAN 2 EMISSIONS DATA'
  580. CALL wrf_message ( message )
  581. CALL med_read_wrf_chem_bioemiss ( nested_grid , config_flags)
  582. endif
  583. ! ELSE
  584. ! message = 'RUNNING WITHOUT CHEMISTRY INITIALIZATION'
  585. ! CALL wrf_message ( message )
  586. ! ENDIF
  587. ENDIF
  588. #endif
  589. ! Output the first time period of the data.
  590. CALL output_input ( fido , nested_grid , config_flags , ierr )
  591. CALL wrf_put_dom_ti_integer ( fido , 'MAP_PROJ' , map_proj , 1 , ierr )
  592. ! CALL wrf_put_dom_ti_real ( fido , 'DX' , dx , 1 , ierr )
  593. ! CALL wrf_put_dom_ti_real ( fido , 'DY' , dy , 1 , ierr )
  594. CALL wrf_put_dom_ti_real ( fido , 'CEN_LAT' , cen_lat , 1 , ierr )
  595. CALL wrf_put_dom_ti_real ( fido , 'CEN_LON' , cen_lon , 1 , ierr )
  596. CALL wrf_put_dom_ti_real ( fido , 'TRUELAT1' , truelat1 , 1 , ierr )
  597. CALL wrf_put_dom_ti_real ( fido , 'TRUELAT2' , truelat2 , 1 , ierr )
  598. CALL wrf_put_dom_ti_real ( fido , 'MOAD_CEN_LAT' , moad_cen_lat , 1 , ierr )
  599. CALL wrf_put_dom_ti_real ( fido , 'STAND_LON' , stand_lon , 1 , ierr )
  600. CALL wrf_put_dom_ti_integer ( fido , 'ISWATER' , iswater , 1 , ierr )
  601. ! These change if the initial time for the nest is not the same as the
  602. ! first time period in the WRF output file.
  603. ! Now that we know the starting date, we need to set the GMT, JULYR, and JULDAY
  604. ! values for the global attributes. This call is based on the setting of the
  605. ! current_date string.
  606. CALL geth_julgmt ( julyr , julday , gmt)
  607. CALL nl_set_julyr ( nested_grid%id , julyr )
  608. CALL nl_set_julday ( nested_grid%id , julday )
  609. CALL nl_set_gmt ( nested_grid%id , gmt )
  610. CALL wrf_put_dom_ti_real ( fido , 'GMT' , gmt , 1 , ierr )
  611. CALL wrf_put_dom_ti_integer ( fido , 'JULYR' , julyr , 1 , ierr )
  612. CALL wrf_put_dom_ti_integer ( fido , 'JULDAY' , julday , 1 , ierr )
  613. print *,'current_date =',current_date
  614. print *,'julyr=',julyr
  615. print *,'julday=',julday
  616. print *,'gmt=',gmt
  617. ! Close the input (wrfout_d01_000000, for example) file. That's right, the
  618. ! input is an output file. Who'd've thunk.
  619. CALL close_dataset ( fido , config_flags , "DATASET=INPUT" )
  620. ! We need to save the 3d/2d data to compute a difference during the next loop. Couple the
  621. ! 3d fields with total mu (mub + mu_2) and the stagger-specific map scale factor.
  622. ! u, theta, h, scalars coupled with my, v coupled with mx
  623. CALL couple ( nested_grid%mu_2 , nested_grid%mub , ubdy3dtemp1 , nested_grid%u_2 , &
  624. 'u' , nested_grid%msfuy , &
  625. ids, ide, jds, jde, kds, kde, ims, ime, jms, jme, kms, kme, ips, ipe, jps, jpe, kps, kpe )
  626. CALL couple ( nested_grid%mu_2 , nested_grid%mub , vbdy3dtemp1 , nested_grid%v_2 , &
  627. 'v' , nested_grid%msfvx , &
  628. ids, ide, jds, jde, kds, kde, ims, ime, jms, jme, kms, kme, ips, ipe, jps, jpe, kps, kpe )
  629. CALL couple ( nested_grid%mu_2 , nested_grid%mub , tbdy3dtemp1 , nested_grid%t_2 , &
  630. 't' , nested_grid%msfty , &
  631. ids, ide, jds, jde, kds, kde, ims, ime, jms, jme, kms, kme, ips, ipe, jps, jpe, kps, kpe )
  632. CALL couple ( nested_grid%mu_2 , nested_grid%mub , pbdy3dtemp1 , nested_grid%ph_2 , &
  633. 'h' , nested_grid%msfty , &
  634. ids, ide, jds, jde, kds, kde, ims, ime, jms, jme, kms, kme, ips, ipe, jps, jpe, kps, kpe )
  635. CALL couple ( nested_grid%mu_2 , nested_grid%mub , qbdy3dtemp1 , nested_grid%moist(ims:ime,kms:kme,jms:jme,P_QV) , &
  636. 't' , nested_grid%msfty , &
  637. ids, ide, jds, jde, kds, kde, ims, ime, jms, jme, kms, kme, ips, ipe, jps, jpe, kps, kpe )
  638. DO j = jps , jpe
  639. DO i = ips , ipe
  640. mbdy2dtemp1(i,1,j) = nested_grid%mu_2(i,j)
  641. END DO
  642. END DO
  643. ! There are 2 components to the lateral boundaries. First, there is the starting
  644. ! point of this time period - just the outer few rows and columns.
  645. CALL stuff_bdy ( ubdy3dtemp1 , nested_grid%u_bxs, nested_grid%u_bxe, &
  646. nested_grid%u_bys, nested_grid%u_bye, &
  647. 'U' , spec_bdy_width , &
  648. ids , ide , jds , jde , kds , kde , &
  649. ims , ime , jms , jme , kms , kme , &
  650. ips , ipe , jps , jpe , kps , kpe )
  651. CALL stuff_bdy ( vbdy3dtemp1 , nested_grid%v_bxs, nested_grid%v_bxe, &
  652. nested_grid%v_bys, nested_grid%v_bye, &
  653. 'V' , spec_bdy_width , &
  654. ids , ide , jds , jde , kds , kde , &
  655. ims , ime , jms , jme , kms , kme , &
  656. ips , ipe , jps , jpe , kps , kpe )
  657. CALL stuff_bdy ( tbdy3dtemp1 , nested_grid%t_bxs, nested_grid%t_bxe, &
  658. nested_grid%t_bys, nested_grid%t_bye, &
  659. 'T' , spec_bdy_width , &
  660. ids , ide , jds , jde , kds , kde , &
  661. ims , ime , jms , jme , kms , kme , &
  662. ips , ipe , jps , jpe , kps , kpe )
  663. CALL stuff_bdy ( pbdy3dtemp1 , nested_grid%ph_bxs, nested_grid%ph_bxe, &
  664. nested_grid%ph_bys, nested_grid%ph_bye, &
  665. 'W' , spec_bdy_width , &
  666. ids , ide , jds , jde , kds , kde , &
  667. ims , ime , jms , jme , kms , kme , &
  668. ips , ipe , jps , jpe , kps , kpe )
  669. CALL stuff_bdy ( qbdy3dtemp1 , nested_grid%moist_bxs(jms:jme,kms:kme,1:spec_bdy_width,P_QV), &
  670. nested_grid%moist_bxe(jms:jme,kms:kme,1:spec_bdy_width,P_QV), &
  671. nested_grid%moist_bys(ims:ime,kms:kme,1:spec_bdy_width,P_QV), &
  672. nested_grid%moist_bye(ims:ime,kms:kme,1:spec_bdy_width,P_QV), &
  673. 'T' , spec_bdy_width , &
  674. ids , ide , jds , jde , kds , kde , &
  675. ims , ime , jms , jme , kms , kme , &
  676. ips , ipe , jps , jpe , kps , kpe )
  677. CALL stuff_bdy ( mbdy2dtemp1 , nested_grid%mu_bxs, nested_grid%mu_bxe, &
  678. nested_grid%mu_bys, nested_grid%mu_bye, &
  679. 'M' , spec_bdy_width , &
  680. ids , ide , jds , jde , 1 , 1 , &
  681. ims , ime , jms , jme , 1 , 1 , &
  682. ips , ipe , jps , jpe , 1 , 1 )
  683. #ifdef WRF_CHEM
  684. do nvchem=1,num_chem
  685. ! if(nvchem.eq.p_o3)then
  686. ! write(0,*)'fill ch_b',cbdy3dtemp1(5,1,5),nvchem
  687. ! endif
  688. cbdy3dtemp1(ips:ipe,kps:kpe,jps:jpe)=nested_grid%chem(ips:ipe,kps:kpe,jps:jpe,nvchem)
  689. ! if(nvchem.eq.p_o3)then
  690. ! write(0,*)'fill ch_b',cbdy3dtemp1(5,1,5)
  691. ! endif
  692. CALL stuff_bdy ( cbdy3dtemp1 , nested_grid%chem_bxs(jms:jme,kms:kme,1:spec_bdy_width,nvchem), &
  693. nested_grid%chem_bxe(jms:jme,kms:kme,1:spec_bdy_width,nvchem), &
  694. nested_grid%chem_bys(ims:ime,kms:kme,1:spec_bdy_width,nvchem), &
  695. nested_grid%chem_bye(ims:ime,kms:kme,1:spec_bdy_width,nvchem), &
  696. 'T' , spec_bdy_width , &
  697. ids , ide , jds , jde , kds , kde , &
  698. ims , ime , jms , jme , kms , kme , &
  699. ips , ipe , jps , jpe , kps , kpe )
  700. cbdy3dtemp0(ips:ipe,kps:kpe,jps:jpe,nvchem)=cbdy3dtemp1(ips:ipe,kps:kpe,jps:jpe)
  701. ! if(nvchem.eq.p_o3)then
  702. ! write(0,*)'filled ch_b',time_loop,cbdy3dtemp1(ips,kps,jps),cbdy3dtemp0(ips,kps,jps,nvchem)
  703. ! endif
  704. enddo
  705. #endif
  706. ELSE IF ( ( time_loop .GT. 1 ) .AND. ( time_loop .LT. time_loop_max ) ) THEN
  707. ! u, theta, h, scalars coupled with my, v coupled with mx
  708. CALL couple ( nested_grid%mu_2 , nested_grid%mub , ubdy3dtemp2 , nested_grid%u_2 , &
  709. 'u' , nested_grid%msfuy , &
  710. ids, ide, jds, jde, kds, kde, ims, ime, jms, jme, kms, kme, ips, ipe, jps, jpe, kps, kpe )
  711. CALL couple ( nested_grid%mu_2 , nested_grid%mub , vbdy3dtemp2 , nested_grid%v_2 , &
  712. 'v' , nested_grid%msfvx , &
  713. ids, ide, jds, jde, kds, kde, ims, ime, jms, jme, kms, kme, ips, ipe, jps, jpe, kps, kpe )
  714. CALL couple ( nested_grid%mu_2 , nested_grid%mub , tbdy3dtemp2 , nested_grid%t_2 , &
  715. 't' , nested_grid%msfty , &
  716. ids, ide, jds, jde, kds, kde, ims, ime, jms, jme, kms, kme, ips, ipe, jps, jpe, kps, kpe )
  717. CALL couple ( nested_grid%mu_2 , nested_grid%mub , pbdy3dtemp2 , nested_grid%ph_2 , &
  718. 'h' , nested_grid%msfty , &
  719. ids, ide, jds, jde, kds, kde, ims, ime, jms, jme, kms, kme, ips, ipe, jps, jpe, kps, kpe )
  720. CALL couple ( nested_grid%mu_2 , nested_grid%mub , qbdy3dtemp2 , nested_grid%moist(ims:ime,kms:kme,jms:jme,P_QV) , &
  721. 't' , nested_grid%msfty , &
  722. ids, ide, jds, jde, kds, kde, ims, ime, jms, jme, kms, kme, ips, ipe, jps, jpe, kps, kpe )
  723. DO j = jps , jpe
  724. DO i = ips , ipe
  725. mbdy2dtemp2(i,1,j) = nested_grid%mu_2(i,j)
  726. END DO
  727. END DO
  728. ! During all of the loops after the first loop, we first compute the boundary
  729. ! tendencies with the current data values and the previously save information
  730. ! stored in the *bdy3dtemp1 arrays.
  731. CALL stuff_bdytend ( ubdy3dtemp2 , ubdy3dtemp1 , new_bdy_frq , &
  732. nested_grid%u_btxs, nested_grid%u_btxe , &
  733. nested_grid%u_btys, nested_grid%u_btye , &
  734. 'U' , &
  735. spec_bdy_width , &
  736. ids , ide , jds , jde , kds , kde , &
  737. ims , ime , jms , jme , kms , kme , &
  738. ips , ipe , jps , jpe , kps , kpe )
  739. CALL stuff_bdytend ( vbdy3dtemp2 , vbdy3dtemp1 , new_bdy_frq , &
  740. nested_grid%v_btxs, nested_grid%v_btxe , &
  741. nested_grid%v_btys, nested_grid%v_btye , &
  742. 'V' , &
  743. spec_bdy_width , &
  744. ids , ide , jds , jde , kds , kde , &
  745. ims , ime , jms , jme , kms , kme , &
  746. ips , ipe , jps , jpe , kps , kpe )
  747. CALL stuff_bdytend ( tbdy3dtemp2 , tbdy3dtemp1 , new_bdy_frq , &
  748. nested_grid%t_btxs, nested_grid%t_btxe , &
  749. nested_grid%t_btys, nested_grid%t_btye , &
  750. 'T' , &
  751. spec_bdy_width , &
  752. ids , ide , jds , jde , kds , kde , &
  753. ims , ime , jms , jme , kms , kme , &
  754. ips , ipe , jps , jpe , kps , kpe )
  755. CALL stuff_bdytend ( pbdy3dtemp2 , pbdy3dtemp1 , new_bdy_frq , &
  756. nested_grid%ph_btxs, nested_grid%ph_btxe , &
  757. nested_grid%ph_btys, nested_grid%ph_btye , &
  758. 'W' , &
  759. spec_bdy_width , &
  760. ids , ide , jds , jde , kds , kde , &
  761. ims , ime , jms , jme , kms , kme , &
  762. ips , ipe , jps , jpe , kps , kpe )
  763. CALL stuff_bdytend ( qbdy3dtemp2 , qbdy3dtemp1 , new_bdy_frq , &
  764. nested_grid%moist_btxs(jms:jme,kms:kme,1:spec_bdy_width,P_QV), &
  765. nested_grid%moist_btxe(jms:jme,kms:kme,1:spec_bdy_width,P_QV), &
  766. nested_grid%moist_btys(ims:ime,kms:kme,1:spec_bdy_width,P_QV), &
  767. nested_grid%moist_btye(ims:ime,kms:kme,1:spec_bdy_width,P_QV), &
  768. 'T' , &
  769. spec_bdy_width , &
  770. ids , ide , jds , jde , kds , kde , &
  771. ims , ime , jms , jme , kms , kme , &
  772. ips , ipe , jps , jpe , kps , kpe )
  773. CALL stuff_bdytend ( mbdy2dtemp2 , mbdy2dtemp1 , new_bdy_frq , &
  774. nested_grid%mu_btxs, nested_grid%mu_btxe , &
  775. nested_grid%mu_btys, nested_grid%mu_btye , &
  776. 'M' , &
  777. spec_bdy_width , &
  778. ids , ide , jds , jde , 1 , 1 , &
  779. ims , ime , jms , jme , 1 , 1 , &
  780. ips , ipe , jps , jpe , 1 , 1 )
  781. #ifdef WRF_CHEM
  782. do nvchem=1,num_chem
  783. cbdy3dtemp1(ips:ipe,kps:kpe,jps:jpe)=cbdy3dtemp0(ips:ipe,kps:kpe,jps:jpe,nvchem)
  784. cbdy3dtemp2(ips:ipe,kps:kpe,jps:jpe)=nested_grid%chem(ips:ipe,kps:kpe,jps:jpe,nvchem)
  785. ! if(nvchem.eq.p_o3)then
  786. ! write(0,*)'fill 1ch_b2',time_loop,cbdy3dtemp1(ips,kps,jps),cbdy3dtemp0(ips,kps,jps,nvchem),cbdy3dtemp2(ips,kps,jps)
  787. ! endif
  788. CALL stuff_bdytend ( cbdy3dtemp2 , cbdy3dtemp1 , new_bdy_frq , &
  789. nested_grid%chem_btxs(jms:jme,kms:kme,1:spec_bdy_width,nvchem), &
  790. nested_grid%chem_btxe(jms:jme,kms:kme,1:spec_bdy_width,nvchem), &
  791. nested_grid%chem_btys(ims:ime,kms:kme,1:spec_bdy_width,nvchem), &
  792. nested_grid%chem_btye(ims:ime,kms:kme,1:spec_bdy_width,nvchem), &
  793. 'T' , &
  794. spec_bdy_width , &
  795. ids , ide , jds , jde , kds , kde , &
  796. ims , ime , jms , jme , kms , kme , &
  797. ips , ipe , jps , jpe , kps , kpe )
  798. cbdy3dtemp0(ips:ipe,kps:kpe,jps:jpe,nvchem)=cbdy3dtemp2(ips:ipe,kps:kpe,jps:jpe)
  799. ! if(nvchem.eq.p_o3)then
  800. ! write(0,*)'fill 2ch_b2',cbdy3dtemp1(ips,kps,jps),cbdy3dtemp0(ips,kps,jps,nvchem),cbdy3dtemp2(ips,kps,jps)
  801. ! endif
  802. enddo
  803. #endif
  804. IF ( time_loop .EQ. 2 ) THEN
  805. ! Generate an output file from this program, which will be an input file to WRF.
  806. CALL wrf_debug ( 100 , 'ndown_em main: calling open_w_dataset for wrfbdy' )
  807. CALL construct_filename1( bdyname , 'wrfbdy' , nested_grid%id , 2 )
  808. CALL open_w_dataset ( fidb, TRIM(bdyname) , nested_grid , config_flags , output_boundary , &
  809. "DATASET=BOUNDARY", ierr )
  810. IF ( ierr .NE. 0 ) THEN
  811. WRITE( wrf_err_message , FMT='(A,A,A,I8)' ) 'program ndown: error opening ',TRIM(bdyname),' for reading ierr=',ierr
  812. CALL WRF_ERROR_FATAL ( wrf_err_message )
  813. ENDIF
  814. END IF
  815. ! Both pieces of the boundary data are now available to be written.
  816. CALL domain_clock_set( nested_grid, &
  817. current_timestr=current_date(1:19) )
  818. temp24= current_date
  819. temp24b=start_date_hold
  820. start_date = start_date_hold
  821. CALL geth_newdate ( temp19 , temp24b(1:19) , (time_loop-2) * model_config_rec%interval_seconds )
  822. current_date = temp19 // '.0000'
  823. CALL geth_julgmt ( julyr , julday , gmt)
  824. CALL nl_set_julyr ( nested_grid%id , julyr )
  825. CALL nl_set_julday ( nested_grid%id , julday )
  826. CALL nl_set_gmt ( nested_grid%id , gmt )
  827. CALL wrf_put_dom_ti_real ( fidb , 'GMT' , gmt , 1 , ierr )
  828. CALL wrf_put_dom_ti_integer ( fidb , 'JULYR' , julyr , 1 , ierr )
  829. CALL wrf_put_dom_ti_integer ( fidb , 'JULDAY' , julday , 1 , ierr )
  830. CALL domain_clock_set( nested_grid, &
  831. current_timestr=current_date(1:19) )
  832. print *,'bdy time = ',time_loop-1,' bdy date = ',current_date,' ',start_date
  833. CALL output_boundary ( fidb , nested_grid , config_flags , ierr )
  834. current_date = temp24
  835. start_date = temp24b
  836. CALL domain_clock_set( nested_grid, &
  837. current_timestr=current_date(1:19) )
  838. IF ( time_loop .EQ. 2 ) THEN
  839. CALL wrf_put_dom_ti_real ( fidb , 'BDYFRQ' , new_bdy_frq , 1 , ierr )
  840. END IF
  841. ! We need to save the 3d data to compute a difference during the next loop. Couple the
  842. ! 3d fields with total mu (mub + mu_2) and the stagger-specific map scale factor.
  843. ! We load up the boundary data again for use in the next loop.
  844. DO j = jps , jpe
  845. DO k = kps , kpe
  846. DO i = ips , ipe
  847. ubdy3dtemp1(i,k,j) = ubdy3dtemp2(i,k,j)
  848. vbdy3dtemp1(i,k,j) = vbdy3dtemp2(i,k,j)
  849. tbdy3dtemp1(i,k,j) = tbdy3dtemp2(i,k,j)
  850. pbdy3dtemp1(i,k,j) = pbdy3dtemp2(i,k,j)
  851. qbdy3dtemp1(i,k,j) = qbdy3dtemp2(i,k,j)
  852. END DO
  853. END DO
  854. END DO
  855. DO j = jps , jpe
  856. DO i = ips , ipe
  857. mbdy2dtemp1(i,1,j) = mbdy2dtemp2(i,1,j)
  858. END DO
  859. END DO
  860. ! There are 2 components to the lateral boundaries. First, there is the starting
  861. ! point of this time period - just the outer few rows and columns.
  862. CALL stuff_bdy ( ubdy3dtemp1 , &
  863. nested_grid%u_bxs, nested_grid%u_bxe , &
  864. nested_grid%u_bys, nested_grid%u_bye , &
  865. 'U' , spec_bdy_width , &
  866. ids , ide , jds , jde , kds , kde , &
  867. ims , ime , jms , jme , kms , kme , &
  868. ips , ipe , jps , jpe , kps , kpe )
  869. CALL stuff_bdy ( vbdy3dtemp1 , &
  870. nested_grid%v_bxs, nested_grid%v_bxe , &
  871. nested_grid%v_bys, nested_grid%v_bye , &
  872. 'V' , spec_bdy_width , &
  873. ids , ide , jds , jde , kds , kde , &
  874. ims , ime , jms , jme , kms , kme , &
  875. ips , ipe , jps , jpe , kps , kpe )
  876. CALL stuff_bdy ( tbdy3dtemp1 , &
  877. nested_grid%t_bxs, nested_grid%t_bxe , &
  878. nested_grid%t_bys, nested_grid%t_bye , &
  879. 'T' , spec_bdy_width , &
  880. ids , ide , jds , jde , kds , kde , &
  881. ims , ime , jms , jme , kms , kme , &
  882. ips , ipe , jps , jpe , kps , kpe )
  883. CALL stuff_bdy ( pbdy3dtemp1 , &
  884. nested_grid%ph_bxs, nested_grid%ph_bxe , &
  885. nested_grid%ph_bys, nested_grid%ph_bye , &
  886. 'W' , spec_bdy_width , &
  887. ids , ide , jds , jde , kds , kde , &
  888. ims , ime , jms , jme , kms , kme , &
  889. ips , ipe , jps , jpe , kps , kpe )
  890. CALL stuff_bdy ( qbdy3dtemp1 , &
  891. nested_grid%moist_bxs(jms:jme,kms:kme,1:spec_bdy_width,P_QV), &
  892. nested_grid%moist_bxe(jms:jme,kms:kme,1:spec_bdy_width,P_QV), &
  893. nested_grid%moist_bys(ims:ime,kms:kme,1:spec_bdy_width,P_QV), &
  894. nested_grid%moist_bye(ims:ime,kms:kme,1:spec_bdy_width,P_QV), &
  895. 'T' , spec_bdy_width , &
  896. ids , ide , jds , jde , kds , kde , &
  897. ims , ime , jms , jme , kms , kme , &
  898. ips , ipe , jps , jpe , kps , kpe )
  899. #ifdef WRF_CHEM
  900. do nvchem=1,num_chem
  901. cbdy3dtemp1(ips:ipe,kps:kpe,jps:jpe)=cbdy3dtemp0(ips:ipe,kps:kpe,jps:jpe,nvchem)
  902. ! if(nvchem.eq.p_o3)then
  903. ! write(0,*)'fill 2ch_b3',cbdy3dtemp1(ips,kps,jps),cbdy3dtemp0(ips,kps,jps,nvchem)
  904. ! endif
  905. CALL stuff_bdy ( cbdy3dtemp1 , &
  906. nested_grid%chem_bxs(jms:jme,kms:kme,1:spec_bdy_width,nvchem), &
  907. nested_grid%chem_bxe(jms:jme,kms:kme,1:spec_bdy_width,nvchem), &
  908. nested_grid%chem_bys(ims:ime,kms:kme,1:spec_bdy_width,nvchem), &
  909. nested_grid%chem_bye(ims:ime,kms:kme,1:spec_bdy_width,nvchem), &
  910. 'T' , spec_bdy_width , &
  911. ids , ide , jds , jde , kds , kde , &
  912. ims , ime , jms , jme , kms , kme , &
  913. ips , ipe , jps , jpe , kps , kpe )
  914. ! cbdy3dtemp0(ips:ipe,kps:kpe,jps:jpe,nvchem)=cbdy3dtemp1(ips:ipe,kps:kpe,jps:jpe)
  915. ! if(nvchem.eq.p_o3)then
  916. ! write(0,*)'fill 2ch_b3',cbdy3dtemp1(ips,kps,jps),cbdy3dtemp0(ips,kps,jps,nvchem)
  917. ! endif
  918. enddo
  919. #endif
  920. CALL stuff_bdy ( mbdy2dtemp1 , &
  921. nested_grid%mu_bxs, nested_grid%mu_bxe , &
  922. nested_grid%mu_bys, nested_grid%mu_bye , &
  923. 'M' , spec_bdy_width , &
  924. ids , ide , jds , jde , 1 , 1 , &
  925. ims , ime , jms , jme , 1 , 1 , &
  926. ips , ipe , jps , jpe , 1 , 1 )
  927. ELSE IF ( time_loop .EQ. time_loop_max ) THEN
  928. ! u, theta, h, scalars coupled with my, v coupled with mx
  929. CALL couple ( nested_grid%mu_2 , nested_grid%mub , ubdy3dtemp2 , nested_grid%u_2 , &
  930. 'u' , nested_grid%msfuy , &
  931. ids, ide, jds, jde, kds, kde, ims, ime, jms, jme, kms, kme, ips, ipe, jps, jpe, kps, kpe )
  932. CALL couple ( nested_grid%mu_2 , nested_grid%mub , vbdy3dtemp2 , nested_grid%v_2 , &
  933. 'v' , nested_grid%msfvx , &
  934. ids, ide, jds, jde, kds, kde, ims, ime, jms, jme, kms, kme, ips, ipe, jps, jpe, kps, kpe )
  935. CALL couple ( nested_grid%mu_2 , nested_grid%mub , tbdy3dtemp2 , nested_grid%t_2 , &
  936. 't' , nested_grid%msfty , &
  937. ids, ide, jds, jde, kds, kde, ims, ime, jms, jme, kms, kme, ips, ipe, jps, jpe, kps, kpe )
  938. CALL couple ( nested_grid%mu_2 , nested_grid%mub , pbdy3dtemp2 , nested_grid%ph_2 , &
  939. 'h' , nested_grid%msfty , &
  940. ids, ide, jds, jde, kds, kde, ims, ime, jms, jme, kms, kme, ips, ipe, jps, jpe, kps, kpe )
  941. CALL couple ( nested_grid%mu_2 , nested_grid%mub , qbdy3dtemp2 , nested_grid%moist(ims:ime,kms:kme,jms:jme,P_QV) , &
  942. 't' , nested_grid%msfty , &
  943. ids, ide, jds, jde, kds, kde, ims, ime, jms, jme, kms, kme, ips, ipe, jps, jpe, kps, kpe )
  944. mbdy2dtemp2(:,1,:) = nested_grid%mu_2(:,:)
  945. ! During all of the loops after the first loop, we first compute the boundary
  946. ! tendencies with the current data values and the previously save information
  947. ! stored in the *bdy3dtemp1 arrays.
  948. #ifdef WRF_CHEM
  949. do nvchem=1,num_chem
  950. cbdy3dtemp1(ips:ipe,kps:kpe,jps:jpe)=cbdy3dtemp0(ips:ipe,kps:kpe,jps:jpe,nvchem)
  951. cbdy3dtemp2(ips:ipe,kps:kpe,jps:jpe)=nested_grid%chem(ips:ipe,kps:kpe,jps:jpe,nvchem)
  952. ! if(nvchem.eq.p_o3)then
  953. ! write(0,*)'fill 1ch_b4',cbdy3dtemp1(ips,kps,jps),cbdy3dtemp0(ips,kps,jps,nvchem),cbdy3dtemp2(ips,kps,jps)
  954. ! endif
  955. CALL stuff_bdytend ( cbdy3dtemp2 , cbdy3dtemp1 , new_bdy_frq , &
  956. nested_grid%chem_btxs(jms:jme,kms:kme,1:spec_bdy_width,nvchem), &
  957. nested_grid%chem_btxe(jms:jme,kms:kme,1:spec_bdy_width,nvchem), &
  958. nested_grid%chem_btys(ims:ime,kms:kme,1:spec_bdy_width,nvchem), &
  959. nested_grid%chem_btye(ims:ime,kms:kme,1:spec_bdy_width,nvchem), &
  960. 'T' , &
  961. spec_bdy_width , &
  962. ids , ide , jds , jde , kds , kde , &
  963. ims , ime , jms , jme , kms , kme , &
  964. ips , ipe , jps , jpe , kps , kpe )
  965. cbdy3dtemp0(ips:ipe,kps:kpe,jps:jpe,nvchem)=cbdy3dtemp2(ips:ipe,kps:kpe,jps:jpe)
  966. ! if(nvchem.eq.p_o3)then
  967. ! write(0,*)'fill 2ch_b4',cbdy3dtemp1(ips,kps,jps),cbdy3dtemp0(ips,kps,jps,nvchem),cbdy3dtemp2(ips,kps,jps)
  968. ! endif
  969. enddo
  970. #endif
  971. CALL stuff_bdytend ( ubdy3dtemp2 , ubdy3dtemp1 , new_bdy_frq , &
  972. nested_grid%u_btxs , nested_grid%u_btxe , &
  973. nested_grid%u_btys , nested_grid%u_btye , &
  974. 'U' , &
  975. spec_bdy_width , &
  976. ids , ide , jds , jde , kds , kde , &
  977. ims , ime , jms , jme , kms , kme , &
  978. ips , ipe , jps , jpe , kps , kpe )
  979. CALL stuff_bdytend ( vbdy3dtemp2 , vbdy3dtemp1 , new_bdy_frq , &
  980. nested_grid%v_btxs , nested_grid%v_btxe , &
  981. nested_grid%v_btys , nested_grid%v_btye , &
  982. 'V' , &
  983. spec_bdy_width , &
  984. ids , ide , jds , jde , kds , kde , &
  985. ims , ime , jms , jme , kms , kme , &
  986. ips , ipe , jps , jpe , kps , kpe )
  987. CALL stuff_bdytend ( tbdy3dtemp2 , tbdy3dtemp1 , new_bdy_frq , &
  988. nested_grid%t_btxs , nested_grid%t_btxe , &
  989. nested_grid%t_btys , nested_grid%t_btye , &
  990. 'T' , &
  991. spec_bdy_width , &
  992. ids , ide , jds , jde , kds , kde , &
  993. ims , ime , jms , jme , kms , kme , &
  994. ips , ipe , jps , jpe , kps , kpe )
  995. CALL stuff_bdytend ( pbdy3dtemp2 , pbdy3dtemp1 , new_bdy_frq , &
  996. nested_grid%ph_btxs , nested_grid%ph_btxe , &
  997. nested_grid%ph_btys , nested_grid%ph_btye , &
  998. 'W' , &
  999. spec_bdy_width , &
  1000. ids , ide , jds , jde , kds , kde , &
  1001. ims , ime , jms , jme , kms , kme , &
  1002. ips , ipe , jps , jpe , kps , kpe )
  1003. CALL stuff_bdytend ( qbdy3dtemp2 , qbdy3dtemp1 , new_bdy_frq , &
  1004. nested_grid%moist_btxs(jms:jme,kms:kme,1:spec_bdy_width,P_QV) , &
  1005. nested_grid%moist_btxe(jms:jme,kms:kme,1:spec_bdy_width,P_QV) , &
  1006. nested_grid%moist_btys(ims:ime,kms:kme,1:spec_bdy_width,P_QV) , &
  1007. nested_grid%moist_btye(ims:ime,kms:kme,1:spec_bdy_width,P_QV) , &
  1008. 'T' , &
  1009. spec_bdy_width , &
  1010. ids , ide , jds , jde , kds , kde , &
  1011. ims , ime , jms , jme , kms , kme , &
  1012. ips , ipe , jps , jpe , kps , kpe )
  1013. CALL stuff_bdytend ( mbdy2dtemp2 , mbdy2dtemp1 , new_bdy_frq , &
  1014. nested_grid%mu_btxs , nested_grid%mu_btxe , &
  1015. nested_grid%mu_btys , nested_grid%mu_btye , &
  1016. 'M' , &
  1017. spec_bdy_width , &
  1018. ids , ide , jds , jde , 1 , 1 , &
  1019. ims , ime , jms , jme , 1 , 1 , &
  1020. ips , ipe , jps , jpe , 1 , 1 )
  1021. IF ( time_loop .EQ. 2 ) THEN
  1022. ! Generate an output file from this program, which will be an input file to WRF.
  1023. CALL wrf_debug ( 100 , 'ndown_em main: calling open_w_dataset for wrfbdy' )
  1024. CALL construct_filename1( bdyname , 'wrfbdy' , nested_grid%id , 2 )
  1025. CALL open_w_dataset ( fidb, TRIM(bdyname) , nested_grid , config_flags , output_boundary , &
  1026. "DATASET=BOUNDARY", ierr )
  1027. IF ( ierr .NE. 0 ) THEN
  1028. WRITE( wrf_err_message , FMT='(A,A,A,I8)' ) 'program ndown: error opening ',TRIM(bdyname),' for reading ierr=',ierr
  1029. CALL WRF_ERROR_FATAL ( wrf_err_message )
  1030. ENDIF
  1031. END IF
  1032. ! Both pieces of the boundary data are now available to be written.
  1033. CALL domain_clock_set( nested_grid, &
  1034. current_timestr=current_date(1:19) )
  1035. temp24= current_date
  1036. temp24b=start_date_hold
  1037. start_date = start_date_hold
  1038. CALL geth_newdate ( temp19 , temp24b(1:19) , (time_loop-2) * model_config_rec%interval_seconds )
  1039. current_date = temp19 // '.0000'
  1040. CALL geth_julgmt ( julyr , julday , gmt)
  1041. CALL nl_set_julyr ( nested_grid%id , julyr )
  1042. CALL nl_set_julday ( nested_grid%id , julday )
  1043. CALL nl_set_gmt ( nested_grid%id , gmt )
  1044. CALL wrf_put_dom_ti_real ( fidb , 'GMT' , gmt , 1 , ierr )
  1045. CALL wrf_put_dom_ti_integer ( fidb , 'JULYR' , julyr , 1 , ierr )
  1046. CALL wrf_put_dom_ti_integer ( fidb , 'JULDAY' , julday , 1 , ierr )
  1047. CALL domain_clock_set( nested_grid, &
  1048. current_timestr=current_date(1:19) )
  1049. CALL output_boundary ( fidb , nested_grid , config_flags , ierr )
  1050. current_date = temp24
  1051. start_date = temp24b
  1052. CALL domain_clock_set( nested_grid, &
  1053. current_timestr=current_date(1:19) )
  1054. IF ( time_loop .EQ. 2 ) THEN
  1055. CALL wrf_put_dom_ti_real ( fidb , 'BDYFRQ' , new_bdy_frq , 1 , ierr )
  1056. END IF
  1057. ! Since this is the last time through here, we need to close the boundary file.
  1058. CALL model_to_grid_config_rec ( nested_grid%id , model_config_rec , config_flags )
  1059. CALL close_dataset ( fidb , config_flags , "DATASET=BOUNDARY" )
  1060. END IF
  1061. ! Process which time now?
  1062. END DO big_time_loop_thingy
  1063. DEALLOCATE(znw_c)
  1064. DEALLOCATE(znu_c)
  1065. CALL model_to_grid_config_rec ( parent_grid%id , model_config_rec , config_flags )
  1066. CALL med_shutdown_io ( parent_grid , config_flags )
  1067. CALL wrf_debug ( 0 , 'ndown_em: SUCCESS COMPLETE NDOWN_EM INIT' )
  1068. CALL wrf_shutdown
  1069. CALL WRFU_Finalize( rc=rc )
  1070. END PROGRAM ndown_em
  1071. SUBROUTINE land_percentages ( xland , &
  1072. landuse_frac , soil_top_cat , soil_bot_cat , &
  1073. isltyp , ivgtyp , &
  1074. num_veg_cat , num_soil_top_cat , num_soil_bot_cat , &
  1075. ids , ide , jds , jde , kds , kde , &
  1076. ims , ime , jms , jme , kms , kme , &
  1077. its , ite , jts , jte , kts , kte , &
  1078. iswater )
  1079. USE module_soil_pre
  1080. IMPLICIT NONE
  1081. INTEGER , INTENT(IN) :: ids , ide , jds , jde , kds , kde , &
  1082. ims , ime , jms , jme , kms , kme , &
  1083. its , ite , jts , jte , kts , kte , &
  1084. iswater
  1085. INTEGER , INTENT(IN) :: num_veg_cat , num_soil_top_cat , num_soil_bot_cat
  1086. REAL , DIMENSION(ims:ime,1:num_veg_cat,jms:jme) , INTENT(INOUT):: landuse_frac
  1087. REAL , DIMENSION(ims:ime,1:num_soil_top_cat,jms:jme) , INTENT(IN):: soil_top_cat
  1088. REAL , DIMENSION(ims:ime,1:num_soil_bot_cat,jms:jme) , INTENT(IN):: soil_bot_cat
  1089. INTEGER , DIMENSION(ims:ime,jms:jme), INTENT(OUT) :: isltyp , ivgtyp
  1090. REAL , DIMENSION(ims:ime,jms:jme) , INTENT(OUT) :: xland
  1091. CALL process_percent_cat_new ( xland , &
  1092. landuse_frac , soil_top_cat , soil_bot_cat , &
  1093. isltyp , ivgtyp , &
  1094. num_veg_cat , num_soil_top_cat , num_soil_bot_cat , &
  1095. ids , ide , jds , jde , kds , kde , &
  1096. ims , ime , jms , jme , kms , kme , &
  1097. its , ite , jts , jte , kts , kte , &
  1098. iswater )
  1099. END SUBROUTINE land_percentages
  1100. SUBROUTINE check_consistency ( ivgtyp , isltyp , landmask , &
  1101. ids , ide , jds , jde , kds , kde , &
  1102. ims , ime , jms , jme , kms , kme , &
  1103. its , ite , jts , jte , kts , kte , &
  1104. iswater )
  1105. IMPLICIT NONE
  1106. INTEGER , INTENT(IN) :: ids , ide , jds , jde , kds , kde , &
  1107. ims , ime , jms , jme , kms , kme , &
  1108. its , ite , jts , jte , kts , kte , &
  1109. iswater
  1110. INTEGER , DIMENSION(ims:ime,jms:jme), INTENT(INOUT) :: isltyp , ivgtyp
  1111. REAL , DIMENSION(ims:ime,jms:jme), INTENT(INOUT) :: landmask
  1112. LOGICAL :: oops
  1113. INTEGER :: oops_count , i , j
  1114. oops = .FALSE.
  1115. oops_count = 0
  1116. DO j = jts, MIN(jde-1,jte)
  1117. DO i = its, MIN(ide-1,ite)
  1118. IF ( ( ( landmask(i,j) .LT. 0.5 ) .AND. ( ivgtyp(i,j) .NE. iswater ) ) .OR. &
  1119. ( ( landmask(i,j) .GT. 0.5 ) .AND. ( ivgtyp(i,j) .EQ. iswater ) ) ) THEN
  1120. print *,'mismatch in landmask and veg type'
  1121. print *,'i,j=',i,j, ' landmask =',NINT(landmask(i,j)),' ivgtyp=',ivgtyp(i,j)
  1122. oops = .TRUE.
  1123. oops_count = oops_count + 1
  1124. landmask(i,j) = 0
  1125. ivgtyp(i,j)=16
  1126. isltyp(i,j)=14
  1127. END IF
  1128. END DO
  1129. END DO
  1130. IF ( oops ) THEN
  1131. CALL wrf_debug( 0, 'mismatch in check_consistency, turned to water points, be careful' )
  1132. END IF
  1133. END SUBROUTINE check_consistency
  1134. SUBROUTINE check_consistency2( ivgtyp , isltyp , landmask , &
  1135. tmn , tsk , sst , xland , &
  1136. tslb , smois , sh2o , &
  1137. num_soil_layers , id , &
  1138. ids , ide , jds , jde , kds , kde , &
  1139. ims , ime , jms , jme , kms , kme , &
  1140. its , ite , jts , jte , kts , kte , &
  1141. iswater )
  1142. USE module_configure
  1143. USE module_optional_input
  1144. INTEGER , INTENT(IN) :: ids , ide , jds , jde , kds , kde , &
  1145. ims , ime , jms , jme , kms , kme , &
  1146. its , ite , jts , jte , kts , kte
  1147. INTEGER , INTENT(IN) :: num_soil_layers , id
  1148. INTEGER , DIMENSION(ims:ime,jms:jme) :: ivgtyp , isltyp
  1149. REAL , DIMENSION(ims:ime,jms:jme) :: landmask , tmn , tsk , sst , xland
  1150. REAL , DIMENSION(ims:ime,num_soil_layers,jms:jme) :: tslb , smois , sh2o
  1151. INTEGER :: oops1 , oops2
  1152. INTEGER :: i , j , k
  1153. fix_tsk_tmn : SELECT CASE ( model_config_rec%sf_surface_physics(id) )
  1154. CASE ( SLABSCHEME , LSMSCHEME , RUCLSMSCHEME )
  1155. DO j = jts, MIN(jde-1,jte)
  1156. DO i = its, MIN(ide-1,ite)
  1157. IF ( ( landmask(i,j) .LT. 0.5 ) .AND. ( flag_sst .EQ. 1 ) ) THEN
  1158. tmn(i,j) = sst(i,j)
  1159. tsk(i,j) = sst(i,j)
  1160. ELSE IF ( landmask(i,j) .LT. 0.5 ) THEN
  1161. tmn(i,j) = tsk(i,j)
  1162. END IF
  1163. END DO
  1164. END DO
  1165. END SELECT fix_tsk_tmn
  1166. ! Is the TSK reasonable?
  1167. DO j = jts, MIN(jde-1,jte)
  1168. DO i = its, MIN(ide-1,ite)
  1169. IF ( tsk(i,j) .LT. 170 .or. tsk(i,j) .GT. 400. ) THEN
  1170. print *,'error in the TSK'
  1171. print *,'i,j=',i,j
  1172. print *,'landmask=',landmask(i,j)
  1173. print *,'tsk, sst, tmn=',tsk(i,j),sst(i,j),tmn(i,j)
  1174. if(tmn(i,j).gt.170. .and. tmn(i,j).lt.400.)then
  1175. tsk(i,j)=tmn(i,j)
  1176. else if(sst(i,j).gt.170. .and. sst(i,j).lt.400.)then
  1177. tsk(i,j)=sst(i,j)
  1178. else
  1179. CALL wrf_error_fatal ( 'TSK unreasonable' )
  1180. end if
  1181. END IF
  1182. END DO
  1183. END DO
  1184. ! Is the TMN reasonable?
  1185. DO j = jts, MIN(jde-1,jte)
  1186. DO i = its, MIN(ide-1,ite)
  1187. IF ( ( ( tmn(i,j) .LT. 170. ) .OR. ( tmn(i,j) .GT. 400. ) ) .AND. ( landmask(i,j) .GT. 0.5 ) ) THEN
  1188. print *,'error in the TMN'
  1189. print *,'i,j=',i,j
  1190. print *,'landmask=',landmask(i,j)
  1191. print *,'tsk, sst, tmn=',tsk(i,j),sst(i,j),tmn(i,j)
  1192. if(tsk(i,j).gt.170. .and. tsk(i,j).lt.400.)then
  1193. tmn(i,j)=tsk(i,j)
  1194. else if(sst(i,j).gt.170. .and. sst(i,j).lt.400.)then
  1195. tmn(i,j)=sst(i,j)
  1196. else
  1197. CALL wrf_error_fatal ( 'TMN unreasonable' )
  1198. endif
  1199. END IF
  1200. END DO
  1201. END DO
  1202. ! Is the TSLB reasonable?
  1203. DO j = jts, MIN(jde-1,jte)
  1204. DO i = its, MIN(ide-1,ite)
  1205. IF ( ( ( tslb(i,1,j) .LT. 170. ) .OR. ( tslb(i,1,j) .GT. 400. ) ) .AND. ( landmask(i,j) .GT. 0.5 ) ) THEN
  1206. print *,'error in the TSLB'
  1207. print *,'i,j=',i,j
  1208. print *,'landmask=',landmask(i,j)
  1209. print *,'tsk, sst, tmn=',tsk(i,j),sst(i,j),tmn(i,j)
  1210. print *,'tslb = ',tslb(i,:,j)
  1211. print *,'old smois = ',smois(i,:,j)
  1212. DO l = 1 , num_soil_layers
  1213. sh2o(i,l,j) = 0.0
  1214. END DO
  1215. DO l = 1 , num_soil_layers
  1216. smois(i,l,j) = 0.3
  1217. END DO
  1218. if(tsk(i,j).gt.170. .and. tsk(i,j).lt.400.)then
  1219. DO l = 1 , num_soil_layers
  1220. tslb(i,l,j)=tsk(i,j)
  1221. END DO
  1222. else if(sst(i,j).gt.170. .and. sst(i,j).lt.400.)then
  1223. DO l = 1 , num_soil_layers
  1224. tslb(i,l,j)=sst(i,j)
  1225. END DO
  1226. else if(tmn(i,j).gt.170. .and. tmn(i,j).lt.400.)then
  1227. DO l = 1 , num_soil_layers
  1228. tslb(i,l,j)=tmn(i,j)
  1229. END DO
  1230. else
  1231. CALL wrf_error_fatal ( 'TSLB unreasonable' )
  1232. endif
  1233. END IF
  1234. END DO
  1235. END DO
  1236. ! Let us make sure (again) that the landmask and the veg/soil categories match.
  1237. oops1=0
  1238. oops2=0
  1239. DO j = jts, MIN(jde-1,jte)
  1240. DO i = its, MIN(ide-1,ite)
  1241. IF ( ( ( landmask(i,j) .LT. 0.5 ) .AND. ( ivgtyp(i,j) .NE. iswater .OR. isltyp(i,j) .NE. 14 ) ) .OR. &
  1242. ( ( landmask(i,j) .GT. 0.5 ) .AND. ( ivgtyp(i,j) .EQ. iswater .OR. isltyp(i,j) .EQ. 14 ) ) ) THEN
  1243. IF ( tslb(i,1,j) .GT. 1. ) THEN
  1244. oops1=oops1+1
  1245. ivgtyp(i,j) = 5
  1246. isltyp(i,j) = 8
  1247. landmask(i,j) = 1
  1248. xland(i,j) = 1
  1249. ELSE IF ( sst(i,j) .GT. 1. ) THEN
  1250. oops2=oops2+1
  1251. ivgtyp(i,j) = iswater
  1252. isltyp(i,j) = 14
  1253. landmask(i,j) = 0
  1254. xland(i,j) = 2
  1255. ELSE
  1256. print *,'the landmask and soil/veg cats do not match'
  1257. print *,'i,j=',i,j
  1258. print *,'landmask=',landmask(i,j)
  1259. print *,'ivgtyp=',ivgtyp(i,j)
  1260. print *,'isltyp=',isltyp(i,j)
  1261. print *,'iswater=', iswater
  1262. print *,'tslb=',tslb(i,:,j)
  1263. print *,'sst=',sst(i,j)
  1264. CALL wrf_error_fatal ( 'mismatch_landmask_ivgtyp' )
  1265. END IF
  1266. END IF
  1267. END DO
  1268. END DO
  1269. if (oops1.gt.0) then
  1270. print *,'points artificially set to land : ',oops1
  1271. endif
  1272. if(oops2.gt.0) then
  1273. print *,'points artificially set to water: ',oops2
  1274. endif
  1275. END SUBROUTINE check_consistency2
  1276. !!!!!!!!!!!!!!!!!!!!!!!!!!!11
  1277. SUBROUTINE vert_cor(parent,znw_c,k_dim_c)
  1278. USE module_domain
  1279. IMPLICIT NONE
  1280. TYPE(domain), POINTER :: parent
  1281. integer , intent(in) :: k_dim_c
  1282. real , dimension(k_dim_c), INTENT(IN) :: znw_c
  1283. integer :: kde_c , kde_n ,n_refine,ii,kkk,k
  1284. real :: dznw_m,cof1,cof2
  1285. kde_c = k_dim_c
  1286. kde_n = parent%e_vert
  1287. n_refine = parent % vert_refine_fact
  1288. kkk = 0
  1289. do k = 1 , kde_c-1
  1290. dznw_m = znw_c(k+1) - znw_c(k)
  1291. do ii = 1,n_refine
  1292. kkk = kkk + 1
  1293. parent%znw(kkk) = znw_c(k) + float(ii-1)/float(n_refine)*dznw_m
  1294. enddo
  1295. enddo
  1296. parent%znw(kde_n) = znw_c(kde_c)
  1297. parent%znw(1) = znw_c(1)
  1298. DO k=1, kde_n-1
  1299. parent%dnw(k) = parent%znw(k+1) - parent%znw(k)
  1300. parent%rdnw(k) = 1./parent%dnw(k)
  1301. parent%znu(k) = 0.5*(parent%znw(k+1)+parent%znw(k))
  1302. END DO
  1303. DO k=2, kde_n-1
  1304. parent%dn(k) = 0.5*(parent%dnw(k)+parent%dnw(k-1))
  1305. parent%rdn(k) = 1./parent%dn(k)
  1306. parent%fnp(k) = .5* parent%dnw(k )/parent%dn(k)
  1307. parent%fnm(k) = .5* parent%dnw(k-1)/parent%dn(k)
  1308. END DO
  1309. cof1 = (2.*parent%dn(2)+parent%dn(3))/(parent%dn(2)+parent%dn(3))*parent%dnw(1)/parent%dn(2)
  1310. cof2 = parent%dn(2) /(parent%dn(2)+parent%dn(3))*parent%dnw(1)/parent%dn(3)
  1311. parent%cf1 = parent%fnp(2) + cof1
  1312. parent%cf2 = parent%fnm(2) - cof1 - cof2
  1313. parent%cf3 = cof2
  1314. parent%cfn = (.5*parent%dnw(kde_n-1)+parent%dn(kde_n-1))/parent%dn(kde_n-1)
  1315. parent%cfn1 = -.5*parent%dnw(kde_n-1)/parent%dn(kde_n-1)
  1316. END SUBROUTINE vert_cor
  1317. SUBROUTINE init_domain_constants_em_ptr ( parent , nest )
  1318. USE module_domain
  1319. USE module_configure
  1320. IMPLICIT NONE
  1321. TYPE(domain), POINTER :: parent , nest
  1322. INTERFACE
  1323. SUBROUTINE init_domain_constants_em ( parent , nest )
  1324. USE module_domain
  1325. USE module_configure
  1326. TYPE(domain) :: parent , nest
  1327. END SUBROUTINE init_domain_constants_em
  1328. END INTERFACE
  1329. CALL init_domain_constants_em ( parent , nest )
  1330. END SUBROUTINE init_domain_constants_em_ptr
  1331. SUBROUTINE vertical_interp (parent_grid,znw_c,znu_c,cf1_c,cf2_c,cf3_c,cfn_c,cfn1_c,k_dim_c)
  1332. USE module_domain
  1333. USE module_configure
  1334. IMPLICIT NONE
  1335. TYPE(domain), POINTER :: parent_grid
  1336. INTEGER , INTENT (IN) :: k_dim_c
  1337. REAL , INTENT (IN) :: cf1_c,cf2_c,cf3_c,cfn_c,cfn1_c
  1338. REAL , DIMENSION(k_dim_c) , INTENT (IN) :: znw_c,znu_c
  1339. integer :: kde_c , kde_n ,n_refine,ii,kkk
  1340. integer :: i , j, k , itrace
  1341. real :: p_top_m , p_surf_m , mu_m , hsca_m , pre_c ,pre_n
  1342. real, allocatable, dimension(:) :: alt_w_c , alt_u_c ,pro_w_c , pro_u_c
  1343. real, allocatable, dimension(:) :: alt_w_n , alt_u_n ,pro_w_n , pro_u_n
  1344. INTEGER :: nids, nide, njds, njde, nkds, nkde, &
  1345. nims, nime, njms, njme, nkms, nkme, &
  1346. nips, nipe, njps, njpe, nkps, nkpe
  1347. hsca_m = 6.7
  1348. n_refine = model_config_rec % vert_refine_fact
  1349. kde_c = k_dim_c
  1350. kde_n = parent_grid%e_vert
  1351. CALL get_ijk_from_grid ( parent_grid , &
  1352. nids, nide, njds, njde, nkds, nkde, &
  1353. nims, nime, njms, njme, nkms, nkme, &
  1354. nips, nipe, njps, njpe, nkps, nkpe )
  1355. print * , 'MOUSTA_VER ',parent_grid%e_vert , kde_c , kde_n
  1356. print *, nids , nide , njds , njde , nkds , nkde
  1357. print *, nims , nime , njms , njme , nkms , nkme
  1358. print *, nips , nipe , njps , njpe , nkps , nkpe
  1359. allocate (alt_w_c(kde_c))
  1360. allocate (alt_u_c(kde_c+1))
  1361. allocate (pro_w_c(kde_c))
  1362. allocate (pro_u_c(kde_c+1))
  1363. allocate (alt_w_n(kde_n))
  1364. allocate (alt_u_n(kde_n+1))
  1365. allocate (pro_w_n(kde_n))
  1366. allocate (pro_u_n(kde_n+1))
  1367. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!11111
  1368. p_top_m = parent_grid%p_top
  1369. p_surf_m = 1.e5
  1370. mu_m = p_surf_m - p_top_m
  1371. print * , 'p_top_m', p_top_m
  1372. ! parent
  1373. do k = 1,kde_c
  1374. pre_c = mu_m * znw_c(k) + p_top_m
  1375. alt_w_c(k) = -hsca_m * alog(pre_c/p_surf_m)
  1376. enddo
  1377. do k = 1,kde_c-1
  1378. pre_c = mu_m * znu_c(k) + p_top_m
  1379. alt_u_c(k+1) = -hsca_m * alog(pre_c/p_surf_m)
  1380. enddo
  1381. alt_u_c(1) = alt_w_c(1)
  1382. alt_u_c(kde_c+1) = alt_w_c(kde_c)
  1383. ! nest
  1384. do k = 1,kde_n
  1385. pre_n = mu_m * parent_grid%znw(k) + p_top_m
  1386. alt_w_n(k) = -hsca_m * alog(pre_n/p_surf_m)
  1387. enddo
  1388. do k = 1,kde_n-1
  1389. pre_n = mu_m * parent_grid%znu(k) + p_top_m
  1390. alt_u_n(k+1) = -hsca_m * alog(pre_n/p_surf_m)
  1391. enddo
  1392. alt_u_n(1) = alt_w_n(1)
  1393. alt_u_n(kde_n+1) = alt_w_n(kde_n)
  1394. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1395. IF ( SIZE( parent_grid%u_2, 1 ) * SIZE( parent_grid%u_2, 3 ) .GT. 1 ) THEN
  1396. do j = njms , njme
  1397. do i = nims , nime
  1398. do k = 1,kde_c-1
  1399. pro_u_c(k+1) = parent_grid%u_2(i,k,j)
  1400. enddo
  1401. pro_u_c(1 ) = cf1_c*parent_grid%u_2(i,1,j) &
  1402. + cf2_c*parent_grid%u_2(i,2,j) &
  1403. + cf3_c*parent_grid%u_2(i,3,j)
  1404. pro_u_c(kde_c+1) = cfn_c *parent_grid%u_2(i,kde_c-1,j) &
  1405. + cfn1_c*parent_grid%u_2(i,kde_c-2,j)
  1406. call inter(pro_u_c,alt_u_c,kde_c+1,pro_u_n,alt_u_n,kde_n+1)
  1407. do k = 1,kde_n-1
  1408. parent_grid%u_2(i,k,j) = pro_u_n(k+1)
  1409. enddo
  1410. enddo
  1411. enddo
  1412. ENDIF
  1413. IF ( SIZE( parent_grid%v_2, 1 ) * SIZE( parent_grid%v_2, 3 ) .GT. 1 ) THEN
  1414. do j = njms , njme
  1415. do i = nims , nime
  1416. do k = 1,kde_c-1
  1417. pro_u_c(k+1) = parent_grid%v_2(i,k,j)
  1418. enddo
  1419. pro_u_c(1 ) = cf1_c*parent_grid%v_2(i,1,j) &
  1420. + cf2_c*parent_grid%v_2(i,2,j) &
  1421. + cf3_c*parent_grid%v_2(i,3,j)
  1422. pro_u_c(kde_c+1) = cfn_c *parent_grid%v_2(i,kde_c-1,j) &
  1423. + cfn1_c*parent_grid%v_2(i,kde_c-2,j)
  1424. call inter(pro_u_c,alt_u_c,kde_c+1,pro_u_n,alt_u_n,kde_n+1)
  1425. do k = 1,kde_n-1
  1426. parent_grid%v_2(i,k,j) = pro_u_n(k+1)
  1427. enddo
  1428. enddo
  1429. enddo
  1430. ENDIF
  1431. IF ( SIZE( parent_grid%w_2, 1 ) * SIZE( parent_grid%w_2, 3 ) .GT. 1 ) THEN
  1432. do j = njms , njme
  1433. do i = nims , nime
  1434. do k = 1,kde_c
  1435. pro_w_c(k) = parent_grid%w_2(i,k,j)
  1436. enddo
  1437. call inter(pro_w_c,alt_w_c,kde_c,pro_w_n,alt_w_n,kde_n)
  1438. do k = 1,kde_n
  1439. parent_grid%w_2(i,k,j) = pro_w_n(k)
  1440. enddo
  1441. enddo
  1442. enddo
  1443. ENDIF
  1444. IF ( SIZE( parent_grid%t_2, 1 ) * SIZE( parent_grid%t_2, 3 ) .GT. 1 ) THEN
  1445. do j = njms , njme
  1446. do i = nims , nime
  1447. do k = 1,kde_c-1
  1448. pro_u_c(k+1) = parent_grid%t_2(i,k,j)
  1449. enddo
  1450. pro_u_c(1 ) = cf1_c*parent_grid%t_2(i,1,j) &
  1451. + cf2_c*parent_grid%t_2(i,2,j) &
  1452. + cf3_c*parent_grid%t_2(i,3,j)
  1453. pro_u_c(kde_c+1) = cfn_c *parent_grid%t_2(i,kde_c-1,j) &
  1454. + cfn1_c*parent_grid%t_2(i,kde_c-2,j)
  1455. call inter(pro_u_c,alt_u_c,kde_c+1,pro_u_n,alt_u_n,kde_n+1)
  1456. do k = 1,kde_n-1
  1457. parent_grid%t_2(i,k,j) = pro_u_n(k+1)
  1458. enddo
  1459. enddo
  1460. enddo
  1461. ENDIF
  1462. DO itrace = PARAM_FIRST_SCALAR, num_moist
  1463. IF ( SIZE( parent_grid%moist, 1 ) * SIZE( parent_grid%moist, 3 ) .GT. 1 ) THEN
  1464. do j = njms , njme
  1465. do i = nims , nime
  1466. do k = 1,kde_c-1
  1467. pro_u_c(k+1) = parent_grid%moist(i,k,j,itrace)
  1468. enddo
  1469. pro_u_c(1 ) = cf1_c*parent_grid%moist(i,1,j,itrace) &
  1470. + cf2_c*parent_grid%moist(i,2,j,itrace) &
  1471. + cf3_c*parent_grid%moist(i,3,j,itrace)
  1472. pro_u_c(kde_c+1) = cfn_c *parent_grid%moist(i,kde_c-1,j,itrace) &
  1473. + cfn1_c*parent_grid%moist(i,kde_c-2,j,itrace)
  1474. call inter(pro_u_c,alt_u_c,kde_c+1,pro_u_n,alt_u_n,kde_n+1)
  1475. do k = 1,kde_n-1
  1476. parent_grid%moist(i,k,j,itrace) = pro_u_n(k+1)
  1477. enddo
  1478. enddo
  1479. enddo
  1480. ENDIF
  1481. ENDDO
  1482. DO itrace = PARAM_FIRST_SCALAR, num_dfi_moist
  1483. IF ( SIZE( parent_grid%dfi_moist, 1 ) * SIZE( parent_grid%dfi_moist, 3 ) .GT. 1 ) THEN
  1484. do j = njms , njme
  1485. do i = nims , nime
  1486. do k = 1,kde_c-1
  1487. pro_u_c(k+1) = parent_grid%dfi_moist(i,k,j,itrace)
  1488. enddo
  1489. pro_u_c(1 ) = cf1_c*parent_grid%dfi_moist(i,1,j,itrace) &
  1490. + cf2_c*parent_grid%dfi_moist(i,2,j,itrace) &
  1491. + cf3_c*parent_grid%dfi_moist(i,3,j,itrace)
  1492. pro_u_c(kde_c+1) = cfn_c *parent_grid%dfi_moist(i,kde_c-1,j,itrace) &
  1493. + cfn1_c*parent_grid%dfi_moist(i,kde_c-2,j,itrace)
  1494. call inter(pro_u_c,alt_u_c,kde_c+1,pro_u_n,alt_u_n,kde_n+1)
  1495. do k = 1,kde_n-1
  1496. parent_grid%dfi_moist(i,k,j,itrace) = pro_u_n(k+1)
  1497. enddo
  1498. enddo
  1499. enddo
  1500. ENDIF
  1501. ENDDO
  1502. DO itrace = PARAM_FIRST_SCALAR, num_scalar
  1503. IF ( SIZE( parent_grid%scalar, 1 ) * SIZE( parent_grid%scalar, 3 ) .GT. 1 ) THEN
  1504. do j = njms , njme
  1505. do i = nims , nime
  1506. do k = 1,kde_c-1
  1507. pro_u_c(k+1) = parent_grid%scalar(i,k,j,itrace)
  1508. enddo
  1509. pro_u_c(1 ) = cf1_c*parent_grid%scalar(i,1,j,itrace) &
  1510. + cf2_c*parent_grid%scalar(i,2,j,itrace) &
  1511. + cf3_c*parent_grid%scalar(i,3,j,itrace)
  1512. pro_u_c(kde_c+1) = cfn_c *parent_grid%scalar(i,kde_c-1,j,itrace) &
  1513. + cfn1_c*parent_grid%scalar(i,kde_c-2,j,itrace)
  1514. call inter(pro_u_c,alt_u_c,kde_c+1,pro_u_n,alt_u_n,kde_n+1)
  1515. do k = 1,kde_n-1
  1516. parent_grid%scalar(i,k,j,itrace) = pro_u_n(k+1)
  1517. enddo
  1518. enddo
  1519. enddo
  1520. ENDIF
  1521. ENDDO
  1522. DO itrace = PARAM_FIRST_SCALAR, num_dfi_scalar
  1523. IF ( SIZE( parent_grid%dfi_scalar, 1 ) * SIZE( parent_grid%dfi_scalar, 3 ) .GT. 1 ) THEN
  1524. do j = njms , njme
  1525. do i = nims , nime
  1526. do k = 1,kde_c-1
  1527. pro_u_c(k+1) = parent_grid%dfi_scalar(i,k,j,itrace)
  1528. enddo
  1529. pro_u_c(1 ) = cf1_c*parent_grid%dfi_scalar(i,1,j,itrace) &
  1530. + cf2_c*parent_grid%dfi_scalar(i,2,j,itrace) &
  1531. + cf3_c*parent_grid%dfi_scalar(i,3,j,itrace)
  1532. pro_u_c(kde_c+1) = cfn_c *parent_grid%dfi_scalar(i,kde_c-1,j,itrace) &
  1533. + cfn1_c*parent_grid%dfi_scalar(i,kde_c-2,j,itrace)
  1534. call inter(pro_u_c,alt_u_c,kde_c+1,pro_u_n,alt_u_n,kde_n+1)
  1535. do k = 1,kde_n-1
  1536. parent_grid%dfi_scalar(i,k,j,itrace) = pro_u_n(k+1)
  1537. enddo
  1538. enddo
  1539. enddo
  1540. ENDIF
  1541. ENDDO
  1542. IF ( SIZE( parent_grid%f_ice_phy, 1 ) * SIZE( parent_grid%f_ice_phy, 3 ) .GT. 1 ) THEN
  1543. do j = njms , njme
  1544. do i = nims , nime
  1545. do k = 1,kde_c-1
  1546. pro_u_c(k+1) = parent_grid%f_ice_phy(i,k,j)
  1547. enddo
  1548. pro_u_c(1 ) = cf1_c*parent_grid%f_ice_phy(i,1,j) &
  1549. + cf2_c*parent_grid%f_ice_phy(i,2,j) &
  1550. + cf3_c*parent_grid%f_ice_phy(i,3,j)
  1551. pro_u_c(kde_c+1) = cfn_c *parent_grid%f_ice_phy(i,kde_c-1,j) &
  1552. + cfn1_c*parent_grid%f_ice_phy(i,kde_c-2,j)
  1553. call inter(pro_u_c,alt_u_c,kde_c+1,pro_u_n,alt_u_n,kde_n+1)
  1554. do k = 1,kde_n-1
  1555. parent_grid%f_ice_phy(i,k,j) = pro_u_n(k+1)
  1556. enddo
  1557. enddo
  1558. enddo
  1559. ENDIF
  1560. IF ( SIZE( parent_grid%f_rain_phy, 1 ) * SIZE( parent_grid%f_rain_phy, 3 ) .GT. 1 ) THEN
  1561. do j = njms , njme
  1562. do i = nims , nime
  1563. do k = 1,kde_c-1
  1564. pro_u_c(k+1) = parent_grid%f_rain_phy(i,k,j)
  1565. enddo
  1566. pro_u_c(1 ) = cf1_c*parent_grid%f_rain_phy(i,1,j) &
  1567. + cf2_c*parent_grid%f_rain_phy(i,2,j) &
  1568. + cf3_c*parent_grid%f_rain_phy(i,3,j)
  1569. pro_u_c(kde_c+1) = cfn_c *parent_grid%f_rain_phy(i,kde_c-1,j) &
  1570. + cfn1_c*parent_grid%f_rain_phy(i,kde_c-2,j)
  1571. call inter(pro_u_c,alt_u_c,kde_c+1,pro_u_n,alt_u_n,kde_n+1)
  1572. do k = 1,kde_n-1
  1573. parent_grid%f_rain_phy(i,k,j) = pro_u_n(k+1)
  1574. enddo
  1575. enddo
  1576. enddo
  1577. ENDIF
  1578. IF ( SIZE( parent_grid%f_rimef_phy, 1 ) * SIZE( parent_grid%f_rimef_phy, 3 ) .GT. 1 ) THEN
  1579. do j = njms , njme
  1580. do i = nims , nime
  1581. do k = 1,kde_c-1
  1582. pro_u_c(k+1) = parent_grid%f_rimef_phy(i,k,j)
  1583. enddo
  1584. pro_u_c(1 ) = cf1_c*parent_grid%f_rimef_phy(i,1,j) &
  1585. + cf2_c*parent_grid%f_rimef_phy(i,2,j) &
  1586. + cf3_c*parent_grid%f_rimef_phy(i,3,j)
  1587. pro_u_c(kde_c+1) = cfn_c *parent_grid%f_rimef_phy(i,kde_c-1,j) &
  1588. + cfn1_c*parent_grid%f_rimef_phy(i,kde_c-2,j)
  1589. call inter(pro_u_c,alt_u_c,kde_c+1,pro_u_n,alt_u_n,kde_n+1)
  1590. do k = 1,kde_n-1
  1591. parent_grid%f_rimef_phy(i,k,j) = pro_u_n(k+1)
  1592. enddo
  1593. enddo
  1594. enddo
  1595. ENDIF
  1596. IF ( SIZE( parent_grid%h_diabatic, 1 ) * SIZE( parent_grid%h_diabatic, 3 ) .GT. 1 ) THEN
  1597. do j = njms , njme
  1598. do i = nims , nime
  1599. do k = 1,kde_c-1
  1600. pro_u_c(k+1) = parent_grid%h_diabatic(i,k,j)
  1601. enddo
  1602. pro_u_c(1 ) = cf1_c*parent_grid%h_diabatic(i,1,j) &
  1603. + cf2_c*parent_grid%h_diabatic(i,2,j) &
  1604. + cf3_c*parent_grid%h_diabatic(i,3,j)
  1605. pro_u_c(kde_c+1) = cfn_c *parent_grid%h_diabatic(i,kde_c-1,j) &
  1606. + cfn1_c*parent_grid%h_diabatic(i,kde_c-2,j)
  1607. call inter(pro_u_c,alt_u_c,kde_c+1,pro_u_n,alt_u_n,kde_n+1)
  1608. do k = 1,kde_n-1
  1609. parent_grid%h_diabatic(i,k,j) = pro_u_n(k+1)
  1610. enddo
  1611. enddo
  1612. enddo
  1613. ENDIF
  1614. IF ( SIZE( parent_grid%rthraten, 1 ) * SIZE( parent_grid%rthraten, 3 ) .GT. 1 ) THEN
  1615. do j = njms , njme
  1616. do i = nims , nime
  1617. do k = 1,kde_c-1
  1618. pro_u_c(k+1) = parent_grid%rthraten(i,k,j)
  1619. enddo
  1620. pro_u_c(1 ) = cf1_c*parent_grid%rthraten(i,1,j) &
  1621. + cf2_c*parent_grid%rthraten(i,2,j) &
  1622. + cf3_c*parent_grid%rthraten(i,3,j)
  1623. pro_u_c(kde_c+1) = cfn_c *parent_grid%rthraten(i,kde_c-1,j) &
  1624. + cfn1_c*parent_grid%rthraten(i,kde_c-2,j)
  1625. call inter(pro_u_c,alt_u_c,kde_c+1,pro_u_n,alt_u_n,kde_n+1)
  1626. do k = 1,kde_n-1
  1627. parent_grid%rthraten(i,k,j) = pro_u_n(k+1)
  1628. enddo
  1629. enddo
  1630. enddo
  1631. ENDIF
  1632. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1633. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1634. deallocate (alt_w_c)
  1635. deallocate (alt_u_c)
  1636. deallocate (pro_w_c)
  1637. deallocate (pro_u_c)
  1638. deallocate (alt_w_n)
  1639. deallocate (alt_u_n)
  1640. deallocate (pro_w_n)
  1641. deallocate (pro_u_n)
  1642. END SUBROUTINE vertical_interp
  1643. !!!!!!!!!!!!!!!!!!!!!!!!11
  1644. SUBROUTINE inter(pro_c,alt_c,kde_c,pro_n,alt_n,kde_n)
  1645. IMPLICIT NONE
  1646. INTEGER , INTENT(IN) :: kde_c,kde_n
  1647. REAL , DIMENSION(kde_c) , INTENT(IN ) :: pro_c,alt_c
  1648. REAL , DIMENSION(kde_n) , INTENT(IN ) :: alt_n
  1649. REAL , DIMENSION(kde_n) , INTENT(OUT) :: pro_n
  1650. real ,dimension(kde_c) :: a,b,c,d
  1651. real :: p
  1652. integer :: i,j
  1653. call coeff_mon(alt_c,pro_c,a,b,c,d,kde_c)
  1654. do i = 1,kde_n-1
  1655. do j=1,kde_c-1
  1656. if ( (alt_n(i) .ge. alt_c(j)).and.(alt_n(i) .lt. alt_c(j+1)) ) then
  1657. p = alt_n(i)-alt_c(j)
  1658. pro_n(i) = p*( p*(a(j)*p+b(j))+c(j)) + d(j)
  1659. goto 20
  1660. endif
  1661. enddo
  1662. 20 continue
  1663. enddo
  1664. pro_n(kde_n) = pro_c(kde_c)
  1665. END SUBROUTINE inter
  1666. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!11
  1667. subroutine coeff_mon(x,y,a,b,c,d,n)
  1668. implicit none
  1669. integer :: n
  1670. real ,dimension(n) :: x,y,a,b,c,d
  1671. real ,dimension(n) :: h,s,p,yp
  1672. integer :: i
  1673. do i=1,n-1
  1674. h(i) = (x(i+1)-x(i))
  1675. s(i) = (y(i+1)-y(i)) / h(i)
  1676. enddo
  1677. do i=2,n-1
  1678. p(i) = (s(i-1)*h(i)+s(i)*h(i-1)) / (h(i-1)+h(i))
  1679. enddo
  1680. p(1) = s(1)
  1681. p(n) = s(n-1)
  1682. do i=1,n
  1683. yp(i) = p(i)
  1684. enddo
  1685. !!!!!!!!!!!!!!!!!!!!!
  1686. do i=2,n-1
  1687. yp(i) = (sign(1.,s(i-1))+sign(1.,s(i)))* min( abs(s(i-1)),abs(s(i)),0.5*abs(p(i)))
  1688. enddo
  1689. do i = 1,n-1
  1690. a(i) = (yp(i)+yp(i+1)-2.*s(i))/(h(i)*h(i))
  1691. b(i) = (3.*s(i)-2.*yp(i)-yp(i+1))/h(i)
  1692. c(i) = yp(i)
  1693. d(i) = y(i)
  1694. enddo
  1695. end subroutine coeff_mon