SURFEX v8.1
General documentation of Surfex
average1_mesh.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 average1_mesh(UG,KLUOUT,KNBLINES,PLAT,PLON,PVALUE,OMULTITYPE,KFACT,PNODATA)
7 ! #######################################################
8 !
9 !!**** *AVERAGE1_MESH* computes the sum of orography, squared orography
10 !! and subgrid orography characteristics
11 !!
12 !! PURPOSE
13 !! -------
14 !!
15 !! METHOD
16 !! ------
17 !!
18 !! EXTERNAL
19 !! --------
20 !!
21 !! IMPLICIT ARGUMENTS
22 !! ------------------
23 !!
24 !!
25 !! REFERENCE
26 !! ---------
27 !!
28 !! AUTHOR
29 !! ------
30 !!
31 !! V. Masson Meteo-France
32 !!
33 !! MODIFICATION
34 !! ------------
35 !!
36 !! Original 12/09/95
37 !!
38 !----------------------------------------------------------------------------
39 !
40 !* 0. DECLARATION
41 ! -----------
42 !
44 !
45 USE modd_pgdwork, ONLY : xall, nsize_all, catype, &
47 USE modd_data_cover_par,ONLY : xcdref
48 !
49 USE modi_get_mesh_index
51 USE modi_abor1_sfx
52 !
53 USE yomhook ,ONLY : lhook, dr_hook
54 USE parkind1 ,ONLY : jprb
55 !
56 IMPLICIT NONE
57 !
58 !* 0.1 Declaration of arguments
59 ! ------------------------
60 !
61 TYPE(surf_atm_grid_t), INTENT(INOUT) :: UG
62 !
63 INTEGER, INTENT(IN) :: KLUOUT
64 INTEGER, INTENT(IN) :: KNBLINES
65 REAL, DIMENSION(:), INTENT(IN) :: PLAT ! latitude of the point to add
66 REAL, DIMENSION(:), INTENT(IN) :: PLON ! longitude of the point to add
67 REAL, DIMENSION(:), INTENT(IN) :: PVALUE ! value of the point to add
68 LOGICAL, INTENT(IN) :: OMULTITYPE
69 INTEGER, INTENT(IN) :: KFACT
70 REAL, OPTIONAL, INTENT(IN) :: PNODATA
71 !
72 !* 0.2 Declaration of other local variables
73 ! ------------------------------------
74 !
75 INTEGER, DIMENSION(NOVMX,SIZE(PLAT)) :: IINDEX ! mesh index of all input points
76  ! 0 indicates the point is out of the domain
77 INTEGER :: JVAL, JTY, IDX ! loop counter on encoutered values
78 INTEGER :: JL, JOV ! loop index on input arrays
79 REAL :: ZEPS=1.e-10 ! a small value
80 LOGICAL :: GFOUND ! T : Value already found in this grid point
81 !
82 LOGICAL, DIMENSION(SIZE(PLAT)) :: GFLAG
83 REAL, DIMENSION(SIZE(PLAT)) :: ZVALUE
84 REAL :: ZNODATA
85 !
86 REAL(KIND=JPRB) :: ZHOOK_HANDLE
87 !----------------------------------------------------------------------------
88 !
89 !* 1. Get position
90 ! ------------
91 !
92 IF (lhook) CALL dr_hook('AVERAGE1_MESH',0,zhook_handle)
93 !
94 ! to calculate the mesh indexes only where pvalue /= pnodata
95 IF (PRESENT(pnodata)) THEN
96  znodata = pnodata
97  zvalue(:) = pvalue(:)
98 ELSE
99  znodata = 0.
100  zvalue(:) = 1.
101 ENDIF
102 !
103  CALL get_mesh_index(ug,kluout,knblines,plat,plon,iindex,zvalue,znodata)
104 !
105 IF (.NOT.PRESENT(pnodata)) zvalue(:) = pvalue(:)
106 !
107 !* 2. Loop on all input data points
108 ! -----------------------------
109 !
110 DO jov = 1, novmx
111  !
112  bloop: &
113  DO jl = 1 , SIZE(plat)
114  !
115 !* 3. Tests on position
116 ! -----------------
117 !
118  idx = iindex(jov,jl)
119 
120  IF (idx==0) cycle bloop
121 !
122 !* 4. Summation
123 ! ---------
124 !
125  IF (PRESENT(pnodata)) THEN
126  IF (zvalue(jl)==znodata) cycle
127  ENDIF
128 !
129 ! the type of the point and the true value
130  IF (omultitype) THEN
131  jty = floor(zvalue(jl)/100.)
132  zvalue(jl) = (zvalue(jl) - jty*100.) / float(kfact)
133  ELSE
134  jty = 1
135  ENDIF
136 
137  nsize_all(idx,jty) = nsize_all(idx,jty)+1
138 !
139 !* 5. Choice of type of summation
140 ! ---------------------------
141 !
142  SELECT CASE (catype)
143 
144  CASE ('ARI')
145  xall(idx,jty,1) = xall(idx,jty,1) + zvalue(jl)
146 
147  CASE ('INV')
148  xall(idx,jty,1) = xall(idx,jty,1) + 1./zvalue(jl)
149 
150  CASE ('CDN')
151  xall(idx,jty,1) = xall(idx,jty,1) + 1./(log(xcdref/zvalue(jl)))**2
152 
153  CASE ('MAJ')
154 
155  gfound=.false.
156  DO jval=1,nvalnbr(idx,jty)
157  IF (abs( xvallist(idx,jval,jty) - zvalue(jl)) < zeps) THEN
158  nvalcount(idx,jval,jty) = nvalcount(idx,jval,jty) + 1
159  gfound=.true.
160  EXIT
161  END IF
162  END DO
163 
164  IF (.NOT. gfound) THEN
165  IF (nvalnbr(idx,jty)==jpvalmax) &
166  CALL abor1_sfx('TOO MANY DIFFERENT VALUES TO AGGREGATE WITH THE MAJORITY RULE')
167  nvalnbr(idx,jty) = nvalnbr(idx,jty) +1
168  jval = nvalnbr(idx,jty)
169  nvalcount(idx,jval,jty) = 1
170  xvallist(idx,jval,jty) = zvalue(jl)
171  END IF
172 
173  END SELECT
174  !
175  ENDDO bloop
176  !
177 ENDDO
178 !
179 IF (lhook) CALL dr_hook('AVERAGE1_MESH',1,zhook_handle)
180 !
181 !-------------------------------------------------------------------------------
182 !
183 END SUBROUTINE average1_mesh
real, dimension(:,:,:), allocatable xvallist
character(len=3) catype
integer, dimension(:,:), allocatable nsize_all
real, dimension(:,:,:), allocatable xall
subroutine abor1_sfx(YTEXT)
Definition: abor1_sfx.F90:7
integer, parameter jprb
Definition: parkind1.F90:32
integer, dimension(:,:), allocatable nvalnbr
subroutine get_mesh_index(UG, KLUOUT, KNBLINES, PLAT, PLON, KINDEX, PVAL
logical lhook
Definition: yomhook.F90:15
integer, dimension(:,:,:), allocatable nvalcount
subroutine average1_mesh(UG, KLUOUT, KNBLINES, PLAT, PLON, PVALUE, OMULT
integer, parameter jpvalmax