1 | ;+ |
---|
2 | ; |
---|
3 | ; @file_comments |
---|
4 | ; check the lateral boundaries condition (east-west and north) of a 2D/3D/4D array |
---|
5 | ; located on a grif of the orca grid familly. |
---|
6 | ; |
---|
7 | ; @categories |
---|
8 | ; ORCA grid |
---|
9 | ; |
---|
10 | ; @param arr {in}{required}{type=2D/3D/4D array} |
---|
11 | ; array to be checked (and corrected if CORRECTION keyword is activated) |
---|
12 | ; |
---|
13 | ; @param grid {in}{required}{type=scalar string} |
---|
14 | ; type of grid-point on which is located the array: 'T', 'U', 'V' or 'F' |
---|
15 | ; |
---|
16 | ; @param psign {in}{optional}{type=1. or -1.}{default=1.} |
---|
17 | ; |
---|
18 | ; @keyword VERBOSE {optional}{type=0 or 1}{default=0} |
---|
19 | ; Activate to get error information when getting a wrong lateral boundaries condition |
---|
20 | ; |
---|
21 | ; @keyword CORRECTION {optional}{type=0 or 1}{default=0} |
---|
22 | ; Activate to correct the wrong lateral boundary condition in arr (in that case arr is changed) |
---|
23 | ; |
---|
24 | ; @returns |
---|
25 | ; the number of wrong lateral boundary condition found in arr (-> 0 means arr is OK) |
---|
26 | ; |
---|
27 | ; @restrictions |
---|
28 | ; only ORCA2, ORCA05 and ORCA025 are coded (but others are very easy to add...) |
---|
29 | ; |
---|
30 | ; @examples |
---|
31 | ; |
---|
32 | ; IDL> \@tst_initorca2 |
---|
33 | ; IDL> a = dist(jpiglo, jpjglo) |
---|
34 | ; IDL> print, lbcorca(a, 'T') |
---|
35 | ; IDL> dummy = lbcorca(a, 'T', /correction) |
---|
36 | ; IDL> print, lbcorca(a, 'T') |
---|
37 | |
---|
38 | ; @history |
---|
39 | ; Mai 2007: Creation, smasson\@locean-ipsl.upmc.fr |
---|
40 | ; |
---|
41 | ; @version |
---|
42 | ; $Id$ |
---|
43 | ; |
---|
44 | ;- |
---|
45 | FUNCTION lbcorca, arr, grid, psign, VERBOSE=verbose, CORRECTION=correction |
---|
46 | ; |
---|
47 | compile_opt idl2, strictarrsubs |
---|
48 | ; |
---|
49 | IF n_elements(psign) EQ 0 THEN psign = 1. |
---|
50 | sz = size(arr) |
---|
51 | jpi = sz[1] |
---|
52 | jpj = sz[2] |
---|
53 | |
---|
54 | res = 0 |
---|
55 | |
---|
56 | ; east-west periodicity checks |
---|
57 | |
---|
58 | IF array_equal(arr[0, *, *, *], arr[jpi-2, *, *, *]) NE 1 THEN BEGIN |
---|
59 | IF keyword_set(verbose) THEN print, 'east-west periodicity (1) error' |
---|
60 | IF keyword_set(correction) THEN arr[0, *, *, *] = arr[jpi-2, *, *, *] |
---|
61 | res = res + 1 |
---|
62 | ENDIF |
---|
63 | IF array_equal(arr[1, *, *, *], arr[jpi-1, *, *, *]) NE 1 THEN BEGIN |
---|
64 | IF keyword_set(verbose) THEN print, 'east-west periodicity (2) error' |
---|
65 | IF keyword_set(correction) THEN arr[jpi-1, *, *, *] = arr[1, *, *, *] |
---|
66 | res = res + 1 |
---|
67 | ENDIF |
---|
68 | |
---|
69 | ; north pole periodicity |
---|
70 | |
---|
71 | CASE 1 OF |
---|
72 | (jpi EQ 182 AND jpj EQ 149) OR (jpi EQ 1442 AND jpj EQ 1021) OR (jpi EQ 4322 AND jpj EQ 3059):BEGIN ; this is ORCA2, 0RCA025, ORCA12... |
---|
73 | CASE grid OF |
---|
74 | 'T':BEGIN |
---|
75 | IF array_equal(arr[1:jpi-1, jpj-1, *, *], psign * reverse(arr[1:jpi-1, jpj-3, *, *])) NE 1 THEN BEGIN |
---|
76 | IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity (1) error' |
---|
77 | IF keyword_set(correction) THEN arr[1:jpi-1, jpj-1, *, *] = psign * reverse(arr[1:jpi-1, jpj-3, *, *]) |
---|
78 | res = res + 1 |
---|
79 | ENDIF |
---|
80 | IF array_equal(arr[1:jpi/2, jpj-2, *, *], psign * reverse(arr[jpi/2:jpi-1, jpj-2, *, *])) NE 1 THEN BEGIN |
---|
81 | IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity (2) error' |
---|
82 | IF keyword_set(correction) THEN arr[1:jpi/2, jpj-2, *, *] = psign * reverse(arr[jpi/2:jpi-1, jpj-2, *, *]) |
---|
83 | res = res + 1 |
---|
84 | ENDIF |
---|
85 | END |
---|
86 | 'U':BEGIN |
---|
87 | IF array_equal(arr[1:jpi-1, jpj-1, *, *], psign * reverse(arr[0:jpi-2, jpj-3, *, *])) NE 1 THEN BEGIN |
---|
88 | IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity (1) error' |
---|
89 | IF keyword_set(correction) THEN arr[1:jpi-1, jpj-1, *, *] = psign * reverse(arr[0:jpi-2, jpj-3, *, *]) |
---|
90 | res = res + 1 |
---|
91 | ENDIF |
---|
92 | IF array_equal(arr[1:jpi/2, jpj-2, *, *], psign * reverse(arr[jpi/2-1:jpi-2, jpj-2, *, *])) NE 1 THEN BEGIN |
---|
93 | IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity (2) error' |
---|
94 | IF keyword_set(correction) THEN arr[1:jpi/2, jpj-2, *, *] = psign * reverse(arr[jpi/2-1:jpi-2, jpj-2, *, *]) |
---|
95 | res = res + 1 |
---|
96 | ENDIF |
---|
97 | END |
---|
98 | 'V':BEGIN |
---|
99 | IF array_equal(arr[1:jpi-1, jpj-1, *, *], psign * reverse(arr[1:jpi-1, jpj-4, *, *])) NE 1 THEN BEGIN |
---|
100 | IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity (1) error' |
---|
101 | IF keyword_set(correction) THEN arr[1:jpi-1, jpj-1, *, *] = psign * reverse(arr[1:jpi-1, jpj-4, *, *]) |
---|
102 | res = res + 1 |
---|
103 | ENDIF |
---|
104 | IF array_equal(arr[1:jpi/2, jpj-2, *, *], psign * reverse(arr[jpi/2:jpi-1, jpj-3, *, *])) NE 1 THEN BEGIN |
---|
105 | IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity (2) error' |
---|
106 | IF keyword_set(correction) THEN arr[1:jpi/2, jpj-2, *, *] = psign * reverse(arr[jpi/2:jpi-1, jpj-3, *, *]) |
---|
107 | res = res + 1 |
---|
108 | ENDIF |
---|
109 | END |
---|
110 | 'F':BEGIN |
---|
111 | IF array_equal(arr[1:jpi-1, jpj-1, *, *], psign * reverse(arr[0:jpi-2, jpj-4, *, *])) NE 1 THEN BEGIN |
---|
112 | IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity (1) error' |
---|
113 | IF keyword_set(correction) THEN arr[1:jpi-1, jpj-1, *, *] = psign * reverse(arr[0:jpi-2, jpj-4, *, *]) |
---|
114 | res = res + 1 |
---|
115 | ENDIF |
---|
116 | IF array_equal(arr[1:jpi/2, jpj-2, *, *], psign * reverse(arr[jpi/2-1:jpi-2, jpj-3, *, *])) NE 1 THEN BEGIN |
---|
117 | IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity (2) error' |
---|
118 | IF keyword_set(correction) THEN arr[1:jpi/2, jpj-2, *, *] = psign * reverse(arr[jpi/2-1:jpi-2, jpj-3, *, *]) |
---|
119 | res = res + 1 |
---|
120 | ENDIF |
---|
121 | END |
---|
122 | ENDCASE |
---|
123 | END |
---|
124 | |
---|
125 | jpi EQ 722 AND jpj EQ 511:BEGIN ; this is ORCA05... |
---|
126 | CASE grid OF |
---|
127 | 'T':BEGIN |
---|
128 | IF array_equal(arr[1:jpi-2, jpj-1, *, *], psign * reverse(arr[1:jpi-2, jpj-2, *, *])) NE 1 THEN BEGIN |
---|
129 | IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity error' |
---|
130 | IF keyword_set(correction) THEN arr[1:jpi-2, jpj-1, *, *] = psign * reverse(arr[1:jpi-2, jpj-2, *, *]) |
---|
131 | res = res + 1 |
---|
132 | ENDIF |
---|
133 | END |
---|
134 | 'U':BEGIN |
---|
135 | IF array_equal(arr[1:jpi-2, jpj-1, *, *], psign * reverse(arr[0:jpi-3, jpj-2, *, *])) NE 1 THEN BEGIN |
---|
136 | IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity error' |
---|
137 | IF keyword_set(correction) THEN arr[1:jpi-2, jpj-1, *, *] = psign * reverse(arr[0:jpi-3, jpj-2, *, *]) |
---|
138 | res = res + 1 |
---|
139 | ENDIF |
---|
140 | END |
---|
141 | 'V':BEGIN |
---|
142 | IF array_equal(arr[1:jpi-2, jpj-1, *, *], psign * reverse(arr[1:jpi-2, jpj-3, *, *])) NE 1 THEN BEGIN |
---|
143 | IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity error' |
---|
144 | IF keyword_set(correction) THEN arr[1:jpi-2, jpj-1, *, *] = psign * reverse(arr[1:jpi-2, jpj-3, *, *]) |
---|
145 | res = res + 1 |
---|
146 | ENDIF |
---|
147 | END |
---|
148 | 'F':BEGIN |
---|
149 | IF array_equal(arr[1:jpi-2, jpj-1, *, *], psign * reverse(arr[0:jpi-3, jpj-3, *, *])) NE 1 THEN BEGIN |
---|
150 | IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity error' |
---|
151 | IF keyword_set(correction) THEN arr[1:jpi-2, jpj-1, *, *] = psign * reverse(arr[0:jpi-3, jpj-3, *, *]) |
---|
152 | res = res + 1 |
---|
153 | ENDIF |
---|
154 | END |
---|
155 | ENDCASE |
---|
156 | END |
---|
157 | ENDCASE |
---|
158 | |
---|
159 | ; east-west periodicity correction (again) |
---|
160 | |
---|
161 | IF keyword_set(correction) THEN BEGIN |
---|
162 | arr[0 , *, *, *] = arr[jpi-2, *, *, *] |
---|
163 | arr[jpi-1, *, *, *] = arr[1 , *, *, *] |
---|
164 | ENDIF |
---|
165 | |
---|
166 | |
---|
167 | RETURN, res |
---|
168 | END |
---|