SURFEX v8.1
General documentation of Surfex
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 (CHN, HSV, HPROGRAM,KLU,HINIT,PRHOA,HCHEM_SURF_FILE)
7 ! #######################################
8 !
9 !!**** *CH_INIT_EMIISION_TEMP_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 !! S.QUEGUINER
23 !!
24 !! MODIFICATIONS
25 !! -------------
26 !! Original 11/2011
27 !! J.Escobar 11/2013 : ajout use MODI_CH_OPEN_INPUTB
28 !! M.Moge 01/2016 using READ_SURF_FIELD2D for 2D surfex fields reads
29 !! M.Leriche & V. Masson 05/16 move open namelist for reading ascii chemi.file
30 !!-----------------------------------------------------------------------------
31 !
32 !* 0. DECLARATIONS
33 !
35 !
36 USE modd_csts, ONLY : xavogadro, xmd
37 USE modi_get_luout
39 USE modi_abor1_sfx
40 USE modi_ch_conversion_factor
41 USE modi_ch_open_inputb
42 USE modi_build_pronoslist_n
43 USE modi_read_surf_field2d
44 USE modi_open_namelist
45 USE modi_close_namelist
46 !
47 USE yomhook ,ONLY : lhook, dr_hook
48 USE parkind1 ,ONLY : jprb
49 !
50 !
51 IMPLICIT NONE
52 !
53 !* 0.1 declarations of arguments
54 !
55 !
56 !
57 !
58 TYPE(ch_emis_snap_t), INTENT(INOUT) :: CHN
59  CHARACTER(LEN=*), DIMENSION(:), POINTER :: HSV
60 !
61  CHARACTER(LEN=6), INTENT(IN) :: HPROGRAM ! Program name
62 INTEGER, INTENT(IN) :: KLU ! number of points
63  CHARACTER(LEN=3), INTENT(IN) :: HINIT ! Flag to know if one initializes:
64 ! ! 'ALL' : all variables for a run
65 ! ! 'PRE' : only variables to build
66 ! ! an initial file
67 REAL, DIMENSION(:),INTENT(IN) :: PRHOA ! air density
68  CHARACTER(LEN=28), INTENT(IN) :: HCHEM_SURF_FILE ! ascii file for chemistry aggregation
69 !
70 !* 0.2 declarations of local variables
71 !
72 REAL, DIMENSION(:,:), ALLOCATABLE :: ZTEMP
73 INTEGER :: ISNAP
74 INTEGER :: IRESP ! File
75 INTEGER :: ILUOUT ! output listing logical unit
76  CHARACTER (LEN=3) :: YCONVERSION
77  CHARACTER (LEN=16) :: YRECFM ! management
78  CHARACTER (LEN=100) :: YCOMMENT ! variables
79 INTEGER :: JSPEC ! Loop index for chemical species
80 INTEGER :: JSNAP ! Loop index for SNAP categories
81 !
82  CHARACTER(LEN=40) :: YSPEC_NAME ! species name
83 !
84 INTEGER :: IVERSION ! version of surfex file being read
85 INTEGER :: IBUG ! version of SURFEX bugfix
86 INTEGER :: ICH ! unit of input chemical file
87 REAL(KIND=JPRB) :: ZHOOK_HANDLE
88 !-------------------------------------------------------------------------------
89 IF (lhook) CALL dr_hook('CH_INIT_SNAP_N',0,zhook_handle)
90  CALL get_luout(hprogram,iluout)
91 !
92 !* ascendant compatibility
93 yrecfm='VERSION'
94  CALL read_surf(hprogram,yrecfm,iversion,iresp)
95 yrecfm='BUG'
96  CALL read_surf(hprogram,yrecfm,ibug,iresp)
97 !
98 !* 1. Chemical Emission snap configuration
99 ! ------------------------------------
100 !
101 ! Read the number of emission species and snaps
102 IF (iversion>7 .OR. (iversion==7 .AND. ibug>=3) ) THEN
103  CALL read_surf(hprogram,'EMISPEC_NBR',chn%NEMIS_NBR,iresp)
104  CALL read_surf(hprogram,'SNAP_NBR',chn%NEMIS_SNAP,iresp)
105  CALL read_surf(hprogram,'SNAP_TIME',chn%CSNAP_TIME_REF,iresp)
106 ELSE
107  CALL abor1_sfx('CH_INIT_SNAPN: NO SNAP EMISSIONS IN SURFEX FILE: FILE TOO OLD')
108 END IF
109 !
110 ! Number of instants for each temporal profile.
111 ! For the time being, they are constant (even for the diurnal cycle)
112 !
113 CHN%NSNAP_M=12 ! 12 months
114 CHN%NSNAP_D=7 ! 7 day a week
115 CHN%NSNAP_H=24 ! 24 hours a day (=> temporal resolution = 1 hour)
116 !
117 !
118 !* 2. Chemical Emission fields
119 ! ------------------------
120 !
121 ALLOCATE(chn%CEMIS_NAME ( chn%NEMIS_NBR))
122 ALLOCATE(chn%CEMIS_COMMENT ( chn%NEMIS_NBR))
123 ALLOCATE(chn%XEMIS_FIELDS_SNAP(klu,chn%NEMIS_SNAP,chn%NEMIS_NBR))
124 ALLOCATE(chn%XEMIS_FIELDS (klu, chn%NEMIS_NBR))
125 !
126 ALLOCATE(chn%XSNAP_MONTHLY(chn%NSNAP_M,chn%NEMIS_SNAP,chn%NEMIS_NBR))
127 ALLOCATE(chn%XSNAP_DAILY (chn%NSNAP_D,chn%NEMIS_SNAP,chn%NEMIS_NBR))
128 ALLOCATE(chn%XSNAP_HOURLY (chn%NSNAP_H,chn%NEMIS_SNAP,chn%NEMIS_NBR))
129 !
130 IF (chn%CSNAP_TIME_REF=='LEGAL') THEN
131  ALLOCATE(chn%XDELTA_LEGAL_TIME(klu))
132  yrecfm='LEGALTIME'
133  CALL read_surf(hprogram,yrecfm,chn%XDELTA_LEGAL_TIME(:),iresp,ycomment)
134 END IF
135 !
136 IF (hprogram=="NC ") THEN
137  isnap = max(chn%NSNAP_M,chn%NSNAP_D,chn%NSNAP_H)
138  ALLOCATE(ztemp(isnap,chn%NEMIS_SNAP))
139 ENDIF
140 !
141 DO jspec = 1,chn%NEMIS_NBR ! Loop on the number of species
142 !
143 ! Read the species name
144  WRITE(yrecfm,'("EMISNAME",I3.3)') jspec
145  CALL read_surf(hprogram,yrecfm,yspec_name,iresp,ycomment)
146  chn%CEMIS_COMMENT(jspec)=ycomment
147  IF (iresp/=0) THEN
148  CALL abor1_sfx('CH_INIT_SNAPN: PROBLEM WHEN READING NAME OF EMITTED CHEMICAL SPECIES')
149  END IF
150  WRITE(iluout,*) ' Emission ',jspec,' : ',trim(yspec_name)
151  chn%CEMIS_NAME(jspec) = yspec_name(1:12)
152 !
153 ! Read the potential emission of species for each snap
154  DO jsnap=1,chn%NEMIS_SNAP
155  WRITE(yrecfm,'("SN",I2.2,"_",A7)') jsnap,chn%CEMIS_NAME(jspec)
156  CALL read_surf(hprogram,yrecfm,chn%XEMIS_FIELDS_SNAP(:,jsnap,jspec),iresp,ycomment)
157  END DO
158 !
159 ! Read the temporal profiles of all snaps
160  yrecfm = "E_"//trim(chn%CEMIS_NAME(jspec))//"_M"
161  IF (hprogram=="NC ") THEN
162  CALL read_surf_field2d(hprogram,ztemp,yrecfm,ycomment,hdir='-')
163  chn%XSNAP_MONTHLY(:,:,jspec) = ztemp(1:chn%NSNAP_M,:)
164  ELSE
165  CALL read_surf_field2d(hprogram,chn%XSNAP_MONTHLY(:,:,jspec),yrecfm,ycomment,hdir='-')
166  ENDIF
167  yrecfm = "E_"//trim(chn%CEMIS_NAME(jspec))//"_D"
168  IF (hprogram=="NC ") THEN
169  CALL read_surf_field2d(hprogram,ztemp,yrecfm,ycomment,hdir='-')
170  chn%XSNAP_DAILY(:,:,jspec) = ztemp(1:chn%NSNAP_D,:)
171  ELSE
172  CALL read_surf_field2d(hprogram,chn%XSNAP_DAILY(:,:,jspec),yrecfm,ycomment,hdir='-')
173  ENDIF
174  yrecfm = "E_"//trim(chn%CEMIS_NAME(jspec))//"_H"
175  IF (hprogram=="NC ") THEN
176  CALL read_surf_field2d(hprogram,ztemp,yrecfm,ycomment,hdir='-')
177  chn%XSNAP_HOURLY(:,:,jspec) = ztemp(1:chn%NSNAP_H,:)
178  ELSE
179  CALL read_surf_field2d(hprogram,chn%XSNAP_HOURLY(:,:,jspec),yrecfm,ycomment,hdir='-')
180  ENDIF
181 END DO
182 !
183 IF (hprogram=="NC ") DEALLOCATE(ztemp)
184 !
185 !* 3. Conversion factor
186 ! -----------------
187 !
188 IF (hinit=='ALL') THEN
189  CALL open_namelist(hprogram,ich,hfile=hchem_surf_file)
190  CALL ch_open_inputb("EMISUNIT", ich, iluout)
191 !
192 ! read unit identifier
193  READ(ich,'(A3)') yconversion
194 !
195  chn%CCONVERSION = yconversion
196 !
197  ALLOCATE (chn%XCONVERSION(klu))
198 ! determine the conversion factor
199  CALL ch_conversion_factor(chn%XCONVERSION, chn%CCONVERSION,prhoa)
200 !
201 !* 4. List of emissions to be aggregated into atm. chemical species
202 ! -------------------------------------------------------------
203 !
204  CALL build_pronoslist_n(hsv, chn%NEMIS_NBR,chn%CEMIS_NAME,chn%TSPRONOSLIST,ich,iluout,6)
205 !
206  CALL close_namelist(hprogram,ich)
207 !-------------------------------------------------------------------------------
208 END IF
209 !
210 IF (lhook) CALL dr_hook('CH_INIT_SNAP_N',1,zhook_handle)
211 !-------------------------------------------------------------------------------
212 !
213 END SUBROUTINE ch_init_snap_n
real, save xmd
Definition: modd_csts.F90:61
subroutine ch_conversion_factor(PCONVERSION, HCONVERSION, PRHOA)
subroutine build_pronoslist_n(HSV, KEMIS_NBR, HEMIS_NAME, TPPRONOS,
subroutine ch_init_snap_n(CHN, HSV, HPROGRAM, KLU, HINIT, PRHOA, HCHE
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:7
subroutine ch_open_inputb(HKEYWORD, KCHANNEL, KLUOUT)
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)
real, save xavogadro
Definition: modd_csts.F90:52