;+ ; ; @file_comments ; check the lateral boundaries condition (east-west and north) of a 2D/3D/4D array ; located on a grif of the orca grid familly. ; ; @categories ; ORCA grid ; ; @param arr {in}{required}{type=2D/3D/4D array} ; array to be checked (and corrected if CORRECTION keyword is activated) ; ; @param grid {in}{required}{type=scalar string} ; type of grid-point on which is located the array: 'T', 'U', 'V' or 'F' ; ; @param psign {in}{optional}{type=1. or -1.}{default=1.} ; ; @keyword VERBOSE {optional}{type=0 or 1}{default=0} ; Activate to get error information when getting a wrong lateral boundaries condition ; ; @keyword CORRECTION {optional}{type=0 or 1}{default=0} ; Activate to correct the wrong lateral boundary condition in arr (in that case arr is changed) ; ; @returns ; the number of wrong lateral boundary condition found in arr (-> 0 means arr is OK) ; ; @restrictions ; only ORCA2, ORCA05 and ORCA025 are coded (but others are very easy to add...) ; ; @examples ; IDL> \@tst_initorca2 ; IDL> a = dist(jpiglo, jpjglo) ; IDL> print, lbcorca(a, 'T') ; IDL> dummy = lbcorca(a, 'T', /correction) ; IDL> print, lbcorca(a, 'T') ; @history ; Mai 2007: Creation, smasson\@locean-ipsl.upmc.fr ; ; @version ; $Id$ ; ;- FUNCTION lbcorca, arr, grid, psign, VERBOSE=verbose, CORRECTION=correction ; compile_opt idl2, strictarrsubs ; IF n_elements(psign) EQ 0 THEN psign = 1. sz = size(arr) jpi = sz[1] jpj = sz[2] res = 0 ; east-west periodicity checks IF array_equal(arr[0, *, *, *], arr[jpi-2, *, *, *]) NE 1 THEN BEGIN IF keyword_set(verbose) THEN print, 'east-west periodicity (1) error' IF keyword_set(correction) THEN arr[0, *, *, *] = arr[jpi-2, *, *, *] res = res + 1 ENDIF IF array_equal(arr[1, *, *, *], arr[jpi-1, *, *, *]) NE 1 THEN BEGIN IF keyword_set(verbose) THEN print, 'east-west periodicity (2) error' IF keyword_set(correction) THEN arr[jpi-1, *, *, *] = arr[1, *, *, *] res = res + 1 ENDIF ; north pole periodicity CASE 1 OF (jpi EQ 182 AND jpj EQ 149) OR (jpi EQ 1442 AND jpj EQ 1021):BEGIN ; this is ORCA2... CASE grid OF 'T':BEGIN IF array_equal(arr[1:jpi-1, jpj-1, *, *], psign * reverse(arr[1:jpi-1, jpj-3, *, *])) NE 1 THEN BEGIN IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity (1) error' IF keyword_set(correction) THEN arr[1:jpi-1, jpj-1, *, *] = psign * reverse(arr[1:jpi-1, jpj-3, *, *]) res = res + 1 ENDIF IF array_equal(arr[1:jpi/2, jpj-2, *, *], psign * reverse(arr[jpi/2:jpi-1, jpj-2, *, *])) NE 1 THEN BEGIN IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity (2) error' IF keyword_set(correction) THEN arr[1:jpi/2, jpj-2, *, *] = psign * reverse(arr[jpi/2:jpi-1, jpj-2, *, *]) res = res + 1 ENDIF END 'U':BEGIN IF array_equal(arr[1:jpi-1, jpj-1, *, *], psign * reverse(arr[0:jpi-2, jpj-3, *, *])) NE 1 THEN BEGIN IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity (1) error' IF keyword_set(correction) THEN arr[1:jpi-1, jpj-1, *, *] = psign * reverse(arr[0:jpi-2, jpj-3, *, *]) res = res + 1 ENDIF IF array_equal(arr[1:jpi/2, jpj-2, *, *], psign * reverse(arr[jpi/2-1:jpi-2, jpj-2, *, *])) NE 1 THEN BEGIN IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity (2) error' IF keyword_set(correction) THEN arr[1:jpi/2, jpj-2, *, *] = psign * reverse(arr[jpi/2-1:jpi-2, jpj-2, *, *]) res = res + 1 ENDIF END 'V':BEGIN IF array_equal(arr[1:jpi-1, jpj-1, *, *], psign * reverse(arr[1:jpi-1, jpj-4, *, *])) NE 1 THEN BEGIN IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity (1) error' IF keyword_set(correction) THEN arr[1:jpi-1, jpj-1, *, *] = psign * reverse(arr[1:jpi-1, jpj-4, *, *]) res = res + 1 ENDIF IF array_equal(arr[1:jpi/2, jpj-2, *, *], psign * reverse(arr[jpi/2:jpi-1, jpj-3, *, *])) NE 1 THEN BEGIN IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity (2) error' IF keyword_set(correction) THEN arr[1:jpi/2, jpj-2, *, *] = psign * reverse(arr[jpi/2:jpi-1, jpj-3, *, *]) res = res + 1 ENDIF END 'F':BEGIN IF array_equal(arr[1:jpi-1, jpj-1, *, *], psign * reverse(arr[0:jpi-2, jpj-4, *, *])) NE 1 THEN BEGIN IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity (1) error' IF keyword_set(correction) THEN arr[1:jpi-1, jpj-1, *, *] = psign * reverse(arr[0:jpi-2, jpj-4, *, *]) res = res + 1 ENDIF IF array_equal(arr[1:jpi/2, jpj-2, *, *], psign * reverse(arr[jpi/2-1:jpi-2, jpj-3, *, *])) NE 1 THEN BEGIN IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity (2) error' IF keyword_set(correction) THEN arr[1:jpi/2, jpj-2, *, *] = psign * reverse(arr[jpi/2-1:jpi-2, jpj-3, *, *]) res = res + 1 ENDIF END ENDCASE END jpi EQ 722 AND jpj EQ 511:BEGIN ; this is ORCA05... CASE grid OF 'T':BEGIN IF array_equal(arr[1:jpi-2, jpj-1, *, *], psign * reverse(arr[1:jpi-2, jpj-2, *, *])) NE 1 THEN BEGIN IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity error' IF keyword_set(correction) THEN arr[1:jpi-2, jpj-1, *, *] = psign * reverse(arr[1:jpi-2, jpj-2, *, *]) res = res + 1 ENDIF END 'U':BEGIN IF array_equal(arr[1:jpi-2, jpj-1, *, *], psign * reverse(arr[0:jpi-3, jpj-2, *, *])) NE 1 THEN BEGIN IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity error' IF keyword_set(correction) THEN arr[1:jpi-2, jpj-1, *, *] = psign * reverse(arr[0:jpi-3, jpj-2, *, *]) res = res + 1 ENDIF END 'V':BEGIN IF array_equal(arr[1:jpi-2, jpj-1, *, *], psign * reverse(arr[1:jpi-2, jpj-3, *, *])) NE 1 THEN BEGIN IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity error' IF keyword_set(correction) THEN arr[1:jpi-2, jpj-1, *, *] = psign * reverse(arr[1:jpi-2, jpj-3, *, *]) res = res + 1 ENDIF END 'F':BEGIN IF array_equal(arr[1:jpi-2, jpj-1, *, *], psign * reverse(arr[0:jpi-3, jpj-3, *, *])) NE 1 THEN BEGIN IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity error' IF keyword_set(correction) THEN arr[1:jpi-2, jpj-1, *, *] = psign * reverse(arr[0:jpi-3, jpj-3, *, *]) res = res + 1 ENDIF END ENDCASE END ENDCASE ; east-west periodicity correction (again) IF keyword_set(correction) THEN BEGIN arr[0 , *, *, *] = arr[jpi-2, *, *, *] arr[jpi-1, *, *, *] = arr[1 , *, *, *] ENDIF RETURN, res END