SURFEX  V8_0
Surfex V8_0 release
 All Classes Files Functions Variables
ch_init_snapn.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_snap_n (&
7  chn, sv, &
8  hprogram,klu,hinit,kch,prhoa)
9 ! #######################################
10 !
11 !!**** *CH_INIT_EMIISION_TEMP_n* - routine to initialize chemical emissions data structure
12 !!
13 !! PURPOSE
14 !! -------
15 ! Allocates and initialize emission surface fields
16 ! by reading their value in initial file.
17 !
18 !!** METHOD
19 !! ------
20 !!
21 !!
22 !! AUTHOR
23 !! ------
24 !! S.QUEGUINER
25 !!
26 !! MODIFICATIONS
27 !! -------------
28 !! Original 11/2011
29 !! J.Escobar 11/2013 : ajout use MODI_CH_OPEN_INPUTB
30 !!-----------------------------------------------------------------------------
31 !
32 !* 0. DECLARATIONS
33 !
34 !
35 !
36 !
37 !
38 !
40 USE modd_sv_n, ONLY : sv_t
41 !
42 USE modd_csts, ONLY : xavogadro, xmd
43 USE modi_get_luout
45 USE modi_abor1_sfx
46 USE modi_ch_conversion_factor
47 USE modi_ch_open_inputb
48 USE modi_build_pronoslist_n
49 !
50 USE yomhook ,ONLY : lhook, dr_hook
51 USE parkind1 ,ONLY : jprb
52 !
53 !
54 IMPLICIT NONE
55 !
56 !* 0.1 declarations of arguments
57 !
58 !
59 !
60 !
61 TYPE(ch_emis_snap_t), INTENT(INOUT) :: chn
62 TYPE(sv_t), INTENT(INOUT) :: sv
63 !
64  CHARACTER(LEN=6), INTENT(IN) :: hprogram ! Program name
65 INTEGER, INTENT(IN) :: klu ! number of points
66  CHARACTER(LEN=3), INTENT(IN) :: hinit ! Flag to know if one initializes:
67 ! ! 'ALL' : all variables for a run
68 ! ! 'PRE' : only variables to build
69 ! ! an initial file
70 INTEGER, INTENT(IN) :: kch ! logical unit of input chemistry file
71 REAL, DIMENSION(:),INTENT(IN) :: prhoa ! air density
72 !
73 !* 0.2 declarations of local variables
74 !
75 REAL, DIMENSION(:,:), ALLOCATABLE :: ztemp
76 INTEGER :: isnap
77 INTEGER :: iresp ! File
78 INTEGER :: iluout ! output listing logical unit
79  CHARACTER (LEN=3) :: yconversion
80  CHARACTER (LEN=16) :: yrecfm ! management
81  CHARACTER (LEN=100) :: ycomment ! variables
82 INTEGER :: jspec ! Loop index for chemical species
83 INTEGER :: jsnap ! Loop index for SNAP categories
84 !
85  CHARACTER(LEN=40) :: yspec_name ! species name
86 !
87 INTEGER :: iversion ! version of surfex file being read
88 INTEGER :: ibug ! version of SURFEX bugfix
89 REAL(KIND=JPRB) :: zhook_handle
90 !-------------------------------------------------------------------------------
91 IF (lhook) CALL dr_hook('CH_INIT_SNAP_N',0,zhook_handle)
92  CALL get_luout(hprogram,iluout)
93 !
94 !* ascendant compatibility
95 yrecfm='VERSION'
96  CALL read_surf(&
97  hprogram,yrecfm,iversion,iresp)
98 yrecfm='BUG'
99  CALL read_surf(&
100  hprogram,yrecfm,ibug,iresp)
101 !
102 !* 1. Chemical Emission snap configuration
103 ! ------------------------------------
104 !
105 ! Read the number of emission species and snaps
106 IF (iversion>7 .OR. (iversion==7 .AND. ibug>=3) ) THEN
107  CALL read_surf(&
108  hprogram,'EMISPEC_NBR',chn%NEMIS_NBR,iresp)
109  CALL read_surf(&
110  hprogram,'SNAP_NBR',chn%NEMIS_SNAP,iresp)
111  CALL read_surf(&
112  hprogram,'SNAP_TIME',chn%CSNAP_TIME_REF,iresp)
113 ELSE
114  CALL abor1_sfx('CH_INIT_SNAPN: NO SNAP EMISSIONS IN SURFEX FILE: FILE TOO OLD')
115 END IF
116 !
117 ! Number of instants for each temporal profile.
118 ! For the time being, they are constant (even for the diurnal cycle)
119 !
120  chn%NSNAP_M=12 ! 12 months
121  chn%NSNAP_D=7 ! 7 day a week
122  chn%NSNAP_H=24 ! 24 hours a day (=> temporal resolution = 1 hour)
123 !
124 !
125 !* 2. Chemical Emission fields
126 ! ------------------------
127 !
128 ALLOCATE(chn%CEMIS_NAME ( chn%NEMIS_NBR))
129 ALLOCATE(chn%CEMIS_COMMENT ( chn%NEMIS_NBR))
130 ALLOCATE(chn%XEMIS_FIELDS_SNAP(klu,chn%NEMIS_SNAP,chn%NEMIS_NBR))
131 ALLOCATE(chn%XEMIS_FIELDS (klu, chn%NEMIS_NBR))
132 !
133 ALLOCATE(chn%XSNAP_MONTHLY(chn%NSNAP_M,chn%NEMIS_SNAP,chn%NEMIS_NBR))
134 ALLOCATE(chn%XSNAP_DAILY (chn%NSNAP_D,chn%NEMIS_SNAP,chn%NEMIS_NBR))
135 ALLOCATE(chn%XSNAP_HOURLY (chn%NSNAP_H,chn%NEMIS_SNAP,chn%NEMIS_NBR))
136 !
137 IF (chn%CSNAP_TIME_REF=='LEGAL') THEN
138  ALLOCATE(chn%XDELTA_LEGAL_TIME(klu))
139  yrecfm='LEGALTIME'
140  CALL read_surf(&
141  hprogram,yrecfm,chn%XDELTA_LEGAL_TIME(:),iresp,ycomment)
142 END IF
143 !
144 IF (hprogram=="NC ") THEN
145  isnap = max(chn%NSNAP_M,chn%NSNAP_D,chn%NSNAP_H)
146  ALLOCATE(ztemp(isnap,chn%NEMIS_SNAP))
147 ENDIF
148 !
149 DO jspec = 1,chn%NEMIS_NBR ! Loop on the number of species
150 !
151 ! Read the species name
152  WRITE(yrecfm,'("EMISNAME",I3.3)') jspec
153  CALL read_surf(&
154  hprogram,yrecfm,yspec_name,iresp,ycomment)
155  chn%CEMIS_COMMENT(jspec)=ycomment
156  IF (iresp/=0) THEN
157  CALL abor1_sfx('CH_INIT_SNAPN: PROBLEM WHEN READING NAME OF EMITTED CHEMICAL SPECIES')
158  END IF
159  WRITE(iluout,*) ' Emission ',jspec,' : ',trim(yspec_name)
160  chn%CEMIS_NAME(jspec) = yspec_name(1:12)
161 !
162 ! Read the potential emission of species for each snap
163  DO jsnap=1,chn%NEMIS_SNAP
164  WRITE(yrecfm,'("SNAP",I2.2,"_",A3)') jsnap,chn%CEMIS_NAME(jspec)
165  CALL read_surf(&
166  hprogram,yrecfm,chn%XEMIS_FIELDS_SNAP(:,jsnap,jspec),iresp,ycomment)
167  END DO
168 !
169 ! Read the temporal profiles of all snaps
170  yrecfm = "E_"//trim(chn%CEMIS_NAME(jspec))//"_M"
171  IF (hprogram=="NC ") THEN
172  CALL read_surf(&
173  hprogram,yrecfm,ztemp,iresp,ycomment,hdir='-')
174  chn%XSNAP_MONTHLY(:,:,jspec) = ztemp(1:chn%NSNAP_M,:)
175  ELSE
176  CALL read_surf(&
177  hprogram,yrecfm,chn%XSNAP_MONTHLY(:,:,jspec),iresp,ycomment,hdir='-')
178  ENDIF
179  yrecfm = "E_"//trim(chn%CEMIS_NAME(jspec))//"_D"
180  IF (hprogram=="NC ") THEN
181  CALL read_surf(&
182  hprogram,yrecfm,ztemp,iresp,ycomment,hdir='-')
183  chn%XSNAP_DAILY(:,:,jspec) = ztemp(1:chn%NSNAP_D,:)
184  ELSE
185  CALL read_surf(&
186  hprogram,yrecfm,chn%XSNAP_DAILY(:,:,jspec),iresp,ycomment,hdir='-')
187  ENDIF
188  yrecfm = "E_"//trim(chn%CEMIS_NAME(jspec))//"_H"
189  IF (hprogram=="NC ") THEN
190  CALL read_surf(&
191  hprogram,yrecfm,ztemp,iresp,ycomment,hdir='-')
192  chn%XSNAP_HOURLY(:,:,jspec) = ztemp(1:chn%NSNAP_H,:)
193  ELSE
194  CALL read_surf(&
195  hprogram,yrecfm,chn%XSNAP_HOURLY(:,:,jspec),iresp,ycomment,hdir='-')
196  ENDIF
197 END DO
198 !
199 IF (hprogram=="NC ") DEALLOCATE(ztemp)
200 !
201 !* 3. Conversion factor
202 ! -----------------
203 !
204 IF (hinit=='ALL') THEN
205 !$OMP SINGLE
206  CALL ch_open_inputb("EMISUNIT", kch, iluout)
207 !
208 ! read unit identifier
209  READ(kch,'(A3)') yconversion
210 !$OMP END SINGLE COPYPRIVATE(YCONVERSION)
211 !
212  chn%CCONVERSION = yconversion
213 !
214  ALLOCATE (chn%XCONVERSION(klu))
215 ! determine the conversion factor
216  CALL ch_conversion_factor(chn, &
217  chn%CCONVERSION,prhoa)
218 !
219 !* 4. List of emissions to be aggregated into atm. chemical species
220 ! -------------------------------------------------------------
221 !
222  CALL build_pronoslist_n(sv, &
223  chn%NEMIS_NBR,chn%CEMIS_NAME,chn%TSPRONOSLIST,kch,iluout,6)
224 !
225 !-------------------------------------------------------------------------------
226 END IF
227 !
228 IF (lhook) CALL dr_hook('CH_INIT_SNAP_N',1,zhook_handle)
229 !-------------------------------------------------------------------------------
230 !
231 END SUBROUTINE ch_init_snap_n
subroutine ch_conversion_factor(CHN, HCONVERSION, PRHOA)
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:6
subroutine ch_init_snap_n(CHN, SV, HPROGRAM, KLU, HINIT, KCH, PRHOA)
subroutine build_pronoslist_n(SV, KEMIS_NBR, HEMIS_NAME, TPPRONOS, KCH, KLUOUT, KVERB)
subroutine get_luout(HPROGRAM, KLUOUT)
Definition: get_luout.F90:6