1 ! Create an initial data set for the WRF model based on an ideal condition
2 ! This program is specifically set up for the NMM core.
8 USE module_initialize_ideal
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
60 INTEGER :: start_year , start_month , start_day
61 INTEGER :: start_hour , start_minute , start_second
62 INTEGER :: end_year , end_month , end_day , &
63 end_hour , end_minute , end_second
64 INTEGER :: interval_seconds , real_data_init_type
65 INTEGER :: time_loop_max , time_loop, rc
68 #include "version_decl"
69 #include "commit_decl"
72 SUBROUTINE Setup_Timekeeping( grid )
74 TYPE(domain), POINTER :: grid
75 END SUBROUTINE Setup_Timekeeping
78 ! Define the name of this program (program_name defined in module_domain)
80 program_name = "IDEAL_HWRF " // TRIM(release_version) // " PREPROCESSOR"
88 ! Initialize the modules used by the WRF system.
89 ! Many of the CALLs made from the
90 ! init_modules routine are NO-OPs. Typical initializations
92 ! REAL, setting the file handles to a pre-use value, defining moisture and
93 ! chemistry indices, etc.
95 CALL wrf_debug ( 100 , 'ideal_hwrf: calling init_modules ' )
97 !!!! CALL init_modules
98 CALL init_modules(1) ! Phase 1 returns after MPI_INIT() (if it is called)
99 CALL WRFU_Initialize( defaultCalKind=WRFU_CAL_GREGORIAN, rc=rc )
100 CALL init_modules(2) ! Phase 2 resumes after MPI_INIT() (if it is called)
102 ! The configuration switches mostly come from the NAMELIST input.
105 IF ( wrf_dm_on_monitor() ) THEN
106 write(message,*) 'call initial_config'
107 CALL wrf_message ( message )
110 CALL get_config_as_buffer( configbuf, configbuflen, nbytes )
111 CALL wrf_dm_bcast_bytes( configbuf, nbytes )
112 CALL set_config_as_buffer( configbuf, configbuflen )
113 CALL wrf_dm_initialize
118 CALL check_nml_consistency
119 CALL set_physics_rconfigs
121 CALL nl_get_debug_level ( 1, debug_level )
122 CALL set_wrf_debug_level ( debug_level )
124 CALL wrf_message ( program_name )
125 CALL wrf_message ( commit_version )
127 ! Allocate the space for the mother of all domains.
129 NULLIFY( null_domain )
130 CALL wrf_debug ( 100 , 'ideal_hwrf: calling alloc_and_configure_domain ' )
131 CALL alloc_and_configure_domain ( domain_id = 1 , &
133 parent = null_domain , &
138 #include "deref_kludge.h"
139 CALL Setup_Timekeeping ( grid )
140 CALL domain_clock_set( grid, &
141 time_step_seconds=model_config_rec%interval_seconds )
142 CALL wrf_debug ( 100 , 'ideal_hwrf: calling set_scalar_indices_from_config ' )
143 CALL set_scalar_indices_from_config ( grid%id , idum1, idum2 )
145 CALL wrf_debug ( 100 , 'ideal_hwrf: calling model_to_grid_config_rec ' )
147 CALL model_to_grid_config_rec ( grid%id , model_config_rec , config_flags )
149 write(message,*) 'after model_to_grid_config_rec, e_we, e_sn are: ', &
150 config_flags%e_we, config_flags%e_sn
151 CALL wrf_message(message)
153 ! Initialize the WRF IO: open files, init file handles, etc.
155 CALL wrf_debug ( 100 , 'ideal_hwrf: calling init_wrfio' )
158 ! Some of the configuration values may have been modified from the initial READ
159 ! of the NAMELIST, so we re-broadcast the configuration records.
162 CALL wrf_debug ( 100 , 'ideal_hwrf: re-broadcast the configuration records' )
163 CALL get_config_as_buffer( configbuf, configbuflen, nbytes )
164 CALL wrf_dm_bcast_bytes( configbuf, nbytes )
165 CALL set_config_as_buffer( configbuf, configbuflen )
168 ! No looping in this layer.
170 CALL med_sidata_input ( grid , config_flags )
174 CALL wrf_debug ( 0 , 'ideal_hwrf: SUCCESS COMPLETE IDEAL_HWRF INIT' )
180 CALL WRFU_Finalize( rc=rc )
182 END PROGRAM ideal_nmm
184 SUBROUTINE med_sidata_input ( grid , config_flags )
190 USE module_bc_time_utilities
191 USE module_initialize_ideal
192 USE module_optional_input
193 #if ( WRF_CHEM == 1 )
194 USE module_input_chem_data
195 USE module_input_chem_bioemiss
207 SUBROUTINE start_domain ( grid , allowed_to_read )
210 LOGICAL, INTENT(IN) :: allowed_to_read
211 END SUBROUTINE start_domain
216 TYPE (grid_config_rec_type) :: config_flags
218 INTEGER :: time_step_begin_restart
219 INTEGER :: idsi , ierr , myproc
220 CHARACTER (LEN=256) :: si_inpname
221 CHARACTER (LEN=132) :: message
223 CHARACTER(LEN=19) :: start_date_char , end_date_char , &
224 current_date_char , next_date_char
226 INTEGER :: time_loop_max , loop
227 INTEGER :: julyr , julday , LEN
229 INTEGER :: io_form_auxinput1
230 INTEGER, EXTERNAL :: use_package
232 LOGICAL :: using_binary_wrfsi
237 INTEGER :: numx_sm_levels_input,numx_st_levels_input
238 REAL,DIMENSION(100) :: smx_levels_input,stx_levels_input
242 ! see http://www.mmm.ucar.edu/wrf/WG2/topics/deref_kludge.htm
243 INTEGER :: sm31 , em31 , sm32 , em32 , sm33 , em33
244 INTEGER :: sm31x, em31x, sm32x, em32x, sm33x, em33x
245 INTEGER :: sm31y, em31y, sm32y, em32y, sm33y, em33y
251 ! The *INIT arrays are used to read init data written out by hwrf_prep_hybrid
252 REAL,ALLOCATABLE,DIMENSION(:,:,:)::TINIT,UINIT,VINIT,QINIT,CWMINIT
253 REAL,ALLOCATABLE,DIMENSION(:,:,:)::PINIT
254 REAL,ALLOCATABLE,DIMENSION(:,:)::PDINIT
256 ! The *B arrays are used to read boundary data written out by hwrf_prep_hybrid
257 REAL,ALLOCATABLE,DIMENSION(:,:,:)::TB,UB,VB,QB,CWMB
258 REAL,ALLOCATABLE,DIMENSION(:,:)::PDB
260 INTEGER :: KB, LM, IM, JM, iunit_gfs, N
263 LOGICAL,EXTERNAL :: WRF_DM_ON_MONITOR
264 integer :: ids,ide, jds,jde, kds,kde
265 integer :: ims,ime, jms,jme, kms,kme
266 integer :: its,ite, jts,jte, kts,kte
271 #include "deref_kludge.h"
274 grid%input_from_file = .true.
275 grid%input_from_file = .false.
277 CALL compute_si_start_and_end ( model_config_rec%start_year (grid%id) , &
278 model_config_rec%start_month (grid%id) , &
279 model_config_rec%start_day (grid%id) , &
280 model_config_rec%start_hour (grid%id) , &
281 model_config_rec%start_minute(grid%id) , &
282 model_config_rec%start_second(grid%id) , &
283 model_config_rec% end_year (grid%id) , &
284 model_config_rec% end_month (grid%id) , &
285 model_config_rec% end_day (grid%id) , &
286 model_config_rec% end_hour (grid%id) , &
287 model_config_rec% end_minute(grid%id) , &
288 model_config_rec% end_second(grid%id) , &
289 model_config_rec%interval_seconds , &
290 model_config_rec%real_data_init_type , &
291 start_date_char , end_date_char , time_loop_max )
293 ! Here we define the initial time to process, for later use by the code.
295 current_date_char = start_date_char
296 ! start_date = start_date_char // '.0000'
297 start_date = start_date_char
298 current_date = start_date
300 CALL nl_set_bdyfrq ( grid%id , REAL(model_config_rec%interval_seconds) )
302 ! Loop over each time period to process.
304 write(message,*) 'time_loop_max: ', time_loop_max
305 CALL wrf_message(message)
306 DO loop = 1 , time_loop_max
308 internal_time_loop=loop
310 write(message,*) 'loop=', loop
311 CALL wrf_message(message)
313 write(message,*) '-----------------------------------------------------------'
314 CALL wrf_message(message)
317 CALL wrf_message(message)
318 write(message,'(A,A,A,I2,A,I2)') ' Current date being processed: ', &
319 current_date, ', which is loop #',loop,' out of ',time_loop_max
320 CALL wrf_message(message)
322 ! After current_date has been set, fill in the julgmt stuff.
324 CALL geth_julgmt ( config_flags%julyr , config_flags%julday , &
327 ! Now that the specific Julian info is available,
328 ! save these in the model config record.
330 CALL nl_set_gmt (grid%id, config_flags%gmt)
331 CALL nl_set_julyr (grid%id, config_flags%julyr)
332 CALL nl_set_julday (grid%id, config_flags%julday)
334 CALL nl_get_io_form_auxinput1( 1, io_form_auxinput1 )
335 using_binary_wrfsi=.false.
338 write(message,*) 'TRIM(config_flags%auxinput1_inname): ', TRIM(config_flags%auxinput1_inname)
339 CALL wrf_message(message)
342 ifph_onlyfirst: if(.not.grid%use_prep_hybrid .or. loop==1) then
344 IF (config_flags%auxinput1_inname(1:10) .eq. 'real_input') THEN
345 using_binary_wrfsi=.true.
348 SELECT CASE ( use_package(io_form_auxinput1) )
352 ! Open the wrfinput file.
354 current_date_char(11:11)='_'
356 WRITE ( wrf_err_message , FMT='(A,A)' )'med_sidata_input: calling open_r_dataset for ',TRIM(config_flags%auxinput1_inname)
357 CALL wrf_debug ( 100 , wrf_err_message )
358 IF ( config_flags%auxinput1_inname(1:8) .NE. 'wrf_real' ) THEN
359 CALL construct_filename4a( si_inpname , config_flags%auxinput1_inname , grid%id , 2 , current_date_char , &
360 config_flags%io_form_auxinput1 )
362 CALL construct_filename2a( si_inpname , config_flags%auxinput1_inname , grid%id , 2 , current_date_char )
364 CALL open_r_dataset ( idsi, TRIM(si_inpname) , grid , config_flags , "DATASET=AUXINPUT1", ierr )
366 IF ( ierr .NE. 0 ) THEN
367 CALL wrf_error_fatal( 'error opening ' // TRIM(si_inpname) // ' for input; bad date in namelist or file not in directory' )
372 CALL wrf_debug (100, 'med_sidata_input: call input_auxinput1_wrf')
374 CALL input_auxinput1 ( idsi, grid, config_flags, ierr )
376 ! Possible optional SI input. This sets flags used by init_domain.
378 IF ( loop .EQ. 1 ) THEN
379 CALL wrf_debug (100, 'med_sidata_input: call init_module_optional_input' )
380 CALL init_module_optional_input ( grid , config_flags )
381 CALL wrf_debug ( 100 , 'med_sidata_input: calling optional_input' )
383 CALL optional_input ( grid , idsi , config_flags )
384 write(0,*) 'maxval st_input(1) within ideal_hwrf: ', maxval(st_input(:,1,:))
387 CALL close_dataset ( idsi , config_flags , "DATASET=AUXINPUT1" )
393 ! Possible optional SI input. This sets flags used by init_domain.
395 IF ( loop .EQ. 1 ) THEN
396 CALL wrf_debug (100, 'med_sidata_input: call init_module_optional_input' )
397 CALL init_module_optional_input ( grid , config_flags )
400 IF (using_binary_wrfsi) THEN
402 current_date_char(11:11)='_'
403 CALL read_si ( grid, current_date_char )
404 current_date_char(11:11)='T'
408 write(message,*) 'binary WPS branch'
409 CALL wrf_message(message)
410 current_date_char(11:11)='_'
411 CALL construct_filename4a( si_inpname , config_flags%auxinput1_inname , grid%id , 2 , current_date_char , &
412 config_flags%io_form_auxinput1 )
413 CALL read_wps ( grid, trim(si_inpname), current_date_char, config_flags%num_metgrid_levels )
414 !!! bogus set some flags??
423 CALL wrf_error_fatal('ideal_hwrf: not valid io_form_auxinput1')
430 grid%vegfra=grid%vegfrc
431 grid%dfrlg=grid%dfl/9.81
436 ! Initialize the mother domain for this time period with input data.
438 CALL wrf_debug ( 100 , 'med_sidata_input: calling init_domain' )
439 grid%input_from_file = .true.
441 CALL init_domain ( grid )
444 read_phinit: if(grid%use_prep_hybrid) then
445 #if defined(DM_PARALLEL)
446 if(.not. wrf_dm_on_monitor()) then
447 call wrf_error_fatal('ideal_hwrf: in use_prep_hybrid mode, threading and mpi are forbidden.')
451 ph_loop1: if(loop==1) then
453 ! determine kds, ids, jds
454 SELECT CASE ( model_data_order )
455 CASE ( DATA_ORDER_ZXY )
456 kds = grid%sd31 ; kde = grid%ed31 ;
457 ids = grid%sd32 ; ide = grid%ed32 ;
458 jds = grid%sd33 ; jde = grid%ed33 ;
460 kms = grid%sm31 ; kme = grid%em31 ;
461 ims = grid%sm32 ; ime = grid%em32 ;
462 jms = grid%sm33 ; jme = grid%em33 ;
464 kts = grid%sp31 ; kte = grid%ep31 ; ! tile is entire patch
465 its = grid%sp32 ; ite = grid%ep32 ; ! tile is entire patch
466 jts = grid%sp33 ; jte = grid%ep33 ; ! tile is entire patch
468 CASE ( DATA_ORDER_XYZ )
469 ids = grid%sd31 ; ide = grid%ed31 ;
470 jds = grid%sd32 ; jde = grid%ed32 ;
471 kds = grid%sd33 ; kde = grid%ed33 ;
473 ims = grid%sm31 ; ime = grid%em31 ;
474 jms = grid%sm32 ; jme = grid%em32 ;
475 kms = grid%sm33 ; kme = grid%em33 ;
477 its = grid%sp31 ; ite = grid%ep31 ; ! tile is entire patch
478 jts = grid%sp32 ; jte = grid%ep32 ; ! tile is entire patch
479 kts = grid%sp33 ; kte = grid%ep33 ; ! tile is entire patch
481 CASE ( DATA_ORDER_XZY )
482 ids = grid%sd31 ; ide = grid%ed31 ;
483 kds = grid%sd32 ; kde = grid%ed32 ;
484 jds = grid%sd33 ; jde = grid%ed33 ;
486 ims = grid%sm31 ; ime = grid%em31 ;
487 kms = grid%sm32 ; kme = grid%em32 ;
488 jms = grid%sm33 ; jme = grid%em33 ;
490 its = grid%sp31 ; ite = grid%ep31 ; ! tile is entire patch
491 kts = grid%sp32 ; kte = grid%ep32 ; ! tile is entire patch
492 jts = grid%sp33 ; jte = grid%ep33 ; ! tile is entire patch
495 ! Allocate 3D initialization arrays:
496 call wrf_message('ALLOCATE PREP_HYBRID INIT ARRAYS')
497 ALLOCATE ( TINIT (ids:(ide-1),kds:(kde-1) ,jds:(jde-1)) )
498 ALLOCATE ( PINIT (ids:(ide-1),kds:kde ,jds:(jde-1)) )
499 ALLOCATE ( UINIT (ids:(ide-1),kds:(kde-1) ,jds:(jde-1)) )
500 ALLOCATE ( VINIT (ids:(ide-1),kds:(kde-1) ,jds:(jde-1)) )
501 ALLOCATE ( QINIT (ids:(ide-1),kds:(kde-1) ,jds:(jde-1)) )
502 ALLOCATE ( CWMINIT(ids:(ide-1),kds:(kde-1) ,jds:(jde-1)) )
503 ALLOCATE ( PDINIT (ids:(ide-1), jds:(jde-1)) )
506 READ(900,iostat=ioerror) PDINIT,TINIT,QINIT,CWMINIT,UINIT,VINIT,PINIT
508 call wrf_error_fatal('Unable to read MAKBND output from unit 900.')
510 WRITE(0,*) 'U V T AT 10 10 10 ',UINIT(10,10,10),VINIT(10,10,10),TINIT(10,10,10)
511 ! Switch from IKJ to IJK ordering
514 grid%pd(I,J) = PDINIT(I,J)
517 grid%u(I,J,K) = UINIT(I,K,J)
518 grid%v(I,J,K) = VINIT(I,K,J)
519 grid%t(I,J,K) = TINIT(I,K,J)
520 grid%q(I,J,K) = QINIT(I,K,J)
521 grid%cwm(I,J,K) = CWMINIT(I,K,J)
523 ! Was commented out in original V2 HWRF too:
525 ! grid%nmm_pint(I,J,K) = pinit(I,K,J)
530 call wrf_message('DEALLOCATE PREP_HYBRID INIT ARRAYS')
531 deallocate(TINIT,PINIT,UINIT,VINIT,QINIT,CWMINIT,PDINIT)
536 CALL model_to_grid_config_rec ( grid%id, model_config_rec, config_flags )
538 ! Close this file that is output from the SI and input to this pre-proc.
540 CALL wrf_debug ( 100 , 'med_sidata_input: back from init_domain' )
543 !!! not sure about this, but doesnt seem like needs to be called each time
544 IF ( loop .EQ. 1 ) THEN
545 CALL start_domain ( grid , .TRUE.)
548 #if ( WRF_CHEM == 1 )
549 IF ( loop == 1 ) THEN
550 ! IF ( ( grid%chem_opt .EQ. RADM2 ) .OR. &
551 ! ( grid%chem_opt .EQ. RADM2SORG ) .OR. &
552 ! ( grid%chem_opt .EQ. RACM ) .OR. &
553 ! ( grid%chem_opt .EQ. RACMSORG ) ) THEN
554 IF( grid%chem_opt > 0 ) then
555 ! Read the chemistry data from a previous wrf forecast (wrfout file)
556 IF(grid%chem_in_opt == 1 ) THEN
557 message = 'INITIALIZING CHEMISTRY WITH OLD SIMULATION'
558 CALL wrf_message ( message )
560 CALL input_ext_chem_file( grid )
562 IF(grid%bio_emiss_opt == BEIS311 ) THEN
563 message = 'READING BEIS3.11 EMISSIONS DATA'
564 CALL wrf_message ( message )
565 CALL med_read_wrf_chem_bioemiss ( grid , config_flags)
566 else IF(grid%bio_emiss_opt == 3 ) THEN !shc
567 message = 'READING MEGAN 2 EMISSIONS DATA'
568 CALL wrf_message ( message )
569 CALL med_read_wrf_chem_bioemiss ( grid , config_flags)
572 ELSEIF(grid%chem_in_opt == 0)then
573 ! Generate chemistry data from a idealized vertical profile
574 message = 'STARTING WITH BACKGROUND CHEMISTRY '
575 CALL wrf_message ( message )
577 write(message,*)' ETA1 '
578 CALL wrf_message ( message )
579 ! write(message,*) grid%eta1
580 ! CALL wrf_message ( message )
582 CALL input_chem_profile ( grid )
584 IF(grid%bio_emiss_opt == BEIS311 ) THEN
585 message = 'READING BEIS3.11 EMISSIONS DATA'
586 CALL wrf_message ( message )
587 CALL med_read_wrf_chem_bioemiss ( grid , config_flags)
588 else IF(grid%bio_emiss_opt == 3 ) THEN !shc
589 message = 'READING MEGAN 2 EMISSIONS DATA'
590 CALL wrf_message ( message )
591 CALL med_read_wrf_chem_bioemiss ( grid , config_flags)
595 message = 'RUNNING WITHOUT CHEMISTRY INITIALIZATION'
596 CALL wrf_message ( message )
602 config_flags%isurban=1
603 config_flags%isoilwater=14
605 CALL assemble_output ( grid , config_flags , loop , time_loop_max )
607 ! Here we define the next time that we are going to process.
609 CALL geth_newdate ( current_date_char , start_date_char , &
610 loop * model_config_rec%interval_seconds )
611 current_date = current_date_char // '.0000'
613 CALL domain_clock_set( grid, current_date(1:19) )
615 write(message,*) 'current_date= ', current_date
616 CALL wrf_message(message)
619 END SUBROUTINE med_sidata_input
621 SUBROUTINE compute_si_start_and_end ( &
622 start_year, start_month, start_day, start_hour, &
623 start_minute, start_second, &
624 end_year , end_month , end_day , end_hour , &
625 end_minute , end_second , &
626 interval_seconds , real_data_init_type , &
627 start_date_char , end_date_char , time_loop_max )
633 INTEGER :: start_year , start_month , start_day , &
634 start_hour , start_minute , start_second
635 INTEGER :: end_year , end_month , end_day , &
636 end_hour , end_minute , end_second
637 INTEGER :: interval_seconds , real_data_init_type
638 INTEGER :: time_loop_max , time_loop
640 CHARACTER(LEN=132) :: message
641 CHARACTER(LEN=19) :: current_date_char , start_date_char , &
642 end_date_char , next_date_char
644 ! WRITE ( start_date_char , FMT = &
645 ! '(I4.4,"-",I2.2,"-",I2.2,"_",I2.2,":",I2.2,":",I2.2)' ) &
646 ! start_year,start_month,start_day,start_hour,start_minute,start_second
647 ! WRITE ( end_date_char , FMT = &
648 ! '(I4.4,"-",I2.2,"-",I2.2,"_",I2.2,":",I2.2,":",I2.2)' ) &
649 ! end_year, end_month, end_day, end_hour, end_minute, end_second
651 WRITE ( start_date_char , FMT = &
652 '(I4.4,"-",I2.2,"-",I2.2,"T",I2.2,":",I2.2,":",I2.2)' ) &
653 start_year,start_month,start_day,start_hour,start_minute,start_second
654 WRITE ( end_date_char , FMT = &
655 '(I4.4,"-",I2.2,"-",I2.2,"T",I2.2,":",I2.2,":",I2.2)' ) &
656 end_year, end_month, end_day, end_hour, end_minute, end_second
658 ! start_date = start_date_char // '.0000'
660 ! Figure out our loop count for the processing times.
663 PRINT '(A,I4,A,A,A)','Time period #',time_loop, &
664 ' to process = ',start_date_char,'.'
665 current_date_char = start_date_char
667 CALL geth_newdate (next_date_char, current_date_char, interval_seconds )
668 IF ( next_date_char .LT. end_date_char ) THEN
669 time_loop = time_loop + 1
670 PRINT '(A,I4,A,A,A)','Time period #',time_loop,&
671 ' to process = ',next_date_char,'.'
672 current_date_char = next_date_char
673 ELSE IF ( next_date_char .EQ. end_date_char ) THEN
674 time_loop = time_loop + 1
675 PRINT '(A,I4,A,A,A)','Time period #',time_loop,&
676 ' to process = ',next_date_char,'.'
677 PRINT '(A,I4,A)','Total analysis times to input = ',time_loop,'.'
678 time_loop_max = time_loop
680 ELSE IF ( next_date_char .GT. end_date_char ) THEN
681 PRINT '(A,I4,A)','Total analysis times to input = ',time_loop,'.'
682 time_loop_max = time_loop
686 write(message,*) 'done in si_start_and_end'
687 CALL wrf_message(message)
688 END SUBROUTINE compute_si_start_and_end
690 SUBROUTINE assemble_output ( grid , config_flags , loop , time_loop_max )
692 !!! replace with something? USE module_big_step_utilities_em
702 external get_wrf_debug_level
707 TYPE (grid_config_rec_type) :: config_flags
708 INTEGER , INTENT(IN) :: loop , time_loop_max
710 INTEGER :: ids , ide , jds , jde , kds , kde
711 INTEGER :: ims , ime , jms , jme , kms , kme
712 INTEGER :: ips , ipe , jps , jpe , kps , kpe
713 INTEGER :: ijds , ijde , spec_bdy_width
714 INTEGER :: inc_h,inc_v
715 INTEGER :: i , j , k , idts
717 INTEGER :: id1 , interval_seconds , ierr, rc, sst_update
718 INTEGER , SAVE :: id ,id4
719 CHARACTER (LEN=80) :: inpname , bdyname
720 CHARACTER(LEN= 4) :: loop_char
721 CHARACTER(LEN=132) :: message
722 character *19 :: temp19
723 character *24 :: temp24 , temp24b
725 REAL, DIMENSION(:,:,:), ALLOCATABLE, SAVE :: ubdy3dtemp1 , vbdy3dtemp1 ,&
727 cwmbdy3dtemp1 , qbdy3dtemp1,&
728 q2bdy3dtemp1 , pdbdy2dtemp1
729 REAL, DIMENSION(:,:,:), ALLOCATABLE, SAVE :: ubdy3dtemp2 , vbdy3dtemp2 , &
731 cwmbdy3dtemp2 , qbdy3dtemp2, &
732 q2bdy3dtemp2, pdbdy2dtemp2
736 ! see http://www.mmm.ucar.edu/wrf/WG2/topics/deref_kludge.htm
737 INTEGER :: sm31 , em31 , sm32 , em32 , sm33 , em33
738 INTEGER :: sm31x, em31x, sm32x, em32x, sm33x, em33x
739 INTEGER :: sm31y, em31y, sm32y, em32y, sm33y, em33y
745 ! The *B arrays are used to read boundary data written out by hwrf_prep_hybrid
746 REAL,ALLOCATABLE,DIMENSION(:,:,:)::TB,UB,VB,QB,CWMB
747 REAL,ALLOCATABLE,DIMENSION(:,:)::PDB
749 ! Dimensions and looping variables:
750 INTEGER :: KB, LM, IM, JM, N
752 ! Unit number to read boundary data from (changes each time)
755 ! Did we allocate the prep_hybrid input arrays?
756 LOGICAL :: alloc_ph_arrays
761 #include "deref_kludge.h"
764 alloc_ph_arrays=.false.
765 call get_wrf_debug_level(debug)
768 ! Various sizes that we need to be concerned about.
771 ide = grid%ed31-1 ! 030730tst
773 jde = grid%ed32-1 ! 030730tst
775 kde = grid%ed33-1 ! 030730tst
785 ipe = grid%ep31-1 ! 030730tst
787 jpe = grid%ep32-1 ! 030730tst
789 kpe = grid%ep33-1 ! 030730tst
791 if (IPE .ne. IDE) IPE=IPE+1
792 if (JPE .ne. JDE) JPE=JPE+1
794 write(message,*) 'assemble output (ids,ide): ', ids,ide
795 CALL wrf_message(message)
796 write(message,*) 'assemble output (ims,ime): ', ims,ime
797 CALL wrf_message(message)
798 write(message,*) 'assemble output (ips,ipe): ', ips,ipe
799 CALL wrf_message(message)
801 write(message,*) 'assemble output (jds,jde): ', jds,jde
802 CALL wrf_message(message)
803 write(message,*) 'assemble output (jms,jme): ', jms,jme
804 CALL wrf_message(message)
805 write(message,*) 'assemble output (jps,jpe): ', jps,jpe
806 CALL wrf_message(message)
808 write(message,*) 'assemble output (kds,kde): ', kds,kde
809 CALL wrf_message(message)
810 write(message,*) 'assemble output (kms,kme): ', kms,kme
811 CALL wrf_message(message)
812 write(message,*) 'assemble output (kps,kpe): ', kps,kpe
813 CALL wrf_message(message)
815 ijds = MIN ( ids , jds )
816 !mptest030805 ijde = MAX ( ide , jde )
817 ijde = MAX ( ide , jde ) + 1 ! to make stuff_bdy dimensions consistent with alloc
819 ! Boundary width, scalar value.
821 spec_bdy_width = model_config_rec%spec_bdy_width
822 interval_seconds = model_config_rec%interval_seconds
823 sst_update = model_config_rec%sst_update
825 !-----------------------------------------------------------------------
827 main_loop_test: IF ( loop .EQ. 1 ) THEN
829 !-----------------------------------------------------------------------
831 IF ( time_loop_max .NE. 1 ) THEN
832 IF(sst_update .EQ. 1)THEN
833 CALL construct_filename1( inpname , 'wrflowinp' , grid%id , 2 )
834 CALL open_w_dataset ( id4, TRIM(inpname) , grid , config_flags , output_auxinput4 , "DATASET=AUXINPUT4", ierr )
835 IF ( ierr .NE. 0 ) THEN
836 CALL wrf_error_fatal( 'ideal_hwrf: error opening wrflowinp for writing' )
838 CALL output_auxinput4 ( id4, grid , config_flags , ierr )
843 ! This is the space needed to save the current 3d data for use in computing
844 ! the lateral boundary tendencies.
846 ALLOCATE ( ubdy3dtemp1(ims:ime,jms:jme,kms:kme) )
847 ALLOCATE ( vbdy3dtemp1(ims:ime,jms:jme,kms:kme) )
848 ALLOCATE ( tbdy3dtemp1(ims:ime,jms:jme,kms:kme) )
849 ALLOCATE ( qbdy3dtemp1(ims:ime,jms:jme,kms:kme) )
850 ALLOCATE ( cwmbdy3dtemp1(ims:ime,jms:jme,kms:kme) )
851 ALLOCATE ( q2bdy3dtemp1(ims:ime,jms:jme,kms:kme) )
852 ALLOCATE ( pdbdy2dtemp1(ims:ime,jms:jme,1:1) )
862 ALLOCATE ( ubdy3dtemp2(ims:ime,jms:jme,kms:kme) )
863 ALLOCATE ( vbdy3dtemp2(ims:ime,jms:jme,kms:kme) )
864 ALLOCATE ( tbdy3dtemp2(ims:ime,jms:jme,kms:kme) )
865 ALLOCATE ( qbdy3dtemp2(ims:ime,jms:jme,kms:kme) )
866 ALLOCATE ( cwmbdy3dtemp2(ims:ime,jms:jme,kms:kme) )
867 ALLOCATE ( q2bdy3dtemp2(ims:ime,jms:jme,kms:kme) )
868 ALLOCATE ( pdbdy2dtemp2(ims:ime,jms:jme,1:1) )
878 ! Open the wrfinput file. From this program, this is an *output* file.
880 CALL construct_filename1( inpname , 'wrfinput' , grid%id , 2 )
882 CALL open_w_dataset ( id1, TRIM(inpname) , grid , config_flags , &
883 output_input , "DATASET=INPUT", ierr )
885 IF ( ierr .NE. 0 ) THEN
886 CALL wrf_error_fatal( 'ideal_hwrf: error opening wrfinput for writing' )
889 ! CALL calc_current_date ( grid%id , 0. )
890 ! grid%write_metadata = .true.
892 write(message,*) 'making call to output_input'
893 CALL wrf_message(message)
895 CALL output_input ( id1, grid , config_flags , ierr )
898 !*** CLOSE THE WRFINPUT DATASET
900 CALL close_dataset ( id1 , config_flags , "DATASET=INPUT" )
902 ! We need to save the 3d data to compute a
903 ! difference during the next loop.
906 !-----------------------------------------------------------------------
907 !*** SOUTHERN BOUNDARY
908 !-----------------------------------------------------------------------
913 DO k = kps , MIN(kde,kpe)
914 DO i = ips , MIN(ide,ipe)
915 ubdy3dtemp1(i,j,k) = grid%u(i,j,k)
916 vbdy3dtemp1(i,j,k) = grid%v(i,j,k)
917 tbdy3dtemp1(i,j,k) = grid%t(i,j,k)
918 qbdy3dtemp1(i,j,k) = grid%q(i,j,k)
919 cwmbdy3dtemp1(i,j,k) = grid%cwm(i,j,k)
920 q2bdy3dtemp1(i,j,k) = grid%q2(i,j,k)
924 DO i = ips , MIN(ide,ipe)
925 pdbdy2dtemp1(i,j,1) = grid%pd(i,j)
930 !-----------------------------------------------------------------------
931 !*** NORTHERN BOUNDARY
932 !-----------------------------------------------------------------------
936 DO k = kps , MIN(kde,kpe)
937 DO i = ips , MIN(ide,ipe)
938 ubdy3dtemp1(i,j,k) = grid%u(i,j,k)
939 vbdy3dtemp1(i,j,k) = grid%v(i,j,k)
940 tbdy3dtemp1(i,j,k) = grid%t(i,j,k)
941 qbdy3dtemp1(i,j,k) = grid%q(i,j,k)
942 cwmbdy3dtemp1(i,j,k) = grid%cwm(i,j,k)
943 q2bdy3dtemp1(i,j,k) = grid%q2(i,j,k)
947 DO i = ips , MIN(ide,ipe)
948 pdbdy2dtemp1(i,j,1) = grid%pd(i,j)
953 !-----------------------------------------------------------------------
954 !*** WESTERN BOUNDARY
955 !-----------------------------------------------------------------------
957 write(message,*) 'western boundary, store winds over J: ', jps, min(jpe,jde)
958 CALL wrf_message(message)
962 DO k = kps , MIN(kde,kpe)
964 DO j = jps+inc_h, min(jde,jpe),2
966 if (J .ge. 3 .and. J .le. JDE-2 .and. mod(J,2) .eq. 1) then
967 tbdy3dtemp1(i,j,k) = grid%t(i,j,k)
968 qbdy3dtemp1(i,j,k) = grid%q(i,j,k)
969 cwmbdy3dtemp1(i,j,k) = grid%cwm(i,j,k)
970 q2bdy3dtemp1(i,j,k) = grid%q2(i,j,k)
972 write(message,*)' loop=',loop,' i=',i,' j=',j,' tbdy3dtemp1(i,j,k)=',tbdy3dtemp1(i,j,k)
973 CALL wrf_debug(10,message)
979 DO k = kps , MIN(kde,kpe)
981 DO j = jps+inc_v, min(jde,jpe),2
982 if (J .ge. 2 .and. J .le. JDE-1 .and. mod(J,2) .eq. 0) then
983 ubdy3dtemp1(i,j,k) = grid%u(i,j,k)
984 vbdy3dtemp1(i,j,k) = grid%v(i,j,k)
990 DO j = jps+inc_h, min(jde,jpe),2
991 if (J .ge. 3 .and. J .le. JDE-2 .and. mod(J,2) .eq. 1) then
992 pdbdy2dtemp1(i,j,1) = grid%pd(i,j)
993 write(message,*)' loop=',loop,' i=',i,' j=',j,' pdbdy2dtemp1(i,j)=',pdbdy2dtemp1(i,j,1)
994 CALL wrf_debug(10,message)
999 !-----------------------------------------------------------------------
1000 !*** EASTERN BOUNDARY
1001 !-----------------------------------------------------------------------
1006 DO k = kps , MIN(kde,kpe)
1008 !*** Make sure the J loop is on the global boundary
1011 DO j = jps+inc_h, min(jde,jpe),2
1012 if (J .ge. 3 .and. J .le. JDE-2 .and. mod(J,2) .eq. 1) then
1013 tbdy3dtemp1(i,j,k) = grid%t(i,j,k)
1014 qbdy3dtemp1(i,j,k) = grid%q(i,j,k)
1015 cwmbdy3dtemp1(i,j,k) = grid%cwm(i,j,k)
1016 q2bdy3dtemp1(i,j,k) = grid%q2(i,j,k)
1021 DO k = kps , MIN(kde,kpe)
1023 DO j = jps+inc_v, min(jde,jpe),2
1024 if (J .ge. 2 .and. J .le. JDE-1 .and. mod(J,2) .eq. 0) then
1025 ubdy3dtemp1(i,j,k) = grid%u(i,j,k)
1026 vbdy3dtemp1(i,j,k) = grid%v(i,j,k)
1032 DO j = jps+inc_h, min(jde,jpe),2
1033 if (J .ge. 3 .and. J .le. JDE-2 .and. mod(J,2) .eq. 1) then
1034 pdbdy2dtemp1(i,j,1) = grid%pd(i,j)
1040 ! There are 2 components to the lateral boundaries.
1041 ! First, there is the starting
1042 ! point of this time period - just the outer few rows and columns.
1045 CALL stuff_bdy_ijk (ubdy3dtemp1, grid%u_bxs, grid%u_bxe, &
1046 grid%u_bys, grid%u_bye, &
1047 'N', spec_bdy_width , &
1048 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1049 ims , ime , jms , jme , kms , kme , &
1050 ips , ipe , jps , jpe , kps , kpe+1 )
1052 CALL stuff_bdy_ijk (vbdy3dtemp1, grid%v_bxs, grid%v_bxe, &
1053 grid%v_bys, grid%v_bye, &
1054 'N', spec_bdy_width , &
1055 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1056 ims , ime , jms , jme , kms , kme , &
1057 ips , ipe , jps , jpe , kps , kpe+1 )
1059 CALL stuff_bdy_ijk (tbdy3dtemp1, grid%t_bxs, grid%t_bxe, &
1060 grid%t_bys, grid%t_bye, &
1061 'N', spec_bdy_width , &
1062 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1063 ims , ime , jms , jme , kms , kme , &
1064 ips , ipe , jps , jpe , kps , kpe+1 )
1066 CALL stuff_bdy_ijk (cwmbdy3dtemp1, grid%cwm_bxs, grid%cwm_bxe, &
1067 grid%cwm_bys, grid%cwm_bye, &
1068 'N', spec_bdy_width , &
1069 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1070 ims , ime , jms , jme , kms , kme , &
1071 ips , ipe , jps , jpe , kps , kpe+1 )
1073 CALL stuff_bdy_ijk (qbdy3dtemp1, grid%q_bxs, grid%q_bxe, &
1074 grid%q_bys, grid%q_bye, &
1075 'N', spec_bdy_width , &
1076 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1077 ims , ime , jms , jme , kms , kme , &
1078 ips , ipe , jps , jpe , kps , kpe+1 )
1080 CALL stuff_bdy_ijk (q2bdy3dtemp1, grid%q2_bxs, grid%q2_bxe, &
1081 grid%q2_bys, grid%q2_bye, &
1082 'N', spec_bdy_width , &
1083 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1084 ims , ime , jms , jme , kms , kme , &
1085 ips , ipe , jps , jpe , kps , kpe+1 )
1088 CALL stuff_bdy_ijk (pdbdy2dtemp1, grid%pd_bxs, grid%pd_bxe, &
1089 grid%pd_bys, grid%pd_bye, &
1090 'M', spec_bdy_width, &
1091 ids , ide+1 , jds , jde+1 , 1 , 1 , &
1092 ims , ime , jms , jme , 1 , 1 , &
1093 ips , ipe , jps , jpe , 1 , 1 )
1095 !-----------------------------------------------------------------------
1097 ELSE IF ( loop .GT. 1 ) THEN
1099 !-----------------------------------------------------------------------
1101 call wrf_debug(1,'LOOP>1, so start making non-init boundary conditions')
1104 bdytmp_useph: if(grid%use_prep_hybrid) then
1105 call wrf_debug(1,'ALLOCATE PREP_HYBRID BOUNDARY ARRAYS')
1106 !! When running in prep_hybrid mode, we must read in the data here.
1108 ! Allocate boundary arrays:
1109 KB = 2*IDE + JDE - 3
1113 ALLOCATE(TB(KB,LM,2))
1114 ALLOCATE(QB(KB,LM,2))
1115 ALLOCATE(CWMB(KB,LM,2))
1116 ALLOCATE(UB(KB,LM,2))
1117 ALLOCATE(VB(KB,LM,2))
1119 alloc_ph_arrays=.true.
1122 IUNIT_GFS = 900 + LOOP - 1
1123 READ(IUNIT_GFS,iostat=ioerror) PDB,TB,QB,CWMB,UB,VB
1125 write(message,*) 'Unable to read MAKBND output from unit ',IUNIT_GFS
1126 call wrf_error_fatal(message)
1129 ! Now copy the data into the temporary boundary arrays, and
1130 ! switch from IKJ to IJK while we do it.
1132 !! Southern boundary
1137 DO k = kps , MIN(kde,kpe)
1139 DO i = ips , MIN(ide,ipe)
1140 tbdy3dtemp2(i,j,k) = TB(N,k,1)
1141 qbdy3dtemp2(i,j,k) = QB(N,k,1)
1142 cwmbdy3dtemp2(i,j,k) = CWMB(N,k,1)
1143 q2bdy3dtemp2(i,j,k) = 0.0 !KWON
1144 write(message,*)'southtend t',k,i,n,tbdy3dtemp2(i,j,k)
1145 call wrf_debug(10,message)
1146 write(message,*)'southtend q',k,i,n,qbdy3dtemp2(i,j,k)
1147 call wrf_debug(10,message)
1149 write(0,*) 'S boundary values T,Q : ', I,tbdy3dtemp2(i,j,k), &
1156 DO k = kps , MIN(kde,kpe)
1158 DO i = ips , MIN(ide,ipe)
1159 ubdy3dtemp2(i,j,k) = UB(N,k,1)
1160 vbdy3dtemp2(i,j,k) = VB(N,k,1)
1166 DO i = ips , MIN(ide,ipe)
1167 pdbdy2dtemp2(i,j,1) = PDB(N,1)
1168 write(message,*)'southtend p',i,n,pdbdy2dtemp1(i,j,1)
1169 call wrf_debug(10,message)
1180 DO k = kps , MIN(kde,kpe)
1182 DO i = ips , MIN(ide,ipe)
1183 tbdy3dtemp2(i,j,k) = TB(N,k,1)
1184 qbdy3dtemp2(i,j,k) = QB(N,k,1)
1185 cwmbdy3dtemp2(i,j,k) = CWMB(N,k,1)
1186 q2bdy3dtemp2(i,j,k) = 0.0 !KWON
1187 write(message,*)'northtend t',k,i,n,tbdy3dtemp2(i,j,k)
1188 call wrf_debug(10,message)
1189 write(message,*)'northtend q',k,i,n,qbdy3dtemp2(i,j,k)
1190 call wrf_debug(10,message)
1195 DO k = kps , MIN(kde,kpe)
1197 DO i = ips , MIN(ide,ipe)
1198 ubdy3dtemp2(i,j,k) = UB(N,k,1)
1199 vbdy3dtemp2(i,j,k) = VB(N,k,1)
1205 DO i = ips , MIN(ide,ipe)
1206 pdbdy2dtemp2(i,j,1) = PDB(N,1)
1207 write(message,*)'northtend p',i,n,pdbdy2dtemp1(i,j,1)
1208 call wrf_debug(10,message)
1218 DO k = kps , MIN(kde,kpe)
1221 DO j = jps+inc_h, MIN(jde,jpe),2
1222 if (J .ge. 3 .and. J .le. jde-2 .and. mod(J,2) .eq. 1) then
1223 tbdy3dtemp2(i,j,k) = TB(N,k,1)
1224 qbdy3dtemp2(i,j,k) = QB(N,k,1)
1225 cwmbdy3dtemp2(i,j,k) = CWMB(N,k,1)
1226 q2bdy3dtemp2(i,j,k) = 0.0 !KWON
1227 write(message,*)'westtend t',k,j,n,tbdy3dtemp2(i,j,k)
1228 call wrf_debug(10,message)
1229 write(message,*)'westtend q',k,j,n,qbdy3dtemp2(i,j,k)
1230 call wrf_debug(10,message)
1236 DO k = kps , MIN(kde,kpe)
1239 DO j = jps+inc_v, MIN(jde,jpe),2
1240 if (J .ge. 2 .and. J .le. jde-1 .and. mod(J,2) .eq. 0) then
1241 ubdy3dtemp2(i,j,k) = UB(N,k,1)
1242 vbdy3dtemp2(i,j,k) = VB(N,k,1)
1250 DO j = jps+inc_h, MIN(jde,jpe),2
1251 if (J .ge. 3 .and. J .le. jde-2 .and. mod(J,2) .eq. 1) then
1252 pdbdy2dtemp2(i,j,1) = PDB(N,1)
1253 write(message,*)'westtend p',j,n,pdbdy2dtemp1(i,j,1)
1254 call wrf_debug(10,message)
1267 DO k = kps , MIN(kde,kpe)
1270 DO j = jps+inc_h, MIN(jde,jpe),2
1271 if (J .ge. 3 .and. J .le. jde-2 .and. mod(J,2) .eq. 1) then
1272 tbdy3dtemp2(i,j,k) = TB(N,k,1)
1273 qbdy3dtemp2(i,j,k) = QB(N,k,1)
1274 cwmbdy3dtemp2(i,j,k) = CWMB(N,k,1)
1275 q2bdy3dtemp2(i,j,k) = 0.0 !KWON
1276 write(message,*)'easttend t',k,j,n,tbdy3dtemp2(i,j,k)
1277 call wrf_debug(10,message)
1278 write(message,*)'easttend q',k,j,n,qbdy3dtemp2(i,j,k)
1279 call wrf_debug(10,message)
1285 DO k = kps , MIN(kde,kpe)
1288 DO j = jps+inc_v, MIN(jde,jpe),2
1289 if (J .ge. 2 .and. J .le. jde-1 .and. mod(J,2) .eq. 0) then
1290 ubdy3dtemp2(i,j,k) = UB(N,k,1)
1291 vbdy3dtemp2(i,j,k) = VB(N,k,1)
1299 DO j = jps+inc_h, MIN(jde,jpe),2
1300 if (J .ge. 3 .and. J .le. jde-2 .and. mod(J,2) .eq. 1) then
1301 pdbdy2dtemp2(i,j,1) = PDB(N,1)
1302 write(message,*)'easttend p',j,n,pdbdy2dtemp1(i,j,1)
1303 call wrf_debug(10,message)
1312 CALL output_auxinput4 ( id4, grid , config_flags , ierr )
1318 write(message,*)' assemble_output loop=',loop,' in IF block'
1319 call wrf_message(message)
1321 ! Open the boundary file.
1323 IF ( loop .eq. 2 ) THEN
1324 CALL construct_filename1( bdyname , 'wrfbdy' , grid%id , 2 )
1325 CALL open_w_dataset ( id, TRIM(bdyname) , grid , config_flags , &
1326 output_boundary , "DATASET=BOUNDARY", ierr )
1327 IF ( ierr .NE. 0 ) THEN
1328 CALL wrf_error_fatal( 'ideal_hwrf: error opening wrfbdy for writing' )
1330 ! grid%write_metadata = .true.
1333 ! grid%write_metadata = .true.
1334 ! grid%write_metadata = .false.
1335 CALL domain_clockadvance( grid )
1339 bdytmp_notph: if(.not.grid%use_prep_hybrid) then
1341 !-----------------------------------------------------------------------
1342 !*** SOUTHERN BOUNDARY
1343 !-----------------------------------------------------------------------
1347 DO k = kps , MIN(kde,kpe)
1348 DO i = ips , MIN(ide,ipe)
1349 ubdy3dtemp2(i,j,k) = grid%u(i,j,k)
1350 vbdy3dtemp2(i,j,k) = grid%v(i,j,k)
1351 tbdy3dtemp2(i,j,k) = grid%t(i,j,k)
1352 qbdy3dtemp2(i,j,k) = grid%q(i,j,k)
1353 cwmbdy3dtemp2(i,j,k) = grid%cwm(i,j,k)
1354 q2bdy3dtemp2(i,j,k) = grid%q2(i,j,k)
1358 DO i = ips , MIN(ide,ipe)
1359 pdbdy2dtemp2(i,j,1) = grid%pd(i,j)
1364 !-----------------------------------------------------------------------
1365 !*** NORTHERN BOUNDARY
1366 !-----------------------------------------------------------------------
1370 DO k = kps , MIN(kde,kpe)
1371 DO i = ips , MIN(ide,ipe)
1372 ubdy3dtemp2(i,j,k) = grid%u(i,j,k)
1373 vbdy3dtemp2(i,j,k) = grid%v(i,j,k)
1374 tbdy3dtemp2(i,j,k) = grid%t(i,j,k)
1375 qbdy3dtemp2(i,j,k) = grid%q(i,j,k)
1376 cwmbdy3dtemp2(i,j,k) = grid%cwm(i,j,k)
1377 q2bdy3dtemp2(i,j,k) = grid%q2(i,j,k)
1381 DO i = ips , MIN(ide,ipe)
1382 pdbdy2dtemp2(i,j,1) = grid%pd(i,j)
1386 !-----------------------------------------------------------------------
1387 !*** WESTERN BOUNDARY
1388 !-----------------------------------------------------------------------
1392 DO k = kps , MIN(kde,kpe)
1395 write(message,*)' assemble_ouput loop=',loop,' inc_h=',inc_h,' jps=',jps
1396 call wrf_debug(10,message)
1398 DO j = jps+inc_h, MIN(jde,jpe),2
1399 if (J .ge. 3 .and. J .le. jde-2 .and. mod(J,2) .eq. 1) then
1400 tbdy3dtemp2(i,j,k) = grid%t(i,j,k)
1402 write(message,*)' loop=',loop,' i=',i,' j=',j,' tbdy3dtemp1(i,j,k)=',tbdy3dtemp1(i,j,k)
1403 call wrf_debug(10,message)
1405 qbdy3dtemp2(i,j,k) = grid%q(i,j,k)
1406 cwmbdy3dtemp2(i,j,k) = grid%cwm(i,j,k)
1407 q2bdy3dtemp2(i,j,k) = grid%q2(i,j,k)
1412 DO k = kps , MIN(kde,kpe)
1414 DO j = jps+inc_v, MIN(jde,jpe),2
1415 if (J .ge. 2 .and. J .le. jde-1 .and. mod(J,2) .eq. 0) then
1416 ubdy3dtemp2(i,j,k) = grid%u(i,j,k)
1417 vbdy3dtemp2(i,j,k) = grid%v(i,j,k)
1423 DO j = jps+inc_h, MIN(jde,jpe),2
1424 if (J .ge. 3 .and. J .le. jde-2 .and. mod(J,2) .eq. 1) then
1425 pdbdy2dtemp2(i,j,1) = grid%pd(i,j)
1426 write(message,*)' loop=',loop,' i=',i,' j=',j,' pdbdy2dtemp1(i,j)=',pdbdy2dtemp1(i,j,1)
1427 CALL wrf_debug(10,message)
1432 !-----------------------------------------------------------------------
1433 !*** EASTERN BOUNDARY
1434 !-----------------------------------------------------------------------
1439 DO k = kps , MIN(kde,kpe)
1441 DO j = jps+inc_h, MIN(jde,jpe),2
1442 if (J .ge. 3 .and. J .le. jde-2 .and. mod(J,2) .eq. 1) then
1443 tbdy3dtemp2(i,j,k) = grid%t(i,j,k)
1444 qbdy3dtemp2(i,j,k) = grid%q(i,j,k)
1445 cwmbdy3dtemp2(i,j,k) = grid%cwm(i,j,k)
1446 q2bdy3dtemp2(i,j,k) = grid%q2(i,j,k)
1451 DO k = kps , MIN(kde,kpe)
1453 DO j = jps+inc_v, MIN(jde,jpe),2
1454 if (J .ge. 2 .and. J .le. jde-1 .and. mod(J,2) .eq. 0) then
1455 ubdy3dtemp2(i,j,k) = grid%u(i,j,k)
1456 vbdy3dtemp2(i,j,k) = grid%v(i,j,k)
1462 DO j = jps+inc_h, MIN(jde,jpe),2
1463 if (J .ge. 3 .and. J .le. jde-2 .and. mod(J,2) .eq. 1) then
1464 pdbdy2dtemp2(i,j,1) = grid%pd(i,j)
1471 !-----------------------------------------------------------------------
1472 ! During all of the loops after the first loop,
1473 ! we first compute the boundary
1474 ! tendencies with the current data values
1475 ! (*bdy3dtemp2 arrays) and the previously
1476 ! saved information stored in the *bdy3dtemp1 arrays.
1479 CALL stuff_bdytend_ijk ( ubdy3dtemp2 , ubdy3dtemp1 , REAL(interval_seconds),&
1480 grid%u_btxs, grid%u_btxe, &
1481 grid%u_btys, grid%u_btye, &
1482 'N', spec_bdy_width , &
1483 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1484 ims , ime , jms , jme , kms , kme , &
1485 ips , ipe , jps , jpe , kps , kpe+1 )
1487 CALL stuff_bdytend_ijk ( vbdy3dtemp2 , vbdy3dtemp1 , REAL(interval_seconds),&
1488 grid%v_btxs, grid%v_btxe, &
1489 grid%v_btys, grid%v_btye, &
1490 'N', spec_bdy_width , &
1491 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1492 ims , ime , jms , jme , kms , kme , &
1493 ips , ipe , jps , jpe , kps , kpe+1 )
1495 CALL stuff_bdytend_ijk ( tbdy3dtemp2 , tbdy3dtemp1 , REAL(interval_seconds),&
1496 grid%t_btxs, grid%t_btxe, &
1497 grid%t_btys, grid%t_btye, &
1498 'N', spec_bdy_width , &
1499 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1500 ims , ime , jms , jme , kms , kme , &
1501 ips , ipe , jps , jpe , kps , kpe+1 )
1503 CALL stuff_bdytend_ijk ( cwmbdy3dtemp2 , cwmbdy3dtemp1 , REAL(interval_seconds),&
1504 grid%cwm_btxs, grid%cwm_btxe, &
1505 grid%cwm_btys, grid%cwm_btye, &
1506 'N', spec_bdy_width , &
1507 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1508 ims , ime , jms , jme , kms , kme , &
1509 ips , ipe , jps , jpe , kps , kpe+1 )
1511 CALL stuff_bdytend_ijk ( qbdy3dtemp2 , qbdy3dtemp1 , REAL(interval_seconds),&
1512 grid%q_btxs, grid%q_btxe, &
1513 grid%q_btys, grid%q_btye, &
1514 'N', spec_bdy_width , &
1515 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1516 ims , ime , jms , jme , kms , kme , &
1517 ips , ipe , jps , jpe , kps , kpe+1 )
1519 CALL stuff_bdytend_ijk ( q2bdy3dtemp2 , q2bdy3dtemp1 , REAL(interval_seconds),&
1520 grid%q2_btxs, grid%q2_btxe, &
1521 grid%q2_btys, grid%q2_btye, &
1522 'N', spec_bdy_width , &
1523 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1524 ims , ime , jms , jme , kms , kme , &
1525 ips , ipe , jps , jpe , kps , kpe+1 )
1527 CALL stuff_bdytend_ijk( pdbdy2dtemp2 , pdbdy2dtemp1, REAL(interval_seconds),&
1528 grid%pd_btxs, grid%pd_btxe, &
1529 grid%pd_btys, grid%pd_btye, &
1530 'M', spec_bdy_width , &
1531 ids , ide+1 , jds , jde+1 , 1 , 1 , &
1532 ims , ime , jms , jme , 1 , 1 , &
1533 ips , ipe , jps , jpe , 1 , 1 )
1537 ! Both pieces of the boundary data are now
1538 ! available to be written (initial time and tendency).
1539 ! This looks ugly, these date shifting things.
1540 ! What's it for? We want the "Times" variable
1541 ! in the lateral BDY file to have the valid times
1542 ! of when the initial fields are written.
1543 ! That's what the loop-2 thingy is for with the start date.
1544 ! We increment the start_date so
1545 ! that the starting time in the attributes is the
1546 ! second time period. Why you may ask. I
1547 ! agree, why indeed.
1549 temp24= current_date
1551 start_date = current_date
1552 CALL geth_newdate ( temp19 , temp24b(1:19) , &
1553 (loop-2) * model_config_rec%interval_seconds )
1554 current_date = temp19 // '.0000'
1555 CALL domain_clock_set( grid, current_date(1:19) )
1556 write(message,*) 'LBC valid between these times ',current_date, ' ',start_date
1557 CALL wrf_message(message)
1559 CALL output_boundary ( id, grid , config_flags , ierr )
1560 current_date = temp24
1561 start_date = temp24b
1563 ! OK, for all of the loops, we output the initialzation
1564 ! data, which would allow us to
1565 ! start the model at any of the available analysis time periods.
1567 ! WRITE ( loop_char , FMT = '(I4.4)' ) loop
1568 ! CALL open_w_dataset ( id1, 'wrfinput'//loop_char , grid , config_flags , output_input , "DATASET=INPUT", ierr )
1569 ! IF ( ierr .NE. 0 ) THEN
1570 ! CALL wrf_error_fatal( 'ideal_hwrf: error opening wrfinput'//loop_char//' for writing' )
1572 ! grid%write_metadata = .true.
1574 ! CALL calc_current_date ( grid%id , 0. )
1575 ! CALL output_input ( id1, grid , config_flags , ierr )
1576 ! CALL close_dataset ( id1 , config_flags , "DATASET=INPUT" )
1578 ! Is this or is this not the last time time? We can remove some unnecessary
1579 ! stores if it is not.
1581 IF ( loop .LT. time_loop_max ) THEN
1583 ! We need to save the 3d data to compute a
1584 ! difference during the next loop. Couple the
1585 ! 3d fields with total mu (mub + mu_2) and the
1586 ! stagger-specific map scale factor.
1587 ! We load up the boundary data again for use in the next loop.
1590 !mp change these limits?????????
1595 ubdy3dtemp1(i,j,k) = ubdy3dtemp2(i,j,k)
1596 vbdy3dtemp1(i,j,k) = vbdy3dtemp2(i,j,k)
1597 tbdy3dtemp1(i,j,k) = tbdy3dtemp2(i,j,k)
1598 cwmbdy3dtemp1(i,j,k) = cwmbdy3dtemp2(i,j,k)
1599 qbdy3dtemp1(i,j,k) = qbdy3dtemp2(i,j,k)
1600 q2bdy3dtemp1(i,j,k) = q2bdy3dtemp2(i,j,k)
1605 !mp change these limits?????????
1609 pdbdy2dtemp1(i,j,1) = pdbdy2dtemp2(i,j,1)
1613 ! There are 2 components to the lateral boundaries.
1614 ! First, there is the starting
1615 ! point of this time period - just the outer few rows and columns.
1617 CALL stuff_bdy_ijk (ubdy3dtemp1, grid%u_bxs, grid%u_bxe, &
1618 grid%u_bys, grid%u_bye, &
1619 'N', spec_bdy_width , &
1620 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1621 ims , ime , jms , jme , kms , kme , &
1622 ips , ipe , jps , jpe , kps , kpe+1 )
1624 CALL stuff_bdy_ijk (vbdy3dtemp1, grid%v_bxs, grid%v_bxe, &
1625 grid%v_bys, grid%v_bye, &
1626 'N', spec_bdy_width , &
1627 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1628 ims , ime , jms , jme , kms , kme , &
1629 ips , ipe , jps , jpe , kps , kpe+1 )
1631 CALL stuff_bdy_ijk (tbdy3dtemp1, grid%t_bxs, grid%t_bxe, &
1632 grid%t_bys, grid%t_bye, &
1633 'N', spec_bdy_width , &
1634 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1635 ims , ime , jms , jme , kms , kme , &
1636 ips , ipe , jps , jpe , kps , kpe+1 )
1638 CALL stuff_bdy_ijk (cwmbdy3dtemp1, grid%cwm_bxs, grid%cwm_bxe, &
1639 grid%cwm_bys, grid%cwm_bye, &
1640 'N', spec_bdy_width , &
1641 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1642 ims , ime , jms , jme , kms , kme , &
1643 ips , ipe , jps , jpe , kps , kpe+1 )
1645 CALL stuff_bdy_ijk (qbdy3dtemp1, grid%q_bxs, grid%q_bxe, &
1646 grid%q_bys, grid%q_bye, &
1647 'N', spec_bdy_width , &
1648 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1649 ims , ime , jms , jme , kms , kme , &
1650 ips , ipe , jps , jpe , kps , kpe+1 )
1652 CALL stuff_bdy_ijk (q2bdy3dtemp1, grid%q2_bxs, grid%q2_bxe, &
1653 grid%q2_bys, grid%q2_bye, &
1654 'N', spec_bdy_width , &
1655 ids , ide+1 , jds , jde+1 , kds , kde+1 , &
1656 ims , ime , jms , jme , kms , kme , &
1657 ips , ipe , jps , jpe , kps , kpe+1 )
1659 CALL stuff_bdy_ijk (pdbdy2dtemp1,grid%pd_bxs, grid%pd_bxe, &
1660 grid%pd_bys, grid%pd_bye, &
1661 'M', spec_bdy_width , &
1662 ids , ide+1 , jds , jde+1 , 1 , 1 , &
1663 ims , ime , jms , jme , 1 , 1 , &
1664 ips , ipe , jps , jpe , 1 , 1 )
1666 ELSE IF ( loop .EQ. time_loop_max ) THEN
1668 ! If this is the last time through here, we need to close the files.
1670 CALL close_dataset ( id , config_flags , "DATASET=BOUNDARY" )
1674 END IF main_loop_test
1677 if(alloc_ph_arrays) then
1678 call wrf_debug(1,'DEALLOCATE PREP_HYBRID BOUNARY ARRAYS')
1679 deallocate(TB,QB,CWMB,UB,VB,PDB)
1683 END SUBROUTINE assemble_output