!dis !dis    Open Source License/Disclaimer, Forecast Systems Laboratory
!dis    NOAA/OAR/FSL, 325 Broadway Boulder, CO 80305
!dis
!dis    This software is distributed under the Open Source Definition,
!dis    which may be found at http://www.opensource.org/osd.html.
!dis
!dis    In particular, redistribution and use in source and binary forms,
!dis    with or without modification, are permitted provided that the
!dis    following conditions are met:
!dis
!dis    - Redistributions of source code must retain this notice, this
!dis    list of conditions and the following disclaimer.
!dis
!dis    - Redistributions in binary form must provide access to this
!dis    notice, this list of conditions and the following disclaimer, and
!dis    the underlying source code.
!dis
!dis    - All modifications to this software must be clearly documented,
!dis    and are solely the responsibility of the agent making the
!dis    modifications.
!dis
!dis    - If significant modifications or enhancements are made to this
!dis    software, the FSL Software Policy Manager
!dis    (softwaremgr@fsl.noaa.gov) should be notified.
!dis
!dis    THIS SOFTWARE AND ITS DOCUMENTATION ARE IN THE PUBLIC DOMAIN
!dis    AND ARE FURNISHED "AS IS."  THE AUTHORS, THE UNITED STATES
!dis    GOVERNMENT, ITS INSTRUMENTALITIES, OFFICERS, EMPLOYEES, AND
!dis    AGENTS MAKE NO WARRANTY, EXPRESS OR IMPLIED, AS TO THE USEFULNESS
!dis    OF THE SOFTWARE AND DOCUMENTATION FOR ANY PURPOSE.  THEY ASSUME
!dis    NO RESPONSIBILITY (1) FOR THE USE OF THE SOFTWARE AND
!dis    DOCUMENTATION; OR (2) TO PROVIDE TECHNICAL SUPPORT TO USERS.
!dis
!dis

!WRF:PACKAGE:IO

     MODULE EMISSIONS_TRACER

!
! Modified from version 2.0 of the emissions standard initialization routine. This
!  program is for use with the chemistry code in WRF V3
!
! This program allows users to specify their own emissions data.
!
! compile with:
!  pgf90 -w -byteswapio -Mfree -Mlfs emiss_v03_tutorial.F
!
!  ifort -FR -convert big_endian emiss_v03_tutorial.F 
!
!  gfortran -ffree-form -fconvert=big-endian emiss_v03_tutorial.F
!or
!
!  mpif90 -axP -free -convert big_endian emiss_v03_tutorial.F
!-----------------------------------------------------------------------
!
! - Output emissions data dimensions (user specified)
!
     PARAMETER(IX2=39,JX2=39,KX=19)
     PARAMETER(NRADM=30)
! 
     CHARACTER (len= 9), DIMENSION(NRADM)     ::  ENAME

     INTEGER                                  ::  I, J, K, N

     REAL, DIMENSION(IX2,KX,JX2,NRADM)   :: EM3RD
     REAL, DIMENSION(IX2,KX,JX2)         :: EM3RS
!
!  STARTHR                0 for starting at 00z , 12 for starting at 12z
!  ENDHR                  ending hour (I choose 23z as 00z is the same as 24z)
!
     INTEGER    :: starthr = 00
     INTEGER    :: endhr = 23
!
! Names of emission variables
!
     DATA ENAME /    &
      'e_so2 ','e_no  ','e_ald ','e_hcho','e_ora2',                     &
      'e_nh3 ','e_hc3 ','e_hc5 ','e_hc8 ',                              &
      'e_eth ','e_co  ','e_ol2 ','e_olt ','e_oli ','e_tol ','e_xyl ',   &
      'e_ket ','e_csl ','e_iso ','e_pm25i','e_pm25j',                   &
      'e_so4i','e_so4j','e_no3i','e_no3j','e_orgi','e_orgj','e_eci',    &
      'e_ecj','e_pm10'/

     CONTAINS

     SUBROUTINE  TR2RADM2
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

! Open output files, 7 = print and log, 19 = unformatted wrf output
     OPEN(19,FILE='wrfem_00to12Z',FORM='UNFORMATTED')
     WRITE(19)NRADM
     WRITE(19)ename
     LDEV=17
     OPEN(LDEV,FILE='tr2radm2.outp')
     L1P=LNBLNK(POINDIR)

! Loop over 24 hours
     DO IHR=starthr,endhr
!
! Specify the tracer emissions for each field on your WRF grid
!
        DO N=1,NRADM

          DO J=1,JX2
          DO K=1,KX
          DO I=1,IX2
            EM3RD(I,K,J,N)= 0.
          ENDDO
          ENDDO
          ENDDO

! File size too big - split emissions files in half; 0-12Z , 12-23Z

         IF(IHR.EQ.13)THEN
           CLOSE(19)
           OPEN(19,FILE='wrfem_12to24Z',FORM='UNFORMATTED')
           WRITE(19)NRADM
           WRITE(19)ename
         ENDIF

         WRITE(19)IHR

!         Write out individual 3-D emission arrays to unformatted file

         DO I=1,IX2
         DO K=1,KX
         DO J=1,JX2
           EM3RS(I,K,J)=EM3RD(I,K,J,N)
         ENDDO
         ENDDO
         ENDDO
         WRITE(19)EM3RS

       ENDDO  ! end of N=1,NRADM loop for writes

     END DO      ! END IHR LOOP

     CLOSE(LDEV)
     CLOSE(19)
     END SUBROUTINE  TR2RADM2
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     END MODULE EMISSIONS_TRACER
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

     PROGRAM EMISS_TEST

     USE EMISSIONS_TRACER
     IMPLICIT NONE

     CALL  TR2RADM2

     END PROGRAM EMISS_TEST
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

