00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 subroutine psmile_neigh_extra_points (search, extra_search, &
00012 mask_array, mask_shape, mask_available, use_how, &
00013 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_extra_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(3)
00052
00053
00054
00055
00056
00057
00058 Integer, Intent (In) :: grid_valid_shape (2, ndim_3d)
00059
00060
00061
00062 Integer, Intent (In) :: nloc
00063
00064
00065
00066
00067
00068 Integer, Intent (In) :: n_corners
00069
00070
00071
00072
00073 Integer, Intent (In) :: len_cpl (search%npart)
00074
00075
00076
00077
00078
00079 Type (Extra_search_info), Intent (InOut) :: extra_search
00080
00081
00082
00083
00084 Integer, Intent (InOut) :: neighbors_3d (ndim_3d, nloc, n_corners)
00085
00086
00087
00088
00089
00090 Integer, Intent (Out) :: ierror
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100 Integer :: grid_id
00101 Integer, Pointer :: recv_list(:)
00102 Integer :: search_mode
00103 Integer :: i, j, n, nbeg, nend
00104
00105
00106
00107 Integer :: n_extra, outside
00108
00109 Integer, Pointer :: indices (:)
00110 Logical, Allocatable :: mask_cell (:)
00111
00112
00113
00114 Integer :: ipart
00115
00116
00117
00118 Integer, parameter :: nerrp = 2
00119 Integer :: ierrp (nerrp)
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 Character(len=len_cvs_string), save :: mycvs =
00144 '$Id: psmile_neigh_extra_points.F90 2991 2011-02-25 08:34:51Z hanke $'
00145
00146
00147
00148
00149
00150 #ifdef VERBOSE
00151 print 9990, trim(ch_id)
00152
00153 call psmile_flushstd
00154 #endif /* VERBOSE */
00155
00156
00157
00158 ierror = 0
00159 search_mode = use_how(1)
00160 grid_id = use_how(3)
00161
00162
00163
00164
00165
00166 if (associated(Grids(grid_id)%recv_list)) then
00167
00168
00169
00170 recv_list => Grids(grid_id)%recv_list
00171 outside = grid_valid_shape(2,1) + sum(recv_list) + 11
00172 else
00173 outside = grid_valid_shape(2,1) + 11
00174 endif
00175
00176 #ifdef PRISM_ASSERTION
00177
00178 if (nloc /= Sum(len_cpl)) then
00179 print *, "nloc, Sum(len_cpl)", nloc, Sum (len_cpl)
00180 call psmile_assert (__FILE__, &
00181 __LINE__, "ncpl == SUM(len_cpl) expected")
00182 endif
00183
00184 if (extra_search%n_extra /= 0) then
00185 call psmile_assert (__FILE__, &
00186 __LINE__, "extra_search%n_extra /= 0")
00187 endif
00188 #endif
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226 #ifdef DEBUG
00227 8990 format (1x, a, ': psmile_neigh_extra_points: search_mode', i8, &
00228 '; mask_available ', l1)
00229 print 8990, trim(ch_id), search_mode, mask_available
00230 #endif
00231
00232 if ( search_mode == PSMILE_nneighbour ) search_mode = PSMILe_Undef
00233
00234 #ifdef DEBUG_TRACE
00235 if ( ictl > 0 .and. ictl <= nloc ) then
00236 print *, ' ictl neigh 1', neighbors_3d(1,ictl,:)
00237 print *, ' ictl neigh 2', neighbors_3d(2,ictl,:)
00238 print *, ' ictl neigh 3', neighbors_3d(3,ictl,:)
00239 endif
00240 #endif
00241 if (mask_available) then
00242
00243
00244
00245
00246 do n = 1, n_corners
00247
00248 do i = 1, nloc
00249
00250 if (neighbors_3d(1, i, n) /= extra_search%global_marker) then
00251
00252
00253
00254
00255
00256
00257 if ( neighbors_3d(1, i, n) < grid_valid_shape(1,1) .or. &
00258 neighbors_3d(1, i, n) > grid_valid_shape(2,1) .or. &
00259 neighbors_3d(2, i, n) < grid_valid_shape(1,2) .or. &
00260 neighbors_3d(2, i, n) > grid_valid_shape(2,2) .or. &
00261 neighbors_3d(3, i, n) < grid_valid_shape(1,3) .or. &
00262 neighbors_3d(3, i, n) > grid_valid_shape(2,3) ) then
00263
00264 neighbors_3d(1, i, n) = outside
00265
00266
00267
00268
00269
00270 else if ( neighbors_3d(1, i, n) >= mask_shape(1,1) .and. &
00271 neighbors_3d(1, i, n) <= mask_shape(2,1) .and. &
00272 neighbors_3d(2, i, n) >= mask_shape(1,2) .and. &
00273 neighbors_3d(2, i, n) <= mask_shape(2,2) .and. &
00274 neighbors_3d(3, i, n) >= mask_shape(1,3) .and. &
00275 neighbors_3d(3, i, n) <= mask_shape(2,3) ) then
00276 #ifdef DEBUG_TRACE
00277 if ( i == ictl ) then
00278 print *, ' ictl neigh & mask ', i, n, neighbors_3d(:, i, n), &
00279 mask_array (neighbors_3d(1, i, n), &
00280 neighbors_3d(2, i, n), &
00281 neighbors_3d(3, i, n))
00282 endif
00283 #endif
00284 if ( .not. mask_array (neighbors_3d(1, i, n), &
00285 neighbors_3d(2, i, n), &
00286 neighbors_3d(3, i, n)) ) &
00287 neighbors_3d(1, i, n) = outside
00288 endif
00289
00290 endif
00291 enddo
00292 enddo
00293
00294
00295
00296
00297
00298
00299 if ( search_mode == PSMILE_novalue .or. &
00300 search_mode == PSMILe_undef ) then
00301
00302
00303
00304
00305
00306 Allocate (mask_cell (nloc), STAT = ierror)
00307 if (ierror > 0) then
00308 ierrp (1) = ierror
00309 ierrp (2) = nloc
00310
00311 ierror = PRISM_Error_Alloc
00312
00313 call psmile_error ( ierror, 'mask_cell', &
00314 ierrp, 2, __FILE__, __LINE__ )
00315 return
00316 endif
00317
00318
00319 do i = 1, nloc
00320 mask_cell (i) = neighbors_3d(1, i, 1) == outside
00321 end do
00322
00323 if ( search_mode == PSMILE_novalue ) then
00324
00325
00326
00327
00328
00329
00330
00331 do n = 2, n_corners
00332
00333 do i = 1, nloc
00334 mask_cell (i) = mask_cell (i) .or. &
00335 neighbors_3d(1, i, n) == outside
00336 end do
00337 end do
00338
00339 do n = 1, n_corners
00340
00341 do i = 1, nloc
00342 if ( mask_cell(i) ) &
00343 neighbors_3d(1, i, n) = outside
00344 enddo
00345 enddo
00346
00347 else
00348
00349
00350
00351
00352 do n = 2, n_corners
00353
00354 do i = 1, nloc
00355 mask_cell (i) = mask_cell (i) .and. &
00356 neighbors_3d(1, i, n) == outside
00357 end do
00358 end do
00359
00360 #ifdef TEST_EXTRA_SEARCH
00361 print *, '### psmile_neigh_extra_points: Extra-Search for testing enabled'
00362 mask_cell(:) = .true.
00363 #endif
00364
00365
00366
00367
00368
00369
00370
00371 n_extra = count (mask_cell (:))
00372
00373 if (n_extra > 0) then
00374
00375
00376
00377
00378
00379
00380 Allocate (indices (n_extra), stat = ierror)
00381 if (ierror > 0) then
00382 ierrp (1) = ierror
00383 ierrp (2) = n_extra
00384
00385 ierror = PRISM_Error_Alloc
00386
00387 call psmile_error ( ierror, 'extra_search%indices', &
00388 ierrp, 2, __FILE__, __LINE__ )
00389 return
00390 endif
00391
00392
00393
00394 #ifdef USE_PACK
00395 indices (1: n_extra) = &
00396 PACK ((/ (i, i=1,nloc) /), mask_cell)
00397 #else
00398 j = 0
00399
00400 do i = 1, nloc
00401 if (mask_cell (i)) then
00402 j = j + 1
00403 indices (j) = i
00404 endif
00405 end do
00406 #endif /* USE_PACK */
00407
00408
00409
00410 nend = 0
00411 do ipart = 1, search%npart
00412 if (len_cpl (ipart) > 0) then
00413 nbeg = nend + 1
00414 nend = nend + len_cpl (ipart)
00415
00416 extra_search%len_extra (ipart) = &
00417 count (mask_cell(nbeg:nend))
00418
00419 endif
00420 end do
00421
00422 #ifdef DEBUGX
00423 do i = 1, nloc
00424 if (mask_cell (i)) then
00425 print *, 'i', i, neighbors_3d(:, i, 1)
00426 do n = 1, n_corners
00427 print *, 'ng', neighbors_3d(:, i, n), &
00428 mask_array (neighbors_3d(1, i, n), &
00429 neighbors_3d(2, i, n), &
00430 neighbors_3d(3, i, n))
00431 end do
00432 endif
00433 end do
00434 #endif
00435
00436
00437
00438 extra_search%indices => indices
00439
00440 extra_search%n_extra = n_extra
00441
00442 endif
00443 endif
00444
00445 Deallocate (mask_cell)
00446
00447 endif
00448
00449 endif
00450
00451
00452
00453 #ifdef VERBOSE
00454 print 9980, trim(ch_id), extra_search%n_extra
00455
00456
00457 call psmile_flushstd
00458 #endif /* VERBOSE */
00459
00460
00461
00462 9990 format (1x, a, ': psmile_neigh_extra_points:')
00463 9980 format (1x, a, ': psmile_neigh_extra_points: eof, n_extra', i6)
00464
00465 end subroutine psmile_neigh_extra_points