source: trunk/SRC/ToBeReviewed/PLOTS/DIVERS/checkfield.pro @ 296

Last change on this file since 296 was 296, checked in by pinsard, 17 years ago

typo

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 16.1 KB
Line 
1;+
2;
3; @file_comments
4;
5; @categories
6;
7; @param TYPE {in}{required}{type=string}
8; A string of two characters specifying the type of plot we do
9;
10; @param N1 {in}{required}{type=integer}
11; Number of elements in the first dimension
12;
13; @param N2 {in}{required}{type=integer}
14; Number of elements in the second dimension
15;
16; @param NAME {in}{optional}{type=string}
17; It gives the name of the file to be opened. If NAME
18; does not contain the separating character of directories ('/' under
19; unix for example), the file will be looked for in the current directory.
20;
21; @returns
22;
23; @restrictions
24;
25; @examples
26;
27; @history
28;
29; @version
30; $Id$
31;
32;-
33;
34FUNCTION err_1d, type, n1, name, n2
35;
36  compile_opt idl2, strictarrsubs
37;
38  return, report(['Error in "' + type + '" type plot with a 1D input array:' $
39                  , 'the number of elements of the input vector ('+strtrim(n1, 1)+') ' $
40                  , 'is not equal to ' + name + ' ('+strtrim(n2, 1)+')'], /simple)
41END
42;
43;+
44;
45; @file_comments
46;
47; @categories
48;
49; @param TYPE {in}{required}{type=string}
50; A string of two characters specifying the type of plot we do
51;
52; @param SZ {in}{optional}{default=defined by <pro>grille</pro>}
53;
54; @param NX {in}{optional}{default=defined by <pro>grille</pro>}
55;
56; @param NY {in}{optional}{default=defined by <pro>grille</pro>}
57;
58; @param NZ
59;
60; @returns
61;
62; @restrictions
63;
64; @examples
65;
66; @history
67;
68; @version
69; $Id$
70;
71;-
72;
73FUNCTION err_2d, type, sz, nx, ny, nz
74;
75  compile_opt idl2, strictarrsubs
76;
77  @cm_4mesh
78  @cm_4cal
79  return, report(['Error in "' + type + '" type plot with a 2D input array:' $
80                  , 'the array dimensions ' + tostr(sz[1:2]) + ' are incompatible' $
81                  , 'with the domain dimensions ' $
82                  , '[jpi/nx, jpj/ny, jpk/nz, jpt] = [' $
83                  + strtrim(jpi, 1) + '/' + strtrim(nx, 1) $
84                  + ', ' + strtrim(jpj, 1) + '/' + strtrim(ny, 1) $
85                  + ', ' + strtrim(jpk, 1) + '/' + strtrim(nz, 1) $
86                  + ', ' + strtrim(jpt, 1) + ']'], /simple)
87END
88;
89;+
90;
91; @file_comments
92;
93; @categories
94;
95; @param TYPE {in}{required}{type=string}
96; A string of two characters specifying the type of plot we do
97;
98; @param SZ {in}{optional}{default=defined by <pro>grille</pro>}
99;
100; @param NX {in}{optional}{default=defined by <pro>grille</pro>}
101;
102; @param NY {in}{optional}{default=defined by <pro>grille</pro>}
103;
104; @param NZ
105;
106; @returns
107;
108; @restrictions
109;
110; @examples
111;
112; @history
113;
114; @version
115; $Id$
116;
117;-
118;
119FUNCTION err_3d, type, sz, nx, ny, nz
120;
121  compile_opt idl2, strictarrsubs
122;
123  @cm_4mesh
124  @cm_4cal
125  return, report(['Error in "' + type + '" type plot with a 3D input array:' $
126                  , 'the array dimensions ' + tostr(sz[1:3]) + ' are incompatible' $
127                  , 'with the domain dimensions ' $
128                  , '[jpi/nx, jpj/ny, jpk/nz, jpt] = [' $
129                  + strtrim(jpi, 1) + '/' + strtrim(nx, 1) $
130                  + ', ' + strtrim(jpj, 1) + '/' + strtrim(ny, 1) $
131                  + ', ' + strtrim(jpk, 1) + '/' + strtrim(nz, 1) $
132                  + ', ' + strtrim(jpt, 1) + ']'], /simple)
133END
134;
135;+
136;
137; @file_comments
138; In input of <pro>plt</pro>, <pro>pltz</pro>, <pro>pltt</pro> and <pro>plt1d</pro>, it check that the field give
139; a size compatible with the domain and, if needed, average to give us
140; a 2d array if we make a plot of the type: 'xy', 'xz', 'xt', 'yz', 'yt'
141; , 'zt' or a 1d array if we make a plot of the type: 'x', 'y', 'z', 't'.
142;
143; @categories
144; Graphics
145;
146; @param FIELD {in}{required}{type=field}
147; It respect <pro>litchamp</pro>'s criterions. See IDL>xhelp,'litchamp'
148;
149; @param PROCEDURE {in}{required}
150;
151; @keyword TYPE
152;
153; @keyword NOQUESTION
154;
155; @keyword BOXZOOM {type=vector}
156; Vector indicating the geographic zone on which we want to cut the map.
157;  If BOXZOOM has :
158; 1 element : The extraction is made on [lon1, lon2, lat1, lat2, 0.,boxzoom[0]]
159; 2 elements: The extraction is made on [lon1, lon2, lat1, lat2, boxzoom[0],boxzoom[1]]
160; 4 elements: The extraction is made on [Boxzoom, 0, max([gdept, gdepw])]
161; 5 elements: The extraction is made on [Boxzoom[0:3], 0, Boxzoom[4]]
162; 6 elements: The extraction is made on Boxzoom
163;
164; Where lon1, lon2,lat1,lat2 are global variables defined at the last
165; <pro>domdef</pro> !
166;
167; @keyword WDEPTH
168; to specify that the field is at W depth instead of T
169; depth (automatically activated if vargrid eq 'W')
170;
171; @keyword VECTEUR{type=vector}
172; It is a structure composed by 2 elements containing the 2 fields U
173; and V of values of the zonal and meridian component of the vector of the fields
174; to draw. These fields can be an array or a structure.
175;       For example: vecteur={matriceu:lec('unsurface'),matricev:lec('vnsurface')}
176;       Comment: name of elements of vectors are inconsequential.
177;       vecteur={u:lec('unsurface'),v:lec('vnsurface')} is also appropriated.
178;
179; @keyword _EXTRA
180; Used to pass keywords
181;
182; @keyword DIREC
183;
184; @uses
185; common.pro
186;
187; @history
188; Sebastien Masson (smasson\@lodyc.jussieu.fr)
189;                      08/02/2000
190;
191; @version
192; $Id$
193;
194; @todo seb: mettre les param
195;
196;-
197;
198FUNCTION checkfield, field, procedure, TYPE = type, BOXZOOM = boxzoom, DIREC = direc, NOQUESTION = noquestion, VECTEUR = vecteur, WDEPTH = wdepth, _EXTRA = ex
199;
200  compile_opt idl2, strictarrsubs
201;
202@cm_4mesh
203@cm_4cal
204@cm_4data
205  IF NOT keyword_set(key_forgetold) THEN BEGIN
206@updatenew
207@updatekwd
208  ENDIF
209;--------------------------------------------------------------
210; I1) Reading of the field
211;--------------------------------------------------------------
212  if n_elements(field) EQ 0 then return, report('field undefined')
213  arr = litchamp(field)
214; first check
215  IF n_elements(arr) EQ 1 THEN BEGIN
216    if arr EQ -1 then $
217      return, report('Error: input array = -1. Maybe the reading did ont perform well...', /simple) $
218    ELSE return, report('Error: input array is a scalar', /simple)
219  ENDIF
220  nan = total(finite(arr, /nan)) < 1
221;---------------------------------------------------------------
222; redefinition of the domain
223;---------------------------------------------------------------
224  minprof = 0.
225  profdefault = 200.
226;
227  Case n_elements(boxzoom) OF
228    0:
229    1:localbox = [minprof, boxzoom[0]]
230    2:localbox = boxzoom
231    4:if strpos(type, 'z') NE -1 THEN $
232      localbox = [boxzoom, minprof, profdefault] ELSE localbox = boxzoom
233    5:localbox = [Boxzoom[0:3], minprof, Boxzoom[4]]
234    6:localbox = boxzoom
235    Else: return, report('Bad definition of boxzoom')
236  ENDCASE
237;
238  if keyword_set(localbox) then BEGIN
239    if keyword_set(vecteur) then grillechoice = [vargrid, 'T', 'U', 'V'] $
240    ELSE grillechoice = [vargrid, 'T']
241    if keyword_set(wdepth) then grillechoice = [grillechoice, 'W']
242    domdef, localbox, GRIDTYPE = grillechoice, _extra = ex
243  ENDIF
244;
245; The procedure domdef determine elements which are inside the boxzoom.
246;
247  if strpos(type, 'z') NE -1 THEN BEGIN
248    if NOT keyword_set(localbox) then BEGIN
249      localbox = [minprof, profdefault]
250      if keyword_set(wdepth) then grillechoice = 'W' $
251      ELSE grillechoice = vargrid
252      domdef, localbox, GRIDTYPE = grillechoice
253    END
254    nelbox = n_elements(localbox)
255;we keep yranges (z axis) before changing the boxzoom.
256    !y.range = [localbox[nelbox-1], localbox[nelbox-2]]
257    if vargrid EQ 'W' OR keyword_set(wdepth) then BEGIN
258      firstzw = 0 > (firstzw-1)
259      lastzw = (lastzw+1) < (jpk-1)
260      nzw = lastzw - firstzw + 1
261    ENDIF ELSE BEGIN
262      firstzt = 0 > (firstzt-1)
263      lastzt = (lastzt+1) < (jpk-1)
264      nzt = lastzt - firstzt + 1
265    ENDELSE
266    @updateold
267  ENDIF
268; make the automatic definition of type for pltz if type is not specified.
269  IF type EQ 'z' AND procedure EQ 'pltz' THEN $
270    if (lon2-lon1) gt (lat2-lat1) then type = 'xz' else type = 'yz'
271; make the automatic definition of type for pltt if type is not specified.
272  IF type EQ 'unkownpltt' AND procedure EQ 'pltt' THEN $
273    if (lon2-lon1) gt (lat2-lat1) then type = 'xt' else type = 'yt'
274;--------------------------------------------------------------
275; verification of the input array size and the value of the type
276;--------------------------------------------------------------
277  grille, -1, -1, -1, -1, nx, ny, nz, firstx, firsty $
278    , firstz, lastx, lasty, lastz, WDEPTH = wdepth
279;--------------------------------------------------------------
280; basic checks
281;--------------------------------------------------------------
282  CASE 1 OF
283    nx EQ 1: IF strpos(type, 'x') NE -1 THEN return, report('Error: impossible to make a "' + type + '" type plot with nx = 1 ', /simple)
284    ny EQ 1: IF strpos(type, 'y') NE -1 THEN return, report('Error: impossible to make a "' + type + '" type plot with ny = 1 ', /simple)
285    nz EQ 1: IF strpos(type, 'z') NE -1 THEN return, report('Error: impossible to make a "' + type + '" type plot with nz = 1 ', /simple)
286    jpt EQ 1: IF strpos(type, 't') NE -1 THEN return, report('Error: impossible to make a "' + type + '" type plot with jpt = 1 ', /simple)
287    ELSE:
288  ENDCASE
289;--------------------------------------------------------------
290; is the size of the array compatible with teh domain?
291;--------------------------------------------------------------
292  arr = fitintobox(temporary(arr), nx, ny, nz, firstx, firsty $
293    , firstz, lastx, lasty, lastz)
294;--------------------------------------------------------------
295  sz = size(arr)
296  case sz[0] of
297;--------------------------------------------------------------
298    0:return, arr
299;--------------------------------------------------------------
300    1:BEGIN
301      nele = n_elements(arr)
302      case type of
303        't':if jpt NE nele THEN return, err_1d(type, nele, 'jpt', jpt)
304        'x':IF  nx NE nele THEN return, err_1d(type, nele,  'nx',  nx)
305        'y':IF  ny NE nele THEN return, err_1d(type, nele,  'ny',  ny)
306        'z':IF  nz NE nele THEN return, err_1d(type, nele,  'nz',  nx)
307        ELSE:return, report(['Error: ' $
308                            , 'Impossible to make a "'+type+'" plot with a 1D array'], /simple)
309      ENDCASE
310    END
311;--------------------------------------------------------------
312    2:BEGIN
313      case type of
314        'x':BEGIN
315          case 1 of
316            sz[1] EQ nx AND sz[2] EQ ny:direc = 'y' ; xy array
317            sz[1] EQ nx AND ny EQ 1 AND sz[2] EQ nz:direc = 'z' ; x(y)z array
318            sz[1] EQ nx AND sz[2] EQ jpt:direc = 't' ; xt array
319            ELSE:return, err_2d(type, sz, nx, ny, nz)
320          endcase
321        end
322        'y':BEGIN
323          case 1 of
324            sz[1] EQ nx AND sz[2] EQ ny:direc = 'x' ; xy array
325            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ nz:direc = 'z' ; (x)yz array
326            sz[1] EQ ny AND sz[2] EQ jpt:direc = 't' ; yt array
327            ELSE:return, err_2d(type, sz, nx, ny, nz)
328          endcase
329        END
330        'z':BEGIN
331          case 1 of
332            sz[1] EQ nx AND ny EQ 1 AND sz[2] EQ nz:direc = 'x' ; x(y)z array
333            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ nz:direc = 'y' ; (x)yz array
334            sz[1] EQ nz AND sz[2] EQ jpt:direc = 't' ; zt array
335            ELSE:return, err_2d(type, sz, nx, ny, nz)
336          endcase
337        END
338        't':BEGIN
339          case 1 OF
340            sz[1] EQ nx AND sz[2] EQ jpt:direc = 'x' ; xt array
341            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ jpt:direc = 'y' ; (x)yt array
342            nx EQ 1 AND ny EQ 1 AND sz[1] EQ nz AND sz[2] EQ jpt:direc = 'z' ; (x)(y)zt array
343            ELSE:return, err_2d(type, sz, nx, ny, nz)
344          ENDCASE
345        END
346        'xy':IF sz[1] NE nx OR sz[2] ne  ny THEN return, err_2d(type, sz, nx, ny, nz) ; xy array
347        'xz':IF sz[1] NE nx OR sz[2] ne  nz THEN return, err_2d(type, sz, nx, ny, nz) ; xz array
348        'yz':IF sz[1] NE ny OR sz[2] NE  nz THEN return, err_2d(type, sz, nx, ny, nz) ; yz array
349        'xt':IF sz[1] NE nx OR sz[2] NE jpt THEN return, err_2d(type, sz, nx, ny, nz) ; xt array
350        'yt':IF sz[1] NE ny OR sz[2] NE jpt THEN return, err_2d(type, sz, nx, ny, nz) ; yt array
351        'zt':IF sz[1] NE nz OR sz[2] NE jpt THEN return, err_2d(type, sz, nx, ny, nz) ; zt array
352      ENDCASE
353    END
354;--------------------------------------------------------------
355    3:BEGIN
356      case type of
357        'x':BEGIN
358          case 1 of
359            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ nz:direc = 'yz' ; xyz array
360            sz[1] EQ nx AND ny EQ 1 AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'zt' ; x(y)zt array
361            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ jpt:direc = 'yt' ; xyt array
362            ELSE:return, err_3d(type, sz, nx, ny, nz)
363          endcase
364        END
365        'y':BEGIN
366          case 1 of
367            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ nz:direc = 'xz' ; xyz array
368            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'zt' ; (x)yzt array
369            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ jpt:direc = 'xt' ; xyt array
370            ELSE:return, err_3d(type, sz, nx, ny, nz)
371          endcase
372        END
373        'z':BEGIN
374          case 1 of
375            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ nz:direc = 'xy' ; xyz array
376            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'yt' ; (x)yzt array
377            sz[1] EQ nx AND ny EQ 1 AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'xt' ; x(y)zt array
378            ELSE:return, err_3d(type, sz, nx, ny, nz)
379          endcase
380        END
381        't':BEGIN
382          case 1 of
383            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ jpt:direc = 'xy' ; xyt array
384            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'yz' ; (x)yzt array
385            sz[1] EQ nx AND ny EQ 1 AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'xz' ; x(y)zt array
386            ELSE:return, err_3d(type, sz, nx, ny, nz)
387          endcase
388        END
389        'xy':BEGIN
390          case 1 OF
391            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ  nz:direc = 'z' ; xyz array
392            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ jpt:direc = 't' ; xyt array
393            ELSE:return, err_3d(type, sz, nx, ny, nz)
394          endcase
395        END
396        'xz':BEGIN
397          case 1 of
398            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ  nz:direc = 'y' ; xyz array
399            sz[1] EQ nx AND ny EQ 1 AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 't' ; x(y)zt
400            ELSE:return, err_3d(type, sz, nx, ny, nz)
401          endcase
402        END
403        'yz':BEGIN
404          case 1 of
405            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ  nz:direc = 'x' ; xyz array
406            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 't' ; (x)yzt
407            ELSE:return, err_3d(type, sz, nx, ny, nz)
408          endcase
409        END
410        'xt':BEGIN
411          case 1 of
412            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ jpt:direc = 'y' ; xyt array
413            sz[1] EQ nx AND ny EQ 1 AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'z' ; x(y)zt array
414            ELSE:return, err_3d(type, sz, nx, ny, nz)
415          endcase
416        END
417        'yt':BEGIN
418          case 1 of
419            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ jpt:direc = 'x' ; xyt array
420            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'z' ; (x)yzt array
421            ELSE:return, err_3d(type, sz, nx, ny, nz)
422          endcase
423        END
424        'zt':BEGIN
425          case 1 of
426            sz[1] EQ nx AND ny EQ 1 AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'x' ; x(y)zt array
427            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'y' ; (x)yzt array
428            ELSE:return, err_3d(type, sz, nx, ny, nz)
429          ENDCASE
430        END
431      ENDCASE
432    END
433;--------------------------------------------------------------
434    4:BEGIN
435      CASE type OF
436        'x':direc = 'yzt'
437        'y':direc = 'xzt'
438        'z':direc = 'xyt'
439        't':direc = 'xyz'
440        'xy':direc = 'zt'
441        'xz':direc = 'yt'
442        'yz':direc = 'xt'
443        'xt':direc = 'yz'
444        'yt':direc = 'xz'
445        'zt':direc = 'xy'
446      ENDCASE
447    END
448  ENDCASE
449;--------------------------------------------------------------
450  IF keyword_set(direc) THEN BEGIN
451    IF strpos(direc, 't') NE -1 OR strpos(type, 't') NE -1 THEN $
452      arr = grossemoyenne(temporary(arr), direc, boxzoom = localbox $
453                          , NAN = nan, /NODOMDEF, WDEPTH = wdepth, _extra = ex) $
454    ELSE arr = moyenne(temporary(arr), direc, boxzoom = localbox $
455                       , NAN = nan, /NODOMDEF, WDEPTH = wdepth, _extra = ex)
456  ENDIF
457  RETURN, arr
458END
Note: See TracBrowser for help on using the repository browser.