SURFEX  V8_0
Surfex V8_0 release
 All Classes Files Functions Variables
writesurf_gr_snow.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_gr_snow (DGU, U, &
7  hprogram,hsurftype,hprefix,tpsnow )
8 ! ##########################################################
9 !
10 !!**** *WRITESURF_GR_SNOW* - routine to write snow surface fields
11 !!
12 !! PURPOSE
13 !! -------
14 ! Writes snow surface fields
15 !
16 !!** METHOD
17 !! ------
18 !!
19 !!
20 !!
21 !! EXTERNAL
22 !! --------
23 !!
24 !!
25 !! IMPLICIT ARGUMENTS
26 !! ------------------
27 !!
28 !! REFERENCE
29 !! ---------
30 !!
31 !!
32 !!
33 !! AUTHOR
34 !! ------
35 !! V. Masson * Meteo France *
36 !!
37 !! MODIFICATIONS
38 !! -------------
39 !! Original 02/2003
40 !! A. Bogatchev 09/2005 EBA snow option
41 !-----------------------------------------------------------------------------
42 !
43 !* 0. DECLARATIONS
44 !
45 !
46 !
48 USE modd_surf_atm_n, ONLY : surf_atm_t
49 !
50 USE modd_surf_par, ONLY : xundef
52 USE modd_prep_snow, ONLY : lsnow_frac_tot
53 !
54 USE modi_detect_field
56 !
57 USE yomhook ,ONLY : lhook, dr_hook
58 USE parkind1 ,ONLY : jprb
59 !
60 IMPLICIT NONE
61 !
62 !* 0.1 declarations of arguments
63 !
64 !
65 TYPE(diag_surf_atm_t), INTENT(INOUT) :: dgu
66 TYPE(surf_atm_t), INTENT(INOUT) :: u
67 !
68  CHARACTER (LEN=6), INTENT(IN) :: hprogram ! program
69  CHARACTER (LEN=*), INTENT(IN) :: hsurftype ! generic name used for
70  ! snow characteristics
71  ! storage in file
72  CHARACTER (LEN=3), INTENT(IN) :: hprefix ! generic name of prefix for
73  ! patch identification
74 TYPE(surf_snow), INTENT(IN) :: tpsnow ! snow characteristics
75 !
76 !* 0.2 declarations of local variables
77 !
78 INTEGER :: isurftype_len
79 !
80  CHARACTER (LEN=100) :: yfmt ! format for writing
81  CHARACTER(LEN=12) :: yrecfm ! Name of the article to be read
82  CHARACTER(LEN=100) :: ycomment ! Comment string
83 INTEGER :: iresp ! IRESP : return-code if a problem appears
84 !
85 LOGICAL :: gsnow ! T --> snow exists somewhere
86 !
87 INTEGER :: jlayer ! loop counter
88  CHARACTER(LEN=4) :: ynlayer ! String depending on the number of layer : less
89  !than 10 or more
90 !
91 REAL(KIND=JPRB) :: zhook_handle
92 !-------------------------------------------------------------------------------
93 IF (lhook) CALL dr_hook('WRITESURF_GR_SNOW',0,zhook_handle)
94 !
95 !* 1. Initialisation
96 ! --------------
97 !
98 isurftype_len = len_trim(hsurftype)
99 !
100 !
101 !* 2. Type of snow scheme
102 ! -------------------
103 !
104 WRITE(yfmt,'(A5,I1,A4)') '(A3,A',isurftype_len,',A4)'
105 WRITE(yrecfm,yfmt) 'SN_',hsurftype,'_TYP'
106 yrecfm=adjustl(hprefix//yrecfm)
107 ycomment=' '
108  CALL write_surf(dgu, u, &
109  hprogram,yrecfm,tpsnow%SCHEME,iresp,hcomment=ycomment)
110 !
111 !
112 !* 3. Number of layers
113 ! ----------------
114 !
115 WRITE(yfmt,'(A5,I1,A4)') '(A3,A',isurftype_len,',A2)'
116 WRITE(yrecfm,yfmt) 'SN_',hsurftype,'_N'
117 yrecfm=adjustl(hprefix//yrecfm)
118 ycomment = '(INTEGER)'
119  CALL write_surf(dgu, u, &
120  hprogram,yrecfm,tpsnow%NLAYER,iresp,hcomment=ycomment)
121 !
122 !
123 !* 4. Tests to find if there is snow
124 ! ------------------------------
125 !
126 IF (tpsnow%NLAYER>0) THEN
127  CALL detect_field(hprogram,tpsnow%WSNOW(:,1,:),gsnow)
128 ELSE
129  gsnow = .false.
130 END IF
131 !
132 WRITE(yfmt,'(A5,I1,A1)') '(A3,A',isurftype_len,')'
133 WRITE(yrecfm,yfmt) 'SN_',hsurftype
134 yrecfm=adjustl(hprefix//yrecfm)
135 ycomment = '(LOGICAL)'
136  CALL write_surf(dgu, u, &
137  hprogram,yrecfm,gsnow,iresp,hcomment=ycomment)
138 !
139 !
140 IF (.NOT. gsnow) THEN
141  IF (lhook) CALL dr_hook('WRITESURF_GR_SNOW',1,zhook_handle)
142  RETURN
143 END IF
144 !
145 !
146 !* 5. Additional key
147 ! ---------------
148 !
149 ycomment = '(LOGICAL)'
150  CALL write_surf(dgu, u, &
151  hprogram,'LSNOW_FRAC_T',lsnow_frac_tot,iresp,hcomment=ycomment)
152 !
153 !
154 DO jlayer = 1,tpsnow%NLAYER
155  !
156  ynlayer='I1.1'
157  IF (jlayer>9) ynlayer='I2.2'
158  !
159  IF (tpsnow%SCHEME=='1-L' .OR. tpsnow%SCHEME=='D95' .OR. tpsnow%SCHEME=='EBA' .OR. &
160  tpsnow%SCHEME=='3-L' .OR. tpsnow%SCHEME=='CRO') THEN
161  !
162  !* 6. Snow reservoir
163  ! --------------
164  !
165  WRITE(yfmt,'(A5,I1,A6)') '(A4,A',isurftype_len,','//ynlayer//')'
166  WRITE(yrecfm,yfmt) 'WSN_',hsurftype,jlayer
167  yrecfm=adjustl(hprefix//yrecfm)
168  WRITE(yfmt,'(A6,I1,A9)') '(A10,A',isurftype_len,','//ynlayer//',A8))'
169  WRITE(ycomment,yfmt) 'X_Y_WSNOW_',hsurftype,jlayer,' (kg/m2)'
170  CALL write_surf(dgu, u, &
171  hprogram,yrecfm,tpsnow%WSNOW(:,jlayer,:),iresp,hcomment=ycomment)
172  !
173  !* 7. Snow density
174  ! ------------
175  !
176  WRITE(yfmt,'(A5,I1,A6)') '(A4,A',isurftype_len,','//ynlayer//')'
177  WRITE(yrecfm,yfmt) 'RSN_',hsurftype,jlayer
178  yrecfm=adjustl(hprefix//yrecfm)
179  WRITE(yfmt,'(A6,I1,A9)') '(A10,A',isurftype_len,','//ynlayer//',A8))'
180  WRITE(ycomment,yfmt) 'X_Y_RSNOW_',hsurftype,jlayer,' (kg/m3)'
181  CALL write_surf(dgu, u, &
182  hprogram,yrecfm,tpsnow%RHO(:,jlayer,:),iresp,hcomment=ycomment)
183  !
184  END IF
185  !
186  !* 8. Snow temperature
187  ! ----------------
188  !
189  IF (tpsnow%SCHEME=='1-L') THEN
190  !
191  WRITE(yfmt,'(A5,I1,A6)') '(A4,A',isurftype_len,','//ynlayer//')'
192  WRITE(yrecfm,yfmt) 'TSN_',hsurftype,jlayer
193  yrecfm=adjustl(hprefix//yrecfm)
194  WRITE(yfmt,'(A6,I1,A9)') '(A10,A',isurftype_len,','//ynlayer//',A8))'
195  WRITE(ycomment,yfmt) 'X_Y_TSNOW_',hsurftype,jlayer,' (K)'
196  CALL write_surf(dgu, u, &
197  hprogram,yrecfm,tpsnow%T(:,jlayer,:),iresp,hcomment=ycomment)
198  !
199  END IF
200  !
201  IF (tpsnow%SCHEME=='3-L' .OR. tpsnow%SCHEME=='CRO') THEN
202  !
203  !* 9. Heat content
204  ! ------------
205  !
206  WRITE(yfmt,'(A5,I1,A6)') '(A4,A',isurftype_len,','//ynlayer//')'
207  WRITE(yrecfm,yfmt) 'HSN_',hsurftype,jlayer
208  yrecfm=adjustl(hprefix//yrecfm)
209  WRITE(yfmt,'(A6,I1,A9)') '(A10,A',isurftype_len,','//ynlayer//',A8))'
210  WRITE(ycomment,yfmt) 'X_Y_HSNOW_',hsurftype,jlayer,' (J/m3)'
211  CALL write_surf(dgu, u, &
212  hprogram,yrecfm,tpsnow%HEAT(:,jlayer,:),iresp,hcomment=ycomment)
213  !
214  !* 10. Age parameter
215  ! ---------------
216  !
217  WRITE(yfmt,'(A5,I1,A6)') '(A4,A',isurftype_len,','//ynlayer//')'
218  WRITE(yrecfm,yfmt) 'SAG_',hsurftype,jlayer
219  yrecfm=adjustl(hprefix//yrecfm)
220  WRITE(yfmt,'(A6,I1,A9)') '(A9,A',isurftype_len,','//ynlayer//',A8))'
221  WRITE(ycomment,yfmt) 'X_Y_SAGE_',hsurftype,jlayer,' (-)'
222  CALL write_surf(dgu, u, &
223  hprogram,yrecfm,tpsnow%AGE(:,jlayer,:),iresp,hcomment=ycomment)
224  !
225  END IF
226  !
227  IF (tpsnow%SCHEME=='CRO') THEN
228  !
229  !* 11. Snow Gran1
230  ! ----------
231  !
232  WRITE(yfmt,'(A5,I1,A6)') '(A4,A',isurftype_len,','//ynlayer//')'
233  WRITE(yrecfm,yfmt) 'SG1_',hsurftype,jlayer
234  yrecfm=adjustl(hprefix//yrecfm)
235  WRITE(yfmt,'(A6,I1,A9)') '(A11,A',isurftype_len,','//ynlayer//',A8))'
236  WRITE(ycomment,yfmt) 'X_Y_SGRAN1_',hsurftype,jlayer,' (-)'
237  CALL write_surf(dgu, u, &
238  hprogram,yrecfm,tpsnow%GRAN1(:,jlayer,:),iresp,hcomment=ycomment)
239  !
240  !* 12. Snow Gran2
241  ! ------------
242  !
243  WRITE(yfmt,'(A5,I1,A6)') '(A4,A',isurftype_len,','//ynlayer//')'
244  WRITE(yrecfm,yfmt) 'SG2_',hsurftype,jlayer
245  yrecfm=adjustl(hprefix//yrecfm)
246  WRITE(yfmt,'(A6,I1,A9)') '(A11,A',isurftype_len,','//ynlayer//',A8))'
247  WRITE(ycomment,yfmt) 'X_Y_SGRAN2_',hsurftype,jlayer,' (-)'
248  CALL write_surf(dgu, u, &
249  hprogram,yrecfm,tpsnow%GRAN2(:,jlayer,:),iresp,hcomment=ycomment)
250  !
251  !* 13. Historical parameter
252  ! -------------------
253  !
254  WRITE(yfmt,'(A5,I1,A6)') '(A4,A',isurftype_len,','//ynlayer//')'
255  WRITE(yrecfm,yfmt) 'SHI_',hsurftype,jlayer
256  yrecfm=adjustl(hprefix//yrecfm)
257  WRITE(yfmt,'(A6,I1,A9)') '(A10,A',isurftype_len,','//ynlayer//',A8))'
258  WRITE(ycomment,yfmt) 'X_Y_SHIST_',hsurftype,jlayer,' (-)'
259  CALL write_surf(dgu, u, &
260  hprogram,yrecfm,tpsnow%HIST(:,jlayer,:),iresp,hcomment=ycomment)
261  !
262  END IF
263  !
264 END DO
265 !
266 !
267 !* 14. Albedo
268 ! ------
269 !
270 IF (tpsnow%SCHEME=='D95' .OR. tpsnow%SCHEME=='EBA' .OR. tpsnow%SCHEME=='1-L' .OR. &
271  tpsnow%SCHEME=='3-L' .OR. tpsnow%SCHEME=='CRO') THEN
272  !
273  WRITE(yfmt,'(A5,I1,A1)') '(A4,A',isurftype_len,')'
274  WRITE(yrecfm,yfmt) 'ASN_',hsurftype
275  yrecfm=adjustl(hprefix//yrecfm)
276  WRITE(yfmt,'(A6,I1,A5)') '(A10,A',isurftype_len,',A10)'
277  WRITE(ycomment,yfmt) 'X_Y_ASNOW_',hsurftype,' (no unit)'
278  CALL write_surf(dgu, u, &
279  hprogram,yrecfm,tpsnow%ALB(:,:),iresp,hcomment=ycomment)
280  !
281 END IF
282 !
283 IF (lhook) CALL dr_hook('WRITESURF_GR_SNOW',1,zhook_handle)
284 !
285 END SUBROUTINE writesurf_gr_snow
subroutine writesurf_gr_snow(DGU, U, HPROGRAM, HSURFTYPE, HPREFIX, TPSNOW)
subroutine detect_field(HPROGRAM, PFIELD, OITSHERE)
Definition: detect_field.F90:6