SURFEX v8.1
General documentation of Surfex
average1_cover.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_cover(UG,U,KLUOUT,KNBLINES,PLAT,PLON,PVALUE,PNODATA)
7 ! #######################################################
8 !
9 !!**** *AVERAGE1_COVER* computes the sum of values of a cover fractions
10 !! and the nature of terrain on the grid
11 !! from a data in land-cover file
12 !!
13 !! PURPOSE
14 !! -------
15 !!
16 !! METHOD
17 !! ------
18 !!
19 !! EXTERNAL
20 !! --------
21 !!
22 !! IMPLICIT ARGUMENTS
23 !! ------------------
24 !!
25 !!
26 !! REFERENCE
27 !! ---------
28 !!
29 !! AUTHOR
30 !! ------
31 !!
32 !! V. Masson Meteo-France
33 !!
34 !! MODIFICATION
35 !! ------------
36 !!
37 !! Original 12/09/95
38 !!
39 !----------------------------------------------------------------------------
40 !
41 !* 0. DECLARATION
42 ! -----------
43 !
45 USE modd_surf_atm_n, ONLY : surf_atm_t
46 !
47 USE modd_surfex_mpi, ONLY : nrank
48 USE modd_pgdwork, ONLY : xall, nsize_all
49 USE modd_data_cover_par, ONLY : jpcover
50 !
51 USE modi_get_mesh_index
53 !
54 !
55 USE yomhook ,ONLY : lhook, dr_hook
56 USE parkind1 ,ONLY : jprb
57 !
58 IMPLICIT NONE
59 !
60 !* 0.1 Declaration of arguments
61 ! ------------------------
62 !
63 TYPE(surf_atm_grid_t), INTENT(INOUT) :: UG
64 TYPE(surf_atm_t), INTENT(INOUT) :: U
65 !
66 INTEGER, INTENT(IN) :: KLUOUT
67 INTEGER, INTENT(IN) :: KNBLINES
68 REAL, DIMENSION(:), INTENT(IN) :: PLAT ! latitude of the point to add
69 REAL, DIMENSION(:), INTENT(IN) :: PLON ! longitude of the point to add
70 REAL, DIMENSION(:), INTENT(IN) :: PVALUE ! value of the point to add
71 REAL, OPTIONAL, INTENT(IN) :: PNODATA
72 !
73 !* 0.2 Declaration of other local variables
74 ! ------------------------------------
75 !
76 INTEGER, DIMENSION(NOVMX,SIZE(PLAT)) :: IINDEX ! mesh index of all input points
77  ! 0 indicates the point is out of the domain
78 !
79 REAL, DIMENSION(:,:,:), ALLOCATABLE :: ZALL
80 REAL, DIMENSION(SIZE(PLAT)) :: ZVALUE
81 REAL :: ZNODATA
82 INTEGER :: JL, JOV, JCOV, IFOUND, ICOV, IND ! loop index on input arrays
83 INTEGER :: ICOVERCLASS ! class of cover type
84 REAL(KIND=JPRB) :: ZHOOK_HANDLE
85 !----------------------------------------------------------------------------
86 !
87 !
88 !* 1. Get position
89 ! ------------
90 !
91 IF (lhook) CALL dr_hook('AVERAGE1_COVER',0,zhook_handle)
92 !
93 icov = SIZE(xall,2)
94 !
95 IF (PRESENT(pnodata)) THEN
96  zvalue(:) = pvalue(:)
97  znodata = pnodata
98  CALL get_mesh_index(ug,kluout,knblines,plat,plon,iindex,zvalue,znodata)
99 ELSE
100  zvalue(:) = 1.
101  znodata = 0.
102  CALL get_mesh_index(ug,kluout,knblines,plat,plon,iindex)
103 ENDIF
104 !
105 !* 2. Loop on all input data points
106 ! -----------------------------
107 !
108 bloop: &
109 DO jl = 1 , SIZE(plat)
110 !
111 !* 3. Tests on position
112 ! -----------------
113 !
114  DO jov = 1, novmx
115 
116  IF (iindex(jov,jl)==0) cycle bloop
117 !
118 !* 4. Test on value meaning
119 ! ---------------------
120 !
121  icoverclass = nint(pvalue(jl))
122 !
123  u%LCOVER(icoverclass) = .true.
124 !
125  IF (icoverclass<1 .OR. icoverclass > jpcover ) cycle
126 !
127 !* 5. Summation
128 ! ---------
129 !
130  nsize_all(iindex(jov,jl),1)=nsize_all(iindex(jov,jl),1)+1
131 !
132 !* 6. Fraction of cover type
133 ! ----------------------
134 !
135  ifound = 0
136  !ICOV: number of covers already found in the domain
137  DO jcov=1,icov
138  !if the cover read is already in the array
139  IF (xall(iindex(jov,jl),jcov,1)==icoverclass*1.) THEN
140  !the number of points found is increased of 1
141  xall(iindex(jov,jl),jcov,2) = xall(iindex(jov,jl),jcov,2) + 1.
142  ifound=1
143  EXIT
144  ENDIF
145  ENDDO
146  !if the cover is not in the array
147  IF (ifound==0) THEN
148  !if we already have some covers for this point
149  IF (xall(iindex(jov,jl),icov,2)/=0.) THEN
150  !to save the current array
151  ALLOCATE(zall(SIZE(xall,1),icov,SIZE(xall,3)))
152  zall(:,:,:) = xall(:,:,:)
153  DEALLOCATE(xall)
154  !we add one cover to the size of the array
155  ALLOCATE(xall(SIZE(zall,1),icov+1,SIZE(zall,3)))
156  xall(:,1:icov,:) = zall(:,:,:)
157  DEALLOCATE(zall)
158  xall(:,icov+1,:) = 0.
159  !the number of covers already found increases
160  icov = icov + 1
161  ENDIF
162  !first index for this point where no cover is defined
163  ind = minloc(xall(iindex(jov,jl),:,2),1,xall(iindex(jov,jl),:,2)==0.)
164  !the new cover is registered
165  xall(iindex(jov,jl),ind,1) = icoverclass*1.
166  xall(iindex(jov,jl),ind,2) = 1.
167  ENDIF
168  !
169  ENDDO
170 !
171 END DO bloop
172 !
173 IF (lhook) CALL dr_hook('AVERAGE1_COVER',1,zhook_handle)
174 !
175 !-------------------------------------------------------------------------------
176 !
177 END SUBROUTINE average1_cover
integer, dimension(:,:), allocatable nsize_all
real, dimension(:,:,:), allocatable xall
integer, parameter jprb
Definition: parkind1.F90:32
subroutine average1_cover(UG, U, KLUOUT, KNBLINES, PLAT, PLON, PVALUE, PN
subroutine get_mesh_index(UG, KLUOUT, KNBLINES, PLAT, PLON, KINDEX, PVAL
logical lhook
Definition: yomhook.F90:15