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
RevLine 
[157]1;+
[231]2;
3; @file_comments
4;
[157]5; @categories
[231]6;
[163]7; @param TYPE {in}{required}{type=string}
[157]8; A string of two characters specifying the type of plot we do
9;
[163]10; @param N1 {in}{required}{type=integer}
[157]11; Number of elements in the first dimension
12;
[163]13; @param N2 {in}{required}{type=integer}
[157]14; Number of elements in the second dimension
15;
[163]16; @param NAME {in}{optional}{type=string}
17; It gives the name of the file to be opened. If NAME
[157]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
[231]22;
[157]23; @restrictions
[231]24;
[157]25; @examples
26;
27; @history
28;
29; @version
30; $Id$
[237]31;
[157]32;-
[37]33FUNCTION err_1d, type, n1, name, n2
[114]34;
35  compile_opt idl2, strictarrsubs
36;
[37]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;
[157]42;+
[231]43;
44; @file_comments
45;
[157]46; @categories
[231]47;
[163]48; @param TYPE {in}{required}{type=string}
[157]49; A string of two characters specifying the type of plot we do
50;
[232]51; @param SZ {in}{optional}{default=defined by <pro>grille</pro>}
[231]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;
[157]57; @param NZ
[231]58;
[157]59; @returns
[231]60;
[157]61; @restrictions
[231]62;
[157]63; @examples
64;
65; @history
66;
67; @version
68; $Id$
[237]69;
[157]70;-
[37]71FUNCTION err_2d, type, sz, nx, ny, nz
[114]72;
73  compile_opt idl2, strictarrsubs
74;
[37]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' $
[238]79                  , 'with the domain dimensions ' $
[37]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;
[157]87;+
[231]88;
89; @file_comments
90;
[157]91; @categories
[231]92;
[163]93; @param TYPE {in}{required}{type=string}
[157]94; A string of two characters specifying the type of plot we do
95;
[231]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;
[157]102; @param NZ
[231]103;
[157]104; @returns
[231]105;
[157]106; @restrictions
[231]107;
[157]108; @examples
109;
110; @history
111;
112; @version
113; $Id$
[231]114;
[157]115;-
[37]116FUNCTION err_3d, type, sz, nx, ny, nz
[114]117;
118  compile_opt idl2, strictarrsubs
119;
[37]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' $
[238]124                  , 'with the domain dimensions ' $
[37]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
[231]131;
[142]132;+
133;
134; @file_comments
[296]135; In input of <pro>plt</pro>, <pro>pltz</pro>, <pro>pltt</pro> and <pro>plt1d</pro>, it check that the field give
[231]136; a size compatible with the domain and, if needed, average to give us
[142]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
[157]141; Graphics
[231]142;
[163]143; @param FIELD {in}{required}{type=field}
[231]144; It respect <pro>litchamp</pro>'s criterions. See IDL>xhelp,'litchamp'
[142]145;
[157]146; @param PROCEDURE {in}{required}
147;
148; @keyword TYPE
149;
150; @keyword NOQUESTION
151;
[163]152; @keyword BOXZOOM {type=vector}
[231]153; Vector indicating the geographic zone on which we want to cut the map.
[142]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;
[237]161; Where lon1, lon2,lat1,lat2 are global variables defined at the last
162; <pro>domdef</pro> !
[142]163;
164; @keyword WDEPTH
[231]165; to specify that the field is at W depth instead of T
[142]166; depth (automatically activated if vargrid eq 'W')
[231]167;
[237]168; @keyword VECTEUR{type=vector}
[142]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')}
[163]173;       Comment: name of elements of vectors are inconsequential.
[142]174;       vecteur={u:lec('unsurface'),v:lec('vnsurface')} is also appropriated.
175;
176; @keyword _EXTRA
[231]177; Used to pass keywords
[142]178;
[231]179; @keyword DIREC
[142]180;
[231]181; @uses
[142]182; common.pro
183;
184; @history
[157]185; Sebastien Masson (smasson\@lodyc.jussieu.fr)
[142]186;                      08/02/2000
187;
188; @version
189; $Id$
190;
[231]191; @todo seb: mettre les param
[142]192;
193;-
[37]194FUNCTION checkfield, field, procedure, TYPE = type, BOXZOOM = boxzoom, DIREC = direc, NOQUESTION = noquestion, VECTEUR = vecteur, WDEPTH = wdepth, _EXTRA = ex
[114]195;
196  compile_opt idl2, strictarrsubs
197;
[37]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;--------------------------------------------------------------
[142]206; I1) Reading of the field
[2]207;--------------------------------------------------------------
[37]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) $
[231]214    ELSE return, report('Error: input array is a scalar', /simple)
[37]215  ENDIF
216  nan = total(finite(arr, /nan)) < 1
[2]217;---------------------------------------------------------------
[142]218; redefinition of the domain
[2]219;---------------------------------------------------------------
[37]220  minprof = 0.
221  profdefault = 200.
[2]222;
[37]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
[2]233;
[37]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;
[231]241; The procedure domdef determine elements which are inside the boxzoom.
242;
[37]243  if strpos(type, 'z') NE -1 THEN BEGIN
[231]244    if NOT keyword_set(localbox) then BEGIN
[37]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)
[142]251;we keep yranges (z axis) before changing the boxzoom.
[231]252    !y.range = [localbox[nelbox-1], localbox[nelbox-2]]
[37]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'
[2]270;--------------------------------------------------------------
[142]271; verification of the input array size and the value of the type
[2]272;--------------------------------------------------------------
[37]273  grille, -1, -1, -1, -1, nx, ny, nz, firstx, firsty $
274    , firstz, lastx, lasty, lastz, WDEPTH = wdepth
[2]275;--------------------------------------------------------------
[37]276; basic checks
[2]277;--------------------------------------------------------------
[37]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
[2]285;--------------------------------------------------------------
[297]286; is the size of the array compatible with the domain?
[2]287;--------------------------------------------------------------
[37]288  arr = fitintobox(temporary(arr), nx, ny, nz, firstx, firsty $
289    , firstz, lastx, lasty, lastz)
[2]290;--------------------------------------------------------------
[37]291  sz = size(arr)
292  case sz[0] of
[2]293;--------------------------------------------------------------
[37]294    0:return, arr
[2]295;--------------------------------------------------------------
[37]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)
[69]303        ELSE:return, report(['Error: ' $
304                            , 'Impossible to make a "'+type+'" plot with a 1D array'], /simple)
[37]305      ENDCASE
[231]306    END
[2]307;--------------------------------------------------------------
[37]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
[231]349    END
[2]350;--------------------------------------------------------------
[37]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
[231]403            ELSE:return, err_3d(type, sz, nx, ny, nz)
[37]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
[231]410            ELSE:return, err_3d(type, sz, nx, ny, nz)
[37]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
[231]417            ELSE:return, err_3d(type, sz, nx, ny, nz)
[37]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
[231]424            ELSE:return, err_3d(type, sz, nx, ny, nz)
[37]425          ENDCASE
[231]426        END
427      ENDCASE
428    END
[2]429;--------------------------------------------------------------
[231]430    4:BEGIN
[37]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'
[231]442      ENDCASE
[37]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.