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