psmile_search_donor_nnx_dble.F90

Go to the documentation of this file.
00001 !-----------------------------------------------------------------------
00002 ! Copyright 2006-2010, NEC Europe Ltd., London, UK.
00003 ! All rights reserved. Use is subject to OASIS4 license terms.
00004 !-----------------------------------------------------------------------
00005 !BOP
00006 !
00007 ! !ROUTINE: PSMILe_Search_donor_nnx_dble
00008 !
00009 ! !INTERFACE:
00010 
00011       subroutine psmile_search_donor_nnx_dble (comp_info, search, var_id, &
00012                         coords1, coords2, coords3, distance,              &
00013                         nfound, locations, n_send, nb_extra,              &
00014                         tol, ierror)
00015 !
00016 ! !USES:
00017 !
00018       use PRISM
00019 !
00020       use PSMILe, dummy_interface => PSMILe_Search_donor_nnx_dble
00021 
00022       Implicit none
00023 !
00024 ! !INPUT PARAMETERS:
00025 !
00026       Type (Enddef_comp),          Intent (In)    :: comp_info
00027 !
00028 !     Info on the component in which the donor cells
00029 !     should be searched.
00030 
00031       Integer,                     Intent (In)    :: var_id
00032 
00033 !     Handle to the grid function
00034 
00035       Integer,                     Intent (In)    :: n_send
00036 
00037 !     Number of points to be searched
00038 
00039       Double Precision, Intent (In)   :: coords1 (n_send)
00040       Double Precision, Intent (In)   :: coords2 (n_send)
00041       Double Precision, Intent (In)   :: coords3 (n_send)
00042 
00043 !     Coordinates to be searched
00044 
00045       Integer,                     Intent (In)    :: nb_extra
00046 
00047 !     Number of nearest neighbours per point to be searched
00048 
00049       Double Precision,            Intent (In)    :: tol
00050 
00051 !     Absolute tolerance for search of "identical" points
00052 !     TOL >= 0.0
00053 
00054 !
00055 ! !INPUT/OUTPUT PARAMETERS:
00056 !
00057       Type (Enddef_global_search), Intent (InOut) :: search
00058 
00059 !     Data on the points to be searched
00060 
00061       Double Precision, Intent (InOut)            :: distance (n_send)
00062 
00063 !     Nearest neighbour distance already found
00064 !
00065       Integer,                     Intent (InOut) :: nfound (n_send)
00066 !
00067 !     Number of nearest neighbours found per point
00068 !
00069 ! !OUTPUT PARAMETERS:
00070 !
00071       Integer,                     Intent (Out)   :: locations (ndim_3d, n_send)
00072 !
00073 !     Locations of nearest neigbour found
00074 !
00075       Integer,                     Intent (Out)   :: ierror
00076 
00077 !     Returns the error code of PSMILe_Search_donor_nnx_dble;
00078 !             ierror = 0 : No error
00079 !             ierror > 0 : Severe error
00080 !
00081 ! !DEFINED PARAMETERS:
00082 !
00083 !  lon   = Index of Longitudes in arrays "sin_values" and "cos_values"
00084 !  lat   = Index of Latitudes  in arrays "sin_values" and "cos_values"
00085 
00086       Integer, Parameter              :: lon = 1
00087       Integer, Parameter              :: lat = 2
00088 !
00089 ! !LOCAL VARIABLES
00090 !
00091 !     ... loop variables
00092 !
00093 !
00094 !     ... field pointer
00095 !
00096       Type (Gridfunction), Pointer  :: field
00097 !
00098 !     ... Method pointer
00099 !
00100       Integer                       :: method_id
00101       Type (Method),        Pointer :: mp
00102       Type (Coords_Block),  Pointer :: coords_pointer
00103 !
00104 !     ... Grid pointer
00105 !
00106       Type (Grid), Pointer          :: grid_info
00107       Integer                       :: grid_id
00108       Type (dble_vector)            :: cosvec, sinvec
00109       Type (dble_vector)            :: sinvec_reg (ndim_2d)
00110       Type (dble_vector)            :: cosvec_reg (ndim_2d)
00111 !
00112 !     ... for points to be searched
00113 !
00114 ! len_item = Length of a data item per point in search%ibuf
00115 !
00116       Integer                       :: len_item, len_rtem
00117       Integer                       :: irreg2_shape (2, ndim_3d)
00118 !
00119       Type (dble_vector)            :: cos_search, sin_search
00120 !
00121 !     ... for masks
00122 !         dummy_mask_array is a dummy array for to be
00123 !         transferred to interpolation routines
00124 !         Note: The target attributes (see !rr) were removed
00125 !               since there problems with a compiler and array bound checking
00126 !
00127       Integer                       :: mask_id
00128       Logical                       :: src_mask_available
00129 !
00130       Logical, Target               :: dummy_mask_array (1)
00131 !rr   Integer, target               :: dummy_mask_shape (2, ndim_3d)
00132       Integer                       :: dummy_mask_shape (2, ndim_3d)
00133 !
00134       Logical, Pointer              :: mask_array (:) 
00135 !rr   Integer, Pointer              :: mask_shape (:, :)
00136       Integer                       :: mask_shape (2, ndim_3d)
00137 !
00138 !     ... for error parameters
00139 !
00140       Integer, Parameter            :: nerrp = 1
00141       Integer                       :: ierrp (nerrp)
00142 !
00143 ! !DESCRIPTION:
00144 !
00145 ! Subroutine "PSMILe_Search_donor_nnx_dble" performs the additional (global)
00146 ! search for coordinates sent by the requesting process if nearest neigbour
00147 ! search is required.
00148 !
00149 ! !REVISION HISTORY:
00150 !
00151 !   Date      Programmer   Description
00152 ! ----------  ----------   -----------
00153 ! 23.10.06    H. Ritzdorf  created
00154 !
00155 !EOP
00156 !----------------------------------------------------------------------
00157 !
00158 ! $Id: psmile_search_donor_nnx_dble.F90 3112 2011-04-07 15:03:18Z hanke $
00159 ! $Author: hanke $
00160 !
00161    Character(len=len_cvs_string), save :: mycvs = 
00162        '$Id: psmile_search_donor_nnx_dble.F90 3112 2011-04-07 15:03:18Z hanke $'
00163 !----------------------------------------------------------------------
00164 !
00165 !  Initialization
00166 !
00167 #ifdef VERBOSE
00168       print 9990, trim(ch_id), comp_info%comp_id, search%sender
00169 
00170       call psmile_flushstd
00171 #endif /* VERBOSE */
00172 !
00173       ierror = 0
00174 !
00175       field     => Fields (var_id)
00176       method_id = field%method_id
00177       mask_id   = field%mask_id
00178 !
00179       mp        => Methods(method_id)
00180       grid_id   = mp%grid_id
00181       coords_pointer => mp%coords_pointer
00182 !
00183       grid_info => Grids (grid_id)
00184 !
00185       src_mask_available = mask_id /= PRISM_UNDEFINED
00186 !
00187       if (src_mask_available) then
00188          mask_array => Masks(mask_id)%mask_array
00189 !rr      mask_shape => Masks(mask_id)%mask_shape
00190          mask_shape =  Masks(mask_id)%mask_shape
00191       else
00192          mask_array => dummy_mask_array
00193 !rr      mask_shape => dummy_mask_shape
00194          mask_shape =  dummy_mask_shape
00195       endif
00196 !
00197 #ifdef PRISM_ASSERTION
00198 !
00199 !===> Internal control
00200 !
00201       if (search%msg_extra%reqest_type /= PSMILe_nnghbr3D) then
00202           call psmile_assert ( __FILE__, __LINE__, &
00203                   'Interpolation method must be Nearest Neighbour')
00204       endif
00205 !
00206       if (grid_info%corner_pointer%corner_datatype /= MPI_DOUBLE_PRECISION) then
00207           call psmile_assert ( __FILE__, __LINE__, &
00208                   'Incorrect datatype for this routine')
00209       endif
00210 !
00211       if (n_send /= search%msg_extra%num_volumes) then
00212           call psmile_assert ( __FILE__, __LINE__, &
00213                   'Inconsistent number of points')
00214       endif
00215 !
00216 #endif
00217 !
00218 !  len_item = Number of pieces of information in integer buffer "ibuf".
00219 !             #1  : Index in indices/dist_dble/send_mask of sending process
00220 !
00221 !  len_rtem = Number of pieces of information per point in
00222 !             floating point buffer "rbuf".
00223 !             #1-3: Coordinates of the point to be searched.
00224 !                   ndim_3d data items
00225 !             #4  : Maximal distance already determined
00226 !                   1 item
00227 !
00228 !     n_send   = search%msg_extra%num_volumes
00229       len_item = search%msg_extra%num_int_per_vol
00230       len_rtem = search%msg_extra%num_items_per_coord
00231 !
00232 !-----------------------------------------------------------------------
00233 !     Allocate and set temporary array which is used to transform
00234 !     the coordinates of points.
00235 !     (*) Longitudes and Latitudes are transformed
00236 !         from degrees into radients.
00237 !     (*) The z-values are currently not transformed
00238 !         ??? Whats about PRISM_Irrlonlat_sigmavrt, ...
00239 !-----------------------------------------------------------------------
00240 !
00241 ! Note: PSMILE_Info_coords_irreg2_dble is used to compute the values
00242 !       and generate arrays
00243 !       cos_search (1:n_send, lat) and sin_search (1:n_send, lat)
00244 !
00245       irreg2_shape (1,1) = 1
00246       irreg2_shape (2,1) = n_send
00247       irreg2_shape (1,2) = 1
00248       irreg2_shape (2,2) = 1
00249       irreg2_shape (1,3) = 1
00250       irreg2_shape (2,3) = 1 ! n_send, but z_coords are not used
00251 !
00252       call psmile_info_coords_irreg2_dble (       &
00253               coords1, coords2, coords3,          &
00254               irreg2_shape, irreg2_shape,         &
00255               sin_search, cos_search, ierror)
00256       if (ierror > 0) return
00257 !
00258 !===> Look for nearest neighbour on block boundary
00259 !
00260       select case ( Grids(grid_id)%grid_type )
00261 
00262 ! -----------------------------------------------------------------------
00263 !      Regular in all directions
00264 ! -----------------------------------------------------------------------
00265 !
00266       case (PRISM_Reglonlatvrt)
00267 !
00268 !===> ... Allocate and compute sin and cos values for the
00269 !         source grid
00270 !         TODO: Reuse values from standard search process
00271 !
00272          call psmile_info_coords_3d_reg_dble (              &
00273                  coords_pointer%coords_dble(1)%vector,      &
00274                  coords_pointer%coords_dble(2)%vector,      &
00275                  coords_pointer%coords_dble(3)%vector,      &
00276                  coords_pointer%coords_shape,               &
00277                  grid_info%grid_shape,                      &
00278                  sinvec_reg, cosvec_reg, ierror)
00279          if (ierror > 0) return
00280 
00281          call psmile_search_nn_3d_reg_dble (                       &
00282                  sin_search%vector, cos_search%vector, coords3,    &
00283                  distance,                                         &
00284                  nfound, locations, n_send,                        &
00285                  coords_pointer%coords_dble(1)%vector,             &
00286                  coords_pointer%coords_dble(2)%vector,             &
00287                  coords_pointer%coords_dble(3)%vector,             &
00288                  coords_pointer%coords_shape,                      &
00289                  sinvec_reg(lon)%vector, cosvec_reg(lon)%vector,   &
00290                  sinvec_reg(lat)%vector, cosvec_reg(lat)%vector,   &
00291                  grid_info%grid_shape,                             &
00292                  mask_array, mask_shape, src_mask_available,       &
00293                  tol, ierror)
00294 !
00295          Deallocate (sinvec_reg(1)%vector, sinvec_reg(2)%vector)
00296          Deallocate (cosvec_reg(1)%vector, cosvec_reg(2)%vector)
00297 !
00298 ! -----------------------------------------------------------------------
00299 !      Irregular in lonlat   direction
00300 !        Regular in vertical direction
00301 ! -----------------------------------------------------------------------
00302 !
00303       case (PRISM_Irrlonlat_regvrt)
00304 !
00305 !===> ... Allocate and compute sin and cos values for the
00306 !         source grid
00307 !         TODO: Reuse values from standard search process
00308 !
00309          call psmile_info_coords_irreg2_dble (                     &
00310                  coords_pointer%coords_dble(1)%vector,             &
00311                  coords_pointer%coords_dble(2)%vector,             &
00312                  coords_pointer%coords_dble(3)%vector,             &
00313                  coords_pointer%coords_shape,                      &
00314                  grid_info%grid_shape,                             &
00315                  sinvec, cosvec, ierror)
00316          if (ierror > 0) return
00317 
00318          call psmile_search_nn_irreg2_dble (                       &
00319                  sin_search%vector, cos_search%vector, coords3,    &
00320                  distance,                                         &
00321                  nfound, locations, n_send,                        &
00322                  coords_pointer%coords_dble(1)%vector,             &
00323                  coords_pointer%coords_dble(2)%vector,             &
00324                  coords_pointer%coords_dble(3)%vector,             &
00325                  coords_pointer%coords_shape,                      &
00326                  sinvec%vector, cosvec%vector,                     &
00327                  grid_info%grid_shape,                             &
00328                  mask_array, mask_shape, src_mask_available,       &
00329                  tol, ierror)
00330 !
00331          Deallocate (sinvec%vector, cosvec%vector)
00332 !
00333 ! -----------------------------------------------------------------------
00334 !      Irregular in lonlat   and vertical direction
00335 ! -----------------------------------------------------------------------
00336 !
00337       case (PRISM_Irrlonlatvrt)
00338 !
00339 !===> ... Allocate and compute sin and cos values for the
00340 !         source grid
00341 !         TODO: Reuse values from standard search process
00342 !
00343          call psmile_info_trf_coords_3d_dble (                     &
00344                  coords_pointer%coords_dble(1)%vector,             &
00345                  coords_pointer%coords_dble(2)%vector,             &
00346                  coords_pointer%coords_dble(3)%vector,             &
00347                  coords_pointer%coords_shape,                      &
00348                  grid_info%grid_shape,                             &
00349                  sinvec, cosvec, ierror)
00350          if (ierror > 0) return
00351 
00352          call psmile_search_nn_3d_dble (                           &
00353                  sin_search%vector, cos_search%vector, coords3,    &
00354                  distance,                                         &
00355                  nfound, locations, n_send,                        &
00356                  coords_pointer%coords_dble(1)%vector,             &
00357                  coords_pointer%coords_dble(2)%vector,             &
00358                  coords_pointer%coords_dble(3)%vector,             &
00359                  coords_pointer%coords_shape,                      &
00360                  sinvec%vector, cosvec%vector,                     &
00361                  grid_info%grid_shape,                             &
00362                  mask_array, mask_shape, src_mask_available,       &
00363                  tol, ierror)
00364 !
00365          Deallocate (sinvec%vector, cosvec%vector)
00366 !
00367 ! -----------------------------------------------------------------------
00368 !      Gauss reduced in lonlat direction
00369 !        Regular in vertical direction
00370 ! -----------------------------------------------------------------------
00371 !
00372       case (PRISM_Gaussreduced_regvrt)
00373 !
00374 !===> ... Allocate and compute sin and cos values for the
00375 !         source grid
00376 !         TODO: Reuse values from standard search process
00377 !               Use search which is better adjusted to
00378 !               the Gauss-grid.
00379 !
00380          call psmile_info_coords_irreg2_dble (                     &
00381                  coords_pointer%coords_dble(1)%vector,             &
00382                  coords_pointer%coords_dble(2)%vector,             &
00383                  coords_pointer%coords_dble(3)%vector,             &
00384                  coords_pointer%coords_shape,                      &
00385                  grid_info%grid_shape,                             &
00386                  sinvec, cosvec, ierror)
00387          if (ierror > 0) return
00388 
00389          ! sinvec%vector(:,lon), sinvec%vector(:lat)
00390          ! cosvec%vector(:,lon), cosvec%vector(:lat)
00391 
00392          call psmile_search_nn_irreg2_dble (                       &
00393                  sin_search%vector, cos_search%vector, coords3,    &
00394                  distance,                                         &
00395                  nfound, locations, n_send,                        &
00396                  coords_pointer%coords_dble(1)%vector,             &
00397                  coords_pointer%coords_dble(2)%vector,             &
00398                  coords_pointer%coords_dble(3)%vector,             &
00399                  coords_pointer%coords_shape,                      &
00400                  sinvec%vector, cosvec%vector,                     &
00401                  grid_info%grid_shape,                             &
00402                  mask_array, mask_shape, src_mask_available,       &
00403                  tol, ierror)
00404 
00405          Deallocate (sinvec%vector, cosvec%vector)
00406 !
00407 ! -----------------------------------------------------------------------
00408 !      Error: unsupported grid type
00409 ! -----------------------------------------------------------------------
00410 !
00411       case DEFAULT
00412 !
00413           ierrp (1) = Grids(grid_id)%grid_type
00414           ierror = PRISM_Error_Internal
00415 
00416           call psmile_error ( ierror, 'unsupported grid generation type', &
00417                               ierrp, 1, __FILE__, __LINE__ )
00418       end select 
00419 !
00420 !===> All done
00421 !
00422       Deallocate (cos_search%vector, sin_search%vector)
00423 !
00424 #ifdef VERBOSE
00425       print 9980, trim(ch_id), grid_id, search%sender, ierror
00426 
00427       call psmile_flushstd
00428 #endif /* VERBOSE */
00429 !
00430       return
00431 !
00432 !  Formats:
00433 !
00434 #ifdef VERBOSE
00435 9990 format (1x, a, ': psmile_search_donor_nnx_dble: comp_id =', i3, &
00436                     '; sender =', i4)
00437 9980 format (1x, a, ': psmile_search_donor_nnx_dble: grid id =', i3, &
00438                     '; eof sender =', i3, ', ierror =', i4)
00439 #endif /* VERBOSE */
00440 
00441       end subroutine PSMILe_Search_donor_nnx_dble

Generated on 1 Dec 2011 for Oasis4 by  doxygen 1.6.1