LCOV - code coverage report
Current view: | top level - hemco/HEMCO/src/Extensions - hcox_megan_mod.F90 (source / functions) |  |  | Hit | Total | Coverage
Test: | coverage.info |  | Lines: | 0 | 1651 | 0.0 %
Date: | 2024-12-17 17:57:11 |  | Functions: | 0 | 22 | 0.0 %

              Line data    Source code
           1             : !------------------------------------------------------------------------------
           2             : !                   Harmonized Emissions Component (HEMCO)                    !
           3             : !------------------------------------------------------------------------------
           4             : !BOP
           5             : !
           6             : ! !MODULE: hcox_megan_mod.F90
           7             : !
           8             : ! !DESCRIPTION: Module HCOX\_Megan\_Mod contains variables and routines
           9             : !  specifying the algorithms that control the MEGAN inventory of biogenic
          10             : !  emissions (as implemented into the GEOS-Chem model).
          11             : !\\
          12             : !\\
          13             : ! This is a HEMCO extension module that uses many of the HEMCO core
          14             : ! utilities.
          15             : !\\
          16             : !\\
          17             : ! MEGAN calculates gamma activity factor based upon temperature and
          18             : ! radiation information from the past. In the original GEOS-Chem
          19             : ! code, the initial 10-d averages were explicitly calculated during
          20             : ! initialization of MEGAN. This is not feasible in an ESMF environment,
          21             : ! and the following restart variables can now be provided through the
          22             : ! HEMCO configuration file:
          23             : ! \begin{itemize}
          24             : ! \item T\_DAVG: long-term historical temperature
          25             : ! \item PARDR\_DAVG: long-term historical direct radiation
          26             : ! \item PARDF\_DAVG: long-term historical diffuse radiation
          27             : ! \item T\_PREVDAY: short-term historical temperature
          28             : ! \end{itemize}
          29             : ! These variables are automatically searched for on the first call of
          30             : ! the run call. If not defined, default values will be used. The values
          31             : ! of T\_DAVG, T\_PREVDAY, PARDR\_DAVG, and PARDF\_DAVG are continuously
          32             : ! updated at the end of the run sequence, e.g. they represent the
          33             : ! instantaneous running average. The e-folding times to be used when
          34             : ! calculating the short=term and long-term running averages are defined
          35             : ! as module parameter below (parameter TAU\_HOURS and TAU\_DAYS).
          36             : !\\
          37             : !\\
          38             : ! A similar procedure is also applied to the leaf area index variables.
          39             : ! The original GEOS-Chem MEGAN code used three LAI variables: current month
          40             : ! LAI (LAI\_CM), previous month LAI (LAI\_PM), and instantaneous LAI (LAI),
          41             : ! which was a daily interpolation of LAI\_CM and next month' LAI, (LAI\_NM).
          42             : ! The HEMCO implementation uses only the instantaneous LAI, assuming it is
          43             : ! updated every day. The short term historical LAI is kept in memory and
          44             : ! used to determine the LAI change over time (used to calculate the gamma
          45             : ! leaf age). It is also updated on every time step.
          46             : ! For the first simulation day, the previous' day LAI is taken from the
          47             : ! restart file (field LAI\_PREVDAY). If no restart variable is defined, a
          48             : ! LAI change of zero is assumed (ckeller, 10/9/2014).
          49             : !\\
          50             : !\\
          51             : ! !References:
          52             : !
          53             : !  \begin{itemize}
          54             : !  \item Guenther, A., et al., \emph{The Model of Emissions of Gases and
          55             : !        Aerosols from Nature version 2.1 (MEGAN2.1): an extended and updated
          56             : !        framework for modeling biogenic emissions}, \underline{Geosci. Model
          57             : !        Dev.}, \textbf{5}, 1471-1792, 2012.
          58             : !  \item Guenther, A., et al., \emph{A global model of natural volatile
          59             : !        organic compound emissions}, \underline{J.Geophys. Res.},
          60             : !        \textbf{100}, 8873-8892, 1995.
          61             : !  \item Wang, Y., D. J. Jacob, and J. A. Logan, \emph{Global simulation of
          62             : !        tropospheric O3-Nox-hydrocarbon chemistry: 1. Model formulation},
          63             : !        \underline{J. Geophys. Res.}, \textbf{103}, D9, 10713-10726, 1998.
          64             : !  \item Guenther, A., B. Baugh, G. Brasseur, J. Greenberg, P. Harley, L.
          65             : !        Klinger, D. Serca, and L. Vierling, \emph{Isoprene emission estimates
          66             : !        and uncertanties for the Central African EXPRESSO study domain},
          67             : !        \underline{J. Geophys. Res.}, \textbf{104}, 30,625-30,639, 1999.
          68             : !  \item Guenther, A. C., T. Pierce, B. Lamb, P. Harley, and R. Fall,
          69             : !        \emph{Natural emissions of non-methane volatile organic compounds,
          70             : !        carbon monoxide, and oxides of nitrogen from North America},
          71             : !        \underline{Atmos. Environ.}, \textbf{34}, 2205-2230, 2000.
          72             : !  \item Guenther, A., and C. Wiedinmyer, \emph{User's guide to Model of
          73             : !        Emissions of Gases and Aerosols from Nature}. http://cdp.ucar.edu.
          74             : !        (Nov. 3, 2004)
          75             : !  \item Guenther, A., \emph{AEF for methyl butenol}, personal commucation.
          76             : !        (Nov, 2004)
          77             : !  \item Sakulyanontvittaya, T., T. Duhl, C. Wiedinmyer, D. Helmig, S.
          78             : !        Matsunaga, M. Potosnak, J. Milford, and A. Guenther, \emph{Monoterpene
          79             : !        and sesquiterpene emission estimates for the United States},
          80             : !        \underline{Environ. Sci. Technol}, \textbf{42}, 1623-1629, 2008.
          81             : !  \end{itemize}
          82             : !
          83             : ! !INTERFACE:
          84             : !
          85             : MODULE HCOX_MEGAN_MOD
          86             : !
          87             : ! !USES:
          88             : !
          89             :   USE HCO_ERROR_MOD
          90             :   USE HCO_DIAGN_MOD
          91             :   USE HCOX_State_MOD,    ONLY : Ext_State
          92             :   USE HCO_STATE_MOD,     ONLY : HCO_STATE
          93             :
          94             :   IMPLICIT NONE
          95             :   PRIVATE
          96             : !
          97             : ! !PUBLIC MEMBER FUNCTIONS:
          98             : !
          99             :   PUBLIC  :: HCOX_Megan_Init
         100             :   PUBLIC  :: HCOX_Megan_Run
         101             :   PUBLIC  :: HCOX_Megan_Final
         102             : !
         103             : ! !PRIVATE MEMBER FUNCTIONS:
         104             : !
         105             :   PRIVATE :: GET_MEGAN_EMISSIONS  ! dbm, new MEGAN driver routine
         106             :                                   ! for all compounds (6/21/2012)
         107             :   PRIVATE :: GET_MEGAN_PARAMS
         108             :   PRIVATE :: GET_MEGAN_AEF
         109             :   PRIVATE :: GET_GAMMA_PAR_PCEEA
         110             :   PRIVATE :: GET_GAMMA_T_LI
         111             :   PRIVATE :: GET_GAMMA_T_LD
         112             :   PRIVATE :: GET_GAMMA_LAI
         113             :   PRIVATE :: GET_GAMMA_AGE
         114             :   PRIVATE :: GET_GAMMA_SM
         115             :   PRIVATE :: CALC_NORM_FAC
         116             :   PRIVATE :: SOLAR_ANGLE
         117             :   PRIVATE :: FILL_RESTART_VARS
         118             :   PRIVATE :: CALC_AEF
         119             :   PRIVATE :: GET_GAMMA_CO2  ! (Tai, Jan 2013)
         120             : !
         121             : ! !REVISION HISTORY:
         122             : !  (1 ) Original code (biogen_em_mod.f) by Dorian Abbot (6/2003).  Updated to
         123             : !        latest algorithm and modified for the standard code by May Fu
         124             : !        (11/2004).
         125             : !  See https://github.com/geoschem/hemco for complete history
         126             : !EOP
         127             : !------------------------------------------------------------------------------
         128             : !BOC
         129             : !
         130             : ! !MODULE VARIABLES:
         131             : !
         132             :   TYPE :: MyInst
         133             :      INTEGER                 :: Instance
         134             :      INTEGER                 :: ExtNr        ! Extension number for MEGAN
         135             :      REAL(hp)                :: ISOP_SCALING ! Isoprene emissions scaling
         136             :      REAL(hp)                :: GLOBCO2      ! Global CO2 conc (ppmv)
         137             :      REAL(hp)                :: ISOPTOSOAP   ! SOAP Emission factor
         138             :      REAL(hp)                :: MONOTOSOAP   ! SOAP Emission factor
         139             :      REAL(hp)                :: OTHRTOSOAP   ! SOAP Emission factor
         140             :      REAL(hp)                :: ISOPTOSOAS   ! Direct SOA Emission factor
         141             :      REAL(hp)                :: MONOTOSOAS   ! Direct SOA Emission factor
         142             :      REAL(hp)                :: OTHRTOSOAS   ! Direct SOA Emission factor
         143             :      LOGICAL                 :: LISOPCO2     ! Include CO2 inhibition of ISOP?
         144             :      LOGICAL                 :: NORMLAI      ! Normalize LAI by PFT?
         145             :      LOGICAL                 :: OFFLINE_BIOGENICVOC ! Use offline emiss?
         146             :
         147             :      ! Physical parameter
         148             :      REAL(hp)                :: D2RAD  ! Degrees to radians
         149             :      REAL(hp)                :: RAD2D  ! Radians to degrees
         150             :
         151             :      ! HEMCO species IDs
         152             :      INTEGER                 :: IDTISOP
         153             :      INTEGER                 :: IDTACET
         154             :      INTEGER                 :: IDTPRPE
         155             :      INTEGER                 :: IDTC2H4
         156             :      INTEGER                 :: IDTALD2
         157             :      INTEGER                 :: IDTMOH
         158             :      INTEGER                 :: IDTEOH
         159             :      INTEGER                 :: IDTLIMO
         160             :      INTEGER                 :: IDTMTPA
         161             :      INTEGER                 :: IDTMTPO
         162             :      INTEGER                 :: IDTSESQ
         163             :      INTEGER                 :: IDTSOAP
         164             :      INTEGER                 :: IDTSOAS
         165             :
         166             :      ! Pointers to annual emission factor arrays.
         167             :      ! These fields are obtained from ext. data (from config file)
         168             :      ! These arrays represent the base emission values in kg/m2/s
         169             :      ! that will be scaled based upon meteorological conditions.
         170             :      REAL(hp), POINTER       :: AEF_ISOP(:,:)
         171             :      REAL(hp), POINTER       :: AEF_MBOX(:,:)
         172             :      REAL(hp), POINTER       :: AEF_BPIN(:,:)
         173             :      REAL(hp), POINTER       :: AEF_CARE(:,:)
         174             :      REAL(hp), POINTER       :: AEF_LIMO(:,:)
         175             :      REAL(hp), POINTER       :: AEF_OCIM(:,:)
         176             :      REAL(hp), POINTER       :: AEF_SABI(:,:)
         177             :
         178             :      ! Annual emission factors arrays
         179             :      ! These fields are not read from file, but are computed in CALC_AEF
         180             :      REAL(hp), POINTER       :: AEF_APIN(:,:)              ! Alpha-pinene
         181             :      REAL(hp), POINTER       :: AEF_MYRC(:,:)              ! Myrcene
         182             :      REAL(hp), POINTER       :: AEF_OMON(:,:)              ! Other monoterpenes
         183             :      REAL(hp), POINTER       :: AEF_ACET(:,:)              ! Acetone
         184             :      REAL(hp), POINTER       :: AEF_MOH(:,:)               ! Methanol
         185             :      REAL(hp), POINTER       :: AEF_EOH(:,:)               ! Ethanol
         186             :      REAL(hp), POINTER       :: AEF_CH2O(:,:)              ! Formaldehyde
         187             :      REAL(hp), POINTER       :: AEF_ALD2(:,:)              ! Acetaldehyde
         188             :      REAL(hp), POINTER       :: AEF_FAXX(:,:)              ! Formic acid
         189             :      REAL(hp), POINTER       :: AEF_AAXX(:,:)              ! Acetic acid
         190             :      REAL(hp), POINTER       :: AEF_C2H4(:,:)              ! Ethene
         191             :      REAL(hp), POINTER       :: AEF_TOLU(:,:)              ! Toluene
         192             :      REAL(hp), POINTER       :: AEF_HCNX(:,:)              ! HCN
         193             :      REAL(hp), POINTER       :: AEF_PRPE(:,:)              ! >= C3 alkenes
         194             :      REAL(hp), POINTER       :: AEF_FARN(:,:)              ! a-Farnesene
         195             :      REAL(hp), POINTER       :: AEF_BCAR(:,:)              ! b-Caryophyllene
         196             :      REAL(hp), POINTER       :: AEF_OSQT(:,:)              ! Other sesquiterp.
         197             :
         198             :      ! Emission arrays (kg/m2/s)
         199             :      REAL(hp), POINTER       :: FLUXISOP(:,:)
         200             :      REAL(hp), POINTER       :: FLUXMONO(:,:)
         201             :      REAL(hp), POINTER       :: FLUXACET(:,:)
         202             :      REAL(hp), POINTER       :: FLUXPRPE(:,:)
         203             :      REAL(hp), POINTER       :: FLUXC2H4(:,:)
         204             :      REAL(hp), POINTER       :: FLUXLIMO(:,:)
         205             :      REAL(hp), POINTER       :: FLUXMTPA(:,:)
         206             :      REAL(hp), POINTER       :: FLUXMTPO(:,:)
         207             :      REAL(hp), POINTER       :: FLUXSESQ(:,:)
         208             :      REAL(hp), POINTER       :: FLUXSOAP(:,:)
         209             :      REAL(hp), POINTER       :: FLUXSOAS(:,:)
         210             :      REAL(hp), POINTER       :: FLUXALD2(:,:)
         211             :      REAL(hp), POINTER       :: FLUXMOH(:,:)
         212             :      REAL(hp), POINTER       :: FLUXEOH(:,:)
         213             :
         214             :      ! Emission arrays for use in diagnostics (kg/m2/s)
         215             :      REAL(sp), POINTER       :: FLUXACETmb(:,:)
         216             :      REAL(sp), POINTER       :: FLUXACETbg(:,:)
         217             :      REAL(sp), POINTER       :: FLUXAPIN(:,:)
         218             :      REAL(sp), POINTER       :: FLUXBPIN(:,:)
         219             :      REAL(sp), POINTER       :: FLUXSABI(:,:)
         220             :      REAL(sp), POINTER       :: FLUXMYRC(:,:)
         221             :      REAL(sp), POINTER       :: FLUXCARE(:,:)
         222             :      REAL(sp), POINTER       :: FLUXOCIM(:,:)
         223             :      REAL(sp), POINTER       :: FLUXOMON(:,:)
         224             :      REAL(sp), POINTER       :: FLUXFARN(:,:)
         225             :      REAL(sp), POINTER       :: FLUXBCAR(:,:)
         226             :      REAL(sp), POINTER       :: FLUXOSQT(:,:)
         227             :      REAL(sp), POINTER       :: FLUXMBOX(:,:)
         228             :      REAL(sp), POINTER       :: FLUXFAXX(:,:)
         229             :      REAL(sp), POINTER       :: FLUXAAXX(:,:)
         230             :
         231             :      ! Normalization factor
         232             :      REAL(hp), POINTER       :: NORM_FAC(:)
         233             :
         234             :      ! Restart variables
         235             :      REAL(sp), POINTER       :: T_LASTXDAYS    (:,:) ! Avg. temp  of last X days
         236             :      REAL(sp), POINTER       :: T_LAST24H      (:,:) ! Avg. temp  of last 24 hrs
         237             :      REAL(sp), POINTER       :: PARDF_LASTXDAYS(:,:) ! Avg. PARDF of last X days
         238             :      REAL(sp), POINTER       :: PARDR_LASTXDAYS(:,:) ! Avg. PARDR of last X days
         239             :      REAL(sp), POINTER       :: LAI_PREVDAY(:,:)     ! LAI of prev. day
         240             :
         241             :      ! Array for PFT
         242             :      REAL(hp), POINTER       :: ARRAY_16(:,:,:)
         243             :
         244             :      ! Days between mid-months (updated by HEMCO clock)
         245             :      INTEGER                 :: DAYS_BTW_M
         246             :
         247             :      ! Input data suffix
         248             :      CHARACTER(LEN=255)      :: SUFFIX
         249             :
         250             :      TYPE(MyInst), POINTER   :: NextInst => NULL()
         251             :   END TYPE MyInst
         252             :
         253             :   ! Pointer to all instances
         254             :   TYPE(MyInst), POINTER      :: AllInst => NULL()
         255             :
         256             :   ! Scalars
         257             :   ! e-folding time to be applied to long-term past conditions (in days)
         258             :   REAL(hp), PARAMETER  :: TAU_DAYS  = 5.0_hp
         259             :
         260             :   ! e-folding time to be applied to short-term past conditions (in hours)
         261             :   REAL(hp), PARAMETER  :: TAU_HOURS = 12.0_hp
         262             :
         263             :   ! W/m2 -> umol/m2/s
         264             :   REAL(hp), PARAMETER  :: WM2_TO_UMOLM2S = 4.766_hp
         265             :
         266             :   ! Maximum LAI value [cm2/cm2]
         267             :   REAL(hp), PARAMETER  :: LAI_MAX = 6.0_hp
         268             :
         269             : CONTAINS
         270             : !EOC
         271             : !------------------------------------------------------------------------------
         272             : !                   Harmonized Emissions Component (HEMCO)                    !
         273             : !------------------------------------------------------------------------------
         274             : !BOP
         275             : !
         276             : ! !IROUTINE: HCOX_Megan_Run
         277             : !
         278             : ! !DESCRIPTION: Subroutine HCOX\_MEGAN\_Run is the driver routine for
         279             : ! the MEGAN model within the new emissions structure.
         280             : ! Note that all diagnostics are commented since those are still written
         281             : ! as part of the old emission structure.
         282             : !\\
         283             : !\\
         284             : ! !INTERFACE:
         285             : !
         286           0 :   SUBROUTINE HCOX_Megan_Run( ExtState, HcoState, RC )
         287             : !
         288             : ! !USES:
         289             : !
         290             :     USE HCO_FLUXARR_MOD,     ONLY : HCO_EmisAdd
         291             :     USE HCO_CLOCK_MOD,       ONLY : HcoClock_First
         292             :     USE HCO_CLOCK_MOD,       ONLY : HcoClock_Rewind
         293             :     USE HCO_CLOCK_MOD,       ONLY : HcoClock_NewHour
         294             :     USE HCO_CLOCK_MOD,       ONLY : HcoClock_NewDay
         295             :     USE HCO_Restart_Mod,     ONLY : HCO_RestartWrite
         296             : !
         297             : ! !INPUT PARAMETERS:
         298             : !
         299             :     TYPE(Ext_State), POINTER       :: ExtState
         300             :     TYPE(HCO_State), POINTER       :: HcoState
         301             : !
         302             : ! !INPUT/OUTPUT PARAMETERS:
         303             : !
         304             :     INTEGER,         INTENT(INOUT) :: RC
         305             : !
         306             : ! !REVISION HISTORY:
         307             : !  05 Aug 2013 - C. Keller   - Initial version
         308             : !  See https://github.com/geoschem/hemco for complete history
         309             : !EOP
         310             : !------------------------------------------------------------------------------
         311             : !BOC
         312             : !
         313             : ! !LOCAL VARIABLES:
         314             : !
         315             :     INTEGER             :: I, J
         316             :     REAL(hp)            :: EMIS_ISOP, EMIS_MBOX, EMIS_APIN, EMIS_BPIN
         317             :     REAL(hp)            :: EMIS_LIMO, EMIS_SABI, EMIS_MYRC, EMIS_CARE
         318             :     REAL(hp)            :: EMIS_OCIM, EMIS_OMON, EMIS_MONO, EMIS_ALD2
         319             :     REAL(hp)            :: EMIS_MOH,  EMIS_EOH,  EMIS_FAXX, EMIS_AAXX
         320             :     REAL(hp)            :: EMIS_ACET, EMIS_PRPE, EMIS_C2H4
         321             :     REAL(hp)            :: EMIS_FARN, EMIS_BCAR, EMIS_OSQT
         322             :     REAL(hp)            :: EMIS_OTHR
         323             :     REAL(hp)            :: X, Y, TMP
         324             :     REAL(hp)            :: TS_EMIS
         325             :     REAL(hp)            :: DNEWFRAC
         326             :     REAL(hp)            :: DOLDFRAC
         327             :     REAL(hp)            :: HNEWFRAC
         328             :     REAL(hp)            :: HOLDFRAC
         329             :     LOGICAL             :: ERR
         330             :     LOGICAL             :: FIRST, IsNewHour, IsNewDay
         331             :
         332             :     ! For diagnostics
         333           0 :     REAL(hp), POINTER   :: Arr2D(:,:)
         334             :     CHARACTER(LEN=63)   :: DiagnName
         335             :     CHARACTER(LEN=255)  :: MSG, LOC
         336             :
         337             :     ! Conversion factors for acetone calculations
         338             :     REAL(hp), PARAMETER   :: YIELD_MO   = 0.116_hp
         339             :     REAL(hp), PARAMETER   :: MONO_SCALE = 0.89_hp
         340             :     REAL(hp), PARAMETER   :: MB_SCALE1  = 0.6_hp
         341             :     REAL(hp), PARAMETER   :: MB_SCALE2  = 0.76_hp
         342             :     REAL(hp), PARAMETER   :: MBOX_MW_g  = 86.13_hp
         343             :
         344             :     ! Conversion facor for SOAP/SOAS calculations
         345             :     REAL(hp), PARAMETER   :: MONOtoC    = ( 12.0 * 10 ) / 136.26
         346             :
         347             :     TYPE(MyInst), POINTER :: Inst
         348             :
         349             :     !=================================================================
         350             :     ! HCOX_Megan_Run begins here!
         351             :     !=================================================================
         352           0 :     LOC = 'HCOX_Megan_Run (HCOX_MEGAN_MOD.F90)'
         353             :
         354             :     ! Enter
         355           0 :     CALL HCO_ENTER( HcoState%Config%Err, LOC, RC )
         356           0 :     IF ( RC /= HCO_SUCCESS ) THEN
         357           0 :         CALL HCO_ERROR( 'ERROR 0', RC, THISLOC=LOC )
         358           0 :         RETURN
         359             :     ENDIF
         360           0 :     ERR = .FALSE.
         361             :
         362             :     ! Nullify
         363           0 :     Arr2d => NULL()
         364           0 :     Inst  => NULL()
         365             :
         366             :     ! Get instance
         367           0 :     CALL InstGet ( ExtState%Megan, Inst, RC )
         368           0 :     IF ( RC /= HCO_SUCCESS ) THEN
         369           0 :        WRITE(MSG,*) 'Cannot find Megan instance Nr. ', ExtState%Megan
         370           0 :        CALL HCO_ERROR(MSG,RC)
         371           0 :        RETURN
         372             :     ENDIF
         373             :
         374             :     ! Time information
         375           0 :     FIRST     = HcoClock_First  ( HcoState%Clock, .TRUE. )
         376             :     IsNewHour = HcoClock_NewHour( HcoState%Clock, .TRUE. )
         377             :     IsNewDay  = HcoClock_NewDay ( HcoState%Clock, .TRUE. )
         378             :
         379             :     ! Initialize flux arrays
         380           0 :     Inst%FLUXISOP   = 0.0_hp
         381           0 :     Inst%FLUXMBOX   = 0.0_hp
         382           0 :     Inst%FLUXAPIN   = 0.0_hp
         383           0 :     Inst%FLUXBPIN   = 0.0_hp
         384           0 :     Inst%FLUXSABI   = 0.0_hp
         385           0 :     Inst%FLUXMYRC   = 0.0_hp
         386           0 :     Inst%FLUXCARE   = 0.0_hp
         387           0 :     Inst%FLUXOCIM   = 0.0_hp
         388           0 :     Inst%FLUXOMON   = 0.0_hp
         389           0 :     Inst%FLUXMONO   = 0.0_hp
         390           0 :     Inst%FLUXACET   = 0.0_hp
         391           0 :     Inst%FLUXALD2   = 0.0_hp
         392           0 :     Inst%FLUXMOH    = 0.0_hp
         393           0 :     Inst%FLUXEOH    = 0.0_hp
         394           0 :     Inst%FLUXFAXX   = 0.0_hp
         395           0 :     Inst%FLUXAAXX   = 0.0_hp
         396           0 :     Inst%FLUXACETmb = 0.0_sp
         397           0 :     Inst%FLUXACETbg = 0.0_sp
         398           0 :     Inst%FLUXPRPE   = 0.0_sp
         399           0 :     Inst%FLUXC2H4   = 0.0_sp
         400           0 :     Inst%FLUXLIMO   = 0.0_sp
         401           0 :     Inst%FLUXMTPA   = 0.0_sp
         402           0 :     Inst%FLUXMTPO   = 0.0_sp
         403           0 :     Inst%FLUXFARN   = 0.0_sp
         404           0 :     Inst%FLUXBCAR   = 0.0_sp
         405           0 :     Inst%FLUXOSQT   = 0.0_sp
         406           0 :     Inst%FLUXSESQ   = 0.0_sp
         407           0 :     Inst%FLUXSOAP   = 0.0_sp
         408           0 :     Inst%FLUXSOAS   = 0.0_sp
         409             :
         410             : #if defined( ESMF_ ) || defined( MODEL_GEOS )
         411             :
         412             :     !----------------------------------------------------------------
         413             :     ! %%%%% ESMF environment: execute these on every call  %%%%%
         414             :     ! %%%%% because this will fill from the External State %%%%%
         415             :     !----------------------------------------------------------------
         416             :
         417             :     ! Generate annual emission factors for MEGAN inventory
         418             :     CALL CALC_AEF( HcoState, ExtState, Inst, RC )
         419             :     IF ( RC /= HCO_SUCCESS ) THEN
         420             :        MSG = 'Error encountered in MEGAN routine CALC_AEF!'
         421             :        CALL HCO_ERROR( MSG, RC )
         422             :        RETURN
         423             :     ENDIF
         424             :
         425             :     ! Calculate normalization factor (dbm, 11/2012)
         426             :     CALL CALC_NORM_FAC( Inst, RC )
         427             :     IF ( RC /= HCO_SUCCESS ) THEN
         428             :        MSG = 'Error encountered in MEGAN routine CALC_NORM_FAC!'
         429             :        CALL HCO_ERROR( MSG, RC )
         430             :        RETURN
         431             :     ENDIF
         432             :
         433             :     ! Fill restart variables.
         434             :     CALL FILL_RESTART_VARS( HcoState, ExtState, Inst, RC )
         435             :     IF ( RC /= HCO_SUCCESS ) THEN
         436             :        MSG = 'Error encountered in MEGAN routine FILL_RESTART_VARS!'
         437             :        CALL HCO_ERROR( MSG, RC )
         438             :        RETURN
         439             :     ENDIF
         440             :
         441             : #else
         442             :
         443             :     !----------------------------------------------------------------
         444             :     ! %%%%% Standard environment: Execute these only once     %%%%%
         445             :     ! %%%%% to avoid constantly overwriting restart variables %%%%%
         446             :     !----------------------------------------------------------------
         447           0 :     IF ( FIRST ) THEN
         448             :
         449             :        ! Generate annual emission factors for MEGAN inventory
         450           0 :        CALL CALC_AEF( HcoState, ExtState, Inst, RC )
         451           0 :        IF ( RC /= HCO_SUCCESS ) THEN
         452           0 :           MSG = 'Error encountered in MEGAN routine CALC_AEF!'
         453           0 :           CALL HCO_ERROR( MSG, RC )
         454           0 :           RETURN
         455             :        ENDIF
         456             :
         457             :        ! Calculate normalization factor (dbm, 11/2012)
         458           0 :        CALL CALC_NORM_FAC( Inst, RC )
         459           0 :        IF ( RC /= HCO_SUCCESS ) THEN
         460           0 :           MSG = 'Error encountered in MEGAN routine CALC_NORM_FAC!'
         461           0 :           CALL HCO_ERROR( MSG, RC )
         462           0 :           RETURN
         463             :        ENDIF
         464             :
         465             :        ! Fill restart variables
         466           0 :        CALL FILL_RESTART_VARS( HcoState, ExtState, Inst, RC )
         467           0 :        IF ( RC /= HCO_SUCCESS ) THEN
         468           0 :           MSG = 'Error encountered in MEGAN routine FILL_RESTART_VARS!'
         469           0 :           CALL HCO_ERROR( MSG, RC )
         470           0 :           RETURN
         471             :        ENDIF
         472             :     ENDIF
         473             :
         474             : #endif
         475             :
         476             :     ! Set to 1 day since we know that LAI is updated every day.
         477           0 :     Inst%DAYS_BTW_M = 1
         478             :
         479             :     ! Calculate weights for running means of historic variables
         480             :     ! DNEWFRAC and DOLDFRAC are the weights given to the current
         481             :     ! and existing value, respectively, when updating running means
         482             :     ! over the last X days. HNEWFRAC and HOLDFRAC are the same but
         483             :     ! for the 24H means. (ckeller, 11/05/2015)
         484           0 :     TS_EMIS  = HcoState%TS_EMIS
         485           0 :     DNEWFRAC = TS_EMIS / ( TAU_DAYS * 24.0_hp * 3600.0_hp )
         486           0 :     DOLDFRAC = 1.0_hp - DNEWFRAC
         487           0 :     HNEWFRAC = TS_EMIS / ( TAU_HOURS * 3600.0_hp )
         488           0 :     HOLDFRAC = 1.0_hp - HNEWFRAC
         489             :
         490             :     !$OMP PARALLEL DO       &
         491             :     !$OMP DEFAULT( SHARED ) &
         492             :     !$OMP PRIVATE( I, J,      EMIS_ISOP, EMIS_MBOX, EMIS_APIN, EMIS_BPIN   ) &
         493             :     !$OMP PRIVATE( EMIS_LIMO, EMIS_SABI, EMIS_MYRC, EMIS_CARE, EMIS_OCIM   ) &
         494             :     !$OMP PRIVATE( EMIS_OMON, EMIS_MONO, EMIS_MOH,  EMIS_EOH,  EMIS_FAXX   ) &
         495             :     !$OMP PRIVATE( EMIS_AAXX, EMIS_ACET, EMIS_PRPE, EMIS_C2H4, TMP         ) &
         496             :     !$OMP PRIVATE( EMIS_FARN, EMIS_BCAR, EMIS_OSQT, EMIS_ALD2, EMIS_OTHR   ) &
         497             :     !$OMP PRIVATE( X, Y, RC )
         498             :
         499             :     !-----------------------------------------------------------------
         500             :     ! Loop over all grid boxes
         501             :     !-----------------------------------------------------------------
         502           0 :     DO J = 1, HcoState%NY
         503           0 :     DO I = 1, HcoState%NX
         504             :
         505             :        ! Zero biogenic species
         506           0 :        EMIS_ISOP  = 0.0_hp
         507           0 :        EMIS_MBOX  = 0.0_hp
         508           0 :        EMIS_APIN  = 0.0_hp
         509           0 :        EMIS_BPIN  = 0.0_hp
         510           0 :        EMIS_LIMO  = 0.0_hp
         511           0 :        EMIS_SABI  = 0.0_hp
         512           0 :        EMIS_MYRC  = 0.0_hp
         513           0 :        EMIS_CARE  = 0.0_hp
         514           0 :        EMIS_OCIM  = 0.0_hp
         515           0 :        EMIS_OMON  = 0.0_hp
         516           0 :        EMIS_MONO  = 0.0_hp
         517           0 :        EMIS_OTHR  = 0.0_hp
         518           0 :        EMIS_ALD2  = 0.0_hp
         519           0 :        EMIS_MOH   = 0.0_hp
         520           0 :        EMIS_EOH   = 0.0_hp
         521           0 :        EMIS_FAXX  = 0.0_hp
         522           0 :        EMIS_AAXX  = 0.0_hp
         523           0 :        EMIS_ACET  = 0.0_hp
         524           0 :        EMIS_PRPE  = 0.0_hp
         525           0 :        EMIS_C2H4  = 0.0_hp
         526           0 :        EMIS_FARN  = 0.0_hp
         527           0 :        EMIS_BCAR  = 0.0_hp
         528           0 :        EMIS_OSQT  = 0.0_hp
         529             :
         530             :        !--------------------------------------------------------------
         531             :        ! Calculate VOC emissions
         532             :        !
         533             :        ! The GET_EMIS*_MEGAN calls now use the annual scale factors
         534             :        ! imported through the HEMCO list, which are already in units
         535             :        ! of kg/m2/s. ckeller, 14/01/25.
         536             :        !
         537             :        ! Updated to new MEGAN routine (dbm, 12/2012)
         538             :        !--------------------------------------------------------------
         539             :
         540             :        !--------------------------------------------------------------------
         541             :        ! MEGAN Isoprene
         542             :        !--------------------------------------------------------------------
         543             :
         544             :        ! Isoprene [kg/m2/s]
         545             :        CALL GET_MEGAN_EMISSIONS( HcoState, ExtState, Inst, &
         546           0 :                                  I, J, 'ISOP', EMIS_ISOP, RC )
         547           0 :        IF ( RC /= HCO_SUCCESS ) THEN
         548             :           CALL HCO_ERROR( &
         549           0 :                           'GET_MEGAN_EMISSIONS_ISOP', RC )
         550           0 :           ERR = .TRUE.
         551           0 :           EXIT
         552             :        ENDIF
         553             :
         554             :        !FP_ISOP (6/2009)
         555           0 :        EMIS_ISOP = Inst%ISOP_SCALING * EMIS_ISOP
         556             :
         557             :        ! Write isoprene emissions into tracer tendency array
         558           0 :        IF ( Inst%IDTISOP > 0 ) THEN
         559           0 :           Inst%FLUXISOP(I,J) = EMIS_ISOP
         560             :        ENDIF
         561             :
         562             :        ! Biogenic emissions of SOA and SOA-Precursor from isopene
         563             :        ! NOTE: These emission factors appear to be based on emissions
         564             :        !  in kgC/m2/s. Convert from kg/m2/s to kgC/m2/s.
         565           0 :        IF ( (Inst%IDTISOP>0) .AND. (Inst%IDTSOAP>0) ) THEN
         566           0 :           Inst%FLUXSOAP(I,J) = Inst%FLUXSOAP(I,J) + &
         567           0 :                ( EMIS_ISOP * MONOtoC ) * Inst%ISOPTOSOAP
         568             :        ENDIF
         569           0 :        IF ( (Inst%IDTISOP>0) .AND. (Inst%IDTSOAS>0) ) THEN
         570           0 :           Inst%FLUXSOAS(I,J) = Inst%FLUXSOAS(I,J) + &
         571           0 :                ( EMIS_ISOP * MONOtoC ) * Inst%ISOPTOSOAS
         572             :        ENDIF
         573             :
         574             :        !--------------------------------------------------------------------
         575             :        ! MEGAN monoterpenes
         576             :        !--------------------------------------------------------------------
         577             :
         578             :        ! ---------------------------------------------------
         579             :        ! Alpha Pinene emissions
         580             :        CALL GET_MEGAN_EMISSIONS( HcoState, ExtState, &
         581           0 :                                  Inst, I, J, 'APIN', EMIS_APIN, RC)
         582           0 :        IF ( RC /= HCO_SUCCESS ) THEN
         583             :           CALL HCO_ERROR( &
         584           0 :                           'GET_MEGAN_EMISSIONS_APIN', RC )
         585           0 :           ERR = .TRUE.
         586           0 :           EXIT
         587             :        ENDIF
         588           0 :        Inst%FLUXAPIN(I,J) = EMIS_APIN
         589             :
         590             :        ! ---------------------------------------------------
         591             :        ! Beta Pinene emissions
         592             :        CALL GET_MEGAN_EMISSIONS( HcoState, ExtState, &
         593           0 :                                  Inst, I, J, 'BPIN', EMIS_BPIN, RC)
         594           0 :        IF ( RC /= HCO_SUCCESS ) THEN
         595             :           CALL HCO_ERROR( &
         596           0 :                           'GET_MEGAN_EMISSIONS_BPIN', RC )
         597           0 :           ERR = .TRUE.
         598           0 :           EXIT
         599             :        ENDIF
         600           0 :        Inst%FLUXBPIN(I,J) = EMIS_BPIN
         601             :
         602             :        ! ---------------------------------------------------
         603             :        ! Limonene emissions
         604             :        CALL GET_MEGAN_EMISSIONS( HcoState, ExtState, &
         605           0 :                                  Inst, I, J, 'LIMO', EMIS_LIMO, RC)
         606           0 :        IF ( RC /= HCO_SUCCESS ) THEN
         607             :           CALL HCO_ERROR( &
         608           0 :                           'GET_MEGAN_EMISSIONS_LIMO', RC )
         609           0 :           ERR = .TRUE.
         610           0 :           EXIT
         611             :        ENDIF
         612           0 :        Inst%FLUXLIMO(I,J) = EMIS_LIMO
         613             :
         614             :        ! ---------------------------------------------------
         615             :        ! Sabinene emissions
         616             :        CALL GET_MEGAN_EMISSIONS( HcoState, ExtState, &
         617           0 :                                  Inst, I, J, 'SABI', EMIS_SABI, RC)
         618           0 :        IF ( RC /= HCO_SUCCESS ) THEN
         619             :           CALL HCO_ERROR( &
         620           0 :                           'GET_MEGAN_EMISSIONS_SABI', RC )
         621           0 :           ERR = .TRUE.
         622           0 :           EXIT
         623             :        ENDIF
         624           0 :        Inst%FLUXSABI(I,J) = EMIS_SABI
         625             :
         626             :        ! ---------------------------------------------------
         627             :        ! Mycrene emissions
         628             :        CALL GET_MEGAN_EMISSIONS( HcoState, ExtState, &
         629           0 :                                  Inst, I, J, 'MYRC', EMIS_MYRC, RC)
         630           0 :        IF ( RC /= HCO_SUCCESS ) THEN
         631             :           CALL HCO_ERROR( &
         632           0 :                           'GET_MEGAN_EMISSIONS_MYRC', RC )
         633           0 :           ERR = .TRUE.
         634           0 :           EXIT
         635             :        ENDIF
         636           0 :        Inst%FLUXMYRC(I,J) = EMIS_MYRC
         637             :
         638             :        ! ---------------------------------------------------
         639             :        ! 3-Carene emissions
         640             :        CALL GET_MEGAN_EMISSIONS( HcoState, ExtState, &
         641           0 :                                  Inst, I, J, 'CARE', EMIS_CARE, RC)
         642           0 :        IF ( RC /= HCO_SUCCESS ) THEN
         643             :           CALL HCO_ERROR( &
         644           0 :                           'GET_MEGAN_EMISSIONS_CARE', RC )
         645           0 :           ERR = .TRUE.
         646           0 :           EXIT
         647             :        ENDIF
         648           0 :        Inst%FLUXCARE(I,J) = EMIS_CARE
         649             :
         650             :        ! ---------------------------------------------------
         651             :        ! Ocimene emissions
         652             :        CALL GET_MEGAN_EMISSIONS( HcoState, ExtState, &
         653           0 :                                  Inst, I, J, 'OCIM', EMIS_OCIM, RC)
         654           0 :        IF ( RC /= HCO_SUCCESS ) THEN
         655             :           CALL HCO_ERROR( &
         656           0 :                           'GET_MEGAN_EMISSIONS_OCIM', RC )
         657           0 :           ERR = .TRUE.
         658           0 :           EXIT
         659             :        ENDIF
         660           0 :        Inst%FLUXOCIM(I,J) = EMIS_OCIM
         661             :
         662             :        ! ---------------------------------------------------
         663             :        ! Other monoterpenes
         664             :        ! (added 12/2012; dbm)
         665             :        CALL GET_MEGAN_EMISSIONS( HcoState, ExtState, &
         666           0 :                                  Inst, I, J, 'OMON', EMIS_OMON, RC)
         667           0 :        IF ( RC /= HCO_SUCCESS ) THEN
         668             :           CALL HCO_ERROR( &
         669           0 :                           'GET_MEGAN_EMISSIONS_OMON', RC )
         670           0 :           ERR = .TRUE.
         671           0 :           EXIT
         672             :        ENDIF
         673           0 :        Inst%FLUXOMON(I,J) = EMIS_OMON
         674             :
         675             :        ! ---------------------------------------------------
         676             :        ! Total monoterpenes = sum of individual
         677             :        ! dbm, now add other lumped monoterpenes (11/2012)
         678             :        EMIS_MONO = EMIS_APIN + EMIS_BPIN + EMIS_LIMO + EMIS_SABI + &
         679           0 :                    EMIS_MYRC + EMIS_CARE + EMIS_OCIM + EMIS_OMON
         680             :
         681             :        ! Add to tracer tendency array [kg/m2/s]
         682           0 :        Inst%FLUXMONO(I,J) = EMIS_MONO
         683             :
         684             :        !--------------------------------------------------------------------
         685             :        ! MEGAN Acetaldehyde
         686             :        !--------------------------------------------------------------------
         687           0 :        IF ( Inst%IDTALD2 > 0 ) THEN
         688             :           CALL GET_MEGAN_EMISSIONS( HcoState, ExtState, &
         689           0 :                                     Inst, I, J, 'ALD2', EMIS_ALD2, RC)
         690           0 :           IF ( RC /= HCO_SUCCESS ) THEN
         691             :              CALL HCO_ERROR( &
         692           0 :                              'GET_MEGAN_EMISSIONS_ALD2', RC )
         693           0 :              ERR = .TRUE.
         694           0 :              EXIT
         695             :           ENDIF
         696             :
         697             :           ! Add to tracer tendency array [kg/m2/s]
         698           0 :           Inst%FLUXALD2(I,J) = EMIS_ALD2
         699             :        ENDIF
         700             :
         701             :        ! ---------------------------------------------------
         702             :        ! MEGAN Methanol
         703           0 :        IF ( Inst%IDTMOH > 0 ) THEN
         704             :           CALL GET_MEGAN_EMISSIONS( HcoState, ExtState, &
         705           0 :                                     Inst, I, J, 'MOH', EMIS_MOH, RC)
         706           0 :           IF ( RC /= HCO_SUCCESS ) THEN
         707             :              CALL HCO_ERROR(  &
         708           0 :                              'GET_MEGAN_EMISSIONS_MOH', RC )
         709           0 :              ERR = .TRUE.
         710           0 :              EXIT
         711             :           ENDIF
         712             :
         713             :           ! Add to tracer tendency array [kg/m2/s]
         714           0 :           Inst%FLUXMOH(I,J) = EMIS_MOH
         715             :        ENDIF
         716             :
         717             :        ! ---------------------------------------------------
         718             :        ! MEGAN Ethanol
         719           0 :        IF ( Inst%IDTEOH > 0 ) THEN
         720             :           CALL GET_MEGAN_EMISSIONS( HcoState, ExtState, &
         721           0 :                                     Inst, I, J, 'EOH', EMIS_EOH, RC)
         722           0 :           IF ( RC /= HCO_SUCCESS ) THEN
         723             :              CALL HCO_ERROR( &
         724           0 :                              'GET_MEGAN_EMISSIONS_EOH', RC )
         725           0 :              ERR = .TRUE.
         726           0 :              EXIT
         727             :           ENDIF
         728             :
         729             :           ! Add to tracer tendency array [kg/m2/s]
         730           0 :           Inst%FLUXEOH(I,J) = EMIS_EOH
         731             :        ENDIF
         732             :
         733             :        !--------------------------------------------------------------------
         734             :        ! Other MEGAN biogenics
         735             :        ! Calls included here for future incorporation or
         736             :        ! specialized simulations. (dbm, 12/2012)
         737             :        !--------------------------------------------------------------------
         738             :
         739             :        ! ---------------------------------------------------
         740             :        ! Methyl butenol
         741             :        CALL GET_MEGAN_EMISSIONS( HcoState, ExtState, &
         742           0 :                                  Inst, I, J, 'MBOX', EMIS_MBOX, RC)
         743           0 :        IF ( RC /= HCO_SUCCESS ) THEN
         744             :           CALL HCO_ERROR( &
         745           0 :                           'GET_MEGAN_EMISSIONS_MBOX', RC )
         746           0 :           ERR = .TRUE.
         747           0 :           EXIT
         748             :        ENDIF
         749           0 :        Inst%FLUXMBOX(I,J) = EMIS_MBOX
         750             :
         751             :        ! ---------------------------------------------------
         752             :        ! MEGAN Formic acid
         753             :        CALL GET_MEGAN_EMISSIONS( HcoState, ExtState, &
         754           0 :                                  Inst, I, J, 'FAXX', EMIS_FAXX, RC )
         755           0 :        IF ( RC /= HCO_SUCCESS ) THEN
         756             :           CALL HCO_ERROR( &
         757           0 :                           'GET_MEGAN_EMISSIONS_FAXX', RC )
         758           0 :           ERR = .TRUE.
         759           0 :           EXIT
         760             :        ENDIF
         761           0 :        Inst%FLUXFAXX(I,J) = EMIS_FAXX
         762             :
         763             :        ! ---------------------------------------------------
         764             :        ! MEGAN Acetic acid
         765             :        CALL GET_MEGAN_EMISSIONS( HcoState, ExtState, &
         766           0 :                                  Inst, I, J, 'AAXX', EMIS_AAXX, RC )
         767           0 :        IF ( RC /= HCO_SUCCESS ) THEN
         768             :           CALL HCO_ERROR( &
         769           0 :                           'GET_MEGAN_EMISSIONS_AAXX', RC )
         770           0 :           ERR = .TRUE.
         771           0 :           EXIT
         772             :        ENDIF
         773           0 :        Inst%FLUXAAXX(I,J) = EMIS_AAXX
         774             :
         775             :        !--------------------------------------------------------------------
         776             :        ! Biogenic acetone emissions
         777             :        !--------------------------------------------------------------------
         778           0 :        IF ( Inst%IDTACET > 0 ) THEN
         779             :
         780             :           !-----------------------------------------------------------------
         781             :           ! (1) BIOGENIC ACETONE FROM METHYL BUTENOL -- NORTH AMERICA
         782             :           !
         783             :           ! Methyl Butenol (a.k.a. MBO) produces acetone with a molar yield
         784             :           ! of 0.6 [Alvarado (1999)].  The biogenic source of MBO is thought
         785             :           ! to be restricted to North America.  According to Guenther (1999)
         786             :           ! North america emits 3.2Tg-C of MBO, producing 1.15 Tg-C of
         787             :           ! Acetone in North America.
         788             :           !
         789             :           !
         790             :           ! Lon and lat of grid box (I,J) in degrees
         791           0 :           X = HcoState%Grid%XMID%Val( I, J )
         792           0 :           IF ( X >= 180.0_hp ) X = X - 360.0_hp
         793           0 :           Y = HcoState%Grid%YMID%Val( I, J )
         794             :
         795             :           ! Methyl butenol is emitted only in North America, where
         796             :           ! ( -167.5 <= lon <= -52.5 ) and ( 16.0 <= lat <= 72.0 )
         797           0 :           IF ( ( X >= -167.5_hp .and. X <= -52.5_hp ) .AND. &
         798             :                ( Y >=   16.0_hp .and. Y <=  72.0_hp ) ) THEN
         799             :              !  Apply yield from MBO to get [kg ACET/m2/s]
         800           0 :              TMP = EMIS_MBOX * MB_SCALE1
         801           0 :              TMP = TMP * HcoState%Spc(Inst%IDTACET)%MW_g / MBOX_MW_g
         802             :
         803             :              ! Scale to a posteriori source from Jacob et al 2001 (bdf, 9/5/01)
         804           0 :              Inst%FLUXACETmb(I,J) = TMP * MB_SCALE2
         805             :           ENDIF
         806             :
         807             :           !-----------------------------------------------------------------
         808             :           ! (3) BIOGENIC ACETONE -- DIRECT EMISSION
         809             :           !
         810             :           ! Direct Emission now includes emission
         811             :           ! from grasses and emission from dry leaf matter
         812             :           CALL GET_MEGAN_EMISSIONS( HcoState, ExtState, &
         813           0 :                                     Inst, I, J, 'ACET', EMIS_ACET, RC)
         814           0 :           IF ( RC /= HCO_SUCCESS ) THEN
         815             :              CALL HCO_ERROR( &
         816           0 :                              'GET_MEGAN_EMISSIONS_ACET', RC )
         817           0 :              ERR = .TRUE.
         818           0 :              EXIT
         819             :           ENDIF
         820             :
         821             :           ! Write to array
         822           0 :           Inst%FLUXACETbg(I,J) = EMIS_ACET
         823             :
         824             :        ENDIF
         825             :
         826             :        !--------------------------------------------------------------------
         827             :        ! Biogenic emissions of SOA and SOA-Precursor from monoterpenes
         828             :        !
         829             :        ! NOTE: These emission factors appear to be based on emissions
         830             :        !  in kgC/m2/s. Convert from kg/m2/s to kgC/m2/s.
         831             :        !--------------------------------------------------------------------
         832           0 :        IF ( Inst%IDTSOAP>0 ) THEN
         833           0 :           Inst%FLUXSOAP(I,J) = Inst%FLUXSOAP(I,J) + &
         834           0 :                ( EMIS_MONO * MONOtoC ) * Inst%MONOTOSOAP
         835             :        ENDIF
         836           0 :        IF ( Inst%IDTSOAS>0 ) THEN
         837           0 :           Inst%FLUXSOAS(I,J) = Inst%FLUXSOAS(I,J) + &
         838           0 :                ( EMIS_MONO * MONOtoC ) * Inst%MONOTOSOAS
         839             :        ENDIF
         840             :
         841             :        !--------------------------------------------------------------------
         842             :        ! Biogenic emissions of PRPE
         843             :        !
         844             :        ! Now uses MEGAN2.1 (dbm, 12/2012)
         845             :        !--------------------------------------------------------------------
         846           0 :        IF ( Inst%IDTPRPE > 0 ) THEN
         847             :           CALL GET_MEGAN_EMISSIONS( HcoState, ExtState, &
         848           0 :                                     Inst, I, J, 'PRPE', EMIS_PRPE, RC)
         849           0 :           IF ( RC /= HCO_SUCCESS ) THEN
         850             :              CALL HCO_ERROR( &
         851           0 :                              'GET_MEGAN_EMISSIONS_PRPE', RC )
         852           0 :              ERR = .TRUE.
         853           0 :              EXIT
         854             :           ENDIF
         855             :
         856             :           ! Add to tracer tendency array [kg/m2/s]
         857           0 :           Inst%FLUXPRPE(I,J) = EMIS_PRPE
         858             :
         859             :        ENDIF
         860             :
         861             :        !--------------------------------------------------------------------
         862             :        ! Biogenic emissions of ethene (C2H4)
         863             :        !
         864             :        ! Now uses MEGAN2.1 (dbm, 12/2012)
         865             :        !--------------------------------------------------------------------
         866           0 :        IF ( Inst%IDTC2H4 > 0 ) THEN
         867             :           CALL GET_MEGAN_EMISSIONS( HcoState, ExtState, &
         868           0 :                                     Inst, I, J, 'C2H4', EMIS_C2H4, RC)
         869           0 :           IF ( RC /= HCO_SUCCESS ) THEN
         870             :              CALL HCO_ERROR( &
         871           0 :                              'GET_MEGAN_EMISSIONS_C2H4', RC )
         872           0 :              ERR = .TRUE.
         873           0 :              EXIT
         874             :           ENDIF
         875             :
         876             :           ! Add to tracer tendency array [kg/m2/s]
         877           0 :           Inst%FLUXC2H4(I,J) = EMIS_C2H4
         878             :        ENDIF
         879             :
         880             :        ! ----------------------------------------------------------------
         881             :        ! The new MEGAN implementation has speciated information
         882             :        ! (hotp 3/7/10)
         883             :        ! as of 7/28/10 for year 2000 GEOS4 2x2.5 in Tg/yr:
         884             :        ! ------------------------------
         885             :        ! HC Class  New MEGAN  Old MEGAN
         886             :        ! --------  ---------  ---------
         887             :        ! MTPA        73         86
         888             :        ! LIMO        10         25
         889             :        ! MTPO        33          3.2+38
         890             :        ! SESQ        13         15
         891             :        !           -----      --------
         892             :        ! TOTAL      129        167.2
         893             :        ! see Pye et al. 2010 ACP
         894             :        !
         895             :        ! Monoterpene lumping:
         896             :        ! GEOS-Chem   MEGAN
         897             :        ! =========   ==========================================
         898             :        ! MTPA        a-pinene   (APIN), b-pinene  (BPIN),
         899             :        !             sabinene   (SABI), carene    (CARE)
         900             :        ! LIMO        limonene   (LIMO)
         901             :        ! MTPO        myrcene    (MYRC), ocimene   (OCIM),
         902             :        !             other mono (OMON)
         903             :        ! SESQ        farnesene  (FARN), b-caryoph (BCAR),
         904             :        !             other sesq (OSQT)
         905             :        ! =========   ==========================================
         906             :
         907             :        !--------------------------------------------------------------
         908             :        ! MEGAN MTPA
         909             :        !--------------------------------------------------------------
         910             :        ! MTPA=a-,b-pinene,sabinene,carene (hotp 5/20/10)
         911           0 :        IF ( Inst%IDTMTPA > 0 ) THEN
         912           0 :           Inst%FLUXMTPA(I,J) = EMIS_APIN + EMIS_BPIN + EMIS_SABI + EMIS_CARE
         913             :        ENDIF
         914             :
         915             :        !--------------------------------------------------------------
         916             :        ! MEGAN Limonene
         917             :        !--------------------------------------------------------------
         918             :        ! [kg/m2/s]
         919           0 :        IF ( Inst%IDTLIMO > 0 ) THEN
         920           0 :           Inst%FLUXLIMO(I,J) = EMIS_LIMO
         921             :        ENDIF
         922             :
         923             :        !--------------------------------------------------------------
         924             :        ! MEGAN MTPO
         925             :        !--------------------------------------------------------------
         926             :        ! MTPO is all other monoterpenes (MEGAN categories:
         927             :        ! myrcene, ocimene, OMON) (hotp 5/20/10)
         928             :        ! All other monoterpenes (mostly camphene, linalool,
         929             :        ! terpinolene, terpinolene, phellandrene) (hotp 3/10/10)
         930             :        ! 14-18% of OMTP is terpinene and terpinolene
         931           0 :        IF ( Inst%IDTMTPO > 0 ) THEN
         932           0 :           Inst%FLUXMTPO(I,J) = EMIS_MYRC + EMIS_OCIM + EMIS_OMON
         933             :        ENDIF
         934             :
         935             :        !--------------------------------------------------------------
         936             :        ! MEGAN sesquiterpenes
         937             :        !--------------------------------------------------------------
         938             :
         939             :        ! ---------------------------------------------------
         940             :        ! a-Farnesene
         941             :        CALL GET_MEGAN_EMISSIONS( HcoState, ExtState, &
         942           0 :                                  Inst, I, J, 'FARN', EMIS_FARN, RC )
         943           0 :        IF ( RC /= HCO_SUCCESS ) THEN
         944             :           CALL HCO_ERROR( &
         945           0 :                           'GET_MEGAN_EMISSIONS_FARN', RC )
         946           0 :           ERR = .TRUE.
         947           0 :           EXIT
         948             :        ENDIF
         949           0 :        Inst%FLUXFARN(I,J) = EMIS_FARN
         950             :
         951             :        ! ---------------------------------------------------
         952             :        ! b_Caryophyllene
         953             :        CALL GET_MEGAN_EMISSIONS( HcoState, ExtState, &
         954           0 :                                  Inst, I, J, 'BCAR', EMIS_BCAR, RC )
         955           0 :        IF ( RC /= HCO_SUCCESS ) THEN
         956             :           CALL HCO_ERROR( &
         957           0 :                           'GET_MEGAN_EMISSIONS_BCAR', RC )
         958           0 :           ERR = .TRUE.
         959           0 :           EXIT
         960             :        ENDIF
         961           0 :        Inst%FLUXBCAR(I,J) = EMIS_BCAR
         962             :
         963             :        ! ---------------------------------------------------
         964             :        ! Other sesquiterpene
         965             :        CALL GET_MEGAN_EMISSIONS( HcoState, ExtState, &
         966           0 :                                  Inst, I, J, 'OSQT', EMIS_OSQT, RC )
         967           0 :        IF ( RC /= HCO_SUCCESS ) THEN
         968             :           CALL HCO_ERROR( &
         969           0 :                           'GET_MEGAN_EMISSIONS_OSQT', RC )
         970           0 :           ERR = .TRUE.
         971           0 :           EXIT
         972             :        ENDIF
         973           0 :        Inst%FLUXOSQT(I,J) = EMIS_OSQT
         974             :
         975             :        ! ---------------------------------------------------
         976             :        ! Total sesquiterpenes from MEGAN (hotp 3/10/10)
         977           0 :        IF ( Inst%IDTSESQ > 0 ) THEN
         978           0 :           Inst%FLUXSESQ(I,J) = EMIS_FARN + EMIS_BCAR + EMIS_OSQT
         979             :        ENDIF
         980             :
         981             :        ! Other terpenes
         982           0 :        EMIS_OTHR = EMIS_FARN + EMIS_BCAR + EMIS_OSQT
         983             :
         984             :        !--------------------------------------------------------------------
         985             :        ! Biogenic emissions of SOA and SOA-Precursor from Other terpenes
         986             :        !
         987             :        ! NOTE: These emission factors appear to be based on emissions
         988             :        !  in kgC/m2/s. Convert from kg/m2/s to kgC/m2/s.
         989             :        !--------------------------------------------------------------------
         990           0 :        IF ( Inst%IDTSOAP>0 ) THEN
         991           0 :           Inst%FLUXSOAP(I,J) = Inst%FLUXSOAP(I,J) + &
         992           0 :                ( EMIS_OTHR * MONOtoC ) * Inst%OTHRTOSOAP
         993             :        ENDIF
         994           0 :        IF ( Inst%IDTSOAS>0 ) THEN
         995           0 :           Inst%FLUXSOAS(I,J) = Inst%FLUXSOAS(I,J) + &
         996           0 :                ( EMIS_OTHR * MONOtoC ) * Inst%OTHRTOSOAS
         997             :        ENDIF
         998             :
         999             :        !-----------------------------------------------------------------
        1000             :        ! Update historical temperature / radiation values
        1001             :        !-----------------------------------------------------------------
        1002             :        ! Do this now on every time step. The arrays are simply the
        1003             :        ! the running means over the intentend time window (24 hours
        1004             :        ! and NUM_DAYS, respectively). This hugely faciliates warm
        1005             :        ! model restarts, irrespective of simulation start/end dates
        1006             :        ! and times. It also makes sure that all environmental
        1007             :        ! variables are incorporated into the time averages (e.g. if
        1008             :        ! emission time step is less than 60 minutes, all values will
        1009             :        ! be used to calculate the daily mean).
        1010             :        ! (ckeller, 11/05/2015)
        1011             :
        1012             :        ! Updated LAI of last 24 hours
        1013           0 :        Inst%LAI_PREVDAY(I,J) = ( HOLDFRAC * Inst%LAI_PREVDAY(I,J) ) + &
        1014           0 :                                ( HNEWFRAC * ExtState%LAI%Arr%Val(I,J) )
        1015             :
        1016             :        ! Updated temperature of last 24 hours
        1017           0 :        Inst%T_LAST24H(I,J) = ( HOLDFRAC * Inst%T_LAST24H(I,J) ) + &
        1018           0 :                              ( HNEWFRAC * ExtState%T2M%Arr%Val(I,J) )
        1019             :
        1020             :        ! Updated temperature of last NUM_DAYS
        1021           0 :        Inst%T_LASTXDAYS(I,J) = ( DOLDFRAC * Inst%T_LASTXDAYS(I,J) ) + &
        1022           0 :                                ( DNEWFRAC * ExtState%T2M%Arr%Val(I,J) )
        1023             :
        1024             :        ! Updated direct radiation of last NUM_DAYS
        1025           0 :        Inst%PARDR_LASTXDAYS(I,J) = ( DOLDFRAC * Inst%PARDR_LASTXDAYS(I,J) ) + &
        1026           0 :                                    ( DNEWFRAC * ExtState%PARDR%Arr%Val(I,J) )
        1027             :
        1028             :        ! Updated diffuse radiation of last NUM_DAYS
        1029           0 :        Inst%PARDF_LASTXDAYS(I,J) = ( DOLDFRAC * Inst%PARDF_LASTXDAYS(I,J) ) + &
        1030           0 :                                    ( DNEWFRAC * ExtState%PARDF%Arr%Val(I,J) )
        1031             :
        1032             :     ENDDO !I
        1033             :     ENDDO !J
        1034             :     !$OMP END PARALLEL DO
        1035             :
        1036           0 :     IF ( ERR ) THEN
        1037           0 :        RC = HCO_FAIL
        1038           0 :        RETURN
        1039             :     ENDIF
        1040             :
        1041             :     !=================================================================
        1042             :     ! PASS TO HEMCO STATE AND UPDATE DIAGNOSTICS
        1043             :     !=================================================================
        1044             :
        1045             :     ! ----------------------------------------------------------------
        1046             :     ! ISOPRENE
        1047           0 :     IF ( Inst%IDTISOP > 0 ) THEN
        1048             :
        1049             :        ! Add flux to emission array
        1050             :        CALL HCO_EmisAdd( HcoState, Inst%FLUXISOP, Inst%IDTISOP, &
        1051           0 :                          RC, ExtNr=Inst%ExtNr )
        1052           0 :        IF ( RC /= HCO_SUCCESS ) THEN
        1053             :           CALL HCO_ERROR( &
        1054           0 :                           'HCO_EmisAdd error: FLUXISOP', RC )
        1055           0 :           RETURN
        1056             :        ENDIF
        1057             :     ENDIF
        1058             :
        1059             :     ! ----------------------------------------------------------------
        1060             :     ! ACETALDEHYDE
        1061           0 :     IF ( Inst%IDTALD2 > 0 ) THEN
        1062             :
        1063             :        ! Add flux to emission array
        1064             :        CALL HCO_EmisAdd( HcoState, Inst%FLUXALD2, Inst%IDTALD2, &
        1065           0 :                          RC, ExtNr=Inst%ExtNr )
        1066           0 :        IF ( RC /= HCO_SUCCESS ) THEN
        1067             :           CALL HCO_ERROR( &
        1068           0 :                           'HCO_EmisAdd error: FLUXALD2', RC )
        1069           0 :           RETURN
        1070             :        ENDIF
        1071             :     ENDIF
        1072             :
        1073             :     ! ----------------------------------------------------------------
        1074             :     ! METHANOL
        1075           0 :     IF ( Inst%IDTMOH > 0 ) THEN
        1076             :
        1077             :        ! Add flux to emission array
        1078             :        CALL HCO_EmisAdd( HcoState, Inst%FLUXMOH, Inst%IDTMOH, &
        1079           0 :                          RC, ExtNr=Inst%ExtNr )
        1080           0 :        IF ( RC /= HCO_SUCCESS ) THEN
        1081             :           CALL HCO_ERROR( &
        1082           0 :                           'HCO_EmisAdd error: FLUXMOH', RC )
        1083           0 :           RETURN
        1084             :        ENDIF
        1085             :     ENDIF
        1086             :
        1087             :     ! ----------------------------------------------------------------
        1088             :     ! ETHANOL
        1089           0 :     IF ( Inst%IDTEOH > 0 ) THEN
        1090             :
        1091             :        ! Add flux to emission array
        1092             :        CALL HCO_EmisAdd( HcoState, Inst%FLUXEOH, Inst%IDTEOH, &
        1093           0 :                          RC, ExtNr=Inst%ExtNr )
        1094           0 :        IF ( RC /= HCO_SUCCESS ) THEN
        1095             :           CALL HCO_ERROR( &
        1096           0 :                           'HCO_EmisAdd error: FLUXEOH', RC )
        1097           0 :           RETURN
        1098             :        ENDIF
        1099             :     ENDIF
        1100             :
        1101             :     ! ----------------------------------------------------------------
        1102             :     ! ACETONE
        1103           0 :     IF ( Inst%IDTACET > 0 ) THEN
        1104             :
        1105             :        ! Add flux to emission array
        1106           0 :        Inst%FLUXACET = Inst%FLUXACETbg + Inst%FLUXACETmb
        1107             :        CALL HCO_EmisAdd( HcoState, Inst%FLUXACET, Inst%IDTACET, &
        1108           0 :                          RC, ExtNr=Inst%ExtNr )
        1109           0 :        IF ( RC /= HCO_SUCCESS ) THEN
        1110             :           CALL HCO_ERROR( &
        1111           0 :                           'HCO_EmisAdd error: FLUXACET', RC )
        1112           0 :           RETURN
        1113             :        ENDIF
        1114             :     ENDIF
        1115             :
        1116             :     ! ----------------------------------------------------------------
        1117             :     ! SOA-Precursor (SOAP)
        1118           0 :     IF (  Inst%IDTSOAP > 0 ) THEN
        1119             :
        1120             :        ! Add flux to emission array
        1121             :        CALL HCO_EmisAdd( HcoState, Inst%FLUXSOAP, Inst%IDTSOAP, &
        1122           0 :                          RC, ExtNr=Inst%ExtNr )
        1123           0 :        IF ( RC /= HCO_SUCCESS ) THEN
        1124             :           CALL HCO_ERROR( &
        1125           0 :                           'HCO_EmisAdd error: FLUXSOAP', RC )
        1126           0 :           RETURN
        1127             :        ENDIF
        1128             :
        1129             :     ENDIF
        1130             :
        1131             :     ! ----------------------------------------------------------------
        1132             :     ! SOA-Simplified (SOAS)
        1133           0 :     IF (  Inst%IDTSOAS > 0 ) THEN
        1134             :
        1135             :        ! Add flux to emission array
        1136             :        CALL HCO_EmisAdd( HcoState, Inst%FLUXSOAS, Inst%IDTSOAS, &
        1137           0 :                          RC, ExtNr=Inst%ExtNr )
        1138           0 :        IF ( RC /= HCO_SUCCESS ) THEN
        1139             :           CALL HCO_ERROR( &
        1140           0 :                           'HCO_EmisAdd error: FLUXSOAS', RC )
        1141           0 :           RETURN
        1142             :        ENDIF
        1143             :
        1144             :     ENDIF
        1145             :
        1146             :     ! ----------------------------------------------------------------
        1147             :     ! ALKENES
        1148           0 :     IF ( Inst%IDTPRPE > 0 ) THEN
        1149             :
        1150             :        ! Add flux to emission array
        1151             :        CALL HCO_EmisAdd( HcoState, Inst%FLUXPRPE, Inst%IDTPRPE, &
        1152           0 :                          RC, ExtNr=Inst%ExtNr )
        1153           0 :        IF ( RC /= HCO_SUCCESS ) THEN
        1154             :           CALL HCO_ERROR( &
        1155           0 :                           'HCO_EmisAdd error: FLUXPRPE', RC )
        1156           0 :           RETURN
        1157             :        ENDIF
        1158             :
        1159             :     ENDIF
        1160             :
        1161             :     ! ----------------------------------------------------------------
        1162             :     ! ETHENE
        1163           0 :     IF ( Inst%IDTC2H4 > 0 ) THEN
        1164             :
        1165             :        ! Add flux to emission array
        1166             :        CALL HCO_EmisAdd( HcoState, Inst%FLUXC2H4, Inst%IDTC2H4, &
        1167           0 :                          RC, ExtNr=Inst%ExtNr )
        1168           0 :        IF ( RC /= HCO_SUCCESS ) THEN
        1169             :           CALL HCO_ERROR( &
        1170           0 :                           'HCO_EmisAdd error: FLUXC2H4', RC )
        1171           0 :           RETURN
        1172             :        ENDIF
        1173             :
        1174             :     ENDIF
        1175             :
        1176             :     ! ----------------------------------------------------------------
        1177             :     ! MTPA
        1178           0 :     IF ( Inst%IDTMTPA > 0 ) THEN
        1179             :
        1180             :        ! Add flux to emission array
        1181             :        CALL HCO_EmisAdd( HcoState, Inst%FLUXMTPA, Inst%IDTMTPA, &
        1182           0 :                          RC, ExtNr=Inst%ExtNr )
        1183           0 :        IF ( RC /= HCO_SUCCESS ) THEN
        1184             :           CALL HCO_ERROR( &
        1185           0 :                           'HCO_EmisAdd error: FLUXMTPA', RC )
        1186           0 :           RETURN
        1187             :        ENDIF
        1188             :
        1189             :     ENDIF
        1190             :
        1191             :     ! ----------------------------------------------------------------
        1192             :     ! MTPO
        1193           0 :     IF ( Inst%IDTMTPO > 0 ) THEN
        1194             :
        1195             :        ! Add flux to emission array
        1196             :        CALL HCO_EmisAdd( HcoState, Inst%FLUXMTPO, Inst%IDTMTPO, &
        1197           0 :                          RC, ExtNr=Inst%ExtNr )
        1198           0 :        IF ( RC /= HCO_SUCCESS ) THEN
        1199             :           CALL HCO_ERROR( &
        1200           0 :                           'HCO_EmisAdd error: FLUXMTPO', RC )
        1201           0 :           RETURN
        1202             :        ENDIF
        1203             :
        1204             :     ENDIF
        1205             :
        1206             :     ! ----------------------------------------------------------------
        1207             :     ! LIMONENE
        1208           0 :     IF ( Inst%IDTLIMO > 0 ) THEN
        1209             :
        1210             :        ! Add flux to emission array
        1211             :        CALL HCO_EmisAdd( HcoState, Inst%FLUXLIMO, Inst%IDTLIMO, &
        1212           0 :                          RC, ExtNr=Inst%ExtNr )
        1213           0 :        IF ( RC /= HCO_SUCCESS ) THEN
        1214             :           CALL HCO_ERROR( &
        1215           0 :                           'HCO_EmisAdd error: FLUXLIMO', RC )
        1216           0 :           RETURN
        1217             :        ENDIF
        1218             :
        1219             :     ENDIF
        1220             :
        1221             :     ! ----------------------------------------------------------------
        1222             :     ! SESQ
        1223           0 :     IF ( Inst%IDTSESQ > 0 ) THEN
        1224             :
        1225             :        ! Add flux to emission array
        1226             :        CALL HCO_EmisAdd( HcoState, Inst%FLUXSESQ, Inst%IDTSESQ, &
        1227           0 :                          RC, ExtNr=Inst%ExtNr )
        1228           0 :        IF ( RC /= HCO_SUCCESS ) THEN
        1229             :           CALL HCO_ERROR( &
        1230           0 :                           'HCO_EmisAdd error: FLUXSESQ', RC )
        1231           0 :           RETURN
        1232             :        ENDIF
        1233             :
        1234             :     ENDIF
        1235             :
        1236             :     ! ----------------------------------------------------------------
        1237             :     ! Eventually copy internal values to ESMF internal state object
        1238             :     ! ----------------------------------------------------------------
        1239             :
        1240             :     ! LAI_PREVDAY
        1241             :     CALL HCO_RestartWrite( HcoState, &
        1242           0 :                            'LAI_PREVDAY', Inst%LAI_PREVDAY, RC )
        1243           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        1244           0 :         CALL HCO_ERROR( 'ERROR 1', RC, THISLOC=LOC )
        1245           0 :         RETURN
        1246             :     ENDIF
        1247             :
        1248             :     ! T_LAST24H
        1249             :     CALL HCO_RestartWrite( HcoState, &
        1250           0 :                            'T_PREVDAY',  Inst%T_LAST24H, RC )
        1251           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        1252           0 :         CALL HCO_ERROR( 'ERROR 2', RC, THISLOC=LOC )
        1253           0 :         RETURN
        1254             :     ENDIF
        1255             :
        1256             :     ! T_LASTXDAYS
        1257             :     CALL HCO_RestartWrite( HcoState, &
        1258           0 :                            'T_DAVG',     Inst%T_LASTXDAYS, RC )
        1259           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        1260           0 :         CALL HCO_ERROR( 'ERROR 3', RC, THISLOC=LOC )
        1261           0 :         RETURN
        1262             :     ENDIF
        1263             :
        1264             :     ! PARDR_LASTXDAYS
        1265             :     CALL HCO_RestartWrite( HcoState, &
        1266           0 :                            'PARDR_DAVG', Inst%PARDR_LASTXDAYS, RC )
        1267           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        1268           0 :         CALL HCO_ERROR( 'ERROR 4', RC, THISLOC=LOC )
        1269           0 :         RETURN
        1270             :     ENDIF
        1271             :
        1272             :     ! PARDF_LASTXDAYS
        1273             :     CALL HCO_RestartWrite( HcoState, &
        1274           0 :                            'PARDF_DAVG', Inst%PARDF_LASTXDAYS, RC )
        1275           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        1276           0 :         CALL HCO_ERROR( 'ERROR 5', RC, THISLOC=LOC )
        1277           0 :         RETURN
        1278             :     ENDIF
        1279             :
        1280             :     !=================================================================
        1281             :     ! ALL DONE!
        1282             :     !=================================================================
        1283             :
        1284             :     ! Cleanup
        1285           0 :     Inst => NULL()
        1286             :
        1287             :     ! Reset first-time flag
        1288           0 :     FIRST = .FALSE.
        1289             :
        1290             :     ! Return w/ success
        1291           0 :     CALL HCO_LEAVE( HcoState%Config%Err,RC )
        1292             :
        1293           0 :   END SUBROUTINE HCOX_Megan_Run
        1294             : !EOC
        1295             : !------------------------------------------------------------------------------
        1296             : !                   Harmonized Emissions Component (HEMCO)                    !
        1297             : !------------------------------------------------------------------------------
        1298             : !BOP
        1299             : !
        1300             : ! !IROUTINE: Get_Megan_Emissions
        1301             : !
        1302             : ! !DESCRIPTION: Subroutine Get\_Megan\_Emissions computes biogenic emissions in
        1303             : !  units of kg/m2/s using the MEGAN inventory. (dbm, 12/2012)
        1304             : !\\
        1305             : !\\
        1306             : ! !INTERFACE:
        1307             : !
        1308           0 :   SUBROUTINE GET_MEGAN_EMISSIONS( HcoState, ExtState, &
        1309             :                                   Inst, I, J, CMPD, MEGAN_EMIS, RC )
        1310             : !
        1311             : ! !INPUT PARAMETERS:
        1312             : !
        1313             :     TYPE(HCO_STATE),  POINTER     :: HcoState
        1314             :     TYPE(Ext_State),  POINTER     :: ExtState
        1315             :     TYPE(MyInst),     POINTER     :: Inst
        1316             :     INTEGER,          INTENT(IN)  :: I, J      ! GEOS-Chem lon & lat indices
        1317             :     CHARACTER(LEN=*), INTENT(IN)  :: CMPD      ! Compound name (dbm,6/21/2012)
        1318             : !
        1319             : ! !OUTPUT PARAMETERS:
        1320             : !
        1321             :     REAL(hp),         INTENT(OUT) :: MEGAN_EMIS ! kg/m2/s
        1322             : !
        1323             : ! !INPUT/OUTPUT PARAMETERS:
        1324             : !
        1325             :     INTEGER,          INTENT(INOUT) :: RC
        1326             : !
        1327             : ! !REMARKS:
        1328             : !  References (see above for full citations):
        1329             : !  ============================================================================
        1330             : !  (1 ) Guenther et al, 1995, 1999, 2000, 2004, 2006
        1331             : !  (2 ) Wang,    et al, 1998
        1332             : !  (3 ) Guenther et al, 2007, MEGAN v2.1 User mannual
        1333             : !  (4 ) Guenther et al, 2012 GMD MEGANv2.1 description and associated code at
        1334             : !                                http://acd.ucar.edu/~guenther/MEGAN/
        1335             : !
        1336             : ! !REVISION HISTORY:
        1337             : !  (1 ) Original code by Dorian Abbot (9/2003).  Updated to the latest
        1338             : !        algorithm and modified for the standard code by May Fu (11/20/04)
        1339             : !  See https://github.com/geoschem/hemco for complete history
        1340             : !EOP
        1341             : !------------------------------------------------------------------------------
        1342             : !BOC
        1343             : !
        1344             : ! !LOCAL VARIABLES:
        1345             : !
        1346             :     REAL(hp)            :: GAMMA_LAI
        1347             :     REAL(hp)            :: GAMMA_AGE
        1348             :     REAL(hp)            :: GAMMA_PAR
        1349             :     REAL(hp)            :: GAMMA_T_LD
        1350             :     REAL(hp)            :: GAMMA_T_LI
        1351             :     REAL(hp)            :: GAMMA_SM
        1352             :     REAL(hp)            :: GAMMA_CO2  ! (Tai, Jan 2013)
        1353             :     REAL(hp)            :: AEF
        1354             :     REAL(hp)            :: D_BTW_M
        1355             :     REAL(hp)            :: TS, SUNCOS
        1356             :     REAL(hp)            :: Q_DIR_2, Q_DIFF_2
        1357             :     REAL(hp)            :: BETA, LDF, CT1, CEO
        1358             :     REAL(hp)            :: ANEW, AGRO, AMAT, AOLD
        1359             :     REAL(hp)            :: ISOLAI, PMISOLAI, MISOLAI
        1360             :     REAL(hp)            :: PFTSUM
        1361             :     LOGICAL             :: BIDIR
        1362             :     CHARACTER(LEN=255)  :: LOC
        1363             :
        1364             :     !=================================================================
        1365             :     ! GET_MEGAN_EMISSIONS begins here!
        1366             :     !=================================================================
        1367           0 :     LOC = 'GET_MEGAN_EMISSIONS (HCOX_MEGAN_MOD.F90)'
        1368             :
        1369             :     ! Initialize parameters, gamma values, and return value
        1370           0 :     MEGAN_EMIS = 0.0_hp
        1371           0 :     GAMMA_LAI  = 0.0_hp
        1372           0 :     GAMMA_AGE  = 0.0_hp
        1373           0 :     GAMMA_T_LD = 0.0_hp
        1374           0 :     GAMMA_T_LI = 0.0_hp
        1375           0 :     GAMMA_PAR  = 0.0_hp
        1376           0 :     GAMMA_SM   = 0.0_hp
        1377           0 :     GAMMA_CO2  = 0.0_hp
        1378           0 :     BETA       = 0.0_hp
        1379           0 :     AEF        = 0.0_hp
        1380           0 :     LDF        = 0.0_hp
        1381           0 :     CT1        = 0.0_hp
        1382           0 :     CEO        = 0.0_hp
        1383           0 :     ANEW       = 0.0_hp
        1384           0 :     AGRO       = 0.0_hp
        1385           0 :     AMAT       = 0.0_hp
        1386           0 :     AOLD       = 0.0_hp
        1387           0 :     BIDIR      = .FALSE.
        1388             :
        1389             :     ! Number of days between MISOLAI and PMISOLAI
        1390           0 :     D_BTW_M  = DBLE( Inst%DAYS_BTW_M )
        1391             :
        1392             :     ! Pass met variables. Now use only LAI (ckeller, 10/9/2014)
        1393           0 :     ISOLAI   = ExtState%LAI%Arr%Val(I,J)
        1394           0 :     PMISOLAI = Inst%LAI_PREVDAY(I,J)
        1395           0 :     MISOLAI  = ISOLAI
        1396           0 :     TS       = ExtState%T2M%Arr%Val(I,J)
        1397           0 :     SUNCOS   = ExtState%SUNCOS%Arr%Val(I,J)
        1398             :
        1399             :     ! Convert Q_DIR and Q_DIFF from (W/m2) to (micromol/m2/s)
        1400           0 :     Q_DIR_2  = ExtState%PARDR%Arr%Val(I,J) * WM2_TO_UMOLM2S
        1401           0 :     Q_DIFF_2 = ExtState%PARDF%Arr%Val(I,J) * WM2_TO_UMOLM2S
        1402             :
        1403             :     ! Eventually normalize LAI by PFT (if setting is set
        1404             :     ! accordingly). ckeller, 7/17/17.
        1405           0 :     IF ( Inst%NORMLAI ) THEN
        1406           0 :        PFTSUM = SUM( Inst%ARRAY_16(I,J,2:16) )
        1407           0 :        IF ( PFTSUM > 0.0_hp ) THEN
        1408           0 :           MISOLAI  = MIN( MISOLAI  / PFTSUM, LAI_MAX )
        1409           0 :           PMISOLAI = MIN( PMISOLAI / PFTSUM, LAI_MAX )
        1410             :        ENDIF
        1411             :     ENDIF
        1412             :
        1413             :     ! --------------------------------------------
        1414             :     ! Get MEGAN parameters for this compound
        1415             :     ! --------------------------------------------
        1416             :     CALL GET_MEGAN_PARAMS ( HcoState,                         &
        1417             :                             CMPD, BETA, LDF,  CT1,  CEO,      &
        1418           0 :                             ANEW, AGRO, AMAT, AOLD, BIDIR, RC )
        1419           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        1420           0 :         CALL HCO_ERROR( 'ERROR 6', RC, THISLOC=LOC )
        1421           0 :         RETURN
        1422             :     ENDIF
        1423             :
        1424             :     ! --------------------------------------------
        1425             :     ! Get base emission factor for this compound and grid square
        1426             :     ! Units: kg/m2/s
        1427             :     ! --------------------------------------------
        1428           0 :     CALL GET_MEGAN_AEF ( HcoState, Inst, I, J, CMPD, AEF, RC )
        1429           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        1430           0 :         CALL HCO_ERROR( 'ERROR 7', RC, THISLOC=LOC )
        1431           0 :         RETURN
        1432             :     ENDIF
        1433             :
        1434             :     !-----------------------------------------------------
        1435             :     ! Only interested in terrestrial biosphere
        1436             :     ! If (local LAI != 0 .AND. baseline emission !=0 )
        1437             :     !-----------------------------------------------------
        1438           0 :     IF ( ISOLAI * AEF > 0.0_hp ) THEN
        1439             :
        1440             :        ! --------------------------------------------------
        1441             :        ! GAMMA_par (light activity factor)
        1442             :        ! --------------------------------------------------
        1443             :
        1444             :        ! Calculate GAMMA PAR only during day
        1445           0 :        IF ( SUNCOS > 0.0_hp ) THEN
        1446             :
        1447             :           GAMMA_PAR = GET_GAMMA_PAR_PCEEA( HcoState,                  &
        1448             :                                            ExtState, Inst, I, J,      &
        1449             :                                            Q_DIR_2,  Q_DIFF_2,        &
        1450           0 :                                            Inst%PARDR_LASTXDAYS(I,J), &
        1451           0 :                                            Inst%PARDF_LASTXDAYS(I,J) )
        1452             :        ELSE
        1453             :
        1454             :           ! If night
        1455             :           GAMMA_PAR = 0.0_hp
        1456             :        ENDIF
        1457             :
        1458             :        ! --------------------------------------------------
        1459             :        ! GAMMA_T_LI (temperature activity factor for
        1460             :        ! light-independent fraction)
        1461             :        ! --------------------------------------------------
        1462           0 :        GAMMA_T_LI = GET_GAMMA_T_LI( TS, BETA )
        1463             :
        1464             :        ! --------------------------------------------------
        1465             :        ! GAMMA_T_LD (temperature activity factor for
        1466             :        ! light-dependent fraction)
        1467             :        ! --------------------------------------------------
        1468           0 :        GAMMA_T_LD = GET_GAMMA_T_LD( TS, Inst%T_LASTXDAYS(I,J), &
        1469           0 :                                     Inst%T_LAST24H(I,J), CT1, CEO )
        1470             :
        1471             :        ! --------------------------------------------------
        1472             :        ! GAMMA_LAI (leaf area index activity factor)
        1473             :        ! --------------------------------------------------
        1474           0 :        GAMMA_LAI = GET_GAMMA_LAI( MISOLAI, BIDIR )
        1475             :
        1476             :        ! --------------------------------------------------
        1477             :        ! GAMMA_AGE (leaf age activity factor)
        1478             :        ! --------------------------------------------------
        1479             :        GAMMA_AGE = GET_GAMMA_AGE( MISOLAI, PMISOLAI, D_BTW_M, &
        1480             :                                   Inst%T_LASTXDAYS(I,J),      &
        1481           0 :                                   ANEW, AGRO, AMAT, AOLD )
        1482             :
        1483             :        ! --------------------------------------------------
        1484             :        ! GAMMA_SM (soil moisture activity factor)
        1485             :        ! --------------------------------------------------
        1486           0 :        GAMMA_SM = GET_GAMMA_SM( ExtState, I, J, CMPD )
        1487             :
        1488             :        ! CO2 inhibition of isoprene (Tai, Jan 2013)
        1489           0 :        IF ( Inst%LISOPCO2 ) THEN
        1490           0 :           GAMMA_CO2 = GET_GAMMA_CO2( Inst%GLOBCO2 )
        1491             :        ELSE
        1492             :           GAMMA_CO2 = 1.0_hp
        1493             :        ENDIF
        1494             :
        1495             :     ELSE
        1496             :
        1497             :        ! set activity factors to zero
        1498             :        GAMMA_PAR  = 0.0_hp
        1499             :        GAMMA_T_LI = 0.0_hp
        1500             :        GAMMA_T_LD = 0.0_hp
        1501             :        GAMMA_LAI  = 0.0_hp
        1502             :        GAMMA_AGE  = 0.0_hp
        1503             :        GAMMA_SM   = 0.0_hp
        1504             :        GAMMA_CO2  = 0.0_hp
        1505             :
        1506             :     END IF
        1507             :
        1508             :     ! Emission is the product of all of these.
        1509             :     ! Units here are kg/m2/s.
        1510             :     ! Normalization factor ensures product of GAMMA values is 1.0 under
        1511             :     !  standard conditions.
        1512           0 :     IF ( CMPD == 'ISOP' ) THEN
        1513             :        ! Only apply CO2 inhibition to isoprene (mps, 9/15/15)
        1514             :        ! Amos Tai wrote:
        1515             :        !  In my opinion, we should not apply the CO2 inhibition factor on
        1516             :        !  other monoterpene species yet, because the empirical data I've used
        1517             :        !  are for isoprene emissions only. But we generally agree that CO2
        1518             :        !  inhibition should affect monoterpenes too, so we'll leave room for
        1519             :        !  future incorporation when new data arise.
        1520           0 :        MEGAN_EMIS = Inst%NORM_FAC(1) * AEF * GAMMA_AGE * GAMMA_SM * &
        1521             :                     GAMMA_LAI * ((1.0_hp - LDF) * GAMMA_T_LI +      &
        1522           0 :                     (LDF * GAMMA_PAR * GAMMA_T_LD)) * GAMMA_CO2
        1523             :     ELSE
        1524           0 :        MEGAN_EMIS = Inst%NORM_FAC(1) * AEF * GAMMA_AGE * GAMMA_SM * &
        1525             :                     GAMMA_LAI * ((1.0_hp - LDF) * GAMMA_T_LI +      &
        1526           0 :                     (LDF * GAMMA_PAR * GAMMA_T_LD))
        1527             :     ENDIF
        1528             :
        1529             :     ! Leave w/ success
        1530           0 :     RC = HCO_SUCCESS
        1531             :
        1532             :   END SUBROUTINE GET_MEGAN_EMISSIONS
        1533             : !EOC
        1534             : !------------------------------------------------------------------------------
        1535             : !                   Harmonized Emissions Component (HEMCO)                    !
        1536             : !------------------------------------------------------------------------------
        1537             : !BOP
        1538             : !
        1539             : ! !IROUTINE: Get_Megan_Params
        1540             : !
        1541             : ! !DESCRIPTION: Subroutine Get\_Megan\_Params returns the emission parameters
        1542             : !  for each MEGAN compound needed to compute emissions. Called from
        1543             : !  GET\_MEGAN\_EMISSIONS.
        1544             : !\\
        1545             : !\\
        1546             : ! !INTERFACE:
        1547             : !
        1548           0 :   SUBROUTINE GET_MEGAN_PARAMS( HcoState,                           &
        1549             :                                CPD,   BTA,   LIDF,  C_T1,  C_EO,   &
        1550             :                                A_NEW, A_GRO, A_MAT, A_OLD, BI_DIR, &
        1551             :                                RC )
        1552             : !
        1553             : ! !INPUT PARAMETERS:
        1554             : !
        1555             :     TYPE(HCO_State),  POINTER    :: HcoState
        1556             :     CHARACTER(LEN=*), INTENT(IN) :: CPD       ! Compound name
        1557             : !
        1558             : ! !INPUT/OUTPUT PARAMETERS:
        1559             : !
        1560             :     REAL(hp), INTENT(INOUT) :: BTA    ! Beta coefficient for temperature activity
        1561             :                                       ! factor for light-independent fraction
        1562             :     REAL(hp), INTENT(INOUT) :: LIDF   ! Light-dependent fraction of emissions
        1563             :     REAL(hp), INTENT(INOUT) :: C_T1   ! CT1 parameter for temperature activity
        1564             :                                       ! factor for light-dependent fraction
        1565             :     REAL(hp), INTENT(INOUT) :: C_EO   ! Ceo parameter for temperature activity
        1566             :                                       ! factor for light-dependent fraction
        1567             :     REAL(hp), INTENT(INOUT) :: A_NEW  ! Relative emission factor (new leaves)
        1568             :     REAL(hp), INTENT(INOUT) :: A_GRO  ! Relative emission factor (growing leaves)
        1569             :     REAL(hp), INTENT(INOUT) :: A_MAT  ! Relative emission factor (mature leaves)
        1570             :     REAL(hp), INTENT(INOUT) :: A_OLD  ! Relative emission factor (old leaves)
        1571             :     LOGICAL,  INTENT(INOUT) :: BI_DIR ! Logical flag to indicate bidirectional exchange
        1572             :     INTEGER,  INTENT(INOUT) :: RC
        1573             : !
        1574             : ! !REMARKS:
        1575             : !  References (see above for full citations):
        1576             : !  ============================================================================
        1577             : !  (1 ) Guenther et al, (GMD 2012) and associated MEGANv2.1 source code
        1578             : !
        1579             : ! !REVISION HISTORY:
        1580             : !  (1 ) Created by dbm 07/2012
        1581             : !  See https://github.com/geoschem/hemco for complete history
        1582             : !EOP
        1583             : !------------------------------------------------------------------------------
        1584             : !BOC
        1585             : !
        1586             : ! !LOCAL VARIABLES:
        1587             : !
        1588             :     CHARACTER(LEN=255):: MSG
        1589             :
        1590             :     !=================================================================
        1591             :     ! GET_MEGAN_PARAMS begins here!
        1592             :     !=================================================================
        1593             :
        1594             :     ! Initialize values
        1595           0 :     BTA    = 0.0_hp
        1596           0 :     LIDF   = 0.0_hp
        1597           0 :     C_T1   = 0.0_hp
        1598           0 :     C_EO   = 0.0_hp
        1599           0 :     A_NEW  = 0.0_hp
        1600           0 :     A_GRO  = 0.0_hp
        1601           0 :     A_MAT  = 0.0_hp
        1602           0 :     A_OLD  = 0.0_hp
        1603           0 :     BI_DIR = .FALSE.
        1604             :
        1605             :     ! ----------------------------------------------------------------
        1606             :     ! Note that not all the above compounds are used in standard chemistry
        1607             :     ! simulations, but they are provided here for future incorporation or
        1608             :     ! specialized applications. More compounds can be added as needed
        1609             :     ! by adding the corresponding CPD name and the appropriate paramaters.
        1610             :     ! (dbm, 01/2013)
        1611             :     !
        1612             :     ! Values are from Table 4 in Guenther et al., 2012
        1613             :     ! ----------------------------------------------------------------
        1614             :
        1615             :     ! Isoprene, MBO
        1616           0 :     IF ( TRIM(CPD) == 'ISOP' .OR. &
        1617             :          TRIM(CPD) == 'MBOX' ) THEN
        1618           0 :        BTA    = 0.13_hp  ! Not actually used for ISOP, MBO
        1619           0 :        LIDF   = 1.0_hp
        1620           0 :        C_T1   = 95.0_hp
        1621           0 :        C_EO   = 2.0_hp
        1622           0 :        A_NEW  = 0.05_hp
        1623           0 :        A_GRO  = 0.6_hp
        1624           0 :        A_MAT  = 1.0_hp
        1625           0 :        A_OLD  = 0.9_hp
        1626           0 :        BI_DIR = .FALSE.
        1627             :
        1628             :     ! Myrcene, sabinene, alpha-pinene
        1629             :     ELSE IF ( TRIM(CPD) == 'MYRC' .OR. &
        1630           0 :               TRIM(CPD) == 'SABI' .OR. &
        1631             :               TRIM(CPD) == 'APIN' ) THEN
        1632           0 :        BTA    = 0.10_hp
        1633           0 :        LIDF   = 0.6_hp
        1634           0 :        C_T1   = 80.0_hp
        1635           0 :        C_EO   = 1.83_hp
        1636           0 :        A_NEW  = 2.0_hp
        1637           0 :        A_GRO  = 1.8_hp
        1638           0 :        A_MAT  = 1.0_hp
        1639           0 :        A_OLD  = 1.05_hp
        1640           0 :        BI_DIR = .FALSE.
        1641             :
        1642             :     ! Limonene, 3-carene, beta-pinene
        1643             :     ELSE IF ( TRIM(CPD) == 'LIMO' .OR. &
        1644           0 :               TRIM(CPD) == 'CARE' .OR. &
        1645             :               TRIM(CPD) == 'BPIN' ) THEN
        1646           0 :        BTA    = 0.10_hp
        1647           0 :        LIDF   = 0.2_hp
        1648           0 :        C_T1   = 80.0_hp
        1649           0 :        C_EO   = 1.83_hp
        1650           0 :        A_NEW  = 2.0_hp
        1651           0 :        A_GRO  = 1.8_hp
        1652           0 :        A_MAT  = 1.0_hp
        1653           0 :        A_OLD  = 1.05_hp
        1654           0 :        BI_DIR = .FALSE.
        1655             :
        1656             :     ! t-beta-ocimene
        1657           0 :     ELSE IF ( TRIM(CPD) == 'OCIM' ) THEN
        1658           0 :        BTA    = 0.10_hp
        1659           0 :        LIDF   = 0.8_hp
        1660           0 :        C_T1   = 80.0_hp
        1661           0 :        C_EO   = 1.83_hp
        1662           0 :        A_NEW  = 2.0_hp
        1663           0 :        A_GRO  = 1.8_hp
        1664           0 :        A_MAT  = 1.0_hp
        1665           0 :        A_OLD  = 1.05_hp
        1666           0 :        BI_DIR = .FALSE.
        1667             :
        1668             :     ! Other monoterpenes (lumped)
        1669           0 :     ELSE IF ( TRIM(CPD) == 'OMON' ) THEN
        1670           0 :        BTA    = 0.10_hp
        1671           0 :        LIDF   = 0.4_hp
        1672           0 :        C_T1   = 80.0_hp
        1673           0 :        C_EO   = 1.83_hp
        1674           0 :        A_NEW  = 2.0_hp
        1675           0 :        A_GRO  = 1.8_hp
        1676           0 :        A_MAT  = 1.0_hp
        1677           0 :        A_OLD  = 1.05_hp
        1678           0 :        BI_DIR = .FALSE.
        1679             :
        1680             :     ! Methanol
        1681           0 :     ELSE IF ( TRIM(CPD) == 'MOH' ) THEN
        1682           0 :        BTA    = 0.08_hp
        1683           0 :        LIDF   = 0.8_hp
        1684           0 :        C_T1   = 60.0_hp
        1685           0 :        C_EO   = 1.6_hp
        1686           0 :        A_NEW  = 3.5_hp
        1687           0 :        A_GRO  = 3.0_hp
        1688           0 :        A_MAT  = 1.0_hp
        1689           0 :        A_OLD  = 1.2_hp
        1690           0 :        BI_DIR = .FALSE.
        1691             :
        1692             :     ! Acetone
        1693           0 :     ELSE IF ( TRIM(CPD) == 'ACET' ) THEN
        1694           0 :        BTA    = 0.1_hp
        1695           0 :        LIDF   = 0.2_hp
        1696           0 :        C_T1   = 80.0_hp
        1697           0 :        C_EO   = 1.83_hp
        1698           0 :        A_NEW  = 1.0_hp
        1699           0 :        A_GRO  = 1.0_hp
        1700           0 :        A_MAT  = 1.0_hp
        1701           0 :        A_OLD  = 1.0_hp
        1702           0 :        BI_DIR = .FALSE.
        1703             :
        1704             :     ! Bidirectional VOC: Ethanol, formaldehyde, acetaldehyde, formic acid,
        1705             :     ! acetic acid
        1706             :     ELSE IF ( TRIM(CPD) == 'EOH'  .OR. &
        1707             :               TRIM(CPD) == 'CH2O' .OR. &
        1708             :               TRIM(CPD) == 'ALD2' .OR. &
        1709           0 :               TRIM(CPD) == 'FAXX' .OR. &
        1710             :               TRIM(CPD) == 'AAXX' ) THEN
        1711           0 :        BTA    = 0.13_hp
        1712           0 :        LIDF   = 0.8_hp
        1713           0 :        C_T1   = 95.0_hp
        1714           0 :        C_EO   = 2.0_hp
        1715           0 :        A_NEW  = 1.0_hp
        1716           0 :        A_GRO  = 1.0_hp
        1717           0 :        A_MAT  = 1.0_hp
        1718           0 :        A_OLD  = 1.0_hp
        1719           0 :        BI_DIR = .TRUE.
        1720             :
        1721             :     ! Stress VOCs: ethene, toluene, HCN
        1722             :     ! There are others species in this category but none are currently
        1723             :     ! used in GEOS-Chem
        1724             :     ELSE IF ( TRIM(CPD) == 'C2H4' .OR. &
        1725           0 :               TRIM(CPD) == 'TOLU' .OR. &
        1726             :               TRIM(CPD) == 'HCNX' ) THEN
        1727           0 :        BTA    = 0.1_hp
        1728           0 :        LIDF   = 0.8_hp
        1729           0 :        C_T1   = 80.0_hp
        1730           0 :        C_EO   = 1.83_hp
        1731           0 :        A_NEW  = 1.0_hp
        1732           0 :        A_GRO  = 1.0_hp
        1733           0 :        A_MAT  = 1.0_hp
        1734           0 :        A_OLD  = 1.0_hp
        1735           0 :        BI_DIR = .FALSE.
        1736             :
        1737             :     ! Other VOCs: >C2 alkenes
        1738             :     ! This includes propene, butene and very minor contribution from
        1739             :     ! larger alkenes
        1740           0 :     ELSE IF ( TRIM(CPD) == 'PRPE' ) THEN
        1741           0 :        BTA    = 0.1_hp
        1742           0 :        LIDF   = 0.2_hp
        1743           0 :        C_T1   = 80.0_hp
        1744           0 :        C_EO   = 1.83_hp
        1745           0 :        A_NEW  = 1.0_hp
        1746           0 :        A_GRO  = 1.0_hp
        1747           0 :        A_MAT  = 1.0_hp
        1748           0 :        A_OLD  = 1.0_hp
        1749           0 :        BI_DIR = .FALSE.
        1750             :
        1751             :     ! SOAupdate: Sesquiterpenes hotp 3/2/10
        1752             :     ! alpha-Farnesene, beta-Caryophyllene, other sesquiterpenes
        1753             :     ELSE IF ( TRIM(CPD) == 'FARN' .OR. &
        1754           0 :               TRIM(CPD) == 'BCAR' .OR. &
        1755             :               TRIM(CPD) == 'OSQT' ) THEN
        1756           0 :        BTA    = 0.17_hp
        1757           0 :        LIDF   = 0.5_hp
        1758           0 :        C_T1   = 130.0_hp
        1759           0 :        C_EO   = 2.37_hp
        1760           0 :        A_NEW  = 0.4_hp
        1761           0 :        A_GRO  = 0.6_hp
        1762           0 :        A_MAT  = 1.0_hp
        1763           0 :        A_OLD  = 0.95_hp
        1764           0 :        BI_DIR = .FALSE.
        1765             :
        1766             :     ! Calls for any other MEGAN compounds (e.g. sesquiterpenes, etc.) can
        1767             :     ! be added following the above format based on the parameters in
        1768             :     ! Guenther 2012 or the MEGAN source code (dbm, 6/21/2012).
        1769             :     ELSE
        1770             :
        1771           0 :        MSG = 'Invalid compound name'
        1772             :        CALL HCO_ERROR(MSG, RC, &
        1773           0 :                       THISLOC='GET_MEGAN_PARAMS' )
        1774           0 :        RETURN
        1775             :
        1776             :     ENDIF
        1777             :
        1778             :     ! Leave w/ success
        1779           0 :     RC = HCO_SUCCESS
        1780             :
        1781             :   END SUBROUTINE GET_MEGAN_PARAMS
        1782             : !EOC
        1783             : !------------------------------------------------------------------------------
        1784             : !                   Harmonized Emissions Component (HEMCO)                    !
        1785             : !------------------------------------------------------------------------------
        1786             : !BOP
        1787             : !
        1788             : ! !IROUTINE: Get_Megan_AEF
        1789             : !
        1790             : ! !DESCRIPTION: Function Get\_Megan\_AEF returns the appropriate AEF value
        1791             : !  for a given compound and grid square.
        1792             : !\\
        1793             : !\\
        1794             : ! !INTERFACE:
        1795             : !
        1796           0 :   SUBROUTINE GET_MEGAN_AEF( HcoState, Inst, I, J, CPD, EMFAC, RC )
        1797             : !
        1798             : ! !INPUT PARAMETERS:
        1799             : !
        1800             :     TYPE(HCO_State),   POINTER     :: HcoState
        1801             :     TYPE(MyInst),      POINTER     :: Inst
        1802             :     INTEGER,           INTENT(IN)  :: I, J        ! Lon & lat indices
        1803             :     CHARACTER(LEN=*),  INTENT(IN)  :: CPD         ! Compound name
        1804             : !
        1805             : ! !OUTPUT PARAMETERS:
        1806             : !
        1807             :     REAL(hp),          INTENT(OUT) :: EMFAC       ! MEGAN base emission factor
        1808             :                                                   ! (kg/m2/s) for grid cell I,J
        1809             : !
        1810             : ! !INPUT/OUTPUT PARAMETERS:
        1811             : !
        1812             :     INTEGER,           INTENT(INOUT) :: RC        ! Return code
        1813             : !
        1814             : ! !REMARKS:
        1815             : !  References (see above for full citations):
        1816             : !  ============================================================================
        1817             : !  (1 ) Guenther et al, 2012, MEGANv2.1 source code
        1818             : !
        1819             : ! !REVISION HISTORY:
        1820             : !  (1 ) Created 11/2012 by dbm
        1821             : !  See https://github.com/geoschem/hemco for complete history
        1822             : !EOP
        1823             : !------------------------------------------------------------------------------
        1824             : !BOC
        1825             : !
        1826             : ! !LOCAL VARIABLES:
        1827             : !
        1828             :     CHARACTER(LEN=255):: MSG
        1829             :
        1830             :     !=================================================================
        1831             :     ! GET_MEGAN_AEF begins here!
        1832             :     !=================================================================
        1833             :
        1834             :     ! Find appropriate tracer
        1835           0 :     SELECT CASE ( TRIM( CPD ) )
        1836             :     CASE ( 'ISOP' )
        1837           0 :        EMFAC = Inst%AEF_ISOP(I,J)
        1838             :     CASE ( 'MBOX' )
        1839           0 :        EMFAC = Inst%AEF_MBOX(I,J)
        1840             :     CASE ( 'MYRC' )
        1841           0 :        EMFAC = Inst%AEF_MYRC(I,J)
        1842             :     CASE ( 'SABI' )
        1843           0 :        EMFAC = Inst%AEF_SABI(I,J)
        1844             :     CASE ( 'APIN' )
        1845           0 :        EMFAC = Inst%AEF_APIN(I,J)
        1846             :     CASE ( 'LIMO' )
        1847           0 :        EMFAC = Inst%AEF_LIMO(I,J)
        1848             :     CASE ( 'CARE' )
        1849           0 :        EMFAC = Inst%AEF_CARE(I,J)
        1850             :     CASE ( 'BPIN' )
        1851           0 :        EMFAC = Inst%AEF_BPIN(I,J)
        1852             :     CASE ( 'OCIM' )
        1853           0 :        EMFAC = Inst%AEF_OCIM(I,J)
        1854             :     CASE ( 'OMON' )
        1855           0 :        EMFAC = Inst%AEF_OMON(I,J)
        1856             :     CASE ( 'MOH' )
        1857           0 :        EMFAC = Inst%AEF_MOH(I,J)
        1858             :     CASE ( 'ACET' )
        1859           0 :        EMFAC = Inst%AEF_ACET(I,J)
        1860             :     CASE ( 'EOH' )
        1861           0 :        EMFAC = Inst%AEF_EOH(I,J)
        1862             :     CASE ( 'CH2O' )
        1863           0 :        EMFAC = Inst%AEF_CH2O(I,J)
        1864             :     CASE ( 'ALD2' )
        1865           0 :        EMFAC = Inst%AEF_ALD2(I,J)
        1866             :     CASE ( 'FAXX' )
        1867           0 :        EMFAC = Inst%AEF_FAXX(I,J)
        1868             :     CASE ( 'AAXX' )
        1869           0 :        EMFAC = Inst%AEF_AAXX(I,J)
        1870             :     CASE ( 'C2H4' )
        1871           0 :        EMFAC = Inst%AEF_C2H4(I,J)
        1872             :     CASE ( 'TOLU' )
        1873           0 :        EMFAC = Inst%AEF_TOLU(I,J)
        1874             :     CASE ( 'HCNX' )
        1875           0 :        EMFAC = Inst%AEF_HCNX(I,J)
        1876             :     CASE ( 'PRPE' )
        1877           0 :        EMFAC = Inst%AEF_PRPE(I,J)
        1878             :     CASE ( 'FARN' )
        1879           0 :        EMFAC = Inst%AEF_FARN(I,J)
        1880             :     CASE ( 'BCAR' )
        1881           0 :        EMFAC = Inst%AEF_BCAR(I,J)
        1882             :     CASE ( 'OSQT' )
        1883           0 :        EMFAC = Inst%AEF_OSQT(I,J)
        1884             :     CASE DEFAULT
        1885           0 :        MSG = 'Invalid compound name'
        1886             :        CALL HCO_ERROR(MSG, &
        1887           0 :                       RC, THISLOC='GET_MEGAN_AEF' )
        1888           0 :        RETURN
        1889             :     END SELECT
        1890             :
        1891             :     ! Return w/ success
        1892           0 :     RC = HCO_SUCCESS
        1893             :
        1894             :   END SUBROUTINE GET_MEGAN_AEF
        1895             : !EOC
        1896             : !------------------------------------------------------------------------------
        1897             : !                   Harmonized Emissions Component (HEMCO)                    !
        1898             : !------------------------------------------------------------------------------
        1899             : !BOP
        1900             : !
        1901             : ! !IROUTINE: Get_Gamma_PAR_PCEEA
        1902             : !
        1903             : ! !DESCRIPTION: Computes the PCEEA gamma activity factor with sensitivity
        1904             : !  to LIGHT.
        1905             : !\\
        1906             : !\\
        1907             : ! !INTERFACE:
        1908             : !
        1909           0 :   FUNCTION GET_GAMMA_PAR_PCEEA( HcoState, ExtState,            &
        1910             :                                 Inst, I, J, Q_DIR_2, Q_DIFF_2, &
        1911             :                                 PARDR_AVG_SIM, PARDF_AVG_SIM ) &
        1912             :     RESULT( GAMMA_P_PCEEA )
        1913             : !
        1914             : ! !USES:
        1915             : !
        1916             :     USE HCO_CLOCK_MOD, ONLY : HcoClock_Get, HcoClock_GetLocal
        1917             : !
        1918             : ! !INPUT PARAMETERS:
        1919             : !
        1920             :     TYPE(HCO_State), POINTER    :: HcoState
        1921             :     TYPE(Ext_State), POINTER    :: ExtState
        1922             :     TYPE(MyInst),    POINTER    :: Inst
        1923             :     INTEGER,         INTENT(IN) :: I,  J             ! Lon & lat indices
        1924             :     REAL(sp),        INTENT(IN) :: PARDR_AVG_SIM     ! Avg direct PAR [W/m2]
        1925             :     REAL(sp),        INTENT(IN) :: PARDF_AVG_SIM     ! Avg diffuse PAR [W/m2]
        1926             :     REAL(hp),        INTENT(IN) :: Q_DIR_2           ! Direct PAR [umol/m2/s]
        1927             :     REAL(hp),        INTENT(IN) :: Q_DIFF_2          ! Diffuse PAR [umol/m2/s]
        1928             : !
        1929             : ! !RETURN VALUE:
        1930             : !
        1931             :     REAL(hp)                    :: GAMMA_P_PCEEA     ! GAMMA factor for light
        1932             : !
        1933             : ! !REMARKS:
        1934             : !  References (see above for full citations):
        1935             : !  ============================================================================
        1936             : !  (1 ) Guenther et al, 2006
        1937             : !  (2 ) Guenther et al, 2007, MEGAN v2.1 user guide
        1938             : !
        1939             : ! !REVISION HISTORY:
        1940             : !  (1 ) Code was taken & adapted directly from the MEGAN v2.1 source code.
        1941             : !      (mpb,2009)
        1942             : !  See https://github.com/geoschem/hemco for complete history
        1943             : !EOP
        1944             : !------------------------------------------------------------------------------
        1945             : !BOC
        1946             : !
        1947             : ! !LOCAL VARIABLES:
        1948             : !
        1949             :     REAL(hp)   :: mmPARDR_DAILY
        1950             :     REAL(hp)   :: mmPARDF_DAILY
        1951             :     REAL(hp)   :: PAC_DAILY, PAC_INSTANT, C_PPFD
        1952             :     REAL(hp)   :: PTOA, PHI
        1953             :     REAL(hp)   :: BETA,   SINbeta
        1954             :     INTEGER    :: DOY, RC
        1955             :     REAL(hp)   :: AAA, BBB
        1956             :     REAL(hp)   :: LocalHour
        1957             :     REAL(hp)   :: LAT
        1958             :
        1959             :     !-----------------------------------------------------------------
        1960             :     ! Compute GAMMA_PAR_PCEEA
        1961             :     !-----------------------------------------------------------------
        1962             :
        1963             :     ! Initialize
        1964           0 :     C_PPFD = 0.0_hp
        1965           0 :     PTOA   = 0.0_hp
        1966             :
        1967             :     ! Convert past light conditions to micromol/m2/s
        1968           0 :     mmPARDR_DAILY = PARDR_AVG_SIM  * WM2_TO_UMOLM2S
        1969           0 :     mmPARDF_DAILY = PARDF_AVG_SIM  * WM2_TO_UMOLM2S
        1970             :
        1971             :     ! Work out the light at the top of the canopy.
        1972           0 :     PAC_DAILY    = mmPARDR_DAILY + mmPARDF_DAILY
        1973           0 :     PAC_INSTANT  = Q_DIR_2       +  Q_DIFF_2
        1974             :
        1975             :     ! Get latitude
        1976           0 :     LAT = HcoState%Grid%YMID%Val(I,J)
        1977             :
        1978             :     ! Get day of year, local-time and latitude
        1979             :     ! TODO: Evaluate RC?
        1980           0 :     CALL HcoClock_Get( HcoState%Clock, cDOY = DOY, RC=RC )
        1981           0 :     CALL HcoClock_GetLocal( HcoState, I, J, cH = LocalHour, RC=RC )
        1982             :
        1983             :     ! Get solar elevation angle
        1984           0 :     SINbeta =  SOLAR_ANGLE( HcoState, Inst, DOY, LocalHour, LAT )
        1985           0 :     BETA    =  ASIN( SINbeta ) * Inst%RAD2D
        1986             :
        1987           0 :     IF ( SINbeta < 0.0_hp ) THEN
        1988             :
        1989             :        GAMMA_P_PCEEA = 0.0_hp
        1990             :
        1991           0 :     ELSEIF ( SINbeta > 0.0_hp ) THEN
        1992             :
        1993             :        ! PPFD at top of atmosphere
        1994             :        PTOA    = 3000.0_hp + 99.0_hp * &
        1995             :                  COS( 2._hp * 3.14159265358979323_hp * &
        1996           0 :                  ( DOY - 10.0_hp ) / 365.0_hp )
        1997             :
        1998             :        ! Above canopy transmission
        1999           0 :        PHI     = PAC_INSTANT / ( SINbeta * PTOA )
        2000             :
        2001             :        ! Work out gamma P
        2002           0 :        BBB     = 1.0_hp + 0.0005_hp *( PAC_DAILY - 400.0_hp )
        2003           0 :        AAA     = ( 2.46_hp * BBB * PHI ) - ( 0.9_hp * PHI**2 )
        2004             :
        2005           0 :        GAMMA_P_PCEEA = SINbeta * AAA
        2006             :
        2007             :     ENDIF
        2008             :
        2009             :     ! Screen unforced errors. IF solar elevation angle is
        2010             :     ! less than 1 THEN gamma_p can not be greater than 0.1.
        2011           0 :     IF ( BETA < 1.0_hp .AND. GAMMA_P_PCEEA > 0.1_hp ) THEN
        2012           0 :        GAMMA_P_PCEEA  = 0.0_hp
        2013             :     ENDIF
        2014             :
        2015             :     ! Prevent negative values
        2016           0 :     GAMMA_P_PCEEA = MAX( GAMMA_P_PCEEA , 0.0_hp )
        2017             :
        2018           0 :   END FUNCTION GET_GAMMA_PAR_PCEEA
        2019             : !EOC
        2020             : !------------------------------------------------------------------------------
        2021             : !                   Harmonized Emissions Component (HEMCO)                    !
        2022             : !------------------------------------------------------------------------------
        2023             : !BOP
        2024             : !
        2025             : ! !IROUTINE: Solar_Angle
        2026             : !
        2027             : ! !DESCRIPTION: Function SOLAR\_ANGLE computes the local solar angle for a
        2028             : !  given day of year, latitude and longitude (or local time).  Called from
        2029             : !  routine Get\_Gamma\_P\_Pecca.
        2030             : !\\
        2031             : !\\
        2032             : ! !INTERFACE:
        2033             : !
        2034           0 :   FUNCTION SOLAR_ANGLE( HcoState, Inst, DOY, SHOUR, LAT ) &
        2035             :        RESULT(SINbeta)
        2036             : !
        2037             : ! !INPUT PARAMETERS:
        2038             : !
        2039             :     TYPE(HCO_State),   POINTER    :: HcoState
        2040             :     TYPE(MyInst),      POINTER    :: Inst
        2041             :     INTEGER,           INTENT(IN) :: DOY       ! Day of year
        2042             :     REAL(hp),          INTENT(IN) :: SHOUR     ! Local time
        2043             :     REAL(hp),          INTENT(IN) :: LAT       ! Latitude
        2044             : !
        2045             : ! !RETURN VALUE:
        2046             : !
        2047             :     REAL(hp)                      :: SINbeta   ! Sin of the local solar angle
        2048             : !
        2049             : ! !REMARKS:
        2050             : !  References (see above for full citations):
        2051             : !  (1 ) Guenther et al, 2006
        2052             : !  (2 ) Guenther et al, MEGAN v2.1 user mannual 2007-09
        2053             : !
        2054             : ! !REVISION HISTORY:
        2055             : !  (1 ) This code was taken directly from the MEGAN v2.1 source code.(mpb,2009)
        2056             : !  See https://github.com/geoschem/hemco for complete history
        2057             : !EOP
        2058             : !------------------------------------------------------------------------------
        2059             : !BOC
        2060             : !
        2061             : ! !LOCAL VARIABLES:
        2062             : !
        2063             :     REAL(hp) :: BETA                        ! solar elevation angle
        2064             :     REAL(hp) :: sindelta, cosdelta, A, B
        2065             :
        2066             :     ! Calculation of sin beta
        2067           0 :     sindelta = -SIN( 0.40907_hp ) * COS( 6.28_hp * ( DOY + 10_dp ) / 365_dp )
        2068             :
        2069           0 :     cosdelta = (1-sindelta**2.0_hp)**0.5_hp
        2070             :
        2071           0 :     A = SIN( LAT * Inst%D2RAD ) * sindelta
        2072           0 :     B = COS( LAT * Inst%D2RAD ) * cosdelta
        2073             :
        2074           0 :     SINbeta = A + B * COS( 2.0_hp * HcoState%Phys%PI * ( SHOUR-12_dp )/24_dp )
        2075             :
        2076           0 :   END FUNCTION SOLAR_ANGLE
        2077             : !EOC
        2078             : !------------------------------------------------------------------------------
        2079             : !                   Harmonized Emissions Component (HEMCO)                    !
        2080             : !------------------------------------------------------------------------------
        2081             : !BOP
        2082             : !
        2083             : ! !IROUTINE: Get_Gamma_T_LI
        2084             : !
        2085             : ! !DESCRIPTION: Function Get\_Gamma\_T\_LI computes the temperature activity
        2086             : !  factor (GAMMA\_T\_LI) for the light-independent fraction of emissions
        2087             : !\\
        2088             : !\\
        2089             : ! !INTERFACE:
        2090             : !
        2091           0 :   FUNCTION GET_GAMMA_T_LI( T, BETA ) &
        2092             :        RESULT( GAMMA_T_LI )
        2093             : !
        2094             : ! !INPUT PARAMETERS:
        2095             : !
        2096             :     ! Current leaf temperature, the surface air temperature field (TS)
        2097             :     ! is assumed equivalent to the leaf temperature over forests.
        2098             :     REAL(hp),  INTENT(IN) :: T
        2099             :
        2100             :     ! Temperature factor per species
        2101             :     REAL(hp),  INTENT(IN) :: BETA
        2102             : !
        2103             : ! !RETURN VALUE:
        2104             : !
        2105             :     ! Activity factor for the light-independent fraction of emissions
        2106             :     REAL(hp)              :: GAMMA_T_LI
        2107             : !
        2108             : ! !REMARKS:
        2109             : !  GAMMA_T =  exp[Beta*(T - T_Standard)]
        2110             : !                                                                             .
        2111             : !             where Beta   = temperature dependent parameter
        2112             : !                   Ts     = standard temperature (normally 303K, 30C)
        2113             : !                                                                             .
        2114             : !  Note: If T = Ts  (i.e. standard conditions) then GAMMA_T = 1
        2115             : !
        2116             : !  References (see above for full citations):
        2117             : !  ============================================================================
        2118             : !  (1 ) Guenther et al, 2006
        2119             : !  (2 ) Guenther et al, MEGAN user mannual 2007-08
        2120             : !  (3 ) Guenther et al., GMD 2012 and MEGANv2.1 source code.
        2121             : !
        2122             : ! !REVISION HISTORY:
        2123             : !  (1 ) Original code by Michael Barkley (2009).
        2124             : !  See https://github.com/geoschem/hemco for complete history
        2125             : !EOP
        2126             : !------------------------------------------------------------------------------
        2127             : !BOC
        2128             : !
        2129             : ! !DEFINED PARAMETERS:
        2130             : !
        2131             :     ! Standard reference temperature [K]
        2132             :     REAL*8, PARAMETER   :: T_STANDARD = 303.d0
        2133             :
        2134             :     !=================================================================
        2135             :     ! GET_GAMMAT_T_LI begins here!
        2136             :     !=================================================================
        2137             :
        2138           0 :     GAMMA_T_LI = EXP( BETA * ( T - T_STANDARD ) )
        2139             :
        2140           0 :   END FUNCTION GET_GAMMA_T_LI
        2141             : !EOC
        2142             : !------------------------------------------------------------------------------
        2143             : !                   Harmonized Emissions Component (HEMCO)                    !
        2144             : !------------------------------------------------------------------------------
        2145             : !BOP
        2146             : !
        2147             : ! !IROUTINE: Get_Gamma_T_LD
        2148             : !
        2149             : ! !DESCRIPTION: Function Get\_Gamma\_T\_LD computes the temperature
        2150             : !  sensitivity for the light-dependent fraction of emissions.
        2151             : !\\
        2152             : !\\
        2153             : ! !INTERFACE:
        2154             : !
        2155           0 :   FUNCTION GET_GAMMA_T_LD( T, PT_15, PT_1, CT1, CEO ) &
        2156             :        RESULT( GAMMA_T_LD )
        2157             : !
        2158             : ! !INPUT PARAMETERS:
        2159             : !
        2160             :     ! Current leaf temperature [K], the surface air temperature field (TS)
        2161             :     ! is assumed equivalent to the leaf temperature over forests.
        2162             :     REAL(hp), INTENT(IN) :: T
        2163             :
        2164             :     ! Average leaf temperature over the past 15 days
        2165             :     REAL(sp), INTENT(IN) :: PT_15
        2166             :
        2167             :     ! Average leaf temperature over the past arbitray day(s).
        2168             :     ! This is not used at present
        2169             :     REAL(sp), INTENT(IN) :: PT_1
        2170             :
        2171             :     ! Compound-specific parameters for light-dependent temperature activity
        2172             :     ! factor (dbm, 6/21/2012)
        2173             :     REAL(hp), INTENT(IN) :: CT1, CEO
        2174             : !
        2175             : ! !RETURN VALUE:
        2176             : !
        2177             :     ! Temperature activity factor for the light-dependent fraction of
        2178             :     ! emissions
        2179             :     REAL(hp)             :: GAMMA_T_LD
        2180             : !
        2181             : ! !REMARKS:
        2182             : !  References (see above for full citations):
        2183             : !  (1 ) Guenther et al, 1995
        2184             : !  (2 ) Guenther et al, 2006
        2185             : !  (3 ) Guenther et al, MEGAN v2.1 user mannual 2007-08
        2186             : !  (4 ) Guenther et al., GMD 2012 and MEGANv2.1 source code.
        2187             : !
        2188             : ! !REVISION HISTORY:
        2189             : !  (1 ) Includes the latest MEGAN v2.1 temperature algorithm (mpb, 2009).
        2190             : !       Note, this temp-dependence is the same for the PCEEA & hybrid models.
        2191             : !  See https://github.com/geoschem/hemco for complete history
        2192             : !EOP
        2193             : !------------------------------------------------------------------------------
        2194             : !BOC
        2195             : !
        2196             : ! !LOCAL VARIABLES:
        2197             : !
        2198             :     REAL(hp)              :: C_T,   CT2
        2199             :     REAL(hp)              :: E_OPT, T_OPT, X
        2200             : !
        2201             : ! !DEFINED PARAMETERS:
        2202             : !
        2203             :     ! Ideal gas constant [J/mol/K]
        2204             :     REAL(hp), PARAMETER   :: R   = 8.3144598e-3_hp
        2205             :
        2206             :     !=================================================================
        2207             :     ! GET_GAMMA_T_LD begins here!
        2208             :     !=================================================================
        2209           0 :     E_OPT = CEO * EXP( 0.08_hp * ( PT_15  - 2.97e2_hp ) )
        2210           0 :     T_OPT = 3.13e2_hp + ( 6.0e-1_hp * ( PT_15 - 2.97e2_hp ) )
        2211           0 :     CT2   = 200.0_hp
        2212             :
        2213             :     ! Variable related to temperature
        2214           0 :     X     = ( 1.0_hp/T_OPT - 1.0_hp/T ) / R
        2215             :
        2216             :     ! C_T: Effect of temperature on leaf BVOC emission, including
        2217             :     ! effect of average temperature over previous 15 days, based on
        2218             :     ! Eq 5a, 5b, 5c from Guenther et al, 1999.
        2219             :     C_T   = E_OPT * CT2 * EXP( CT1 * X ) / &
        2220           0 :             ( CT2 - CT1 * ( 1.0_hp - EXP( CT2 * X ) ) )
        2221             :
        2222             :     ! Hourly emission activity = C_T
        2223             :     ! Prevent negative values
        2224           0 :     GAMMA_T_LD = MAX( C_T, 0.0_hp )
        2225             :
        2226           0 :   END FUNCTION GET_GAMMA_T_LD
        2227             : !EOC
        2228             : !------------------------------------------------------------------------------
        2229             : !                   Harmonized Emissions Component (HEMCO)                    !
        2230             : !------------------------------------------------------------------------------
        2231             : !BOP
        2232             : !
        2233             : ! !IROUTINE: Get_Gamma_Lai
        2234             : !
        2235             : ! !DESCRIPTION: Function Get\_Gamma\_Lai computes the gamma exchange activity
        2236             : !  factor which is sensitive to leaf area (= GAMMA\_LAI).
        2237             : !\\
        2238             : !\\
        2239             : ! !INTERFACE:
        2240             : !
        2241           0 :   FUNCTION GET_GAMMA_LAI( CMLAI, BIDIREXCH ) &
        2242             :        RESULT( GAMMA_LAI )
        2243             : !
        2244             : ! !INPUT PARAMETERS:
        2245             : !
        2246             :     REAL(hp),     INTENT(IN) :: CMLAI       ! Current month's LAI [cm2/cm2]
        2247             :     LOGICAL,      INTENT(IN) :: BIDIREXCH   ! Logical flag indicating whether
        2248             :                                             ! the compound undergoes bidirectional
        2249             :                                             ! exchange
        2250             : !
        2251             : ! !RETURN VALUE:
        2252             : !
        2253             :     REAL(hp)             :: GAMMA_LAI
        2254             : !
        2255             : ! !REMARKS:
        2256             : !  References (see above for full citations):
        2257             : !  ============================================================================
        2258             : !  (1 ) Guenther et al, 2006
        2259             : !  (2 ) Guenther et al, MEGAN user mannual 2007-08
        2260             : !  (3 ) Guenther et al., GMD 2012 and MEGANv2.1 source code.
        2261             : !
        2262             : ! !REVISION HISTORY:
        2263             : !  (1 ) Original code by Dorian Abbot (9/2003).  Modified for the standard
        2264             : !        code by May Fu (11/2004)
        2265             : !  See https://github.com/geoschem/hemco for complete history
        2266             : !EOP
        2267             : !------------------------------------------------------------------------------
        2268             : !BOC
        2269             :
        2270             :     ! Formulation for birectional compounds is as described for
        2271             :     ! ALD2 in Millet et al., ACP 2010
        2272           0 :     IF ( BIDIREXCH ) THEN
        2273             :
        2274           0 :        IF ( CMLAI <= 6.0_hp) THEN
        2275             :
        2276             :           ! if lai less than 2:
        2277           0 :           IF ( CMLAI <= 2.0_hp ) THEN
        2278           0 :              GAMMA_LAI = 0.5_hp * CMLAI
        2279             :
        2280             :           ! if between 2 and 6:
        2281             :           ELSE
        2282           0 :              GAMMA_LAI = 1.0_hp - 0.0625_hp * ( CMLAI - 2.0_hp )
        2283             :           END IF
        2284             :
        2285             :        ELSE
        2286             :           ! keep at 0.75 for LAI > 6
        2287             :           GAMMA_LAI = 0.75_hp
        2288             :        END IF
        2289             :
        2290             :     ! For all other compounds use the standard gamma_lai formulation
        2291             :     ELSE
        2292           0 :        GAMMA_LAI = 0.49_hp * CMLAI / SQRT( 1.0_hp + 0.2_hp * CMLAI*CMLAI)
        2293             :     ENDIF
        2294             :
        2295           0 :   END FUNCTION GET_GAMMA_LAI
        2296             : !EOC
        2297             : !------------------------------------------------------------------------------
        2298             : !                   Harmonized Emissions Component (HEMCO)                    !
        2299             : !------------------------------------------------------------------------------
        2300             : !BOP
        2301             : !
        2302             : ! !IROUTINE: Get_Gamma_Age
        2303             : !
        2304             : ! !DESCRIPTION: Function Get\_Gamma\_Age computes the gamma exchange
        2305             : !  activity factor which is sensitive to leaf age (= Gamma\_Age).
        2306             : !\\
        2307             : !\\
        2308             : ! !INTERFACE:
        2309             : !
        2310           0 :   FUNCTION GET_GAMMA_AGE( CMLAI, PMLAI, DBTWN, TT, AN, AG, AM, AO ) &
        2311             :        RESULT( GAMMA_AGE )
        2312             : !
        2313             : ! !INPUT PARAMETERS:
        2314             : !
        2315             :     REAL(hp), INTENT(IN) :: CMLAI     ! Current month's LAI [cm2/cm2]
        2316             :     REAL(hp), INTENT(IN) :: PMLAI     ! Previous months LAI [cm2/cm2]
        2317             :     REAL(hp), INTENT(IN) :: DBTWN     ! Number of days between
        2318             :     REAL(sp), INTENT(IN) :: TT        ! Daily average temperature [K]
        2319             :     REAL(hp), INTENT(IN) :: AN        ! Relative emiss factor (new leaves)
        2320             :     REAL(hp), INTENT(IN) :: AG        ! Relative emiss factor (growing leaves)
        2321             :     REAL(hp), INTENT(IN) :: AM        ! Relative emiss factor (mature leaves)
        2322             :     REAL(hp), INTENT(IN) :: AO        ! Relative emiss factor (old leaves)
        2323             : !
        2324             : ! !RETURN VALUE:
        2325             : !
        2326             :     REAL(hp)             :: GAMMA_AGE ! Activity factor
        2327             : !
        2328             : ! !REMARKS:
        2329             : !  References (see above for full citations):
        2330             : !  ============================================================================
        2331             : !  (1 ) Guenther et al, 2006
        2332             : !  (2 ) Guenther et al, MEGAN user mannual 2007-08
        2333             : !  (3 ) Guenther et al., GMD 2012 and MEGANv2.1 source code
        2334             : !
        2335             : ! !REVISION HISTORY:
        2336             : !  (1 ) Original code by Dorian Abbot (9/2003). Modified for the standard
        2337             : !        code by May Fu (11/2004)
        2338             : !  See https://github.com/geoschem/hemco for complete history
        2339             : !EOP
        2340             : !------------------------------------------------------------------------------
        2341             : !BOC
        2342             : !
        2343             : ! !LOCAL VARIABLES:
        2344             : !
        2345             :     REAL(hp)             :: FNEW  ! Fraction of new leaves in canopy
        2346             :     REAL(hp)             :: FGRO  ! Fraction of growing leaves
        2347             :     REAL(hp)             :: FMAT  ! Fraction of mature leaves
        2348             :     REAL(hp)             :: FOLD  ! Fraction of old leaves
        2349             :
        2350             :     ! TI: number of days after budbreak required to induce emissions
        2351             :     REAL(hp)             :: TI
        2352             :
        2353             :     ! TM: number of days after budbreak required to reach peak emissions
        2354             :     REAL(hp)             :: TM
        2355             :
        2356             :     !=================================================================
        2357             :     ! GET_GAMMA_AGE begins here!
        2358             :     !=================================================================
        2359             :
        2360             :     !-----------------------
        2361             :     ! Compute TI and TM
        2362             :     ! (mpb,2009)
        2363             :     !-----------------------
        2364             :
        2365           0 :     IF ( TT <= 303.0_hp ) THEN
        2366           0 :        TI = 5.0_hp + 0.7_hp * ( 300.0_hp - TT )
        2367           0 :     ELSEIF ( TT >  303.0_hp ) THEN
        2368           0 :        TI = 2.9_hp
        2369             :     ENDIF
        2370           0 :     TM = 2.3_hp * TI
        2371             :
        2372             :     !-----------------------
        2373             :     ! Compute GAMMA_AGE
        2374             :     !-----------------------
        2375             :
        2376           0 :     IF ( CMLAI == PMLAI ) THEN !(i.e. LAI stays the same)
        2377             :
        2378             :        FNEW = 0.0_hp
        2379             :        FGRO = 0.1_hp
        2380             :        FMAT = 0.8_hp
        2381             :        FOLD = 0.1_hp
        2382             :
        2383           0 :     ELSE IF ( CMLAI > PMLAI ) THEN !(i.e. LAI has INcreased)
        2384             :
        2385             :        ! Calculate Fnew
        2386           0 :        IF ( DBTWN > TI ) THEN
        2387           0 :           FNEW = ( TI / DBTWN ) * ( 1.0_hp -  PMLAI / CMLAI )
        2388             :        ELSE
        2389           0 :           FNEW = 1.0_hp - ( PMLAI / CMLAI )
        2390             :        ENDIF
        2391             :
        2392             :        ! Calculate FMAT
        2393           0 :        IF ( DBTWN > TM ) THEN
        2394             :           FMAT = ( PMLAI / CMLAI ) + &
        2395           0 :                  (( DBTWN - TM ) / DBTWN )*( 1.0_hp -  PMLAI / CMLAI )
        2396             :        ELSE
        2397           0 :           FMAT = ( PMLAI / CMLAI )
        2398             :        ENDIF
        2399             :
        2400             :        ! Calculate Fgro and Fold
        2401           0 :        FGRO = 1.0_hp - FNEW - FMAT
        2402           0 :        FOLD = 0.0_hp
        2403             :
        2404             :     ELSE ! This is the case if  PMLAI > CMLAI (i.e. LAI has DEcreased)
        2405             :
        2406           0 :        FNEW = 0.0_hp
        2407           0 :        FGRO = 0.0_hp
        2408           0 :        FOLD = ( PMLAI - CMLAI ) / PMLAI
        2409           0 :        FMAT = 1.0_hp - FOLD
        2410             :
        2411             :     ENDIF
        2412             :
        2413             :     ! Age factor
        2414           0 :     GAMMA_AGE = FNEW * AN + FGRO * AG + FMAT * AM + FOLD * AO
        2415             :
        2416             :     ! Prevent negative values
        2417           0 :     GAMMA_AGE = MAX( GAMMA_AGE , 0.0_hp )
        2418             :
        2419           0 :   END FUNCTION GET_GAMMA_AGE
        2420             : !EOC
        2421             : !------------------------------------------------------------------------------
        2422             : !                   Harmonized Emissions Component (HEMCO)                    !
        2423             : !------------------------------------------------------------------------------
        2424             : !BOP
        2425             : !
        2426             : ! !IROUTINE: get_gamma_sm
        2427             : !
        2428             : ! !DESCRIPTION: Function GET\_GAMMA\_SM computes activity factor for soil
        2429             : !  moisture
        2430             : !\\
        2431             : !\\
        2432             : ! !INTERFACE:
        2433             : !
        2434           0 :   FUNCTION GET_GAMMA_SM( ExtState, I, J, CMPD ) &
        2435             :        RESULT( GAMMA_SM )
        2436             : !
        2437             : ! !INPUT PARAMETERS:
        2438             : !
        2439             :     TYPE(Ext_State),  POINTER     :: ExtState
        2440             :     INTEGER,          INTENT(IN)  :: I, J     ! GEOS-Chem lon & lat indices
        2441             :     CHARACTER(LEN=*), INTENT(IN)  :: CMPD     ! Compound name (dbm, 6/21/2012)
        2442             :
        2443             : ! !RETURN VALUE:
        2444             : !
        2445             :     REAL(hp)                      :: GAMMA_SM ! Activity factor
        2446             : !
        2447             : ! !REMARKS:
        2448             : !  References (see above for full citations):
        2449             : !  ============================================================================
        2450             : !  (1 ) Guenther et al, ACP 2006
        2451             : !  (2 ) Guenther et al., GMD 2012 and MEGANv2.1 source code
        2452             : !
        2453             : ! !REVISION HISTORY:
        2454             : !  (1 ) Created by dbm (6/2012). We are not currently using a soil moisture
        2455             : !       effect for isoprene. For all compounds other than acetaldehyde and
        2456             : !       ethanol, gamma_sm =1 presently.
        2457             : !  See https://github.com/geoschem/hemco for complete history
        2458             : !EOP
        2459             : !------------------------------------------------------------------------------
        2460             : !BOC
        2461             : !
        2462             : ! !LOCAL VARIABLES:
        2463             : !
        2464             :     REAL(hp)  :: GWETROOT
        2465             :
        2466             :     !=================================================================
        2467             :     ! GET_GAMMA_SM begins here!
        2468             :     !=================================================================
        2469             :
        2470             :     ! By default gamma_sm is 1.0
        2471           0 :     GAMMA_SM = 1.0_hp
        2472             :
        2473             :     ! Error trap: GWETROOT must be between 0.0 and 1.0 (ckeller, 4/16/15)
        2474           0 :     GWETROOT = MIN(MAX(ExtState%GWETROOT%Arr%Val(I,J),0.0_hp),1.0_hp)
        2475             :
        2476           0 :     IF ( TRIM( CMPD ) == 'ALD2' .OR. TRIM ( CMPD ) == 'EOH' ) THEN
        2477             :
        2478             :        ! GWETROOT = degree of saturation or wetness in the root-zone
        2479             :        ! (top meter of soil). This is defined as the ratio of the volumetric
        2480             :        ! soil moisture to the porosity. We use a soil moisture activity factor
        2481             :        ! for ALD2 to account for stimulation of emission by flooding.
        2482             :        ! (Millet et al., ACP 2010)
        2483             :        ! Constant value of 1.0 for GWETROOT = 0-0.9, increasing linearly to
        2484             :        ! 3.0 at GWETROOT =1.
        2485           0 :        GAMMA_SM = MAX( 20.0_hp * GWETROOT - 17.0_hp, 1.0_hp)
        2486             :
        2487             :     ENDIF
        2488             :
        2489           0 :   END FUNCTION GET_GAMMA_SM
        2490             : !EOC
        2491             : !------------------------------------------------------------------------------
        2492             : !                   Harmonized Emissions Component (HEMCO)                    !
        2493             : !------------------------------------------------------------------------------
        2494             : !BOP
        2495             : !
        2496             : ! !IROUTINE: get_gamma_co2
        2497             : !
        2498             : ! !DESCRIPTION: Function GET\_GAMMA\_CO2 computes the CO2 activity factor
        2499             : !  associated with CO2 inhibition of isoprene emission. Called from
        2500             : !  GET\_MEGAN\_EMISSIONS only.
        2501             : !\\
        2502             : !\\
        2503             : ! !INTERFACE:
        2504             : !
        2505           0 :   FUNCTION GET_GAMMA_CO2( CO2a ) &
        2506             :        RESULT( GAMMA_CO2 )
        2507             : !
        2508             : ! !INPUT PARAMETERS:
        2509             :     REAL(hp), INTENT(IN) :: CO2a       ! Atmospheric CO2 conc [ppmv]
        2510             : !
        2511             : ! !RETURN VALUE:
        2512             :     REAL(hp)             :: GAMMA_CO2  ! CO2 activity factor [unitless]
        2513             : !
        2514             : ! !LOCAL VARIABLES:
        2515             :     REAL(hp)             :: CO2i       ! Intercellular CO2 conc [ppmv]
        2516             :     REAL(hp)             :: ISMAXi     ! Asymptote for intercellular CO2
        2517             :     REAL(hp)             :: HEXPi      ! Exponent for intercellular CO2
        2518             :     REAL(hp)             :: CSTARi     ! Scaling coef for intercellular CO2
        2519             :     REAL(hp)             :: ISMAXa     ! Asymptote for atmospheric CO2
        2520             :     REAL(hp)             :: HEXPa      ! Exponent for atmospheric CO2
        2521             :     REAL(hp)             :: CSTARa     ! Scaling coef for atmospheric CO2
        2522             :     LOGICAL              :: LPOSSELL   ! Use Possell & Hewitt (2011)?
        2523             :     LOGICAL              :: LWILKINSON ! Use Wilkinson et al. (2009)?
        2524             : !
        2525             : ! !REMARKS:
        2526             : !  References:
        2527             : !  ============================================================================
        2528             : !  (1 ) Heald, C. L., Wilkinson, M. J., Monson, R. K., Alo, C. A.,
        2529             : !       Wang, G. L., and Guenther, A.: Response of isoprene emission
        2530             : !       to ambient co(2) changes and implications for global budgets,
        2531             : !       Global Change Biology, 15, 1127-1140, 2009.
        2532             : !  (2 ) Wilkinson, M. J., Monson, R. K., Trahan, N., Lee, S., Brown, E.,
        2533             : !       Jackson, R. B., Polley, H. W., Fay, P. A., and Fall, R.: Leaf
        2534             : !       isoprene emission rate as a function of atmospheric CO2
        2535             : !       concentration, Global Change Biology, 15, 1189-1200, 2009.
        2536             : !  (3 ) Possell, M., and Hewitt, C. N.: Isoprene emissions from plants
        2537             : !       are mediated by atmospheric co2 concentrations, Global Change
        2538             : !       Biology, 17, 1595-1610, 2011.
        2539             : !
        2540             : ! !REVISION HISTORY:
        2541             : !  (1 ) Implemented in the standard code by A. Tai (Jun 2012).
        2542             : !  See https://github.com/geoschem/hemco for complete history
        2543             : !EOP
        2544             : !------------------------------------------------------------------------------
        2545             : !BOC
        2546             :
        2547             :     !----------------------------------------------------------
        2548             :     ! Choose between two alternative CO2 inhibition schemes
        2549             :     !----------------------------------------------------------
        2550             :
        2551             :     ! Empirical relationship of Possell & Hewitt (2011) based on nine
        2552             :     ! experimental studies including Wilkinson et al. (2009). This is
        2553             :     ! especially recommended for sub-ambient CO2 concentrations:
        2554           0 :     LPOSSELL    = .TRUE.   ! Default option
        2555             :
        2556             :     ! Semi-process-based parameterization of Wilkinson et al. (2009),
        2557             :     ! taking into account of sensitivity to intercellular CO2
        2558             :     ! fluctuation, which is here set as a constant fraction of
        2559             :     ! atmospheric CO2:
        2560           0 :     LWILKINSON  = .FALSE.   ! Set .TRUE. only if LPOSSELL = .FALSE.
        2561             :
        2562             :     !-----------------------
        2563             :     ! Compute GAMMA_CO2
        2564             :     !-----------------------
        2565             :
        2566             :     IF ( LPOSSELL ) THEN
        2567             :
        2568             :        ! Use empirical relationship of Possell & Hewitt (2011):
        2569           0 :        GAMMA_CO2 = 8.9406_hp / ( 1.0_hp + 8.9406_hp * 0.0024_hp * CO2a )
        2570             :
        2571             :     ELSEIF ( LWILKINSON ) THEN
        2572             :
        2573             :        ! Use parameterization of Wilkinson et al. (2009):
        2574             :
        2575             :        ! Parameters for intercellular CO2 using linear interpolation:
        2576             :        IF ( CO2a <= 600.0_hp ) THEN
        2577             :           ISMAXi = 1.036_hp  - (1.036_hp - 1.072_hp) / &
        2578             :                    (600.0_hp - 400.0_hp) * (600.0_hp - CO2a)
        2579             :           HEXPi  = 2.0125_hp - (2.0125_hp - 1.7000_hp) / &
        2580             :                    (600.0_hp - 400.0_hp) * (600.0_hp - CO2a)
        2581             :           CSTARi = 1150.0_hp - (1150.0_hp - 1218.0_hp) / &
        2582             :                    (600.0_hp - 400.0_hp) * (600.0_hp - CO2a)
        2583             :        ELSEIF ( CO2a > 600.0_hp .AND. CO2a < 800.0_hp ) THEN
        2584             :           ISMAXi = 1.046_hp  - (1.046_hp - 1.036_hp) / &
        2585             :                    (800.0_hp - 600.0_hp) * (800.0_hp - CO2a)
        2586             :           HEXPi  = 1.5380_hp - (1.5380_hp - 2.0125_hp) / &
        2587             :                    (800.0_hp - 600.0_hp) * (800.0_hp - CO2a)
        2588             :           CSTARi = 2025.0_hp - (2025.0_hp - 1150.0_hp) / &
        2589             :                    (800.0_hp - 600.0_hp) * (800.0_hp - CO2a)
        2590             :        ELSE
        2591             :           ISMAXi = 1.014_hp - (1.014_hp - 1.046_hp) / &
        2592             :                    (1200.0_hp - 800.0_hp) * (1200.0_hp - CO2a)
        2593             :           HEXPi  = 2.8610_hp - (2.8610_hp - 1.5380_hp) / &
        2594             :                    (1200.0_hp - 800.0_hp) * (1200.0_hp - CO2a)
        2595             :           CSTARi = 1525.0_hp - (1525.0_hp - 2025.0_hp) / &
        2596             :                    (1200.0_hp - 800.0_hp) * (1200.0_hp - CO2a)
        2597             :        ENDIF
        2598             :
        2599             :        ! Parameters for atmospheric CO2:
        2600             :        ISMAXa    = 1.344_hp
        2601             :        HEXPa     = 1.4614_hp
        2602             :        CSTARa    = 585.0_hp
        2603             :
        2604             :        ! For now, set CO2_Ci = 0.7d0 * CO2_Ca as recommended by Heald
        2605             :        ! et al. (2009):
        2606             :        CO2i      = 0.7_hp * CO2a
        2607             :
        2608             :        ! Compute GAMMA_CO2:
        2609             :        GAMMA_CO2 = ( ISMAXi -  ISMAXi * CO2i**HEXPi / &
        2610             :                    ( CSTARi**HEXPi + CO2i**HEXPi ) )  &
        2611             :                    * ( ISMAXa - ISMAXa * ( 0.7_hp * CO2a )**HEXPa / &
        2612             :                    ( CSTARa**HEXPa + ( 0.7_hp * CO2a )**HEXPa ) )
        2613             :
        2614             :     ELSE
        2615             :
        2616             :        ! No CO2 inhibition scheme is used; GAMMA_CO2 set to unity:
        2617             :        GAMMA_CO2 = 1.0_hp
        2618             :
        2619             :     ENDIF
        2620             :
        2621           0 :   END FUNCTION GET_GAMMA_CO2
        2622             : !EOC
        2623             : !------------------------------------------------------------------------------
        2624             : !                   Harmonized Emissions Component (HEMCO)                    !
        2625             : !------------------------------------------------------------------------------
        2626             : !BOP
        2627             : !
        2628             : ! !IROUTINE: CALC_NORM_FAC
        2629             : !
        2630             : ! !DESCRIPTION: Function CALC\_NORM\_FAC calculates the normalization factor
        2631             : !  needed to compute emissions. Called from GET\_MEGAN\_EMISSIONS.
        2632             : !\\
        2633             : !\\
        2634             : ! !INTERFACE:
        2635             : !
        2636           0 :   SUBROUTINE CALC_NORM_FAC( Inst, RC )
        2637             : !
        2638             : ! !INPUT PARAMETERS:
        2639             : !
        2640             :     TYPE(MyInst),    POINTER        :: Inst
        2641             : !
        2642             : ! !INPUT/OUTPUT PARAMETERS
        2643             : !
        2644             :     INTEGER,         INTENT(INOUT)  :: RC
        2645             : !
        2646             : ! !REMARKS:
        2647             : !  References (see above for full citations):
        2648             : !  ============================================================================
        2649             : !  (1 ) Guenther et al, (GMD 2012) and associated MEGANv2.1 source code
        2650             : !
        2651             : ! !REVISION HISTORY:
        2652             : !  (1 ) Created by dbm 11/2012. We calculate only 1 normalization factor for all
        2653             : !       compounds based on the isoprene gamma values. Formally there should be a
        2654             : !       different normalization factor for each compound, but we are following
        2655             : !       Alex Guenther's approach here and the MEGAN source code.
        2656             : !       "Hi Dylan, sorry for being so slow to get back to you.
        2657             : !        Since the change is only a few percent or less, I didn't
        2658             : !        bother to assign a different normalization factor to each
        2659             : !        compound.  Since the MEGAN canopy environment model also
        2660             : !        has 8 different canopy types (tropical broadleaf tree,
        2661             : !        conifer tree, etc.) then to be correct we should have a
        2662             : !        different CCE for each canopy type for each compound class
        2663             : !        (which would be 160 slightly different values of CCE)."
        2664             : !  See https://github.com/geoschem/hemco for complete history
        2665             : !EOP
        2666             : !------------------------------------------------------------------------------
        2667             : !BOC
        2668             : !
        2669             : ! !LOCAL VARIABLES:
        2670             : !
        2671             :     REAL(hp) :: PAC_DAILY, PHI, BBB, AAA, GAMMA_P_STANDARD
        2672             :     REAL(hp) :: GAMMA_T_LI_STANDARD
        2673             :     REAL(hp) :: GAMMA_SM_STANDARD
        2674             :     REAL(hp) :: CMLAI, GAMMA_LAI_STANDARD
        2675             :     REAL(hp) :: GAMMA_AGE_STANDARD
        2676             :     REAL(hp) :: PT_15, T, R, CEO, CT1, E_OPT, T_OPT, CT2, X
        2677             :     REAL(hp) :: GAMMA_T_LD_STANDARD
        2678             :     REAL(hp) :: LDF, GAMMA_STANDARD
        2679             :
        2680             :     !-----------------------------------------------------------------
        2681             :     ! CALC_NORM_FAC
        2682             :     !-----------------------------------------------------------------
        2683             :
        2684             :     ! -----------------
        2685             :     ! GAMMA_P for standard conditions
        2686             :     ! -----------------
        2687             :     ! Based on Eq. 11b from Guenther et al., 2006
        2688             :     ! Using standard conditions of phi = 0.6, solar angle of 60 deg,
        2689             :     ! and P_daily = 400
        2690             :     ! Note corrigendum for Eq. 11b in that paper, should be a
        2691             :     ! minus sign before the 0.9.
        2692           0 :     PAC_DAILY = 400.0_hp
        2693           0 :     PHI       = 0.6_hp
        2694           0 :     BBB       = 1.0_hp + 0.0005_hp *( PAC_DAILY - 400.0_hp )
        2695           0 :     AAA       = ( 2.46_hp * BBB * PHI ) - ( 0.9_hp * PHI**2 )
        2696             :     ! sin(60) = 0.866
        2697           0 :     GAMMA_P_STANDARD = 0.866_hp * AAA
        2698             :
        2699             :     ! -----------------
        2700             :     ! GAMMA_T_LI for standard conditions
        2701             :     ! -----------------
        2702             :     ! gamma_t_li = EXP( Beta * ( T - T_Standard ) )
        2703             :     ! This is 1.0 for T = T_Standard
        2704           0 :     GAMMA_T_LI_STANDARD = 1.0_hp
        2705             :
        2706             :     ! -----------------
        2707             :     ! GAMMA_SM for standard conditions
        2708             :     ! -----------------
        2709             :     ! Standard condition is soil moisture = 0.3 m^3/m^3
        2710             :     ! GAMMA_SM = 1.0 for all compounds under this condition
        2711           0 :     GAMMA_SM_STANDARD = 1.0_hp
        2712             :
        2713             :     ! -----------------
        2714             :     ! GAMMA_LAI for standard conditions
        2715             :     ! -----------------
        2716             :     ! Standard condition is LAI = 5
        2717           0 :     CMLAI = 5.0_hp
        2718           0 :     GAMMA_LAI_STANDARD = 0.49_hp * CMLAI / SQRT( 1.0_hp + 0.2_hp * CMLAI*CMLAI )
        2719             :
        2720             :     ! -----------------
        2721             :     ! GAMMA_AGE for standard conditions
        2722             :     ! -----------------
        2723             :     ! Standard condition is 0% new, 10% growing, 80% mature, 10% old foliage
        2724             :     ! Isoprene uses A_NEW = 0.05d0, A_GRO = 0.6d0, A_MAT = 1.d0, A_OLD = 0.9d0
        2725           0 :     GAMMA_AGE_STANDARD = 0.1_hp*0.6_hp + 0.8_hp*1.0_hp + 0.1_hp*0.9_hp
        2726             :
        2727             :     ! -----------------
        2728             :     ! GAMMA_T_LD for standard conditions
        2729             :     ! -----------------
        2730             :     ! Standard condition is
        2731             :     ! PT_15 = average leaf temp over past 24-240 hours = 297K
        2732             :     ! T = air temperature = 303K
        2733           0 :     PT_15 = 297.0_hp
        2734           0 :     T     = 303.0_hp
        2735           0 :     R     = 8.3144598e-3_hp
        2736             :     ! parameters for isoprene
        2737           0 :     CEO = 2.0_hp
        2738           0 :     CT1 = 95.0_hp
        2739             :
        2740           0 :     E_OPT = CEO * EXP( 0.08_hp * ( PT_15  - 2.97e2_hp ) )
        2741           0 :     T_OPT = 3.13e2_hp + ( 6.0e-1_hp * ( PT_15 - 2.97e2_hp ) )
        2742           0 :     CT2   = 200.0_hp
        2743             :
        2744             :     ! Variable related to temperature
        2745           0 :     X     = ( 1.0_hp/T_OPT - 1.0_hp/T ) / R
        2746             :
        2747             :     GAMMA_T_LD_STANDARD = E_OPT * CT2 * EXP( CT1 * X ) / &
        2748           0 :                           ( CT2 - CT1 * ( 1.0_hp - EXP( CT2 * X ) ) )
        2749             :
        2750             :     ! -----------------
        2751             :     ! Overall GAMMA_STANDARD
        2752             :     ! -----------------
        2753             :     ! LDF = 1d0 for isoprene
        2754           0 :     LDF = 1.0_hp
        2755             :     GAMMA_STANDARD = &
        2756             :          GAMMA_AGE_STANDARD * GAMMA_SM_STANDARD * GAMMA_LAI_STANDARD &
        2757             :          * ((1.0_hp - LDF) * GAMMA_T_LI_STANDARD &
        2758           0 :          + (LDF * GAMMA_P_STANDARD * GAMMA_T_LD_STANDARD))
        2759             :     ! This ends up being 1.0101081.
        2760             :
        2761           0 :     Inst%NORM_FAC = 1.0_hp / GAMMA_STANDARD
        2762             :
        2763             :     ! Return w/ success
        2764           0 :     RC = HCO_SUCCESS
        2765             :
        2766           0 :   END SUBROUTINE CALC_NORM_FAC
        2767             : !EOC
        2768             :
        2769             : !------------------------------------------------------------------------------
        2770             : !                   Harmonized Emissions Component (HEMCO)                    !
        2771             : !------------------------------------------------------------------------------
        2772             : !BOP
        2773             : !
        2774             : ! !IROUTINE: Fill_Restart_Vars
        2775             : !
        2776             : ! !DESCRIPTION: Subroutine FILL\_RESTART\_VARS fills the megan restart
        2777             : !  variables.
        2778             : !\\
        2779             : !\\
        2780             : ! !INTERFACE:
        2781             : !
        2782           0 :   SUBROUTINE FILL_RESTART_VARS( HcoState, ExtState, Inst, RC )
        2783             : !
        2784             : ! !USES:
        2785             : !
        2786             :     USE HCO_Restart_Mod,    ONLY : HCO_RestartGet
        2787             : !
        2788             : ! !INPUT PARAMETERS:
        2789             : !
        2790             :     TYPE(HCO_State), POINTER        :: HcoState
        2791             :     TYPE(Ext_State), POINTER        :: ExtState
        2792             :     TYPE(MyInst),    POINTER        :: Inst
        2793             : !
        2794             : ! !INPUT/OUTPUT PARAMETERS:
        2795             : !
        2796             :     INTEGER,         INTENT(INOUT)  :: RC
        2797             : !
        2798             : ! !REVISION HISTORY:
        2799             : !  19 Dec 2014 - C. Keller    - Initial version
        2800             : !  See https://github.com/geoschem/hemco for complete history
        2801             : !EOP
        2802             : !------------------------------------------------------------------------------
        2803             : !BOC
        2804             : !
        2805             : ! !LOCAL VARIABLES:
        2806             : !
        2807             :     INTEGER           :: I
        2808             :     LOGICAL           :: FND
        2809             :
        2810             :     !=================================================================
        2811             :     ! FILL_RESTART_VARS begins here!
        2812             :     !=================================================================
        2813             :
        2814             :     ! On first call, see if there are restart variables available for
        2815             :     ! historic values of temperature and irradiation. If so, fill the
        2816             :     ! daily arrays with those average values to start with. If not,
        2817             :     ! simply use the current values.
        2818             :     ! The same procedure is applied to the 15 day average values. For
        2819             :     ! temperature, we also restart previous day temperature so that
        2820             :     ! we can determine a trend in the daily average temperatures
        2821             :     ! (between the long term daily averages and the most recent daily
        2822             :     ! average).
        2823             :     ! We now first call HCO_CopyFromInt_ESMF to check if the variable
        2824             :     ! is found in the (ESMF) internal state object. In an non-ESMF
        2825             :     ! environment, this call will always return FND=.FALSE.
        2826             :     ! (ckeller, 3/9/15).
        2827             :
        2828             :     !-----------------------------------------------------------------
        2829             :     ! LAI
        2830             :     !-----------------------------------------------------------------
        2831             :     CALL HCO_RestartGet( HcoState, 'LAI_PREVDAY', &
        2832           0 :                          Inst%LAI_PREVDAY, RC, FILLED=FND )
        2833             :
        2834             :     ! Default value
        2835           0 :     IF ( .NOT. FND ) THEN
        2836           0 :        Inst%LAI_PREVDAY = ExtState%LAI%Arr%Val
        2837             :     ENDIF
        2838             :
        2839             :     !-----------------------------------------------------------------
        2840             :     ! DIFFUSE RADIATION ( PARDF )
        2841             :     !-----------------------------------------------------------------
        2842             :
        2843             :     ! Temperature over last 24 hours
        2844             :     CALL HCO_RestartGet( HcoState, 'T_PREVDAY', &
        2845           0 :                          Inst%T_LAST24H, RC, DefVal = 288.15_sp )
        2846             :
        2847             :     ! Temperature over last X days
        2848             :     CALL HCO_RestartGet( HcoState, 'T_DAVG', &
        2849           0 :                          Inst%T_LASTXDAYS, RC, DefVal = 288.15_sp )
        2850             :
        2851             :     ! Direct radiation (PARDR) over last X days
        2852             :     CALL HCO_RestartGet( HcoState, 'PARDR_DAVG', &
        2853           0 :                          Inst%PARDR_LASTXDAYS, RC, DefVal = 30.0_sp )
        2854             :
        2855             :     ! Diffuse radiation (PARDF) over last X days
        2856             :     CALL HCO_RestartGet( HcoState, 'PARDF_DAVG', &
        2857           0 :                          Inst%PARDF_LASTXDAYS, RC, DefVal = 48.0_sp )
        2858             :
        2859             :     ! Return w/ success
        2860           0 :     RC = HCO_SUCCESS
        2861             :
        2862           0 :   END SUBROUTINE FILL_RESTART_VARS
        2863             : !EOC
        2864             : !------------------------------------------------------------------------------
        2865             : !                   Harmonized Emissions Component (HEMCO)                    !
        2866             : !------------------------------------------------------------------------------
        2867             : !BOP
        2868             : !
        2869             : ! !IROUTINE: CALC_AEF
        2870             : !
        2871             : ! !DESCRIPTION: Subroutine CALC\_AEF reads Emission Factors for all
        2872             : !  biogenic VOC species from disk.
        2873             : !\\
        2874             : !\\
        2875             : ! !INTERFACE:
        2876             : !
        2877           0 :   SUBROUTINE CALC_AEF( HcoState, ExtState, Inst, RC )
        2878             : !
        2879             : ! !USES:
        2880             : !
        2881             :     USE HCO_EMISLIST_MOD,    ONLY : HCO_GetPtr
        2882             :     USE HCO_CALC_MOD,        ONLY : HCO_EvalFld
        2883             : !
        2884             : ! !INPUT PARAMETERS:
        2885             : !
        2886             :     TYPE(Ext_State), POINTER       :: ExtState
        2887             :     TYPE(HCO_State), POINTER       :: HcoState
        2888             :     TYPE(MyInst),    POINTER       :: Inst
        2889             : !
        2890             : ! !INPUT/OUTPUT PARAMETERS:
        2891             : !
        2892             :     INTEGER,         INTENT(INOUT) :: RC
        2893             : !
        2894             : ! !REMARKS:
        2895             : !  Reference: (5 ) Guenther et al, 2004
        2896             : !
        2897             : ! !REVISION HISTORY:
        2898             : !  (1 ) Original code by Dorian Abbot (9/2003).  Modified for the standard
        2899             : !        code by May Fu (11/2004)
        2900             : !  See https://github.com/geoschem/hemco for complete history
        2901             : !EOP
        2902             : !------------------------------------------------------------------------------
        2903             : !BOC
        2904             : !
        2905             : ! !LOCAL VARIABLES:
        2906             : !
        2907             :     INTEGER                 :: I, J, P, ARR_IND
        2908             :     REAL(hp)                :: FACTOR
        2909             :     REAL(hp)                :: PFT_EF_OMON(15), PFT_EF_MOH(15)
        2910             :     REAL(hp)                :: PFT_EF_ACET(15), PFT_EF_BIDR(15)
        2911             :     REAL(hp)                :: PFT_EF_STRS(15), PFT_EF_OTHR(15)
        2912             :     ! --->
        2913             :     ! dbm, compute EF maps for a-pinene and myrcene as well since there seems to
        2914             :     ! be an issue with the EF maps for these species provided on the MEGAN
        2915             :     ! data portal
        2916             :     REAL(hp)                :: PFT_EF_APIN(15), PFT_EF_MYRC(15)
        2917             :     ! <---
        2918             :     REAL(hp)                :: PFT_EF_FARN(15), PFT_EF_BCAR(15)
        2919             :     REAL(hp)                :: PFT_EF_OSQT(15)
        2920             :     REAL(hp)                :: EM_FRAC_ALD2(15), EM_FRAC_EOH(15)
        2921             :     REAL(hp)                :: EM_FRAC_FAXX(15), EM_FRAC_AAXX(15)
        2922             :     REAL(hp)                :: EM_FRAC_CH2O(15)
        2923             :
        2924             :     ! Pointers to CLM4 plant functional types
        2925           0 :     REAL(hp)  :: PFT_BARE(HcoState%NX,HcoState%NY)
        2926           0 :     REAL(hp)  :: PFT_NDLF_EVGN_TMPT_TREE(HcoState%NX,HcoState%NY)
        2927           0 :     REAL(hp)  :: PFT_NDLF_EVGN_BORL_TREE(HcoState%NX,HcoState%NY)
        2928           0 :     REAL(hp)  :: PFT_NDLF_DECD_BORL_TREE(HcoState%NX,HcoState%NY)
        2929           0 :     REAL(hp)  :: PFT_BDLF_EVGN_TROP_TREE(HcoState%NX,HcoState%NY)
        2930           0 :     REAL(hp)  :: PFT_BDLF_EVGN_TMPT_TREE(HcoState%NX,HcoState%NY)
        2931           0 :     REAL(hp)  :: PFT_BDLF_DECD_TROP_TREE(HcoState%NX,HcoState%NY)
        2932           0 :     REAL(hp)  :: PFT_BDLF_DECD_TMPT_TREE(HcoState%NX,HcoState%NY)
        2933           0 :     REAL(hp)  :: PFT_BDLF_DECD_BORL_TREE(HcoState%NX,HcoState%NY)
        2934           0 :     REAL(hp)  :: PFT_BDLF_EVGN_SHRB(HcoState%NX,HcoState%NY)
        2935           0 :     REAL(hp)  :: PFT_BDLF_DECD_TMPT_SHRB(HcoState%NX,HcoState%NY)
        2936           0 :     REAL(hp)  :: PFT_BDLF_DECD_BORL_SHRB(HcoState%NX,HcoState%NY)
        2937           0 :     REAL(hp)  :: PFT_C3_ARCT_GRSS(HcoState%NX,HcoState%NY)
        2938           0 :     REAL(hp)  :: PFT_C3_NARC_GRSS(HcoState%NX,HcoState%NY)
        2939           0 :     REAL(hp)  :: PFT_C4_GRSS(HcoState%NX,HcoState%NY)
        2940           0 :     REAL(hp)  :: PFT_CROP(HcoState%NX,HcoState%NY)
        2941             :
        2942             :     CHARACTER(LEN=255)      :: LOC
        2943             :
        2944             :     ! Suffix
        2945             :     CHARACTER(LEN=255)      :: SFX
        2946             :
        2947             :     !=================================================================
        2948             :     ! CALC_AEF begins here!
        2949             :     !=================================================================
        2950           0 :     LOC = 'CALC_AEF (HCOX_MEGAN_MOD.F90)'
        2951             :
        2952             :     ! Suffix
        2953           0 :     SFX = Inst%SUFFIX
        2954             :
        2955             :     ! ----------------------------------------------------------------
        2956             :     ! Note that not all these compounds are used in standard chemistry
        2957             :     ! simulations, but they are provided here for future incorporation or
        2958             :     ! specialized applications. More compounds can be added as needed
        2959             :     ! by adding the corresponding PFT-specific emission factors and
        2960             :     ! emission category fraction.
        2961             :     ! (dbm, 01/2013)
        2962             :     ! ----------------------------------------------------------------
        2963             :
        2964             :     !-----------------------------------------------------------------
        2965             :     ! Point to external data
        2966             :     !-----------------------------------------------------------------
        2967             :     CALL HCO_EvalFld( HcoState, 'MEGAN_AEF_ISOP'//TRIM(SFX), &
        2968           0 :                       Inst%AEF_ISOP, RC )
        2969           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        2970           0 :         CALL HCO_ERROR( 'ERROR 8', RC, THISLOC=LOC )
        2971           0 :         RETURN
        2972             :     ENDIF
        2973             :
        2974             :     CALL HCO_EvalFld( HcoState, 'MEGAN_AEF_MBOX'//TRIM(SFX), &
        2975           0 :                       Inst%AEF_MBOX, RC )
        2976           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        2977           0 :         CALL HCO_ERROR( 'ERROR 9', RC, THISLOC=LOC )
        2978           0 :         RETURN
        2979             :     ENDIF
        2980             :
        2981             :     CALL HCO_EvalFld( HcoState, 'MEGAN_AEF_BPIN'//TRIM(SFX), &
        2982           0 :                       Inst%AEF_BPIN, RC )
        2983           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        2984           0 :         CALL HCO_ERROR( 'ERROR 10', RC, THISLOC=LOC )
        2985           0 :         RETURN
        2986             :     ENDIF
        2987             :
        2988             :     CALL HCO_EvalFld( HcoState, 'MEGAN_AEF_CARE'//TRIM(SFX), &
        2989           0 :                       Inst%AEF_CARE, RC )
        2990           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        2991           0 :         CALL HCO_ERROR( 'ERROR 11', RC, THISLOC=LOC )
        2992           0 :         RETURN
        2993             :     ENDIF
        2994             :
        2995             :     CALL HCO_EvalFld( HcoState, 'MEGAN_AEF_LIMO'//TRIM(SFX), &
        2996           0 :                       Inst%AEF_LIMO, RC )
        2997           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        2998           0 :         CALL HCO_ERROR( 'ERROR 12', RC, THISLOC=LOC )
        2999           0 :         RETURN
        3000             :     ENDIF
        3001             :
        3002             :     CALL HCO_EvalFld( HcoState, 'MEGAN_AEF_OCIM'//TRIM(SFX), &
        3003           0 :                       Inst%AEF_OCIM, RC )
        3004           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        3005           0 :         CALL HCO_ERROR( 'ERROR 13', RC, THISLOC=LOC )
        3006           0 :         RETURN
        3007             :     ENDIF
        3008             :
        3009             :     CALL HCO_EvalFld( HcoState, 'MEGAN_AEF_SABI'//TRIM(SFX), &
        3010           0 :                       Inst%AEF_SABI, RC )
        3011           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        3012           0 :         CALL HCO_ERROR( 'ERROR 14', RC, THISLOC=LOC )
        3013           0 :         RETURN
        3014             :     ENDIF
        3015             :
        3016             :     !-----------------------------------------------------------------
        3017             :     ! Point to PFT fractions
        3018             :     !-----------------------------------------------------------------
        3019             :
        3020             :     ! CLM4 PFT coverage (unitless)
        3021             :     ! From Table 3 in Guenther et al., 2012
        3022             :     ! PFT_BARE                : Bare
        3023             :     ! PFT_NDLF_EVGN_TMPT_TREE : Needleleaf evergreen temperate tree
        3024             :     ! PFT_NDLF_EVGN_BORL_TREE : Needleleaf evergreen boreal tree
        3025             :     ! PFT_NDLF_DECD_BORL_TREE : Needleleaf deciduous boreal tree
        3026             :     ! PFT_BDLF_EVGN_TROP_TREE : Broadleaf evergreen tropical tree
        3027             :     ! PFT_BDLF_EVGN_TMPT_TREE : Broadleaf evergreen temperate tree
        3028             :     ! PFT_BDLF_DECD_TROP_TREE : Broadleaf deciduous tropical tree
        3029             :     ! PFT_BDLF_DECD_TMPT_TREE : Broadleaf deciduous temperate tree
        3030             :     ! PFT_BDLF_DECD_BORL_TREE : Broadleaf deciduous boreal tree
        3031             :     ! PFT_BDLF_EVGN_SHRB      : Broadleaf evergreen temperate shrub
        3032             :     ! PFT_BDLF_DECD_TMPT_SHRB : Broadleaf deciduous temperate shrub
        3033             :     ! PFT_BDLF_DECD_BORL_SHRB : Broadleaf deciduous boreal shrub
        3034             :     ! PFT_C3_ARCT_GRSS        : Arctic C3 grass
        3035             :     ! PFT_C3_NARC_GRSS        : Cool C3 grass
        3036             :     ! PFT_C4_GRSS             : Warm C4 grass
        3037             :     ! PFT_CROP                : Crop
        3038             :
        3039             :     CALL HCO_EvalFld( HcoState, &
        3040             :                       'CLM4_PFT_BARE'//TRIM(SFX), &
        3041           0 :                       PFT_BARE, RC )
        3042           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        3043           0 :         CALL HCO_ERROR( 'ERROR 15', RC, THISLOC=LOC )
        3044           0 :         RETURN
        3045             :     ENDIF
        3046             :
        3047             :     CALL HCO_EvalFld( HcoState, &
        3048             :                       'CLM4_PFT_NDLF_EVGN_TMPT_TREE'//TRIM(SFX), &
        3049           0 :                       PFT_NDLF_EVGN_TMPT_TREE, RC )
        3050           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        3051           0 :         CALL HCO_ERROR( 'ERROR 16', RC, THISLOC=LOC )
        3052           0 :         RETURN
        3053             :     ENDIF
        3054             :
        3055             :     CALL HCO_EvalFld( HcoState, &
        3056             :                       'CLM4_PFT_NDLF_EVGN_BORL_TREE'//TRIM(SFX), &
        3057           0 :                       PFT_NDLF_EVGN_BORL_TREE, RC )
        3058           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        3059           0 :         CALL HCO_ERROR( 'ERROR 17', RC, THISLOC=LOC )
        3060           0 :         RETURN
        3061             :     ENDIF
        3062             :
        3063             :     CALL HCO_EvalFld( HcoState, &
        3064             :                       'CLM4_PFT_NDLF_DECD_BORL_TREE'//TRIM(SFX), &
        3065           0 :                       PFT_NDLF_DECD_BORL_TREE, RC )
        3066           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        3067           0 :         CALL HCO_ERROR( 'ERROR 18', RC, THISLOC=LOC )
        3068           0 :         RETURN
        3069             :     ENDIF
        3070             :
        3071             :     CALL HCO_EvalFld( HcoState, &
        3072             :                       'CLM4_PFT_BDLF_EVGN_TROP_TREE'//TRIM(SFX), &
        3073           0 :                       PFT_BDLF_EVGN_TROP_TREE, RC )
        3074           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        3075           0 :         CALL HCO_ERROR( 'ERROR 19', RC, THISLOC=LOC )
        3076           0 :         RETURN
        3077             :     ENDIF
        3078             :
        3079             :     CALL HCO_EvalFld( HcoState, &
        3080             :                       'CLM4_PFT_BDLF_EVGN_TMPT_TREE'//TRIM(SFX), &
        3081           0 :                       PFT_BDLF_EVGN_TMPT_TREE, RC )
        3082           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        3083           0 :         CALL HCO_ERROR( 'ERROR 20', RC, THISLOC=LOC )
        3084           0 :         RETURN
        3085             :     ENDIF
        3086             :
        3087             :     CALL HCO_EvalFld( HcoState, &
        3088             :                       'CLM4_PFT_BDLF_DECD_TROP_TREE'//TRIM(SFX), &
        3089           0 :                       PFT_BDLF_DECD_TROP_TREE, RC )
        3090           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        3091           0 :         CALL HCO_ERROR( 'ERROR 21', RC, THISLOC=LOC )
        3092           0 :         RETURN
        3093             :     ENDIF
        3094             :
        3095             :     CALL HCO_EvalFld( HcoState, &
        3096             :                       'CLM4_PFT_BDLF_DECD_TMPT_TREE'//TRIM(SFX), &
        3097           0 :                       PFT_BDLF_DECD_TMPT_TREE, RC )
        3098           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        3099           0 :         CALL HCO_ERROR( 'ERROR 22', RC, THISLOC=LOC )
        3100           0 :         RETURN
        3101             :     ENDIF
        3102             :
        3103             :     CALL HCO_EvalFld( HcoState, &
        3104             :                       'CLM4_PFT_BDLF_DECD_BORL_TREE'//TRIM(SFX), &
        3105           0 :                       PFT_BDLF_DECD_BORL_TREE, RC )
        3106           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        3107           0 :         CALL HCO_ERROR( 'ERROR 23', RC, THISLOC=LOC )
        3108           0 :         RETURN
        3109             :     ENDIF
        3110             :
        3111             :     CALL HCO_EvalFld( HcoState, &
        3112             :                       'CLM4_PFT_BDLF_EVGN_SHRB'//TRIM(SFX), &
        3113           0 :                       PFT_BDLF_EVGN_SHRB, RC )
        3114           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        3115           0 :         CALL HCO_ERROR( 'ERROR 24', RC, THISLOC=LOC )
        3116           0 :         RETURN
        3117             :     ENDIF
        3118             :
        3119             :     CALL HCO_EvalFld( HcoState, &
        3120             :                       'CLM4_PFT_BDLF_DECD_TMPT_SHRB'//TRIM(SFX), &
        3121           0 :                       PFT_BDLF_DECD_TMPT_SHRB, RC )
        3122           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        3123           0 :         CALL HCO_ERROR( 'ERROR 25', RC, THISLOC=LOC )
        3124           0 :         RETURN
        3125             :     ENDIF
        3126             :
        3127             :     CALL HCO_EvalFld( HcoState, &
        3128             :                       'CLM4_PFT_BDLF_DECD_BORL_SHRB'//TRIM(SFX), &
        3129           0 :                       PFT_BDLF_DECD_BORL_SHRB, RC )
        3130           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        3131           0 :         CALL HCO_ERROR( 'ERROR 26', RC, THISLOC=LOC )
        3132           0 :         RETURN
        3133             :     ENDIF
        3134             :
        3135             :     CALL HCO_EvalFld( HcoState, &
        3136             :                       'CLM4_PFT_C3_ARCT_GRSS'//TRIM(SFX), &
        3137           0 :                       PFT_C3_ARCT_GRSS, RC )
        3138           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        3139           0 :         CALL HCO_ERROR( 'ERROR 27', RC, THISLOC=LOC )
        3140           0 :         RETURN
        3141             :     ENDIF
        3142             :
        3143             :     CALL HCO_EvalFld( HcoState, &
        3144             :                       'CLM4_PFT_C3_NARC_GRSS'//TRIM(SFX), &
        3145           0 :                       PFT_C3_NARC_GRSS, RC )
        3146           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        3147           0 :         CALL HCO_ERROR( 'ERROR 28', RC, THISLOC=LOC )
        3148           0 :         RETURN
        3149             :     ENDIF
        3150             :
        3151             :     CALL HCO_EvalFld( HcoState, &
        3152             :                       'CLM4_PFT_C4_GRSS'//TRIM(SFX), &
        3153           0 :                       PFT_C4_GRSS, RC )
        3154           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        3155           0 :         CALL HCO_ERROR( 'ERROR 29', RC, THISLOC=LOC )
        3156           0 :         RETURN
        3157             :     ENDIF
        3158             :
        3159             :     CALL HCO_EvalFld( HcoState, &
        3160             :                       'CLM4_PFT_CROP'//TRIM(SFX), &
        3161           0 :                       PFT_CROP, RC )
        3162           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        3163           0 :         CALL HCO_ERROR( 'ERROR 30', RC, THISLOC=LOC )
        3164           0 :         RETURN
        3165             :     ENDIF
        3166             :
        3167             :     ! Copy PFTs into ARRAY_16
        3168           0 :     Inst%ARRAY_16(:,:, 1) = PFT_BARE
        3169           0 :     Inst%ARRAY_16(:,:, 2) = PFT_NDLF_EVGN_TMPT_TREE
        3170           0 :     Inst%ARRAY_16(:,:, 3) = PFT_NDLF_EVGN_BORL_TREE
        3171           0 :     Inst%ARRAY_16(:,:, 4) = PFT_NDLF_DECD_BORL_TREE
        3172           0 :     Inst%ARRAY_16(:,:, 5) = PFT_BDLF_EVGN_TROP_TREE
        3173           0 :     Inst%ARRAY_16(:,:, 6) = PFT_BDLF_EVGN_TMPT_TREE
        3174           0 :     Inst%ARRAY_16(:,:, 7) = PFT_BDLF_DECD_TROP_TREE
        3175           0 :     Inst%ARRAY_16(:,:, 8) = PFT_BDLF_DECD_TMPT_TREE
        3176           0 :     Inst%ARRAY_16(:,:, 9) = PFT_BDLF_DECD_BORL_TREE
        3177           0 :     Inst%ARRAY_16(:,:,10) = PFT_BDLF_EVGN_SHRB
        3178           0 :     Inst%ARRAY_16(:,:,11) = PFT_BDLF_DECD_TMPT_SHRB
        3179           0 :     Inst%ARRAY_16(:,:,12) = PFT_BDLF_DECD_BORL_SHRB
        3180           0 :     Inst%ARRAY_16(:,:,13) = PFT_C3_ARCT_GRSS
        3181           0 :     Inst%ARRAY_16(:,:,14) = PFT_C3_NARC_GRSS
        3182           0 :     Inst%ARRAY_16(:,:,15) = PFT_C4_GRSS
        3183           0 :     Inst%ARRAY_16(:,:,16) = PFT_CROP
        3184             :
        3185             :     ! --------------------------------------------------------------------------------
        3186             :     ! PFT-specific EFs from Table 2 in Guenther et al., 2012
        3187             :     ! in ug compound/m2/h
        3188             :     ! PFTs 1-15 in the table correspond to #2-16
        3189             :     ! (i.e., excluding bare ground #1) in the above array.
        3190             :     ! --------------------------------------------------------------------------------
        3191             :     ! Compound Class EF1 EF2 EF3 EF4 EF5 EF6 EF7 EF8 EF9 EF10 EF11 EF12 EF13 EF14 EF15
        3192             :     ! --------------------------------------------------------------------------------
        3193             :     ! Other Monoterp 180 180 170 150 150 150 150 150 110 200  110  5    5    5    5
        3194             :     ! Methanol       900 900 900 500 900 500 900 900 900 900  900  500  500  500  900
        3195             :     ! Acetone        240 240 240 240 240 240 240 240 240 240  240  80   80   80   80
        3196             :     ! Bidirect VOC   500 500 500 500 500 500 500 500 500 500  500  80   80   80   80
        3197             :     ! Stress VOC     300 300 300 300 300 300 300 300 300 300  300  300  300  300  300
        3198             :     ! Other VOC      140 140 140 140 140 140 140 140 140 140  140  140  140  140  140
        3199             :     ! a-Pinene       500 500 510 600 400 600 400 400 200 300  200    2    2    2    2
        3200             :     ! Myrcene         70  70  60  80  30  80  30  30  30  50   30  0.3  0.3  0.3  0.3
        3201             :     ! a-Farnesene     40  40  40  60  40  60  40  40  40  40   40    3    3    3    4
        3202             :     ! b-Carophyllene  80  80  80  60  40  60  40  40  50  50   50    1    1    1    4
        3203             :     ! Other sesqt.   120 120 120 120 100 120 100 100 100 100  100    2    2    2    2
        3204             :     ! --------------------------------------------------------------------------------
        3205             :
        3206             :     ! One thing to note is these are net emissions to the canopy atmosphere
        3207             :     ! but not net emissions to the above canopy atmosphere since they don't
        3208             :     !  account for within-canopy deposition. Only an issue for OVOCs.
        3209             :
        3210             :     !               EF1       EF2       EF3       EF4       EF5
        3211             :     PFT_EF_OMON = (/180.0_hp, 180.0_hp, 170.0_hp, 150.0_hp, 150.0_hp, &
        3212             :     !               EF6       EF7       EF8       EF9       EF10
        3213             :                     150.0_hp, 150.0_hp, 150.0_hp, 110.0_hp, 200.0_hp, &
        3214             :     !               EF11      EF12      EF13      EF14      EF15
        3215           0 :                     110.0_hp, 5.0_hp  , 5.0_hp  , 5.0_hp  , 5.0_hp/)
        3216             :
        3217             :     !               EF1       EF2       EF3       EF4       EF5
        3218             :     PFT_EF_MOH  = (/900.0_hp, 900.0_hp, 900.0_hp, 500.0_hp, 900.0_hp, &
        3219             :     !               EF6       EF7       EF8       EF9       EF10
        3220             :                     500.0_hp, 900.0_hp, 900.0_hp, 900.0_hp, 900.0_hp, &
        3221             :     !               EF11      EF12      EF13      EF14      EF15
        3222           0 :                     900.0_hp, 500.0_hp, 500.0_hp, 500.0_hp, 900.0_hp/)
        3223             :
        3224             :     !               EF1       EF2       EF3       EF4       EF5
        3225             :     PFT_EF_ACET = (/240.0_hp, 240.0_hp, 240.0_hp, 240.0_hp, 240.0_hp, &
        3226             :     !               EF6       EF7       EF8       EF9       EF10
        3227             :                     240.0_hp, 240.0_hp, 240.0_hp, 240.0_hp, 240.0_hp, &
        3228             :     !               EF11      EF12      EF13      EF14      EF15
        3229           0 :                     240.0_hp, 80.0_hp , 80.0_hp , 80.0_hp , 80.0_hp/)
        3230             :
        3231             :     !               EF1       EF2       EF3       EF4       EF5
        3232             :     PFT_EF_BIDR = (/500.0_hp, 500.0_hp, 500.0_hp, 500.0_hp, 500.0_hp, &
        3233             :     !               EF6       EF7       EF8       EF9       EF10
        3234             :                     500.0_hp, 500.0_hp, 500.0_hp, 500.0_hp, 500.0_hp, &
        3235             :     !               EF11      EF12      EF13      EF14      EF15
        3236           0 :                     500.0_hp, 80.0_hp , 80.0_hp , 80.0_hp , 80.0_hp/)
        3237             :
        3238             :     !               EF1       EF2       EF3       EF4       EF5
        3239             :     PFT_EF_STRS = (/300.0_hp, 300.0_hp, 300.0_hp, 300.0_hp, 300.0_hp, &
        3240             :     !               EF6       EF7       EF8       EF9       EF10
        3241             :                     300.0_hp, 300.0_hp, 300.0_hp, 300.0_hp, 300.0_hp, &
        3242             :     !               EF11      EF12      EF13      EF14      EF15
        3243           0 :                     300.0_hp, 300.0_hp, 300.0_hp, 300.0_hp, 300.0_hp/)
        3244             :
        3245             :     !               EF1       EF2       EF3       EF4       EF5
        3246             :     PFT_EF_OTHR = (/140.0_hp, 140.0_hp, 140.0_hp, 140.0_hp, 140.0_hp, &
        3247             :     !               EF6       EF7       EF8       EF9       EF10
        3248             :                     140.0_hp, 140.0_hp, 140.0_hp, 140.0_hp, 140.0_hp, &
        3249             :     !               EF11      EF12      EF13      EF14      EF15
        3250           0 :                     140.0_hp, 140.0_hp, 140.0_hp, 140.0_hp, 140.0_hp/)
        3251             :
        3252             :     ! ---> Now compute EFs for a-pinene and myrcene as well (dbm, 12/2012)
        3253             :     !               EF1       EF2       EF3       EF4       EF5
        3254             :     PFT_EF_APIN = (/500.0_hp, 500.0_hp, 510.0_hp, 600.0_hp, 400.0_hp, &
        3255             :     !               EF6       EF7       EF8       EF9       EF10
        3256             :                     600.0_hp, 400.0_hp, 400.0_hp, 200.0_hp, 300.0_hp, &
        3257             :     !               EF11      EF12      EF13      EF14      EF15
        3258           0 :                     200.0_hp, 2.0_hp,   2.0_hp,   2.0_hp,   2.0_hp/)
        3259             :
        3260             :     !               EF1       EF2       EF3       EF4       EF5
        3261             :     PFT_EF_MYRC = (/70.0_hp,  70.0_hp,  60.0_hp,  80.0_hp,  30.0_hp, &
        3262             :     !               EF6       EF7       EF8       EF9       EF10
        3263             :                     80.0_hp,  30.0_hp,  30.0_hp,  30.0_hp,  50.0_hp, &
        3264             :     !               EF11      EF12      EF13      EF14      EF15
        3265           0 :                     30.0_hp,  0.3_hp,   0.3_hp,   0.3_hp,   0.3_hp/)
        3266             :     ! <---
        3267             :
        3268             :     !               EF1       EF2       EF3       EF4       EF5
        3269             :     PFT_EF_FARN = (/40.0_hp,  40.0_hp,  40.0_hp,  60.0_hp,  40.0_hp, &
        3270             :     !               EF6       EF7       EF8       EF9       EF10
        3271             :                     60.0_hp,  40.0_hp,  40.0_hp,  40.0_hp,  40.0_hp, &
        3272             :     !               EF11      EF12      EF13      EF14      EF15
        3273           0 :                     40.0_hp,  3.0_hp,   3.0_hp,   3.0_hp,   4.0_hp/)
        3274             :
        3275             :     !               EF1       EF2       EF3       EF4       EF5
        3276             :     PFT_EF_BCAR = (/80.0_hp,  80.0_hp,  80.0_hp,  60.0_hp,  40.0_hp, &
        3277             :     !               EF6       EF7       EF8       EF9       EF10
        3278             :                     60.0_hp,  40.0_hp,  40.0_hp,  50.0_hp,  50.0_hp, &
        3279             :     !               EF11      EF12      EF13      EF14      EF15
        3280           0 :                     50.0_hp,  1.0_hp,   1.0_hp,   1.0_hp,   4.0_hp/)
        3281             :
        3282             :     !               EF1       EF2       EF3       EF4       EF5
        3283             :     PFT_EF_OSQT = (/120.0_hp, 120.0_hp, 120.0_hp, 120.0_hp, 100.0_hp, &
        3284             :     !               EF6       EF7       EF8       EF9       EF10
        3285             :                     120.0_hp, 100.0_hp, 100.0_hp, 100.0_hp, 100.0_hp, &
        3286             :     !               EF11      EF12      EF13      EF14      EF15
        3287           0 :                     100.0_hp, 2.0_hp,   2.0_hp,   2.0_hp,   2.0_hp/)
        3288             :
        3289             :
        3290             :     ! Other monoterpenes, methanol, acetone, MBO are each 100% of thier
        3291             :     ! respective categories. The VOCs within the stress category each
        3292             :     ! account for a specific fraction of emissions across all PFTs
        3293             :     ! (ethene 58%, toluene 3%, HCN 1.5%). The VOCs within the
        3294             :     ! other category also account for a given fraction of emissions
        3295             :     ! across all PFTs (propene 48%, butene 24%, other alkenes 0.2%). But
        3296             :     ! VOCs in the bidirectional category account for a different amount of
        3297             :     ! the total flux for the different PFTs. So in this case we define a
        3298             :     ! vector containing these fractions.
        3299             :
        3300             :     ! Acetaldehyde: 40% of bidirectional category flux, except 25%
        3301             :     ! for grasses and crops
        3302             :     EM_FRAC_ALD2 = (/0.40_hp, 0.40_hp, 0.40_hp, 0.40_hp, 0.40_hp, &
        3303             :                      0.40_hp, 0.40_hp, 0.40_hp, 0.40_hp, 0.40_hp, &
        3304           0 :                      0.40_hp, 0.25_hp, 0.25_hp, 0.25_hp, 0.25_hp/)
        3305             :
        3306             :     ! Ethanol: 40% of bidirectional category flux, except 25%
        3307             :     ! for grasses and crops
        3308             :     EM_FRAC_EOH  = (/0.40_hp, 0.40_hp, 0.40_hp, 0.40_hp, 0.40_hp, &
        3309             :                      0.40_hp, 0.40_hp, 0.40_hp, 0.40_hp, 0.40_hp, &
        3310           0 :                      0.40_hp, 0.25_hp, 0.25_hp, 0.25_hp, 0.25_hp/)
        3311             :
        3312             :     ! Formic acid: 6% of bidirectional category flux, except 15%
        3313             :     ! for grasses and crops
        3314             :     EM_FRAC_FAXX = (/0.06_hp, 0.06_hp, 0.06_hp, 0.06_hp, 0.06_hp, &
        3315             :                      0.06_hp, 0.06_hp, 0.06_hp, 0.06_hp, 0.06_hp, &
        3316           0 :                      0.06_hp, 0.15_hp, 0.15_hp, 0.15_hp, 0.15_hp/)
        3317             :
        3318             :     ! Acetic acid: 6% of bidirectional category flux, except 15%
        3319             :     ! for grasses and crops
        3320             :     EM_FRAC_AAXX = (/0.06_hp, 0.06_hp, 0.06_hp, 0.06_hp, 0.06_hp, &
        3321             :                      0.06_hp, 0.06_hp, 0.06_hp, 0.06_hp, 0.06_hp, &
        3322           0 :                      0.06_hp, 0.15_hp, 0.15_hp, 0.15_hp, 0.15_hp/)
        3323             :
        3324             :     ! Formaldehyde: 8% of bidirectional category flux, except 20%
        3325             :     ! for grasses and crops
        3326             :     EM_FRAC_CH2O = (/0.08_hp, 0.08_hp, 0.08_hp, 0.08_hp, 0.08_hp, &
        3327             :                      0.08_hp, 0.08_hp, 0.08_hp, 0.08_hp, 0.08_hp, &
        3328           0 :                      0.08_hp, 0.20_hp, 0.20_hp, 0.20_hp, 0.20_hp/)
        3329             :
        3330             :     ! Set AEF arrays to zero
        3331           0 :     Inst%AEF_APIN(:,:) = 0.0_hp
        3332           0 :     Inst%AEF_MYRC(:,:) = 0.0_hp
        3333           0 :     Inst%AEF_OMON(:,:) = 0.0_hp
        3334           0 :     Inst%AEF_FARN(:,:) = 0.0_hp
        3335           0 :     Inst%AEF_BCAR(:,:) = 0.0_hp
        3336           0 :     Inst%AEF_OSQT(:,:) = 0.0_hp
        3337           0 :     Inst%AEF_MOH (:,:) = 0.0_hp
        3338           0 :     Inst%AEF_ACET(:,:) = 0.0_hp
        3339           0 :     Inst%AEF_EOH (:,:) = 0.0_hp
        3340           0 :     Inst%AEF_CH2O(:,:) = 0.0_hp
        3341           0 :     Inst%AEF_ALD2(:,:) = 0.0_hp
        3342           0 :     Inst%AEF_FAXX(:,:) = 0.0_hp
        3343           0 :     Inst%AEF_AAXX(:,:) = 0.0_hp
        3344           0 :     Inst%AEF_C2H4(:,:) = 0.0_hp
        3345           0 :     Inst%AEF_TOLU(:,:) = 0.0_hp
        3346           0 :     Inst%AEF_HCNX(:,:) = 0.0_hp
        3347           0 :     Inst%AEF_PRPE(:,:) = 0.0_hp
        3348             :
        3349             :     ! Loop through plant types
        3350           0 :     DO P = 1, 15
        3351             :
        3352             :        ! Add 1 to Array_16 index to skip bare ground
        3353           0 :        ARR_IND = P + 1
        3354             :
        3355             :        ! Don't need to divide ARRAY_16 by 100 since data from netCDF
        3356             :        ! file has already been converted to fraction (mps, 2/12/15)
        3357             :
        3358             :        ! ---> Now compute EFs for a-pinene and myrcene as well (dbm, 12/2012)
        3359             :        ! a-pinene: 100% of category
        3360             :        Inst%AEF_APIN(:,:) = Inst%AEF_APIN(:,:) + &
        3361           0 :             Inst%ARRAY_16(:,:,ARR_IND) * PFT_EF_APIN(P)
        3362             :
        3363             :        ! Myrcene: 100% of category
        3364             :        Inst%AEF_MYRC(:,:) = Inst%AEF_MYRC(:,:) + &
        3365           0 :             Inst%ARRAY_16(:,:,ARR_IND) * PFT_EF_MYRC(P)
        3366             :        ! <---
        3367             :
        3368             :        ! Other monoterpenes: 100% of category
        3369             :        Inst%AEF_OMON(:,:) = Inst%AEF_OMON(:,:) + &
        3370           0 :             Inst%ARRAY_16(:,:,ARR_IND) * PFT_EF_OMON(P)
        3371             :
        3372             :        ! a-Farnesene: 100% of category
        3373             :        Inst%AEF_FARN(:,:) = Inst%AEF_FARN(:,:) + &
        3374           0 :             Inst%ARRAY_16(:,:,ARR_IND) * PFT_EF_FARN(P)
        3375             :
        3376             :        ! b-Caryophyllene: 100% of category
        3377             :        Inst%AEF_BCAR(:,:) = Inst%AEF_BCAR(:,:) + &
        3378           0 :             Inst%ARRAY_16(:,:,ARR_IND) * PFT_EF_BCAR(P)
        3379             :
        3380             :        ! Other sesquiterpenes: 100% of category
        3381             :        Inst%AEF_OSQT(:,:) = Inst%AEF_OSQT(:,:) + &
        3382           0 :             Inst%ARRAY_16(:,:,ARR_IND) * PFT_EF_OSQT(P)
        3383             :
        3384             :        ! Methanol: 100% of category
        3385             :        Inst%AEF_MOH(:,:) = Inst%AEF_MOH(:,:) + &
        3386           0 :             Inst%ARRAY_16(:,:,ARR_IND) * PFT_EF_MOH(P)
        3387             :
        3388             :        ! Acetone: 100% of category
        3389             :        Inst%AEF_ACET(:,:) = Inst%AEF_ACET(:,:) + &
        3390           0 :             Inst%ARRAY_16(:,:,ARR_IND) * PFT_EF_ACET(P)
        3391             :
        3392             :        ! Ethanol: variable fraction of category
        3393             :        Inst%AEF_EOH(:,:) = Inst%AEF_EOH(:,:) + &
        3394           0 :             Inst%ARRAY_16(:,:,ARR_IND)*PFT_EF_BIDR(P)*EM_FRAC_EOH(P)
        3395             :
        3396             :        ! Formaldehyde: variable fraction of category
        3397             :        Inst%AEF_CH2O(:,:) = Inst%AEF_CH2O(:,:) + &
        3398           0 :             Inst%ARRAY_16(:,:,ARR_IND)*PFT_EF_BIDR(P)*EM_FRAC_CH2O(P)
        3399             :
        3400             :        ! Acetaldehyde: variable fraction of category
        3401             :        Inst%AEF_ALD2(:,:) = Inst%AEF_ALD2(:,:) + &
        3402           0 :             Inst%ARRAY_16(:,:,ARR_IND)*PFT_EF_BIDR(P)*EM_FRAC_ALD2(P)
        3403             :
        3404             :        ! Formic acid: variable fraction of category
        3405             :        Inst%AEF_FAXX(:,:) = Inst%AEF_FAXX(:,:) + &
        3406           0 :             Inst%ARRAY_16(:,:,ARR_IND)*PFT_EF_BIDR(P)*EM_FRAC_FAXX(P)
        3407             :
        3408             :        ! Acetic acid: variable fraction of category
        3409             :        Inst%AEF_AAXX(:,:) = Inst%AEF_AAXX(:,:) + &
        3410           0 :             Inst%ARRAY_16(:,:,ARR_IND)*PFT_EF_BIDR(P)*EM_FRAC_AAXX(P)
        3411             :
        3412             :        ! Ethene: 58% of "stress" category for all PFTs
        3413             :        Inst%AEF_C2H4(:,:) = Inst%AEF_C2H4(:,:) + &
        3414           0 :             Inst%ARRAY_16(:,:,ARR_IND) * PFT_EF_STRS(P) * 0.58_hp
        3415             :
        3416             :        ! Toluene: 3% of "stress" category for all PFTs
        3417             :        Inst%AEF_TOLU(:,:) = Inst%AEF_TOLU(:,:) + &
        3418           0 :             Inst%ARRAY_16(:,:,ARR_IND) * PFT_EF_STRS(P) * 0.03_hp
        3419             :
        3420             :        ! HCN: 1.5% of "stress" category for all PFTs
        3421             :        Inst%AEF_HCNX(:,:) = Inst%AEF_HCNX(:,:) + &
        3422           0 :             Inst%ARRAY_16(:,:,ARR_IND) * PFT_EF_STRS(P) * 0.015_hp
        3423             :
        3424             :        ! Propene: 48% of "other" category for all PFTs
        3425             :        ! Butene:  24% of "other" category for all PFTs
        3426             :        ! Larger alkenes: 0.2% of "other" category for all PFTs
        3427             :        ! Total: 72.2%
        3428             :        Inst%AEF_PRPE(:,:) = Inst%AEF_PRPE(:,:) + &
        3429           0 :             Inst%ARRAY_16(:,:,ARR_IND) * PFT_EF_OTHR(P) * 0.722_hp
        3430             :
        3431             :     ENDDO
        3432             :
        3433             :     ! Convert AEF arrays from [ug/m2/hr] to [kg/m2/s]
        3434           0 :     FACTOR = 1.0e-9_hp / 3600.0_hp
        3435           0 :     Inst%AEF_APIN = Inst%AEF_APIN * FACTOR
        3436           0 :     Inst%AEF_MYRC = Inst%AEF_MYRC * FACTOR
        3437           0 :     Inst%AEF_OMON = Inst%AEF_OMON * FACTOR
        3438           0 :     Inst%AEF_FARN = Inst%AEF_FARN * FACTOR
        3439           0 :     Inst%AEF_BCAR = Inst%AEF_BCAR * FACTOR
        3440           0 :     Inst%AEF_OSQT = Inst%AEF_OSQT * FACTOR
        3441           0 :     Inst%AEF_ACET = Inst%AEF_ACET * FACTOR
        3442           0 :     Inst%AEF_EOH  = Inst%AEF_EOH  * FACTOR
        3443           0 :     Inst%AEF_ALD2 = Inst%AEF_ALD2 * FACTOR
        3444           0 :     Inst%AEF_C2H4 = Inst%AEF_C2H4 * FACTOR
        3445           0 :     Inst%AEF_TOLU = Inst%AEF_TOLU * FACTOR
        3446           0 :     Inst%AEF_PRPE = Inst%AEF_PRPE * FACTOR
        3447           0 :     Inst%AEF_MOH  = Inst%AEF_MOH  * FACTOR
        3448           0 :     Inst%AEF_CH2O = Inst%AEF_CH2O * FACTOR
        3449           0 :     Inst%AEF_FAXX = Inst%AEF_FAXX * FACTOR
        3450           0 :     Inst%AEF_AAXX = Inst%AEF_AAXX * FACTOR
        3451           0 :     Inst%AEF_HCNX = Inst%AEF_HCNX * FACTOR
        3452             :
        3453             :     ! Return w/ success
        3454           0 :     RC = HCO_SUCCESS
        3455             :
        3456             :   END SUBROUTINE CALC_AEF
        3457             : !EOC
        3458             : !------------------------------------------------------------------------------
        3459             : !                   Harmonized Emissions Component (HEMCO)                    !
        3460             : !------------------------------------------------------------------------------
        3461             : !BOP
        3462             : !
        3463             : ! !IROUTINE: HCOX_Megan_Init
        3464             : !
        3465             : ! !DESCRIPTION: Subroutine HCOX\_Megan\_Init allocates and initializes all
        3466             : !  module arrays.
        3467             : !\\
        3468             : !\\
        3469             : ! !INTERFACE:
        3470             : !
        3471           0 :   SUBROUTINE HCOX_Megan_Init( HcoState, ExtName, ExtState, RC )
        3472             : !
        3473             : ! !USES:
        3474             : !
        3475             :     USE HCO_STATE_MOD,    ONLY : Hco_GetHcoID
        3476             :     USE HCO_STATE_MOD,    ONLY : HCO_GetExtHcoID
        3477             :     USE HCO_ExtList_Mod,  ONLY : GetExtNr, GetExtOpt
        3478             :     USE HCO_Restart_Mod,  ONLY : HCO_RestartDefine
        3479             : !
        3480             : ! !INPUT PARAMETERS:
        3481             : !
        3482             :     TYPE(HCO_State),  POINTER        :: HcoState
        3483             :     CHARACTER(LEN=*), INTENT(IN   )  :: ExtName
        3484             :     TYPE(Ext_State),  POINTER        :: ExtState
        3485             : !
        3486             : ! !INPUT/OUTPUT PARAMETERS:
        3487             : !
        3488             :     INTEGER, INTENT(INOUT)           :: RC
        3489             : !
        3490             : ! !REVISION HISTORY:
        3491             : !  05 Aug 2013 - C. Keller   - Initial version
        3492             : !  See https://github.com/geoschem/hemco for complete history
        3493             : !EOP
        3494             : !------------------------------------------------------------------------------
        3495             : !BOC
        3496             : !
        3497             : ! !LOCAL VARIABLES:
        3498             : !
        3499             :     INTEGER                        :: ExtNr, iExtNr
        3500             :     INTEGER                        :: I, nSpc, AS, NX, NY
        3501           0 :     INTEGER, ALLOCATABLE           :: HcoIDs(:)
        3502             :     LOGICAL                        :: FOUND
        3503             :     REAL*8                         :: PI_180
        3504           0 :     REAL(hp), POINTER              :: Ptr2D(:,:)
        3505             :     TYPE(MyInst), POINTER          :: Inst
        3506             :     CHARACTER(LEN=255)             :: MSG, LOC
        3507           0 :     CHARACTER(LEN=31), ALLOCATABLE :: SpcNames(:)
        3508             :     LOGICAL                        :: Optfound
        3509             :
        3510             :     !=================================================================
        3511             :     ! HCOX_MEGAN_INIT begins here!
        3512             :     !=================================================================
        3513           0 :     LOC = 'HCOX_MEGAN_INIT (HCOX_MEGAN_MOD.F90)'
        3514             :
        3515             :     ! Extension Nr.
        3516           0 :     ExtNr = GetExtNr( HcoState%Config%ExtList, TRIM(ExtName) )
        3517           0 :     IF ( ExtNr <= 0 ) RETURN
        3518             :
        3519             :     ! Enter
        3520           0 :     CALL HCO_ENTER( HcoState%Config%Err, LOC, RC )
        3521           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        3522           0 :         CALL HCO_ERROR( 'ERROR 31', RC, THISLOC=LOC )
        3523           0 :         RETURN
        3524             :     ENDIF
        3525             :
        3526             :     ! Nullify
        3527           0 :     Ptr2D => NULL()
        3528           0 :     Inst  => NULL()
        3529             :
        3530             :     ! Create an instance for this extension
        3531           0 :     CALL InstCreate ( ExtNr, ExtState%Megan, Inst, RC )
        3532           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        3533             :        CALL HCO_ERROR ( &
        3534           0 :                        'Cannot create MEGAN instance', RC )
        3535           0 :        RETURN
        3536             :     ENDIF
        3537             :
        3538             :     ! Check to see if offline biogenic VOCs are used. If so, those
        3539             :     ! will be used in place of online MEGAN emissions (mps, 12/17/19).
        3540           0 :     Inst%OFFLINE_BIOGENICVOC = .FALSE.
        3541             :     CALL GetExtOpt( HcoState%Config, 0, 'OFFLINE_BIOGENICVOC', &
        3542           0 :                     OptValBool=OptFound, Found=FOUND, RC=RC )
        3543           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        3544           0 :         CALL HCO_ERROR( 'ERROR 32', RC, THISLOC=LOC )
        3545           0 :         RETURN
        3546             :     ENDIF
        3547           0 :     IF ( FOUND ) Inst%OFFLINE_BIOGENICVOC = OptFound
        3548             :
        3549             :     ! Verbose mode
        3550           0 :     IF ( HcoState%amIRoot) THEN
        3551             :
        3552             :        ! Write the name of the extension regardless of the verbose setting
        3553           0 :        msg = 'Using HEMCO extension: MEGAN (biogenic emissions)'
        3554           0 :        IF ( HCO_IsVerb( HcoState%Config%Err ) ) THEN
        3555           0 :           CALL HCO_Msg( HcoState%Config%Err, msg, sep1='-' ) ! with separator
        3556             :        ELSE
        3557           0 :           CALL HCO_Msg( msg, verb=.TRUE.                   ) ! w/o separator
        3558             :        ENDIF
        3559             :
        3560             :        ! Write all other messages as debug printout only
        3561           0 :        WRITE(MSG,*) '- Use offline biogenic VOCs? ', Inst%OFFLINE_BIOGENICVOC
        3562           0 :        CALL HCO_MSG( HcoState%Config%Err, MSG )
        3563             :     ENDIF
        3564             :
        3565             :     !-----------------------------------------------------------------
        3566             :     ! Read settings
        3567             :     !-----------------------------------------------------------------
        3568             :
        3569             :     ! Read settings specified in configuration file
        3570             :     ! Note: the specified strings have to match those in
        3571             :     !       the config. file!
        3572             :     CALL GetExtOpt( HcoState%Config, ExtNr, 'Isoprene scaling', &
        3573           0 :                     OptValHp=Inst%ISOP_SCALING, RC=RC )
        3574           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        3575           0 :         CALL HCO_ERROR( 'ERROR 33', RC, THISLOC=LOC )
        3576           0 :         RETURN
        3577             :     ENDIF
        3578             :     CALL GetExtOpt( HcoState%Config, ExtNr, 'CO2 inhibition', &
        3579           0 :                     OptValBool=Inst%LISOPCO2, RC=RC )
        3580           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        3581           0 :         CALL HCO_ERROR( 'ERROR 34', RC, THISLOC=LOC )
        3582           0 :         RETURN
        3583             :     ENDIF
        3584             :     CALL GetExtOpt( HcoState%Config, ExtNr, 'CO2 conc (ppmv)', &
        3585           0 :                     OptValHp=Inst%GLOBCO2, RC=RC )
        3586           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        3587           0 :         CALL HCO_ERROR( 'ERROR 35', RC, THISLOC=LOC )
        3588           0 :         RETURN
        3589             :     ENDIF
        3590             :
        3591             :     ! Normalize LAI by PFT? Default setting is 'yes'
        3592             :     ! ckeller, 7/17/17.
        3593           0 :     Inst%NORMLAI = .TRUE.
        3594             :     CALL GetExtOpt( HcoState%Config, ExtNr, 'Normalize LAI', &
        3595           0 :                     OptValBool=OptFound, Found=FOUND, RC=RC )
        3596           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        3597           0 :         CALL HCO_ERROR( 'ERROR 36', RC, THISLOC=LOC )
        3598           0 :         RETURN
        3599             :     ENDIF
        3600           0 :     IF ( FOUND ) Inst%NORMLAI = OptFound
        3601             :
        3602             :     ! Check GLOBCO2 if CO2 inhibition is turned on (LISOPCO2 = .TRUE.)
        3603             :     ! GLOBCO2 should be between 150-1250 ppmv. Isoprene response to
        3604             :     ! CO2 outside this range has no empirical basis. (Tai, Jan 2013)
        3605           0 :     IF ( Inst%LISOPCO2 ) THEN
        3606           0 :        IF ( Inst%GLOBCO2 <  150.0_hp .OR. &
        3607             :             Inst%GLOBCO2 > 1250.0_hp     ) THEN
        3608           0 :           MSG = 'Global CO2 outside valid range of 150-1250 ppmv!'
        3609           0 :           CALL HCO_ERROR(MSG, RC )
        3610           0 :           RETURN
        3611             :        ENDIF
        3612             :     ENDIF
        3613             :
        3614           0 :     Optfound = .FALSE.
        3615             :     !optional arguments for SOAP
        3616             :     CALL GetExtOpt ( HcoState%Config, ExtNr, 'Isoprene to SOAP', &
        3617           0 :                      OptValHp=Inst%ISOPTOSOAP, FOUND=Optfound, RC=RC )
        3618           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        3619           0 :         CALL HCO_ERROR( 'ERROR 37', RC, THISLOC=LOC )
        3620           0 :         RETURN
        3621             :     ENDIF
        3622           0 :     IF ( Optfound ) THEN
        3623             :        !convert from carbon basis to mass basis
        3624           0 :        Inst%ISOPTOSOAP = Inst%ISOPTOSOAP * 1.134
        3625             :     ELSE
        3626             :        !set to zero if not specified
        3627           0 :        Inst%ISOPTOSOAP = 0.0
        3628             :     ENDIF
        3629             :
        3630           0 :     Optfound = .FALSE.
        3631             :     !optional arguments for SOAS
        3632             :     CALL GetExtOpt ( HcoState%Config, ExtNr, 'Isoprene to SOAS', &
        3633           0 :                      OptValHp=Inst%ISOPTOSOAS, FOUND=Optfound, RC=RC )
        3634           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        3635           0 :         CALL HCO_ERROR( 'ERROR 38', RC, THISLOC=LOC )
        3636           0 :         RETURN
        3637             :     ENDIF
        3638           0 :     IF ( Optfound ) THEN
        3639             :        !convert from carbon basis to mass basis
        3640           0 :        Inst%ISOPTOSOAS = Inst%ISOPTOSOAS * 1.134
        3641             :     ELSE
        3642             :        !set to zero if not specified
        3643           0 :        Inst%ISOPTOSOAS = 0.0
        3644             :     ENDIF
        3645             :
        3646           0 :     Optfound = .FALSE.
        3647             :     CALL GetExtOpt ( HcoState%Config, Inst%ExtNr, 'Monoterp to SOAP', &
        3648           0 :                      OptValHp=Inst%MONOTOSOAP, FOUND=Optfound, RC=RC )
        3649           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        3650           0 :         CALL HCO_ERROR( 'ERROR 39', RC, THISLOC=LOC )
        3651           0 :         RETURN
        3652             :     ENDIF
        3653           0 :     IF ( Optfound ) THEN
        3654             :        !convert from carbon basis to mass basis
        3655             :        Inst%MONOTOSOAP = Inst%MONOTOSOAP ! * 1.134
        3656             :     ELSE
        3657             :        !set to zero if not specified
        3658           0 :        Inst%MONOTOSOAP = 0.0
        3659             :     ENDIF
        3660             :
        3661           0 :     Optfound = .FALSE.
        3662             :     CALL GetExtOpt ( HcoState%Config, Inst%ExtNr, 'Monoterp to SOAS', &
        3663           0 :                      OptValHp=Inst%MONOTOSOAS, FOUND=Optfound, RC=RC )
        3664           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        3665           0 :         CALL HCO_ERROR( 'ERROR 40', RC, THISLOC=LOC )
        3666           0 :         RETURN
        3667             :     ENDIF
        3668           0 :     IF ( Optfound ) THEN
        3669             :        !convert from carbon basis to mass basis
        3670             :        Inst%MONOTOSOAS = Inst%MONOTOSOAS ! * 1.134
        3671             :     ELSE
        3672             :        !set to zero if not specified
        3673           0 :        Inst%MONOTOSOAS = 0.0
        3674             :     ENDIF
        3675             :
        3676           0 :     Optfound = .FALSE.
        3677             :     CALL GetExtOpt ( HcoState%Config, Inst%ExtNr, 'Othrterp to SOAP', &
        3678           0 :                      OptValHp=Inst%OTHRTOSOAP, FOUND=Optfound, RC=RC )
        3679           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        3680           0 :         CALL HCO_ERROR( 'ERROR 41', RC, THISLOC=LOC )
        3681           0 :         RETURN
        3682             :     ENDIF
        3683           0 :     IF ( Optfound ) THEN
        3684             :        !convert from carbon basis to mass basis
        3685           0 :        Inst%OTHRTOSOAP = Inst%OTHRTOSOAP * 1.134
        3686             :     ELSE
        3687             :        !set to zero if not specified
        3688           0 :        Inst%OTHRTOSOAP = 0.0
        3689             :     ENDIF
        3690             :
        3691           0 :     Optfound = .FALSE.
        3692             :     CALL GetExtOpt ( HcoState%Config, Inst%ExtNr, 'Othrterp to SOAS', &
        3693           0 :                      OptValHp=Inst%OTHRTOSOAS, FOUND=Optfound, RC=RC )
        3694           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        3695           0 :         CALL HCO_ERROR( 'ERROR 42', RC, THISLOC=LOC )
        3696           0 :         RETURN
        3697             :     ENDIF
        3698           0 :     IF ( Optfound ) THEN
        3699             :        !convert from carbon basis to mass basis
        3700           0 :        Inst%OTHRTOSOAS = Inst%OTHRTOSOAS * 1.134
        3701             :     ELSE
        3702             :        !set to zero if not specified
        3703           0 :        Inst%OTHRTOSOAS = 0.0
        3704             :     ENDIF
        3705             :
        3706             :     !-----------------------------------------------------------------
        3707             :     ! Set species IDs
        3708             :     !-----------------------------------------------------------------
        3709             :
        3710             :     ! Verbose mode
        3711           0 :     IF ( HcoState%amIRoot ) THEN
        3712           0 :        MSG = ' - Use the following species:'
        3713           0 :        CALL HCO_MSG( HcoState%Config%Err, MSG )
        3714             :     ENDIF
        3715             :
        3716             :     ! Get species IDs
        3717             :     ! --> Assume that species are ordered ISOP, ACET, PRPE, C2H4 in
        3718             :     !     config. file!
        3719           0 :     CALL HCO_GetExtHcoID( HcoState, ExtNr, HcoIDs, SpcNames, nSpc, RC)
        3720           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        3721           0 :         CALL HCO_ERROR( 'ERROR 43', RC, THISLOC=LOC )
        3722           0 :         RETURN
        3723             :     ENDIF
        3724             :
        3725             :     ! Assign species IDs
        3726           0 :     Inst%IDTISOP = -1
        3727           0 :     Inst%IDTACET = -1
        3728           0 :     Inst%IDTPRPE = -1
        3729           0 :     Inst%IDTC2H4 = -1
        3730           0 :     Inst%IDTALD2 = -1
        3731           0 :     Inst%IDTMOH  = -1
        3732           0 :     Inst%IDTEOH  = -1
        3733           0 :     Inst%IDTSOAP = -1
        3734           0 :     Inst%IDTSOAS = -1
        3735           0 :     Inst%IDTMTPA = -1
        3736           0 :     Inst%IDTMTPO = -1
        3737           0 :     Inst%IDTLIMO = -1
        3738           0 :     Inst%IDTSESQ = -1
        3739           0 :     DO I = 1, nSpc
        3740           0 :        SELECT CASE ( TRIM(SpcNames(I)) )
        3741             :        CASE( 'ISOP' )
        3742           0 :           IF ( .not. Inst%OFFLINE_BIOGENICVOC ) THEN
        3743           0 :              Inst%IDTISOP = HcoIDs(I)
        3744           0 :              WRITE(MSG,*) '   Isoprene   = ',TRIM(SpcNames(I)),Inst%IDTISOP
        3745             :           ELSE
        3746             :              WRITE(MSG,*) '   Isoprene will be obtained from ' // &
        3747           0 :                           'offline biogenic VOC emissions'
        3748             :           ENDIF
        3749             :        CASE( 'ACET' )
        3750           0 :           IF ( .not. Inst%OFFLINE_BIOGENICVOC ) THEN
        3751           0 :              Inst%IDTACET = HcoIDs(I)
        3752           0 :              WRITE(MSG,*) '   Acetone    = ',TRIM(SpcNames(I)),Inst%IDTACET
        3753             :           ELSE
        3754             :              WRITE(MSG,*) '   Acetone will be obtained from ' // &
        3755           0 :                           'offline biogenic VOC emissions'
        3756             :           ENDIF
        3757             :        CASE( 'PRPE' )
        3758           0 :           IF ( .not. Inst%OFFLINE_BIOGENICVOC ) THEN
        3759           0 :              Inst%IDTPRPE = HcoIDs(I)
        3760           0 :              WRITE(MSG,*) '   PRPE       = ',TRIM(SpcNames(I)),Inst%IDTPRPE
        3761             :           ELSE
        3762             :              WRITE(MSG,*) '   PRPE will be obtained from ' // &
        3763           0 :                           'offline biogenic VOC emissions'
        3764             :           ENDIF
        3765             :        CASE( 'ALD2' )
        3766           0 :           IF ( .not. Inst%OFFLINE_BIOGENICVOC ) THEN
        3767           0 :              Inst%IDTALD2 = HcoIDs(I)
        3768           0 :              WRITE(MSG,*) '   ALD2       = ',TRIM(SpcNames(I)),Inst%IDTALD2
        3769             :           ELSE
        3770             :              WRITE(MSG,*) '   ALD2 will be obtained from ' // &
        3771           0 :                           'offline biogenic VOC emissions'
        3772             :           ENDIF
        3773             :        CASE( 'MOH' )
        3774           0 :           IF ( .not. Inst%OFFLINE_BIOGENICVOC ) THEN
        3775           0 :              Inst%IDTMOH  = HcoIDs(I)
        3776           0 :              WRITE(MSG,*) '   MOH        = ',TRIM(SpcNames(I)),Inst%IDTMOH
        3777             :           ELSE
        3778             :              WRITE(MSG,*) '   MOH will be obtained from ' // &
        3779           0 :                           'offline biogenic VOC emissions'
        3780             :           ENDIF
        3781             :        CASE( 'EOH' )
        3782           0 :           IF ( .not. Inst%OFFLINE_BIOGENICVOC ) THEN
        3783           0 :              Inst%IDTEOH  = HcoIDs(I)
        3784           0 :              WRITE(MSG,*) '   EOH        = ',TRIM(SpcNames(I)),Inst%IDTEOH
        3785             :           ELSE
        3786             :              WRITE(MSG,*) '   EOH will be obtained from ' // &
        3787           0 :                           'offline biogenic VOC emissions'
        3788             :           ENDIF
        3789             :        CASE( 'C2H4' )
        3790           0 :           IF ( .not. Inst%OFFLINE_BIOGENICVOC ) THEN
        3791           0 :              Inst%IDTC2H4 = HcoIDs(I)
        3792           0 :              WRITE(MSG,*) '   C2H4       = ',TRIM(SpcNames(I)),Inst%IDTC2H4
        3793             :           ELSE
        3794             :              WRITE(MSG,*) '   C2H4 will be obtained from ' // &
        3795           0 :                           'offline biogenic VOC emissions'
        3796             :           ENDIF
        3797             :        CASE( 'SOAP' )
        3798           0 :           IF ( .not. Inst%OFFLINE_BIOGENICVOC ) THEN
        3799           0 :              Inst%IDTSOAP = HcoIDs(I)
        3800           0 :              WRITE(MSG,*) '   SOAP       = ',TRIM(SpcNames(I)),Inst%IDTSOAP
        3801             :           ELSE
        3802             :              WRITE(MSG,*) '   SOAP will be obtained from ' // &
        3803           0 :                           'offline biogenic VOC emissions'
        3804             :           ENDIF
        3805             :        CASE( 'SOAS' )
        3806           0 :           IF ( .not. Inst%OFFLINE_BIOGENICVOC ) THEN
        3807           0 :              Inst%IDTSOAS = HcoIDs(I)
        3808           0 :              WRITE(MSG,*) '   SOAS       = ',TRIM(SpcNames(I)),Inst%IDTSOAS
        3809             :           ELSE
        3810             :              WRITE(MSG,*) '   SOAS will be obtained from ' // &
        3811           0 :                           'offline biogenic VOC emissions'
        3812             :           ENDIF
        3813             :        CASE( 'MTPA' )
        3814           0 :           IF ( .not. Inst%OFFLINE_BIOGENICVOC ) THEN
        3815           0 :              Inst%IDTMTPA = HcoIDs(I)
        3816           0 :              WRITE(MSG,*) '   MTPA       = ',TRIM(SpcNames(I)),Inst%IDTMTPA
        3817             :           ELSE
        3818             :              WRITE(MSG,*) '   MTPA will be obtained from ' // &
        3819           0 :                           'offline biogenic VOC emissions'
        3820             :           ENDIF
        3821             :        CASE( 'MTPO' )
        3822           0 :           IF ( .not. Inst%OFFLINE_BIOGENICVOC ) THEN
        3823           0 :              Inst%IDTMTPO = HcoIDs(I)
        3824           0 :              WRITE(MSG,*) '   MTPO       = ',TRIM(SpcNames(I)),Inst%IDTMTPO
        3825             :           ELSE
        3826             :              WRITE(MSG,*) '   MTPO will be obtained from ' // &
        3827           0 :                           'offline biogenic VOC emissions'
        3828             :           ENDIF
        3829             :        CASE( 'LIMO' )
        3830           0 :           IF ( .not. Inst%OFFLINE_BIOGENICVOC ) THEN
        3831           0 :              Inst%IDTLIMO = HcoIDs(I)
        3832           0 :              WRITE(MSG,*) '   LIMO       = ',TRIM(SpcNames(I)),Inst%IDTLIMO
        3833             :           ELSE
        3834             :              WRITE(MSG,*) '   LIMO will be obtained from ' // &
        3835           0 :                           'offline biogenic VOC emissions'
        3836             :           ENDIF
        3837             :        CASE( 'SESQ' )
        3838           0 :           IF ( .not. Inst%OFFLINE_BIOGENICVOC ) THEN
        3839           0 :              Inst%IDTSESQ = HcoIDs(I)
        3840           0 :              WRITE(MSG,*) '   SESQ       = ',TRIM(SpcNames(I)),Inst%IDTSESQ
        3841             :           ELSE
        3842             :              WRITE(MSG,*) '   SESQ will be obtained from ' // &
        3843           0 :                           'offline biogenic VOC emissions'
        3844             :           ENDIF
        3845             :        CASE DEFAULT
        3846           0 :           MSG = 'Invalid species names: ' // TRIM(SpcNames(I))
        3847           0 :           CALL HCO_ERROR(MSG, RC )
        3848           0 :           RETURN
        3849             :        END SELECT
        3850             :
        3851             :        ! Verbose
        3852           0 :        IF ( HcoState%amIRoot ) CALL HCO_MSG( HcoState%Config%Err, MSG )
        3853             :     ENDDO
        3854             :
        3855             :     ! Verbose mode
        3856           0 :     IF ( HcoState%amIRoot ) THEN
        3857           0 :        WRITE(MSG,*) ' --> Isoprene scale factor is ',Inst%ISOP_SCALING
        3858           0 :        CALL HCO_MSG( HcoState%Config%Err, MSG )
        3859           0 :        WRITE(MSG,*) ' --> Use CO2 inhibition on isoprene option ', &
        3860           0 :                     Inst%LISOPCO2
        3861           0 :        CALL HCO_MSG( HcoState%Config%Err, MSG )
        3862           0 :        WRITE(MSG,*) ' --> Global atmospheric CO2 concentration : ', &
        3863           0 :                     Inst%GLOBCO2, ' ppmv'
        3864           0 :        CALL HCO_MSG( HcoState%Config%Err, MSG )
        3865           0 :        WRITE(MSG,*) ' --> Normalize LAI by PFT: ', &
        3866           0 :                     Inst%NORMLAI
        3867           0 :        CALL HCO_MSG( HcoState%Config%Err, MSG )
        3868           0 :        WRITE(MSG,*) ' --> Isoprene to SOA-Precursor', &
        3869             :                     !convert back to direct mass basis just for show
        3870           0 :                     Inst%ISOPTOSOAP / 1.134
        3871           0 :        CALL HCO_MSG( HcoState%Config%Err, MSG )
        3872           0 :        WRITE(MSG,*) ' --> Isoprene direct to SOA (Simple)', &
        3873             :                     !convert back to direct mass basis just for show
        3874           0 :                     Inst%ISOPTOSOAS / 1.134
        3875           0 :        CALL HCO_MSG( HcoState%Config%Err, MSG )
        3876           0 :        WRITE(MSG,*) ' --> Monoterpene to SOA-Precursor', &
        3877             :                     !convert back to direct mass basis just for show
        3878           0 :                     Inst%MONOTOSOAP / 1.134
        3879           0 :        CALL HCO_MSG( HcoState%Config%Err, MSG )
        3880           0 :        WRITE(MSG,*) ' --> Monoterpene direct to SOA (Simple)', &
        3881             :                     !convert back to direct mass basis just for show
        3882           0 :                     Inst%MONOTOSOAS / 1.134
        3883           0 :        CALL HCO_MSG( HcoState%Config%Err, MSG )
        3884           0 :        WRITE(MSG,*) ' --> Othrterpene to SOA-Precursor', &
        3885             :                     !convert back to direct mass basis just for show
        3886           0 :                     Inst%OTHRTOSOAP / 1.134
        3887           0 :        CALL HCO_MSG( HcoState%Config%Err, MSG )
        3888           0 :        WRITE(MSG,*) ' --> Othrterpene direct to SOA (Simple)', &
        3889             :                     !convert back to direct mass basis just for show
        3890           0 :                     Inst%OTHRTOSOAS / 1.134
        3891           0 :        CALL HCO_MSG( HcoState%Config%Err, MSG )
        3892             :     ENDIF
        3893             :
        3894             :     CALL GetExtOpt( HcoState%Config, ExtNr, 'MEGAN_SUFFIX', &
        3895           0 :                     OptValChar=Inst%SUFFIX, FOUND=FOUND, RC=RC )
        3896           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        3897           0 :         CALL HCO_ERROR( 'ERROR 44', RC, THISLOC=LOC )
        3898           0 :         RETURN
        3899             :     ENDIF
        3900           0 :     IF ( .NOT. FOUND ) Inst%SUFFIX = ''
        3901             :
        3902             :     !-----------------------------------------------------------------
        3903             :     ! Allocate module variables
        3904             :     !-----------------------------------------------------------------
        3905             :
        3906             :     ! Get horizontal grid extensions on this CPU
        3907           0 :     NX = HcoState%NX
        3908           0 :     NY = HcoState%NY
        3909             :
        3910           0 :     ALLOCATE( Inst%T_LAST24H( NX, NY ), STAT=AS )
        3911           0 :     IF ( AS /= 0 ) THEN
        3912           0 :        CALL HCO_ERROR( 'T_LAST24H', RC )
        3913           0 :        RETURN
        3914             :     ENDIF
        3915           0 :     Inst%T_LAST24H = 0.0_sp
        3916             :
        3917           0 :     ALLOCATE( Inst%T_LASTXDAYS( NX, NY ), STAT=AS )
        3918             :     IF ( AS /= 0 ) THEN
        3919           0 :        CALL HCO_ERROR( 'T_LASTXDAYS', RC )
        3920           0 :        RETURN
        3921             :     ENDIF
        3922           0 :     Inst%T_LASTXDAYS = 0.0_sp
        3923             :
        3924           0 :     ALLOCATE( Inst%PARDR_LASTXDAYS( NX, NY ), STAT=AS )
        3925             :     IF ( AS /= 0 ) THEN
        3926           0 :        CALL HCO_ERROR( 'PARDR_LASTXDAYS', RC )
        3927           0 :        RETURN
        3928             :     ENDIF
        3929           0 :     Inst%PARDR_LASTXDAYS = 0.0_sp
        3930             :
        3931           0 :     ALLOCATE( Inst%PARDF_LASTXDAYS( NX, NY ), STAT=AS )
        3932             :     IF ( AS /= 0 ) THEN
        3933           0 :        CALL HCO_ERROR( 'PARDF_LASTXDAYS', RC )
        3934           0 :        RETURN
        3935             :     ENDIF
        3936           0 :     Inst%PARDF_LASTXDAYS = 0.0_sp
        3937             :
        3938           0 :     ALLOCATE( Inst%LAI_PREVDAY( NX, NY ), STAT=AS )
        3939             :     IF ( AS /= 0 ) THEN
        3940           0 :       CALL HCO_ERROR( 'LAI_PREVDAY', RC )
        3941           0 :       RETURN
        3942             :     ENDIF
        3943           0 :     Inst%LAI_PREVDAY = 0.0_sp
        3944             :
        3945             :     ! Normalization factor
        3946             :     ! There should be a different normalization factor for each compound, but
        3947             :     ! we calculate only 1 normalization factor for all compounds (dbm 11/2012)
        3948           0 :     ALLOCATE( Inst%NORM_FAC( 1 ), STAT=AS )
        3949             :     IF ( AS /= 0 ) THEN
        3950           0 :       CALL HCO_ERROR( 'NORM_FAC', RC )
        3951           0 :       RETURN
        3952             :     ENDIF
        3953           0 :     Inst%NORM_FAC = -99d0
        3954             :
        3955           0 :     ALLOCATE( Inst%AEF_APIN( NX, NY ), STAT=AS )
        3956             :     IF ( AS /= 0 ) THEN
        3957           0 :        CALL HCO_ERROR( 'AEF_APIN', RC )
        3958           0 :        RETURN
        3959             :     ENDIF
        3960           0 :     Inst%AEF_APIN = 0.0_hp
        3961             :
        3962           0 :     ALLOCATE( Inst%AEF_MYRC( NX, NY ), STAT=AS )
        3963             :     IF ( AS /= 0 ) THEN
        3964           0 :        CALL HCO_ERROR( 'AEF_MYRC', RC )
        3965           0 :        RETURN
        3966             :     ENDIF
        3967           0 :     Inst%AEF_MYRC = 0.0_hp
        3968             :
        3969           0 :     ALLOCATE( Inst%AEF_OMON( NX, NY ), STAT=AS )
        3970             :     IF ( AS /= 0 ) THEN
        3971           0 :        CALL HCO_ERROR( 'AEF_OMON', RC )
        3972           0 :        RETURN
        3973             :     ENDIF
        3974           0 :     Inst%AEF_OMON = 0.0_hp
        3975             :
        3976           0 :     ALLOCATE( Inst%AEF_FARN( NX, NY ), STAT=AS )
        3977             :     IF ( AS /= 0 ) THEN
        3978           0 :        CALL HCO_ERROR( 'AEF_FARN', RC )
        3979           0 :        RETURN
        3980             :     ENDIF
        3981           0 :     Inst%AEF_FARN = 0.0_hp
        3982             :
        3983           0 :     ALLOCATE( Inst%AEF_BCAR( NX, NY ), STAT=AS )
        3984             :     IF ( AS /= 0 ) THEN
        3985           0 :        CALL HCO_ERROR( 'AEF_BCAR', RC )
        3986           0 :        RETURN
        3987             :     ENDIF
        3988           0 :     Inst%AEF_BCAR = 0.0_hp
        3989             :
        3990           0 :     ALLOCATE( Inst%AEF_OSQT( NX, NY ), STAT=AS )
        3991             :     IF ( AS /= 0 ) THEN
        3992           0 :        CALL HCO_ERROR( 'AEF_OSQT', RC )
        3993           0 :        RETURN
        3994             :     ENDIF
        3995           0 :     Inst%AEF_OSQT = 0.0_hp
        3996             :
        3997           0 :     ALLOCATE( Inst%AEF_MOH( NX, NY ), STAT=AS )
        3998             :     IF ( AS /= 0 ) THEN
        3999           0 :        CALL HCO_ERROR( 'AEF_MOH', RC )
        4000           0 :        RETURN
        4001             :     ENDIF
        4002           0 :     Inst%AEF_MOH = 0.0_hp
        4003             :
        4004           0 :     ALLOCATE( Inst%AEF_ACET( NX, NY ), STAT=AS )
        4005             :     IF ( AS /= 0 ) THEN
        4006           0 :        CALL HCO_ERROR( 'AEF_ACET', RC )
        4007           0 :        RETURN
        4008             :     ENDIF
        4009           0 :     Inst%AEF_ACET = 0.0_hp
        4010             :
        4011           0 :     ALLOCATE( Inst%AEF_EOH( NX, NY ), STAT=AS )
        4012             :     IF ( AS /= 0 ) THEN
        4013           0 :        CALL HCO_ERROR( 'AEF_EOH', RC )
        4014           0 :        RETURN
        4015             :     ENDIF
        4016           0 :     Inst%AEF_EOH = 0.0_hp
        4017             :
        4018           0 :     ALLOCATE( Inst%AEF_CH2O( NX, NY ), STAT=AS )
        4019             :     IF ( AS /= 0 ) THEN
        4020           0 :        CALL HCO_ERROR( 'AEF_CH2O', RC )
        4021           0 :        RETURN
        4022             :     ENDIF
        4023           0 :     Inst%AEF_CH2O = 0.0_hp
        4024             :
        4025           0 :     ALLOCATE( Inst%AEF_ALD2( NX, NY ), STAT=AS )
        4026             :     IF ( AS /= 0 ) THEN
        4027           0 :        CALL HCO_ERROR( 'AEF_ALD2', RC )
        4028           0 :        RETURN
        4029             :     ENDIF
        4030           0 :     Inst%AEF_ALD2 = 0.0_hp
        4031             :
        4032           0 :     ALLOCATE( Inst%AEF_FAXX( NX, NY ), STAT=AS )
        4033             :     IF ( AS /= 0 ) THEN
        4034           0 :        CALL HCO_ERROR( 'AEF_FAXX', RC )
        4035           0 :        RETURN
        4036             :     ENDIF
        4037           0 :     Inst%AEF_FAXX = 0.0_hp
        4038             :
        4039           0 :     ALLOCATE( Inst%AEF_AAXX( NX, NY ), STAT=AS )
        4040             :     IF ( AS /= 0 ) THEN
        4041           0 :        CALL HCO_ERROR( 'AEF_AAXX', RC )
        4042           0 :        RETURN
        4043             :     ENDIF
        4044           0 :     Inst%AEF_AAXX = 0.0_hp
        4045             :
        4046           0 :     ALLOCATE( Inst%AEF_C2H4( NX, NY ), STAT=AS )
        4047             :     IF ( AS /= 0 ) THEN
        4048           0 :        CALL HCO_ERROR( 'AEF_C2H4', RC )
        4049           0 :        RETURN
        4050             :     ENDIF
        4051           0 :     Inst%AEF_C2H4 = 0.0_hp
        4052             :
        4053           0 :     ALLOCATE( Inst%AEF_TOLU( NX, NY ), STAT=AS )
        4054             :     IF ( AS /= 0 ) THEN
        4055           0 :        CALL HCO_ERROR( 'AEF_TOLU', RC )
        4056           0 :        RETURN
        4057             :     ENDIF
        4058           0 :     Inst%AEF_TOLU = 0.0_hp
        4059             :
        4060           0 :     ALLOCATE( Inst%AEF_HCNX( NX, NY ), STAT=AS )
        4061             :     IF ( AS /= 0 ) THEN
        4062           0 :        CALL HCO_ERROR( 'AEF_HCNX', RC )
        4063           0 :        RETURN
        4064             :     ENDIF
        4065           0 :     Inst%AEF_HCNX = 0.0_hp
        4066             :
        4067           0 :     ALLOCATE( Inst%AEF_PRPE( NX, NY ), STAT=AS )
        4068             :     IF ( AS /= 0 ) THEN
        4069           0 :        CALL HCO_ERROR( 'AEF_PRPE', RC )
        4070           0 :        RETURN
        4071             :     ENDIF
        4072           0 :     Inst%AEF_PRPE = 0.0_hp
        4073             :
        4074           0 :     ALLOCATE( Inst%FLUXISOP( NX, NY ), STAT=AS )
        4075             :     IF ( AS /= 0 ) THEN
        4076           0 :        CALL HCO_ERROR( 'FLUXISOP', RC )
        4077           0 :        RETURN
        4078             :     ENDIF
        4079           0 :     Inst%FLUXISOP = 0.0_hp
        4080             :
        4081           0 :     ALLOCATE( Inst%FLUXMONO( NX, NY ), STAT=AS )
        4082             :     IF ( AS /= 0 ) THEN
        4083           0 :        CALL HCO_ERROR( 'FLUXMONO', RC )
        4084           0 :        RETURN
        4085             :     ENDIF
        4086           0 :     Inst%FLUXMONO = 0.0_hp
        4087             :
        4088           0 :     ALLOCATE( Inst%FLUXACET( NX, NY ), STAT=AS )
        4089             :     IF ( AS /= 0 ) THEN
        4090           0 :        CALL HCO_ERROR( 'FLUXACET', RC )
        4091           0 :        RETURN
        4092             :     ENDIF
        4093           0 :     Inst%FLUXACET = 0.0_hp
        4094             :
        4095           0 :     ALLOCATE( Inst%FLUXACETmb( NX, NY ), STAT=AS )
        4096             :     IF ( AS /= 0 ) THEN
        4097           0 :        CALL HCO_ERROR( 'FLUXACETmb', RC )
        4098           0 :        RETURN
        4099             :     ENDIF
        4100           0 :     Inst%FLUXACETmb = 0.0_sp
        4101             :
        4102           0 :     ALLOCATE( Inst%FLUXACETbg( NX, NY ), STAT=AS )
        4103             :     IF ( AS /= 0 ) THEN
        4104           0 :        CALL HCO_ERROR( 'FLUXACETbg', RC )
        4105           0 :        RETURN
        4106             :     ENDIF
        4107           0 :     Inst%FLUXACETbg = 0.0_sp
        4108             :
        4109           0 :     ALLOCATE( Inst%FLUXPRPE( NX, NY ), STAT=AS )
        4110             :     IF ( AS /= 0 ) THEN
        4111           0 :        CALL HCO_ERROR( 'FLUXPRPE', RC )
        4112           0 :        RETURN
        4113             :     ENDIF
        4114           0 :     Inst%FLUXPRPE = 0.0_hp
        4115             :
        4116           0 :     ALLOCATE( Inst%FLUXC2H4( NX, NY ), STAT=AS )
        4117             :     IF ( AS /= 0 ) THEN
        4118           0 :        CALL HCO_ERROR( 'FLUXC2H4', RC )
        4119           0 :        RETURN
        4120             :     ENDIF
        4121           0 :     Inst%FLUXC2H4 = 0.0_hp
        4122             :
        4123           0 :     ALLOCATE( Inst%FLUXLIMO( NX, NY ), STAT=AS )
        4124             :     IF ( AS /= 0 ) THEN
        4125           0 :        CALL HCO_ERROR( 'FLUXLIMO', RC )
        4126           0 :        RETURN
        4127             :     ENDIF
        4128           0 :     Inst%FLUXLIMO = 0.0_hp
        4129             :
        4130           0 :     ALLOCATE( Inst%FLUXMTPA( NX, NY ), STAT=AS )
        4131             :     IF ( AS /= 0 ) THEN
        4132           0 :        CALL HCO_ERROR( 'FLUXMTPA', RC )
        4133           0 :        RETURN
        4134             :     ENDIF
        4135           0 :     Inst%FLUXMTPA = 0.0_hp
        4136             :
        4137           0 :     ALLOCATE( Inst%FLUXMTPO( NX, NY ), STAT=AS )
        4138             :     IF ( AS /= 0 ) THEN
        4139           0 :        CALL HCO_ERROR( 'FLUXMTPO', RC )
        4140           0 :        RETURN
        4141             :     ENDIF
        4142           0 :     Inst%FLUXMTPO = 0.0_hp
        4143             :
        4144           0 :     ALLOCATE( Inst%FLUXSESQ( NX, NY ), STAT=AS )
        4145             :     IF ( AS /= 0 ) THEN
        4146           0 :        CALL HCO_ERROR( 'FLUXSESQ', RC )
        4147           0 :        RETURN
        4148             :     ENDIF
        4149           0 :     Inst%FLUXSESQ = 0.0_hp
        4150             :
        4151           0 :     ALLOCATE( Inst%FLUXSOAP( NX, NY ), STAT=AS )
        4152             :     IF ( AS /= 0 ) THEN
        4153           0 :        CALL HCO_ERROR( 'FLUXSOAP', RC )
        4154           0 :        RETURN
        4155             :     ENDIF
        4156           0 :     Inst%FLUXSOAP = 0.0_hp
        4157             :
        4158           0 :     ALLOCATE( Inst%FLUXSOAS( NX, NY ), STAT=AS )
        4159             :     IF ( AS /= 0 ) THEN
        4160           0 :        CALL HCO_ERROR( 'FLUXSOAS', RC )
        4161           0 :        RETURN
        4162             :     ENDIF
        4163           0 :     Inst%FLUXSOAS = 0.0_hp
        4164             :
        4165           0 :     ALLOCATE( Inst%FLUXALD2( NX, NY ), STAT=AS )
        4166             :     IF ( AS /= 0 ) THEN
        4167           0 :        CALL HCO_ERROR( 'FLUXALD2', RC )
        4168           0 :        RETURN
        4169             :     ENDIF
        4170           0 :     Inst%FLUXALD2 = 0.0_hp
        4171             :
        4172           0 :     ALLOCATE( Inst%FLUXMOH( NX, NY ), STAT=AS )
        4173             :     IF ( AS /= 0 ) THEN
        4174           0 :        CALL HCO_ERROR( 'FLUXMOH', RC )
        4175           0 :        RETURN
        4176             :     ENDIF
        4177           0 :     Inst%FLUXMOH = 0.0_hp
        4178             :
        4179           0 :     ALLOCATE( Inst%FLUXEOH( NX, NY ), STAT=AS )
        4180             :     IF ( AS /= 0 ) THEN
        4181           0 :        CALL HCO_ERROR( 'FLUXEOH', RC )
        4182           0 :        RETURN
        4183             :     ENDIF
        4184           0 :     Inst%FLUXEOH = 0.0_hp
        4185             :
        4186           0 :     ALLOCATE( Inst%FLUXAPIN( NX, NY ), STAT=AS )
        4187             :     IF ( AS /= 0 ) THEN
        4188           0 :        CALL HCO_ERROR( 'FLUXAPIN', RC )
        4189           0 :        RETURN
        4190             :     ENDIF
        4191           0 :     Inst%FLUXAPIN = 0.0_sp
        4192             :
        4193           0 :     ALLOCATE( Inst%FLUXBPIN( NX, NY ), STAT=AS )
        4194             :     IF ( AS /= 0 ) THEN
        4195           0 :        CALL HCO_ERROR( 'FLUXBPIN', RC )
        4196           0 :        RETURN
        4197             :     ENDIF
        4198           0 :     Inst%FLUXBPIN = 0.0_sp
        4199             :
        4200           0 :     ALLOCATE( Inst%FLUXSABI( NX, NY ), STAT=AS )
        4201             :     IF ( AS /= 0 ) THEN
        4202           0 :        CALL HCO_ERROR( 'FLUXSABI', RC )
        4203           0 :        RETURN
        4204             :     ENDIF
        4205           0 :     Inst%FLUXSABI = 0.0_sp
        4206             :
        4207           0 :     ALLOCATE( Inst%FLUXMYRC( NX, NY ), STAT=AS )
        4208             :     IF ( AS /= 0 ) THEN
        4209           0 :        CALL HCO_ERROR( 'FLUXMYRC', RC )
        4210           0 :        RETURN
        4211             :     ENDIF
        4212           0 :     Inst%FLUXMYRC = 0.0_sp
        4213             :
        4214           0 :     ALLOCATE( Inst%FLUXCARE( NX, NY ), STAT=AS )
        4215             :     IF ( AS /= 0 ) THEN
        4216           0 :        CALL HCO_ERROR( 'FLUXCARE', RC )
        4217           0 :        RETURN
        4218             :     ENDIF
        4219           0 :     Inst%FLUXCARE = 0.0_sp
        4220             :
        4221           0 :     ALLOCATE( Inst%FLUXOCIM( NX, NY ), STAT=AS )
        4222             :     IF ( AS /= 0 ) THEN
        4223           0 :        CALL HCO_ERROR( 'FLUXOCIM', RC )
        4224           0 :        RETURN
        4225             :     ENDIF
        4226           0 :     Inst%FLUXOCIM = 0.0_sp
        4227             :
        4228           0 :     ALLOCATE( Inst%FLUXOMON( NX, NY ), STAT=AS )
        4229             :     IF ( AS /= 0 ) THEN
        4230           0 :        CALL HCO_ERROR(  'FLUXOMON', RC )
        4231           0 :        RETURN
        4232             :     ENDIF
        4233           0 :     Inst%FLUXOMON = 0.0_sp
        4234             :
        4235           0 :     ALLOCATE( Inst%FLUXFARN( NX, NY ), STAT=AS )
        4236             :     IF ( AS /= 0 ) THEN
        4237           0 :        CALL HCO_ERROR( 'FLUXFARN', RC )
        4238           0 :        RETURN
        4239             :     ENDIF
        4240           0 :     Inst%FLUXFARN = 0.0_sp
        4241             :
        4242           0 :     ALLOCATE( Inst%FLUXBCAR( NX, NY ), STAT=AS )
        4243             :     IF ( AS /= 0 ) THEN
        4244           0 :        CALL HCO_ERROR( 'FLUXBCAR', RC )
        4245           0 :        RETURN
        4246             :     ENDIF
        4247           0 :     Inst%FLUXBCAR = 0.0_sp
        4248             :
        4249           0 :     ALLOCATE( Inst%FLUXOSQT( NX, NY ), STAT=AS )
        4250             :     IF ( AS /= 0 ) THEN
        4251           0 :        CALL HCO_ERROR( 'FLUXOSQT', RC )
        4252           0 :        RETURN
        4253             :     ENDIF
        4254           0 :     Inst%FLUXOSQT = 0.0_sp
        4255             :
        4256           0 :     ALLOCATE( Inst%FLUXMBOX( NX, NY ), STAT=AS )
        4257             :     IF ( AS /= 0 ) THEN
        4258           0 :        CALL HCO_ERROR( 'FLUXMBOX', RC )
        4259           0 :        RETURN
        4260             :     ENDIF
        4261           0 :     Inst%FLUXMBOX = 0.0_sp
        4262             :
        4263           0 :     ALLOCATE( Inst%FLUXFAXX( NX, NY ), STAT=AS )
        4264             :     IF ( AS /= 0 ) THEN
        4265           0 :        CALL HCO_ERROR( 'FLUXFAXX', RC )
        4266           0 :        RETURN
        4267             :     ENDIF
        4268           0 :     Inst%FLUXFAXX = 0.0_sp
        4269             :
        4270           0 :     ALLOCATE( Inst%FLUXAAXX( NX, NY ), STAT=AS )
        4271             :     IF ( AS /= 0 ) THEN
        4272           0 :        CALL HCO_ERROR( 'FLUXAAXX', RC )
        4273           0 :        RETURN
        4274             :     ENDIF
        4275           0 :     Inst%FLUXAAXX = 0.0_sp
        4276             :
        4277           0 :     ALLOCATE( Inst%ARRAY_16( NX, NY, 16 ), STAT=AS )
        4278             :     IF ( AS /= 0 ) THEN
        4279           0 :        CALL HCO_ERROR( 'ARRAY_16', RC )
        4280           0 :        RETURN
        4281             :     ENDIF
        4282           0 :     Inst%ARRAY_16 = 0.0_hp
        4283             :
        4284             :     ALLOCATE ( Inst%AEF_ISOP ( NX, NY ), &
        4285             :                Inst%AEF_MBOX ( NX, NY ), &
        4286             :                Inst%AEF_BPIN ( NX, NY ), &
        4287             :                Inst%AEF_CARE ( NX, NY ), &
        4288             :                Inst%AEF_LIMO ( NX, NY ), &
        4289             :                Inst%AEF_OCIM ( NX, NY ), &
        4290           0 :                Inst%AEF_SABI ( NX, NY ), STAT=AS )
        4291           0 :     IF ( AS /= 0 ) THEN
        4292           0 :        CALL HCO_ERROR( 'AEF allocation error', RC )
        4293           0 :        RETURN
        4294             :     ENDIF
        4295           0 :     Inst%AEF_ISOP  = 0.0_hp
        4296           0 :     Inst%AEF_MBOX  = 0.0_hp
        4297           0 :     Inst%AEF_BPIN  = 0.0_hp
        4298           0 :     Inst%AEF_CARE  = 0.0_hp
        4299           0 :     Inst%AEF_LIMO  = 0.0_hp
        4300           0 :     Inst%AEF_OCIM  = 0.0_hp
        4301           0 :     Inst%AEF_SABI  = 0.0_hp
        4302             :
        4303             :     !=================================================================
        4304             :     ! Create manual diagnostics
        4305             :     !=================================================================
        4306             :     CALL Diagn_Create( HcoState  = HcoState,              &
        4307             :                        cName     = 'InvMEGAN_ACET_MBOX',  &
        4308             :                        ExtNr     = ExtNr,                 &
        4309             :                        Cat       = -1,                    &
        4310             :                        Hier      = -1,                    &
        4311             :                        HcoID     = -1,                    &
        4312             :                        SpaceDim  = 2,                     &
        4313             :                        OutUnit   = 'kg/m2/s',             &
        4314             :                        AutoFill  = 0,                     &
        4315             :                        Trgt2D    = Inst%FLUXACETmb,       &
        4316           0 :                        RC        = RC )
        4317           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        4318           0 :         CALL HCO_ERROR( 'ERROR 45', RC, THISLOC=LOC )
        4319           0 :         RETURN
        4320             :     ENDIF
        4321             :
        4322             :     CALL Diagn_Create( HcoState  = HcoState,              &
        4323             :                        cName     = 'InvMEGAN_ACET_DIRECT',&
        4324             :                        ExtNr     = ExtNr,                 &
        4325             :                        Cat       = -1,                    &
        4326             :                        Hier      = -1,                    &
        4327             :                        HcoID     = -1,                    &
        4328             :                        SpaceDim  = 2,                     &
        4329             :                        OutUnit   = 'kg/m2/s',             &
        4330             :                        AutoFill  = 0,                     &
        4331             :                        Trgt2D    = Inst%FLUXACETbg,       &
        4332           0 :                        RC        = RC )
        4333           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        4334           0 :         CALL HCO_ERROR( 'ERROR 46', RC, THISLOC=LOC )
        4335           0 :         RETURN
        4336             :     ENDIF
        4337             :
        4338             :     CALL Diagn_Create( HcoState  = HcoState,              &
        4339             :                        cName     = 'InvMEGAN_APIN',       &
        4340             :                        ExtNr     = ExtNr,                 &
        4341             :                        Cat       = -1,                    &
        4342             :                        Hier      = -1,                    &
        4343             :                        HcoID     = -1,                    &
        4344             :                        SpaceDim  = 2,                     &
        4345             :                        OutUnit   = 'kg/m2/s',             &
        4346             :                        AutoFill  = 0,                     &
        4347             :                        Trgt2D    = Inst%FLUXAPIN,         &
        4348           0 :                        RC        = RC )
        4349           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        4350           0 :         CALL HCO_ERROR( 'ERROR 47', RC, THISLOC=LOC )
        4351           0 :         RETURN
        4352             :     ENDIF
        4353             :
        4354             :     CALL Diagn_Create( HcoState  = HcoState,              &
        4355             :                        cName     = 'InvMEGAN_BPIN',       &
        4356             :                        ExtNr     = ExtNr,                 &
        4357             :                        Cat       = -1,                    &
        4358             :                        Hier      = -1,                    &
        4359             :                        HcoID     = -1,                    &
        4360             :                        SpaceDim  = 2,                     &
        4361             :                        OutUnit   = 'kg/m2/s',             &
        4362             :                        AutoFill  = 0,                     &
        4363             :                        Trgt2D    = Inst%FLUXBPIN,         &
        4364           0 :                        RC        = RC )
        4365           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        4366           0 :         CALL HCO_ERROR( 'ERROR 48', RC, THISLOC=LOC )
        4367           0 :         RETURN
        4368             :     ENDIF
        4369             :
        4370             :     CALL Diagn_Create( HcoState  = HcoState,              &
        4371             :                        cName     = 'InvMEGAN_SABI',       &
        4372             :                        ExtNr     = ExtNr,                 &
        4373             :                        Cat       = -1,                    &
        4374             :                        Hier      = -1,                    &
        4375             :                        HcoID     = -1,                    &
        4376             :                        SpaceDim  = 2,                     &
        4377             :                        OutUnit   = 'kg/m2/s',             &
        4378             :                        AutoFill  = 0,                     &
        4379             :                        Trgt2D    = Inst%FLUXSABI,         &
        4380           0 :                        RC        = RC )
        4381           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        4382           0 :         CALL HCO_ERROR( 'ERROR 49', RC, THISLOC=LOC )
        4383           0 :         RETURN
        4384             :     ENDIF
        4385             :
        4386             :     CALL Diagn_Create( HcoState  = HcoState,              &
        4387             :                        cName     = 'InvMEGAN_MYRC',       &
        4388             :                        ExtNr     = ExtNr,                 &
        4389             :                        Cat       = -1,                    &
        4390             :                        Hier      = -1,                    &
        4391             :                        HcoID     = -1,                    &
        4392             :                        SpaceDim  = 2,                     &
        4393             :                        OutUnit   = 'kg/m2/s',             &
        4394             :                        AutoFill  = 0,                     &
        4395             :                        Trgt2D    = Inst%FLUXMYRC,         &
        4396           0 :                        RC        = RC )
        4397           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        4398           0 :         CALL HCO_ERROR( 'ERROR 50', RC, THISLOC=LOC )
        4399           0 :         RETURN
        4400             :     ENDIF
        4401             :
        4402             :     CALL Diagn_Create( HcoState  = HcoState,              &
        4403             :                        cName     = 'InvMEGAN_CARE',       &
        4404             :                        ExtNr     = ExtNr,                 &
        4405             :                        Cat       = -1,                    &
        4406             :                        Hier      = -1,                    &
        4407             :                        HcoID     = -1,                    &
        4408             :                        SpaceDim  = 2,                     &
        4409             :                        OutUnit   = 'kg/m2/s',             &
        4410             :                        AutoFill  = 0,                     &
        4411             :                        Trgt2D    = Inst%FLUXCARE,         &
        4412           0 :                        RC        = RC )
        4413           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        4414           0 :         CALL HCO_ERROR( 'ERROR 51', RC, THISLOC=LOC )
        4415           0 :         RETURN
        4416             :     ENDIF
        4417             :
        4418             :     CALL Diagn_Create( HcoState  = HcoState,              &
        4419             :                        cName     = 'InvMEGAN_OCIM',       &
        4420             :                        ExtNr     = ExtNr,                 &
        4421             :                        Cat       = -1,                    &
        4422             :                        Hier      = -1,                    &
        4423             :                        HcoID     = -1,                    &
        4424             :                        SpaceDim  = 2,                     &
        4425             :                        OutUnit   = 'kg/m2/s',             &
        4426             :                        AutoFill  = 0,                     &
        4427             :                        Trgt2D    = Inst%FLUXOCIM,         &
        4428           0 :                        RC        = RC )
        4429           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        4430           0 :         CALL HCO_ERROR( 'ERROR 52', RC, THISLOC=LOC )
        4431           0 :         RETURN
        4432             :     ENDIF
        4433             :
        4434             :     CALL Diagn_Create( HcoState  = HcoState,              &
        4435             :                        cName     = 'InvMEGAN_OMON',       &
        4436             :                        ExtNr     = ExtNr,                 &
        4437             :                        Cat       = -1,                    &
        4438             :                        Hier      = -1,                    &
        4439             :                        HcoID     = -1,                    &
        4440             :                        SpaceDim  = 2,                     &
        4441             :                        OutUnit   = 'kg/m2/s',             &
        4442             :                        AutoFill  = 0,                     &
        4443             :                        Trgt2D    = Inst%FLUXOMON,         &
        4444           0 :                        RC        = RC )
        4445           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        4446           0 :         CALL HCO_ERROR( 'ERROR 53', RC, THISLOC=LOC )
        4447           0 :         RETURN
        4448             :     ENDIF
        4449             :
        4450             :     CALL Diagn_Create( HcoState  = HcoState,              &
        4451             :                        cName     = 'InvMEGAN_FARN',       &
        4452             :                        ExtNr     = ExtNr,                 &
        4453             :                        Cat       = -1,                    &
        4454             :                        Hier      = -1,                    &
        4455             :                        HcoID     = -1,                    &
        4456             :                        SpaceDim  = 2,                     &
        4457             :                        OutUnit   = 'kg/m2/s',             &
        4458             :                        AutoFill  = 0,                     &
        4459             :                        Trgt2D    = Inst%FLUXFARN,         &
        4460           0 :                        RC        = RC )
        4461           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        4462           0 :         CALL HCO_ERROR( 'ERROR 54', RC, THISLOC=LOC )
        4463           0 :         RETURN
        4464             :     ENDIF
        4465             :
        4466             :     CALL Diagn_Create( HcoState  = HcoState,              &
        4467             :                        cName     = 'InvMEGAN_BCAR',       &
        4468             :                        ExtNr     = ExtNr,                 &
        4469             :                        Cat       = -1,                    &
        4470             :                        Hier      = -1,                    &
        4471             :                        HcoID     = -1,                    &
        4472             :                        SpaceDim  = 2,                     &
        4473             :                        OutUnit   = 'kg/m2/s',             &
        4474             :                        AutoFill  = 0,                     &
        4475             :                        Trgt2D    = Inst%FLUXBCAR,         &
        4476           0 :                        RC        = RC )
        4477           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        4478           0 :         CALL HCO_ERROR( 'ERROR 55', RC, THISLOC=LOC )
        4479           0 :         RETURN
        4480             :     ENDIF
        4481             :
        4482             :     CALL Diagn_Create( HcoState  = HcoState,              &
        4483             :                        cName     = 'InvMEGAN_OSQT',       &
        4484             :                        ExtNr     = ExtNr,                 &
        4485             :                        Cat       = -1,                    &
        4486             :                        Hier      = -1,                    &
        4487             :                        HcoID     = -1,                    &
        4488             :                        SpaceDim  = 2,                     &
        4489             :                        OutUnit   = 'kg/m2/s',             &
        4490             :                        AutoFill  = 0,                     &
        4491             :                        Trgt2D    = Inst%FLUXOSQT,         &
        4492           0 :                        RC        = RC )
        4493           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        4494           0 :         CALL HCO_ERROR( 'ERROR 56', RC, THISLOC=LOC )
        4495           0 :         RETURN
        4496             :     ENDIF
        4497             :
        4498             :     CALL Diagn_Create( HcoState  = HcoState,              &
        4499             :                        cName     = 'InvMEGAN_MBOX',       &
        4500             :                        ExtNr     = ExtNr,                 &
        4501             :                        Cat       = -1,                    &
        4502             :                        Hier      = -1,                    &
        4503             :                        HcoID     = -1,                    &
        4504             :                        SpaceDim  = 2,                     &
        4505             :                        OutUnit   = 'kg/m2/s',             &
        4506             :                        AutoFill  = 0,                     &
        4507             :                        Trgt2D    = Inst%FLUXMBOX,         &
        4508           0 :                        RC        = RC )
        4509           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        4510           0 :         CALL HCO_ERROR( 'ERROR 57', RC, THISLOC=LOC )
        4511           0 :         RETURN
        4512             :     ENDIF
        4513             :
        4514             :     CALL Diagn_Create( HcoState  = HcoState,              &
        4515             :                        cName     = 'InvMEGAN_FAXX',       &
        4516             :                        ExtNr     = ExtNr,                 &
        4517             :                        Cat       = -1,                    &
        4518             :                        Hier      = -1,                    &
        4519             :                        HcoID     = -1,                    &
        4520             :                        SpaceDim  = 2,                     &
        4521             :                        OutUnit   = 'kg/m2/s',             &
        4522             :                        AutoFill  = 0,                     &
        4523             :                        Trgt2D    = Inst%FLUXFAXX,         &
        4524           0 :                        RC        = RC )
        4525           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        4526           0 :         CALL HCO_ERROR( 'ERROR 58', RC, THISLOC=LOC )
        4527           0 :         RETURN
        4528             :     ENDIF
        4529             :
        4530             :     CALL Diagn_Create( HcoState  = HcoState,              &
        4531             :                        cName     = 'InvMEGAN_AAXX',       &
        4532             :                        ExtNr     = ExtNr,                 &
        4533             :                        Cat       = -1,                    &
        4534             :                        Hier      = -1,                    &
        4535             :                        HcoID     = -1,                    &
        4536             :                        SpaceDim  = 2,                     &
        4537             :                        OutUnit   = 'kg/m2/s',             &
        4538             :                        AutoFill  = 0,                     &
        4539             :                        Trgt2D    = Inst%FLUXAAXX,         &
        4540           0 :                        RC        = RC )
        4541           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        4542           0 :         CALL HCO_ERROR( 'ERROR 59', RC, THISLOC=LOC )
        4543           0 :         RETURN
        4544             :     ENDIF
        4545             :
        4546             :     !=================================================================
        4547             :     ! Initialize internal diagnostics. These are the restart variables
        4548             :     ! that can be used for a 'warm' start of MEGAN.
        4549             :     !=================================================================
        4550             :     CALL HCO_RestartDefine ( HcoState, 'LAI_PREVDAY', &
        4551           0 :                              Inst%LAI_PREVDAY, '1', RC )
        4552           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        4553           0 :         CALL HCO_ERROR( 'ERROR 60', RC, THISLOC=LOC )
        4554           0 :         RETURN
        4555             :     ENDIF
        4556             :
        4557             :     CALL HCO_RestartDefine ( HcoState, 'T_PREVDAY', &
        4558           0 :                              Inst%T_LAST24H,   'K', RC )
        4559           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        4560           0 :         CALL HCO_ERROR( 'ERROR 61', RC, THISLOC=LOC )
        4561           0 :         RETURN
        4562             :     ENDIF
        4563             :
        4564             :     CALL HCO_RestartDefine ( HcoState, 'T_DAVG', &
        4565           0 :                              Inst%T_LASTXDAYS, 'K', RC )
        4566           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        4567           0 :         CALL HCO_ERROR( 'ERROR 62', RC, THISLOC=LOC )
        4568           0 :         RETURN
        4569             :     ENDIF
        4570             :
        4571             :     CALL HCO_RestartDefine (  HcoState, 'PARDR_DAVG', &
        4572           0 :                              Inst%PARDR_LASTXDAYS, 'W/m2', RC )
        4573           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        4574           0 :         CALL HCO_ERROR( 'ERROR 63', RC, THISLOC=LOC )
        4575           0 :         RETURN
        4576             :     ENDIF
        4577             :
        4578             :     CALL HCO_RestartDefine ( HcoState, 'PARDF_DAVG', &
        4579           0 :                              Inst%PARDF_LASTXDAYS, 'W/m2', RC )
        4580           0 :     IF ( RC /= HCO_SUCCESS ) THEN
        4581           0 :         CALL HCO_ERROR( 'ERROR 64', RC, THISLOC=LOC )
        4582           0 :         RETURN
        4583             :     ENDIF
        4584             :
        4585             :     !=================================================================
        4586             :     ! The original MEGAN code used to read the emission factors here.
        4587             :     ! We now get the emisson factors through HEMCO, hence no need to
        4588             :     ! do this anymore (ckeller, 05/19/2014).
        4589             :     !=================================================================
        4590             :
        4591             :     ! Set physical constants
        4592           0 :     PI_180     = HcoState%Phys%PI_180
        4593           0 :     Inst%D2RAD = PI_180                ! Degrees to radians
        4594           0 :     Inst%RAD2D = 1.0_hp / PI_180       ! Radians to degrees
        4595             :
        4596             :     ! Enable met. fields
        4597           0 :     ExtState%T2M%DoUse       = .TRUE.
        4598           0 :     ExtState%SUNCOS%DoUse    = .TRUE.
        4599           0 :     ExtState%PARDR%DoUse     = .TRUE.
        4600           0 :     ExtState%PARDF%DoUse     = .TRUE.
        4601           0 :     ExtState%LAI%DoUse       = .TRUE.
        4602           0 :     ExtState%GWETROOT%DoUse  = .TRUE.
        4603             :
        4604             :     ! Cleanup
        4605           0 :     Inst => NULL()
        4606             :
        4607             :     ! Leave w/ success
        4608           0 :     IF ( ALLOCATED(HcoIDs  ) ) DEALLOCATE(HcoIDs  )
        4609           0 :     IF ( ALLOCATED(SpcNames) ) DEALLOCATE(SpcNames)
        4610           0 :     CALL HCO_LEAVE( HcoState%Config%Err,RC )
        4611             :
        4612           0 :   END SUBROUTINE HCOX_Megan_Init
        4613             : !EOC
        4614             : !------------------------------------------------------------------------------
        4615             : !                   Harmonized Emissions Component (HEMCO)                    !
        4616             : !------------------------------------------------------------------------------
        4617             : !BOP
        4618             : !
        4619             : ! !IROUTINE: HCOX_Megan_Final
        4620             : !
        4621             : ! !DESCRIPTION: Subroutine HCOX\_Megan\_Final deallocates all allocated arrays
        4622             : !  at the end of a GEOS-Chem model run.
        4623             : !\\
        4624             : !\\
        4625             : ! !INTERFACE:
        4626             : !
        4627           0 :   SUBROUTINE HCOX_MEGAN_FINAL ( HcoState, ExtState, RC )
        4628             : !
        4629             : ! !USES
        4630             : !
        4631             : !
        4632             : ! !INPUT PARAMETERS:
        4633             : !
        4634             :     TYPE(HCO_State), POINTER        :: HcoState      ! HEMCO State obj
        4635             :     TYPE(Ext_State), POINTER        :: ExtState      ! Extension State obj
        4636             : !
        4637             : ! !INPUT/OUTPUT PARAMETERS:
        4638             : !
        4639             :     INTEGER,         INTENT(INOUT)  :: RC
        4640             : !
        4641             : ! !REVISION HISTORY:
        4642             : !  05 Aug 2013 - C. Keller   - Initial version
        4643             : !  See https://github.com/geoschem/hemco for complete history
        4644             : !EOP
        4645             : !------------------------------------------------------------------------------
        4646             : !BOC
        4647             : !
        4648             : ! !LOCAL VARIABLES:
        4649             : !
        4650           0 :     CALL InstRemove ( ExtState%Megan )
        4651             :
        4652           0 :   END SUBROUTINE HCOX_MEGAN_FINAL
        4653             : !EOC
        4654             : !------------------------------------------------------------------------------
        4655             : !                   Harmonized Emissions Component (HEMCO)                    !
        4656             : !------------------------------------------------------------------------------
        4657             : !BOP
        4658             : !
        4659             : ! !IROUTINE: InstGet
        4660             : !
        4661             : ! !DESCRIPTION: Subroutine InstGet returns a pointer to the desired instance.
        4662             : !\\
        4663             : !\\
        4664             : ! !INTERFACE:
        4665             : !
        4666           0 :   SUBROUTINE InstGet ( Instance, Inst, RC, PrevInst )
        4667             : !
        4668             : ! !INPUT PARAMETERS:
        4669             : !
        4670             :     INTEGER                             :: Instance
        4671             :     TYPE(MyInst),     POINTER           :: Inst
        4672             :     INTEGER                             :: RC
        4673             :     TYPE(MyInst),     POINTER, OPTIONAL :: PrevInst
        4674             : !
        4675             : ! !REVISION HISTORY:
        4676             : !  18 Feb 2016 - C. Keller   - Initial version
        4677             : !  See https://github.com/geoschem/hemco for complete history
        4678             : !EOP
        4679             : !------------------------------------------------------------------------------
        4680             : !BOC
        4681             :     TYPE(MyInst),     POINTER    :: PrvInst
        4682             :
        4683             :     !=================================================================
        4684             :     ! InstGet begins here!
        4685             :     !=================================================================
        4686             :
        4687             :     ! Get instance. Also archive previous instance.
        4688           0 :     PrvInst => NULL()
        4689           0 :     Inst    => AllInst
        4690           0 :     DO WHILE ( ASSOCIATED(Inst) )
        4691           0 :        IF ( Inst%Instance == Instance ) EXIT
        4692           0 :        PrvInst => Inst
        4693           0 :        Inst    => Inst%NextInst
        4694             :     END DO
        4695           0 :     IF ( .NOT. ASSOCIATED( Inst ) ) THEN
        4696           0 :        RC = HCO_FAIL
        4697           0 :        RETURN
        4698             :     ENDIF
        4699             :
        4700             :     ! Pass output arguments
        4701           0 :     IF ( PRESENT(PrevInst) ) PrevInst => PrvInst
        4702             :
        4703             :     ! Cleanup & Return
        4704           0 :     PrvInst => NULL()
        4705           0 :     RC = HCO_SUCCESS
        4706             :
        4707             :   END SUBROUTINE InstGet
        4708             : !EOC
        4709             : !------------------------------------------------------------------------------
        4710             : !                   Harmonized Emissions Component (HEMCO)                    !
        4711             : !------------------------------------------------------------------------------
        4712             : !BOP
        4713             : !
        4714             : ! !IROUTINE: InstCreate
        4715             : !
        4716             : ! !DESCRIPTION: Subroutine InstCreate adds a new instance to the list of
        4717             : !  instances, assigns a unique instance number to this new instance, and
        4718             : !  archives this instance number to output argument Instance.
        4719             : !\\
        4720             : !\\
        4721             : ! !INTERFACE:
        4722             : !
        4723           0 :   SUBROUTINE InstCreate ( ExtNr, Instance, Inst, RC )
        4724             : !
        4725             : ! !INPUT PARAMETERS:
        4726             : !
        4727             :     INTEGER,       INTENT(IN)       :: ExtNr
        4728             : !
        4729             : ! !OUTPUT PARAMETERS:
        4730             : !
        4731             :     INTEGER,       INTENT(  OUT)    :: Instance
        4732             :     TYPE(MyInst),  POINTER          :: Inst
        4733             : !
        4734             : ! !INPUT/OUTPUT PARAMETERS:
        4735             : !
        4736             :     INTEGER,       INTENT(INOUT)    :: RC
        4737             : !
        4738             : ! !REVISION HISTORY:
        4739             : !  18 Feb 2016 - C. Keller   - Initial version
        4740             : !  See https://github.com/geoschem/hemco for complete history
        4741             : !EOP
        4742             : !------------------------------------------------------------------------------
        4743             : !BOC
        4744             :     TYPE(MyInst), POINTER          :: TmpInst
        4745             :     INTEGER                        :: nnInst
        4746             :
        4747             :     !=================================================================
        4748             :     ! InstCreate begins here!
        4749             :     !=================================================================
        4750             :
        4751             :     ! ----------------------------------------------------------------
        4752             :     ! Generic instance initialization
        4753             :     ! ----------------------------------------------------------------
        4754             :
        4755             :     ! Initialize
        4756           0 :     Inst => NULL()
        4757             :
        4758             :     ! Get number of already existing instances
        4759           0 :     TmpInst => AllInst
        4760           0 :     nnInst = 0
        4761           0 :     DO WHILE ( ASSOCIATED(TmpInst) )
        4762           0 :        nnInst  =  nnInst + 1
        4763           0 :        TmpInst => TmpInst%NextInst
        4764             :     END DO
        4765             :
        4766             :     ! Create new instance
        4767           0 :     ALLOCATE(Inst)
        4768           0 :     Inst%Instance = nnInst + 1
        4769           0 :     Inst%ExtNr    = ExtNr
        4770             :
        4771             :     ! Attach to instance list
        4772           0 :     Inst%NextInst => AllInst
        4773           0 :     AllInst       => Inst
        4774             :
        4775             :     ! Update output instance
        4776           0 :     Instance = Inst%Instance
        4777             :
        4778             :     ! ----------------------------------------------------------------
        4779             :     ! Type specific initialization statements follow below
        4780             :     ! ----------------------------------------------------------------
        4781             :
        4782             :     ! Return w/ success
        4783           0 :     RC = HCO_SUCCESS
        4784             :
        4785           0 :   END SUBROUTINE InstCreate
        4786             : !EOC
        4787             : !------------------------------------------------------------------------------
        4788             : !                   Harmonized Emissions Component (HEMCO)                    !
        4789             : !------------------------------------------------------------------------------
        4790             : !BOP
        4791             : !
        4792             : ! !IROUTINE: InstRemove
        4793             : !
        4794             : ! !DESCRIPTION: Subroutine InstRemove removes an instance from the list of
        4795             : ! instances.
        4796             : !\\
        4797             : !\\
        4798             : ! !INTERFACE:
        4799             : !
        4800           0 :   SUBROUTINE InstRemove ( Instance )
        4801             : !
        4802             : ! !INPUT PARAMETERS:
        4803             : !
        4804             :     INTEGER                     :: Instance
        4805             : !
        4806             : ! !REVISION HISTORY:
        4807             : !  18 Feb 2016 - C. Keller   - Initial version
        4808             : !  See https://github.com/geoschem/hemco for complete history
        4809             : !EOP
        4810             : !------------------------------------------------------------------------------
        4811             : !BOC
        4812             :     INTEGER                     :: RC
        4813             :     TYPE(MyInst), POINTER       :: PrevInst
        4814             :     TYPE(MyInst), POINTER       :: Inst
        4815             :
        4816             :     !=================================================================
        4817             :     ! InstRemove begins here!
        4818             :     !=================================================================
        4819             :
        4820             :     ! Get instance. Also archive previous instance.
        4821           0 :     PrevInst => NULL()
        4822           0 :     Inst     => NULL()
        4823           0 :     CALL InstGet ( Instance, Inst, RC, PrevInst=PrevInst )
        4824             :
        4825             :     ! Instance-specific deallocation
        4826           0 :     IF ( ASSOCIATED(Inst) ) THEN
        4827             :
        4828             :        !---------------------------------------------------------------------
        4829             :        ! Deallocate fields of Inst before popping off from the list
        4830             :        ! in order to avoid memory leaks (Bob Yantosca (17 Aug 2022)
        4831             :        !---------------------------------------------------------------------
        4832           0 :        IF ( ASSOCIATED( Inst%ARRAY_16 ) ) THEN
        4833           0 :           DEALLOCATE( Inst%ARRAY_16 )
        4834             :        ENDIF
        4835           0 :        Inst%ARRAY_16 => NULL()
        4836             :
        4837           0 :        IF ( ASSOCIATED( Inst%NORM_FAC ) ) THEN
        4838           0 :           DEALLOCATE( Inst%NORM_FAC )
        4839             :        ENDIF
        4840           0 :        Inst%NORM_FAC => NULL()
        4841             :
        4842           0 :        IF ( ASSOCIATED( Inst%AEF_ISOP ) ) THEN
        4843           0 :           DEALLOCATE( Inst%AEF_ISOP )
        4844             :        ENDIF
        4845           0 :        Inst%AEF_ISOP => NULL()
        4846             :
        4847           0 :        IF ( ASSOCIATED( Inst%AEF_MBOX ) ) THEN
        4848           0 :           DEALLOCATE( Inst%AEF_MBOX )
        4849             :        ENDIF
        4850           0 :        Inst%AEF_MBOX => NULL()
        4851             :
        4852           0 :        IF ( ASSOCIATED( Inst%AEF_BPIN ) ) THEN
        4853           0 :           DEALLOCATE( Inst%AEF_BPIN )
        4854             :        ENDIF
        4855           0 :        Inst%AEF_BPIN => NULL()
        4856             :
        4857           0 :        IF ( ASSOCIATED( Inst%AEF_CARE ) ) THEN
        4858           0 :           DEALLOCATE( Inst%AEF_CARE )
        4859             :        ENDIF
        4860           0 :        Inst%AEF_CARE => NULL()
        4861             :
        4862           0 :        IF ( ASSOCIATED( Inst%AEF_LIMO ) ) THEN
        4863           0 :           DEALLOCATE( Inst%AEF_LIMO )
        4864             :        ENDIF
        4865           0 :        Inst%AEF_LIMO => NULL()
        4866             :
        4867           0 :        IF ( ASSOCIATED( Inst%AEF_OCIM ) ) THEN
        4868           0 :           DEALLOCATE( Inst%AEF_OCIM )
        4869             :        ENDIF
        4870           0 :        Inst%AEF_OCIM => NULL()
        4871             :
        4872           0 :        IF ( ASSOCIATED( Inst%AEF_SABI ) ) THEN
        4873           0 :           DEALLOCATE( Inst%AEF_SABI )
        4874             :        ENDIF
        4875           0 :        Inst%AEF_SABI => NULL()
        4876             :
        4877           0 :        IF ( ASSOCIATED( Inst%AEF_APIN ) ) THEN
        4878           0 :           DEALLOCATE( Inst%AEF_APIN )
        4879             :        ENDIF
        4880           0 :        Inst%AEF_APIN => NULL()
        4881             :
        4882           0 :        IF ( ASSOCIATED( Inst%AEF_MYRC ) ) THEN
        4883           0 :           DEALLOCATE( Inst%AEF_MYRC )
        4884             :        ENDIF
        4885           0 :        Inst%AEF_MYRC => NULL()
        4886             :
        4887           0 :        IF ( ASSOCIATED( Inst%AEF_OMON ) ) THEN
        4888           0 :           DEALLOCATE( Inst%AEF_OMON )
        4889             :        ENDIF
        4890           0 :        Inst%AEF_OMON => NULL()
        4891             :
        4892           0 :        IF ( ASSOCIATED( Inst%AEF_ACET ) ) THEN
        4893           0 :           DEALLOCATE( Inst%AEF_ACET )
        4894             :        ENDIF
        4895           0 :        Inst%AEF_ACET => NULL()
        4896             :
        4897           0 :        IF ( ASSOCIATED( Inst%AEF_MOH  ) ) THEN
        4898           0 :           DEALLOCATE( Inst%AEF_MOH  )
        4899             :        ENDIF
        4900           0 :        Inst%AEF_MOH => NULL()
        4901             :
        4902           0 :        IF ( ASSOCIATED( Inst%AEF_EOH  ) ) THEN
        4903           0 :           DEALLOCATE( Inst%AEF_EOH  )
        4904             :        ENDIF
        4905           0 :        Inst%AEF_EOH  => NULL()
        4906             :
        4907           0 :        IF ( ASSOCIATED( Inst%AEF_CH2O ) ) THEN
        4908           0 :           DEALLOCATE( Inst%AEF_CH2O )
        4909             :        ENDIF
        4910           0 :        Inst%AEF_CH2O => NULL()
        4911             :
        4912           0 :        IF ( ASSOCIATED( Inst%AEF_ALD2 ) ) THEN
        4913           0 :           DEALLOCATE( Inst%AEF_ALD2 )
        4914             :        ENDIF
        4915           0 :        Inst%AEF_ALD2 => NULL()
        4916             :
        4917           0 :        IF ( ASSOCIATED( Inst%AEF_FAXX ) ) THEN
        4918           0 :           DEALLOCATE( Inst%AEF_FAXX )
        4919             :        ENDIF
        4920           0 :        Inst%AEF_FAXX => NULL()
        4921             :
        4922           0 :        IF ( ASSOCIATED( Inst%AEF_AAXX ) ) THEN
        4923           0 :           DEALLOCATE( Inst%AEF_AAXX )
        4924             :        ENDIF
        4925           0 :        Inst%AEF_AAXX => NULL()
        4926             :
        4927           0 :        IF ( ASSOCIATED( Inst%AEF_C2H4 ) ) THEN
        4928           0 :           DEALLOCATE( Inst%AEF_C2H4 )
        4929             :        ENDIF
        4930           0 :        Inst%AEF_C2H4 => NULL()
        4931             :
        4932           0 :        IF ( ASSOCIATED( Inst%AEF_TOLU ) ) THEN
        4933           0 :           DEALLOCATE( Inst%AEF_TOLU )
        4934             :        ENDIF
        4935           0 :        Inst%AEF_TOLU => NULL()
        4936             :
        4937           0 :        IF ( ASSOCIATED( Inst%AEF_HCNX ) ) THEN
        4938           0 :           DEALLOCATE( Inst%AEF_HCNX )
        4939             :        ENDIF
        4940           0 :        Inst%AEF_HCNX => NULL()
        4941             :
        4942           0 :        IF ( ASSOCIATED( Inst%AEF_PRPE ) ) THEN
        4943           0 :           DEALLOCATE( Inst%AEF_PRPE )
        4944             :        ENDIF
        4945           0 :        Inst%AEF_PRPE => NULL()
        4946             :
        4947           0 :        IF ( ASSOCIATED( Inst%AEF_FARN ) ) THEN
        4948           0 :           DEALLOCATE( Inst%AEF_FARN )
        4949             :        ENDIF
        4950           0 :        Inst%AEF_FARN => NULL()
        4951             :
        4952           0 :        IF ( ASSOCIATED( Inst%AEF_BCAR ) ) THEN
        4953           0 :           DEALLOCATE( Inst%AEF_BCAR )
        4954             :        ENDIF
        4955           0 :        Inst%AEF_BCAR => NULL()
        4956             :
        4957           0 :        IF ( ASSOCIATED( Inst%AEF_OSQT ) ) THEN
        4958           0 :           DEALLOCATE( Inst%AEF_OSQT )
        4959             :        ENDIF
        4960           0 :        Inst%AEF_OSQT => NULL()
        4961             :
        4962           0 :        IF ( ASSOCIATED( Inst%FLUXISOP ) ) THEN
        4963           0 :           DEALLOCATE( Inst%FLUXISOP )
        4964             :        ENDIF
        4965           0 :        Inst%FLUXISOP => NULL()
        4966             :
        4967           0 :        IF ( ASSOCIATED( Inst%FLUXMONO ) ) THEN
        4968           0 :           DEALLOCATE( Inst%FLUXMONO )
        4969             :        ENDIF
        4970           0 :        Inst%FLUXMONO => NULL()
        4971             :
        4972           0 :        IF ( ASSOCIATED( Inst%FLUXACET ) ) THEN
        4973           0 :           DEALLOCATE( Inst%FLUXACET )
        4974             :        ENDIF
        4975           0 :        Inst%FLUXACET => NULL()
        4976             :
        4977           0 :        IF ( ASSOCIATED( Inst%FLUXACETmb ) ) THEN
        4978           0 :           DEALLOCATE( Inst%FLUXACETmb )
        4979             :        ENDIF
        4980           0 :        Inst%FLUXACETmb => NULL()
        4981             :
        4982           0 :        IF ( ASSOCIATED( Inst%FLUXACETbg ) ) THEN
        4983           0 :           DEALLOCATE( Inst%FLUXACETbg )
        4984             :        ENDIF
        4985           0 :        Inst%FLUXACETbg => NULL()
        4986             :
        4987           0 :        IF ( ASSOCIATED( Inst%FLUXPRPE ) ) THEN
        4988           0 :           DEALLOCATE( Inst%FLUXPRPE )
        4989             :        ENDIF
        4990           0 :        Inst%FLUXPRPE => NULL()
        4991             :
        4992           0 :        IF ( ASSOCIATED( Inst%FLUXC2H4 ) ) THEN
        4993           0 :           DEALLOCATE( Inst%FLUXC2H4 )
        4994             :        ENDIF
        4995           0 :        Inst%FLUXC2H4 => NULL()
        4996             :
        4997           0 :        IF ( ASSOCIATED( Inst%FLUXLIMO ) ) THEN
        4998           0 :           DEALLOCATE( Inst%FLUXLIMO )
        4999             :        ENDIF
        5000           0 :        Inst%FLUXLIMO => NULL()
        5001             :
        5002           0 :        IF ( ASSOCIATED( Inst%FLUXMTPA ) ) THEN
        5003           0 :           DEALLOCATE( Inst%FLUXMTPA )
        5004             :        ENDIF
        5005           0 :        Inst%FLUXMTPA => NULL()
        5006             :
        5007           0 :        IF ( ASSOCIATED( Inst%FLUXMTPO ) ) THEN
        5008           0 :           DEALLOCATE( Inst%FLUXMTPO )
        5009             :        ENDIF
        5010           0 :        Inst%FLUXMTPO => NULL()
        5011             :
        5012           0 :        IF ( ASSOCIATED( Inst%FLUXSESQ ) ) THEN
        5013           0 :           DEALLOCATE( Inst%FLUXSESQ )
        5014             :        ENDIF
        5015           0 :        Inst%FLUXSESQ => NULL()
        5016             :
        5017           0 :        IF ( ASSOCIATED( Inst%FLUXSOAP ) ) THEN
        5018           0 :           DEALLOCATE( Inst%FLUXSOAP )
        5019             :        ENDIF
        5020           0 :        Inst%FLUXSOAP => NULL()
        5021             :
        5022           0 :        IF ( ASSOCIATED( Inst%FLUXSOAS ) ) THEN
        5023           0 :           DEALLOCATE( Inst%FLUXSOAS )
        5024             :        ENDIF
        5025           0 :        Inst%FLUXSOAS => NULL()
        5026             :
        5027           0 :        IF ( ASSOCIATED( Inst%FLUXALD2 ) ) THEN
        5028           0 :           DEALLOCATE( Inst%FLUXALD2 )
        5029             :        ENDIF
        5030           0 :        Inst%FLUXALD2 => NULL()
        5031             :
        5032           0 :        IF ( ASSOCIATED( Inst%FLUXMOH ) ) THEN
        5033           0 :           DEALLOCATE( Inst%FLUXMOH )
        5034             :        ENDIF
        5035           0 :        Inst%FLUXMOH => NULL()
        5036             :
        5037           0 :        IF ( ASSOCIATED( Inst%FLUXEOH ) ) THEN
        5038           0 :           DEALLOCATE( Inst%FLUXEOH )
        5039             :        ENDIF
        5040           0 :        Inst%FLUXEOH => NULL()
        5041             :
        5042           0 :        IF ( ASSOCIATED( Inst%FLUXAPIN ) ) THEN
        5043           0 :           DEALLOCATE( Inst%FLUXAPIN )
        5044             :        ENDIF
        5045           0 :        Inst%FLUXAPIN => NULL()
        5046             :
        5047           0 :        IF ( ASSOCIATED( Inst%FLUXBPIN ) ) THEN
        5048           0 :           DEALLOCATE( Inst%FLUXBPIN )
        5049             :        ENDIF
        5050           0 :        Inst%FLUXBPIN => NULL()
        5051             :
        5052           0 :        IF ( ASSOCIATED( Inst%FLUXSABI ) ) THEN
        5053           0 :           DEALLOCATE( Inst%FLUXSABI )
        5054             :        ENDIF
        5055           0 :        Inst%FLUXSABI => NULL()
        5056             :
        5057           0 :        IF ( ASSOCIATED( Inst%FLUXMYRC ) ) THEN
        5058           0 :           DEALLOCATE( Inst%FLUXMYRC )
        5059             :        ENDIF
        5060           0 :        Inst%FLUXMYRC => NULL()
        5061             :
        5062           0 :        IF ( ASSOCIATED( Inst%FLUXCARE ) ) THEN
        5063           0 :           DEALLOCATE( Inst%FLUXCARE )
        5064             :        ENDIF
        5065           0 :        Inst%FLUXCARE => NULL()
        5066             :
        5067           0 :        IF ( ASSOCIATED( Inst%FLUXOCIM ) ) THEN
        5068           0 :           DEALLOCATE( Inst%FLUXOCIM )
        5069             :        ENDIF
        5070           0 :        Inst%FLUXOCIM => NULL()
        5071             :
        5072           0 :        IF ( ASSOCIATED( Inst%FLUXOMON ) ) THEN
        5073           0 :           DEALLOCATE( Inst%FLUXOMON )
        5074             :        ENDIF
        5075           0 :        Inst%FLUXOMON => NULL()
        5076             :
        5077           0 :        IF ( ASSOCIATED( Inst%FLUXMBOX ) ) THEN
        5078           0 :           DEALLOCATE( Inst%FLUXMBOX )
        5079             :        ENDIF
        5080           0 :        Inst%FLUXMBOX => NULL()
        5081             :
        5082           0 :        IF ( ASSOCIATED( Inst%FLUXFAXX ) ) THEN
        5083           0 :           DEALLOCATE( Inst%FLUXFAXX )
        5084             :        ENDIF
        5085           0 :        Inst%FLUXFAXX => NULL()
        5086             :
        5087           0 :        IF ( ASSOCIATED( Inst%FLUXAAXX ) ) THEN
        5088           0 :           DEALLOCATE( Inst%FLUXAAXX )
        5089             :        ENDIF
        5090           0 :        Inst%FLUXAAXX => NULL()
        5091             :
        5092           0 :        IF ( ASSOCIATED( Inst%FLUXFARN ) ) THEN
        5093           0 :           DEALLOCATE( Inst%FLUXFARN )
        5094             :        ENDIF
        5095           0 :        Inst%FLUXFARN => NULL()
        5096             :
        5097           0 :        IF ( ASSOCIATED( Inst%FLUXBCAR ) ) THEN
        5098           0 :           DEALLOCATE( Inst%FLUXBCAR )
        5099             :        ENDIF
        5100           0 :        Inst%FLUXBCAR => NULL()
        5101             :
        5102           0 :        IF ( ASSOCIATED( Inst%FLUXOSQT ) ) THEN
        5103           0 :           DEALLOCATE( Inst%FLUXOSQT )
        5104             :        ENDIF
        5105           0 :        Inst%FLUXOSQT => NULL()
        5106             :
        5107           0 :        IF ( ASSOCIATED( Inst%LAI_PREVDAY ) ) THEN
        5108           0 :           DEALLOCATE( Inst%LAI_PREVDAY )
        5109             :        ENDIF
        5110           0 :        Inst%LAI_PREVDAY => NULL()
        5111             :
        5112           0 :        IF ( ASSOCIATED( Inst%T_LASTXDAYS ) ) THEN
        5113           0 :           DEALLOCATE( Inst%T_LASTXDAYS )
        5114             :        ENDIF
        5115           0 :        Inst%T_LASTXDAYS => NULL()
        5116             :
        5117           0 :        IF ( ASSOCIATED( Inst%T_LAST24H ) ) THEN
        5118           0 :           DEALLOCATE( Inst%T_LAST24H )
        5119             :        ENDIF
        5120           0 :        Inst%T_LAST24H => NULL()
        5121             :
        5122           0 :        IF ( ASSOCIATED( Inst%PARDF_LASTXDAYS ) ) THEN
        5123           0 :           DEALLOCATE( Inst%PARDF_LASTXDAYS )
        5124             :        ENDIF
        5125           0 :        Inst%PARDF_LASTXDAYS => NULL()
        5126             :
        5127           0 :        IF ( ASSOCIATED( Inst%PARDR_LASTXDAYS ) ) THEN
        5128           0 :           DEALLOCATE( Inst%PARDR_LASTXDAYS )
        5129             :        ENDIF
        5130           0 :        Inst%PARDR_LASTXDAYS => NULL()
        5131             :
        5132             :        !---------------------------------------------------------------------
        5133             :        ! Pop off instance from list
        5134             :        !---------------------------------------------------------------------
        5135           0 :        IF ( ASSOCIATED(PrevInst) ) THEN
        5136           0 :           PrevInst%NextInst => Inst%NextInst
        5137             :        ELSE
        5138           0 :           AllInst => Inst%NextInst
        5139             :        ENDIF
        5140           0 :        DEALLOCATE(Inst)
        5141             :     ENDIF
        5142             :
        5143             :     ! Free pointers before exiting
        5144           0 :     PrevInst => NULL()
        5145           0 :     Inst     => NULL()
        5146             :
        5147           0 :   END SUBROUTINE InstRemove
        5148             : !EOC
        5149           0 : END MODULE HCOX_MEGAN_MOD

Generated by: LCOV version 1.14