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