SURFEX v8.1
General documentation of Surfex
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, PCONVERSION, HSV, HPROGRAM,KLU,HINIT,PRHOA,HCHEM_SURF_FILE)
7 ! #######################################
8 !
9 !!**** *CH_INIT_EMIISION_n* - routine to initialize chemical emissions data structure
10 !!
11 !! PURPOSE
12 !! -------
13 ! Allocates and initialize emission surface fields
14 ! by reading their value in initial file.
15 !
16 !!** METHOD
17 !! ------
18 !!
19 !!
20 !! AUTHOR
21 !! ------
22 !! D. Gazen * L.A. *
23 !!
24 !! MODIFICATIONS
25 !! -------------
26 !! Original 08/03/2001
27 !! D.Gazen 01/12/03 change emissions handling for surf. externalization
28 !! P.Tulet 01/01/04 introduction of rhodref for externalization
29 !! M.Leriche 04/2014 change length of CHARACTER for emission 6->12
30 !! M.Leriche & V. Masson 05/16 bug in write emis fields for nest
31 !-----------------------------------------------------------------------------
32 !
33 !* 0. DECLARATIONS
34 !
35 !
37 !
38 USE modi_get_luout
39 USE modi_build_emisstab_n
40 USE modi_build_pronoslist_n
42 USE modi_open_namelist
43 USE modi_close_namelist
44 USE modi_read_surf_field2d
45 !
46 !
47 USE yomhook ,ONLY : lhook, dr_hook
48 USE parkind1 ,ONLY : jprb
49 !
50 USE modi_abor1_sfx
51 !
52 IMPLICIT NONE
53 !
54 !* 0.1 declarations of arguments
55 !
56 !
57 !
58 TYPE(ch_emis_field_t), INTENT(INOUT) :: CHE
59 REAL, DIMENSION(:), POINTER :: PCONVERSION
60  CHARACTER(LEN=*), DIMENSION(:), POINTER :: HSV
61 !
62  CHARACTER(LEN=6), INTENT(IN) :: HPROGRAM ! Program name
63 INTEGER, INTENT(IN) :: KLU ! number of points
64  CHARACTER(LEN=3), INTENT(IN) :: HINIT ! Flag to know if one initializes:
65 ! ! 'ALL' : all variables for a run
66 ! ! 'PRE' : only variables to build
67 ! ! an initial file
68 REAL, DIMENSION(:),INTENT(IN) :: PRHOA ! air density
69  CHARACTER(LEN=28), INTENT(IN) :: HCHEM_SURF_FILE ! ascii file for chemistry aggregation
70 !
71 !* 0.2 declarations of local variables
72 !
73 INTEGER :: IRESP ! File
74 INTEGER :: ILUOUT ! output listing logical unit
75  CHARACTER (LEN=16) :: YRECFM ! management
76  CHARACTER (LEN=40) :: YCOMMENT ! variables
77 INTEGER :: JSPEC ! Loop index for cover data
78 INTEGER :: IIND1,IIND2 ! Indices counter
79 !
80  CHARACTER(LEN=40) :: YSPEC_NAME ! species name
81  CHARACTER(LEN=12), DIMENSION(:),ALLOCATABLE :: YEMIS_NAME ! species name
82 INTEGER,DIMENSION(:),ALLOCATABLE :: INBTIMES! number of emission times array
83 INTEGER,DIMENSION(:),ALLOCATABLE :: ITIMES ! emission times for a species
84 INTEGER,DIMENSION(:),ALLOCATABLE :: IOFFNDX ! index array of offline emission species
85 INTEGER :: INBTS ! number of emission times for a species
86 INTEGER :: INBOFF ! Number of offline emissions
87 INTEGER :: IVERB ! verbose level
88 INTEGER :: ICH ! logical unit of input chemistry file
89  CHARACTER(LEN=3) :: YSURF ! surface type
90 REAL, DIMENSION(:,:), ALLOCATABLE :: ZWORK2D ! work array to read emission fields
91 !
92 INTEGER :: IVERSION ! version of surfex file being read
93 REAL(KIND=JPRB) :: ZHOOK_HANDLE
94 !-------------------------------------------------------------------------------
95 IF (lhook) CALL dr_hook('CH_INIT_EMISSION_N',0,zhook_handle)
96  CALL get_luout(hprogram,iluout)
97 WRITE(iluout,*) '------ Beginning of CH_INIT_EMISSION ------'
98 !
99 !* ascendant compatibility
100 yrecfm='VERSION'
101  CALL read_surf(hprogram,yrecfm,iversion,iresp)
102 !
103 !* 1. Chemical Emission fields
104 ! ------------------------
105 !
106 ! Read the total number of emission files
107 IF (iversion>=4) THEN
108  CALL read_surf(hprogram,'EMISFILE_NBR',che%NEMIS_NBR,iresp)
109 ELSE
110  CALL read_surf(hprogram,'EMISFILE_GR_NBR',che%NEMIS_NBR,iresp)
111 END IF
112 IF (iresp/=0) THEN
113  CALL abor1_sfx('CH_INIT_EMISSIONN: PROBLEM WHEN READING NB OF 2D CHEMICAL EMISSION FIELDS')
114 END IF
115 !
116 ! Read the number of emission species
117 IF (iversion>=4) THEN
118  CALL read_surf(hprogram,'EMISPEC_NBR',che%NEMISPEC_NBR,iresp)
119 ELSE
120  CALL read_surf(hprogram,'EMISPEC_GR_NBR',che%NEMISPEC_NBR,iresp)
121 END IF
122 IF (iresp/=0) THEN
123  CALL abor1_sfx('CH_INIT_EMISSIONN: PROBLEM WHEN READING NB OF EMITTED CHEMICAL SPECIES')
124 END IF
125 !
126 !
127 IF (.NOT. ASSOCIATED(che%CEMIS_NAME)) THEN
128  ALLOCATE(che%CEMIS_NAME(che%NEMISPEC_NBR))
129 ELSE
130  WRITE(iluout,*) 'CEMIS_NAME already allocated with SIZE :',SIZE(che%CEMIS_NAME)
131 END IF
132 
133 IF (.NOT. ASSOCIATED(che%CEMIS_AREA)) ALLOCATE(che%CEMIS_AREA(che%NEMISPEC_NBR))
134 IF (.NOT. ASSOCIATED(che%NEMIS_TIME)) ALLOCATE(che%NEMIS_TIME(che%NEMIS_NBR))
135 CHE%NEMIS_TIME(:) = -1
136 !
137 IF (hinit/='ALL') THEN
138  ALLOCATE(che%XEMIS_FIELDS(klu,che%NEMIS_NBR))
139  ALLOCATE(che%CEMIS_COMMENT(che%NEMIS_NBR))
140 END IF
141 !
142 ALLOCATE(itimes(che%NEMIS_NBR))
143 ALLOCATE(inbtimes(che%NEMISPEC_NBR))
144 ALLOCATE(ioffndx(che%NEMISPEC_NBR))
145 !
146 inbtimes(:) = -1
147 ioffndx(:) = 0 ! Index array of offline species
148 !
149 iind1 = 0 ! Index to fill NEMIS_GR_TIMES array
150 iind2 = 0 ! with emission times of offline species
151 !
152 inboff = 0 ! number of offline emission species (with emis time > 0)
153 DO jspec = 1,che%NEMISPEC_NBR ! Loop on the number of species
154 !
155 ! Read article EMISNAMExxx for the name of species
156 ! and extract from comment : surface type + number of emission times
157  WRITE(yrecfm,'("EMISNAME",I3.3)') jspec
158  CALL read_surf(hprogram,yrecfm,yspec_name,iresp,ycomment)
159  IF (iresp/=0) THEN
160  CALL abor1_sfx('CH_INIT_EMISSIONN: PROBLEM WHEN READING NAME OF EMITTED CHEMICAL SPECIES')
161  END IF
162 
163  WRITE(yrecfm,'("EMISAREA",I3.3)') jspec
164  CALL read_surf(hprogram,yrecfm,ysurf,iresp,ycomment)
165  WRITE(yrecfm,'("EMISNBT",I3.3)') jspec
166  CALL read_surf(hprogram,yrecfm,inbts,iresp,ycomment)
167  WRITE(iluout,*) ' Emission ',jspec,' : ',trim(yspec_name),'(',inbts,' instants )'
168 !
169 ! Read emission times for species number JSPEC
170  WRITE(yrecfm,'("EMISTIMES",I3.3)') jspec
171  CALL read_surf(hprogram,yrecfm,itimes(1:inbts),iresp,ycomment,'-')
172  IF (iresp/=0) THEN
173  CALL abor1_sfx('CH_INIT_EMISSIONN: PROBLEM WHEN READING EMISSION TIMES')
174  END IF
175  IF (inbts == 1) WRITE(iluout,*) ' -> ',itimes(1)
176 !
177 ! Is it an offline emission ?
178  IF (inbts >= 1) THEN
179  IF (itimes(1) >= 0) THEN
180 ! Yes it is. (Note that negative time refers to inline emission like biogenics
181 ! fluxes)
182 !
183  inboff = inboff+1
184  ioffndx(inboff) = jspec
185 !
186 ! INBTIMES and NEMIS_TIME only updated for offline emission
187  iind1 = iind2+1
188  iind2 = iind2+inbts
189  che%NEMIS_TIME(iind1:iind2) = itimes(1:inbts)
190  inbtimes(inboff) = inbts
191  END IF
192  END IF
193 !
194 CHE%NTIME_MAX = MAXVAL(CHE%NEMIS_TIME)
195 !
196 ! INBTIMES, CEMIS_AREA and CEMIS_NAME
197 ! are updated for ALL species
198  che%CEMIS_NAME(jspec) = yspec_name
199  che%CEMIS_AREA(jspec) = ysurf
200 !
201 !* 2. Simple reading of emission fields
202 
203  IF (hinit /= "ALL") THEN
204  yrecfm='E_'//trim(adjustl(yspec_name))
205  ALLOCATE(zwork2d(klu,inbts))
206  CALL read_surf_field2d(hprogram,zwork2d(:,:),yrecfm,ycomment)
207  che%XEMIS_FIELDS(:,iind1:iind2) = zwork2d(:,:)
208  che%CEMIS_COMMENT(iind1:iind2) = ycomment
209  DEALLOCATE(zwork2d)
210  END IF
211 !
212 END DO
213 !
214 WRITE(iluout,*) '---- Nunmer of OFFLINE species = ',inboff
215 WRITE(iluout,*) 'INBTIMES=',inbtimes
216 WRITE(iluout,*) 'IOFFNDX=',ioffndx
217 
218 iverb=6
219 
220 !* 3. Conversion and aggregation
221 
222 IF (hinit == "ALL") THEN
223  IF (inboff > 0) THEN
224  CALL open_namelist(hprogram,ich,hfile=hchem_surf_file)
225  ALLOCATE(che%TSEMISS(inboff))
226  ALLOCATE(yemis_name(inboff))
227 
228  CALL build_emisstab_n(pconversion, hprogram,ich,che%CEMIS_NAME,inbtimes,che%NEMIS_TIME,&
229  ioffndx,che%TSEMISS,klu,iluout,iverb,prhoa)
230  DO jspec = 1,inboff ! Loop on the number of species
231  yemis_name(jspec) = che%TSEMISS(jspec)%CNAME(1:12)
232  END DO
233  CALL build_pronoslist_n(hsv, SIZE(che%TSEMISS),yemis_name,che%TSPRONOSLIST,ich,iluout,iverb)
234  DEALLOCATE(yemis_name)
235  CALL close_namelist(hprogram,ich)
236  ELSE
237  ALLOCATE(che%TSEMISS(0))
238  NULLIFY(che%TSPRONOSLIST)
239  END IF
240 ENDIF
241 
242 DEALLOCATE(itimes,inbtimes,ioffndx)
243 WRITE(iluout,*) '------ Leaving CH_INIT_EMISSION ------'
244 IF (lhook) CALL dr_hook('CH_INIT_EMISSION_N',1,zhook_handle)
245 !-------------------------------------------------------------------------------
246 !
247 END SUBROUTINE ch_init_emission_n
subroutine build_emisstab_n(PCONVERSION, HPROGRAM, KCH, HEMIS_GR_NAME, KNBTIMES, KEMIS_GR_TIME, KOFFNDX, TPEMISS, KSIZE, KLUOUT, KVERB, PRHODREF)
subroutine build_pronoslist_n(HSV, KEMIS_NBR, HEMIS_NAME, TPPRONOS,
subroutine ch_init_emission_n(CHE, PCONVERSION, HSV, HPROGRAM, KLU
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:7
integer, parameter jprb
Definition: parkind1.F90:32
subroutine close_namelist(HPROGRAM, KLUNAM)
subroutine get_luout(HPROGRAM, KLUOUT)
Definition: get_luout.F90:7
logical lhook
Definition: yomhook.F90:15
subroutine read_surf_field2d(HPROGRAM, PFIELD2D, HFIELDNAME, HCOMMEN
subroutine open_namelist(HPROGRAM, KLUNAM, HFILE)