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

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

improvemnts of headers (typo, links)

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