1 ! Create an initial data set for the WRF model based on real data. This
2 ! program is specifically set up for the NMM core.
8 USE module_initialize_real
10 USE module_driver_constants
13 USE module_check_a_mundo
15 USE module_input_chem_data
16 USE module_input_chem_bioemiss
27 INTEGER :: loop , levels_to_process , debug_level
30 TYPE(domain) , POINTER :: null_domain
31 TYPE(domain) , POINTER :: grid
32 TYPE (grid_config_rec_type) :: config_flags
33 INTEGER :: number_at_same_level
35 INTEGER :: max_dom, domain_id
36 INTEGER :: idum1, idum2
39 ! INTEGER, PARAMETER :: configbuflen = 2*1024
40 INTEGER, PARAMETER :: configbuflen = 4*CONFIG_BUF_LEN
41 INTEGER :: configbuf( configbuflen )
42 LOGICAL , EXTERNAL :: wrf_dm_on_monitor
45 INTEGER :: ids , ide , jds , jde , kds , kde
46 INTEGER :: ims , ime , jms , jme , kms , kme
47 INTEGER :: ips , ipe , jps , jpe , kps , kpe
48 INTEGER :: ijds , ijde , spec_bdy_width
49 INTEGER :: i , j , k , idts
52 ! see http://www.mmm.ucar.edu/wrf/WG2/topics/deref_kludge.htm
53 INTEGER :: sm31 , em31 , sm32 , em32 , sm33 , em33
54 INTEGER :: sm31x, em31x, sm32x, em32x, sm33x, em33x
55 INTEGER :: sm31y, em31y, sm32y, em32y, sm33y, em33y
58 CHARACTER (LEN=80) :: message
61 INTEGER :: start_year , start_month , start_day
62 INTEGER :: start_hour , start_minute , start_second
63 INTEGER :: end_year , end_month , end_day , &
64 end_hour , end_minute , end_second
65 INTEGER :: interval_seconds , real_data_init_type
66 INTEGER :: time_loop_max , time_loop, rc
69 #include "version_decl"
70 #include "commit_decl"
73 SUBROUTINE Setup_Timekeeping( grid )
75 TYPE(domain), POINTER :: grid
76 END SUBROUTINE Setup_Timekeeping
79 ! Define the name of this program (program_name defined in module_domain)
81 program_name = "REAL_NMM " // TRIM(release_version) // " PREPROCESSOR"
89 ! Initialize the modules used by the WRF system.
90 ! Many of the CALLs made from the
91 ! init_modules routine are NO-OPs. Typical initializations
93 ! REAL, setting the file handles to a pre-use value, defining moisture and
94 ! chemistry indices, etc.
96 CALL wrf_debug ( 100 , 'real_nmm: calling init_modules ' )
98 !!!! CALL init_modules
99 CALL init_modules(1) ! Phase 1 returns after MPI_INIT() (if it is called)
100 CALL WRFU_Initialize( defaultCalKind=WRFU_CAL_GREGORIAN, rc=rc )
101 CALL init_modules(2) ! Phase 2 resumes after MPI_INIT() (if it is called)
103 ! The configuration switches mostly come from the NAMELIST input.
106 IF ( wrf_dm_on_monitor() ) THEN
107 write(message,*) 'call initial_config'
108 CALL wrf_message ( message )
111 CALL get_config_as_buffer( configbuf, configbuflen, nbytes )
112 CALL wrf_dm_bcast_bytes( configbuf, nbytes )
113 CALL set_config_as_buffer( configbuf, configbuflen )
114 CALL wrf_dm_initialize
119 CALL nl_set_use_wps_input ( 1,1 )
121 CALL check_nml_consistency
122 CALL set_physics_rconfigs
124 CALL nl_get_debug_level ( 1, debug_level )
125 CALL set_wrf_debug_level ( debug_level )
127 CALL wrf_message ( program_name )
128 CALL wrf_message ( commit_version )
130 ! Allocate the space for the mother of all domains.
132 NULLIFY( null_domain )
133 CALL wrf_debug ( 100 , 'real_nmm: calling alloc_and_configure_domain ' )
134 CALL alloc_and_configure_domain ( domain_id = 1 , &
136 parent = null_domain , &
141 #include "deref_kludge.h"
142 CALL Setup_Timekeeping ( grid )
143 CALL domain_clock_set( grid, &
144 time_step_seconds=model_config_rec%interval_seconds )
145 CALL wrf_debug ( 100 , 'real_nmm: calling set_scalar_indices_from_config ' )
146 CALL set_scalar_indices_from_config ( grid%id , idum1, idum2 )
148 CALL wrf_debug ( 100 , 'real_nmm: calling model_to_grid_config_rec ' )
150 CALL model_to_grid_config_rec ( grid%id , model_config_rec , config_flags )
152 write(message,*) 'after model_to_grid_config_rec, e_we, e_sn are: ', &
153 config_flags%e_we, config_flags%e_sn
154 CALL wrf_message(message)
156 ! Initialize the WRF IO: open files, init file handles, etc.
158 CALL wrf_debug ( 100 , 'real_nmm: calling init_wrfio' )
161 ! Some of the configuration values may have been modified from the initial READ
162 ! of the NAMELIST, so we re-broadcast the configuration records.
165 CALL wrf_debug ( 100 , 'real_nmm: re-broadcast the configuration records' )
166 CALL get_config_as_buffer( configbuf, configbuflen, nbytes )
167 CALL wrf_dm_bcast_bytes( configbuf, nbytes )
168 CALL set_config_as_buffer( configbuf, configbuflen )
171 ! No looping in this layer.
173 CALL med_sidata_input ( grid , config_flags )
177 CALL wrf_debug ( 0 , 'real_nmm: SUCCESS COMPLETE REAL_NMM INIT' )
183 CALL WRFU_Finalize( rc=rc )
185 END PROGRAM real_data
187 SUBROUTINE med_sidata_input ( grid , config_flags )
193 USE module_bc_time_utilities
194 USE module_initialize_real
195 USE module_optional_input
196 #if ( WRF_CHEM == 1 )
197 USE module_input_chem_data
198 USE module_input_chem_bioemiss
210 SUBROUTINE start_domain ( grid , allowed_to_read )
213 LOGICAL, INTENT(IN) :: allowed_to_read
214 END SUBROUTINE start_domain
219 TYPE (grid_config_rec_type) :: config_flags
221 INTEGER :: time_step_begin_restart
222 INTEGER :: idsi , ierr , myproc
223 CHARACTER (LEN=80) :: si_inpname
224 CHARACTER (LEN=132) :: message
226 CHARACTER(LEN=19) :: start_date_char , end_date_char , &
227 current_date_char , next_date_char
229 INTEGER :: time_loop_max , loop
230 INTEGER :: julyr , julday , LEN
232 INTEGER :: io_form_auxinput1
233 INTEGER, EXTERNAL :: use_package
235 LOGICAL :: using_binary_wrfsi
240 INTEGER :: numx_sm_levels_input,numx_st_levels_input
241 REAL,DIMENSION(100) :: smx_levels_input,stx_levels_input
245 ! see http://www.mmm.ucar.edu/wrf/WG2/topics/deref_kludge.htm
246 INTEGER :: sm31 , em31 , sm32 , em32 , sm33 , em33
247 INTEGER :: sm31x, em31x, sm32x, em32x, sm33x, em33x
248 INTEGER :: sm31y, em31y, sm32y, em32y, sm33y, em33y
254 ! The *INIT arrays are used to read init data written out by hwrf_prep_hybrid
255 REAL,ALLOCATABLE,DIMENSION(:,:,:)::TINIT,UINIT,VINIT,QINIT,CWMINIT
256 REAL,ALLOCATABLE,DIMENSION(:,:,:)::PINIT
257 REAL,ALLOCATABLE,DIMENSION(:,:)::PDINIT
259 ! The *B arrays are used to read boundary data written out by hwrf_prep_hybrid
260 REAL,ALLOCATABLE,DIMENSION(:,:,:)::TB,UB,VB,QB,CWMB
261 REAL,ALLOCATABLE,DIMENSION(:,:)::PDB
263 INTEGER :: KB, LM, IM, JM, iunit_gfs, N
266 LOGICAL,EXTERNAL :: WRF_DM_ON_MONITOR
267 integer :: ids,ide, jds,jde, kds,kde
268 integer :: ims,ime, jms,jme, kms,kme
269 integer :: its,ite, jts,jte, kts,kte
274 #include "deref_kludge.h"
276 grid%input_from_file = .true.
277 grid%input_from_file = .false.
279 CALL compute_si_start_and_end ( model_config_rec%start_year (grid%id) , &
280 model_config_rec%start_month (grid%id) , &
281 model_config_rec%start_day (grid%id) , &
282 model_config_rec%start_hour (grid%id) , &
283 model_config_rec%start_minute(grid%id) , &
284 model_config_rec%start_second(grid%id) , &
285 model_config_rec% end_year (grid%id) , &
286 model_config_rec% end_month (grid%id) , &
287 model_config_rec% end_day (grid%id) , &
288 model_config_rec% end_hour (grid%id) , &
289 model_config_rec% end_minute(grid%id) , &
290 model_config_rec% end_second(grid%id) , &
291 model_config_rec%interval_seconds , &
292 model_config_rec%real_data_init_type , &
293 start_date_char , end_date_char , time_loop_max )
295 ! Here we define the initial time to process, for later use by the code.
297 current_date_char = start_date_char
298 ! start_date = start_date_char // '.0000'
299 start_date = start_date_char
300 current_date = start_date
302 CALL nl_set_bdyfrq ( grid%id , REAL(model_config_rec%interval_seconds) )
304 ! Loop over each time period to process.
306 write(message,*) 'time_loop_max: ', time_loop_max
307 CALL wrf_message(message)
308 DO loop = 1 , time_loop_max
310 internal_time_loop=loop
312 write(message,*) 'loop=', loop
313 CALL wrf_message(message)
315 write(message,*) '-----------------------------------------------------------'
316 CALL wrf_message(message)
319 CALL wrf_message(message)
320 write(message,'(A,A,A,I2,A,I2)') ' Current date being processed: ', &
321 current_date, ', which is loop #',loop,' out of ',time_loop_max
322 CALL wrf_message(message)
324 ! After current_date has been set, fill in the julgmt stuff.
326 CALL geth_julgmt ( config_flags%julyr , config_flags%julday , &
329 ! Now that the specific Julian info is available,
330 ! save these in the model config record.
332 CALL nl_set_gmt (grid%id, config_flags%gmt)
333 CALL nl_set_julyr (grid%id, config_flags%julyr)
334 CALL nl_set_julday (grid%id, config_flags%julday)
336 CALL nl_get_io_form_auxinput1( 1, io_form_auxinput1 )
337 using_binary_wrfsi=.false.
340 write(message,*) 'TRIM(config_flags%auxinput1_inname): ', TRIM(config_flags%auxinput1_inname)
341 CALL wrf_message(message)
344 ifph_onlyfirst: if(.not.grid%use_prep_hybrid .or. loop==1) then
346 IF (config_flags%auxinput1_inname(1:10) .eq. 'real_input') THEN
347 using_binary_wrfsi=.true.
350 SELECT CASE ( use_package(io_form_auxinput1) )
351 #if defined(NETCDF) || defined(PNETCDF) || defined(PIO)
352 CASE ( IO_NETCDF , IO_PNETCDF , IO_PIO )
354 ! Open the wrfinput file.
356 current_date_char(11:11)='_'
358 WRITE ( wrf_err_message , FMT='(A,A)' )'med_sidata_input: calling open_r_dataset for ',TRIM(config_flags%auxinput1_inname)
359 CALL wrf_debug ( 100 , wrf_err_message )
360 IF ( config_flags%auxinput1_inname(1:8) .NE. 'wrf_real' ) THEN
361 CALL construct_filename4a( si_inpname , config_flags%auxinput1_inname , grid%id , 2 , current_date_char , &
362 config_flags%io_form_auxinput1 )
364 CALL construct_filename2a( si_inpname , config_flags%auxinput1_inname , grid%id , 2 , current_date_char )
366 CALL open_r_dataset ( idsi, TRIM(si_inpname) , grid , config_flags , "DATASET=AUXINPUT1", ierr )
368 IF ( ierr .NE. 0 ) THEN
369 CALL wrf_error_fatal( 'error opening ' // TRIM(si_inpname) // ' for input; bad date in namelist or file not in directory' )
374 CALL wrf_debug (100, 'med_sidata_input: call input_auxinput1_wrf')
376 CALL input_auxinput1 ( idsi, grid, config_flags, ierr )
378 ! Possible optional SI input. This sets flags used by init_domain.
380 IF ( loop .EQ. 1 ) THEN
381 CALL wrf_debug (100, 'med_sidata_input: call init_module_optional_input' )
382 CALL init_module_optional_input ( grid , config_flags )
383 CALL wrf_debug ( 100 , 'med_sidata_input: calling optional_input' )
385 CALL optional_input ( grid , idsi , config_flags )
388 CALL close_dataset ( idsi , config_flags , "DATASET=AUXINPUT1" )
394 ! Possible optional SI input. This sets flags used by init_domain.
396 IF ( loop .EQ. 1 ) THEN
397 CALL wrf_debug (100, 'med_sidata_input: call init_module_optional_input' )
398 CALL init_module_optional_input ( grid , config_flags )
401 IF (using_binary_wrfsi) THEN
403 current_date_char(11:11)='_'
404 CALL read_si ( grid, current_date_char )
405 current_date_char(11:11)='T'
409 write(message,*) 'binary WPS branch'
410 CALL wrf_message(message)
411 current_date_char(11:11)='_'
412 CALL construct_filename4a( si_inpname , config_flags%auxinput1_inname , grid%id , 2 , current_date_char , &
413 config_flags%io_form_auxinput1 )
414 CALL read_wps ( grid, trim(si_inpname), current_date_char, config_flags%num_metgrid_levels )
415 !!! bogus set some flags??
424 CALL wrf_error_fatal('real: not valid io_form_auxinput1')
431 grid%vegfra=grid%vegfrc
432 grid%dfrlg=grid%dfl/9.81
437 ! Initialize the mother domain for this time period with input data.
439 CALL wrf_debug ( 100 , 'med_sidata_input: calling init_domain' )
440 grid%input_from_file = .true.
442 CALL init_domain ( grid )
445 read_phinit: if(grid%use_prep_hybrid) then
446 #if defined(DM_PARALLEL)
447 if(.not. wrf_dm_on_monitor()) then
448 call wrf_error_fatal('real: in use_prep_hybrid mode, threading and mpi are forbidden.')
452 ph_loop1: if(loop==1) then
454 ! determine kds, ids, jds
455 SELECT CASE ( model_data_order )
456 CASE ( DATA_ORDER_ZXY )
457 kds = grid%sd31 ; kde = grid%ed31 ;
458 ids = grid%sd32 ; ide = grid%ed32 ;
459 jds = grid%sd33 ; jde = grid%ed33 ;
461 kms = grid%sm31 ; kme = grid%em31 ;
462 ims = grid%sm32 ; ime = grid%em32 ;
463 jms = grid%sm33 ; jme = grid%em33 ;
465 kts = grid%sp31 ; kte = grid%ep31 ; ! tile is entire patch
466 its = grid%sp32 ; ite = grid%ep32 ; ! tile is entire patch
467 jts = grid%sp33 ; jte = grid%ep33 ; ! tile is entire patch
469 CASE ( DATA_ORDER_XYZ )
470 ids = grid%sd31 ; ide = grid%ed31 ;
471 jds = grid%sd32 ; jde = grid%ed32 ;
472 kds = grid%sd33 ; kde = grid%ed33 ;
474 ims = grid%sm31 ; ime = grid%em31 ;
475 jms = grid%sm32 ; jme = grid%em32 ;
476 kms = grid%sm33 ; kme = grid%em33 ;
478 its = grid%sp31 ; ite = grid%ep31 ; ! tile is entire patch
479 jts = grid%sp32 ; jte = grid%ep32 ; ! tile is entire patch
480 kts = grid%sp33 ; kte = grid%ep33 ; ! tile is entire patch
482 CASE ( DATA_ORDER_XZY )
483 ids = grid%sd31 ; ide = grid%ed31 ;
484 kds = grid%sd32 ; kde = grid%ed32 ;
485 jds = grid%sd33 ; jde = grid%ed33 ;
487 ims = grid%sm31 ; ime = grid%em31 ;
488 kms = grid%sm32 ; kme = grid%em32 ;
489 jms = grid%sm33 ; jme = grid%em33 ;
491 its = grid%sp31 ; ite = grid%ep31 ; ! tile is entire patch
492 kts = grid%sp32 ; kte = grid%ep32 ; ! tile is entire patch
493 jts = grid%sp33 ; jte = grid%ep33 ; ! tile is entire patch
496 ! Allocate 3D initialization arrays:
497 call wrf_message('ALLOCATE PREP_HYBRID INIT ARRAYS')
498 ALLOCATE ( TINIT (ids:(ide-1),kds:(kde-1) ,jds:(jde-1)) )
499 ALLOCATE ( PINIT (ids:(ide-1),kds:kde ,jds:(jde-1)) )
500 ALLOCATE ( UINIT (ids:(ide-1),kds:(kde-1) ,jds:(jde-1)) )
501 ALLOCATE ( VINIT (ids:(ide-1),kds:(kde-1) ,jds:(jde-1)) )
502 ALLOCATE ( QINIT (ids:(ide-1),kds:(kde-1) ,jds:(jde-1)) )
503 ALLOCATE ( CWMINIT(ids:(ide-1),kds:(kde-1) ,jds:(jde-1)) )
504 ALLOCATE ( PDINIT (ids:(ide-1), jds:(jde-1)) )
507 READ(900,iostat=ioerror) PDINIT,TINIT,QINIT,CWMINIT,UINIT,VINIT,PINIT
509 call wrf_error_fatal('Unable to read MAKBND output from unit 900.')
511 WRITE(mess,*) 'U V T AT 10 10 10 ',UINIT(10,10,10),VINIT(10,10,10),TINIT(10,10,10)
512 call wrf_message(mess)
513 ! Switch from IKJ to IJK ordering
516 grid%pd(I,J) = PDINIT(I,J)
519 grid%u(I,J,K) = UINIT(I,K,J)
520 grid%v(I,J,K) = VINIT(I,K,J)
521 grid%t(I,J,K) = TINIT(I,K,J)
522 grid%q(I,J,K) = QINIT(I,K,J)
523 grid%cwm(I,J,K) = CWMINIT(I,K,J)
525 ! Was commented out in original V2 HWRF too:
527 ! grid%nmm_pint(I,J,K) = pinit(I,K,J)
532 call wrf_message('DEALLOCATE PREP_HYBRID INIT ARRAYS')
533 deallocate(TINIT,PINIT,UINIT,VINIT,QINIT,CWMINIT,PDINIT)
538 CALL model_to_grid_config_rec ( grid%id, model_config_rec, config_flags )
540 ! Close this file that is output from the SI and input to this pre-proc.
542 CALL wrf_debug ( 100 , 'med_sidata_input: back from init_domain' )
545 !!! not sure about this, but doesnt seem like needs to be called each time
546 IF ( loop .EQ. 1 ) THEN
547 CALL start_domain ( grid , .TRUE.)
550 #if ( WRF_CHEM == 1 )
551 IF ( loop == 1 ) THEN
552 ! IF ( ( grid%chem_opt .EQ. RADM2 ) .OR. &
553 ! ( grid%chem_opt .EQ. RADM2SORG ) .OR. &
554 ! ( grid%chem_opt .EQ. RACM ) .OR. &
555 ! ( grid%chem_opt .EQ. RACMSORG ) ) THEN
556 IF( grid%chem_opt > 0 ) then
557 ! Read the chemistry data from a previous wrf forecast (wrfout file)
558 IF(grid%chem_in_opt == 1 ) THEN
559 message = 'INITIALIZING CHEMISTRY WITH OLD SIMULATION'
560 CALL wrf_message ( message )
562 CALL input_ext_chem_file( grid )
564 IF(grid%bio_emiss_opt == BEIS311 ) THEN
565 message = 'READING BEIS3.11 EMISSIONS DATA'
566 CALL wrf_message ( message )
567 CALL med_read_wrf_chem_bioemiss ( grid , config_flags)
568 else IF(grid%bio_emiss_opt == 3 ) THEN !shc
569 message = 'READING MEGAN 2 EMISSIONS DATA'
570 CALL wrf_message ( message )
571 CALL med_read_wrf_chem_bioemiss ( grid , config_flags)
574 ELSEIF(grid%chem_in_opt == 0)then
575 ! Generate chemistry data from a idealized vertical profile
576 message = 'STARTING WITH BACKGROUND CHEMISTRY '
577 CALL wrf_message ( message )
579 write(message,*)' ETA1 '
580 CALL wrf_message ( message )
581 ! write(message,*) grid%eta1
582 ! CALL wrf_message ( message )
584 CALL input_chem_profile ( grid )
586 IF(grid%bio_emiss_opt == BEIS311 ) THEN
587 message = 'READING BEIS3.11 EMISSIONS DATA'
588 CALL wrf_message ( message )
589 CALL med_read_wrf_chem_bioemiss ( grid , config_flags)
590 else IF(grid%bio_emiss_opt == 3 ) THEN !shc
591 message = 'READING MEGAN 2 EMISSIONS DATA'
592 CALL wrf_message ( message )
593 CALL med_read_wrf_chem_bioemiss ( grid , config_flags)
597 message = 'RUNNING WITHOUT CHEMISTRY INITIALIZATION'
598 CALL wrf_message ( message )
604 config_flags%isurban=1
605 config_flags%isoilwater=14
607 CALL assemble_output ( grid , config_flags , loop , time_loop_max )
609 ! Here we define the next time that we are going to process.
611 CALL geth_newdate ( current_date_char , start_date_char , &
612 loop * model_config_rec%interval_seconds )
613 current_date = current_date_char // '.0000'
615 CALL domain_clock_set( grid, current_date(1:19) )
617 write(message,*) 'current_date= ', current_date
618 CALL wrf_message(message)
621 END SUBROUTINE med_sidata_input
623 SUBROUTINE compute_si_start_and_end ( &
624 start_year, start_month, start_day, start_hour, &
625 start_minute, start_second, &
626 end_year , end_month , end_day , end_hour , &
627 end_minute , end_second , &
628 interval_seconds , real_data_init_type , &
629 start_date_char , end_date_char , time_loop_max )
635 INTEGER :: start_year , start_month , start_day , &
636 start_hour , start_minute , start_second
637 INTEGER :: end_year , end_month , end_day , &
638 end_hour , end_minute , end_second
639 INTEGER :: interval_seconds , real_data_init_type
640 INTEGER :: time_loop_max , time_loop
642 CHARACTER(LEN=132) :: message
643 CHARACTER(LEN=19) :: current_date_char , start_date_char , &
644 end_date_char , next_date_char
646 ! WRITE ( start_date_char , FMT = &
647 ! '(I4.4,"-",I2.2,"-",I2.2,"_",I2.2,":",I2.2,":",I2.2)' ) &
648 ! start_year,start_month,start_day,start_hour,start_minute,start_second
649 ! WRITE ( end_date_char , FMT = &
650 ! '(I4.4,"-",I2.2,"-",I2.2,"_",I2.2,":",I2.2,":",I2.2)' ) &
651 ! end_year, end_month, end_day, end_hour, end_minute, end_second
653 WRITE ( start_date_char , FMT = &
654 '(I4.4,"-",I2.2,"-",I2.2,"T",I2.2,":",I2.2,":",I2.2)' ) &
655 start_year,start_month,start_day,start_hour,start_minute,start_second
656 WRITE ( end_date_char , FMT = &
657 '(I4.4,"-",I2.2,"-",I2.2,"T",I2.2,":",I2.2,":",I2.2)' ) &
658 end_year, end_month, end_day, end_hour, end_minute, end_second
660 ! start_date = start_date_char // '.0000'
662 ! Figure out our loop count for the processing times.
665 PRINT '(A,I4,A,A,A)','Time period #',time_loop, &
666 ' to process = ',start_date_char,'.'
667 current_date_char = start_date_char
669 CALL geth_newdate (next_date_char, current_date_char, interval_seconds )
670 IF ( next_date_char .LT. end_date_char ) THEN
671 time_loop = time_loop + 1
672 PRINT '(A,I4,A,A,A)','Time period #',time_loop,&
673 ' to process = ',next_date_char,'.'
674 current_date_char = next_date_char
675 ELSE IF ( next_date_char .EQ. end_date_char ) THEN
676 time_loop = time_loop + 1
677 PRINT '(A,I4,A,A,A)','Time period #',time_loop,&
678 ' to process = ',next_date_char,'.'
679 PRINT '(A,I4,A)','Total analysis times to input = ',time_loop,'.'
680 time_loop_max = time_loop
682 ELSE IF ( next_date_char .GT. end_date_char ) THEN
683 PRINT '(A,I4,A)','Total analysis times to input = ',time_loop,'.'
684 time_loop_max = time_loop
688 write(message,*) 'done in si_start_and_end'
689 CALL wrf_message(message)
690 END SUBROUTINE compute_si_start_and_end
692 SUBROUTINE assemble_output ( grid , config_flags , loop , time_loop_max )
694 !!! replace with something? USE module_big_step_utilities_em
704 external get_wrf_debug_level
709 TYPE (grid_config_rec_type) :: config_flags
710 INTEGER , INTENT(IN) :: loop , time_loop_max
711 character*255 :: mess
712 INTEGER :: ids , ide , jds , jde , kds , kde
713 INTEGER :: ims , ime , jms , jme , kms , kme
714 INTEGER :: ips , ipe , jps , jpe , kps , kpe
715 INTEGER :: ijds , ijde , spec_bdy_width
716 INTEGER :: inc_h,inc_v
717 INTEGER :: i , j , k , idts
719 INTEGER :: id1 , interval_seconds , ierr, rc, sst_update
720 INTEGER , SAVE :: id ,id4
721 CHARACTER (LEN=80) :: inpname , bdyname
722 CHARACTER(LEN= 4) :: loop_char
723 CHARACTER(LEN=132) :: message
724 character *19 :: temp19
725 character *24 :: temp24 , temp24b
727 REAL, DIMENSION(:,:,:), ALLOCATABLE, SAVE :: ubdy3dtemp1 , vbdy3dtemp1 ,&
729 cwmbdy3dtemp1 , qbdy3dtemp1,&
730 q2bdy3dtemp1 , pdbdy2dtemp1
731 REAL, DIMENSION(:,:,:), ALLOCATABLE, SAVE :: ubdy3dtemp2 , vbdy3dtemp2 , &
733 cwmbdy3dtemp2 , qbdy3dtemp2, &
734 q2bdy3dtemp2, pdbdy2dtemp2
738 ! see http://www.mmm.ucar.edu/wrf/WG2/topics/deref_kludge.htm
739 INTEGER :: sm31 , em31 , sm32 , em32 , sm33 , em33
740 INTEGER :: sm31x, em31x, sm32x, em32x, sm33x, em33x
741 INTEGER :: sm31y, em31y, sm32y, em32y, sm33y, em33y
747 ! The *B arrays are used to read boundary data written out by hwrf_prep_hybrid
748 REAL,ALLOCATABLE,DIMENSION(:,:,:)::TB,UB,VB,QB,CWMB
749 REAL,ALLOCATABLE,DIMENSION(:,:)::PDB
751 ! Dimensions and looping variables:
752 INTEGER :: KB, LM, IM, JM, N
754 ! Unit number to read boundary data from (changes each time)
757 ! Did we allocate the prep_hybrid input arrays?
758 LOGICAL :: alloc_ph_arrays
763 #include "deref_kludge.h"
766 alloc_ph_arrays=.false.
767 call get_wrf_debug_level(debug)
770 ! Various sizes that we need to be concerned about.
773 ide = grid%ed31-1 ! 030730tst
775 jde = grid%ed32-1 ! 030730tst
777 kde = grid%ed33-1 ! 030730tst
787 ipe = grid%ep31-1 ! 030730tst
789 jpe = grid%ep32-1 ! 030730tst
791 kpe = grid%ep33-1 ! 030730tst
793 if (IPE .ne. IDE) IPE=IPE+1
794 if (JPE .ne. JDE) JPE=JPE+1
796 write(message,*) 'assemble output (ids,ide): ', ids,ide
797 CALL wrf_message(message)
798 write(message,*) 'assemble output (ims,ime): ', ims,ime
799 CALL wrf_message(message)
800 write(message,*) 'assemble output (ips,ipe): ', ips,ipe
801 CALL wrf_message(message)
803 write(message,*) 'assemble output (jds,jde): ', jds,jde
804 CALL wrf_message(message)
805 write(message,*) 'assemble output (jms,jme): ', jms,jme
806 CALL wrf_message(message)
807 write(message,*) 'assemble output (jps,jpe): ', jps,jpe
808 CALL wrf_message(message)
810 write(message,*) 'assemble output (kds,kde): ', kds,kde
811 CALL wrf_message(message)
812 write(message,*) 'assemble output (kms,kme): ', kms,kme
813 CALL wrf_message(message)
814 write(message,*) 'assemble output (kps,kpe): ', kps,kpe
815 CALL wrf_message(message)
817 ijds = MIN ( ids , jds )
818 !mptest030805 ijde = MAX ( ide , jde )
819 ijde = MAX ( ide , jde ) + 1 ! to make stuff_bdy dimensions consistent with alloc
821 ! Boundary width, scalar value.
823 spec_bdy_width = model_config_rec%spec_bdy_width
824 interval_seconds = model_config_rec%interval_seconds
825 sst_update = model_config_rec%sst_update
827 !-----------------------------------------------------------------------
829 main_loop_test: IF ( loop .EQ. 1 ) THEN
831 !-----------------------------------------------------------------------
833 IF ( time_loop_max .NE. 1 ) THEN
834 IF(sst_update .EQ. 1)THEN
835 CALL construct_filename1( inpname , 'wrflowinp' , grid%id , 2 )
836 CALL open_w_dataset ( id4, TRIM(inpname) , grid , config_flags , output_auxinput4 , "DATASET=AUXINPUT4", ierr )
837 IF ( ierr .NE. 0 ) THEN
838 CALL wrf_error_fatal( 'real: error opening wrflowinp for writing' )
840 CALL output_auxinput4 ( id4, grid , config_flags , ierr )
845 ! This is the space needed to save the current 3d data for use in computing
846 ! the lateral boundary tendencies.
848 ALLOCATE ( ubdy3dtemp1(ims:ime,jms:jme,kms:kme) )
849 ALLOCATE ( vbdy3dtemp1(ims:ime,jms:jme,kms:kme) )
850 ALLOCATE ( tbdy3dtemp1(ims:ime,jms:jme,kms:kme) )
851 ALLOCATE ( qbdy3dtemp1(ims:ime,jms:jme,kms:kme) )
852 ALLOCATE ( cwmbdy3dtemp1(ims:ime,jms:jme,kms:kme) )
853 ALLOCATE ( q2bdy3dtemp1(ims:ime,jms:jme,kms:kme) )
854 ALLOCATE ( pdbdy2dtemp1(ims:ime,jms:jme,1:1) )
864 ALLOCATE ( ubdy3dtemp2(ims:ime,jms:jme,kms:kme) )
865 ALLOCATE ( vbdy3dtemp2(ims:ime,jms:jme,kms:kme) )
866 ALLOCATE ( tbdy3dtemp2(ims:ime,jms:jme,kms:kme) )
867 ALLOCATE ( qbdy3dtemp2(ims:ime,jms:jme,kms:kme) )
868 ALLOCATE ( cwmbdy3dtemp2(ims:ime,jms:jme,kms:kme) )
869 ALLOCATE ( q2bdy3dtemp2(ims:ime,jms:jme,kms:kme) )
870 ALLOCATE ( pdbdy2dtemp2(ims:ime,jms:jme,1:1) )
880 ! Open the wrfinput file. From this program, this is an *output* file.
882 CALL construct_filename1( inpname , 'wrfinput' , grid%id , 2 )
884 CALL open_w_dataset ( id1, TRIM(inpname) , grid , config_flags , &
885 output_input , "DATASET=INPUT", ierr )
887 IF ( ierr .NE. 0 ) THEN
888 CALL wrf_error_fatal( 'real: error opening wrfinput for writing' )
891 ! CALL calc_current_date ( grid%id , 0. )
892 ! grid%write_metadata = .true.
894 write(message,*) 'making call to output_input'
895 CALL wrf_message(message)
897 CALL output_input ( id1, grid , config_flags , ierr )
900 !*** CLOSE THE WRFINPUT DATASET
902 CALL close_dataset ( id1 , config_flags , "DATASET=INPUT" )
904 ! We need to save the 3d data to compute a
905 ! difference during the next loop.
908 !-----------------------------------------------------------------------
909 !*** SOUTHERN BOUNDARY
910 !-----------------------------------------------------------------------
915 DO k = kps , MIN(kde,kpe)
916 DO i = ips , MIN(ide,ipe)
917 ubdy3dtemp1(i,j,k) = grid%u(i,j,k)
918 vbdy3dtemp1(i,j,k) = grid%v(i,j,k)
919 tbdy3dtemp1(i,j,k) = grid%t(i,j,k)
920 qbdy3dtemp1(i,j,k) = grid%q(i,j,k)
921 cwmbdy3dtemp1(i,j,k) = grid%cwm(i,j,k)
922 q2bdy3dtemp1(i,j,k) = grid%q2(i,j,k)
926 DO i = ips , MIN(ide,ipe)
927 pdbdy2dtemp1(i,j,1) = grid%pd(i,j)
932 !-----------------------------------------------------------------------
933 !*** NORTHERN BOUNDARY
934 !-----------------------------------------------------------------------
938 DO k = kps , MIN(kde,kpe)
939 DO i = ips , MIN(ide,ipe)
940 ubdy3dtemp1(i,j,k) = grid%u(i,j,k)
941 vbdy3dtemp1(i,j,k) = grid%v(i,j,k)
942 tbdy3dtemp1(i,j,k) = grid%t(i,j,k)
943 qbdy3dtemp1(i,j,k) = grid%q(i,j,k)
944 cwmbdy3dtemp1(i,j,k) = grid%cwm(i,j,k)
945 q2bdy3dtemp1(i,j,k) = grid%q2(i,j,k)
949 DO i = ips , MIN(ide,ipe)
950 pdbdy2dtemp1(i,j,1) = grid%pd(i,j)
955 !-----------------------------------------------------------------------
956 !*** WESTERN BOUNDARY
957 !-----------------------------------------------------------------------
959 write(message,*) 'western boundary, store winds over J: ', jps, min(jpe,jde)
960 CALL wrf_message(message)
964 DO k = kps , MIN(kde,kpe)
966 DO j = jps+inc_h, min(jde,jpe),2
968 if (J .ge. 3 .and. J .le. JDE-2 .and. mod(J,2) .eq. 1) then
969 tbdy3dtemp1(i,j,k) = grid%t(i,j,k)
970 qbdy3dtemp1(i,j,k) = grid%q(i,j,k)
971 cwmbdy3dtemp1(i,j,k) = grid%cwm(i,j,k)
972 q2bdy3dtemp1(i,j,k) = grid%q2(i,j,k)
974 write(message,*)' loop=',loop,' i=',i,' j=',j,' tbdy3dtemp1(i,j,k)=',tbdy3dtemp1(i,j,k)
975 CALL wrf_debug(10,message)
981 DO k = kps , MIN(kde,kpe)
983 DO j = jps+inc_v, min(jde,jpe),2
984 if (J .ge. 2 .and. J .le. JDE-1 .and. mod(J,2) .eq. 0) then
985 ubdy3dtemp1(i,j,k) = grid%u(i,j,k)
986 vbdy3dtemp1(i,j,k) = grid%v(i,j,k)
992 DO j = jps+inc_h, min(jde,jpe),2
993 if (J .ge. 3 .and. J .le. JDE-2 .and. mod(J,2) .eq. 1) then
994 pdbdy2dtemp1(i,j,1) = grid%pd(i,j)
995 write(message,*)' loop=',loop,' i=',i,' j=',j,' pdbdy2dtemp1(i,j)=',pdbdy2dtemp1(i,j,1)
996 CALL wrf_debug(10,message)
1001 !-----------------------------------------------------------------------
1002 !*** EASTERN BOUNDARY
1003 !-----------------------------------------------------------------------
1008 DO k = kps , MIN(kde,kpe)
1010 !*** Make sure the J loop is on the global boundary
1013 DO j = jps+inc_h, min(jde,jpe),2
1014 if (J .ge. 3 .and. J .le. JDE-2 .and. mod(J,2) .eq. 1) then
1015 tbdy3dtemp1(i,j,k) = grid%t(i,j,k)
1016 qbdy3dtemp1(i,j,k) = grid%q(i,j,k)
1017 cwmbdy3dtemp1(i,j,k) = grid%cwm(i,j,k)
1018 q2bdy3dtemp1(i,j,k) = grid%q2(i,j,k)
1023 DO k = kps , MIN(kde,kpe)
1025 DO j = jps+inc_v, min(jde,jpe),2
1026 if (J .ge. 2 .and. J .le. JDE-1 .and. mod(J,2) .eq. 0) then
1027 ubdy3dtemp1(i,j,k) = grid%u(i,j,k)
1028 vbdy3dtemp1(i,j,k) = grid%v(i,j,k)
1034 DO j = jps+inc_h, min(jde,jpe),2
1035 if (J .ge. 3 .and. J .le. JDE-2 .and. mod(J,2) .eq. 1) then
1036 pdbdy2dtemp1(i,j,1) = grid%pd(i,j)
1042 ! There are 2 components to the lateral boundaries.
1043 ! First, there is the starting
1044 ! point of this time period - just the outer few rows and columns.
1047 CALL stuff_bdy_ijk (ubdy3dtemp1, grid%u_bxs, grid%u_bxe, &
1048 grid%u_bys, grid%u_bye, &
1049 'N', spec_bdy_width , &
1050 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1051 ims , ime , jms , jme , kms , kme , &
1052 ips , ipe , jps , jpe , kps , kpe+1 )
1054 CALL stuff_bdy_ijk (vbdy3dtemp1, grid%v_bxs, grid%v_bxe, &
1055 grid%v_bys, grid%v_bye, &
1056 'N', spec_bdy_width , &
1057 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1058 ims , ime , jms , jme , kms , kme , &
1059 ips , ipe , jps , jpe , kps , kpe+1 )
1061 CALL stuff_bdy_ijk (tbdy3dtemp1, grid%t_bxs, grid%t_bxe, &
1062 grid%t_bys, grid%t_bye, &
1063 'N', spec_bdy_width , &
1064 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1065 ims , ime , jms , jme , kms , kme , &
1066 ips , ipe , jps , jpe , kps , kpe+1 )
1068 CALL stuff_bdy_ijk (cwmbdy3dtemp1, grid%cwm_bxs, grid%cwm_bxe, &
1069 grid%cwm_bys, grid%cwm_bye, &
1070 'N', spec_bdy_width , &
1071 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1072 ims , ime , jms , jme , kms , kme , &
1073 ips , ipe , jps , jpe , kps , kpe+1 )
1075 CALL stuff_bdy_ijk (qbdy3dtemp1, grid%q_bxs, grid%q_bxe, &
1076 grid%q_bys, grid%q_bye, &
1077 'N', spec_bdy_width , &
1078 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1079 ims , ime , jms , jme , kms , kme , &
1080 ips , ipe , jps , jpe , kps , kpe+1 )
1082 CALL stuff_bdy_ijk (q2bdy3dtemp1, grid%q2_bxs, grid%q2_bxe, &
1083 grid%q2_bys, grid%q2_bye, &
1084 'N', spec_bdy_width , &
1085 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1086 ims , ime , jms , jme , kms , kme , &
1087 ips , ipe , jps , jpe , kps , kpe+1 )
1090 CALL stuff_bdy_ijk (pdbdy2dtemp1, grid%pd_bxs, grid%pd_bxe, &
1091 grid%pd_bys, grid%pd_bye, &
1092 'M', spec_bdy_width, &
1093 ids , ide+1 , jds , jde+1 , 1 , 1 , &
1094 ims , ime , jms , jme , 1 , 1 , &
1095 ips , ipe , jps , jpe , 1 , 1 )
1097 !-----------------------------------------------------------------------
1099 ELSE IF ( loop .GT. 1 ) THEN
1101 !-----------------------------------------------------------------------
1103 call wrf_debug(1,'LOOP>1, so start making non-init boundary conditions')
1106 bdytmp_useph: if(grid%use_prep_hybrid) then
1107 call wrf_debug(1,'ALLOCATE PREP_HYBRID BOUNDARY ARRAYS')
1108 !! When running in prep_hybrid mode, we must read in the data here.
1110 ! Allocate boundary arrays:
1111 KB = 2*IDE + JDE - 3
1115 ALLOCATE(TB(KB,LM,2))
1116 ALLOCATE(QB(KB,LM,2))
1117 ALLOCATE(CWMB(KB,LM,2))
1118 ALLOCATE(UB(KB,LM,2))
1119 ALLOCATE(VB(KB,LM,2))
1121 alloc_ph_arrays=.true.
1124 IUNIT_GFS = 900 + LOOP - 1
1125 READ(IUNIT_GFS,iostat=ioerror) PDB,TB,QB,CWMB,UB,VB
1127 write(message,*) 'Unable to read MAKBND output from unit ',IUNIT_GFS
1128 call wrf_error_fatal(message)
1131 ! Now copy the data into the temporary boundary arrays, and
1132 ! switch from IKJ to IJK while we do it.
1134 !! Southern boundary
1139 DO k = kps , MIN(kde,kpe)
1141 DO i = ips , MIN(ide,ipe)
1142 tbdy3dtemp2(i,j,k) = TB(N,k,1)
1143 qbdy3dtemp2(i,j,k) = QB(N,k,1)
1144 cwmbdy3dtemp2(i,j,k) = CWMB(N,k,1)
1145 q2bdy3dtemp2(i,j,k) = 0.0 !KWON
1146 write(message,*)'southtend t',k,i,n,tbdy3dtemp2(i,j,k)
1147 call wrf_debug(10,message)
1148 write(message,*)'southtend q',k,i,n,qbdy3dtemp2(i,j,k)
1149 call wrf_debug(10,message)
1151 write(mess,*) 'S boundary values T,Q : ', I,tbdy3dtemp2(i,j,k), &
1153 call wrf_debug(1,message)
1159 DO k = kps , MIN(kde,kpe)
1161 DO i = ips , MIN(ide,ipe)
1162 ubdy3dtemp2(i,j,k) = UB(N,k,1)
1163 vbdy3dtemp2(i,j,k) = VB(N,k,1)
1169 DO i = ips , MIN(ide,ipe)
1170 pdbdy2dtemp2(i,j,1) = PDB(N,1)
1171 write(message,*)'southtend p',i,n,pdbdy2dtemp1(i,j,1)
1172 call wrf_debug(10,message)
1183 DO k = kps , MIN(kde,kpe)
1185 DO i = ips , MIN(ide,ipe)
1186 tbdy3dtemp2(i,j,k) = TB(N,k,1)
1187 qbdy3dtemp2(i,j,k) = QB(N,k,1)
1188 cwmbdy3dtemp2(i,j,k) = CWMB(N,k,1)
1189 q2bdy3dtemp2(i,j,k) = 0.0 !KWON
1190 write(message,*)'northtend t',k,i,n,tbdy3dtemp2(i,j,k)
1191 call wrf_debug(10,message)
1192 write(message,*)'northtend q',k,i,n,qbdy3dtemp2(i,j,k)
1193 call wrf_debug(10,message)
1198 DO k = kps , MIN(kde,kpe)
1200 DO i = ips , MIN(ide,ipe)
1201 ubdy3dtemp2(i,j,k) = UB(N,k,1)
1202 vbdy3dtemp2(i,j,k) = VB(N,k,1)
1208 DO i = ips , MIN(ide,ipe)
1209 pdbdy2dtemp2(i,j,1) = PDB(N,1)
1210 write(message,*)'northtend p',i,n,pdbdy2dtemp1(i,j,1)
1211 call wrf_debug(10,message)
1221 DO k = kps , MIN(kde,kpe)
1224 DO j = jps+inc_h, MIN(jde,jpe),2
1225 if (J .ge. 3 .and. J .le. jde-2 .and. mod(J,2) .eq. 1) then
1226 tbdy3dtemp2(i,j,k) = TB(N,k,1)
1227 qbdy3dtemp2(i,j,k) = QB(N,k,1)
1228 cwmbdy3dtemp2(i,j,k) = CWMB(N,k,1)
1229 q2bdy3dtemp2(i,j,k) = 0.0 !KWON
1230 write(message,*)'westtend t',k,j,n,tbdy3dtemp2(i,j,k)
1231 call wrf_debug(10,message)
1232 write(message,*)'westtend q',k,j,n,qbdy3dtemp2(i,j,k)
1233 call wrf_debug(10,message)
1239 DO k = kps , MIN(kde,kpe)
1242 DO j = jps+inc_v, MIN(jde,jpe),2
1243 if (J .ge. 2 .and. J .le. jde-1 .and. mod(J,2) .eq. 0) then
1244 ubdy3dtemp2(i,j,k) = UB(N,k,1)
1245 vbdy3dtemp2(i,j,k) = VB(N,k,1)
1253 DO j = jps+inc_h, MIN(jde,jpe),2
1254 if (J .ge. 3 .and. J .le. jde-2 .and. mod(J,2) .eq. 1) then
1255 pdbdy2dtemp2(i,j,1) = PDB(N,1)
1256 write(message,*)'westtend p',j,n,pdbdy2dtemp1(i,j,1)
1257 call wrf_debug(10,message)
1270 DO k = kps , MIN(kde,kpe)
1273 DO j = jps+inc_h, MIN(jde,jpe),2
1274 if (J .ge. 3 .and. J .le. jde-2 .and. mod(J,2) .eq. 1) then
1275 tbdy3dtemp2(i,j,k) = TB(N,k,1)
1276 qbdy3dtemp2(i,j,k) = QB(N,k,1)
1277 cwmbdy3dtemp2(i,j,k) = CWMB(N,k,1)
1278 q2bdy3dtemp2(i,j,k) = 0.0 !KWON
1279 write(message,*)'easttend t',k,j,n,tbdy3dtemp2(i,j,k)
1280 call wrf_debug(10,message)
1281 write(message,*)'easttend q',k,j,n,qbdy3dtemp2(i,j,k)
1282 call wrf_debug(10,message)
1288 DO k = kps , MIN(kde,kpe)
1291 DO j = jps+inc_v, MIN(jde,jpe),2
1292 if (J .ge. 2 .and. J .le. jde-1 .and. mod(J,2) .eq. 0) then
1293 ubdy3dtemp2(i,j,k) = UB(N,k,1)
1294 vbdy3dtemp2(i,j,k) = VB(N,k,1)
1302 DO j = jps+inc_h, MIN(jde,jpe),2
1303 if (J .ge. 3 .and. J .le. jde-2 .and. mod(J,2) .eq. 1) then
1304 pdbdy2dtemp2(i,j,1) = PDB(N,1)
1305 write(message,*)'easttend p',j,n,pdbdy2dtemp1(i,j,1)
1306 call wrf_debug(10,message)
1315 CALL output_auxinput4 ( id4, grid , config_flags , ierr )
1321 write(message,*)' assemble_output loop=',loop,' in IF block'
1322 call wrf_message(message)
1324 ! Open the boundary file.
1326 IF ( loop .eq. 2 ) THEN
1327 CALL construct_filename1( bdyname , 'wrfbdy' , grid%id , 2 )
1328 CALL open_w_dataset ( id, TRIM(bdyname) , grid , config_flags , &
1329 output_boundary , "DATASET=BOUNDARY", ierr )
1330 IF ( ierr .NE. 0 ) THEN
1331 CALL wrf_error_fatal( 'real: error opening wrfbdy for writing' )
1333 ! grid%write_metadata = .true.
1336 ! grid%write_metadata = .true.
1337 ! grid%write_metadata = .false.
1338 CALL domain_clockadvance( grid )
1342 bdytmp_notph: if(.not.grid%use_prep_hybrid) then
1344 !-----------------------------------------------------------------------
1345 !*** SOUTHERN BOUNDARY
1346 !-----------------------------------------------------------------------
1350 DO k = kps , MIN(kde,kpe)
1351 DO i = ips , MIN(ide,ipe)
1352 ubdy3dtemp2(i,j,k) = grid%u(i,j,k)
1353 vbdy3dtemp2(i,j,k) = grid%v(i,j,k)
1354 tbdy3dtemp2(i,j,k) = grid%t(i,j,k)
1355 qbdy3dtemp2(i,j,k) = grid%q(i,j,k)
1356 cwmbdy3dtemp2(i,j,k) = grid%cwm(i,j,k)
1357 q2bdy3dtemp2(i,j,k) = grid%q2(i,j,k)
1361 DO i = ips , MIN(ide,ipe)
1362 pdbdy2dtemp2(i,j,1) = grid%pd(i,j)
1367 !-----------------------------------------------------------------------
1368 !*** NORTHERN BOUNDARY
1369 !-----------------------------------------------------------------------
1373 DO k = kps , MIN(kde,kpe)
1374 DO i = ips , MIN(ide,ipe)
1375 ubdy3dtemp2(i,j,k) = grid%u(i,j,k)
1376 vbdy3dtemp2(i,j,k) = grid%v(i,j,k)
1377 tbdy3dtemp2(i,j,k) = grid%t(i,j,k)
1378 qbdy3dtemp2(i,j,k) = grid%q(i,j,k)
1379 cwmbdy3dtemp2(i,j,k) = grid%cwm(i,j,k)
1380 q2bdy3dtemp2(i,j,k) = grid%q2(i,j,k)
1384 DO i = ips , MIN(ide,ipe)
1385 pdbdy2dtemp2(i,j,1) = grid%pd(i,j)
1389 !-----------------------------------------------------------------------
1390 !*** WESTERN BOUNDARY
1391 !-----------------------------------------------------------------------
1395 DO k = kps , MIN(kde,kpe)
1398 write(message,*)' assemble_ouput loop=',loop,' inc_h=',inc_h,' jps=',jps
1399 call wrf_debug(10,message)
1401 DO j = jps+inc_h, MIN(jde,jpe),2
1402 if (J .ge. 3 .and. J .le. jde-2 .and. mod(J,2) .eq. 1) then
1403 tbdy3dtemp2(i,j,k) = grid%t(i,j,k)
1405 write(message,*)' loop=',loop,' i=',i,' j=',j,' tbdy3dtemp1(i,j,k)=',tbdy3dtemp1(i,j,k)
1406 call wrf_debug(10,message)
1408 qbdy3dtemp2(i,j,k) = grid%q(i,j,k)
1409 cwmbdy3dtemp2(i,j,k) = grid%cwm(i,j,k)
1410 q2bdy3dtemp2(i,j,k) = grid%q2(i,j,k)
1415 DO k = kps , MIN(kde,kpe)
1417 DO j = jps+inc_v, MIN(jde,jpe),2
1418 if (J .ge. 2 .and. J .le. jde-1 .and. mod(J,2) .eq. 0) then
1419 ubdy3dtemp2(i,j,k) = grid%u(i,j,k)
1420 vbdy3dtemp2(i,j,k) = grid%v(i,j,k)
1426 DO j = jps+inc_h, MIN(jde,jpe),2
1427 if (J .ge. 3 .and. J .le. jde-2 .and. mod(J,2) .eq. 1) then
1428 pdbdy2dtemp2(i,j,1) = grid%pd(i,j)
1429 write(message,*)' loop=',loop,' i=',i,' j=',j,' pdbdy2dtemp1(i,j)=',pdbdy2dtemp1(i,j,1)
1430 CALL wrf_debug(10,message)
1435 !-----------------------------------------------------------------------
1436 !*** EASTERN BOUNDARY
1437 !-----------------------------------------------------------------------
1442 DO k = kps , MIN(kde,kpe)
1444 DO j = jps+inc_h, MIN(jde,jpe),2
1445 if (J .ge. 3 .and. J .le. jde-2 .and. mod(J,2) .eq. 1) then
1446 tbdy3dtemp2(i,j,k) = grid%t(i,j,k)
1447 qbdy3dtemp2(i,j,k) = grid%q(i,j,k)
1448 cwmbdy3dtemp2(i,j,k) = grid%cwm(i,j,k)
1449 q2bdy3dtemp2(i,j,k) = grid%q2(i,j,k)
1454 DO k = kps , MIN(kde,kpe)
1456 DO j = jps+inc_v, MIN(jde,jpe),2
1457 if (J .ge. 2 .and. J .le. jde-1 .and. mod(J,2) .eq. 0) then
1458 ubdy3dtemp2(i,j,k) = grid%u(i,j,k)
1459 vbdy3dtemp2(i,j,k) = grid%v(i,j,k)
1465 DO j = jps+inc_h, MIN(jde,jpe),2
1466 if (J .ge. 3 .and. J .le. jde-2 .and. mod(J,2) .eq. 1) then
1467 pdbdy2dtemp2(i,j,1) = grid%pd(i,j)
1474 !-----------------------------------------------------------------------
1475 ! During all of the loops after the first loop,
1476 ! we first compute the boundary
1477 ! tendencies with the current data values
1478 ! (*bdy3dtemp2 arrays) and the previously
1479 ! saved information stored in the *bdy3dtemp1 arrays.
1482 CALL stuff_bdytend_ijk ( ubdy3dtemp2 , ubdy3dtemp1 , REAL(interval_seconds),&
1483 grid%u_btxs, grid%u_btxe, &
1484 grid%u_btys, grid%u_btye, &
1485 'N', spec_bdy_width , &
1486 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1487 ims , ime , jms , jme , kms , kme , &
1488 ips , ipe , jps , jpe , kps , kpe+1 )
1490 CALL stuff_bdytend_ijk ( vbdy3dtemp2 , vbdy3dtemp1 , REAL(interval_seconds),&
1491 grid%v_btxs, grid%v_btxe, &
1492 grid%v_btys, grid%v_btye, &
1493 'N', spec_bdy_width , &
1494 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1495 ims , ime , jms , jme , kms , kme , &
1496 ips , ipe , jps , jpe , kps , kpe+1 )
1498 CALL stuff_bdytend_ijk ( tbdy3dtemp2 , tbdy3dtemp1 , REAL(interval_seconds),&
1499 grid%t_btxs, grid%t_btxe, &
1500 grid%t_btys, grid%t_btye, &
1501 'N', spec_bdy_width , &
1502 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1503 ims , ime , jms , jme , kms , kme , &
1504 ips , ipe , jps , jpe , kps , kpe+1 )
1506 CALL stuff_bdytend_ijk ( cwmbdy3dtemp2 , cwmbdy3dtemp1 , REAL(interval_seconds),&
1507 grid%cwm_btxs, grid%cwm_btxe, &
1508 grid%cwm_btys, grid%cwm_btye, &
1509 'N', spec_bdy_width , &
1510 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1511 ims , ime , jms , jme , kms , kme , &
1512 ips , ipe , jps , jpe , kps , kpe+1 )
1514 CALL stuff_bdytend_ijk ( qbdy3dtemp2 , qbdy3dtemp1 , REAL(interval_seconds),&
1515 grid%q_btxs, grid%q_btxe, &
1516 grid%q_btys, grid%q_btye, &
1517 'N', spec_bdy_width , &
1518 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1519 ims , ime , jms , jme , kms , kme , &
1520 ips , ipe , jps , jpe , kps , kpe+1 )
1522 CALL stuff_bdytend_ijk ( q2bdy3dtemp2 , q2bdy3dtemp1 , REAL(interval_seconds),&
1523 grid%q2_btxs, grid%q2_btxe, &
1524 grid%q2_btys, grid%q2_btye, &
1525 'N', spec_bdy_width , &
1526 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1527 ims , ime , jms , jme , kms , kme , &
1528 ips , ipe , jps , jpe , kps , kpe+1 )
1530 CALL stuff_bdytend_ijk( pdbdy2dtemp2 , pdbdy2dtemp1, REAL(interval_seconds),&
1531 grid%pd_btxs, grid%pd_btxe, &
1532 grid%pd_btys, grid%pd_btye, &
1533 'M', spec_bdy_width , &
1534 ids , ide+1 , jds , jde+1 , 1 , 1 , &
1535 ims , ime , jms , jme , 1 , 1 , &
1536 ips , ipe , jps , jpe , 1 , 1 )
1540 ! Both pieces of the boundary data are now
1541 ! available to be written (initial time and tendency).
1542 ! This looks ugly, these date shifting things.
1543 ! What's it for? We want the "Times" variable
1544 ! in the lateral BDY file to have the valid times
1545 ! of when the initial fields are written.
1546 ! That's what the loop-2 thingy is for with the start date.
1547 ! We increment the start_date so
1548 ! that the starting time in the attributes is the
1549 ! second time period. Why you may ask. I
1550 ! agree, why indeed.
1552 temp24= current_date
1554 start_date = current_date
1555 CALL geth_newdate ( temp19 , temp24b(1:19) , &
1556 (loop-2) * model_config_rec%interval_seconds )
1557 current_date = temp19 // '.0000'
1558 CALL domain_clock_set( grid, current_date(1:19) )
1559 write(message,*) 'LBC valid between these times ',current_date, ' ',start_date
1560 CALL wrf_message(message)
1562 CALL output_boundary ( id, grid , config_flags , ierr )
1563 current_date = temp24
1564 start_date = temp24b
1566 ! OK, for all of the loops, we output the initialzation
1567 ! data, which would allow us to
1568 ! start the model at any of the available analysis time periods.
1570 ! WRITE ( loop_char , FMT = '(I4.4)' ) loop
1571 ! CALL open_w_dataset ( id1, 'wrfinput'//loop_char , grid , config_flags , output_input , "DATASET=INPUT", ierr )
1572 ! IF ( ierr .NE. 0 ) THEN
1573 ! CALL wrf_error_fatal( 'real: error opening wrfinput'//loop_char//' for writing' )
1575 ! grid%write_metadata = .true.
1577 ! CALL calc_current_date ( grid%id , 0. )
1578 ! CALL output_input ( id1, grid , config_flags , ierr )
1579 ! CALL close_dataset ( id1 , config_flags , "DATASET=INPUT" )
1581 ! Is this or is this not the last time time? We can remove some unnecessary
1582 ! stores if it is not.
1584 IF ( loop .LT. time_loop_max ) THEN
1586 ! We need to save the 3d data to compute a
1587 ! difference during the next loop. Couple the
1588 ! 3d fields with total mu (mub + mu_2) and the
1589 ! stagger-specific map scale factor.
1590 ! We load up the boundary data again for use in the next loop.
1593 !mp change these limits?????????
1598 ubdy3dtemp1(i,j,k) = ubdy3dtemp2(i,j,k)
1599 vbdy3dtemp1(i,j,k) = vbdy3dtemp2(i,j,k)
1600 tbdy3dtemp1(i,j,k) = tbdy3dtemp2(i,j,k)
1601 cwmbdy3dtemp1(i,j,k) = cwmbdy3dtemp2(i,j,k)
1602 qbdy3dtemp1(i,j,k) = qbdy3dtemp2(i,j,k)
1603 q2bdy3dtemp1(i,j,k) = q2bdy3dtemp2(i,j,k)
1608 !mp change these limits?????????
1612 pdbdy2dtemp1(i,j,1) = pdbdy2dtemp2(i,j,1)
1616 ! There are 2 components to the lateral boundaries.
1617 ! First, there is the starting
1618 ! point of this time period - just the outer few rows and columns.
1620 CALL stuff_bdy_ijk (ubdy3dtemp1, grid%u_bxs, grid%u_bxe, &
1621 grid%u_bys, grid%u_bye, &
1622 'N', spec_bdy_width , &
1623 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1624 ims , ime , jms , jme , kms , kme , &
1625 ips , ipe , jps , jpe , kps , kpe+1 )
1627 CALL stuff_bdy_ijk (vbdy3dtemp1, grid%v_bxs, grid%v_bxe, &
1628 grid%v_bys, grid%v_bye, &
1629 'N', spec_bdy_width , &
1630 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1631 ims , ime , jms , jme , kms , kme , &
1632 ips , ipe , jps , jpe , kps , kpe+1 )
1634 CALL stuff_bdy_ijk (tbdy3dtemp1, grid%t_bxs, grid%t_bxe, &
1635 grid%t_bys, grid%t_bye, &
1636 'N', spec_bdy_width , &
1637 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1638 ims , ime , jms , jme , kms , kme , &
1639 ips , ipe , jps , jpe , kps , kpe+1 )
1641 CALL stuff_bdy_ijk (cwmbdy3dtemp1, grid%cwm_bxs, grid%cwm_bxe, &
1642 grid%cwm_bys, grid%cwm_bye, &
1643 'N', spec_bdy_width , &
1644 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1645 ims , ime , jms , jme , kms , kme , &
1646 ips , ipe , jps , jpe , kps , kpe+1 )
1648 CALL stuff_bdy_ijk (qbdy3dtemp1, grid%q_bxs, grid%q_bxe, &
1649 grid%q_bys, grid%q_bye, &
1650 'N', spec_bdy_width , &
1651 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1652 ims , ime , jms , jme , kms , kme , &
1653 ips , ipe , jps , jpe , kps , kpe+1 )
1655 CALL stuff_bdy_ijk (q2bdy3dtemp1, grid%q2_bxs, grid%q2_bxe, &
1656 grid%q2_bys, grid%q2_bye, &
1657 'N', spec_bdy_width , &
1658 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1659 ims , ime , jms , jme , kms , kme , &
1660 ips , ipe , jps , jpe , kps , kpe+1 )
1662 CALL stuff_bdy_ijk (pdbdy2dtemp1,grid%pd_bxs, grid%pd_bxe, &
1663 grid%pd_bys, grid%pd_bye, &
1664 'M', spec_bdy_width , &
1665 ids , ide+1 , jds , jde+1 , 1 , 1 , &
1666 ims , ime , jms , jme , 1 , 1 , &
1667 ips , ipe , jps , jpe , 1 , 1 )
1669 ELSE IF ( loop .EQ. time_loop_max ) THEN
1671 ! If this is the last time through here, we need to close the files.
1673 CALL close_dataset ( id , config_flags , "DATASET=BOUNDARY" )
1677 END IF main_loop_test
1680 if(alloc_ph_arrays) then
1681 call wrf_debug(1,'DEALLOCATE PREP_HYBRID BOUNARY ARRAYS')
1682 deallocate(TB,QB,CWMB,UB,VB,PDB)
1686 END SUBROUTINE assemble_output