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

Last change on this file since 378 was 378, checked in by pinsard, 16 years ago

improvements of headers (typo, links, paragraphes, etc)

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