00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 subroutine psmile_neigh_global_points (search, extra_search, &
00012 mask_array, mask_shape, mask_available, use_how, &
00013 grid_id, grid_valid_shape, &
00014 neighbors_3d, nloc, n_corners, len_cpl, ierror)
00015
00016
00017
00018 use PRISM_constants
00019
00020 use PSMILe, dummy_interface => PSMILe_Neigh_global_points
00021 #ifdef DEBUG_TRACE
00022 use psmile_debug_trace
00023 #endif
00024
00025 Implicit none
00026
00027
00028
00029 Type (Enddef_search), Intent (In) :: search
00030
00031
00032
00033 Integer, Intent (In) :: mask_shape (2, ndim_3d)
00034
00035
00036
00037 Logical, Intent (In) :: mask_array (mask_shape (1,1):
00038 mask_shape (2,1),
00039 mask_shape (1,2):
00040 mask_shape (2,2),
00041 mask_shape (1,3):
00042 mask_shape (2,3))
00043
00044
00045 Logical, Intent (In) :: mask_available
00046
00047
00048
00049
00050
00051 Integer, Intent (In) :: use_how
00052
00053
00054
00055
00056
00057
00058 Integer, Intent (In) :: grid_id
00059
00060
00061
00062
00063 Integer, Intent (In) :: grid_valid_shape (2, ndim_3d)
00064
00065
00066
00067 Integer, Intent (In) :: nloc
00068
00069
00070
00071
00072
00073 Integer, Intent (In) :: n_corners
00074
00075
00076
00077
00078 Integer, Intent (In) :: len_cpl (search%npart)
00079
00080
00081
00082
00083
00084 Type (Extra_search_info), Intent (InOut) :: extra_search
00085
00086
00087
00088
00089 Integer, Intent (InOut) :: neighbors_3d (ndim_3d, nloc, n_corners)
00090
00091
00092
00093
00094
00095 Integer, Intent (Out) :: ierror
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 Integer :: grid_type
00106
00107
00108
00109 Integer :: i, j, n, nbeg, nend, nprev
00110
00111
00112
00113 Integer :: code, nreq
00114 Integer :: outside
00115
00116
00117 Integer, Pointer :: required (:)
00118 Integer, Pointer :: indices_req (:)
00119 Integer, Allocatable :: mask_cell (:)
00120 Integer, Allocatable :: search_required (:)
00121
00122
00123
00124 Integer :: ipart
00125
00126
00127
00128 Integer, parameter :: nerrp = 2
00129 Integer :: ierrp (nerrp)
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 Character(len=len_cvs_string), save :: mycvs =
00153 '$Id: psmile_neigh_global_points.F90 2983 2011-02-24 12:49:29Z hanke $'
00154
00155
00156
00157
00158
00159 #ifdef VERBOSE
00160 print 9990, trim(ch_id)
00161
00162 call psmile_flushstd
00163 #endif /* VERBOSE */
00164
00165
00166
00167 ierror = 0
00168
00169 #ifdef PRISM_ASSERTION
00170
00171 if (nloc /= Sum(len_cpl)) then
00172 print *, "nloc, Sum(len_cpl)", nloc, Sum (len_cpl)
00173 call psmile_assert (__FILE__, &
00174 __LINE__, "ncpl == SUM(len_cpl) expected")
00175 endif
00176 #endif
00177
00178 if (n_corners > 31) then
00179 ierror = PRISM_Error_internal
00180 ierrp (1) = n_corners
00181
00182 call psmile_error ( ierror, &
00183 'Number of corrners too large', &
00184 ierrp, 1, __FILE__, __LINE__ )
00185 return
00186 endif
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203 Allocate (search_required (nloc), STAT = ierror)
00204
00205 if (ierror > 0) then
00206 ierrp (1) = ierror
00207 ierrp (2) = nloc
00208
00209 ierror = PRISM_Error_Alloc
00210
00211 call psmile_error ( ierror, 'search_required', &
00212 ierrp, 2, __FILE__, __LINE__ )
00213 return
00214 endif
00215
00216 search_required (:) = 0
00217
00218
00219
00220 grid_type = Grids(grid_id)%grid_type
00221
00222 if (grid_type == PRISM_Reglonlatvrt .or. &
00223 grid_type == PRISM_Irrlonlat_Regvrt .or. &
00224 grid_type == PRISM_Irrlonlatvrt .or. &
00225 grid_type == PRISM_Gaussreduced_Regvrt) then
00226
00227 code = 1
00228 do n = 1, n_corners
00229
00230 do i = 1, nloc
00231 if (neighbors_3d(1, i, n) < grid_valid_shape(1,1) .or. &
00232 neighbors_3d(1, i, n) > grid_valid_shape(2,1) .or. &
00233 neighbors_3d(2, i, n) < grid_valid_shape(1,2) .or. &
00234 neighbors_3d(2, i, n) > grid_valid_shape(2,2) .or. &
00235 neighbors_3d(3, i, n) < grid_valid_shape(1,3) .or. &
00236 neighbors_3d(3, i, n) > grid_valid_shape(2,3)) then
00237 search_required (i) = search_required (i) + code
00238 end if
00239 end do
00240
00241
00242
00243 code = code * 2
00244 end do
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272 if (mask_available .and. use_how == PSMILE_novalue) then
00273
00274
00275
00276
00277
00278 Allocate (mask_cell (nloc), STAT = ierror)
00279 if (ierror > 0) then
00280 ierrp (1) = ierror
00281 ierrp (2) = nloc
00282
00283 ierror = PRISM_Error_Alloc
00284
00285 call psmile_error ( ierror, 'mask_cell', &
00286 ierrp, 2, __FILE__, __LINE__ )
00287 return
00288 endif
00289
00290 mask_cell (:) = 0
00291
00292
00293
00294 code = 1
00295
00296 do n = 1, n_corners
00297 #ifdef DEBUG_TRACE
00298 if (ictl > 0 .and. ictl <= nloc) then
00299 if (neighbors_3d(1, ictl, n) >= grid_valid_shape(1,1) .and. &
00300 neighbors_3d(1, ictl, n) <= grid_valid_shape(2,1) .and. &
00301 neighbors_3d(2, ictl, n) >= grid_valid_shape(1,2) .and. &
00302 neighbors_3d(2, ictl, n) <= grid_valid_shape(2,2) .and. &
00303 neighbors_3d(3, ictl, n) >= grid_valid_shape(1,3) .and. &
00304 neighbors_3d(3, ictl, n) <= grid_valid_shape(2,3) ) then
00305 print *, 'DEBUG_TRACE: psmile_neigh_global_points: ictl', &
00306 ictl, n, neighbors_3d(:, ictl, n), &
00307 mask_array (neighbors_3d(1, ictl, n), &
00308 neighbors_3d(2, ictl, n), &
00309 neighbors_3d(3, ictl, n))
00310 endif
00311 endif
00312 #endif
00313
00314
00315 do i = 1, nloc
00316 if (IAND (search_required (i), code) == 0) then
00317
00318
00319
00320
00321 if ( .not. mask_array (neighbors_3d(1, i, n), &
00322 neighbors_3d(2, i, n), &
00323 neighbors_3d(3, i, n)) ) &
00324 mask_cell(i) = mask_cell (i) + 1
00325 endif
00326 end do
00327
00328
00329
00330 code = code * 2
00331 end do
00332
00333
00334
00335
00336
00337 if ((grid_type == PRISM_Gaussreduced_Regvrt) .and. &
00338 associated(grids(grid_id)%recv_list)) then
00339 outside = grid_valid_shape(2,1) + sum(grids(grid_id)%recv_list) + 11
00340 else
00341 outside = grid_valid_shape(2,1) + 11
00342 endif
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352 do n = 1, n_corners
00353
00354 do i = 1, nloc
00355 if ( mask_cell(i) > 0 ) then
00356 neighbors_3d(1, i, n) = outside
00357 endif
00358 enddo
00359 enddo
00360
00361
00362
00363
00364 do i = 1, nloc
00365 if ( mask_cell(i) > 0) then
00366 search_required (i) = 0
00367 endif
00368 end do
00369
00370
00371
00372 Deallocate (mask_cell)
00373
00374 endif
00375
00376 else
00377
00378 ierrp (1) = grid_type
00379 ierror = PRISM_Error_Internal
00380
00381 call psmile_error ( ierror, 'unknown grid generation type', &
00382 ierrp, 1, __FILE__, __LINE__ )
00383 return
00384
00385 endif
00386
00387
00388
00389
00390
00391
00392
00393 nprev = 0
00394
00395 do ipart = 1, search%npart
00396 if (len_cpl (ipart) > 0) then
00397 nbeg = nprev + 1
00398 nend = nprev + len_cpl (ipart)
00399
00400 nreq = 0
00401
00402 do i = nbeg, nend
00403 if (search_required(i) /= 0) nreq = nreq + 1
00404 end do
00405
00406 if (nreq > 0) then
00407 Allocate (indices_req (nreq), required (nreq), stat = ierror)
00408 if (ierror > 0) then
00409 ierrp (1) = ierror
00410 ierrp (2) = nreq * 2
00411
00412 ierror = PRISM_Error_Alloc
00413
00414 call psmile_error ( ierror, 'indices_req, required', &
00415 ierrp, 2, __FILE__, __LINE__ )
00416 return
00417 endif
00418
00419 j = 0
00420
00421 do i = nbeg, nend
00422 if (search_required(i) /= 0) then
00423 j = j + 1
00424 indices_req (j) = i
00425 required (j) = search_required (i)
00426 endif
00427 end do
00428
00429
00430
00431 extra_search%indices_req(ipart)%vector => indices_req
00432 extra_search%required (ipart)%vector => required
00433 extra_search%len_req (ipart) = nreq
00434
00435 extra_search%n_req = extra_search%n_req + nreq
00436
00437 #ifdef DEBUG_TRACE
00438 do j = 1, nreq
00439 if (ictl == indices_req (j)) exit
00440 end do
00441
00442 if (j <= nreq) then
00443 print *, 'DEBUG_TRACE: psmile_neigh_global_points: ipart, ictl', &
00444 ipart, ictl
00445 print *, 'DEBUG_TRACE: index in indices_req :', j, &
00446 ', required:', required(j)
00447
00448 do n = 1, n_corners
00449 print *, 'DEBUG_TRACE: ng', neighbors_3d(:, ictl, n)
00450 end do
00451 endif
00452 #endif
00453
00454 #ifdef DEBUGX
00455 print *, 'ipart, nreq ', ipart, nreq
00456 do j = 1, nreq
00457 i = indices_req (j)
00458 print *, 'j, i, required', j, i, required(j)
00459
00460 do n = 1, n_corners
00461 print *, 'ng', neighbors_3d(:, i, n)
00462 end do
00463 end do
00464 #endif
00465 endif
00466
00467
00468
00469 nprev = nend
00470 endif
00471 end do
00472
00473
00474
00475 #ifdef VERBOSE
00476 print 9980, trim(ch_id), extra_search%n_req
00477
00478 call psmile_flushstd
00479 #endif /* VERBOSE */
00480
00481
00482
00483 9990 format (1x, a, ': psmile_neigh_global_points:')
00484 9980 format (1x, a, ': psmile_neigh_global_points: eof, nreq', i6)
00485
00486 #ifdef PRISM_ASSERTION
00487 #endif
00488
00489 end subroutine psmile_neigh_global_points