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/trunk/src/OCE/DOM – NEMO

source: NEMO/trunk/src/OCE/DOM/domutl.F90 @ 13458

Last change on this file since 13458 was 13458, checked in by smasson, 4 years ago

trunk: mpp_min(max)loc testing only inner domain, see #2521

  • Property svn:keywords set to Id
File size: 5.6 KB
Line 
1MODULE domutl
2   !!======================================================================
3   !!                       ***  MODULE  domutl  ***
4   !! Grid utilities:
5   !!======================================================================
6   !! History : 4.2  !  2020-04  (S. Masson)  Original code
7   !!----------------------------------------------------------------------
8
9   !!----------------------------------------------------------------------
10   !!   dom_ngb       : find the closest grid point from a given lon/lat position
11   !!   dom_uniq      : identify unique point of a grid (TUVF)
12   !!----------------------------------------------------------------------
13   !
14   USE dom_oce        ! ocean space and time domain
15   !
16   USE in_out_manager ! I/O manager
17   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
18   USE lib_mpp        ! for mppsum
19
20   IMPLICIT NONE
21   PRIVATE
22
23   PUBLIC dom_ngb    ! routine called in iom.F90 module
24   PUBLIC dom_uniq   ! Called by dommsk and domwri
25
26   !!----------------------------------------------------------------------
27   !! NEMO/OCE 4.2 , NEMO Consortium (2020)
28   !! $Id$
29   !! Software governed by the CeCILL license (see ./LICENSE)
30   !!----------------------------------------------------------------------
31CONTAINS
32
33   SUBROUTINE dom_ngb( plon, plat, kii, kjj, cdgrid, kkk )
34      !!----------------------------------------------------------------------
35      !!                    ***  ROUTINE dom_ngb  ***
36      !!
37      !! ** Purpose :   find the closest grid point from a given lon/lat position
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
44      INTEGER         , INTENT(in   ), OPTIONAL :: kkk  ! k-index of the mask level used
45      CHARACTER(len=1), INTENT(in   ) ::   cdgrid       ! grid name 'T', 'U', 'V', 'W'
46      !
47      INTEGER :: ik         ! working level
48      INTEGER , DIMENSION(2) ::   iloc
49      REAL(wp)               ::   zlon, zmini
50      REAL(wp), DIMENSION(jpi,jpj) ::   zglam, zgphi, zdist
51      LOGICAL , DIMENSION(jpi,jpj) ::   llmsk
52      !!--------------------------------------------------------------------
53      !
54      ik = 1
55      IF ( PRESENT(kkk) ) ik=kkk
56      !
57      SELECT CASE( cdgrid )
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
62      END SELECT
63      !
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
69      !
70      zgphi(:,:) = zgphi(:,:) - plat
71      zdist(:,:) = zglam(:,:) * zglam(:,:) + zgphi(:,:) * zgphi(:,:)
72      !
73      CALL mpp_minloc( 'domngb', zdist(:,:), llmsk, zmini, iloc, ldhalo = .TRUE. )
74      kii = iloc(1)
75      kjj = iloc(2)
76      !
77   END SUBROUTINE dom_ngb
78
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   
112   !!======================================================================
113END MODULE domutl
Note: See TracBrowser for help on using the repository browser.