SURFEX  V8_0
Surfex V8_0 release
 All Classes Files Functions Variables
ch_init_emissionn.F90
Go to the documentation of this file.
1 !SFX_LIC Copyright 1994-2014 CNRS, Meteo-France and Universite Paul Sabatier
2 !SFX_LIC This is part of the SURFEX software governed by the CeCILL-C licence
3 !SFX_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt
4 !SFX_LIC for details. version 1.
5 ! #########
6  SUBROUTINE ch_init_emission_n (CHE, CHU, SV, &
7  hprogram,klu,kch,prhoa)
8 ! #######################################
9 !
10 !!**** *CH_INIT_EMIISION_n* - routine to initialize chemical emissions data structure
11 !!
12 !! PURPOSE
13 !! -------
14 ! Allocates and initialize emission surface fields
15 ! by reading their value in initial file.
16 !
17 !!** METHOD
18 !! ------
19 !!
20 !!
21 !! AUTHOR
22 !! ------
23 !! D. Gazen * L.A. *
24 !!
25 !! MODIFICATIONS
26 !! -------------
27 !! Original 08/03/2001
28 !! D.Gazen 01/12/03 change emissions handling for surf. externalization
29 !! P.Tulet 01/01/04 introduction of rhodref for externalization
30 !! M.Leriche 04/2014 change length of CHARACTER for emission 6->12
31 !-----------------------------------------------------------------------------
32 !
33 !* 0. DECLARATIONS
34 !
35 !
37 USE modd_ch_surf_n, ONLY : ch_surf_t
38 USE modd_sv_n, ONLY : sv_t
39 !
40 USE modi_get_luout
41 USE modi_build_emisstab_n
42 USE modi_build_pronoslist_n
44 !
45 !
46 USE yomhook ,ONLY : lhook, dr_hook
47 USE parkind1 ,ONLY : jprb
48 !
49 USE modi_abor1_sfx
50 !
51 IMPLICIT NONE
52 !
53 !* 0.1 declarations of arguments
54 !
55 !
56 !
57 TYPE(ch_emis_field_t), INTENT(INOUT) :: che
58 TYPE(ch_surf_t), INTENT(INOUT) :: chu
59 TYPE(sv_t), INTENT(INOUT) :: sv
60 !
61  CHARACTER(LEN=6), INTENT(IN) :: hprogram ! Program name
62 INTEGER, INTENT(IN) :: klu ! number of points
63 INTEGER, INTENT(IN) :: kch ! logical unit of input chemistry file
64 REAL, DIMENSION(:),INTENT(IN) :: prhoa ! air density
65 !
66 !* 0.2 declarations of local variables
67 !
68 INTEGER :: iresp ! File
69 INTEGER :: iluout ! output listing logical unit
70  CHARACTER (LEN=16) :: yrecfm ! management
71  CHARACTER (LEN=100) :: ycomment ! variables
72 INTEGER :: jspec ! Loop index for cover data
73 INTEGER :: iind1,iind2 ! Indices counter
74 !
75  CHARACTER(LEN=40) :: yspec_name ! species name
76  CHARACTER(LEN=12), DIMENSION(:),ALLOCATABLE :: yemis_name ! species name
77 INTEGER,DIMENSION(:),ALLOCATABLE :: inbtimes! number of emission times array
78 INTEGER,DIMENSION(:),ALLOCATABLE :: itimes ! emission times for a species
79 INTEGER,DIMENSION(:),ALLOCATABLE :: ioffndx ! index array of offline emission species
80 INTEGER :: inbts ! number of emission times for a species
81 INTEGER :: inboff ! Number of offline emissions
82 INTEGER :: iverb ! verbose level
83  CHARACTER(LEN=3) :: ysurf ! surface type
84 !
85 INTEGER :: iversion ! version of surfex file being read
86 REAL(KIND=JPRB) :: zhook_handle
87 !-------------------------------------------------------------------------------
88 IF (lhook) CALL dr_hook('CH_INIT_EMISSION_N',0,zhook_handle)
89  CALL get_luout(hprogram,iluout)
90 WRITE(iluout,*) '------ Beginning of CH_INIT_EMISSION ------'
91 !
92 !* ascendant compatibility
93 yrecfm='VERSION'
94  CALL read_surf( &
95  hprogram,yrecfm,iversion,iresp)
96 !
97 !* 2. Chemical Emission fields
98 ! ------------------------
99 !
100 ! Read the total number of emission files
101 IF (iversion>=4) THEN
102  CALL read_surf( &
103  hprogram,'EMISFILE_NBR',che%NEMIS_NBR,iresp)
104 ELSE
105  CALL read_surf( &
106  hprogram,'EMISFILE_GR_NBR',che%NEMIS_NBR,iresp)
107 END IF
108 IF (iresp/=0) THEN
109  CALL abor1_sfx('CH_INIT_EMISSIONN: PROBLEM WHEN READING NB OF 2D CHEMICAL EMISSION FIELDS')
110 END IF
111 !
112 ! Read the number of emission species
113 IF (iversion>=4) THEN
114  CALL read_surf( &
115  hprogram,'EMISPEC_NBR',che%NEMISPEC_NBR,iresp)
116 ELSE
117  CALL read_surf( &
118  hprogram,'EMISPEC_GR_NBR',che%NEMISPEC_NBR,iresp)
119 END IF
120 IF (iresp/=0) THEN
121  CALL abor1_sfx('CH_INIT_EMISSIONN: PROBLEM WHEN READING NB OF EMITTED CHEMICAL SPECIES')
122 END IF
123 !
124 !
125 IF (.NOT. ASSOCIATED(che%CEMIS_NAME)) THEN
126  ALLOCATE(che%CEMIS_NAME(che%NEMISPEC_NBR))
127 ELSE
128  WRITE(iluout,*) 'CEMIS_NAME already allocated with SIZE :',SIZE(che%CEMIS_NAME)
129 END IF
130 
131 IF (.NOT. ASSOCIATED(che%CEMIS_AREA)) ALLOCATE(che%CEMIS_AREA(che%NEMISPEC_NBR))
132 IF (.NOT. ASSOCIATED(che%NEMIS_TIME)) ALLOCATE(che%NEMIS_TIME(che%NEMIS_NBR))
133  che%NEMIS_TIME(:) = -1
134 !
135 ALLOCATE(itimes(che%NEMIS_NBR))
136 ALLOCATE(inbtimes(che%NEMISPEC_NBR))
137 ALLOCATE(ioffndx(che%NEMISPEC_NBR))
138 !
139 inbtimes(:) = -1
140 ioffndx(:) = 0 ! Index array of offline species
141 !
142 iind1 = 0 ! Index to fill NEMIS_GR_TIMES array
143 iind2 = 0 ! with emission times of offline species
144 !
145 inboff = 0 ! number of offline emission species (with emis time > 0)
146 DO jspec = 1,che%NEMISPEC_NBR ! Loop on the number of species
147 !
148 ! Read article EMISNAMExxx for the name of species
149 ! and extract from comment : surface type + number of emission times
150  WRITE(yrecfm,'("EMISNAME",I3.3)') jspec
151  CALL read_surf( &
152  hprogram,yrecfm,yspec_name,iresp,ycomment)
153  IF (iresp/=0) THEN
154  CALL abor1_sfx('CH_INIT_EMISSIONN: PROBLEM WHEN READING NAME OF EMITTED CHEMICAL SPECIES')
155  END IF
156 
157  WRITE(yrecfm,'("EMISAREA",I3.3)') jspec
158  CALL read_surf( &
159  hprogram,yrecfm,ysurf,iresp,ycomment)
160  WRITE(yrecfm,'("EMISNBT",I3.3)') jspec
161  CALL read_surf( &
162  hprogram,yrecfm,inbts,iresp,ycomment)
163  WRITE(iluout,*) ' Emission ',jspec,' : ',trim(yspec_name),'(',inbts,' instants )'
164 !
165 ! Read emission times for species number JSPEC
166  WRITE(yrecfm,'("EMISTIMES",I3.3)') jspec
167  CALL read_surf( &
168  hprogram,yrecfm,itimes(1:inbts),iresp,ycomment,'-')
169  IF (iresp/=0) THEN
170  CALL abor1_sfx('CH_INIT_EMISSIONN: PROBLEM WHEN READING EMISSION TIMES')
171  END IF
172  IF (inbts == 1) WRITE(iluout,*) ' -> ',itimes(1)
173 !
174 ! Is it an offline emission ?
175  IF (inbts >= 1) THEN
176  IF (itimes(1) >= 0) THEN
177 ! Yes it is. (Note that negative time refers to inline emission like biogenics
178 ! fluxes)
179 !
180  inboff = inboff+1
181  ioffndx(inboff) = jspec
182 !
183 ! INBTIMES and NEMIS_TIME only updated for offline emission
184  iind1 = iind2+1
185  iind2 = iind2+inbts
186  che%NEMIS_TIME(iind1:iind2) = itimes(1:inbts)
187  inbtimes(inboff) = inbts
188  END IF
189  END IF
190 !
191  che%NTIME_MAX = maxval(che%NEMIS_TIME)
192 !
193 ! INBTIMES, CEMIS_AREA and CEMIS_NAME
194 ! are updated for ALL species
195  che%CEMIS_NAME(jspec) = yspec_name
196  che%CEMIS_AREA(jspec) = ysurf
197 !
198 END DO
199 !
200 WRITE(iluout,*) '---- Nunmer of OFFLINE species = ',inboff
201 WRITE(iluout,*) 'INBTIMES=',inbtimes
202 WRITE(iluout,*) 'IOFFNDX=',ioffndx
203 
204 iverb=6
205 
206 IF (inboff > 0) THEN
207  ALLOCATE(che%TSEMISS(inboff))
208  ALLOCATE(yemis_name(inboff))
209 
210  CALL build_emisstab_n( &
211  chu, &
212  hprogram,kch,che%CEMIS_NAME,inbtimes,che%NEMIS_TIME,&
213  ioffndx,che%TSEMISS,klu,iluout,iverb,prhoa)
214  DO jspec = 1,inboff ! Loop on the number of species
215  yemis_name(jspec) = che%TSEMISS(jspec)%CNAME(1:12)
216  END DO
217  CALL build_pronoslist_n(sv, &
218  SIZE(che%TSEMISS),yemis_name,che%TSPRONOSLIST,kch,iluout,iverb)
219  DEALLOCATE(yemis_name)
220 ELSE
221  ALLOCATE(che%TSEMISS(0))
222  nullify(che%TSPRONOSLIST)
223 END IF
224 
225 DEALLOCATE(itimes,inbtimes,ioffndx)
226 WRITE(iluout,*) '------ Leaving CH_INIT_EMISSION ------'
227 IF (lhook) CALL dr_hook('CH_INIT_EMISSION_N',1,zhook_handle)
228 !-------------------------------------------------------------------------------
229 !
230 END SUBROUTINE ch_init_emission_n
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:6
subroutine build_pronoslist_n(SV, KEMIS_NBR, HEMIS_NAME, TPPRONOS, KCH, KLUOUT, KVERB)
subroutine ch_init_emission_n(CHE, CHU, SV, HPROGRAM, KLU, KCH, PRHOA)
subroutine get_luout(HPROGRAM, KLUOUT)
Definition: get_luout.F90:6
subroutine build_emisstab_n(CHU, HPROGRAM, KCH, HEMIS_GR_NAME, KNBTIMES, KEMIS_GR_TIME, KOFFNDX, TPEMISS, KSIZE, KLUOUT, KVERB, PRHODREF)