SURFEX  V8_0
Surfex V8_0 release
 All Classes Files Functions Variables
read_prep_garden_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 read_prep_garden_snow(HPROGRAM,HSNOW,KSNOW_LAYER,HFILE,HFILETYPE,HFILEPGD,HFILEPGDTYPE,OUNIF)
7 ! #######################################################
8 !
9 !!**** *READ_PREP_GARDEN_SNOW* - routine to read the configuration for snow
10 !! in ISBA fields preparation
11 !!
12 !! PURPOSE
13 !! -------
14 !!
15 !!** METHOD
16 !! ------
17 !!
18 !! EXTERNAL
19 !! --------
20 !!
21 !!
22 !! IMPLICIT ARGUMENTS
23 !! ------------------
24 !!
25 !! REFERENCE
26 !! ---------
27 !!
28 !!
29 !! AUTHOR
30 !! ------
31 !! V. Masson *Meteo France*
32 !!
33 !! MODIFICATIONS
34 !! -------------
35 !! Original 01/2004
36 !! A. Bogatchev 09/2005 EBA snow option
37 !! V. Vionnet 06/2008 - Flag for snow metamorphism
38 ! - Preparation of uniform snow fields : density, temperture,albedo,grain types
39 !! - Flag to avtivate new maximal liquid water holding capacity : formulation used by Crocus
40 !! M. Lafaysse 08/2013 init XZSNOW or XLWCSNOW
41 ! B. Decharme 07/2013 Add ES snow grid case : 6-L or 12-L
42 !-------------------------------------------------------------------------------
43 !
44 !* 0. DECLARATIONS
45 ! ------------
46 !
48 USE modd_read_namelist, ONLY : lnam_read
49 !
50 USE modd_surf_par, ONLY : xundef
51 USE modd_snow_par, ONLY : xansmin, xrhosmax
52 USE modd_csts, ONLY : xtt
53 !
54 USE mode_pos_surf
56 USE modi_get_luout
57 USE modi_open_namelist
58 USE modi_close_namelist
59 USE modi_abor1_sfx
60 !
61 USE modd_prep_teb_garden, ONLY : cfile_snow_gd, ctype_snow, cfilepgd_snow_gd, &
62  ctypepgd_snow, lsnow_ideal_gd, &
63  xwsnow_p=>xwsnow_gd, xtsnow_p=>xtsnow_gd, xlwcsnow_p=>xlwcsnow_gd, &
64  xrsnow_p=>xrsnow_gd, xagesnow_p=>xagesnow_gd, xasnow_gd
65 !
66 USE modd_prep_snow, ONLY : nsnow_layer_max, lsnow_prep_perm
67 !
68 USE yomhook ,ONLY : lhook, dr_hook
69 USE parkind1 ,ONLY : jprb
70 !
71 IMPLICIT NONE
72 !
73 !* 0.1 Declarations of arguments
74 ! -------------------------
75 !
76  CHARACTER(LEN=6), INTENT(IN) :: hprogram ! program calling ISBA
77  CHARACTER(LEN=3), INTENT(OUT) :: hsnow ! snow scheme
78 INTEGER, INTENT(OUT) :: ksnow_layer ! number of snow layers
79  CHARACTER(LEN=28), OPTIONAL, INTENT(OUT) :: hfile ! file name
80  CHARACTER(LEN=6), OPTIONAL, INTENT(OUT) :: hfiletype ! file type
81  CHARACTER(LEN=28),OPTIONAL, INTENT(OUT) :: hfilepgd ! file name
82  CHARACTER(LEN=6), OPTIONAL, INTENT(OUT) :: hfilepgdtype ! file type
83  LOGICAL, OPTIONAL, INTENT(OUT) :: ounif ! uniform snow
84 !
85 !* 0.2 Declarations of local variables
86 ! -------------------------------
87 !
88  CHARACTER(LEN=3) :: csnow
89 INTEGER :: nsnow_layer
90  CHARACTER(LEN=28) :: cfile_snow, cfilepgd_snow
91 LOGICAL :: lsnow_ideal, lsnow_frac_tot, lswemax
92 REAL :: xasnow, xswemax
93 REAL, DIMENSION(NSNOW_LAYER_MAX) :: xwsnow, xzsnow, xrsnow, xtsnow, xlwcsnow, xsg1snow, xsg2snow,&
94  xhistsnow, xagesnow
95 INTEGER :: jlayer
96 !
97 REAL, DIMENSION(NSNOW_LAYER_MAX) :: xwsnow_gd, xzsnow_gd, xrsnow_gd, xtsnow_gd, xlwcsnow_gd, &
98  xsg1snow_gd, xsg2snow_gd, xhistsnow_gd, xagesnow_gd
99 !
100 LOGICAL :: lfile
101 !
102 LOGICAL :: gfound ! Return code when searching namelist
103 INTEGER :: iluout ! output file logical unit
104 INTEGER :: ilunam ! namelist file logical unit
105 REAL(KIND=JPRB) :: zhook_handle
106 !-------------------------------------------------------------------------------
107 namelist/nam_prep_isba_snow/csnow, nsnow_layer, cfile_snow, ctype_snow, &
108  cfilepgd_snow, ctypepgd_snow, &
109  lsnow_ideal, lsnow_frac_tot, lsnow_prep_perm, &
110  xwsnow, xzsnow, xtsnow, xlwcsnow, xrsnow, xasnow, &
111  xsg1snow, xsg2snow, xhistsnow, xagesnow, &
112  lswemax,xswemax
113 namelist/nam_prep_garden_snow/csnow_gd, nsnow_layer_gd, cfile_snow_gd, ctype_snow, &
114  cfilepgd_snow_gd, ctypepgd_snow, &
115  lsnow_ideal_gd, xwsnow_gd, xzsnow_gd, xtsnow_gd, xlwcsnow_gd, xrsnow_gd, xasnow_gd
116 !-------------------------------------------------------------------------------
117 !* default
118 ! -------
119 !
120 
121 IF (lhook) CALL dr_hook('READ_PREP_GARDEN_SNOW',0,zhook_handle)
122 IF (lnam_read) THEN
123  !
124  csnow_gd = 'D95'
125  nsnow_layer_gd = 1
126  !
127  cfile_snow_gd = ' '
128  ctype_snow = ' '
129  cfilepgd_snow_gd = ' '
130  ctypepgd_snow = ' '
131  !
132  lsnow_ideal_gd = .false.
133  lsnow_prep_perm = .true.
134  !
135  xwsnow_gd(:) = 0.
136  xzsnow_gd(:) = xundef
137  xrsnow_gd(:) = xrhosmax
138  xtsnow_gd(:) = xtt
139  xlwcsnow_gd(:) = 0.
140  xasnow_gd = xansmin
141  xsg1snow_gd(:) = xundef
142  xsg2snow(:) = xundef
143  xhistsnow_gd(:) = xundef
144  xagesnow_gd(:) = xundef
145  !
146  lswemax=.false.
147  xswemax=500.
148  !
149  CALL get_luout(hprogram,iluout)
150  CALL open_namelist(hprogram,ilunam)
151  !
152  !* reading of namelist
153  ! -------------------
154  !
155  !* default can be provided by ISBA scheme variables
156  CALL posnam(ilunam,'NAM_PREP_ISBA_SNOW',gfound,iluout)
157  IF (gfound) THEN
158  !
159  csnow = 'D95'
160  nsnow_layer = 1
161  cfile_snow = ' '
162  cfilepgd_snow = ' '
163  lsnow_ideal = .false.
164  lsnow_frac_tot = .false.
165  xwsnow(:) = xundef
166  xzsnow(:) = xundef
167  xrsnow(:) = xrhosmax
168  xtsnow(:) = xtt
169  xasnow = xansmin
170  xsg1snow(:) = xundef
171  xsg2snow(:) = xundef
172  xhistsnow(:) = xundef
173  xagesnow(:) = xundef
174  xlwcsnow(:) = 0.
175  !
176  READ(unit=ilunam,nml=nam_prep_isba_snow)
177  CALL test_nam_var_surf(iluout,'CSNOW',csnow,'D95','3-L','EBA','NON','CRO')
178  !
179  csnow_gd = csnow
180  nsnow_layer_gd = nsnow_layer
181  cfile_snow_gd = cfile_snow
182  cfilepgd_snow_gd = cfilepgd_snow
183  lsnow_ideal_gd = lsnow_ideal
184  xwsnow_gd(:) = xwsnow(:)
185  xzsnow_gd(:) = xzsnow(:)
186  xrsnow_gd(:) = xrsnow(:)
187  xtsnow_gd(:) = xtsnow(:)
188  xlwcsnow_gd(:) = xlwcsnow(:)
189  xasnow_gd = xasnow
190  xsg1snow_gd(:) = xsg1snow(:)
191  xsg2snow_gd(:) = xsg2snow(:)
192  xhistsnow_gd(:) = xhistsnow(:)
193  xagesnow_gd(:) = xagesnow(:)
194  !
195  ENDIF
196  !
197  !* It is erased by GARDEN namelist if specified
198  CALL posnam(ilunam,'NAM_PREP_GARDEN_SNOW',gfound,iluout)
199  IF (gfound) THEN
200  READ(unit=ilunam,nml=nam_prep_garden_snow)
201  !crocus can't be used in garden if not used in isba scheme
202  CALL test_nam_var_surf(iluout,'CSNOW',csnow_gd,'D95','3-L','EBA','NON')
203  ENDIF
204  !
205  IF (csnow_gd=='NON') nsnow_layer_gd = 0
206  !
207  IF (csnow_gd=='D95' .OR. csnow_gd=='EBA') nsnow_layer_gd = 1
208  ! not more than 3 layers for snow in garden
209  IF (csnow_gd=='3-L' .AND. nsnow_layer_gd<=2) nsnow_layer_gd = 12
210  !
211  IF (nsnow_layer_gd > nsnow_layer_max) THEN
212  WRITE(iluout,*) '------------------------------------'
213  WRITE(iluout,*) 'Please update modd_prep_snow.f90 routine : '
214  WRITE(iluout,*) 'The maximum number of snow layers '
215  WRITE(iluout,*) 'in the declaration of the namelist variables '
216  WRITE(iluout,*) 'must be decreased to : ', nsnow_layer_max
217  WRITE(iluout,*) '------------------------------------'
218  CALL abor1_sfx('READ_PREP_GARDEN_SNOW: NUMBER OF SNOW LAYERS MUST BE INCREASED IN NAMELIST DECLARATION')
219  ENDIF
220  !
221  ALLOCATE(xwsnow_p(nsnow_layer_gd))
222  ALLOCATE(xrsnow_p(nsnow_layer_gd))
223  ALLOCATE(xtsnow_p(nsnow_layer_gd))
224  ALLOCATE(xagesnow_p(nsnow_layer_gd))
225  ALLOCATE(xlwcsnow_p(nsnow_layer_gd))
226  !
227  DO jlayer=1,nsnow_layer_gd
228 
229  IF ((xzsnow_gd(jlayer)>0) .AND.(xzsnow_gd(jlayer)/=xundef )) THEN
230  IF ((xwsnow_gd(jlayer)>0) .AND.(xwsnow_gd(jlayer)/=xundef )) THEN
231  WRITE(iluout,*) 'XWSNOW and XZSNOW are both defined.'
232  WRITE(iluout,*) 'You must define only one of them.'
233  WRITE(iluout,*) ' PLEASE CORRECT THAT '
234  CALL abor1_sfx('READ_PREP_GARDEN_SNOW: ERROR IN INITIALIZATION OF SNOW DEPTH')
235  ELSE
236  xwsnow_p(jlayer)=xzsnow_gd(jlayer)*xrsnow_gd(jlayer)
237  ENDIF
238  ELSE
239  xwsnow_p(jlayer)=xwsnow_gd(jlayer)
240  ENDIF
241  ENDDO
242 
243  xrsnow_p=xrsnow_gd(1:nsnow_layer_gd)
244  xtsnow_p=xtsnow_gd(1:nsnow_layer_gd)
245  xagesnow_p=xagesnow_gd(1:nsnow_layer_gd)
246  xlwcsnow_p=xlwcsnow_gd(1:nsnow_layer_gd)
247  !
248  CALL close_namelist(hprogram,ilunam)
249  !
250 ENDIF
251 !
252 hsnow = csnow_gd
253 !
254 ksnow_layer = nsnow_layer_gd
255 !
256 IF(all(xwsnow_p(:)==xundef).AND.present(ounif))THEN
257  ounif=.false.
258 ELSEIF(present(ounif))THEN
259  ounif=.true.
260 ENDIF
261 !
262 lfile=(len_trim(cfile_snow_gd)>0.AND.len_trim(ctype_snow)>0 &
263  .AND.len_trim(cfilepgd_snow_gd)>0.AND.len_trim(ctypepgd_snow)>0)
264 !
265 IF (present(ounif)) lfile=(lfile .AND. .NOT.ounif)
266 !
267 IF(present(hfile))THEN
268  IF(lfile)THEN
269  hfile = cfile_snow_gd
270  ELSE
271  hfile = ' '
272  ENDIF
273 ENDIF
274 IF(present(hfiletype))THEN
275  IF(lfile)THEN
276  hfiletype = ctype_snow
277  ELSE
278  hfiletype = ' '
279  ENDIF
280 ENDIF
281 IF(present(hfilepgdtype))THEN
282  IF(lfile)THEN
283  hfilepgdtype = ctypepgd_snow
284  ELSE
285  hfilepgdtype = ' '
286  ENDIF
287 ENDIF
288 IF(present(hfilepgd))THEN
289  IF(lfile)THEN
290  hfilepgd = cfilepgd_snow_gd
291  ELSE
292  hfilepgd = ' '
293  ENDIF
294 ENDIF
295 IF (lfile.AND.present(ounif)) ounif=.false.
296 !
297 IF (lhook) CALL dr_hook('READ_PREP_GARDEN_SNOW',1,zhook_handle)
298 !
299 !-------------------------------------------------------------------------------
300 !-------------------------------------------------------------------------------
301 !
302 END SUBROUTINE read_prep_garden_snow
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:6
subroutine read_prep_garden_snow(HPROGRAM, HSNOW, KSNOW_LAYER, HFILE, HFILETYPE, HFILEPGD, HFILEPGDTYPE, OUNIF)
subroutine close_namelist(HPROGRAM, KLUNAM)
subroutine posnam(KULNAM, HDNAML, OFOUND, KLUOUT)
subroutine get_luout(HPROGRAM, KLUOUT)
Definition: get_luout.F90:6
subroutine open_namelist(HPROGRAM, KLUNAM, HFILE)