input_wrf.F

References to this file elsewhere.
1 !WRF:MEDIATION:IO
2 !  ---principal wrf input routine (called from routines in module_io_domain ) 
3 
4   SUBROUTINE input_wrf ( fid , grid , config_flags , switch , ierr )
5     USE module_domain
6     USE module_state_description
7     USE module_configure
8     USE module_io
9     USE module_io_wrf
10     USE module_date_time
11     USE module_bc_time_utilities
12     USE module_utility
13     IMPLICIT NONE
14 #include <wrf_io_flags.h>
15 #include <wrf_status_codes.h>
16     TYPE(domain) :: grid
17     TYPE(grid_config_rec_type),  INTENT(INOUT)    :: config_flags
18     INTEGER, INTENT(IN) :: fid
19     INTEGER, INTENT(IN) :: switch
20     INTEGER, INTENT(INOUT) :: ierr
21 
22     ! Local data
23     INTEGER ids , ide , jds , jde , kds , kde , &
24             ims , ime , jms , jme , kms , kme , &
25             ips , ipe , jps , jpe , kps , kpe
26 
27     INTEGER       iname(9)
28     INTEGER       iordering(3)
29     INTEGER       icurrent_date(24)
30     INTEGER       i,j,k
31     INTEGER       icnt
32     INTEGER       ndim
33     INTEGER       ilen
34     INTEGER , DIMENSION(3) :: domain_start , domain_end
35     INTEGER , DIMENSION(3) :: memory_start , memory_end
36     INTEGER , DIMENSION(3) :: patch_start , patch_end
37     CHARACTER*256 errmess, currtimestr
38     CHARACTER*40            :: this_datestr, next_datestr
39     CHARACTER*9   NAMESTR
40     INTEGER       IBDY, NAMELEN
41     LOGICAL wrf_dm_on_monitor
42     EXTERNAL wrf_dm_on_monitor
43     Type(WRFU_Time) time, currtime
44     CHARACTER*19  new_date
45     CHARACTER*24  base_date
46     CHARACTER*80  fname
47     LOGICAL dryrun
48     INTEGER idt
49     INTEGER itmp
50     INTEGER dyn_opt_tmp, dyn_opt, filestate, ierr3
51     INTEGER :: ide_compare , jde_compare , kde_compare
52     REAL , DIMENSION(16) :: lats16 , lons16
53     CHARACTER (len=19) simulation_start_date
54     INTEGER simulation_start_year   , &
55             simulation_start_month  , &
56             simulation_start_day    , &
57             simulation_start_hour   , &
58             simulation_start_minute , &
59             simulation_start_second
60     LOGICAL reset_simulation_start
61     REAL dx_compare , dy_compare , dum
62 
63 !<DESCRIPTION>
64 !
65 ! Core wrf input routine for all input data streams. Part of mediation layer.
66 ! 
67 ! Note that WRF IOAPI routines wrf_get_dom_ti_*() do not return values during 
68 ! training reads (dryrun).  
69 ! 
70 !</DESCRIPTION>
71 
72     WRITE(wrf_err_message,*)'input_wrf: begin, fid = ',fid
73     CALL wrf_debug( 300 , wrf_err_message )
74 
75     ierr = 0
76 
77     CALL get_ijk_from_grid (  grid ,                        &
78                               ids, ide, jds, jde, kds, kde,    &
79                               ims, ime, jms, jme, kms, kme,    &
80                               ips, ipe, jps, jpe, kps, kpe    )
81 
82 ! simulation start time is a Singleton maintained by head_grid
83     IF ( ( switch .EQ.     model_input_only  ) .OR. &
84          ( switch .EQ.          restart_only ) ) THEN
85       CALL wrf_get_dom_ti_char ( fid , 'SIMULATION_START_DATE' , simulation_start_date , ierr )
86       CALL nl_get_reset_simulation_start ( 1, reset_simulation_start )
87       IF ( ( ierr .EQ. 0 ) .AND. ( .NOT. reset_simulation_start ) ) THEN
88         ! Overwrite simulation start date with metadata.  
89 #ifdef PLANET
90         READ ( simulation_start_date , fmt = '(I4,1x,I5,1x,I2,1x,I2,1x,I2)' )       &
91                simulation_start_year,                                               &
92                simulation_start_day,    simulation_start_hour,                      &
93                simulation_start_minute, simulation_start_second
94         simulation_start_month = 0
95 #else
96         READ ( simulation_start_date , fmt = '(I4,1x,I2,1x,I2,1x,I2,1x,I2,1x,I2)' ) &
97                simulation_start_year,   simulation_start_month,                     &
98                simulation_start_day,    simulation_start_hour,                      &
99                simulation_start_minute, simulation_start_second
100 #endif
101         CALL nl_set_simulation_start_year   ( 1 , simulation_start_year   )
102         CALL nl_set_simulation_start_month  ( 1 , simulation_start_month  )
103         CALL nl_set_simulation_start_day    ( 1 , simulation_start_day    )
104         CALL nl_set_simulation_start_hour   ( 1 , simulation_start_hour   )
105         CALL nl_set_simulation_start_minute ( 1 , simulation_start_minute )
106         CALL nl_set_simulation_start_second ( 1 , simulation_start_second )
107         IF ( switch .EQ. model_input_only  ) THEN
108           WRITE(wrf_err_message,*)fid,' input_wrf, model_input_only:  SIMULATION_START_DATE = ', &
109                                   simulation_start_date(1:19)
110           CALL wrf_debug ( 300 , TRIM(wrf_err_message ) )
111         ELSE IF ( switch .EQ. restart_only  ) THEN
112           WRITE(wrf_err_message,*)fid,' input_wrf, restart_only:  SIMULATION_START_DATE = ', &
113                                   simulation_start_date(1:19)
114           CALL wrf_debug ( 300 , TRIM(wrf_err_message ) )
115         ENDIF
116       ELSE
117         CALL nl_get_start_year   ( 1 , simulation_start_year   )
118         CALL nl_get_start_month  ( 1 , simulation_start_month  )
119         CALL nl_get_start_day    ( 1 , simulation_start_day    )
120         CALL nl_get_start_hour   ( 1 , simulation_start_hour   )
121         CALL nl_get_start_minute ( 1 , simulation_start_minute )
122         CALL nl_get_start_second ( 1 , simulation_start_second )
123         CALL nl_set_simulation_start_year   ( 1 , simulation_start_year   )
124         CALL nl_set_simulation_start_month  ( 1 , simulation_start_month  )
125         CALL nl_set_simulation_start_day    ( 1 , simulation_start_day    )
126         CALL nl_set_simulation_start_hour   ( 1 , simulation_start_hour   )
127         CALL nl_set_simulation_start_minute ( 1 , simulation_start_minute )
128         CALL nl_set_simulation_start_second ( 1 , simulation_start_second )
129         IF ( reset_simulation_start ) THEN
130           CALL wrf_message('input_wrf: forcing SIMULATION_START_DATE = head_grid start time')
131           CALL wrf_message('           due to namelist variable reset_simulation_start') 
132         ELSE
133           CALL wrf_message('input_wrf: SIMULATION_START_DATE not available in input')
134           CALL wrf_message('will use head_grid start time from namelist') 
135         ENDIF
136       ENDIF
137       ! Initialize derived time quantity in grid%xtime.  
138       ! Note that this call is also made in setup_timekeeping().  
139       ! Ugh, what a hack.  Simplify all this later...  
140       CALL domain_clock_get( grid, minutesSinceSimulationStart=grid%xtime )
141       ! Note that it is NOT necessary to reset grid%julian here.  
142       WRITE(wrf_err_message,*) 'input_wrf:  set xtime to ',grid%xtime
143       CALL wrf_debug ( 100, TRIM(wrf_err_message) )
144     ENDIF
145 
146 
147     !  Test to make sure that the input data is the right size.  Do this for input from real/ideal into
148     !  WRF, and from the standard initialization into real.
149 
150     IF ( ( switch .EQ.     model_input_only  ) .OR. &
151          ( switch .EQ. aux_model_input1_only ) ) THEN
152        ierr = 0
153        CALL wrf_get_dom_ti_integer ( fid , 'WEST-EAST_GRID_DIMENSION' ,    ide_compare , 1 , icnt , ierr3 ) 
154        ierr = max( ierr, ierr3 )
155        CALL wrf_get_dom_ti_integer ( fid , 'SOUTH-NORTH_GRID_DIMENSION' ,  jde_compare , 1 , icnt , ierr3 ) 
156        ierr = max( ierr, ierr3 )
157        CALL wrf_get_dom_ti_integer ( fid , 'BOTTOM-TOP_GRID_DIMENSION' ,   kde_compare , 1 , icnt , ierr3 ) 
158        ierr = max( ierr, ierr3 )
159 !      IF ( ierr3 .NE. 0 ) CALL wrf_error_fatal( 'wrf_get_dom_ti_integer getting dimension information from dataset' )
160        IF ( ierr3 .NE. 0 ) CALL wrf_debug( 'wrf_get_dom_ti_integer getting dimension information from dataset' )
161    
162 #if (EM_CORE == 1)
163        !  Test to make sure that the grid distances are the right size.
164    
165        CALL wrf_get_dom_ti_real ( fid , 'DX' ,  dx_compare , 1 , icnt , ierr )
166        CALL wrf_get_dom_ti_real ( fid , 'DY' ,  dy_compare , 1 , icnt , ierr )
167        IF ( ( ABS ( dx_compare - config_flags%dx ) .GT. 1.E-5 * dx_compare ) .OR. &
168             ( ABS ( dy_compare - config_flags%dy ) .GT. 1.E-5 * dy_compare ) ) THEN
169           IF ( ( config_flags%polar ) .AND. ( config_flags%grid_id .EQ. 1 ) ) THEN
170              WRITE(wrf_err_message,*)'input_wrf: DX and DY from input file expected to be wrong'
171              CALL wrf_debug ( 1 , wrf_err_message )
172           ELSE
173              print *,'dx_compare,dy_compare = ',dx_compare,dy_compare
174              CALL wrf_error_fatal( 'DX and DY do not match from the namelist and the input file' )
175           END IF
176        END IF
177 #endif
178     END IF
179 
180     ! do the check later (see check_if_dryrun below)
181 
182     CALL nl_get_dyn_opt( 1, dyn_opt )
183     CALL wrf_get_dom_ti_integer ( fid, 'DYN_OPT', dyn_opt_tmp, 1, icnt, ierr )
184 
185     !  We do not want the CEN_LAT LON values from the boundary file.  For 1-way nests
186     !  with ndown, this ends up being the data from the previous coarse domain.
187 
188     IF ( switch .NE. boundary_only ) THEN
189        CALL wrf_get_dom_ti_real ( fid , 'CEN_LAT' ,  config_flags%cen_lat , 1 , icnt , ierr )
190        WRITE(wrf_err_message,*)'input_wrf: wrf_get_dom_ti_real for CEN_LAT returns ',config_flags%cen_lat
191        CALL wrf_debug ( 300 , wrf_err_message )
192        CALL nl_set_cen_lat ( grid%id , config_flags%cen_lat )
193 
194        CALL wrf_get_dom_ti_real ( fid , 'CEN_LON' ,  config_flags%cen_lon , 1 , icnt , ierr )
195        WRITE(wrf_err_message,*)'input_wrf: wrf_get_dom_ti_real for CEN_LON returns ',config_flags%cen_lon
196        CALL wrf_debug ( 300 , wrf_err_message )
197        CALL nl_set_cen_lon ( grid%id , config_flags%cen_lon )
198     ELSE
199        CALL wrf_get_dom_ti_real ( fid , 'CEN_LAT' ,  dum , 1 , icnt , ierr )
200        WRITE(wrf_err_message,*)'input_wrf: wrf_get_dom_ti_real for CEN_LAT returns ',dum
201        CALL wrf_debug ( 300 , wrf_err_message )
202 
203        CALL wrf_get_dom_ti_real ( fid , 'CEN_LON' ,  dum , 1 , icnt , ierr )
204        WRITE(wrf_err_message,*)'input_wrf: wrf_get_dom_ti_real for CEN_LON returns ',dum
205        CALL wrf_debug ( 300 , wrf_err_message )
206     END IF
207 
208     CALL wrf_get_dom_ti_real ( fid , 'TRUELAT1' ,  config_flags%truelat1 , 1 , icnt , ierr )
209     WRITE(wrf_err_message,*)'input_wrf: wrf_get_dom_ti_real for TRUELAT1 returns ',config_flags%truelat1
210     CALL wrf_debug ( 300 , wrf_err_message )
211     CALL nl_set_truelat1 ( grid%id , config_flags%truelat1 )
212 
213     CALL wrf_get_dom_ti_real ( fid , 'TRUELAT2' ,  config_flags%truelat2 , 1 , icnt , ierr )
214     WRITE(wrf_err_message,*)'input_wrf: wrf_get_dom_ti_real for TRUELAT2 returns ',config_flags%truelat2
215     CALL wrf_debug ( 300 , wrf_err_message )
216     CALL nl_set_truelat2 ( grid%id , config_flags%truelat2 )
217 
218     CALL wrf_get_dom_ti_real ( fid , 'MOAD_CEN_LAT' ,  config_flags%moad_cen_lat , 1 , icnt , ierr )
219     WRITE(wrf_err_message,*)'input_wrf: wrf_get_dom_ti_real for MOAD_CEN_LAT returns ',config_flags%moad_cen_lat
220     CALL wrf_debug ( 300 , wrf_err_message )
221     CALL nl_set_moad_cen_lat ( grid%id , config_flags%moad_cen_lat )
222 
223     CALL wrf_get_dom_ti_real ( fid , 'STAND_LON' ,  config_flags%stand_lon , 1 , icnt , ierr )
224     WRITE(wrf_err_message,*)'input_wrf: wrf_get_dom_ti_real for STAND_LON returns ',config_flags%stand_lon
225     CALL wrf_debug ( 300 , wrf_err_message )
226     CALL nl_set_stand_lon ( grid%id , config_flags%stand_lon )
227 
228 #if ( NMM_CORE != 1 )
229     IF ( program_name(1:7) .EQ. "REAL_EM" ) THEN
230     CALL wrf_get_dom_ti_real ( fid , 'corner_lats' ,  lats16 , 16 , icnt , ierr )
231     WRITE(wrf_err_message,FMT='(A,16f6.1)')'input_wrf: wrf_get_dom_ti_real for CORNER_LATS returns ',lats16
232     CALL wrf_debug ( 300 , wrf_err_message )
233     grid%em_lat_ll_t = lats16( 1)
234     grid%em_lat_ul_t = lats16( 2)
235     grid%em_lat_ur_t = lats16( 3)
236     grid%em_lat_lr_t = lats16( 4)
237     grid%em_lat_ll_u = lats16( 5)
238     grid%em_lat_ul_u = lats16( 6)
239     grid%em_lat_ur_u = lats16( 7)
240     grid%em_lat_lr_u = lats16( 8)
241     grid%em_lat_ll_v = lats16( 9)
242     grid%em_lat_ul_v = lats16(10)
243     grid%em_lat_ur_v = lats16(11)
244     grid%em_lat_lr_v = lats16(12)
245     grid%em_lat_ll_d = lats16(13)
246     grid%em_lat_ul_d = lats16(14)
247     grid%em_lat_ur_d = lats16(15)
248     grid%em_lat_lr_d = lats16(16)
249 
250     CALL wrf_get_dom_ti_real ( fid , 'corner_lons' ,  lons16 , 16 , icnt , ierr )
251     WRITE(wrf_err_message,FMT='(A,16f6.1)')'input_wrf: wrf_get_dom_ti_real for CORNER_LONS returns ',lons16
252     CALL wrf_debug ( 300 , wrf_err_message )
253     grid%em_lon_ll_t = lons16( 1)
254     grid%em_lon_ul_t = lons16( 2)
255     grid%em_lon_ur_t = lons16( 3)
256     grid%em_lon_lr_t = lons16( 4)
257     grid%em_lon_ll_u = lons16( 5)
258     grid%em_lon_ul_u = lons16( 6)
259     grid%em_lon_ur_u = lons16( 7)
260     grid%em_lon_lr_u = lons16( 8)
261     grid%em_lon_ll_v = lons16( 9)
262     grid%em_lon_ul_v = lons16(10)
263     grid%em_lon_ur_v = lons16(11)
264     grid%em_lon_lr_v = lons16(12)
265     grid%em_lon_ll_d = lons16(13)
266     grid%em_lon_ul_d = lons16(14)
267     grid%em_lon_ur_d = lons16(15)
268     grid%em_lon_lr_d = lons16(16)
269     ENDIF
270 #endif
271 
272 #if ( NMM_CORE != 1 )
273 ! program_name is defined in module_domain and set in the main program for whatever application
274 ! is using subroutine input_wrf (that is, the subroutine you are looking at here). Data files
275 ! written by SI have P_TOP as a metadata item; the real program and wrf model have it as a 
276 ! state variable. This test is to supress non-fatal but confusing messages from the model complaining
277 ! that P_TOP cannot be read from the metadata for this dataset.  JM 20040905
278 !
279 ! Note, P_TOP is not defined in the NMM core.
280 
281     IF ( program_name(1:7) .EQ. "REAL_EM" ) THEN
282       CALL wrf_get_dom_ti_real ( fid , 'P_TOP' ,  grid%p_top , 1 , icnt , ierr )
283       WRITE(wrf_err_message,*)'input_wrf: wrf_get_dom_ti_real for P_TOP returns ',grid%p_top
284       CALL wrf_debug ( 300 , wrf_err_message )
285     ENDIF
286 #endif
287 
288     IF ( switch .NE. boundary_only ) THEN
289       CALL wrf_get_dom_ti_real ( fid , 'GMT' ,  config_flags%gmt , 1 , icnt , ierr )
290       WRITE(wrf_err_message,*)'input_wrf: wrf_get_dom_ti_real for GMT returns ',config_flags%gmt
291       CALL wrf_debug ( 300 , wrf_err_message )
292       CALL nl_set_gmt ( grid%id , config_flags%gmt )
293 
294       CALL wrf_get_dom_ti_integer ( fid , 'JULYR' ,  config_flags%julyr , 1 , icnt , ierr )
295       WRITE(wrf_err_message,*)'input_wrf: wrf_get_dom_ti_integer for JULYR returns ',config_flags%julyr
296       CALL wrf_debug ( 300 , wrf_err_message )
297       CALL nl_set_julyr ( grid%id , config_flags%julyr )
298 
299       CALL wrf_get_dom_ti_integer ( fid , 'JULDAY' ,  config_flags%julday , 1 , icnt , ierr )
300       WRITE(wrf_err_message,*)'input_wrf: wrf_get_dom_ti_integer for JULDAY returns ',config_flags%julday
301       CALL wrf_debug ( 300 , wrf_err_message )
302       CALL nl_set_julday ( grid%id , config_flags%julday )
303     ENDIF
304 
305     CALL wrf_get_dom_ti_integer ( fid , 'MAP_PROJ' ,  config_flags%map_proj , 1 , icnt , ierr )
306     WRITE(wrf_err_message,*)'input_wrf: wrf_get_dom_ti_integer for MAP_PROJ returns ',config_flags%map_proj
307     CALL wrf_debug ( 300 , wrf_err_message )
308     CALL nl_set_map_proj ( grid%id , config_flags%map_proj )
309 
310     CALL wrf_get_dom_ti_char ( fid , 'MMINLU', mminlu , ierr )
311     WRITE(wrf_err_message,*)'input_wrf: wrf_get_dom_ti_char for MMINLU returns ',mminlu(1:4)
312     CALL wrf_debug ( 300 , wrf_err_message )
313     CALL nl_set_mminlu ( 1, mminlu(1:4) )
314 
315     CALL wrf_get_dom_ti_integer ( fid , 'ISWATER' ,  config_flags%iswater , 1 , icnt , ierr )
316     WRITE(wrf_err_message,*)'input_wrf: wrf_get_dom_ti_integer for ISWATER returns ',config_flags%iswater
317     CALL wrf_debug ( 300 , wrf_err_message )
318     IF ( ierr .NE. 0 ) THEN
319          IF (mminlu == 'UMD') THEN
320               config_flags%iswater = 14
321          ELSE 
322               config_flags%iswater = 16 
323          ENDIF
324     ENDIF
325     CALL nl_set_iswater ( grid%id , config_flags%iswater )
326 
327     CALL wrf_get_dom_ti_integer ( fid , 'ISICE' ,  config_flags%isice , 1 , icnt , ierr )
328     WRITE(wrf_err_message,*)'input_wrf: wrf_get_dom_ti_integer for ISICE returns ',config_flags%isice
329     CALL wrf_debug ( 300 , wrf_err_message )
330     IF ( ierr .NE.  0 ) THEN
331          IF (mminlu == 'UMD') THEN
332               config_flags%isice = 14
333          ELSE
334               config_flags%isice = 24
335          ENDIF
336     ENDIF
337     CALL nl_set_isice ( grid%id , config_flags%isice )
338 
339     CALL wrf_get_dom_ti_integer ( fid , 'ISURBAN' ,  config_flags%isurban , 1 , icnt , ierr )
340     WRITE(wrf_err_message,*)'input_wrf: wrf_get_dom_ti_integer for ISURBAN returns ',config_flags%isurban
341     CALL wrf_debug ( 300 , wrf_err_message )
342     IF ( ierr .NE. 0 ) THEN
343          IF (mminlu == 'UMD') THEN
344               config_flags%isurban = 13
345          ELSE
346               config_flags%isurban = 1
347          ENDIF
348     ENDIF
349     CALL nl_set_isurban ( grid%id , config_flags%isurban )
350 
351     CALL wrf_get_dom_ti_integer ( fid , 'ISOILWATER' ,  config_flags%isoilwater , 1 , icnt , ierr )
352     WRITE(wrf_err_message,*)'input_wrf: wrf_get_dom_ti_integer for ISOILWATER returns ',config_flags%isoilwater
353     CALL wrf_debug ( 300 , wrf_err_message )
354     IF ( ierr .NE. 0 ) THEN
355          config_flags%isoilwater = 14
356     ENDIF
357     CALL nl_set_isoilwater ( grid%id , config_flags%isoilwater )
358 
359 #ifdef MOVE_NESTS
360 ! Added these fields for restarting of moving nests, JM
361 ! DANGER and TODO
362 ! It is very important that these be set correctly if they are set at all in here.
363 ! Garbage values will produce unpredictable results, possibly segfaults, in the nesting
364 ! code. Need some integrity checking here or elsewhere in the code to at least check to
365 ! make sure that the istart and jstart values make sense with respect to the nest dimensions
366 ! and the position in the parent domain.
367     CALL wrf_get_dom_ti_integer ( fid , 'I_PARENT_START' ,  itmp  , 1 , icnt, ierr )
368     IF ( ierr .EQ. 0 .AND. switch .EQ. restart_only ) THEN
369       config_flags%i_parent_start = itmp
370       CALL nl_set_i_parent_start ( grid%id , config_flags%i_parent_start )
371     ENDIF
372     CALL wrf_get_dom_ti_integer ( fid , 'J_PARENT_START' ,  itmp  , 1 , icnt, ierr )
373     IF ( ierr .EQ. 0 .AND. switch .EQ. restart_only ) THEN
374       config_flags%j_parent_start = itmp
375       CALL nl_set_j_parent_start ( grid%id , config_flags%j_parent_start )
376     ENDIF
377 #endif
378 
379 ! If this was not a training read (dry run) check for erroneous values.  
380     CALL wrf_inquire_filename ( fid , fname , filestate , ierr )
381     IF ( ierr /= 0 ) THEN
382       WRITE(wrf_err_message,*)'module_io_wrf: input_wrf: wrf_inquire_filename Status = ',ierr
383       CALL wrf_error_fatal( wrf_err_message )
384     ENDIF
385 
386     WRITE(wrf_err_message,*)'input_wrf: fid,filestate = ',fid,filestate
387     CALL wrf_debug( 300 , wrf_err_message )
388 
389     dryrun        = ( filestate .EQ. WRF_FILE_OPENED_NOT_COMMITTED )
390 
391     WRITE(wrf_err_message,*)'input_wrf: dryrun = ',dryrun
392     CALL wrf_debug( 300 , wrf_err_message )
393 
394     check_if_dryrun : IF ( .NOT. dryrun ) THEN
395 
396 #if (EM_CORE == 1)
397 
398 !KLUDGE - is there a more elegant way to determine "old si" input
399     IF      ( ( switch .EQ.     model_input_only  ) .OR. &
400             ( ( switch .EQ. aux_model_input1_only ) .AND. &
401               ( config_flags%auxinput1_inname(1:8) .EQ. 'wrf_real' ) ) ) THEN
402 
403        !  Test to make sure that the input data is the right size.
404 
405        IF ( ( ide .NE. ide_compare    ) .OR. &
406             ( kde .NE. kde_compare    ) .OR. &
407             ( jde .NE. jde_compare    ) ) THEN
408           WRITE(wrf_err_message,*)'input_wrf.F: SIZE MISMATCH:  namelist ide,jde,kde=',ide,jde,kde,&
409                                   '; input data ide,jde,kde=',ide_compare , jde_compare , kde_compare
410           CALL wrf_error_fatal( wrf_err_message )
411        ENDIF
412 
413     ELSE IF ( switch .EQ. aux_model_input1_only ) THEN
414 
415        !  Test to make sure that the input data is the right size.
416        
417        IF ( ( ide                             .NE. ide_compare ) .OR. &
418             ( config_flags%num_metgrid_levels .NE. kde_compare ) .OR. &
419             ( jde                             .NE. jde_compare ) ) THEN
420          WRITE(wrf_err_message,*)'input_wrf.F: SIZE MISMATCH:  ',&
421                                  'namelist ide,jde,num_metgrid_levels=',ide,jde,config_flags%num_metgrid_levels,&
422                                  '; input data ide,jde,num_metgrid_levels=',ide_compare , jde_compare , kde_compare
423          CALL wrf_error_fatal( wrf_err_message )
424        ENDIF
425     ENDIF
426 
427 #endif
428 
429 #if (NMM_CORE == 1)
430 
431     IF      ( ( switch .EQ. aux_model_input1_only  ) .AND. &
432               ( config_flags%auxinput1_inname(1:8) .EQ. 'wrf_real' ) ) THEN
433 
434        CALL wrf_get_dom_ti_integer ( fid , 'BOTTOM-TOP_GRID_DIMSNSION' ,   kde_compare , 1 , icnt , ierr3 )
435 
436        !  Test to make sure that the input data is the right size.
437 
438        IF ( ( ide-1 .NE. ide_compare    ) .OR. &
439             ( kde   .NE. kde_compare    ) .OR. &
440             ( jde-1 .NE. jde_compare    ) .AND. ierr3 .EQ. 0 ) THEN
441           WRITE(wrf_err_message,*)'input_wrf.F: SIZE MISMATCH:  namelist ide-1,jde-1,kde=',ide-1,jde-1,kde,&
442                                   '; input data ide,jde,kde=',ide_compare , jde_compare , kde_compare
443           CALL wrf_debug( 100, wrf_err_message )
444        ENDIF
445 
446        ELSEIF ( switch .EQ. aux_model_input1_only ) THEN          ! assume just WPS in this branch
447          IF ( ( ide-1                           .NE. ide_compare ) .OR. &
448             ( config_flags%num_metgrid_levels .NE. kde_compare ) .OR. &
449             ( jde-1                             .NE. jde_compare ) .AND. ierr3 .EQ. 0 ) THEN
450                 WRITE(wrf_err_message,*)'input_wrf.F: SIZE MISMATCH:  ',&
451                  'namelist ide-1,jde-1,num_metgrid_levels=',ide-1,jde-1,config_flags%num_metgrid_levels,&
452                  '; input data ide,jde,num_metgrid_levels=',ide_compare , jde_compare , kde_compare
453                 IF (ide-1 .eq. ide_compare .AND. jde-1 .EQ. jde_compare) THEN
454                   CALL wrf_message(wrf_err_message)
455                   CALL wrf_error_fatal( "appears that the vertical dimension is wrong - quitting" )
456                 ELSE
457                   CALL wrf_message(wrf_err_message)
458                   CALL wrf_error_fatal( "appears that I or J dimensions are wrong - quitting" )
459                 ENDIF
460          ENDIF
461        ENDIF
462 
463 #endif
464 
465 
466     IF ( dyn_opt_tmp .NE. dyn_opt .AND. switch .EQ. model_input_only ) THEN
467       WRITE(wrf_err_message,*)'input_wrf: dyn_opt in file ',dyn_opt_tmp,' NE namelist ',dyn_opt
468       CALL wrf_error_fatal( wrf_err_message )
469     ENDIF
470 
471     ENDIF check_if_dryrun 
472 
473 !
474 ! This call to wrf_get_next_time will position the dataset over the next time-frame
475 ! in the file and return the current_date, which is used as an argument to the
476 ! read_field routines in the blocks of code included below.  Note that we read the
477 ! next time *after* all the meta data has been read. This is only important for the
478 ! WRF internal I/O format because it is order-dependent. Other formats shouldn't care
479 ! about this.
480 !
481 
482     3003 continue
483 
484     CALL wrf_get_next_time(fid, current_date , ierr)
485     WRITE(wrf_err_message,*)fid,' input_wrf: wrf_get_next_time current_date: ',current_date(1:19),' Status = ',ierr
486     CALL wrf_debug ( 300 , TRIM(wrf_err_message ) )
487     IF ( ierr .NE. 0 .AND. ierr .NE. WRF_WARN_NOTSUPPORTED .AND. ierr .NE. WRF_WARN_DRYRUN_READ ) THEN 
488       CALL wrf_message ( TRIM(wrf_err_message ) )
489       IF ( switch .EQ. boundary_only ) THEN
490         WRITE(wrf_err_message,*) ' ... May have run out of valid boundary conditions in file ',TRIM(fname)
491         CALL wrf_error_fatal( TRIM(wrf_err_message) )
492       ELSE
493 #if ( NMM_CORE != 1 )
494         WRITE(wrf_err_message,*) '... Could not find matching time in input file ',TRIM(fname)
495         CALL wrf_error_fatal( TRIM(wrf_err_message) )
496 #endif
497       ENDIF
498     ELSE IF ( ierr .NE. WRF_WARN_NOTSUPPORTED .AND. ierr .NE. WRF_WARN_DRYRUN_READ) THEN 
499 !
500 ! check input time against domain time (which will be start time at beginning, see share/set_timekeeping.F)
501 ! JM 20040511
502 !
503       SELECT CASE ( switch )
504         CASE ( model_input_only, aux_model_input1_only, aux_model_input2_only,       &
505                aux_model_input3_only, aux_model_input4_only, aux_model_input5_only, aux_model_input10_only )
506 #ifdef WRF_CHEM
507            IF( (config_flags%io_style_emissions .eq. 1) .and.                       &
508               ((switch.eq.aux_model_input4_only) .or. (switch.eq.aux_model_input5_only)) )then
509                CALL wrf_message( "**WARNING** Time in input file not being checked **WARNING**" )
510            ELSE
511 #endif
512             CALL wrf_atotime( current_date(1:19), time )
513             CALL domain_clock_get( grid, current_time=currtime, &
514                                          current_timestr=currtimestr )
515 #if (DA_CORE != 1)
516 ! Don't perform the check for WRFVAR, as we're not passing the right dates 
517 ! around
518             CALL domain_clockprint(150, grid, &
519                    'DEBUG input_wrf():  get CurrTime from clock,')
520             IF ( time .NE. currtime ) THEN
521                 WRITE( wrf_err_message , * )'Time in file: ',trim( current_date(1:19) )
522                 CALL wrf_message ( trim(wrf_err_message) )
523                 WRITE( wrf_err_message , * )'Time on domain: ',trim( currtimestr )
524                 CALL wrf_message ( trim(wrf_err_message) )
525                 CALL wrf_message( "**WARNING** Time in input file not equal to time on domain **WARNING**" )
526                 WRITE(wrf_err_message,*) "**WARNING** Trying next time in file ",TRIM(fname)," ..."
527                 CALL wrf_message( TRIM(wrf_err_message) )
528                 GOTO 3003
529             ENDIF
530 #endif
531 #ifdef WRF_CHEM
532             ENDIF
533 #endif
534         CASE DEFAULT
535       END SELECT
536     ENDIF
537 
538 ! set the lbc time interval fields in the domain data structure
539 ! these time values are checked as stopping condition for the while loop in 
540 ! latbound_in() defined in share/medation_integrate.F, which is used to
541 ! iterate forward to the correct interval in the input LBC file
542 ! 
543     IF ( switch .EQ. boundary_only ) THEN
544         CALL wrf_get_dom_td_char ( fid , 'THISBDYTIME' ,  current_date(1:19), this_datestr , ierr )
545         CALL wrf_atotime( this_datestr(1:19), grid%this_bdy_time )
546         CALL wrf_get_dom_td_char ( fid , 'NEXTBDYTIME' ,  current_date(1:19), next_datestr , ierr )
547         CALL wrf_atotime( next_datestr(1:19), grid%next_bdy_time )
548     ENDIF
549 
550 #if 1
551     IF      ( switch .EQ. model_input_only ) THEN
552       CALL wrf_inputin( fid , grid , config_flags , switch , ierr )
553     ELSE IF ( switch .EQ. history_only ) THEN
554       CALL wrf_histin( fid , grid , config_flags , switch , ierr )
555     ELSE IF ( switch .EQ. aux_model_input1_only ) THEN
556       CALL wrf_auxinput1in( fid , grid , config_flags , switch , ierr )
557     ELSE IF ( switch .EQ. aux_model_input2_only ) THEN
558       CALL wrf_auxinput2in( fid , grid , config_flags , switch , ierr )
559     ELSE IF ( switch .EQ. aux_model_input3_only ) THEN
560       CALL wrf_auxinput3in( fid , grid , config_flags , switch , ierr )
561     ELSE IF ( switch .EQ. aux_model_input4_only ) THEN
562       CALL wrf_auxinput4in( fid , grid , config_flags , switch , ierr )
563     ELSE IF ( switch .EQ. aux_model_input5_only ) THEN
564       CALL wrf_auxinput5in( fid , grid , config_flags , switch , ierr )
565     ELSE IF ( switch .EQ. aux_model_input6_only ) THEN
566       CALL wrf_auxinput6in( fid , grid , config_flags , switch , ierr )
567     ELSE IF ( switch .EQ. aux_model_input7_only ) THEN
568       CALL wrf_auxinput7in( fid , grid , config_flags , switch , ierr )
569     ELSE IF ( switch .EQ. aux_model_input8_only ) THEN
570       CALL wrf_auxinput8in( fid , grid , config_flags , switch , ierr )
571     ELSE IF ( switch .EQ. aux_model_input9_only ) THEN
572       CALL wrf_auxinput9in( fid , grid , config_flags , switch , ierr )
573     ELSE IF ( switch .EQ. aux_model_input10_only ) THEN
574       CALL wrf_auxinput10in( fid , grid , config_flags , switch , ierr )
575     ELSE IF ( switch .EQ. aux_model_input11_only ) THEN
576       CALL wrf_auxinput11in( fid , grid , config_flags , switch , ierr )
577 
578 
579     ELSE IF ( switch .EQ. aux_hist1_only ) THEN
580       CALL wrf_auxhist1in( fid , grid , config_flags , switch , ierr )
581     ELSE IF ( switch .EQ. aux_hist2_only ) THEN
582       CALL wrf_auxhist2in( fid , grid , config_flags , switch , ierr )
583     ELSE IF ( switch .EQ. aux_hist3_only ) THEN
584       CALL wrf_auxhist3in( fid , grid , config_flags , switch , ierr )
585     ELSE IF ( switch .EQ. aux_hist4_only ) THEN
586       CALL wrf_auxhist4in( fid , grid , config_flags , switch , ierr )
587     ELSE IF ( switch .EQ. aux_hist5_only ) THEN
588       CALL wrf_auxhist5in( fid , grid , config_flags , switch , ierr )
589     ELSE IF ( switch .EQ. aux_hist6_only ) THEN
590       CALL wrf_auxhist6in( fid , grid , config_flags , switch , ierr )
591     ELSE IF ( switch .EQ. aux_hist7_only ) THEN
592       CALL wrf_auxhist7in( fid , grid , config_flags , switch , ierr )
593     ELSE IF ( switch .EQ. aux_hist8_only ) THEN
594       CALL wrf_auxhist8in( fid , grid , config_flags , switch , ierr )
595     ELSE IF ( switch .EQ. aux_hist9_only ) THEN
596       CALL wrf_auxhist9in( fid , grid , config_flags , switch , ierr )
597     ELSE IF ( switch .EQ. aux_hist10_only ) THEN
598       CALL wrf_auxhist10in( fid , grid , config_flags , switch , ierr )
599     ELSE IF ( switch .EQ. aux_hist11_only ) THEN
600       CALL wrf_auxhist11in( fid , grid , config_flags , switch , ierr )
601 
602     ELSE IF ( switch .EQ. restart_only ) THEN
603       CALL wrf_restartin( fid , grid , config_flags , switch , ierr )
604     ELSE IF ( switch .EQ. boundary_only ) THEN
605       CALL wrf_bdyin( fid , grid , config_flags , switch , ierr )
606     ENDIF
607 #else
608     CALL wrf_message ( "ALL I/O DISABLED IN share/module_io_wrf.F")
609 #endif
610 
611     WRITE(wrf_err_message,*)'input_wrf: end, fid = ',fid
612     CALL wrf_debug( 300 , wrf_err_message )
613 
614     RETURN
615   END SUBROUTINE input_wrf