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

Last change on this file since 163 was 163, checked in by navarro, 18 years ago

header improvements : type of parameters and keywords, default values, spell checking + idldoc assistant (IDL online_help)

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