1 MODULE module_wps_io_arw
3 USE module_optional_input
8 ! The numerical data types defined in this module are:
9 ! i_byte - specification kind for byte (1-byte) integer variable
10 ! i_short - specification kind for short (2-byte) integer variable
11 ! i_long - specification kind for long (4-byte) integer variable
12 ! i_llong - specification kind for double long (8-byte) integer variable
13 ! r_single - specification kind for single precision (4-byte) real variable
14 ! r_double - specification kind for double precision (8-byte) real variable
15 ! r_quad - specification kind for quad precision (16-byte) real variable
17 ! i_kind - generic specification kind for default integer
18 ! r_kind - generic specification kind for default floating point
21 ! Integer type definitions below
24 integer, parameter, public :: i_byte = selected_int_kind(1) ! byte integer
25 integer, parameter, public :: i_short = selected_int_kind(4) ! short integer
26 ! integer, parameter, public :: i_long = selected_int_kind(8) ! long integer
27 integer, parameter, public :: i_long = kind(1) ! long integer
28 integer, parameter, private :: llong_t = selected_int_kind(16) ! llong integer
29 integer, parameter, public :: i_llong = max( llong_t, i_long )
31 ! Expected 8-bit byte sizes of the integer kinds
32 integer, parameter, public :: num_bytes_for_i_byte = 1
33 integer, parameter, public :: num_bytes_for_i_short = 2
34 integer, parameter, public :: num_bytes_for_i_long = 4
35 integer, parameter, public :: num_bytes_for_i_llong = 8
37 ! Define arrays for default definition
38 integer, parameter, private :: num_i_kinds = 4
39 integer, parameter, dimension( num_i_kinds ), private :: integer_types = (/ &
40 i_byte, i_short, i_long, i_llong /)
41 integer, parameter, dimension( num_i_kinds ), private :: integer_byte_sizes = (/ &
42 num_bytes_for_i_byte, num_bytes_for_i_short, &
43 num_bytes_for_i_long, num_bytes_for_i_llong /)
46 ! **** CHANGE THE FOLLOWING TO CHANGE THE DEFAULT INTEGER TYPE KIND ***
47 integer, parameter, private :: default_integer = 2 ! 1=byte,
51 integer, parameter, public :: i_kind = integer_types( default_integer )
52 integer, parameter, public :: num_bytes_for_i_kind = &
53 integer_byte_sizes( default_integer )
56 ! Real definitions below
59 integer, parameter, public :: r_single = selected_real_kind(6) ! single precision
60 integer, parameter, public :: r_double = selected_real_kind(15) ! double precision
61 integer, parameter, private :: quad_t = selected_real_kind(20) ! quad precision
62 integer, parameter, public :: r_quad = max( quad_t, r_double )
64 ! Expected 8-bit byte sizes of the real kinds
65 integer, parameter, public :: num_bytes_for_r_single = 4
66 integer, parameter, public :: num_bytes_for_r_double = 8
67 integer, parameter, public :: num_bytes_for_r_quad = 16
69 ! Define arrays for default definition
70 integer, parameter, private :: num_r_kinds = 3
71 integer, parameter, dimension( num_r_kinds ), private :: real_kinds = (/ &
72 r_single, r_double, r_quad /)
73 integer, parameter, dimension( num_r_kinds ), private :: real_byte_sizes = (/ &
74 num_bytes_for_r_single, num_bytes_for_r_double, &
75 num_bytes_for_r_quad /)
78 ! **** CHANGE THE FOLLOWING TO CHANGE THE DEFAULT REAL TYPE KIND ***
79 integer, parameter, private :: default_real = 2 ! 1=single,
81 !! END FROM MODULE_KINDS
83 ! Input 3D meteorological fields.
86 REAL , DIMENSION(:,:,:) , ALLOCATABLE :: landuse_frac_input , &
87 soil_top_cat_input , &
91 ! Input 2D surface fields.
93 REAL , DIMENSION(:,:) , ALLOCATABLE :: soilt010_input , soilt040_input , &
94 soilt100_input , soilt200_input , &
95 soilm010_input , soilm040_input , &
96 soilm100_input , soilm200_input , &
99 REAL , DIMENSION(:,:) , ALLOCATABLE :: lat_wind, lon_wind
104 REAL,DIMENSION(:,:),ALLOCATABLE :: dum2d
105 INTEGER,DIMENSION(:,:),ALLOCATABLE :: idum2d
106 REAL,DIMENSION(:,:,:),ALLOCATABLE :: dum3d
108 LOGICAL , SAVE :: first_time_in = .TRUE.
110 INTEGER :: flag_soilt010 , flag_soilt100 , flag_soilt200 , &
111 flag_soilm010 , flag_soilm100 , flag_soilm200
113 ! Some constants to allow simple dimensions in the defined types
116 CHARACTER (LEN=256) , PRIVATE :: a_message
121 SUBROUTINE read_wps ( grid, filename, file_date_string, num_metgrid_levels )
128 TYPE(domain) , INTENT(INOUT) :: grid
129 CHARACTER (LEN=19) , INTENT(IN) :: file_date_string
130 CHARACTER (LEN=4) :: dummychar
131 CHARACTER (LEN=132) :: VarName
132 CHARACTER (LEN=150) :: chartemp
133 CHARACTER (*) , INTENT(IN) :: filename
135 INTEGER :: ids,ide,jds,jde,kds,kde &
136 ,ims,ime,jms,jme,kms,kme &
137 ,its,ite,jts,jte,kts,kte
139 INTEGER :: i , j , k , loop, IMAX, JMAX
140 INTEGER :: DATAHANDLE, num_metgrid_levels
141 INTEGER :: Sysdepinfo, Status
142 INTEGER :: istatus,ioutcount,iret,index,ierr
144 integer :: nrecs,iunit, L,hor_size,hor_size_u,hor_size_v
147 character*132, allocatable :: datestr_all(:)
148 character*132, allocatable :: varname_all(:)
149 integer, allocatable :: domainend_all(:,:)
150 integer, allocatable :: start_block(:)
151 integer, allocatable :: end_block(:)
152 integer, allocatable :: start_byte(:)
153 integer, allocatable :: end_byte(:)
154 integer(kind=i_llong), allocatable :: file_offset(:)
157 REAL :: dummy,tmp,garb
158 REAL, ALLOCATABLE:: dumdata(:,:,:)
159 REAL, ALLOCATABLE:: dumdata_u(:,:,:)
160 REAL, ALLOCATABLE:: dumdata_v(:,:,:)
162 REAL :: lats16(16),lons16(16)
164 CHARACTER (LEN= 8) :: dummy_char
166 INTEGER :: ok , map_proj , ok_open, igarb,igarb2, N
168 INTEGER :: num_veg_cat , num_soil_top_cat , num_soil_bot_cat
170 #if defined(DM_PARALLEL) && !defined(STUBMPI)
173 SELECT CASE ( model_data_order )
174 CASE ( DATA_ORDER_ZXY )
175 kds = grid%sd31 ; kde = grid%ed31 ;
176 ids = grid%sd32 ; ide = grid%ed32 ;
177 jds = grid%sd33 ; jde = grid%ed33 ;
179 kms = grid%sm31 ; kme = grid%em31 ;
180 ims = grid%sm32 ; ime = grid%em32 ;
181 jms = grid%sm33 ; jme = grid%em33 ;
183 kts = grid%sp31 ; kte = grid%ep31 ; ! tile is entire patch
184 its = grid%sp32 ; ite = grid%ep32 ; ! tile is entire patch
185 jts = grid%sp33 ; jte = grid%ep33 ; ! tile is entire patch
187 CASE ( DATA_ORDER_XYZ )
188 ids = grid%sd31 ; ide = grid%ed31 ;
189 jds = grid%sd32 ; jde = grid%ed32 ;
190 kds = grid%sd33 ; kde = grid%ed33 ;
192 ims = grid%sm31 ; ime = grid%em31 ;
193 jms = grid%sm32 ; jme = grid%em32 ;
194 kms = grid%sm33 ; kme = grid%em33 ;
196 its = grid%sp31 ; ite = grid%ep31 ; ! tile is entire patch
197 jts = grid%sp32 ; jte = grid%ep32 ; ! tile is entire patch
198 kts = grid%sp33 ; kte = grid%ep33 ; ! tile is entire patch
200 CASE ( DATA_ORDER_XZY )
201 ids = grid%sd31 ; ide = grid%ed31 ;
202 kds = grid%sd32 ; kde = grid%ed32 ;
203 jds = grid%sd33 ; jde = grid%ed33 ;
205 ims = grid%sm31 ; ime = grid%em31 ;
206 kms = grid%sm32 ; kme = grid%em32 ;
207 jms = grid%sm33 ; jme = grid%em33 ;
209 its = grid%sp31 ; ite = grid%ep31 ; ! tile is entire patch
210 kts = grid%sp32 ; kte = grid%ep32 ; ! tile is entire patch
211 jts = grid%sp33 ; jte = grid%ep33 ; ! tile is entire patch
215 ! Initialize what soil temperature and moisture is available.
241 ! How many soil levels have we found? Well, right now, none.
243 num_st_levels_input = 0
244 num_sm_levels_input = 0
248 ! Get the space for the data if this is the first time here.
251 IF (.NOT. ALLOCATED (pmsl) ) ALLOCATE ( pmsl(its:ite,jts:jte) )
252 IF (.NOT. ALLOCATED (psfc_in) ) ALLOCATE ( psfc_in(its:ite,jts:jte) )
257 call count_recs_wrf_binary_file(iunit, trim(fileName), nrecs)
259 allocate (datestr_all(nrecs))
260 allocate (varname_all(nrecs))
261 allocate (domainend_all(3,nrecs))
262 allocate (start_block(nrecs))
263 allocate (end_block(nrecs))
264 allocate (start_byte(nrecs))
265 allocate (end_byte(nrecs))
266 allocate (file_offset(nrecs))
268 call inventory_wrf_binary_file(iunit, trim(filename), nrecs, &
269 datestr_all,varname_all,domainend_all, &
270 start_block,end_block,start_byte,end_byte,file_offset)
272 call mpi_file_open(mpi_comm_world, trim(filename), &
273 mpi_mode_rdonly,mpi_info_null, iunit, ierr)
275 call wrf_error_fatal("Error opening file with mpi io")
279 call retrieve_index(index,VarName,varname_all,nrecs,iret)
281 print*,VarName," not found in file"
284 call mpi_file_read_at(iunit,file_offset(index)+5*4, &
286 mpi_status_ignore, ierr)
289 print*,"Error reading ", VarName," using MPIIO"
291 print*,VarName, ' from MPIIO READ= ',garb
292 CALL nl_set_cen_lat ( grid%id , garb )
297 call retrieve_index(index,VarName,varname_all,nrecs,iret)
298 call mpi_file_read_at(iunit,file_offset(index)+5*4, &
300 mpi_status_ignore, ierr)
301 CALL nl_set_cen_lon ( grid%id , garb )
302 CALL nl_set_stand_lon ( grid%id , garb )
305 call retrieve_index(index,VarName,varname_all,nrecs,iret)
306 call mpi_file_read_at(iunit,file_offset(index)+5*4, &
308 mpi_status_ignore, ierr)
309 CALL nl_set_pole_lat ( grid%id , garb )
312 call retrieve_index(index,VarName,varname_all,nrecs,iret)
313 call mpi_file_read_at(iunit,file_offset(index)+5*4, &
315 mpi_status_ignore, ierr)
316 CALL nl_set_truelat1 ( grid%id , garb )
319 call retrieve_index(index,VarName,varname_all,nrecs,iret)
320 call mpi_file_read_at(iunit,file_offset(index)+5*4, &
322 mpi_status_ignore, ierr)
323 CALL nl_set_truelat2 ( grid%id , garb )
326 call retrieve_index(index,VarName,varname_all,nrecs,iret)
328 call mpi_file_read_at(iunit,file_offset(index)+5*4, &
329 igarb,1,mpi_integer4, &
330 mpi_status_ignore, ierr)
332 CALL nl_set_map_proj( grid%id, igarb)
335 call retrieve_index(index,VarName,varname_all,nrecs,iret)
336 call mpi_file_read_at(iunit,file_offset(index)+5*4, &
337 igarb,1,mpi_integer4, &
338 mpi_status_ignore, ierr)
339 CALL nl_set_isurban ( grid%id, igarb)
342 call retrieve_index(index,VarName,varname_all,nrecs,iret)
343 call mpi_file_read_at(iunit,file_offset(index)+5*4, &
344 igarb,1,mpi_integer4, &
345 mpi_status_ignore, ierr)
346 write(a_message,*) 'setting iswater to be: ', igarb
347 CALL wrf_message ( a_message )
348 CALL nl_set_iswater (grid%id, igarb )
351 call retrieve_index(index,VarName,varname_all,nrecs,iret)
352 call mpi_file_read_at(iunit,file_offset(index)+5*4, &
353 igarb2,1,mpi_integer4, &
354 mpi_status_ignore, ierr)
355 write(a_message,*) 'setting isice to be: ', igarb2
356 CALL wrf_message ( a_message )
357 CALL nl_set_isice (grid%id, igarb2 )
359 IF ( igarb .eq. 16 .and. igarb2 .eq. 24 ) THEN
360 CALL nl_set_mminlu ( grid%id, 'USGS')
363 IF ( igarb .eq. 17 .and. igarb2 .eq. 15 ) THEN
365 CALL nl_set_mminlu ( grid%id, 'MODIFIED_IGBP_MODIS_NOAH')
366 ! CALL nl_set_mminlu ( grid%id, 'MODIS')
369 IF ( igarb .eq. 15 .and. igarb2 .eq. 16 ) THEN
370 CALL nl_set_mminlu ( grid%id, 'SiB')
374 call retrieve_index(index,VarName,varname_all,nrecs,iret)
375 call mpi_file_read_at(iunit,file_offset(index)+5*4, &
376 igarb,1,mpi_integer4, &
377 mpi_status_ignore, ierr)
381 call retrieve_index(index,VarName,varname_all,nrecs,iret)
382 call mpi_file_read_at(iunit,file_offset(index)+5*4, &
383 igarb,1,mpi_integer4, &
384 mpi_status_ignore, ierr)
387 VarName='FLAG_METGRID'
388 call retrieve_index(index,VarName,varname_all,nrecs,iret)
389 if (iret .eq. 0) then
390 call mpi_file_read_at(iunit,file_offset(index)+5*4, &
391 igarb,1,mpi_integer4, &
392 mpi_status_ignore, ierr)
396 VarName='FLAG_SOILHGT'
397 call retrieve_index(index,VarName,varname_all,nrecs,iret)
398 if (iret .eq. 0) then
399 call mpi_file_read_at(iunit,file_offset(index)+5*4, &
400 igarb,1,mpi_integer4, &
401 mpi_status_ignore, ierr)
406 call retrieve_index(index,VarName,varname_all,nrecs,iret)
407 if (iret .eq. 0) then
408 call mpi_file_read_at(iunit,file_offset(index)+5*4, &
409 igarb,1,mpi_integer4, &
410 mpi_status_ignore, ierr)
415 call retrieve_index(index,VarName,varname_all,nrecs,iret)
416 if (iret .eq. 0) then
417 call mpi_file_read_at(iunit,file_offset(index)+5*4, &
418 igarb,1,mpi_integer4, &
419 mpi_status_ignore, ierr)
423 VarName='NUM_METGRID_SOIL_LEVELS'
424 call retrieve_index(index,VarName,varname_all,nrecs,iret)
425 call mpi_file_read_at(iunit,file_offset(index)+5*4, &
426 igarb,1,mpi_integer4, &
427 mpi_status_ignore, ierr)
429 CALL nl_set_num_metgrid_soil_levels(grid%id, igarb)
430 num_sw_levels_input=igarb
433 VarName='FLAG_SOIL_LEVELS'
434 call retrieve_index(index,VarName,varname_all,nrecs,iret)
435 if (iret .eq. 0) then
436 call mpi_file_read_at(iunit,file_offset(index)+5*4, &
437 igarb,1,mpi_integer4, &
438 mpi_status_ignore, ierr)
439 flag_soil_levels=igarb
443 VarName='FLAG_SOIL_LAYERS'
444 call retrieve_index(index,VarName,varname_all,nrecs,iret)
445 call mpi_file_read_at(iunit,file_offset(index)+5*4, &
446 igarb,1,mpi_integer4, &
447 mpi_status_ignore, ierr)
448 flag_soil_layers=igarb
453 call retrieve_index(index,VarName,varname_all,nrecs,iret)
454 call mpi_file_read_at(iunit,file_offset(index)+5*4, &
455 igarb,1,mpi_integer4, &
456 mpi_status_ignore, ierr)
457 CALL nl_set_islake ( grid%id, igarb)
460 call retrieve_index(index,VarName,varname_all,nrecs,iret)
461 call mpi_file_read_at(iunit,file_offset(index)+5*4, &
462 igarb,1,mpi_integer4, &
463 mpi_status_ignore, ierr)
464 CALL nl_set_isoilwater ( grid%id, igarb)
466 VarName='MOAD_CEN_LAT'
467 call retrieve_index(index,VarName,varname_all,nrecs,iret)
468 call mpi_file_read_at(iunit,file_offset(index)+5*4, &
470 mpi_status_ignore, ierr)
471 CALL nl_set_moad_cen_lat ( grid%id,garb)
473 VarName='corner_lats'
474 call retrieve_index(index,VarName,varname_all,nrecs,iret)
475 call mpi_file_read_at(iunit,file_offset(index)+5*4, &
476 lats16,16,mpi_real4, &
477 mpi_status_ignore, ierr)
479 VarName='corner_lons'
480 call retrieve_index(index,VarName,varname_all,nrecs,iret)
481 call mpi_file_read_at(iunit,file_offset(index)+5*4, &
482 lons16,16,mpi_real4, &
483 mpi_status_ignore, ierr)
486 ! call retrieve_index(index,VarName,varname_all,nrecs,iret)
487 ! if (iret .eq. 0) then
488 ! call mpi_file_read_at(iunit,file_offset(index)+5*4, &
489 ! dummychar,1,mpi_char, &
490 ! mpi_status_ignore, ierr)
493 hor_size=(IDE-IDS)*(JDE-JDS)
494 hor_size_u=(IDE+1-IDS)*(JDE-JDS)
495 hor_size_v=(IDE-IDS)*(JDE+1-JDS)
498 allocate(dumdata(IDS:IDE-1,JDS:JDE-1,num_metgrid_levels))
499 allocate(dumdata_u(IDS:IDE,JDS:JDE-1,num_metgrid_levels))
500 allocate(dumdata_v(IDS:IDE-1,JDS:JDE,num_metgrid_levels))
502 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
503 CALL mpi_file_read_at(iunit,file_offset(index+1), &
504 dumdata,hor_size*num_metgrid_levels,mpi_real4, &
505 mpi_status_ignore, ierr)
508 DO K=1,num_metgrid_levels
509 DO J=JTS,min(JTE,JDE-1)
510 DO I=ITS,min(ITE,IDE-1)
511 grid%p_gc(I,K,J)=dumdata(I,J,K)
518 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
519 CALL mpi_file_read_at(iunit,file_offset(index+1), &
520 dumdata,hor_size*num_metgrid_levels,mpi_real4, &
521 mpi_status_ignore, ierr)
524 DO K=1,num_metgrid_levels
525 DO J=JTS,min(JTE,JDE-1)
526 DO I=ITS,min(ITE,IDE-1)
527 grid%ght_gc(I,K,J)=dumdata(I,J,K)
533 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
534 CALL mpi_file_read_at(iunit,file_offset(index+1), &
535 dumdata,hor_size,mpi_real4, &
536 mpi_status_ignore, ierr)
538 DO J=JTS,min(JTE,JDE-1)
539 DO I=ITS,min(ITE,IDE-1)
540 grid%vegcat(I,J)=dumdata(I,J,1)
545 ! CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
546 ! CALL mpi_file_read_at(iunit,file_offset(index+1), &
547 ! dumdata,hor_size,mpi_real4, &
548 ! mpi_status_ignore, ierr)
549 ! DO J=JTS,min(JTE,JDE-1)
550 ! DO I=ITS,min(ITE,IDE-1)
551 ! grid%input_soil_cat(I,J)=dumdata(I,J,1)
556 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
557 CALL mpi_file_read_at(iunit,file_offset(index+1), &
558 dumdata,hor_size,mpi_real4, &
559 mpi_status_ignore, ierr)
561 DO J=JTS,min(JTE,JDE-1)
562 DO I=ITS,min(ITE,IDE-1)
563 grid%canwat(I,J)=dumdata(I,J,1)
568 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
569 CALL mpi_file_read_at(iunit,file_offset(index+1), &
570 dumdata,hor_size,mpi_real4, &
571 mpi_status_ignore, ierr)
572 DO J=JTS,min(JTE,JDE-1)
573 DO I=ITS,min(ITE,IDE-1)
574 grid%snow(I,J)=dumdata(I,J,1)
579 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
580 CALL mpi_file_read_at(iunit,file_offset(index+1), &
581 dumdata,hor_size,mpi_real4, &
582 mpi_status_ignore, ierr)
583 DO J=JTS,min(JTE,JDE-1)
584 DO I=ITS,min(ITE,IDE-1)
585 grid%snowh(I,J)=dumdata(I,J,1)
590 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
591 CALL mpi_file_read_at(iunit,file_offset(index+1), &
592 dumdata,hor_size,mpi_real4, &
593 mpi_status_ignore, ierr)
594 DO J=JTS,min(JTE,JDE-1)
595 DO I=ITS,min(ITE,IDE-1)
596 grid%tsk_gc(I,J)=dumdata(I,J,1)
601 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
602 CALL mpi_file_read_at(iunit,file_offset(index+1), &
603 dumdata,hor_size,mpi_real4, &
604 mpi_status_ignore, ierr)
605 DO J=JTS,min(JTE,JDE-1)
606 DO I=ITS,min(ITE,IDE-1)
607 grid%toposoil(I,J)=dumdata(I,J,1)
612 ! CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
613 ! CALL mpi_file_read_at(iunit,file_offset(index+1), &
614 ! dumdata,hor_size,mpi_real4, &
615 ! mpi_status_ignore, ierr)
616 ! DO J=JTS,min(JTE,JDE-1)
617 ! DO I=ITS,min(ITE,IDE-1)
618 ! grid%xice_gc(I,J)=dumdata(I,J,1)
623 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
624 CALL mpi_file_read_at(iunit,file_offset(index+1), &
625 dumdata,hor_size,mpi_real4, &
626 mpi_status_ignore, ierr)
627 DO J=JTS,min(JTE,JDE-1)
628 DO I=ITS,min(ITE,IDE-1)
629 grid%st100200(I,J)=dumdata(I,J,1)
634 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
635 CALL mpi_file_read_at(iunit,file_offset(index+1), &
636 dumdata,hor_size,mpi_real4, &
637 mpi_status_ignore, ierr)
638 DO J=JTS,min(JTE,JDE-1)
639 DO I=ITS,min(ITE,IDE-1)
640 grid%st040100(I,J)=dumdata(I,J,1)
645 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
646 CALL mpi_file_read_at(iunit,file_offset(index+1), &
647 dumdata,hor_size,mpi_real4, &
648 mpi_status_ignore, ierr)
650 DO J=JTS,min(JTE,JDE-1)
651 DO I=ITS,min(ITE,IDE-1)
652 grid%st010040(I,J)=dumdata(I,J,1)
657 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
658 CALL mpi_file_read_at(iunit,file_offset(index+1), &
659 dumdata,hor_size,mpi_real4, &
660 mpi_status_ignore, ierr)
662 DO J=JTS,min(JTE,JDE-1)
663 DO I=ITS,min(ITE,IDE-1)
664 grid%st000010(I,J)=dumdata(I,J,1)
669 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
670 CALL mpi_file_read_at(iunit,file_offset(index+1), &
671 dumdata,hor_size,mpi_real4, &
672 mpi_status_ignore, ierr)
674 DO J=JTS,min(JTE,JDE-1)
675 DO I=ITS,min(ITE,IDE-1)
676 grid%sm100200(I,J)=dumdata(I,J,1)
681 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
682 CALL mpi_file_read_at(iunit,file_offset(index+1), &
683 dumdata,hor_size,mpi_real4, &
684 mpi_status_ignore, ierr)
686 DO J=JTS,min(JTE,JDE-1)
687 DO I=ITS,min(ITE,IDE-1)
688 grid%sm040100(I,J)=dumdata(I,J,1)
693 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
694 CALL mpi_file_read_at(iunit,file_offset(index+1), &
695 dumdata,hor_size,mpi_real4, &
696 mpi_status_ignore, ierr)
698 DO J=JTS,min(JTE,JDE-1)
699 DO I=ITS,min(ITE,IDE-1)
700 grid%sm010040(I,J)=dumdata(I,J,1)
705 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
706 CALL mpi_file_read_at(iunit,file_offset(index+1), &
707 dumdata,hor_size,mpi_real4, &
708 mpi_status_ignore, ierr)
710 DO J=JTS,min(JTE,JDE-1)
711 DO I=ITS,min(ITE,IDE-1)
712 grid%sm000010(I,J)=dumdata(I,J,1)
717 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
718 CALL mpi_file_read_at(iunit,file_offset(index+1), &
719 dumdata,hor_size,mpi_real4, &
720 mpi_status_ignore, ierr)
722 if ( ierr .eq. 0 ) flag_psfc=1
724 DO J=JTS,min(JTE,JDE-1)
725 DO I=ITS,min(ITE,IDE-1)
726 grid%psfc(I,J)=dumdata(I,J,1)
731 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
732 CALL mpi_file_read_at(iunit,file_offset(index+1), &
733 dumdata,hor_size*num_metgrid_levels,mpi_real4, &
734 mpi_status_ignore, ierr)
736 DO K=1,num_metgrid_levels
737 DO J=JTS,min(JTE,JDE-1)
738 DO I=ITS,min(ITE,IDE-1)
739 grid%rh_gc(I,K,J)=dumdata(I,J,K)
745 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
746 CALL mpi_file_read_at(iunit,file_offset(index+1), &
747 dumdata_v,hor_size_v*num_metgrid_levels,mpi_real4, &
748 mpi_status_ignore, ierr)
750 DO K=1,num_metgrid_levels
751 DO J=JTS,min(JTE,JDE)
752 DO I=ITS,min(ITE,IDE-1)
753 grid%v_gc(I,K,J)=dumdata_v(I,J,K)
754 if (grid%v_gc(I,K,J) .ne. grid%v_gc(I,K,J) .or. abs(grid%v_gc(I,K,J)) .gt. 100.) then
755 write(a_message,*) 'bad v_gc defined: ', I,K,J,grid%v_gc(I,K,J)
756 CALL wrf_message ( a_message )
757 call wrf_error_fatal(" bad v_gc")
764 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
765 CALL mpi_file_read_at(iunit,file_offset(index+1), &
766 dumdata_u,hor_size_u*num_metgrid_levels,mpi_real4, &
767 mpi_status_ignore, ierr)
768 DO K=1,num_metgrid_levels
769 DO J=JTS,min(JTE,JDE-1)
770 DO I=ITS,min(ITE,IDE)
771 grid%u_gc(I,K,J)=dumdata_u(I,J,K)
772 if (grid%u_gc(I,K,J) .ne. grid%u_gc(I,K,J) .or. abs(grid%u_gc(I,K,J)) .gt. 100.) then
773 write(a_message,*) 'bad u_gc defined: ', I,K,J,grid%u_gc(I,K,J)
774 CALL wrf_message ( a_message )
775 call wrf_error_fatal(" bad u_gc")
782 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
783 CALL mpi_file_read_at(iunit,file_offset(index+1), &
784 dumdata,hor_size*num_metgrid_levels,mpi_real4, &
785 mpi_status_ignore, ierr)
786 DO K=1,num_metgrid_levels
787 DO J=JTS,min(JTE,JDE-1)
788 DO I=ITS,min(ITE,IDE-1)
789 grid%t_gc(I,K,J)=dumdata(I,J,K)
790 if (grid%t_gc(I,K,J) .ne. grid%t_gc(I,K,J) .or. abs(grid%t_gc(I,K,J)) .gt. 350.) then
791 write(a_message,*) 'bad t_gc defined: ', I,K,J,grid%t_gc(I,K,J)
792 CALL wrf_message ( a_message )
793 call wrf_error_fatal(" bad t_gc")
800 ! CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
801 ! CALL mpi_file_read_at(iunit,file_offset(index+1), &
802 ! dumdata,hor_size*num_metgrid_levels,mpi_real4, &
803 ! mpi_status_ignore, ierr)
804 ! DO K=1,num_metgrid_levels
805 ! DO J=JTS,min(JTE,JDE-1)
806 ! DO I=ITS,min(ITE,IDE-1)
807 ! grid%nmm_rwmr_gc(I,J,K)=dumdata(I,J,K)
813 ! CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
814 ! CALL mpi_file_read_at(iunit,file_offset(index+1), &
815 ! dumdata,hor_size*num_metgrid_levels,mpi_real4, &
816 ! mpi_status_ignore, ierr)
817 ! DO K=1,num_metgrid_levels
818 ! DO J=JTS,min(JTE,JDE-1)
819 ! DO I=ITS,min(ITE,IDE-1)
820 ! grid%nmm_snmr_gc(I,J,K)=dumdata(I,J,K)
826 ! CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
827 ! CALL mpi_file_read_at(iunit,file_offset(index+1), &
828 ! dumdata,hor_size*num_metgrid_levels,mpi_real4, &
829 ! mpi_status_ignore, ierr)
830 ! DO K=1,num_metgrid_levels
831 ! DO J=JTS,min(JTE,JDE-1)
832 ! DO I=ITS,min(ITE,IDE-1)
833 ! grid%nmm_clwmr_gc(I,J,K)=dumdata(I,J,K)
839 ! CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
840 ! CALL mpi_file_read_at(iunit,file_offset(index+1), &
841 ! dumdata,hor_size*num_metgrid_levels,mpi_real4, &
842 ! mpi_status_ignore, ierr)
843 ! DO K=1,num_metgrid_levels
844 ! DO J=JTS,min(JTE,JDE-1)
845 ! DO I=ITS,min(ITE,IDE-1)
846 ! grid%nmm_cice_gc(I,J,K)=dumdata(I,J,K)
852 ! CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
853 ! CALL mpi_file_read_at(iunit,file_offset(index+1), &
854 ! dumdata,hor_size*num_metgrid_levels,mpi_real4, &
855 ! mpi_status_ignore, ierr)
856 ! DO K=1,num_metgrid_levels
857 ! DO J=JTS,min(JTE,JDE-1)
858 ! DO I=ITS,min(ITE,IDE-1)
859 ! grid%nmm_rimef_gc(I,J,K)=dumdata(I,J,K)
866 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
867 CALL mpi_file_read_at(iunit,file_offset(index+1), &
868 dumdata,hor_size,mpi_real4, &
869 mpi_status_ignore, ierr)
870 DO J=JTS,min(JTE,JDE-1)
871 DO I=ITS,min(ITE,IDE-1)
872 grid%pslv_gc(I,J)=dumdata(I,J,1)
878 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
879 CALL mpi_file_read_at(iunit,file_offset(index+1), &
880 dumdata,hor_size,mpi_real4, &
881 mpi_status_ignore, ierr)
883 DO J=JTS,min(JTE,JDE-1)
884 DO I=ITS,min(ITE,IDE-1)
885 grid%snoalb(I,J)=dumdata(I,J,1)
889 num_veg_cat = SIZE ( grid%landusef , DIM=2 )
890 num_soil_top_cat = SIZE ( grid%soilctop , DIM=2 )
891 num_soil_bot_cat = SIZE ( grid%soilcbot , DIM=2 )
894 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
895 CALL mpi_file_read_at(iunit,file_offset(index+1), &
896 dumdata,hor_size*12,mpi_real4, &
897 mpi_status_ignore, ierr)
900 DO J=JTS,min(JTE,JDE-1)
901 DO I=ITS,min(ITE,IDE-1)
902 grid%greenfrac(I,K,J)=dumdata(I,J,K)
908 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
909 CALL mpi_file_read_at(iunit,file_offset(index+1), &
910 dumdata,hor_size*12,mpi_real4, &
911 mpi_status_ignore, ierr)
914 DO J=JTS,min(JTE,JDE-1)
915 DO I=ITS,min(ITE,IDE-1)
916 grid%albedo12m(I,K,J)=dumdata(I,J,K)
922 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
923 CALL mpi_file_read_at(iunit,file_offset(index+1), &
924 dumdata,hor_size*num_soil_bot_cat,mpi_real4, &
925 mpi_status_ignore, ierr)
927 DO K=1,num_soil_bot_cat
928 DO J=JTS,min(JTE,JDE-1)
929 DO I=ITS,min(ITE,IDE-1)
930 grid%soilcbot(I,K,J)=dumdata(I,J,K)
936 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
937 CALL mpi_file_read_at(iunit,file_offset(index+1), &
938 dumdata,hor_size,mpi_real4, &
939 mpi_status_ignore, ierr)
941 DO J=JTS,min(JTE,JDE-1)
942 DO I=ITS,min(ITE,IDE-1)
943 grid%soilcat(I,J)=dumdata(I,J,1)
947 write(a_message,*) 'veg_cat and soil_cat sizes:::: ', num_veg_cat , num_soil_top_cat
948 CALL wrf_message ( a_message )
951 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
952 CALL mpi_file_read_at(iunit,file_offset(index+1), &
953 dumdata,hor_size*num_soil_top_cat,mpi_real4, &
954 mpi_status_ignore, ierr)
955 DO K=1,num_soil_top_cat
956 DO J=JTS,min(JTE,JDE-1)
957 DO I=ITS,min(ITE,IDE-1)
958 grid%soilctop(I,K,J)=dumdata(I,J,K)
964 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
965 CALL mpi_file_read_at(iunit,file_offset(index+1), &
966 dumdata,hor_size,mpi_real4, &
967 mpi_status_ignore, ierr)
969 DO J=JTS,min(JTE,JDE-1)
970 DO I=ITS,min(ITE,IDE-1)
971 grid%tmn_gc(I,J)=dumdata(I,J,1)
976 ! CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
977 ! CALL mpi_file_read_at(iunit,file_offset(index+1), &
978 ! dumdata,hor_size,mpi_real4, &
979 ! mpi_status_ignore, ierr)
981 ! DO J=JTS,min(JTE,JDE-1)
982 ! DO I=ITS,min(ITE,IDE-1)
983 ! grid%nmm_htv_gc(I,J)=dumdata(I,J,1)
988 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
989 CALL mpi_file_read_at(iunit,file_offset(index+1), &
990 dumdata,hor_size,mpi_real4, &
991 mpi_status_ignore, ierr)
993 DO J=JTS,min(JTE,JDE-1)
994 DO I=ITS,min(ITE,IDE-1)
995 grid%ht_gc(I,J)=dumdata(I,J,1)
1000 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
1001 CALL mpi_file_read_at(iunit,file_offset(index+1), &
1002 dumdata,hor_size,mpi_real4, &
1003 mpi_status_ignore, ierr)
1005 DO J=JTS,min(JTE,JDE-1)
1006 DO I=ITS,min(ITE,IDE-1)
1007 grid%lu_index(I,J)=dumdata(I,J,1)
1012 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
1013 CALL mpi_file_read_at(iunit,file_offset(index+1), &
1014 dumdata,hor_size*num_veg_cat,mpi_real4, &
1015 mpi_status_ignore, ierr)
1018 DO J=JTS,min(JTE,JDE-1)
1019 DO I=ITS,min(ITE,IDE-1)
1020 grid%landusef(I,K,J)=dumdata(I,J,K)
1026 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
1027 CALL mpi_file_read_at(iunit,file_offset(index+1), &
1028 dumdata,hor_size,mpi_real4, &
1029 mpi_status_ignore, ierr)
1031 DO J=JTS,min(JTE,JDE-1)
1032 DO I=ITS,min(ITE,IDE-1)
1033 grid%landmask(I,J)=dumdata(I,J,1)
1038 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
1039 CALL mpi_file_read_at(iunit,file_offset(index+1), &
1040 dumdata,hor_size,mpi_real4, &
1041 mpi_status_ignore, ierr)
1042 DO J=JTS,min(JTE,JDE-1)
1043 DO I=ITS,min(ITE,IDE-1)
1044 grid%f(I,J)=dumdata(I,J,1)
1049 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
1050 CALL mpi_file_read_at(iunit,file_offset(index+1), &
1051 dumdata,hor_size,mpi_real4, &
1052 mpi_status_ignore, ierr)
1053 DO J=JTS,min(JTE,JDE-1)
1054 DO I=ITS,min(ITE,IDE-1)
1055 grid%e(I,J)=dumdata(I,J,1)
1060 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
1061 CALL mpi_file_read_at(iunit,file_offset(index+1), &
1062 dumdata,hor_size,mpi_real4, &
1063 mpi_status_ignore, ierr)
1064 DO J=JTS,min(JTE,JDE-1)
1065 DO I=ITS,min(ITE,IDE-1)
1066 grid%cosa(I,J)=dumdata(I,J,1)
1071 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
1072 CALL mpi_file_read_at(iunit,file_offset(index+1), &
1073 dumdata,hor_size,mpi_real4, &
1074 mpi_status_ignore, ierr)
1075 DO J=JTS,min(JTE,JDE-1)
1076 DO I=ITS,min(ITE,IDE-1)
1077 grid%sina(I,J)=dumdata(I,J,1)
1082 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
1083 CALL mpi_file_read_at(iunit,file_offset(index+1), &
1084 dumdata_u,hor_size_u,mpi_real4, &
1085 mpi_status_ignore, ierr)
1086 DO J=JTS,min(JTE,JDE-1)
1087 DO I=ITS,min(ITE,IDE)
1088 grid%msfu(I,J)=dumdata_u(I,J,1)
1090 !! bandaid for newly created WPS geogrid static files
1091 if (grid%msfu(I,J) .lt. 0.7) then
1092 write(a_message,*) 'weird msfu at I,J: ', I,J,grid%msfu(I,J)
1093 CALL wrf_message ( a_message )
1095 if(J .eq. min(JTE,JDE-1)) then
1096 grid%msfu(I,J)=dumdata_u(I,J-1,1)
1097 write(a_message,*) 'changing msfu to: ',I,J, grid%msfu(I,J)
1098 CALL wrf_message ( a_message )
1108 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
1109 CALL mpi_file_read_at(iunit,file_offset(index+1), &
1110 dumdata_v,hor_size_v,mpi_real4, &
1111 mpi_status_ignore, ierr)
1112 DO J=JTS,min(JTE,JDE)
1113 DO I=ITS,min(ITE,IDE-1)
1114 grid%msfv(I,J)=dumdata_v(I,J,1)
1116 if (grid%msfv(I,J) .lt. 0.7 ) then
1117 write(a_message,*) 'weird msfv at I,J: ', I,J,grid%msfv(I,J)
1118 CALL wrf_message ( a_message )
1119 grid%msfv(I,J)=dumdata_v(I,J-1,1)
1120 if( J .eq. min(JTE,JDE)) then
1121 write(a_message,*) 'changing msfv to: ',I,J, grid%msfv(I,J)
1122 CALL wrf_message ( a_message )
1131 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
1132 CALL mpi_file_read_at(iunit,file_offset(index+1), &
1133 dumdata,hor_size,mpi_real4, &
1134 mpi_status_ignore, ierr)
1135 DO J=JTS,min(JTE,JDE-1)
1136 DO I=ITS,min(ITE,IDE-1)
1137 grid%msft(I,J)=dumdata(I,J,1)
1142 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
1143 CALL mpi_file_read_at(iunit,file_offset(index+1), &
1144 dumdata,hor_size,mpi_real4, &
1145 mpi_status_ignore, ierr)
1146 DO J=JTS,min(JTE,JDE-1)
1147 DO I=ITS,min(ITE,IDE-1)
1148 grid%clat(I,J)=dumdata(I,J,1)
1153 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
1154 CALL mpi_file_read_at(iunit,file_offset(index+1), &
1155 dumdata_u,hor_size_u,mpi_real4, &
1156 mpi_status_ignore, ierr)
1157 DO J=JTS,min(JTE,JDE-1)
1158 DO I=ITS,min(ITE,IDE)
1159 grid%xlong_u(I,J)=dumdata_u(I,J,1)
1164 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
1165 CALL mpi_file_read_at(iunit,file_offset(index+1), &
1166 dumdata_u,hor_size_u,mpi_real4, &
1167 mpi_status_ignore, ierr)
1168 DO J=JTS,min(JTE,JDE-1)
1169 DO I=ITS,min(ITE,IDE)
1170 grid%xlat_u(I,J)=dumdata_u(I,J,1)
1175 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
1176 CALL mpi_file_read_at(iunit,file_offset(index+1), &
1177 dumdata_v,hor_size_v,mpi_real4, &
1178 mpi_status_ignore, ierr)
1179 DO J=JTS,min(JTE,JDE)
1180 DO I=ITS,min(ITE,IDE-1)
1181 grid%xlong_v(I,J)=dumdata_v(I,J,1)
1186 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
1187 CALL mpi_file_read_at(iunit,file_offset(index+1), &
1188 dumdata_v,hor_size_v,mpi_real4, &
1189 mpi_status_ignore, ierr)
1190 DO J=JTS,min(JTE,JDE)
1191 DO I=ITS,min(ITE,IDE-1)
1192 grid%xlat_v(I,J)=dumdata_v(I,J,1)
1197 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
1198 CALL mpi_file_read_at(iunit,file_offset(index+1), &
1199 dumdata,hor_size,mpi_real4, &
1200 mpi_status_ignore, ierr)
1202 DO J=JTS,min(JTE,JDE-1)
1203 DO I=ITS,min(ITE,IDE-1)
1204 grid%xlong_gc(I,J)=dumdata(I,J,1)
1208 write(a_message,*) 'reading XLAT_M'
1209 CALL wrf_message ( a_message )
1211 CALL retrieve_index(index,VarName,varname_all,nrecs,iret)
1212 CALL mpi_file_read_at(iunit,file_offset(index+1), &
1213 dumdata,hor_size,mpi_real4, &
1214 mpi_status_ignore, ierr)
1216 DO J=JTS,min(JTE,JDE-1)
1217 DO I=ITS,min(ITE,IDE-1)
1218 grid%xlat_gc(I,J)=dumdata(I,J,1)
1221 write(a_message,*) 'xlat_gc defined'
1222 CALL wrf_message ( a_message )
1224 call mpi_file_close(mpi_comm_world, ierr)
1226 write(a_message,*) 'to ST000010 def'
1227 CALL wrf_message ( a_message )
1230 num_st_levels_input = num_st_levels_input + 1
1231 st_levels_input(num_st_levels_input) = char2int2(varName(3:8))
1232 DO J=JTS,min(JTE,JDE-1)
1233 DO I=ITS,min(ITE,IDE-1)
1234 st_input(I,num_st_levels_input + 1,J) = grid%st000010(i,j)
1237 write(a_message,*) 'past ST000010 def'
1238 CALL wrf_message ( a_message )
1242 num_st_levels_input = num_st_levels_input + 1
1243 st_levels_input(num_st_levels_input) = char2int2(varName(3:8))
1244 DO J=JTS,min(JTE,JDE-1)
1245 DO I=ITS,min(ITE,IDE-1)
1246 st_input(I,num_st_levels_input + 1,J) = grid%st010040(i,j)
1252 num_st_levels_input = num_st_levels_input + 1
1253 st_levels_input(num_st_levels_input) = char2int2(varName(3:8))
1254 DO J=JTS,min(JTE,JDE-1)
1255 DO I=ITS,min(ITE,IDE-1)
1256 st_input(I,num_st_levels_input + 1,J) = grid%st040100(i,j)
1262 num_st_levels_input = num_st_levels_input + 1
1263 st_levels_input(num_st_levels_input) = char2int2(varName(3:8))
1264 DO J=JTS,min(JTE,JDE-1)
1265 DO I=ITS,min(ITE,IDE-1)
1266 st_input(I,num_st_levels_input + 1,J) = grid%st100200(i,j)
1272 num_sm_levels_input = num_sm_levels_input + 1
1273 sm_levels_input(num_sm_levels_input) = char2int2(varName(3:8))
1274 DO J=JTS,min(JTE,JDE-1)
1275 DO I=ITS,min(ITE,IDE-1)
1276 sm_input(I,num_sm_levels_input + 1,J) = grid%sm000010(i,j)
1282 num_sm_levels_input = num_sm_levels_input + 1
1283 sm_levels_input(num_sm_levels_input) = char2int2(varName(3:8))
1284 DO J=JTS,min(JTE,JDE-1)
1285 DO I=ITS,min(ITE,IDE-1)
1286 sm_input(I,num_sm_levels_input + 1,J) = grid%sm010040(i,j)
1292 num_sm_levels_input = num_sm_levels_input + 1
1293 sm_levels_input(num_sm_levels_input) = char2int2(varName(3:8))
1294 DO J=JTS,min(JTE,JDE-1)
1295 DO I=ITS,min(ITE,IDE-1)
1296 sm_input(I,num_sm_levels_input + 1,J) = grid%sm040100(i,j)
1302 num_sm_levels_input = num_sm_levels_input + 1
1303 sm_levels_input(num_sm_levels_input) = char2int2(varName(3:8))
1304 DO J=JTS,min(JTE,JDE-1)
1305 DO I=ITS,min(ITE,IDE-1)
1306 sm_input(I,num_sm_levels_input + 1,J) = grid%sm100200(i,j)
1312 write(a_message,*) 'maxval st_input(1): ', maxval(st_input(:,1,:))
1313 CALL wrf_message ( a_message )
1314 write(a_message,*) 'maxval st_input(2): ', maxval(st_input(:,2,:))
1315 CALL wrf_message ( a_message )
1316 write(a_message,*) 'maxval st_input(3): ', maxval(st_input(:,3,:))
1317 CALL wrf_message ( a_message )
1318 write(a_message,*) 'maxval st_input(4): ', maxval(st_input(:,4,:))
1319 CALL wrf_message ( a_message )
1324 DEALLOCATE(dumdata_u)
1325 DEALLOCATE(dumdata_v)
1328 end subroutine read_wps
1330 ! -------------------------------------------------------------------------
1331 ! -------------------------------------------------------------------------
1335 subroutine retrieve_index(index,string,varname_all,nrecs,iret)
1336 !$$$ subprogram documentation block
1338 ! subprogram: retrieve_index get record number of desired variable
1339 ! prgmmr: parrish org: np22 date: 2004-11-29
1341 ! abstract: by examining previously generated inventory of wrf binary restart file,
1342 ! find record number that contains the header record for variable
1343 ! identified by input character variable "string".
1345 ! program history log:
1346 ! 2004-11-29 parrish
1348 ! input argument list:
1349 ! string - mnemonic for variable desired
1350 ! varname_all - list of all mnemonics obtained from inventory of file
1351 ! nrecs - total number of sequential records counted in wrf
1352 ! binary restart file
1354 ! output argument list:
1355 ! index - desired record number
1356 ! iret - return status, set to 0 if variable was found,
1361 ! machine: ibm RS/6000 SP
1367 integer,intent(out)::iret
1368 integer,intent(in)::nrecs
1369 integer,intent(out):: index
1370 character(*), intent(in):: string
1371 character(132),intent(in)::varname_all(nrecs)
1378 if(trim(string) == trim(varname_all(i))) then
1384 write(6,*)' problem reading wrf nmm binary file, rec id "',trim(string),'" not found'
1388 end subroutine retrieve_index
1389 subroutine next_buf(in_unit,buf,nextbyte,locbyte,thisblock,lrecl,nreads,lastbuf)
1390 !$$$ subprogram documentation block
1392 ! subprogram: next_buf bring in next direct access block
1393 ! prgmmr: parrish org: np22 date: 2004-11-29
1395 ! abstract: bring in next direct access block when needed, as the file is scanned
1396 ! from beginning to end during counting and inventory of records.
1397 ! (subroutines count_recs_wrf_binary_file and inventory_wrf_binary_file)
1399 ! program history log:
1400 ! 2004-11-29 parrish
1402 ! input argument list:
1403 ! in_unit - fortran unit number where input file is opened through.
1404 ! nextbyte - byte number from beginning of file that is desired
1405 ! locbyte - byte number from beginning of last block read for desired byt
1406 ! lrecl - direct access block length
1407 ! nreads - number of blocks read before now (for diagnostic information
1408 ! lastbuf - logical, if true, then no more blocks, so return
1410 ! output argument list:
1411 ! buf - output array containing contents of next block
1412 ! locbyte - byte number from beginning of new block read for desired byte
1413 ! thisblock - number of new block being read by this routine
1414 ! nreads - number of blocks read now (for diagnostic information only)
1415 ! lastbuf - logical, if true, then at end of file.
1419 ! machine: ibm RS/6000 SP
1422 ! use kinds, only: i_byte,i_llong
1425 integer(i_llong) lrecl
1426 integer in_unit,nreads
1427 integer(i_byte) buf(lrecl)
1428 integer(i_llong) nextbyte,locbyte,thisblock
1438 ! compute thisblock:
1440 thisblock = 1_i_llong + (nextbyte-1_i_llong)/lrecl
1442 locbyte = 1_i_llong+mod(locbyte-1_i_llong,lrecl)
1444 read(in_unit,rec=thisblock,iostat=ierr)buf
1447 end subroutine next_buf
1449 subroutine inventory_wrf_binary_file(in_unit,wrf_ges_filename,nrecs, &
1450 datestr_all,varname_all,domainend_all, &
1451 start_block,end_block,start_byte,end_byte,file_offset)
1452 !$$$ subprogram documentation block
1454 ! subprogram: inventory_wrf_binary_file get contents of wrf binary file
1455 ! prgmmr: parrish org: np22 date: 2004-11-29
1457 ! abstract: generate list of contents and map of wrf binary file which can be
1458 ! used for reading and writing with mpi io routines.
1459 ! same basic routine as count_recs_wrf_binary_file, except
1460 ! now wrf unpacking routines are used to decode wrf header
1461 ! records, and send back lists of variable mnemonics, dates,
1462 ! grid dimensions, and byte addresses relative to start of
1463 ! file for each field (this is used by mpi io routines).
1465 ! program history log:
1466 ! 2004-11-29 parrish
1469 ! input argument list:
1470 ! in_unit - fortran unit number where input file is opened through.
1471 ! wrf_ges_filename - filename of input wrf binary restart file
1472 ! nrecs - number of sequential records found on input wrf binary restart file.
1473 ! (obtained by a previous call to count_recs_wrf_binary_file)
1475 ! output argument list: (all following dimensioned nrecs)
1476 ! datestr_all - date character string for each field, where applicable (or else blanks)
1477 ! varname_all - wrf mnemonic for each variable, where applicable (or blank)
1478 ! domainend_all - dimensions of each field, where applicable (up to 3 dimensions)
1479 ! start_block - direct access block number containing 1st byte of record
1480 ! (after 4 byte record mark)
1481 ! end_block - direct access block number containing last byte of record
1482 ! (before 4 byte record mark)
1483 ! start_byte - relative byte address in direct access block of 1st byte of record
1484 ! end_byte - relative byte address in direct access block of last byte of record
1485 ! file_offset - absolute address of byte before 1st byte of record (used by mpi io)
1489 ! machine: ibm RS/6000 SP
1492 ! use kinds, only: r_single,i_byte,i_long,i_llong
1493 use module_internal_header_util
1496 integer,intent(in)::in_unit,nrecs
1497 character(*),intent(in)::wrf_ges_filename
1498 character(132),intent(out)::datestr_all(nrecs),varname_all(nrecs)
1499 integer,intent(out)::domainend_all(3,nrecs)
1500 integer,intent(out)::start_block(nrecs),end_block(nrecs)
1501 integer,intent(out)::start_byte(nrecs),end_byte(nrecs)
1502 integer(i_llong),intent(out)::file_offset(nrecs)
1505 integer(i_llong) nextbyte,locbyte,thisblock
1506 integer(i_byte) lenrec4(4)
1507 integer(i_long) lenrec,lensave
1508 equivalence (lenrec4(1),lenrec)
1509 integer(i_byte) missing4(4)
1510 integer(i_long) missing
1511 equivalence (missing,missing4(1))
1512 integer(i_llong),parameter:: lrecl=2**20
1513 integer(i_byte) buf(lrecl)
1514 integer i,loc_count,nreads
1516 integer(i_byte) hdrbuf4(2048)
1517 integer(i_long) hdrbuf(512)
1518 equivalence(hdrbuf(1),hdrbuf4(1))
1519 integer,parameter:: int_field = 530
1520 integer,parameter:: int_dom_ti_char = 220
1521 integer,parameter:: int_dom_ti_real = 140
1522 integer,parameter:: int_dom_ti_integer = 180
1525 integer datahandle,count
1526 character(128) element,dumstr,strdata
1528 character(132) blanks
1530 integer fieldtype,comm,iocomm
1532 character(132) memoryorder,stagger,dimnames(3)
1533 integer domainstart(3),domainend(3)
1534 integer memorystart(3),memoryend(3)
1535 integer patchstart(3),patchend(3)
1536 character(132) datestr,varname
1538 real(r_double) dummy_field(1)
1542 ! real(r_single) dummy_field(1)
1543 ! integer dummy_field
1549 call wrf_sizeof_integer(itypesize)
1550 inttypesize=itypesize
1554 write(a_message,*) 'inventory subroutine'
1555 CALL wrf_message ( a_message )
1557 write(a_message,*) 'opening file : ', trim(wrf_ges_filename)
1558 CALL wrf_message ( a_message )
1560 open(in_unit,file=trim(wrf_ges_filename),access='direct',recl=lrecl)
1569 ! get length of next record
1572 nextbyte=nextbyte+1_i_llong
1573 locbyte=locbyte+1_i_llong
1574 if(locbyte > lrecl .and. lastbuf) go to 900
1575 if(locbyte > lrecl) call next_buf(in_unit,buf,nextbyte,locbyte,thisblock,lrecl,nreads,lastbuf)
1576 lenrec4(i)=buf(locbyte)
1578 if(lenrec <= 0 .and. lastbuf) go to 900
1579 if(lenrec <= 0 .and. .not. lastbuf) go to 885
1580 nextbyte=nextbyte+1_i_llong
1581 locbyte=locbyte+1_i_llong
1582 if(locbyte > lrecl .and. lastbuf) go to 900
1583 if(locbyte > lrecl) call next_buf(in_unit,buf,nextbyte,locbyte,thisblock,lrecl,nreads,lastbuf)
1586 start_block(irecs)=thisblock
1587 start_byte(irecs)=locbyte
1588 file_offset(irecs)=nextbyte-1_i_llong
1589 hdrbuf4(1)=buf(locbyte)
1590 hdrbuf4(2:4)=missing4(2:4)
1591 hdrbuf4(5:8)=missing4(1:4)
1592 datestr_all(irecs)=blanks
1593 varname_all(irecs)=blanks
1594 domainend_all(1:3,irecs)=0
1597 ! write(a_message,*) '1, hdrbuf4(1): 1', hdrbuf4(1)
1598 ! CALL wrf_message ( a_message )
1600 if(loc_count.ge.lenrec) exit
1601 loc_count=loc_count+1
1602 nextbyte=nextbyte+1_i_llong
1603 locbyte=locbyte+1_i_llong
1604 if(locbyte > lrecl .and. lastbuf) go to 900
1605 if(locbyte > lrecl) call next_buf(in_unit,buf,nextbyte,locbyte,thisblock,lrecl,nreads,lastbuf)
1606 hdrbuf4(i)=buf(locbyte)
1607 ! write(0,*) 'I, hdrbuf4(I): ', I, hdrbuf4(I)
1610 ! if(lenrec==2048) then write(0,*)' irecs,hdrbuf(2),int_dom_ti_char,int_field=', &
1611 ! irecs,hdrbuf(2),int_dom_ti_char,int_field, int_dom_ti_real, int_dom_ti_integer
1613 if(lenrec==2048.and.(hdrbuf(2) == int_dom_ti_char .or. hdrbuf(2) == int_field &
1614 .or. hdrbuf(2) == int_dom_ti_real .or. hdrbuf(2) == int_dom_ti_integer)) then
1616 ! bring in next full record, so we can unpack datestr, varname, and domainend
1618 loc_count=loc_count+1
1619 nextbyte=nextbyte+1_i_llong
1620 locbyte=locbyte+1_i_llong
1621 if(locbyte > lrecl .and. lastbuf) go to 900
1622 if(locbyte > lrecl) call next_buf(in_unit,buf,nextbyte,locbyte,thisblock,lrecl,nreads,lastbuf)
1623 hdrbuf4(i)=buf(locbyte)
1624 ! write(0,*) 'I, hdrbuf4(I): ', I, hdrbuf4(I)
1626 ! write(0,*) 'past 9,lenrec loop'
1627 ! write(0,*) 'hdrbuf(2): ', hdrbuf(2)
1629 if(hdrbuf(2) == int_dom_ti_char) then
1631 call int_get_ti_header_char(hdrbuf,hdrbufsize,inttypesize, &
1632 datahandle,element,dumstr,strdata,loccode)
1633 varname_all(irecs)=trim(element)
1634 datestr_all(irecs)=trim(strdata)
1635 write(a_message,*)'(1) irecs,varname,datestr = ',irecs,trim(varname_all(irecs)),trim(datestr_all(irecs))
1636 CALL wrf_message ( a_message )
1638 else if(hdrbuf(2) == int_dom_ti_real) then
1640 ! write(0,*) 'call int_get_ti_header_real'
1642 ! write(0,*) 'hdrbuf(1:10): ', hdrbuf(1:10)
1644 ! write(0,*) 'call with inttypesize typesize: ', inttypesize,typesize
1646 call int_get_ti_header_real(hdrbuf,hdrbufsize,inttypesize,typesize, &
1647 datahandle,element,rdata,count,loccode)
1649 ! write(0,*) 'return int_get_ti_header_real'
1651 varname_all(irecs)=trim(element)
1653 ! write(0,*) 'varname_all(irecs): ', varname_all(irecs)
1655 ! datestr_all(irecs)=trim(strdata)
1657 write(a_message,*)'(2) irecs,varname,datestr = ',irecs,trim(varname_all(irecs)),rdata(1)
1658 CALL wrf_message ( a_message )
1659 ! write(0,*) ' --------------------------- '
1661 else if(hdrbuf(2) == int_dom_ti_integer) then
1663 call int_get_ti_header_integer(hdrbuf,hdrbufsize,inttypesize,typesize, &
1664 datahandle,element,idata,count,loccode)
1665 varname_all(irecs)=trim(element)
1666 ! datestr_all(irecs)=trim(strdata)
1667 write(0,*)'(3) irecs,varname,datestr = ',irecs,trim(varname_all(irecs)),idata(1:count)
1671 ! write(0,*) 'call int_get_write_field_header'
1672 call int_get_write_field_header(hdrbuf,hdrbufsize,inttypesize,typesize, &
1673 datahandle,datestr,varname,dummy_field,fieldtype,comm,iocomm, &
1674 domaindesc,memoryorder,stagger,dimnames, &
1675 domainstart,domainend,memorystart,memoryend,patchstart,patchend)
1676 varname_all(irecs)=trim(varname)
1677 datestr_all(irecs)=trim(datestr)
1678 domainend_all(1:3,irecs)=domainend(1:3)
1679 ! write(0,*)'(4) irecs,datestr,domend,varname = ', &
1680 ! irecs,trim(datestr_all(irecs)),domainend_all(1:3,irecs),trim(varname_all(irecs))
1685 nextbyte=nextbyte-loc_count+lenrec
1686 locbyte=locbyte-loc_count+lenrec
1687 if(locbyte > lrecl .and. lastbuf) go to 900
1688 if(locbyte > lrecl) call next_buf(in_unit,buf,nextbyte,locbyte,thisblock,lrecl,nreads,lastbuf)
1689 end_block(irecs)=thisblock
1690 end_byte(irecs)=locbyte
1693 nextbyte=nextbyte+1_i_llong
1694 locbyte=locbyte+1_i_llong
1695 if(locbyte > lrecl .and. lastbuf) go to 900
1696 if(locbyte > lrecl) call next_buf(in_unit,buf,nextbyte,locbyte,thisblock,lrecl,nreads,lastbuf)
1697 lenrec4(i)=buf(locbyte)
1699 if(lenrec /= lensave) go to 890
1704 write(6,*)' reached impossible place in inventory_wrf_binary_file'
1709 write(a_message,*)' problem in inventory_wrf_binary_file, lenrec has bad value before end of file'
1710 CALL wrf_message ( a_message )
1711 write(a_message,*)' lenrec =',lenrec
1712 CALL wrf_message ( a_message )
1717 write(a_message,*)' problem in inventory_wrf_binary_file, beginning and ending rec len words unequal'
1718 CALL wrf_message ( a_message )
1719 write(a_message,*)' begining reclen =',lensave
1720 CALL wrf_message ( a_message )
1721 write(a_message,*)' ending reclen =',lenrec
1722 CALL wrf_message ( a_message )
1723 write(a_message,*)' irecs =',irecs
1724 CALL wrf_message ( a_message )
1725 write(a_message,*)' nrecs =',nrecs
1726 CALL wrf_message ( a_message )
1727 call wrf_error_fatal("curious reclen discrepancy")
1732 write(a_message,*)' normal end of file reached in inventory_wrf_binary_file'
1733 CALL wrf_message ( a_message )
1734 write(a_message,*)' nblocks=',thisblock
1735 CALL wrf_message ( a_message )
1736 write(a_message,*)' irecs,nrecs=',irecs,nrecs
1737 CALL wrf_message ( a_message )
1738 write(a_message,*)' nreads=',nreads
1739 CALL wrf_message ( a_message )
1742 end subroutine inventory_wrf_binary_file
1744 SUBROUTINE wrf_sizeof_integer( retval )
1747 ! 4 is defined by CPP
1750 END SUBROUTINE wrf_sizeof_integer
1752 SUBROUTINE wrf_sizeof_real( retval )
1755 ! 4 is defined by CPP
1758 END SUBROUTINE wrf_sizeof_real
1764 subroutine count_recs_wrf_binary_file(in_unit,wrf_ges_filename,nrecs)
1765 !$$$ subprogram documentation block
1767 ! subprogram: count_recs_binary_file count # recs on wrf binary file
1768 ! prgmmr: parrish org: np22 date: 2004-11-29
1770 ! abstract: count number of sequential records contained in wrf binary
1771 ! file. this is done by opening the file in direct access
1772 ! mode with block length of 2**20, the size of the physical
1773 ! blocks on ibm "blue" and "white" machines. for optimal
1774 ! performance, change block length to correspond to the
1775 ! physical block length of host machine disk space.
1776 ! records are counted by looking for the 4 byte starting
1777 ! and ending sequential record markers, which contain the
1778 ! record size in bytes. only blocks are read which are known
1779 ! by simple calculation to contain these record markers.
1780 ! even though this is done on one processor, it is still
1781 ! very fast, and the time will always scale by the number of
1782 ! sequential records, not their size. this step and the
1783 ! following inventory step consistently take less than 0.1 seconds
1786 ! program history log:
1787 ! 2004-11-29 parrish
1789 ! input argument list:
1790 ! in_unit - fortran unit number where input file is opened through.
1791 ! wrf_ges_filename - filename of input wrf binary restart file
1793 ! output argument list:
1794 ! nrecs - number of sequential records found on input wrf binary restart fil
1798 ! machine: ibm RS/6000 SP
1802 ! do an initial read through of a wrf binary file, and get total number of sequential fil
1804 ! use kinds, only: r_single,i_byte,i_long,i_llong
1807 integer,intent(in)::in_unit
1808 character(*),intent(in)::wrf_ges_filename
1809 integer,intent(out)::nrecs
1811 integer(i_llong) nextbyte,locbyte,thisblock
1812 integer(i_byte) lenrec4(4)
1813 integer(i_long) lenrec,lensave
1814 equivalence (lenrec4(1),lenrec)
1815 integer(i_byte) missing4(4)
1816 integer(i_long) missing
1817 equivalence (missing,missing4(1))
1818 integer(i_llong),parameter:: lrecl=2**20
1819 integer(i_byte) buf(lrecl)
1820 integer i,loc_count,nreads
1823 open(in_unit,file=trim(wrf_ges_filename),access='direct',recl=lrecl)
1832 ! get length of next record
1835 nextbyte=nextbyte+1_i_llong
1836 locbyte=locbyte+1_i_llong
1837 if(locbyte > lrecl .and. lastbuf) go to 900
1838 if(locbyte > lrecl) call next_buf(in_unit,buf,nextbyte,locbyte,thisblock,lrecl,nreads,lastbuf)
1839 lenrec4(i)=buf(locbyte)
1841 if(lenrec <= 0 .and. lastbuf) go to 900
1842 if(lenrec <= 0 .and. .not.lastbuf) go to 885
1843 nextbyte=nextbyte+1_i_llong
1844 locbyte=locbyte+1_i_llong
1845 if(locbyte > lrecl .and. lastbuf) go to 900
1846 if(locbyte > lrecl) call next_buf(in_unit,buf,nextbyte,locbyte,thisblock,lrecl,nreads,lastbuf)
1852 if(loc_count.ge.lenrec) exit
1853 loc_count=loc_count+1
1854 nextbyte=nextbyte+1_i_llong
1855 locbyte=locbyte+1_i_llong
1856 if(locbyte > lrecl .and. lastbuf) go to 900
1857 if(locbyte > lrecl) call next_buf(in_unit,buf,nextbyte,locbyte,thisblock,lrecl,nreads,lastbuf)
1860 if(loc_count.ge.lenrec) exit
1861 loc_count=loc_count+1
1862 nextbyte=nextbyte+1_i_llong
1863 locbyte=locbyte+1_i_llong
1864 if(locbyte > lrecl .and. lastbuf) go to 900
1865 if(locbyte > lrecl) call next_buf(in_unit,buf,nextbyte,locbyte,thisblock,lrecl,nreads,lastbuf)
1867 nextbyte=nextbyte-loc_count+lenrec
1868 locbyte=locbyte-loc_count+lenrec
1869 if(locbyte > lrecl .and. lastbuf) go to 900
1870 if(locbyte > lrecl) call next_buf(in_unit,buf,nextbyte,locbyte,thisblock,lrecl,nreads,lastbuf)
1873 nextbyte=nextbyte+1_i_llong
1874 locbyte=locbyte+1_i_llong
1875 if(locbyte > lrecl .and. lastbuf) go to 900
1876 if(locbyte > lrecl) call next_buf(in_unit,buf,nextbyte,locbyte,thisblock,lrecl,nreads,lastbuf)
1877 lenrec4(i)=buf(locbyte)
1879 if(lenrec /= lensave) go to 890
1884 write(6,*)' reached impossible place in count_recs_wrf_binary_file'
1889 write(6,*)' problem in count_recs_wrf_binary_file, lenrec has bad value before end of file'
1890 write(6,*)' lenrec =',lenrec
1895 write(6,*)' problem in count_recs_wrf_binary_file, beginning and ending rec len words unequal'
1896 write(6,*)' begining reclen =',lensave
1897 write(6,*)' ending reclen =',lenrec
1899 call wrf_error_fatal("bad reclen stuff")
1903 write(6,*)' normal end of file reached in count_recs_wrf_binary_file'
1904 write(6,*)' nblocks=',thisblock
1905 write(6,*)' nrecs=',nrecs
1906 write(6,*)' nreads=',nreads
1909 end subroutine count_recs_wrf_binary_file
1911 subroutine retrieve_field(in_unit,wrfges,out,start_block,end_block,start_byte,end_byte)
1912 !$$$ subprogram documentation block
1914 ! subprogram: retrieve_field retrieve field from wrf binary file
1915 ! prgmmr: parrish org: np22 date: 2004-11-29
1917 ! abstract: still using direct access, retrieve a field from the wrf binary restart file.
1919 ! program history log:
1920 ! 2004-11-29 parrish
1922 ! input argument list:
1923 ! in_unit - fortran unit number where input file is opened through.
1924 ! wrfges - filename of input wrf binary restart file
1925 ! start_block - direct access block number containing 1st byte of record
1926 ! (after 4 byte record mark)
1927 ! end_block - direct access block number containing last byte of record
1928 ! (before 4 byte record mark)
1929 ! start_byte - relative byte address in direct access block of 1st byte of record
1930 ! end_byte - relative byte address in direct access block of last byte of record
1932 ! output argument list:
1933 ! out - output buffer where desired field is deposited
1937 ! machine: ibm RS/6000 SP
1941 ! use kinds, only: i_byte,i_kind
1944 integer(i_kind),intent(in)::in_unit
1945 character(50),intent(in)::wrfges
1946 integer(i_kind),intent(in)::start_block,end_block,start_byte,end_byte
1947 integer(i_byte),intent(out)::out(*)
1949 integer(i_llong),parameter:: lrecl=2**20
1950 integer(i_byte) buf(lrecl)
1951 integer(i_kind) i,ii,k
1952 integer(i_llong) ibegin,iend
1955 open(in_unit,file=trim(wrfges),access='direct',recl=lrecl)
1957 write(6,*)' in retrieve_field, start_block,end_block=',start_block,end_block
1958 write(6,*)' in retrieve_field, start_byte,end_byte=',start_byte,end_byte
1960 do k=start_block,end_block
1961 read(in_unit,rec=k,iostat=ierr)buf
1962 ibegin=1 ; iend=lrecl
1963 if(k == start_block) ibegin=start_byte
1964 if(k == end_block) iend=end_byte
1972 end subroutine retrieve_field
1975 END MODULE module_wps_io_arw