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