1 | MODULE obs_inter_sup |
---|
2 | !!===================================================================== |
---|
3 | !! *** MODULE obs_inter_sup *** |
---|
4 | !! Observation diagnostics: Support for interpolation |
---|
5 | !!===================================================================== |
---|
6 | |
---|
7 | !!---------------------------------------------------------------------- |
---|
8 | !! obs_int_comm_3d : Get 3D interpolation stencil |
---|
9 | !! obs_int_comm_2d : Get 2D interpolation stencil |
---|
10 | !!--------------------------------------------------------------------- |
---|
11 | !! * Modules used |
---|
12 | USE par_kind ! Precision variables |
---|
13 | USE dom_oce ! Domain variables |
---|
14 | USE mpp_map ! Map of processor points |
---|
15 | USE lib_mpp ! MPP stuff |
---|
16 | USE obs_mpp ! MPP stuff for observations |
---|
17 | USE obs_grid ! Grid tools |
---|
18 | USE in_out_manager ! I/O stuff |
---|
19 | |
---|
20 | IMPLICIT NONE |
---|
21 | |
---|
22 | !! * Routine accessibility |
---|
23 | PRIVATE |
---|
24 | |
---|
25 | PUBLIC obs_int_comm_3d, & ! Get 3D interpolation stencil |
---|
26 | & obs_int_comm_2d ! Get 2D interpolation stencil |
---|
27 | |
---|
28 | !!---------------------------------------------------------------------- |
---|
29 | !! NEMO/OCE 4.0 , NEMO Consortium (2018) |
---|
30 | !! $Id$ |
---|
31 | !! Software governed by the CeCILL license (see ./LICENSE) |
---|
32 | !!---------------------------------------------------------------------- |
---|
33 | |
---|
34 | CONTAINS |
---|
35 | |
---|
36 | SUBROUTINE obs_int_comm_3d( kptsi, kptsj, kobs, kpi, kpj, kpk, kgrdi, kgrdj, & |
---|
37 | & pval, pgval, kproc ) |
---|
38 | !!---------------------------------------------------------------------- |
---|
39 | !! *** ROUTINE obs_int_comm_3d *** |
---|
40 | !! |
---|
41 | !! ** Purpose : Get 3D interpolation stencil |
---|
42 | !! |
---|
43 | !! ** Method : Either on-demand communication with |
---|
44 | !! obs_int_comm_3d_global |
---|
45 | !! or local memory with |
---|
46 | !! obs_int_comm_3D_local |
---|
47 | !! depending on ln_global_grid |
---|
48 | !! |
---|
49 | !! ** Action : |
---|
50 | !! |
---|
51 | !! History : |
---|
52 | !! ! 08-02 (K. Mogensen) Original code |
---|
53 | !!---------------------------------------------------------------------- |
---|
54 | !! * Arguments |
---|
55 | INTEGER, INTENT(IN) :: kptsi ! Number of i horizontal points per stencil |
---|
56 | INTEGER, INTENT(IN) :: kptsj ! Number of j horizontal points per stencil |
---|
57 | INTEGER, INTENT(IN) :: kobs ! Local number of observations |
---|
58 | INTEGER, INTENT(IN) :: kpi ! Number of points in i direction |
---|
59 | INTEGER, INTENT(IN) :: kpj ! Number of points in j direction |
---|
60 | INTEGER, INTENT(IN) :: kpk ! Number of levels |
---|
61 | INTEGER, DIMENSION(kptsi,kptsj,kobs), INTENT(IN) :: & |
---|
62 | & kgrdi, & ! i,j indicies for each stencil |
---|
63 | & kgrdj |
---|
64 | INTEGER, OPTIONAL, DIMENSION(kptsi,kptsj,kobs), INTENT(IN) :: & |
---|
65 | & kproc ! Precomputed processor for each i,j,iobs points |
---|
66 | REAL(KIND=wp), DIMENSION(kpi,kpj,kpk), INTENT(IN) ::& |
---|
67 | & pval ! Local 3D array to extract data from |
---|
68 | REAL(KIND=wp), DIMENSION(kptsi,kptsj,kpk,kobs), INTENT(OUT) ::& |
---|
69 | & pgval ! Stencil at each point |
---|
70 | !! * Local declarations |
---|
71 | |
---|
72 | IF (ln_grid_global) THEN |
---|
73 | |
---|
74 | IF (PRESENT(kproc)) THEN |
---|
75 | |
---|
76 | CALL obs_int_comm_3d_global( kptsi, kptsj, kobs, kpi, kpj, kpk, kgrdi, & |
---|
77 | & kgrdj, pval, pgval, kproc=kproc ) |
---|
78 | |
---|
79 | ELSE |
---|
80 | |
---|
81 | CALL obs_int_comm_3d_global( kptsi, kptsj, kobs, kpi, kpj, kpk, kgrdi, & |
---|
82 | & kgrdj, pval, pgval ) |
---|
83 | |
---|
84 | ENDIF |
---|
85 | |
---|
86 | ELSE |
---|
87 | |
---|
88 | CALL obs_int_comm_3d_local( kptsi, kptsj, kobs, kpi, kpj, kpk, kgrdi, kgrdj, & |
---|
89 | & pval, pgval ) |
---|
90 | |
---|
91 | ENDIF |
---|
92 | |
---|
93 | END SUBROUTINE obs_int_comm_3d |
---|
94 | |
---|
95 | SUBROUTINE obs_int_comm_2d( kptsi, kptsj, kobs, kpi, kpj, kgrdi, kgrdj, pval, pgval, & |
---|
96 | & kproc ) |
---|
97 | !!---------------------------------------------------------------------- |
---|
98 | !! *** ROUTINE obs_int_comm_2d *** |
---|
99 | !! |
---|
100 | !! ** Purpose : Get 2D interpolation stencil |
---|
101 | !! |
---|
102 | !! ** Method : Call to obs_int_comm_3d |
---|
103 | !! |
---|
104 | !! ** Action : |
---|
105 | !! |
---|
106 | !! History : |
---|
107 | !! ! 08-02 (K. Mogensen) Original code |
---|
108 | !!---------------------------------------------------------------------- |
---|
109 | !! |
---|
110 | !! * Arguments |
---|
111 | INTEGER, INTENT(IN) :: kptsi ! Number of i horizontal points per stencil |
---|
112 | INTEGER, INTENT(IN) :: kptsj ! Number of j horizontal points per stencil |
---|
113 | INTEGER, INTENT(IN) :: kobs ! Local number of observations |
---|
114 | INTEGER, INTENT(IN) :: kpi ! Number of model grid points in i direction |
---|
115 | INTEGER, INTENT(IN) :: kpj ! Number of model grid points in j direction |
---|
116 | INTEGER, DIMENSION(kptsi,kptsj,kobs), INTENT(IN) :: & |
---|
117 | & kgrdi, & ! i,j indicies for each stencil |
---|
118 | & kgrdj |
---|
119 | INTEGER, OPTIONAL, DIMENSION(kptsi,kptsj,kobs), INTENT(IN) :: & |
---|
120 | & kproc ! Precomputed processor for each i,j,iobs points |
---|
121 | REAL(KIND=wp), DIMENSION(kpi,kpj), INTENT(IN) ::& |
---|
122 | & pval ! Local 3D array to extra data from |
---|
123 | REAL(KIND=wp), DIMENSION(kptsi,kptsj,kobs), INTENT(OUT) ::& |
---|
124 | & pgval ! Stencil at each point |
---|
125 | !! * Local declarations |
---|
126 | REAL(KIND=wp), DIMENSION(jpi,jpj,1) :: zval |
---|
127 | REAL(KIND=wp), DIMENSION(kptsi,kptsj,1,kobs) ::& |
---|
128 | & zgval |
---|
129 | |
---|
130 | ! Set up local "3D" buffer |
---|
131 | |
---|
132 | zval(:,:,1) = pval(:,:) |
---|
133 | |
---|
134 | ! Call the 3D version |
---|
135 | |
---|
136 | IF (PRESENT(kproc)) THEN |
---|
137 | |
---|
138 | CALL obs_int_comm_3d( kptsi, kptsj, kobs, kpi, kpj, 1, kgrdi, kgrdj, zval, & |
---|
139 | & zgval, kproc=kproc ) |
---|
140 | ELSE |
---|
141 | |
---|
142 | CALL obs_int_comm_3d( kptsi, kptsj, kobs, kpi, kpj, 1, kgrdi, kgrdj, zval, & |
---|
143 | & zgval ) |
---|
144 | |
---|
145 | ENDIF |
---|
146 | |
---|
147 | ! Copy "3D" data back to 2D |
---|
148 | |
---|
149 | pgval(:,:,:) = zgval(:,:,1,:) |
---|
150 | |
---|
151 | END SUBROUTINE obs_int_comm_2d |
---|
152 | |
---|
153 | SUBROUTINE obs_int_comm_3d_global( kptsi, kptsj, kobs, kpi, kpj, kpk, kgrdi, kgrdj, & |
---|
154 | & pval, pgval, kproc ) |
---|
155 | !!---------------------------------------------------------------------- |
---|
156 | !! *** ROUTINE obs_int_comm_3d_global *** |
---|
157 | !! |
---|
158 | !! ** Purpose : Get 3D interpolation stencil (global version) |
---|
159 | !! |
---|
160 | !! ** Method : On-demand communication where each processor send its |
---|
161 | !! list of (i,j) of points to all processors and receive |
---|
162 | !! the corresponding values |
---|
163 | !! |
---|
164 | !! ** Action : |
---|
165 | !! |
---|
166 | !! History : |
---|
167 | !! ! 08-02 (K. Mogensen) Original code |
---|
168 | !!---------------------------------------------------------------------- |
---|
169 | !! * Arguments |
---|
170 | INTEGER, INTENT(IN) :: kptsi ! Number of i horizontal points per stencil |
---|
171 | INTEGER, INTENT(IN) :: kptsj ! Number of j horizontal points per stencil |
---|
172 | INTEGER, INTENT(IN) :: kobs ! Local number of observations |
---|
173 | INTEGER, INTENT(IN) :: kpi ! Number of model points in i direction |
---|
174 | INTEGER, INTENT(IN) :: kpj ! Number of model points in j direction |
---|
175 | INTEGER, INTENT(IN) :: kpk ! Number of levels |
---|
176 | INTEGER, DIMENSION(kptsi,kptsj,kobs), INTENT(IN) :: & |
---|
177 | & kgrdi, & ! i,j indicies for each stencil |
---|
178 | & kgrdj |
---|
179 | INTEGER, OPTIONAL, DIMENSION(kptsi,kptsj,kobs), INTENT(IN) :: & |
---|
180 | & kproc ! Precomputed processor for each i,j,iobs points |
---|
181 | REAL(KIND=wp), DIMENSION(kpi,kpj,kpk), INTENT(IN) ::& |
---|
182 | & pval ! Local 3D array to extract data from |
---|
183 | REAL(KIND=wp), DIMENSION(kptsi,kptsj,kpk,kobs), INTENT(OUT) ::& |
---|
184 | & pgval ! Stencil at each point |
---|
185 | !! * Local declarations |
---|
186 | REAL(KIND=wp), DIMENSION(:,:), ALLOCATABLE :: & |
---|
187 | & zsend, & |
---|
188 | & zrecv |
---|
189 | INTEGER, DIMENSION(:), ALLOCATABLE :: & |
---|
190 | & igrdij_send, & |
---|
191 | & igrdij_recv |
---|
192 | INTEGER, DIMENSION(kptsi,kptsj,kobs) :: & |
---|
193 | & iorder, & |
---|
194 | & iproc |
---|
195 | INTEGER :: nplocal(jpnij) |
---|
196 | INTEGER :: npglobal(jpnij) |
---|
197 | INTEGER :: ji |
---|
198 | INTEGER :: jj |
---|
199 | INTEGER :: jk |
---|
200 | INTEGER :: jp |
---|
201 | INTEGER :: jobs |
---|
202 | INTEGER :: it |
---|
203 | INTEGER :: itot |
---|
204 | INTEGER :: ii |
---|
205 | INTEGER :: ij |
---|
206 | |
---|
207 | ! Check valid points |
---|
208 | |
---|
209 | IF ( ( MAXVAL(kgrdi) > jpiglo ) .OR. ( MINVAL(kgrdi) < 1 ) .OR. & |
---|
210 | & ( MAXVAL(kgrdj) > jpjglo ) .OR. ( MINVAL(kgrdj) < 1 ) ) THEN |
---|
211 | |
---|
212 | CALL ctl_stop( 'Error in obs_int_comm_3d_global', & |
---|
213 | & 'Point outside global domain' ) |
---|
214 | |
---|
215 | ENDIF |
---|
216 | |
---|
217 | ! Count number of points on each processors |
---|
218 | |
---|
219 | nplocal(:) = 0 |
---|
220 | IF (PRESENT(kproc)) THEN |
---|
221 | iproc(:,:,:) = kproc(:,:,:) |
---|
222 | DO jobs = 1, kobs |
---|
223 | DO jj = 1, kptsj |
---|
224 | DO ji = 1, kptsi |
---|
225 | nplocal(iproc(ji,jj,jobs)) = nplocal(iproc(ji,jj,jobs)) + 1 |
---|
226 | END DO |
---|
227 | END DO |
---|
228 | END DO |
---|
229 | ELSE |
---|
230 | DO jobs = 1, kobs |
---|
231 | DO jj = 1, kptsj |
---|
232 | DO ji = 1, kptsi |
---|
233 | iproc(ji,jj,jobs) = mppmap(kgrdi(ji,jj,jobs),& |
---|
234 | & kgrdj(ji,jj,jobs)) |
---|
235 | nplocal(iproc(ji,jj,jobs)) = nplocal(iproc(ji,jj,jobs)) + 1 |
---|
236 | END DO |
---|
237 | END DO |
---|
238 | END DO |
---|
239 | ENDIF |
---|
240 | |
---|
241 | ! Send local number of points and receive points on current domain |
---|
242 | |
---|
243 | CALL mpp_alltoall_int( 1, nplocal, npglobal ) |
---|
244 | |
---|
245 | ! Allocate message parsing workspace |
---|
246 | |
---|
247 | itot = SUM(npglobal) |
---|
248 | |
---|
249 | ALLOCATE( & |
---|
250 | & igrdij_send(kptsi*kptsj*kobs*2), & |
---|
251 | & igrdij_recv(itot*2), & |
---|
252 | & zsend(kpk,itot), & |
---|
253 | & zrecv(kpk,kptsi*kptsj*kobs) & |
---|
254 | & ) |
---|
255 | |
---|
256 | ! Pack buffers for list of points |
---|
257 | |
---|
258 | it = 0 |
---|
259 | DO jp = 1, jpnij |
---|
260 | DO jobs = 1, kobs |
---|
261 | DO jj = 1, kptsj |
---|
262 | DO ji = 1, kptsi |
---|
263 | IF ( iproc(ji,jj,jobs) == jp ) THEN |
---|
264 | it = it + 1 |
---|
265 | iorder(ji,jj,jobs) = it |
---|
266 | igrdij_send(2*it-1) = kgrdi(ji,jj,jobs) |
---|
267 | igrdij_send(2*it ) = kgrdj(ji,jj,jobs) |
---|
268 | ENDIF |
---|
269 | END DO |
---|
270 | END DO |
---|
271 | END DO |
---|
272 | END DO |
---|
273 | |
---|
274 | ! Send and recieve buffers for list of points |
---|
275 | |
---|
276 | CALL mpp_alltoallv_int( igrdij_send, kptsi*kptsj*kobs*2, nplocal(:)*2, & |
---|
277 | & igrdij_recv, itot*2, npglobal(:)*2 ) |
---|
278 | |
---|
279 | ! Pack interpolation data to be sent |
---|
280 | |
---|
281 | DO ji = 1, itot |
---|
282 | ii = mi1(igrdij_recv(2*ji-1)) |
---|
283 | ij = mj1(igrdij_recv(2*ji)) |
---|
284 | DO jk = 1, kpk |
---|
285 | zsend(jk,ji) = pval(ii,ij,jk) |
---|
286 | END DO |
---|
287 | END DO |
---|
288 | |
---|
289 | ! Re-adjust sizes |
---|
290 | |
---|
291 | nplocal(:) = kpk*nplocal(:) |
---|
292 | npglobal(:) = kpk*npglobal(:) |
---|
293 | |
---|
294 | |
---|
295 | ! Send and receive data for interpolation stencil |
---|
296 | |
---|
297 | CALL mpp_alltoallv_real( zsend, kpk*itot, npglobal, & |
---|
298 | & zrecv, kpk*kptsi*kptsj*kobs, nplocal ) |
---|
299 | |
---|
300 | ! Copy the received data into output data structure |
---|
301 | |
---|
302 | DO jobs = 1, kobs |
---|
303 | DO jj = 1, kptsj |
---|
304 | DO ji = 1, kptsi |
---|
305 | it = iorder(ji,jj,jobs) |
---|
306 | DO jk = 1, kpk |
---|
307 | pgval(ji,jj,jk,jobs) = zrecv(jk,it) |
---|
308 | END DO |
---|
309 | END DO |
---|
310 | END DO |
---|
311 | END DO |
---|
312 | |
---|
313 | ! Deallocate message parsing workspace |
---|
314 | |
---|
315 | DEALLOCATE( & |
---|
316 | & igrdij_send, & |
---|
317 | & igrdij_recv, & |
---|
318 | & zsend, & |
---|
319 | & zrecv & |
---|
320 | & ) |
---|
321 | |
---|
322 | END SUBROUTINE obs_int_comm_3d_global |
---|
323 | |
---|
324 | SUBROUTINE obs_int_comm_3d_local( kptsi, kptsj, kobs, kpi, kpj, kpk, kgrdi, kgrdj, & |
---|
325 | & pval, pgval ) |
---|
326 | !!---------------------------------------------------------------------- |
---|
327 | !! *** ROUTINE obs_int_comm_3d_global *** |
---|
328 | !! |
---|
329 | !! ** Purpose : Get 3D interpolation stencil (global version) |
---|
330 | !! |
---|
331 | !! ** Method : On-demand communication where each processor send its |
---|
332 | !! list of (i,j) of points to all processors and receive |
---|
333 | !! the corresponding values |
---|
334 | !! |
---|
335 | !! ** Action : |
---|
336 | !! |
---|
337 | !! History : |
---|
338 | !! ! 08-02 (K. Mogensen) Original code |
---|
339 | !!---------------------------------------------------------------------- |
---|
340 | !! * Arguments |
---|
341 | INTEGER, INTENT(IN) :: kptsi ! Number of i horizontal points per stencil |
---|
342 | INTEGER, INTENT(IN) :: kptsj ! Number of j horizontal points per stencil |
---|
343 | INTEGER, INTENT(IN) :: kobs ! Local number of observations |
---|
344 | INTEGER, INTENT(IN) :: kpi ! Number of model points in i direction |
---|
345 | INTEGER, INTENT(IN) :: kpj ! Number of model points in j direction |
---|
346 | INTEGER, INTENT(IN) :: kpk ! Number of levels |
---|
347 | INTEGER, DIMENSION(kptsi,kptsj,kobs), INTENT(IN) :: & |
---|
348 | & kgrdi, & ! i,j indicies for each stencil |
---|
349 | & kgrdj |
---|
350 | REAL(KIND=wp), DIMENSION(kpi,kpj,kpk), INTENT(IN) ::& |
---|
351 | & pval ! Local 3D array to extract data from |
---|
352 | REAL(KIND=wp), DIMENSION(kptsi,kptsj,kpk,kobs), INTENT(OUT) ::& |
---|
353 | & pgval ! Stencil at each point |
---|
354 | !! * Local declarations |
---|
355 | INTEGER :: ji |
---|
356 | INTEGER :: jj |
---|
357 | INTEGER :: jk |
---|
358 | INTEGER :: jobs |
---|
359 | |
---|
360 | ! Check valid points |
---|
361 | |
---|
362 | IF ( ( MAXVAL(kgrdi) > jpi ) .OR. ( MINVAL(kgrdi) < 1 ) .OR. & |
---|
363 | & ( MAXVAL(kgrdj) > jpj ) .OR. ( MINVAL(kgrdj) < 1 ) ) THEN |
---|
364 | |
---|
365 | CALL ctl_stop( 'Error in obs_int_comm_3d_local', & |
---|
366 | & 'Point outside local domain' ) |
---|
367 | |
---|
368 | ENDIF |
---|
369 | |
---|
370 | ! Copy local data |
---|
371 | |
---|
372 | DO jobs = 1, kobs |
---|
373 | DO jj = 1, kptsj |
---|
374 | DO ji = 1, kptsi |
---|
375 | DO jk = 1, kpk |
---|
376 | pgval(ji,jj,jk,jobs) = & |
---|
377 | & pval(kgrdi(ji,jj,jobs),kgrdj(ji,jj,jobs),jk) |
---|
378 | END DO |
---|
379 | END DO |
---|
380 | END DO |
---|
381 | END DO |
---|
382 | |
---|
383 | END SUBROUTINE obs_int_comm_3d_local |
---|
384 | |
---|
385 | END MODULE obs_inter_sup |
---|
386 | |
---|