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 | ; @keyword STOP {optional}{type=0 or 1}{default=0} |
---|
25 | ; Activate to stop within the programm when getting a wrong lateral boundaries condition |
---|
26 | ; |
---|
27 | ; @returns |
---|
28 | ; the number of wrong lateral boundary condition found in arr (-> 0 means arr is OK) |
---|
29 | ; |
---|
30 | ; @restrictions |
---|
31 | ; only ORCA2, ORCA05 and ORCA025 are coded (but others are very easy to add...) |
---|
32 | ; |
---|
33 | ; @examples |
---|
34 | ; |
---|
35 | ; IDL> \@tst_initorca2 |
---|
36 | ; IDL> a = dist(jpiglo, jpjglo) |
---|
37 | ; IDL> print, lbcorca(a, 'T') |
---|
38 | ; IDL> dummy = lbcorca(a, 'T', /correction) |
---|
39 | ; IDL> print, lbcorca(a, 'T') |
---|
40 | |
---|
41 | ; @history |
---|
42 | ; Mai 2007: Creation, smasson\@locean-ipsl.upmc.fr |
---|
43 | ; |
---|
44 | ; @version |
---|
45 | ; $Id$ |
---|
46 | ; |
---|
47 | ;- |
---|
48 | FUNCTION lbcorca, arr, grid, psign, VERBOSE=verbose, CORRECTION=correction, STOP = stop |
---|
49 | ; |
---|
50 | compile_opt idl2, strictarrsubs |
---|
51 | ; |
---|
52 | IF n_elements(psign) EQ 0 THEN psign = 1. |
---|
53 | sz = size(arr) |
---|
54 | jpi = sz[1] |
---|
55 | jpj = sz[2] |
---|
56 | |
---|
57 | res = 0 |
---|
58 | |
---|
59 | ; east-west periodicity checks |
---|
60 | |
---|
61 | tst = arr[0, *, *, *] - arr[jpi-2, *, *, *] |
---|
62 | nberr = total(tst NE 0) |
---|
63 | IF nberr NE 0 THEN BEGIN |
---|
64 | IF keyword_set(verbose) THEN print, grid + 'east-west periodicity (1) : '+strtrim(nberr, 1)+' errors' |
---|
65 | IF keyword_set(verbose) AND nberr LE 10 THEN print, ' located on : ', where(tst NE 0) |
---|
66 | IF keyword_set(stop) THEN stop |
---|
67 | IF keyword_set(correction) THEN arr[0, *, *, *] = arr[jpi-2, *, *, *] |
---|
68 | res = res + 1 |
---|
69 | ENDIF |
---|
70 | tst = arr[1, *, *, *] - arr[jpi-1, *, *, *] |
---|
71 | nberr = total(tst NE 0) |
---|
72 | IF nberr NE 0 THEN BEGIN |
---|
73 | IF keyword_set(verbose) THEN print, grid + 'east-west periodicity (2) : '+strtrim(nberr, 1)+' errors' |
---|
74 | IF keyword_set(verbose) AND nberr LE 10 THEN print, ' located on : ', where(tst NE 0) |
---|
75 | IF keyword_set(stop) THEN stop |
---|
76 | IF keyword_set(correction) THEN arr[jpi-1, *, *, *] = arr[1, *, *, *] |
---|
77 | res = res + 1 |
---|
78 | ENDIF |
---|
79 | |
---|
80 | ; north pole periodicity |
---|
81 | |
---|
82 | CASE 1 OF |
---|
83 | (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... |
---|
84 | CASE grid OF |
---|
85 | 'T':BEGIN |
---|
86 | tst = arr[1:jpi-1, jpj-1, *, *] - psign * reverse(arr[1:jpi-1, jpj-3, *, *]) |
---|
87 | nberr = total(tst NE 0) |
---|
88 | IF nberr NE 0 THEN BEGIN |
---|
89 | IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity (1) : '+strtrim(nberr, 1)+' errors' |
---|
90 | IF keyword_set(verbose) AND nberr LE 10 THEN print, ' located on : ', where(tst NE 0) |
---|
91 | IF keyword_set(stop) THEN stop |
---|
92 | IF keyword_set(correction) THEN arr[1:jpi-1, jpj-1, *, *] = psign * reverse(arr[1:jpi-1, jpj-3, *, *]) |
---|
93 | res = res + 1 |
---|
94 | ENDIF |
---|
95 | tst = arr[1:jpi/2, jpj-2, *, *] - psign * reverse(arr[jpi/2:jpi-1, jpj-2, *, *]) |
---|
96 | nberr = total(tst NE 0) |
---|
97 | IF nberr NE 0 THEN BEGIN |
---|
98 | IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity (2) : '+strtrim(nberr, 1)+' errors' |
---|
99 | IF keyword_set(verbose) AND nberr LE 10 THEN print, ' located on : ', where(tst NE 0) |
---|
100 | IF keyword_set(stop) THEN stop |
---|
101 | IF keyword_set(correction) THEN arr[jpi/2:jpi-1, jpj-2, *, *] = psign * reverse(arr[1:jpi/2, jpj-2, *, *]) |
---|
102 | res = res + 1 |
---|
103 | ENDIF |
---|
104 | END |
---|
105 | 'U':BEGIN |
---|
106 | tst = arr[1:jpi-1, jpj-1, *, *] - psign * reverse(arr[0:jpi-2, jpj-3, *, *]) |
---|
107 | nberr = total(tst NE 0) |
---|
108 | IF nberr NE 0 THEN BEGIN |
---|
109 | IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity (1) : '+strtrim(nberr, 1)+' errors' |
---|
110 | IF keyword_set(verbose) AND nberr LE 10 THEN print, ' located on : ', where(tst NE 0) |
---|
111 | IF keyword_set(stop) THEN stop |
---|
112 | IF keyword_set(correction) THEN arr[1:jpi-1, jpj-1, *, *] = psign * reverse(arr[0:jpi-2, jpj-3, *, *]) |
---|
113 | res = res + 1 |
---|
114 | ENDIF |
---|
115 | tst = arr[1:jpi/2, jpj-2, *, *] - psign * reverse(arr[jpi/2-1:jpi-2, jpj-2, *, *]) |
---|
116 | nberr = total(tst NE 0) |
---|
117 | IF nberr NE 0 THEN BEGIN |
---|
118 | IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity (2) : '+strtrim(nberr, 1)+' errors' |
---|
119 | IF keyword_set(verbose) AND nberr LE 10 THEN print, ' located on : ', where(tst NE 0) |
---|
120 | IF keyword_set(stop) THEN stop |
---|
121 | IF keyword_set(correction) THEN arr[jpi/2-1:jpi-2, jpj-2, *, *] = psign * reverse(arr[1:jpi/2, jpj-2, *, *]) |
---|
122 | res = res + 1 |
---|
123 | ENDIF |
---|
124 | END |
---|
125 | 'V':BEGIN |
---|
126 | tst = arr[1:jpi-1, jpj-1, *, *] - psign * reverse(arr[1:jpi-1, jpj-4, *, *]) |
---|
127 | nberr = total(tst NE 0) |
---|
128 | IF nberr NE 0 THEN BEGIN |
---|
129 | IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity (1) : '+strtrim(nberr, 1)+' errors' |
---|
130 | IF keyword_set(verbose) AND nberr LE 10 THEN print, ' located on : ', where(tst NE 0) |
---|
131 | IF keyword_set(stop) THEN stop |
---|
132 | IF keyword_set(correction) THEN arr[1:jpi-1, jpj-1, *, *] = psign * reverse(arr[1:jpi-1, jpj-4, *, *]) |
---|
133 | res = res + 1 |
---|
134 | ENDIF |
---|
135 | tst = arr[1:jpi-1, jpj-2, *, *] - psign * reverse(arr[1:jpi-1, jpj-3, *, *]) |
---|
136 | nberr = total(tst NE 0) |
---|
137 | IF nberr NE 0 THEN BEGIN |
---|
138 | IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity (2) : '+strtrim(nberr, 1)+' errors' |
---|
139 | IF keyword_set(verbose) AND nberr LE 10 THEN print, ' located on : ', where(tst NE 0) |
---|
140 | IF keyword_set(stop) THEN stop |
---|
141 | IF keyword_set(correction) THEN arr[1:jpi-1, jpj-2, *, *] = psign * reverse(arr[1:jpi-1, jpj-3, *, *]) |
---|
142 | res = res + 1 |
---|
143 | ENDIF |
---|
144 | END |
---|
145 | 'F':BEGIN |
---|
146 | tst = arr[1:jpi-1, jpj-1, *, *] - psign * reverse(arr[0:jpi-2, jpj-4, *, *]) |
---|
147 | nberr = total(tst NE 0) |
---|
148 | IF nberr NE 0 THEN BEGIN |
---|
149 | IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity (1) : '+strtrim(nberr, 1)+' errors' |
---|
150 | IF keyword_set(verbose) AND nberr LE 10 THEN print, ' located on : ', where(tst NE 0) |
---|
151 | IF keyword_set(stop) THEN stop |
---|
152 | IF keyword_set(correction) THEN arr[1:jpi-1, jpj-1, *, *] = psign * reverse(arr[0:jpi-2, jpj-4, *, *]) |
---|
153 | res = res + 1 |
---|
154 | ENDIF |
---|
155 | tst = arr[1:jpi-1, jpj-2, *, *] - psign * reverse(arr[0:jpi-2, jpj-3, *, *]) |
---|
156 | nberr = total(tst NE 0) |
---|
157 | IF nberr NE 0 THEN BEGIN |
---|
158 | IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity (2) : '+strtrim(nberr, 1)+' errors' |
---|
159 | IF keyword_set(verbose) AND nberr LE 10 THEN print, ' located on : ', where(tst NE 0) |
---|
160 | IF keyword_set(stop) THEN stop |
---|
161 | IF keyword_set(correction) THEN arr[1:jpi-1, jpj-2, *, *] = psign * reverse(arr[0:jpi-2, jpj-3, *, *]) |
---|
162 | res = res + 1 |
---|
163 | ENDIF |
---|
164 | END |
---|
165 | ENDCASE |
---|
166 | END |
---|
167 | |
---|
168 | jpi EQ 722 AND jpj EQ 511:BEGIN ; this is ORCA05... |
---|
169 | CASE grid OF |
---|
170 | 'T':BEGIN |
---|
171 | tst = arr[1:jpi-2, jpj-1, *, *] - psign * reverse(arr[1:jpi-2, jpj-2, *, *]) |
---|
172 | nberr = total(tst NE 0) |
---|
173 | IF nberr NE 0 THEN BEGIN |
---|
174 | IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity : '+strtrim(nberr, 1)+' errors' |
---|
175 | IF keyword_set(verbose) AND nberr LE 10 THEN print, ' located on : ', where(tst NE 0) |
---|
176 | IF keyword_set(stop) THEN stop |
---|
177 | IF keyword_set(correction) THEN arr[1:jpi-2, jpj-1, *, *] = psign * reverse(arr[1:jpi-2, jpj-2, *, *]) |
---|
178 | res = res + 1 |
---|
179 | ENDIF |
---|
180 | END |
---|
181 | 'U':BEGIN |
---|
182 | tst = arr[1:jpi-2, jpj-1, *, *] - psign * reverse(arr[0:jpi-3, jpj-2, *, *]) |
---|
183 | nberr = total(tst NE 0) |
---|
184 | IF nberr NE 0 THEN BEGIN |
---|
185 | IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity : '+strtrim(nberr, 1)+' errors' |
---|
186 | IF keyword_set(verbose) AND nberr LE 10 THEN print, ' located on : ', where(tst NE 0) |
---|
187 | IF keyword_set(stop) THEN stop |
---|
188 | IF keyword_set(correction) THEN arr[1:jpi-2, jpj-1, *, *] = psign * reverse(arr[0:jpi-3, jpj-2, *, *]) |
---|
189 | res = res + 1 |
---|
190 | ENDIF |
---|
191 | END |
---|
192 | 'V':BEGIN |
---|
193 | tst = arr[1:jpi-2, jpj-1, *, *] - psign * reverse(arr[1:jpi-2, jpj-3, *, *]) |
---|
194 | nberr = total(tst NE 0) |
---|
195 | IF nberr NE 0 THEN BEGIN |
---|
196 | IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity (1) : '+strtrim(nberr, 1)+' errors' |
---|
197 | IF keyword_set(verbose) AND nberr LE 10 THEN print, ' located on : ', where(tst NE 0) |
---|
198 | IF keyword_set(stop) THEN stop |
---|
199 | IF keyword_set(correction) THEN arr[1:jpi-2, jpj-1, *, *] = psign * reverse(arr[1:jpi-2, jpj-3, *, *]) |
---|
200 | res = res + 1 |
---|
201 | ENDIF |
---|
202 | tst = arr[jpi/2:jpi-1, jpj-2, *, *] - psign * reverse(arr[0:jpi/2-1, jpj-2, *, *]) |
---|
203 | nberr = total(tst NE 0) |
---|
204 | IF nberr NE 0 THEN BEGIN |
---|
205 | IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity (2) : '+strtrim(nberr, 1)+' errors' |
---|
206 | IF keyword_set(verbose) AND nberr LE 10 THEN print, ' located on : ', where(tst NE 0) |
---|
207 | IF keyword_set(stop) THEN stop |
---|
208 | IF keyword_set(correction) THEN arr[jpi/2:jpi-1, jpj-2, *, *] = psign * reverse(arr[0:jpi/2-1, jpj-2, *, *]) |
---|
209 | res = res + 1 |
---|
210 | ENDIF |
---|
211 | END |
---|
212 | 'F':BEGIN |
---|
213 | tst = arr[1:jpi-2, jpj-1, *, *] - psign * reverse(arr[0:jpi-3, jpj-3, *, *]) |
---|
214 | nberr = total(tst NE 0) |
---|
215 | IF nberr NE 0 THEN BEGIN |
---|
216 | IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity (2) : '+strtrim(nberr, 1)+' errors' |
---|
217 | IF keyword_set(verbose) AND nberr LE 10 THEN print, ' located on : ', where(tst NE 0) |
---|
218 | IF keyword_set(stop) THEN stop |
---|
219 | IF keyword_set(correction) THEN arr[1:jpi-2, jpj-1, *, *] = psign * reverse(arr[0:jpi-3, jpj-3, *, *]) |
---|
220 | res = res + 1 |
---|
221 | ENDIF |
---|
222 | tst = arr[jpi/2:jpi-2, jpj-2, *, *] - psign * reverse(arr[0:jpi/2-2, jpj-2, *, *]) |
---|
223 | nberr = total(tst NE 0) |
---|
224 | IF nberr NE 0 THEN BEGIN |
---|
225 | IF keyword_set(verbose) THEN print, grid + 'grid: north pole periodicity (2) : '+strtrim(nberr, 1)+' errors' |
---|
226 | IF keyword_set(verbose) AND nberr LE 10 THEN print, ' located on : ', where(tst NE 0) |
---|
227 | IF keyword_set(stop) THEN stop |
---|
228 | IF keyword_set(correction) THEN arr[jpi/2:jpi-2, jpj-2, *, *] = psign * reverse(arr[0:jpi/2-2, jpj-2, *, *]) |
---|
229 | res = res + 1 |
---|
230 | ENDIF |
---|
231 | END |
---|
232 | ENDCASE |
---|
233 | END |
---|
234 | ENDCASE |
---|
235 | |
---|
236 | ; east-west periodicity correction (again) |
---|
237 | |
---|
238 | IF keyword_set(correction) THEN BEGIN |
---|
239 | arr[0 , *, *, *] = arr[jpi-2, *, *, *] |
---|
240 | arr[jpi-1, *, *, *] = arr[1 , *, *, *] |
---|
241 | ENDIF |
---|
242 | |
---|
243 | |
---|
244 | RETURN, res |
---|
245 | END |
---|