psmile_search_donor_nnx_real.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_real
00008 !
00009 ! !INTERFACE:
00010 
00011       subroutine psmile_search_donor_nnx_real (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_real
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       Real, Intent (In)               :: coords1 (n_send)
00040       Real, Intent (In)               :: coords2 (n_send)
00041       Real, 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       Real,            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       Real, 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_real;
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 (real_vector)            :: cosvec, sinvec
00109       Type (real_vector)            :: sinvec_reg (ndim_2d)
00110       Type (real_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 (real_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_real" 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_real.F90 2082 2009-10-21 13:31:19Z hanke $
00159 ! $Author: hanke $
00160 !
00161    Character(len=len_cvs_string), save :: mycvs = 
00162        '$Id: psmile_search_donor_nnx_real.F90 2082 2009-10-21 13:31:19Z 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(1) /= 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_REAL) then
00207           call psmile_assert ( __FILE__, __LINE__, &
00208                   'Incorrect datatype for this routine')
00209       endif
00210 !
00211       if (n_send /= search%msg_extra (8)) then
00212           call psmile_assert ( __FILE__, __LINE__, &
00213                   'Inconsistent number of points')
00214       endif
00215 !
00216 #endif
00217 
00218 #ifdef DEBUG
00219       print *, trim(ch_id), ': search%msg_extra(1:4)', search%msg_extra(1:4)
00220 !
00221       call psmile_flushstd
00222 #endif /* DEBUG */
00223 !
00224 !  len_item = Number of pieces of information in integer buffer "ibuf".
00225 !             #1  : Index in indices/dist_real/send_mask of sending process
00226 !
00227 !  len_rtem = Number of pieces of information per point in
00228 !             floating point buffer "rbuf".
00229 !             #1-3: Coordinates of the point to be searched.
00230 !                   ndim_3d data items
00231 !             #4  : Maximal distance already determined
00232 !                   1 item
00233 !
00234 !     n_send   = search%msg_extra (8)
00235       len_item = search%msg_extra (9)
00236       len_rtem = search%msg_extra (10)
00237 !
00238 !-----------------------------------------------------------------------
00239 !     Allocate and set temporary array which is used to transform
00240 !     the coordinates of points.
00241 !     (*) Longitudes and Latitudes are transformed
00242 !         from degrees into radients.
00243 !     (*) The z-values are currently not transformed
00244 !         ??? Whats about PRISM_Irrlonlat_sigmavrt, ...
00245 !-----------------------------------------------------------------------
00246 !
00247 ! Note: PSMILE_Info_coords_irreg2_real is used to compute the values
00248 !       and generate arrays
00249 !       cos_search (1:n_send, lat) and sin_search (1:n_send, lat)
00250 !
00251       irreg2_shape (1,1) = 1
00252       irreg2_shape (2,1) = n_send
00253       irreg2_shape (1,2) = 1
00254       irreg2_shape (2,2) = 1
00255       irreg2_shape (1,3) = 1
00256       irreg2_shape (2,3) = 1 ! n_send, but z_coords are not used
00257 !
00258       call psmile_info_coords_irreg2_real (       &
00259               coords1, coords2, coords3,          &
00260               irreg2_shape, irreg2_shape,         &
00261               sin_search, cos_search, ierror)
00262       if (ierror > 0) return
00263 !
00264 !===> Look for nearest neighbour on block boundary
00265 !
00266       select case ( Grids(grid_id)%grid_type )
00267 
00268 ! -----------------------------------------------------------------------
00269 !      Regular in all directions
00270 ! -----------------------------------------------------------------------
00271 !
00272       case (PRISM_Reglonlatvrt)
00273 !
00274 !===> ... Allocate and compute sin and cos values for the
00275 !         source grid
00276 !         TODO: Reuse values from standard search process
00277 !
00278          call psmile_info_coords_3d_reg_real (              &
00279                  coords_pointer%coords_real(1)%vector,      &
00280                  coords_pointer%coords_real(2)%vector,      &
00281                  coords_pointer%coords_real(3)%vector,      &
00282                  coords_pointer%coords_shape,               &
00283                  grid_info%grid_shape,                      &
00284                  sinvec_reg, cosvec_reg, ierror)
00285          if (ierror > 0) return
00286 
00287          call psmile_search_nn_3d_reg_real (                       &
00288                  sin_search%vector, cos_search%vector, coords3,    &
00289                  distance,                                         &
00290                  nfound, locations, n_send,                        &
00291                  coords_pointer%coords_real(1)%vector,             &
00292                  coords_pointer%coords_real(2)%vector,             &
00293                  coords_pointer%coords_real(3)%vector,             &
00294                  coords_pointer%coords_shape,                      &
00295                  sinvec_reg(lon)%vector, cosvec_reg(lon)%vector,   &
00296                  sinvec_reg(lat)%vector, cosvec_reg(lat)%vector,   &
00297                  grid_info%grid_shape,                             &
00298                  mask_array, mask_shape, src_mask_available,       &
00299                  tol, ierror)
00300 !
00301          Deallocate (sinvec_reg(1)%vector, sinvec_reg(2)%vector)
00302          Deallocate (cosvec_reg(1)%vector, cosvec_reg(2)%vector)
00303 !
00304 ! -----------------------------------------------------------------------
00305 !      Irregular in lonlat   direction
00306 !        Regular in vertical direction
00307 ! -----------------------------------------------------------------------
00308 !
00309       case (PRISM_Irrlonlat_regvrt)
00310 !
00311 !===> ... Allocate and compute sin and cos values for the
00312 !         source grid
00313 !         TODO: Reuse values from standard search process
00314 !
00315          call psmile_info_coords_irreg2_real (                     &
00316                  coords_pointer%coords_real(1)%vector,             &
00317                  coords_pointer%coords_real(2)%vector,             &
00318                  coords_pointer%coords_real(3)%vector,             &
00319                  coords_pointer%coords_shape,                      &
00320                  grid_info%grid_shape,                             &
00321                  sinvec, cosvec, ierror)
00322          if (ierror > 0) return
00323 
00324          call psmile_search_nn_irreg2_real (                       &
00325                  sin_search%vector, cos_search%vector, coords3,    &
00326                  distance,                                         &
00327                  nfound, locations, n_send,                        &
00328                  coords_pointer%coords_real(1)%vector,             &
00329                  coords_pointer%coords_real(2)%vector,             &
00330                  coords_pointer%coords_real(3)%vector,             &
00331                  coords_pointer%coords_shape,                      &
00332                  sinvec%vector, cosvec%vector,                     &
00333                  grid_info%grid_shape,                             &
00334                  mask_array, mask_shape, src_mask_available,       &
00335                  tol, ierror)
00336 !
00337          Deallocate (sinvec%vector, cosvec%vector)
00338 !
00339 ! -----------------------------------------------------------------------
00340 !      Irregular in lonlat   and vertical direction
00341 ! -----------------------------------------------------------------------
00342 !
00343       case (PRISM_Irrlonlatvrt)
00344 !
00345 !===> ... Allocate and compute sin and cos values for the
00346 !         source grid
00347 !         TODO: Reuse values from standard search process
00348 !
00349          call psmile_info_trf_coords_3d_real (                     &
00350                  coords_pointer%coords_real(1)%vector,             &
00351                  coords_pointer%coords_real(2)%vector,             &
00352                  coords_pointer%coords_real(3)%vector,             &
00353                  coords_pointer%coords_shape,                      &
00354                  grid_info%grid_shape,                             &
00355                  sinvec, cosvec, ierror)
00356          if (ierror > 0) return
00357 
00358          call psmile_search_nn_3d_real (                           &
00359                  sin_search%vector, cos_search%vector, coords3,    &
00360                  distance,                                         &
00361                  nfound, locations, n_send,                        &
00362                  coords_pointer%coords_real(1)%vector,             &
00363                  coords_pointer%coords_real(2)%vector,             &
00364                  coords_pointer%coords_real(3)%vector,             &
00365                  coords_pointer%coords_shape,                      &
00366                  sinvec%vector, cosvec%vector,                     &
00367                  grid_info%grid_shape,                             &
00368                  mask_array, mask_shape, src_mask_available,       &
00369                  tol, ierror)
00370 !
00371          Deallocate (sinvec%vector, cosvec%vector)
00372 !
00373 ! -----------------------------------------------------------------------
00374 !      Gauss reduced in lonlat direction
00375 !        Regular in vertical direction
00376 ! -----------------------------------------------------------------------
00377 !
00378       case (PRISM_Gaussreduced_regvrt)
00379 !
00380 !===> ... Allocate and compute sin and cos values for the
00381 !         source grid
00382 !         TODO: Reuse values from standard search process
00383 !               Use search which is better adjusted to
00384 !               the Gauss-grid.
00385 !
00386          call psmile_info_coords_irreg2_real (                     &
00387                  coords_pointer%coords_real(1)%vector,             &
00388                  coords_pointer%coords_real(2)%vector,             &
00389                  coords_pointer%coords_real(3)%vector,             &
00390                  coords_pointer%coords_shape,                      &
00391                  grid_info%grid_shape,                             &
00392                  sinvec, cosvec, ierror)
00393          if (ierror > 0) return
00394 
00395          ! sinvec%vector(:,lon), sinvec%vector(:lat)
00396          ! cosvec%vector(:,lon), cosvec%vector(:lat)
00397 
00398          call psmile_search_nn_irreg2_real (                       &
00399                  sin_search%vector, cos_search%vector, coords3,    &
00400                  distance,                                         &
00401                  nfound, locations, n_send,                        &
00402                  coords_pointer%coords_real(1)%vector,             &
00403                  coords_pointer%coords_real(2)%vector,             &
00404                  coords_pointer%coords_real(3)%vector,             &
00405                  coords_pointer%coords_shape,                      &
00406                  sinvec%vector, cosvec%vector,                     &
00407                  grid_info%grid_shape,                             &
00408                  mask_array, mask_shape, src_mask_available,       &
00409                  tol, ierror)
00410 
00411          Deallocate (sinvec%vector, cosvec%vector)
00412 !
00413 ! -----------------------------------------------------------------------
00414 !      Error: unsupported grid type
00415 ! -----------------------------------------------------------------------
00416 !
00417       case DEFAULT
00418 !
00419           ierrp (1) = Grids(grid_id)%grid_type
00420           ierror = PRISM_Error_Internal
00421 
00422           call psmile_error ( ierror, 'unsupported grid generation type', &
00423                               ierrp, 1, __FILE__, __LINE__ )
00424       end select 
00425 !
00426 !===> All done
00427 !
00428       Deallocate (cos_search%vector, sin_search%vector)
00429 !
00430 #ifdef VERBOSE
00431       print 9980, trim(ch_id), grid_id, search%sender, ierror
00432 
00433       call psmile_flushstd
00434 #endif /* VERBOSE */
00435 !
00436       return
00437 !
00438 !  Formats:
00439 !
00440 #ifdef VERBOSE
00441 9990 format (1x, a, ': psmile_search_donor_nnx_real: comp_id =', i3, &
00442                     '; sender =', i4)
00443 9980 format (1x, a, ': psmile_search_donor_nnx_real: grid id =', i3, &
00444                     '; eof sender =', i3, ', ierror =', i4)
00445 #endif /* VERBOSE */
00446 
00447       end subroutine PSMILe_Search_donor_nnx_real

Generated on 18 Mar 2011 for Oasis4 by  doxygen 1.6.1