[12807] | 1 | MODULE 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 | |
---|
[13514] | 23 | INTERFACE is_tile |
---|
| 24 | MODULE PROCEDURE is_tile_2d, is_tile_3d, is_tile_4d |
---|
| 25 | END INTERFACE is_tile |
---|
| 26 | |
---|
[12807] | 27 | PUBLIC dom_ngb ! routine called in iom.F90 module |
---|
| 28 | PUBLIC dom_uniq ! Called by dommsk and domwri |
---|
[13514] | 29 | PUBLIC is_tile |
---|
[1725] | 30 | |
---|
| 31 | !!---------------------------------------------------------------------- |
---|
[12807] | 32 | !! NEMO/OCE 4.2 , NEMO Consortium (2020) |
---|
[1725] | 33 | !! $Id$ |
---|
[10068] | 34 | !! Software governed by the CeCILL license (see ./LICENSE) |
---|
[1725] | 35 | !!---------------------------------------------------------------------- |
---|
| 36 | CONTAINS |
---|
| 37 | |
---|
[6140] | 38 | SUBROUTINE dom_ngb( plon, plat, kii, kjj, cdgrid, kkk ) |
---|
[1725] | 39 | !!---------------------------------------------------------------------- |
---|
| 40 | !! *** ROUTINE dom_ngb *** |
---|
| 41 | !! |
---|
[2715] | 42 | !! ** Purpose : find the closest grid point from a given lon/lat position |
---|
[1725] | 43 | !! |
---|
| 44 | !! ** Method : look for minimum distance in cylindrical projection |
---|
| 45 | !! -> not good if located at too high latitude... |
---|
| 46 | !!---------------------------------------------------------------------- |
---|
| 47 | REAL(wp) , INTENT(in ) :: plon, plat ! longitude,latitude of the point |
---|
| 48 | INTEGER , INTENT( out) :: kii, kjj ! i-,j-index of the closes grid point |
---|
[6140] | 49 | INTEGER , INTENT(in ), OPTIONAL :: kkk ! k-index of the mask level used |
---|
[1725] | 50 | CHARACTER(len=1), INTENT(in ) :: cdgrid ! grid name 'T', 'U', 'V', 'W' |
---|
[2715] | 51 | ! |
---|
[6140] | 52 | INTEGER :: ik ! working level |
---|
[2715] | 53 | INTEGER , DIMENSION(2) :: iloc |
---|
| 54 | REAL(wp) :: zlon, zmini |
---|
[13553] | 55 | REAL(wp), DIMENSION(jpi,jpj) :: zglam, zgphi, zdist |
---|
| 56 | LOGICAL , DIMENSION(jpi,jpj) :: llmsk |
---|
[1725] | 57 | !!-------------------------------------------------------------------- |
---|
[2715] | 58 | ! |
---|
[6140] | 59 | ik = 1 |
---|
| 60 | IF ( PRESENT(kkk) ) ik=kkk |
---|
[12807] | 61 | ! |
---|
[1725] | 62 | SELECT CASE( cdgrid ) |
---|
[13553] | 63 | CASE( 'U' ) ; zglam(:,:) = glamu(:,:) ; zgphi(:,:) = gphiu(:,:) ; llmsk(:,:) = tmask_h(:,:) * umask(:,:,ik) == 1._wp |
---|
| 64 | CASE( 'V' ) ; zglam(:,:) = glamv(:,:) ; zgphi(:,:) = gphiv(:,:) ; llmsk(:,:) = tmask_h(:,:) * vmask(:,:,ik) == 1._wp |
---|
| 65 | CASE( 'F' ) ; zglam(:,:) = glamf(:,:) ; zgphi(:,:) = gphif(:,:) ; llmsk(:,:) = tmask_h(:,:) * fmask(:,:,ik) == 1._wp |
---|
| 66 | CASE DEFAULT; zglam(:,:) = glamt(:,:) ; zgphi(:,:) = gphit(:,:) ; llmsk(:,:) = tmask_h(:,:) * tmask(:,:,ik) == 1._wp |
---|
[1725] | 67 | END SELECT |
---|
[12807] | 68 | ! |
---|
[7646] | 69 | zlon = MOD( plon + 720., 360. ) ! plon between 0 and 360 |
---|
| 70 | zglam(:,:) = MOD( zglam(:,:) + 720., 360. ) ! glam between 0 and 360 |
---|
| 71 | IF( zlon > 270. ) zlon = zlon - 360. ! zlon between -90 and 270 |
---|
| 72 | IF( zlon < 90. ) WHERE( zglam(:,:) > 180. ) zglam(:,:) = zglam(:,:) - 360. ! glam between -180 and 180 |
---|
| 73 | zglam(:,:) = zglam(:,:) - zlon |
---|
[13553] | 74 | ! |
---|
[1725] | 75 | zgphi(:,:) = zgphi(:,:) - plat |
---|
| 76 | zdist(:,:) = zglam(:,:) * zglam(:,:) + zgphi(:,:) * zgphi(:,:) |
---|
[2715] | 77 | ! |
---|
[13553] | 78 | CALL mpp_minloc( 'domngb', zdist(:,:), llmsk, zmini, iloc, ldhalo = .TRUE. ) |
---|
| 79 | kii = iloc(1) |
---|
| 80 | kjj = iloc(2) |
---|
| 81 | ! |
---|
[1725] | 82 | END SUBROUTINE dom_ngb |
---|
| 83 | |
---|
[12807] | 84 | |
---|
| 85 | SUBROUTINE dom_uniq( puniq, cdgrd ) |
---|
| 86 | !!---------------------------------------------------------------------- |
---|
| 87 | !! *** ROUTINE dom_uniq *** |
---|
| 88 | !! |
---|
| 89 | !! ** Purpose : identify unique point of a grid (TUVF) |
---|
| 90 | !! |
---|
| 91 | !! ** Method : 1) aplly lbc_lnk on an array with different values for each element |
---|
| 92 | !! 2) check which elements have been changed |
---|
| 93 | !!---------------------------------------------------------------------- |
---|
| 94 | CHARACTER(len=1) , INTENT(in ) :: cdgrd ! |
---|
| 95 | REAL(wp), DIMENSION(:,:), INTENT(inout) :: puniq ! |
---|
| 96 | ! |
---|
| 97 | REAL(wp) :: zshift ! shift value link to the process number |
---|
| 98 | INTEGER :: ji ! dummy loop indices |
---|
| 99 | LOGICAL , DIMENSION(jpi,jpj,1) :: lluniq ! store whether each point is unique or not |
---|
| 100 | REAL(wp), DIMENSION(jpi,jpj ) :: ztstref |
---|
| 101 | !!---------------------------------------------------------------------- |
---|
| 102 | ! |
---|
| 103 | ! build an array with different values for each element |
---|
| 104 | ! in mpp: make sure that these values are different even between process |
---|
| 105 | ! -> apply a shift value according to the process number |
---|
| 106 | zshift = jpimax * jpjmax * ( narea - 1 ) |
---|
| 107 | ztstref(:,:) = RESHAPE( (/ (zshift + REAL(ji,wp), ji = 1, jpi*jpj) /), (/ jpi, jpj /) ) |
---|
| 108 | ! |
---|
| 109 | puniq(:,:) = ztstref(:,:) ! default definition |
---|
| 110 | CALL lbc_lnk( 'domwri', puniq, cdgrd, 1. ) ! apply boundary conditions |
---|
| 111 | lluniq(:,:,1) = puniq(:,:) == ztstref(:,:) ! check which values have not been changed |
---|
| 112 | ! |
---|
| 113 | puniq(:,:) = REAL( COUNT( lluniq(:,:,:), dim = 3 ), wp ) |
---|
| 114 | ! |
---|
| 115 | END SUBROUTINE dom_uniq |
---|
[13514] | 116 | |
---|
| 117 | |
---|
[13745] | 118 | FUNCTION is_tile_2d( pt ) |
---|
[13514] | 119 | !! |
---|
| 120 | REAL(wp), DIMENSION(:,:), INTENT(in) :: pt |
---|
| 121 | INTEGER :: is_tile_2d |
---|
| 122 | !! |
---|
[13563] | 123 | IF( ln_tile .AND. (SIZE(pt, 1) < jpi .OR. SIZE(pt, 2) < jpj) ) THEN |
---|
[13514] | 124 | is_tile_2d = 1 |
---|
| 125 | ELSE |
---|
| 126 | is_tile_2d = 0 |
---|
| 127 | ENDIF |
---|
| 128 | END FUNCTION is_tile_2d |
---|
| 129 | |
---|
| 130 | |
---|
[13745] | 131 | FUNCTION is_tile_3d( pt ) |
---|
[13514] | 132 | !! |
---|
| 133 | REAL(wp), DIMENSION(:,:,:), INTENT(in) :: pt |
---|
| 134 | INTEGER :: is_tile_3d |
---|
| 135 | !! |
---|
[13563] | 136 | IF( ln_tile .AND. (SIZE(pt, 1) < jpi .OR. SIZE(pt, 2) < jpj) ) THEN |
---|
[13514] | 137 | is_tile_3d = 1 |
---|
| 138 | ELSE |
---|
| 139 | is_tile_3d = 0 |
---|
| 140 | ENDIF |
---|
| 141 | END FUNCTION is_tile_3d |
---|
| 142 | |
---|
| 143 | |
---|
[13745] | 144 | FUNCTION is_tile_4d( pt ) |
---|
[13514] | 145 | !! |
---|
| 146 | REAL(wp), DIMENSION(:,:,:,:), INTENT(in) :: pt |
---|
| 147 | INTEGER :: is_tile_4d |
---|
| 148 | !! |
---|
[13563] | 149 | IF( ln_tile .AND. (SIZE(pt, 1) < jpi .OR. SIZE(pt, 2) < jpj) ) THEN |
---|
[13514] | 150 | is_tile_4d = 1 |
---|
| 151 | ELSE |
---|
| 152 | is_tile_4d = 0 |
---|
| 153 | ENDIF |
---|
| 154 | END FUNCTION is_tile_4d |
---|
| 155 | |
---|
[1725] | 156 | !!====================================================================== |
---|
[12807] | 157 | END MODULE domutl |
---|