SURFEX  V8_0
Surfex V8_0 release
 All Classes Files Functions Variables
read_prep_isba_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_isba_snow(HPROGRAM,HSNOW,KSNOW_LAYER,HFILE,HFILETYPE,HFILEPGD,HFILEPGDTYPE,OUNIF)
7 ! #######################################################
8 !
9 !!**** *READ_PREP_ISBA_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 !! B. Decharme 07/2012 Bug init uniform snow
41 !! M. Lafaysse 11/2012, snow liquid water content
42 !! M. Lafaysse 11/2012, possibility to prescribe snow depth instead of snow water equivalent
43 !! M Lafaysse 04/2014 : LSNOW_PREP_PERM
44 ! B. Decharme 07/2013 ES snow grid layer can be > to 3 (default 12)
45 !-------------------------------------------------------------------------------
46 !
47 !* 0. DECLARATIONS
48 ! ------------
49 !
51 USE modd_read_namelist, ONLY : lnam_read
52 !
53 USE modd_surf_par, ONLY : xundef
54 USE modd_snow_par, ONLY : xansmin, xrhosmax
55 USE modd_csts, ONLY : xtt
56 !
57 USE mode_pos_surf
59 USE modi_get_luout
60 USE modi_open_namelist
61 USE modi_close_namelist
62 USE modi_abor1_sfx
63 !
64 USE modd_prep_isba, ONLY : cfile_snow, ctype_snow, cfilepgd_snow, &
65  ctypepgd_snow, lsnow_ideal, &
66  xwsnow_p=>xwsnow, xtsnow_p=>xtsnow, &
67  xlwcsnow_p=>xlwcsnow, &
68  xrsnow_p=>xrsnow, xasnow, &
69  xsg1snow_p=>xsg1snow, xsg2snow_p=>xsg2snow, &
70  xhistsnow_p=>xhistsnow, xagesnow_p=>xagesnow
71 
72 !
73 USE modd_prep_snow, ONLY : lsnow_frac_tot, nsnow_layer_max , lsnow_prep_perm
74 !
75 USE yomhook ,ONLY : lhook, dr_hook
76 USE parkind1 ,ONLY : jprb
77 !
78 IMPLICIT NONE
79 !
80 !* 0.1 Declarations of arguments
81 ! -------------------------
82 !
83  CHARACTER(LEN=6), INTENT(IN) :: hprogram ! program calling ISBA
84  CHARACTER(LEN=3), INTENT(OUT) :: hsnow ! snow scheme
85 INTEGER, INTENT(OUT) :: ksnow_layer ! number of snow layers
86  CHARACTER(LEN=28), OPTIONAL, INTENT(OUT) :: hfile ! file name
87  CHARACTER(LEN=6), OPTIONAL, INTENT(OUT) :: hfiletype ! file type
88  CHARACTER(LEN=28), OPTIONAL, INTENT(OUT) :: hfilepgd ! file name
89  CHARACTER(LEN=6), OPTIONAL, INTENT(OUT) :: hfilepgdtype ! file type
90 LOGICAL, OPTIONAL, INTENT(OUT) :: ounif ! uniform snow
91 !
92 !* 0.2 Declarations of local variables
93 ! -------------------------------
94 !
95 REAL, DIMENSION(NSNOW_LAYER_MAX) :: xwsnow, xzsnow, xrsnow, xtsnow, xlwcsnow, &
96  xsg1snow, xsg2snow, xhistsnow, xagesnow
97 INTEGER :: jlayer
98 !
99 LOGICAL :: lfile
100 !
101 LOGICAL :: gfound ! Return code when searching namelist
102 INTEGER :: iluout ! output file logical unit
103 INTEGER :: ilunam ! namelist file logical unit
104 REAL(KIND=JPRB) :: zhook_handle
105 !-------------------------------------------------------------------------------
106 namelist/nam_prep_isba_snow/csnow, nsnow_layer, cfile_snow, ctype_snow, &
107  cfilepgd_snow, ctypepgd_snow, &
108  lsnow_ideal, lsnow_frac_tot,lsnow_prep_perm, &
109  xwsnow, xzsnow, xtsnow, xlwcsnow, xrsnow, xasnow, &
110  xsg1snow, xsg2snow, xhistsnow, xagesnow, &
111  lswemax,xswemax
112 !-------------------------------------------------------------------------------
113 !* default
114 ! -------
115 !
116 IF (lhook) CALL dr_hook('READ_PREP_ISBA_SNOW',0,zhook_handle)
117 IF (lnam_read) THEN
118  !
119  csnow = 'D95'
120  nsnow_layer = 1
121  !
122  cfile_snow = ' '
123  ctype_snow = ' '
124  cfilepgd_snow = ' '
125  ctypepgd_snow = ' '
126  !
127  lsnow_ideal = .false.
128  lsnow_frac_tot = .false.
129  lsnow_prep_perm = .true.
130  !
131  xwsnow(:) = xundef
132  xzsnow(:) = xundef
133  xrsnow(:) = xundef
134  xtsnow(:) = xtt
135  xlwcsnow(:) = 0.
136  xasnow = xansmin
137  xsg1snow(:) = xundef
138  xsg2snow(:) = xundef
139  xhistsnow(:) = xundef
140  xagesnow(:) = xundef
141  !
142  lswemax=.false.
143  xswemax=500.
144  !
145  CALL get_luout(hprogram,iluout)
146  CALL open_namelist(hprogram,ilunam)
147  !
148  !* reading of namelist
149  ! -------------------
150  !
151  CALL posnam(ilunam,'NAM_PREP_ISBA_SNOW',gfound,iluout)
152  IF (gfound) READ(unit=ilunam,nml=nam_prep_isba_snow)
153  !
154  CALL test_nam_var_surf(iluout,'CSNOW',csnow,'D95','3-L','EBA','CRO','NON')
155  !
156  IF (csnow=='NON') nsnow_layer = 0
157  !
158  IF (csnow=='D95' .OR. csnow=='EBA') nsnow_layer = 1
159  !
160  IF ((csnow=='3-L' .OR. csnow=='CRO') .AND. nsnow_layer<=2) nsnow_layer = 12
161  !
162  IF (nsnow_layer > nsnow_layer_max) THEN
163  WRITE(iluout,*) '------------------------------------'
164  WRITE(iluout,*) 'Please update modd_prep_snow.f90 routine : '
165  WRITE(iluout,*) 'The maximum number of snow layers '
166  WRITE(iluout,*) 'in the declaration of the namelist variables '
167  WRITE(iluout,*) 'must be decreased to : ', nsnow_layer_max
168  WRITE(iluout,*) '------------------------------------'
169  CALL abor1_sfx('READ_PREP_ISBA_SNOW: NUMBER OF SNOW LAYERS MUST BE INCREASED IN NAMELIST DECLARATION')
170  ENDIF
171  !
172  ! Convert prescribed snow depth and snow density in snow water equivalent
173  DO jlayer=1,nsnow_layer
174  IF (xzsnow(jlayer)/=xundef) THEN
175  IF (xwsnow(jlayer)/=xundef) THEN
176  WRITE(iluout,*) '----------------------------'
177  WRITE(iluout,*) 'layer ',jlayer,':'
178  WRITE(iluout,*) 'XWSNOW and XZSNOW are both defined.'
179  WRITE(iluout,*) 'You must define only one of them.'
180  WRITE(iluout,*) ' PLEASE CORRECT THAT '
181  WRITE(iluout,*) '----------------------------'
182  CALL abor1_sfx('READ_PREP_ISBA_SNOW: ERROR IN INITIALISATION OF SNOW PARAMETERS')
183  ELSEIF (xrsnow(jlayer)==xundef) THEN
184  WRITE(iluout,*) '----------------------------'
185  WRITE(iluout,*) 'layer ',jlayer,':'
186  WRITE(iluout,*) 'XZSNOW is defined '
187  WRITE(iluout,*) 'but XRSNOW is not. '
188  WRITE(iluout,*) ' PLEASE CORRECT THAT '
189  WRITE(iluout,*) '----------------------------'
190  CALL abor1_sfx('READ_PREP_ISBA_SNOW: ERROR IN INITIALISATION OF SNOW PARAMETERS')
191  ELSE
192  xwsnow(jlayer)=xzsnow(jlayer)*xrsnow(jlayer)
193  END IF
194  ENDIF
195  END DO
196 
197  IF(nsnow_layer>=3)THEN
198  IF(xwsnow(1)/=xundef.AND.any(xwsnow(2:nsnow_layer)==xundef))THEN
199  WHERE(xwsnow(2:nsnow_layer)==xundef)xwsnow(2:nsnow_layer)=0.0
200  ENDIF
201  IF(xrsnow(1)/=xundef.AND.any(xrsnow(2:nsnow_layer)==xundef))THEN
202  WHERE(xrsnow(2:nsnow_layer)==xundef)xrsnow(2:nsnow_layer)=xrsnow(1)
203  ENDIF
204  ENDIF
205  !
206  ALLOCATE(xwsnow_p(nsnow_layer))
207  ALLOCATE(xrsnow_p(nsnow_layer))
208  ALLOCATE(xtsnow_p(nsnow_layer))
209  ALLOCATE(xlwcsnow_p(nsnow_layer))
210  ALLOCATE(xagesnow_p(nsnow_layer))
211  !
212  xwsnow_p =xwsnow(1:nsnow_layer)
213  xrsnow_p =xrsnow(1:nsnow_layer)
214  xtsnow_p =xtsnow(1:nsnow_layer)
215  xagesnow_p=xagesnow(1:nsnow_layer)
216  xlwcsnow_p=xlwcsnow(1:nsnow_layer)
217  !
218 
219  !Coherence test between XTSNOW and XLWCSNOW
220  DO jlayer=1,nsnow_layer
221  IF ((xlwcsnow_p(jlayer)>0.).AND.(xtsnow_p(jlayer)<xtt)) THEN
222  WRITE(iluout,*) '----------------------------'
223  WRITE(iluout,*) 'layer ',jlayer,':'
224  WRITE(iluout,*) 'Incoherence between '
225  WRITE(iluout,*) 'snow liquid water content '
226  WRITE(iluout,*) 'and snow temperature. '
227  WRITE(iluout,*) ' PLEASE CORRECT THAT '
228  WRITE(iluout,*) '----------------------------'
229  CALL abor1_sfx('READ_PREP_ISBA_SNOW: ERROR IN INITIALISATION OF SNOW PARAMETERS')
230  END IF
231  END DO
232 
233  IF (csnow=='CRO') THEN
234  !
235  ALLOCATE(xsg1snow_p(nsnow_layer))
236  ALLOCATE(xsg2snow_p(nsnow_layer))
237  ALLOCATE(xhistsnow_p(nsnow_layer))
238  !
239  xsg1snow_p =xsg1snow(1:nsnow_layer)
240  xsg2snow_p =xsg2snow(1:nsnow_layer)
241  xhistsnow_p=xhistsnow(1:nsnow_layer)
242  !
243  DO jlayer=1,nsnow_layer
244  IF ((xsg1snow_p(jlayer)==xundef .OR. xsg2snow_p(jlayer)==xundef .OR. &
245  xhistsnow_p(jlayer)==xundef .OR. xagesnow_p(jlayer)==xundef) &
246  .AND. xwsnow_p(jlayer).NE.0. .AND. xwsnow_p(jlayer)/=xundef ) THEN
247  WRITE(iluout,*) '----------------------------'
248  WRITE(iluout,*) 'WSNOW/=0 AND ONE OF SG1SNOW,'
249  WRITE(iluout,*) 'SG2SNOW, HISTSNOW OR AGESNOW'
250  WRITE(iluout,*) ' ==XUNDEF '
251  WRITE(iluout,*) ' PLEASE CORRECT THAT '
252  WRITE(iluout,*) '----------------------------'
253  CALL abor1_sfx('READ_PREP_ISBA_SNOW: ERROR IN INITIALISATION OF SNOW PARAMETERS')
254  ENDIF
255  ENDDO
256  !
257  ELSE
258  !
259  ALLOCATE(xsg1snow_p(0))
260  ALLOCATE(xsg2snow_p(0))
261  ALLOCATE(xhistsnow_p(0))
262  !
263  ENDIF
264  !
265  CALL close_namelist(hprogram,ilunam)
266  !
267 ENDIF
268 !
269 hsnow = csnow
270 !
271 ksnow_layer = nsnow_layer
272 !
273 IF(all(xwsnow_p(:)==xundef).AND.present(ounif))THEN
274  ounif=.false.
275 ELSEIF(present(ounif))THEN
276  ounif=.true.
277 ENDIF
278 !
279 lfile=(len_trim(cfile_snow)>0.AND.len_trim(ctype_snow)>0 &
280  .AND.len_trim(cfilepgd_snow)>0.AND.len_trim(ctypepgd_snow)>0)
281 !
282 IF(present(hfile))THEN
283  IF(lfile)THEN
284  hfile = cfile_snow
285  ELSE
286  hfile = ' '
287  ENDIF
288 ENDIF
289 IF(present(hfiletype))THEN
290  IF(lfile)THEN
291  hfiletype = ctype_snow
292  ELSE
293  hfiletype = ' '
294  ENDIF
295 ENDIF
296 IF(present(hfilepgdtype))THEN
297  IF(lfile)THEN
298  hfilepgdtype = ctypepgd_snow
299  ELSE
300  hfilepgdtype = ' '
301  ENDIF
302 ENDIF
303 IF(present(hfilepgd))THEN
304  IF(lfile)THEN
305  hfilepgd = cfilepgd_snow
306  ELSE
307  hfilepgd = ' '
308  ENDIF
309 ENDIF
310 IF (lfile.AND.present(ounif)) ounif=.false.
311 !
312 IF (lhook) CALL dr_hook('READ_PREP_ISBA_SNOW',1,zhook_handle)
313 !
314 !-------------------------------------------------------------------------------
315 !-------------------------------------------------------------------------------
316 !
317 END SUBROUTINE read_prep_isba_snow
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:6
subroutine close_namelist(HPROGRAM, KLUNAM)
subroutine posnam(KULNAM, HDNAML, OFOUND, KLUOUT)
subroutine get_luout(HPROGRAM, KLUOUT)
Definition: get_luout.F90:6
subroutine read_prep_isba_snow(HPROGRAM, HSNOW, KSNOW_LAYER, HFILE, HFILETYPE, HFILEPGD, HFILEPGDTYPE, OUNIF)
subroutine open_namelist(HPROGRAM, KLUNAM, HFILE)