[5037] | 1 | !---------------------------------------------------------------------- |
---|
| 2 | ! NEMO system team, System and Interface for oceanic RElocable Nesting |
---|
| 3 | !---------------------------------------------------------------------- |
---|
| 4 | ! |
---|
| 5 | ! DESCRIPTION: |
---|
[13369] | 6 | !> @brief |
---|
[5037] | 7 | !> This module manage nearest interpolation on regular grid. |
---|
| 8 | !> |
---|
| 9 | !> @details |
---|
| 10 | !> to compute nearest interpolation:<br/> |
---|
| 11 | !> @code |
---|
| 12 | !> CALL interp_nearest_fill(dd_value, dd_fill, id_detect, id_rho, ld_even [,ld_discont] ) |
---|
| 13 | !> @endcode |
---|
[13369] | 14 | !> - dd_value is 2D array of variable value |
---|
[5037] | 15 | !> - dd_fill is the FillValue of variable |
---|
[13369] | 16 | !> - id_detect is 2D array of point to be interpolated (see interp module) |
---|
[5037] | 17 | !> - id_rho is array of refinment factor |
---|
[13369] | 18 | !> - ld_even indicates even refinment or not |
---|
[5037] | 19 | !> - ld_discont indicates longitudinal discontinuity (-180°/180°, 0°/360°) or not |
---|
| 20 | !> |
---|
| 21 | !> @author |
---|
| 22 | !> J.Paul |
---|
[12080] | 23 | !> |
---|
[5617] | 24 | !> @date September, 2014 - Initial version |
---|
[5037] | 25 | !> |
---|
[12080] | 26 | !> @note Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt) |
---|
[5037] | 27 | !---------------------------------------------------------------------- |
---|
| 28 | MODULE interp_nearest |
---|
| 29 | |
---|
| 30 | USE netcdf ! nf90 library |
---|
| 31 | USE global ! global variable |
---|
| 32 | USE kind ! F90 kind parameter |
---|
| 33 | USE logger ! log file manager |
---|
| 34 | USE fct ! basic useful function |
---|
| 35 | |
---|
| 36 | IMPLICIT NONE |
---|
| 37 | ! NOTE_avoid_public_variables_if_possible |
---|
| 38 | |
---|
| 39 | ! type and variable |
---|
| 40 | |
---|
| 41 | ! function and subroutine |
---|
| 42 | PUBLIC :: interp_nearest_fill !< compute interpolation using nearest method |
---|
| 43 | |
---|
| 44 | PRIVATE :: interp_nearest__2D !< compute binearest interpolation on 2D gid |
---|
| 45 | PRIVATE :: interp_nearest__1D !< compute nearest interpolation on 1D gid |
---|
| 46 | PRIVATE :: interp_nearest__2D_fill !< fill value using binearest interpolation |
---|
| 47 | PRIVATE :: interp_nearest__1D_fill !< fill value using nearest interpolation |
---|
| 48 | |
---|
[12080] | 49 | CONTAINS |
---|
| 50 | !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
| 51 | SUBROUTINE interp_nearest_fill(dd_value, id_detect, id_rho) |
---|
[5037] | 52 | !------------------------------------------------------------------- |
---|
| 53 | !> @brief |
---|
[13369] | 54 | !> This subroutine compute horizontal nearest interpolation on 4D array of value. |
---|
| 55 | !> |
---|
[5037] | 56 | !> @author J.Paul |
---|
[5617] | 57 | !> @date September, 2014 - Initial Version |
---|
[5037] | 58 | !> |
---|
[13369] | 59 | !> @param[inout] dd_value 2D array of variable value |
---|
| 60 | !> @param[inout] id_detect 2D array of point to be interpolated |
---|
[5037] | 61 | !> @param[in] id_rho array of refinment factor |
---|
| 62 | !------------------------------------------------------------------- |
---|
[12080] | 63 | |
---|
[5037] | 64 | IMPLICIT NONE |
---|
[12080] | 65 | |
---|
[5037] | 66 | ! Argument |
---|
[13369] | 67 | REAL(dp) , DIMENSION(:,:,:,:), INTENT(INOUT) :: dd_value |
---|
[5037] | 68 | INTEGER(I4) , DIMENSION(:,:,:) , INTENT(INOUT) :: id_detect |
---|
| 69 | INTEGER(I4) , DIMENSION(:) , INTENT(IN ) :: id_rho |
---|
| 70 | |
---|
| 71 | ! local variable |
---|
[5609] | 72 | INTEGER(i4), DIMENSION(4) :: il_shape |
---|
[5037] | 73 | |
---|
[5609] | 74 | INTEGER(I4), DIMENSION(:,:,:), ALLOCATABLE :: il_detect |
---|
| 75 | |
---|
[5037] | 76 | ! loop indices |
---|
| 77 | INTEGER(i4) :: ji |
---|
| 78 | INTEGER(i4) :: jj |
---|
| 79 | INTEGER(i4) :: jk |
---|
| 80 | INTEGER(i4) :: jl |
---|
| 81 | !---------------------------------------------------------------- |
---|
| 82 | |
---|
| 83 | il_shape(:)=SHAPE(dd_value) |
---|
| 84 | |
---|
[5609] | 85 | ALLOCATE(il_detect(il_shape(1),il_shape(2),il_shape(3))) |
---|
[5037] | 86 | DO jl=1,il_shape(4) |
---|
[5609] | 87 | il_detect(:,:,:)=id_detect(:,:,:) |
---|
[5037] | 88 | ! loop on vertical level |
---|
| 89 | DO jk=1,il_shape(3) |
---|
| 90 | |
---|
| 91 | ! I-J plan |
---|
| 92 | CALL interp_nearest__2D(dd_value(:,:,jk,jl),& |
---|
[5609] | 93 | & il_detect(:,:,jk), & |
---|
[13369] | 94 | & id_rho(jp_I), id_rho(jp_J) ) |
---|
[5609] | 95 | IF( ANY(il_detect(:,:,jk)==1) )THEN |
---|
[5037] | 96 | ! I direction |
---|
| 97 | DO jj=1,il_shape(2) |
---|
| 98 | CALL interp_nearest__1D( dd_value(:,jj,jk,jl),& |
---|
[5609] | 99 | & il_detect(:,jj,jk), & |
---|
[5037] | 100 | & id_rho(jp_I) ) |
---|
| 101 | ENDDO |
---|
[5609] | 102 | IF( ALL(il_detect(:,:,jk)==0) )THEN |
---|
[5037] | 103 | CYCLE |
---|
| 104 | ELSE |
---|
| 105 | ! J direction |
---|
| 106 | DO ji=1,il_shape(1) |
---|
| 107 | CALL interp_nearest__1D( dd_value(ji,:,jk,jl),& |
---|
[5609] | 108 | & il_detect(ji,:,jk), & |
---|
[5037] | 109 | & id_rho(jp_J) ) |
---|
| 110 | ENDDO |
---|
| 111 | ENDIF |
---|
| 112 | ENDIF |
---|
| 113 | |
---|
| 114 | ENDDO |
---|
| 115 | ENDDO |
---|
| 116 | |
---|
[5609] | 117 | id_detect(:,:,:)=il_detect(:,:,:) |
---|
| 118 | DEALLOCATE(il_detect) |
---|
| 119 | |
---|
[5037] | 120 | END SUBROUTINE interp_nearest_fill |
---|
[12080] | 121 | !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
| 122 | SUBROUTINE interp_nearest__2D(dd_value, id_detect, id_rhoi, id_rhoj) |
---|
[5037] | 123 | !------------------------------------------------------------------- |
---|
| 124 | !> @brief |
---|
[13369] | 125 | !> This subroutine compute nearest interpolation on 2D array of value. |
---|
| 126 | !> |
---|
[5037] | 127 | !> @author J.Paul |
---|
[5617] | 128 | !> @date September, 2014 - Initial Version |
---|
[5037] | 129 | !> |
---|
[13369] | 130 | !> @param[inout] dd_value 2D array of variable value |
---|
| 131 | !> @param[inout] id_detect 2D array of point to be interpolated |
---|
[5037] | 132 | !> @param[in] id_rhoi refinment factor in i-direction |
---|
| 133 | !> @param[in] id_rhoj refinment factor in j-direction |
---|
| 134 | !> @param[in] id_rhok refinment factor in k-direction |
---|
| 135 | !------------------------------------------------------------------- |
---|
| 136 | |
---|
| 137 | IMPLICIT NONE |
---|
[12080] | 138 | |
---|
[5037] | 139 | ! Argument |
---|
[13369] | 140 | REAL(dp) , DIMENSION(:,:), INTENT(INOUT) :: dd_value |
---|
[5037] | 141 | INTEGER(I4) , DIMENSION(:,:), INTENT(INOUT) :: id_detect |
---|
| 142 | INTEGER(I4) , INTENT(IN ) :: id_rhoi |
---|
| 143 | INTEGER(I4) , INTENT(IN ) :: id_rhoj |
---|
| 144 | |
---|
| 145 | ! local variable |
---|
| 146 | INTEGER(i4), DIMENSION(2) :: il_shape |
---|
| 147 | |
---|
| 148 | ! loop indices |
---|
| 149 | INTEGER(i4) :: ji |
---|
| 150 | INTEGER(i4) :: jj |
---|
| 151 | |
---|
| 152 | !---------------------------------------------------------------- |
---|
| 153 | |
---|
| 154 | IF( ANY(id_detect(:,:)==1) )THEN |
---|
| 155 | |
---|
| 156 | il_shape(:)=SHAPE(dd_value) |
---|
| 157 | |
---|
| 158 | DO jj=1,il_shape(2)-1,id_rhoj |
---|
| 159 | DO ji=1,il_shape(1)-1,id_rhoi |
---|
[13369] | 160 | |
---|
[5037] | 161 | ! check if point to be interpolated |
---|
| 162 | IF( ALL(id_detect(ji:ji+id_rhoi, & |
---|
| 163 | & jj:jj+id_rhoj)==0) ) CYCLE |
---|
| 164 | |
---|
| 165 | ! compute value on detetected point |
---|
| 166 | CALL interp_nearest__2D_fill(dd_value( ji:ji+id_rhoi, & |
---|
| 167 | & jj:jj+id_rhoj ), & |
---|
| 168 | & id_detect(ji:ji+id_rhoi, & |
---|
| 169 | & jj:jj+id_rhoj ) ) |
---|
| 170 | |
---|
| 171 | ENDDO |
---|
| 172 | ENDDO |
---|
| 173 | |
---|
| 174 | ENDIF |
---|
| 175 | |
---|
| 176 | END SUBROUTINE interp_nearest__2D |
---|
[12080] | 177 | !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
| 178 | SUBROUTINE interp_nearest__1D(dd_value, id_detect, id_rhoi) |
---|
[5037] | 179 | !------------------------------------------------------------------- |
---|
| 180 | !> @brief |
---|
[13369] | 181 | !> This subroutine compute nearest interpolation on 1D array of value. |
---|
| 182 | !> |
---|
[5037] | 183 | !> @author J.Paul |
---|
[5617] | 184 | !> @date September, 2014 - Initial Version |
---|
[5037] | 185 | !> |
---|
[13369] | 186 | !> @param[inout] dd_value 1D array of variable value |
---|
| 187 | !> @param[inout] id_detect 1D array of point to be interpolated |
---|
[5037] | 188 | !> @param[in] id_rhoi refinment factor |
---|
| 189 | !------------------------------------------------------------------- |
---|
| 190 | |
---|
| 191 | IMPLICIT NONE |
---|
[12080] | 192 | |
---|
[5037] | 193 | ! Argument |
---|
[13369] | 194 | REAL(dp) , DIMENSION(:), INTENT(INOUT) :: dd_value |
---|
[5037] | 195 | INTEGER(I4) , DIMENSION(:), INTENT(INOUT) :: id_detect |
---|
| 196 | INTEGER(I4) , INTENT(IN ) :: id_rhoi |
---|
| 197 | |
---|
| 198 | ! local variable |
---|
| 199 | INTEGER(i4), DIMENSION(1) :: il_shape |
---|
| 200 | |
---|
| 201 | ! loop indices |
---|
| 202 | INTEGER(i4) :: ji |
---|
| 203 | !---------------------------------------------------------------- |
---|
| 204 | |
---|
| 205 | IF( ANY(id_detect(:)==1) )THEN |
---|
| 206 | il_shape(:)=SHAPE(dd_value) |
---|
| 207 | |
---|
| 208 | DO ji=1,il_shape(1)-1,id_rhoi |
---|
[13369] | 209 | |
---|
[5037] | 210 | ! check if point to be interpolated |
---|
| 211 | IF( ALL(id_detect(ji:ji+id_rhoi)==0) ) CYCLE |
---|
| 212 | |
---|
| 213 | ! compute value on detetected point |
---|
| 214 | CALL interp_nearest__1D_fill( dd_value( ji:ji+id_rhoi ), & |
---|
| 215 | & id_detect(ji:ji+id_rhoi ) ) |
---|
| 216 | |
---|
| 217 | ENDDO |
---|
| 218 | |
---|
| 219 | ENDIF |
---|
| 220 | |
---|
| 221 | END SUBROUTINE interp_nearest__1D |
---|
[12080] | 222 | !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
| 223 | SUBROUTINE interp_nearest__2D_fill(dd_value, id_detect) |
---|
[5037] | 224 | !------------------------------------------------------------------- |
---|
| 225 | !> @brief |
---|
[13369] | 226 | !> This subroutine compute nearest interpolation of a 2D array of value. |
---|
| 227 | !> |
---|
[5037] | 228 | !> @author J.Paul |
---|
[5617] | 229 | !> @date September, 2014 - Initial Version |
---|
[5037] | 230 | !> |
---|
| 231 | !> @param[inout] dd_value 2D array of mixed grid value |
---|
| 232 | !> @param[inout] id_detect 2D array of point to be interpolated |
---|
| 233 | !------------------------------------------------------------------- |
---|
[12080] | 234 | |
---|
[5037] | 235 | IMPLICIT NONE |
---|
[12080] | 236 | |
---|
[5037] | 237 | ! Argument |
---|
[13369] | 238 | REAL(dp) , DIMENSION(:,:) , INTENT(INOUT) :: dd_value |
---|
[5037] | 239 | INTEGER(i4), DIMENSION(:,:) , INTENT(INOUT) :: id_detect |
---|
| 240 | |
---|
| 241 | ! local variable |
---|
| 242 | INTEGER(i4), DIMENSION(2) :: il_shape |
---|
| 243 | |
---|
| 244 | INTEGER(i4) :: il_i1 |
---|
| 245 | INTEGER(i4) :: il_i2 |
---|
| 246 | INTEGER(i4) :: il_j1 |
---|
| 247 | INTEGER(i4) :: il_j2 |
---|
| 248 | |
---|
| 249 | INTEGER(i4) :: il_half1 |
---|
| 250 | INTEGER(i4) :: il_half2 |
---|
| 251 | |
---|
| 252 | ! loop indices |
---|
| 253 | INTEGER(i4) :: ji |
---|
| 254 | INTEGER(i4) :: jj |
---|
| 255 | !---------------------------------------------------------------- |
---|
| 256 | |
---|
| 257 | il_shape(:)=SHAPE(dd_value(:,:)) |
---|
| 258 | |
---|
| 259 | il_i1=1 |
---|
| 260 | il_i2=il_shape(1) |
---|
| 261 | |
---|
| 262 | il_j1=1 |
---|
| 263 | il_j2=il_shape(2) |
---|
| 264 | |
---|
| 265 | il_half1=CEILING(il_shape(1)*0.5) |
---|
| 266 | il_half2=CEILING(il_shape(2)*0.5) |
---|
| 267 | |
---|
| 268 | DO jj=1,il_half2 |
---|
| 269 | |
---|
| 270 | DO ji=1,il_half1 |
---|
[13369] | 271 | |
---|
[5037] | 272 | ! lower left point |
---|
| 273 | IF(id_detect(ji,jj)==1)THEN |
---|
| 274 | |
---|
| 275 | dd_value( ji,jj)=dd_value(il_i1,il_j1) |
---|
| 276 | id_detect(ji,jj)=0 |
---|
| 277 | |
---|
| 278 | ENDIF |
---|
| 279 | |
---|
| 280 | ! lower right point |
---|
| 281 | IF(id_detect(il_shape(1)-ji+1,jj)==1)THEN |
---|
| 282 | |
---|
| 283 | dd_value( il_shape(1)-ji+1,jj)=dd_value(il_i2,il_j1) |
---|
| 284 | id_detect(il_shape(1)-ji+1,jj)=0 |
---|
| 285 | |
---|
| 286 | ENDIF |
---|
| 287 | |
---|
| 288 | ! upper left point |
---|
| 289 | IF(id_detect(ji,il_shape(2)-jj+1)==1)THEN |
---|
| 290 | |
---|
| 291 | dd_value( ji,il_shape(2)-jj+1)=dd_value(il_i1,il_j2) |
---|
| 292 | id_detect(ji,il_shape(2)-jj+1)=0 |
---|
| 293 | |
---|
[13369] | 294 | ENDIF |
---|
[5037] | 295 | |
---|
| 296 | ! upper right point |
---|
| 297 | IF(id_detect(il_shape(1)-ji+1,il_shape(2)-jj+1)==1)THEN |
---|
| 298 | |
---|
| 299 | dd_value( il_shape(1)-ji+1,il_shape(2)-jj+1)=dd_value(il_i2,il_j2) |
---|
| 300 | id_detect(il_shape(1)-ji+1,il_shape(2)-jj+1)=0 |
---|
| 301 | |
---|
[13369] | 302 | ENDIF |
---|
[5037] | 303 | |
---|
| 304 | ENDDO |
---|
| 305 | |
---|
| 306 | ENDDO |
---|
| 307 | |
---|
| 308 | END SUBROUTINE interp_nearest__2D_fill |
---|
[12080] | 309 | !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
| 310 | SUBROUTINE interp_nearest__1D_fill(dd_value, id_detect) |
---|
[5037] | 311 | !------------------------------------------------------------------- |
---|
| 312 | !> @brief |
---|
[13369] | 313 | !> This subroutine compute nearest interpolation of a 1D array of value. |
---|
| 314 | !> |
---|
[5037] | 315 | !> @author J.Paul |
---|
[5617] | 316 | !> @date September, 2014 - Initial Version |
---|
[5037] | 317 | !> |
---|
| 318 | !> @param[inout] dd_value 1D array of mixed grid value |
---|
| 319 | !> @param[inout] id_detect 1D array of point to be interpolated |
---|
| 320 | !------------------------------------------------------------------- |
---|
[12080] | 321 | |
---|
[5037] | 322 | IMPLICIT NONE |
---|
[12080] | 323 | |
---|
[5037] | 324 | ! Argument |
---|
[13369] | 325 | REAL(dp) , DIMENSION(:), INTENT(INOUT) :: dd_value |
---|
[5037] | 326 | INTEGER(i4), DIMENSION(:), INTENT(INOUT) :: id_detect |
---|
| 327 | |
---|
| 328 | ! local variable |
---|
| 329 | INTEGER(i4), DIMENSION(1) :: il_shape |
---|
| 330 | |
---|
| 331 | INTEGER(i4) :: il_i1 |
---|
| 332 | INTEGER(i4) :: il_i2 |
---|
| 333 | |
---|
| 334 | INTEGER(i4) :: il_half1 |
---|
[13369] | 335 | |
---|
[5037] | 336 | ! loop indices |
---|
| 337 | INTEGER(i4) :: ji |
---|
| 338 | !---------------------------------------------------------------- |
---|
| 339 | |
---|
| 340 | il_shape(:)=SHAPE(dd_value) |
---|
| 341 | |
---|
| 342 | il_i1=1 |
---|
| 343 | il_i2=il_shape(1) |
---|
| 344 | |
---|
| 345 | il_half1=CEILING(il_shape(1)*0.5) |
---|
[13369] | 346 | |
---|
[5037] | 347 | DO ji=1,il_half1 |
---|
[13369] | 348 | |
---|
[5037] | 349 | ! lower left point |
---|
| 350 | IF(id_detect(ji)==1)THEN |
---|
| 351 | |
---|
| 352 | dd_value( ji)=dd_value(il_i1) |
---|
| 353 | id_detect(ji)=0 |
---|
| 354 | |
---|
| 355 | ENDIF |
---|
| 356 | |
---|
| 357 | ! lower right point |
---|
| 358 | IF(id_detect(il_shape(1)-ji+1)==1)THEN |
---|
| 359 | |
---|
| 360 | dd_value( il_shape(1)-ji+1)=dd_value(il_i2) |
---|
| 361 | id_detect(il_shape(1)-ji+1)=0 |
---|
| 362 | |
---|
| 363 | ENDIF |
---|
| 364 | |
---|
| 365 | ENDDO |
---|
| 366 | |
---|
| 367 | END SUBROUTINE interp_nearest__1D_fill |
---|
[12080] | 368 | !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
[5037] | 369 | END MODULE interp_nearest |
---|