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

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

modification of some headers (+some corrections) to prepare usage of the new idldoc

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