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 ! output history at beginning of restart if alarm is ringing
66 CALL med_hist_out ( grid , HISTORY_ALARM, config_flags )
68 CALL med_hist_out ( grid , HISTORY_ALARM, config_flags )
70 CALL WRFU_AlarmRingerOff( grid%alarms( HISTORY_ALARM ), rc=rc )
72 ELSE IF ( (config_flags%restart) .AND. ( currTime .EQ. startTime ) .AND. &
73 ( config_flags%write_hist_at_0h_rst ) ) THEN
74 ! output history at beginning of restart even if alarm is not ringing
75 CALL med_hist_out ( grid , HISTORY_ALARM, config_flags )
76 CALL WRFU_AlarmRingerOff( grid%alarms( HISTORY_ALARM ), rc=rc )
80 IF( WRFU_AlarmIsRinging( grid%alarms( INPUTOUT_ALARM ), rc=rc ) ) THEN
81 CALL med_filter_out ( grid , config_flags )
82 CALL WRFU_AlarmRingerOff( grid%alarms( INPUTOUT_ALARM ), rc=rc )
85 DO ialarm = first_auxhist, last_auxhist
87 rc = 1 ! dummy statement
88 ELSE IF( WRFU_AlarmIsRinging( grid%alarms( ialarm ), rc=rc ) ) THEN
89 CALL med_hist_out ( grid , ialarm, config_flags )
90 CALL WRFU_AlarmRingerOff( grid%alarms( ialarm ), rc=rc )
94 DO ialarm = first_auxinput, last_auxinput
96 rc = 1 ! dummy statement
98 ! - Get chemistry data
99 ELSE IF( ialarm .EQ. AUXINPUT5_ALARM .AND. config_flags%chem_opt > 0 ) THEN
100 IF( config_flags%emiss_inpt_opt /= 0 ) THEN
101 IF( WRFU_AlarmIsRinging( grid%alarms( ialarm ), rc=rc ) ) THEN
102 call wrf_debug(15,' CALL med_read_wrf_chem_emiss ')
103 CALL med_read_wrf_chem_emiss ( grid , config_flags )
104 CALL WRFU_AlarmRingerOff( grid%alarms( ialarm ), rc=rc )
105 call wrf_debug(15,' Back from CALL med_read_wrf_chem_emiss ')
108 IF( WRFU_AlarmIsRinging( grid%alarms( ialarm ), rc=rc ) ) THEN
109 CALL med_auxinput_in ( grid, ialarm, config_flags )
110 CALL WRFU_AlarmRingerOff( grid%alarms( ialarm ), rc=rc )
113 ELSE IF( ialarm .EQ. AUXINPUT13_ALARM .AND. config_flags%chem_opt > 0 ) THEN
114 IF( config_flags%emiss_opt_vol /= 0 ) THEN
115 IF( WRFU_AlarmIsRinging( grid%alarms( ialarm ), rc=rc ) ) THEN
116 call wrf_debug(15,' CALL med_read_wrf_volc_emiss ')
117 CALL med_read_wrf_volc_emiss ( grid , config_flags )
118 CALL WRFU_AlarmRingerOff( grid%alarms( ialarm ), rc=rc )
119 call wrf_debug(15,' Back from CALL med_read_wrf_volc_emiss ')
122 IF( WRFU_AlarmIsRinging( grid%alarms( ialarm ), rc=rc ) ) THEN
123 CALL med_auxinput_in ( grid, ialarm, config_flags )
124 CALL WRFU_AlarmRingerOff( grid%alarms( ialarm ), rc=rc )
129 ELSE IF( ialarm .EQ. AUXINPUT11_ALARM ) THEN
130 IF( config_flags%obs_nudge_opt .EQ. 1) THEN
131 CALL med_fddaobs_in ( grid , config_flags )
134 ELSE IF( WRFU_AlarmIsRinging( grid%alarms( ialarm ), rc=rc ) ) THEN
135 CALL med_auxinput_in ( grid, ialarm, config_flags )
136 WRITE ( message , FMT='(A,i3,A,i3)' ) 'Input data processed for aux input ' , &
137 ialarm - first_auxinput + 1, ' for domain ',grid%id
138 CALL wrf_debug ( 0 , message )
139 CALL WRFU_AlarmRingerOff( grid%alarms( ialarm ), rc=rc )
144 CALL WRFU_ClockGet( grid%domain_clock, CurrTime=currTime, StartTime=startTime )
145 IF ( ( WRFU_AlarmIsRinging( grid%alarms( RESTART_ALARM ), rc=rc ) ) .AND. &
146 ( currTime .NE. startTime ) ) THEN
149 CALL domain_clock_get( grid, current_time=CurrTime )
150 CALL WRFU_TimeGet( CurrTime, YY=julyr, dayOfYear=julday, H=hr, M=min, S=sec, MS=ms, rc=rc)
151 gmt=hr+real(min)/60.+real(sec)/3600.+real(ms)/(1000*3600)
152 if (grid%id .eq. 2) call med_namelist_out ( grid , config_flags )
153 !end of zhang's doing
155 IF ( grid%id .EQ. 1 ) THEN
156 ! Only the parent initiates the restart writing. Otherwise, different
157 ! domains may be written out at different times and with different
158 ! time stamps in the file names.
159 CALL med_restart_out ( grid , config_flags )
161 CALL WRFU_AlarmRingerOff( grid%alarms( RESTART_ALARM ), rc=rc )
163 CALL WRFU_AlarmRingerOff( grid%alarms( RESTART_ALARM ), rc=rc )
166 ! - Look for boundary data after writing out history and restart files
167 CALL med_latbound_in ( grid , config_flags )
170 END SUBROUTINE med_before_solve_io
172 SUBROUTINE med_after_solve_io ( grid , config_flags )
174 USE module_domain , ONLY : domain
176 USE module_configure , ONLY : grid_config_rec_type
183 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
185 ! Compute time series variables
188 ! Compute track variables
189 CALL track_driver(grid)
192 END SUBROUTINE med_after_solve_io
194 SUBROUTINE med_pre_nest_initial ( parent , newid , config_flags )
197 USE module_domain , ONLY : domain, domain_clock_get
199 USE module_domain , ONLY : domain
202 USE module_utility , ONLY : WRFU_Time
204 USE module_utility , ONLY : WRFU_Time, WRFU_TimeEQ
208 USE module_configure , ONLY : grid_config_rec_type
214 TYPE(domain) , POINTER :: parent
215 INTEGER, INTENT(IN) :: newid
216 TYPE (grid_config_rec_type) , INTENT(INOUT) :: config_flags
217 TYPE (grid_config_rec_type) :: nest_config_flags
220 INTEGER :: itmp, fid, ierr, icnt
221 CHARACTER*256 :: rstname, message, timestr
223 TYPE(WRFU_Time) :: strt_time, cur_time
227 CALL domain_clock_get( parent, current_timestr=timestr, start_time=strt_time, current_time=cur_time )
228 CALL construct_filename2a ( rstname , config_flags%rst_inname , newid , 2 , timestr )
231 IF ( config_flags%restart .AND. (cur_time .EQ. strt_time) ) THEN
233 IF ( config_flags%restart .AND. WRFU_TimeEQ(cur_time,strt_time) ) THEN
235 WRITE(message,*)'RESTART: nest, opening ',TRIM(rstname),' for reading header information only'
236 CALL wrf_message ( message )
237 ! note that the parent pointer is not strictly correct, but nest is not allocated yet and
238 ! only the i/o communicator fields are used from "parent" (and those are dummies in current
240 CALL open_r_dataset ( fid , TRIM(rstname) , parent , config_flags , "DATASET=RESTART", ierr )
241 IF ( ierr .NE. 0 ) THEN
242 WRITE( message , '("program wrf: error opening ",A32," for reading")') TRIM(rstname)
243 CALL WRF_ERROR_FATAL ( message )
246 ! update the values of parent_start that were read in from the namelist (nest may have moved)
247 CALL wrf_get_dom_ti_integer ( fid , 'I_PARENT_START' , itmp , 1 , icnt, ierr )
248 IF ( ierr .EQ. 0 ) THEN
249 config_flags%i_parent_start = itmp
250 CALL nl_set_i_parent_start ( newid , config_flags%i_parent_start )
252 CALL wrf_get_dom_ti_integer ( fid , 'J_PARENT_START' , itmp , 1 , icnt, ierr )
253 IF ( ierr .EQ. 0 ) THEN
254 config_flags%j_parent_start = itmp
255 CALL nl_set_j_parent_start ( newid , config_flags%j_parent_start )
258 CALL close_dataset ( fid , config_flags , "DATASET=RESTART" )
262 END SUBROUTINE med_pre_nest_initial
265 SUBROUTINE med_nest_initial ( parent , nest , config_flags )
267 USE module_domain , ONLY : domain , domain_clock_get , get_ijk_from_grid
270 USE module_configure , ONLY : grid_config_rec_type
277 TYPE(domain) , POINTER :: parent, nest
278 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
279 TYPE (grid_config_rec_type) :: nest_config_flags
282 LOGICAL, EXTERNAL :: wrf_dm_on_monitor
283 TYPE(WRFU_Time) :: strt_time, cur_time
284 CHARACTER * 80 :: rstname , timestr
285 CHARACTER * 256 :: message
289 INTEGER :: ids , ide , jds , jde , kds , kde , &
290 ims , ime , jms , jme , kms , kme , &
291 ips , ipe , jps , jpe , kps , kpe
295 TYPE (WRFU_TimeInterval) :: interval, TimeSinceStart
296 INTEGER :: vortex_interval , n
298 INTEGER :: save_itimestep ! This is a kludge, correct fix will
299 ! involve integrating the time-step
300 ! counting into the time manager.
302 REAL, ALLOCATABLE, DIMENSION(:,:) :: save_acsnow &
313 SUBROUTINE med_interp_domain ( parent , nest )
314 USE module_domain , ONLY : domain
315 TYPE(domain) , POINTER :: parent , nest
316 END SUBROUTINE med_interp_domain
318 SUBROUTINE med_initialdata_input_ptr( nest , config_flags )
319 USE module_domain , ONLY : domain
320 USE module_configure , ONLY : grid_config_rec_type
321 TYPE (grid_config_rec_type), INTENT(IN) :: config_flags
322 TYPE(domain) , POINTER :: nest
323 END SUBROUTINE med_initialdata_input_ptr
325 SUBROUTINE med_nest_feedback ( parent , nest , config_flags )
326 USE module_domain , ONLY : domain
327 USE module_configure , ONLY : grid_config_rec_type
328 TYPE (domain), POINTER :: nest , parent
329 TYPE (grid_config_rec_type), INTENT(IN) :: config_flags
330 END SUBROUTINE med_nest_feedback
332 SUBROUTINE start_domain ( grid , allowed_to_move )
333 USE module_domain , ONLY : domain
335 LOGICAL, INTENT(IN) :: allowed_to_move
336 END SUBROUTINE start_domain
338 SUBROUTINE blend_terrain ( ter_interpolated , ter_input , &
339 ids , ide , jds , jde , kds , kde , &
340 ims , ime , jms , jme , kms , kme , &
341 ips , ipe , jps , jpe , kps , kpe )
342 INTEGER :: ids , ide , jds , jde , kds , kde , &
343 ims , ime , jms , jme , kms , kme , &
344 ips , ipe , jps , jpe , kps , kpe
345 REAL , DIMENSION(ims:ime,jms:jme) :: ter_interpolated
346 REAL , DIMENSION(ims:ime,jms:jme) :: ter_input
347 END SUBROUTINE blend_terrain
349 SUBROUTINE copy_3d_field ( ter_interpolated , ter_input , &
350 ids , ide , jds , jde , kds , kde , &
351 ims , ime , jms , jme , kms , kme , &
352 ips , ipe , jps , jpe , kps , kpe )
353 INTEGER :: ids , ide , jds , jde , kds , kde , &
354 ims , ime , jms , jme , kms , kme , &
355 ips , ipe , jps , jpe , kps , kpe
356 REAL , DIMENSION(ims:ime,jms:jme) :: ter_interpolated
357 REAL , DIMENSION(ims:ime,jms:jme) :: ter_input
358 END SUBROUTINE copy_3d_field
360 SUBROUTINE input_terrain_rsmas ( grid , &
361 ids , ide , jds , jde , kds , kde , &
362 ims , ime , jms , jme , kms , kme , &
363 ips , ipe , jps , jpe , kps , kpe )
364 USE module_domain , ONLY : domain
365 TYPE ( domain ) :: grid
366 INTEGER :: ids , ide , jds , jde , kds , kde , &
367 ims , ime , jms , jme , kms , kme , &
368 ips , ipe , jps , jpe , kps , kpe
369 END SUBROUTINE input_terrain_rsmas
371 SUBROUTINE wrf_tsin ( grid , ierr )
373 TYPE ( domain ), INTENT(INOUT) :: grid
374 INTEGER, INTENT(INOUT) :: ierr
375 END SUBROUTINE wrf_tsin
379 CALL domain_clock_get( parent, start_time=strt_time, current_time=cur_time )
381 IF ( .not. ( config_flags%restart .AND. strt_time .EQ. cur_time ) ) THEN
382 nest%first_force = .true.
384 ! initialize nest with interpolated data from the parent
385 nest%imask_nostag = 1
388 nest%imask_xystag = 1
391 parent%nest_pos = parent%ht
392 where ( parent%nest_pos .gt. 0. ) parent%nest_pos = parent%nest_pos + 500. ! make a cliff
395 ! initialize some other constants (and 1d arrays in z)
396 CALL init_domain_constants ( parent, nest )
398 ! fill in entire fine grid domain with interpolated coarse grid data
399 CALL med_interp_domain( parent, nest )
401 ! De-reference dimension information stored in the grid data structure.
402 CALL get_ijk_from_grid ( nest , &
403 ids, ide, jds, jde, kds, kde, &
404 ims, ime, jms, jme, kms, kme, &
405 ips, ipe, jps, jpe, kps, kpe )
407 ! get the nest config flags
408 CALL model_to_grid_config_rec ( nest%id , model_config_rec , nest_config_flags )
410 IF ( nest_config_flags%input_from_file .OR. nest_config_flags%input_from_hires ) THEN
412 WRITE(message,FMT='(A,I2,A)') '*** Initializing nest domain #',nest%id,&
413 ' from an input file. ***'
414 CALL wrf_debug ( 0 , message )
416 ! Store horizontally interpolated terrain-based fields in temp location if the input
417 ! data is from a pristine, un-cycled model input file. For the original topo from
418 ! the real program, we will need to adjust the terrain (and a couple of other base-
419 ! state fields) so reflect the smoothing and matching between the parent and child
422 CALL copy_3d_field ( nest%ht_int , nest%ht , &
423 ids , ide , jds , jde , 1 , 1 , &
424 ims , ime , jms , jme , 1 , 1 , &
425 ips , ipe , jps , jpe , 1 , 1 )
426 CALL copy_3d_field ( nest%mub_fine , nest%mub , &
427 ids , ide , jds , jde , 1 , 1 , &
428 ims , ime , jms , jme , 1 , 1 , &
429 ips , ipe , jps , jpe , 1 , 1 )
430 CALL copy_3d_field ( nest%phb_fine , nest%phb , &
431 ids , ide , jds , jde , kds , kde , &
432 ims , ime , jms , jme , kms , kme , &
433 ips , ipe , jps , jpe , kps , kpe )
435 IF ( nest_config_flags%input_from_file ) THEN
436 ! read input from dataset
437 CALL med_initialdata_input_ptr( nest , nest_config_flags )
439 ELSE IF ( nest_config_flags%input_from_hires ) THEN
440 ! read in high res topography
441 CALL input_terrain_rsmas ( nest, &
442 ids , ide , jds , jde , 1 , 1 , &
443 ims , ime , jms , jme , 1 , 1 , &
444 ips , ipe , jps , jpe , 1 , 1 )
447 ! save elevation and mub for temp and qv adjustment
449 CALL copy_3d_field ( nest%ht_fine , nest%ht , &
450 ids , ide , jds , jde , 1 , 1 , &
451 ims , ime , jms , jme , 1 , 1 , &
452 ips , ipe , jps , jpe , 1 , 1 )
453 CALL copy_3d_field ( nest%mub_save , nest%mub , &
454 ids , ide , jds , jde , 1 , 1 , &
455 ims , ime , jms , jme , 1 , 1 , &
456 ips , ipe , jps , jpe , 1 , 1 )
458 ! blend parent and nest fields: terrain, mub, and phb. The ht, mub and phb are used in start_domain.
460 IF ( nest%save_topo_from_real == 1 ) THEN
461 CALL blend_terrain ( nest%ht_int , nest%ht , &
462 ids , ide , jds , jde , 1 , 1 , &
463 ims , ime , jms , jme , 1 , 1 , &
464 ips , ipe , jps , jpe , 1 , 1 )
465 CALL blend_terrain ( nest%mub_fine , nest%mub , &
466 ids , ide , jds , jde , 1 , 1 , &
467 ims , ime , jms , jme , 1 , 1 , &
468 ips , ipe , jps , jpe , 1 , 1 )
469 CALL blend_terrain ( nest%phb_fine , nest%phb , &
470 ids , ide , jds , jde , kds , kde , &
471 ims , ime , jms , jme , kms , kme , &
472 ips , ipe , jps , jpe , kps , kpe )
477 CALL adjust_tempqv ( nest%mub , nest%mub_save , &
478 nest%znw , nest%p_top , &
479 nest%t_2 , nest%p , nest%moist(ims,kms,jms,P_QV) , &
480 ids , ide , jds , jde , kds , kde , &
481 ims , ime , jms , jme , kms , kme , &
482 ips , ipe , jps , jpe , kps , kpe )
485 WRITE(message,FMT='(A,I2,A,I2,A)') '*** Initializing nest domain #',nest%id,&
486 ' by horizontally interpolating parent domain #' ,parent%id, &
488 CALL wrf_debug ( 0 , message )
491 ! For nests without an input file, we still need to read time series locations
492 ! from the tslist file
493 CALL wrf_tsin( nest , ierr )
498 ! feedback, mostly for this new terrain, but it is the safe thing to do
499 parent%ht_coarse = parent%ht
501 CALL med_nest_feedback ( parent , nest , config_flags )
503 ! set some other initial fields, fill out halos, base fields; re-do parent due
504 ! to new terrain elevation from feedback
505 nest%imask_nostag = 1
508 nest%imask_xystag = 1
509 nest%press_adj = .TRUE.
510 CALL start_domain ( nest , .TRUE. )
512 CALL get_ijk_from_grid ( parent , &
513 ids, ide, jds, jde, kds, kde, &
514 ims, ime, jms, jme, kms, kme, &
515 ips, ipe, jps, jpe, kps, kpe )
517 ALLOCATE( save_acsnow(ims:ime,jms:jme) )
518 ALLOCATE( save_acsnom(ims:ime,jms:jme) )
519 ALLOCATE( save_cuppt(ims:ime,jms:jme) )
520 ALLOCATE( save_rainc(ims:ime,jms:jme) )
521 ALLOCATE( save_rainnc(ims:ime,jms:jme) )
522 ALLOCATE( save_sfcevp(ims:ime,jms:jme) )
523 ALLOCATE( save_sfcrunoff(ims:ime,jms:jme) )
524 ALLOCATE( save_udrunoff(ims:ime,jms:jme) )
525 save_acsnow = parent%acsnow
526 save_acsnom = parent%acsnom
527 save_cuppt = parent%cuppt
528 save_rainc = parent%rainc
529 save_rainnc = parent%rainnc
530 save_sfcevp = parent%sfcevp
531 save_sfcrunoff = parent%sfcrunoff
532 save_udrunoff = parent%udrunoff
533 save_itimestep = parent%itimestep
534 parent%imask_nostag = 1
535 parent%imask_xstag = 1
536 parent%imask_ystag = 1
537 parent%imask_xystag = 1
539 parent%press_adj = .FALSE.
540 CALL start_domain ( parent , .TRUE. )
542 parent%acsnow = save_acsnow
543 parent%acsnom = save_acsnom
544 parent%cuppt = save_cuppt
545 parent%rainc = save_rainc
546 parent%rainnc = save_rainnc
547 parent%sfcevp = save_sfcevp
548 parent%sfcrunoff = save_sfcrunoff
549 parent%udrunoff = save_udrunoff
550 parent%itimestep = save_itimestep
551 DEALLOCATE( save_acsnow )
552 DEALLOCATE( save_acsnom )
553 DEALLOCATE( save_cuppt )
554 DEALLOCATE( save_rainc )
555 DEALLOCATE( save_rainnc )
556 DEALLOCATE( save_sfcevp )
557 DEALLOCATE( save_sfcrunoff )
558 DEALLOCATE( save_udrunoff )
559 ! end of kludge: 20040604
564 IF ( wrf_dm_on_monitor() ) CALL start_timing
566 CALL domain_clock_get( nest, current_timestr=timestr )
567 CALL construct_filename2a ( rstname , config_flags%rst_inname , nest%id , 2 , timestr )
569 WRITE(message,*)'RESTART: nest, opening ',TRIM(rstname),' for reading'
570 CALL wrf_message ( message )
571 CALL model_to_grid_config_rec ( nest%id , model_config_rec , nest_config_flags )
572 CALL open_r_dataset ( fid , TRIM(rstname) , nest , nest_config_flags , "DATASET=RESTART", ierr )
573 IF ( ierr .NE. 0 ) THEN
574 WRITE( message , '("program wrf: error opening ",A32," for reading")') TRIM(rstname)
575 CALL WRF_ERROR_FATAL ( message )
577 CALL input_restart ( fid, nest , nest_config_flags , ierr )
578 CALL close_dataset ( fid , nest_config_flags , "DATASET=RESTART" )
580 IF ( wrf_dm_on_monitor() ) THEN
581 WRITE ( message , FMT = '("processing restart file for domain ",I8)' ) nest%id
582 CALL end_timing ( TRIM(message) )
585 nest%imask_nostag = 1
588 nest%imask_xystag = 1
589 nest%press_adj = .FALSE.
590 CALL start_domain ( nest , .TRUE. )
592 ! this doesn't need to be done for moving nests, since ht_coarse is part of the restart
593 parent%ht_coarse = parent%ht
596 ! In case of a restart, assume that the movement has already occurred in the previous
597 ! run and turn off the alarm for the starting time. We must impose a requirement that the
598 ! run be restarted on-interval. Test for that and print a warning if it isn't.
599 ! Note, simulation_start, etc. should be available as metadata in the restart file, and
600 ! these will have gotten, set, and retrievable as rconfig data been set in share/input_wrf.F
601 ! using the nl_get routines below. JM 20060314
603 CALL nl_get_vortex_interval ( nest%id , vortex_interval )
604 CALL WRFU_TimeIntervalSet( interval, M=vortex_interval, rc=rc )
606 CALL domain_clock_get( nest, timeSinceSimulationStart=TimeSinceStart )
607 n = WRFU_TimeIntervalDIVQuot( TimeSinceStart , interval )
608 IF ( ( interval * n ) .NE. TimeSinceStart ) THEN
609 CALL wrf_message('WARNING: Restart is not on a vortex_interval time boundary.')
610 CALL wrf_message('The code will work but results will not agree exactly with a ')
611 CALL wrf_message('a run that was done straight-through, without a restart.')
613 !! In case of a restart, assume that the movement has already occurred in the previous
614 !! run and turn off the alarm for the starting time. We must impose a requirement that the
615 !! run be restarted on-interval. Test for that and print a warning if it isn't.
616 !! Note, simulation_start, etc. should be available as metadata in the restart file, and
617 !! these will have gotten, set, and retrievable as rconfig data been set in share/input_wrf.F
618 !! using the nl_get routines below. JM 20060314
619 ! CALL WRFU_AlarmRingerOff( nest%alarms( COMPUTE_VORTEX_CENTER_ALARM ), rc=rc )
622 ! this code, currently commented out, is an attempt to have the
623 ! vortex centering interval be set according to simulation start
624 ! time (rather than run start time) in case of a restart. But
625 ! there are other problems (the WRF clock is currently using
626 ! run-start as it's start time) so the alarm still would not fire
627 ! right if the model were started off-interval. Leave it here and
628 ! enable when the clock is changed to use sim-start for start time.
630 CALL nl_get_vortex_interval ( nest%id , vortex_interval )
631 CALL WRFU_TimeIntervalSet( interval, M=vortex_interval, rc=rc )
633 CALL domain_clock_get( nest, timeSinceSimulationStart=TimeSinceStart )
635 CALL domain_alarm_create( nest, COMPUTE_VORTEX_CENTER_ALARM, interval )
636 CALL WRFU_AlarmEnable( nest%alarms( COMPUTE_VORTEX_CENTER_ALARM ), rc=rc )
637 n = WRFU_TimeIntervalDIVQuot( TimeSinceStart , interval )
638 IF ( ( interval * n ) .EQ. TimeSinceStart ) THEN
639 CALL WRFU_AlarmRingerOn( nest%alarms( COMPUTE_VORTEX_CENTER_ALARM ), rc=rc )
641 CALL WRFU_AlarmRingerOff( nest%alarms( COMPUTE_VORTEX_CENTER_ALARM ), rc=rc )
650 #if (NMM_CORE == 1 && NMM_NEST == 1)
651 !===================================================================================
652 ! Added for the NMM core. This is gopal's doing.
653 !===================================================================================
657 SUBROUTINE med_nest_egrid_configure ( parent , nest )
658 USE module_domain , ONLY : domain
659 TYPE(domain) , POINTER :: parent , nest
660 END SUBROUTINE med_nest_egrid_configure
662 SUBROUTINE med_construct_egrid_weights ( parent , nest )
663 USE module_domain , ONLY : domain
664 TYPE(domain) , POINTER :: parent , nest
665 END SUBROUTINE med_construct_egrid_weights
667 SUBROUTINE BASE_STATE_PARENT ( Z3d,Q3d,T3d,PSTD, &
669 FIS,QSH,PD,PDTOP,PTOP, &
672 IDS,IDE,JDS,JDE,KDS,KDE, &
673 IMS,IME,JMS,JME,KMS,KME, &
674 IPS,IPE,JPS,JPE,KPS,KPE )
677 USE MODULE_MODEL_CONSTANTS
679 INTEGER, INTENT(IN ) :: IDS,IDE,JDS,JDE,KDS,KDE
680 INTEGER, INTENT(IN ) :: IMS,IME,JMS,JME,KMS,KME
681 INTEGER, INTENT(IN ) :: IPS,IPE,JPS,JPE,KPS,KPE
682 REAL, INTENT(IN ) :: PDTOP,PTOP
683 REAL, DIMENSION(KMS:KME), INTENT(IN) :: ETA1,ETA2,DETA1,DETA2
684 REAL, DIMENSION(IMS:IME,JMS:JME), INTENT(IN) :: FIS,PD,QSH
685 REAL, DIMENSION(IMS:IME,JMS:JME,KMS:KME), INTENT(IN) :: PINT,T,Q,CWM
686 REAL, DIMENSION(KMS:KME) , INTENT(OUT):: PSTD
687 REAL, DIMENSION(IMS:IME,JMS:JME,KMS:KME), INTENT(OUT):: Z3d,Q3d,T3d
689 END SUBROUTINE BASE_STATE_PARENT
691 SUBROUTINE NEST_TERRAIN ( nest, config_flags )
692 USE module_domain , ONLY : domain
693 USE module_configure , ONLY : grid_config_rec_type
694 TYPE(domain) , POINTER :: nest
695 TYPE(grid_config_rec_type) , INTENT(IN) :: config_flags
696 END SUBROUTINE NEST_TERRAIN
698 SUBROUTINE med_interp_domain ( parent , nest )
699 USE module_domain , ONLY : domain
700 TYPE(domain) , POINTER :: parent , nest
701 END SUBROUTINE med_interp_domain
703 SUBROUTINE med_init_domain_constants_nmm ( parent, nest )
704 USE module_domain , ONLY : domain
705 TYPE(domain) , POINTER :: parent , nest
706 END SUBROUTINE med_init_domain_constants_nmm
708 SUBROUTINE start_domain ( grid , allowed_to_move )
709 USE module_domain , ONLY : domain
711 LOGICAL, INTENT(IN) :: allowed_to_move
712 END SUBROUTINE start_domain
718 if (config_flags%restart .or. nest%analysis) then
719 nest%first_force = .true.
721 nest%first_force = .false.
723 !end of zhang's doing
725 !zhang's doing for analysis option
726 IF(.not. nest%analysis .and. .not. config_flags%restart)THEN ! initialize for cold-start
729 !----------------------------------------------------------------------------
730 ! initialize nested domain configurations including setting up wbd,sbd, etc
731 !----------------------------------------------------------------------------
733 CALL med_nest_egrid_configure ( parent , nest )
735 !-------------------------------------------------------------------------
736 ! initialize lat-lons and determine weights
737 !-------------------------------------------------------------------------
739 CALL med_construct_egrid_weights ( parent, nest )
742 ! De-reference dimension information stored in the grid data structure.
744 ! From the hybrid, construct the GPMs on isobaric surfaces and then interpolate those
745 ! values on to the nested domain. 23 standard prssure levels are assumed here. For
746 ! levels below ground, lapse rate atmosphere is assumed before the use of vertical
747 ! spline interpolation
772 CALL BASE_STATE_PARENT ( parent%Z3d,parent%Q3d,parent%T3d,parent%PSTD, &
773 parent%PINT,parent%T,parent%Q,parent%CWM, &
774 parent%FIS,parent%QSH,parent%PD,parent%pdtop,parent%pt, &
775 parent%ETA1,parent%ETA2, &
776 parent%DETA1,parent%DETA2, &
777 IDS,IDE,JDS,JDE,KDS,KDE, &
778 IMS,IME,JMS,JME,KMS,KME, &
779 IPS,IPE,JPS,JPE,KPS,KPE )
782 ! Set new terrain. Since some terrain adjustment is done within the interpolation calls
783 ! at the next step, the new terrain over the nested domain has to be called here.
807 CALL NEST_TERRAIN ( nest, config_flags )
809 ! Initialize some more constants required especially for terrain adjustment processes
811 nest%PSTD=parent%PSTD
813 parent%KZMAX=KME ! just for safety
815 DO J = JPS, MIN(JPE,JDE-1)
816 DO I = IPS, MIN(IPE,IDE-1)
817 nest%fis(I,J)=nest%hres_fis(I,J)
821 !--------------------------------------------------------------------------
823 !--------------------------------------------------------------------------
825 ! initialize nest with interpolated data from the parent
827 nest%imask_nostag = 0
830 nest%imask_xystag = 0
833 CALL med_interp_domain( parent, nest )
835 CALL domain_clock_get( parent, start_time=strt_time, current_time=cur_time )
837 IF ( .not. ( config_flags%restart .AND. strt_time .EQ. cur_time ) ) THEN
839 CALL med_interp_domain( parent, nest )
843 CALL domain_clock_get( nest, current_timestr=timestr )
844 CALL construct_filename2a ( rstname , config_flags%rst_inname , nest%id , 2 , timestr )
846 WRITE(message,*)'RESTART: nest, opening ',TRIM(rstname),' for reading'
847 CALL wrf_message ( message )
848 CALL model_to_grid_config_rec ( nest%id , model_config_rec , nest_config_flags )
849 CALL open_r_dataset ( fid , TRIM(rstname) , nest , nest_config_flags , "DATASET=RESTART", ierr )
850 IF ( ierr .NE. 0 ) THEN
851 WRITE( message , '("program wrf: error opening ",A32," for reading")') TRIM(rstname)
852 CALL WRF_ERROR_FATAL ( message )
854 CALL input_restart ( fid, nest , nest_config_flags , ierr )
855 CALL close_dataset ( fid , nest_config_flags , "DATASET=RESTART" )
860 !------------------------------------------------------------------------------
861 ! set up constants (module_initialize_real.F for nested nmm domain)
862 !-----------------------------------------------------------------------------
864 CALL med_init_domain_constants_nmm ( parent, nest )
866 !--------------------------------------------------------------------------------------
867 ! set some other initial fields, fill out halos, etc.
868 !--------------------------------------------------------------------------------------
870 CALL start_domain ( nest, .TRUE.)
873 !zhang's doing: else for analysis or restart option
876 CALL nl_set_isice ( nest%id , config_flags%isice )
877 CALL nl_set_isoilwater ( nest%id , config_flags%isoilwater )
878 CALL nl_set_isurban ( nest%id , config_flags%isurban )
879 CALL nl_set_gmt ( nest%id , config_flags%gmt )
880 CALL nl_set_julyr (nest%id, config_flags%julyr)
881 CALL nl_set_julday ( nest%id , config_flags%julday )
883 CALL med_analysis_out ( nest, config_flags )
887 !------------------------------------------------------------------------------------
888 ! read in analysis (equivalent of restart for the nested domains)
889 !------------------------------------------------------------------------------------
892 IF( nest%analysis .and. .not. config_flags%restart)THEN
893 CALL med_analysis_in ( nest, config_flags )
894 ELSE IF (config_flags%restart)THEN
895 CALL med_restart_in ( nest, config_flags )
897 !end of zhang's doing
899 !----------------------------------------------------------------------------
900 ! initialize nested domain configurations including setting up wbd,sbd, etc
901 !----------------------------------------------------------------------------
903 CALL med_nest_egrid_configure ( parent , nest )
905 !-------------------------------------------------------------------------
906 ! initialize lat-lons and determine weights (overwrite for safety)
907 !-------------------------------------------------------------------------
909 CALL med_construct_egrid_weights ( parent, nest )
911 nest%imask_nostag = 0
914 nest%imask_xystag = 0
916 !------------------------------------------------------------------------------
917 ! set up constants (module_initialize_real.F for nested nmm domain)
918 !-----------------------------------------------------------------------------
920 CALL med_init_domain_constants_nmm ( parent, nest )
922 !--------------------------------------------------------------------------------------
923 ! set some other initial fields, fill out halos, etc. (again, safety sake only)
924 ! Also, in order to accomodate some physics initialization after nest move, set
925 ! analysis back to false for future use
926 !--------------------------------------------------------------------------------------
928 CALL start_domain ( nest, .TRUE.)
930 nest%analysis=.FALSE.
931 CALL nl_set_analysis( nest%id, nest%analysis)
937 !===================================================================================
938 ! Added for the NMM core. End of gopal's doing.
939 !===================================================================================
942 END SUBROUTINE med_nest_initial
944 SUBROUTINE init_domain_constants ( parent , nest )
945 USE module_domain , ONLY : domain
947 TYPE(domain) :: parent , nest
949 CALL init_domain_constants_em ( parent, nest )
951 END SUBROUTINE init_domain_constants
954 SUBROUTINE med_nest_force ( parent , nest )
956 USE module_domain , ONLY : domain
958 USE module_configure , ONLY : grid_config_rec_type
966 TYPE(domain) , POINTER :: parent, nest
968 INTEGER :: idum1 , idum2 , fid, rc
970 #if (NMM_CORE == 1 && NMM_NEST == 1)
971 INTEGER :: IDS,IDE,JDS,JDE,KDS,KDE ! gopal
972 INTEGER :: IMS,IME,JMS,JME,KMS,KME
973 INTEGER :: ITS,ITE,JTS,JTE,KTS,KTE
977 SUBROUTINE med_force_domain ( parent , nest )
978 USE module_domain , ONLY : domain
979 TYPE(domain) , POINTER :: parent , nest
980 END SUBROUTINE med_force_domain
981 SUBROUTINE med_interp_domain ( parent , nest )
982 USE module_domain , ONLY : domain
983 TYPE(domain) , POINTER :: parent , nest
984 END SUBROUTINE med_interp_domain
985 #if (NMM_CORE == 1 && NMM_NEST == 1)
986 !===================================================================================
987 ! Added for the NMM core. This is gopal's doing.
988 !===================================================================================
990 SUBROUTINE BASE_STATE_PARENT ( Z3d,Q3d,T3d,PSTD, &
992 FIS,QSH,PD,PDTOP,PTOP, &
995 IDS,IDE,JDS,JDE,KDS,KDE, &
996 IMS,IME,JMS,JME,KMS,KME, &
997 ITS,ITE,JTS,JTE,KTS,KTE )
1000 USE MODULE_MODEL_CONSTANTS
1002 INTEGER, INTENT(IN ) :: IDS,IDE,JDS,JDE,KDS,KDE
1003 INTEGER, INTENT(IN ) :: IMS,IME,JMS,JME,KMS,KME
1004 INTEGER, INTENT(IN ) :: ITS,ITE,JTS,JTE,KTS,KTE
1005 REAL, INTENT(IN ) :: PDTOP,PTOP
1006 REAL, DIMENSION(KMS:KME), INTENT(IN) :: ETA1,ETA2,DETA1,DETA2
1007 REAL, DIMENSION(IMS:IME,JMS:JME), INTENT(IN) :: FIS,PD,QSH
1008 REAL, DIMENSION(IMS:IME,JMS:JME,KMS:KME), INTENT(IN) :: PINT,T,Q,CWM
1009 REAL, DIMENSION(KMS:KME) , INTENT(OUT):: PSTD
1010 REAL, DIMENSION(IMS:IME,JMS:JME,KMS:KME), INTENT(OUT):: Z3d,Q3d,T3d
1012 END SUBROUTINE BASE_STATE_PARENT
1017 #if (NMM_CORE == 1 && NMM_NEST == 1)
1019 ! De-reference dimension information stored in the grid data structure.
1043 CALL BASE_STATE_PARENT ( parent%Z3d,parent%Q3d,parent%T3d,parent%PSTD, &
1044 parent%PINT,parent%T,parent%Q,parent%CWM, &
1045 parent%FIS,parent%QSH,parent%PD,parent%pdtop,parent%pt, &
1046 parent%ETA1,parent%ETA2, &
1047 parent%DETA1,parent%DETA2, &
1048 IDS,IDE,JDS,JDE,KDS,KDE, &
1049 IMS,IME,JMS,JME,KMS,KME, &
1050 ITS,ITE,JTS,JTE,KTS,KTE )
1054 IF ( .NOT. WRFU_ClockIsStopTime(nest%domain_clock ,rc=rc) ) THEN
1055 ! initialize nest with interpolated data from the parent
1056 nest%imask_nostag = 1
1057 nest%imask_xstag = 1
1058 nest%imask_ystag = 1
1059 nest%imask_xystag = 1
1060 CALL med_force_domain( parent, nest )
1063 ! might also have calls here to do input from a file into the nest
1066 END SUBROUTINE med_nest_force
1068 SUBROUTINE med_nest_feedback ( parent , nest , config_flags )
1070 USE module_domain , ONLY : domain , get_ijk_from_grid
1072 USE module_configure , ONLY : grid_config_rec_type
1080 TYPE(domain) , POINTER :: parent, nest
1081 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
1083 INTEGER :: idum1 , idum2 , fid, rc
1084 INTEGER :: ids , ide , jds , jde , kds , kde , &
1085 ims , ime , jms , jme , kms , kme , &
1086 ips , ipe , jps , jpe , kps , kpe
1090 SUBROUTINE med_feedback_domain ( parent , nest )
1091 USE module_domain , ONLY : domain
1092 TYPE(domain) , POINTER :: parent , nest
1093 END SUBROUTINE med_feedback_domain
1096 ! feedback nest to the parent
1097 IF ( config_flags%feedback .NE. 0 ) THEN
1098 CALL med_feedback_domain( parent, nest )
1100 CALL get_ijk_from_grid ( parent , &
1101 ids, ide, jds, jde, kds, kde, &
1102 ims, ime, jms, jme, kms, kme, &
1103 ips, ipe, jps, jpe, kps, kpe )
1104 ! gopal's change- added ifdef
1105 #if ( EM_CORE == 1 )
1106 DO j = jps, MIN(jpe,jde-1)
1107 DO i = ips, MIN(ipe,ide-1)
1108 IF ( parent%nest_pos(i,j) .EQ. 9021000. ) THEN
1109 parent%nest_pos(i,j) = parent%ht(i,j)*1.5 + 1000.
1110 ELSE IF ( parent%ht(i,j) .NE. 0. ) THEN
1111 parent%nest_pos(i,j) = parent%ht(i,j) + 500.
1113 parent%nest_pos(i,j) = 0.
1122 END SUBROUTINE med_nest_feedback
1124 SUBROUTINE med_last_solve_io ( grid , config_flags )
1126 USE module_state_description
1127 USE module_domain , ONLY : domain, domain_clock_get
1128 USE module_configure , ONLY : grid_config_rec_type
1136 TYPE(domain) :: grid
1137 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
1142 TYPE(WRFU_Time) :: CurrTime !zhang new
1143 INTEGER :: hr, min, sec, ms,julyr,julday
1145 !end of zhang's doing
1148 ! #if (EM_CORE == 1)
1149 IF( WRFU_AlarmIsRinging( grid%alarms( HISTORY_ALARM ), rc=rc ) .AND. &
1150 (grid%dfi_write_dfi_history .OR. grid%dfi_stage == DFI_FST .OR. grid%dfi_opt == DFI_NODFI) ) THEN
1152 ! IF( WRFU_AlarmIsRinging( grid%alarms( HISTORY_ALARM ), rc=rc )) THEN
1154 CALL med_hist_out ( grid , HISTORY_ALARM , config_flags )
1157 IF( WRFU_AlarmIsRinging( grid%alarms( INPUTOUT_ALARM ), rc=rc ) ) THEN
1158 CALL med_filter_out ( grid , config_flags )
1161 ! registry-generated file of the following
1162 ! IF( WRFU_AlarmIsRinging( grid%alarms( AUXHIST1_ALARM ), rc=rc ) ) THEN
1163 ! CALL med_hist_out ( grid , AUXHIST1_ALARM , config_flags )
1165 #include "med_last_solve_io.inc"
1168 IF( WRFU_AlarmIsRinging( grid%alarms( RESTART_ALARM ), rc=rc ) ) THEN
1171 !zhang new CALL ESMF_TimeGet( grid%current_time, YY=julyr, dayOfYear=julday, H=hr, M=min, S=sec, MS=ms, rc=rc)
1172 CALL domain_clock_get( grid, current_time=CurrTime )
1173 CALL WRFU_TimeGet( CurrTime, YY=julyr, dayOfYear=julday, H=hr, M=min, S=sec, MS=ms, rc=rc)
1174 gmt=hr+real(min)/60.+real(sec)/3600.+real(ms)/(1000*3600)
1175 if (grid%id .eq. 2) call med_namelist_out ( grid , config_flags )
1176 !end of zhang's doing
1178 IF ( grid%id .EQ. 1 ) THEN
1179 CALL med_restart_out ( grid , config_flags )
1183 ! Write out time series
1184 CALL write_ts( grid )
1187 END SUBROUTINE med_last_solve_io
1191 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1194 !==================================================================================
1195 ! Added for the NMM 3d var. This is simply an extension of med_restart_out.
1196 ! The file is simply called wrfanal***. This is gopal's doing
1197 !===================================================================================
1199 SUBROUTINE med_analysis_in ( grid , config_flags )
1201 USE module_domain , ONLY : domain, domain_clock_get
1202 USE module_io_domain
1205 USE module_configure , ONLY : grid_config_rec_type
1206 USE module_bc_time_utilities
1207 !zhang USE WRF_ESMF_MOD
1212 TYPE(domain) :: grid
1213 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
1216 LOGICAL, EXTERNAL :: wrf_dm_on_monitor
1217 CHARACTER*80 :: rstname , outname
1218 INTEGER :: fid , rid
1219 CHARACTER (LEN=256) :: message
1222 !zhang old TYPE(ESMF_Time) :: CurrTime
1223 TYPE(WRFU_Time) :: CurrTime
1224 CHARACTER*80 :: timestr
1226 IF ( wrf_dm_on_monitor() ) THEN
1232 !zhang's doing CALL ESMF_ClockGet( grid%domain_clock, CurrTime=CurrTime, rc=ierr )
1233 !zhang's doing CALL wrf_timetoa ( CurrTime, timestr )
1234 CALL domain_clock_get( grid, current_timestr=timestr )
1235 CALL construct_filename2a ( rstname ,config_flags%anl_outname, grid%id , 2 , timestr )
1237 WRITE( message , '("med_analysis_in: opening ",A," for reading")' ) TRIM ( rstname )
1238 CALL wrf_debug( 1 , message )
1239 CALL open_r_dataset ( rid, TRIM(rstname), grid , &
1240 config_flags , "DATASET=RESTART", ierr )
1242 IF ( ierr .NE. 0 ) THEN
1243 ! Could not open the analysis file, so notify user.
1245 write(message,'(A,I0,A,A,A)') 'WARNING: Domain ',grid%id,' analysis file ',trim(rstname),' is missing.'
1246 call wrf_message(message)
1247 write(message,'(A,I0,A)') '-------> Domain ',grid%id,' running as a cold start (interp from parent).'
1248 call wrf_message(message)
1250 IF ( wrf_dm_on_monitor() ) THEN
1251 WRITE (message, '("Failing to read restart for domain ",I8)') grid%id
1252 CALL end_timing ( TRIM(message) )
1257 ! Was able to open the analysis file. Read it as a restart file.
1259 CALL input_restart ( rid, grid , config_flags , ierr )
1260 IF ( wrf_dm_on_monitor() ) THEN
1261 WRITE ( message , FMT = '("Reading restart for domain ",I8)' ) grid%id
1262 CALL end_timing ( TRIM(message) )
1264 CALL close_dataset ( rid , config_flags , "DATASET=RESTART" )
1269 END SUBROUTINE med_analysis_in
1270 !=========================================================================================================
1271 !=========================================================================================================
1272 SUBROUTINE med_analysis_out ( grid , config_flags )
1274 USE module_domain , ONLY : domain, domain_clock_get
1275 USE module_io_domain
1278 USE module_configure , ONLY : grid_config_rec_type
1279 USE module_bc_time_utilities
1280 !zhang USE WRF_ESMF_MOD
1285 TYPE(domain) :: grid
1286 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
1289 LOGICAL, EXTERNAL :: wrf_dm_on_monitor
1290 CHARACTER*80 :: rstname , outname
1291 INTEGER :: fid , rid
1292 CHARACTER (LEN=256) :: message
1295 !zhang TYPE(ESMF_Time) :: CurrTime
1296 TYPE(WRFU_Time) :: CurrTime
1297 CHARACTER*80 :: timestr
1299 IF ( wrf_dm_on_monitor() ) THEN
1305 !zhang's doing CALL ESMF_ClockGet( grid%domain_clock, CurrTime=CurrTime, rc=ierr )
1306 !zhang's doing CALL wrf_timetoa ( CurrTime, timestr )
1307 CALL domain_clock_get( grid, current_timestr=timestr )
1308 CALL construct_filename2a ( rstname ,config_flags%anl_outname, grid%id , 2 , timestr )
1310 WRITE( message , '("med_analysis_out: opening ",A," for writing")' ) TRIM ( rstname )
1311 CALL wrf_debug( 1 , message )
1312 CALL open_w_dataset ( rid, TRIM(rstname), grid , &
1313 config_flags , output_restart , "DATASET=RESTART", ierr )
1315 IF ( ierr .NE. 0 ) THEN
1316 CALL WRF_message( message )
1318 CALL output_restart ( rid, grid , config_flags , ierr )
1319 IF ( wrf_dm_on_monitor() ) THEN
1320 WRITE ( message , FMT = '("Writing restart for domain ",I8)' ) grid%id
1321 CALL end_timing ( TRIM(message) )
1323 CALL close_dataset ( rid , config_flags , "DATASET=RESTART" )
1325 END SUBROUTINE med_analysis_out
1329 RECURSIVE SUBROUTINE med_restart_out ( grid , config_flags )
1331 USE module_domain , ONLY : domain , domain_clock_get
1332 USE module_io_domain
1334 USE module_configure , ONLY : grid_config_rec_type
1336 ! USE module_bc_time_utilities
1342 TYPE(domain) :: grid
1343 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
1346 LOGICAL, EXTERNAL :: wrf_dm_on_monitor
1347 CHARACTER*80 :: rstname , outname
1348 INTEGER :: fid , rid, kid
1349 CHARACTER (LEN=256) :: message
1352 CHARACTER*80 :: timestr
1353 TYPE (grid_config_rec_type) :: kid_config_flags
1355 IF ( wrf_dm_on_monitor() ) THEN
1359 ! take this out - no effect - LPC
1360 ! rid=grid%id !zhang's doing
1362 ! write out this domains restart file first
1364 CALL domain_clock_get( grid, current_timestr=timestr )
1365 CALL construct_filename2a ( rstname , config_flags%rst_outname , grid%id , 2 , timestr )
1367 WRITE( message , '("med_restart_out: opening ",A," for writing")' ) TRIM ( rstname )
1368 CALL wrf_debug( 1 , message )
1369 CALL open_w_dataset ( rid, TRIM(rstname), grid , &
1370 config_flags , output_restart , "DATASET=RESTART", ierr )
1372 IF ( ierr .NE. 0 ) THEN
1373 CALL WRF_message( message )
1375 CALL output_restart ( rid, grid , config_flags , ierr )
1376 IF ( wrf_dm_on_monitor() ) THEN
1377 WRITE ( message , FMT = '("Writing restart for domain ",I8)' ) grid%id
1378 CALL end_timing ( TRIM(message) )
1380 CALL close_dataset ( rid , config_flags , "DATASET=RESTART" )
1382 ! call recursively for children, (if any)
1383 DO kid = 1, max_nests
1384 IF ( ASSOCIATED( grid%nests(kid)%ptr ) ) THEN
1385 CALL model_to_grid_config_rec ( grid%nests(kid)%ptr%id , model_config_rec , kid_config_flags )
1386 CALL med_restart_out ( grid%nests(kid)%ptr , kid_config_flags )
1391 END SUBROUTINE med_restart_out
1393 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1396 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1398 SUBROUTINE med_restart_in ( grid , config_flags )
1400 USE module_domain , ONLY : domain, domain_clock_get
1401 USE module_io_domain
1404 USE module_configure , ONLY : grid_config_rec_type
1405 USE module_bc_time_utilities
1410 TYPE(domain) :: grid
1411 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
1414 LOGICAL, EXTERNAL :: wrf_dm_on_monitor
1415 CHARACTER*80 :: rstname , outname
1416 INTEGER :: fid , rid
1417 CHARACTER (LEN=256) :: message
1420 !zhang old TYPE(ESMF_Time) :: CurrTime
1421 TYPE(WRFU_Time) :: CurrTime
1422 CHARACTER*80 :: timestr
1424 IF ( wrf_dm_on_monitor() ) THEN
1430 !zhang's doing CALL ESMF_ClockGet( grid%domain_clock, CurrTime=CurrTime, rc=ierr )
1431 !zhang's doing CALL wrf_timetoa ( CurrTime, timestr )
1432 CALL domain_clock_get( grid, current_timestr=timestr )
1433 CALL construct_filename2a ( rstname ,config_flags%rst_outname, grid%id , 2 , timestr )
1435 WRITE( message , '("med_restart_in: opening ",A," for reading")' ) TRIM ( rstname )
1436 CALL wrf_debug( 1 , message )
1437 CALL open_r_dataset ( rid, TRIM(rstname), grid , &
1438 config_flags , "DATASET=RESTART", ierr )
1440 IF ( ierr .NE. 0 ) THEN
1441 ! CALL WRF_message( message )
1442 CALL WRF_ERROR_FATAL('NESTED DOMAIN ERROR: FOR ANALYSIS SET TO TRUE, YOU NEED wrfanal FILE')
1444 CALL input_restart ( rid, grid , config_flags , ierr )
1445 IF ( wrf_dm_on_monitor() ) THEN
1446 WRITE ( message , FMT = '("Reading restart for domain ",I8)' ) grid%id
1447 CALL end_timing ( TRIM(message) )
1449 CALL close_dataset ( rid , config_flags , "DATASET=RESTART" )
1452 END SUBROUTINE med_restart_in
1453 !end of zhang's doing
1456 SUBROUTINE med_hist_out ( grid , stream, config_flags )
1458 USE module_domain , ONLY : domain
1460 USE module_io_domain
1461 USE module_configure , ONLY : grid_config_rec_type
1462 ! USE module_bc_time_utilities
1467 TYPE(domain) :: grid
1468 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
1469 INTEGER , INTENT(IN) :: stream
1471 LOGICAL, EXTERNAL :: wrf_dm_on_monitor
1472 CHARACTER*80 :: fname, n2
1473 CHARACTER (LEN=256) :: message
1476 IF ( wrf_dm_on_monitor() ) THEN
1480 IF ( stream .LT. first_history .OR. stream .GT. last_auxhist ) THEN
1481 WRITE(message,*)'med_hist_out: invalid history stream ',stream
1482 CALL wrf_error_fatal( message )
1485 SELECT CASE( stream )
1486 CASE ( HISTORY_ALARM )
1487 CALL open_hist_w( grid, config_flags, stream, HISTORY_ALARM, &
1488 config_flags%history_outname, grid%oid, &
1489 output_history, fname, n2, ierr )
1490 CALL output_history ( grid%oid, grid , config_flags , ierr )
1492 ! registry-generated selections and calls top open_hist_w for aux streams
1493 #include "med_hist_out_opens.inc"
1497 WRITE(message,*)'med_hist_out: opened ',TRIM(fname),' as ',TRIM(n2)
1498 CALL wrf_debug( 1, message )
1500 grid%nframes(stream) = grid%nframes(stream) + 1
1502 SELECT CASE( stream )
1503 CASE ( HISTORY_ALARM )
1504 IF ( grid%nframes(stream) >= config_flags%frames_per_outfile ) THEN
1505 CALL close_dataset ( grid%oid , config_flags , n2 )
1507 grid%nframes(stream) = 0
1509 ! registry-generated selections and calls top close_dataset for aux streams
1510 #include "med_hist_out_closes.inc"
1513 IF ( wrf_dm_on_monitor() ) THEN
1514 WRITE ( message , FMT = '("Writing ",A30," for domain ",I8)' )TRIM(fname),grid%id
1515 CALL end_timing ( TRIM(message) )
1519 END SUBROUTINE med_hist_out
1522 SUBROUTINE med_fddaobs_in ( grid , config_flags )
1523 USE module_domain , ONLY : domain
1524 USE module_configure , ONLY : grid_config_rec_type
1526 TYPE(domain) :: grid
1527 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
1528 CALL wrf_fddaobs_in( grid, config_flags )
1530 END SUBROUTINE med_fddaobs_in
1533 SUBROUTINE med_auxinput_in ( grid , stream, config_flags )
1535 USE module_domain , ONLY : domain
1536 USE module_io_domain
1538 USE module_configure , ONLY : grid_config_rec_type
1539 ! USE module_bc_time_utilities
1544 TYPE(domain) :: grid
1545 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
1546 INTEGER , INTENT(IN) :: stream
1548 CHARACTER (LEN=256) :: message
1551 IF ( stream .LT. first_auxinput .OR. stream .GT. last_auxinput ) THEN
1552 WRITE(message,*)'med_auxinput_in: invalid input stream ',stream
1553 CALL wrf_error_fatal( message )
1556 grid%nframes(stream) = grid%nframes(stream) + 1
1558 SELECT CASE( stream )
1559 ! registry-generated file of calls to open filename
1560 ! CASE ( AUXINPUT1_ALARM )
1561 ! CALL open_aux_u( grid, config_flags, stream, AUXINPUT1_ALARM, &
1562 ! config_flags%auxinput1_inname, grid%auxinput1_oid, &
1563 ! input_auxinput1, ierr )
1564 ! CALL input_auxinput1 ( grid%auxinput1_oid, grid , config_flags , ierr )
1565 #include "med_auxinput_in.inc"
1568 SELECT CASE( stream )
1569 ! registry-generated selections and calls top close_dataset for aux streams
1570 #include "med_auxinput_in_closes.inc"
1574 END SUBROUTINE med_auxinput_in
1576 SUBROUTINE med_filter_out ( grid , config_flags )
1578 USE module_domain , ONLY : domain , domain_clock_get
1579 USE module_io_domain
1581 USE module_configure , ONLY : grid_config_rec_type
1583 USE module_bc_time_utilities
1588 TYPE(domain) :: grid
1589 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
1591 LOGICAL, EXTERNAL :: wrf_dm_on_monitor
1592 CHARACTER*80 :: rstname , outname
1593 INTEGER :: fid , rid
1594 CHARACTER (LEN=256) :: message
1597 CHARACTER*80 :: timestr
1599 IF ( config_flags%write_input ) THEN
1601 IF ( wrf_dm_on_monitor() ) THEN
1605 CALL domain_clock_get( grid, current_timestr=timestr )
1606 CALL construct_filename2a ( outname , config_flags%input_outname , grid%id , 2 , timestr )
1608 WRITE ( message , '("med_filter_out 1: opening ",A," for writing. ")') TRIM ( outname )
1609 CALL wrf_debug( 1, message )
1611 CALL open_w_dataset ( fid, TRIM(outname), grid , &
1612 config_flags , output_input , "DATASET=INPUT", ierr )
1613 IF ( ierr .NE. 0 ) THEN
1614 CALL wrf_error_fatal( message )
1617 IF ( ierr .NE. 0 ) THEN
1618 CALL wrf_error_fatal( message )
1621 CALL output_input ( fid, grid , config_flags , ierr )
1622 CALL close_dataset ( fid , config_flags , "DATASET=INPUT" )
1624 IF ( wrf_dm_on_monitor() ) THEN
1625 WRITE ( message , FMT = '("Writing filter output for domain ",I8)' ) grid%id
1626 CALL end_timing ( TRIM(message) )
1631 END SUBROUTINE med_filter_out
1633 SUBROUTINE med_latbound_in ( grid , config_flags )
1635 USE module_domain , ONLY : domain , domain_clock_get, head_grid
1636 USE module_io_domain
1638 USE module_configure , ONLY : grid_config_rec_type
1640 ! USE module_bc_time_utilities
1645 #include <wrf_status_codes.h>
1648 TYPE(domain) :: grid
1649 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
1652 LOGICAL, EXTERNAL :: wrf_dm_on_monitor
1653 LOGICAL :: lbc_opened
1654 INTEGER :: idum1 , idum2 , ierr , open_status , fid, rc
1656 CHARACTER (LEN=256) :: message
1657 CHARACTER (LEN=80) :: bdyname
1658 Type (WRFU_Time ) :: startTime, stopTime, currentTime
1659 Type (WRFU_TimeInterval ) :: stepTime
1660 integer myproc,i,j,k
1662 #include <wrf_io_flags.h>
1664 CALL wrf_debug ( 200 , 'in med_latbound_in' )
1666 ! #if (EM_CORE == 1)
1667 ! Avoid trying to re-read the boundary conditions if we are doing DFI integration
1668 ! and do not expect to find boundary conditions for the current time
1669 IF ( (grid%dfi_opt .EQ. DFI_DDFI .OR. grid%dfi_opt .EQ. DFI_TDFI) .AND. grid%dfi_stage .EQ. DFI_FWD ) RETURN
1672 IF ( grid%id .EQ. 1 .AND. config_flags%specified .AND. config_flags%io_form_boundary .GT. 0 ) THEN
1674 CALL domain_clock_get( grid, current_time=currentTime, &
1675 start_time=startTime, &
1676 stop_time=stopTime, &
1677 time_step=stepTime )
1680 !jm The test below never worked because set_time_time_read_again is never called to store a
1681 !jm time that lbc_read_time can compare with currentTime (see module_bc_time_utilities). This means
1682 !jm lbc_read_time will never return anything but false -- will also generate an ESMF error that the
1683 !jm stored time was never initialized. Removing that branch from the conditional.
1684 !jm IF ( ( lbc_read_time( currentTime ) ) .AND. &
1685 !jm ( currentTime + stepTime .GE. stopTime ) .AND. &
1686 !jm ( currentTime .NE. startTime ) ) THEN
1687 !jm CALL wrf_debug( 100 , 'med_latbound_in: Skipping attempt to read lateral boundary file during last time step ' )
1689 !jm ELSE IF ( WRFU_AlarmIsRinging( grid%alarms( BOUNDARY_ALARM ), rc=rc ) ) THEN
1691 IF ( WRFU_AlarmIsRinging( grid%alarms( BOUNDARY_ALARM ), rc=rc ) ) THEN
1692 CALL wrf_debug ( 100 , 'in med_latbound_in preparing to read' )
1693 CALL WRFU_AlarmRingerOff( grid%alarms( BOUNDARY_ALARM ), rc=rc )
1694 IF ( wrf_dm_on_monitor() ) CALL start_timing
1696 ! typically a <date> wouldn't be part of the bdy_inname, so just pass a dummy
1697 CALL construct_filename2a ( bdyname , config_flags%bdy_inname , grid%id , 2 , 'dummydate' )
1699 CALL wrf_inquire_opened(grid%lbc_fid , TRIM(bdyname) , open_status , ierr )
1700 IF ( open_status .EQ. WRF_FILE_OPENED_FOR_READ ) THEN
1703 lbc_opened = .FALSE.
1705 CALL wrf_dm_bcast_bytes ( lbc_opened , LWORDSIZE )
1706 IF ( .NOT. lbc_opened ) THEN
1707 CALL construct_filename1 ( bdyname , 'wrfbdy' , grid%id , 2 )
1708 WRITE(message,*)'Opening: ',TRIM(bdyname)
1709 CALL wrf_debug(100,TRIM(message))
1710 CALL open_r_dataset ( grid%lbc_fid, TRIM(bdyname) , grid , config_flags , "DATASET=BOUNDARY", ierr )
1711 IF ( ierr .NE. 0 ) THEN
1712 WRITE( message, * ) 'med_latbound_in: error opening ',TRIM(bdyname), ' for reading. IERR = ',ierr
1713 CALL WRF_ERROR_FATAL( message )
1716 CALL wrf_debug( 100 , bdyname // 'already opened' )
1718 CALL wrf_debug( 100 , 'med_latbound_in: calling input_boundary ' )
1719 CALL input_boundary ( grid%lbc_fid, grid , config_flags , ierr )
1721 ! #if (EM_CORE == 1)
1722 IF ( (config_flags%dfi_opt .NE. DFI_NODFI) .AND. (head_grid%dfi_stage .NE. DFI_FST) ) THEN
1723 CALL wrf_debug( 100 , 'med_latbound_in: closing boundary file ' )
1724 CALL close_dataset ( grid%lbc_fid , config_flags , "DATASET=BOUNDARY" )
1728 CALL domain_clock_get( grid, current_time=currentTime )
1729 DO WHILE (currentTime .GE. grid%next_bdy_time ) ! next_bdy_time is set by input_boundary from bdy file
1730 CALL wrf_debug( 100 , 'med_latbound_in: calling input_boundary ' )
1731 CALL input_boundary ( grid%lbc_fid, grid , config_flags , ierr )
1733 CALL WRFU_AlarmSet( grid%alarms( BOUNDARY_ALARM ), RingTime=grid%next_bdy_time, rc=rc )
1735 IF ( ierr .NE. 0 .and. ierr .NE. WRF_WARN_NETCDF ) THEN
1736 WRITE( message, * ) 'med_latbound_in: error reading ',TRIM(bdyname), ' IERR = ',ierr
1737 CALL WRF_ERROR_FATAL( message )
1739 IF ( currentTime .EQ. grid%this_bdy_time ) grid%dtbc = 0.
1741 IF ( wrf_dm_on_monitor() ) THEN
1742 WRITE ( message , FMT = '("processing lateral boundary for domain ",I8)' ) grid%id
1743 CALL end_timing ( TRIM(message) )
1748 END SUBROUTINE med_latbound_in
1750 SUBROUTINE med_setup_step ( grid , config_flags )
1752 USE module_domain , ONLY : domain
1753 USE module_configure , ONLY : grid_config_rec_type
1759 !The driver layer routine integrate() calls this mediation layer routine
1760 !prior to initiating a time step on the domain specified by the argument
1761 !grid. This provides the model-layer contributor an opportunity to make
1762 !any pre-time-step initializations that pertain to a particular model
1763 !domain. In WRF, this routine is used to call
1764 !set_scalar_indices_from_config for the specified domain.
1769 TYPE(domain) :: grid
1770 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
1772 INTEGER :: idum1 , idum2
1774 CALL set_scalar_indices_from_config ( grid%id , idum1 , idum2 )
1778 END SUBROUTINE med_setup_step
1780 SUBROUTINE med_endup_step ( grid , config_flags )
1782 USE module_domain , ONLY : domain
1783 USE module_configure , ONLY : grid_config_rec_type, model_config_rec
1789 !The driver layer routine integrate() calls this mediation layer routine
1790 !prior to initiating a time step on the domain specified by the argument
1791 !grid. This provides the model-layer contributor an opportunity to make
1792 !any pre-time-step initializations that pertain to a particular model
1793 !domain. In WRF, this routine is used to call
1794 !set_scalar_indices_from_config for the specified domain.
1799 TYPE(domain) :: grid
1800 TYPE (grid_config_rec_type) , INTENT(OUT) :: config_flags
1802 INTEGER :: idum1 , idum2
1804 IF ( grid%id .EQ. 1 ) THEN
1805 ! turn off the restart flag after the first mother-domain step is finished
1806 model_config_rec%restart = .FALSE.
1807 config_flags%restart = .FALSE.
1808 CALL nl_set_restart(1, .FALSE.)
1814 END SUBROUTINE med_endup_step
1816 SUBROUTINE open_aux_u ( grid , config_flags, stream, alarm_id, &
1817 auxinput_inname, oid, insub, ierr )
1819 USE module_domain , ONLY : domain , domain_clock_get
1820 USE module_io_domain
1822 USE module_configure , ONLY : grid_config_rec_type
1823 ! USE module_bc_time_utilities
1828 TYPE(domain) :: grid
1829 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
1830 INTEGER , INTENT(IN) :: stream
1831 INTEGER , INTENT(IN) :: alarm_id
1832 CHARACTER*(*) , INTENT(IN) :: auxinput_inname
1833 INTEGER , INTENT(INOUT) :: oid
1835 INTEGER , INTENT(OUT) :: ierr
1837 CHARACTER*80 :: fname, n2
1838 CHARACTER (LEN=256) :: message
1839 CHARACTER*80 :: timestr
1840 TYPE(WRFU_Time) :: ST,CT
1843 IF ( stream .LT. first_stream .OR. stream .GT. last_stream ) THEN
1844 WRITE(message,*)'open_aux_u: invalid input stream ',stream
1845 CALL wrf_error_fatal( message )
1850 IF ( oid .eq. 0 ) THEN
1851 CALL domain_clock_get( grid, current_time=CT, start_time=ST, &
1852 current_timestr=timestr )
1853 CALL nl_get_adjust_input_times( grid%id, adjust )
1855 CALL adjust_io_timestr( grid%io_intervals( alarm_id ), CT, ST, timestr )
1857 CALL construct_filename2a ( fname , auxinput_inname, &
1858 grid%id , 2 , timestr )
1859 IF ( stream-first_input .EQ. 10 ) THEN
1860 WRITE(n2,'("DATASET=AUXINPUT10")')
1861 ELSE IF ( stream-first_input .EQ. 11 ) THEN
1862 WRITE(n2,'("DATASET=AUXINPUT11")')
1863 ELSE IF ( stream-first_input .GE. 10 ) THEN
1864 WRITE(n2,'("DATASET=AUXINPUT",I2)')stream-first_input
1866 WRITE(n2,'("DATASET=AUXINPUT",I1)')stream-first_input
1868 WRITE ( message , '("open_aux_u : opening ",A," for reading. DATASET ",A)') TRIM ( fname ),TRIM(n2)
1869 CALL wrf_debug( 1, message )
1872 !Open_u_dataset is called rather than open_r_dataset to allow interfaces
1873 !that can do blending or masking to update an existing field. (MCEL IO does this).
1874 !No effect for other interfaces; open_u_dataset is equivalent to open_r_dataset
1878 CALL open_u_dataset ( oid, TRIM(fname), grid , &
1879 config_flags , insub , n2, ierr )
1881 IF ( ierr .NE. 0 ) THEN
1882 WRITE ( message , '("open_aux_u : error opening ",A," for reading. ",I3)') &
1883 TRIM ( fname ), ierr
1884 CALL wrf_message( message )
1887 END SUBROUTINE open_aux_u
1889 SUBROUTINE open_hist_w ( grid , config_flags, stream, alarm_id, &
1890 hist_outname, oid, outsub, fname, n2, ierr )
1892 USE module_domain , ONLY : domain , domain_clock_get
1893 USE module_io_domain
1895 USE module_configure , ONLY : grid_config_rec_type
1896 ! USE module_bc_time_utilities
1901 TYPE(domain) :: grid
1902 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
1903 INTEGER , INTENT(IN) :: stream
1904 INTEGER , INTENT(IN) :: alarm_id
1905 CHARACTER*(*) , INTENT(IN) :: hist_outname
1906 INTEGER , INTENT(INOUT) :: oid
1908 CHARACTER*(*) , INTENT(OUT) :: fname, n2
1909 INTEGER , INTENT(OUT) :: ierr
1912 CHARACTER (LEN=256) :: message
1913 CHARACTER*80 :: timestr
1914 TYPE(WRFU_Time) :: ST,CT
1917 IF ( stream .LT. first_history .OR. stream .GT. last_history ) THEN
1918 WRITE(message,*)'open_hist_w: invalid history stream ',stream
1919 CALL wrf_error_fatal( message )
1924 ! Note that computation of fname and n2 are outside of the oid IF statement
1925 ! since they are OUT args and may be used by callers even if oid/=0.
1926 CALL domain_clock_get( grid, current_time=CT, start_time=ST, &
1927 current_timestr=timestr )
1928 CALL nl_get_adjust_output_times( grid%id, adjust )
1930 CALL adjust_io_timestr( grid%io_intervals( alarm_id ), CT, ST, timestr )
1932 CALL construct_filename2a ( fname , hist_outname, &
1933 grid%id , 2 , timestr )
1934 IF ( stream-first_history .EQ. history_only ) THEN
1935 WRITE(n2,'("DATASET=HISTORY")')
1936 ELSE IF ( stream-first_history .GE. 10 ) THEN
1937 WRITE(n2,'("DATASET=AUXHIST",I2)')stream-first_history
1939 WRITE(n2,'("DATASET=AUXHIST",I1)')stream-first_history
1941 IF ( oid .eq. 0 ) THEN
1942 WRITE ( message , '("open_hist_w : opening ",A," for writing. ")') TRIM ( fname )
1943 CALL wrf_debug( 1, message )
1946 !Open_u_dataset is called rather than open_r_dataset to allow interfaces
1947 !that can do blending or masking to update an existing field. (MCEL IO does this).
1948 !No effect for other interfaces; open_u_dataset is equivalent to open_r_dataset
1952 CALL open_w_dataset ( oid, TRIM(fname), grid , &
1953 config_flags , outsub , n2, ierr )
1955 IF ( ierr .NE. 0 ) THEN
1956 WRITE ( message , '("open_hist_w : error opening ",A," for writing. ",I3)') &
1957 TRIM ( fname ), ierr
1958 CALL wrf_message( message )
1961 END SUBROUTINE open_hist_w
1964 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1968 SUBROUTINE med_read_wrf_chem_input ( grid , config_flags )
1970 USE module_domain , ONLY : domain , domain_clock_get
1971 USE module_io_domain
1973 USE module_configure , ONLY : grid_config_rec_type
1975 USE module_bc_time_utilities
1979 USE module_date_time
1985 TYPE(domain) :: grid
1987 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
1990 LOGICAL, EXTERNAL :: wrf_dm_on_monitor
1992 INTEGER :: ierr, efid
1993 REAL :: time, tupdate
1994 real, allocatable :: dumc0(:,:,:)
1995 CHARACTER (LEN=256) :: message, current_date_char, date_string
1996 CHARACTER (LEN=80) :: inpname
1998 #include <wrf_io_flags.h>
1999 ! IF ( grid%id .EQ. 1 ) THEN
2001 CALL domain_clock_get( grid, current_timestr=current_date_char )
2003 CALL construct_filename1 ( inpname , config_flags%auxinput12_inname , grid%id , 2 )
2004 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_input: Open file ',TRIM(inpname)
2005 CALL wrf_message( TRIM(message) )
2007 if( grid%auxinput12_oid .NE. 0 ) then
2008 CALL close_dataset ( grid%auxinput12_oid , config_flags , "DATASET=AUXINPUT12" )
2011 CALL open_r_dataset ( grid%auxinput12_oid, TRIM(inpname) , grid , config_flags, &
2012 "DATASET=AUXINPUT12", ierr )
2013 IF ( ierr .NE. 0 ) THEN
2014 WRITE( message , * ) 'med_read_wrf_chem_input error opening ', TRIM( inpname )
2015 CALL wrf_error_fatal( TRIM( message ) )
2018 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_input: Read chemistry from wrfout at time ',&
2019 TRIM(current_date_char)
2020 CALL wrf_message( TRIM(message) )
2022 CALL wrf_debug (100 , 'mediation_integrate: calling input_auxinput12' )
2023 CALL input_auxinput12 ( grid%auxinput12_oid, grid , config_flags , ierr )
2025 CALL close_dataset ( grid%auxinput12_oid , config_flags , "DATASET=AUXINPUT12" )
2028 CALL wrf_debug (100 , 'mediation_integrate: med_read_wrf_chem_input: exit' )
2030 END SUBROUTINE med_read_wrf_chem_input
2031 !------------------------------------------------------------------------
2032 ! Chemistry emissions input control. Three options are available and are
2033 ! set via the namelist variable io_style_emissions:
2035 ! 0 = Emissions are not read in from a file. They will contain their
2036 ! default values, which can be set in the Registry.
2037 ! (Intended for debugging of chem code)
2039 ! 1 = Emissions are read in from two 12 hour files that are cycled.
2040 ! With this choice, auxinput5_inname should be set to
2041 ! the value "wrfchemi_hhZ_d<domain>".
2043 ! 2 = Emissions are read in from files identified by date and that have
2044 ! a length defined by frames_per_auxinput5. Both
2045 ! auxinput5_inname should be set to
2046 ! "wrfchemi_d<domain>_<date>".
2047 !------------------------------------------------------------------------
2048 SUBROUTINE med_read_wrf_chem_emiss ( grid , config_flags )
2050 USE module_domain , ONLY : domain , domain_clock_get
2051 USE module_io_domain
2053 USE module_configure , ONLY : grid_config_rec_type
2055 USE module_bc_time_utilities
2059 USE module_date_time
2065 TYPE(domain) :: grid
2067 ! TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
2068 TYPE (grid_config_rec_type) :: config_flags
2069 Type (WRFU_Time ) :: stopTime, currentTime
2070 Type (WRFU_TimeInterval ) :: stepTime
2073 LOGICAL, EXTERNAL :: wrf_dm_on_monitor
2075 INTEGER :: ierr, efid
2076 INTEGER :: ihr, ihrdiff, i
2077 REAL :: time, tupdate
2078 real, allocatable :: dumc0(:,:,:)
2079 CHARACTER (LEN=256) :: message, current_date_char, date_string
2080 CHARACTER (LEN=80) :: inpname
2082 #include <wrf_io_flags.h>
2084 CALL model_to_grid_config_rec ( grid%id , model_config_rec , config_flags )
2086 ! This "if" should be commented out when using emission files for nested
2087 ! domains. Also comment out the "ENDIF" line noted below.
2088 ! IF ( grid%id .EQ. 1 ) THEN
2090 CALL domain_clock_get( grid, current_time=currentTime, &
2091 current_timestr=current_date_char, &
2092 stop_time=stopTime, &
2093 time_step=stepTime )
2095 time = float(grid%itimestep) * grid%dt
2098 ! io_style_emissions option 0: no emissions read in...
2100 if( config_flags%io_style_emissions == 0 ) then
2103 ! io_style_emissions option 1: cycle through two 12 hour input files...
2105 else if( config_flags%io_style_emissions == 1 ) then
2107 tupdate = mod( time, (12. * 3600.) )
2108 read(current_date_char(12:13),'(I2)') ihr
2112 IF( tupdate .LT. grid%dt ) THEN
2115 IF( ihr .EQ. 00 .OR. ihr .EQ. 12 ) THEN
2119 IF( currentTime + stepTime .GE. stopTime .AND. &
2120 grid%auxinput5_oid .NE. 0 ) THEN
2121 CALL close_dataset ( grid%auxinput5_oid , config_flags , "DATASET=AUXINPUT5" )
2125 ! write(message,FMT='(A,F10.1,A)') ' EMISSIONS UPDATE TIME ',time,TRIM(current_date_char(12:13))
2126 ! CALL wrf_message( TRIM(message) )
2128 IF ( tupdate .EQ. 0. .AND. ihr .LT. 12 ) THEN
2130 CALL construct_filename1 ( inpname , 'wrfchemi_00z' , grid%id , 2 )
2131 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_emissions: Open file ',TRIM(inpname)
2132 CALL wrf_message( TRIM(message) )
2134 if( grid%auxinput5_oid .NE. 0 ) then
2135 CALL close_dataset ( grid%auxinput5_oid , config_flags , "DATASET=AUXINPUT5" )
2138 CALL open_r_dataset ( grid%auxinput5_oid, TRIM(inpname) , grid , config_flags, &
2139 "DATASET=AUXINPUT5", ierr )
2140 IF ( ierr .NE. 0 ) THEN
2141 WRITE( message , * ) 'med_read_wrf_chem_emissions: error opening ', TRIM( inpname )
2142 CALL wrf_error_fatal( TRIM( message ) )
2145 ELSE IF ( tupdate .EQ. 0. .AND. ihr .GE. 12 ) THEN
2148 CALL construct_filename1 ( inpname , 'wrfchemi_12z' , grid%id , 2 )
2149 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_emissions: Open file ',TRIM(inpname)
2150 CALL wrf_message( TRIM(message) )
2152 if( grid%auxinput5_oid .NE. 0 ) then
2153 CALL close_dataset ( grid%auxinput5_oid , config_flags , "DATASET=AUXINPUT5" )
2156 CALL open_r_dataset ( grid%auxinput5_oid, TRIM(inpname) , grid , config_flags, &
2157 "DATASET=AUXINPUT5", ierr )
2158 IF ( ierr .NE. 0 ) THEN
2159 WRITE( message , * ) 'med_read_wrf_chem_emissions: error opening ', TRIM( inpname )
2160 CALL wrf_error_fatal( TRIM( message ) )
2164 WRITE( message, '(A,2F10.1)' ) ' HOURLY EMISSIONS UPDATE TIME ',time,mod(time,3600.)
2165 CALL wrf_message( TRIM(message) )
2167 ! hourly updates to emissions
2168 IF ( ( mod( time, 3600. ) .LT. grid%dt ) .AND. &
2169 ( currentTime + stepTime .LT. stopTime ) ) THEN
2170 ! IF ( wrf_dm_on_monitor() ) CALL start_timing
2172 WRITE(message,'(A,A)')'mediation_integrate: med_read_wrf_chem_emissions: Read emissions for time ',TRIM(current_date_char)
2173 CALL wrf_message( TRIM(message) )
2175 IF ( tupdate .EQ. 0. .AND. ihrdiff .GT. 0) THEN
2176 IF( ihrdiff .GT. 12) THEN
2177 WRITE(message,'(A)')'mediation_integrate: med_read_wrf_chem_emissions: Error in emissions time, skipping all times in file '
2178 CALL wrf_message( TRIM(message) )
2181 WRITE(message,'(A,I4)')'mediation_integrate: med_read_wrf_chem_emissions: Skip emissions ',i
2182 CALL wrf_message( TRIM(message) )
2183 CALL input_auxinput5 ( grid%auxinput5_oid, grid , config_flags , ierr )
2187 CALL wrf_debug (100 , 'mediation_integrate: calling input_auxinput5' )
2188 CALL input_auxinput5 ( grid%auxinput5_oid, grid , config_flags , ierr )
2190 CALL wrf_debug (100 , 'mediation_integrate: med_read_wrf_chem_emissions: Do not read emissions' )
2194 ! io_style_emissions option 2: use dated emission files whose length is
2195 ! set via frames_per_auxinput5...
2197 else if( config_flags%io_style_emissions == 2 ) then
2198 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_emissions: Read emissions for time ',TRIM(current_date_char)
2199 CALL wrf_message( TRIM(message) )
2201 ! Code to read hourly emission files...
2203 if( grid%auxinput5_oid == 0 ) then
2204 CALL construct_filename2a(inpname , grid%emi_inname, grid%id , 2, current_date_char)
2205 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_emissions: Open file ',TRIM(inpname)
2206 CALL wrf_message( TRIM(message) )
2207 CALL open_r_dataset ( grid%auxinput5_oid, TRIM(inpname) , grid , config_flags, &
2208 "DATASET=AUXINPUT5", ierr )
2209 IF ( ierr .NE. 0 ) THEN
2210 WRITE( message , * ) 'med_read_wrf_chem_emissions: error opening ', TRIM( inpname )
2211 CALL wrf_error_fatal( TRIM( message ) )
2215 ! Read the emissions data.
2217 CALL wrf_debug (100 , 'mediation_integrate: calling input_auxinput5' )
2218 CALL input_auxinput5 ( grid%auxinput5_oid, grid , config_flags , ierr )
2220 ! If reached the indicated number of frames in the emissions file, close it.
2222 grid%emissframes = grid%emissframes + 1
2223 IF ( grid%emissframes >= config_flags%frames_per_auxinput5 ) THEN
2224 CALL close_dataset ( grid%auxinput5_oid , config_flags , "DATASET=AUXINPUT5" )
2225 grid%emissframes = 0
2226 grid%auxinput5_oid = 0
2230 ! unknown io_style_emissions option...
2233 call wrf_error_fatal("Unknown emission style selected via io_style_emissions.")
2236 ! The following line should be commented out when using emission files
2237 ! for nested domains. Also comment out the "if" noted above.
2240 CALL wrf_debug (100 , 'mediation_integrate: med_read_wrf_chem_emissions: exit' )
2242 END SUBROUTINE med_read_wrf_chem_emiss
2244 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2245 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2247 SUBROUTINE med_read_wrf_chem_bioemiss ( grid , config_flags )
2249 USE module_domain , ONLY : domain , domain_clock_get
2250 USE module_io_domain
2252 USE module_configure , ONLY : grid_config_rec_type
2254 USE module_bc_time_utilities
2258 USE module_date_time
2264 TYPE(domain) :: grid
2266 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
2269 LOGICAL, EXTERNAL :: wrf_dm_on_monitor
2271 INTEGER :: ierr, efid
2272 REAL :: time, tupdate
2273 real, allocatable :: dumc0(:,:,:)
2274 CHARACTER (LEN=256) :: message, current_date_char, date_string
2275 CHARACTER (LEN=80) :: inpname
2277 #include <wrf_io_flags.h>
2278 ! IF ( grid%id .EQ. 1 ) THEN
2280 CALL domain_clock_get( grid, current_timestr=current_date_char )
2282 CALL construct_filename1 ( inpname , 'wrfbiochemi' , grid%id , 2 )
2283 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_bioemissions: Open file ',TRIM(inpname)
2284 CALL wrf_message( TRIM(message) )
2286 if( grid%auxinput6_oid .NE. 0 ) then
2287 CALL close_dataset ( grid%auxinput6_oid , config_flags , "DATASET=AUXINPUT6" )
2290 CALL open_r_dataset ( grid%auxinput6_oid, TRIM(inpname) , grid , config_flags, &
2291 "DATASET=AUXINPUT6", ierr )
2292 IF ( ierr .NE. 0 ) THEN
2293 WRITE( message , * ) 'med_read_wrf_chem_bioemissions: error opening ', TRIM( inpname )
2294 CALL wrf_error_fatal( TRIM( message ) )
2297 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_bioemissions: Read biogenic emissions at time ',&
2298 TRIM(current_date_char)
2299 CALL wrf_message( TRIM(message) )
2301 CALL wrf_debug (100 , 'mediation_integrate: calling input_auxinput6' )
2302 CALL input_auxinput6 ( grid%auxinput6_oid, grid , config_flags , ierr )
2304 CALL close_dataset ( grid%auxinput6_oid , config_flags , "DATASET=AUXINPUT6" )
2307 CALL wrf_debug (100 , 'mediation_integrate: med_read_wrf_chem_bioemissions: exit' )
2309 END SUBROUTINE med_read_wrf_chem_bioemiss
2310 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2311 SUBROUTINE med_read_wrf_chem_emissopt4 ( grid , config_flags )
2313 USE module_domain , ONLY : domain , domain_clock_get
2314 USE module_io_domain
2316 USE module_configure , ONLY : grid_config_rec_type
2318 USE module_bc_time_utilities
2322 USE module_date_time
2328 TYPE(domain) :: grid
2330 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
2333 LOGICAL, EXTERNAL :: wrf_dm_on_monitor
2335 INTEGER :: ierr, efid
2336 REAL :: time, tupdate
2337 real, allocatable :: dumc0(:,:,:)
2338 CHARACTER (LEN=256) :: message, current_date_char, date_string
2339 CHARACTER (LEN=80) :: inpname
2341 #include <wrf_io_flags.h>
2342 ! IF ( grid%id .EQ. 1 ) THEN
2344 CALL domain_clock_get( grid, current_timestr=current_date_char )
2346 CALL construct_filename1 ( inpname , 'wrfchemi' , grid%id , 2 )
2347 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_emissions: Open file ',TRIM(inpname)
2348 CALL wrf_message( TRIM(message) )
2350 if( grid%auxinput5_oid .NE. 0 ) then
2351 CALL close_dataset ( grid%auxinput5_oid , config_flags , "DATASET=AUXINPUT5" )
2354 CALL open_r_dataset ( grid%auxinput5_oid, TRIM(inpname) , grid , config_flags, &
2355 "DATASET=AUXINPUT5", ierr )
2356 IF ( ierr .NE. 0 ) THEN
2357 WRITE( message , * ) 'med_read_wrf_chem_emissions: error opening ', TRIM( inpname )
2358 CALL wrf_error_fatal( TRIM( message ) )
2361 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_emissions: Read biogenic emissions at time ',&
2362 TRIM(current_date_char)
2363 CALL wrf_message( TRIM(message) )
2365 CALL wrf_debug (100 , 'mediation_integrate: calling input_auxinput5' )
2366 CALL input_auxinput5 ( grid%auxinput5_oid, grid , config_flags , ierr )
2368 CALL close_dataset ( grid%auxinput5_oid , config_flags , "DATASET=AUXINPUT5" )
2371 CALL wrf_debug (100 , 'mediation_integrate: med_read_wrf_chem_emissions: exit' )
2373 END SUBROUTINE med_read_wrf_chem_emissopt4
2375 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2376 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2378 SUBROUTINE med_read_wrf_chem_dms_emiss ( grid , config_flags )
2380 USE module_domain , ONLY : domain , domain_clock_get
2381 USE module_io_domain
2383 USE module_configure , ONLY : grid_config_rec_type
2385 USE module_bc_time_utilities
2389 USE module_date_time
2395 TYPE(domain) :: grid
2397 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
2400 LOGICAL, EXTERNAL :: wrf_dm_on_monitor
2402 INTEGER :: ierr, efid
2403 REAL :: time, tupdate
2404 real, allocatable :: dumc0(:,:,:)
2405 CHARACTER (LEN=256) :: message, current_date_char, date_string
2406 CHARACTER (LEN=80) :: inpname
2408 #include <wrf_io_flags.h>
2409 ! IF ( grid%id .EQ. 1 ) THEN
2411 CALL domain_clock_get( grid, current_timestr=current_date_char )
2413 CALL construct_filename1 ( inpname , 'wrfchemi_dms' , grid%id , 2 )
2414 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_dms_emiss: Open file ',TRIM(inpname)
2415 CALL wrf_message( TRIM(message) )
2417 if( grid%auxinput7_oid .NE. 0 ) then
2418 CALL close_dataset ( grid%auxinput7_oid , config_flags , "DATASET=AUXINPUT7" )
2421 CALL open_r_dataset ( grid%auxinput7_oid, TRIM(inpname) , grid , config_flags, &
2422 "DATASET=AUXINPUT7", ierr )
2423 IF ( ierr .NE. 0 ) THEN
2424 WRITE( message , * ) 'med_read_wrf_chem_dms_emiss: error opening ', TRIM( inpname )
2425 CALL wrf_error_fatal( TRIM( message ) )
2428 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_dms_emiss: Read dms reference fields',&
2429 TRIM(current_date_char)
2430 CALL wrf_message( TRIM(message) )
2432 CALL wrf_debug (100 , 'mediation_integrate: calling input_auxinput7' )
2433 CALL input_auxinput7 ( grid%auxinput7_oid, grid , config_flags , ierr )
2435 CALL close_dataset ( grid%auxinput7_oid , config_flags , "DATASET=AUXINPUT7" )
2438 CALL wrf_debug (100 , 'mediation_integrate: med_read_wrf_chem_dms_emiss: exit' )
2440 END SUBROUTINE med_read_wrf_chem_dms_emiss
2442 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2443 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2445 SUBROUTINE med_read_wrf_chem_gocart_bg ( grid , config_flags )
2447 USE module_domain , ONLY : domain , domain_clock_get
2448 USE module_io_domain
2450 USE module_configure , ONLY : grid_config_rec_type
2452 USE module_bc_time_utilities
2456 USE module_date_time
2462 TYPE(domain) :: grid
2464 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
2467 LOGICAL, EXTERNAL :: wrf_dm_on_monitor
2469 INTEGER :: ierr, efid
2470 REAL :: time, tupdate
2471 real, allocatable :: dumc0(:,:,:)
2472 CHARACTER (LEN=256) :: message, current_date_char, date_string
2473 CHARACTER (LEN=80) :: inpname
2475 #include <wrf_io_flags.h>
2476 ! IF ( grid%id .EQ. 1 ) THEN
2478 CALL domain_clock_get( grid, current_timestr=current_date_char )
2480 CALL construct_filename1 ( inpname , 'wrfchemi_gocart_bg' , grid%id , 2 )
2481 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_gocart_bg: Open file ',TRIM(inpname)
2482 CALL wrf_message( TRIM(message) )
2484 if( grid%auxinput8_oid .NE. 0 ) then
2485 CALL close_dataset ( grid%auxinput8_oid , config_flags , "DATASET=AUXINPUT8" )
2488 CALL open_r_dataset ( grid%auxinput8_oid, TRIM(inpname) , grid , config_flags, &
2489 "DATASET=AUXINPUT8", ierr )
2490 IF ( ierr .NE. 0 ) THEN
2491 WRITE( message , * ) 'med_read_wrf_chem_gocart_bg: error opening ', TRIM( inpname )
2492 CALL wrf_error_fatal( TRIM( message ) )
2495 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_gocart_bg: Read gocart_bg at time ',&
2496 TRIM(current_date_char)
2497 CALL wrf_message( TRIM(message) )
2499 CALL wrf_debug (100 , 'mediation_integrate: calling input_auxinput8' )
2500 CALL input_auxinput8 ( grid%auxinput8_oid, grid , config_flags , ierr )
2502 CALL close_dataset ( grid%auxinput8_oid , config_flags , "DATASET=AUXINPUT8" )
2505 ! CALL wrf_global_to_patch_real ( backg_no3_io , grid%backg_no3 , grid%domdesc, ' ' , 'xyz' , &
2506 ! ids, ide-1 , jds , jde-1 , kds , kde-1, &
2507 ! ims, ime , jms , jme , kms , kme , &
2508 ! ips, ipe , jps , jpe , kps , kpe )
2511 CALL wrf_debug (100 , 'mediation_integrate: med_read_wrf_chem_gocart_bg: exit' )
2513 END SUBROUTINE med_read_wrf_chem_gocart_bg
2514 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2516 SUBROUTINE med_read_wrf_volc_emiss ( grid , config_flags )
2518 USE module_domain , ONLY : domain , domain_clock_get
2519 USE module_io_domain
2521 USE module_configure , ONLY : grid_config_rec_type
2523 USE module_bc_time_utilities
2527 USE module_date_time
2533 TYPE(domain) :: grid
2535 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
2538 LOGICAL, EXTERNAL :: wrf_dm_on_monitor
2540 INTEGER :: ierr, efid
2541 REAL :: time, tupdate
2542 real, allocatable :: dumc0(:,:,:)
2543 CHARACTER (LEN=256) :: message, current_date_char, date_string
2544 CHARACTER (LEN=80) :: inpname
2546 #include <wrf_io_flags.h>
2547 CALL domain_clock_get( grid, current_timestr=current_date_char )
2549 CALL construct_filename1 ( inpname , 'wrfchemv' , grid%id , 2 )
2550 WRITE(message,*)'mediation_integrate: med_read_wrf_volc_emiss: Open file ',TRIM(inpname)
2551 CALL wrf_message( TRIM(message) )
2553 if( grid%auxinput13_oid .NE. 0 ) then
2554 CALL close_dataset ( grid%auxinput13_oid , config_flags , "DATASET=AUXINPUT13" )
2557 CALL open_r_dataset ( grid%auxinput13_oid, TRIM(inpname) , grid , config_flags, &
2558 "DATASET=AUXINPUT13", ierr )
2559 IF ( ierr .NE. 0 ) THEN
2560 WRITE( message , * ) 'med_read_wrf_volc_emiss: error opening ', TRIM( inpname )
2561 CALL wrf_error_fatal( TRIM( message ) )
2564 WRITE(message,*)'mediation_integrate: med_read_wrf_volc_emiss: Read volcanic ash emissions',&
2565 TRIM(current_date_char)
2566 CALL wrf_message( TRIM(message) )
2568 CALL wrf_debug (100 , 'mediation_integrate: calling input_auxinput13' )
2569 CALL input_auxinput13 ( grid%auxinput13_oid, grid , config_flags , ierr )
2571 CALL close_dataset ( grid%auxinput13_oid , config_flags , "DATASET=AUXINPUT13" )
2573 CALL wrf_debug (100 , 'mediation_integrate: med_read_wrf_volc_emiss: exit' )
2575 END SUBROUTINE med_read_wrf_volc_emiss
2577 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2578 SUBROUTINE med_read_wrf_chem_emissopt3 ( grid , config_flags )
2580 USE module_domain , ONLY : domain , domain_clock_get
2581 USE module_io_domain
2583 USE module_configure , ONLY : grid_config_rec_type
2585 USE module_bc_time_utilities
2589 USE module_date_time
2595 TYPE(domain) :: grid
2597 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
2600 LOGICAL, EXTERNAL :: wrf_dm_on_monitor
2602 INTEGER :: ierr, efid
2603 REAL :: time, tupdate
2604 real, allocatable :: dumc0(:,:,:)
2605 CHARACTER (LEN=256) :: message, current_date_char, date_string
2606 CHARACTER (LEN=80) :: inpname
2608 #include <wrf_io_flags.h>
2609 ! IF ( grid%id .EQ. 1 ) THEN
2611 CALL domain_clock_get( grid, current_timestr=current_date_char )
2613 CALL construct_filename1 ( inpname , 'wrffirechemi' , grid%id , 2 )
2614 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_fireemissions: Open file ',TRIM(inpname)
2615 CALL wrf_message( TRIM(message) )
2617 if( grid%auxinput7_oid .NE. 0 ) then
2618 CALL close_dataset ( grid%auxinput7_oid , config_flags , "DATASET=AUXINPUT7" )
2621 CALL open_r_dataset ( grid%auxinput7_oid, TRIM(inpname) , grid , config_flags, &
2622 "DATASET=AUXINPUT7", ierr )
2623 IF ( ierr .NE. 0 ) THEN
2624 WRITE( message , * ) 'med_read_wrf_chem_fireemissions: error opening ', TRIM( inpname )
2625 CALL wrf_error_fatal( TRIM( message ) )
2628 WRITE(message,*)'mediation_integrate: med_read_wrf_chem_fireemissions: Read fire emissions at time ',&
2629 TRIM(current_date_char)
2630 CALL wrf_message( TRIM(message) )
2632 CALL wrf_debug (00 , 'mediation_integrate: calling input_auxinput7' )
2633 CALL input_auxinput7 ( grid%auxinput7_oid, grid , config_flags , ierr )
2635 CALL close_dataset ( grid%auxinput7_oid , config_flags , "DATASET=AUXINPUT7" )
2638 CALL wrf_debug (00 , 'mediation_integrate: med_read_wrf_chem_fireemissions: exit' )
2640 END SUBROUTINE med_read_wrf_chem_emissopt3
2643 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2646 !zhang's doing for outputing restart namelist parameters
2647 RECURSIVE SUBROUTINE med_namelist_out ( grid , config_flags )
2649 USE module_domain , ONLY : domain, domain_clock_get
2650 USE module_io_domain
2653 USE module_configure , ONLY : grid_config_rec_type
2654 USE module_bc_time_utilities
2655 !zhang new USE WRF_ESMF_MOD
2662 TYPE(domain), INTENT(IN) :: grid
2663 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
2666 !zhang new TYPE(ESMF_Time) :: CurrTime
2667 TYPE(WRFU_Time) :: CurrTime
2668 INTEGER :: nout,rc,kid
2669 INTEGER :: hr, min, sec, ms,julyr,julday
2671 CHARACTER*80 :: prefix, outname
2672 CHARACTER*80 :: timestr
2674 LOGICAL,EXTERNAL :: wrf_dm_on_monitor
2676 TYPE (grid_config_rec_type) :: kid_config_flags
2678 prefix = "wrfnamelist_d<domain>_<date>"
2681 !zhang new CALL ESMF_ClockGet( grid%domain_clock, CurrTime=CurrTime, rc=rc )
2682 !zhang new CALL wrf_timetoa ( CurrTime, timestr )
2683 CALL domain_clock_get( grid, current_timestr=timestr )
2685 CALL construct_filename2a ( outname , prefix, grid%id , 2 , timestr )
2687 IF ( wrf_dm_on_monitor() ) THEN
2690 OPEN ( FILE = trim(outname) , UNIT = nout, STATUS = 'UNKNOWN', FORM = 'FORMATTED')
2691 !zhang new CALL ESMF_TimeGet( grid%current_time, YY=julyr, dayOfYear=julday, H=hr, M=min, S=sec, MS=ms, rc=rc)
2692 CALL domain_clock_get( grid, current_time=CurrTime )
2693 CALL WRFU_TimeGet( CurrTime, YY=julyr, dayOfYear=julday, H=hr, M=min, S=sec, MS=ms, rc=rc)
2695 gmt=hr+real(min)/60.+real(sec)/3600.+real(ms)/(1000*3600)
2696 WRITE(NOUT,*) grid%i_parent_start
2697 WRITE(NOUT,*) grid%j_parent_start
2699 WRITE(NOUT,*) julday
2705 ! call recursively for children, (if any)
2706 DO kid = 1, max_nests
2707 IF ( ASSOCIATED( grid%nests(kid)%ptr ) ) THEN
2708 CALL model_to_grid_config_rec ( grid%nests(kid)%ptr%id , model_config_rec , kid_config_flags )
2709 CALL med_namelist_out ( grid%nests(kid)%ptr , kid_config_flags )
2714 END SUBROUTINE med_namelist_out
2715 !end of zhang's doing