SURFEX v8.1
General documentation of Surfex
writesurf_ch_emisn.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 writesurf_ch_emis_n (HSELECT, CHE, HPROGRAM)
7 ! ##########################################################
8 !
9 !!**** *WRITESURF_CH_EMIS_n* - routine to write chemistry emission fields
10 !!
11 !! PURPOSE
12 !! -------
13 !!
14 !! AUTHOR
15 !! ------
16 !! V. Masson *Meteo France*
17 !!
18 !! MODIFICATIONS
19 !! -------------
20 !! Original 03/2004
21 !! M.Moge 01/2016 using WRITE_SURF_FIELD2D/3D for 2D/3D surfex fields writes
22 !-------------------------------------------------------------------------------
23 !
24 !* 0. DECLARATIONS
25 ! ------------
26 !
28 !
30 USE modi_write_surf_field2d
31 !
32 USE yomhook ,ONLY : lhook, dr_hook
33 USE parkind1 ,ONLY : jprb
34 !
35 USE modi_abor1_sfx
36 !
37 IMPLICIT NONE
38 !
39 !* 0.1 Declarations of arguments
40 ! -------------------------
41 !
42 !
43  CHARACTER(LEN=*), DIMENSION(:), INTENT(IN) :: HSELECT
44 !
45 TYPE(ch_emis_field_t), INTENT(INOUT) :: CHE
46 !
47  CHARACTER(LEN=6), INTENT(IN) :: HPROGRAM ! program calling
48 !
49 !* 0.2 Declarations of local variables
50 ! -------------------------------
51 !
52 INTEGER :: IRESP ! IRESP : return-code if a problem appears
53  ! at the open of the file in LFI routines
54 !
55  CHARACTER(LEN=12) :: YRECFM ! Name of the article to be written
56  CHARACTER(LEN=100):: YCOMMENT ! Comment string
57  CHARACTER(LEN=100):: YCOMMENTUNIT ! Comment string : unit of the datas in the field to write
58  CHARACTER(LEN=80) :: YNAME ! emitted species name
59 !
60  CHARACTER(LEN=40),DIMENSION(CHE%NEMIS_NBR) :: YEMISPEC_NAMES
61 INTEGER, DIMENSION(CHE%NEMIS_NBR) :: INBTIMES
62 INTEGER, DIMENSION(CHE%NEMIS_NBR) :: IFIRST,ILAST,INEXT
63 
64 INTEGER :: JI,JT ! loop indices
65 INTEGER :: JSPEC ! loop index
66 INTEGER :: INTIMESMAX,ITMP
67 INTEGER :: IEMISPEC_NBR
68 LOGICAL :: GFOUND,LOK
69 REAL(KIND=JPRB) :: ZHOOK_HANDLE
70 
71 !-------------------------------------------------------------------------------
72 !
73 !* 1. Chemical Emission fields :
74 ! --------------------------
75 !
76 IF (lhook) CALL dr_hook('WRITESURF_CH_EMIS_N',0,zhook_handle)
77 yrecfm='EMISFILE_NBR'
78 ycomment='Total number of 2D emission files.'
79  CALL write_surf(hselect, &
80  hprogram,yrecfm,che%NEMIS_NBR,iresp,hcomment=ycomment)
81 !
82 ! count emitted species
83 iemispec_nbr = 0
84 DO ji=1,che%NEMIS_NBR
85  yname = trim(adjustl(che%CEMIS_NAME(ji)))
86  gfound = .false.
87  DO jspec = 1,iemispec_nbr
88  IF (yemispec_names(jspec) == yname) THEN
89  gfound = .true.
90  EXIT
91  END IF
92  END DO
93  IF (.NOT. gfound) THEN
94  iemispec_nbr = iemispec_nbr+1
95  yemispec_names(iemispec_nbr) = yname
96  inbtimes(iemispec_nbr) = 1
97  ifirst(iemispec_nbr) = ji
98  ilast(iemispec_nbr) = ji
99  inext(ji) = 0
100  ELSE
101  inext(ilast(jspec)) = ji
102  inext(ji) = 0
103  ilast(jspec) = ji
104  inbtimes(jspec) = inbtimes(jspec)+1
105  END IF
106 END DO
107 !
108 yrecfm='EMISPEC_NBR '
109 ycomment='Number of emitted chemical species.'
110  CALL write_surf(hselect, &
111  hprogram,yrecfm,iemispec_nbr,iresp,hcomment=ycomment)
112 !
113 IF (iemispec_nbr > 0) THEN
114  !
115  DO jspec = 1,iemispec_nbr
116  CALL write_emis_spec(inbtimes(jspec))
117  ENDDO
118  !
119 ENDIF
120 !
121 IF (lhook) CALL dr_hook('WRITESURF_CH_EMIS_N',1,zhook_handle)
122 !
123 !-------------------------------------------------------------------------------
124 CONTAINS
125 !
126 SUBROUTINE write_emis_spec(KSIZE)
127 !
128 INTEGER, INTENT(IN) :: KSIZE
129 INTEGER,DIMENSION(KSIZE) :: ITIME
130 INTEGER,DIMENSION(KSIZE) :: IINDEX
131 REAL,DIMENSION(SIZE(CHE%XEMIS_FIELDS,1),KSIZE) :: ZWORK2D
132 REAL(KIND=JPRB) :: ZHOOK_HANDLE
133 !
134 IF (lhook) CALL dr_hook('WRITESURF_CH_EMIS_N:WRITE_EMIS_SPEC',0,zhook_handle)
135 !
136 ji = ifirst(jspec)
137 jt = 0
138 ! fill the emission times array (ITIME)
139 ! and the corresponding indices array (IINDEX)
140 ! for species number JSPEC
141 DO WHILE(ji /= 0)
142  jt = jt+1
143  itime(jt) = che%NEMIS_TIME(ji)
144  iindex(jt) = ji
145  ji = inext(ji)
146 END DO
147 IF (jt /= ksize) THEN
148  CALL abor1_sfx('WRITESURF_CH_EMISN: ABNORMAL ERROR')
149 END IF
150 ! sort indices according to ITIME values
151 lok = .true.
152 DO WHILE (lok)
153  lok = .false.
154  DO ji=2,ksize
155  IF (itime(ji-1) > itime(ji)) THEN
156  lok = .true.
157  itmp = itime(ji-1)
158  itime(ji-1) = itime(ji)
159  itime(ji) = itmp
160  itmp = iindex(ji-1)
161  iindex(ji-1) = iindex(ji)
162  iindex(ji) = itmp
163  END IF
164  END DO
165 END DO
166 ! Now fill the ZWORK2D array for writing
167 zwork2d(:,:) = che%XEMIS_FIELDS(:,iindex(:))
168 !
169 ! Write NAME of species JSPEC with AREA and number of emission times
170 ! stored in the commentary
171 WRITE(yrecfm,'("EMISNAME",I3.3)') jspec
172 WRITE(ycomment,'(A3,", emission times number:",I5)') che%CEMIS_AREA(iindex(1)),ksize
173  CALL write_surf(hselect, &
174  hprogram,yrecfm,yemispec_names(jspec),iresp,hcomment=ycomment)
175 !
176 WRITE(yrecfm,'("EMISAREA",I3.3)') jspec
177 ycomment = "Emission area"
178  CALL write_surf(hselect, &
179  hprogram,yrecfm,che%CEMIS_AREA(iindex(1)),iresp,hcomment=ycomment)
180 !
181 WRITE(yrecfm,'("EMISNBT",I3.3)') jspec
182 ycomment = "Emission times number"
183  CALL write_surf(hselect, &
184  hprogram,yrecfm,ksize,iresp,hcomment=ycomment)
185 
186 ! Write emission times (ITIME) for species JSPEC
187 WRITE(yrecfm,'("EMISTIMES",I3.3)') jspec
188 ycomment = "Emission times in second"
189  CALL write_surf(hselect, &
190  hprogram,yrecfm,itime(:),iresp,hcomment=ycomment,hdir='-',hnam_dim="Temporal_emiss ")
191 !
192 ! Finally write emission data for species JSPEC
193 yrecfm = "E_"//trim(yemispec_names(jspec))
194 ycomment = "Emission data (x,y,t),"//trim(che%CEMIS_COMMENT(iindex(1)))
195 ycommentunit='-'
196  CALL write_surf_field2d(hselect, &
197  hprogram,zwork2d(:,:),yrecfm,ycomment,ycommentunit,hnam_dim="Temporal_emiss ")
198 !
199 IF (lhook) CALL dr_hook('WRITESURF_CH_EMIS_N:WRITE_EMIS_SPEC',1,zhook_handle)
200 !
201 END SUBROUTINE write_emis_spec
202 !
203 END SUBROUTINE writesurf_ch_emis_n
static const char * trim(const char *name, int *n)
Definition: drhook.c:2383
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:7
integer, parameter jprb
Definition: parkind1.F90:32
subroutine writesurf_ch_emis_n(HSELECT, CHE, HPROGRAM)
logical lhook
Definition: yomhook.F90:15
subroutine write_surf_field2d(HSELECT, HPROGRAM, PFIELD2D, HFIELDNAME
subroutine write_emis_spec(KSIZE)