domngb.F90 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. MODULE domngb
  2. !!======================================================================
  3. !! *** MODULE domngb ***
  4. !! Grid search: find the closest grid point from a given on/lat position
  5. !!======================================================================
  6. !! History : 3.2 ! 2009-11 (S. Masson) Original code
  7. !!----------------------------------------------------------------------
  8. !!----------------------------------------------------------------------
  9. !! dom_ngb : find the closest grid point from a given lon/lat position
  10. !!----------------------------------------------------------------------
  11. USE dom_oce ! ocean space and time domain
  12. USE in_out_manager ! I/O manager
  13. USE lib_mpp ! for mppsum
  14. USE wrk_nemo ! Memory allocation
  15. USE timing ! Timing
  16. IMPLICIT NONE
  17. PRIVATE
  18. PUBLIC dom_ngb ! routine called in iom.F90 module
  19. !!----------------------------------------------------------------------
  20. !! NEMO/OPA 3.3 , NEMO Consortium (2010)
  21. !! $Id: domngb.F90 3294 2012-01-28 16:44:18Z rblod $
  22. !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
  23. !!----------------------------------------------------------------------
  24. CONTAINS
  25. SUBROUTINE dom_ngb( plon, plat, kii, kjj, cdgrid )
  26. !!----------------------------------------------------------------------
  27. !! *** ROUTINE dom_ngb ***
  28. !!
  29. !! ** Purpose : find the closest grid point from a given lon/lat position
  30. !!
  31. !! ** Method : look for minimum distance in cylindrical projection
  32. !! -> not good if located at too high latitude...
  33. !!----------------------------------------------------------------------
  34. !
  35. REAL(wp) , INTENT(in ) :: plon, plat ! longitude,latitude of the point
  36. INTEGER , INTENT( out) :: kii, kjj ! i-,j-index of the closes grid point
  37. CHARACTER(len=1), INTENT(in ) :: cdgrid ! grid name 'T', 'U', 'V', 'W'
  38. !
  39. INTEGER , DIMENSION(2) :: iloc
  40. REAL(wp) :: zlon, zmini
  41. REAL(wp), POINTER, DIMENSION(:,:) :: zglam, zgphi, zmask, zdist
  42. !!--------------------------------------------------------------------
  43. !
  44. IF( nn_timing == 1 ) CALL timing_start('dom_ngb')
  45. !
  46. CALL wrk_alloc( jpi, jpj, zglam, zgphi, zmask, zdist )
  47. !
  48. zmask(:,:) = 0._wp
  49. SELECT CASE( cdgrid )
  50. CASE( 'U' ) ; zglam(:,:) = glamu(:,:) ; zgphi(:,:) = gphiu(:,:) ; zmask(nldi:nlei,nldj:nlej) = umask(nldi:nlei,nldj:nlej,1)
  51. CASE( 'V' ) ; zglam(:,:) = glamv(:,:) ; zgphi(:,:) = gphiv(:,:) ; zmask(nldi:nlei,nldj:nlej) = vmask(nldi:nlei,nldj:nlej,1)
  52. CASE( 'F' ) ; zglam(:,:) = glamf(:,:) ; zgphi(:,:) = gphif(:,:) ; zmask(nldi:nlei,nldj:nlej) = fmask(nldi:nlei,nldj:nlej,1)
  53. CASE DEFAULT ; zglam(:,:) = glamt(:,:) ; zgphi(:,:) = gphit(:,:) ; zmask(nldi:nlei,nldj:nlej) = tmask(nldi:nlei,nldj:nlej,1)
  54. END SELECT
  55. zlon = MOD( plon + 720., 360. ) ! plon between 0 and 360
  56. zglam(:,:) = MOD( zglam(:,:) + 720., 360. ) ! glam between 0 and 360
  57. IF( zlon > 270. ) zlon = zlon - 360. ! zlon between -90 and 270
  58. IF( zlon < 90. ) WHERE( zglam(:,:) > 180. ) zglam(:,:) = zglam(:,:) - 360. ! glam between -180 and 180
  59. zglam(:,:) = zglam(:,:) - zlon
  60. zgphi(:,:) = zgphi(:,:) - plat
  61. zdist(:,:) = zglam(:,:) * zglam(:,:) + zgphi(:,:) * zgphi(:,:)
  62. IF( lk_mpp ) THEN
  63. CALL mpp_minloc( zdist(:,:), zmask, zmini, kii, kjj)
  64. ELSE
  65. iloc(:) = MINLOC( zdist(:,:), mask = zmask(:,:) == 1.e0 )
  66. kii = iloc(1) + nimpp - 1
  67. kjj = iloc(2) + njmpp - 1
  68. ENDIF
  69. !
  70. CALL wrk_dealloc( jpi, jpj, zglam, zgphi, zmask, zdist )
  71. !
  72. IF( nn_timing == 1 ) CALL timing_stop('dom_ngb')
  73. !
  74. END SUBROUTINE dom_ngb
  75. !!======================================================================
  76. END MODULE domngb