SURFEX  V8_0
Surfex V8_0 release
 All Classes Files Functions Variables
ini_var_from_patch.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  SUBROUTINE ini_var_from_patch (DTCO, I, UG, U, &
6  hprogram,kluout,hname,pfield,kpts,pdef)
7 !!
8 !! PURPOSE
9 !! -------
10 !!
11 !! (1) KPTS=n interpol field with n pts
12 !! (2) KPTS=0 conserve cells mass
13 !! Case 2 : simple extrapolation based on the inside cell informations.
14 !! this is donne before conserving cell or global mass
15 !!
16 !! METHOD
17 !! ------
18 !!
19 !! EXTERNAL
20 !! --------
21 !!
22 !! IMPLICIT ARGUMENTS
23 !! ------------------
24 !!
25 !! REFERENCE
26 !! ---------
27 !!
28 !! AUTHOR
29 !! ------
30 !!
31 !! R. Alkama Meteo-France
32 !!
33 !! MODIFICATION
34 !! ------------
35 !! Original 12/2010
36 !!
37 !----------------------------------------------------------------------------
38 !!* 0. DECLARATION
39 ! -----------
40 !
41 !
42 !
43 !
45 USE modd_isba_n, ONLY : isba_t
47 USE modd_surf_atm_n, ONLY : surf_atm_t
48 !
49 USE modd_surf_par, ONLY : xundef
50 !
51 USE modi_get_surf_mask_n
52 USE modi_interpol_field
55 !
56 USE yomhook ,ONLY : lhook, dr_hook
57 USE parkind1 ,ONLY : jprb
58 !
59 IMPLICIT NONE
60 !
61 !* 0.1 Declaration of arguments
62 ! ------------------------
63 !
64 !
65 TYPE(data_cover_t), INTENT(INOUT) :: dtco
66 TYPE(isba_t), INTENT(INOUT) :: i
67 TYPE(surf_atm_grid_t), INTENT(INOUT) :: ug
68 TYPE(surf_atm_t), INTENT(INOUT) :: u
69 !
70  CHARACTER(LEN=6), INTENT(IN) :: hprogram ! host model
71 INTEGER, INTENT(IN ) :: kluout
72 INTEGER, INTENT(IN ) :: kpts
73  CHARACTER(LEN=*), INTENT(IN ) :: hname
74 REAL, DIMENSION(:,:), INTENT(INOUT) :: pfield
75 !
76 REAL, DIMENSION(: ), OPTIONAL, INTENT(IN) :: pdef
77 !
78 !* 0.2 Declaration of local variables
79 ! ------------------------------
80 !
81 LOGICAL, DIMENSION(SIZE(I%XLAI,1),SIZE(I%XLAI,2)) :: gveg
82 REAL, DIMENSION(SIZE(PFIELD,1)) :: zfield1_tot, zfield2_tot
83 INTEGER, DIMENSION(SIZE(PFIELD,1)) :: imask ! mask for packing from complete field to nature field
84 INTEGER, DIMENSION(SIZE(PFIELD,1)) :: nsize
85 INTEGER, DIMENSION(U%NSIZE_FULL) :: nsize_tot
86 REAL, DIMENSION(U%NSIZE_FULL) :: zfield_tot
87 INTEGER :: ini, ipatch, ifull, inpts
88 INTEGER :: jpatch ! loop counter on patch
89 REAL :: zratio_tot
90 !
91 REAL(KIND=JPRB) :: zhook_handle
92 !
93 !-------------------------------------------------------------------------------
94 ! (1) & (2) INTERPOL FILED
95 !-------------------------
96 !
97 IF (lhook) CALL dr_hook('INI_VAR_FROM_PATCH',0,zhook_handle)
98 !
99 ini=SIZE(pfield,1)
100 ipatch=SIZE(pfield,2)
101 !
102 IF (kpts>0)THEN
103  !
104  CALL get_surf_mask_n(dtco, u, &
105  'NATURE',ini,imask,u%NSIZE_FULL,kluout)
106  !
107  DO jpatch=1,ipatch
108  nsize(:)=0
109  WHERE (pfield(:,jpatch).NE.xundef) nsize(:)=1
110  WHERE (i%XPATCH(:,jpatch)==0.) nsize(:)=-1
111  CALL unpack_same_rank(imask,nsize,nsize_tot,-1)
112  CALL unpack_same_rank(imask,pfield(:,jpatch),zfield_tot)
113  IF(present(pdef))THEN
114  CALL interpol_field(ug, u, &
115  hprogram,kluout,nsize_tot,zfield_tot,hname,pdef=pdef(jpatch),knpts=kpts)
116  ELSE
117  CALL interpol_field(ug, u, &
118  hprogram,kluout,nsize_tot,zfield_tot,hname,knpts=kpts)
119  ENDIF
120  CALL pack_same_rank(imask,zfield_tot,pfield(:,jpatch))
121  ENDDO
122  !
123 ELSE
124 !
125 !-------------------------------------------------------------------------------
126 ! (3) Cell mass conservative + simple interpolation based on global cell
127 ! informations
128 !----------------------------
129 !
130  !
131  zfield1_tot(:)=0.
132  zfield2_tot(:)=0.
133  !
134  gveg(:,:)=.true.
135  !
136  IF (trim(hname)=='WR')THEN
137  !no interception over soil(1), roc(2) and glaciers(3)
138  DO jpatch=1,ipatch
139  WHERE(i%XPATCH(:,jpatch) /=0. .AND. i%XPATCH_OLD(:,jpatch) ==0..AND.i%XLAI(:,jpatch)==0.)
140  pfield(:,jpatch) = 0.
141  gveg(:,jpatch) = .false.
142  ENDWHERE
143  END DO
144  END IF
145  !
146  !quantity of water before restart in each grid point
147  DO jpatch=1,ipatch
148  zfield1_tot(:)=zfield1_tot(:)+ i%XPATCH_OLD(:,jpatch)*pfield(:,jpatch)
149  END DO
150  !
151  DO jpatch=1,ipatch
152  !if a patch appears in a grid point, it takes the quantity of water in the
153  !whole grid point before
154  WHERE(i%XPATCH(:,jpatch) /=0. .AND. i%XPATCH_OLD(:,jpatch)==0. .AND. gveg(:,jpatch))
155  pfield(:,jpatch)=zfield1_tot(:)
156  ENDWHERE
157  !quantity of water after restart and landuse in each grid point
158  zfield2_tot(:)=zfield2_tot(:)+ i%XPATCH(:,jpatch)*pfield(:,jpatch)
159  END DO
160  !
161  ! Conserve cell mass if not WG and WGI
162  ! If WG or WGI conserve global mass via CONSERV_GLOBAL_MASS routine
163  ! is recomanded
164  !
165  IF (trim(hname)/='WG' .AND. trim(hname)/='WGI') THEN
166  DO jpatch=1,ipatch
167  WHERE(zfield2_tot(:) > 1.e-12)
168  pfield(:,jpatch)=(zfield1_tot(:)/zfield2_tot(:))*pfield(:,jpatch)
169  ENDWHERE
170  END DO
171  ENDIF
172  !
173  WHERE(i%XPATCH(:,:) ==0.)pfield(:,:)=xundef
174  !
175 ENDIF
176 !
177 !-------------------------------------------------------------------------------
178 !
179 IF (lhook) CALL dr_hook('INI_VAR_FROM_PATCH',1,zhook_handle)
180 !
181 !-------------------------------------------------------------------------------
182 !
183 END SUBROUTINE ini_var_from_patch
subroutine get_surf_mask_n(DTCO, U, HTYPE, KDIM, KMASK, KLU, KLUOUT)
subroutine interpol_field(UG, U, HPROGRAM, KLUOUT, KCODE, PFIELD, HFIELD, PDEF, KNPTS)
subroutine ini_var_from_patch(DTCO, I, UG, U, HPROGRAM, KLUOUT, HNAME, PFIELD, KPTS, PDEF)