SURFEX v8.1
General documentation of Surfex
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 (OSNOWDIMNC, HSELECT, HPROGRAM, HSURFTYPE, &
7  HPREFIX, KI, KMASK_P, KPATCH, TPSNOW, &
8  PWSN_WR, PRHO_WR, PHEA_WR, PAGE_WR, PSG1_WR, &
9  PSG2_WR, PHIS_WR, PALB_WR)
10 ! ##########################################################
11 !
12 !!**** *WRITESURF_GR_SNOW* - routine to write snow surface fields
13 !!
14 !! PURPOSE
15 !! -------
16 ! Writes snow surface fields
17 !
18 !!** METHOD
19 !! ------
20 !!
21 !!
22 !!
23 !! EXTERNAL
24 !! --------
25 !!
26 !!
27 !! IMPLICIT ARGUMENTS
28 !! ------------------
29 !!
30 !! REFERENCE
31 !! ---------
32 !!
33 !!
34 !!
35 !! AUTHOR
36 !! ------
37 !! V. Masson * Meteo France *
38 !!
39 !! MODIFICATIONS
40 !! -------------
41 !! Original 02/2003
42 !! A. Bogatchev 09/2005 EBA snow option
43 !-----------------------------------------------------------------------------
44 !
45 !* 0. DECLARATIONS
46 !
47 USE modd_surf_par, ONLY : xundef
50 !
52 !
53 USE modi_write_field_2d_patch
54 USE modi_write_field_1d_patch
55 USE modi_detect_field
57 !
58 USE yomhook ,ONLY : lhook, dr_hook
59 USE parkind1 ,ONLY : jprb
60 !
61 IMPLICIT NONE
62 !
63 !* 0.1 declarations of arguments
64 !
65 LOGICAL, INTENT(IN) :: OSNOWDIMNC
66 !
67  CHARACTER(LEN=*), DIMENSION(:), INTENT(IN) :: HSELECT
68 !
69  CHARACTER (LEN=6), INTENT(IN) :: HPROGRAM ! program
70  CHARACTER (LEN=*), INTENT(IN) :: HSURFTYPE ! generic name used for
71  ! snow characteristics
72  ! storage in file
73  CHARACTER (LEN=3), INTENT(IN) :: HPREFIX ! generic name of prefix for
74  ! patch identification
75 INTEGER, INTENT(IN) :: KI ! horizontal size of snow var.
76 INTEGER, DIMENSION(:), INTENT(IN) :: KMASK_P
77 INTEGER, INTENT(IN) :: KPATCH ! number of tiles
78 TYPE(surf_snow), INTENT(IN) :: TPSNOW ! snow characteristics
79 REAL, DIMENSION(:,:,:), INTENT(INOUT) :: PWSN_WR
80 REAL, DIMENSION(:,:,:), INTENT(INOUT) :: PRHO_WR
81 REAL, DIMENSION(:,:,:), INTENT(INOUT) :: PHEA_WR
82 REAL, DIMENSION(:,:,:), INTENT(INOUT) :: PAGE_WR
83 REAL, DIMENSION(:,:,:), INTENT(INOUT) :: PSG1_WR
84 REAL, DIMENSION(:,:,:), INTENT(INOUT) :: PSG2_WR
85 REAL, DIMENSION(:,:,:), INTENT(INOUT) :: PHIS_WR
86 REAL, DIMENSION(:,:), INTENT(INOUT) :: PALB_WR
87 !
88 !* 0.2 declarations of local variables
89 !
90  CHARACTER (LEN=100) :: YFMT ! format for writing
91  CHARACTER(LEN=12) :: YRECFM ! Name of the article to be read
92  CHARACTER(LEN=100) :: YCOMMENT ! Comment string
93  CHARACTER(LEN=4) :: YNLAYER ! String depending on the number of layer : less
94  !than 10 or more
95  CHARACTER(LEN=3) :: YPAT
96 !
97 INTEGER :: ISURFTYPE_LEN, IPAT_LEN, IFACT
98 INTEGER :: IRESP ! IRESP : return-code if a problem appears
99 INTEGER :: JL, JP ! loop counter
100 !
101 LOGICAL :: GSNOW ! T --> snow exists somewhere
102 !
103 REAL(KIND=JPRB) :: ZHOOK_HANDLE
104 !-------------------------------------------------------------------------------
105 IF (lhook) CALL dr_hook('WRITESURF_GR_SNOW',0,zhook_handle)
106 !
107 !* 1. Initialisation
108 ! --------------
109 !
110 isurftype_len = len_trim(hsurftype)
111 !
112 jp = max(1,kpatch)
113 !
114 IF (kpatch<=1) THEN
115  !
116  !* 2. Type of snow scheme
117  ! -------------------
118  !
119  WRITE(yfmt,'(A5,I1,A4)') '(A3,A',isurftype_len,',A4)'
120  WRITE(yrecfm,yfmt) 'SN_',hsurftype,'_TYP'
121  yrecfm=adjustl(hprefix//yrecfm)
122  ycomment = ' '
123  CALL write_surf(hselect,hprogram,yrecfm,tpsnow%SCHEME,iresp,hcomment=ycomment)
124  !
125  !
126  !* 3. Number of layers
127  ! ----------------
128  !
129  WRITE(yfmt,'(A5,I1,A4)') '(A3,A',isurftype_len,',A2)'
130  WRITE(yrecfm,yfmt) 'SN_',hsurftype,'_N'
131  yrecfm=adjustl(hprefix//yrecfm)
132  ycomment = '(INTEGER)'
133  CALL write_surf(hselect,hprogram,yrecfm,tpsnow%NLAYER,iresp,hcomment=ycomment)
134  !
135  !
136  !* 4. Tests to find if there is snow
137  ! ------------------------------
138  !
139 ENDIF
140 !
141 IF (kpatch>0.AND.lsplit_patch) THEN
142  WRITE(ypat,'(I2)') kpatch
143  ypat = "P"//adjustl(ypat)
144  ipat_len = len_trim(adjustl(ypat))
145 ELSE
146  ypat = " "
147  ipat_len=1
148 ENDIF
149 !
150 
151 IF (tpsnow%NLAYER>0) THEN
152  CALL detect_field(hprogram,tpsnow%WSNOW(:,1:1),gsnow)
153 ELSE
154  gsnow = .false.
155 END IF
156 !
157 WRITE(yfmt,'(A5,I1,A2,I1,A1)') '(A3,A',isurftype_len,',A',ipat_len,')'
158 WRITE(yrecfm,yfmt) 'SN_',adjustl(hsurftype(:len_trim(hsurftype))),adjustl(ypat(:len_trim(ypat)))
159 yrecfm=adjustl(hprefix//yrecfm)
160 ycomment = '(LOGICAL)'
161  CALL write_surf(hselect,hprogram,yrecfm,gsnow,iresp,hcomment=ycomment)
162 !
163 !* 5. Additional key
164 ! ---------------
165 !
166 IF (kpatch==1) THEN
167  ycomment = '(LOGICAL)'
168  CALL write_surf(hselect,hprogram,'LSNOW_FRAC_T',lsnow_frac_tot,iresp,hcomment=ycomment)
169 ENDIF
170 !
171 IF ( osnowdimnc .AND. hprogram=='OFFLIN' ) THEN
172  !
173  IF (tpsnow%SCHEME=='1-L' .OR. tpsnow%SCHEME=='D95' .OR. tpsnow%SCHEME=='EBA' .OR. &
174  tpsnow%SCHEME=='3-L' .OR. tpsnow%SCHEME=='CRO') THEN
175  !
176  WRITE(yfmt,'(A5,I1,A1)') '(A4,A',isurftype_len,')'
177  WRITE(yrecfm,yfmt) 'WSN_',hsurftype
178  yrecfm=adjustl(hprefix//yrecfm)
179  WRITE(yfmt,'(A5,I1,A4)') '(A9,A',isurftype_len,',A8)'
180  WRITE(ycomment,yfmt) 'X_Y_WSNOW',hsurftype,' (kg/m2)'
181  CALL write_field_2d_patch(hselect,hprogram,yrecfm,ycomment,kpatch,kmask_p,tpsnow%WSNOW(:,:),&
182  ki,'snow_layer',pwsn_wr)
183  !
184  WRITE(yfmt,'(A5,I1,A1)') '(A4,A',isurftype_len,')'
185  WRITE(yrecfm,yfmt) 'RSN_',hsurftype
186  yrecfm=adjustl(hprefix//yrecfm)
187  WRITE(yfmt,'(A5,I1,A4)') '(A9,A',isurftype_len,',A8)'
188  WRITE(ycomment,yfmt) 'X_Y_RSNOW',hsurftype,' (kg/m2)'
189  CALL write_field_2d_patch(hselect,hprogram,yrecfm,ycomment,kpatch,kmask_p,tpsnow%RHO(:,:),&
190  ki,'snow_layer',prho_wr)
191  !
192  ENDIF
193  !
194  IF (tpsnow%SCHEME=='3-L' .OR. tpsnow%SCHEME=='CRO') THEN
195  !
196  WRITE(yfmt,'(A5,I1,A1)') '(A4,A',isurftype_len,')'
197  WRITE(yrecfm,yfmt) 'HSN_',hsurftype
198  yrecfm=adjustl(hprefix//yrecfm)
199  WRITE(yfmt,'(A5,I1,A4)') '(A9,A',isurftype_len,',A8)'
200  WRITE(ycomment,yfmt) 'X_Y_HSNOW',hsurftype,' (kg/m2)'
201  CALL write_field_2d_patch(hselect,hprogram,yrecfm,ycomment,kpatch,kmask_p,tpsnow%HEAT(:,:),&
202  ki,'snow_layer',phea_wr)
203  !
204  WRITE(yfmt,'(A5,I1,A1)') '(A4,A',isurftype_len,')'
205  WRITE(yrecfm,yfmt) 'ASN_',hsurftype
206  yrecfm=adjustl(hprefix//yrecfm)
207  WRITE(yfmt,'(A5,I1,A4)') '(A8,A',isurftype_len,',A8)'
208  WRITE(ycomment,yfmt) 'X_Y_SAGE',hsurftype,' (kg/m2)'
209  CALL write_field_2d_patch(hselect,hprogram,yrecfm,ycomment,kpatch,kmask_p,tpsnow%AGE(:,:),&
210  ki,'snow_layer',page_wr)
211  !
212  ENDIF
213  !
214  IF (tpsnow%SCHEME=='CRO') THEN
215  !
216  WRITE(yfmt,'(A5,I1,A1)') '(A4,A',isurftype_len,')'
217  WRITE(yrecfm,yfmt) 'SG1_',hsurftype
218  yrecfm=adjustl(hprefix//yrecfm)
219  WRITE(yfmt,'(A5,I1,A4)') '(A7,A',isurftype_len,',A8)'
220  WRITE(ycomment,yfmt) 'X_Y_SG1',hsurftype,' (kg/m2)'
221  CALL write_field_2d_patch(hselect,hprogram,yrecfm,ycomment,kpatch,kmask_p,tpsnow%GRAN1(:,:),&
222  ki,'snow_layer',psg1_wr)
223  !
224  WRITE(yfmt,'(A5,I1,A1)') '(A4,A',isurftype_len,')'
225  WRITE(yrecfm,yfmt) 'SG2_',hsurftype
226  yrecfm=adjustl(hprefix//yrecfm)
227  WRITE(yfmt,'(A5,I1,A4)') '(A7,A',isurftype_len,',A8)'
228  WRITE(ycomment,yfmt) 'X_Y_SG2',hsurftype,' (kg/m2)'
229  CALL write_field_2d_patch(hselect,hprogram,yrecfm,ycomment,kpatch,kmask_p,tpsnow%GRAN2(:,:),&
230  ki,'snow_layer',psg2_wr)
231  !
232  WRITE(yfmt,'(A5,I1,A1)') '(A4,A',isurftype_len,')'
233  WRITE(yrecfm,yfmt) 'SHI_',hsurftype
234  yrecfm=adjustl(hprefix//yrecfm)
235  WRITE(yfmt,'(A5,I1,A4)') '(A8,A',isurftype_len,',A8)'
236  WRITE(ycomment,yfmt) 'X_Y_HIST',hsurftype,' (kg/m2)'
237  CALL write_field_2d_patch(hselect,hprogram,yrecfm,ycomment,kpatch,kmask_p,tpsnow%HIST(:,:),&
238  ki,'snow_layer',phis_wr)
239  !
240  ENDIF
241  !
242  IF (tpsnow%SCHEME=='1-L') THEN
243  !
244  WRITE(yfmt,'(A5,I1,A1)') '(A4,A',isurftype_len,')'
245  WRITE(yrecfm,yfmt) 'TSN_',hsurftype
246  yrecfm=adjustl(hprefix//yrecfm)
247  WRITE(yfmt,'(A6,I1,A4)') '(A10,A',isurftype_len,',A8)'
248  WRITE(ycomment,yfmt) 'X_Y_TSNOW',hsurftype,' (K)'
249  CALL write_field_2d_patch(hselect,hprogram,yrecfm,ycomment,kpatch,kmask_p,tpsnow%T(:,:),ki,'snow_layer')
250  !
251  END IF
252  !
253 ELSE
254  !
255  DO jl = 1,tpsnow%NLAYER
256  !
257  ynlayer='I1.1'
258  IF (jl>9) ynlayer='I2.2'
259  !
260  IF (tpsnow%SCHEME=='1-L' .OR. tpsnow%SCHEME=='D95' .OR. tpsnow%SCHEME=='EBA' .OR. &
261  tpsnow%SCHEME=='3-L' .OR. tpsnow%SCHEME=='CRO') THEN
262  !
263  !* 6. Snow reservoir
264  ! --------------
265  !
266  WRITE(yfmt,'(A5,I1,A6)') '(A4,A',isurftype_len,','//ynlayer//')'
267  WRITE(yrecfm,yfmt) 'WSN_',hsurftype,jl
268  yrecfm=adjustl(hprefix//yrecfm)
269  WRITE(yfmt,'(A6,I1,A9)') '(A10,A',isurftype_len,','//ynlayer//',A8))'
270  WRITE(ycomment,yfmt) 'X_Y_WSNOW_',hsurftype,jl,' (kg/m2)'
271  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,kpatch,kmask_p,tpsnow%WSNOW(:,jl),&
272  ki,pwsn_wr(:,jl,:))
273  !
274  !* 7. Snow density
275  ! ------------
276  !
277  WRITE(yfmt,'(A5,I1,A6)') '(A4,A',isurftype_len,','//ynlayer//')'
278  WRITE(yrecfm,yfmt) 'RSN_',hsurftype,jl
279  yrecfm=adjustl(hprefix//yrecfm)
280  WRITE(yfmt,'(A6,I1,A9)') '(A10,A',isurftype_len,','//ynlayer//',A8))'
281  WRITE(ycomment,yfmt) 'X_Y_RSNOW_',hsurftype,jl,' (kg/m3)'
282  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,kpatch,kmask_p,tpsnow%RHO(:,jl),&
283  ki,prho_wr(:,jl,:))
284  !
285  END IF
286  !
287  IF (tpsnow%SCHEME=='3-L' .OR. tpsnow%SCHEME=='CRO') THEN
288  !
289  !* 9. Heat content
290  ! ------------
291  !
292  WRITE(yfmt,'(A5,I1,A6)') '(A4,A',isurftype_len,','//ynlayer//')'
293  WRITE(yrecfm,yfmt) 'HSN_',hsurftype,jl
294  yrecfm=adjustl(hprefix//yrecfm)
295  WRITE(yfmt,'(A6,I1,A9)') '(A10,A',isurftype_len,','//ynlayer//',A8))'
296  WRITE(ycomment,yfmt) 'X_Y_HSNOW_',hsurftype,jl,' (J/m3)'
297  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,kpatch,kmask_p,tpsnow%HEAT(:,jl),&
298  ki,phea_wr(:,jl,:))
299  !
300  !* 10. Age parameter
301  ! ---------------
302  !
303  WRITE(yfmt,'(A5,I1,A6)') '(A4,A',isurftype_len,','//ynlayer//')'
304  WRITE(yrecfm,yfmt) 'SAG_',hsurftype,jl
305  yrecfm=adjustl(hprefix//yrecfm)
306  WRITE(yfmt,'(A6,I1,A9)') '(A9,A',isurftype_len,','//ynlayer//',A8))'
307  WRITE(ycomment,yfmt) 'X_Y_SAGE_',hsurftype,jl,' (-)'
308  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,kpatch,kmask_p,tpsnow%AGE(:,jl),&
309  ki,page_wr(:,jl,:))
310  !
311  END IF
312  !
313  IF (tpsnow%SCHEME=='CRO') THEN
314  !
315  !* 11. Snow Gran1
316  ! ----------
317  !
318  WRITE(yfmt,'(A5,I1,A6)') '(A4,A',isurftype_len,','//ynlayer//')'
319  WRITE(yrecfm,yfmt) 'SG1_',hsurftype,jl
320  yrecfm=adjustl(hprefix//yrecfm)
321  WRITE(yfmt,'(A6,I1,A9)') '(A11,A',isurftype_len,','//ynlayer//',A8))'
322  WRITE(ycomment,yfmt) 'X_Y_SGRAN1_',hsurftype,jl,' (-)'
323  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,kpatch,kmask_p,tpsnow%GRAN1(:,jl),&
324  ki,psg1_wr(:,jl,:))
325  !
326  !* 11. Snow Gran2
327  ! ----------
328  !
329  WRITE(yfmt,'(A5,I1,A6)') '(A4,A',isurftype_len,','//ynlayer//')'
330  WRITE(yrecfm,yfmt) 'SG2_',hsurftype,jl
331  yrecfm=adjustl(hprefix//yrecfm)
332  WRITE(yfmt,'(A6,I1,A9)') '(A11,A',isurftype_len,','//ynlayer//',A8))'
333  WRITE(ycomment,yfmt) 'X_Y_SGRAN2_',hsurftype,jl,' (-)'
334  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,kpatch,kmask_p,tpsnow%GRAN2(:,jl),&
335  ki,psg2_wr(:,jl,:))
336  !
337  !* 13. Historical parameter
338  ! -------------------
339  !
340  WRITE(yfmt,'(A5,I1,A6)') '(A4,A',isurftype_len,','//ynlayer//')'
341  WRITE(yrecfm,yfmt) 'SHI_',hsurftype,jl
342  yrecfm=adjustl(hprefix//yrecfm)
343  WRITE(yfmt,'(A6,I1,A9)') '(A10,A',isurftype_len,','//ynlayer//',A8))'
344  WRITE(ycomment,yfmt) 'X_Y_SHIST_',hsurftype,jl,' (-)'
345  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,kpatch,kmask_p,tpsnow%HIST(:,jl),&
346  ki,phis_wr(:,jl,:))
347  !
348  ENDIF
349  !
350  !* 8. Snow temperature
351  ! ----------------
352  !
353  IF (tpsnow%SCHEME=='1-L') THEN
354  !
355  WRITE(yfmt,'(A5,I1,A6)') '(A4,A',isurftype_len,','//ynlayer//')'
356  WRITE(yrecfm,yfmt) 'TSN_',hsurftype,jl
357  yrecfm=adjustl(hprefix//yrecfm)
358  WRITE(yfmt,'(A6,I1,A9)') '(A10,A',isurftype_len,','//ynlayer//',A8))'
359  WRITE(ycomment,yfmt) 'X_Y_TSNOW_',hsurftype,jl,' (K)'
360  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,kpatch,kmask_p,tpsnow%T(:,jl),ki)
361  !
362  END IF
363  !
364  ENDDO
365  !
366 ENDIF
367 !
368 !
369 !* 14. Albedo
370 ! ------
371 !
372 IF (tpsnow%SCHEME=='D95' .OR. tpsnow%SCHEME=='EBA' .OR. tpsnow%SCHEME=='1-L' .OR. &
373  tpsnow%SCHEME=='3-L' .OR. tpsnow%SCHEME=='CRO') THEN
374  !
375  WRITE(yfmt,'(A5,I1,A1)') '(A4,A',isurftype_len,')'
376  WRITE(yrecfm,yfmt) 'ASN_',hsurftype
377  yrecfm=adjustl(hprefix//yrecfm)
378  WRITE(yfmt,'(A6,I1,A5)') '(A10,A',isurftype_len,',A10)'
379  WRITE(ycomment,yfmt) 'X_Y_ASNOW_',hsurftype,' (no unit)'
380  CALL write_field_1d_patch(hselect,hprogram,yrecfm,ycomment,kpatch,kmask_p,tpsnow%ALB(:),&
381  ki,palb_wr)
382  !
383 END IF
384 !
385 IF (lhook) CALL dr_hook('WRITESURF_GR_SNOW',1,zhook_handle)
386 !
387 END SUBROUTINE writesurf_gr_snow
subroutine write_field_1d_patch(HSELECT, HPROGRAM, HRECFM, HCOMMENT, KP, KMASK, PFIELD_IN, KSIZE, PWORK_WR)
real, parameter xundef
integer, parameter jprb
Definition: parkind1.F90:32
subroutine write_field_2d_patch(HSELECT, HPROGRAM, HRECFM, HCOMMENT, KP, KMASK, PFIELD_IN, KSIZE, HNAM_DIM, PWORK_WR)
logical lhook
Definition: yomhook.F90:15
logical lsnow_frac_tot
subroutine writesurf_gr_snow(OSNOWDIMNC, HSELECT, HPROGRAM, HSURF
subroutine detect_field(HPROGRAM, PFIELD, OITSHERE)
Definition: detect_field.F90:7