updated top-level README and version_decl for V4.5 (#1847)
[WRF.git] / chem / convert_emiss.F
blobfcc38344f0467458bbe250c0c8a7ae667876a9e6
1 ! This program that converts the following emissions data into 
2 !    into WRF input data data files. The potential fields are:
3 !       1) anthropogenic emissions data
4 !       2) biogenic emissions data
5 !       3) GOCART dust errosion factor
6 !       4) GOCART sea salt emissions factor
7 !       5) GOCART dimethyl sulfide emissions
8 !       6) Wild fire biomass burn location obtained from GOES-ABBA data 
10 !    The WRF namelist.input file is used to decide which data 
11 !    is to be converted when this program is executed.
14 PROGRAM convert_emissions
15 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
17    USE module_machine
18    USE module_wrf_error
19    USE module_integrate
20    USE module_domain
21 !   USE module_domain, ONLY : domain, alloc_and_configure_domain, &
22 !        domain_clock_set, domain_clock_get, head_grid, program_name, domain_clockprint
23 !  USE module_initialize_real, ONLY : wrfu_initialize, rebalance_driver, find_my_parent
24    USE module_driver_constants
25    USE module_configure, ONLY : grid_config_rec_type, model_config_rec, &
26         initial_config, get_config_as_buffer, set_config_as_buffer
27    USE module_io_domain
29 #ifdef DM_PARALLEL
30    USE module_dm
31 #endif
32 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
33 !new for bc
34    USE module_bc
35    USE module_get_file_names
36 #if (EM_CORE ==1)
37    USE module_big_step_utilities_em
38 #endif
39 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
40    IMPLICIT NONE
42    INTERFACE
43      SUBROUTINE init_domain_constants_em_ptr ( parent , nest )
44        USE module_domain
45        USE module_configure
46        TYPE(domain), POINTER  :: parent , nest
47      END SUBROUTINE init_domain_constants_em_ptr
49    END INTERFACE
52    INTERFACE
53      SUBROUTINE Setup_Timekeeping( grid )
54       USE module_domain
55       TYPE(domain), POINTER :: grid
56      END SUBROUTINE Setup_Timekeeping
57    END INTERFACE
59    INTEGER, PARAMETER  :: rnum8=4
60    REAL    :: time 
62    INTEGER :: loop , levels_to_process
63    INTEGER :: rc
65    TYPE(domain) , POINTER      :: keep_grid, grid_ptr, null_domain, grid, ingrid
66    TYPE (grid_config_rec_type) :: config_flags, config_flags_in
67    INTEGER                     :: number_at_same_level
69    INTEGER :: max_dom, domain_id
70    INTEGER :: id1, id , fid, ierr
71    INTEGER :: idum1, idum2 , ihour, icnt
72 #ifdef DM_PARALLEL
73    INTEGER                 :: nbytes
74    INTEGER, PARAMETER      :: configbuflen = 4* CONFIG_BUF_LEN
75    INTEGER                 :: configbuf( configbuflen )
76    LOGICAL , EXTERNAL      :: wrf_dm_on_monitor
77 #endif
79    REAL    :: dt_from_file, tstart_from_file, tend_from_file
80    INTEGER :: ids , ide , jds , jde , kds , kde
81    INTEGER :: ips , ipe , jps , jpe , kps , kpe
82    INTEGER :: ims , ime , jms , jme , kms , kme
83    INTEGER :: i , j , k , idts, ntsd, emi_frame, nemi_frames
84    integer     ::  kw, kg
85    real        ::  top, bot,fac
86    INTEGER :: debug_level = 0
87    INTEGER, PARAMETER  :: iklev=55
88    real,dimension(iklev) :: p_g,p_wrf
89    REAL        :: p00, t00, a, p_surf, pd_surf,p_top
90    integer :: kbot,ktop,k_initial,k_final,kk4,ko,kl
91    REAL, ALLOCATABLE, DIMENSION(:) :: gocart_lev
92    REAL, ALLOCATABLE, DIMENSION(:,:) :: tmp2
93    REAL, ALLOCATABLE, DIMENSION(:,:,:) :: tmp_oh,tmp_no3,tmp_h2o2,tmp3,interpolate
94    REAL, ALLOCATABLE :: dumc0(:,:,:),dumc4(:,:,:),zlevel(:,:,:)
95    REAL, ALLOCATABLE :: dumc1(:,:)
96    real mmax
97 ! Volcanic stuff
98 !     
99    real, allocatable, dimension (:,:) :: ash_mass,ash_height,erup_dt
100    real, allocatable, dimension (:,:) :: so2_mass, volc_vent
101    real, allocatable, dimension (:) :: vert_mass_dist
102    real, dimension(10) :: size_dist
103    real :: x1,percen_mass_umbrel,base_umbrel,ashz_above_vent
106 #if (NMM_CORE == 1)
107    REAL, ALLOCATABLE :: plvl(:,:,:)
108    REAL, ALLOCATABLE :: pdsl(:,:)
109 #endif
111    CHARACTER (LEN=80)     :: message
113    CHARACTER(LEN=24) :: previous_date , this_date , next_date
114    CHARACTER(LEN=19) :: start_date_char , end_date_char , current_date_char , next_date_char
115    CHARACTER(LEN= 4) :: loop_char
117    INTEGER :: start_year , start_month , start_day , start_hour , start_minute , start_second
118    INTEGER ::   end_year ,   end_month ,   end_day ,   end_hour ,   end_minute ,   end_second
119    INTEGER :: interval_seconds , real_data_init_type
120    INTEGER :: int_sec
121    INTEGER :: time_loop_max , time_loop
123    REAL :: cen_lat, cen_lon, moad_cen_lat, truelat1, truelat2, gmt, stand_lon, dum1
124    INTEGER :: map_proj, julyr, julday, iswater, isice, isurban, isoilwater
125 ! Add a logical leap-year variable as we want to calculate Julian day from the volc_d01 file
126    LOGICAL :: LEAP
127 ! Add beg_yr, beg_mon, and beg_jul to calculate the eruption Julian day and hour from the 
128 !  volc_d01 data file as it can be different than the run start day and hour.
129    INTEGER :: iswaterr,itest,beg_yr,beg_mon,beg_jul,beg_day,beg_hour
130    INTEGER :: itime = 0
131    INTEGER :: inew_nei = 0
132    INTEGER :: inew_ch4 = 1      ! set to 0 if the emission inventory doesn't include CH4 
133    INTEGER :: nv = 0
134    INTEGER :: nv_f = 0
135    INTEGER :: nv_g = 0
136    INTEGER :: itime_f = 0
138    REAL :: dx,dy,area,eh
140    CHARACTER(LEN= 8) :: chlanduse
143    CHARACTER (LEN=80) :: inpname , eminame, dum_str, wrfinname
144    CHARACTER (LEN=80)       :: bdyname, bdyname2
145    CHARACTER (LEN=20)       :: dname
146    CHARACTER (LEN=12)       :: dname2
147    CHARACTER (LEN=256)      :: timestr
149 ! MBO is separated, SESQ is added
150 ! Number of reference emission and LAI files to open
151    INTEGER, PARAMETER :: numfil=21
152    INTEGER            :: status,system
153 ! Filenames of reference emissions and LAI
154    CHARACTER*100 onefil
155    CHARACTER*12 emfil(numfil)
156    DATA emfil/'ISO','OLI','API','LIM','XYL','HC3','ETE','OLT',  &
157               'KET','ALD','HCHO','ETH','ORA2','CO','NR','SESQ','MBO',       &
158               'NOAG_GROW','NOAG_NONGROW','NONONAG','ISOP'/
160 ! these are needed on some compilers, eg compaq/alpha, to
161 ! permit pass by reference through the registry generated
162 ! interface to med_read_emissions, below
163 #ifdef DEREF_KLUDGE
164    INTEGER     :: sm31 , em31 , sm32 , em32 , sm33 , em33
165 #endif
167 #include "version_decl"
168 #include "commit_decl"
170 #define DM_BCAST_MACRO(A) CALL wrf_dm_bcast_bytes ( A , size ( A ) * rnum8 )
172    !  Get the NAMELIST data for input.
174    !  Define the name of this program (program_name defined in module_domain)
176    program_name = "WRF-CHEM " // TRIM(release_version) // " EMISSIONS PREPROCESSOR"
178 #ifdef DM_PARALLEL
179    CALL disable_quilting
180 #endif
182 !  CALL init_modules
183    CALL       wrf_debug ( 100 , 'convert_emiss: calling init_modules ' )
184    CALL init_modules(1)   ! Phase 1 returns after MPI_INIT() (if it is called)
185 #ifdef NO_LEAP_CALENDAR
186    CALL WRFU_Initialize( defaultCalKind=WRFU_CAL_NOLEAP, rc=rc )
187 #else
188    CALL WRFU_Initialize( defaultCalKind=WRFU_CAL_GREGORIAN, rc=rc )
189 #endif
190    CALL init_modules(2)   ! Phase 2 resumes after MPI_INIT() (if it is called)
193 #ifdef DM_PARALLEL
194    IF ( wrf_dm_on_monitor() ) THEN
195      CALL initial_config
196    ENDIF
197    CALL get_config_as_buffer( configbuf, configbuflen, nbytes )
198    CALL wrf_dm_bcast_bytes( configbuf, nbytes )
199    CALL set_config_as_buffer( configbuf, configbuflen )
200    CALL wrf_dm_initialize
201 #else
202    CALL initial_config
203 #endif
205    !  And here is an instance of using the information in the NAMELIST.  
207    CALL nl_get_debug_level ( 1, debug_level )
208    CALL set_wrf_debug_level ( debug_level )
209    
210    !  Allocated and configure the mother domain.  Since we are in the nesting down
211    !  mode, we know a) we got a nest, and b) we only got 1 nest.
213    NULLIFY( null_domain )
214    
215    CALL  wrf_message ( program_name )
216    CALL  wrf_message ( commit_version )
217    write(message,FMT='(A)') ' allocate for wrfinput_d01 '
218    CALL alloc_and_configure_domain ( domain_id  = 1           , &
219                                      grid       = head_grid   , &
220                                      parent     = null_domain , &
221                                      kid        = -1            )
222    grid => head_grid
224    !  Set up time initializations.
226    CALL Setup_Timekeeping ( grid )
228    CALL domain_clock_set( head_grid, &
229                           time_step_seconds=model_config_rec%interval_seconds )
230    CALL       wrf_debug ( 100 , 'convert_gocart: calling model_to_grid_config_rec ' )
231    CALL model_to_grid_config_rec ( grid%id , model_config_rec , config_flags )
232    CALL       wrf_debug ( 100 , 'convert_gocart: calling set_scalar_indices_from_config ' )
233    CALL set_scalar_indices_from_config ( grid%id , idum1, idum2 )
235    !  Initialize the I/O for WRF.
237    CALL       wrf_debug ( 100 , 'convert_gocart: calling init_wrfio' )
238    CALL init_wrfio
240 #ifdef DM_PARALLEL
241    CALL get_config_as_buffer( configbuf, configbuflen, nbytes )
242    CALL wrf_dm_bcast_bytes( configbuf, nbytes )
243    CALL set_config_as_buffer( configbuf, configbuflen )
244 #endif
246 !     !  Get the grid info from the wrfinput file
248    CALL  wrf_debug ( 100, message )
249    write(message,FMT='(A)') ' set scalars for wrfinput_d01 '
250    CALL  wrf_debug ( 100, message )
251    CALL set_scalar_indices_from_config ( grid%id , idum1, idum2 )
253    write(message,FMT='(A)') ' construct filename for wrfinput_d01 '
254    CALL  wrf_debug ( 100, message )
255    CALL construct_filename1( wrfinname , 'wrfinput' , grid%id , 2 )
257    write(message,FMT='(A,A)') ' open file ',TRIM(wrfinname)
258    CALL  wrf_message ( message )
259    CALL open_r_dataset ( fid, TRIM(wrfinname) , head_grid , config_flags , "DATASET=INPUT", ierr )
261 ! read wrfinput
263    CALL med_initialdata_input( head_grid , config_flags )
265    write(message,FMT='(A)') ' wrfinput open error check '
266    CALL  wrf_debug ( 100, message )
267    IF ( ierr .NE. 0 ) THEN
268       WRITE( wrf_err_message , FMT='(A,A,A,I8)' )  &
269           'program convert_emiss: error opening ',TRIM(wrfinname),' for reading ierr=',ierr
270       CALL WRF_ERROR_FATAL ( wrf_err_message )
271    ENDIF
272    write(message,FMT='(A)') ' past opening wrfinput_d01 '
273    CALL  wrf_debug ( 00, message )
276       CALL close_dataset      ( fid , config_flags , "DATASET=INPUT" )
279    !  An available simple timer from the timing module.
281    CALL set_scalar_indices_from_config ( grid%id , idum1, idum2 )
283    CALL Setup_Timekeeping ( grid )
284    CALL domain_clock_set( grid, &
285                           time_step_seconds=model_config_rec%interval_seconds )
286    CALL domain_clock_get( grid, current_timestr=timestr )
287    write(message,FMT='(A,A)') ' current_time ',Trim(timestr)
288    CALL  wrf_debug ( 100, message )
290    CALL model_to_grid_config_rec ( grid%id , model_config_rec , config_flags )
292    !  Figure out the starting and ending dates in a character format.
294    start_year   = model_config_rec%start_year  (grid%id)
295    start_month  = model_config_rec%start_month (grid%id)
296    start_day    = model_config_rec%start_day   (grid%id)
297    start_hour   = model_config_rec%start_hour  (grid%id)
298    start_minute = model_config_rec%start_minute(grid%id)
299    start_second = model_config_rec%start_second(grid%id)
301    end_year   = model_config_rec%  end_year  (grid%id)
302    end_month  = model_config_rec%  end_month (grid%id)
303    end_day    = model_config_rec%  end_day   (grid%id)
304    end_hour   = model_config_rec%  end_hour  (grid%id)
305    end_minute = model_config_rec%  end_minute(grid%id)
306    end_second = model_config_rec%  end_second(grid%id)
308    int_sec = 0
309    int_sec    = config_flags%auxinput5_interval
310    if ( int_sec == 0 ) then
311      int_sec    = config_flags%auxinput5_interval_s
312    endif
313    if ( int_sec == 0 ) then
314      int_sec    = 60 * config_flags%auxinput5_interval_m
315    endif
316    if ( int_sec == 0 ) then
317      int_sec    = 3600 * config_flags%auxinput5_interval_h
318    endif
319    if ( int_sec == 0 ) then
320      int_sec    = 86400 * config_flags%auxinput5_interval_d
321    endif
322    CALL domain_clock_set( grid, &
323                           time_step_seconds=int_Sec )
324   
326    real_data_init_type = model_config_rec%real_data_init_type
328    WRITE ( start_date_char , FMT = '(I4.4,"-",I2.2,"-",I2.2,"_",I2.2,":",I2.2,":",I2.2)' ) &
329            start_year,start_month,start_day,start_hour,start_minute,start_second
330    WRITE (   end_date_char , FMT = '(I4.4,"-",I2.2,"-",I2.2,"_",I2.2,":",I2.2,":",I2.2)' ) &
331              end_year,  end_month,  end_day,  end_hour,  end_minute,  end_second
332    print *,'START DATE ',start_date_char, int_sec, model_config_rec%interval_seconds
333    print *,'END DATE ',end_date_char
335 ! these are needed on some compilers, eg compaq/alpha, to
336 ! permit pass by reference through the registry generated
337 ! interface to med_read_emissions, below
338 #ifdef DEREF_KLUDGE
339    sm31             = grid%sm31
340    em31             = grid%em31
341    sm32             = grid%sm32
342    em32             = grid%em32
343    sm33             = grid%sm33
344    em33             = grid%em33
345 #endif
346        CALL get_ijk_from_grid (  grid ,                        &
347                                  ids, ide, jds, jde, kds, kde,    &
348                                  ims, ime, jms, jme, kms, kme,    &
349                                  ips, ipe, jps, jpe, kps, kpe    )
350 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
352 ! Allocate scratch arrays
354      ALLOCATE (dumc0(ids:ide,kds:grid%kemit,jds:jde))
355 !    ALLOCATE (dumc4(ids:ide-1,kds:grid%kemit,jds:jde-1))
356      ALLOCATE (dumc1(ids:ide,jds:jde))
358      ALLOCATE( tmp_oh(ids:ide,jds:jde,iklev) )
359      ALLOCATE( tmp_h2o2(ids:ide,jds:jde,iklev) )
360      ALLOCATE( tmp_no3(ids:ide,jds:jde,iklev) )
361      ALLOCATE( tmp2(ids:ide,jds:jde) )
362      ALLOCATE( tmp3(ids:ide,jds:jde,3) )
363      ALLOCATE( interpolate(ids:ide,kds:kde,jds:jde) )
364      ALLOCATE( gocart_lev(iklev))
365      if(config_flags%emiss_opt_vol == 1 .or. config_flags%emiss_opt_vol == 2) then
366         ALLOCATE( ash_mass(ids:ide,jds:jde) )
367         ALLOCATE( so2_mass(ids:ide,jds:jde) )
368         ALLOCATE( volc_vent(ids:ide,jds:jde) )
369         ALLOCATE( ash_height(ids:ide,jds:jde) )
370         ALLOCATE( erup_dt(ids:ide,jds:jde) )
371         ALLOCATE( vert_mass_dist(kds:kde) )
372         ALLOCATE( zlevel(ids:ide,kds:kde,jds:jde) )
373      endif
376    ihour = start_hour
378 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
380 !   read reference fields that some of the GOCART modules require (can be run with other modules too?)
382    if(config_flags%chem_opt == GOCART_SIMPLE               &
383       .or.    config_flags%chem_opt == GOCARTRACM_KPP      &
384       .or.    config_flags%chem_opt == CHEM_VOLC           &
385       .or.    config_flags%dmsemis_opt == DMSGOCART        &
386       .or.    config_flags%dust_opt  ==   DUSTGOCART       &
387                                                            ) then
388    write(message,FMT='(A)') ' READ GOCART BACKGROUND DATA '
389    CALL  wrf_debug ( 00, message )
391 #ifdef DM_PARALLEL
392    IF (wrf_dm_on_monitor()) THEN
393      OPEN(19,FILE='wrf_gocart_backg',FORM='UNFORMATTED')
394    endif
395 #else
396      OPEN(19,FILE='wrf_gocart_backg',FORM='UNFORMATTED')
397 #endif     
399 #ifdef DM_PARALLEL
400        IF (wrf_dm_on_monitor()) THEN
401            read(19)tmp2(ids:ide  ,jds:jde  )
402        ENDIF
403        DM_BCAST_MACRO(tmp2)
404 #else
405        print *,ids,ide,jds,jde
406        read(19)tmp2(ids:ide  ,jds:jde  )
407 #endif
408       grid%dms_0(ips:ipe,jps:jpe) = tmp2(ips:ipe,jps:jpe)
410 #ifdef DM_PARALLEL
411        IF (wrf_dm_on_monitor()) THEN
412            read(19)tmp3(ids:ide  ,jds:jde  ,1:3)
413        ENDIF
414        DM_BCAST_MACRO(tmp3)
415 #else
416        read(19)tmp3(ids:ide  ,jds:jde  ,1:3)
417 #endif
418 !     do i=1,3 
419 !      grid%erod(ips:ipe,jps:jpe,i)=tmp3(ips:ipe,jps:jpe,i)
420 !     enddo
422 #ifdef DM_PARALLEL
423        IF (wrf_dm_on_monitor()) THEN
424            read(19)gocart_lev(1:iklev)
425        ENDIF
426        DM_BCAST_MACRO(gocart_lev)
427 #else
428        read(19)gocart_lev(1:iklev)
429 #endif
431        write(*,*) 'GOCART_LEV: ',gocart_lev(:)
433 #ifdef DM_PARALLEL
434        IF (wrf_dm_on_monitor()) THEN
435            read(19)tmp_h2o2(ids:ide,jds:jde,1:iklev)
436        ENDIF
437        DM_BCAST_MACRO(tmp_h2o2)
438 #else
439        read(19)tmp_h2o2(ids:ide,jds:jde,1:iklev)
440 #endif
442 #ifdef DM_PARALLEL
443        IF (wrf_dm_on_monitor()) THEN
444            read(19)tmp_oh(ids:ide,jds:jde,1:iklev)
445        ENDIF
446        DM_BCAST_MACRO(tmp_oh)
447 #else
448        read(19)tmp_oh(ids:ide,jds:jde,1:iklev)
449 #endif
451 #ifdef DM_PARALLEL
452        IF (wrf_dm_on_monitor()) THEN
453            read(19)tmp_no3(ids:ide,jds:jde,1:iklev)
454        ENDIF
455        DM_BCAST_MACRO(tmp_no3)
456 #else
457        read(19)tmp_no3(ids:ide,jds:jde,1:iklev)
458 #endif
460      CLOSE(19)
462 !  CALL input_ext_chem_gocart_bg ( grid ) 
463    write(message,FMT='(A)') ' PAST  GOCART BACKGROUND DATA'
464    CALL  wrf_debug ( 00, message )
466    grid%input_from_file = .false.
468    write(message,FMT='(A)') ' OPEN  GOCART BACKGROUND DATA WRF file'
469    CALL  wrf_debug ( 00, message )
471    CALL construct_filename1( inpname , 'wrfchemi_gocart_bg' , grid%id , 2 )
472    CALL open_w_dataset ( id1, TRIM(inpname) , grid , config_flags , output_auxinput8 , "DATASET=AUXINPUT8", ierr )
473    write(message,FMT='(A,A)') '  GOCART BACKGROUND DATA file name: ',TRIM(inpname)
474    CALL  wrf_message ( message )
475    
476    IF ( ierr .NE. 0 ) THEN
477      CALL wrf_error_fatal( 'convert_emiss: error opening wrfchem emissions file for writing' )
478    ENDIF
480    write(message,FMT='(A)') ' PAST OPEN  GOCART BACKGROUND DATA WRF file '
481    CALL  wrf_debug ( 100, message )
483    CALL calc_current_date ( grid%id , 0. )
484    CALL geth_newdate ( current_date_char, current_date, 3600 )
485    current_date = current_date_char // '.0000'
487 !     if( stand_lon  == 0. ) then
488 !        stand_lon = cen_lon
489 !     endif
491 !     if( moad_cen_lat  == 0. ) then
492 !        moad_cen_lat = cen_lat
493 !     endif
496     idum1 = 1
497     IF( (config_flags%chem_opt == GOCART_SIMPLE) .OR. &
498         (config_flags%chem_opt == CHEM_VOLC)     .OR. &
499         (config_flags%chem_opt == GOCARTRACM_KPP) ) then
500 ! interpolate 3d fields to WRF in vertical
502      do k=1,iklev
503         p_g(k) = log10( gocart_lev(k) * 1023.) 
504      enddo
505       CALL nl_get_base_pres  ( 1 , p00 )
506       CALL nl_get_base_temp  ( 1 , t00 )
507       CALL nl_get_base_lapse ( 1 , a   )
508       call nl_get_p_top_requested (1,p_top)
509      t00=290.
510      a=50.
511 !    p00=100000.
512 !    p_top=5000.
514 #if (EM_CORE == 1) 
515      do j=jps,jpe
516      do i=ips,ipe
517         p_surf = p00 * EXP ( -t00/a + ( (t00/a)**2 - 2.*g*grid%ht(i,j)/a/r_d ) **0.5 )
518         do k=kps,kpe
519            grid%pb(i,k,j) = grid%znu(k)*(p_surf - p_top) + p_top
520         enddo
521         do kw=kpe-1,kps,-1
522          do kg=iklev-1,1,-1
523             if( p_g(kg) <= log10(.01*grid%pb(i,kw,j)) ) then
524                kbot = max(1,kg-1)
525                ktop = max(min(kg,iklev-1),2)
526             endif
527          enddo ! kg loop
529          fac= (tmp_no3(i  ,j  ,ktop)-tmp_no3(i  ,j  ,kbot))/ (p_g(ktop) - p_g(kbot))
530          grid%backg_no3(i, kw, j) = tmp_no3(i  ,j  ,kbot)+fac*(log10(.01*grid%pb(i,kw,j))-p_g(kbot))
532 ! OH
533          fac= (tmp_oh(i  ,j  ,ktop)-tmp_oh(i  ,j  ,kbot))/ (p_g(ktop) - p_g(kbot))
534          grid%backg_oh(i, kw, j) = tmp_oh(i  ,j  ,kbot)+fac*(log10(.01*grid%pb(i,kw,j))-p_g(kbot))
536 ! H2O2
537          fac= (tmp_h2o2(i  ,j  ,ktop)-tmp_h2o2(i  ,j  ,kbot) )/(p_g(ktop) - p_g(kbot))
538          grid%backg_h2o2(i, kw, j) = tmp_h2o2(i  ,j  ,kbot)+fac*(log10(.01*grid%pb(i,kw,j))-p_g(kbot))
540         enddo  ! kw loop
542      enddo
543      enddo
544 #endif
545 #if ( NMM_CORE == 1 )
547    ! Get scalar grid point heights
548    ALLOCATE(  plvl(ips:ipe,kps:kpe,jps:jpe) )
549    ALLOCATE(  pdsl(ips:ipe,jps:jpe) )
551        IF(grid%sigma.EQ. 1)THEN
552          do j=jps,jpe
553          do i=ips,ipe
554            pdsl(i,j)=grid%pd(i,j)
555          ENDDO
556          ENDDO
557        ELSE
558          do j=jps,jpe
559          do i=ips,ipe
560            pdsl(i,j)=grid%res(i,j)*grid%pd(i,j)
561          enddo
562          enddO
563        ENDIF
565       do j=jps,jpe
566         do k=kps,kpe
567         do i=ips,ipe
568           plvl(i,k,j)=grid%eta1(k)*grid%pdtop+grid%eta2(k)*pdsl(i,j)+grid%pt
569         ENDDO
570         ENDDO
571       ENDDO
573      do j=jps,jpe
574      do i=ips,ipe
576       do kw=kpe-1,kps,-1
577        do kg=iklev-1,1,-1
578           if( p_g(kg) <= log10(.01*plvl(i,kw,j)) ) then
579              kbot = max(1,kg-1)
580              ktop = max(min(kg,iklev-1),2)
581           endif
582        enddo ! kg loop
584        fac= (tmp_no3(i  ,j  ,ktop)-tmp_no3(i  ,j  ,kbot))/ (p_g(ktop) - p_g(kbot))
585        grid%backg_no3(i, kw, j) = tmp_no3(i  ,j  ,kbot)+fac*(log10(.01*plvl(i,kw,j))-p_g(kbot))
587 ! OH
588        fac= (tmp_oh(i  ,j  ,ktop)-tmp_oh(i  ,j  ,kbot))/ (p_g(ktop) - p_g(kbot))
589        grid%backg_oh(i, kw, j) = tmp_oh(i  ,j  ,kbot)+fac*(log10(.01*plvl(i,kw,j))-p_g(kbot))
591 ! H2O2
592        fac= (tmp_h2o2(i  ,j  ,ktop)-tmp_h2o2(i  ,j  ,kbot) )/(p_g(ktop) - p_g(kbot))
593        grid%backg_h2o2(i, kw, j) = tmp_h2o2(i  ,j  ,kbot)+fac*(log10(.01*plvl(i,kw,j))-p_g(kbot))
595       enddo  ! kw loop
597      enddo
598      enddo
600 #endif
602    ENDIF ! chem_opt gocart_simple or gocartracm
604    CALL output_auxinput8 ( id1 , grid , config_flags , ierr )
606    CALL close_dataset ( id1 , config_flags , "DATASET=AUXOUTPUT8" )
608    ENDIF ! chem_opt gocart_simple,dmsgocart,dustgocart
610    DEALLOCATE( tmp_oh )
611    DEALLOCATE( tmp_h2o2 )
612    DEALLOCATE( tmp_no3 )
613    DEALLOCATE( tmp2)
614    DEALLOCATE( tmp3)
615    DEALLOCATE( interpolate )
617 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
618 ! Volcanic emissions
620       if(config_flags%emiss_opt_vol == 1 .or. config_flags%emiss_opt_vol == 2) then
621      write(message, FMT='(A,4I6)') ' I am reading global volcanic emissions, dims: =',ids, ide-1, jds, jde-1
622      call wrf_message( TRIM( message ) )
623      CALL construct_filename1 ( bdyname , 'volc' , grid%id , 2 )
624 #ifdef DM_PARALLEL
625      IF (wrf_dm_on_monitor()) THEN
626         open (92,file=bdyname,form='unformatted')
627      ENDIf
628 #else
629      OPEN(92,FILE=bdyname,FORM='UNFORMATTED')
630 #endif
631      write(message, FMT='(A,A)') ' OPENED FILE: ',TRIM(bdyname)
632      call wrf_message( TRIM( message ) )
633 #ifdef DM_PARALLEL
634      IF (wrf_dm_on_monitor()) THEN
635        read(92)nv_g
636        read(92)dname
637        read(92)dname2
638        CALL wrf_dm_bcast_bytes ( nv_g , rnum8 )
639        CALL wrf_dm_bcast_bytes ( dname , rnum8 )
640        CALL wrf_dm_bcast_bytes ( dname2 , rnum8 )
641      ENDIF
642 #else
643        read(92)nv_g
644        read(92)dname
645        read(92)dname2
646 #endif
647       CALL geth_julgmt ( config_flags%julyr , config_flags%julday , config_flags%gmt )
648 !      dname = YYYYMMDDHHMMSS
649 !              12345678901234
650 ! read in the eruption beg_yr and beg_mon from the volc_d01 data file
651        read(unit=dname2(1:4), FMT='(I4)')beg_yr
652        read(unit=dname2(5:6), FMT='(I2)')beg_mon
653        read(unit=dname2(7:8), FMT='(I2)')beg_day
654        read(unit=dname2(9:10), FMT='(I2)')beg_hour
656 ! convert the date from the volc_d01 data file to Julian day
657         LEAP = .FALSE.
658         IF((MOD(beg_yr,4) .EQ. 0 .AND. MOD(beg_yr,100).NE.0 ).OR. MOD(beg_yr,400).EQ.0 ) THEN
659             LEAP = .TRUE.        
660         ENDIF
661         IF (LEAP) THEN
662           K = 1
663         ELSE
664           K = 2
665         END IF
666         beg_jul = ((275*beg_mon)/9) - K*((beg_mon+9)/12) + beg_day - 30
668        write(0,*)' DNAME2 = ',dname2,beg_jul,beg_hour
669 #ifdef DM_PARALLEL
670         IF (wrf_dm_on_monitor()) THEN
671             read(92)size_dist
672         ENDIF
673         DM_BCAST_MACRO(size_dist)
674 !       write(0,*)size_dist
675 #else
676         read(92)size_dist
677 #endif
678 !       write(0,*)'size_dist = ',size_dist,ids,ide,jds,jde
679      if(config_flags%emiss_opt_vol == 2 ) then
680 #ifdef DM_PARALLEL
681        IF (wrf_dm_on_monitor()) THEN
682 !          write(0,*)'now do so2 '
683            read(92)so2_mass(ids:ide  ,jds:jde  )
684        ENDIF
685        DM_BCAST_MACRO(so2_mass)
686 !          write(0,*)maxval(so2_mass)
687 #else
688 !          write(0,*)'now do so2-s '
689        read(92)so2_mass(ids:ide  ,jds:jde  )
690 #endif
691      endif ! config_flags%emiss_opt_vol == 2 
692 #ifdef DM_PARALLEL
693        IF (wrf_dm_on_monitor()) THEN
694            write(0,*)'now do ash mass '
695            read(92)ash_mass(ids:ide  ,jds:jde  )
696        ENDIF
697        DM_BCAST_MACRO(ash_mass)
698 #else
699        read(92)ash_mass(ids:ide  ,jds:jde  )
700 #endif
701 #ifdef DM_PARALLEL
702        IF (wrf_dm_on_monitor()) THEN
703            write(0,*)'now do ash heigt '
704            read(92)ash_height(ids:ide  ,jds:jde  )
705        ENDIF
706        DM_BCAST_MACRO(ash_height)
707 #else
708        read(92)ash_height(ids:ide  ,jds:jde  )
709 #endif
710 #ifdef DM_PARALLEL
711        IF (wrf_dm_on_monitor()) THEN
712 !          write(0,*)'now do volc vent '
713            read(92)volc_vent(ids:ide  ,jds:jde  )
714        ENDIF
715        DM_BCAST_MACRO(volc_vent)
716 !          write(0,*)maxval(volc_vent)
717 #else
718        read(92)volc_vent(ids:ide  ,jds:jde  )
719 #endif
721 #ifdef DM_PARALLEL
722        IF (wrf_dm_on_monitor()) THEN
723            write(0,*)'now do erup dt '
724            read(92)erup_dt(ids:ide  ,jds:jde  )
725        ENDIF
726        DM_BCAST_MACRO(erup_dt)
727 #else  
728        read(92)erup_dt(ids:ide  ,jds:jde  )
729 #endif 
730        do j=jps,jpe
731        do k=kps,kpe
732        do i=ips,ipe
733          zlevel(i,k,j) = (grid%phb(i,k,j)+grid%ph_2(i,k,j))/9.81
734        enddo
735        enddo
736        enddo
737        percen_mass_umbrel=.75
738        base_umbrel=.25    ! fraction
739        do j=jps,jpe
740        do i=ips,ipe
742          if(ash_height(i,j).le.0.)CYCLE
744           area = config_flags%dx * config_flags%dy 
745 !         so2_mass=1.5e4*3600.*1.e9/64./area
746           eh=2600.*(ash_height(i,j)*.0005)**4.1494
747           ash_mass(i,j)=eh*1.e9/area
749 !        if(erup_dt(i,j).le.0.)CYCLE
750          ashz_above_vent=ash_height(i,j)+volc_vent(i,j) !zlevel(i,kps,j)
751 !        ashz_above_vent=ash_height(i,j)+zlevel(i,kps,j) 
753 !        write(0,*)'found active volcano at i,j,kps,kpe = ',i,j,kps,kpe
754 !        write(0,*)ash_height(i,j),ash_mass(i,j),erup_dt(i,j),ashz_above_vent
755          do k=kpe-1,kps,-1
756 !           write(0,*)k,zlevel(i,k,j)
757             if(zlevel(i,k,j) < ashz_above_vent)then
758               k_final=k+1
759               exit
760             endif
761          enddo
762 !        write(0,*)'k_final = ',k_final
763          do k=kpe-1,kps,-1
764 !           write(0,*)k,zlevel(i,k,j)
765            if(zlevel(i,k,j) < (1.-base_umbrel)*ashz_above_vent)then
766               k_initial=k
767               exit
768             endif
769          enddo
770 !        write(0,*)'k_init = ',k_initial
771          vert_mass_dist=0.
772             
773            !- parabolic vertical distribution between k_initial and k_final
774            kk4 = k_final-k_initial+2
775            do ko=1,kk4-1
776                kl=ko+k_initial-1
777                vert_mass_dist(kl) = 6.*percen_mass_umbrel* float(ko)/float(kk4)**2 * (1. - float(ko)/float(kk4))
778            enddo
779 !          write(0,*)' mass=',sum(vert_mass_dist)*100.
780            if(sum(vert_mass_dist(kps:kpe)) .ne. percen_mass_umbrel) then
781                x1= ( percen_mass_umbrel- sum(vert_mass_dist(kps:kpe)) )/float(k_final-k_initial+1)
782                do ko=k_initial,k_final
783                  vert_mass_dist(ko) = vert_mass_dist(ko)+ x1 !- values between 0 and 1.
784                enddo
785 !               print*,'new mass=',sum(vmd)*100.,x1
786                !pause
787            endif
788            !k_final > 0 .and. k_initial >
790 !linear detrainment from vent to base of umbrella
791            do ko=1,k_initial-1
792               vert_mass_dist(ko)=float(ko)/float(k_initial-1)
793            enddo
794            x1=sum(vert_mass_dist(1:k_initial-1))
795            
796            do ko=1,k_initial-1
797                vert_mass_dist(ko)=(1.-percen_mass_umbrel)*vert_mass_dist(ko)/x1
798            enddo
799                
800                do ko=1,k_final
801 !                vert_mass_dist(ko) = vert_mass_dist(ko)+ x1 !- values between 0 and 1.
802 !                write(0,*)'k,vert_mass_dist = ',ko,vert_mass_dist(ko),zlevel(i,ko,j)
803                  grid%emis_vol(i,ko,j,p_e_vash1)=size_dist(1)*vert_mass_dist(ko)*ash_mass(i,j)
804                  grid%emis_vol(i,ko,j,p_e_vash2)=size_dist(2)*vert_mass_dist(ko)*ash_mass(i,j)
805                  grid%emis_vol(i,ko,j,p_e_vash3)=size_dist(3)*vert_mass_dist(ko)*ash_mass(i,j)
806                  grid%emis_vol(i,ko,j,p_e_vash4)=size_dist(4)*vert_mass_dist(ko)*ash_mass(i,j)
807                  grid%emis_vol(i,ko,j,p_e_vash5)=size_dist(5)*vert_mass_dist(ko)*ash_mass(i,j)
808                  grid%emis_vol(i,ko,j,p_e_vash6)=size_dist(6)*vert_mass_dist(ko)*ash_mass(i,j)
809                  grid%emis_vol(i,ko,j,p_e_vash7)=size_dist(7)*vert_mass_dist(ko)*ash_mass(i,j)
810                  grid%emis_vol(i,ko,j,p_e_vash8)=size_dist(8)*vert_mass_dist(ko)*ash_mass(i,j)
811                  grid%emis_vol(i,ko,j,p_e_vash9)=size_dist(9)*vert_mass_dist(ko)*ash_mass(i,j)
812                  grid%emis_vol(i,ko,j,p_e_vash10)=size_dist(10)*vert_mass_dist(ko)*ash_mass(i,j)
813                  if(config_flags%emiss_opt_vol == 2)grid%emis_vol(i,ko,j,p_e_vso2)=vert_mass_dist(ko)*so2_mass(i,j)
814                enddo
815 ! Changes made to Julian day from the volc_d01 file
816                grid%erup_beg(i,j)=float(beg_jul)*1000.+float(beg_hour)
817                grid%erup_end(i,j)=grid%erup_beg(i,j)+erup_dt(i,j)
818                 write(0,*)'new mass=',sum(vert_mass_dist)*100.,x1
819 !          endif
820        enddo
821        enddo
824 ! simple file dump here....
826          write(message,FMT='(A)') ' OPEN EMISSIONS WRF file for emissions coming from volcano data set'
827          call wrf_message( TRIM( message ) )
828          write(message, FMT='(A)') ' NO TIME DEPENDENCE IN THIS DATASET'
829 ! emissions from  volcanoes (prep_chem_sources)
830 !              
831          CALL construct_filename1( inpname , 'wrfchemv' , grid%id , 2 )
832          CALL open_w_dataset ( id1, TRIM(inpname) , grid , config_flags , output_auxinput13, "DATASET=AUXINPUT13", ierr )
833                
834          CALL output_auxinput13( id1 , grid , config_flags , ierr )
835        
836          CALL close_dataset ( id1 , config_flags , "DATASET=AUXOUTPUT13" )
839      endif
840 !!!!!!!!!!!!!!!!!!!! end volcanic stuff
841 !        
842      if(config_flags%emiss_opt_vol == 1 .or. config_flags%emiss_opt_vol == 2) then 
843         DEALLOCATE( ash_mass )
844         DEALLOCATE( so2_mass )
845         DEALLOCATE( volc_vent )
846         DEALLOCATE( ash_height )
847         DEALLOCATE( erup_dt)
848         DEALLOCATE( zlevel)
849         DEALLOCATE( vert_mass_dist)
850      endif
853 ! now do fire and/or global emissions
855      if(config_flags%emiss_opt == ecptec .or. config_flags%emiss_opt == gocart_ecptec ) then
856      write(message, FMT='(A,4I6)') ' I am reading global anthropogenic emissions, dims: =',ids, ide-1, jds, jde-1
857      call wrf_message( TRIM( message ) )
859      CALL construct_filename1 ( bdyname , 'emissopt3' , grid%id , 2 )
860 #ifdef DM_PARALLEL
861      IF (wrf_dm_on_monitor()) THEN
862         open (92,file=bdyname,form='unformatted')
863      ENDIf
864 #else
865      OPEN(92,FILE=bdyname,FORM='UNFORMATTED')
866 #endif
867    write(message, FMT='(A,A)') ' OPENED FILE: ',TRIM(bdyname)
868    call wrf_message( TRIM( message ) )
870          itest=0
871          if(config_flags%emiss_opt == ecptec)itest=1
872          if(config_flags%emiss_opt == gocart_ecptec)then
873            itest=0
874            write(message, FMT='(A)') ' I am reading emissions for gocart only (aerosols)'
875            call wrf_message( TRIM( message ) )
876          endif
877 #ifdef DM_PARALLEL
878      IF (wrf_dm_on_monitor()) THEN
879        read(92)nv_g
880        read(92)dname
881        read(92)itime
882      ENDIF
883      CALL wrf_dm_bcast_bytes ( nv_g , rnum8 )
884      CALL wrf_dm_bcast_bytes ( dname , rnum8 )
885      CALL wrf_dm_bcast_bytes ( itime , rnum8 )
886 #else
887      read(92)nv_g
888      read(92)dname
889      read(92)itime
890 #endif
891    
892 #ifdef DM_PARALLEL
893        IF (wrf_dm_on_monitor()) THEN
894            read(92)dumc1(ids:ide  ,jds:jde  )
895        ENDIF
896        DM_BCAST_MACRO(dumc1)
897 #else
898        read(92)dumc1(ids:ide  ,jds:jde  )
899 #endif
900          grid%emis_ant(ips:ipe  ,kps,jps:jpe  ,p_e_so2)=dumc1(ips:ipe  ,jps:jpe  )
902 #ifdef DM_PARALLEL
903        IF (wrf_dm_on_monitor()) THEN
904            read(92)dumc1(ids:ide  ,jds:jde  )
905        ENDIF
906        DM_BCAST_MACRO(dumc1)
907 #else
908        read(92)dumc1(ids:ide  ,jds:jde  )
909 #endif
910          if(itest.eq.1)grid%emis_ant(ips:ipe  ,kps,jps:jpe  ,p_e_no2)=dumc1(ips:ipe  ,jps:jpe  )
912 #ifdef DM_PARALLEL
913        IF (wrf_dm_on_monitor()) THEN
914            read(92)dumc1(ids:ide  ,jds:jde  )
915        ENDIF
916        DM_BCAST_MACRO(dumc1)
917 #else
918        read(92)dumc1(ids:ide  ,jds:jde  )
919 #endif
920          if(itest.eq.1)grid%emis_ant(ips:ipe  ,kps,jps:jpe  ,p_e_no)=dumc1(ips:ipe  ,jps:jpe  )
922 #ifdef DM_PARALLEL
923        IF (wrf_dm_on_monitor()) THEN
924            read(92)dumc1(ids:ide  ,jds:jde  )
925        ENDIF
926        DM_BCAST_MACRO(dumc1)
927 #else
928        read(92)dumc1(ids:ide  ,jds:jde  )
929 #endif
930          if(itest.eq.1)grid%emis_ant(ips:ipe  ,kps,jps:jpe  ,p_e_ald)=dumc1(ips:ipe  ,jps:jpe  )
932 #ifdef DM_PARALLEL
933        IF (wrf_dm_on_monitor()) THEN
934            read(92)dumc1(ids:ide  ,jds:jde  )
935        ENDIF
936        DM_BCAST_MACRO(dumc1)
937 #else
938        read(92)dumc1(ids:ide  ,jds:jde  )
939 #endif
940          if(itest.eq.1)grid%emis_ant(ips:ipe  ,kps,jps:jpe  ,p_e_hcho)=dumc1(ips:ipe  ,jps:jpe  )
942 #ifdef DM_PARALLEL
943        IF (wrf_dm_on_monitor()) THEN
944            read(92)dumc1(ids:ide  ,jds:jde  )
945        ENDIF
946        DM_BCAST_MACRO(dumc1)
947 #else
948        read(92)dumc1(ids:ide  ,jds:jde  )
949 #endif
950          if(itest.eq.1)grid%emis_ant(ips:ipe  ,kps,jps:jpe  ,p_e_ora2)=dumc1(ips:ipe  ,jps:jpe  )
952 #ifdef DM_PARALLEL
953        IF (wrf_dm_on_monitor()) THEN
954            read(92)dumc1(ids:ide  ,jds:jde  )
955        ENDIF
956        DM_BCAST_MACRO(dumc1)
957 #else
958        read(92)dumc1(ids:ide  ,jds:jde  )
959 #endif
960          if(itest.eq.1)grid%emis_ant(ips:ipe  ,kps,jps:jpe  ,p_e_nh3)=dumc1(ips:ipe  ,jps:jpe  )
962 #ifdef DM_PARALLEL
963        IF (wrf_dm_on_monitor()) THEN
964            read(92)dumc1(ids:ide  ,jds:jde  )
965        ENDIF
966        DM_BCAST_MACRO(dumc1)
967 #else
968        read(92)dumc1(ids:ide  ,jds:jde  )
969 #endif
970          if(itest.eq.1)grid%emis_ant(ips:ipe  ,kps,jps:jpe  ,p_e_hc3)=dumc1(ips:ipe  ,jps:jpe  )
972 #ifdef DM_PARALLEL
973        IF (wrf_dm_on_monitor()) THEN
974            read(92)dumc1(ids:ide  ,jds:jde  )
975        ENDIF
976        DM_BCAST_MACRO(dumc1)
977 #else
978        read(92)dumc1(ids:ide  ,jds:jde  )
979 #endif
980          if(itest.eq.1)grid%emis_ant(ips:ipe  ,kps,jps:jpe  ,p_e_hc5)=dumc1(ips:ipe  ,jps:jpe  )
982 #ifdef DM_PARALLEL
983        IF (wrf_dm_on_monitor()) THEN
984            read(92)dumc1(ids:ide  ,jds:jde  )
985        ENDIF
986        DM_BCAST_MACRO(dumc1)
987 #else
988        read(92)dumc1(ids:ide  ,jds:jde  )
989 #endif
990          if(itest.eq.1)grid%emis_ant(ips:ipe  ,kps,jps:jpe  ,p_e_hc8)=dumc1(ips:ipe  ,jps:jpe  )
992 #ifdef DM_PARALLEL
993        IF (wrf_dm_on_monitor()) THEN
994            read(92)dumc1(ids:ide  ,jds:jde  )
995        ENDIF
996        DM_BCAST_MACRO(dumc1)
997 #else
998        read(92)dumc1(ids:ide  ,jds:jde  )
999 #endif
1000          if(itest.eq.1)grid%emis_ant(ips:ipe  ,kps,jps:jpe  ,p_e_eth)=dumc1(ips:ipe  ,jps:jpe  )
1002 #ifdef DM_PARALLEL
1003        IF (wrf_dm_on_monitor()) THEN
1004            read(92)dumc1(ids:ide  ,jds:jde  )
1005        ENDIF
1006        DM_BCAST_MACRO(dumc1)
1007 #else
1008        read(92)dumc1(ids:ide  ,jds:jde  )
1009 #endif
1010          if(itest.eq.1)grid%emis_ant(ips:ipe  ,kps,jps:jpe  ,p_e_co)=dumc1(ips:ipe  ,jps:jpe  )
1012 #ifdef DM_PARALLEL
1013        IF (wrf_dm_on_monitor()) THEN
1014            read(92)dumc1(ids:ide  ,jds:jde  )
1015        ENDIF
1016        DM_BCAST_MACRO(dumc1)
1017 #else
1018        read(92)dumc1(ids:ide  ,jds:jde  )
1019 #endif
1020          if(itest.eq.1)grid%emis_ant(ips:ipe  ,kps,jps:jpe  ,p_e_ol2)=dumc1(ips:ipe  ,jps:jpe  )
1022 #ifdef DM_PARALLEL
1023        IF (wrf_dm_on_monitor()) THEN
1024            read(92)dumc1(ids:ide  ,jds:jde  )
1025        ENDIF
1026        DM_BCAST_MACRO(dumc1)
1027 #else
1028        read(92)dumc1(ids:ide  ,jds:jde  )
1029 #endif
1030          if(itest.eq.1)grid%emis_ant(ips:ipe  ,kps,jps:jpe  ,p_e_olt)=dumc1(ips:ipe  ,jps:jpe  )
1032 #ifdef DM_PARALLEL
1033        IF (wrf_dm_on_monitor()) THEN
1034            read(92)dumc1(ids:ide  ,jds:jde  )
1035        ENDIF
1036        DM_BCAST_MACRO(dumc1)
1037 #else
1038        read(92)dumc1(ids:ide  ,jds:jde  )
1039 #endif
1040          if(itest.eq.1)grid%emis_ant(ips:ipe  ,kps,jps:jpe  ,p_e_oli)=dumc1(ips:ipe  ,jps:jpe  )
1042 #ifdef DM_PARALLEL
1043        IF (wrf_dm_on_monitor()) THEN
1044            read(92)dumc1(ids:ide  ,jds:jde  )
1045        ENDIF
1046        DM_BCAST_MACRO(dumc1)
1047 #else
1048        read(92)dumc1(ids:ide  ,jds:jde  )
1049 #endif
1050          if(itest.eq.1)grid%emis_ant(ips:ipe  ,kps,jps:jpe  ,p_e_tol)=dumc1(ips:ipe  ,jps:jpe  )
1052 #ifdef DM_PARALLEL
1053        IF (wrf_dm_on_monitor()) THEN
1054            read(92)dumc1(ids:ide  ,jds:jde  )
1055        ENDIF
1056        DM_BCAST_MACRO(dumc1)
1057 #else
1058        read(92)dumc1(ids:ide  ,jds:jde  )
1059 #endif
1060          if(itest.eq.1)grid%emis_ant(ips:ipe  ,kps,jps:jpe  ,p_e_xyl)=dumc1(ips:ipe  ,jps:jpe  )
1062 #ifdef DM_PARALLEL
1063        IF (wrf_dm_on_monitor()) THEN
1064            read(92)dumc1(ids:ide  ,jds:jde  )
1065        ENDIF
1066        DM_BCAST_MACRO(dumc1)
1067 #else
1068        read(92)dumc1(ids:ide  ,jds:jde  )
1069 #endif
1070          if(itest.eq.1)grid%emis_ant(ips:ipe  ,kps,jps:jpe  ,p_e_ket)=dumc1(ips:ipe  ,jps:jpe  )
1072 #ifdef DM_PARALLEL
1073        IF (wrf_dm_on_monitor()) THEN
1074            read(92)dumc1(ids:ide  ,jds:jde  )
1075        ENDIF
1076        DM_BCAST_MACRO(dumc1)
1077 #else
1078        read(92)dumc1(ids:ide  ,jds:jde  )
1079 #endif
1080          if(itest.eq.1)grid%emis_ant(ips:ipe  ,kps,jps:jpe  ,p_e_csl)=dumc1(ips:ipe  ,jps:jpe  )
1082 #ifdef DM_PARALLEL
1083        IF (wrf_dm_on_monitor()) THEN
1084            read(92)dumc1(ids:ide  ,jds:jde  )
1085        ENDIF
1086        DM_BCAST_MACRO(dumc1)
1087 #else
1088        read(92)dumc1(ids:ide  ,jds:jde  )
1089 #endif
1090          if(itest.eq.1)grid%emis_ant(ips:ipe  ,kps,jps:jpe  ,p_e_iso)=dumc1(ips:ipe  ,jps:jpe  )
1092 #ifdef DM_PARALLEL
1093        IF (wrf_dm_on_monitor()) THEN
1094            read(92)dumc1(ids:ide  ,jds:jde  )
1095        ENDIF
1096        DM_BCAST_MACRO(dumc1)
1097 #else
1098        read(92)dumc1(ids:ide  ,jds:jde  )
1099 #endif
1100          grid%emis_ant(ips:ipe  ,kps,jps:jpe  ,p_e_pm_25)=dumc1(ips:ipe  ,jps:jpe  )
1102 #ifdef DM_PARALLEL
1103        IF (wrf_dm_on_monitor()) THEN
1104            read(92)dumc1(ids:ide  ,jds:jde  )
1105        ENDIF
1106        DM_BCAST_MACRO(dumc1)
1107 #else
1108        read(92)dumc1(ids:ide  ,jds:jde  )
1109 #endif
1110          grid%emis_ant(ips:ipe  ,kps,jps:jpe  ,p_e_pm_10)=dumc1(ips:ipe  ,jps:jpe  )
1112 #ifdef DM_PARALLEL
1113        IF (wrf_dm_on_monitor()) THEN
1114            read(92)dumc1(ids:ide  ,jds:jde  )
1115        ENDIF
1116        DM_BCAST_MACRO(dumc1)
1117 #else
1118        read(92)dumc1(ids:ide  ,jds:jde  )
1119 #endif
1120          grid%emis_ant(ips:ipe  ,kps,jps:jpe  ,p_e_oc)=dumc1(ips:ipe  ,jps:jpe  )
1122 #ifdef DM_PARALLEL
1123        IF (wrf_dm_on_monitor()) THEN
1124            read(92)dumc1(ids:ide  ,jds:jde  )
1125        ENDIF
1126        DM_BCAST_MACRO(dumc1)
1127 #else
1128        read(92)dumc1(ids:ide  ,jds:jde  )
1129 #endif
1130          grid%emis_ant(ips:ipe  ,kps,jps:jpe  ,p_e_bc)=dumc1(ips:ipe  ,jps:jpe  )
1132 #ifdef DM_PARALLEL
1133        IF (wrf_dm_on_monitor()) THEN
1134            read(92)dumc1(ids:ide  ,jds:jde  )
1135        ENDIF
1136        DM_BCAST_MACRO(dumc1)
1137 #else
1138        read(92)dumc1(ids:ide  ,jds:jde  )
1139 #endif
1140 !        grid%emis_ant(ips:ipe  ,kps,jps:jpe  ,p_e_dms)=dumc1(ips:ipe  ,jps:jpe  )
1142 #ifdef DM_PARALLEL
1143        IF (wrf_dm_on_monitor()) THEN
1144            read(92)dumc1(ids:ide  ,jds:jde  )
1145        ENDIF
1146        DM_BCAST_MACRO(dumc1)
1147 #else
1148        read(92)dumc1(ids:ide  ,jds:jde  )
1149 #endif
1150          grid%emis_ant(ips:ipe  ,kps,jps:jpe  ,p_e_sulf)=dumc1(ips:ipe  ,jps:jpe  )
1152 #ifdef DM_PARALLEL
1153        IF (wrf_dm_on_monitor()) THEN
1154            read(92)dumc1(ids:ide  ,jds:jde  )
1155        ENDIF
1156        DM_BCAST_MACRO(dumc1)
1157 #else
1158        read(92)dumc1(ids:ide  ,jds:jde  )
1159 #endif
1160 !        grid%emis_ant(ips:ipe  ,kps,jps:jpe  ,p_e_ash)=dumc1(ips:ipe  ,jps:jpe  )
1162      CLOSE(92)
1164 ! simple file dump here....
1166          write(message,FMT='(A)') ' OPEN EMISSIONS WRF files for emissions coming from global data set'
1167          call wrf_message( TRIM( message ) )
1168          write(message, FMT='(A)') ' NO TIME DEPENDENCE IN THIS DATASET'
1171 ! emissions from retro/edgar/gocart
1173          CALL construct_filename1( inpname , 'wrfchemi' , grid%id , 2 )
1174          CALL open_w_dataset ( id1, TRIM(inpname) , grid , config_flags , output_auxinput5 , "DATASET=AUXINPUT5", ierr )
1176          CALL output_auxinput5 ( id1 , grid , config_flags , ierr )
1178          CALL close_dataset ( id1 , config_flags , "DATASET=AUXOUTPUT5" )
1180      endif  ! emiss_opt = ecptec or gocart_ecptec
1182 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1184      if(config_flags%biomass_burn_opt == biomassb ) then
1186         CALL construct_filename1 ( bdyname2 , 'emissfire' , grid%id , 2 )
1187         write(message, FMT='(A,A)') ' TRY TO OPEN FILE: ',TRIM(bdyname2)
1188         call wrf_message( TRIM( message ) )
1189         CALL wrf_debug( 00 , 'calling fire emissions' )
1191 #ifdef DM_PARALLEL
1192         IF (wrf_dm_on_monitor()) THEN
1193            open (93,file=bdyname2,form='unformatted',status='old')
1194         ENDIf
1195 #else
1196         OPEN(93,FILE=bdyname2,FORM='UNFORMATTED',status='old')
1197 #endif
1199 #ifdef DM_PARALLEL
1200         IF (wrf_dm_on_monitor()) THEN
1201            read(93)nv_f
1202            read(93)dname 
1203            read(93)itime_f
1204         ENDIF
1205         CALL wrf_dm_bcast_bytes ( nv_f , rnum8 )
1206         CALL wrf_dm_bcast_bytes ( dname , rnum8 )
1207         CALL wrf_dm_bcast_bytes ( itime_f , rnum8 )
1208 #else
1209         read(93)nv_f
1210         read(93)dname 
1211         read(93)itime_f
1212 #endif
1213      write(message, FMT='(A,I10)') ' Number of fire emissions: ',nv_f
1214      call wrf_message( TRIM( message ) )
1215      write(message, '(A,I8,A,I8)') ' FIRE EMISSIONS INPUT FILE TIME PERIOD (GMT): ',itime_f-1,' TO ',itime_f
1216      call wrf_message( TRIM( message ) )
1218 #ifdef DM_PARALLEL
1219        IF (wrf_dm_on_monitor()) THEN
1220            read(93)dumc1(ids:ide  ,jds:jde  )
1221        ENDIF
1222      DM_BCAST_MACRO(dumc1)
1223 #else
1224        read(93)dumc1(ids:ide  ,jds:jde  )
1225 #endif
1227 !    write(*,*) 'MAXVAL2 ',MAXVAL(dumc1(:,:))
1228 !    write(*,*) 'MINVAL2 ',MINVAL(dumc1(:,:))
1230      write(message, FMT='(A)') ' put dumc1 into ebu_in_so2'
1231      call wrf_debug(100, TRIM( message ) )
1232      grid%ebu_in(ips:ipe,1,  jps:jpe  ,p_ebu_in_so2) =dumc1(ips:ipe  ,jps:jpe  )
1234 #ifdef DM_PARALLEL
1235        IF (wrf_dm_on_monitor()) THEN
1236            read(93)dumc1(ids:ide  ,jds:jde  )
1237        ENDIF
1238        DM_BCAST_MACRO(dumc1)
1239 #else
1240        read(93)dumc1(ids:ide  ,jds:jde  )
1241 #endif
1242        grid%ebu_in(ips:ipe,1,  jps:jpe  ,p_ebu_in_no2) =dumc1(ips:ipe  ,jps:jpe  )
1244 #ifdef DM_PARALLEL
1245        IF (wrf_dm_on_monitor()) THEN
1246            read(93)dumc1(ids:ide  ,jds:jde  )
1247        ENDIF
1248        DM_BCAST_MACRO(dumc1)
1249 #else
1250        read(93)dumc1(ids:ide  ,jds:jde  )
1251 #endif
1252        grid%ebu_in(ips:ipe,1,  jps:jpe  ,p_ebu_in_no) =dumc1(ips:ipe  ,jps:jpe  )
1254 #ifdef DM_PARALLEL
1255        IF (wrf_dm_on_monitor()) THEN
1256            read(93)dumc1(ids:ide  ,jds:jde  )
1257        ENDIF
1258      DM_BCAST_MACRO(dumc1)
1259 #else
1260        read(93)dumc1(ids:ide  ,jds:jde  )
1261 #endif
1262        grid%ebu_in(ips:ipe,1,  jps:jpe  ,p_ebu_in_ald) =dumc1(ips:ipe  ,jps:jpe  )
1264 #ifdef DM_PARALLEL
1265        IF (wrf_dm_on_monitor()) THEN
1266            read(93)dumc1(ids:ide  ,jds:jde  )
1267        ENDIF
1268      DM_BCAST_MACRO(dumc1)
1269 #else
1270        read(93)dumc1(ids:ide  ,jds:jde  )
1271 #endif
1272        grid%ebu_in(ips:ipe,1,  jps:jpe  ,p_ebu_in_hcho) =dumc1(ips:ipe  ,jps:jpe  )
1274 #ifdef DM_PARALLEL
1275        IF (wrf_dm_on_monitor()) THEN
1276            read(93)dumc1(ids:ide  ,jds:jde  )
1277        ENDIF
1278      DM_BCAST_MACRO(dumc1)
1279 #else
1280        read(93)dumc1(ids:ide  ,jds:jde  )
1281 #endif
1282        grid%ebu_in(ips:ipe,1,  jps:jpe  ,p_ebu_in_ora2) =dumc1(ips:ipe  ,jps:jpe  )
1284 #ifdef DM_PARALLEL
1285        IF (wrf_dm_on_monitor()) THEN
1286            read(93)dumc1(ids:ide  ,jds:jde  )
1287        ENDIF
1288      DM_BCAST_MACRO(dumc1)
1289 #else
1290        read(93)dumc1(ids:ide  ,jds:jde  )
1291 #endif
1292      ! grid%ebu_in(ips:ipe,1,  jps:jpe  ,p_ebu_in_nh3) =dumc1(ips:ipe  ,jps:jpe  )
1294 #ifdef DM_PARALLEL
1295        IF (wrf_dm_on_monitor()) THEN
1296            read(93)dumc1(ids:ide  ,jds:jde  )
1297        ENDIF
1298      DM_BCAST_MACRO(dumc1)
1299 #else
1300        read(93)dumc1(ids:ide  ,jds:jde  )
1301 #endif
1302        grid%ebu_in(ips:ipe,1,  jps:jpe  ,p_ebu_in_hc3) =dumc1(ips:ipe  ,jps:jpe  )
1304 #ifdef DM_PARALLEL
1305        IF (wrf_dm_on_monitor()) THEN
1306            read(93)dumc1(ids:ide  ,jds:jde  )
1307        ENDIF
1308      DM_BCAST_MACRO(dumc1)
1309 #else
1310        read(93)dumc1(ids:ide  ,jds:jde  )
1311 #endif
1312        grid%ebu_in(ips:ipe,1,  jps:jpe  ,p_ebu_in_hc5) =dumc1(ips:ipe  ,jps:jpe  )
1314 #ifdef DM_PARALLEL
1315        IF (wrf_dm_on_monitor()) THEN
1316            read(93)dumc1(ids:ide  ,jds:jde  )
1317        ENDIF
1318      DM_BCAST_MACRO(dumc1)
1319 #else
1320        read(93)dumc1(ids:ide  ,jds:jde  )
1321 #endif
1322        grid%ebu_in(ips:ipe,1,  jps:jpe  ,p_ebu_in_hc8) =dumc1(ips:ipe  ,jps:jpe  )
1324 #ifdef DM_PARALLEL
1325        IF (wrf_dm_on_monitor()) THEN
1326            read(93)dumc1(ids:ide  ,jds:jde  )
1327        ENDIF
1328      DM_BCAST_MACRO(dumc1)
1329 #else
1330        read(93)dumc1(ids:ide  ,jds:jde  )
1331 #endif
1332        grid%ebu_in(ips:ipe,1,  jps:jpe  ,p_ebu_in_eth) =dumc1(ips:ipe  ,jps:jpe  )
1334 #ifdef DM_PARALLEL
1335        IF (wrf_dm_on_monitor()) THEN
1336            read(93)dumc1(ids:ide  ,jds:jde  )
1337        ENDIF
1338      DM_BCAST_MACRO(dumc1)
1339 #else
1340        read(93)dumc1(ids:ide  ,jds:jde  )
1341 #endif
1342        grid%ebu_in(ips:ipe,1,  jps:jpe  ,p_ebu_in_co) =dumc1(ips:ipe  ,jps:jpe  )
1344 #ifdef DM_PARALLEL
1345        IF (wrf_dm_on_monitor()) THEN
1346            read(93)dumc1(ids:ide  ,jds:jde  )
1347        ENDIF
1348      DM_BCAST_MACRO(dumc1)
1349 #else
1350        read(93)dumc1(ids:ide  ,jds:jde  )
1351 #endif
1352    !   grid%ebu_in(ips:ipe,1,  jps:jpe  ,p_ebu_in_ol2) =dumc1(ips:ipe  ,jps:jpe  )
1354 #ifdef DM_PARALLEL
1355        IF (wrf_dm_on_monitor()) THEN
1356            read(93)dumc1(ids:ide  ,jds:jde  )
1357        ENDIF
1358      DM_BCAST_MACRO(dumc1)
1359 #else
1360        read(93)dumc1(ids:ide  ,jds:jde  )
1361 #endif
1362        grid%ebu_in(ips:ipe,1,  jps:jpe  ,p_ebu_in_olt) =dumc1(ips:ipe  ,jps:jpe  )
1364 #ifdef DM_PARALLEL
1365        IF (wrf_dm_on_monitor()) THEN
1366            read(93)dumc1(ids:ide  ,jds:jde  )
1367        ENDIF
1368      DM_BCAST_MACRO(dumc1)
1369 #else
1370        read(93)dumc1(ids:ide  ,jds:jde  )
1371 #endif
1372        grid%ebu_in(ips:ipe,1,  jps:jpe  ,p_ebu_in_oli) =dumc1(ips:ipe  ,jps:jpe  )
1374 #ifdef DM_PARALLEL
1375        IF (wrf_dm_on_monitor()) THEN
1376            read(93)dumc1(ids:ide  ,jds:jde  )
1377        ENDIF
1378      DM_BCAST_MACRO(dumc1)
1379 #else
1380        read(93)dumc1(ids:ide  ,jds:jde  )
1381 #endif
1382        grid%ebu_in(ips:ipe,1,  jps:jpe  ,p_ebu_in_tol) =dumc1(ips:ipe  ,jps:jpe  )
1384 #ifdef DM_PARALLEL
1385        IF (wrf_dm_on_monitor()) THEN
1386            read(93)dumc1(ids:ide  ,jds:jde  )
1387        ENDIF
1388      DM_BCAST_MACRO(dumc1)
1389 #else
1390        read(93)dumc1(ids:ide  ,jds:jde  )
1391 #endif
1392        grid%ebu_in(ips:ipe,1,  jps:jpe  ,p_ebu_in_xyl) =dumc1(ips:ipe  ,jps:jpe  )
1394 #ifdef DM_PARALLEL
1395        IF (wrf_dm_on_monitor()) THEN
1396            read(93)dumc1(ids:ide  ,jds:jde  )
1397        ENDIF
1398      DM_BCAST_MACRO(dumc1)
1399 #else
1400        read(93)dumc1(ids:ide  ,jds:jde  )
1401 #endif
1402        grid%ebu_in(ips:ipe,1,  jps:jpe  ,p_ebu_in_ket) =dumc1(ips:ipe  ,jps:jpe  )
1404 #ifdef DM_PARALLEL
1405        IF (wrf_dm_on_monitor()) THEN
1406            read(93)dumc1(ids:ide  ,jds:jde  )
1407        ENDIF
1408      DM_BCAST_MACRO(dumc1)
1409 #else
1410        read(93)dumc1(ids:ide  ,jds:jde  )
1411 #endif
1412        grid%ebu_in(ips:ipe,1,  jps:jpe  ,p_ebu_in_csl) =dumc1(ips:ipe  ,jps:jpe  )
1414 #ifdef DM_PARALLEL
1415        IF (wrf_dm_on_monitor()) THEN
1416            read(93)dumc1(ids:ide  ,jds:jde  )
1417        ENDIF
1418      DM_BCAST_MACRO(dumc1)
1419 #else
1420        read(93)dumc1(ids:ide  ,jds:jde  )
1421 #endif
1422        grid%ebu_in(ips:ipe,1,  jps:jpe  ,p_ebu_in_iso) =dumc1(ips:ipe  ,jps:jpe  )
1424 #ifdef DM_PARALLEL
1425        IF (wrf_dm_on_monitor()) THEN
1426            read(93)dumc1(ids:ide  ,jds:jde  )
1427        ENDIF
1428      DM_BCAST_MACRO(dumc1)
1429 #else
1430        read(93)dumc1(ids:ide  ,jds:jde  )
1431 #endif
1432        grid%ebu_in(ips:ipe,1,  jps:jpe  ,p_ebu_in_pm25) =dumc1(ips:ipe  ,jps:jpe  )
1434 #ifdef DM_PARALLEL
1435        IF (wrf_dm_on_monitor()) THEN
1436            read(93)dumc1(ids:ide  ,jds:jde  )
1437        ENDIF
1438      DM_BCAST_MACRO(dumc1)
1439 #else
1440        read(93)dumc1(ids:ide  ,jds:jde  )
1441 #endif
1442        grid%ebu_in(ips:ipe,1,  jps:jpe  ,p_ebu_in_pm10) =dumc1(ips:ipe  ,jps:jpe  )
1444 #ifdef DM_PARALLEL
1445        IF (wrf_dm_on_monitor()) THEN
1446            read(93)dumc1(ids:ide  ,jds:jde  )
1447        ENDIF
1448      DM_BCAST_MACRO(dumc1)
1449 #else
1450        read(93)dumc1(ids:ide  ,jds:jde  )
1451 #endif
1452        grid%ebu_in(ips:ipe,1,  jps:jpe  ,p_ebu_in_oc) =dumc1(ips:ipe  ,jps:jpe  )
1454 #ifdef DM_PARALLEL
1455        IF (wrf_dm_on_monitor()) THEN
1456            read(93)dumc1(ids:ide  ,jds:jde  )
1457        ENDIF
1458      DM_BCAST_MACRO(dumc1)
1459 #else
1460        read(93)dumc1(ids:ide  ,jds:jde  )
1461 #endif
1462        grid%ebu_in(ips:ipe,1,  jps:jpe  ,p_ebu_in_bc) =dumc1(ips:ipe  ,jps:jpe  )
1464 #ifdef DM_PARALLEL
1465        IF (wrf_dm_on_monitor()) THEN
1466            read(93)dumc1(ids:ide  ,jds:jde  )
1467        ENDIF
1468      DM_BCAST_MACRO(dumc1)
1469 #else
1470        read(93)dumc1(ids:ide  ,jds:jde  )
1471 #endif
1472        grid%ebu_in(ips:ipe,1,  jps:jpe  ,p_ebu_in_dms) =dumc1(ips:ipe  ,jps:jpe  )
1474 #ifdef DM_PARALLEL
1475        IF (wrf_dm_on_monitor()) THEN
1476            read(93)dumc1(ids:ide  ,jds:jde  )
1477        ENDIF
1478      DM_BCAST_MACRO(dumc1)
1479 #else
1480        read(93)dumc1(ids:ide  ,jds:jde  )
1481 #endif
1482        grid%ebu_in(ips:ipe,1,  jps:jpe  ,p_ebu_in_sulf) =dumc1(ips:ipe  ,jps:jpe  )
1484 #ifdef DM_PARALLEL
1485        IF (wrf_dm_on_monitor()) THEN
1486            read(93)dumc1(ids:ide  ,jds:jde  )
1487        ENDIF
1488      DM_BCAST_MACRO(dumc1)
1489 #else
1490        read(93)dumc1(ids:ide  ,jds:jde  )
1491 #endif
1492       grid%ebu_in(ips:ipe,1,  jps:jpe  ,p_ebu_in_ash) =dumc1(ips:ipe  ,jps:jpe  )
1494 #ifdef DM_PARALLEL
1495        IF (wrf_dm_on_monitor()) THEN
1496            read(93)dumc1(ids:ide  ,jds:jde  )
1497        ENDIF
1498      DM_BCAST_MACRO(dumc1)
1499 #else
1500        read(93)dumc1(ids:ide  ,jds:jde  )
1501 #endif
1502        grid%mean_fct_agtf(ips:ipe  ,jps:jpe  )=dumc1(ips:ipe  ,jps:jpe  )
1503 #ifdef DM_PARALLEL
1504        IF (wrf_dm_on_monitor()) THEN
1505            read(93)dumc1(ids:ide  ,jds:jde  )
1506        ENDIF
1507      DM_BCAST_MACRO(dumc1)
1508 #else
1509        read(93)dumc1(ids:ide  ,jds:jde  )
1510 #endif
1511        grid%mean_fct_agef(ips:ipe  ,jps:jpe  )=dumc1(ips:ipe  ,jps:jpe  )
1512 #ifdef DM_PARALLEL
1513        IF (wrf_dm_on_monitor()) THEN
1514            read(93)dumc1(ids:ide  ,jds:jde  )
1515        ENDIF
1516      DM_BCAST_MACRO(dumc1)
1517 #else
1518        read(93)dumc1(ids:ide  ,jds:jde  )
1519 #endif
1520        grid%mean_fct_agsv(ips:ipe  ,jps:jpe  )=dumc1(ips:ipe  ,jps:jpe  )
1521 #ifdef DM_PARALLEL
1522        IF (wrf_dm_on_monitor()) THEN
1523            read(93)dumc1(ids:ide  ,jds:jde  )
1524        ENDIF
1525      DM_BCAST_MACRO(dumc1)
1526 #else
1527        read(93)dumc1(ids:ide  ,jds:jde  )
1528 #endif
1529        grid%mean_fct_aggr(ips:ipe  ,jps:jpe  )=dumc1(ips:ipe  ,jps:jpe  )
1530 #ifdef DM_PARALLEL
1531        IF (wrf_dm_on_monitor()) THEN
1532            read(93)dumc1(ids:ide  ,jds:jde  )
1533        ENDIF
1534      DM_BCAST_MACRO(dumc1)
1535 #else
1536        read(93)dumc1(ids:ide  ,jds:jde  )
1537 #endif
1538        grid%firesize_agtf(ips:ipe  ,jps:jpe  )=dumc1(ips:ipe  ,jps:jpe  )
1539 #ifdef DM_PARALLEL
1540        IF (wrf_dm_on_monitor()) THEN
1541            read(93)dumc1(ids:ide  ,jds:jde  )
1542        ENDIF
1543      DM_BCAST_MACRO(dumc1)
1544 #else
1545        read(93)dumc1(ids:ide  ,jds:jde  )
1546 #endif
1547        grid%firesize_agef(ips:ipe  ,jps:jpe  )=dumc1(ips:ipe  ,jps:jpe  )
1548 #ifdef DM_PARALLEL
1549        IF (wrf_dm_on_monitor()) THEN
1550            read(93)dumc1(ids:ide  ,jds:jde  )
1551        ENDIF
1552      DM_BCAST_MACRO(dumc1)
1553 #else
1554        read(93)dumc1(ids:ide  ,jds:jde  )
1555 #endif
1556        grid%firesize_agsv(ips:ipe  ,jps:jpe  )=dumc1(ips:ipe  ,jps:jpe  )
1557 #ifdef DM_PARALLEL
1558        IF (wrf_dm_on_monitor()) THEN
1559            read(93)dumc1(ids:ide  ,jds:jde  )
1560        ENDIF
1561      DM_BCAST_MACRO(dumc1)
1562 #else
1563        read(93)dumc1(ids:ide  ,jds:jde  )
1564 #endif
1565        grid%firesize_aggr(ips:ipe  ,jps:jpe  )=dumc1(ips:ipe  ,jps:jpe  )
1567          CLOSE(93)
1569 ! fire stuff
1571          CALL construct_filename1( inpname , 'wrffirechemi' , grid%id , 2 )
1572          write(message, FMT='(A,A)') ' NOW OPEN FILE FOR WRITE: ',TRIM(inpname)
1573          call wrf_message( TRIM( message ) )
1575          CALL open_w_dataset ( id1, TRIM(inpname) , grid , config_flags , output_auxinput7 , "DATASET=AUXINPUT7", ierr )
1576          write(message,FMT='(A,A)') ' FIRE EMISSIONS OUTPUT file name: ',TRIM(inpname)
1577          CALL  wrf_message ( message )
1578          IF ( ierr .NE. 0 ) THEN
1579             write(message, FMT='(A,I10)') ' convert_emiss: error opening wrfchem fire emissions file for writing',ierr
1580             CALL wrf_error_fatal( TRIM( message ) )
1581          ENDIF
1583          CALL output_auxinput7 ( id1 , grid , config_flags , ierr )
1585          CALL close_dataset ( id1 , config_flags , "DATASET=AUXOUTPUT7" )
1587      endif ! biomassburn
1589 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1590 !    NOW DO BIG TIMEDEPENDENT EMISSIONS FILE
1592     if(CONFIG_FLAGS%EMISS_OPT == ECBMZ_MOSAIC ) then
1593        write(message, FMT='(A,I10)') ' convert_emiss: error: conversion for all CBMZ emission arrays not available '
1594        CALL wrf_error_fatal( TRIM( message ) )
1595     endif
1596     if(CONFIG_FLAGS%EMISS_OPT == ERADM .or. CONFIG_FLAGS%EMISS_OPT == ERADMSORG .or.  &
1597        CONFIG_FLAGS%EMISS_OPT == MOZEM .or. CONFIG_FLAGS%EMISS_OPT == MOZCEM    .or.  &
1598        CONFIG_FLAGS%EMISS_OPT == ECBMZ_MOSAIC ) then
1599    !  Figure out our loop count for the processing times.
1600 #ifdef DM_PARALLEL
1601      IF (wrf_dm_on_monitor()) THEN
1602 #endif
1604    time_loop = 1
1605    write(message,FMT='(A,I4,A,A)') 'Time period #',time_loop,' to process = ',start_date_char
1606    CALL  wrf_message ( message )
1607    current_date_char = start_date_char
1608    loop_count : DO
1609       CALL geth_newdate ( next_date_char , current_date_char , int_sec )
1610       IF      ( next_date_char .LT. end_date_char ) THEN
1611          time_loop = time_loop + 1
1612          write(message,FMT='(A,I4,A,A)') 'Time period #',time_loop,' to process = ',next_date_char
1613          CALL  wrf_message ( message )
1614          current_date_char = next_date_char
1615       ELSE IF ( next_date_char .EQ. end_date_char ) THEN
1616          time_loop = time_loop + 1
1617          write(message,FMT='(A,I4,A,A)') 'Time period #',time_loop,' to process = ',next_date_char
1618          CALL  wrf_message ( message )
1619          write(message,FMT='(A,I4)') 'Total analysis times to input = ',time_loop
1620          CALL  wrf_message ( message )
1621          time_loop_max = time_loop
1622          EXIT loop_count
1623       ELSE IF ( next_date_char .GT. end_date_char ) THEN
1624          write(message,FMT='(A,I4)') 'Total analysis times to input = ',time_loop
1625          CALL  wrf_message ( message )
1626          time_loop_max = time_loop
1627          time_loop_max = time_loop
1628          EXIT loop_count
1629       END IF
1630    END DO loop_count
1631    write(message,FMT='(A,I4,A,I4)') 'Total number of times to input = ',time_loop,' ',time_loop_max
1632    CALL  wrf_message ( message )
1633 #ifdef DM_PARALLEL
1634      ENDIF 
1635    CALL wrf_dm_bcast_bytes ( time_loop , rnum8 )
1636    CALL wrf_dm_bcast_bytes ( time_loop_max , rnum8 )
1637 #endif
1639    !  Here we define the initial time to process, for later use by the code.
1641    current_date_char = start_date_char
1642    start_date = start_date_char // '.0000'
1643    current_date = start_date
1645 #ifdef DM_PARALLEL
1646    CALL wrf_dm_bcast_bytes ( start_hour , rnum8 )
1647 #endif
1649    ihour = start_hour
1650    write(message,FMT='(A)') ' READ EMISSIONS 1'
1651    CALL  wrf_debug ( 100, message )
1652 ! do the ugly stuff
1654      if(start_hour.eq.0)CALL construct_filename1 ( bdyname , 'wrfem_00to12z' , grid%id , 2 )
1655      if(start_hour.eq.12)CALL construct_filename1 ( bdyname , 'wrfem_12to24z' , grid%id , 2 )
1657 #ifdef DM_PARALLEL
1658      IF (wrf_dm_on_monitor()) THEN
1659         open (91,file=bdyname,form='unformatted',status='old')
1661         write(*,*) TRIM( bdyname )
1662      ENDIf
1663 #else
1664 !  write(message, FMT='(A,A)') ' OPEN FILE: ',bdyname
1665 !  call wrf_message( TRIM( message ) )
1666         open (91,file=bdyname,form='unformatted',status='old')
1667 #endif
1669 !  write(message, FMT='(A,A)') ' OPENED FILE: ',bdyname
1670 !  call wrf_message( TRIM( message ) )
1671 #ifdef DM_PARALLEL
1672      IF (wrf_dm_on_monitor()) THEN
1673        read(91)nv
1674        read(91)dname 
1675        read(91)itime
1676      ENDIF
1677      CALL wrf_dm_bcast_bytes ( nv , rnum8 )
1678      CALL wrf_dm_bcast_bytes ( dname , rnum8 )
1679      CALL wrf_dm_bcast_bytes ( itime , rnum8 )
1680 #else
1681      read(91)nv
1682      read(91)dname 
1683      read(91)itime
1684 #endif
1685      write(message, FMT='(A,I10)') ' Number of emissions: ',nv
1686      call wrf_message( TRIM( message ) )
1687      write(message, '(A,I8,A,I8)') ' EMISSIONS INPUT FILE TIME PERIOD (GMT): ',itime-1,' TO ',itime
1688      call wrf_message( TRIM( message ) )
1690 #ifdef DM_PARALLEL
1691      IF (wrf_dm_on_monitor()) THEN
1692      write(message, FMT='(A)') ' read dumc0 '
1693      call wrf_debug(100, TRIM( message ) )
1694         read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1695      ENDIF
1696      DM_BCAST_MACRO(dumc0)
1697 #else
1698          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1699 #endif
1700      write(message, FMT='(A)') ' write dumc0 to emiss_ant'
1701      call wrf_debug(100, TRIM( message ) )
1702      write(message, FMT='(A,3I10)') ' dims:',ips  ,kps,jps
1703      call wrf_message( TRIM( message ) )
1704      write(message, FMT='(A,4I10)') ' dims:',ipe-1,kpe,jpe-1,grid%kemit
1705      call wrf_message( TRIM( message ) )
1706      write(message, FMT='(A,3I10)') ' dims:',ids  ,kds,jds
1707      call wrf_message( TRIM( message ) )
1708      write(message, FMT='(A,4I10)') ' dims:',ide-1,kde,jde-1
1709      call wrf_message( TRIM( message ) )
1710      write(message, FMT='(A,5I10)') ' dims:',size(grid%emis_ant,1),size(grid%emis_ant,2),size(grid%emis_ant,3),size(grid%emis_ant,4),p_e_so2
1711      call wrf_message( TRIM( message ) )
1712      write(message, FMT='(A,5I10)') ' dims:',size(dumc0,1),size(dumc0,2),size(dumc0,3)
1713      call wrf_message( TRIM( message ) )
1714 !    write(*,*) dumc0(ids:ide-1,1,7)
1715          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_so2)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
1716 !    write(*,*) grid%emis_ant(ips:ipe-1,1,7,p_e_so2)
1717 #ifdef DM_PARALLEL
1718      IF (wrf_dm_on_monitor()) THEN
1719          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1720      ENDIF
1721      DM_BCAST_MACRO(dumc0)
1722 #else
1724          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1725 #endif
1726          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_no)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
1728      IF (inew_nei .eq. 1) THEN
1729 #ifdef DM_PARALLEL
1730      IF (wrf_dm_on_monitor()) THEN
1731          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1732      ENDIF
1733      DM_BCAST_MACRO(dumc0)
1734 #else
1736          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1737 #endif
1738          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_no2)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
1739      ENDIF
1741 #ifdef DM_PARALLEL
1742      IF (wrf_dm_on_monitor()) THEN
1743          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1744      ENDIF
1745      DM_BCAST_MACRO(dumc0)
1746 #else
1747          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1748 #endif
1749          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_ald)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
1750 #ifdef DM_PARALLEL
1751      IF (wrf_dm_on_monitor()) THEN
1752          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1753      ENDIF
1754      DM_BCAST_MACRO(dumc0)
1755 #else
1756          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1757 #endif
1758          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_hcho)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
1759 #ifdef DM_PARALLEL
1760      IF (wrf_dm_on_monitor()) THEN
1761          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1762      ENDIF
1763      DM_BCAST_MACRO(dumc0)
1764 #else
1765          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1766 #endif
1767          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_ora2)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
1768 #ifdef DM_PARALLEL
1769      IF (wrf_dm_on_monitor()) THEN
1770          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1771      ENDIF
1772      DM_BCAST_MACRO(dumc0)
1773 #else
1774          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1775 #endif
1776          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_nh3)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
1777 #ifdef DM_PARALLEL
1778      IF (wrf_dm_on_monitor()) THEN
1779          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1780      ENDIF
1781      DM_BCAST_MACRO(dumc0)
1782 #else
1783          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1784 #endif
1785          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_hc3)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
1786 #ifdef DM_PARALLEL
1787      IF (wrf_dm_on_monitor()) THEN
1788          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1789      ENDIF
1790      DM_BCAST_MACRO(dumc0)
1791 #else
1792          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1793 #endif
1794          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_hc5)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
1795 #ifdef DM_PARALLEL
1796      IF (wrf_dm_on_monitor()) THEN
1797          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1798      ENDIF
1799      DM_BCAST_MACRO(dumc0)
1800 #else
1801          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1802 #endif
1803          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_hc8)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
1804 #ifdef DM_PARALLEL
1805      IF (wrf_dm_on_monitor()) THEN
1806          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1807      ENDIF
1808      DM_BCAST_MACRO(dumc0)
1809 #else
1810          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1811 #endif
1812          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_eth)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
1813 #ifdef DM_PARALLEL
1814      IF (wrf_dm_on_monitor()) THEN
1815          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1816      ENDIF
1817      DM_BCAST_MACRO(dumc0)
1818 #else
1819          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1820 #endif
1821          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_co)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
1822 #ifdef DM_PARALLEL
1823      IF (wrf_dm_on_monitor()) THEN
1824          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1825      ENDIF
1826      DM_BCAST_MACRO(dumc0)
1827 #else
1828          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1829 #endif
1830          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_ol2)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
1831 #ifdef DM_PARALLEL
1832      IF (wrf_dm_on_monitor()) THEN
1833          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1834      ENDIF
1835      DM_BCAST_MACRO(dumc0)
1836 #else
1837          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1838 #endif
1839          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_olt)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
1840 #ifdef DM_PARALLEL
1841      IF (wrf_dm_on_monitor()) THEN
1842          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1843      ENDIF
1844      DM_BCAST_MACRO(dumc0)
1845 #else
1846          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1847 #endif
1848          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_oli)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
1849 #ifdef DM_PARALLEL
1850      IF (wrf_dm_on_monitor()) THEN
1851          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1852      ENDIF
1853      DM_BCAST_MACRO(dumc0)
1854 #else
1855          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1856 #endif
1857          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_tol)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
1858 #ifdef DM_PARALLEL
1859      IF (wrf_dm_on_monitor()) THEN
1860          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1861      ENDIF
1862      DM_BCAST_MACRO(dumc0)
1863 #else
1864          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1865 #endif
1866          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_xyl)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
1867 #ifdef DM_PARALLEL
1868      IF (wrf_dm_on_monitor()) THEN
1869          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1870      ENDIF
1871      DM_BCAST_MACRO(dumc0)
1872 #else
1873          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1874 #endif
1875          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_ket)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
1876 #ifdef DM_PARALLEL
1877      IF (wrf_dm_on_monitor()) THEN
1878          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1879      ENDIF
1880      DM_BCAST_MACRO(dumc0)
1881 #else
1882          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1883 #endif
1884          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_csl)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
1885 #ifdef DM_PARALLEL
1886      IF (wrf_dm_on_monitor()) THEN
1887          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1888      ENDIF
1889      DM_BCAST_MACRO(dumc0)
1890 #else
1891          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1892 #endif
1893          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_iso)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
1894      IF( inew_ch4 == 1 ) THEN
1895 #ifdef DM_PARALLEL
1896      IF (wrf_dm_on_monitor()) THEN
1897          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1898      ENDIF
1899      DM_BCAST_MACRO(dumc0)
1900 #else
1901          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1902 #endif
1903          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_ch4)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
1904      ENDIF
1905 #ifdef DM_PARALLEL
1906      IF (wrf_dm_on_monitor()) THEN
1907          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1908      ENDIF
1909      DM_BCAST_MACRO(dumc0)
1910 #else
1911          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1912 #endif
1913          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_pm25i)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
1914 #ifdef DM_PARALLEL
1915      IF (wrf_dm_on_monitor()) THEN
1916          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1917      ENDIF
1918      DM_BCAST_MACRO(dumc0)
1919 #else
1920          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1921 #endif
1922          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_pm25j)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
1923 #ifdef DM_PARALLEL
1924      IF (wrf_dm_on_monitor()) THEN
1925          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1926      ENDIF
1927      DM_BCAST_MACRO(dumc0)
1928 #else
1929          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1930 #endif
1931          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_so4i)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
1932 #ifdef DM_PARALLEL
1933      IF (wrf_dm_on_monitor()) THEN
1934          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1935      ENDIF
1936      DM_BCAST_MACRO(dumc0)
1937 #else
1938          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1939 #endif
1940          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_so4j)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
1941 #ifdef DM_PARALLEL
1942      IF (wrf_dm_on_monitor()) THEN
1943          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1944      ENDIF
1945      DM_BCAST_MACRO(dumc0)
1946 #else
1947          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1948 #endif
1949          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_no3i)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
1950 #ifdef DM_PARALLEL
1951      IF (wrf_dm_on_monitor()) THEN
1952          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1953      ENDIF
1954      DM_BCAST_MACRO(dumc0)
1955 #else
1956          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1957 #endif
1958          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_no3j)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
1960      IF (inew_nei .eq. 1) THEN
1961 !! naai and naaj for aqmeii
1962 #ifdef DM_PARALLEL
1963      IF (wrf_dm_on_monitor()) THEN
1964          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1965      ENDIF
1966      DM_BCAST_MACRO(dumc0)
1967 #else
1968          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1969 #endif
1970          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_naai)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
1971 #ifdef DM_PARALLEL
1972      IF (wrf_dm_on_monitor()) THEN
1973          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1974      ENDIF
1975      DM_BCAST_MACRO(dumc0)
1976 #else
1977          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1978 #endif
1979          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_naaj)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
1980      ENDIF
1982 #ifdef DM_PARALLEL
1983      IF (wrf_dm_on_monitor()) THEN
1984          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1985      ENDIF
1986      DM_BCAST_MACRO(dumc0)
1987 #else
1988          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1989 #endif
1990          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_orgi)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
1991 #ifdef DM_PARALLEL
1992      IF (wrf_dm_on_monitor()) THEN
1993          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1994      ENDIF
1995      DM_BCAST_MACRO(dumc0)
1996 #else
1997          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
1998 #endif
1999          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_orgj)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2000 #ifdef DM_PARALLEL
2001      IF (wrf_dm_on_monitor()) THEN
2002          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2003      ENDIF
2004      DM_BCAST_MACRO(dumc0)
2005 #else
2006          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2007 #endif
2008          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_eci)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2009 #ifdef DM_PARALLEL
2010      IF (wrf_dm_on_monitor()) THEN
2011          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2012      ENDIF
2013      DM_BCAST_MACRO(dumc0)
2014 #else
2015          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2016 #endif
2017          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_ecj)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2018 #ifdef DM_PARALLEL
2019      IF (wrf_dm_on_monitor()) THEN
2020          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2021      ENDIF
2022      DM_BCAST_MACRO(dumc0)
2023 #else
2024          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2025 #endif
2026          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_pm_10)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2028 !liqy-add cl emission
2029 #ifdef DM_PARALLEL
2030      IF (wrf_dm_on_monitor()) THEN
2031          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2032      ENDIF
2033      DM_BCAST_MACRO(dumc0)
2034 #else
2035          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2036 #endif
2037          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe,p_e_hcl)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2039 #ifdef DM_PARALLEL
2040      IF (wrf_dm_on_monitor()) THEN
2041          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2042      ENDIF
2043      DM_BCAST_MACRO(dumc0)
2044 #else
2045          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2046 #endif
2047          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe,p_e_ch3cl)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2049 #ifdef DM_PARALLEL
2050      IF (wrf_dm_on_monitor()) THEN
2051          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2052      ENDIF
2053      DM_BCAST_MACRO(dumc0)
2054 #else
2055          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2056 #endif
2057          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe,p_e_cli)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2059 #ifdef DM_PARALLEL
2060      IF (wrf_dm_on_monitor()) THEN
2061          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2062      ENDIF
2063      DM_BCAST_MACRO(dumc0)
2064 #else
2065          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2066 #endif
2067          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe,p_e_clj)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2068 !liqy-20160426
2069    write(message,FMT='(A)') ' PAST READ EMISSIONS 1'
2070    CALL  wrf_message ( message )
2072 !  grid%input_from_file = .false.
2074    if (config_flags%io_style_emissions.eq.1)then
2075       write(eminame,FMT='(A9,i2.2,a1)') 'wrfchemi_',ihour,'z'
2076       CALL construct_filename1 ( inpname ,TRIM(eminame), grid%id , 2 )
2077    else
2078       CALL construct_filename1( inpname , 'wrfchemi' , grid%id , 2 )
2079    endif
2081    write(message,FMT='(A,A,I10)') ' OPEN FILE ',TRIM(inpname),config_flags%io_form_auxinput5
2082    CALL  wrf_debug ( 100, message )
2083    CALL open_w_dataset ( id1, TRIM(inpname) , grid , config_flags , output_auxinput5 , "DATASET=AUXINPUT5", ierr )
2084    write(message,FMT='(A,A)') ' EMISSIONS OUTPUT file name: ',TRIM(inpname)
2085    CALL  wrf_message ( message )
2086    IF ( ierr .NE. 0 ) THEN
2087      CALL wrf_error_fatal( 'convert_emiss: error opening wrfchem emissions file for writing' )
2088    ENDIF
2090    CALL calc_current_date ( grid%id , 0. )
2091    CALL geth_newdate ( current_date_char, current_date, 3600 )
2092    current_date = current_date_char // '.0000'
2093          if( stand_lon  == 0. ) then
2094          stand_lon = cen_lon
2095       endif
2096    
2097       if( moad_cen_lat  == 0. ) then
2098          moad_cen_lat = cen_lat
2099       endif
2101    write(message,FMT='(A)') ' WRITE EMISSIONS 1'
2102    CALL  wrf_message ( message )
2103     CALL output_auxinput5 ( id1 , grid , config_flags, ierr )
2105    CALL wrf_dm_bcast_bytes ( time_loop , rnum8 )
2106    nemi_frames = time_loop
2107   
2108     write(message,FMT='(A,4I10)') 'FRAMES: ',int(nemi_frames),time_loop
2109    CALL  wrf_message ( message )
2110     current_date_char = start_date_char
2111     current_date = current_date_char
2112 !  if( debug_level >= -100) print *,'NEMI_FRAMES ', nemi_frames,time_loop
2114 !  DO emi_frame = 2,1
2115    DO emi_frame = 2,nemi_frames
2116     write(message,FMT='(A,4I10)') 'LOOP: ',emi_frame,nemi_frames
2117    CALL  wrf_message ( message )
2118 #ifdef DM_PARALLEL
2119      IF (wrf_dm_on_monitor()) THEN
2120      write(message,FMT='(A,I4)') 'emi_frame: ',emi_frame
2121      CALL  wrf_debug ( 100, message )
2122      CALL domain_clock_get ( grid, current_timestr=timestr )
2123      write(message,FMT='(A,A)') ' Current time ',Trim(timestr)
2124      CALL  wrf_debug ( 100, message )
2126      current_date_char = current_date(1:19)
2127      CALL geth_newdate ( next_date_char, current_date_char, int(int_sec) )
2128      current_date = next_date_char // '.0000'
2130      write(message,FMT='(A,A)') ' Date &  time ',Trim(current_date)
2131      CALL  wrf_message ( message )
2132      CALL domain_clockadvance( grid )
2134      write(message,FMT='(A,I4)') ' Read emissions ',emi_frame
2135      CALL  wrf_debug ( 100, message )
2136      write(message,FMT='(A,I4)') ' Hour ',ihour
2137      CALL  wrf_message ( message )
2138      ihour = mod(ihour + 1,24)
2140 ! Allow writing of both 12h files with 1 submission when io_style_emissions=1 (2 12h files)
2141      if(ihour.eq.0 .or. ihour.eq.12)then
2142 ! Read from next binary emissions file
2143          close(91)
2144          if(ihour.eq.0) then
2145            CALL construct_filename1 ( bdyname , 'wrfem_00to12z' , grid%id , 2 )
2146          elseif(ihour.eq.12) then
2147            CALL construct_filename1 ( bdyname , 'wrfem_12to24z' , grid%id , 2 )
2148          endif
2149          open (91,file=bdyname,form='unformatted')
2150 !Write a 2nd netcdf emiss file?
2151          if (config_flags%io_style_emissions .eq.1) then
2152            CALL close_dataset ( id1 , config_flags , "DATASET=AUXOUTPUT5" )
2153            write(eminame,FMT='(A9,i2.2,a1)') 'wrfchemi_',ihour,'z'
2154            CALL construct_filename1 ( inpname ,TRIM(eminame), grid%id , 2 )
2155            write(message,FMT='(A,A,I10)') ' OPEN FILE ',TRIM(inpname),config_flags%io_form_auxinput5
2156            CALL  wrf_debug ( 0, message )
2157            CALL open_w_dataset ( id1, TRIM(inpname) , grid , config_flags , output_auxinput5 , "DATASET=AUXINPUT5", ierr )
2158            write(message,FMT='(A,A)') ' EMISSIONS OUTPUT file name: ',TRIM(inpname)
2159            CALL  wrf_message ( message )
2160            IF ( ierr .NE. 0 ) THEN
2161              CALL wrf_error_fatal( 'Error opening wrfchem emissions file for writing' )
2162            ENDIF
2163          endif
2164      endif
2166      ENDIF
2167      CALL wrf_dm_bcast_bytes ( ihour , rnum8 )
2168 !    CALL wrf_dm_bcast_bytes ( bdyname , rnum8 )
2169 #else
2170      write(message,FMT='(A,I4)') 'emi_frame: ',emi_frame
2171      CALL  wrf_debug ( 100, message )
2172      CALL domain_clock_get ( grid, current_timestr=timestr )
2173      write(message,FMT='(A,A)') ' Current time ',Trim(timestr)
2174      CALL  wrf_debug ( 100, message )
2176      current_date_char = current_date(1:19)
2177      CALL geth_newdate ( next_date_char, current_date_char, int(int_sec) )
2178      current_date = next_date_char // '.0000'
2180      write(message,FMT='(A,A)') ' Date &  time ',Trim(current_date)
2181      CALL  wrf_message ( message )
2182      CALL domain_clockadvance( grid ) 
2183      write(message,FMT='(A,I4)') ' Read emissions ',emi_frame
2184      CALL  wrf_debug ( 100, message )
2185      ihour = mod(ihour + 1,24)
2186      if(ihour.eq.0)then
2187          close(91)
2188          CALL construct_filename1 ( bdyname , 'wrfem_00to12z' , grid%id , 2 )
2189          open (91,file=bdyname,form='unformatted')
2190      endif
2191      if(ihour.eq.12) then 
2192          close(91)
2193          CALL construct_filename1 ( bdyname , 'wrfem_12to24z' , grid%id , 2 )
2194          open (91,file=bdyname,form='unformatted')
2195      endif
2196 ! Allow writing of both 12h files with 1 submission when io_style_emissions=1 (2 12h files)
2197      if(ihour.eq.0 .or. ihour.eq.12)then
2198 ! Read from next emissions file
2199          close(91)
2200          if(ihour.eq.0) then
2201            CALL construct_filename1 ( bdyname , 'wrfem_00to12z' , grid%id , 2 )
2202          elseif(ihour.eq.12) then
2203            CALL construct_filename1 ( bdyname , 'wrfem_12to24z' , grid%id , 2 )
2204          endif
2205          open (91,file=bdyname,form='unformatted')
2206 !Write a 2nd netcdf emiss file?
2207          if (config_flags%io_style_emissions .eq.1) then
2208            CALL close_dataset ( id1 , config_flags , "DATASET=AUXOUTPUT5" )
2209            write(message,FMT='(A)') ' CLOSED FIRST FILE, OPENING SECOND FILE'
2210            CALL  wrf_message ( message )
2211            write(eminame,FMT='(A9,i2.2,a1)') 'wrfchemi_',ihour,'z'
2212            CALL construct_filename1 ( inpname , TRIM(eminame) , grid%id , 2 )
2213            write(message,FMT='(A,A,I10)') ' OPEN FILE ',TRIM(inpname),config_flags%io_form_auxinput5
2214            CALL  wrf_debug ( 0, message )
2215            CALL open_w_dataset ( id1, TRIM(inpname) , grid , config_flags , output_auxinput5 , "DATASET=AUXINPUT5", ierr )
2216            write(message,FMT='(A,A)') ' EMISSIONS OUTPUT file name: ',TRIM(inpname)
2217            CALL  wrf_message ( message )
2218            IF ( ierr .NE. 0 ) THEN
2219              CALL wrf_error_fatal( 'Error opening wrfchem emissions file for writing' )
2220            ENDIF
2221          endif
2222      endif
2223 #endif
2225      write(message, '(A,A,I10)') ' USING FILE: ',TRIM(bdyname),ihour
2226      call wrf_message( TRIM( message ) )
2228      if(ihour.eq.0.or.ihour.eq.12)then
2229 #ifdef DM_PARALLEL
2230      IF (wrf_dm_on_monitor()) THEN
2231        read(91)nv
2232        read(91)dname 
2233      ENDIF
2234      CALL wrf_dm_bcast_bytes ( nv , rnum8 )
2235      CALL wrf_dm_bcast_bytes ( dname , rnum8 )
2236 #else
2237      read(91)nv
2238      read(91)dname 
2239 #endif
2240      write(message, '(A,I10)') ' Reading FILE header: ',nv
2241      call wrf_message( TRIM( message ) )
2243      endif
2245 #ifdef DM_PARALLEL
2246      IF (wrf_dm_on_monitor()) THEN
2247         read(91)itime
2248      ENDIF
2249      CALL wrf_dm_bcast_bytes ( itime , rnum8 )
2250 #else
2251      read(91)itime
2252 #endif
2254      write(message, '(A,I10)') ' Reading data from file: ',itime
2255      call wrf_message( TRIM( message ) )
2257 #ifdef DM_PARALLEL
2258      IF (wrf_dm_on_monitor()) THEN
2259          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2260      ENDIF
2261      DM_BCAST_MACRO(dumc0)
2262 #else
2263         read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2264 #endif
2265          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_so2)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2267 #ifdef DM_PARALLEL
2268      IF (wrf_dm_on_monitor()) THEN
2269          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2270      ENDIF
2271      DM_BCAST_MACRO(dumc0)
2272 #else
2274          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2275 #endif
2276          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_no)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2278      IF (inew_nei .eq. 1) THEN
2279 #ifdef DM_PARALLEL
2280      IF (wrf_dm_on_monitor()) THEN
2281          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2282      ENDIF
2283      DM_BCAST_MACRO(dumc0)
2284 #else
2286          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2287 #endif
2288          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_no2)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2289       ENDIF
2291 #ifdef DM_PARALLEL
2292      IF (wrf_dm_on_monitor()) THEN
2293          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2294      ENDIF
2295      DM_BCAST_MACRO(dumc0)
2296 #else
2297          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2298 #endif
2299          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_ald)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2300 #ifdef DM_PARALLEL
2301      IF (wrf_dm_on_monitor()) THEN
2302          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2303      ENDIF
2304      DM_BCAST_MACRO(dumc0)
2305 #else
2306          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2307 #endif
2308          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_hcho)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2309 #ifdef DM_PARALLEL
2310      IF (wrf_dm_on_monitor()) THEN
2311          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2312      ENDIF
2313      DM_BCAST_MACRO(dumc0)
2314 #else
2315          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2316 #endif
2317          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_ora2)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2318 #ifdef DM_PARALLEL
2319      IF (wrf_dm_on_monitor()) THEN
2320          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2321      ENDIF
2322      DM_BCAST_MACRO(dumc0)
2323 #else
2324          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2325 #endif
2326          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_nh3)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2327 #ifdef DM_PARALLEL
2328      IF (wrf_dm_on_monitor()) THEN
2329          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2330      ENDIF
2331      DM_BCAST_MACRO(dumc0)
2332 #else
2333          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2334 #endif
2335          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_hc3)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2336 #ifdef DM_PARALLEL
2337      IF (wrf_dm_on_monitor()) THEN
2338          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2339      ENDIF
2340      DM_BCAST_MACRO(dumc0)
2341 #else
2342          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2343 #endif
2344          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_hc5)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2345 #ifdef DM_PARALLEL
2346      IF (wrf_dm_on_monitor()) THEN
2347          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2348      ENDIF
2349      DM_BCAST_MACRO(dumc0)
2350 #else
2351          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2352 #endif
2353          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_hc8)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2354 #ifdef DM_PARALLEL
2355      IF (wrf_dm_on_monitor()) THEN
2356          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2357      ENDIF
2358      DM_BCAST_MACRO(dumc0)
2359 #else
2360          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2361 #endif
2362          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_eth)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2363 #ifdef DM_PARALLEL
2364      IF (wrf_dm_on_monitor()) THEN
2365          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2366      ENDIF
2367      DM_BCAST_MACRO(dumc0)
2368 #else
2369          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2370 #endif
2371          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_co)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2372 #ifdef DM_PARALLEL
2373      IF (wrf_dm_on_monitor()) THEN
2374          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2375      ENDIF
2376      DM_BCAST_MACRO(dumc0)
2377 #else
2378          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2379 #endif
2380          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_ol2)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2381 #ifdef DM_PARALLEL
2382      IF (wrf_dm_on_monitor()) THEN
2383          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2384      ENDIF
2385      DM_BCAST_MACRO(dumc0)
2386 #else
2387          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2388 #endif
2389          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_olt)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2390 #ifdef DM_PARALLEL
2391      IF (wrf_dm_on_monitor()) THEN
2392          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2393      ENDIF
2394      DM_BCAST_MACRO(dumc0)
2395 #else
2396          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2397 #endif
2398          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_oli)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2399 #ifdef DM_PARALLEL
2400      IF (wrf_dm_on_monitor()) THEN
2401          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2402      ENDIF
2403      DM_BCAST_MACRO(dumc0)
2404 #else
2405          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2406 #endif
2407          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_tol)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2408 #ifdef DM_PARALLEL
2409      IF (wrf_dm_on_monitor()) THEN
2410          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2411      ENDIF
2412      DM_BCAST_MACRO(dumc0)
2413 #else
2414          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2415 #endif
2416          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_xyl)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2417 #ifdef DM_PARALLEL
2418      IF (wrf_dm_on_monitor()) THEN
2419          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2420      ENDIF
2421      DM_BCAST_MACRO(dumc0)
2422 #else
2423          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2424 #endif
2425          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_ket)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2426 #ifdef DM_PARALLEL
2427      IF (wrf_dm_on_monitor()) THEN
2428          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2429      ENDIF
2430      DM_BCAST_MACRO(dumc0)
2431 #else
2432          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2433 #endif
2434          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_csl)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2435 #ifdef DM_PARALLEL
2436      IF (wrf_dm_on_monitor()) THEN
2437          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2438      ENDIF
2439      DM_BCAST_MACRO(dumc0)
2440 #else
2441          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2442 #endif
2443          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_iso)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2444      IF( inew_ch4 == 1 ) THEN
2445 #ifdef DM_PARALLEL
2446      IF (wrf_dm_on_monitor()) THEN
2447          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2448      ENDIF
2449      DM_BCAST_MACRO(dumc0)
2450 #else
2451          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2452 #endif
2453          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_ch4)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2454      ENDIF
2455 #ifdef DM_PARALLEL
2456      IF (wrf_dm_on_monitor()) THEN
2457          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2458      ENDIF
2459      DM_BCAST_MACRO(dumc0)
2460 #else
2461          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2462 #endif
2463          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_pm25i)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2464 #ifdef DM_PARALLEL
2465      IF (wrf_dm_on_monitor()) THEN
2466          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2467      ENDIF
2468      DM_BCAST_MACRO(dumc0)
2469 #else
2470          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2471 #endif
2472          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_pm25j)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2473 #ifdef DM_PARALLEL
2474      IF (wrf_dm_on_monitor()) THEN
2475          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2476      ENDIF
2477      DM_BCAST_MACRO(dumc0)
2478 #else
2479          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2480 #endif
2481          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_so4i)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2482 #ifdef DM_PARALLEL
2483      IF (wrf_dm_on_monitor()) THEN
2484          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2485      ENDIF
2486      DM_BCAST_MACRO(dumc0)
2487 #else
2488          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2489 #endif
2490          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_so4j)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2491 #ifdef DM_PARALLEL
2492      IF (wrf_dm_on_monitor()) THEN
2493          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2494      ENDIF
2495      DM_BCAST_MACRO(dumc0)
2496 #else
2497          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2498 #endif
2499          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_no3i)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2500 #ifdef DM_PARALLEL
2501      IF (wrf_dm_on_monitor()) THEN
2502          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2503      ENDIF
2504      DM_BCAST_MACRO(dumc0)
2505 #else
2506          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2507 #endif
2508          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_no3j)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2510 !  AQMEII
2511      IF (inew_nei .eq. 1) THEN
2512 #ifdef DM_PARALLEL
2513      IF (wrf_dm_on_monitor()) THEN
2514          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2515      ENDIF
2516      DM_BCAST_MACRO(dumc0)
2517 #else
2518          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2519 #endif
2520          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_naai)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2522 #ifdef DM_PARALLEL
2523      IF (wrf_dm_on_monitor()) THEN
2524          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2525      ENDIF
2526      DM_BCAST_MACRO(dumc0)
2527 #else
2528          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2529 #endif
2530          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_naaj)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2531      ENDIF
2533 #ifdef DM_PARALLEL
2534      IF (wrf_dm_on_monitor()) THEN
2535          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2536      ENDIF
2537      DM_BCAST_MACRO(dumc0)
2538 #else
2539          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2540 #endif
2541          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_orgi)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2542 #ifdef DM_PARALLEL
2543      IF (wrf_dm_on_monitor()) THEN
2544          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2545      ENDIF
2546      DM_BCAST_MACRO(dumc0)
2547 #else
2548          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2549 #endif
2550          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_orgj)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2551 #ifdef DM_PARALLEL
2552      IF (wrf_dm_on_monitor()) THEN
2553          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2554      ENDIF
2555      DM_BCAST_MACRO(dumc0)
2556 #else
2557          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2558 #endif
2559          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_eci)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2561 #ifdef DM_PARALLEL
2562      IF (wrf_dm_on_monitor()) THEN
2563          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2564      ENDIF
2565      DM_BCAST_MACRO(dumc0)
2566 #else
2567          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2568 #endif
2569          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_ecj)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2571 #ifdef DM_PARALLEL
2572      IF (wrf_dm_on_monitor()) THEN
2573          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2574      ENDIF
2575      DM_BCAST_MACRO(dumc0)
2576 #else
2577          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2578 #endif
2579          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe  ,p_e_pm_10)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2580 !liqy-add cl emission
2581 #ifdef DM_PARALLEL
2582      IF (wrf_dm_on_monitor()) THEN
2583          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2584      ENDIF
2585      DM_BCAST_MACRO(dumc0)
2586 #else
2587          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2588 #endif
2589          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe,p_e_hcl)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2591 #ifdef DM_PARALLEL
2592      IF (wrf_dm_on_monitor()) THEN
2593          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2594      ENDIF
2595      DM_BCAST_MACRO(dumc0)
2596 #else
2597          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2598 #endif
2599          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe,p_e_ch3cl)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2601 #ifdef DM_PARALLEL
2602      IF (wrf_dm_on_monitor()) THEN
2603          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2604      ENDIF
2605      DM_BCAST_MACRO(dumc0)
2606 #else
2607          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2608 #endif
2610          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe,p_e_cli)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2612 #ifdef DM_PARALLEL
2613      IF (wrf_dm_on_monitor()) THEN
2614          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2615      ENDIF
2616      DM_BCAST_MACRO(dumc0)
2617 #else
2618          read(91)dumc0(ids:ide-1,kds:grid%kemit,jds:jde-1)
2619 #endif
2620          grid%emis_ant(ips:ipe  ,kps:grid%kemit,jps:jpe,p_e_clj)=dumc0(ips:ipe  ,kps:grid%kemit,jps:jpe  )
2622 !liqy-20160426
2623      write(message,FMT='(A)') ' Past reading emissions '
2624      CALL  wrf_debug ( 100, message ) 
2626    ! write global atributes into wrf emissions file
2628      write(message,FMT='(A)') ' Output emissions '
2629      CALL  wrf_debug ( 100, message ) 
2630      CALL output_auxinput5 ( id1 , grid , config_flags , ierr )
2632 !   idum1 = 1
2633    END DO   ! NEMI_FRAMES loop
2636    CLOSE(91)
2637    CALL close_dataset ( id1 , config_flags , "DATASET=AUXOUTPUT5" )
2639      write(message,FMT='(A)') ' DONE WRITING TIME DEPENDENT EMISSIONS FILE'
2640      CALL  wrf_message ( message )
2642     endif  !    ERADM .or.ERADMSORG .or. ECBMZ
2644 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2645 !    NOW DO BIOGENIC EMISSIONS FILE
2647     if(CONFIG_FLAGS%BIO_EMISS_OPT == BEIS314 ) then
2649    write(message,FMT='(A)') ' READ BIOGENIC EMISSIONS '
2650    CALL  wrf_debug ( 100, message )
2652 !!!!!-------------------------------------------------------------------
2654 ! Loop over the file names
2655       DO i=1,numfil
2657 !   Remove scratch unzipped file
2658        status=system('rm -f scratem*')
2660 !   All reference emissions except NO
2661        IF(i.LE.17)THEN 
2662         onefil='BIOREF_'//             &
2663          TRIM(ADJUSTL(emfil(i)))//'.gz'
2664 !   NO reference emissions
2665        ELSE IF(i.GE.18.AND.i.LE.20)THEN 
2666         onefil='AVG_'//                &
2667          TRIM(ADJUSTL(emfil(i)))//'.gz'
2668 !   LAI
2669        ELSE
2670         onefil='LAI_'//                &
2671          TRIM(ADJUSTL(emfil(i)))//'S.gz'
2672        ENDIF
2674 !   Copy selected file to scratch
2675        status=system('cp '//TRIM(ADJUSTL(onefil))//' scratem.gz')
2677 !   Unzip scratch
2678        status=system('gunzip scratem')
2680 !   Open scratch and read into appropriate array
2681        OPEN(26,FILE='scratem',FORM='FORMATTED')
2682        IF(i.EQ. 1) then
2683 #ifdef DM_PARALLEL
2684            IF (wrf_dm_on_monitor()) THEN
2685              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2686            ENDIF
2687          DM_BCAST_MACRO(dumc1)
2688 #else
2689              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2690 #endif
2691              grid%sebio_iso(ips:ipe  ,jps:jpe  ) = dumc1(ips:ipe  ,jps:jpe  )
2692        ENDIF
2693        IF(i.EQ. 2)then
2694 #ifdef DM_PARALLEL
2695            IF (wrf_dm_on_monitor()) THEN
2696              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2697            ENDIF
2698          DM_BCAST_MACRO(dumc1)
2699 #else
2700              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2701 #endif
2702               grid%sebio_oli(ips:ipe  ,jps:jpe  ) = dumc1(ips:ipe  ,jps:jpe  )
2703        ENDIF
2704        IF(i.EQ. 3)then
2705 #ifdef DM_PARALLEL
2706            IF (wrf_dm_on_monitor()) THEN
2707              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2708            ENDIF
2709          DM_BCAST_MACRO(dumc1)
2710 #else
2711              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2712 #endif
2713               grid%sebio_api(ips:ipe  ,jps:jpe  ) = dumc1(ips:ipe  ,jps:jpe  )
2714        ENDIF
2715        IF(i.EQ. 4)then
2716 #ifdef DM_PARALLEL
2717            IF (wrf_dm_on_monitor()) THEN
2718              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2719            ENDIF
2720          DM_BCAST_MACRO(dumc1)
2721 #else
2722              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2723 #endif
2724               grid%sebio_lim(ips:ipe  ,jps:jpe  ) = dumc1(ips:ipe  ,jps:jpe  )
2725        ENDIF
2726        IF(i.EQ. 5)then
2727 #ifdef DM_PARALLEL
2728            IF (wrf_dm_on_monitor()) THEN
2729              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2730            ENDIF
2731          DM_BCAST_MACRO(dumc1)
2732 #else
2733              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2734 #endif
2735               grid%sebio_xyl(ips:ipe  ,jps:jpe  ) = dumc1(ips:ipe  ,jps:jpe  )
2736        ENDIF
2737        IF(i.EQ. 6)then
2738 #ifdef DM_PARALLEL
2739            IF (wrf_dm_on_monitor()) THEN
2740              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2741            ENDIF
2742          DM_BCAST_MACRO(dumc1)
2743 #else
2744              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2745 #endif
2746               grid%sebio_hc3(ips:ipe  ,jps:jpe  ) = dumc1(ips:ipe  ,jps:jpe  )
2747        ENDIF
2748        IF(i.EQ. 7)then
2749 #ifdef DM_PARALLEL
2750            IF (wrf_dm_on_monitor()) THEN
2751              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2752            ENDIF
2753          DM_BCAST_MACRO(dumc1)
2754 #else
2755              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2756 #endif
2757               grid%sebio_ete(ips:ipe  ,jps:jpe  ) = dumc1(ips:ipe  ,jps:jpe  )
2758        ENDIF
2759        IF(i.EQ. 8)then
2760 #ifdef DM_PARALLEL
2761            IF (wrf_dm_on_monitor()) THEN
2762              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2763            ENDIF
2764          DM_BCAST_MACRO(dumc1)
2765 #else
2766              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2767 #endif
2768               grid%sebio_olt(ips:ipe  ,jps:jpe  ) = dumc1(ips:ipe  ,jps:jpe  )
2769        ENDIF
2770        IF(i.EQ. 9)then
2771 #ifdef DM_PARALLEL
2772            IF (wrf_dm_on_monitor()) THEN
2773              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2774            ENDIF
2775          DM_BCAST_MACRO(dumc1)
2776 #else
2777              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2778 #endif
2779               grid%sebio_ket(ips:ipe  ,jps:jpe  ) = dumc1(ips:ipe  ,jps:jpe  )
2780        ENDIF
2781        IF(i.EQ.10)then
2782 #ifdef DM_PARALLEL
2783            IF (wrf_dm_on_monitor()) THEN
2784              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2785            ENDIF
2786          DM_BCAST_MACRO(dumc1)
2787 #else
2788              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2789 #endif
2790               grid%sebio_ald(ips:ipe  ,jps:jpe  ) = dumc1(ips:ipe  ,jps:jpe  )
2791        ENDIF
2792        IF(i.EQ.11)then
2793 #ifdef DM_PARALLEL
2794            IF (wrf_dm_on_monitor()) THEN
2795              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2796            ENDIF
2797          DM_BCAST_MACRO(dumc1)
2798 #else
2799              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2800 #endif
2801               grid%sebio_hcho(ips:ipe  ,jps:jpe  ) = dumc1(ips:ipe  ,jps:jpe  )
2802        ENDIF
2803        IF(i.EQ.12)then
2804 #ifdef DM_PARALLEL
2805            IF (wrf_dm_on_monitor()) THEN
2806              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2807            ENDIF
2808          DM_BCAST_MACRO(dumc1)
2809 #else
2810              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2811 #endif
2812               grid%sebio_eth(ips:ipe  ,jps:jpe  ) = dumc1(ips:ipe  ,jps:jpe  )
2813        ENDIF
2814        IF(i.EQ.13)then
2815 #ifdef DM_PARALLEL
2816            IF (wrf_dm_on_monitor()) THEN
2817              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2818            ENDIF
2819          DM_BCAST_MACRO(dumc1)
2820 #else
2821              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2822 #endif
2823               grid%sebio_ora2(ips:ipe  ,jps:jpe  ) = dumc1(ips:ipe  ,jps:jpe  )
2824        ENDIF
2825        IF(i.EQ.14)then
2826 #ifdef DM_PARALLEL
2827            IF (wrf_dm_on_monitor()) THEN
2828              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2829            ENDIF
2830          DM_BCAST_MACRO(dumc1)
2831 #else
2832              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2833 #endif
2834               grid%sebio_co(ips:ipe  ,jps:jpe  ) = dumc1(ips:ipe  ,jps:jpe  )
2835        ENDIF
2837        IF(i.EQ.15)then
2838 #ifdef DM_PARALLEL
2839            IF (wrf_dm_on_monitor()) THEN
2840              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2841            ENDIF
2842          DM_BCAST_MACRO(dumc1)
2843 #else
2844              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2845 #endif
2846               grid%sebio_nr(ips:ipe  ,jps:jpe  ) = dumc1(ips:ipe  ,jps:jpe  )
2847        ENDIF
2849 ! SESQ and MBO are added
2850        IF(i.EQ.16)then
2851 #ifdef DM_PARALLEL
2852            IF (wrf_dm_on_monitor()) THEN
2853              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2854            ENDIF
2855          DM_BCAST_MACRO(dumc1)
2856 #else
2857              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2858 #endif
2859               grid%sebio_sesq(ips:ipe  ,jps:jpe  ) = dumc1(ips:ipe  ,jps:jpe  )
2860        ENDIF
2862        IF(i.EQ.17)then
2863 #ifdef DM_PARALLEL
2864            IF (wrf_dm_on_monitor()) THEN
2865              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2866        ENDIF
2867          DM_BCAST_MACRO(dumc1)
2868 #else
2869          READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2870 #endif
2871               grid%sebio_mbo(ips:ipe  ,jps:jpe  ) = dumc1(ips:ipe  ,jps:jpe  )
2872        ENDIF
2874        IF(i.EQ.18)then
2875 #ifdef DM_PARALLEL
2876            IF (wrf_dm_on_monitor()) THEN
2877              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2878            ENDIF
2879          DM_BCAST_MACRO(dumc1)
2880 #else
2881              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2882 #endif
2883               grid%noag_grow(ips:ipe  ,jps:jpe  ) = dumc1(ips:ipe  ,jps:jpe  )
2884        ENDIF
2886        IF(i.EQ.19)then
2887 #ifdef DM_PARALLEL
2888            IF (wrf_dm_on_monitor()) THEN
2889              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2890            ENDIF
2891          DM_BCAST_MACRO(dumc1)
2892 #else
2893              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2894 #endif
2895               grid%noag_nongrow(ips:ipe  ,jps:jpe  ) = dumc1(ips:ipe  ,jps:jpe  )
2896        ENDIF
2898        IF(i.EQ.20)then
2899 #ifdef DM_PARALLEL
2900            IF (wrf_dm_on_monitor()) THEN
2901              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2902            ENDIF
2903          DM_BCAST_MACRO(dumc1)
2904 #else
2905              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2906 #endif
2907               grid%nononag(ips:ipe  ,jps:jpe  ) = dumc1(ips:ipe  ,jps:jpe  )
2908        ENDIF
2910        IF(i.EQ.21)then
2911 #ifdef DM_PARALLEL
2912            IF (wrf_dm_on_monitor()) THEN
2913              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2914            ENDIF
2915          DM_BCAST_MACRO(dumc1)
2916 #else
2917              READ(26,'(12E9.2)') dumc1(ids:ide-1,jds:jde-1)
2918 #endif
2919               grid%slai(ips:ipe  ,jps:jpe  ) = dumc1(ips:ipe  ,jps:jpe  )
2920        ENDIF
2921        CLOSE(26)
2923       ENDDO
2925    write(message,FMT='(A)') ' PAST READ BIOGENIC EMISSIONS '
2926    CALL  wrf_debug ( 100, message )
2928    write(message,FMT='(A)') ' OPEN BIOGENIC EMISSIONS WRF file'
2929    CALL  wrf_debug ( 100, message )
2931    CALL construct_filename1( inpname , 'wrfbiochemi' , grid%id , 2 )
2932    CALL open_w_dataset ( id1, TRIM(inpname) , grid , config_flags , output_auxinput6 , "DATASET=AUXINPUT6", ierr )
2933    write(message,FMT='(A,A)') ' BIOGENIC EMISSIONS file name: ',TRIM(inpname)
2934    CALL  wrf_message ( message )
2936    IF ( ierr .NE. 0 ) THEN
2937      CALL wrf_error_fatal( 'convert_emiss: error opening wrfchem emissions file for writing' )
2938    ENDIF
2940    write(message,FMT='(A)') ' WRITE BIOGENIC EMISSIONS WRF file '
2941    CALL  wrf_debug ( 100, message )
2943    CALL output_auxinput6 ( id1 , grid , config_flags , ierr )
2945    CALL close_dataset ( id1 , config_flags , "DATASET=AUXOUTPUT6" )
2947     endif  !    BIO_EMIS_OPT = BEIS314
2948 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2950     DEALLOCATE ( dumc0 )
2951     DEALLOCATE ( dumc1 )
2953    CALL med_shutdown_io ( grid , config_flags )
2955    CALL wrf_debug ( 0 , ' EMISSIONS CONVERSION : end of program ')
2957    CALL wrf_shutdown
2959    CALL WRFU_Finalize( rc=rc )
2961 END PROGRAM  convert_emissions