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

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

modification of headers : mainly blanks around = sign for keywords in declaration of function and pro

  • 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 $
195                   , TYPE=type, BOXZOOM=boxzoom, DIREC=direc $
196                   , NOQUESTION=noquestion, VECTEUR=vecteur, WDEPTH=wdepth $
197                   , _EXTRA=ex
198;
199  compile_opt idl2, strictarrsubs
200;
201@cm_4mesh
202@cm_4cal
203@cm_4data
204  IF NOT keyword_set(key_forgetold) THEN BEGIN
205@updatenew
206@updatekwd
207  ENDIF
208;--------------------------------------------------------------
209; I1) Reading of the field
210;--------------------------------------------------------------
211  if n_elements(field) EQ 0 then return, report('field undefined')
212  arr = litchamp(field)
213; first check
214  IF n_elements(arr) EQ 1 THEN BEGIN
215    if arr EQ -1 then $
216      return, report('Error: input array = -1. Maybe the reading did ont perform well...', /simple) $
217    ELSE return, report('Error: input array is a scalar', /simple)
218  ENDIF
219  nan = total(finite(arr, /nan)) < 1
220;---------------------------------------------------------------
221; redefinition of the domain
222;---------------------------------------------------------------
223  minprof = 0.
224  profdefault = 200.
225;
226  Case n_elements(boxzoom) OF
227    0:
228    1:localbox = [minprof, boxzoom[0]]
229    2:localbox = boxzoom
230    4:if strpos(type, 'z') NE -1 THEN $
231      localbox = [boxzoom, minprof, profdefault] ELSE localbox = boxzoom
232    5:localbox = [Boxzoom[0:3], minprof, Boxzoom[4]]
233    6:localbox = boxzoom
234    Else: return, report('Bad definition of boxzoom')
235  ENDCASE
236;
237  if keyword_set(localbox) then BEGIN
238    if keyword_set(vecteur) then grillechoice = [vargrid, 'T', 'U', 'V'] $
239    ELSE grillechoice = [vargrid, 'T']
240    if keyword_set(wdepth) then grillechoice = [grillechoice, 'W']
241    domdef, localbox, GRIDTYPE = grillechoice, _extra = ex
242  ENDIF
243;
244; The procedure domdef determine elements which are inside the boxzoom.
245;
246  if strpos(type, 'z') NE -1 THEN BEGIN
247    if NOT keyword_set(localbox) then BEGIN
248      localbox = [minprof, profdefault]
249      if keyword_set(wdepth) then grillechoice = 'W' $
250      ELSE grillechoice = vargrid
251      domdef, localbox, GRIDTYPE = grillechoice
252    END
253    nelbox = n_elements(localbox)
254;we keep yranges (z axis) before changing the boxzoom.
255    !y.range = [localbox[nelbox-1], localbox[nelbox-2]]
256    if vargrid EQ 'W' OR keyword_set(wdepth) then BEGIN
257      firstzw = 0 > (firstzw-1)
258      lastzw = (lastzw+1) < (jpk-1)
259      nzw = lastzw - firstzw + 1
260    ENDIF ELSE BEGIN
261      firstzt = 0 > (firstzt-1)
262      lastzt = (lastzt+1) < (jpk-1)
263      nzt = lastzt - firstzt + 1
264    ENDELSE
265    @updateold
266  ENDIF
267; make the automatic definition of type for pltz if type is not specified.
268  IF type EQ 'z' AND procedure EQ 'pltz' THEN $
269    if (lon2-lon1) gt (lat2-lat1) then type = 'xz' else type = 'yz'
270; make the automatic definition of type for pltt if type is not specified.
271  IF type EQ 'unkownpltt' AND procedure EQ 'pltt' THEN $
272    if (lon2-lon1) gt (lat2-lat1) then type = 'xt' else type = 'yt'
273;--------------------------------------------------------------
274; verification of the input array size and the value of the type
275;--------------------------------------------------------------
276  grille, -1, -1, -1, -1, nx, ny, nz, firstx, firsty $
277    , firstz, lastx, lasty, lastz, WDEPTH = wdepth
278;--------------------------------------------------------------
279; basic checks
280;--------------------------------------------------------------
281  CASE 1 OF
282    nx EQ 1: IF strpos(type, 'x') NE -1 THEN return, report('Error: impossible to make a "' + type + '" type plot with nx = 1 ', /simple)
283    ny EQ 1: IF strpos(type, 'y') NE -1 THEN return, report('Error: impossible to make a "' + type + '" type plot with ny = 1 ', /simple)
284    nz EQ 1: IF strpos(type, 'z') NE -1 THEN return, report('Error: impossible to make a "' + type + '" type plot with nz = 1 ', /simple)
285    jpt EQ 1: IF strpos(type, 't') NE -1 THEN return, report('Error: impossible to make a "' + type + '" type plot with jpt = 1 ', /simple)
286    ELSE:
287  ENDCASE
288;--------------------------------------------------------------
289; is the size of the array compatible with the domain?
290;--------------------------------------------------------------
291  arr = fitintobox(temporary(arr), nx, ny, nz, firstx, firsty $
292    , firstz, lastx, lasty, lastz)
293;--------------------------------------------------------------
294  sz = size(arr)
295  case sz[0] of
296;--------------------------------------------------------------
297    0:return, arr
298;--------------------------------------------------------------
299    1:BEGIN
300      nele = n_elements(arr)
301      case type of
302        't':if jpt NE nele THEN return, err_1d(type, nele, 'jpt', jpt)
303        'x':IF  nx NE nele THEN return, err_1d(type, nele,  'nx',  nx)
304        'y':IF  ny NE nele THEN return, err_1d(type, nele,  'ny',  ny)
305        'z':IF  nz NE nele THEN return, err_1d(type, nele,  'nz',  nx)
306        ELSE:return, report(['Error: ' $
307                            , 'Impossible to make a "'+type+'" plot with a 1D array'], /simple)
308      ENDCASE
309    END
310;--------------------------------------------------------------
311    2:BEGIN
312      case type of
313        'x':BEGIN
314          case 1 of
315            sz[1] EQ nx AND sz[2] EQ ny:direc = 'y' ; xy array
316            sz[1] EQ nx AND ny EQ 1 AND sz[2] EQ nz:direc = 'z' ; x(y)z array
317            sz[1] EQ nx AND sz[2] EQ jpt:direc = 't' ; xt array
318            ELSE:return, err_2d(type, sz, nx, ny, nz)
319          endcase
320        end
321        'y':BEGIN
322          case 1 of
323            sz[1] EQ nx AND sz[2] EQ ny:direc = 'x' ; xy array
324            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ nz:direc = 'z' ; (x)yz array
325            sz[1] EQ ny AND sz[2] EQ jpt:direc = 't' ; yt array
326            ELSE:return, err_2d(type, sz, nx, ny, nz)
327          endcase
328        END
329        'z':BEGIN
330          case 1 of
331            sz[1] EQ nx AND ny EQ 1 AND sz[2] EQ nz:direc = 'x' ; x(y)z array
332            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ nz:direc = 'y' ; (x)yz array
333            sz[1] EQ nz AND sz[2] EQ jpt:direc = 't' ; zt array
334            ELSE:return, err_2d(type, sz, nx, ny, nz)
335          endcase
336        END
337        't':BEGIN
338          case 1 OF
339            sz[1] EQ nx AND sz[2] EQ jpt:direc = 'x' ; xt array
340            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ jpt:direc = 'y' ; (x)yt array
341            nx EQ 1 AND ny EQ 1 AND sz[1] EQ nz AND sz[2] EQ jpt:direc = 'z' ; (x)(y)zt array
342            ELSE:return, err_2d(type, sz, nx, ny, nz)
343          ENDCASE
344        END
345        'xy':IF sz[1] NE nx OR sz[2] ne  ny THEN return, err_2d(type, sz, nx, ny, nz) ; xy array
346        'xz':IF sz[1] NE nx OR sz[2] ne  nz THEN return, err_2d(type, sz, nx, ny, nz) ; xz array
347        'yz':IF sz[1] NE ny OR sz[2] NE  nz THEN return, err_2d(type, sz, nx, ny, nz) ; yz array
348        'xt':IF sz[1] NE nx OR sz[2] NE jpt THEN return, err_2d(type, sz, nx, ny, nz) ; xt array
349        'yt':IF sz[1] NE ny OR sz[2] NE jpt THEN return, err_2d(type, sz, nx, ny, nz) ; yt array
350        'zt':IF sz[1] NE nz OR sz[2] NE jpt THEN return, err_2d(type, sz, nx, ny, nz) ; zt array
351      ENDCASE
352    END
353;--------------------------------------------------------------
354    3:BEGIN
355      case type of
356        'x':BEGIN
357          case 1 of
358            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ nz:direc = 'yz' ; xyz array
359            sz[1] EQ nx AND ny EQ 1 AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'zt' ; x(y)zt array
360            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ jpt:direc = 'yt' ; xyt array
361            ELSE:return, err_3d(type, sz, nx, ny, nz)
362          endcase
363        END
364        'y':BEGIN
365          case 1 of
366            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ nz:direc = 'xz' ; xyz array
367            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'zt' ; (x)yzt array
368            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ jpt:direc = 'xt' ; xyt array
369            ELSE:return, err_3d(type, sz, nx, ny, nz)
370          endcase
371        END
372        'z':BEGIN
373          case 1 of
374            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ nz:direc = 'xy' ; xyz array
375            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'yt' ; (x)yzt array
376            sz[1] EQ nx AND ny EQ 1 AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'xt' ; x(y)zt array
377            ELSE:return, err_3d(type, sz, nx, ny, nz)
378          endcase
379        END
380        't':BEGIN
381          case 1 of
382            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ jpt:direc = 'xy' ; xyt array
383            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'yz' ; (x)yzt array
384            sz[1] EQ nx AND ny EQ 1 AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'xz' ; x(y)zt array
385            ELSE:return, err_3d(type, sz, nx, ny, nz)
386          endcase
387        END
388        'xy':BEGIN
389          case 1 OF
390            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ  nz:direc = 'z' ; xyz array
391            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ jpt:direc = 't' ; xyt array
392            ELSE:return, err_3d(type, sz, nx, ny, nz)
393          endcase
394        END
395        'xz':BEGIN
396          case 1 of
397            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ  nz:direc = 'y' ; xyz array
398            sz[1] EQ nx AND ny EQ 1 AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 't' ; x(y)zt
399            ELSE:return, err_3d(type, sz, nx, ny, nz)
400          endcase
401        END
402        'yz':BEGIN
403          case 1 of
404            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ  nz:direc = 'x' ; xyz array
405            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 't' ; (x)yzt
406            ELSE:return, err_3d(type, sz, nx, ny, nz)
407          endcase
408        END
409        'xt':BEGIN
410          case 1 of
411            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ jpt:direc = 'y' ; xyt array
412            sz[1] EQ nx AND ny EQ 1 AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'z' ; x(y)zt array
413            ELSE:return, err_3d(type, sz, nx, ny, nz)
414          endcase
415        END
416        'yt':BEGIN
417          case 1 of
418            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ jpt:direc = 'x' ; xyt array
419            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'z' ; (x)yzt array
420            ELSE:return, err_3d(type, sz, nx, ny, nz)
421          endcase
422        END
423        'zt':BEGIN
424          case 1 of
425            sz[1] EQ nx AND ny EQ 1 AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'x' ; x(y)zt array
426            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'y' ; (x)yzt array
427            ELSE:return, err_3d(type, sz, nx, ny, nz)
428          ENDCASE
429        END
430      ENDCASE
431    END
432;--------------------------------------------------------------
433    4:BEGIN
434      CASE type OF
435        'x':direc = 'yzt'
436        'y':direc = 'xzt'
437        'z':direc = 'xyt'
438        't':direc = 'xyz'
439        'xy':direc = 'zt'
440        'xz':direc = 'yt'
441        'yz':direc = 'xt'
442        'xt':direc = 'yz'
443        'yt':direc = 'xz'
444        'zt':direc = 'xy'
445      ENDCASE
446    END
447  ENDCASE
448;--------------------------------------------------------------
449  IF keyword_set(direc) THEN BEGIN
450    IF strpos(direc, 't') NE -1 OR strpos(type, 't') NE -1 THEN $
451      arr = grossemoyenne(temporary(arr), direc, boxzoom = localbox $
452                          , NAN = nan, /NODOMDEF, WDEPTH = wdepth, _extra = ex) $
453    ELSE arr = moyenne(temporary(arr), direc, boxzoom = localbox $
454                       , NAN = nan, /NODOMDEF, WDEPTH = wdepth, _extra = ex)
455  ENDIF
456  RETURN, arr
457END
Note: See TracBrowser for help on using the repository browser.