New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
domutl.F90 in NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/DOM – NEMO

source: NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/OCE/DOM/domutl.F90 @ 13998

Last change on this file since 13998 was 13998, checked in by techene, 3 years ago

branch updated with trunk 13787

  • Property svn:keywords set to Id
File size: 5.6 KB
RevLine 
[12807]1MODULE domutl
[1725]2   !!======================================================================
[12807]3   !!                       ***  MODULE  domutl  ***
4   !! Grid utilities:
[1725]5   !!======================================================================
[12807]6   !! History : 4.2  !  2020-04  (S. Masson)  Original code
[1725]7   !!----------------------------------------------------------------------
8
9   !!----------------------------------------------------------------------
[2715]10   !!   dom_ngb       : find the closest grid point from a given lon/lat position
[12807]11   !!   dom_uniq      : identify unique point of a grid (TUVF)
[1725]12   !!----------------------------------------------------------------------
[12807]13   !
[2715]14   USE dom_oce        ! ocean space and time domain
[9019]15   !
[3294]16   USE in_out_manager ! I/O manager
[12807]17   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
[2715]18   USE lib_mpp        ! for mppsum
[1725]19
20   IMPLICIT NONE
21   PRIVATE
22
[12807]23   PUBLIC dom_ngb    ! routine called in iom.F90 module
24   PUBLIC dom_uniq   ! Called by dommsk and domwri
[1725]25
26   !!----------------------------------------------------------------------
[12807]27   !! NEMO/OCE 4.2 , NEMO Consortium (2020)
[1725]28   !! $Id$
[10068]29   !! Software governed by the CeCILL license (see ./LICENSE)
[1725]30   !!----------------------------------------------------------------------
31CONTAINS
32
[6140]33   SUBROUTINE dom_ngb( plon, plat, kii, kjj, cdgrid, kkk )
[1725]34      !!----------------------------------------------------------------------
35      !!                    ***  ROUTINE dom_ngb  ***
36      !!
[2715]37      !! ** Purpose :   find the closest grid point from a given lon/lat position
[1725]38      !!
39      !! ** Method  :   look for minimum distance in cylindrical projection
40      !!                -> not good if located at too high latitude...
41      !!----------------------------------------------------------------------
42      REAL(wp)        , INTENT(in   ) ::   plon, plat   ! longitude,latitude of the point
43      INTEGER         , INTENT(  out) ::   kii, kjj     ! i-,j-index of the closes grid point
[6140]44      INTEGER         , INTENT(in   ), OPTIONAL :: kkk  ! k-index of the mask level used
[1725]45      CHARACTER(len=1), INTENT(in   ) ::   cdgrid       ! grid name 'T', 'U', 'V', 'W'
[2715]46      !
[6140]47      INTEGER :: ik         ! working level
[2715]48      INTEGER , DIMENSION(2) ::   iloc
49      REAL(wp)               ::   zlon, zmini
[13998]50      REAL(wp), DIMENSION(jpi,jpj) ::   zglam, zgphi, zdist
51      LOGICAL , DIMENSION(jpi,jpj) ::   llmsk
[1725]52      !!--------------------------------------------------------------------
[2715]53      !
[6140]54      ik = 1
55      IF ( PRESENT(kkk) ) ik=kkk
[12807]56      !
[1725]57      SELECT CASE( cdgrid )
[13998]58      CASE( 'U' ) ;   zglam(:,:) = glamu(:,:)   ;   zgphi(:,:) = gphiu(:,:)   ;   llmsk(:,:) = tmask_h(:,:) * umask(:,:,ik) == 1._wp
59      CASE( 'V' ) ;   zglam(:,:) = glamv(:,:)   ;   zgphi(:,:) = gphiv(:,:)   ;   llmsk(:,:) = tmask_h(:,:) * vmask(:,:,ik) == 1._wp
60      CASE( 'F' ) ;   zglam(:,:) = glamf(:,:)   ;   zgphi(:,:) = gphif(:,:)   ;   llmsk(:,:) = tmask_h(:,:) * fmask(:,:,ik) == 1._wp
61      CASE DEFAULT;   zglam(:,:) = glamt(:,:)   ;   zgphi(:,:) = gphit(:,:)   ;   llmsk(:,:) = tmask_h(:,:) * tmask(:,:,ik) == 1._wp
[1725]62      END SELECT
[12807]63      !
[7646]64      zlon       = MOD( plon       + 720., 360. )                                     ! plon between    0 and 360
65      zglam(:,:) = MOD( zglam(:,:) + 720., 360. )                                     ! glam between    0 and 360
66      IF( zlon > 270. )   zlon = zlon - 360.                                          ! zlon between  -90 and 270
67      IF( zlon <  90. )   WHERE( zglam(:,:) > 180. ) zglam(:,:) = zglam(:,:) - 360.   ! glam between -180 and 180
68      zglam(:,:) = zglam(:,:) - zlon
[13998]69      !
[1725]70      zgphi(:,:) = zgphi(:,:) - plat
71      zdist(:,:) = zglam(:,:) * zglam(:,:) + zgphi(:,:) * zgphi(:,:)
[2715]72      !
[13998]73      CALL mpp_minloc( 'domngb', zdist(:,:), llmsk, zmini, iloc, ldhalo = .TRUE. )
74      kii = iloc(1)
75      kjj = iloc(2)
76      !
[1725]77   END SUBROUTINE dom_ngb
78
[12807]79
80   SUBROUTINE dom_uniq( puniq, cdgrd )
81      !!----------------------------------------------------------------------
82      !!                  ***  ROUTINE dom_uniq  ***
83      !!                   
84      !! ** Purpose :   identify unique point of a grid (TUVF)
85      !!
86      !! ** Method  :   1) aplly lbc_lnk on an array with different values for each element
87      !!                2) check which elements have been changed
88      !!----------------------------------------------------------------------
89      CHARACTER(len=1)        , INTENT(in   ) ::   cdgrd   !
90      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   puniq   !
91      !
92      REAL(wp)                       ::  zshift   ! shift value link to the process number
93      INTEGER                        ::  ji       ! dummy loop indices
94      LOGICAL , DIMENSION(jpi,jpj,1) ::   lluniq  ! store whether each point is unique or not
95      REAL(wp), DIMENSION(jpi,jpj  ) ::   ztstref
96      !!----------------------------------------------------------------------
97      !
98      ! build an array with different values for each element
99      ! in mpp: make sure that these values are different even between process
100      ! -> apply a shift value according to the process number
101      zshift = jpimax * jpjmax * ( narea - 1 )
102      ztstref(:,:) = RESHAPE( (/ (zshift + REAL(ji,wp), ji = 1, jpi*jpj) /), (/ jpi, jpj /) )
103      !
104      puniq(:,:) = ztstref(:,:)                    ! default definition
105      CALL lbc_lnk( 'domwri', puniq, cdgrd, 1. )   ! apply boundary conditions
106      lluniq(:,:,1) = puniq(:,:) == ztstref(:,:)   ! check which values have not been changed
107      !
108      puniq(:,:) = REAL( COUNT( lluniq(:,:,:), dim = 3 ), wp )
109      !
110   END SUBROUTINE dom_uniq
111   
[1725]112   !!======================================================================
[12807]113END MODULE domutl
Note: See TracBrowser for help on using the repository browser.