SURFEX  V8_0
Surfex V8_0 release
 All Classes Files Functions Variables
build_pronoslistn.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 build_pronoslist_n (SV, &
7  kemis_nbr,hemis_name,tppronos,kch,kluout,kverb)
8 !! #######################################################################
9 !!
10 !!*** *BUILD_PRONOSLIST*
11 !!
12 !! PURPOSE
13 !! -------
14 !!
15 !!
16 !!** METHOD
17 !! ------
18 !!
19 !!
20 !! AUTHOR
21 !! ------
22 !! D. Gazen
23 !!
24 !! MODIFICATIONS
25 !! -------------
26 !! Original 01/02/00
27 !! C. Mari 30/10/00 call to MODD_TYPE_EFUTIL
28 !! D. Gazen 01/12/03 change emissions handling for surf. externalization
29 !! P. Tulet 01/05/05 aerosols primary emission
30 !! M.Leriche 04/2014 change length of CHARACTER for emission 6->12
31 !!
32 !! EXTERNAL
33 !! --------
34 !
35 USE modd_sv_n, ONLY : sv_t
36 !
37 USE modi_ch_open_inputb
38 !!
39 !! IMPLICIT ARGUMENTS
40 !! ------------------
41 USE modd_surfex_omp, ONLY : nblock
43 !------------------------------------------------------------------------------
44 !
45 !* 0. DECLARATIONS
46 ! -----------------
47 !
48 USE yomhook ,ONLY : lhook, dr_hook
49 USE parkind1 ,ONLY : jprb
50 !
51 USE modi_abor1_sfx
52 !
53 IMPLICIT NONE
54 !
55 !* 0.1 declaration of arguments
56 !
57 !
58 TYPE(sv_t), INTENT(INOUT) :: sv
59 !
60 INTEGER, INTENT(IN) :: kemis_nbr ! number of emitted species
61  CHARACTER(LEN=12), DIMENSION(KEMIS_NBR), INTENT(IN) :: hemis_name ! name of emitted species
62 TYPE(pronosvar_t), POINTER :: tppronos
63 INTEGER, INTENT(IN) :: kch ! logical unit of input chemistry file
64 INTEGER, INTENT(IN) :: kluout ! output listing channel
65 INTEGER, INTENT(IN) :: kverb ! verbose level
66 !
67 !* 0.2 declaration of local variables
68 !
69  CHARACTER(LEN=256) :: yinpline ! input agregation line read from Namelist
70 INTEGER :: indx !
71 INTEGER :: inbcoeff ! Numer of agregations coeff for one species
72 INTEGER :: ji ! loop index
73 INTEGER :: indx_pro ! index of the pronostic variable in CNAMES array
74 INTEGER :: ierr
75  CHARACTER(LEN=32) :: ypro_name, yemis_name ! Name of the pronostic & emission species
76 LOGICAL :: gfound
77  CHARACTER(LEN=6), DIMENSION(:),POINTER :: cnames
78 TYPE(pronosvar_t), POINTER :: head,current
79 INTEGER :: ieq
80 REAL(KIND=JPRB) :: zhook_handle
81 !
82 !------------------------------------------------------------------------------
83 !
84 !* EXECUTABLE STATEMENTS
85 ! ---------------------
86 !
87 IF (lhook) CALL dr_hook('BUILD_PRONOSLIST_N',0,zhook_handle)
88 !
89 ! CNAMES points on chemical variables name
90  cnames => sv%CSV
91 ieq = SIZE(sv%CSV)
92 !
93 ! Namelist is opened and the agregation eq. are reached
94 !
95 !$OMP SINGLE
96  CALL ch_open_inputb("AGREGATION", kch , kluout)
97 !$OMP END SINGLE
98 !
99 ! Parse each eq. line and build the TPPRONOS list
100 !
101 nullify(head)
102 nullify(current)
103 DO
104 !
105 ! Read a line and convert 'tab' to 'space' characters
106 ! until the keyword 'END_AGREGATION' is reached
107 !$OMP SINGLE
108  READ(kch,'(A)',iostat=ierr) yinpline
109 !$OMP END SINGLE COPYPRIVATE(YINPLINE,IERR)
110  IF (ierr /= 0) EXIT
111  yinpline = trim(adjustl(yinpline))
112  IF (len_trim(yinpline) == 0) cycle ! skip blank line
113  IF (yinpline == 'END_AGREGATION') EXIT
114  CALL tab2space(yinpline)
115 !
116 !
117 !Extract pronostic variable name
118  indx = index(yinpline,' ')
119  ypro_name = yinpline(1:indx-1)
120 !
121 ! search the variable in CNAMES, STOP if not FOUND
122  gfound = .false.
123  DO ji=1,ieq
124  IF (cnames(ji) == ypro_name) THEN
125  indx_pro = ji
126  gfound = .true.
127  EXIT
128  END IF
129  END DO
130  IF (.NOT. gfound) THEN
131  WRITE(kluout,*) 'BUILD_PRONOSLIST ERROR : ',trim(ypro_name),&
132  ' not found in pronostic variables list !'
133  CALL abor1_sfx('BUILD_PRONOSLISTN: VARIABLE NOT FOUND')
134  END IF
135 !
136 ! If YPRO_NAME variable already encountered : append the new equation (coeffs)
137  gfound = .false.
138  inbcoeff = 0
139  current=>head
140  DO WHILE(ASSOCIATED(current))
141  IF (current%NAMINDEX == indx_pro) THEN
142  inbcoeff = current%NBCOEFF
143  gfound = .true.
144  EXIT
145  END IF
146  current=>current%NEXT
147  END DO
148  IF (.NOT. gfound) THEN
149 ! New pronostic cell is created
150  ALLOCATE(current)
151  current%NAMINDEX = indx_pro
152  current%NEXT => head
153  head => current
154  END IF
155 !
156 !
157 ! Extract the agregation coeffs
158  DO
159 ! get REAL coeff
160  yinpline = adjustl(yinpline(indx:))
161  indx = index(yinpline,' ')
162  IF (indx == 1) EXIT
163  inbcoeff = inbcoeff+1
164  IF (inbcoeff > jpnbcoeffmax) THEN
165  WRITE(kluout,*) 'FATAL ERROR : Number of aggregation coefficients for ',&
166  trim(ypro_name),' exceeds constant JPNBCOEFFMAX = ',jpnbcoeffmax
167  WRITE(kluout,*) '=> You should increase the JPNBCOEFFMAX value in modd_type_efutil.f90'
168  CALL abor1_sfx('BUILD_PRONOSLISTN: NUMBER OF AGGREGATION COEFFICIENTS TOO BIG')
169  END IF
170  READ(yinpline(1:indx-1),*) current%XCOEFF(inbcoeff)
171 !
172 ! get EMIS species name
173  yinpline = adjustl(yinpline(indx:))
174  indx = index(yinpline,' ')
175  yemis_name = yinpline(1:indx-1)
176 !
177 ! check EMIS species name
178  gfound = .false.
179  DO ji=1,kemis_nbr
180  IF (trim(hemis_name(ji)) == trim(yemis_name)) THEN
181  gfound = .true.
182  current%NEFINDEX(inbcoeff) = ji
183  EXIT
184  END IF
185  END DO
186  IF (.NOT. gfound) THEN
187  WRITE(kluout,*) 'ERROR : ',trim(yemis_name),&
188  ' not found in emission variables list !'
189  CALL abor1_sfx('BUILD_PRONOSLISTN: UNKNOWN EMISSION VARIABLE')
190  END IF
191  END DO
192  current%NBCOEFF = inbcoeff
193 END DO
194 !
195 ! Update TPPRONOS pointer with head of list
196 tppronos => head
197 !
198 IF (kverb >= 6) THEN
199  WRITE(kluout,*) 'BUILD_PRONOSLIST: Aggregation results'
200  current=>head
201  DO WHILE(ASSOCIATED(current))
202  WRITE(kluout,*) 'Emission for Atmospheric Chemical Species ',trim(cnames(current%NAMINDEX)),' (index ',&
203  current%NAMINDEX,' in CSV)'
204  WRITE(kluout,*) 'is aggregated with the following weights from the Emission Inventory Species:'
205  DO ji=1,current%NBCOEFF
206  WRITE(kluout,*) current%XCOEFF(ji),hemis_name(current%NEFINDEX(ji))
207  END DO
208  current=>current%NEXT
209  END DO
210 END IF
211 !
212 IF (lhook) CALL dr_hook('BUILD_PRONOSLIST_N',1,zhook_handle)
213 !
214  CONTAINS
215 !!
216 !! ###########################
217  SUBROUTINE tab2space(HTEXT)
218 !! ###########################
219 !!
220 !!*** *TAB2SPACE*
221 !!
222 !! PURPOSE
223 !! -------
224 !! Convert 'tab' character to 'space' character in the string HTEXT
225 !!
226 !!** METHOD
227 !! ------
228 !!
229 !! AUTHOR
230 !! ------
231 !! D. Gazen
232 !!
233 !! MODIFICATIONS
234 !! -------------
235 !! Original 01/02/2000
236 !!
237 !! EXTERNAL
238 !! --------
239 !!
240 !! IMPLICIT ARGUMENTS
241 !! ------------------
242 !------------------------------------------------------------------------------
243 !
244 !* 0. DECLARATIONS
245 ! -----------------
246 IMPLICIT NONE
247 !
248 !* 0.1 declaration of arguments
249 !
250  CHARACTER(len=*),INTENT(INOUT) :: htext
251 !
252 !* 0.2 declaration of local variables
253 !
254  CHARACTER, PARAMETER :: yptab = char(9) ! TAB character is ASCII : 9
255 INTEGER :: ji
256 REAL(KIND=JPRB) :: zhook_handle
257 !
258 !------------------------------------------------------------------------------
259 !
260 !* EXECUTABLE STATEMENTS
261 ! ---------------------
262 !
263 IF (lhook) CALL dr_hook('TAB2SPACE',0,zhook_handle)
264 DO ji=1,len_trim(htext)
265  IF (htext(ji:ji) == yptab) htext(ji:ji) = ' '
266 END DO
267 IF (lhook) CALL dr_hook('TAB2SPACE',1,zhook_handle)
268 END SUBROUTINE tab2space
269 
270 END SUBROUTINE build_pronoslist_n
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:6
subroutine tab2space(HTEXT)
subroutine build_pronoslist_n(SV, KEMIS_NBR, HEMIS_NAME, TPPRONOS, KCH, KLUOUT, KVERB)