00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 subroutine psmile_info_trs_loc_irreg2_dble (comp_info, &
00012 coords, shape, control, len_cpl, &
00013 var_id, grid_valid_shape, &
00014 search, method_id, &
00015 send_index, ierror)
00016
00017
00018
00019 use PRISM_constants
00020
00021 use PSMILe, dummy_interface => PSMILe_info_trs_loc_irreg2_dble
00022 #ifdef DEBUG_TRACE
00023 use psmile_debug_trace
00024 #endif
00025
00026 implicit none
00027
00028
00029
00030 Type (Enddef_comp), Intent (In) :: comp_info
00031
00032
00033
00034
00035 Type (Enddef_search), Intent (InOut) :: search
00036
00037
00038
00039 Type (dble_vector), Intent (In) :: coords (ndim_3d, search%npart)
00040
00041
00042
00043 Integer, Intent (In) :: shape (2, ndim_3d, search%npart)
00044
00045
00046
00047
00048
00049 Integer, Intent (In) :: control (2, ndim_3d, search%npart)
00050
00051
00052
00053 Integer, Intent (InOut) :: len_cpl (search%npart)
00054
00055
00056
00057 Integer, Intent (In) :: var_id
00058
00059
00060
00061 Integer, Intent (In) :: grid_valid_shape (2, ndim_3d)
00062
00063
00064
00065 Integer, Intent (In) :: method_id
00066
00067
00068
00069 Integer, Intent (InOut) :: send_index
00070
00071
00072
00073
00074
00075 integer, Intent (Out) :: ierror
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 Integer, Parameter :: indl = 1
00087 Integer, Parameter :: indz = 2
00088
00089
00090
00091
00092
00093 Type (Gridfunction), Pointer :: field
00094
00095
00096
00097 Type (Method), Pointer :: mp
00098
00099
00100
00101 Type (Grid), Pointer :: grid_info
00102
00103 Integer :: grid_id
00104 Integer :: ncpl, new_ncpl
00105 Integer :: jj, totsiz, offset
00106
00107
00108
00109 Integer :: i, j, n, n1, n2, n3, nn
00110 Integer :: jpart
00111
00112
00113
00114 Type (Corner_Block), Pointer :: cp
00115 Type (Send_information), Pointer :: send_info
00116 Type (Extra_search_info) :: extra_search
00117
00118 Integer :: nb_neighbors, nb_extra
00119 Integer, Pointer :: dstijk (:, :)
00120 Integer, Allocatable :: new_dstijk (:, :)
00121
00122 Integer, Allocatable :: neighbors_3d (:, :, :)
00123 Integer :: interpolation(ndim_3d)
00124 Integer :: interpolation_mode, search_mode
00125 Integer :: interpolation_type
00126 Integer :: interpolation_methods (indz)
00127 Integer :: n_intmethods
00128 Logical :: interpolation_search (indz)
00129 Logical :: global_search
00130 Logical :: global_cell_search
00131
00132
00133
00134
00135
00136
00137
00138 Integer :: id_src_mask, id_tgt_mask
00139 Integer :: mask_id
00140 Integer :: use_how (3)
00141 Logical :: src_mask_available, use_mask
00142
00143 Logical, Target :: dummy_mask_array (1)
00144
00145 Integer :: dummy_mask_shape (2, ndim_3d)
00146 Integer, Target :: dummy_mask (1)
00147
00148
00149 Integer :: mask_shape (2, ndim_3d)
00150 Logical, Pointer :: mask_array (:)
00151 Integer, Pointer :: src_mask (:)
00152
00153
00154
00155 Integer :: ibeg, iend, ipart, nprev
00156 Integer :: new_len_cpl(search%npart)
00157
00158
00159
00160 Integer :: cpl_id
00161 Integer :: epio_id, trs_rank
00162 Integer :: local_src_size, shift, src_size
00163 Integer :: src_cell_size
00164 Integer :: id_trans_out
00165 Integer :: ip, len, leni, lenij
00166
00167 Integer, Pointer :: list_entries (:, :)
00168 Type (dble_vector) :: src_grid (ndim_3d)
00169 Type (dble_vector) :: src_cell (ndim_3d)
00170 Integer, Allocatable :: neighbors (:, :)
00171 Integer, Pointer :: neighcells (:, :)
00172 Integer, Allocatable :: source_cell_index (:)
00173 Integer, Pointer :: nbr_cells (:)
00174 Integer, Pointer :: new_nbr_cells (:)
00175 Integer :: nbr_cells_tot, nb_corners
00176 Integer :: nbr_corners(ndim_3d)
00177 Integer :: corner_shape (2, ndim_3d)
00178 Integer :: corner_shape_3d (2, ndim_3d, ndim_3d)
00179
00180
00181
00182 Integer :: id_trans_in, dest_comp_id
00183 Logical :: use_target_grid
00184 Logical :: use_target_cell
00185 Logical :: use_source_cell
00186 Integer :: tgt_corners(3)
00187
00188 Type (dble_vector) :: tgt_grid (ndim_3d)
00189 Type (dble_vector) :: tgt_cell (ndim_3d)
00190 Type (dble_vector) :: new_tgt_cell (ndim_3d)
00191 Integer, Pointer :: tgt_mask(:)
00192
00193
00194
00195 logical :: transformed, cubic
00196 Type (dble_vector) :: sinvec, cosvec
00197
00198
00199
00200 Integer, parameter :: nerrp = 3
00201 Integer :: ierrp (nerrp)
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
00227
00228
00229 Character(len=len_cvs_string), save :: mycvs =
00230 '$Id: psmile_info_trs_loc_irreg2_dble.F90 2936 2011-02-03 09:36:47Z hanke $'
00231
00232
00233
00234
00235
00236 data dummy_mask_shape /0, 1, 0, 1, 0, 1/
00237
00238
00239
00240
00241
00242 #ifdef VERBOSE
00243 print 9990, trim(ch_id), method_id, search%msg_intersections%first_tgt_method_id, &
00244 search%sender
00245
00246 call psmile_flushstd
00247 #endif /* VERBOSE */
00248
00249 ierror = 0
00250
00251 field => Fields(var_id)
00252 mp => Methods(method_id)
00253 send_info => mp%send_infos_coupler(send_index)
00254 grid_id = mp%grid_id
00255 grid_info => Grids(grid_id)
00256 cp => Grids(grid_id)%corner_pointer
00257
00258 transformed = .false.
00259 cubic = .false.
00260
00261 global_search = .false.
00262 global_cell_search = .false.
00263 interpolation_search (:) = .false.
00264
00265 use_how(1) = PSMILe_undef
00266 use_how(2) = PSMILe_undef
00267 use_how(3) = grid_id
00268
00269 #ifdef PRISM_ASSERTION
00270
00271
00272
00273 if ( .not. associated(field%Taskout) ) then
00274 print *, 'var_id', var_id
00275 call psmile_assert (__FILE__, &
00276 __LINE__, "Taskout is not available for Field")
00277 end if
00278
00279 if (var_id < 1 .or. var_id > Number_of_Fields_allocated) then
00280 print *, 'var_id', var_id
00281 call psmile_assert (__FILE__, &
00282 __LINE__, "Incorrect var_id")
00283 endif
00284
00285 if ( mp%status == PSMILe_Status_free .or. &
00286 mp%status == PSMILe_Status_undefined ) then
00287 call psmile_assert (__FILE__, &
00288 __LINE__, "Incorrect method")
00289 endif
00290
00291 if (send_index < 1) then
00292 print *, send_index
00293 call psmile_assert (__FILE__, &
00294 __LINE__, "send_index is out of range")
00295 endif
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310 if (send_info%nvec == indz) then
00311 if (search%grid_type /= PRISM_Reglonlatvrt .and. &
00312 search%grid_type /= PRISM_Irrlonlat_Regvrt .and. &
00313 search%grid_type /= PRISM_Gaussreduced_Regvrt ) then
00314 print *, "nvec", send_info%nvec
00315 call psmile_assert (__FILE__, &
00316 __LINE__, "nvec == indz not expected for this grid type")
00317 endif
00318 else if (send_info%nvec /= 1) then
00319 print *, "nvec", send_info%nvec
00320 call psmile_assert (__FILE__, &
00321 __LINE__, "nvec must be in range [1:2]")
00322 endif
00323
00324 if (send_info%nloc /= Sum(len_cpl)) then
00325 print *, "ncpl", send_info%nloc, Sum (len_cpl)
00326 call psmile_assert (__FILE__, &
00327 __LINE__, "ncpl == SUM(len_cpl) expected")
00328 endif
00329 #endif
00330
00331
00332
00333 ncpl = send_info%nloc
00334 dstijk => send_info%dstijk
00335
00336
00337
00338
00339
00340
00341
00342 mask_id = field%mask_id
00343 src_mask_available = mask_id /= PRISM_UNDEFINED
00344 use_mask = src_mask_available
00345
00346 if (src_mask_available) then
00347 mask_array => Masks(mask_id)%mask_array
00348
00349 mask_shape = Masks(mask_id)%mask_shape
00350 else
00351 mask_array => dummy_mask_array
00352
00353 mask_shape = dummy_mask_shape
00354 endif
00355
00356
00357
00358
00359
00360 id_trans_in = search%msg_intersections%transient_in_id
00361 id_trans_out = search%msg_intersections%transient_out_id
00362 dest_comp_id = all_comp_infos (search%msg_intersections%all_comp_infos_comp_idx)%global_comp_id
00363
00364 do i = 1, size (field%Taskout)
00365 if (field%Taskout(i)%origin_type == PSMILe_comp .and. &
00366 field%Taskout(i)%remote_comp_id == dest_comp_id .and. &
00367 field%Taskout(i)%remote_transi_id == id_trans_in .and. &
00368 field%Taskout(i)%global_transi_id == id_trans_out) exit
00369 end do
00370
00371 if (i > size (field%Taskout)) then
00372 #ifdef DEBUG
00373 print *, 'psmile_info_trs_loc_irreg2_dble: method_id ', method_id
00374 print *, 'search for Taskout id ', id_trans_out, ' and Taskin Id ', &
00375 id_trans_in, ' for dest component', dest_comp_id
00376
00377 do i = 1, size (field%Taskout)
00378 print 9960, i, &
00379 field%Taskout(i)%origin_type, &
00380 field%Taskout(i)%remote_comp_id, &
00381 field%Taskout(i)%remote_transi_id, &
00382 field%Taskout(i)%global_transi_id
00383 end do
00384 #endif /* DEBUG */
00385
00386 ierrp (1) = id_trans_in
00387 ierrp (2) = id_trans_out
00388 ierror = PRISM_Error_Internal
00389
00390 call psmile_error ( ierror, 'cannot find Taskout index for transient ids', &
00391 ierrp, 2, __FILE__, __LINE__ )
00392 endif
00393
00394 interpolation_type = field%Taskout(i)%interp%interp_type
00395 interpolation_methods = field%Taskout(i)%interp%interp_meth (1:2)
00396
00397
00398
00399
00400
00401
00402 #ifdef DEBUG
00403 print *, "interpolation type ", interpolation_type
00404 print *, "interpolation method", interpolation_methods
00405 #endif
00406
00407 select case (interpolation_type)
00408 case (PSMILe_3D)
00409 n_intmethods = 1
00410
00411 case (PSMILe_2D1D)
00412 n_intmethods = 2
00413
00414
00415
00416 case default
00417 ierrp (1) = interpolation_type
00418 ierror = PRISM_Error_Interp_type
00419
00420 call psmile_error ( ierror, &
00421 'unsupported interpolation for gridtype PRISM_Irrlonlat_regvrt', &
00422 ierrp, 1, __FILE__, __LINE__ )
00423 return
00424
00425 end select
00426
00427 do j = n_intmethods, 1, -1
00428 if (interpolation_methods(j) /= PSMILe_none) exit
00429 end do
00430
00431 n_intmethods = j
00432
00433 if (n_intmethods == 0) then
00434 ierror = PRISM_Error_Interp_type
00435 call psmile_error ( ierror, 'All interpolations are PSMILE_none', &
00436 ierrp, 0, __FILE__, __LINE__ )
00437 return
00438 endif
00439
00440
00441
00442 nb_neighbors = 1
00443 nb_extra = 1
00444
00445 do j = 1, n_intmethods
00446 select case (interpolation_methods(j))
00447
00448
00449
00450 case (PSMILe_conserv2D)
00451 nb_neighbors = nb_neighbors * 4
00452 use_how(1) = field%Taskout(i)%interp%arg4(j)
00453 use_how(2) = PSMILe_conserv2D
00454 interpolation_search (j) = &
00455 field%Taskout(i)%interp%arg3 (j) == PSMILE_global
00456
00457 case (PSMILe_conserv3D)
00458 nb_neighbors = nb_neighbors * 8
00459 use_how(1) = field%Taskout(i)%interp%arg4(j)
00460 use_how(2) = PSMILe_conserv3D
00461 interpolation_search (j) = &
00462 field%Taskout(i)%interp%arg3 (j) == PSMILE_global
00463
00464
00465
00466 case (PSMILe_nnghbr3D, PSMILe_nnghbr2D)
00467 use_how(1) = field%Taskout(i)%interp%arg4(j)
00468 nb_neighbors = nb_neighbors * field%Taskout(i)%interp%arg2(j)
00469 nb_extra = nb_extra * field%Taskout(i)%interp%arg2(j)
00470 use_mask = use_mask .and. &
00471 (field%Taskout(i)%interp%arg5(j) /= 1)
00472
00473
00474
00475 case (PSMILe_trilinear)
00476 nb_neighbors = nb_neighbors * 8
00477 use_how(1) = field%Taskout(i)%interp%arg4(j)
00478 interpolation_search (j) = &
00479 field%Taskout(i)%interp%arg3 (j) == PSMILE_global
00480
00481 case (PSMILe_bilinear)
00482 nb_neighbors = nb_neighbors * 4
00483 use_how(1) = field%Taskout(i)%interp%arg4(j)
00484 interpolation_search (j) = &
00485 field%Taskout(i)%interp%arg3 (j) == PSMILE_global
00486
00487 case (PSMILe_linear)
00488
00489
00490 nb_neighbors = nb_neighbors * 2
00491 use_how(1) = field%Taskout(i)%interp%arg4(j)
00492 interpolation_search (j) = &
00493 field%Taskout(i)%interp%arg3 (j) == PSMILE_global
00494
00495
00496
00497 case (PSMILe_bicubic)
00498 nb_neighbors = nb_neighbors * 4 * 4
00499 use_how(1) = field%Taskout(i)%interp%arg4(j)
00500 cubic = .true.
00501 interpolation_search (j) = &
00502 field%Taskout(i)%interp%arg3 (j) == PSMILE_global
00503
00504 case (PSMILe_none)
00505
00506 case (PSMILe_undef)
00507 ierrp (1) = j
00508 ierror = PRISM_Error_Interp_type
00509
00510 call psmile_error ( ierror, &
00511 'undefined interpolation method (PSMILE_UNDEF) found', &
00512 ierrp, 1, __FILE__, __LINE__ )
00513 return
00514
00515 case default
00516 ierrp (1) = interpolation_methods(j)
00517 ierror = PRISM_Error_Internal
00518
00519 call psmile_error ( ierror, &
00520 'unsupported interpolation for gridtype PRISM_Irrlonlat_regvrt', &
00521 ierrp, 1, __FILE__, __LINE__ )
00522 return
00523
00524 end select
00525 end do
00526
00527 if (nb_neighbors < 1) then
00528 ierror = PRISM_Error_Interp_type
00529 ierrp (1) = nb_neighbors
00530
00531 call psmile_error ( ierror, &
00532 'Number of interpolation bases is less than 1', &
00533 ierrp, 1, __FILE__, __LINE__ )
00534 return
00535 endif
00536
00537 if (comp_info%size > 1) then
00538 if ( interpolation_methods(1) == PSMILe_conserv2D ) then
00539 global_cell_search = ANY (interpolation_search)
00540 else
00541 global_search = ANY (interpolation_search)
00542 endif
00543
00544 #ifdef DEBUG
00545 print *, "interpolation search", interpolation_search (:)
00546 print *, "global search", global_search
00547 print *, "global cell search", global_cell_search
00548 #endif
00549 else
00550 interpolation_search = .false.
00551 endif
00552
00553 #ifdef PRISM_ASSERTION
00554 do j = 1, n_intmethods
00555 select case (interpolation_methods(j))
00556
00557
00558
00559 case (PSMILe_conserv2D)
00560 if (n_intmethods > 2 .or. &
00561 (n_intmethods == 2 .and. &
00562 interpolation_methods(2) /= PSMILe_linear)) then
00563 call psmile_assert (__FILE__, __LINE__, &
00564 "Don't know to combine PSMILe_conserv2D with that interpolation")
00565 endif
00566
00567 case (PSMILe_conserv3D)
00568 if (n_intmethods > 1) then
00569 call psmile_assert (__FILE__, __LINE__, &
00570 "Don't know to combine PSMILe_trilinear with other interpolations")
00571 endif
00572
00573
00574
00575 case (PSMILe_nnghbr3D)
00576 if (n_intmethods > 1) then
00577 call psmile_assert (__FILE__, __LINE__, &
00578 "Don't know to combine PSMILe_nnghbr3D with other interpolations")
00579 endif
00580
00581 case (PSMILe_nnghbr2D)
00582 if (n_intmethods > 1) then
00583 call psmile_assert (__FILE__, __LINE__, &
00584 "Don't know to combine PSMILe_nnghbr2D with other interpolations")
00585 endif
00586
00587
00588
00589 case (PSMILe_trilinear)
00590 if (n_intmethods > 1) then
00591 call psmile_assert (__FILE__, __LINE__, &
00592 "Don't know to combine PSMILe_trilinear with other interpolations")
00593 endif
00594
00595
00596 case (PSMILe_bilinear)
00597 if (n_intmethods > 2 .or. &
00598 (n_intmethods == 2 .and. &
00599 interpolation_methods(2) /= PSMILe_linear)) then
00600 call psmile_assert (__FILE__, __LINE__, &
00601 "Don't know to combine PSMILe_bilinear with that interpolation")
00602 endif
00603
00604
00605 case (PSMILe_linear)
00606 if (n_intmethods < 2 .or. &
00607 (n_intmethods == 2 .and. &
00608 (interpolation_methods(1) /= PSMILe_bilinear .and. &
00609 interpolation_methods(1) /= PSMILe_bicubic))) then
00610 call psmile_assert (__FILE__, __LINE__, &
00611 "Don't know to combine PSMILe_linear with that interpolation")
00612 endif
00613
00614
00615
00616
00617 case (PSMILe_bicubic)
00618 if (n_intmethods > 2 .or. &
00619 (n_intmethods == 2 .and. &
00620 interpolation_methods(2) /= PSMILe_linear)) then
00621 call psmile_assert (__FILE__, __LINE__, &
00622 "Don't know to combine PSMILe_bicubic with that interpolation")
00623 endif
00624
00625 end select
00626 end do
00627 #endif
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637 use_target_cell = ( interpolation_methods(1) == PSMILe_Conserv2D .or. &
00638 interpolation_methods(1) == PSMILe_Conserv3D )
00639
00640 use_source_cell = use_target_cell
00641
00642 if (use_target_cell) then
00643
00644
00645
00646 use_target_grid = .false.
00647
00648 if ( search%grid_type == PRISM_Irrlonlat_regvrt ) then
00649 tgt_corners(1:2) = 4
00650 tgt_corners(3) = 4
00651
00652 do i = 1, ndim_3d
00653 Allocate (tgt_cell(i)%vector(ncpl*tgt_corners(i)), stat = ierror)
00654 if ( ierror > 0 ) then
00655 ierrp (1) = ierror
00656 ierrp (2) = ncpl
00657
00658 ierror = PRISM_Error_Alloc
00659 call psmile_error ( ierror, 'tgt_cell(i)%vector', &
00660 ierrp, 2, __FILE__, __LINE__ )
00661 return
00662 endif
00663 end do
00664 else if ( search%grid_type == PRISM_Reglonlatvrt ) then
00665
00666 tgt_corners(:) = 4
00667
00668 do i = 1, ndim_3d
00669 Allocate (tgt_cell(i)%vector(ncpl*tgt_corners(i)), stat = ierror)
00670 if ( ierror > 0 ) then
00671 ierrp (1) = ierror
00672 ierrp (2) = ncpl
00673
00674 ierror = PRISM_Error_Alloc
00675 call psmile_error ( ierror, 'tgt_cell(i)%vector', &
00676 ierrp, 2, __FILE__, __LINE__ )
00677 return
00678 endif
00679 end do
00680
00681 else if ( search%grid_type == PRISM_Gaussreduced_regvrt ) then
00682
00683 tgt_corners = nb_neighbors
00684
00685 nprev = 0
00686 ncpl = 0
00687
00688 do ipart = 1, search%npart
00689
00690 totsiz = size(coords(1,ipart)%vector)
00691 offset = totsiz/2
00692
00693 if (len_cpl (ipart) > 0) then
00694 ibeg = nprev + 1
00695 iend = nprev + len_cpl (ipart)
00696
00697 do j = ibeg, iend
00698 if ( dstijk(1,j) /= PSMILe_Undef .and. &
00699 dstijk(1,j)-shape(1,1,ipart)+1 <= offset ) ncpl = ncpl + 1
00700
00701
00702
00703
00704
00705 enddo
00706
00707 nprev = nprev + len_cpl (ipart)
00708
00709 endif
00710
00711 enddo
00712
00713 send_info%nloc = ncpl
00714
00715 do i = 1, ndim_3d
00716 Allocate (tgt_cell(i)%vector(ncpl*tgt_corners(i)), stat = ierror)
00717 if ( ierror > 0 ) then
00718 ierrp (1) = ierror
00719 ierrp (2) = ncpl
00720
00721 ierror = PRISM_Error_Alloc
00722 call psmile_error ( ierror, 'tgt_cell(i)%vector', &
00723 ierrp, 2, __FILE__, __LINE__ )
00724 return
00725 endif
00726 end do
00727
00728 else
00729 ierrp (1) = search%grid_type
00730 ierror = PRISM_Error_Internal
00731 call psmile_error ( ierror, 'unsupported grid type', &
00732 ierrp, 1, __FILE__, __LINE__ )
00733 return
00734 endif
00735
00736 nprev = 0
00737 jj = 0
00738
00739 do ipart = 1, search%npart
00740
00741 if (len_cpl (ipart) > 0) then
00742
00743 ibeg = nprev + 1
00744 iend = nprev + len_cpl (ipart)
00745
00746 if (search%grid_type == PRISM_Irrlonlat_regvrt) then
00747
00748 len = shape(2,1,ipart)-shape(1,1,ipart)+1
00749 do i = 1, ndim_2d
00750
00751 do jpart = ibeg, iend, 5000
00752
00753 do j = jpart, min(iend,jpart+5000-1)
00754
00755 n = (dstijk(2,j)-shape(1,2,ipart))*len + &
00756 dstijk(1,j)-shape(1,1,ipart)+1
00757 tgt_cell(i)%vector(0*ncpl+j) = coords(i,ipart)%vector(n)
00758 tgt_cell(i)%vector(1*ncpl+j) = coords(i,ipart)%vector(n+1)
00759 tgt_cell(i)%vector(2*ncpl+j) = coords(i,ipart)%vector(n+len+1)
00760 tgt_cell(i)%vector(3*ncpl+j) = coords(i,ipart)%vector(n+len)
00761
00762
00763
00764
00765
00766 enddo
00767 enddo
00768
00769 end do
00770
00771 do j = ibeg, iend
00772 if ( dstijk(3,j) /= PSMILe_Undef ) then
00773 n = dstijk(3,j)-shape(1,3,ipart)+1
00774 do nn = 0, nb_neighbors-1
00775 tgt_cell(3)%vector(nn*ncpl+j) = coords(3,ipart)%vector(n)
00776 enddo
00777 else
00778 do nn = 0, nb_neighbors-1
00779 tgt_cell(3)%vector(nn*ncpl+j) = 0.0
00780 enddo
00781 endif
00782 enddo
00783
00784 if ( search%msg_intersections%requires_conserv_remap == PSMILe_Conserv3D ) then
00785 ierrp (1) = search%grid_type
00786 ierror = PRISM_Error_Internal
00787 call psmile_error ( ierror, 'unsupported interpolation', &
00788 ierrp, 1, __FILE__, __LINE__ )
00789 return
00790 endif
00791
00792 else if ( search%grid_type == PRISM_Reglonlatvrt ) then
00793
00794 len = shape(2,1,ipart)-shape(1,1,ipart)+1
00795
00796 do jpart = ibeg, iend, 5000
00797
00798 do j = jpart, min(iend,jpart+5000-1)
00799
00800 if ( dstijk(1,j) /= PSMILe_Undef .and. dstijk(2,j) /= PSMILe_Undef ) then
00801 n1 = dstijk(1,j)-shape(1,1,ipart)
00802
00803 n2 = (dstijk(2,j)-shape(1,2,ipart))*len
00804 tgt_cell(1)%vector(0*ncpl+j) = coords(1,ipart)%vector(n1+1)
00805 tgt_cell(1)%vector(1*ncpl+j) = coords(1,ipart)%vector(n1+2)
00806 tgt_cell(1)%vector(2*ncpl+j) = coords(1,ipart)%vector(n1+2)
00807 tgt_cell(1)%vector(3*ncpl+j) = coords(1,ipart)%vector(n1+1)
00808 tgt_cell(2)%vector(0*ncpl+j) = coords(2,ipart)%vector(n2+1)
00809 tgt_cell(2)%vector(1*ncpl+j) = coords(2,ipart)%vector(n2+1)
00810 tgt_cell(2)%vector(2*ncpl+j) = coords(2,ipart)%vector(n2+len+1)
00811 tgt_cell(2)%vector(3*ncpl+j) = coords(2,ipart)%vector(n2+len+1)
00812 else
00813 do nn = 0, nb_neighbors-1
00814 tgt_cell(1)%vector(nn*ncpl+j) = 0.0
00815 tgt_cell(2)%vector(nn*ncpl+j) = 0.0
00816 enddo
00817 endif
00818 end do
00819 end do
00820
00821 if ( search%msg_intersections%requires_conserv_remap == PSMILe_Conserv3D ) then
00822 do j = ibeg, iend
00823 if ( dstijk(3,j) /= PSMILe_Undef ) then
00824 n3 = dstijk(3,j)-shape(1,3,ipart)+1
00825 do nn = 0, 3
00826 tgt_cell(3)%vector(nn*ncpl+j) = coords(3,ipart)%vector(n3)
00827 enddo
00828 do nn = 4, nb_neighbors-1
00829 tgt_cell(3)%vector(nn*ncpl+j) = coords(3,ipart)%vector(n3+1)
00830 enddo
00831 else
00832 do nn = 0, nb_neighbors-1
00833 tgt_cell(3)%vector(nn*ncpl+j) = 0.0
00834 enddo
00835 endif
00836 end do
00837 else
00838 do j = ibeg, iend
00839 if ( dstijk(3,j) /= PSMILe_Undef ) then
00840 n3 = dstijk(3,j)-shape(1,3,ipart)+1
00841 do nn = 0, nb_neighbors-1
00842 tgt_cell(3)%vector(nn*ncpl+j) = coords(3,ipart)%vector(n3)
00843 enddo
00844 else
00845 do nn = 0, nb_neighbors-1
00846 tgt_cell(3)%vector(nn*ncpl+j) = 0.0
00847 enddo
00848 endif
00849 enddo
00850 endif
00851
00852 else if (search%grid_type == PRISM_Gaussreduced_regvrt) then
00853
00854 if (len_cpl (ipart) > 0) then
00855
00856 totsiz = size(coords(1,ipart)%vector)
00857 offset = totsiz/2
00858
00859 len_cpl(ipart) = 0
00860
00861 do jpart = ibeg, iend, 5000
00862
00863 do j = jpart, min(iend,jpart+5000-1)
00864
00865 if ( dstijk(1,j) /= PSMILe_Undef .and. &
00866 dstijk(1,j)-shape(1,1,ipart)+1 <= offset ) then
00867
00868
00869
00870
00871
00872 n = dstijk(1,j)-shape(1,1,ipart)+1
00873 jj = jj + 1
00874 len_cpl(ipart) = len_cpl(ipart) + 1
00875
00876 tgt_cell(1)%vector(0*ncpl+jj) = coords(1,ipart)%vector(n)
00877 tgt_cell(1)%vector(1*ncpl+jj) = coords(1,ipart)%vector(n+offset)
00878 tgt_cell(1)%vector(2*ncpl+jj) = coords(1,ipart)%vector(n+offset)
00879 tgt_cell(1)%vector(3*ncpl+jj) = coords(1,ipart)%vector(n)
00880 tgt_cell(2)%vector(0*ncpl+jj) = coords(2,ipart)%vector(n)
00881 tgt_cell(2)%vector(1*ncpl+jj) = coords(2,ipart)%vector(n)
00882 tgt_cell(2)%vector(2*ncpl+jj) = coords(2,ipart)%vector(n+offset)
00883 tgt_cell(2)%vector(3*ncpl+jj) = coords(2,ipart)%vector(n+offset)
00884
00885 n3 = dstijk(3,j)-shape(1,3,ipart)+1
00886 do nn = 0, nb_neighbors-1
00887 tgt_cell(3)%vector(nn*ncpl+jj) = coords(3,ipart)%vector(n3)
00888 enddo
00889
00890
00891
00892
00893 endif
00894
00895 enddo
00896 enddo
00897
00898 if ( search%msg_intersections%requires_conserv_remap == PSMILe_Conserv3D ) then
00899 ierrp (1) = search%grid_type
00900 ierror = PRISM_Error_Internal
00901 call psmile_error ( ierror, 'unsupported interpolation', &
00902 ierrp, 1, __FILE__, __LINE__ )
00903 return
00904 endif
00905
00906 endif
00907
00908 else
00909
00910 ierrp (1) = search%grid_type
00911 ierror = PRISM_Error_Internal
00912 call psmile_error ( ierror, 'unsupported grid type', &
00913 ierrp, 1, __FILE__, __LINE__ )
00914 return
00915
00916 endif
00917
00918 nprev = nprev + len_cpl (ipart)
00919
00920 endif
00921
00922 end do
00923
00924 else
00925
00926
00927
00928 use_target_grid = .not. ( &
00929 search%grid_type == PRISM_Irrlonlatvrt .and. &
00930 search%npart == 1 .and. &
00931 ncpl == (shape(2,1,1)-shape(1,1,1)+1)* &
00932 (shape(2,2,1)-shape(1,2,1)+1)* &
00933 (shape(2,3,1)-shape(1,3,1)+1) )
00934
00935 if (use_target_grid) then
00936
00937
00938
00939 do i = 1, ndim_3d
00940 Allocate (tgt_grid(i)%vector(ncpl), stat = ierror)
00941 if ( ierror > 0 ) then
00942 ierrp (1) = ierror
00943 ierrp (2) = ncpl
00944
00945 ierror = PRISM_Error_Alloc
00946 call psmile_error ( ierror, 'tgt_grid(i)%vector', &
00947 ierrp, 2, __FILE__, __LINE__ )
00948 return
00949 endif
00950 end do
00951
00952
00953
00954 if ( search%grid_type == PRISM_Reglonlatvrt .or. &
00955 search%grid_type == PRISM_Irrlonlat_regvrt .or. &
00956 search%grid_type == PRISM_Gaussreduced_regvrt) then
00957
00958
00959
00960 nprev = 0
00961 do ipart = 1, search%npart
00962 if (len_cpl (ipart) > 0) then
00963 ibeg = nprev + 1
00964 iend = nprev + len_cpl (ipart)
00965
00966 call psmile_extract_indices_2d_dble ( &
00967 coords(1,ipart)%vector, shape (:,1:ndim_2d, ipart), &
00968 dstijk (:, ibeg:iend), len_cpl(ipart), &
00969 tgt_grid(1)%vector(ibeg:iend), ierror)
00970 if (ierror /= 0) return
00971
00972 call psmile_extract_indices_2d_dble ( &
00973 coords(2,ipart)%vector, shape (:,1:ndim_2d, ipart), &
00974 dstijk (:, ibeg:iend), len_cpl(ipart), &
00975 tgt_grid(2)%vector(ibeg:iend), ierror)
00976 if (ierror /= 0) return
00977
00978 tgt_grid(3)%vector(ibeg:iend) = &
00979 coords(3,ipart)%vector(dstijk(3,ibeg:iend)-shape(1,3,ipart)+1)
00980
00981 nprev = nprev + len_cpl (ipart)
00982 endif
00983 end do
00984
00985 else if (search%grid_type == PRISM_Irrlonlatvrt) then
00986
00987
00988
00989 nprev = 0
00990 do ipart = 1, search%npart
00991 if (len_cpl (ipart) > 0) then
00992 ibeg = nprev + 1
00993 iend = nprev + len_cpl (ipart)
00994
00995 do i = 1, ndim_3d
00996 call psmile_extract_indices_3d_dble ( &
00997 coords(i,ipart)%vector, shape(:,:, ipart), &
00998 dstijk (:, ibeg:iend), len_cpl(ipart), &
00999 tgt_grid(i)%vector(ibeg:iend), &
01000 ierror)
01001 if (ierror > 0) return
01002 end do
01003
01004 nprev = nprev + len_cpl (ipart)
01005 endif
01006 end do
01007
01008 else
01009
01010
01011
01012 ierrp (1) = search%grid_type
01013 ierror = PRISM_Error_Internal
01014 call psmile_error ( ierror, 'unsupported grid type', &
01015 ierrp, 1, __FILE__, __LINE__ )
01016 return
01017
01018 endif
01019
01020 else
01021
01022
01023
01024 do i = 1, ndim_3d
01025 tgt_grid(i)%vector => coords(i,1)%vector
01026 end do
01027 endif
01028
01029 endif
01030
01031
01032
01033
01034
01035
01036
01037 Allocate (neighbors_3d(ndim_3d, ncpl, nb_neighbors), STAT = ierror)
01038 if ( ierror > 0 ) then
01039 ierrp (1) = ierror
01040 ierrp (2) = ndim_3d * ncpl * nb_neighbors
01041
01042 ierror = PRISM_Error_Alloc
01043 call psmile_error ( ierror, 'neighbors_3d', &
01044 ierrp, 2, __FILE__, __LINE__ )
01045 return
01046 endif
01047
01048
01049
01050 extra_search%global_search = global_search
01051
01052 call psmile_neigh_extra_search_init (search, grid_id, extra_search, ierror)
01053 if (ierror > 0) return
01054
01055
01056
01057 search_mode = 3
01058
01059 j = 1
01060 do while (j <= n_intmethods)
01061
01062 select case (interpolation_methods(j))
01063
01064
01065
01066
01067
01068 case (PSMILe_nnghbr3D)
01069
01070
01071
01072
01073 if (.not. transformed) then
01074 call psmile_info_coords_irreg2_dble ( &
01075 mp%coords_pointer%coords_dble(1)%vector, &
01076 mp%coords_pointer%coords_dble(2)%vector, &
01077 mp%coords_pointer%coords_dble(3)%vector, &
01078 mp%coords_pointer%coords_shape, &
01079 grid_valid_shape, &
01080 sinvec, cosvec, ierror)
01081 if (ierror > 0) return
01082
01083 transformed = .true.
01084 endif
01085
01086
01087
01088 nprev = 0
01089
01090 if (send_info%nvec == 1) then
01091
01092 do ipart = 1, search%npart
01093 if (len_cpl (ipart) > 0) then
01094
01095 call psmile_neigh_near_irr2_3d_dble (grid_id, &
01096 tgt_grid(1)%vector, &
01097 tgt_grid(2)%vector, &
01098 tgt_grid(3)%vector, &
01099 mp%coords_pointer%coords_dble(1)%vector, &
01100 mp%coords_pointer%coords_dble(2)%vector, &
01101 mp%coords_pointer%coords_dble(3)%vector, &
01102 mp%coords_pointer%coords_shape, &
01103 mask_array, mask_shape, use_mask, &
01104 sinvec%vector, cosvec%vector, &
01105 grid_valid_shape, search_mode, &
01106 send_info%srclocs(1,1)%vector, &
01107 ncpl, nprev, len_cpl (ipart), &
01108 neighbors_3d, nb_neighbors, &
01109 extra_search, ierror)
01110 if (ierror > 0) return
01111
01112 nprev = nprev + len_cpl (ipart)
01113 end if
01114 end do
01115
01116 else
01117 do ipart = 1, search%npart
01118 if (len_cpl (ipart) > 0) then
01119
01120 call psmile_neigh_near_irreg2_dble (grid_id, &
01121 tgt_grid(1)%vector(nprev+1:), &
01122 tgt_grid(2)%vector(nprev+1:), &
01123 tgt_grid(3)%vector(nprev+1:), &
01124 mp%coords_pointer%coords_dble(1)%vector, &
01125 mp%coords_pointer%coords_dble(2)%vector, &
01126 mp%coords_pointer%coords_dble(3)%vector, &
01127 mp%coords_pointer%coords_shape, &
01128 mask_array, mask_shape, use_mask, &
01129 sinvec%vector, cosvec%vector, &
01130 grid_valid_shape, search_mode, &
01131 send_info%srclocs(indl, ipart)%vector, &
01132 send_info%srclocs(indz, ipart)%vector, &
01133 send_info%npoints(1:indz, ipart), &
01134 ncpl, nprev, &
01135 neighbors_3d, nb_neighbors, &
01136 extra_search, ierror)
01137
01138 if (ierror > 0) return
01139
01140 nprev = nprev + len_cpl (ipart)
01141 end if
01142 end do
01143 endif
01144
01145 case (PSMILe_nnghbr2D)
01146
01147
01148
01149 if (.not. transformed) then
01150 call psmile_info_coords_irreg2_dble ( &
01151 mp%coords_pointer%coords_dble(1)%vector, &
01152 mp%coords_pointer%coords_dble(2)%vector, &
01153 mp%coords_pointer%coords_dble(3)%vector, &
01154 mp%coords_pointer%coords_shape, &
01155 grid_valid_shape, &
01156 sinvec, cosvec, ierror)
01157 if (ierror > 0) return
01158
01159 transformed = .true.
01160 endif
01161
01162
01163
01164 nprev = 0
01165 search_mode = 2
01166
01167 if (send_info%nvec == 1) then
01168
01169 do ipart = 1, search%npart
01170 if (len_cpl (ipart) > 0) then
01171
01172 call psmile_neigh_near_irr2_3d_dble (grid_id, &
01173 tgt_grid(1)%vector, &
01174 tgt_grid(2)%vector, &
01175 tgt_grid(3)%vector, &
01176 mp%coords_pointer%coords_dble(1)%vector, &
01177 mp%coords_pointer%coords_dble(2)%vector, &
01178 mp%coords_pointer%coords_dble(3)%vector, &
01179 mp%coords_pointer%coords_shape, &
01180 mask_array, mask_shape, use_mask, &
01181 sinvec%vector, cosvec%vector, &
01182 grid_valid_shape, search_mode, &
01183 send_info%srclocs(1,1)%vector, &
01184 ncpl, nprev, len_cpl (ipart), &
01185 neighbors_3d, nb_neighbors, &
01186 extra_search, ierror)
01187 if (ierror > 0) return
01188
01189 nprev = nprev + len_cpl (ipart)
01190 end if
01191 end do
01192
01193 else
01194 do ipart = 1, search%npart
01195 if (len_cpl (ipart) > 0) then
01196
01197 call psmile_neigh_near_irreg2_dble (grid_id, &
01198 tgt_grid(1)%vector(nprev+1:), &
01199 tgt_grid(2)%vector(nprev+1:), &
01200 tgt_grid(3)%vector(nprev+1:), &
01201 mp%coords_pointer%coords_dble(1)%vector, &
01202 mp%coords_pointer%coords_dble(2)%vector, &
01203 mp%coords_pointer%coords_dble(3)%vector, &
01204 mp%coords_pointer%coords_shape, &
01205 mask_array, mask_shape, use_mask, &
01206 sinvec%vector, cosvec%vector, &
01207 grid_valid_shape, search_mode, &
01208 send_info%srclocs(indl, ipart)%vector, &
01209 send_info%srclocs(indz, ipart)%vector, &
01210 send_info%npoints(1:indz, ipart), &
01211 ncpl, nprev, &
01212 neighbors_3d, nb_neighbors, &
01213 extra_search, ierror)
01214
01215 if (ierror > 0) return
01216
01217 nprev = nprev + len_cpl (ipart)
01218 end if
01219 end do
01220 endif
01221
01222
01223
01224
01225
01226 case (PSMILe_trilinear, PSMILe_bilinear, PSMILe_bicubic)
01227
01228
01229 interpolation_mode = 3
01230 search_mode = 3
01231
01232 if (interpolation_methods(j) == PSMILe_bilinear .or. &
01233 interpolation_methods(j) == PSMILe_bicubic) then
01234 if (interpolation_methods(j+1) == PSMILe_linear) then
01235 j = j + 1
01236
01237
01238
01239
01240 search_mode = 3
01241 else
01242
01243 interpolation_mode = 2
01244 search_mode = 2
01245 endif
01246 endif
01247
01248 if (send_info%nvec == 1) then
01249
01250
01251 if ( cubic ) then
01252 call psmile_neigh_tricu_3d ( &
01253 grid_valid_shape, &
01254 interpolation_mode, grid_info%cyclic, &
01255 send_info%srclocs(1,1)%vector, &
01256 ncpl, neighbors_3d, nb_neighbors, &
01257 ierror)
01258 else
01259 call psmile_neigh_trili_3d ( &
01260 grid_valid_shape, &
01261 interpolation_mode, grid_info%cyclic, &
01262 send_info%srclocs(1,1)%vector, &
01263 ncpl, neighbors_3d, nb_neighbors, &
01264 ierror)
01265 endif
01266 if (ierror /= 0) return
01267
01268 else
01269 nprev = 0
01270
01271 do ipart = 1, search%npart
01272 if (len_cpl (ipart) > 0) then
01273
01274 if ( cubic ) then
01275 call psmile_neigh_tricu_irreg2 ( &
01276 grid_valid_shape, &
01277 interpolation_mode, grid_info%cyclic, &
01278 send_info%srclocs(indl, ipart)%vector, &
01279 send_info%srclocs(indz, ipart)%vector, &
01280 send_info%npoints(1:indz, ipart), &
01281 ncpl, nprev, &
01282 neighbors_3d, nb_neighbors, ierror)
01283 else
01284 call psmile_neigh_trili_irreg2 ( &
01285 grid_valid_shape, &
01286 interpolation_mode, grid_info%cyclic, &
01287 send_info%srclocs(indl, ipart)%vector, &
01288 send_info%srclocs(indz, ipart)%vector, &
01289 send_info%npoints(1:indz, ipart), &
01290 ncpl, nprev, &
01291 neighbors_3d, nb_neighbors, ierror)
01292 endif
01293
01294 if (ierror /= 0) return
01295
01296 nprev = nprev + len_cpl (ipart)
01297 end if
01298 end do
01299
01300 endif
01301
01302
01303
01304
01305
01306
01307
01308 case (PSMILe_conserv2D)
01309
01310 Allocate(nbr_cells(ncpl))
01311
01312
01313 interpolation_mode = 3
01314
01315 corner_shape_3d = 1
01316
01317 do i = 1, ndim_2d
01318 corner_shape_3d(:,i,1) = cp%corner_shape(:,i)
01319 corner_shape_3d(:,i,2) = cp%corner_shape(:,i)
01320 enddo
01321
01322 corner_shape_3d(:,i,3) = cp%corner_shape(:,3)
01323
01324 if (interpolation_methods(j+1) == PSMILe_linear) then
01325 j = j + 1
01326 else
01327
01328 interpolation_mode = 2
01329 search_mode = 2
01330 endif
01331
01332 ipart = search%npart
01333
01334 if (send_info%nvec == 1) then
01335
01336
01337 nbr_corners(1:2) = 4
01338 nbr_corners(3) = 2
01339
01340 call psmile_neigh_cells_3d_dble ( use_how, &
01341 grid_valid_shape, &
01342 interpolation_mode, grid_info%cyclic, &
01343 corner_shape_3d, nbr_corners, &
01344 cp%corners_dble(1)%vector, &
01345 cp%corners_dble(2)%vector, &
01346 cp%corners_dble(3)%vector, &
01347 search, control, tgt_cell, tgt_corners, &
01348 send_info%npoints(1,1), &
01349 send_info%srclocs(1,1)%vector, &
01350 send_info%msklocs(1,1)%vector, &
01351 ncpl, nb_neighbors, nbr_cells, ierror )
01352 if (ierror /= 0) return
01353
01354 else if (send_info%nvec == 2) then
01355
01356
01357
01358 nbr_corners(1:2) = 4
01359 nbr_corners(3) = 2
01360
01361 call psmile_neigh_cells_irreg2_dble ( use_how, &
01362 grid_valid_shape, interpolation_mode, &
01363 grid_info%cyclic, &
01364 corner_shape_3d, nbr_corners, &
01365 cp%corners_dble(1)%vector, &
01366 cp%corners_dble(2)%vector, &
01367 search, control, tgt_cell, tgt_corners(1), &
01368 send_info%npoints(1:indz, 1:ipart), &
01369 send_info%srclocs(1:indz, 1:ipart), &
01370 send_info%msklocs(1:indz, 1:ipart), &
01371 ncpl, nb_neighbors, nbr_cells, ierror )
01372
01373 if (ierror /= 0) return
01374
01375 else if (send_info%nvec == ndim_3d) then
01376
01377 if (send_info%nloc > 0) then
01378 call psmile_neigh_cells_3d_reg_dble ( &
01379 grid_valid_shape, &
01380 interpolation_mode, grid_info%cyclic, &
01381 grid_id, search, coords, &
01382 send_info%npoints(1:ndim_3d, 1:ipart), &
01383 send_info%srclocs(1:ndim_3d, 1:ipart), &
01384 ncpl, nbr_cells, ierror )
01385
01386 if (ierror /= 0) return
01387 end if
01388
01389 endif
01390
01391 if ( associated(search%boundary_cell) .and. global_cell_search ) then
01392
01393 nprev = 0
01394 nn = 1
01395
01396 len = size(search%boundary_cell(:,1))
01397
01398 do ipart = 1, search%npart
01399
01400 if (len_cpl (ipart) > 0) then
01401
01402 ibeg = nprev + 1
01403 iend = nprev + len_cpl (ipart)
01404
01405 if ( search%grid_type == PRISM_Irrlonlat_regvrt ) then
01406
01407 leni = shape(2,1,ipart)-shape(1,1,ipart)+1
01408
01409
01410
01411
01412
01413
01414 do jpart = ibeg, iend, 5000
01415 do j = jpart, min(iend,jpart+5000-1)
01416
01417 if ( dstijk(1,j) /= PSMILe_Undef .and. &
01418 dstijk(2,j) /= PSMILe_Undef .and. &
01419 nn <= len ) then
01420
01421 n = (dstijk(2,j)-shape(1,2,ipart))*leni + &
01422 dstijk(1,j)-shape(1,1,ipart)+1
01423
01424 if ( j == search%boundary_cell(nn,1) ) then
01425 n2 = ( n-1) / leni + 1
01426 n1 = n - (n2-1)*leni
01427 search%boundary_cell(nn,2) = &
01428 n1 + search%global_index(ipart)%vector(1)
01429 search%boundary_cell(nn,3) = &
01430 n2 + search%global_index(ipart)%vector(3)
01431 search%boundary_cell(nn,4) = &
01432 dstijk(3,j)-shape(1,3,ipart)+1 + &
01433 search%global_index(ipart)%vector(5)
01434 nn = nn + 1
01435 endif
01436
01437 endif
01438 enddo
01439 enddo
01440
01441 else if ( search%grid_type == PRISM_Reglonlatvrt ) then
01442
01443
01444
01445
01446
01447
01448 do jpart = ibeg, iend, 5000
01449 do j = jpart, min(iend,jpart+5000-1)
01450
01451 if ( dstijk(1,j) /= PSMILe_Undef .and. &
01452 dstijk(2,j) /= PSMILe_Undef .and. &
01453 nn <= len ) then
01454
01455 if ( j == search%boundary_cell(nn,1) ) then
01456
01457 search%boundary_cell(nn,2) = dstijk(1,j)-shape(1,1,ipart)+1 + &
01458 search%global_index(ipart)%vector(1)
01459 search%boundary_cell(nn,3) = dstijk(2,j)-shape(1,2,ipart)+1 + &
01460 search%global_index(ipart)%vector(3)
01461 search%boundary_cell(nn,4) = dstijk(3,j)-shape(1,3,ipart)+1 + &
01462 search%global_index(ipart)%vector(5)
01463 nn = nn + 1
01464 endif
01465
01466 endif
01467 enddo
01468 enddo
01469
01470 else if ( search%grid_type == PRISM_Gaussreduced_regvrt ) then
01471
01472
01473
01474
01475
01476
01477 do jpart = ibeg, iend, 5000
01478 do j = jpart, min(iend,jpart+5000-1)
01479
01480 if ( dstijk(1,j) /= PSMILe_Undef .and. &
01481 dstijk(2,j) /= PSMILe_Undef .and. &
01482 nn <= len ) then
01483
01484 if ( j == search%boundary_cell(nn,1) ) then
01485
01486 search%boundary_cell(nn,2) = dstijk(1,j)-shape(1,1,ipart)+1 + &
01487 search%global_index(ipart)%vector(1)
01488 search%boundary_cell(nn,3) = 1
01489 search%boundary_cell(nn,4) = dstijk(3,j)-shape(1,3,ipart)+1 + &
01490 search%global_index(ipart)%vector(5)
01491 nn = nn + 1
01492 endif
01493
01494 endif
01495 enddo
01496 enddo
01497
01498 else
01499
01500
01501
01502
01503 ierrp (1) = search%grid_type
01504 ierror = PRISM_Error_Internal
01505 call psmile_error ( ierror, 'unsupported grid type', &
01506 ierrp, 1, __FILE__, __LINE__ )
01507 return
01508
01509 endif
01510
01511 nprev = iend
01512
01513 endif
01514
01515 enddo
01516
01517 endif
01518
01519 if ( global_cell_search ) &
01520 call psmile_global_search_cell_dble ( grid_id, var_id, &
01521 comp_info, send_info, search, extra_search, ncpl, &
01522 nbr_cells, n_intmethods, interpolation_methods, &
01523 interpolation_search, ierror )
01524
01525 if ( associated(search%boundary_cell) .and. global_cell_search ) then
01526
01527
01528
01529
01530
01531 new_len_cpl = len_cpl
01532 new_ncpl = send_info%nloc
01533
01534 if ( new_ncpl < ncpl ) then
01535
01536
01537
01538 allocate(new_nbr_cells(new_ncpl), new_dstijk(3,new_ncpl), stat = ierror)
01539 if ( ierror > 0 ) then
01540 ierrp (1) = ierror
01541 ierrp (2) = send_info%nloc
01542
01543 ierror = PRISM_Error_Alloc
01544 call psmile_error ( ierror, 'new_nbr_cell, new_dstijk', &
01545 ierrp, 2, __FILE__, __LINE__ )
01546 return
01547 endif
01548
01549 do i = 1, ndim_3d
01550 Allocate (new_tgt_cell(i)%vector(new_ncpl*tgt_corners(i)), stat = ierror)
01551 if ( ierror > 0 ) then
01552 ierrp (1) = ierror
01553 ierrp (2) = send_info%nloc*tgt_corners(i)
01554
01555 ierror = PRISM_Error_Alloc
01556 call psmile_error ( ierror, 'new_tgt_cell(i)%vector', &
01557 ierrp, 2, __FILE__, __LINE__ )
01558 return
01559 endif
01560 end do
01561
01562 nn = 1
01563
01564 ipart = 1
01565
01566 ibeg = 1
01567 iend = len_cpl (ipart)
01568
01569 nprev = iend
01570
01571
01572
01573 do n = 1, ncpl
01574
01575 if ( n > iend ) then
01576 ipart = ipart + 1
01577 ibeg = nprev + 1
01578 iend = nprev + len_cpl (ipart)
01579 nprev = iend
01580 endif
01581
01582
01583
01584
01585
01586
01587
01588
01589
01590
01591 if ( nbr_cells(n) > 0 ) then
01592 new_nbr_cells(nn) = nbr_cells(n)
01593 new_dstijk(:,nn) = dstijk(:,n)
01594 nn = nn + 1
01595 else
01596 new_len_cpl(ipart) = new_len_cpl(ipart) - 1
01597 endif
01598
01599 enddo
01600
01601 len_cpl = new_len_cpl
01602
01603 do i = 1, ndim_2d
01604 nn = 1
01605 do n = 1, ncpl
01606 if ( nbr_cells(n) > 0 ) then
01607 #ifdef DEBUGX
01608 print *, ' - shift tgt cell idx ', n , ' -> ', nn
01609 #endif
01610 new_tgt_cell(i)%vector(0*new_ncpl+nn) = tgt_cell(i)%vector(0*ncpl+n)
01611 new_tgt_cell(i)%vector(1*new_ncpl+nn) = tgt_cell(i)%vector(1*ncpl+n)
01612 new_tgt_cell(i)%vector(2*new_ncpl+nn) = tgt_cell(i)%vector(2*ncpl+n)
01613 new_tgt_cell(i)%vector(3*new_ncpl+nn) = tgt_cell(i)%vector(3*ncpl+n)
01614 nn = nn + 1
01615 endif
01616 enddo
01617 enddo
01618
01619 do n = 1, ncpl
01620 nn = 1
01621 if ( nbr_cells(n) > 0 ) then
01622 do n3 = 0, nb_neighbors-1
01623 new_tgt_cell(3)%vector(n3*new_ncpl+nn) = tgt_cell(3)%vector(n3*ncpl+n)
01624 enddo
01625 nn = nn + 1
01626 endif
01627 enddo
01628
01629
01630
01631 deallocate(nbr_cells, send_info%dstijk)
01632 do i = 1, ndim_3d
01633 deallocate(tgt_cell(i)%vector)
01634 enddo
01635
01636 Allocate(send_info%dstijk(3,new_ncpl), stat = ierror)
01637 if ( ierror > 0 ) then
01638 ierrp (1) = ierror
01639 ierrp (2) = send_info%nloc
01640
01641 ierror = PRISM_Error_Alloc
01642 call psmile_error ( ierror, 'send_info%dstijk', &
01643 ierrp, 2, __FILE__, __LINE__ )
01644 return
01645 endif
01646
01647 nbr_cells => new_nbr_cells
01648
01649 tgt_cell(1)%vector => new_tgt_cell(1)%vector
01650 tgt_cell(2)%vector => new_tgt_cell(2)%vector
01651 tgt_cell(3)%vector => new_tgt_cell(3)%vector
01652
01653 send_info%dstijk = new_dstijk
01654
01655 Deallocate(new_dstijk)
01656
01657 ncpl = send_info%nloc
01658
01659 endif
01660
01661 endif
01662
01663 #ifdef TODO
01664 case (PSMILe_conserv3D)
01665
01666
01667 interpolation_mode = 3
01668 search_mode = 3
01669
01670 corner_shape_3d = 1
01671
01672 if (search%grid_type == PRISM_Irrlonlat_regvrt) then
01673 do i = 1, ndim_2d
01674 corner_shape_3d(:,i,1) = cp%corner_shape(:,i)
01675 corner_shape_3d(:,i,2) = cp%corner_shape(:,i)
01676 enddo
01677 corner_shape_3d(:,i,3) = cp%corner_shape(:,3)
01678 else if (search%grid_type == PRISM_Irrlonlatvrt) then
01679 do i = 1, ndim_3d
01680 corner_shape_3d(:,:,i) = cp%corner_shape(:,:)
01681 enddo
01682 else if (search%grid_type == PRISM_Reglonlatvrt) then
01683 do i = 1, ndim_3d
01684 corner_shape_3d(:,i,i) = cp%corner_shape(:,i)
01685 enddo
01686 else if (search%grid_type == PRISM_Gaussreduced_regvrt) then
01687 do i = 1, ndim_3d
01688 corner_shape_3d(:,i,i) = cp%corner_shape(:,i)
01689 enddo
01690 else
01691
01692
01693
01694 ierrp (1) = search%grid_type
01695 ierror = PRISM_Error_Internal
01696 call psmile_error ( ierror, 'unsupported grid type', &
01697 ierrp, 1, __FILE__, __LINE__ )
01698 return
01699
01700 endif
01701
01702 if (send_info%nvec == 1) then
01703
01704
01705 nbr_corners(1:2) = 4
01706 nbr_corners(3) = 2
01707
01708 call psmile_neigh_cells_3d_dble ( use_how, &
01709 grid_valid_shape, &
01710 interpolation_mode, grid_info%cyclic, &
01711 corner_shape_3d, nbr_corners, &
01712 cp%corners_dble(1)%vector, &
01713 cp%corners_dble(2)%vector, &
01714 cp%corners_dble(3)%vector, &
01715 search, control, tgt_cell, tgt_corners, &
01716 send_info%npoints(1,1), &
01717 send_info%srclocs(1,1)%vector, &
01718 send_info%msklocs(1,1)%vector, &
01719 ncpl, nb_neighbors, nbr_cells, ierror )
01720 if (ierror /= 0) return
01721
01722 else if (send_info%nvec == 2) then
01723
01724
01725
01726 nbr_corners = 4
01727
01728 call psmile_neigh_cells_irreg2_dble ( use_how, &
01729 grid_valid_shape, interpolation_mode, &
01730 grid_info%cyclic, &
01731 corner_shape_3d, nbr_corners, &
01732 cp%corners_dble(1)%vector, &
01733 cp%corners_dble(2)%vector, &
01734 search, control, tgt_cell, tgt_corners(1), &
01735 send_info%npoints(1:indz, 1:ipart), &
01736 send_info%srclocs(1:indz, 1:ipart), &
01737 send_info%msklocs(1:indz, 1:ipart), &
01738 ncpl, nb_neighbors, nbr_cells, ierror )
01739
01740 if (ierror /= 0) return
01741
01742 else
01743
01744 if (send_info%nloc > 0) then
01745 call psmile_neigh_cells_3d_reg_dble ( &
01746 grid_valid_shape, &
01747 interpolation_mode, grid_info%cyclic, &
01748 grid_id, search, coords, &
01749 send_info%npoints(1:ndim_3d, 1:ipart), &
01750 send_info%srclocs(1:ndim_3d, 1:ipart), &
01751 ncpl, nbr_cells, ierror )
01752
01753 if (ierror /= 0) return
01754 end if
01755
01756 endif
01757 #endif
01758
01759 #ifdef TODO
01760 case (PSMILe_user3D)
01761 call psmile_trs_give_
01762 if (ierror /= 0) return
01763 #endif
01764
01765
01766
01767 case default
01768 ierrp (1) = interpolation_methods (j)
01769 ierror = PRISM_Error_Internal
01770
01771 call psmile_error ( ierror, 'unsupported 3d interpolation method', &
01772 ierrp, 1, __FILE__, __LINE__ )
01773 return
01774 end select
01775
01776
01777
01778 j = j + 1
01779 end do
01780
01781 #ifdef DEBUG_TRACE
01782 if ( use_target_grid ) then
01783
01784
01785 do ictl = 1, ncpl
01786 if (dstijk (1, ictl) == ictl_ind (1) .and. &
01787 dstijk (2, ictl) == ictl_ind (2) .and. &
01788 dstijk (3, ictl) == ictl_ind (3)) exit
01789 end do
01790
01791 if (ictl <= ncpl) then
01792 print *, 'vor global search: ictl, dstijk (:, i)', &
01793 ictl, ';', dstijk (:, ictl)
01794 print *, 'ictl target coord', ictl, tgt_grid(1)%vector(ictl), &
01795 tgt_grid(2)%vector(ictl), &
01796 tgt_grid(3)%vector(ictl)
01797
01798 do i = 1, nb_neighbors
01799 print *, 'neighbors_3d (:, ictl)', neighbors_3d (:, ictl, i)
01800 end do
01801 else
01802 print *, 'psmile_info_trs_irreg2_dble: ictl_ind not found', ictl_ind
01803 endif
01804 endif
01805 #endif
01806
01807
01808
01809
01810 if (global_search) then
01811 if (interpolation_methods(1) /= PSMILe_nnghbr3D .and. &
01812 interpolation_methods(1) /= PSMILe_nnghbr2D) then
01813
01814
01815
01816 call psmile_neigh_global_points (search, extra_search, &
01817 mask_array, mask_shape, src_mask_available, use_how(1), &
01818 grid_id, grid_valid_shape, &
01819 neighbors_3d, ncpl, nb_neighbors, len_cpl, ierror)
01820 if (ierror > 0) return
01821
01822 if (extra_search%n_req > 0) then
01823
01824 call psmile_global_search_dble (comp_info, &
01825 control, len_cpl, &
01826 var_id, grid_valid_shape, search, tgt_grid, &
01827 neighbors_3d, ncpl, nb_neighbors, extra_search, &
01828 interpolation_methods, interpolation_search, &
01829 n_intmethods, &
01830 send_index, src_mask_available, use_mask, &
01831 use_how(1), PRISM_Irrlonlat_Regvrt, ierror)
01832 if (ierror > 0) return
01833 endif
01834
01835 else
01836
01837
01838
01839 endif
01840 endif
01841
01842 #ifdef DEBUG_TRACE
01843 if (ictl <= ncpl .and. use_target_grid) then
01844 print *, 'after global_search: i, dstijk (:, i)', ictl, dstijk (:, ictl)
01845
01846 do i = 1, nb_neighbors
01847 print *, 'neighbors_3d (:, ictl)', neighbors_3d (:, ictl, i)
01848 end do
01849 endif
01850 #endif
01851
01852
01853
01854
01855 if (interpolation_methods(1) /= PSMILe_nnghbr3D) then
01856 call psmile_neigh_extra_points (search, extra_search, &
01857 mask_array, mask_shape, src_mask_available, use_how, &
01858 grid_valid_shape, &
01859 neighbors_3d, ncpl, nb_neighbors, len_cpl, ierror)
01860 if (ierror > 0) return
01861 endif
01862
01863 #ifdef DEBUG_TRACE
01864 if (ictl <= ncpl .and. use_target_grid) then
01865 print *, 'after neigh_extra: ictl, dstijk (:, ictl)', ictl, dstijk (:, ictl)
01866
01867 do i = 1, nb_neighbors
01868 print *, 'neighbors_3d (:, ictl)', neighbors_3d (:, ictl, i)
01869 end do
01870 endif
01871 #endif
01872
01873
01874
01875 if (extra_search%n_extra > 0) then
01876
01877
01878
01879
01880 if (global_search) then
01881 call psmile_neigh_extra_search_dble (search, extra_search, &
01882 nb_extra, ierror)
01883 if (ierror > 0) return
01884 endif
01885
01886
01887
01888
01889 search_mode = 2
01890
01891 nprev = 0
01892
01893
01894
01895 if (.not. transformed) then
01896 call psmile_info_coords_irreg2_dble ( &
01897 mp%coords_pointer%coords_dble(1)%vector, &
01898 mp%coords_pointer%coords_dble(2)%vector, &
01899 mp%coords_pointer%coords_dble(3)%vector, &
01900 mp%coords_pointer%coords_shape, &
01901 grid_valid_shape, &
01902 sinvec, cosvec, ierror)
01903 if (ierror > 0) return
01904
01905 transformed = .true.
01906 endif
01907
01908
01909
01910 if (send_info%nvec == 1) then
01911
01912 do ipart = 1, search%npart
01913 if (len_cpl (ipart) > 0) then
01914
01915 call psmile_neigh_nearx_irr2_3d_dble (grid_id, &
01916 tgt_grid(1)%vector, &
01917 tgt_grid(2)%vector, &
01918 tgt_grid(3)%vector, &
01919 mp%coords_pointer%coords_dble(1)%vector, &
01920 mp%coords_pointer%coords_dble(2)%vector, &
01921 mp%coords_pointer%coords_dble(3)%vector, &
01922 mp%coords_pointer%coords_shape, &
01923 mask_array, mask_shape, src_mask_available, &
01924 sinvec%vector, cosvec%vector, &
01925 grid_valid_shape, search_mode, &
01926 send_info%srclocs(1,1)%vector, &
01927 ncpl, nprev, len_cpl (ipart), &
01928 neighbors_3d, nb_extra, &
01929 extra_search, ierror)
01930
01931 if (ierror > 0) return
01932
01933 nprev = nprev + len_cpl (ipart)
01934 end if
01935 end do
01936 #ifdef DEBUG_TRACE
01937 if (ictl <= ncpl .and. use_target_grid) then
01938 print *, 'after PSMILe_Neigh_nearx_irr2_3d_dble'
01939 print *, 'ictl, dstijk (:, ictl)', ictl, dstijk (:, ictl)
01940
01941 do i = 1, nb_neighbors
01942 print *, 'neighbors_3d (:, ictl)', neighbors_3d (:, ictl, i)
01943 end do
01944 endif
01945 #endif
01946 else
01947
01948 do ipart = 1, search%npart
01949 if (len_cpl (ipart) > 0) then
01950
01951 call psmile_neigh_nearx_irreg2_dble (grid_id, &
01952 tgt_grid(1)%vector, tgt_grid(2)%vector, &
01953 tgt_grid(3)%vector, &
01954 mp%coords_pointer%coords_dble(1)%vector, &
01955 mp%coords_pointer%coords_dble(2)%vector, &
01956 mp%coords_pointer%coords_dble(3)%vector, &
01957 mp%coords_pointer%coords_shape, &
01958 mask_array, mask_shape, src_mask_available, &
01959 sinvec%vector, cosvec%vector, &
01960 grid_valid_shape, search_mode, &
01961 send_info%srclocs(indl, ipart)%vector, &
01962 send_info%srclocs(indz, ipart)%vector, &
01963 send_info%npoints(1:indz, ipart), &
01964 ncpl, nprev, &
01965 neighbors_3d, nb_extra, &
01966 extra_search, ierror)
01967
01968 if (ierror > 0) return
01969
01970 nprev = nprev + len_cpl (ipart)
01971 end if
01972 end do
01973 endif
01974
01975
01976
01977
01978 #ifdef DEBUG_TRACE
01979 if (ictl <= ncpl .and. use_target_grid) then
01980 print *, 'before PSMILe_global_search_nnx_dble'
01981 print *, 'ictl, dstijk (:, ictl)', ictl, dstijk (:, ictl)
01982
01983 do i = 1, nb_neighbors
01984 print *, 'neighbors_3d (:, ictl)', neighbors_3d (:, ictl, i)
01985 end do
01986 endif
01987 #endif
01988 if (global_search) then
01989 call psmile_global_search_nnx_dble (comp_info, &
01990 search, var_id, &
01991 tgt_grid(1)%vector, &
01992 tgt_grid(2)%vector, &
01993 tgt_grid(3)%vector, &
01994 neighbors_3d, ncpl, nb_neighbors, nb_extra, &
01995 extra_search, send_index, ierror)
01996 if (ierror > 0) return
01997 endif
01998 #ifdef DEBUG_TRACE
01999 if (ictl <= ncpl .and. use_target_grid) then
02000 print *, 'after PSMILe_global_search_nnx_dble'
02001 print *, 'ictl, dstijk (:, ictl)', ictl, dstijk (:, ictl)
02002
02003 do i = 1, nb_neighbors
02004 print *, 'neighbors_3d (:, ictl)', neighbors_3d (:, ictl, i)
02005 end do
02006 endif
02007 #endif
02008
02009
02010
02011 call psmile_neigh_extra_search_clean (search, extra_search, ierror)
02012 endif
02013
02014
02015
02016
02017 if (transformed) then
02018 Deallocate (cosvec%vector)
02019 Deallocate (sinvec%vector)
02020 endif
02021
02022
02023
02024
02025
02026
02027 if ( use_source_cell ) then
02028
02029 nbr_cells_tot = sum(nbr_cells)
02030 nb_corners = nb_neighbors
02031
02032
02033
02034
02035 if ( nbr_cells_tot == 0 ) then
02036 send_index = PRISM_UNDEFINED
02037 go to 1100
02038 endif
02039
02040 Allocate (neighcells(nbr_cells_tot, nb_corners), &
02041 source_cell_index(nbr_cells_tot), STAT = ierror)
02042 if ( ierror > 0 ) then
02043 ierrp (1) = ierror
02044 ierrp (2) = nbr_cells_tot * ( nb_corners + 1 )
02045 ierror = PRISM_Error_Alloc
02046 call psmile_error ( ierror, 'neighcells & source_cell_index', &
02047 ierrp, 2, __FILE__, __LINE__ )
02048 return
02049 endif
02050
02051
02052
02053
02054
02055
02056
02057
02058 nb_corners = 1
02059
02060 call psmile_compact_neighbors_3d (neighcells_3d, nbr_cells_tot, &
02061 nb_corners, grid_valid_shape, &
02062 extra_search, send_info, &
02063 neighcells, ierror)
02064 #ifdef move0_for_cells
02065
02066
02067
02068
02069
02070
02071
02072 call psmile_move0_neighbors (neighcells, nbr_cells_tot, nb_corners, &
02073 ierror)
02074 if (ierror > 0) return
02075 #endif /* move0_for_cells */
02076
02077
02078
02079 src_cell_size = send_info%n_list * nb_neighbors
02080
02081 do i = 1, ndim_3d
02082 Allocate (src_cell(i)%vector(src_cell_size), stat = ierror)
02083 if ( ierror > 0 ) then
02084 ierrp (1) = ierror
02085 ierrp (2) = src_cell_size
02086
02087 ierror = PRISM_Error_Alloc
02088 call psmile_error ( ierror, 'src_cell(i)%vector', &
02089 ierrp, 2, __FILE__, __LINE__ )
02090 return
02091 endif
02092 end do
02093
02094
02095
02096
02097 corner_shape(1:2,1:2) = cp%corner_shape(1:2,1:2)
02098 corner_shape(:,3) = mp%coords_pointer%coords_shape(:,3)
02099
02100 call psmile_ccompact_irreg2_dble ( &
02101 send_info, grid_valid_shape, &
02102 corner_shape, cp%nbr_corners/2, &
02103 cp%corners_dble(1)%vector, &
02104 cp%corners_dble(2)%vector, &
02105 mp%coords_pointer%coords_dble(3)%vector, &
02106 extra_search, &
02107 src_cell_size, nbr_cells_tot, &
02108 source_cell_index, &
02109 neighcells, &
02110 src_cell(1)%vector, &
02111 src_cell(2)%vector, &
02112 src_cell(3)%vector, ierror )
02113 if (ierror /= 0) return
02114
02115 if (associated(neighcells_3d)) Deallocate (neighcells_3d)
02116
02117 else
02118
02119
02120
02121 Allocate (neighbors(ncpl, nb_neighbors), STAT = ierror)
02122 if ( ierror > 0 ) then
02123 ierrp (1) = ierror
02124 ierrp (2) = ncpl * nb_neighbors
02125
02126 ierror = PRISM_Error_Alloc
02127 call psmile_error ( ierror, 'neighbors', &
02128 ierrp, 2, __FILE__, __LINE__ )
02129 return
02130 endif
02131
02132 #ifdef DEBUG_TRACE
02133 if (ictl <= ncpl .and. use_target_grid) then
02134 print *, 'before compact neighbors_3d'
02135 print *, 'ictl, dstijk (:, ictl)', ictl, dstijk (:, ictl)
02136
02137 do i = 1, nb_neighbors
02138 print *, 'neighbors_3d (:, ictl)', neighbors_3d (:, ictl, i)
02139 end do
02140 endif
02141 #endif
02142 call psmile_compact_neighbors_3d (neighbors_3d, ncpl, &
02143 nb_neighbors, grid_valid_shape, &
02144 extra_search, send_info, &
02145 neighbors, ierror)
02146 if (ierror /= 0) return
02147 #ifdef DEBUG_TRACE
02148 if (ictl <= ncpl .and. use_target_grid) then
02149 print *, 'after compact neighbors_3d'
02150 print *, 'ictl, dstijk (:, ictl)', ictl, dstijk (:, ictl)
02151
02152 do i = 1, nb_neighbors
02153 print *, 'neighbors_3d (:, ictl)', neighbors_3d (:, ictl, i)
02154 end do
02155 endif
02156 #endif
02157
02158
02159
02160 if (interpolation_methods(1) /= PSMILe_nnghbr3D) then
02161 call psmile_move0_neighbors (neighbors, ncpl, nb_neighbors, &
02162 ierror)
02163 if (ierror > 0) return
02164 endif
02165
02166 #ifdef DEBUG_TRACE
02167 if (ictl <= ncpl .and. use_target_grid) then
02168 print *, 'ictl, dstijk (:, ictl)', ictl, dstijk (:, ictl)
02169
02170 do i = 1, nb_neighbors
02171 print *, 'neighbors_3d (:, ictl)', neighbors_3d (:, ictl, i)
02172 end do
02173
02174 print *, 'neighbors (ictl)', neighbors (ictl, 1:nb_neighbors)
02175 if (allocated (ictl_neighbours)) deallocate (ictl_neighbours)
02176 allocate (ictl_neighbours(nb_neighbors))
02177 ictl_neighbours (1:nb_neighbors) = neighbors (ictl, 1:nb_neighbors)
02178 endif
02179 #endif
02180 Deallocate (neighbors_3d, STAT = ierror)
02181 if ( ierror > 0 ) then
02182 ierrp (1) = ierror
02183 ierrp (2) = ndim_3d*ncpl*nb_neighbors
02184
02185 ierror = PRISM_Error_Dealloc
02186 call psmile_error ( ierror, 'neighbors_3d', &
02187 ierrp, 2, __FILE__, __LINE__ )
02188 return
02189 endif
02190
02191 endif
02192
02193
02194
02195
02196
02197
02198
02199
02200
02201
02202
02203
02204
02205
02206
02207
02208
02209 if ( use_target_cell ) then
02210 if ( send_info%nvec == 1 ) then
02211 send_info%npoints(1,1) = sum(len_cpl(1:search%npart))
02212 else if ( send_info%nvec == 2 ) then
02213 do ipart = 1, search%npart
02214 if ( send_info%npoints(indz,ipart) /= 0 ) then
02215 send_info%npoints(indl,ipart) = len_cpl (ipart)/ &
02216 send_info%npoints(indz,ipart)
02217 else
02218 send_info%npoints(indl,ipart) = 0
02219 endif
02220 enddo
02221 endif
02222 endif
02223
02224 src_size = send_info%n_list
02225 local_src_size = src_size - send_info%num2recv
02226
02227
02228
02229 if ( src_size == 0 ) then
02230 send_index = PRISM_UNDEFINED
02231
02232 go to 1000
02233 endif
02234
02235
02236
02237
02238
02239
02240
02241
02242
02243
02244
02245
02246
02247
02248
02249 if ( use_source_cell .and. src_mask_available) then
02250 use_mask = .false.
02251 id_src_mask = 1
02252
02253 Allocate (src_mask(src_size), stat = ierror)
02254 if ( ierror > 0 ) then
02255 ierrp (1) = ierror
02256 ierrp (2) = src_size
02257
02258 ierror = PRISM_Error_Alloc
02259 call psmile_error ( ierror, 'src_mask', &
02260 ierrp, 2, __FILE__, __LINE__ )
02261 return
02262 endif
02263
02264
02265
02266
02267 call psmile_ext_compact_list_log2int (send_info, &
02268 extra_search, mask_array, mask_shape, &
02269 grid_valid_shape, src_mask, src_size, ierror)
02270 if (ierror /= 0) return
02271
02272 else
02273
02274 id_src_mask = 0
02275 src_mask => dummy_mask
02276
02277 endif
02278
02279 #ifdef DEBUGX
02280 if ( use_source_cell ) then
02281 nn = 0
02282 do n = 1, ncpl
02283 write( * ,'(a,i8)') ' Target cell ', n
02284 do i = 1, tgt_corners(1)
02285 write( * ,'(i6,3f8.3)' ) i, tgt_cell(1)%vector((i-1)*ncpl+n), &
02286 tgt_cell(2)%vector((i-1)*ncpl+n), &
02287 tgt_cell(3)%vector((i-1)*ncpl+n)
02288 enddo
02289 write( * ,'(a)') ' -------------------------- '
02290 do j = 1, nbr_cells(n)
02291 do i = 1, tgt_corners(1)
02292 n1 = neighcells(nn+j,i)
02293 write( * ,'(i6, 3f8.3)' ) n1, src_cell(1)%vector(n1), &
02294 src_cell(2)%vector(n1), &
02295 src_cell(3)%vector(n1)
02296 enddo
02297 if ( src_mask_available ) then
02298 n2 = neighcells(nn+j,1)
02299 write( * ,'(a,l1)' ) 'Mask set to ', src_mask(n2)
02300 endif
02301 write( * ,'(a)' ) ' ......................... '
02302
02303 enddo
02304 nn = nn + nbr_cells(n)
02305 write( * ,'(a)' ) ' ========================== '
02306 enddo
02307 endif
02308 #endif /* DEBUGX */
02309
02310
02311
02312
02313
02314
02315 if ( .not. use_source_cell ) then
02316
02317 do i = 1, ndim_3d
02318 Allocate (src_grid(i)%vector(src_size), stat = ierror)
02319 if ( ierror > 0 ) then
02320 ierrp (1) = ierror
02321 ierrp (2) = src_size
02322
02323 ierror = PRISM_Error_Alloc
02324 call psmile_error ( ierror, 'src_grid(i)%vector', &
02325 ierrp, 2, __FILE__, __LINE__ )
02326 return
02327 endif
02328 end do
02329
02330
02331
02332 do i = 1, ndim_2d
02333 call psmile_ext_compact_irreg2_dble ( &
02334 send_info, &
02335 mp%coords_pointer%coords_dble(i)%vector, &
02336 mp%coords_pointer%coords_shape, &
02337 grid_valid_shape, &
02338 src_grid(i)%vector, src_size, &
02339 ierror)
02340
02341 if (ierror /= 0) return
02342 end do
02343
02344 if (send_info%send_entire_valid_shape) then
02345
02346 i = 3
02347 shift = grid_valid_shape (1,i) - mp%coords_pointer%coords_shape(1,i)
02348 len = (grid_valid_shape (2,1) - grid_valid_shape (1,1) + 1) * &
02349 (grid_valid_shape (2,2) - grid_valid_shape (1,2) + 1)
02350
02351 do n = 1, local_src_size / len
02352 src_grid(i)%vector((n-1)*len+1:n*len) = &
02353 mp%coords_pointer%coords_dble(i)%vector(shift+n)
02354 end do
02355
02356 else
02357
02358 list_entries => send_info%list_entries
02359
02360 #ifdef PRISM_ASSERTION
02361 if (.not. Associated (list_entries)) then
02362 call psmile_assert (__FILE__, __LINE__, &
02363 "list_entries are not available")
02364 endif
02365 #endif
02366
02367 i = 3
02368 shift = mp%coords_pointer%coords_shape(1,i) - 1
02369
02370 src_grid(i)%vector(1:local_src_size) = &
02371 mp%coords_pointer%coords_dble(i)%vector( &
02372 list_entries(i, 1:local_src_size) - shift)
02373 endif
02374
02375
02376
02377 if (send_info%num2recv > 0) then
02378 do i = 1, ndim_3d
02379 ip = local_src_size
02380
02381 do n = 1, send_info%nrecv
02382 src_grid(i)%vector(ip+1:ip+send_info%len_sent(n)) = &
02383 extra_search%dble_bufs(n)%vector( &
02384 (i-1)*send_info%len_sent(n)+1: &
02385 i *send_info%len_sent(n))
02386
02387 ip = ip + send_info%len_sent (n)
02388 end do
02389 end do
02390
02391 do n = 1, send_info%nrecv
02392 Deallocate (extra_search%dble_bufs(n)%vector)
02393 end do
02394 endif
02395
02396 #ifdef DEBUG_TRACE
02397 if (ictl <= ncpl .and. use_target_grid) then
02398
02399 ipart = 1
02400
02401 if (search%grid_type == PRISM_Reglonlatvrt .or. &
02402 search%grid_type == PRISM_Irrlonlat_regvrt) then
02403 call psmile_print_irreg2_coord_dble (coords(1,ipart)%vector, &
02404 coords(2,ipart)%vector, &
02405 coords(3,ipart)%vector, &
02406 shape (:, :, ipart), &
02407 dstijk (:, ictl), 1, 'searched')
02408 else if (search%grid_type == PRISM_Irrlonlatvrt) then
02409 call psmile_print_3d_coord_dble (coords(1,ipart)%vector, &
02410 coords(2,ipart)%vector, &
02411 coords(3,ipart)%vector, &
02412 shape (:, :, ipart), &
02413 dstijk (:, ictl), 1, 'searched')
02414 endif
02415
02416 print *, 'coords (ictl)'
02417 do i = 1, nb_neighbors
02418 if (neighbors (ictl, i) > 0) then
02419 print *, 'i', i, &
02420 src_grid(1)%vector(neighbors (ictl, i)),&
02421 src_grid(2)%vector(neighbors (ictl, i)),&
02422 src_grid(3)%vector(neighbors (ictl, i))
02423 endif
02424 end do
02425 endif
02426 #endif
02427 endif
02428
02429 interpolation(1:ndim_2d) = interpolation_methods(1:ndim_2d)
02430 interpolation(ndim_3d) = PSMILe_Undef
02431
02432 call psmile_get_epio_handle (field%comp_id, grid_id, method_id, mask_id, &
02433 interpolation, search%msg_intersections, id_trans_out, &
02434 id_trans_in, search%sender, cpl_id, epio_id, trs_rank, ierror)
02435
02436 if ( epio_id /= PSMILe_undef ) then
02437
02438
02439
02440
02441
02442
02443 call psmile_trs_set_triple_links (id_trans_out, id_trans_in, &
02444 epio_id, trs_rank, ierror)
02445 if (ierror /= 0) return
02446
02447
02448
02449 if ( use_source_cell ) then
02450 do i = 1, ndim_3d
02451 Deallocate (src_cell(i)%vector)
02452 end do
02453 else
02454 do i = 1, ndim_3d
02455 Deallocate (src_grid(i)%vector)
02456 end do
02457 endif
02458
02459 if (id_src_mask > 0) then
02460 Deallocate (src_mask)
02461 endif
02462
02463 if ( use_target_cell ) then
02464 do i = 1, ndim_3d
02465 Deallocate (tgt_cell(i)%vector)
02466 end do
02467 else
02468 if (use_target_grid) then
02469 do i = 1, ndim_3d
02470 Deallocate (tgt_grid(i)%vector)
02471 end do
02472 endif
02473 endif
02474
02475 else
02476
02477
02478
02479
02480
02481
02482
02483 if ( use_source_cell ) then
02484 call psmile_trs_set_src_epio3d_dble (epio_id, &
02485 trs_rank, src_size, src_cell_size, &
02486 src_cell(1)%vector, &
02487 src_cell(2)%vector, &
02488 src_cell(3)%vector, &
02489 id_src_mask, src_mask, ierror)
02490
02491
02492
02493 do i = 1, ndim_3d
02494 Deallocate (src_cell(i)%vector)
02495 end do
02496
02497 else
02498
02499 call psmile_trs_set_src_epio3d_dble (epio_id, &
02500 trs_rank, src_size, src_size, &
02501 src_grid(1)%vector, &
02502 src_grid(2)%vector, &
02503 src_grid(3)%vector, &
02504 id_src_mask, src_mask, ierror)
02505
02506
02507
02508 do i = 1, ndim_3d
02509 Deallocate (src_grid(i)%vector)
02510 end do
02511 endif
02512
02513 if (ierror /= 0) return
02514
02515
02516
02517 if (id_src_mask > 0) then
02518 Deallocate (src_mask)
02519 endif
02520
02521
02522
02523
02524
02525
02526
02527
02528 id_tgt_mask = 0
02529
02530 do j = 1, n_intmethods
02531 if ( (interpolation_methods(j) == PSMILe_conserv2D .or. &
02532 interpolation_methods(j) == PSMILe_conserv3D ) .and. &
02533 associated(search%search_mask) ) id_tgt_mask = 0
02534 enddo
02535
02536 if ( id_tgt_mask == 1 ) then
02537
02538 Allocate (tgt_mask(ncpl), stat = ierror)
02539 if ( ierror > 0 ) then
02540 ierrp (1) = ierror
02541 ierrp (2) = ncpl
02542
02543 ierror = PRISM_Error_Alloc
02544 call psmile_error ( ierror, 'tgt_mask', &
02545 ierrp, 2, __FILE__, __LINE__ )
02546 return
02547 endif
02548 tgt_mask = 0
02549 nprev = 0
02550 do ipart = 1, search%npart
02551 if (len_cpl (ipart) > 0) then
02552 ibeg = nprev + 1
02553 iend = nprev + len_cpl (ipart)
02554
02555 leni = shape(2,1,ipart)-shape(1,1,ipart)
02556 lenij = leni * (shape(2,2,ipart)-shape(1,2,ipart))
02557
02558 do j = ibeg, iend
02559
02560 if ( dstijk(1,j) /= PSMILe_Undef .and. &
02561 dstijk(2,j) /= PSMILe_Undef .and. &
02562 dstijk(3,j) /= PSMILe_Undef ) then
02563
02564 n = (dstijk(3,j)-shape(1,3,ipart))*lenij + &
02565 (dstijk(2,j)-shape(1,2,ipart))*leni + &
02566 dstijk(1,j)-shape(1,1,ipart)+1
02567
02568 if ( search%search_mask(ipart)%vector(n) ) tgt_mask(j) = 1
02569
02570 endif
02571
02572 enddo
02573
02574 nprev = nprev + len_cpl (ipart)
02575 endif
02576 end do
02577
02578 else
02579
02580 id_tgt_mask = 0
02581 tgt_mask => dummy_mask
02582
02583 endif
02584
02585
02586
02587 if ( use_target_cell ) then
02588
02589
02590
02591 nb_corners = 4
02592 call psmile_trs_set_tgt_epio3d_dble ( &
02593 epio_id, trs_rank, ncpl, nb_corners, &
02594 tgt_cell(1)%vector, tgt_cell(2)%vector, tgt_cell(3)%vector, &
02595 id_tgt_mask, tgt_mask, ierror)
02596
02597
02598
02599 do i = 1, ndim_3d
02600 Deallocate (tgt_cell(i)%vector)
02601 end do
02602 else
02603
02604 nb_corners = 1
02605 call psmile_trs_set_tgt_epio3d_dble ( &
02606 epio_id, trs_rank, ncpl, nb_corners, &
02607 tgt_grid(1)%vector, tgt_grid(2)%vector, tgt_grid(3)%vector, &
02608 id_tgt_mask, tgt_mask, ierror)
02609
02610
02611
02612 if (use_target_grid) then
02613 do i = 1, ndim_3d
02614 Deallocate (tgt_grid(i)%vector)
02615 end do
02616 endif
02617 endif
02618
02619
02620
02621 if ( id_tgt_mask == 1 ) Deallocate(tgt_mask)
02622
02623
02624
02625
02626
02627 call psmile_trs_set_triple_links (id_trans_out, id_trans_in, &
02628 epio_id, trs_rank, ierror)
02629 if (ierror /= 0) return
02630
02631
02632
02633 if ( use_source_cell ) then
02634 call psmile_trs_give_neighcells3d (epio_id, trs_rank, &
02635 ncpl, nbr_cells, nbr_cells_tot, nb_neighbors, &
02636 source_cell_index, neighcells, grid_info%grid_type, &
02637 ierror)
02638 else
02639 call psmile_trs_give_neighbors3d (epio_id, trs_rank, &
02640 ncpl, nb_neighbors, neighbors, ierror)
02641 endif
02642 if (ierror /= 0) return
02643
02644
02645
02646 cpl_list(cpl_id)%epio_id = epio_id
02647 cpl_list(cpl_id)%trs_rank = trs_rank
02648
02649 endif
02650
02651 send_info%epio_id = epio_id
02652 send_info%trs_rank = trs_rank
02653
02654 #ifdef DEBUG
02655 print * , trim(ch_id), ': psmile_info_trs_loc_irreg2_dble: index, epio_id, n_list', &
02656 send_index, epio_id, send_info%n_list, &
02657 send_info%send_entire_valid_shape
02658 #endif
02659
02660
02661
02662 1000 continue
02663
02664 call psmile_locations_dealloc (send_info, ierror)
02665
02666 if ( use_source_cell ) then
02667 Deallocate (source_cell_index, neighcells, nbr_cells)
02668 else
02669 Deallocate (neighbors)
02670 endif
02671
02672 1100 continue
02673
02674
02675
02676 #ifdef VERBOSE
02677 print 9980, trim(ch_id), ierror
02678
02679 call psmile_flushstd
02680 #endif /* VERBOSE */
02681
02682
02683
02684
02685 #ifdef VERBOSE
02686
02687 9990 format (1x, a, ': psmile_info_trs_loc_irreg2_dble: method_id', i3, &
02688 ' to ', i3, '(', i2)
02689 9980 format (1x, a, ': psmile_info_trs_loc_irreg2_dble: eof ierror =', i3)
02690
02691 9970 format (1x, a, ': psmile_info_trs_loc_irreg2_dble: eof src_size=0, ierror =', i3)
02692
02693 #endif /* VERBOSE */
02694
02695 #ifdef DEBUG
02696 9960 format (1x, 'Taskout%In_channel(', i3, '): origin_type', i5, &
02697 ', remote comp id', i4, &
02698 ', global_transi_id', i4, ', remote_transi_id', i4)
02699 #endif
02700
02701 end subroutine PSMILe_info_trs_loc_irreg2_dble