SURFEX v8.1
General documentation of Surfex
get_mesh_index_ign.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 get_mesh_index_ign(KSSO,PGRID_PAR,PLAT,PLON,&
7  KINDEX,KISSOX,KISSOY,PVALUE,PNODATA)
8 ! ###############################################################
9 !
10 !!**** *GET_MESH_INDEX_IGN* get the grid mesh where point (lat,lon) is located
11 !!
12 !! PURPOSE
13 !! -------
14 !!
15 !! AUTHOR
16 !! ------
17 !!
18 !! E. Martin Meteo-France
19 !!
20 !! MODIFICATION
21 !! ------------
22 !!
23 !! Original 10/2007
24 !!
25 !----------------------------------------------------------------------------
26 !
27 !* 0. DECLARATION
28 ! -----------
29 !
32  nfracd
34 !
36 !
37 !
38 USE yomhook ,ONLY : lhook, dr_hook
39 USE parkind1 ,ONLY : jprb
40 !
41 IMPLICIT NONE
42 !
43 !* 0.1 Declaration of arguments
44 ! ------------------------
45 !
46 INTEGER, INTENT(IN) :: KSSO ! number of subgrid mesh in each direction
47 REAL, DIMENSION(:), INTENT(IN) :: PGRID_PAR ! grid parameters
48 REAL, DIMENSION(:), INTENT(IN) :: PLAT ! latitude of the point
49 REAL, DIMENSION(:), INTENT(IN) :: PLON ! longitude of the point
50 INTEGER, DIMENSION(:,:), INTENT(OUT) :: KINDEX ! index of the grid mesh where the point is
51 INTEGER, DIMENSION(:,:), INTENT(OUT) :: KISSOX ! X index of the subgrid mesh
52 INTEGER, DIMENSION(:,:), INTENT(OUT) :: KISSOY ! Y index of the subgrid mesh
53 !
54 REAL, DIMENSION(:), OPTIONAL, INTENT(IN) :: PVALUE ! value of the point to add
55 REAL, OPTIONAL, INTENT(IN) :: PNODATA
56 !
57 !* 0.2 Declaration of other local variables
58 ! ------------------------------------
59 !
60 INTEGER :: ILAMBERT ! Lambert type
61 !
62 REAL, DIMENSION(:), ALLOCATABLE :: ZX ! X Lambert coordinate
63 REAL, DIMENSION(:), ALLOCATABLE :: ZY ! Y Lambert coordinate
64 !
65 REAL, DIMENSION(:), ALLOCATABLE :: ZXLIM ! X Lambert coordinate
66 !
67 REAL, DIMENSION(SIZE(PLAT)) :: ZVALUE
68 !
69 LOGICAL, DIMENSION(SIZE(PLAT)) :: GMASK
70 !
71 REAL :: ZVALX
72 !
73 REAL :: ZNODATA
74 !
75 INTEGER :: ISIZE, IFACT
76 INTEGER :: IL, ICPT ! Grid dimension
77 INTEGER :: JL ! loop counter in lambert grid
78 INTEGER :: JI, JJ ! loop counter on input points
79 INTEGER, DIMENSION(SIZE(PLAT),2) :: ICI
80 INTEGER, DIMENSION(1) :: IDX0
81 REAL(KIND=JPRB) :: ZHOOK_HANDLE, ZHOOK_HANDLE_OMP
82 !----------------------------------------------------------------------------
83 !
84 IF (lhook) CALL dr_hook('GET_MESH_INDEX_IGN_1',0,zhook_handle)
85 !
86 IF (PRESENT(pvalue) .AND. PRESENT(pnodata)) THEN
87  zvalue(:) = pvalue(:)
88  znodata = pnodata
89 ELSE
90  zvalue(:) = 1
91  znodata = 0
92 ENDIF
93 !
94 IF (.NOT. ALLOCATED(xxlim)) THEN
95 !
96 !* 1. Uncode parameters of the grid
97 ! -----------------------------
98 !
99  CALL get_gridtype_ign(pgrid_par,klambert=ilambert,kl=il)
100 !
101  ifact = floor(sqrt(float(il)))
102  isize = floor(float(il) / ifact)
103  ALLOCATE(nfracd(ifact+1))
104  nfracd(1) = 1
105  nfracd(ifact+1) = il
106  DO jj=2,ifact
107  nfracd(jj) = 1 + (jj-1)*isize
108  ENDDO
109 !
110  ALLOCATE(zx(il))
111  ALLOCATE(zy(il))
112  ALLOCATE(xdx(il))
113  ALLOCATE(xdy(il))
114  ALLOCATE(xxlim(il))
115  ALLOCATE(xylim(il))
116 
117  ALLOCATE(xxlims(0:il))
118  ALLOCATE(nxids(il))
119 
120  ALLOCATE(zxlim(il))
121 !
122  CALL get_gridtype_ign(pgrid_par,px=zx,py=zy,pdx=xdx,pdy=xdy)
123 !
124 !* 2. Limits of grid meshes in x and y
125 ! --------------------------------
126 !
127  xxlim(:)=zx(:)-xdx(:)/2.
128  xylim(:)=zy(:)-xdy(:)/2.
129 !
130  xx_min = minval(xxlim)
131  xx_max = maxval(xxlim+xdx)
132  xy_min = minval(xylim)
133  xy_max = maxval(xylim+xdy)
134 
135  xdx_max = minval(xdx)
136 
137  zxlim(:) = xxlim(:)
138 
139  zvalx = maxval(zxlim) + 1.
140  DO ji=1,il
141  idx0 = minloc(zxlim)
142  xxlims(ji) = zxlim(idx0(1))
143  nxids(ji) = idx0(1)
144  zxlim(idx0(1)) = zvalx
145  ENDDO
146  xxlims(0) = xxlims(1) - xdx_max -1.
147 
148  DEALLOCATE(zxlim)
149  DEALLOCATE(zx )
150  DEALLOCATE(zy )
151  !
152 ENDIF
153 IF (lhook) CALL dr_hook('GET_MESH_INDEX_IGN_1',1,zhook_handle)
154 IF (lhook) CALL dr_hook('GET_MESH_INDEX_IGN_2',0,zhook_handle)
155 !
156 !* 3. Projection
157 ! ----------
158 !
159 ALLOCATE(zx(SIZE(plat)))
160 ALLOCATE(zy(SIZE(plat)))
161 !
162  CALL get_gridtype_ign(pgrid_par,klambert=ilambert)
163 !
164 ! write (*,*),'APPEL XY_IGN'
165  CALL xy_ign(ilambert,zx,zy,plat,plon)
166 ! write(*,*) ' X Y SORTIE : ', ZX(1),ZY(1)
167 !
168 gmask(:) = .false.
169 DO jl=1,SIZE(plat)
170  IF ( zx(jl)<xx_min .OR. zx(jl)>xx_max &
171  .OR. zy(jl)<xy_min .OR. zy(jl)>xy_max ) gmask(jl) = .true.
172 ENDDO
173 !
174 !* 5. Localisation of the data points on (x,y) grid
175 ! ---------------------------------------------
176 !
177 ifact = SIZE(nfracd) - 1
178 !
179 kindex(:,:)=0
180 !
181 kissox(:,:) = 0
182 kissoy(:,:) = 0
183 !
184 ici(:,:) = 0
185 !
186 IF (lhook) CALL dr_hook('GET_MESH_INDEX_IGN_2',1,zhook_handle)
187 !
188 !$OMP PARALLEL PRIVATE(ZHOOK_HANDLE_OMP)
189 IF (lhook) CALL dr_hook('GET_MESH_INDEX_IGN_3',0,zhook_handle_omp)
190 !$OMP DO PRIVATE(JL,JI,JJ)
191 DO jl=1,SIZE(plat)
192  !
193  IF (zvalue(jl)==znodata) cycle
194  IF (gmask(jl)) cycle
195  !
196  frac: &
197  DO jj=ifact,1,-1
198  !
199  IF (zx(jl)>xxlims(nfracd(jj))) THEN
200  !
201  DO ji = nfracd(jj+1),nfracd(jj),-1
202  IF (zx(jl)>xxlims(ji)) THEN
203  ici(jl,2) = ji
204  EXIT
205  ENDIF
206  ENDDO
207  !
208  DO ji = ici(jl,2),0,-1
209  IF (zx(jl)>=xxlims(ji)+xdx_max) THEN
210  ici(jl,1) = ji+1
211  EXIT
212  ENDIF
213  ENDDO
214  !
215  EXIT frac
216  !
217  ENDIF
218  !
219  ENDDO frac
220  !
221 ENDDO
222 !$OMP END DO
223 IF (lhook) CALL dr_hook('GET_MESH_INDEX_IGN_3',1,zhook_handle_omp)
224 !$OMP END PARALLEL
225 !
226 IF (lhook) CALL dr_hook('GET_MESH_INDEX_IGN_4',0,zhook_handle)
227 !
228 DO jl=1,SIZE(plat)
229  !
230  IF (zvalue(jl)==znodata) cycle
231  IF (gmask(jl)) cycle
232  !
233  icpt = 0
234  DO ji=ici(jl,1),ici(jl,2)
235  !
236  IF (zy(jl)>xylim(nxids(ji)) .AND. zy(jl)<xylim(nxids(ji))+xdy(nxids(ji)) &
237  .AND. zx(jl)<xxlims(ji)+xdx(nxids(ji))) THEN
238  !
239  icpt = icpt + 1
240  !
241  kindex(icpt,jl) = nxids(ji)
242  !
243  IF (ksso/=0) THEN
244  kissox(icpt,jl) = 1 + int( float(ksso) * (zx(jl)-xxlim(nxids(ji)))/xdx(nxids(ji)) )
245  kissoy(icpt,jl) = 1 + int( float(ksso) * (zy(jl)-xylim(nxids(ji)))/xdy(nxids(ji)) )
246  ENDIF
247  !
248  IF (icpt==novmx) EXIT
249  !
250  ENDIF
251  !
252  ENDDO
253  !
254 ENDDO
255 !
256 !-------------------------------------------------------------------------------
257 DEALLOCATE(zx )
258 DEALLOCATE(zy )
259 IF (lhook) CALL dr_hook('GET_MESH_INDEX_IGN_4',1,zhook_handle)
260 !-------------------------------------------------------------------------------
261 !
262 END SUBROUTINE get_mesh_index_ign
subroutine get_gridtype_ign(PGRID_PAR, KLAMBERT, KL, PX, PY, PDX, PDY, KDIMX, KDIMY, PXALL, PYALL)
subroutine xy_ign(KLAMBERT, PX, PY, PLAT, PLON)
real, dimension(:), allocatable xxlims
real, dimension(:), allocatable xxlim
integer, parameter jprb
Definition: parkind1.F90:32
integer, dimension(:), allocatable nxids
logical lhook
Definition: yomhook.F90:15
real, dimension(:), allocatable xylim
subroutine get_mesh_index_ign(KSSO, PGRID_PAR, PLAT, PLON, KINDEX, KISSOX, KISSOY, PVALUE, PNODATA)
real, dimension(:), allocatable xdy
real, dimension(:), allocatable xdx
integer, dimension(:), allocatable nfracd