source: branches/publications/ORCHIDEE_2.2_r7266/ORCHIDEE/src_sechiba/chemistry.f90 @ 7541

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