SURFEX  V8_0
Surfex V8_0 release
 All Classes Files Functions Variables
pgd_field.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 pgd_field (DTCO, UG, U, USS, &
7  hprogram,hfield,harea,hfile,hfiletype,punif,pfield,opresent)
8 ! ##############################################################
9 !
10 !!**** *PGD_FIELD* monitor for averaging and interpolations of ISBA physiographic fields
11 !!
12 !! PURPOSE
13 !! -------
14 !!
15 !! METHOD
16 !! ------
17 !!
18 !
19 !! EXTERNAL
20 !! --------
21 !!
22 !! IMPLICIT ARGUMENTS
23 !! ------------------
24 !!
25 !! REFERENCE
26 !! ---------
27 !!
28 !! AUTHOR
29 !! ------
30 !!
31 !! V. Masson Meteo-France
32 !!
33 !! MODIFICATION
34 !! ------------
35 !!
36 !! Original 10/12/97
37 !! 09/2010 (E. Kourzeneva): interpolation of the lake depth
38 !! is not allowed and not necessary
39 !!
40 !! 02/2014 (B. Decharme): interpolation of the lake depth
41 !! re-allowed but using the nearest point
42 !----------------------------------------------------------------------------
43 !
44 !* 0. DECLARATION
45 ! -----------
46 !
47 !
48 !
49 !
52 USE modd_surf_atm_n, ONLY : surf_atm_t
54 !
55 USE modd_surf_par, ONLY : xundef
56 USE modd_pgd_grid, ONLY : nl
57 USE modd_pgdwork, ONLY : xsumval, nsize, catype, &
58  nvalnbr, nvalcount, xvallist, jpvalmax
59 !
60 USE modi_get_luout
61 USE modi_treat_field
62 USE modi_interpol_field
64 !
65 !
66 USE yomhook ,ONLY : lhook, dr_hook
67 USE parkind1 ,ONLY : jprb
68 !
69 USE modi_abor1_sfx
70 !
71 USE modi_get_surf_mask_n
72 !
73 USE modi_get_type_dim_n
74 !
75 IMPLICIT NONE
76 !
77 !* 0.1 Declaration of arguments
78 ! ------------------------
79 !
80 !
81 TYPE(data_cover_t), INTENT(INOUT) :: dtco
82 TYPE(surf_atm_grid_t), INTENT(INOUT) :: ug
83 TYPE(surf_atm_t), INTENT(INOUT) :: u
84 TYPE(surf_atm_sso_t), INTENT(INOUT) :: uss
85 !
86  CHARACTER(LEN=6), INTENT(IN) :: hprogram ! Type of program
87  CHARACTER(LEN=*), INTENT(IN) :: hfield ! field name for prints
88  CHARACTER(LEN=3), INTENT(IN) :: harea ! area where field is defined
89 ! ! 'ALL' : everywhere
90 ! ! 'NAT' : on nature
91 ! ! 'TWN' : on town
92 ! ! 'SEA' : on sea
93 ! ! 'WAT' : on inland waters
94  CHARACTER(LEN=28), INTENT(IN) :: hfile ! data file name
95  CHARACTER(LEN=6), INTENT(IN) :: hfiletype ! data file type
96 REAL, INTENT(IN) :: punif ! prescribed uniform value for field
97 REAL, DIMENSION(:),INTENT(OUT):: pfield ! physiographic field
98 LOGICAL, OPTIONAL, INTENT(OUT) :: opresent
99 !
100 !
101 !* 0.2 Declaration of local variables
102 ! ------------------------------
103 !
104 INTEGER :: ilu ! expected physical size of full surface array
105 INTEGER :: iluout ! output listing logical unit
106 INTEGER, DIMENSION(:), POINTER :: imask ! mask for packing from complete field to nature field
107 INTEGER :: idim !
108 
109 !
110  CHARACTER(LEN=20) :: yfield
111  CHARACTER(LEN=6) :: ymask
112 INTEGER :: inpts ! number of points used for interpolation
113 REAL, DIMENSION(NL) :: zfield ! physiographic field on full grid
114 REAL(KIND=JPRB) :: zhook_handle
115 !-------------------------------------------------------------------------------
116 !
117 !* 1. Initializations
118 ! ---------------
119 !
120 IF (lhook) CALL dr_hook('PGD_FIELD',0,zhook_handle)
121 zfield(:) = xundef
122 IF (present(opresent)) opresent=.true.
123 !-------------------------------------------------------------------------------
124 !
125 !* 2. Output listing logical unit
126 ! ---------------------------
127 !
128  CALL get_luout(hprogram,iluout)
129 !
130 !-------------------------------------------------------------------------------
131 !
132 !* 3. Read from file
133 ! --------------
134 !
135 IF (len_trim(hfile)/=0) THEN
136 !
137 !-------------------------------------------------------------------------------
138 !
139 !* 4. Averages the field
140 ! ------------------
141 !
142  ALLOCATE(nsize(nl))
143  ALLOCATE(xsumval(nl))
144 !
145  nsize(:) = 0.
146  xsumval(:) = 0.
147  inpts = 3
148 !
149  IF(hfield=="water depth") THEN
150  inpts = 1
151  ENDIF
152 !
153  IF (catype=='MAJ') THEN
154  ALLOCATE(nvalnbr(nl))
155  ALLOCATE(nvalcount(nl,jpvalmax))
156  ALLOCATE(xvallist(nl,jpvalmax))
157  nvalnbr = 0
158  nvalcount = 0
159  xvallist = xundef
160  inpts = 1
161  END IF
162 !
163  yfield = ' '
164  yfield = hfield(1:min(len(hfield),20))
165 !
166  CALL treat_field(ug, u, uss, &
167  hprogram,'SURF ',hfiletype,'A_MESH',hfile, &
168  yfield,zfield,harea )
169 !
170 !-------------------------------------------------------------------------------
171 !
172 !* 4. Mask for the interpolations
173 ! ---------------------------
174 !
175  SELECT CASE (harea)
176  CASE ('LAN')
177  WHERE ((u%XTOWN(:)+u%XNATURE(:))==0. .AND. nsize(:)==0 ) nsize(:) = -1
178  CASE ('TWN')
179  WHERE (u%XTOWN (:)==0. .AND. nsize(:)==0 ) nsize(:) = -1
180  CASE ('BLD')
181  WHERE (u%XTOWN (:)==0. .AND. nsize(:)==0 ) nsize(:) = -1
182  CASE ('NAT')
183  WHERE (u%XNATURE(:)==0. .AND. nsize(:)==0 ) nsize(:) = -1
184  CASE ('SEA')
185  WHERE (u%XSEA (:)==0. .AND. nsize(:)==0 ) nsize(:) = -1
186  CASE ('WAT')
187  WHERE (u%XWATER (:)==0. .AND. nsize(:)==0 ) nsize(:) = -1
188  END SELECT
189 !
190 !-------------------------------------------------------------------------------
191 !
192 !* 5. Interpolation if some points are not initialized (no data for these points)
193 ! ------------------------------------------------
194 !
195  IF (punif/=xundef) THEN
196  CALL interpol_field(ug, u, &
197  hprogram,iluout,nsize,zfield(:),hfield,pdef=punif,knpts=inpts)
198  ELSE
199  CALL interpol_field(ug, u, &
200  hprogram,iluout,nsize,zfield(:),hfield)
201  END IF
202 !
203  DEALLOCATE(nsize )
204  DEALLOCATE(xsumval )
205  IF (catype=='MAJ') THEN
206  DEALLOCATE(nvalnbr )
207  DEALLOCATE(nvalcount)
208  DEALLOCATE(xvallist )
209  END IF
210 !
211 !-------------------------------------------------------------------------------
212 !
213 ELSEIF (punif/=xundef) THEN
214 !
215 !* 3.1 Use of the presribed field
216 ! --------------------------
217 !
218  zfield(:) = punif
219 !
220 ELSE
221 !
222  IF (present(opresent)) THEN
223  opresent=.false.
224  IF (lhook) CALL dr_hook('PGD_FIELD',1,zhook_handle)
225  RETURN
226  ENDIF
227 !
228  WRITE(iluout,*) ' '
229  WRITE(iluout,*) '***********************************************************'
230  WRITE(iluout,*) '* Error in PGD field preparation of field : ', hfield
231  WRITE(iluout,*) '* There is no prescribed value and no input file *'
232  WRITE(iluout,*) '***********************************************************'
233  WRITE(iluout,*) ' '
234  CALL abor1_sfx('PGD_FIELD: NO PRESCRIBED VALUE NOR INPUT FILE FOR '//hfield)
235 !
236 END IF
237 !-------------------------------------------------------------------------------
238 !
239 !* 6. Mask for the field
240 ! ------------------
241 !
242 SELECT CASE (harea)
243  CASE ('LAN')
244  ymask = 'LAND '
245  CASE ('TWN')
246  ymask = 'TOWN '
247  CASE ('BLD')
248  ymask = 'TOWN '
249  CASE ('NAT')
250  ymask = 'NATURE'
251  CASE ('SEA')
252  ymask = 'SEA '
253  CASE ('WAT')
254  ymask = 'WATER '
255  CASE default
256  pfield(:) = zfield(:)
257  IF (lhook) CALL dr_hook('PGD_FIELD',1,zhook_handle)
258  RETURN
259 END SELECT
260 
261  CALL get_type_dim_n(dtco, u, &
262  ymask,idim)
263 IF (idim/=SIZE(pfield)) THEN
264  WRITE(iluout,*)'Wrong dimension of MASK: ',idim,SIZE(pfield)
265  CALL abor1_sfx('PGD_FIELD: WRONG DIMENSION OF MASK')
266 ENDIF
267 
268 ALLOCATE(imask(idim))
269 ilu=0
270  CALL get_surf_mask_n(dtco, u, &
271  ymask,idim,imask,ilu,iluout)
272  CALL pack_same_rank(imask,zfield(:),pfield(:))
273 DEALLOCATE(imask)
274 IF (lhook) CALL dr_hook('PGD_FIELD',1,zhook_handle)
275 
276 !
277 !-------------------------------------------------------------------------------
278 !
279 END SUBROUTINE pgd_field
subroutine get_type_dim_n(DTCO, U, HTYPE, KDIM)
subroutine pgd_field(DTCO, UG, U, USS, HPROGRAM, HFIELD, HAREA, HFILE, HFILETYPE, PUNIF, PFIELD, OPRESENT)
Definition: pgd_field.F90:6
subroutine treat_field(UG, U, USS, HPROGRAM, HSCHEME, HFILETYPE, HSUBROUTINE, HFILENAME, HFIELD, PPGDARRAY, HSFTYPE)
Definition: treat_field.F90:6
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:6
subroutine get_surf_mask_n(DTCO, U, HTYPE, KDIM, KMASK, KLU, KLUOUT)
subroutine get_luout(HPROGRAM, KLUOUT)
Definition: get_luout.F90:6
subroutine interpol_field(UG, U, HPROGRAM, KLUOUT, KCODE, PFIELD, HFIELD, PDEF, KNPTS)