2 !WRF:MEDIATION_LAYER:IO
6 SUBROUTINE med_calc_model_time ( grid , config_flags )
8 USE module_domain , ONLY : domain, domain_clock_get
9 USE module_configure , ONLY : grid_config_rec_type
17 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
22 ! this is now handled by with calls to time manager
23 ! time = head_grid%dt * head_grid%total_time_steps
24 ! CALL calc_current_date (grid%id, time)
27 END SUBROUTINE med_calc_model_time
29 SUBROUTINE med_before_solve_io ( grid , config_flags )
31 USE module_state_description
32 USE module_domain , ONLY : domain, domain_clock_get
33 USE module_configure , ONLY : grid_config_rec_type
42 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
46 TYPE(WRFU_Time) :: currTime, startTime
49 TYPE(WRFU_Time) :: CurrTime !zhang new
50 INTEGER :: hr, min, sec, ms,julyr,julday
55 CHARACTER*256 :: message
58 CALL WRFU_ClockGet( grid%domain_clock, CurrTime=currTime, StartTime=startTime )
59 IF( WRFU_AlarmIsRinging( grid%alarms( HISTORY_ALARM ), rc=rc ) .AND. &
60 (grid%dfi_write_dfi_history .OR. grid%dfi_stage == DFI_FST .OR. grid%dfi_opt == DFI_NODFI) ) THEN
62 IF( WRFU_AlarmIsRinging( grid%alarms( HISTORY_ALARM ), rc=rc )) THEN
64 IF ( (config_flags%restart) .AND. ( currTime .EQ. startTime ) ) THEN
65 ! no history output on the first time of the restart
67 CALL med_hist_out ( grid , HISTORY_ALARM, config_flags )
69 CALL WRFU_AlarmRingerOff( grid%alarms( HISTORY_ALARM ), rc=rc )
72 IF( WRFU_AlarmIsRinging( grid%alarms( INPUTOUT_ALARM ), rc=rc ) ) THEN
73 CALL med_filter_out ( grid , config_flags )
74 CALL WRFU_AlarmRingerOff( grid%alarms( INPUTOUT_ALARM ), rc=rc )
77 DO ialarm = first_auxhist, last_auxhist
79 rc = 1 ! dummy statement
80 ELSE IF( WRFU_AlarmIsRinging( grid%alarms( ialarm ), rc=rc ) ) THEN
81 CALL med_hist_out ( grid , ialarm, config_flags )
82 CALL WRFU_AlarmRingerOff( grid%alarms( ialarm ), rc=rc )
86 DO ialarm = first_auxinput, last_auxinput
88 rc = 1 ! dummy statement
90 ! - Get chemistry data
91 ELSE IF( ialarm .EQ. AUXINPUT5_ALARM .AND. config_flags%chem_opt > 0 ) THEN
92 IF( config_flags%emiss_inpt_opt /= 0 ) THEN
93 IF( WRFU_AlarmIsRinging( grid%alarms( ialarm ), rc=rc ) ) THEN
94 call wrf_debug(15,' CALL med_read_wrf_chem_emiss ')
95 CALL med_read_wrf_chem_emiss ( grid , config_flags )
96 CALL WRFU_AlarmRingerOff( grid%alarms( ialarm ), rc=rc )
97 call wrf_debug(15,' Back from CALL med_read_wrf_chem_emiss ')
100 IF( WRFU_AlarmIsRinging( grid%alarms( ialarm ), rc=rc ) ) THEN
101 CALL med_auxinput_in ( grid, ialarm, config_flags )
102 CALL WRFU_AlarmRingerOff( grid%alarms( ialarm ), rc=rc )
107 ELSE IF( ialarm .EQ. AUXINPUT11_ALARM ) THEN
108 IF( config_flags%obs_nudge_opt .EQ. 1) THEN
109 CALL med_fddaobs_in ( grid , config_flags )
112 ELSE IF( WRFU_AlarmIsRinging( grid%alarms( ialarm ), rc=rc ) ) THEN
113 CALL med_auxinput_in ( grid, ialarm, config_flags )
114 WRITE ( message , FMT='(A,i3,A,i3)' ) 'Input data processed for aux input ' , &
115 ialarm - first_auxinput + 1, ' for domain ',grid%id
116 CALL wrf_debug ( 0 , message )
117 CALL WRFU_AlarmRingerOff( grid%alarms( ialarm ), rc=rc )
122 CALL WRFU_ClockGet( grid%domain_clock, CurrTime=currTime, StartTime=startTime )
123 IF ( ( WRFU_AlarmIsRinging( grid%alarms( RESTART_ALARM ), rc=rc ) ) .AND. &
124 ( currTime .NE. startTime ) ) THEN
127 CALL domain_clock_get( grid, current_time=CurrTime )
128 CALL WRFU_TimeGet( CurrTime, YY=julyr, dayOfYear=julday, H=hr, M=min, S=sec, MS=ms, rc=rc)
129 gmt=hr+real(min)/60.+real(sec)/3600.+real(ms)/(1000*3600)
130 if (grid%id .eq. 2) call med_namelist_out ( grid , config_flags )
131 !end of zhang's doing
133 IF ( grid%id .EQ. 1 ) THEN
134 ! Only the parent initiates the restart writing. Otherwise, different
135 ! domains may be written out at different times and with different
136 ! time stamps in the file names.
137 CALL med_restart_out ( grid , config_flags )
139 CALL WRFU_AlarmRingerOff( grid%alarms( RESTART_ALARM ), rc=rc )
141 CALL WRFU_AlarmRingerOff( grid%alarms( RESTART_ALARM ), rc=rc )
144 ! - Look for boundary data after writing out history and restart files
145 CALL med_latbound_in ( grid , config_flags )
148 END SUBROUTINE med_before_solve_io
150 SUBROUTINE med_after_solve_io ( grid , config_flags )
152 USE module_domain , ONLY : domain
154 USE module_configure , ONLY : grid_config_rec_type
161 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
163 ! Compute time series variables
167 END SUBROUTINE med_after_solve_io
169 SUBROUTINE med_pre_nest_initial ( parent , newid , config_flags )
172 USE module_domain , ONLY : domain, domain_clock_get
174 USE module_domain , ONLY : domain
176 USE module_utility , ONLY : WRFU_Time, WRFU_TimeEQ
179 USE module_configure , ONLY : grid_config_rec_type
185 TYPE(domain) , POINTER :: parent
186 INTEGER, INTENT(IN) :: newid
187 TYPE (grid_config_rec_type) , INTENT(INOUT) :: config_flags
188 TYPE (grid_config_rec_type) :: nest_config_flags
191 INTEGER :: itmp, fid, ierr, icnt
192 CHARACTER*256 :: rstname, message, timestr
194 TYPE(WRFU_Time) :: strt_time, cur_time
198 CALL domain_clock_get( parent, current_timestr=timestr, start_time=strt_time, current_time=cur_time )
199 CALL construct_filename2a ( rstname , config_flags%rst_inname , newid , 2 , timestr )
201 IF ( config_flags%restart .AND. WRFU_TimeEQ(cur_time,strt_time) ) THEN
202 WRITE(message,*)'RESTART: nest, opening ',TRIM(rstname),' for reading header information only'
203 CALL wrf_message ( message )
204 ! note that the parent pointer is not strictly correct, but nest is not allocated yet and
205 ! only the i/o communicator fields are used from "parent" (and those are dummies in current
207 CALL open_r_dataset ( fid , TRIM(rstname) , parent , config_flags , "DATASET=RESTART", ierr )
208 IF ( ierr .NE. 0 ) THEN
209 WRITE( message , '("program wrf: error opening ",A32," for reading")') TRIM(rstname)
210 CALL WRF_ERROR_FATAL ( message )
213 ! update the values of parent_start that were read in from the namelist (nest may have moved)
214 CALL wrf_get_dom_ti_integer ( fid , 'I_PARENT_START' , itmp , 1 , icnt, ierr )
215 IF ( ierr .EQ. 0 ) THEN
216 config_flags%i_parent_start = itmp
217 CALL nl_set_i_parent_start ( newid , config_flags%i_parent_start )
219 CALL wrf_get_dom_ti_integer ( fid , 'J_PARENT_START' , itmp , 1 , icnt, ierr )
220 IF ( ierr .EQ. 0 ) THEN
221 config_flags%j_parent_start = itmp
222 CALL nl_set_j_parent_start ( newid , config_flags%j_parent_start )
225 CALL close_dataset ( fid , config_flags , "DATASET=RESTART" )
229 END SUBROUTINE med_pre_nest_initial
232 SUBROUTINE med_nest_initial ( parent , nest , config_flags )
234 USE module_domain , ONLY : domain , domain_clock_get , get_ijk_from_grid
237 USE module_configure , ONLY : grid_config_rec_type
244 TYPE(domain) , POINTER :: parent, nest
245 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
246 TYPE (grid_config_rec_type) :: nest_config_flags
249 TYPE(WRFU_Time) :: strt_time, cur_time
250 CHARACTER * 80 :: rstname , timestr
251 CHARACTER * 256 :: message
255 INTEGER :: ids , ide , jds , jde , kds , kde , &
256 ims , ime , jms , jme , kms , kme , &
257 ips , ipe , jps , jpe , kps , kpe
261 TYPE (WRFU_TimeInterval) :: interval, TimeSinceStart
262 INTEGER :: vortex_interval , n
264 INTEGER :: save_itimestep ! This is a kludge, correct fix will
265 ! involve integrating the time-step
266 ! counting into the time manager.
268 REAL, ALLOCATABLE, DIMENSION(:,:) :: save_acsnow &
279 SUBROUTINE med_interp_domain ( parent , nest )
280 USE module_domain , ONLY : domain
281 TYPE(domain) , POINTER :: parent , nest
282 END SUBROUTINE med_interp_domain
284 SUBROUTINE med_initialdata_input_ptr( nest , config_flags )
285 USE module_domain , ONLY : domain
286 USE module_configure , ONLY : grid_config_rec_type
287 TYPE (grid_config_rec_type), INTENT(IN) :: config_flags
288 TYPE(domain) , POINTER :: nest
289 END SUBROUTINE med_initialdata_input_ptr
291 SUBROUTINE med_nest_feedback ( parent , nest , config_flags )
292 USE module_domain , ONLY : domain
293 USE module_configure , ONLY : grid_config_rec_type
294 TYPE (domain), POINTER :: nest , parent
295 TYPE (grid_config_rec_type), INTENT(IN) :: config_flags
296 END SUBROUTINE med_nest_feedback
298 SUBROUTINE start_domain ( grid , allowed_to_move )
299 USE module_domain , ONLY : domain
301 LOGICAL, INTENT(IN) :: allowed_to_move
302 END SUBROUTINE start_domain
304 SUBROUTINE blend_terrain ( ter_interpolated , ter_input , &
305 ids , ide , jds , jde , kds , kde , &
306 ims , ime , jms , jme , kms , kme , &
307 ips , ipe , jps , jpe , kps , kpe )
308 INTEGER :: ids , ide , jds , jde , kds , kde , &
309 ims , ime , jms , jme , kms , kme , &
310 ips , ipe , jps , jpe , kps , kpe
311 REAL , DIMENSION(ims:ime,jms:jme) :: ter_interpolated
312 REAL , DIMENSION(ims:ime,jms:jme) :: ter_input
313 END SUBROUTINE blend_terrain
315 SUBROUTINE copy_3d_field ( ter_interpolated , ter_input , &
316 ids , ide , jds , jde , kds , kde , &
317 ims , ime , jms , jme , kms , kme , &
318 ips , ipe , jps , jpe , kps , kpe )
319 INTEGER :: ids , ide , jds , jde , kds , kde , &
320 ims , ime , jms , jme , kms , kme , &
321 ips , ipe , jps , jpe , kps , kpe
322 REAL , DIMENSION(ims:ime,jms:jme) :: ter_interpolated
323 REAL , DIMENSION(ims:ime,jms:jme) :: ter_input
324 END SUBROUTINE copy_3d_field
326 SUBROUTINE input_terrain_rsmas ( grid , &
327 ids , ide , jds , jde , kds , kde , &
328 ims , ime , jms , jme , kms , kme , &
329 ips , ipe , jps , jpe , kps , kpe )
330 USE module_domain , ONLY : domain
331 TYPE ( domain ) :: grid
332 INTEGER :: ids , ide , jds , jde , kds , kde , &
333 ims , ime , jms , jme , kms , kme , &
334 ips , ipe , jps , jpe , kps , kpe
335 END SUBROUTINE input_terrain_rsmas
339 CALL domain_clock_get( parent, start_time=strt_time, current_time=cur_time )
341 IF ( .not. ( config_flags%restart .AND. strt_time .EQ. cur_time ) ) THEN
342 nest%first_force = .true.
344 ! initialize nest with interpolated data from the parent
345 nest%imask_nostag = 1
348 nest%imask_xystag = 1
351 parent%nest_pos = parent%ht
352 where ( parent%nest_pos .gt. 0. ) parent%nest_pos = parent%nest_pos + 500. ! make a cliff
355 ! fill in entire fine grid domain with interpolated coarse grid data
356 CALL med_interp_domain( parent, nest )
358 ! De-reference dimension information stored in the grid data structure.
359 CALL get_ijk_from_grid ( nest , &
360 ids, ide, jds, jde, kds, kde, &
361 ims, ime, jms, jme, kms, kme, &
362 ips, ipe, jps, jpe, kps, kpe )
364 ! initialize some other constants (and 1d arrays in z)
365 CALL init_domain_constants ( parent, nest )
367 ! get the nest config flags
368 CALL model_to_grid_config_rec ( nest%id , model_config_rec , nest_config_flags )
370 IF ( nest_config_flags%input_from_file .OR. nest_config_flags%input_from_hires ) THEN
372 WRITE(message,FMT='(A,I2,A)') '*** Initializing nest domain #',nest%id,&
373 ' from an input file. ***'
374 CALL wrf_debug ( 0 , message )
376 ! Store horizontally interpolated terrain-based fields in temp location if the input
377 ! data is from a pristine, un-cycled model input file. For the original topo from
378 ! the real program, we will need to adjust the terrain (and a couple of other base-
379 ! state fields) so reflect the smoothing and matching between the parent and child
380 ! domains. For cycled forecasts, the topo has already been adjusted, and we skip
383 IF ( nest%save_topo_from_real == 1 ) THEN
384 CALL copy_3d_field ( nest%ht_int , nest%ht , &
385 ids , ide , jds , jde , 1 , 1 , &
386 ims , ime , jms , jme , 1 , 1 , &
387 ips , ipe , jps , jpe , 1 , 1 )
388 CALL copy_3d_field ( nest%mub_fine , nest%mub , &
389 ids , ide , jds , jde , 1 , 1 , &
390 ims , ime , jms , jme , 1 , 1 , &
391 ips , ipe , jps , jpe , 1 , 1 )
392 CALL copy_3d_field ( nest%phb_fine , nest%phb , &
393 ids , ide , jds , jde , kds , kde , &
394 ims , ime , jms , jme , kms , kme , &
395 ips , ipe , jps , jpe , kps , kpe )
398 IF ( nest_config_flags%input_from_file ) THEN
399 ! read input from dataset
400 CALL med_initialdata_input_ptr( nest , nest_config_flags )
402 ELSE IF ( nest_config_flags%input_from_hires ) THEN
403 ! read in high res topography
404 CALL input_terrain_rsmas ( nest, &
405 ids , ide , jds , jde , 1 , 1 , &
406 ims , ime , jms , jme , 1 , 1 , &
407 ips , ipe , jps , jpe , 1 , 1 )
410 ! save elevation and mub for temp and qv adjustment
412 CALL copy_3d_field ( nest%ht_fine , nest%ht , &
413 ids , ide , jds , jde , 1 , 1 , &
414 ims , ime , jms , jme , 1 , 1 , &
415 ips , ipe , jps , jpe , 1 , 1 )
416 CALL copy_3d_field ( nest%mub_save , nest%mub , &
417 ids , ide , jds , jde , 1 , 1 , &
418 ims , ime , jms , jme , 1 , 1 , &
419 ips , ipe , jps , jpe , 1 , 1 )
421 ! blend parent and nest fields: terrain, mub, and phb. The ht, mub and phb are used in start_domain.
423 IF ( nest%save_topo_from_real == 1 ) THEN
424 CALL blend_terrain ( nest%ht_int , nest%ht , &
425 ids , ide , jds , jde , 1 , 1 , &
426 ims , ime , jms , jme , 1 , 1 , &
427 ips , ipe , jps , jpe , 1 , 1 )
428 CALL blend_terrain ( nest%mub_fine , nest%mub , &
429 ids , ide , jds , jde , 1 , 1 , &
430 ims , ime , jms , jme , 1 , 1 , &
431 ips , ipe , jps , jpe , 1 , 1 )
432 CALL blend_terrain ( nest%phb_fine , nest%phb , &
433 ids , ide , jds , jde , kds , kde , &
434 ims , ime , jms , jme , kms , kme , &
435 ips , ipe , jps , jpe , kps , kpe )
440 CALL adjust_tempqv ( nest%mub , nest%mub_save , &
441 nest%znw , nest%p_top , &
442 nest%t_2 , nest%p , nest%moist(ims,kms,jms,P_QV) , &
443 ids , ide , jds , jde , kds , kde , &
444 ims , ime , jms , jme , kms , kme , &
445 ips , ipe , jps , jpe , kps , kpe )
448 WRITE(message,FMT='(A,I2,A,I2,A)') '*** Initializing nest domain #',nest%id,&
449 ' by horizontally interpolating parent domain #' ,parent%id, &
451 CALL wrf_debug ( 0 , message )
455 ! feedback, mostly for this new terrain, but it is the safe thing to do
456 parent%ht_coarse = parent%ht
458 CALL med_nest_feedback ( parent , nest , config_flags )
460 ! set some other initial fields, fill out halos, base fields; re-do parent due
461 ! to new terrain elevation from feedback
462 nest%imask_nostag = 1
465 nest%imask_xystag = 1
466 nest%press_adj = .TRUE.
467 CALL start_domain ( nest , .TRUE. )
469 CALL get_ijk_from_grid ( parent , &
470 ids, ide, jds, jde, kds, kde, &
471 ims, ime, jms, jme, kms, kme, &
472 ips, ipe, jps, jpe, kps, kpe )
474 ALLOCATE( save_acsnow(ims:ime,jms:jme) )
475 ALLOCATE( save_acsnom(ims:ime,jms:jme) )
476 ALLOCATE( save_cuppt(ims:ime,jms:jme) )
477 ALLOCATE( save_rainc(ims:ime,jms:jme) )
478 ALLOCATE( save_rainnc(ims:ime,jms:jme) )
479 ALLOCATE( save_sfcevp(ims:ime,jms:jme) )
480 ALLOCATE( save_sfcrunoff(ims:ime,jms:jme) )
481 ALLOCATE( save_udrunoff(ims:ime,jms:jme) )
482 save_acsnow = parent%acsnow
483 save_acsnom = parent%acsnom
484 save_cuppt = parent%cuppt
485 save_rainc = parent%rainc
486 save_rainnc = parent%rainnc
487 save_sfcevp = parent%sfcevp
488 save_sfcrunoff = parent%sfcrunoff
489 save_udrunoff = parent%udrunoff
490 save_itimestep = parent%itimestep
491 parent%imask_nostag = 1
492 parent%imask_xstag = 1
493 parent%imask_ystag = 1
494 parent%imask_xystag = 1
496 parent%press_adj = .FALSE.
497 CALL start_domain ( parent , .TRUE. )
499 parent%acsnow = save_acsnow
500 parent%acsnom = save_acsnom
501 parent%cuppt = save_cuppt
502 parent%rainc = save_rainc
503 parent%rainnc = save_rainnc
504 parent%sfcevp = save_sfcevp
505 parent%sfcrunoff = save_sfcrunoff
506 parent%udrunoff = save_udrunoff
507 parent%itimestep = save_itimestep
508 DEALLOCATE( save_acsnow )
509 DEALLOCATE( save_acsnom )
510 DEALLOCATE( save_cuppt )
511 DEALLOCATE( save_rainc )
512 DEALLOCATE( save_rainnc )
513 DEALLOCATE( save_sfcevp )
514 DEALLOCATE( save_sfcrunoff )
515 DEALLOCATE( save_udrunoff )
516 ! end of kludge: 20040604
521 CALL domain_clock_get( nest, current_timestr=timestr )
522 CALL construct_filename2a ( rstname , config_flags%rst_inname , nest%id , 2 , timestr )
524 WRITE(message,*)'RESTART: nest, opening ',TRIM(rstname),' for reading'
525 CALL wrf_message ( message )
526 CALL model_to_grid_config_rec ( nest%id , model_config_rec , nest_config_flags )
527 CALL open_r_dataset ( fid , TRIM(rstname) , nest , nest_config_flags , "DATASET=RESTART", ierr )
528 IF ( ierr .NE. 0 ) THEN
529 WRITE( message , '("program wrf: error opening ",A32," for reading")') TRIM(rstname)
530 CALL WRF_ERROR_FATAL ( message )
532 CALL input_restart ( fid, nest , nest_config_flags , ierr )
533 CALL close_dataset ( fid , nest_config_flags , "DATASET=RESTART" )
535 nest%imask_nostag = 1
538 nest%imask_xystag = 1
539 nest%press_adj = .FALSE.
540 CALL start_domain ( nest , .TRUE. )
542 ! this doesn't need to be done for moving nests, since ht_coarse is part of the restart
543 parent%ht_coarse = parent%ht
546 ! In case of a restart, assume that the movement has already occurred in the previous
547 ! run and turn off the alarm for the starting time. We must impose a requirement that the
548 ! run be restarted on-interval. Test for that and print a warning if it isn't.
549 ! Note, simulation_start, etc. should be available as metadata in the restart file, and
550 ! these will have gotten, set, and retrievable as rconfig data been set in share/input_wrf.F
551 ! using the nl_get routines below. JM 20060314
553 CALL nl_get_vortex_interval ( nest%id , vortex_interval )
554 CALL WRFU_TimeIntervalSet( interval, M=vortex_interval, rc=rc )
556 CALL domain_clock_get( nest, timeSinceSimulationStart=TimeSinceStart )
557 n = WRFU_TimeIntervalDIVQuot( TimeSinceStart , interval )
558 IF ( ( interval * n ) .NE. TimeSinceStart ) THEN
559 CALL wrf_message('WARNING: Restart is not on a vortex_interval time boundary.')
560 CALL wrf_message('The code will work but results will not agree exactly with a ')
561 CALL wrf_message('a run that was done straight-through, without a restart.')
563 !! In case of a restart, assume that the movement has already occurred in the previous
564 !! run and turn off the alarm for the starting time. We must impose a requirement that the
565 !! run be restarted on-interval. Test for that and print a warning if it isn't.
566 !! Note, simulation_start, etc. should be available as metadata in the restart file, and
567 !! these will have gotten, set, and retrievable as rconfig data been set in share/input_wrf.F
568 !! using the nl_get routines below. JM 20060314
569 ! CALL WRFU_AlarmRingerOff( nest%alarms( COMPUTE_VORTEX_CENTER_ALARM ), rc=rc )
572 ! this code, currently commented out, is an attempt to have the
573 ! vortex centering interval be set according to simulation start
574 ! time (rather than run start time) in case of a restart. But
575 ! there are other problems (the WRF clock is currently using
576 ! run-start as it's start time) so the alarm still would not fire
577 ! right if the model were started off-interval. Leave it here and
578 ! enable when the clock is changed to use sim-start for start time.
580 CALL nl_get_vortex_interval ( nest%id , vortex_interval )
581 CALL WRFU_TimeIntervalSet( interval, M=vortex_interval, rc=rc )
583 CALL domain_clock_get( nest, timeSinceSimulationStart=TimeSinceStart )
585 CALL domain_alarm_create( nest, COMPUTE_VORTEX_CENTER_ALARM, interval )
586 CALL WRFU_AlarmEnable( nest%alarms( COMPUTE_VORTEX_CENTER_ALARM ), rc=rc )
587 n = WRFU_TimeIntervalDIVQuot( TimeSinceStart , interval )
588 IF ( ( interval * n ) .EQ. TimeSinceStart ) THEN
589 CALL WRFU_AlarmRingerOn( nest%alarms( COMPUTE_VORTEX_CENTER_ALARM ), rc=rc )
591 CALL WRFU_AlarmRingerOff( nest%alarms( COMPUTE_VORTEX_CENTER_ALARM ), rc=rc )
600 #if (NMM_CORE == 1 && NMM_NEST == 1)
601 !===================================================================================
602 ! Added for the NMM core. This is gopal's doing.
603 !===================================================================================
607 SUBROUTINE med_nest_egrid_configure ( parent , nest )
608 USE module_domain , ONLY : domain
609 TYPE(domain) , POINTER :: parent , nest
610 END SUBROUTINE med_nest_egrid_configure
612 SUBROUTINE med_construct_egrid_weights ( parent , nest )
613 USE module_domain , ONLY : domain
614 TYPE(domain) , POINTER :: parent , nest
615 END SUBROUTINE med_construct_egrid_weights
617 SUBROUTINE BASE_STATE_PARENT ( Z3d,Q3d,T3d,PSTD, &
619 FIS,QSH,PD,PDTOP,PTOP, &
622 IDS,IDE,JDS,JDE,KDS,KDE, &
623 IMS,IME,JMS,JME,KMS,KME, &
624 IPS,IPE,JPS,JPE,KPS,KPE )
627 USE MODULE_MODEL_CONSTANTS
629 INTEGER, INTENT(IN ) :: IDS,IDE,JDS,JDE,KDS,KDE
630 INTEGER, INTENT(IN ) :: IMS,IME,JMS,JME,KMS,KME
631 INTEGER, INTENT(IN ) :: IPS,IPE,JPS,JPE,KPS,KPE
632 REAL, INTENT(IN ) :: PDTOP,PTOP
633 REAL, DIMENSION(KMS:KME), INTENT(IN) :: ETA1,ETA2,DETA1,DETA2
634 REAL, DIMENSION(IMS:IME,JMS:JME), INTENT(IN) :: FIS,PD,QSH
635 REAL, DIMENSION(IMS:IME,JMS:JME,KMS:KME), INTENT(IN) :: PINT,T,Q,CWM
636 REAL, DIMENSION(KMS:KME) , INTENT(OUT):: PSTD
637 REAL, DIMENSION(IMS:IME,JMS:JME,KMS:KME), INTENT(OUT):: Z3d,Q3d,T3d
639 END SUBROUTINE BASE_STATE_PARENT
641 SUBROUTINE NEST_TERRAIN ( nest, config_flags )
642 USE module_domain , ONLY : domain
643 USE module_configure , ONLY : grid_config_rec_type
644 TYPE(domain) , POINTER :: nest
645 TYPE(grid_config_rec_type) , INTENT(IN) :: config_flags
646 END SUBROUTINE NEST_TERRAIN
648 SUBROUTINE med_interp_domain ( parent , nest )
649 USE module_domain , ONLY : domain
650 TYPE(domain) , POINTER :: parent , nest
651 END SUBROUTINE med_interp_domain
653 SUBROUTINE med_init_domain_constants_nmm ( parent, nest )
654 USE module_domain , ONLY : domain
655 TYPE(domain) , POINTER :: parent , nest
656 END SUBROUTINE med_init_domain_constants_nmm
658 SUBROUTINE start_domain ( grid , allowed_to_move )
659 USE module_domain , ONLY : domain
661 LOGICAL, INTENT(IN) :: allowed_to_move
662 END SUBROUTINE start_domain
668 if (config_flags%restart .or. nest%analysis) then
669 nest%first_force = .true.
671 nest%first_force = .false.
673 !end of zhang's doing
675 !zhang's doing for analysis option
676 IF(.not. nest%analysis .and. .not. config_flags%restart)THEN ! initialize for cold-start
679 !----------------------------------------------------------------------------
680 ! initialize nested domain configurations including setting up wbd,sbd, etc
681 !----------------------------------------------------------------------------
683 CALL med_nest_egrid_configure ( parent , nest )
685 !-------------------------------------------------------------------------
686 ! initialize lat-lons and determine weights
687 !-------------------------------------------------------------------------
689 CALL med_construct_egrid_weights ( parent, nest )
692 ! De-reference dimension information stored in the grid data structure.
694 ! From the hybrid, construct the GPMs on isobaric surfaces and then interpolate those
695 ! values on to the nested domain. 23 standard prssure levels are assumed here. For
696 ! levels below ground, lapse rate atmosphere is assumed before the use of vertical
697 ! spline interpolation
722 CALL BASE_STATE_PARENT ( parent%Z3d,parent%Q3d,parent%T3d,parent%PSTD, &
723 parent%PINT,parent%T,parent%Q,parent%CWM, &
724 parent%FIS,parent%QSH,parent%PD,parent%pdtop,parent%pt, &
725 parent%ETA1,parent%ETA2, &
726 parent%DETA1,parent%DETA2, &
727 IDS,IDE,JDS,JDE,KDS,KDE, &
728 IMS,IME,JMS,JME,KMS,KME, &
729 IPS,IPE,JPS,JPE,KPS,KPE )
732 ! Set new terrain. Since some terrain adjustment is done within the interpolation calls
733 ! at the next step, the new terrain over the nested domain has to be called here.
757 CALL NEST_TERRAIN ( nest, config_flags )
759 ! Initialize some more constants required especially for terrain adjustment processes
761 nest%PSTD=parent%PSTD
763 parent%KZMAX=KME ! just for safety
765 DO J = JPS, MIN(JPE,JDE-1)
766 DO I = IPS, MIN(IPE,IDE-1)
767 nest%fis(I,J)=nest%hres_fis(I,J)
771 !--------------------------------------------------------------------------
773 !--------------------------------------------------------------------------
775 ! initialize nest with interpolated data from the parent
777 nest%imask_nostag = 0
780 nest%imask_xystag = 0
783 CALL med_interp_domain( parent, nest )
785 CALL domain_clock_get( parent, start_time=strt_time, current_time=cur_time )
787 IF ( .not. ( config_flags%restart .AND. strt_time .EQ. cur_time ) ) THEN
789 CALL med_interp_domain( parent, nest )
793 CALL domain_clock_get( nest, current_timestr=timestr )
794 CALL construct_filename2a ( rstname , config_flags%rst_inname , nest%id , 2 , timestr )
796 WRITE(message,*)'RESTART: nest, opening ',TRIM(rstname),' for reading'
797 CALL wrf_message ( message )
798 CALL model_to_grid_config_rec ( nest%id , model_config_rec , nest_config_flags )
799 CALL open_r_dataset ( fid , TRIM(rstname) , nest , nest_config_flags , "DATASET=RESTART", ierr )
800 IF ( ierr .NE. 0 ) THEN
801 WRITE( message , '("program wrf: error opening ",A32," for reading")') TRIM(rstname)
802 CALL WRF_ERROR_FATAL ( message )
804 CALL input_restart ( fid, nest , nest_config_flags , ierr )
805 CALL close_dataset ( fid , nest_config_flags , "DATASET=RESTART" )
810 !------------------------------------------------------------------------------
811 ! set up constants (module_initialize_real.F for nested nmm domain)
812 !-----------------------------------------------------------------------------
814 CALL med_init_domain_constants_nmm ( parent, nest )
816 !--------------------------------------------------------------------------------------
817 ! set some other initial fields, fill out halos, etc.
818 !--------------------------------------------------------------------------------------
820 CALL start_domain ( nest, .TRUE.)
823 !zhang's doing: else for analysis or restart option
826 CALL nl_set_isice ( nest%id , config_flags%isice )
827 CALL nl_set_isoilwater ( nest%id , config_flags%isoilwater )
828 CALL nl_set_isurban ( nest%id , config_flags%isurban )
829 CALL nl_set_gmt ( nest%id , config_flags%gmt )
830 CALL nl_set_julyr (nest%id, config_flags%julyr)
831 CALL nl_set_julday ( nest%id , config_flags%julday )
833 CALL med_analysis_out ( nest, config_flags )
837 !------------------------------------------------------------------------------------
838 ! read in analysis (equivalent of restart for the nested domains)
839 !------------------------------------------------------------------------------------
842 IF( nest%analysis .and. .not. config_flags%restart)THEN
843 CALL med_analysis_in ( nest, config_flags )
844 ELSE IF (config_flags%restart)THEN
845 CALL med_restart_in ( nest, config_flags )
847 !end of zhang's doing
849 !----------------------------------------------------------------------------
850 ! initialize nested domain configurations including setting up wbd,sbd, etc
851 !----------------------------------------------------------------------------
853 CALL med_nest_egrid_configure ( parent , nest )
855 !-------------------------------------------------------------------------
856 ! initialize lat-lons and determine weights (overwrite for safety)
857 !-------------------------------------------------------------------------
859 CALL med_construct_egrid_weights ( parent, nest )
861 nest%imask_nostag = 0
864 nest%imask_xystag = 0
866 !------------------------------------------------------------------------------
867 ! set up constants (module_initialize_real.F for nested nmm domain)
868 !-----------------------------------------------------------------------------
870 CALL med_init_domain_constants_nmm ( parent, nest )
872 !--------------------------------------------------------------------------------------
873 ! set some other initial fields, fill out halos, etc. (again, safety sake only)
874 ! Also, in order to accomodate some physics initialization after nest move, set
875 ! analysis back to false for future use
876 !--------------------------------------------------------------------------------------
878 CALL start_domain ( nest, .TRUE.)
880 nest%analysis=.FALSE.
881 CALL nl_set_analysis( nest%id, nest%analysis)
887 !===================================================================================
888 ! Added for the NMM core. End of gopal's doing.
889 !===================================================================================
892 END SUBROUTINE med_nest_initial
894 SUBROUTINE init_domain_constants ( parent , nest )
895 USE module_domain , ONLY : domain
897 TYPE(domain) :: parent , nest
899 CALL init_domain_constants_em ( parent, nest )
901 END SUBROUTINE init_domain_constants
904 SUBROUTINE med_nest_force ( parent , nest )
906 USE module_domain , ONLY : domain
908 USE module_configure , ONLY : grid_config_rec_type
916 TYPE(domain) , POINTER :: parent, nest
918 INTEGER :: idum1 , idum2 , fid, rc
920 #if (NMM_CORE == 1 && NMM_NEST == 1)
921 INTEGER :: IDS,IDE,JDS,JDE,KDS,KDE ! gopal
922 INTEGER :: IMS,IME,JMS,JME,KMS,KME
923 INTEGER :: ITS,ITE,JTS,JTE,KTS,KTE
927 SUBROUTINE med_force_domain ( parent , nest )
928 USE module_domain , ONLY : domain
929 TYPE(domain) , POINTER :: parent , nest
930 END SUBROUTINE med_force_domain
931 SUBROUTINE med_interp_domain ( parent , nest )
932 USE module_domain , ONLY : domain
933 TYPE(domain) , POINTER :: parent , nest
934 END SUBROUTINE med_interp_domain
935 #if (NMM_CORE == 1 && NMM_NEST == 1)
936 !===================================================================================
937 ! Added for the NMM core. This is gopal's doing.
938 !===================================================================================
940 SUBROUTINE BASE_STATE_PARENT ( Z3d,Q3d,T3d,PSTD, &
942 FIS,QSH,PD,PDTOP,PTOP, &
945 IDS,IDE,JDS,JDE,KDS,KDE, &
946 IMS,IME,JMS,JME,KMS,KME, &
947 ITS,ITE,JTS,JTE,KTS,KTE )
950 USE MODULE_MODEL_CONSTANTS
952 INTEGER, INTENT(IN ) :: IDS,IDE,JDS,JDE,KDS,KDE
953 INTEGER, INTENT(IN ) :: IMS,IME,JMS,JME,KMS,KME
954 INTEGER, INTENT(IN ) :: ITS,ITE,JTS,JTE,KTS,KTE
955 REAL, INTENT(IN ) :: PDTOP,PTOP
956 REAL, DIMENSION(KMS:KME), INTENT(IN) :: ETA1,ETA2,DETA1,DETA2
957 REAL, DIMENSION(IMS:IME,JMS:JME), INTENT(IN) :: FIS,PD,QSH
958 REAL, DIMENSION(IMS:IME,JMS:JME,KMS:KME), INTENT(IN) :: PINT,T,Q,CWM
959 REAL, DIMENSION(KMS:KME) , INTENT(OUT):: PSTD
960 REAL, DIMENSION(IMS:IME,JMS:JME,KMS:KME), INTENT(OUT):: Z3d,Q3d,T3d
962 END SUBROUTINE BASE_STATE_PARENT
967 #if (NMM_CORE == 1 && NMM_NEST == 1)
969 ! De-reference dimension information stored in the grid data structure.
993 CALL BASE_STATE_PARENT ( parent%Z3d,parent%Q3d,parent%T3d,parent%PSTD, &
994 parent%PINT,parent%T,parent%Q,parent%CWM, &
995 parent%FIS,parent%QSH,parent%PD,parent%pdtop,parent%pt, &
996 parent%ETA1,parent%ETA2, &
997 parent%DETA1,parent%DETA2, &
998 IDS,IDE,JDS,JDE,KDS,KDE, &
999 IMS,IME,JMS,JME,KMS,KME, &
1000 ITS,ITE,JTS,JTE,KTS,KTE )
1004 IF ( .NOT. WRFU_ClockIsStopTime(nest%domain_clock ,rc=rc) ) THEN
1005 ! initialize nest with interpolated data from the parent
1006 nest%imask_nostag = 1
1007 nest%imask_xstag = 1
1008 nest%imask_ystag = 1
1009 nest%imask_xystag = 1
1010 CALL med_force_domain( parent, nest )
1013 ! might also have calls here to do input from a file into the nest
1016 END SUBROUTINE med_nest_force
1018 SUBROUTINE med_nest_feedback ( parent , nest , config_flags )
1020 USE module_domain , ONLY : domain , get_ijk_from_grid
1022 USE module_configure , ONLY : grid_config_rec_type
1030 TYPE(domain) , POINTER :: parent, nest
1031 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
1033 INTEGER :: idum1 , idum2 , fid, rc
1034 INTEGER :: ids , ide , jds , jde , kds , kde , &
1035 ims , ime , jms , jme , kms , kme , &
1036 ips , ipe , jps , jpe , kps , kpe
1040 SUBROUTINE med_feedback_domain ( parent , nest )
1041 USE module_domain , ONLY : domain
1042 TYPE(domain) , POINTER :: parent , nest
1043 END SUBROUTINE med_feedback_domain
1046 ! feedback nest to the parent
1047 IF ( .NOT. WRFU_ClockIsStopTime(nest%domain_clock ,rc=rc) .AND. &
1048 config_flags%feedback .NE. 0 ) THEN
1049 CALL med_feedback_domain( parent, nest )
1051 CALL get_ijk_from_grid ( parent , &
1052 ids, ide, jds, jde, kds, kde, &
1053 ims, ime, jms, jme, kms, kme, &
1054 ips, ipe, jps, jpe, kps, kpe )
1055 ! gopal's change- added ifdef
1056 #if ( EM_CORE == 1 )
1057 DO j = jps, MIN(jpe,jde-1)
1058 DO i = ips, MIN(ipe,ide-1)
1059 IF ( parent%nest_pos(i,j) .EQ. 9021000. ) THEN
1060 parent%nest_pos(i,j) = parent%ht(i,j)*1.5 + 1000.
1061 ELSE IF ( parent%ht(i,j) .NE. 0. ) THEN
1062 parent%nest_pos(i,j) = parent%ht(i,j) + 500.
1064 parent%nest_pos(i,j) = 0.
1073 END SUBROUTINE med_nest_feedback
1075 SUBROUTINE med_last_solve_io ( grid , config_flags )
1077 USE module_state_description
1078 USE module_domain , ONLY : domain, domain_clock_get
1079 USE module_configure , ONLY : grid_config_rec_type
1087 TYPE(domain) :: grid
1088 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
1093 TYPE(WRFU_Time) :: CurrTime !zhang new
1094 INTEGER :: hr, min, sec, ms,julyr,julday
1096 !end of zhang's doing
1100 IF( WRFU_AlarmIsRinging( grid%alarms( HISTORY_ALARM ), rc=rc ) .AND. &
1101 (grid%dfi_write_dfi_history .OR. grid%dfi_stage == DFI_FST .OR. grid%dfi_opt == DFI_NODFI) ) THEN
1103 IF( WRFU_AlarmIsRinging( grid%alarms( HISTORY_ALARM ), rc=rc )) THEN
1105 CALL med_hist_out ( grid , HISTORY_ALARM , config_flags )
1108 IF( WRFU_AlarmIsRinging( grid%alarms( INPUTOUT_ALARM ), rc=rc ) ) THEN
1109 CALL med_filter_out ( grid , config_flags )
1112 ! registry-generated file of the following
1113 ! IF( WRFU_AlarmIsRinging( grid%alarms( AUXHIST1_ALARM ), rc=rc ) ) THEN
1114 ! CALL med_hist_out ( grid , AUXHIST1_ALARM , config_flags )
1116 #include "med_last_solve_io.inc"
1119 IF( WRFU_AlarmIsRinging( grid%alarms( RESTART_ALARM ), rc=rc ) ) THEN
1122 !zhang new CALL ESMF_TimeGet( grid%current_time, YY=julyr, dayOfYear=julday, H=hr, M=min, S=sec, MS=ms, rc=rc)
1123 CALL domain_clock_get( grid, current_time=CurrTime )
1124 CALL WRFU_TimeGet( CurrTime, YY=julyr, dayOfYear=julday, H=hr, M=min, S=sec, MS=ms, rc=rc)
1125 gmt=hr+real(min)/60.+real(sec)/3600.+real(ms)/(1000*3600)
1126 if (grid%id .eq. 2) call med_namelist_out ( grid , config_flags )
1127 !end of zhang's doing
1129 IF ( grid%id .EQ. 1 ) THEN
1130 CALL med_restart_out ( grid , config_flags )
1134 ! Write out time series
1135 CALL write_ts( grid )
1138 END SUBROUTINE med_last_solve_io
1142 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1145 !==================================================================================
1146 ! Added for the NMM 3d var. This is simply an extension of med_restart_out.
1147 ! The file is simply called wrfanal***. This is gopal's doing
1148 !===================================================================================
1150 SUBROUTINE med_analysis_in ( grid , config_flags )
1152 USE module_domain , ONLY : domain, domain_clock_get
1153 USE module_io_domain
1156 USE module_configure , ONLY : grid_config_rec_type
1157 USE module_bc_time_utilities
1158 !zhang USE WRF_ESMF_MOD
1163 TYPE(domain) :: grid
1164 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
1167 LOGICAL, EXTERNAL :: wrf_dm_on_monitor
1168 CHARACTER*80 :: rstname , outname
1169 INTEGER :: fid , rid
1170 CHARACTER (LEN=256) :: message
1173 !zhang old TYPE(ESMF_Time) :: CurrTime
1174 TYPE(WRFU_Time) :: CurrTime
1175 CHARACTER*80 :: timestr
1177 IF ( wrf_dm_on_monitor() ) THEN
1183 !zhang's doing CALL ESMF_ClockGet( grid%domain_clock, CurrTime=CurrTime, rc=ierr )
1184 !zhang's doing CALL wrf_timetoa ( CurrTime, timestr )
1185 CALL domain_clock_get( grid, current_timestr=timestr )
1186 CALL construct_filename2a ( rstname ,config_flags%anl_outname, grid%id , 2 , timestr )
1188 WRITE( message , '("med_analysis_in: opening ",A," for reading")' ) TRIM ( rstname )
1189 CALL wrf_debug( 1 , message )
1190 CALL open_r_dataset ( rid, TRIM(rstname), grid , &
1191 config_flags , "DATASET=RESTART", ierr )
1193 IF ( ierr .NE. 0 ) THEN
1194 ! CALL WRF_message( message )
1195 CALL WRF_ERROR_FATAL('NESTED DOMAIN ERROR: FOR ANALYSIS SET TO TRUE, YOU NEED wrfanal FILE')
1197 CALL input_restart ( rid, grid , config_flags , ierr )
1198 IF ( wrf_dm_on_monitor() ) THEN
1199 WRITE ( message , FMT = '("Reading restart for domain ",I8)' ) grid%id
1200 CALL end_timing ( TRIM(message) )
1202 CALL close_dataset ( rid , config_flags , "DATASET=RESTART" )
1205 END SUBROUTINE med_analysis_in
1206 !=========================================================================================================
1207 !=========================================================================================================
1208 SUBROUTINE med_analysis_out ( grid , config_flags )
1210 USE module_domain , ONLY : domain, domain_clock_get
1211 USE module_io_domain
1214 USE module_configure , ONLY : grid_config_rec_type
1215 USE module_bc_time_utilities
1216 !zhang USE WRF_ESMF_MOD
1221 TYPE(domain) :: grid
1222 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
1225 LOGICAL, EXTERNAL :: wrf_dm_on_monitor
1226 CHARACTER*80 :: rstname , outname
1227 INTEGER :: fid , rid
1228 CHARACTER (LEN=256) :: message
1231 !zhang TYPE(ESMF_Time) :: CurrTime
1232 TYPE(WRFU_Time) :: CurrTime
1233 CHARACTER*80 :: timestr
1235 IF ( wrf_dm_on_monitor() ) THEN
1241 !zhang's doing CALL ESMF_ClockGet( grid%domain_clock, CurrTime=CurrTime, rc=ierr )
1242 !zhang's doing CALL wrf_timetoa ( CurrTime, timestr )
1243 CALL domain_clock_get( grid, current_timestr=timestr )
1244 CALL construct_filename2a ( rstname ,config_flags%anl_outname, grid%id , 2 , timestr )
1246 WRITE( message , '("med_analysis_out: opening ",A," for writing")' ) TRIM ( rstname )
1247 CALL wrf_debug( 1 , message )
1248 CALL open_w_dataset ( rid, TRIM(rstname), grid , &
1249 config_flags , output_restart , "DATASET=RESTART", ierr )
1251 IF ( ierr .NE. 0 ) THEN
1252 CALL WRF_message( message )
1254 CALL output_restart ( rid, grid , config_flags , ierr )
1255 IF ( wrf_dm_on_monitor() ) THEN
1256 WRITE ( message , FMT = '("Writing restart for domain ",I8)' ) grid%id
1257 CALL end_timing ( TRIM(message) )
1259 CALL close_dataset ( rid , config_flags , "DATASET=RESTART" )
1261 END SUBROUTINE med_analysis_out
1265 RECURSIVE SUBROUTINE med_restart_out ( grid , config_flags )
1267 USE module_domain , ONLY : domain , domain_clock_get
1268 USE module_io_domain
1270 USE module_configure , ONLY : grid_config_rec_type
1272 USE module_bc_time_utilities
1278 TYPE(domain) :: grid
1279 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
1282 LOGICAL, EXTERNAL :: wrf_dm_on_monitor
1283 CHARACTER*80 :: rstname , outname
1284 INTEGER :: fid , rid, kid
1285 CHARACTER (LEN=256) :: message
1288 CHARACTER*80 :: timestr
1289 TYPE (grid_config_rec_type) :: kid_config_flags
1291 IF ( wrf_dm_on_monitor() ) THEN
1295 ! take this out - no effect - LPC
1296 ! rid=grid%id !zhang's doing
1298 ! write out this domains restart file first
1300 CALL domain_clock_get( grid, current_timestr=timestr )
1301 CALL construct_filename2a ( rstname , config_flags%rst_outname , grid%id , 2 , timestr )
1303 WRITE( message , '("med_restart_out: opening ",A," for writing")' ) TRIM ( rstname )
1304 CALL wrf_debug( 1 , message )
1305 CALL open_w_dataset ( rid, TRIM(rstname), grid , &
1306 config_flags , output_restart , "DATASET=RESTART", ierr )
1308 IF ( ierr .NE. 0 ) THEN
1309 CALL WRF_message( message )
1311 CALL output_restart ( rid, grid , config_flags , ierr )
1312 IF ( wrf_dm_on_monitor() ) THEN
1313 WRITE ( message , FMT = '("Writing restart for domain ",I8)' ) grid%id
1314 CALL end_timing ( TRIM(message) )
1316 CALL close_dataset ( rid , config_flags , "DATASET=RESTART" )
1318 ! call recursively for children, (if any)
1319 DO kid = 1, max_nests
1320 IF ( ASSOCIATED( grid%nests(kid)%ptr ) ) THEN
1321 CALL model_to_grid_config_rec ( grid%nests(kid)%ptr%id , model_config_rec , kid_config_flags )
1322 CALL med_restart_out ( grid%nests(kid)%ptr , kid_config_flags )
1327 END SUBROUTINE med_restart_out
1329 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1332 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1334 SUBROUTINE med_restart_in ( grid , config_flags )
1336 USE module_domain , ONLY : domain, domain_clock_get
1337 USE module_io_domain
1340 USE module_configure , ONLY : grid_config_rec_type
1341 USE module_bc_time_utilities
1346 TYPE(domain) :: grid
1347 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
1350 LOGICAL, EXTERNAL :: wrf_dm_on_monitor
1351 CHARACTER*80 :: rstname , outname
1352 INTEGER :: fid , rid
1353 CHARACTER (LEN=256) :: message
1356 !zhang old TYPE(ESMF_Time) :: CurrTime
1357 TYPE(WRFU_Time) :: CurrTime
1358 CHARACTER*80 :: timestr
1360 IF ( wrf_dm_on_monitor() ) THEN
1366 !zhang's doing CALL ESMF_ClockGet( grid%domain_clock, CurrTime=CurrTime, rc=ierr )
1367 !zhang's doing CALL wrf_timetoa ( CurrTime, timestr )
1368 CALL domain_clock_get( grid, current_timestr=timestr )
1369 CALL construct_filename2a ( rstname ,config_flags%rst_outname, grid%id , 2 , timestr )
1371 WRITE( message , '("med_restart_in: opening ",A," for reading")' ) TRIM ( rstname )
1372 CALL wrf_debug( 1 , message )
1373 CALL open_r_dataset ( rid, TRIM(rstname), grid , &
1374 config_flags , "DATASET=RESTART", ierr )
1376 IF ( ierr .NE. 0 ) THEN
1377 ! CALL WRF_message( message )
1378 CALL WRF_ERROR_FATAL('NESTED DOMAIN ERROR: FOR ANALYSIS SET TO TRUE, YOU NEED wrfanal FILE')
1380 CALL input_restart ( rid, grid , config_flags , ierr )
1381 IF ( wrf_dm_on_monitor() ) THEN
1382 WRITE ( message , FMT = '("Reading restart for domain ",I8)' ) grid%id
1383 CALL end_timing ( TRIM(message) )
1385 CALL close_dataset ( rid , config_flags , "DATASET=RESTART" )
1388 END SUBROUTINE med_restart_in
1389 !end of zhang's doing
1392 SUBROUTINE med_hist_out ( grid , stream, config_flags )
1394 USE module_domain , ONLY : domain
1396 USE module_io_domain
1397 USE module_configure , ONLY : grid_config_rec_type
1398 USE module_bc_time_utilities
1403 TYPE(domain) :: grid
1404 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
1405 INTEGER , INTENT(IN) :: stream
1407 LOGICAL, EXTERNAL :: wrf_dm_on_monitor
1408 CHARACTER*80 :: fname, n2
1409 CHARACTER (LEN=256) :: message
1412 IF ( wrf_dm_on_monitor() ) THEN
1416 IF ( stream .LT. first_history .OR. stream .GT. last_auxhist ) THEN
1417 WRITE(message,*)'med_hist_out: invalid history stream ',stream
1418 CALL wrf_error_fatal( message )
1421 SELECT CASE( stream )
1422 CASE ( HISTORY_ALARM )
1423 CALL open_hist_w( grid, config_flags, stream, HISTORY_ALARM, &
1424 config_flags%history_outname, grid%oid, &
1425 output_history, fname, n2, ierr )
1426 CALL output_history ( grid%oid, grid , config_flags , ierr )
1428 ! registry-generated selections and calls top open_hist_w for aux streams
1429 #include "med_hist_out_opens.inc"
1433 WRITE(message,*)'med_hist_out: opened ',TRIM(fname),' as ',TRIM(n2)
1434 CALL wrf_debug( 1, message )
1436 grid%nframes(stream) = grid%nframes(stream) + 1
1438 SELECT CASE( stream )
1439 CASE ( HISTORY_ALARM )
1440 IF ( grid%nframes(stream) >= config_flags%frames_per_outfile ) THEN
1441 CALL close_dataset ( grid%oid , config_flags , n2 )
1443 grid%nframes(stream) = 0
1445 ! registry-generated selections and calls top close_dataset for aux streams
1446 #include "med_hist_out_closes.inc"
1449 IF ( wrf_dm_on_monitor() ) THEN
1450 WRITE ( message , FMT = '("Writing ",A30," for domain ",I8)' )TRIM(fname),grid%id
1451 CALL end_timing ( TRIM(message) )
1455 END SUBROUTINE med_hist_out
1458 SUBROUTINE med_fddaobs_in ( grid , config_flags )
1459 USE module_domain , ONLY : domain
1460 USE module_configure , ONLY : grid_config_rec_type
1462 TYPE(domain) :: grid
1463 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
1464 CALL wrf_fddaobs_in( grid, config_flags )
1466 END SUBROUTINE med_fddaobs_in
1469 SUBROUTINE med_auxinput_in ( grid , stream, config_flags )
1471 USE module_domain , ONLY : domain
1472 USE module_io_domain
1474 USE module_configure , ONLY : grid_config_rec_type
1475 USE module_bc_time_utilities
1480 TYPE(domain) :: grid
1481 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
1482 INTEGER , INTENT(IN) :: stream
1484 CHARACTER (LEN=256) :: message
1487 IF ( stream .LT. first_auxinput .OR. stream .GT. last_auxinput ) THEN
1488 WRITE(message,*)'med_auxinput_in: invalid input stream ',stream
1489 CALL wrf_error_fatal( message )
1492 grid%nframes(stream) = grid%nframes(stream) + 1
1494 SELECT CASE( stream )
1495 ! registry-generated file of calls to open filename
1496 ! CASE ( AUXINPUT1_ALARM )
1497 ! CALL open_aux_u( grid, config_flags, stream, AUXINPUT1_ALARM, &
1498 ! config_flags%auxinput1_inname, grid%auxinput1_oid, &
1499 ! input_auxinput1, ierr )
1500 ! CALL input_auxinput1 ( grid%auxinput1_oid, grid , config_flags , ierr )
1501 #include "med_auxinput_in.inc"
1504 SELECT CASE( stream )
1505 ! registry-generated selections and calls top close_dataset for aux streams
1506 #include "med_auxinput_in_closes.inc"
1510 END SUBROUTINE med_auxinput_in
1512 SUBROUTINE med_filter_out ( grid , config_flags )
1514 USE module_domain , ONLY : domain , domain_clock_get
1515 USE module_io_domain
1517 USE module_configure , ONLY : grid_config_rec_type
1519 USE module_bc_time_utilities
1524 TYPE(domain) :: grid
1525 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
1527 LOGICAL, EXTERNAL :: wrf_dm_on_monitor
1528 CHARACTER*80 :: rstname , outname
1529 INTEGER :: fid , rid
1530 CHARACTER (LEN=256) :: message
1533 CHARACTER*80 :: timestr
1535 IF ( config_flags%write_input ) THEN
1537 IF ( wrf_dm_on_monitor() ) THEN
1541 CALL domain_clock_get( grid, current_timestr=timestr )
1542 CALL construct_filename2a ( outname , config_flags%input_outname , grid%id , 2 , timestr )
1544 WRITE ( message , '("med_filter_out 1: opening ",A," for writing. ")') TRIM ( outname )
1545 CALL wrf_debug( 1, message )
1547 CALL open_w_dataset ( fid, TRIM(outname), grid , &
1548 config_flags , output_input , "DATASET=INPUT", ierr )
1549 IF ( ierr .NE. 0 ) THEN
1550 CALL wrf_error_fatal( message )
1553 IF ( ierr .NE. 0 ) THEN
1554 CALL wrf_error_fatal( message )
1557 CALL output_input ( fid, grid , config_flags , ierr )
1558 CALL close_dataset ( fid , config_flags , "DATASET=INPUT" )
1560 IF ( wrf_dm_on_monitor() ) THEN
1561 WRITE ( message , FMT = '("Writing filter output for domain ",I8)' ) grid%id
1562 CALL end_timing ( TRIM(message) )
1567 END SUBROUTINE med_filter_out
1569 SUBROUTINE med_latbound_in ( grid , config_flags )
1571 USE module_domain , ONLY : domain , domain_clock_get, head_grid
1572 USE module_io_domain
1574 USE module_configure , ONLY : grid_config_rec_type
1576 USE module_bc_time_utilities
1581 #include <wrf_status_codes.h>
1584 TYPE(domain) :: grid
1585 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
1588 LOGICAL, EXTERNAL :: wrf_dm_on_monitor
1589 LOGICAL :: lbc_opened
1590 INTEGER :: idum1 , idum2 , ierr , open_status , fid, rc
1592 CHARACTER (LEN=256) :: message
1593 CHARACTER (LEN=80) :: bdyname
1594 Type (WRFU_Time ) :: startTime, stopTime, currentTime
1595 Type (WRFU_TimeInterval ) :: stepTime
1596 integer myproc,i,j,k
1598 #include <wrf_io_flags.h>
1600 CALL wrf_debug ( 200 , 'in med_latbound_in' )
1603 ! Avoid trying to re-read the boundary conditions if we are doing DFI integration
1604 ! and do not expect to find boundary conditions for the current time
1605 IF ( (grid%dfi_opt .EQ. DFI_DDFI .OR. grid%dfi_opt .EQ. DFI_TDFI) .AND. grid%dfi_stage .EQ. DFI_FWD ) RETURN
1608 IF ( grid%id .EQ. 1 .AND. config_flags%specified .AND. config_flags%io_form_boundary .GT. 0 ) THEN
1610 CALL domain_clock_get( grid, current_time=currentTime, &
1611 start_time=startTime, &
1612 stop_time=stopTime, &
1613 time_step=stepTime )
1615 IF ( ( lbc_read_time( currentTime ) ) .AND. &
1616 ( currentTime + stepTime .GE. stopTime ) .AND. &
1617 ( currentTime .NE. startTime ) ) THEN
1618 CALL wrf_debug( 100 , 'med_latbound_in: Skipping attempt to read lateral boundary file during last time step ' )
1620 ELSE IF ( WRFU_AlarmIsRinging( grid%alarms( BOUNDARY_ALARM ), rc=rc ) ) THEN
1621 CALL wrf_debug ( 100 , 'in med_latbound_in preparing to read' )
1622 CALL WRFU_AlarmRingerOff( grid%alarms( BOUNDARY_ALARM ), rc=rc )
1623 IF ( wrf_dm_on_monitor() ) CALL start_timing
1625 ! typically a <date> wouldn't be part of the bdy_inname, so just pass a dummy
1626 CALL construct_filename2a ( bdyname , config_flags%bdy_inname , grid%id , 2 , 'dummydate' )
1628 CALL wrf_inquire_opened(grid%lbc_fid , TRIM(bdyname) , open_status , ierr )
1629 IF ( open_status .EQ. WRF_FILE_OPENED_FOR_READ ) THEN
1632 lbc_opened = .FALSE.
1634 CALL wrf_dm_bcast_bytes ( lbc_opened , LWORDSIZE )
1635 IF ( .NOT. lbc_opened ) THEN
1636 CALL construct_filename1 ( bdyname , 'wrfbdy' , grid%id , 2 )
1637 WRITE(message,*)'Opening: ',TRIM(bdyname)
1638 CALL wrf_debug(100,TRIM(message))
1639 CALL open_r_dataset ( grid%lbc_fid, TRIM(bdyname) , grid , config_flags , "DATASET=BOUNDARY", ierr )
1640 IF ( ierr .NE. 0 ) THEN
1641 WRITE( message, * ) 'med_latbound_in: error opening ',TRIM(bdyname), ' for reading. IERR = ',ierr
1642 CALL WRF_ERROR_FATAL( message )
1645 CALL wrf_debug( 100 , bdyname // 'already opened' )
1647 CALL wrf_debug( 100 , 'med_latbound_in: calling input_boundary ' )
1648 CALL input_boundary ( grid%lbc_fid, grid , config_flags , ierr )
1651 IF ( (config_flags%dfi_opt .NE. DFI_NODFI) .AND. (head_grid%dfi_stage .NE. DFI_FST) ) THEN
1652 CALL wrf_debug( 100 , 'med_latbound_in: closing boundary file ' )
1653 CALL close_dataset ( grid%lbc_fid , config_flags , "DATASET=BOUNDARY" )
1657 CALL domain_clock_get( grid, current_time=currentTime )
1658 DO WHILE (currentTime .GE. grid%next_bdy_time ) ! next_bdy_time is set by input_boundary from bdy file
1659 CALL wrf_debug( 100 , 'med_latbound_in: calling input_boundary ' )
1660 CALL input_boundary ( grid%lbc_fid, grid , config_flags , ierr )
1662 CALL WRFU_AlarmSet( grid%alarms( BOUNDARY_ALARM ), RingTime=grid%next_bdy_time, rc=rc )
1664 IF ( ierr .NE. 0 .and. ierr .NE. WRF_WARN_NETCDF ) THEN
1665 WRITE( message, * ) 'med_latbound_in: error reading ',TRIM(bdyname), ' IERR = ',ierr
1666 CALL WRF_ERROR_FATAL( message )
1668 IF ( currentTime .EQ. grid%this_bdy_time ) grid%dtbc = 0.
1670 IF ( wrf_dm_on_monitor() ) THEN
1671 WRITE ( message , FMT = '("processing lateral boundary for domain ",I8)' ) grid%id
1672 CALL end_timing ( TRIM(message) )
1677 END SUBROUTINE med_latbound_in
1679 SUBROUTINE med_setup_step ( grid , config_flags )
1681 USE module_domain , ONLY : domain
1682 USE module_configure , ONLY : grid_config_rec_type
1688 !The driver layer routine integrate() calls this mediation layer routine
1689 !prior to initiating a time step on the domain specified by the argument
1690 !grid. This provides the model-layer contributor an opportunity to make
1691 !any pre-time-step initializations that pertain to a particular model
1692 !domain. In WRF, this routine is used to call
1693 !set_scalar_indices_from_config for the specified domain.
1698 TYPE(domain) :: grid
1699 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
1701 INTEGER :: idum1 , idum2
1703 CALL set_scalar_indices_from_config ( grid%id , idum1 , idum2 )
1707 END SUBROUTINE med_setup_step
1709 SUBROUTINE med_endup_step ( grid , config_flags )
1711 USE module_domain , ONLY : domain
1712 USE module_configure , ONLY : grid_config_rec_type, model_config_rec
1718 !The driver layer routine integrate() calls this mediation layer routine
1719 !prior to initiating a time step on the domain specified by the argument
1720 !grid. This provides the model-layer contributor an opportunity to make
1721 !any pre-time-step initializations that pertain to a particular model
1722 !domain. In WRF, this routine is used to call
1723 !set_scalar_indices_from_config for the specified domain.
1728 TYPE(domain) :: grid
1729 TYPE (grid_config_rec_type) , INTENT(OUT) :: config_flags
1731 INTEGER :: idum1 , idum2
1733 IF ( grid%id .EQ. 1 ) THEN
1734 ! turn off the restart flag after the first mother-domain step is finished
1735 model_config_rec%restart = .FALSE.
1736 config_flags%restart = .FALSE.
1737 CALL nl_set_restart(1, .FALSE.)
1743 END SUBROUTINE med_endup_step
1745 SUBROUTINE open_aux_u ( grid , config_flags, stream, alarm_id, &
1746 auxinput_inname, oid, insub, ierr )
1748 USE module_domain , ONLY : domain , domain_clock_get
1749 USE module_io_domain
1751 USE module_configure , ONLY : grid_config_rec_type
1752 USE module_bc_time_utilities
1757 TYPE(domain) :: grid
1758 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
1759 INTEGER , INTENT(IN) :: stream
1760 INTEGER , INTENT(IN) :: alarm_id
1761 CHARACTER*(*) , INTENT(IN) :: auxinput_inname
1762 INTEGER , INTENT(INOUT) :: oid
1764 INTEGER , INTENT(OUT) :: ierr
1766 CHARACTER*80 :: fname, n2
1767 CHARACTER (LEN=256) :: message
1768 CHARACTER*80 :: timestr
1769 TYPE(WRFU_Time) :: ST,CT
1772 IF ( stream .LT. first_stream .OR. stream .GT. last_stream ) THEN
1773 WRITE(message,*)'open_aux_u: invalid input stream ',stream
1774 CALL wrf_error_fatal( message )
1779 IF ( oid .eq. 0 ) THEN
1780 CALL domain_clock_get( grid, current_time=CT, start_time=ST, &
1781 current_timestr=timestr )
1782 CALL nl_get_adjust_input_times( grid%id, adjust )
1784 CALL adjust_io_timestr( grid%io_intervals( alarm_id ), CT, ST, timestr )
1786 CALL construct_filename2a ( fname , auxinput_inname, &
1787 grid%id , 2 , timestr )
1788 IF ( stream .EQ. 10 ) THEN
1789 WRITE(n2,'("DATASET=AUXINPUT10")')
1790 ELSE IF ( stream .EQ. 11 ) THEN
1791 WRITE(n2,'("DATASET=AUXINPUT11")')
1792 ELSE IF ( stream .GE. 10 ) THEN
1793 WRITE(n2,'("DATASET=AUXINPUT",I2)')stream-first_input
1795 WRITE(n2,'("DATASET=AUXINPUT",I1)')stream-first_input
1797 WRITE ( message , '("open_aux_u : opening ",A," for reading. ")') TRIM ( fname )
1798 CALL wrf_debug( 1, message )
1801 !Open_u_dataset is called rather than open_r_dataset to allow interfaces
1802 !that can do blending or masking to update an existing field. (MCEL IO does this).
1803 !No effect for other interfaces; open_u_dataset is equivalent to open_r_dataset
1807 CALL open_u_dataset ( oid, TRIM(fname), grid , &
1808 config_flags , insub , n2, ierr )
1810 IF ( ierr .NE. 0 ) THEN
1811 WRITE ( message , '("open_aux_u : error opening ",A," for reading. ",I3)') &
1812 TRIM ( fname ), ierr
1813 CALL wrf_message( message )
1816 END SUBROUTINE open_aux_u
1818 SUBROUTINE open_hist_w ( grid , config_flags, stream, alarm_id, &
1819 hist_outname, oid, outsub, fname, n2, ierr )
1821 USE module_domain , ONLY : domain , domain_clock_get
1822 USE module_io_domain
1824 USE module_configure , ONLY : grid_config_rec_type
1825 USE module_bc_time_utilities
1830 TYPE(domain) :: grid
1831 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
1832 INTEGER , INTENT(IN) :: stream
1833 INTEGER , INTENT(IN) :: alarm_id
1834 CHARACTER*(*) , INTENT(IN) :: hist_outname
1835 INTEGER , INTENT(INOUT) :: oid
1837 CHARACTER*(*) , INTENT(OUT) :: fname, n2
1838 INTEGER , INTENT(OUT) :: ierr
1841 CHARACTER (LEN=256) :: message
1842 CHARACTER*80 :: timestr
1843 TYPE(WRFU_Time) :: ST,CT
1846 IF ( stream .LT. first_history .OR. stream .GT. last_history ) THEN
1847 WRITE(message,*)'open_hist_w: invalid history stream ',stream
1848 CALL wrf_error_fatal( message )
1853 ! Note that computation of fname and n2 are outside of the oid IF statement
1854 ! since they are OUT args and may be used by callers even if oid/=0.
1855 CALL domain_clock_get( grid, current_time=CT, start_time=ST, &
1856 current_timestr=timestr )
1857 CALL nl_get_adjust_output_times( grid%id, adjust )
1859 CALL adjust_io_timestr( grid%io_intervals( alarm_id ), CT, ST, timestr )
1861 CALL construct_filename2a ( fname , hist_outname, &
1862 grid%id , 2 , timestr )
1863 IF ( stream .EQ. history_only ) THEN
1864 WRITE(n2,'("DATASET=HISTORY")')
1865 ELSE IF ( stream .GE. 10 ) THEN
1866 WRITE(n2,'("DATASET=AUXHIST",I2)')stream-first_history
1868 WRITE(n2,'("DATASET=AUXHIST",I1)')stream-first_history
1871 len_n2 = LEN_TRIM(n2)
1872 WRITE(n2(len_n2+1:len_n2+19),'(",REAL_OUTPUT_SIZE=4")')
1874 IF ( oid .eq. 0 ) THEN
1875 WRITE ( message , '("open_hist_w : opening ",A," for writing. ")') TRIM ( fname )
1876 CALL wrf_debug( 1, message )
1879 !Open_u_dataset is called rather than open_r_dataset to allow interfaces
1880 !that can do blending or masking to update an existing field. (MCEL IO does this).
1881 !No effect for other interfaces; open_u_dataset is equivalent to open_r_dataset
1885 CALL open_w_dataset ( oid, TRIM(fname), grid , &
1886 config_flags , outsub , n2, ierr )
1888 IF ( ierr .NE. 0 ) THEN
1889 WRITE ( message , '("open_hist_w : error opening ",A," for writing. ",I3)') &
1890 TRIM ( fname ), ierr
1891 CALL wrf_message( message )
1894 END SUBROUTINE open_hist_w
1897 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1900 !------------------------------------------------------------------------
1901 ! Chemistry emissions input control. Three options are available and are
1902 ! set via the namelist variable io_style_emissions:
1904 ! 0 = Emissions are not read in from a file. They will contain their
1905 ! default values, which can be set in the Registry.
1906 ! (Intended for debugging of chem code)
1908 ! 1 = Emissions are read in from two 12 hour files that are cycled.
1909 ! With this choice, emi_inname and emi_outname should be set to
1910 ! the value "wrfchemi_d<domain>". The value of frames_per_emissfile
1913 ! 2 = Emissions are read in from files identified by date and that have
1914 ! a length defined by frames_per_emissfile (in hours). Both
1915 ! emi_inname and emi_outname should be set to
1916 ! "wrfchemi_d<domain>_<date>".
1917 !------------------------------------------------------------------------
1918 SUBROUTINE med_read_wrf_chem_emiss ( grid , config_flags )
1920 USE module_domain , ONLY : domain , domain_clock_get
1921 USE module_io_domain
1923 USE module_configure , ONLY : grid_config_rec_type
1925 USE module_bc_time_utilities
1929 USE module_date_time
1935 TYPE(domain) :: grid
1937 ! TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
1938 TYPE (grid_config_rec_type) :: config_flags
1939 Type (WRFU_Time ) :: stopTime, currentTime
1940 Type (WRFU_TimeInterval ) :: stepTime
1943 LOGICAL, EXTERNAL :: wrf_dm_on_monitor
1945 INTEGER :: ierr, efid
1946 INTEGER :: ihr, ihrdiff, i
1947 REAL :: time, tupdate
1948 real, allocatable :: dumc0(:,:,:)
1949 CHARACTER (LEN=256) :: message, current_date_char, date_string
1950 CHARACTER (LEN=80) :: inpname
1952 #include <wrf_io_flags.h>
1954 CALL model_to_grid_config_rec ( grid%id , model_config_rec , config_flags )
1956 ! This "if" should be commented out when using emission files for nested
1957 ! domains. Also comment out the "ENDIF" line noted below.
1958 ! IF ( grid%id .EQ. 1 ) THEN
1960 CALL domain_clock_get( grid, current_time=currentTime, &
1961 current_timestr=current_date_char, &
1962 stop_time=stopTime, &
1963 time_step=stepTime )
1965 time = float(grid%itimestep) * grid%dt
1968 ! io_style_emissions option 0: no emissions read in...
1970 if( config_flags%io_style_emissions == 0 ) then
1973 ! io_style_emissions option 1: cycle through two 12 hour input files...
1975 else if( config_flags%io_style_emissions == 1 ) then
1977 tupdate = mod( time, (12. * 3600.) )
1978 read(current_date_char(12:13),'(I2)') ihr
1982 IF( tupdate .LT. grid%dt ) THEN
1985 IF( ihr .EQ. 00 .OR. ihr .EQ. 12 ) THEN
1989 IF( currentTime + stepTime .GE. stopTime .AND. &
1990 grid%auxinput5_oid .NE. 0 ) THEN
1991 CALL close_dataset ( grid%auxinput5_oid , config_flags , "DATASET=AUXINPUT5" )
1995 ! write(message,FMT='(A,F10.1,A)') ' EMISSIONS UPDATE TIME ',time,TRIM(current_date_char(12:13))
1996 ! CALL wrf_message( TRIM(message) )
1998 IF ( tupdate .EQ. 0. .AND. ihr .LT. 12 ) THEN
2000 CALL construct_filename1 ( inpname , 'wrfchemi_00z' , grid%id , 2 )
2001 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_emissions: Open file ',TRIM(inpname)
2002 CALL wrf_message( TRIM(message) )
2004 if( grid%auxinput5_oid .NE. 0 ) then
2005 CALL close_dataset ( grid%auxinput5_oid , config_flags , "DATASET=AUXINPUT5" )
2008 CALL open_r_dataset ( grid%auxinput5_oid, TRIM(inpname) , grid , config_flags, &
2009 "DATASET=AUXINPUT5", ierr )
2010 IF ( ierr .NE. 0 ) THEN
2011 WRITE( message , * ) 'med_read_wrf_chem_emissions: error opening ', TRIM( inpname )
2012 CALL wrf_error_fatal( TRIM( message ) )
2015 ELSE IF ( tupdate .EQ. 0. .AND. ihr .GE. 12 ) THEN
2018 CALL construct_filename1 ( inpname , 'wrfchemi_12z' , grid%id , 2 )
2019 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_emissions: Open file ',TRIM(inpname)
2020 CALL wrf_message( TRIM(message) )
2022 if( grid%auxinput5_oid .NE. 0 ) then
2023 CALL close_dataset ( grid%auxinput5_oid , config_flags , "DATASET=AUXINPUT5" )
2026 CALL open_r_dataset ( grid%auxinput5_oid, TRIM(inpname) , grid , config_flags, &
2027 "DATASET=AUXINPUT5", ierr )
2028 IF ( ierr .NE. 0 ) THEN
2029 WRITE( message , * ) 'med_read_wrf_chem_emissions: error opening ', TRIM( inpname )
2030 CALL wrf_error_fatal( TRIM( message ) )
2034 WRITE( message, '(A,2F10.1)' ) ' HOURLY EMISSIONS UPDATE TIME ',time,mod(time,3600.)
2035 CALL wrf_message( TRIM(message) )
2037 ! hourly updates to emissions
2038 IF ( ( mod( time, 3600. ) .LT. grid%dt ) .AND. &
2039 ( currentTime + stepTime .LT. stopTime ) ) THEN
2040 ! IF ( wrf_dm_on_monitor() ) CALL start_timing
2042 WRITE(message,'(A,A)')'mediation_integrate: med_read_wrf_chem_emissions: Read emissions for time ',TRIM(current_date_char)
2043 CALL wrf_message( TRIM(message) )
2045 IF ( tupdate .EQ. 0. .AND. ihrdiff .GT. 0) THEN
2046 IF( ihrdiff .GT. 12) THEN
2047 WRITE(message,'(A)')'mediation_integrate: med_read_wrf_chem_emissions: Error in emissions time, skipping all times in file '
2048 CALL wrf_message( TRIM(message) )
2051 WRITE(message,'(A,I4)')'mediation_integrate: med_read_wrf_chem_emissions: Skip emissions ',i
2052 CALL wrf_message( TRIM(message) )
2053 CALL input_auxinput5 ( grid%auxinput5_oid, grid , config_flags , ierr )
2057 CALL wrf_debug (100 , 'mediation_integrate: calling input_auxinput5' )
2058 CALL input_auxinput5 ( grid%auxinput5_oid, grid , config_flags , ierr )
2060 CALL wrf_debug (100 , 'mediation_integrate: med_read_wrf_chem_emissions: Do not read emissions' )
2064 ! io_style_emissions option 2: use dated emission files whose length is
2065 ! set via frames_per_emissfile...
2067 else if( config_flags%io_style_emissions == 2 ) then
2068 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_emissions: Read emissions for time ',TRIM(current_date_char)
2069 CALL wrf_message( TRIM(message) )
2071 ! Code to read hourly emission files...
2073 if( grid%auxinput5_oid == 0 ) then
2074 CALL construct_filename2a(inpname , grid%emi_inname, grid%id , 2, current_date_char)
2075 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_emissions: Open file ',TRIM(inpname)
2076 CALL wrf_message( TRIM(message) )
2077 CALL open_r_dataset ( grid%auxinput5_oid, TRIM(inpname) , grid , config_flags, &
2078 "DATASET=AUXINPUT5", ierr )
2079 IF ( ierr .NE. 0 ) THEN
2080 WRITE( message , * ) 'med_read_wrf_chem_emissions: error opening ', TRIM( inpname )
2081 CALL wrf_error_fatal( TRIM( message ) )
2085 ! Read the emissions data.
2087 CALL wrf_debug (100 , 'mediation_integrate: calling input_auxinput5' )
2088 CALL input_auxinput5 ( grid%auxinput5_oid, grid , config_flags , ierr )
2090 ! If reached the indicated number of frames in the emissions file, close it.
2092 grid%emissframes = grid%emissframes + 1
2093 IF ( grid%emissframes >= config_flags%frames_per_emissfile ) THEN
2094 CALL close_dataset ( grid%auxinput5_oid , config_flags , "DATASET=AUXINPUT5" )
2095 grid%emissframes = 0
2096 grid%auxinput5_oid = 0
2100 ! unknown io_style_emissions option...
2103 call wrf_error_fatal("Unknown emission style selected via io_style_emissions.")
2106 ! The following line should be commented out when using emission files
2107 ! for nested domains. Also comment out the "if" noted above.
2110 CALL wrf_debug (100 , 'mediation_integrate: med_read_wrf_chem_emissions: exit' )
2112 END SUBROUTINE med_read_wrf_chem_emiss
2114 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2115 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2117 SUBROUTINE med_read_wrf_chem_bioemiss ( grid , config_flags )
2119 USE module_domain , ONLY : domain , domain_clock_get
2120 USE module_io_domain
2122 USE module_configure , ONLY : grid_config_rec_type
2124 USE module_bc_time_utilities
2128 USE module_date_time
2134 TYPE(domain) :: grid
2136 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
2139 LOGICAL, EXTERNAL :: wrf_dm_on_monitor
2141 INTEGER :: ierr, efid
2142 REAL :: time, tupdate
2143 real, allocatable :: dumc0(:,:,:)
2144 CHARACTER (LEN=256) :: message, current_date_char, date_string
2145 CHARACTER (LEN=80) :: inpname
2147 #include <wrf_io_flags.h>
2148 ! IF ( grid%id .EQ. 1 ) THEN
2150 CALL domain_clock_get( grid, current_timestr=current_date_char )
2152 CALL construct_filename1 ( inpname , 'wrfbiochemi' , grid%id , 2 )
2153 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_bioemissions: Open file ',TRIM(inpname)
2154 CALL wrf_message( TRIM(message) )
2156 if( grid%auxinput6_oid .NE. 0 ) then
2157 CALL close_dataset ( grid%auxinput6_oid , config_flags , "DATASET=AUXINPUT6" )
2160 CALL open_r_dataset ( grid%auxinput6_oid, TRIM(inpname) , grid , config_flags, &
2161 "DATASET=AUXINPUT6", ierr )
2162 IF ( ierr .NE. 0 ) THEN
2163 WRITE( message , * ) 'med_read_wrf_chem_bioemissions: error opening ', TRIM( inpname )
2164 CALL wrf_error_fatal( TRIM( message ) )
2167 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_bioemissions: Read biogenic emissions at time ',&
2168 TRIM(current_date_char)
2169 CALL wrf_message( TRIM(message) )
2171 CALL wrf_debug (100 , 'mediation_integrate: calling input_auxinput6' )
2172 CALL input_auxinput6 ( grid%auxinput6_oid, grid , config_flags , ierr )
2174 CALL close_dataset ( grid%auxinput6_oid , config_flags , "DATASET=AUXINPUT6" )
2177 CALL wrf_debug (100 , 'mediation_integrate: med_read_wrf_chem_bioemissions: exit' )
2179 END SUBROUTINE med_read_wrf_chem_bioemiss
2181 SUBROUTINE med_read_wrf_chem_gocartbg ( grid , config_flags )
2183 USE module_domain , ONLY : domain , domain_clock_get
2184 USE module_io_domain
2186 USE module_configure , ONLY : grid_config_rec_type
2188 USE module_bc_time_utilities
2192 USE module_date_time
2198 TYPE(domain) :: grid
2200 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
2203 LOGICAL, EXTERNAL :: wrf_dm_on_monitor
2205 INTEGER :: ierr, efid
2206 REAL :: time, tupdate
2207 real, allocatable :: dumc0(:,:,:)
2208 CHARACTER (LEN=256) :: message, current_date_char, date_string
2209 CHARACTER (LEN=80) :: inpname
2211 #include <wrf_io_flags.h>
2212 ! IF ( grid%id .EQ. 1 ) THEN
2214 CALL domain_clock_get( grid, current_timestr=current_date_char )
2216 CALL construct_filename1 ( inpname , 'wrfchemi_gocart_bg' , grid%id , 2 )
2217 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_gocartbg: Open file ',TRIM(inpname)
2218 CALL wrf_message( TRIM(message) )
2220 if( grid%auxinput8_oid .NE. 0 ) then
2221 CALL close_dataset ( grid%auxinput8_oid , config_flags , "DATASET=AUXINPUT8" )
2224 CALL open_r_dataset ( grid%auxinput8_oid, TRIM(inpname) , grid , config_flags, &
2225 "DATASET=AUXINPUT8", ierr )
2226 IF ( ierr .NE. 0 ) THEN
2227 WRITE( message , * ) 'med_read_wrf_chem_gocartbg error opening ', TRIM( inpname )
2228 CALL wrf_error_fatal( TRIM( message ) )
2231 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_gocartbg: Read fire emissions at time ',&
2232 TRIM(current_date_char)
2233 CALL wrf_message( TRIM(message) )
2235 CALL wrf_debug (100 , 'mediation_integrate: calling input_auxinput8' )
2236 CALL input_auxinput8 ( grid%auxinput8_oid, grid , config_flags , ierr )
2238 CALL close_dataset ( grid%auxinput8_oid , config_flags , "DATASET=AUXINPUT8" )
2241 CALL wrf_debug (100 , 'mediation_integrate: med_read_wrf_chem_gocartbg: exit' )
2243 END SUBROUTINE med_read_wrf_chem_gocartbg
2244 SUBROUTINE med_read_wrf_chem_emissopt3 ( grid , config_flags )
2246 USE module_domain , ONLY : domain , domain_clock_get
2247 USE module_io_domain
2249 USE module_configure , ONLY : grid_config_rec_type
2251 USE module_bc_time_utilities
2255 USE module_date_time
2261 TYPE(domain) :: grid
2263 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
2266 LOGICAL, EXTERNAL :: wrf_dm_on_monitor
2268 INTEGER :: ierr, efid
2269 REAL :: time, tupdate
2270 real, allocatable :: dumc0(:,:,:)
2271 CHARACTER (LEN=256) :: message, current_date_char, date_string
2272 CHARACTER (LEN=80) :: inpname
2274 #include <wrf_io_flags.h>
2275 ! IF ( grid%id .EQ. 1 ) THEN
2277 CALL domain_clock_get( grid, current_timestr=current_date_char )
2279 CALL construct_filename1 ( inpname , 'wrffirechemi' , grid%id , 2 )
2280 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_fireemissions: Open file ',TRIM(inpname)
2281 CALL wrf_message( TRIM(message) )
2283 if( grid%auxinput7_oid .NE. 0 ) then
2284 CALL close_dataset ( grid%auxinput7_oid , config_flags , "DATASET=AUXINPUT7" )
2287 CALL open_r_dataset ( grid%auxinput7_oid, TRIM(inpname) , grid , config_flags, &
2288 "DATASET=AUXINPUT7", ierr )
2289 IF ( ierr .NE. 0 ) THEN
2290 WRITE( message , * ) 'med_read_wrf_chem_fireemissions: error opening ', TRIM( inpname )
2291 CALL wrf_error_fatal( TRIM( message ) )
2294 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_fireemissions: Read fire emissions at time ',&
2295 TRIM(current_date_char)
2296 CALL wrf_message( TRIM(message) )
2298 CALL wrf_debug (00 , 'mediation_integrate: calling input_auxinput7' )
2299 CALL input_auxinput7 ( grid%auxinput7_oid, grid , config_flags , ierr )
2301 CALL close_dataset ( grid%auxinput7_oid , config_flags , "DATASET=AUXINPUT7" )
2304 CALL wrf_debug (00 , 'mediation_integrate: med_read_wrf_chem_fireemissions: exit' )
2306 END SUBROUTINE med_read_wrf_chem_emissopt3
2307 !------------------------------------------------------------------------
2308 ! Biomass burn emissions input control. Three options are available and are
2309 ! set via the namelist variable io_style_fireemissions:
2311 ! 0 = Emissions are not read in from a file. They will contain their
2312 ! default values, which can be set in the Registry.
2313 ! (Intended for debugging of chem code)
2315 ! 1 = Emissions are read in from two 12 hour files that are cycled.
2316 ! With this choice, emi_inname and emi_outname should be set to
2317 ! the value "wrffirechemi_d<domain>". The value of frames_per_fireemissfile
2320 ! 2 = Emissions are read in from files identified by date and that have
2321 ! a length defined by frames_per_fireemissfile (in hours). Both
2322 ! fireemis_inname and fireemis_outname should be set to
2323 ! "wrffirechemi_d<domain>_<date>".
2324 !------------------------------------------------------------------------
2325 SUBROUTINE med_read_wrf_chem_fireemiss ( grid , config_flags )
2327 USE module_domain , ONLY : domain , domain_clock_get
2328 USE module_io_domain
2330 USE module_configure , ONLY : grid_config_rec_type
2332 USE module_bc_time_utilities
2336 USE module_date_time
2342 TYPE(domain) :: grid
2344 ! TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
2345 TYPE (grid_config_rec_type) :: config_flags
2346 Type (WRFU_Time ) :: stopTime, currentTime
2347 Type (WRFU_TimeInterval ) :: stepTime
2350 LOGICAL, EXTERNAL :: wrf_dm_on_monitor
2352 INTEGER :: ierr, efid, ihr
2353 REAL :: time, tupdate
2354 real, allocatable :: dumc0(:,:,:)
2355 CHARACTER (LEN=256) :: message, current_date_char, date_string
2356 CHARACTER (LEN=80) :: inpname
2358 #include <wrf_io_flags.h>
2360 CALL model_to_grid_config_rec ( grid%id , model_config_rec , config_flags )
2362 ! This "if" should be commented out when using emission files for nested
2363 ! domains. Also comment out the "ENDIF" line noted below.
2364 ! IF ( grid%id .EQ. 1 ) THEN
2366 CALL domain_clock_get( grid, current_time=currentTime, &
2367 current_timestr=current_date_char, &
2368 stop_time=stopTime, &
2369 time_step=stepTime )
2371 time = float(grid%itimestep) * grid%dt
2374 ! io_style_emissions option 0: no emissions read in...
2376 if( config_flags%io_style_fireemissions == 0 ) then
2379 ! io_style_emissions option 1: cycle through two 12 hour input files...
2381 else if( config_flags%io_style_fireemissions == 1 ) then
2383 tupdate = mod( time, (12. * 3600.) )
2384 IF( tupdate .LT. grid%dt ) THEN
2387 IF( currentTime + stepTime .GE. stopTime .AND. &
2388 grid%auxinput7_oid .NE. 0 ) THEN
2389 CALL close_dataset ( grid%auxinput7_oid , config_flags , "DATASET=AUXINPUT7" )
2393 IF ( tupdate .EQ. 0. ) THEN
2394 read( current_date_char(12:13),'(i2)') ihr
2395 IF ( ihr .LT. 12 .AND. ihr .GE. 0 ) THEN
2396 CALL construct_filename1 ( inpname , 'wrffirechemi_00z' , grid%id , 2 )
2397 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_fireemiss: Open file ',TRIM(inpname)
2398 CALL wrf_message( TRIM(message) )
2400 if( grid%auxinput7_oid .NE. 0 ) then
2401 CALL close_dataset ( grid%auxinput7_oid , config_flags , "DATASET=AUXINPUT7" )
2404 CALL open_r_dataset ( grid%auxinput7_oid, TRIM(inpname) , grid , config_flags, &
2405 "DATASET=AUXINPUT7", ierr )
2406 IF ( ierr .NE. 0 ) THEN
2407 WRITE( message , * ) 'med_read_wrf_chem_fireemiss: error opening ', TRIM( inpname )
2408 CALL wrf_error_fatal( TRIM( message ) )
2410 ELSE IF ( ihr .LT. 24 .AND. ihr .GE. 12 ) THEN
2411 CALL construct_filename1 ( inpname , 'wrffirechemi_12z' , grid%id , 2 )
2412 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_fireemiss: Open file ',TRIM(inpname)
2413 CALL wrf_message( TRIM(message) )
2415 if( grid%auxinput7_oid .NE. 0 ) then
2416 CALL close_dataset ( grid%auxinput7_oid , config_flags , "DATASET=AUXINPUT7" )
2419 CALL open_r_dataset ( grid%auxinput7_oid, TRIM(inpname) , grid , config_flags, &
2420 "DATASET=AUXINPUT7", ierr )
2421 IF ( ierr .NE. 0 ) THEN
2422 WRITE( message , * ) 'med_read_wrf_chem_fireemiss: error opening ', TRIM( inpname )
2423 CALL wrf_error_fatal( TRIM( message ) )
2426 WRITE( message , '(A,I10)' ) 'med_read_wrf_chem_fireemiss: error in fire emissions file time ', ihr
2427 CALL wrf_error_fatal( TRIM( message ) )
2431 WRITE( message, '(A,2F10.1)' ) ' FIRE EMISSIONS UPDATE TIME ',time,mod(time,3600.)
2432 CALL wrf_message( TRIM(message) )
2434 ! updates to fire emissions
2435 IF ( ( mod( time, 3600. ) .LT. grid%dt ) .AND. &
2436 ( currentTime + stepTime .LT. stopTime ) ) THEN
2438 WRITE(message,'(A,A)')'mediation_integrate: med_read_wrf_chem_fireemiss: Read emissions for time ',TRIM(current_date_char)
2439 CALL wrf_message( TRIM(message) )
2440 CALL wrf_debug (100 , 'mediation_integrate: calling input_auxinput7' )
2441 CALL input_auxinput7 ( grid%auxinput7_oid, grid , config_flags , ierr )
2443 CALL wrf_debug (100 , 'mediation_integrate: med_read_wrf_chem_fireemiss: Do not read emissions' )
2448 ! io_style_emissions option 2: use dated emission files whose length is
2449 ! set via frames_per_fireemissfile...
2451 else if( config_flags%io_style_fireemissions == 2 ) then
2452 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_fireemiss: Read emissions for time ',TRIM(current_date_char)
2453 CALL wrf_message( TRIM(message) )
2455 ! Code to read fire emission files...
2457 if( grid%auxinput7_oid == 0 ) then
2458 CALL construct_filename2a(inpname , grid%fireemi_inname, grid%id , 2, current_date_char)
2459 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_fireemiss: Open file ',TRIM(inpname)
2460 CALL wrf_message( TRIM(message) )
2461 CALL open_r_dataset ( grid%auxinput7_oid, TRIM(inpname) , grid , config_flags, &
2462 "DATASET=AUXINPUT7", ierr )
2463 IF ( ierr .NE. 0 ) THEN
2464 WRITE( message , * ) 'med_read_wrf_chem_fireemiss: error opening ', TRIM( inpname )
2465 CALL wrf_error_fatal( TRIM( message ) )
2469 ! Read the emissions data.
2471 CALL wrf_debug (100 , 'mediation_integrate: calling input_auxinput7' )
2472 CALL input_auxinput7 ( grid%auxinput7_oid, grid , config_flags , ierr )
2474 ! If reached the indicated number of frames in the emissions file, close it.
2476 grid%fireemissframes = grid%fireemissframes + 1
2477 IF ( grid%fireemissframes >= config_flags%frames_per_fireemissfile ) THEN
2478 CALL close_dataset ( grid%auxinput7_oid , config_flags , "DATASET=AUXINPUT7" )
2479 grid%fireemissframes = 0
2480 grid%auxinput7_oid = 0
2483 ! unknown io_style_emissions option...
2486 call wrf_error_fatal("Unknown emission style selected via io_style_emissions.")
2489 ! The following line should be commented out when using emission files
2490 ! for nested domains. Also comment out the "if" noted above.
2493 CALL wrf_debug (100 , 'mediation_integrate: med_read_wrf_chem_fireemiss: exit' )
2495 END SUBROUTINE med_read_wrf_chem_fireemiss
2497 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2498 SUBROUTINE med_read_wrf_chem_emissopt4 ( grid , config_flags )
2500 USE module_domain , ONLY : domain , domain_clock_get
2501 USE module_io_domain
2503 USE module_configure , ONLY : grid_config_rec_type
2505 USE module_bc_time_utilities
2509 USE module_date_time
2515 TYPE(domain) :: grid
2517 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
2520 LOGICAL, EXTERNAL :: wrf_dm_on_monitor
2522 INTEGER :: ierr, efid
2523 REAL :: time, tupdate
2524 real, allocatable :: dumc0(:,:,:)
2525 CHARACTER (LEN=256) :: message, current_date_char, date_string
2526 CHARACTER (LEN=80) :: inpname
2528 #include <wrf_io_flags.h>
2529 ! IF ( grid%id .EQ. 1 ) THEN
2531 CALL domain_clock_get( grid, current_timestr=current_date_char )
2533 CALL construct_filename1 ( inpname , 'wrfchemi' , grid%id , 2 )
2534 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_emissions: Open file ',TRIM(inpname)
2535 CALL wrf_message( TRIM(message) )
2537 if( grid%auxinput5_oid .NE. 0 ) then
2538 CALL close_dataset ( grid%auxinput5_oid , config_flags , "DATASET=AUXINPUT5" )
2541 CALL open_r_dataset ( grid%auxinput5_oid, TRIM(inpname) , grid , config_flags, &
2542 "DATASET=AUXINPUT5", ierr )
2543 IF ( ierr .NE. 0 ) THEN
2544 WRITE( message , * ) 'med_read_wrf_chem_emissions: error opening ', TRIM( inpname )
2545 CALL wrf_error_fatal( TRIM( message ) )
2548 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_emissions: Read biogenic emissions at time ',&
2549 TRIM(current_date_char)
2550 CALL wrf_message( TRIM(message) )
2552 CALL wrf_debug (100 , 'mediation_integrate: calling input_auxinput5' )
2553 CALL input_auxinput5 ( grid%auxinput5_oid, grid , config_flags , ierr )
2555 CALL close_dataset ( grid%auxinput5_oid , config_flags , "DATASET=AUXINPUT5" )
2558 CALL wrf_debug (100 , 'mediation_integrate: med_read_wrf_chem_emissions: exit' )
2560 END SUBROUTINE med_read_wrf_chem_emissopt4
2562 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2563 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2565 SUBROUTINE med_read_wrf_chem_dust_emiss ( grid , config_flags )
2567 USE module_domain , ONLY : domain , domain_clock_get
2568 USE module_io_domain
2570 USE module_configure , ONLY : grid_config_rec_type
2572 USE module_bc_time_utilities
2576 USE module_date_time
2582 TYPE(domain) :: grid
2584 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
2587 LOGICAL, EXTERNAL :: wrf_dm_on_monitor
2589 INTEGER :: ierr, efid
2590 REAL :: time, tupdate
2591 real, allocatable :: dumc0(:,:,:)
2592 CHARACTER (LEN=256) :: message, current_date_char, date_string
2593 CHARACTER (LEN=80) :: inpname
2595 #include <wrf_io_flags.h>
2596 ! IF ( grid%id .EQ. 1 ) THEN
2598 CALL domain_clock_get( grid, current_timestr=current_date_char )
2600 CALL construct_filename1 ( inpname , 'wrfchemi_dust' , grid%id , 2 )
2601 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_dust_emiss: Open file ',TRIM(inpname)
2602 CALL wrf_message( TRIM(message) )
2604 if( grid%auxinput8_oid .NE. 0 ) then
2605 CALL close_dataset ( grid%auxinput8_oid , config_flags , "DATASET=AUXINPUT8" )
2608 CALL open_r_dataset ( grid%auxinput8_oid, TRIM(inpname) , grid , config_flags, &
2609 "DATASET=AUXINPUT8", ierr )
2610 IF ( ierr .NE. 0 ) THEN
2611 WRITE( message , * ) 'med_read_wrf_chem_dust_emiss: error opening ', TRIM( inpname )
2612 CALL wrf_error_fatal( TRIM( message ) )
2615 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_dust_emiss: Read dust errosion factor at time ',&
2616 TRIM(current_date_char)
2617 CALL wrf_message( TRIM(message) )
2619 CALL wrf_debug (100 , 'mediation_integrate: calling input_auxinput8' )
2620 CALL input_auxinput8 ( grid%auxinput8_oid, grid , config_flags , ierr )
2622 CALL close_dataset ( grid%auxinput8_oid , config_flags , "DATASET=AUXINPUT8" )
2625 CALL wrf_debug (100 , 'mediation_integrate: med_read_wrf_chem_dust_emiss: exit' )
2627 END SUBROUTINE med_read_wrf_chem_dust_emiss
2629 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2630 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2632 SUBROUTINE med_read_wrf_chem_dms_emiss ( grid , config_flags )
2634 USE module_domain , ONLY : domain , domain_clock_get
2635 USE module_io_domain
2637 USE module_configure , ONLY : grid_config_rec_type
2639 USE module_bc_time_utilities
2643 USE module_date_time
2649 TYPE(domain) :: grid
2651 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
2654 LOGICAL, EXTERNAL :: wrf_dm_on_monitor
2656 INTEGER :: ierr, efid
2657 REAL :: time, tupdate
2658 real, allocatable :: dumc0(:,:,:)
2659 CHARACTER (LEN=256) :: message, current_date_char, date_string
2660 CHARACTER (LEN=80) :: inpname
2662 #include <wrf_io_flags.h>
2663 ! IF ( grid%id .EQ. 1 ) THEN
2665 CALL domain_clock_get( grid, current_timestr=current_date_char )
2667 CALL construct_filename1 ( inpname , 'wrfchemi_dms' , grid%id , 2 )
2668 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_dms_emiss: Open file ',TRIM(inpname)
2669 CALL wrf_message( TRIM(message) )
2671 if( grid%auxinput7_oid .NE. 0 ) then
2672 CALL close_dataset ( grid%auxinput7_oid , config_flags , "DATASET=AUXINPUT7" )
2675 CALL open_r_dataset ( grid%auxinput7_oid, TRIM(inpname) , grid , config_flags, &
2676 "DATASET=AUXINPUT7", ierr )
2677 IF ( ierr .NE. 0 ) THEN
2678 WRITE( message , * ) 'med_read_wrf_chem_dms_emiss: error opening ', TRIM( inpname )
2679 CALL wrf_error_fatal( TRIM( message ) )
2682 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_dms_emiss: Read dms reference fields',&
2683 TRIM(current_date_char)
2684 CALL wrf_message( TRIM(message) )
2686 CALL wrf_debug (100 , 'mediation_integrate: calling input_auxinput7' )
2687 CALL input_auxinput7 ( grid%auxinput7_oid, grid , config_flags , ierr )
2689 CALL close_dataset ( grid%auxinput7_oid , config_flags , "DATASET=AUXINPUT7" )
2692 CALL wrf_debug (100 , 'mediation_integrate: med_read_wrf_chem_dms_emiss: exit' )
2694 END SUBROUTINE med_read_wrf_chem_dms_emiss
2696 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2697 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2699 SUBROUTINE med_read_wrf_chem_gocart_bg ( grid , config_flags )
2701 USE module_domain , ONLY : domain , domain_clock_get
2702 USE module_io_domain
2704 USE module_configure , ONLY : grid_config_rec_type
2706 USE module_bc_time_utilities
2710 USE module_date_time
2716 TYPE(domain) :: grid
2718 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
2721 LOGICAL, EXTERNAL :: wrf_dm_on_monitor
2723 INTEGER :: ierr, efid
2724 REAL :: time, tupdate
2725 real, allocatable :: dumc0(:,:,:)
2726 CHARACTER (LEN=256) :: message, current_date_char, date_string
2727 CHARACTER (LEN=80) :: inpname
2729 #include <wrf_io_flags.h>
2730 ! IF ( grid%id .EQ. 1 ) THEN
2732 CALL domain_clock_get( grid, current_timestr=current_date_char )
2734 CALL construct_filename1 ( inpname , 'wrfchemi_gocart_bg' , grid%id , 2 )
2735 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_gocart_bg: Open file ',TRIM(inpname)
2736 CALL wrf_message( TRIM(message) )
2738 if( grid%auxinput8_oid .NE. 0 ) then
2739 CALL close_dataset ( grid%auxinput8_oid , config_flags , "DATASET=AUXINPUT8" )
2742 CALL open_r_dataset ( grid%auxinput8_oid, TRIM(inpname) , grid , config_flags, &
2743 "DATASET=AUXINPUT8", ierr )
2744 IF ( ierr .NE. 0 ) THEN
2745 WRITE( message , * ) 'med_read_wrf_chem_gocart_bg: error opening ', TRIM( inpname )
2746 CALL wrf_error_fatal( TRIM( message ) )
2749 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_gocart_bg: Read gocart_bg at time ',&
2750 TRIM(current_date_char)
2751 CALL wrf_message( TRIM(message) )
2753 CALL wrf_debug (100 , 'mediation_integrate: calling input_auxinput8' )
2754 CALL input_auxinput8 ( grid%auxinput8_oid, grid , config_flags , ierr )
2756 CALL close_dataset ( grid%auxinput8_oid , config_flags , "DATASET=AUXINPUT8" )
2759 ! CALL wrf_global_to_patch_real ( backg_no3_io , grid%backg_no3 , grid%domdesc, ' ' , 'xyz' , &
2760 ! ids, ide-1 , jds , jde-1 , kds , kde-1, &
2761 ! ims, ime , jms , jme , kms , kme , &
2762 ! ips, ipe , jps , jpe , kps , kpe )
2765 CALL wrf_debug (100 , 'mediation_integrate: med_read_wrf_chem_gocart_bg: exit' )
2767 END SUBROUTINE med_read_wrf_chem_gocart_bg
2771 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2774 !zhang's doing for outputing restart namelist parameters
2775 RECURSIVE SUBROUTINE med_namelist_out ( grid , config_flags )
2777 USE module_domain , ONLY : domain, domain_clock_get
2778 USE module_io_domain
2781 USE module_configure , ONLY : grid_config_rec_type
2782 USE module_bc_time_utilities
2783 !zhang new USE WRF_ESMF_MOD
2790 TYPE(domain), INTENT(IN) :: grid
2791 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
2794 !zhang new TYPE(ESMF_Time) :: CurrTime
2795 TYPE(WRFU_Time) :: CurrTime
2796 INTEGER :: nout,rc,kid
2797 INTEGER :: hr, min, sec, ms,julyr,julday
2799 CHARACTER*80 :: prefix, outname
2800 CHARACTER*80 :: timestr
2802 LOGICAL,EXTERNAL :: wrf_dm_on_monitor
2804 TYPE (grid_config_rec_type) :: kid_config_flags
2807 IF ( wrf_dm_on_monitor() ) THEN
2811 prefix = "wrfnamelist_d<domain>_<date>"
2814 !zhang new CALL ESMF_ClockGet( grid%domain_clock, CurrTime=CurrTime, rc=rc )
2815 !zhang new CALL wrf_timetoa ( CurrTime, timestr )
2816 CALL domain_clock_get( grid, current_timestr=timestr )
2818 CALL construct_filename2a ( outname , prefix, grid%id , 2 , timestr )
2820 IF ( wrf_dm_on_monitor() ) THEN
2823 OPEN ( FILE = trim(outname) , UNIT = nout, STATUS = 'UNKNOWN', FORM = 'FORMATTED')
2824 !zhang new CALL ESMF_TimeGet( grid%current_time, YY=julyr, dayOfYear=julday, H=hr, M=min, S=sec, MS=ms, rc=rc)
2825 CALL domain_clock_get( grid, current_time=CurrTime )
2826 CALL WRFU_TimeGet( CurrTime, YY=julyr, dayOfYear=julday, H=hr, M=min, S=sec, MS=ms, rc=rc)
2828 gmt=hr+real(min)/60.+real(sec)/3600.+real(ms)/(1000*3600)
2829 WRITE(NOUT,*) grid%i_parent_start
2830 WRITE(NOUT,*) grid%j_parent_start
2832 WRITE(NOUT,*) julday
2838 ! call recursively for children, (if any)
2839 DO kid = 1, max_nests
2840 IF ( ASSOCIATED( grid%nests(kid)%ptr ) ) THEN
2841 CALL model_to_grid_config_rec ( grid%nests(kid)%ptr%id , model_config_rec , kid_config_flags )
2842 CALL med_namelist_out ( grid%nests(kid)%ptr , kid_config_flags )
2847 END SUBROUTINE med_namelist_out
2848 !end of zhang's doing