3 ! create an initial data set for the WRF model based on an ideal condition
6 USE module_domain , ONLY : domain
7 USE module_initialize_ideal
8 USE module_configure , ONLY : grid_config_rec_type
13 USE module_input_chem_data
14 USE module_input_chem_bioemiss
22 SUBROUTINE med_read_wrf_chem_bioemiss ( grid , config_flags)
25 TYPE (grid_config_rec_type) config_flags
26 END SUBROUTINE med_read_wrf_chem_bioemiss
36 TYPE(domain) , POINTER :: keep_grid, grid_ptr, null_domain, grid
38 TYPE (grid_config_rec_type) :: config_flags
39 TYPE (WRFU_Time) startTime, stopTime, currentTime
40 TYPE (WRFU_TimeInterval) stepTime
42 INTEGER :: max_dom , domain_id , fid , oid , idum1 , idum2 , ierr
43 INTEGER :: debug_level, rc
44 LOGICAL :: input_from_file
47 SUBROUTINE med_initialdata_output ( grid , config_flags )
48 USE module_domain , ONLY : domain
49 USE module_configure , ONLY : grid_config_rec_type
50 TYPE (domain) , POINTER :: grid
51 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
52 END SUBROUTINE med_initialdata_output
55 #include "version_decl"
60 INTEGER, PARAMETER :: configbuflen = 4* CONFIG_BUF_LEN
61 INTEGER :: configbuf( configbuflen )
62 LOGICAL , EXTERNAL :: wrf_dm_on_monitor
65 CHARACTER (LEN=80) :: message
67 ! Define the name of this program (program_name defined in module_domain)
69 program_name = "IDEAL " // TRIM(release_version) // " PREPROCESSOR"
71 ! Get the NAMELIST data for input.
73 CALL init_modules(1) ! Phase 1 returns after MPI_INIT() (if it is called)
74 #ifdef NO_LEAP_CALENDAR
75 CALL WRFU_Initialize( defaultCalKind=WRFU_CAL_NOLEAP, rc=rc )
77 CALL WRFU_Initialize( defaultCalKind=WRFU_CAL_GREGORIAN, rc=rc )
79 CALL init_modules(2) ! Phase 2 resumes after MPI_INIT() (if it is called)
82 IF ( wrf_dm_on_monitor() ) THEN
85 CALL get_config_as_buffer( configbuf, configbuflen, nbytes )
86 CALL wrf_dm_bcast_bytes( configbuf, nbytes )
87 CALL set_config_as_buffer( configbuf, configbuflen )
88 CALL wrf_dm_initialize
92 CALL nl_get_debug_level ( 1, debug_level )
93 CALL set_wrf_debug_level ( debug_level )
95 CALL wrf_message ( program_name )
98 ! allocated and configure the mother domain
100 NULLIFY( null_domain )
102 CALL alloc_and_configure_domain ( domain_id = 1 , &
104 parent = null_domain , &
108 ! TBH: Note that historically, IDEAL did not set up clocks. These
109 ! TBH: are explicit replacements for old default initializations... They
110 ! TBH: are needed to ensure that time manager calls do not fail due to
111 ! TBH: uninitialized clock. Clean this up later...
112 CALL WRFU_TimeSet(startTime, YY=1, MM=1, DD=1, H=0, M=0, S=0, rc=rc)
114 currentTime = startTime
115 ! TBH: Bogus time step value -- clock is never advanced...
116 CALL WRFU_TimeIntervalSet(stepTime, S=180, rc=rc)
117 grid%domain_clock = WRFU_ClockCreate( TimeStep= stepTime, &
118 StartTime=startTime, &
119 StopTime= stopTime, &
121 CALL wrf_check_error( WRFU_SUCCESS, rc, &
122 'grid%domain_clock = WRFU_ClockCreate() FAILED', &
125 CALL wrf_debug ( 100 , 'wrf: calling model_to_grid_config_rec ' )
126 CALL model_to_grid_config_rec ( head_grid%id , model_config_rec , config_flags )
127 CALL wrf_debug ( 100 , 'wrf: calling set_scalar_indices_from_config ' )
128 CALL set_scalar_indices_from_config ( head_grid%id , idum1, idum2 )
131 WRITE ( current_date , FMT = '(I4.4,"-",I5.5,"_",I2.2,":",I2.2,":",I2.2,".0000")' ) &
132 config_flags%start_year, &
133 config_flags%start_day, &
134 config_flags%start_hour, &
135 config_flags%start_minute, &
136 config_flags%start_second
138 WRITE ( current_date , FMT = '(I4.4,"-",I2.2,"-",I2.2,"_",I2.2,":",I2.2,":",I2.2,".0000")' ) &
139 config_flags%start_year, &
140 config_flags%start_month, &
141 config_flags%start_day, &
142 config_flags%start_hour, &
143 config_flags%start_minute, &
144 config_flags%start_second
146 CALL domain_clockprint ( 150, grid, &
147 'DEBUG assemble_output: clock before 1st currTime set,' )
148 WRITE (wrf_err_message,*) &
149 'DEBUG assemble_output: before 1st currTime set, current_date = ',TRIM(current_date)
150 CALL wrf_debug ( 150 , wrf_err_message )
151 CALL domain_clock_set( grid, current_timestr=current_date(1:19) )
152 CALL domain_clockprint ( 150, grid, &
153 'DEBUG assemble_output: clock after 1st currTime set,' )
155 CALL wrf_debug ( 100 , 'wrf: calling init_wrfio' )
159 CALL get_config_as_buffer( configbuf, configbuflen, nbytes )
160 CALL wrf_dm_bcast_bytes( configbuf, nbytes )
161 CALL set_config_as_buffer( configbuf, configbuflen )
165 IF( grid%chem_opt > 0 ) then
166 ! Read the chemistry data from a previous wrf forecast (wrfout file)
167 IF(grid%chem_in_opt == 1 ) THEN
168 message = 'INITIALIZING CHEMISTRY WITH OLD SIMULATION'
169 CALL wrf_message ( message )
171 CALL med_read_wrf_chem_input ( grid , config_flags)
172 IF(grid%emiss_opt == ECPTEC .or. grid%emiss_opt == GOCART_ECPTEC &
173 .or. grid%biomass_burn_opt == BIOMASSB) THEN
174 message = 'READING EMISSIONS DATA OPT 3'
175 CALL wrf_message ( message )
176 ! CALL med_read_bin_chem_emissopt3 ( grid , config_flags)
177 CALL med_read_wrf_chem_emissopt3 ( grid , config_flags)
180 IF(grid%bio_emiss_opt == 2 ) THEN
181 message = 'READING BEIS3.11 EMISSIONS DATA'
182 CALL wrf_message ( message )
183 CALL med_read_wrf_chem_bioemiss ( grid , config_flags)
184 else IF(grid%bio_emiss_opt == 3 ) THEN !shc
185 message = 'READING MEGAN 2 EMISSIONS DATA'
186 CALL wrf_message ( message )
187 CALL med_read_wrf_chem_bioemiss ( grid , config_flags)
190 IF(grid%dust_opt == 1 .or. grid%dmsemis_opt == 1 .or. grid%chem_opt == 300) THEN !shc
191 message = 'READING GOCART BG AND/OR DUST and DMS REF FIELDS'
192 CALL wrf_message ( message )
193 CALL med_read_wrf_chem_gocart_bg ( grid , config_flags)
196 ELSEIF(grid%chem_in_opt == 0)then
197 ! Generate chemistry data from a idealized vertical profile
198 message = 'STARTING WITH BACKGROUND CHEMISTRY '
199 CALL wrf_message ( message )
201 CALL input_chem_profile ( grid )
203 IF(grid%bio_emiss_opt == 2 ) THEN
204 message = 'READING BEIS3.11 EMISSIONS DATA'
205 CALL wrf_message ( message )
206 CALL med_read_wrf_chem_bioemiss ( grid , config_flags)
207 else IF(grid%bio_emiss_opt == 3 ) THEN !shc
208 message = 'READING MEGAN 2 EMISSIONS DATA'
209 CALL wrf_message ( message )
210 CALL med_read_wrf_chem_bioemiss ( grid , config_flags)
212 IF(grid%emiss_opt == ECPTEC .or. grid%emiss_opt == GOCART_ECPTEC &
213 .or. grid%biomass_burn_opt == BIOMASSB) THEN
214 message = 'READING EMISSIONS DATA OPT 3'
215 CALL wrf_message ( message )
216 ! CALL med_read_bin_chem_emissopt3 ( grid , config_flags)
217 CALL med_read_wrf_chem_emissopt3 ( grid , config_flags)
220 IF(grid%dust_opt == 1 .or. grid%dmsemis_opt == 1 .or. grid%chem_opt == 300) THEN !shc
221 message = 'READING GOCART BG AND/OR DUST and DMS REF FIELDS'
222 CALL wrf_message ( message )
223 CALL med_read_wrf_chem_gocart_bg ( grid , config_flags)
227 message = 'RUNNING WITHOUT CHEMISTRY INITIALIZATION'
228 CALL wrf_message ( message )
233 CALL med_initialdata_output( head_grid , config_flags )
235 CALL wrf_debug ( 0 , 'wrf: SUCCESS COMPLETE IDEAL INIT' )
236 CALL med_shutdown_io ( head_grid , config_flags )
239 CALL WRFU_Finalize( rc=rc )
243 SUBROUTINE med_initialdata_output ( grid , config_flags )
247 USE module_initialize_ideal
254 TYPE(domain) , POINTER :: grid
255 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
257 INTEGER :: time_step_begin_restart
258 INTEGER :: fid , ierr , id
259 CHARACTER (LEN=80) :: rstname
260 CHARACTER (LEN=80) :: message
261 CHARACTER (LEN=80) :: inpname , bdyname
263 ! Initialize the mother domain.
265 grid%input_from_file = .false.
266 CALL init_domain ( grid )
267 CALL calc_current_date ( grid%id, 0.)
269 CALL construct_filename1 ( inpname , 'wrfinput' , grid%id , 2 )
270 CALL open_w_dataset ( id, TRIM(inpname) , grid , config_flags , output_input , "DATASET=INPUT", ierr )
271 IF ( ierr .NE. 0 ) THEN
272 WRITE (wrf_err_message,*)'ideal: error opening wrfinput for writing ',ierr
273 CALL wrf_error_fatal( wrf_err_message )
275 CALL output_input ( id, grid , config_flags , ierr )
276 CALL close_dataset ( id , config_flags, "DATASET=INPUT" )
279 IF ( config_flags%specified ) THEN
281 CALL construct_filename1 ( bdyname , 'wrfbdy' , grid%id , 2 )
282 CALL open_w_dataset ( id, TRIM(bdyname) , grid , config_flags , output_boundary , "DATASET=BOUNDARY", ierr )
283 IF ( ierr .NE. 0 ) THEN
284 WRITE (wrf_err_message,*)'ideal: error opening wrfbdy for writing ',ierr
285 CALL wrf_error_fatal( wrf_err_message )
287 CALL output_boundary ( id, grid , config_flags , ierr )
288 CALL close_dataset ( id , config_flags , "DATASET=BOUNDARY" )
293 END SUBROUTINE med_initialdata_output