source: tags/ORCHIDEE_4_1/ORCHIDEE/src_sechiba/chemistry.f90 @ 8119

Last change on this file since 8119 was 7526, checked in by josefine.ghattas, 2 years ago

Work on interpolations: Merge revision 7509-7511, 7515 and 7516 as done on branch ORCHIDEE_2_2.
Note reinf_slope, alb_vis, alb_nir and woodharvest have no valid data because these interpolations are not done.
See ticket #812

  • Property svn:keywords set to Date Revision HeadURL
File size: 103.3 KB
Line 
1! ================================================================================================================================
2!  MODULE       : chemistry
3!
4!  CONTACT      : orchidee-help _at_ listes.ipsl.fr
5!
6!  LICENCE      : IPSL (2006)
7!  This software is governed by the CeCILL licence see ORCHIDEE/ORCHIDEE_CeCILL.LIC
8!
9!>\BRIEF   
10!!
11!!\n DESCRIPTION:
12!!
13!! RECENT CHANGE(S): The content of this module were previously part of the diffuco module.
14!!                   ok_inca changed name into ok_bvoc and DIFFUCO_OK_INCA changed into CHEMISTRY_BVOC
15!!                   LEAFAGE_OK_INCA changed name into CHEMISTRY_LEAFAGE
16!!
17!! $HeadURL$
18!! $Date$
19!! $Revision$
20!! \n
21!_ ================================================================================================================================
22
23MODULE chemistry
24
25  USE ioipsl
26  USE constantes
27  USE qsat_moisture
28  USE sechiba_io_p
29  USE ioipsl
30  USE pft_parameters
31  USE grid
32  USE time, ONLY : one_day, dt_sechiba, julian_diff, one_hour, one_year
33  USE ioipsl_para 
34  USE xios_orchidee
35  USE function_library, ONLY :lai_to_biomass 
36
37  IMPLICIT NONE
38
39  PRIVATE
40  PUBLIC :: chemistry_xios_initialize, chemistry_initialize, chemistry_bvoc, chemistry_flux_interface, chemistry_clear
41
42
43  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION(:,:) :: flx_iso            !! Isoprene emissions from vegetation (kgC.m^{-2}.s^{-1})
44!$OMP THREADPRIVATE(flx_iso)
45  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION(:,:) :: flx_mono           !! Monoterpene emissions from vegetation (kgC.m^{-2}.s^{-1})
46!$OMP THREADPRIVATE(flx_mono)
47  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION(:,:) :: flx_ORVOC          !! Other Volatile Organic Compound emissions from vegetation (kgC.m^{-2}.s^{-1})
48!$OMP THREADPRIVATE(flx_ORVOC)
49  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION(:,:) :: flx_MBO            !! 2-methyl-3-buten-2-ol emissions from vegetation (mainly pines in America) (kgC.m^{-2}.s^{-1})
50!$OMP THREADPRIVATE(flx_MBO)
51  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION(:,:) :: flx_methanol       !! Methanol emissions from vegetation (kgC.m^{-2}.s^{-1})
52!$OMP THREADPRIVATE(flx_methanol)
53  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION(:,:) :: flx_acetone        !! Acetone emissions from vegetation (kgC.m^{-2}.s^{-1})
54!$OMP THREADPRIVATE(flx_acetone)
55  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION(:,:) :: flx_acetal         !! Acetaldehyde emissions from vegetation (kgC.m^{-2}.s^{-1})
56!$OMP THREADPRIVATE(flx_acetal)
57  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION(:,:) :: flx_formal         !! Formaldehyde emissions from vegetation (kgC.m^{-2}.s^{-1})
58!$OMP THREADPRIVATE(flx_formal)
59  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION(:,:) :: flx_acetic         !! Acetic acid emissions from vegetation (kgC.m^{-2}.s^{-1})
60!$OMP THREADPRIVATE(flx_acetic)
61  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION(:,:) :: flx_formic         !! Formic acid emissions from vegetation (kgC.m^{-2}.s^{-1})
62!$OMP THREADPRIVATE(flx_formic)
63  REAL(r_std),ALLOCATABLE, SAVE, DIMENSION(:,:)  :: flx_apinen         !! Alpha pinene emissions from vegetation (kgC.m^{-2}.s^{-1})
64!$OMP THREADPRIVATE(flx_apinen)
65  REAL(r_std),ALLOCATABLE, SAVE, DIMENSION(:,:)  :: flx_bpinen         !! Beta pinene emissions from vegetation (kgC.m^{-2}.s^{-1})
66!$OMP THREADPRIVATE(flx_bpinen)
67  REAL(r_std),ALLOCATABLE, SAVE, DIMENSION(:,:)  :: flx_limonen        !! Limonene emissions from vegetation (kgC.m^{-2}.s^{-1})
68!$OMP THREADPRIVATE(flx_limonen)
69  REAL(r_std),ALLOCATABLE, SAVE, DIMENSION(:,:)  :: flx_myrcen         !! Myrcene emissions from vegetation (kgC.m^{-2}.s^{-1})
70!$OMP THREADPRIVATE(flx_myrcen)
71  REAL(r_std),ALLOCATABLE, SAVE, DIMENSION(:,:)  :: flx_sabinen        !! Sabinene emissions from vegetation (kgC.m^{-2}.s^{-1})
72!$OMP THREADPRIVATE(flx_sabinen)
73  REAL(r_std),ALLOCATABLE, SAVE, DIMENSION(:,:)  :: flx_camphen        !! Camphene emissions from vegetation (kgC.m^{-2}.s^{-1})
74!$OMP THREADPRIVATE(flx_camphen)
75  REAL(r_std),ALLOCATABLE, SAVE, DIMENSION(:,:)  :: flx_3caren         !! 3-Carene emissions from vegetation (kgC.m^{-2}.s^{-1})
76!$OMP THREADPRIVATE(flx_3caren)
77  REAL(r_std),ALLOCATABLE, SAVE, DIMENSION(:,:)  :: flx_tbocimen       !! T-beta Ocimene emissions from vegetation (kgC.m^{-2}.s^{-1})
78!$OMP THREADPRIVATE(flx_tbocimen)
79  REAL(r_std),ALLOCATABLE, SAVE, DIMENSION(:,:)  :: flx_othermono      !! Emissions of other monoterpenes from vegetation (kgC.m^{-2}.s^{-1})
80!$OMP THREADPRIVATE(flx_othermono)
81  REAL(r_std),ALLOCATABLE, SAVE, DIMENSION(:,:)  :: flx_sesquiter      !! Sesquiterpene emissions from vegetation (kgC.m^{-2}.s^{-1})
82!$OMP THREADPRIVATE(flx_sesquiter)
83  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION(:,:) :: flx_fertil_no      !! Biogenic nitrogen oxide soil emission due to N-fertilisation (ngN.m^{-2}.s^{-1})
84!$OMP THREADPRIVATE(flx_fertil_no)
85  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION(:,:) :: flx_no_soil        !! Nitrogen Oxide emissions from soil, before deposition on canopy
86                                                                       !! (ngN.m^{-2}.s^{-1})
87!$OMP THREADPRIVATE(flx_no_soil)
88  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION(:,:) :: flx_no             !! Net nitrogen Oxide emissions from soil, after deposition on canopy
89!$OMP THREADPRIVATE(flx_no)
90  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION(:,:) :: CRF                !! Canopy reduction factor for net NO flux calculation (kjpindex,nvm)   
91!$OMP THREADPRIVATE(CRF)
92
93  ! variables used inside diffuco_inca module
94  LOGICAL, ALLOCATABLE, SAVE, DIMENSION(:)     :: ok_siesta        !! Flag for controlling post-pulse period (true/false)
95!$OMP THREADPRIVATE(ok_siesta)
96  LOGICAL, ALLOCATABLE, SAVE, DIMENSION(:)     :: allow_pulse      !! Flag for controlling pulse period (true/false)
97!$OMP THREADPRIVATE(allow_pulse)
98  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION(:) :: pulse            !! Pulse fonction
99!$OMP THREADPRIVATE(pulse)
100  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION(:) :: pulseday         !! Counter for pulse period
101!$OMP THREADPRIVATE(pulseday)
102  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION(:) :: siestaday        !! Counter for post-pulse period
103!$OMP THREADPRIVATE(siestaday)
104  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION(:) :: pulselim         !! Pulse period length
105!$OMP THREADPRIVATE(pulselim)
106  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION(:) :: siestalim        !! Post-pulse period length
107!$OMP THREADPRIVATE(siestalim)
108  REAL(r_std), SAVE                            :: nbre_precip 
109!$OMP THREADPRIVATE(nbre_precip)
110  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION(:) :: flx_co2_bbg_year !! CO2 emissions from biomass burning
111                                                                   !! Read in an input file (kgC.m^{-2}.year^{-1})
112!$OMP THREADPRIVATE(flx_co2_bbg_year)
113  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION(:) :: N_qt_WRICE_year  !! N fertilizers applied on wetland rice
114                                                                   !! Read in an input file (kgN.yr^{-1})
115!$OMP THREADPRIVATE(N_qt_WRICE_year)
116  REAL(r_std), ALLOCATABLE, SAVE, DIMENSION(:) :: N_qt_OTHER_year  !! N fertilizers applied on other crops and grasses
117                                                                   !! Read in an input file (kgN.yr^{-1})
118!$OMP THREADPRIVATE(N_qt_OTHER_year)
119  LOGICAL, SAVE   :: l_first_chemistry_inca=.TRUE.                 !! Initialisation for chemistry_flux_interface
120!$OMP THREADPRIVATE(l_first_chemistry_inca)
121     
122
123
124CONTAINS
125
126
127!! =============================================================================================================================
128!! SUBROUTINE:    chemistry_xios_initialize
129!!
130!>\BRIEF          Initialize xios dependant defintion before closing context defintion
131!!
132!! DESCRIPTION:   Initialize xios dependant defintion before closing context defintion
133!!
134!! \n
135!_ ==============================================================================================================================
136
137  SUBROUTINE chemistry_xios_initialize
138
139    CHARACTER(LEN=255) :: filename, name
140     
141
142    !! 1. Treat the file for fertilzation needed for option ok_cropsfertil_Nox
143
144    ! Read the input file name from run.def
145    filename = 'orchidee_fertilizer_1995.nc'
146    CALL getin_p('N_FERTIL_FILE',filename) 
147
148    ! Remove suffix .nc from filename
149    name = filename(1:LEN_TRIM(FILENAME)-3)
150    CALL xios_orchidee_set_file_attr("fertilizer_file",name=name)
151
152    ! Check if the file will be read by XIOS, by IOIPSL or not at all
153    IF (xios_interpolation .AND. ok_cropsfertil_Nox) THEN
154       IF (printlev>=2) WRITE (numout,*) 'The fertilizer file will be read later by XIOS'
155    ELSE
156       IF (ok_cropsfertil_Nox) THEN
157          IF (printlev>=2) WRITE (numout,*) 'The fertilizer file will be read later by IOIPSL'
158       ELSE
159          IF (printlev>=2) WRITE (numout,*) 'The fertilizer file will not be read'
160       END IF
161
162       ! The fertilizer file will not be read by XIOS. Now deactivate it for XIOS.
163       CALL xios_orchidee_set_file_attr("fertilizer_file",enabled=.FALSE.)
164       CALL xios_orchidee_set_field_attr("N_qt_WRICE_year_interp",enabled=.FALSE.)
165       CALL xios_orchidee_set_field_attr("N_qt_OTHER_year_interp",enabled=.FALSE.)
166    END IF
167
168
169    !! 2. Treat the file for bbg fertil needed for option ok_bbgfertil_Nox
170
171    ! Read the input file name from run.def
172    filename = 'orchidee_bbg_clim.nc'
173    CALL getin_p('CO2_BBG_FILE',filename)
174
175    ! Remove suffix .nc from filename
176    name = filename(1:LEN_TRIM(FILENAME)-3)
177    CALL xios_orchidee_set_file_attr("bbg_clim_file",name=name)
178
179    ! Check if the file will be read by XIOS, by IOIPSL or not at all
180    IF (xios_interpolation .AND. ok_bbgfertil_Nox) THEN
181       IF (printlev>=2) WRITE (numout,*) 'The bbgfertil file will be read later by XIOS'
182    ELSE
183       IF (ok_bbgfertil_Nox) THEN
184          IF (printlev>=2) WRITE (numout,*) 'The bbgfertil file will be read later by IOIPSL'
185       ELSE
186          IF (printlev>=2) WRITE (numout,*) 'The bbgfertil file will not be read'
187       END IF
188
189       ! This file will not be read by XIOS. Now deactivate it for XIOS.
190       CALL xios_orchidee_set_file_attr("bbg_clim_file",enabled=.FALSE.)
191       CALL xios_orchidee_set_field_attr("flx_co2_bbg_year_interp",enabled=.FALSE.)
192    END IF
193
194
195  END SUBROUTINE chemistry_xios_initialize
196
197!! ================================================================================================================================
198!! SUBROUTINE   : chemistry_initialize
199!!
200!>\BRIEF         This subroutine initializes the chemistry module
201!!
202!! DESCRIPTION  : Some of the variables and flags used chemistry_bvoc are allocated and initialised here.
203!!
204!! RECENT CHANGE(S): Changed name from diffuco_inca_init to chemistry_initialize
205!!
206!! MAIN OUTPUT VARIABLE(S): None
207!!
208!! REFERENCE(S) : None
209!!
210!! FLOWCHART    : None
211!_ ================================================================================================================================
212  SUBROUTINE chemistry_initialize(kjpindex, lalo, neighbours, resolution)
213
214    USE interpweight
215
216    IMPLICIT NONE
217   
218    !! 0. Variables and parameter declaration
219
220    !! 0.1 Input variables
221
222    INTEGER(i_std), INTENT(in)                         :: kjpindex         !! Domain size (unitless)
223    REAL(r_std), DIMENSION(kjpindex,2), INTENT (in)    :: lalo             !! Geographical coordinates
224    INTEGER(i_std), DIMENSION(kjpindex,8), INTENT (in) :: neighbours       !! Vector of neighbours for each
225                                                                           !! grid point (1=N, 2=E, 3=S, 4=W)
226    REAL(r_std),DIMENSION (kjpindex,2), INTENT(in)     :: resolution       !! The size in km of each grid-box in X and Y
227
228    !! 0.2 Output variables
229    REAL(r_std), DIMENSION(kjpindex)                   :: achem_wrice      !! Availability of data for the interpolation
230    REAL(r_std), DIMENSION(kjpindex)                   :: achem_other      !! Availability of data for the interpolation
231    REAL(r_std), DIMENSION(kjpindex)                   :: achem_co2        !! Availability of data for the interpolation
232
233    !! 0.3 Modified variables
234
235    !! 0.4 Local variables
236    LOGICAL                                            :: allow_weathergen
237    CHARACTER(LEN=80)                                  :: filename, fieldname
238    INTEGER(i_std)                                     :: iml, jml, lml, tml, force_id
239    INTEGER(i_std)                                     :: ier
240    REAL(r_std)                                        :: vmin, vmax       !! min/max values to use for the
241                                                                           !!   renormalization
242    CHARACTER(LEN=250)                                 :: maskvname        !! Variable to read the mask from
243                                                                           !! the file
244    CHARACTER(LEN=80)                                  :: lonname, latname !! lon, lat names in input file
245    REAL(r_std), DIMENSION(:), ALLOCATABLE             :: variabletypevals !! Values for all the types of the variable
246                                                                           !!   (variabletypevals(1) = -un, not used)
247    CHARACTER(LEN=50)                                  :: fractype         !! method of calculation of fraction
248                                                                           !!   'XYKindTime': Input values are kinds
249                                                                           !!     of something with a temporal
250                                                                           !!     evolution on the dx*dy matrix'
251    LOGICAL                                            :: nonegative       !! whether negative values should be removed
252    CHARACTER(LEN=50)                                  :: maskingtype      !! Type of masking
253                                                                           !!   'nomask': no-mask is applied
254                                                                           !!   'mbelow': take values below maskvals(1)
255                                                                           !!   'mabove': take values above maskvals(1)
256                                                                           !!   'msumrange': take values within 2 ranges;
257                                                                           !!      maskvals(2) <= SUM(vals(k)) <= maskvals(1)
258                                                                           !!      maskvals(1) < SUM(vals(k)) <= maskvals(3)
259                                                                           !!        (normalized by maskvals(3))
260                                                                           !!   'var': mask values are taken from a
261                                                                           !!     variable inside the file (>0)
262    REAL(r_std), DIMENSION(3)                          :: maskvals         !! values to use to mask (according to
263                                                                           !!   `maskingtype')
264    CHARACTER(LEN=250)                                 :: namemaskvar      !! name of the variable to use to mask
265    REAL(r_std)                                        :: chem_norefinf    !! No value
266    REAL(r_std)                                        :: chem_default     !! Default value
267
268!_ ================================================================================================================================
269
270    ALLOCATE (pulse(kjpindex),stat=ier)
271    IF (ier /= 0) CALL ipslerr_p(3,'chemistry_initialize','Problem in allocate of variable pulse','','')
272    pulse(:) = un
273
274    ! If we acount for NOx pulse emissions
275    IF (ok_pulse_NOx) THEN
276
277       ALLOCATE (ok_siesta(kjpindex),stat=ier)
278       IF (ier /= 0) CALL ipslerr_p(3,'chemistry_initialize','Problem in allocate of variable ok_siesta','','')
279       ok_siesta(:) = .FALSE.
280
281       ALLOCATE (allow_pulse(kjpindex),stat=ier)
282       IF (ier /= 0) CALL ipslerr_p(3,'chemistry_initialize','Problem in allocate of variable allow_pulse','','')
283       allow_pulse(:) = .FALSE.
284
285       ALLOCATE (pulseday(kjpindex),stat=ier)
286       IF (ier /= 0) CALL ipslerr_p(3,'chemistry_initialize','Problem in allocate of variable pulseday','','')
287       pulseday(:) = zero
288
289       ALLOCATE (siestaday(kjpindex),stat=ier)
290       IF (ier /= 0) CALL ipslerr_p(3,'chemistry_initialize','Problem in allocate of variable siestaday','','')
291       siestaday(:) = zero
292
293       ALLOCATE (pulselim(kjpindex),stat=ier)
294       IF (ier /= 0) CALL ipslerr_p(3,'chemistry_initialize','Problem in allocate of variable pulselim','','')
295       pulselim(:) = zero
296
297       ALLOCATE (siestalim(kjpindex),stat=ier)
298       IF (ier /= 0) CALL ipslerr_p(3,'chemistry_initialize','Problem in allocate of variable siestalim','','')
299       siestalim(:) = zero
300
301    END IF ! (ok_pulse_NOx)
302
303    ! If we acount for NOx emissions by N-fertilizers
304    IF (ok_cropsfertil_NOx) THEN
305
306       ALLOCATE (N_qt_WRICE_year(kjpindex),stat=ier)  !! N fertilizers on wetland rice, read in file
307       IF (ier /= 0) CALL ipslerr_p(3,'chemistry_initialize','Problem in allocate of variable N_qt_WRICE_year','','')
308       N_qt_WRICE_year(:) = zero
309   
310       ALLOCATE (N_qt_OTHER_year(kjpindex),stat=ier)  !! N fertilizers on other crops and grasses, read in file
311       IF (ier /= 0) CALL ipslerr_p(3,'chemistry_initialize','Problem in allocate of variable N_qt_OTHER_year','','')
312       N_qt_OTHER_year(:) = zero
313
314       WRITE (numout,*) ' *********************** Interpolating N fertilizers files for NOx emissions... '
315
316       !Config Key   = N_FERTIL_FILE
317       !Config Desc  = File name
318       !Config If    = CHEMISTRY_BVOC and NOx_FERTILIZERS_USE
319       !Config Def   = orchidee_fertilizer_1995.nc
320       !Config Help  =
321       !Config Units = -
322       filename = 'orchidee_fertilizer_1995.nc'
323       CALL getin_p('N_FERTIL_FILE',filename) 
324
325       IF ( xios_interpolation ) THEN
326   
327         CALL xios_orchidee_recv_field('N_qt_WRICE_year_interp',N_qt_WRICE_year)
328         CALL xios_orchidee_recv_field('N_qt_OTHER_year_interp',N_qt_OTHER_year)   
329
330         achem_wrice(:)=1
331         achem_other(:)=1
332       ELSE
333       
334         !! Variables for interpweight
335         vmin = 0.
336         vmax = 0.
337         ! Type of calculation of cell fractions
338         fractype = 'default'
339         ! Name of the longitude and latitude in the input file
340         lonname = 'lon'
341         latname = 'lat'
342         ! Default value when no value is get from input file
343         chem_default = 0.
344         ! Reference value when no value is get from input file
345         chem_norefinf = 0.
346         ! Should negative values be set to zero from input file?
347         nonegative = .TRUE.
348         ! Type of mask to apply to the input data (see header for more details)
349         maskingtype = 'nomask'
350         ! Values to use for the masking
351         maskvals = (/ min_sechiba, undef_sechiba, undef_sechiba /)
352         ! Name of the variable with the values for the mask in the input file (only if maskkingtype='var') (here not used)
353         namemaskvar = ''
354
355         fieldname= 'N_qt_WRICE_year'
356         IF (printlev >= 1) WRITE(numout,*) "chemistry_initialize: Read and interpolate file " &
357              // TRIM(filename) //" for variable N_qt_WRICE_year"
358         CALL interpweight_2Dcont(kjpindex, 0, 0, lalo, resolution, neighbours,                        &
359              contfrac, filename, fieldname, lonname, latname, vmin, vmax, nonegative, maskingtype,       &
360              maskvals, namemaskvar, -1, fractype, chem_default, chem_norefinf,                           &
361              N_qt_WRICE_year, achem_wrice)
362       
363         fieldname= 'N_qt_OTHER_year'
364         IF (printlev >= 1) WRITE(numout,*) "chemistry_initialize: Read and interpolate file " &
365              // TRIM(filename) //" for variable N_qt_OTHER_year"
366         CALL interpweight_2Dcont(kjpindex, 0, 0, lalo, resolution, neighbours,                        &
367              contfrac, filename, fieldname, lonname, latname, vmin, vmax, nonegative, maskingtype,       &
368              maskvals, namemaskvar, -1, fractype, chem_default, chem_norefinf,                           &
369              N_qt_OTHER_year, achem_other)
370       END IF   
371    END IF
372
373    ALLOCATE (flx_iso(kjpindex,nvm), stat=ier) 
374    IF (ier /= 0) CALL ipslerr_p(3,'chemistry_init','Problem in allocate of variable flx_iso','','')
375    flx_iso(:,:) = 0. 
376
377    ALLOCATE (flx_mono(kjpindex,nvm), stat=ier) 
378    IF (ier /= 0) CALL ipslerr_p(3,'chemistry_init','Problem in allocate of variable flx_mono','','')
379    flx_mono(:,:) = 0. 
380
381    ALLOCATE (flx_ORVOC(kjpindex,nvm), stat=ier) 
382    IF (ier /= 0) CALL ipslerr_p(3,'chemistry_init','Problem in allocate of variable flx_ORVOC ','','')
383    flx_ORVOC(:,:) = 0. 
384
385    ALLOCATE (flx_MBO(kjpindex,nvm), stat=ier) 
386    IF (ier /= 0) CALL ipslerr_p(3,'chemistry_init','Problem in allocate of variable flx_MBO','','')
387    flx_MBO(:,:) = 0. 
388
389    ALLOCATE (flx_methanol(kjpindex,nvm), stat=ier) 
390    IF (ier /= 0) CALL ipslerr_p(3,'chemistry_init','Problem in allocate of variable flx_methanol','','')
391    flx_methanol(:,:) = 0. 
392
393    ALLOCATE (flx_acetone(kjpindex,nvm), stat=ier) 
394    IF (ier /= 0) CALL ipslerr_p(3,'chemistry_init','Problem in allocate of variable flx_acetone','','')
395    flx_acetone(:,:) = 0. 
396
397    ALLOCATE (flx_acetal(kjpindex,nvm), stat=ier) 
398    IF (ier /= 0) CALL ipslerr_p(3,'chemistry_init','Problem in allocate of variable flx_acetal','','')
399    flx_acetal(:,:) = 0. 
400
401    ALLOCATE (flx_formal(kjpindex,nvm), stat=ier) 
402    IF (ier /= 0) CALL ipslerr_p(3,'chemistry_init','Problem in allocate of variable flx_formal','','')
403    flx_formal(:,:) = 0. 
404
405    ALLOCATE (flx_acetic(kjpindex,nvm), stat=ier) 
406    IF (ier /= 0) CALL ipslerr_p(3,'chemistry_init','Problem in allocate of variable flx_acetic','','')
407    flx_acetic(:,:) = 0. 
408
409    ALLOCATE (flx_formic(kjpindex,nvm), stat=ier) 
410    IF (ier /= 0) CALL ipslerr_p(3,'chemistry_init','Problem in allocate of variable flx_formic','','')
411    flx_formic(:,:) = 0. 
412
413    ALLOCATE (flx_no_soil(kjpindex,nvm), stat=ier) 
414    IF (ier /= 0) CALL ipslerr_p(3,'chemistry_init','Problem in allocate of variable flx_no_soil','','')
415    flx_no_soil(:,:) = 0. 
416
417    ALLOCATE (flx_no(kjpindex,nvm), stat=ier) 
418    IF (ier /= 0) CALL ipslerr_p(3,'chemistry_init','Problem in allocate of variable flx_no','','')
419    flx_no(:,:) = 0. 
420       
421    ALLOCATE (flx_fertil_no(kjpindex,nvm), stat=ier) 
422    IF (ier /= 0) CALL ipslerr_p(3,'chemistry_init','Problem in allocate of variable flx_fertil_no','','')
423    flx_fertil_no(:,:) = 0. 
424
425    ALLOCATE (flx_apinen(kjpindex,nvm), stat=ier) 
426    IF (ier /= 0) CALL ipslerr_p(3,'chemistry_init','Problem in allocate of variable flx_apinen','','')
427    flx_apinen(:,:) = 0.       
428
429    ALLOCATE (flx_bpinen (kjpindex,nvm), stat=ier) 
430    IF (ier /= 0) CALL ipslerr_p(3,'chemistry_init','Problem in allocate of variable flx_bpinen','','')
431    flx_bpinen(:,:) = 0.     
432
433    ALLOCATE (flx_limonen  (kjpindex,nvm), stat=ier) 
434    IF (ier /= 0) CALL ipslerr_p(3,'chemistry_init','Problem in allocate of variable flx_limonen','','')
435    flx_limonen(:,:) = 0.   
436
437    ALLOCATE (flx_myrcen(kjpindex,nvm), stat=ier) 
438    IF (ier /= 0) CALL ipslerr_p(3,'chemistry_init','Problem in allocate of variable flx_myrcen','','')
439    flx_myrcen(:,:) = 0.       
440
441    ALLOCATE (flx_sabinen(kjpindex,nvm), stat=ier) 
442    IF (ier /= 0) CALL ipslerr_p(3,'chemistry_init','Problem in allocate of variable flx_sabinen','','')
443    flx_sabinen(:,:) = 0.     
444
445    ALLOCATE (flx_camphen(kjpindex,nvm), stat=ier) 
446    IF (ier /= 0) CALL ipslerr_p(3,'chemistry_init','Problem in allocate of variable flx_camphen','','')
447    flx_camphen(:,:) = 0.     
448
449    ALLOCATE (flx_3caren(kjpindex,nvm), stat=ier) 
450    IF (ier /= 0) CALL ipslerr_p(3,'chemistry_init','Problem in allocate of variable flx_3caren','','')
451    flx_3caren(:,:) = 0.       
452
453    ALLOCATE (flx_tbocimen(kjpindex,nvm), stat=ier) 
454    IF (ier /= 0) CALL ipslerr_p(3,'chemistry_init','Problem in allocate of variable flx_tbocimen','','')
455    flx_tbocimen(:,:) = 0.     
456
457    ALLOCATE (flx_othermono(kjpindex,nvm), stat=ier) 
458    IF (ier /= 0) CALL ipslerr_p(3,'chemistry_init','Problem in allocate of variable flx_othermono','','')
459    flx_othermono(:,:) = 0.   
460
461    ALLOCATE (flx_sesquiter(kjpindex,nvm), stat=ier) 
462    IF (ier /= 0) CALL ipslerr_p(3,'chemistry_init','Problem in allocate of variable flx_sesquiter','','')
463    flx_sesquiter(:,:) = 0.   
464
465    ALLOCATE(CRF(kjpindex,nvm), stat=ier) 
466    IF (ier /= 0) CALL ipslerr_p(3,'chemistry_init','Problem in allocate of variable CRF ','','')
467    CRF(:,:) = 0. 
468
469
470    ! If we acount for NOx emissions due to Biomass Burning
471    IF (ok_bbgfertil_NOx) THEN
472
473       ALLOCATE (flx_co2_bbg_year(kjpindex),stat=ier) !! CO2 emissions from bbg, read in file
474       IF (ier /= 0) CALL ipslerr_p(3,'chemistry_initialize','Problem in allocate of variable flx_co2_bbg_year','','')
475       flx_co2_bbg_year(:) = zero   
476
477       WRITE (numout,*) ' *********************** Interpolating CO2 bbg files for NOx emissions... '
478       !Config Key   = N_FERTIL_FILE
479       !Config Desc  = File name
480       !Config If    = CHEMISTRY_BVOC and NOx_FERTILIZERS_USE
481       !Config Def   = orchidee_fertilizer_1995.nc
482       !Config Help  = ...
483       !Config Units = -
484       filename = 'orchidee_bbg_clim.nc'
485       CALL getin_p('CO2_BBG_FILE',filename)
486
487       IF (xios_interpolation) THEN
488   
489         CALL xios_orchidee_recv_field('flx_co2_bbg_year_interp',flx_co2_bbg_year)
490
491         achem_co2(:)=1
492       ELSE
493 
494         !! Variables for interpweight
495         vmin = 0.
496         vmax = 0.
497         ! Type of calculation of cell fractions
498         fractype = 'default'
499         ! Name of the longitude and latitude in the input file
500         lonname = 'lon'
501         latname = 'lat'
502         ! Default value when no value is get from input file
503         chem_default = 0.
504         ! Reference value when no value is get from input file
505         chem_norefinf = 0.
506         ! Should negative values be set to zero from input file?
507         nonegative = .TRUE.
508         ! Type of mask to apply to the input data (see header for more details)
509         maskingtype = 'nomask'
510         ! Values to use for the masking
511         maskvals = (/ min_sechiba, undef_sechiba, undef_sechiba /)
512         ! Name of the variable with the values for the mask in the input file (only if maskkingtype='var') (here not used)
513         namemaskvar = ''
514
515         fieldname = 'flx_co2_bbg_year'
516         IF (printlev >= 1) WRITE(numout,*) "chemistry_initialize: Read and interpolate file " &
517              // TRIM(filename) //" for variable flx_co2_bbg_year"
518         CALL interpweight_2Dcont(kjpindex, 0, 0, lalo, resolution, neighbours,                         &
519              contfrac, filename, fieldname, lonname, latname, vmin, vmax, nonegative, maskingtype,     &
520              maskvals, namemaskvar, -1, fractype, chem_default, chem_norefinf,                         &
521              flx_co2_bbg_year, achem_co2)
522       END IF
523    END IF
524
525    IF ( OFF_LINE_MODE ) THEN
526
527       !-
528       !- What are the alowed options for the temporal interpolation
529       !-
530       ! ALLOW_WEATHERGEN : Allow weather generator to create data
531       ! This parameter is already read in the driver
532       allow_weathergen = .FALSE.
533       CALL getin_p('ALLOW_WEATHERGEN',allow_weathergen)
534       
535       ! FORCING_FILE : Name of file containing the forcing data
536       ! This parameter is already read in the driver
537       filename='forcing_file.nc'
538       CALL getin_p('FORCING_FILE',filename)
539       CALL flininfo(filename,iml, jml, lml, tml, force_id)   
540       WRITE(numout,*) 'Number of data per year in forcing file :', tml 
541       CALL flinclo(force_id)
542       WRITE(numout,*) 'Forcing file closed in chemistry_initialize'
543       
544       
545       IF ( allow_weathergen ) THEN
546          WRITE(numout,*) '**chemistry_initialize: Using weather generator, careful to precip division for NOx '
547          nbre_precip = un
548          WRITE(numout,*) 'Division pour les precip, NOx:', nbre_precip
549       ELSE
550          WRITE(numout,*) 'DT_SECHIBA :', dt_sechiba
551          nbre_precip = (one_day/dt_sechiba)/(tml/one_year)
552          WRITE(numout,*) 'Division pour les precip, NOx:', nbre_precip
553       END IF
554
555    ELSE ! (in coupled mode)
556
557       nbre_precip = un
558       
559    END IF  ! (OFF_LINE_MODE)
560
561    ! Write diagnostics
562    IF (ok_cropsfertil_NOx) THEN
563      CALL xios_orchidee_send_field("interp_avail_achem_wrice",achem_wrice)
564      CALL xios_orchidee_send_field("interp_avail_achem_other",achem_other)
565      CALL xios_orchidee_send_field("interp_diag_N_qt_WRICE_year",N_qt_WRICE_year)
566      CALL xios_orchidee_send_field("interp_diag_N_qt_OTHER_year",N_qt_OTHER_year)
567
568    END IF
569    IF (ok_bbgfertil_NOx) THEN
570      CALL xios_orchidee_send_field("interp_avail_achem_co2",achem_co2)
571      CALL xios_orchidee_send_field("interp_diag_flx_co2_bbg_year",flx_co2_bbg_year)
572    END IF
573
574       
575  END SUBROUTINE chemistry_initialize
576
577
578!! ================================================================================================================================
579!! SUBROUTINE   : chemistry_bvoc
580!!
581!>\BRIEF         This subroutine computes biogenic emissions of reactive compounds, that is of
582!!               VOCs (volatile organic compounds) from vegetation and NOx (nitrogen oxides) from soils.
583!!               Calculation are mostly based on the works by Guenther et al. (1995) and Yienger and Levy (1995).\n
584!!
585!! DESCRIPTION  : Biogenic VOC emissions from vegetation are based on the parameterisations developped by
586!!                Guenther et al. (1995). Biogenic VOCs considered here are: isoprene, monoterpenes, OVOC and ORVOC
587!!                as bulked emissions, methanol, acetone, acetaldehyde, formaldehyde, acetic acid, formic acid
588!!                as single emissions.\n
589!!                For every biogenic VOCs an emission factor (EF), depending on the PFT considered, is used.\n
590!!                Isoprene emissions depend on temperature and radiation. A partition between sunlit and shaded
591!!                leaves is taken into account and either one (if ok_multilayer = FALSE) or several layers
592!!                (if ok_multilayer = TRUE) in the canopy can be used.\n
593!!                When radiation extinction is considered, the canopy radiative transfer model takes into
594!!                account light extinction through canopy, calculating first need diffuse and direct radiation
595!!                based on Andrew Friend 2001 radiative model and Spitters et al. 1986. The calculation of lai,
596!!                parscat, parsh and parsun, laisun and laishabsed based on Guenther et al.(JGR, 1995) and Norman (1982).\n
597!!                Emissions for other BVOCs (monoterpenes, OVOC, ORVOC and other single compounds such as
598!!                methanol, acetone...) depend only on temperature.\n   
599!!                The impact of leaf age, using an emission activity prescribed for each of the 4 leaf age
600!!                classes can also be considered for isoprene and methanol emissions when ok_leafage = TRUE.\n
601!!                NOx emissions from soils are based on Yienger and Levy (1995) and depend on soil moisture
602!!                and temperature and PFT. The pulse effect, related to significant rain occuring after severe
603!!                drought can also be considered (ok_pulse_NOx = TRUE), as well as the increase in emissions related to
604!!                biomass buring (ok_bbgfertil_NOx = TRUE) or use of fertilizers (ok_cropsfertil_NOx = TRUE).
605!!                A net NO flux is eventually calculated taking into account loss by deposition on the surface, using
606!!                a Canopy Reduction Factor (CRF) based on stomatal and leaf area.\n
607!!                This subroutine is called by diffuco_main only if biogenic emissions are activated
608!!                for sechiba (flag CHEMISTRY_BVOC=TRUE).\n
609!!
610!! RECENT CHANGE(S): Changed name from diffuco_inca to chemistry_bvoc
611!!
612!! MAIN OUTPUT VARIABLE(S): :: PAR, :: PARsun, :: PARsh, :: laisun, :: laish,
613!!                          :: flx_iso, :: flx_mono, :: flx_ORVOC, :: flx_MBO,
614!!                          :: flx_methanol, :: flx_acetone, :: flx_acetal, :: flx_formal,
615!!                          :: flx_acetic, :: flx_formic, :: flx_no_soil, :: flx_no,
616!!                          :: CRF, :: flx_fertil_no, :: Trans, :: Fdf,
617!!                          :: PARdf, :: PARdr, :: PARsuntab, :: PARshtab
618!!
619!! REFERENCE(S) :
620!! - Andrew Friend (2001), Modelling canopy CO2 fluxes: are 'big-leaf' simplifications justified?
621!! Global Ecology and Biogeography, 10, 6, 603-619, doi: 10.1046/j.1466-822x.2001.00268.x
622!! - Spitters, C.J.T, Toussaint, H.A.J.M, Groudriaan, J. (1986), Separating the diffuse and direct
623!! component of global radiation and its implications for modeling canopy photosynthesis, Agricultural
624!! and Forest Meteorology, 38, 1-3, 217-229, doi:10.1016/0168-1923(86)90060-2
625!! - Norman JM (1982) Simulation of microclimates. In: Hatfield JL, Thomason IJ (eds)
626!!  Biometeorology in integrated pest management. Academic, New York, pp 65–99
627!! - Guenther, A., Hewitt, C. N., Erickson, D., Fall, R., Geron, C., Graedel, T., Harley, P.,
628!! Klinger, L., Lerdau, M., McKay, W. A., Pierce, T., Scholes, B., Steinbrecher, R., Tallamraju,
629!! R., Taylor, J. et Zimmerman, P. (1995), A global model of natural volatile organic compound
630!! emissions, J. Geophys. Res., 100, 8873-8892.
631!! - MacDonald, R. et Fall, R. (1993), Detection of substantial emissions of methanol from
632!! plants to the atmosphere, Atmos. Environ., 27A, 1709-1713.
633!! - Guenther, A., Geron, C., Pierce, T., Lamb, B., Harley, P. et Fall, R. (2000), Natural emissions
634!! of non-methane volatile organic compounds, carbon monoxide, and oxides of nitrogen from
635!! North America, Atmos. Environ., 34, 2205-2230.
636!! - Yienger, J. J. et Levy II, H. (1995), Empirical model of global soil-biogenic NOx emissions,
637!! J. Geophys. Res., 100, 11,447-11,464.
638!! - Lathiere, J., D.A. Hauglustaine, A. Friend, N. De Noblet-Ducoudre, N. Viovy, and
639!!  G. Folberth (2006), Impact of climate variability and land use changes on global biogenic volatile
640!! organic compound emissions, Atmospheric Chemistry and Physics, 6, 2129-2146.
641!! - Lathiere, J., D.A. Hauglustaine, N. De Noblet-Ducoudre, G. Krinner et G.A. Folberth (2005),
642!! Past and future changes in biogenic volatile organic compound emissions simulated with a global
643!! dynamic vegetation model, Geophysical Research Letters, 32, doi: 10.1029/2005GL024164.
644!! - Lathiere, J. (2005), Evolution des emissions de composes organiques et azotes par la biosphere
645!!  continentale dans le modele LMDz-INCA-ORCHIDEE, These de doctorat, Universite Paris VI.
646!!
647!! FLOWCHART    : None
648!_ ================================================================================================================================
649
650  SUBROUTINE chemistry_bvoc (kjpindex, swdown, coszang, temp_air, &
651       temp_sol, ptnlev1, precip_rain, humrel, veget_max, lai, &
652       frac_age, lalo, ccanopy, cim,  wind, snow, &
653       veget, hist_id, hist2_id,kjit, index, &
654       indexlai, indexveg)
655
656    !! 0. Variables and parameter declaration
657
658    !! 0.1 Input variables
659
660    INTEGER(i_std), INTENT(in)                                 :: kjpindex         !! Domain size - terrestrial pixels only (unitless)
661    INTEGER(i_std), INTENT(in)                                 :: kjit             !! Time step number (-)
662    INTEGER(i_std),INTENT (in)                                 :: hist_id          !! History file identifier (-)
663    INTEGER(i_std),INTENT (in)                                 :: hist2_id         !! History file 2 identifier (-)
664    INTEGER(i_std),DIMENSION (kjpindex), INTENT (in)           :: index            !! Indeces of the points on the map (-)
665    INTEGER(i_std),DIMENSION (kjpindex*(nlai+1)), INTENT (in)  :: indexlai         !! Indeces of the points on the 3D map
666    INTEGER(i_std),DIMENSION (kjpindex*nvm), INTENT (in)       :: indexveg         !! Indeces of the points on the 3D map (-)
667    REAL(r_std), DIMENSION(kjpindex), INTENT(in)               :: swdown           !! Down-welling surface short-wave flux
668                                                                                   !! (W.m^{-2})
669    REAL(r_std), DIMENSION(kjpindex), INTENT(in)               :: coszang          !! Cosine of the solar zenith angle (unitless)
670    REAL(r_std), DIMENSION(kjpindex), INTENT(in)               :: temp_air         !! Air temperature (K)
671    REAL(r_std), DIMENSION(kjpindex), INTENT(in)               :: temp_sol         !! Skin temperature (K)
672    REAL(r_std), DIMENSION(kjpindex), INTENT(in)               :: ptnlev1          !! 1st level of soil temperature (K)
673    REAL(r_std), DIMENSION(kjpindex), INTENT(in)               :: precip_rain      !! Rain precipitation !!?? init
674    REAL(r_std), DIMENSION(kjpindex,nvm), INTENT(in)           :: humrel           !! Soil moisture stress (0-1, unitless)
675    REAL(r_std), DIMENSION(kjpindex,nvm), INTENT(in)           :: veget_max        !! Max. vegetation fraction (0-1, unitless)
676    REAL(r_std),DIMENSION (kjpindex), INTENT (in)              :: snow             !! Snow mass (kg)
677    REAL(r_std),DIMENSION (kjpindex,nvm), INTENT (in)          :: veget            !! Fraction of vegetation type (-)
678    REAL(r_std), DIMENSION(kjpindex,nvm), INTENT(in)           :: lai              !! Leaf area index (m^2.m^{-2})
679    REAL(r_std), DIMENSION(kjpindex,nvm,nleafages), INTENT(in) :: frac_age         !! Age efficacity from STOMATE for iso
680    REAL(r_std), DIMENSION(kjpindex,2), INTENT(in)             :: lalo             !! Geographical coordinates for pixels (degrees)
681    REAL(r_std),DIMENSION (kjpindex), INTENT (in)              :: ccanopy          !! CO2 concentration inside the canopy
682    REAL(r_std),DIMENSION (kjpindex,nvm), INTENT (in)          :: cim              !! Intercellular CO2 over nlai
683    REAL(r_std), DIMENSION (kjpindex), INTENT(in)              :: wind             !! Wind module (m s^{-1})
684
685    !! 0.2 Output variables
686
687    !! 0.3 Modified variables
688
689    !! 0.4 Local variables
690
691    INTEGER(i_std)                             :: ji, jv, jf, jl    !! Indices (unitless)
692    REAL(r_std), DIMENSION(kjpindex,nvm)       :: fol_dens          !! foliar density (gDM.m^{-2})
693    REAL(r_std), DIMENSION(kjpindex)           :: tleaf             !! Foliar temperature (K)
694    REAL(r_std), DIMENSION(kjpindex)           :: t_no              !! Temperature used for soil NO emissions (C)
695    REAL(r_std), DIMENSION(kjpindex)           :: exp_1             !! First exponential used in the calculation of
696                                                                    !! isoprene dependancy to Temperature
697    REAL(r_std), DIMENSION(kjpindex)           :: exp_2             !! Second exponential used in the calculation of
698                                                                    !! Isoprene dependancy to Temperature
699    REAL(r_std), DIMENSION(kjpindex)           :: Ct_iso            !! Isoprene dependancy to Temperature
700    REAL(r_std), DIMENSION(kjpindex)           :: Cl_iso            !! Isoprene dependancy to Light
701    REAL(r_std), DIMENSION(kjpindex)           :: Ct_mono           !! Monoterpene dependancy to Temperature
702    REAL(r_std), DIMENSION(kjpindex)           :: Ct_sesq           !! Sesquiterpenes dependancy to Temperature
703    REAL(r_std), DIMENSION(kjpindex)           :: Ct_meth           !! Methanol dependancy to Temperature
704    REAL(r_std), DIMENSION(kjpindex)           :: Ct_acet           !! Acetone dependancy to Temperature
705    REAL(r_std), DIMENSION(kjpindex)           :: Ct_oxyVOC         !! Other oxygenated BVOC dependancy to Temperature
706    REAL(r_std)                                :: GAMMA_iso         !! Temperature and light dependancy for isoprene and fo each PFT
707    REAL(r_std)                                :: GAMMA_iso_m       !! Temperature and light dependancy for isoprene and fo each PFT for multilayer
708    REAL(r_std), DIMENSION(kjpindex)           :: Ylt_mono          !! Total Temperature and light dependancy for monoterpenes
709    REAL(r_std), DIMENSION(kjpindex)           :: Ylt_sesq          !! Total Temperature and light dependancy for sesquiterpens
710    REAL(r_std), DIMENSION(kjpindex)           :: Ylt_meth          !! Total Temperature and light dependancy for methanol
711    REAL(r_std), DIMENSION(kjpindex)           :: Ylt_acet          !! Total Temperature and light dependancy for acetone
712    REAL(r_std), DIMENSION(kjpindex)           :: Ct_MBO            !! MBO dependance to Temperature
713    REAL(r_std), DIMENSION(kjpindex)           :: Cl_MBO            !! MBO dependance to Light
714    REAL(r_std), DIMENSION(kjpindex)           :: Xvar              !! Parameter used in the calculation
715                                                                    !! of MBO dependance to Temperature
716    REAL(r_std), DIMENSION(kjpindex,nvm)       :: flx_OVOC          !! Biogenic OVOC emission -
717                                                                    !! Other Volatil Organic Components (kgC.m^{-2}.s^{-1})
718    !!Canopy radiative transfer model
719    REAL(r_std), DIMENSION(kjpindex)           :: So                !! Maximum radiation at the Earth surface (W.m^{-2})
720    REAL(r_std), DIMENSION(kjpindex)           :: Rfrac             !! Parameter in the regression of diffuse
721                                                                    !! share on transmission
722    REAL(r_std), DIMENSION(kjpindex)           :: Kfrac             !! Parameter in the regression of diffuse
723                                                                    !! share on transmission
724    REAL(r_std), DIMENSION(kjpindex)           :: swdf              !! Sw diffuse radiation (W.m^{-2})
725    REAL(r_std), DIMENSION(kjpindex)           :: swdr              !! Sw direct radiation (W.m^{-2})
726    REAL(r_std), DIMENSION(kjpindex,nvm)       :: PARscat           !! Scatter PAR @tex ($\mu mol m^{-2} s^{-1}$) @endtex
727    REAL(r_std), DIMENSION(kjpindex,nvm)       :: Clsun_iso         !! Isoprene dependance to light for sun leaves
728    REAL(r_std), DIMENSION(kjpindex,nvm)       :: Clsh_iso          !! Isoprene dependance to light for shaded leaves
729    !! for multilayer canopy model for iso flux
730    REAL(r_std), DIMENSION(kjpindex,nlai+1)    :: PARscattab        !! Scatter PAR @tex ($\mu mol m^{-2} s^{-1}$) @endtex
731    REAL(r_std), DIMENSION(nlai+1)             :: laitab            !! LAI per layer (m^2.m^{-2})
732    REAL(r_std), DIMENSION(kjpindex,nlai)      :: laisuntabdep      !! LAI of sun leaves in each layer (m^2.m^{-2})
733    REAL(r_std), DIMENSION(kjpindex,nlai)      :: laishtabdep       !! LAI of shaded leaves in each layer
734                                                                    !! (m^2.m^{-2})
735    REAL(r_std)                                :: Clsun_iso_tab     !! Isoprene dependance to light
736                                                                    !! for sun leaves and per layer
737    REAL(r_std)                                :: Clsh_iso_tab      !! Isoprene dependance to light
738                                                                    !! for shaded leaves and per layer
739    !for multilayer canopy model Spitter et al. 1986
740    REAL(r_std), DIMENSION(kjpindex,nlai+1)    :: PARnotscat        !! Not-Scattered PAR
741    REAL(r_std), DIMENSION(kjpindex,nlai+1)    :: PARabsdir         !! Absorbed light of the PAR direct flux 
742    REAL(r_std), DIMENSION(kjpindex,nlai+1)    :: PARabsdiff        !! Absorbed light of the PAR diffuse flux 
743    REAL(r_std), PARAMETER                     :: sigma = 0.20      !! scattering coefficient of single leaves and for visible radiation
744    REAL(r_std), PARAMETER                     :: cluster = 0.85    !! clustering coefficient for leaves, the same that is setting for default in MEGAN V2.10
745    REAL(r_std)                                :: rho               !! reflection index of a green, closed vegetation
746    REAL(r_std)                                :: kbl               !! extinction coefficient of black leaves
747    REAL(r_std)                                :: kdf               !! extinction coefficient of diffuse flux
748    !!Leaf age
749    REAL(r_std), DIMENSION(kjpindex,nvm)       :: Eff_age_iso       !! Isoprene emission dependance to Leaf Age
750    REAL(r_std), DIMENSION(kjpindex,nvm)       :: Eff_age_meth      !! Methanol emission dependance to Leaf Age
751    REAL(r_std), DIMENSION(kjpindex,nvm)       :: Eff_age_VOC       !! Other VOC emission dependance to Leaf Age
752    !!BBG and Fertilizers for NOx soil emission
753    REAL(r_std), DIMENSION(kjpindex)           :: veget_max_nowoody !! sum of veget_max for non-woody PFT
754    REAL(r_std), DIMENSION(kjpindex,nvm)       :: N_qt_WRICE_pft    !! N fertiliser on RICE
755                                                                    !! (kgN per year per grid cell)
756    REAL(r_std), DIMENSION(kjpindex,nvm)       :: N_qt_OTHER_pft    !! N fertiliser on other veg
757                                                                    !! (kgN per year per grid cell)
758    !! CO2 inhibition effect on isoprene
759    REAL(r_std),DIMENSION (kjpindex,nvm)       :: fco2_wshort       !! Wilkinson short term function for CO2 impact on BVOC (isoprene)
760    REAL(r_std),DIMENSION (kjpindex)           :: fco2_wlong        !! Wilkinson long term function for CO2 impact on BVOC (isoprene)
761    REAL(r_std)                                :: fco2_ctrl
762    REAL(r_std),DIMENSION (kjpindex,nvm)       :: fco2              !! Function for CO2 impact on BVOC (isoprene)
763    REAL(r_std), DIMENSION(kjpindex)           :: Ismax_short
764    REAL(r_std), DIMENSION(kjpindex)           :: h_short
765    REAL(r_std), DIMENSION(kjpindex)           :: Cstar_short
766    REAL(r_std)                                :: Ismax_long
767    REAL(r_std)                                :: h_long
768    REAL(r_std)                                :: Cstar_long
769
770    !! 0.5 Parameters values
771
772    REAL(r_std), PARAMETER :: CT1 = 95000.0       !! Empirical coeffcient (see Guenther .et. al, 1995, eq(10)) (J.mol^{-1})
773    REAL(r_std), PARAMETER :: CT2 = 230000.0      !! Empirical coefficient (see Guenther .et. al, 1995, eq(10)) (J.mol^{-1})
774    REAL(r_std), PARAMETER :: TS = 303.0          !! Leaf temperature at standard condition
775                                                  !! (see Guenther .et. al, 1995, eq(10)) (K)
776    REAL(r_std), PARAMETER :: TM = 314.0          !! Leaf temperature (see Guenther .et. al, 1995, eq(10)) (K)
777
778    REAL(r_std), PARAMETER :: alpha_ = 0.0027     !! Empirical coeffcient (see Guenther .et. al, 1995, eq(9)) (unitless)
779    REAL(r_std), PARAMETER :: CL1 = 1.066         !! Empirical coeffcient (see Guenther .et. al, 1995, eq(9)) (unitless)
780    REAL(r_std), PARAMETER :: beta = 0.09         !! Empirical coeffcient (see Guenther .et. al, 1995, eq(11)) (K^{-1})
781    REAL(r_std), PARAMETER :: lai_threshold = 11. !! Lai threshold for the calculation of scattered radiation
782                                                  !! based on Guenther .et. al (1995) (m^2.m^{-2})
783
784                                             
785    ! Biogenic emissions
786    REAL(r_std),DIMENSION(kjpindex)          :: PAR                !! Photosynthetic active radiation, half of swdown
787                                                                   !! @tex ($\mu mol photons. m^{-2} s^{-1}$) @endtex
788    REAL(r_std),DIMENSION(kjpindex,nvm)      :: PARsun             !! PAR received by sun leaves
789                                                                   !! @tex ($\mu mol m^{-2} s^{-1}$) @endtex
790    REAL(r_std),DIMENSION(kjpindex,nvm)      :: PARsh              !! PAR received by shaded leaves
791                                                                   !! @tex ($\mu mol m^{-2} s^{-1}$) @endtex
792    REAL(r_std),DIMENSION(kjpindex,nvm)      :: laisun             !! Leaf area index of Sun leaves (m^2.m^{-2})
793    REAL(r_std),DIMENSION(kjpindex,nvm)      :: laish              !! Leaf area index of Shaded leaves (m^2.m^{-2})
794
795    CHARACTER(LEN=14)                        :: tleafsun_name      !! To store variables names for I/O
796    CHARACTER(LEN=13)                        :: tleafsh_name       !! To store variables names for I/O
797    REAL(r_std), DIMENSION(kjpindex,nlai+1)  :: Tleafsun_temp      !! temporary sunlit leaf temperature matrix for writing
798    REAL(r_std), DIMENSION(kjpindex,nlai+1)  :: Tleafsh_temp       !! temporary shade leaf temperature matrix for writing
799    REAL(r_std),DIMENSION(kjpindex)          :: Fdf                !! Fraction of the radiation which is diffused (0-1, unitless)
800    REAL(r_std),DIMENSION(kjpindex,nlai+1)   :: PARsuntab          !! PAR received by sun leaves over LAI layers
801                                                                   !! @tex ($\mu mol m^{-2} s^{-1}$) @endtex
802    REAL(r_std),DIMENSION(kjpindex,nlai+1)   :: PARshtab           !! PAR received by shaded leaves over LAI layers
803                                                                   !! @tex ($\mu mol m^{-2} s^{-1}$) @endtex
804    REAL(r_std),DIMENSION(kjpindex)          :: PARdf              !! Diffuse photosynthetic active radiation
805                                                                   !! @tex ($\mu mol m^{-2} s^{-1}$) @endtex
806    REAL(r_std),DIMENSION(kjpindex)          :: PARdr              !! Direct photosynthetic active radiation
807                                                                   !! @tex ($\mu mol m^{-2} s^{-1}$) @endtex
808    REAL(r_std),DIMENSION(kjpindex)          :: Trans              !! Atmospheric Transmissivity (unitless)
809
810!_ ================================================================================================================================
811        fco2 = 0.
812        fco2_wshort = 0.
813        fco2_wlong = 0.
814        Fdf(:) = 0.
815        PAR(:) = 0. 
816        PARsun(:,:) = 0. 
817        PARsh(:,:) = 0. 
818        laisun(:,:) = 0. 
819        laish(:,:) = 0. 
820        CRF(:,:) = 0.               
821        Trans(:) = 0.           
822        PARdf(:) = 0.           
823        PARdr(:) = 0.           
824        PARsuntab(:,:) = 0.       
825        PARshtab(:,:) = 0.       
826   
827
828    !! 1. Canopy radiative transfer model
829
830    !! Canopy radiative transfer model: takes into account light extinction through canopy
831    !! First need to calculate diffuse and direct radiation
832    !! Based on Andrew Friend radiative model (Global Ecology & Biogeography, 2001)
833    !! And Spitters et al. (Agricultural and Forest Meteorology, 1986)
834       
835    IF ( ok_radcanopy ) THEN
836
837       DO ji = 1, kjpindex
838          IF (coszang(ji) .GT. zero) THEN
839             !! 1.1 Extra-terrestrial solar irradiance at a plan parallel to Earh's surface
840             So(ji) = Sct*( un + 0.033*COS(360.*pi/180.*julian_diff/365.))*coszang(ji)
841             !! 1.2 Atmospheric transmissivity
842             Trans(ji) = swdown(ji)/So(ji)
843             !! 1.3 Empirical calculation of fraction diffuse from transmission based on Spitters et al. (1986)
844             Rfrac(ji) = 0.847 - 1.61*coszang(ji) + 1.04*(coszang(ji)**2.)
845             Kfrac(ji) = (1.47 - Rfrac(ji))/1.66     
846             IF (Trans(ji) .LE. 0.22) THEN
847                Fdf(ji) = un
848             ELSE IF (Trans(ji) .LE. 0.35) THEN
849                Fdf(ji) = un - 6.4*((Trans(ji) - 0.22)**2.) 
850             ELSE IF (Trans(ji) .LE. Kfrac(ji)) THEN
851                Fdf(ji) = 1.47 - 1.66*Trans(ji)
852             ELSE
853                Fdf(ji) = Rfrac(ji)
854             END IF
855             !! 1.4 Direct and diffuse sw radiation in W.m^{-2}
856             swdf(ji) = swdown(ji)*Fdf(ji)
857             swdr(ji) = swdown(ji)*(un-Fdf(ji))
858          ELSE
859             swdf(ji) = zero
860             swdr(ji) = zero
861          END IF
862
863          !! 1.5 PAR diffuse and direct in umol/m^2/s
864          PARdf(ji) = swdf(ji) * W_to_mol * RG_to_PAR
865          PARdr(ji) = swdr(ji) * W_to_mol * RG_to_PAR 
866       END DO
867
868       !! 1.6 Calculation of lai, parscat, parsh and parsun, laisun and laish !!?? define the terms
869       !! Based on Guenther et al. (JGR, 1995) and Norman (1982)
870       ! One-layer canopy model or multi-layer canopy model
871       IF (ok_multilayer) THEN 
872
873
874          ! Calculation PER LAYER
875          DO jl = nlai+1, 1, -1
876            laitab(jl) = laimax*(EXP(lai_level_depth*(jl-1) - un)/(EXP(lai_level_depth*nlai) - un))
877
878         !introduction of the Spitter way to calculate radiation over the levels !!!!!!!
879             DO ji = 1, kjpindex
880                kdf = cluster*0.8*SQRT((1 - sigma))
881                IF (ABS(ACOS(coszang(ji))) .LT. pi/2. .AND. coszang(ji) .NE. zero) THEN
882                   ! Coefficients calculation:
883                   kbl = cluster*0.5/ABS(coszang(ji))
884                   rho = ((1-SQRT((1 - sigma)))/(1+SQRT((1 - sigma))))*(2/(1+1.6*ABS(coszang(ji))))
885
886                   PARnotscat(ji,jl) = (1 - sigma)*PARdr(ji)*kbl*EXP(-SQRT((1 - sigma))*kbl*laitab(jl))
887                   PARabsdir(ji,jl) = (1 - rho)*SQRT((1 - sigma))*PARdr(ji)*kbl*EXP(-SQRT((1 - sigma))*kbl*laitab(jl))
888                   PARabsdiff(ji,jl) = (1 - rho)*PARdf(ji)*kdf*EXP(-kdf*laitab(jl))
889                   PARshtab(ji,jl) = (PARabsdiff(ji,jl) + (PARabsdir(ji,jl) - PARnotscat(ji,jl)))/(1 - sigma)
890                   PARsuntab(ji,jl) = PARshtab(ji,jl) + (1-sigma)*kbl*PARdr(ji)/(1 - sigma) 
891
892                   !correction using the equation (4) in Bodin et al 2012 and (7) or (8) in Spitter et al 1986
893                   !using the extinction coefficient kbl = 0.5/coszang and not only 0.5
894                   IF (jl .NE. nlai+1) THEN
895                      laisuntabdep(ji,jl) =(laitab(jl+1)-laitab(jl))*EXP(-kbl*laitab(jl))
896                      laishtabdep(ji,jl) =(laitab(jl+1)-laitab(jl))*(1.-EXP(-kbl*laitab(jl)))
897                   ENDIF
898
899                ELSE
900
901                   PARshtab(ji,jl) = PARdf(ji)*kdf*EXP(-kdf*laitab(jl))
902                   PARsuntab(ji,jl) = 0.
903
904                   IF (jl .NE. nlai+1) THEN
905                      laisuntabdep(ji,jl) = 0.
906                      laishtabdep(ji,jl) = laitab(jl+1)-laitab(jl)
907
908                   ENDIF 
909                END IF
910             END DO
911          END DO
912
913
914
915       ! introduction of the Spitter way to calculate radiation over the levels !!!!!!!
916       ELSE
917          ! Calculation FOR one layer
918          DO jv = 1, nvm
919             DO ji = 1, kjpindex
920                IF (lai(ji,jv) .LE. lai_threshold) THEN
921                   PARscat(ji,jv) = 0.07*PARdr(ji)*(1.1 - 0.1*lai(ji,jv))*exp(-coszang(ji))
922                ELSE
923                   PARscat(ji,jv) = zero
924                END IF
925
926                IF (coszang(ji) .NE. zero ) THEN
927                   PARsh(ji,jv) = PARdf(ji)*exp(-0.5*((lai(ji,jv))**0.7)) + PARscat(ji,jv)
928                   PARsun(ji,jv) = PARdr(ji)*COS(60.*pi/180.)/coszang(ji) + PARsh(ji,jv)
929                ELSE
930                   PARsh(ji,jv) = PARdf(ji)*exp(-0.5*(lai(ji,jv)**0.7)) + PARscat(ji,jv)
931                   PARsun(ji,jv) = zero 
932                END IF
933                IF (ABS(ACOS(coszang(ji))) .LT. pi/2. .AND. ABS(coszang(ji)) .GT. min_sechiba) THEN 
934                   ! calculation as in Lathiere (2005) = with correction removing lai in Guenther (1995)
935                   laisun(ji,jv) = (un - exp(-0.5*lai(ji,jv)/(coszang(ji))))*coszang(ji)/COS(60.*pi/180.)
936                   laish(ji,jv) = lai(ji,jv) - laisun(ji,jv)
937                ELSE
938                   laisun(ji,jv) = zero
939                   laish(ji,jv) = lai(ji,jv)
940                END IF
941             END DO
942          END DO
943       ENDIF
944    END IF
945
946
947    !! 2. Calculation of non-PFT dependant parameters used for VOC emissions
948    DO ji = 1, kjpindex ! (loop over # pixels)
949       !! 2.1 Calculation of Tleaf (based on Lathiere, 2005)
950
951
952       tleaf(ji) = temp_air(ji)
953
954       !! 2.2 Isoprene emission dependency - with no PARsun/PARshaded partitioning - Guenther et al. (1995) and Lathiere (2005)
955       !> @codeinc $$?? ecrire les equation en latex ?
956       exp_1(ji) = exp( (CT1 * ( tleaf(ji) - TS )) / (RR*TS*tleaf(ji)) )
957       exp_2(ji) = exp( (CT2 *( tleaf(ji) - TM )) / (RR*TS*tleaf(ji)) )
958       PAR(ji)   = swdown(ji) * W_to_mol * RG_to_PAR        ! from W/m^2 to umol photons/m^2/s and half of sw for PAR
959       Ct_iso(ji)    = exp_1(ji)/(un + exp_2(ji))            ! temperature dependance 
960       Cl_iso(ji)    = alpha_*CL1*PAR(ji)/sqrt(un + (alpha_**2) * (PAR(ji)**2) ) ! light dependance
961       !> @endcodeinc
962 
963       !! 2.3 Monoterpene and oxy VOB emission dependency to Temperature
964       !!     light independant fraction
965       !> @codeinc
966       !Ct_mono(ji) = exp(beta*(tleaf(ji) - TS))  ! Old method
967       Ct_mono(ji) = exp(beta_mono*(tleaf(ji) - TS))
968       Ct_sesq(ji) = exp(beta_sesq*(tleaf(ji) - TS))
969       Ct_meth(ji) = exp(beta_meth*(tleaf(ji) - TS))
970       Ct_acet(ji) = exp(beta_acet*(tleaf(ji) - TS))
971       Ct_oxyVOC(ji) = exp(beta_oxyVOC*(tleaf(ji) - TS))     
972       !> @endcodeinc
973       !! 2.4 MBO biogenic emissions dependency, only from PFT7 and PFT4 for location of vegetation emitter
974       ! but in fact MBO fluxes only in America (ponderosa and lodgepole pines only found in these areas)
975       !> @codeinc
976       Xvar(ji) = ((un/312.3) - (un/tleaf(ji)))/RR
977       !> @endcodeinc
978       !! 2.4.1 temperature dependency
979       !> @codeinc
980       Ct_MBO(ji)    = (1.52*209000.0*exp(67000.0*Xvar(ji)))/(209000.0 - 67000.0*(un - exp(209000.0*Xvar(ji))))
981       !> @endcodeinc
982       !! 2.4.2 light dependency
983       Cl_MBO(ji)    = (0.0011*1.44*PAR(ji))/(sqrt(un + (0.0011**2)*(PAR(ji)**2)))
984       !! 2.5 NO biogenic emissions given in ngN/m^2/s, emission factor in ngN/m^2/s too
985       !! calculation of temperature used for NO soil emissions
986       t_no(ji) = ptnlev1(ji) - ZeroCelsius  !!temp must be in celsius to calculate no emissions
987       !! 2.6 calculation of non-woody veget_max fraction
988       IF (ok_cropsfertil_NOx) THEN
989          veget_max_nowoody(ji) = zero
990          DO jv = 1,nvm
991             IF ( (jv /= ibare_sechiba) .AND. .NOT.(is_tree(jv)) ) THEN
992                veget_max_nowoody(ji) = veget_max_nowoody(ji) + veget_max(ji,jv)
993             ENDIF
994          ENDDO
995       END IF
996    END DO ! (loop over # pixels)
997
998    !! 2bis. Calculation of CO2 function for inhibition effect on isoprene
999    ! 2 approaches can be used: either Possell et al. (2005) or Wilkinson et al. (2006)
1000
1001!! 19/04/2010 and then implemented in version revised by Nicolas Vuichard, 08042014
1002!! Impact of atmospheric CO2 on isoprene emissions
1003!! Can be activated or not
1004!! If considered, can use either Possell 2005 or Wilkinson 2009 parameterisation
1005!! This is used to rescale the emission factor, considered to be measured at 350 ppm of CO2
1006!! to the CO2 conditions of the run
1007
1008IF ( ok_co2bvoc_poss ) THEN
1009   WRITE(numout,*) 'CO2 impact on isoprene: Possell calculation'
1010
1011   !! Possell function needs to be normalized (experiments at 400 ppm and EF before 1995)
1012   !! Normalized at 350 ppm
1013   fco2_ctrl = (-0.0123+(441.4795/350.)+(-1282.65/(350.**2)))
1014
1015   !! 2 tests: using the canopy (atmospheric) CO2 'ccanopy'
1016   !! or the intercellular CO2 over nlai 'cim'
1017   !! with cim = ccanopy*0.667
1018   !! in the end I go for ccanopy for the Possell function since too much differences
1019   !! when using cim and also the function has been derived based on atmospheric CO2
1020   DO ji = 1, kjpindex
1021
1022      fco2(ji,:) = (-0.0123+(441.4795/ccanopy(ji))+(-1282.65/(ccanopy(ji)*ccanopy(ji))))/fco2_ctrl
1023
1024   END DO
1025ELSE IF ( ok_co2bvoc_wilk ) THEN
1026   WRITE(numout,*) 'CO2 impact on isoprene: Wilkinson calculation'
1027
1028   !! In the Wilkinson function, 2 impacts are considered:
1029   !! -short-term impact for CO2 variation during a single day (seconds/minutes)
1030   !! -long-term impact for CO2 variation during leaf-growth (weeks/month)
1031
1032
1033   !! Long-term parameters
1034   !! Constant
1035   Ismax_long = 1.344
1036   h_long = 1.4614
1037   Cstar_long = 585.
1038   !! Short-term parameters
1039   !! They have to be calculated based on atmospheric CO2
1040   !! 10/05/2010
1041   !! For atmospheric CO2 lower than 400 ppm or higher than 1200 ppm
1042   !! (min and max CO2 level tested for short-term effect in Wilkinson et al. 2009)
1043   !! we use the parameters calculated at 400/1200 ppm. For intermediate CO2 concentration,
1044   !! parameters are calculated.
1045   !! Linear interpolation
1046
1047   DO ji = 1, kjpindex
1048
1049      IF (ccanopy(ji) .LE. 400.) THEN
1050
1051         Ismax_short(ji) = 1.072
1052         h_short(ji) = 1.7
1053         Cstar_short(ji) = 1218.
1054
1055      ELSE IF (ccanopy(ji) .EQ. 600.) THEN
1056
1057         Ismax_short(ji) = 1.036
1058         h_short(ji) = 2.0125
1059         Cstar_short(ji) = 1150.
1060
1061      ELSE IF (ccanopy(ji) .EQ. 800.) THEN
1062
1063         Ismax_short(ji) = 1.046
1064         h_short(ji) = 1.5380
1065         Cstar_short(ji) = 2025.
1066
1067      ELSE IF (ccanopy(ji) .GE. 1200.) THEN
1068
1069         Ismax_short(ji) = 1.014
1070         h_short(ji) = 2.8610
1071         Cstar_short(ji) = 1525.
1072
1073
1074      ELSE IF ((ccanopy(ji) .GT. 400.) .AND. (ccanopy(ji) .LT. 600.)) THEN
1075
1076         Ismax_short(ji) = 1.036 + (ccanopy(ji)-600.)*(1.036-1.072)/(600.-400.)
1077         h_short(ji) = 2.0125 + (ccanopy(ji)-600.)*(2.0125-1.7)/(600.-400.)
1078         Cstar_short(ji) =  1150. + (ccanopy(ji)-600.)*(1150.-1218.)/(600.-400.)
1079
1080      ELSE IF ((ccanopy(ji) .GT. 600.) .AND. (ccanopy(ji) .LT. 800.)) THEN
1081
1082         Ismax_short(ji) = 1.046 + (ccanopy(ji)-800.)*(1.046-1.036)/(800.-600.)
1083         h_short(ji) = 1.5380 + (ccanopy(ji)-800.)*(1.5380-2.0125)/(800.-600.)
1084         Cstar_short(ji) = 2025. + (ccanopy(ji)-800.)*(2025.-1150.)/(800.-600.)
1085
1086      ELSE IF ((ccanopy(ji) .GT. 800.) .AND. (ccanopy(ji) .LT. 1200.)) THEN
1087
1088        Ismax_short(ji) = 1.014 + (ccanopy(ji)-1200.)*(1.014-1.046)/(1200.-800.)
1089        h_short(ji) = 2.8610 + (ccanopy(ji)-1200.)*(2.8610-1.5380)/(1200.-800.)
1090        Cstar_short(ji) = 1525. + (ccanopy(ji)-1200.)*(1525.-2025.)/(1200.-800.)
1091
1092
1093      END IF
1094
1095   END DO
1096
1097   WRITE(numout,*) '***Wilkinson BVOC-CO2 function: parameters***'
1098   WRITE(numout,*) 'Ismax_long: ', Ismax_long
1099   WRITE(numout,*) 'h_long: ', h_long
1100   WRITE(numout,*) 'Cstar_long: ', Cstar_long
1101   WRITE(numout,*) 'Ismax_short: ', MAXVAL(Ismax_short(:)) , MINVAL(Ismax_short(:))
1102   WRITE(numout,*) 'h_short: ', MAXVAL(h_short(:)) , MINVAL(h_short(:))
1103   WRITE(numout,*) 'Cstar_short: ', MAXVAL(Cstar_short(:)) , MINVAL(Cstar_short(:))
1104   WRITE(numout,*) '******'
1105
1106   DO ji = 1, kjpindex
1107      fco2_wlong(ji) = (Ismax_long-((Ismax_long*((0.667*ccanopy(ji))**h_long))/&
1108                     & ((Cstar_long**h_long)+(0.667*ccanopy(ji))**h_long)))/1.06566
1109      DO jv = 1, nvm
1110         fco2_wshort(ji,jv) = (Ismax_short(ji)-((Ismax_short(ji)*((cim(ji,jv))**h_short(ji)))/&
1111                            & ((Cstar_short(ji)**h_short(ji))+(cim(ji,jv))**h_short(ji))))/1.010803
1112      END DO
1113   END DO
1114
1115   DO ji = 1, kjpindex
1116      DO jv = 1, nvm
1117         fco2(ji,jv) = fco2_wshort(ji,jv)*fco2_wlong(ji)
1118      END DO
1119   END DO
1120
1121ELSE
1122      WRITE(numout,*) 'CO2 impact on isoprene not considered'
1123      fco2(:,:) = 1.
1124END IF
1125
1126
1127    !! 3. Calculation of PFT dependant parameters and
1128    ! Calculation of VOC emissions flux
1129
1130    Eff_age_iso(:,:) = zero
1131    Eff_age_meth(:,:) = zero
1132
1133
1134    DO jv = 1, nvm ! loop over the PDFs
1135       DO ji = 1, kjpindex ! loop over the grid cell
1136          ! 6-Calculation of Leaf Age Function (Lathiere 2005)
1137          IF ( ok_leafage ) THEN
1138             DO jf = 1, nleafages
1139                !> @codeinc
1140                Eff_age_iso(ji,jv) = Eff_age_iso(ji,jv) + frac_age(ji,jv,jf)*iso_activity(jf)
1141                Eff_age_meth(ji,jv) = Eff_age_meth(ji,jv) + frac_age(ji,jv,jf)*methanol_activity(jf)
1142                !> @endcodeinc
1143             END DO
1144             !> @codeinc
1145             Eff_age_VOC(ji,jv) = un
1146             !> @endcodeinc
1147          ELSE
1148             Eff_age_iso(ji,jv) = un
1149             Eff_age_meth(ji,jv) = un
1150             Eff_age_VOC(ji,jv) = un
1151          END IF
1152          !! 5. Calculation of foliar density
1153          ! Changes the IF-statement so it also works for
1154          ! a dynamic sla
1155!!$          IF ( sla(jv) .eq. zero ) THEN
1156          IF ( veget_max(ji,jv) .eq. zero ) THEN
1157             fol_dens(ji,jv) = zero
1158          ELSE
1159             ! 2 factor for conversion from gC to gDM. Use
1160             ! lai_to_biomass to account for dynamic sla
1161             fol_dens(ji,jv) = lai_to_biomass(2 * lai(ji,jv),jv)
1162          ENDIF
1163          !! 6. Calculation of VOC emissions from vegetation
1164          IF ( ok_radcanopy ) THEN
1165             ! if multi-layer canopy model
1166             IF (ok_multilayer) THEN
1167
1168                laisun(ji,jv) = zero
1169                laish(ji,jv) = zero
1170                GAMMA_iso_m  = zero
1171                flx_iso(ji,jv) = zero
1172                flx_mono(ji,jv) = zero
1173                flx_apinen(ji,jv) = zero
1174                flx_bpinen(ji,jv) = zero
1175                flx_limonen(ji,jv) = zero
1176                flx_myrcen(ji,jv) =  zero
1177                flx_sabinen(ji,jv) =  zero
1178                flx_camphen(ji,jv) = zero
1179                flx_3caren(ji,jv) = zero
1180                flx_tbocimen(ji,jv) = zero
1181                flx_othermono(ji,jv) = zero
1182                flx_sesquiter(ji,jv) =  zero
1183                flx_methanol(ji,jv) = zero
1184                flx_acetone(ji,jv) =  zero
1185                flx_acetal(ji,jv) = zero
1186                flx_formal(ji,jv) = zero
1187                flx_acetic(ji,jv) = zero
1188                flx_formic(ji,jv) = zero
1189                ! loop over the NLAI canopy layers
1190                DO jl = 1, nlai
1191                   IF ((laitab(jl) .LE. lai(ji,jv)).AND.(lai(ji,jv).NE.zero)) THEN
1192                      !sunlit vegetation
1193                      Clsun_iso_tab   = alpha_*CL1*PARsuntab(ji,jl)/sqrt(un + (alpha_**2) * (PARsuntab(ji,jl)**2) )
1194                      ! shaded vegetation
1195                      Clsh_iso_tab    = alpha_*CL1*PARshtab(ji,jl)/sqrt(un + (alpha_**2) * (PARshtab(ji,jl)**2) ) 
1196                      flx_iso(ji,jv) = flx_iso(ji,jv) + (laisuntabdep(ji,jl)*Clsun_iso_tab+ &
1197                           & laishtabdep(ji,jl)*Clsh_iso_tab)* &
1198                           & fol_dens(ji,jv)/lai(ji,jv)*Ct_iso(ji)*em_factor_isoprene(jv)* &
1199                           & Eff_age_iso(ji,jv)*fco2(ji,jv)*1e-9/one_hour
1200
1201                      GAMMA_iso_m = GAMMA_iso_m + (laisuntabdep(ji,jl)*Clsun_iso_tab+ &
1202                           & laishtabdep(ji,jl)*Clsh_iso_tab)* &
1203                           & fol_dens(ji,jv)/lai(ji,jv)*Ct_iso(ji)*1e-9/one_hour
1204
1205                      laisun(ji,jv) = laisun(ji,jv) + laisuntabdep(ji,jl)
1206                      laish(ji,jv)  = laish(ji,jv) + laishtabdep(ji,jl)
1207                   END IF
1208                END DO
1209
1210                !! 6.1 Calculation of monoterpene biogenic emissions
1211                flx_mono(ji,jv) = ((1-LDF_mono)*Ct_mono(ji)*1e-9/one_hour*fol_dens(ji,jv) + LDF_mono*GAMMA_iso_m)* &
1212                     & em_factor_monoterpene(jv)*Eff_age_VOC(ji,jv) 
1213                !! 6.12 Calculation of sesquiterpenes biogenic emission
1214                flx_sesquiter(ji,jv) = ((1-LDF_sesq)*Ct_sesq(ji)*1e-9/one_hour*fol_dens(ji,jv) +LDF_sesq*GAMMA_iso_m)* &
1215                     & em_factor_sesquiterp(jv)*Eff_age_VOC(ji,jv)
1216                !! 6.13 Calculation of methanol biogenic emissions
1217                flx_methanol(ji,jv) = ((1-LDF_meth)*Ct_meth(ji)*1e-9/one_hour*fol_dens(ji,jv) +LDF_meth*GAMMA_iso_m)* &
1218                     & em_factor_methanol(jv)*Eff_age_meth(ji,jv)
1219                !! 6.14 Calculation of acetone biogenic emissions
1220                flx_acetone(ji,jv) = ((1-LDF_acet)*Ct_acet(ji)*1e-9/one_hour*fol_dens(ji,jv) +LDF_acet*GAMMA_iso_m)* &
1221                     & em_factor_acetone(jv)*Eff_age_VOC(ji,jv)
1222                !! 6.14 Calculation of acetaldehyde biogenic emissions
1223                flx_acetal(ji,jv) = ((1-LDF_meth)*Ct_meth(ji)*1e-9/one_hour*fol_dens(ji,jv) +LDF_meth*GAMMA_iso_m)* &
1224                     & em_factor_acetal(jv)*Eff_age_VOC(ji,jv)
1225                !! 6.16 Calculation of formaldehyde biogenic emissions
1226                flx_formal(ji,jv) = ((1-LDF_meth)*Ct_meth(ji)*1e-9/one_hour*fol_dens(ji,jv) +LDF_meth*GAMMA_iso_m)* &
1227                     & em_factor_formal(jv)*Eff_age_VOC(ji,jv)
1228                !! 6.17 Calculation of acetic acid biogenic emissions
1229                flx_acetic(ji,jv) = ((1-LDF_meth)*Ct_meth(ji)*1e-9/one_hour*fol_dens(ji,jv) +LDF_meth*GAMMA_iso_m)* &
1230                     & em_factor_acetic(jv)*Eff_age_VOC(ji,jv)
1231                !! 6.18 Calculation of formic acid biogenic emissions
1232                flx_formic(ji,jv) = ((1-LDF_meth)*Ct_meth(ji)*1e-9/one_hour*fol_dens(ji,jv) +LDF_meth*GAMMA_iso_m)* &
1233                     & em_factor_formic(jv)*Eff_age_VOC(ji,jv)
1234
1235
1236                !! 6.3 Calculation of alfa pinene biogenic emission
1237                flx_apinen(ji,jv) = em_factor_apinene(jv)*flx_mono(ji,jv) 
1238                !! 6.4 Calculation of beta pinene biogenic emission
1239                flx_bpinen(ji,jv) = em_factor_bpinene(jv)*flx_mono(ji,jv) 
1240                !! 6.5 Calculation of limonene biogenic emission
1241                flx_limonen(ji,jv) = em_factor_limonene(jv)*flx_mono(ji,jv) 
1242                !! 6.6 Calculation of myrcene biogenic emission !!
1243                flx_myrcen(ji,jv) = em_factor_myrcene(jv)*flx_mono(ji,jv) 
1244                !! 6.7 Calculation of sabinene biogenic emission
1245                flx_sabinen(ji,jv) = em_factor_sabinene(jv)*flx_mono(ji,jv) 
1246                !! 6.8 Calculation of camphene biogenic emission
1247                flx_camphen(ji,jv) = em_factor_camphene(jv)*flx_mono(ji,jv) 
1248                !! 6.9 Calculation of 3-carene biogenic emission
1249                flx_3caren(ji,jv) = em_factor_3carene(jv)*flx_mono(ji,jv) 
1250                !! 6.10 Calculation of t-beta-ocimene biogenic emission
1251                flx_tbocimen(ji,jv) = em_factor_tbocimene(jv)*flx_mono(ji,jv) 
1252                !! 6.11 Calculation of other monoterpenes biogenic emission
1253                flx_othermono(ji,jv) = em_factor_othermonot(jv)*flx_mono(ji,jv) 
1254
1255                ! if mono-layer canopy model
1256             ELSE
1257                !sunlit vegetation
1258                Clsun_iso(ji,jv)   = alpha_*CL1*PARsun(ji,jv)/sqrt(un + (alpha_**2) * (PARsun(ji,jv)**2) )
1259                ! shaded vegetation     
1260                Clsh_iso(ji,jv)    = alpha_*CL1*PARsh(ji,jv)/sqrt(un + (alpha_**2) * (PARsh(ji,jv)**2) )       
1261                IF (lai(ji,jv) .NE. zero) THEN
1262                   !! 6.1 Calculation of isoprene biogenic emissions
1263                   GAMMA_iso = (laisun(ji,jv)*Clsun_iso(ji,jv) + laish(ji,jv)*Clsh_iso(ji,jv))/lai(ji,jv)*Ct_iso(ji)
1264                   flx_iso(ji,jv) = GAMMA_iso*fol_dens(ji,jv)*em_factor_isoprene(jv)*Eff_age_iso(ji,jv)*fco2(ji,jv)*1e-9/one_hour
1265                   !! 6.2 Calculation of monoterpene biogenic emissions
1266                   flx_mono(ji,jv) = ((1-LDF_mono)*Ct_mono(ji)+LDF_mono*GAMMA_iso)*fol_dens(ji,jv)* &
1267                        & em_factor_monoterpene(jv)*Eff_age_VOC(ji,jv)*1e-9/one_hour
1268                   !! 6.3 Calculation of alfa pinene biogenic emission
1269                   flx_apinen(ji,jv) = em_factor_apinene(jv)*flx_mono(ji,jv)
1270                   !! 6.4 Calculation of beta pinene biogenic emission
1271                   flx_bpinen(ji,jv) = em_factor_bpinene(jv)*flx_mono(ji,jv)
1272                   !! 6.5 Calculation of limonene biogenic emission
1273                   flx_limonen(ji,jv) = em_factor_limonene(jv)*flx_mono(ji,jv)
1274                   !! 6.6 Calculation of myrcene biogenic emission
1275                   flx_myrcen(ji,jv) = em_factor_myrcene(jv)*flx_mono(ji,jv)
1276                   !! 6.7 Calculation of sabinene biogenic emission
1277                   flx_sabinen(ji,jv) = em_factor_sabinene(jv)*flx_mono(ji,jv)
1278                   !! 6.8 Calculation of camphene biogenic emission
1279                   flx_camphen(ji,jv) = em_factor_camphene(jv)*flx_mono(ji,jv)
1280                   !! 6.9 Calculation of 3-carene biogenic emission
1281                   flx_3caren(ji,jv) = em_factor_3carene(jv)*flx_mono(ji,jv)
1282                   !! 6.10 Calculation of t-beta-ocimene biogenic emission
1283                   flx_tbocimen(ji,jv) = em_factor_tbocimene(jv)*flx_mono(ji,jv)
1284                   !! 6.11 Calculation of other monoterpenes biogenic emission
1285                   flx_othermono(ji,jv) = em_factor_othermonot(jv)*flx_mono(ji,jv)
1286                   !! 6.12 Calculation of sesquiterpenes biogenic emission
1287                   flx_sesquiter(ji,jv) = ((1-LDF_sesq)*Ct_sesq(ji)+LDF_sesq*GAMMA_iso)*fol_dens(ji,jv)* &
1288                        & em_factor_sesquiterp(jv)*Eff_age_VOC(ji,jv)*1e-9/one_hour
1289                   !! 6.13 Calculation of methanol biogenic emissions
1290                   flx_methanol(ji,jv) = ((1-LDF_meth)*Ct_meth(ji)+LDF_meth*GAMMA_iso)*fol_dens(ji,jv)* &
1291                        & em_factor_methanol(jv)*Eff_age_meth(ji,jv)*1e-9/one_hour
1292                   !! 6.14 Calculation of acetone biogenic emissions
1293                   flx_acetone(ji,jv) = ((1-LDF_acet)*Ct_acet(ji)+LDF_acet*GAMMA_iso)*fol_dens(ji,jv)* &
1294                        & em_factor_acetone(jv)*Eff_age_VOC(ji,jv)*1e-9/one_hour
1295                   !! 6.15 Calculation of acetaldehyde biogenic emissions
1296                   flx_acetal(ji,jv) = ((1-LDF_meth)*Ct_meth(ji)+LDF_meth*GAMMA_iso)*fol_dens(ji,jv)* &
1297                        & em_factor_acetal(jv)*Eff_age_VOC(ji,jv)*1e-9/one_hour
1298                   !! 6.16 Calculation of formaldehyde biogenic emissions
1299                   flx_formal(ji,jv) = ((1-LDF_meth)*Ct_meth(ji)+LDF_meth*GAMMA_iso)*fol_dens(ji,jv)* &
1300                        & em_factor_formal(jv)*Eff_age_VOC(ji,jv)*1e-9/one_hour
1301                   !! 6.17 Calculation of acetic acid biogenic emissions
1302                   flx_acetic(ji,jv) = ((1-LDF_meth)*Ct_meth(ji)+LDF_meth*GAMMA_iso)*fol_dens(ji,jv)* &
1303                        & em_factor_acetic(jv)*Eff_age_VOC(ji,jv)*1e-9/one_hour
1304                   !! 6.18 Calculation of formic acid biogenic emissions
1305                   flx_formic(ji,jv) = ((1-LDF_meth)*Ct_meth(ji)+LDF_meth*GAMMA_iso)*fol_dens(ji,jv)* &
1306                        & em_factor_formic(jv)*Eff_age_VOC(ji,jv)*1e-9/one_hour
1307 
1308                ELSE
1309                   !
1310                   flx_iso(ji,jv) = zero
1311                   flx_mono(ji,jv) = zero
1312                   flx_apinen(ji,jv) = zero 
1313                   flx_bpinen(ji,jv) = zero 
1314                   flx_limonen(ji,jv) = zero 
1315                   flx_myrcen(ji,jv) =  zero
1316                   flx_sabinen(ji,jv) =  zero 
1317                   flx_camphen(ji,jv) = zero 
1318                   flx_3caren(ji,jv) = zero 
1319                   flx_tbocimen(ji,jv) = zero
1320                   flx_othermono(ji,jv) = zero 
1321                   flx_sesquiter(ji,jv) =  zero 
1322                   flx_methanol(ji,jv) = zero
1323                   flx_acetone(ji,jv) =  zero 
1324                   flx_acetal(ji,jv) = zero
1325                   flx_formal(ji,jv) = zero 
1326                   flx_acetic(ji,jv) = zero 
1327                   flx_formic(ji,jv) = zero 
1328                END IF
1329             END IF
1330             ! if no light extinction due to vegetation 
1331          ELSE
1332             !! Isoprene emissions - general equation
1333             flx_iso(ji,jv) = fol_dens(ji,jv)*Ct_iso(ji)*Cl_iso(ji)*Eff_age_iso(ji,jv)*fco2(ji,jv)* &
1334                  em_factor_isoprene(jv)*1e-9/one_hour
1335             !! 6.2 Calculation of monoterpene biogenic emissions
1336             Ylt_mono(ji) = ((1-LDF_mono)*Ct_mono(ji)+LDF_mono*Ct_iso(ji)*Cl_iso(ji)) 
1337             flx_mono(ji,jv) = fol_dens(ji,jv)*em_factor_monoterpene(jv)*Ylt_mono(ji)*Eff_age_VOC(ji,jv)*&
1338                  1e-9/one_hour
1339             !! 6.3 Calculation of alfa pinene biogenic emission
1340             flx_apinen(ji,jv) = em_factor_apinene(jv)*flx_mono(ji,jv) 
1341             !! 6.4 Calculation of beta pinene biogenic emission
1342             flx_bpinen(ji,jv) = em_factor_bpinene(jv)*flx_mono(ji,jv)                       
1343             !! 6.5 Calculation of limonene biogenic emission
1344             flx_limonen(ji,jv) = em_factor_limonene(jv)*flx_mono(ji,jv)                     
1345             !! 6.6 Calculation of myrcene biogenic emission
1346             flx_myrcen(ji,jv) = em_factor_myrcene(jv)*flx_mono(ji,jv)                       
1347             !! 6.7 Calculation of sabinene biogenic emission
1348             flx_sabinen(ji,jv) = em_factor_sabinene(jv)*flx_mono(ji,jv)           
1349             !! 6.8 Calculation of camphene biogenic emission
1350             flx_camphen(ji,jv) = em_factor_camphene(jv)*flx_mono(ji,jv)
1351             !! 6.9 Calculation of 3-carene biogenic emission
1352             flx_3caren(ji,jv) = em_factor_3carene(jv)*flx_mono(ji,jv)                       
1353             !! 6.10 Calculation of t-beta-ocimene biogenic emission
1354             flx_tbocimen(ji,jv) = em_factor_tbocimene(jv)*flx_mono(ji,jv)                     
1355             !! 6.11 Calculation of other monoterpenes biogenic emission
1356             flx_othermono(ji,jv) = em_factor_othermonot(jv)*flx_mono(ji,jv)                   
1357             !! 6.12 Calculation of sesquiterpenes biogenic emission
1358             Ylt_sesq(ji) = ((1-LDF_sesq)*Ct_sesq(ji)+LDF_sesq*Ct_iso(ji)*Cl_iso(ji))
1359             flx_sesquiter(ji,jv) = fol_dens(ji,jv)*em_factor_sesquiterp(jv)*Ylt_sesq(ji)*Eff_age_VOC(ji,jv)*1e-9/one_hour   
1360             !! 6.16 Calculation of methanol biogenic emissions
1361             Ylt_meth(ji) = ((1-LDF_meth)*Ct_meth(ji)+LDF_meth*Ct_iso(ji)*Cl_iso(ji))
1362             flx_methanol(ji,jv) = fol_dens(ji,jv)*em_factor_methanol(jv)*Ylt_meth(ji)*Eff_age_meth(ji,jv)*1e-9/one_hour
1363             !! 6.17 Calculation of acetone biogenic emissions
1364             Ylt_acet(ji) = ((1-LDF_acet)*Ct_acet(ji)+LDF_acet*Ct_iso(ji)*Cl_iso(ji))
1365             flx_acetone(ji,jv) = fol_dens(ji,jv)*em_factor_acetone(jv)*Ylt_acet(ji)*Eff_age_VOC(ji,jv)*1e-9/one_hour
1366             !! 6.18 Calculation of acetaldehyde biogenic emissions
1367             flx_acetal(ji,jv) = fol_dens(ji,jv)*em_factor_acetal(jv)*Ylt_meth(ji)*Eff_age_VOC(ji,jv)*1e-9/one_hour
1368             !! 6.19 Calculation of formaldehyde biogenic emissions
1369             flx_formal(ji,jv) = fol_dens(ji,jv)*em_factor_formal(jv)*Ylt_meth(ji)*Eff_age_VOC(ji,jv)*1e-9/one_hour
1370             !! 6.20 Calculation of acetic acid biogenic emissions
1371             flx_acetic(ji,jv) = fol_dens(ji,jv)*em_factor_acetic(jv)*Ylt_meth(ji)*Eff_age_VOC(ji,jv)*1e-9/one_hour
1372             !! 6.21 Calculation of formic acid biogenic emissions
1373             flx_formic(ji,jv) = fol_dens(ji,jv)*em_factor_formic(jv)*Ylt_meth(ji)*Eff_age_VOC(ji,jv)*1e-9/one_hour
1374
1375          END IF
1376
1377          !! 6.22 Calculation of ORVOC biogenic emissions
1378          !! Other Reactive Volatile Organic Compounds
1379          !> @codeinc
1380          flx_ORVOC(ji,jv) = fol_dens(ji,jv)*em_factor_ORVOC(jv)*Ct_mono(ji)*Eff_age_VOC(ji,jv)*1e-9/one_hour
1381          !> @endcodeinc
1382          !! 6.4 Calculation of OVOC biogenic emissions
1383          !! Other Volatile Organic Compounds
1384          flx_OVOC(ji,jv) = fol_dens(ji,jv)*em_factor_OVOC(jv)*Ct_mono(ji)*Eff_age_VOC(ji,jv)*1e-9/one_hour
1385          !! 6.5 Calculation of MBO biogenic emissions
1386          !! 2-Methyl-3-Buten-2-ol
1387          IF(lalo(ji,1) .GE. 20. .AND. lalo(ji,2) .LE. -100) THEN
1388             flx_MBO(ji,jv) = fol_dens(ji,jv)*em_factor_MBO(jv)*Ct_MBO(ji)*Cl_MBO(ji)*Eff_age_VOC(ji,jv)*1e-9/one_hour
1389          ELSE
1390             flx_MBO(ji,jv) = zero
1391          END IF
1392       END DO
1393
1394    END DO
1395
1396
1397    !! 7. Calculation of NOx emissions from soils
1398    ! Based on Yienger & Levy (1995) and Lathiere (2005, chapter 3)
1399    DO ji = 1, kjpindex
1400       !! 7.1 Precipitation-related pulse function
1401       IF (ok_pulse_NOx) THEN
1402          ! if we are during a period where pulses are not allowed
1403          IF (ok_siesta(ji)) THEN
1404             ! if this period is not over
1405             IF (FLOOR(siestaday(ji)) .LE. siestalim(ji)) THEN
1406                siestaday(ji) = siestaday(ji) + (dt_sechiba/one_day)
1407                ! if this period is over
1408             ELSE
1409                ok_siesta(ji) = .FALSE.
1410                siestaday(ji) = zero
1411             END IF
1412          END IF
1413          ! if we are during a period where pulses are allowed
1414          IF ((.NOT. ok_siesta(ji)) .AND. (.NOT. allow_pulse(ji))) THEN
1415             IF (humrel(ji,1) .LT. 0.15) THEN
1416                ! if precip exceeds 1 mm/day over one time step => a pulse occurs
1417                IF(precip_rain(ji)/nbre_precip .GE. un/(one_day/dt_sechiba)) THEN
1418                   ! if precip is up to 5 mm/day => pulse length is 3 days
1419                   IF (precip_rain(ji)/nbre_precip .LT. 5./(one_day/dt_sechiba)) THEN
1420                      pulselim(ji) = 3.
1421                      ! if precip is up to 15 mm/day => pulse length is 7 days
1422                   ELSE IF (precip_rain(ji)/nbre_precip .LT. 15./(one_day/dt_sechiba)) THEN
1423                      pulselim(ji) = 7.
1424                      ! if precip is upper than 15 mm/day => pulse length is 14 days
1425                   ELSE IF (precip_rain(ji)/nbre_precip .GE. 15./(one_day/dt_sechiba)) THEN
1426                      pulselim(ji) = 14.
1427                   END IF
1428                   allow_pulse(ji)=.TRUE.
1429                   pulseday(ji) = un
1430                END IF
1431             END IF
1432          END IF
1433          ! if we were during a pulse period
1434          IF (allow_pulse(ji)) THEN
1435             ! if we are still during the pulse period
1436             ! 16/06/2010 We assume a (pulselim-1) days for the pulse length (NVui+Jlath)
1437             IF(FLOOR(pulseday(ji)) .LT. pulselim(ji)) THEN
1438                ! calculation of the pulse function
1439                IF (pulselim(ji).EQ.3) THEN
1440                   pulse(ji) = 11.19*exp(-0.805*pulseday(ji))
1441                ELSE IF (pulselim(ji).EQ.7) THEN
1442                   pulse(ji) = 14.68*exp(-0.384*pulseday(ji))
1443                ELSE IF (pulselim(ji).EQ.14) THEN
1444                   pulse(ji) = 18.46*exp(-0.208*pulseday(ji))
1445                END IF
1446                pulseday(ji) = pulseday(ji) + (dt_sechiba/one_day)
1447                ! if the pulse period is over
1448             ELSE
1449                ! pulse function is set to 1
1450                pulse(ji) = un
1451                allow_pulse(ji) = .FALSE.
1452                siestaday(ji) = un
1453                siestalim(ji) = pulselim(ji)
1454                ok_siesta(ji) = .TRUE. 
1455             END IF
1456          END IF
1457          ! no precipitation-related pulse function
1458       ELSE
1459          pulse(ji) = un
1460       END IF
1461    END DO
1462
1463    !! 7.2 Calculation of NO basal emissions including pulse effect
1464    DO jv = 1, nvm
1465       DO ji = 1, kjpindex
1466          !Tropical forests
1467          IF ( is_tropical(jv) .AND. is_evergreen(jv) ) THEN
1468             ! Wet soils
1469             IF (humrel(ji,1) .GT. 0.3) THEN
1470                flx_no_soil(ji,jv) = 2.6*pulse(ji)
1471                ! Dry soils
1472             ELSE
1473                flx_no_soil(ji,jv) = 8.6*pulse(ji)
1474             END IF
1475             !Else If agricultural lands OR Wet soils
1476          ELSE IF ( ( .NOT.(natural(jv)) ) .OR. ( humrel(ji,1) .GT. 0.3 ) ) THEN
1477             ! Calculation of NO emissions depending of Temperature
1478             IF (t_no(ji) .LT. zero) THEN
1479                flx_no_soil(ji,jv) = zero
1480             ELSE IF (t_no(ji) .LE. 10.) THEN
1481                flx_no_soil(ji,jv) = 0.28*em_factor_no_wet(jv)*t_no(ji)*pulse(ji)
1482             ELSE IF (t_no(ji) .LE. 30.) THEN
1483                flx_no_soil(ji,jv) = em_factor_no_wet(jv)*exp(0.103*t_no(ji))*pulse(ji)
1484             ELSE
1485                flx_no_soil(ji,jv) = 21.97*em_factor_no_wet(jv)*pulse(ji)
1486             END IF
1487             !Else if Temp negative
1488          ELSE IF (t_no(ji) .LT. zero) THEN
1489             flx_no_soil(ji,jv) = zero
1490             !Else if Temp <= 30
1491          ELSE IF (t_no(ji) .LE. 30.) THEN
1492             flx_no_soil(ji,jv) = (em_factor_no_dry(jv)*t_no(ji))/30.*pulse(ji)
1493          ELSE
1494             flx_no_soil(ji,jv) = em_factor_no_dry(jv)*pulse(ji)
1495          END IF
1496
1497          !! 7.3 IF ACTIVATED (ok_bbgfertil_NOx = TRUE) calculation of NOx soil emission increase due to biomass burning
1498          ! Calculation of Biomass-Burning-induced NOx emissions (Lathiere, 2005)
1499          ! => NOx emissions 3-fold increase
1500          IF (ok_bbgfertil_NOx) THEN
1501             IF ( natural(jv) ) THEN
1502                ! North Tropical zone from May to June
1503                IF ((lalo(ji,1) .LE. 30. .AND. lalo(ji,1) .GE. zero).AND. &
1504                     (julian_diff .GE. 121. .AND. julian_diff .LE. 181).AND.(flx_co2_bbg_year(ji) .GT. 0.1)) THEN
1505                   flx_no_soil(ji,jv) = flx_no_soil(ji,jv)*3.
1506                   ! South Tropical zone from November to December
1507                ELSE IF ((lalo(ji,1) .GE. -30. .AND. lalo(ji,1) .LT. zero).AND.(julian_diff .GE. 305.).AND. & 
1508                        (flx_co2_bbg_year(ji) .GT. 0.1)) THEN
1509                   flx_no_soil(ji,jv) = flx_no_soil(ji,jv)*3.
1510                END IF
1511             END IF
1512          END IF
1513
1514          !! 7.4 IF ACTIVATED (ok_cropsfertil_NOx = TRUE) calculation of NOx soil emission increase due to fertilizer use
1515          ! Calculation of N-fertiliser-induced NOx emissions
1516          flx_fertil_no(ji,jv) = zero
1517          IF (ok_cropsfertil_NOx) THEN
1518             IF (veget_max_nowoody(ji) .NE. zero) THEN
1519                ! Non-agricultural lands
1520                IF ( (jv == ibare_sechiba) .OR. is_tree(jv) ) THEN
1521                   N_qt_WRICE_pft(ji,jv) = zero
1522                   N_qt_OTHER_pft(ji,jv) = zero
1523                ! Grasslands or Croplands
1524                ELSE
1525                   N_qt_WRICE_pft(ji,jv) = N_qt_WRICE_year(ji)*veget_max(ji,jv)/veget_max_nowoody(ji)
1526                   N_qt_OTHER_pft(ji,jv) = N_qt_OTHER_year(ji)*veget_max(ji,jv)/veget_max_nowoody(ji)
1527                END IF
1528             ELSE
1529                N_qt_WRICE_pft(ji,jv) = zero
1530                N_qt_OTHER_pft(ji,jv) = zero
1531             END IF
1532
1533             ! North temperate regions from May to August
1534             ! OR South Temperate regions from November to February
1535             IF (((lalo(ji,1) .GT. 30.) .AND. (julian_diff .GE. 121. .AND. julian_diff .LE. 243.).AND. &
1536                  (veget_max(ji,jv) .GT. min_sechiba)) .OR. &
1537                  ((lalo(ji,1) .LT. -30.) .AND. (julian_diff .GE. 305. .OR. julian_diff .LE. 59.) .AND.&
1538                  (veget_max(ji,jv) .GT. min_sechiba))) THEN
1539                ! 1e12 for conversion from kg to Ng
1540                ! 1/(365/12*24*60*60*4) for conversion from year to seconds corrected for 4 months of emissions
1541                flx_fertil_no(ji,jv) = (N_qt_WRICE_pft(ji,jv)*(1/30.)+N_qt_OTHER_pft(ji,jv))*(2.5/100.) &
1542                     & *1e12/(365*24*60*60*4/12)/(area(ji)*veget_max(ji,jv))
1543                ! OR Tropical regions all the year
1544             ELSE IF ((lalo(ji,1) .GE. -30.).AND.(lalo(ji,1) .LE. 30.).AND.(veget_max(ji,jv) .GT. min_sechiba)) THEN
1545                flx_fertil_no(ji,jv) = (N_qt_WRICE_pft(ji,jv)*(1/30.)+N_qt_OTHER_pft(ji,jv))*(2.5/100.) &
1546                     & *1e12/(365*24*60*60)/(area(ji)*veget_max(ji,jv))
1547             END IF
1548             flx_no_soil(ji,jv) = flx_no_soil(ji,jv) + flx_fertil_no(ji,jv)
1549          END IF
1550
1551          !! 7.5 Calculation of net NO flux above soil accounting for surface deposition,
1552          !! based on the Canopy Reduction Factor (CRF), calculated using Leaf Area and Stomatal Area
1553          !kc=cuticle absorptivity = 0.24m^2/m^2
1554          !ks=stomatal absorptivity = 8.75m^2/m^2
1555          !Larch=Larcher SAI/LAI ratio given in Larcher 1991
1556          !> @codeinc
1557          CRF(ji,jv) = (exp(-8.75*Larch(jv)*lai(ji,jv)) + exp(-0.24*lai(ji,jv)))/2.
1558          flx_no(ji,jv) = flx_no_soil(ji,jv)*CRF(ji,jv)
1559          !> @endcodeinc
1560       END DO
1561    END DO
1562
1563
1564    ! Write output with XIOS
1565    CALL xios_orchidee_send_field("PAR",PAR)
1566    CALL xios_orchidee_send_field("flx_fertil_no",flx_fertil_no)
1567    CALL xios_orchidee_send_field("flx_iso",flx_iso)
1568    CALL xios_orchidee_send_field("flx_mono",flx_mono)
1569    CALL xios_orchidee_send_field("flx_ORVOC",flx_ORVOC)
1570    CALL xios_orchidee_send_field("flx_MBO",flx_MBO)
1571    CALL xios_orchidee_send_field("flx_methanol",flx_methanol)
1572    CALL xios_orchidee_send_field("flx_acetone",flx_acetone)
1573    CALL xios_orchidee_send_field("flx_acetal",flx_acetal)
1574    CALL xios_orchidee_send_field("flx_formal",flx_formal)
1575    CALL xios_orchidee_send_field("flx_acetic",flx_acetic)
1576    CALL xios_orchidee_send_field("flx_formic",flx_formic)
1577    CALL xios_orchidee_send_field("flx_no_soil",flx_no_soil)
1578    CALL xios_orchidee_send_field("flx_no",flx_no)
1579    CALL xios_orchidee_send_field('flx_apinen'   , flx_apinen)
1580    CALL xios_orchidee_send_field('flx_bpinen'   , flx_bpinen)
1581    CALL xios_orchidee_send_field('flx_limonen'  ,flx_limonen)
1582    CALL xios_orchidee_send_field('flx_myrcen'   , flx_myrcen)
1583    CALL xios_orchidee_send_field('flx_sabinen'  ,flx_sabinen)
1584    CALL xios_orchidee_send_field('flx_camphen'  ,flx_camphen)
1585    CALL xios_orchidee_send_field('flx_3caren'   , flx_3caren)
1586    CALL xios_orchidee_send_field('flx_tbocimen' ,flx_tbocimen)
1587    CALL xios_orchidee_send_field('flx_othermono',flx_othermono)
1588    CALL xios_orchidee_send_field('flx_sesquiter',flx_sesquiter)
1589    CALL xios_orchidee_send_field("CRF",CRF)
1590    CALL xios_orchidee_send_field('fco2', fco2)
1591
1592    IF ( ok_radcanopy ) THEN
1593       CALL xios_orchidee_send_field("PARdf",PARdf)
1594       CALL xios_orchidee_send_field("PARdr",PARdr)
1595       
1596       IF (ok_multilayer) THEN
1597          CALL xios_orchidee_send_field("PARsuntab",PARsuntab)
1598          CALL xios_orchidee_send_field("PARshtab",PARshtab)
1599       ELSE
1600          CALL xios_orchidee_send_field("PARsun",PARsun)
1601          CALL xios_orchidee_send_field("PARsh",PARsh)
1602          CALL xios_orchidee_send_field("laisun",laisun)
1603          CALL xios_orchidee_send_field("laish",laish)
1604       ENDIF
1605    ENDIF
1606
1607    IF ( ok_bbgfertil_Nox ) THEN
1608       CALL xios_orchidee_send_field("flx_co2_bbg_year",flx_co2_bbg_year)
1609    END IF
1610
1611    IF ( ok_cropsfertil_Nox ) THEN
1612       CALL xios_orchidee_send_field("N_qt_WRICE_year",N_qt_WRICE_year)
1613       CALL xios_orchidee_send_field("N_qt_OTHER_year",N_qt_OTHER_year)
1614    END IF
1615   
1616
1617    ! Write output with IOIPSL
1618    IF ( .NOT. almaoutput ) THEN
1619
1620       CALL histwrite_p(hist_id, 'PAR', kjit, PAR, kjpindex, index)
1621       IF ( ok_radcanopy ) THEN
1622          CALL histwrite_p(hist_id, 'laisun', kjit, laisun, kjpindex*nvm, indexveg)
1623          CALL histwrite_p(hist_id, 'laish', kjit, laish, kjpindex*nvm, indexveg)
1624          CALL histwrite_p(hist_id, 'Fdf', kjit, Fdf, kjpindex, index)
1625          IF (ok_multilayer) THEN
1626             CALL histwrite_p(hist_id, 'PARsuntab', kjit, PARsuntab, kjpindex*(nlai+1), indexlai)
1627             CALL histwrite_p(hist_id, 'PARshtab', kjit, PARshtab, kjpindex*(nlai+1), indexlai)
1628          ELSE
1629             CALL histwrite_p(hist_id, 'PARsun', kjit, PARsun, kjpindex*nvm, indexveg)
1630             CALL histwrite_p(hist_id, 'PARsh', kjit, PARsh, kjpindex*nvm, indexveg)
1631          END IF
1632          CALL histwrite_p(hist_id, 'coszang', kjit, coszang, kjpindex, index)
1633          CALL histwrite_p(hist_id, 'PARdf', kjit, PARdf, kjpindex, index)
1634          CALL histwrite_p(hist_id, 'PARdr', kjit, PARdr, kjpindex, index)
1635          CALL histwrite_p(hist_id, 'Trans', kjit, Trans, kjpindex, index)
1636       END IF
1637       CALL histwrite_p(hist_id, 'flx_fertil_no', kjit, flx_fertil_no, kjpindex*nvm, indexveg)
1638       CALL histwrite_p(hist_id, 'CRF', kjit, CRF, kjpindex*nvm, indexveg)
1639       CALL histwrite_p(hist_id, 'fco2', kjit, fco2, kjpindex*nvm, indexveg)
1640
1641       IF ( ok_bbgfertil_Nox ) THEN
1642          CALL histwrite_p(hist_id, 'flx_co2_bbg_year', 1, flx_co2_bbg_year, kjpindex, index)
1643       ENDIF
1644       IF ( ok_cropsfertil_Nox ) THEN
1645          CALL histwrite_p(hist_id, 'N_qt_WRICE_year', 1, N_qt_WRICE_year, kjpindex, index)
1646          CALL histwrite_p(hist_id, 'N_qt_OTHER_year', 1, N_qt_OTHER_year, kjpindex, index)
1647       ENDIF
1648       CALL histwrite_p(hist_id, 'flx_iso', kjit, flx_iso, kjpindex*nvm, indexveg)
1649       CALL histwrite_p(hist_id, 'flx_mono', kjit, flx_mono, kjpindex*nvm, indexveg)
1650       CALL histwrite_p(hist_id, 'flx_apinen', kjit, flx_apinen, kjpindex*nvm, indexveg)
1651       CALL histwrite_p(hist_id, 'flx_bpinen', kjit, flx_bpinen, kjpindex*nvm, indexveg)
1652       CALL histwrite_p(hist_id, 'flx_limonen', kjit, flx_limonen, kjpindex*nvm, indexveg)
1653       CALL histwrite_p(hist_id, 'flx_myrcen', kjit, flx_myrcen, kjpindex*nvm, indexveg)
1654       CALL histwrite_p(hist_id, 'flx_sabinen', kjit, flx_sabinen, kjpindex*nvm, indexveg)
1655       CALL histwrite_p(hist_id, 'flx_camphen', kjit, flx_camphen, kjpindex*nvm, indexveg)
1656       CALL histwrite_p(hist_id, 'flx_3caren', kjit, flx_3caren, kjpindex*nvm, indexveg)
1657       CALL histwrite_p(hist_id, 'flx_tbocimen', kjit, flx_tbocimen, kjpindex*nvm, indexveg)
1658       CALL histwrite_p(hist_id, 'flx_othermono', kjit, flx_othermono, kjpindex*nvm, indexveg)
1659       CALL histwrite_p(hist_id, 'flx_sesquiter', kjit, flx_sesquiter, kjpindex*nvm, indexveg)
1660       CALL histwrite_p(hist_id, 'flx_ORVOC', kjit, flx_ORVOC, kjpindex*nvm, indexveg)
1661       CALL histwrite_p(hist_id, 'flx_MBO', kjit, flx_MBO, kjpindex*nvm, indexveg)
1662       CALL histwrite_p(hist_id, 'flx_methanol', kjit, flx_methanol, kjpindex*nvm, indexveg)
1663       CALL histwrite_p(hist_id, 'flx_acetone', kjit, flx_acetone, kjpindex*nvm, indexveg)
1664       CALL histwrite_p(hist_id, 'flx_acetal', kjit, flx_acetal, kjpindex*nvm, indexveg)
1665       CALL histwrite_p(hist_id, 'flx_formal', kjit, flx_formal, kjpindex*nvm, indexveg)
1666       CALL histwrite_p(hist_id, 'flx_acetic', kjit, flx_acetic, kjpindex*nvm, indexveg)
1667       CALL histwrite_p(hist_id, 'flx_formic', kjit, flx_formic, kjpindex*nvm, indexveg)
1668       CALL histwrite_p(hist_id, 'flx_no_soil', kjit, flx_no_soil, kjpindex*nvm, indexveg)
1669       CALL histwrite_p(hist_id, 'flx_no', kjit, flx_no, kjpindex*nvm, indexveg)
1670       
1671       IF ( hist2_id > 0 ) THEN
1672          CALL histwrite_p(hist2_id, 'PAR', kjit, PAR, kjpindex, index)
1673          IF ( ok_radcanopy ) THEN
1674             CALL histwrite_p(hist2_id, 'PARsun', kjit, PARsun, kjpindex*nvm, indexveg)
1675             CALL histwrite_p(hist2_id, 'PARsh', kjit, PARsh, kjpindex*nvm, indexveg)
1676             CALL histwrite_p(hist2_id, 'laisun', kjit, laisun, kjpindex*nvm, indexveg)
1677             CALL histwrite_p(hist2_id, 'laish', kjit, laish, kjpindex*nvm, indexveg)
1678          ENDIF
1679          CALL histwrite_p(hist2_id, 'flx_fertil_no', kjit, flx_fertil_no, kjpindex*nvm, indexveg)
1680          CALL histwrite_p(hist2_id, 'CRF', kjit, CRF, kjpindex*nvm, indexveg)
1681          IF ( ok_bbgfertil_Nox ) THEN
1682             CALL histwrite_p(hist2_id, 'flx_co2_bbg_year', 1, flx_co2_bbg_year, kjpindex, index)
1683          ENDIF
1684          IF ( ok_cropsfertil_Nox ) THEN
1685             CALL histwrite_p(hist2_id, 'N_qt_WRICE_year', 1, N_qt_WRICE_year, kjpindex, index)
1686             CALL histwrite_p(hist2_id, 'N_qt_OTHER_year', 1, N_qt_OTHER_year, kjpindex, index)
1687          ENDIF
1688          CALL histwrite_p(hist2_id, 'flx_iso', kjit, flx_iso, kjpindex*nvm, indexveg)
1689          CALL histwrite_p(hist2_id, 'flx_mono', kjit, flx_mono, kjpindex*nvm, indexveg)
1690          CALL histwrite_p(hist2_id, 'flx_apinen', kjit, flx_apinen, kjpindex*nvm, indexveg)
1691          CALL histwrite_p(hist2_id, 'flx_bpinen', kjit, flx_bpinen, kjpindex*nvm, indexveg)
1692          CALL histwrite_p(hist2_id, 'flx_limonen', kjit, flx_limonen, kjpindex*nvm, indexveg)
1693          CALL histwrite_p(hist2_id, 'flx_myrcen', kjit, flx_myrcen, kjpindex*nvm, indexveg)
1694          CALL histwrite_p(hist2_id, 'flx_sabinen', kjit, flx_sabinen, kjpindex*nvm, indexveg)
1695          CALL histwrite_p(hist2_id, 'flx_camphen', kjit, flx_camphen, kjpindex*nvm, indexveg)
1696          CALL histwrite_p(hist2_id, 'flx_3caren', kjit, flx_3caren, kjpindex*nvm, indexveg)
1697          CALL histwrite_p(hist2_id, 'flx_tbocimen', kjit, flx_tbocimen, kjpindex*nvm, indexveg)
1698          CALL histwrite_p(hist2_id, 'flx_othermono', kjit, flx_othermono, kjpindex*nvm, indexveg)
1699          CALL histwrite_p(hist2_id, 'flx_sesquiter', kjit, flx_sesquiter, kjpindex*nvm, indexveg)
1700          CALL histwrite_p(hist2_id, 'flx_ORVOC', kjit, flx_ORVOC, kjpindex*nvm, indexveg)
1701          CALL histwrite_p(hist2_id, 'flx_MBO', kjit, flx_MBO, kjpindex*nvm, indexveg)
1702          CALL histwrite_p(hist2_id, 'flx_methanol', kjit, flx_methanol, kjpindex*nvm, indexveg)
1703          CALL histwrite_p(hist2_id, 'flx_acetone', kjit, flx_acetone, kjpindex*nvm, indexveg)
1704          CALL histwrite_p(hist2_id, 'flx_acetal', kjit, flx_acetal, kjpindex*nvm, indexveg)
1705          CALL histwrite_p(hist2_id, 'flx_formal', kjit, flx_formal, kjpindex*nvm, indexveg)
1706          CALL histwrite_p(hist2_id, 'flx_acetic', kjit, flx_acetic, kjpindex*nvm, indexveg)
1707          CALL histwrite_p(hist2_id, 'flx_formic', kjit, flx_formic, kjpindex*nvm, indexveg)
1708          CALL histwrite_p(hist2_id, 'flx_no_soil', kjit, flx_no_soil, kjpindex*nvm, indexveg)
1709          CALL histwrite_p(hist2_id, 'flx_no', kjit, flx_no, kjpindex*nvm, indexveg)
1710       ENDIF
1711    ENDIF
1712
1713    IF (printlev>=3) WRITE(numout,*) 'OK chemistry_bvoc'
1714
1715  END SUBROUTINE chemistry_bvoc
1716
1717!! ================================================================================================================================
1718!! SUBROUTINE   : chemistry_flux_interface
1719!!
1720!>\BRIEF         This subroutine will give to the interface between inca model and orchidee model in sechiba all the flux ask by inca
1721!!
1722!! DESCRIPTION  :  This subroutine allow the transfer of fluxes between surface and atmospheric chemistry. It is called from sechiba
1723!!
1724!! RECENT CHANGE(S): None
1725!!
1726!! MAIN OUTPUT VARIABLE(S): ::
1727!!
1728!! REFERENCE(S) : None
1729!!
1730!! FLOWCHART    : None
1731!_ ================================================================================================================================
1732
1733 SUBROUTINE chemistry_flux_interface( field_out_names, fields_out, field_in_names, fields_in)
1734
1735     !
1736     ! Optional arguments
1737     !
1738     ! Names and fields for emission variables : to be transport by Orchidee to Inca
1739     CHARACTER(LEN=*),DIMENSION(:), OPTIONAL, INTENT(IN) :: field_out_names
1740     REAL(r_std),DIMENSION(:,:,:), OPTIONAL, INTENT(OUT) :: fields_out
1741     !
1742     ! Names and fields for deposit variables : to be transport from chemistry model by INCA to ORCHIDEE.
1743     CHARACTER(LEN=*),DIMENSION(:), OPTIONAL, INTENT(IN) :: field_in_names
1744     REAL(r_std),DIMENSION(:,:), OPTIONAL, INTENT(IN)    :: fields_in
1745     !
1746     ! Number of fields to give (nb_fields_out) or get from (nb_fields_in) INCA :
1747     INTEGER(i_std), SAVE   :: nb_fields_out, nb_fields_in
1748!$OMP THREADPRIVATE(nb_fields_out, nb_fields_in)
1749
1750     ! Id of fields to give (nb_fields_out) or get from (nb_fields_in) INCA :
1751     INTEGER(i_std)  :: i_fields_out, i_fields_in
1752
1753     IF (l_first_chemistry_inca) THEN
1754
1755        ! il faut verifier que ok_bvoc (chemistry_ok_bvoc) est bien active sinon on arrete tout
1756        if (.not.ok_bvoc) then
1757          CALL ipslerr_p (3,'chemistry_inca', &
1758            &          'you need to activate chemistry_ok_bvoc in orchidee.def',&
1759            &          'This model won''t be able to continue.', &
1760            &          '')
1761        endif
1762
1763        ! Prepare fieds out/in for interface with INCA.
1764        IF (PRESENT(field_out_names)) THEN
1765           nb_fields_out=SIZE(field_out_names)
1766        ELSE
1767           nb_fields_out=0
1768        ENDIF
1769
1770        IF (PRESENT(field_in_names)) THEN
1771           nb_fields_in=SIZE(field_in_names)
1772        ELSE
1773           nb_fields_in=0
1774        ENDIF
1775        l_first_chemistry_inca = .FALSE.
1776
1777     ENDIF
1778
1779
1780
1781     IF (ok_bvoc) THEN 
1782        ! Fields for deposit variables : to be transport from chemistry model by INCA to ORCHIDEE.
1783        DO i_fields_in=1,nb_fields_in
1784           SELECT CASE(TRIM(field_in_names(i_fields_in)))
1785           CASE DEFAULT 
1786              CALL ipslerr_p (3,'chemistry_inca', &
1787                   &          'You ask in INCA an unknown field '//TRIM(field_in_names(i_fields_in))//&
1788                   &          ' to give to ORCHIDEE for this specific version.',&
1789                   &          'This model won''t be able to continue.', &
1790                   &          '(check your tracer parameters in INCA)')
1791           END SELECT
1792        ENDDO
1793       
1794        ! Fields for Biogenic emissions : to be transport by Orchidee to Inca
1795        DO i_fields_out=1,nb_fields_out
1796           SELECT CASE(TRIM(field_out_names(i_fields_out)))
1797           CASE("flx_iso") 
1798              fields_out(:,:,i_fields_out)=flx_iso(:,:)
1799           CASE("flx_mono") 
1800              fields_out(:,:,i_fields_out)=flx_mono(:,:)
1801           CASE("flx_ORVOC") 
1802              fields_out(:,:,i_fields_out)=flx_ORVOC(:,:)
1803           CASE("flx_MBO") 
1804              fields_out(:,:,i_fields_out)=flx_MBO(:,:)
1805           CASE("flx_methanol") 
1806              fields_out(:,:,i_fields_out)=flx_methanol(:,:)
1807           CASE("flx_acetone") 
1808              fields_out(:,:,i_fields_out)=flx_acetone(:,:)
1809           CASE("flx_acetal") 
1810              fields_out(:,:,i_fields_out)=flx_acetal(:,:)
1811           CASE("flx_formal") 
1812              fields_out(:,:,i_fields_out)=flx_formal(:,:)
1813           CASE("flx_acetic") 
1814              fields_out(:,:,i_fields_out)=flx_acetic(:,:)
1815           CASE("flx_formic") 
1816              fields_out(:,:,i_fields_out)=flx_formic(:,:)
1817           CASE("flx_no_soil") 
1818              fields_out(:,:,i_fields_out)=flx_no_soil(:,:)
1819           CASE("flx_nox") 
1820              fields_out(:,:,i_fields_out)=flx_no(:,:)
1821           CASE("flx_fertil_no") 
1822              fields_out(:,:,i_fields_out)=flx_fertil_no(:,:)
1823           CASE("flx_apinen")
1824              fields_out(:,:,i_fields_out)=flx_apinen(:,:)
1825           CASE("flx_bpinen")
1826              fields_out(:,:,i_fields_out)=flx_bpinen(:,:)
1827           CASE("flx_limonen")
1828              fields_out(:,:,i_fields_out)=flx_limonen(:,:)
1829           CASE("flx_myrcen")
1830              fields_out(:,:,i_fields_out)=flx_myrcen(:,:)
1831           CASE("flx_sabinen")
1832              fields_out(:,:,i_fields_out)=flx_sabinen(:,:)
1833           CASE("flx_camphen")
1834              fields_out(:,:,i_fields_out)=flx_camphen(:,:)
1835           CASE("flx_3caren")
1836              fields_out(:,:,i_fields_out)=flx_3caren(:,:)
1837           CASE("flx_tbocimen")
1838              fields_out(:,:,i_fields_out)=flx_tbocimen(:,:)
1839           CASE("flx_othermono")
1840              fields_out(:,:,i_fields_out)=flx_othermono(:,:)
1841           CASE("flx_sesquiter")
1842              fields_out(:,:,i_fields_out)=flx_sesquiter(:,:)
1843             
1844           CASE DEFAULT 
1845              CALL ipslerr_p (3,'chemistry_inca', &
1846                   &          'You ask from INCA an unknown field '//TRIM(field_out_names(i_fields_out))//&
1847                   &          ' to ORCHIDEE for this specific version.',&
1848                   &          'This model won''t be able to continue.', &
1849                   &          '(check your tracer parameters in INCA)')
1850           END SELECT
1851        ENDDO
1852       
1853     ENDIF
1854   END SUBROUTINE chemistry_flux_interface
1855
1856!! ================================================================================================================================
1857!! SUBROUTINE   : chemistry_clear
1858!!
1859!>\BRIEF         Clear chemistry module
1860!!
1861!! DESCRIPTION  :  Deallocate memory and reset initialization variables to there original values
1862!!
1863!_ ================================================================================================================================
1864   SUBROUTINE chemistry_clear
1865
1866     !! 1. Initialize as for first run
1867     l_first_chemistry_inca = .TRUE.
1868     
1869     !! 2. Deallocate dynamic variables
1870     IF (ALLOCATED(pulse)) DEALLOCATE (pulse)
1871     IF (ALLOCATED (ok_siesta)) DEALLOCATE (ok_siesta) 
1872     IF (ALLOCATED (allow_pulse)) DEALLOCATE (allow_pulse)
1873     IF (ALLOCATED (pulseday)) DEALLOCATE (pulseday)
1874     IF (ALLOCATED (siestaday)) DEALLOCATE (siestaday)
1875     IF (ALLOCATED (pulselim)) DEALLOCATE (pulselim)
1876     IF (ALLOCATED (siestalim)) DEALLOCATE (siestalim)
1877     IF (ALLOCATED (N_qt_WRICE_year)) DEALLOCATE (N_qt_WRICE_year)
1878     IF (ALLOCATED (N_qt_OTHER_year)) DEALLOCATE (N_qt_OTHER_year)
1879     IF (ALLOCATED (flx_iso)) DEALLOCATE (flx_iso)
1880     IF (ALLOCATED (flx_mono)) DEALLOCATE (flx_mono)
1881     IF (ALLOCATED (flx_ORVOC)) DEALLOCATE (flx_ORVOC)
1882     IF (ALLOCATED (flx_MBO)) DEALLOCATE (flx_MBO)
1883     IF (ALLOCATED (flx_methanol)) DEALLOCATE (flx_methanol)
1884     IF (ALLOCATED (flx_acetone)) DEALLOCATE (flx_acetone)
1885     IF (ALLOCATED (flx_acetal)) DEALLOCATE (flx_acetal)
1886     IF (ALLOCATED (flx_formal)) DEALLOCATE (flx_formal)
1887     IF (ALLOCATED (flx_acetic)) DEALLOCATE (flx_acetic)
1888     IF (ALLOCATED (flx_formic)) DEALLOCATE (flx_formic)
1889     IF (ALLOCATED (flx_no_soil)) DEALLOCATE (flx_no_soil)
1890     IF (ALLOCATED (flx_no)) DEALLOCATE (flx_no)
1891     IF (ALLOCATED (flx_fertil_no)) DEALLOCATE (flx_fertil_no)
1892     IF (ALLOCATED (flx_apinen)) DEALLOCATE (flx_apinen)
1893     IF (ALLOCATED (flx_bpinen)) DEALLOCATE (flx_bpinen)
1894     IF (ALLOCATED (flx_limonen)) DEALLOCATE (flx_limonen)
1895     IF (ALLOCATED (flx_myrcen)) DEALLOCATE (flx_myrcen)
1896     IF (ALLOCATED (flx_sabinen)) DEALLOCATE (flx_sabinen)
1897     IF (ALLOCATED (flx_camphen)) DEALLOCATE (flx_camphen)
1898     IF (ALLOCATED (flx_3caren)) DEALLOCATE (flx_3caren)
1899     IF (ALLOCATED (flx_tbocimen)) DEALLOCATE (flx_tbocimen)
1900     IF (ALLOCATED (flx_othermono)) DEALLOCATE (flx_othermono)
1901     IF (ALLOCATED (flx_sesquiter)) DEALLOCATE (flx_sesquiter)
1902     IF (ALLOCATED (CRF)) DEALLOCATE (CRF)
1903     IF (ALLOCATED (flx_co2_bbg_year)) DEALLOCATE (flx_co2_bbg_year)
1904
1905   END SUBROUTINE chemistry_clear
1906   
1907END MODULE chemistry
Note: See TracBrowser for help on using the repository browser.