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

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

change *.pro file properties (del eof-style, del executable, set keywords Id

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 14.8 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5; NAME:checkfield
6;
7; PURPOSE:en entree de plt, pltz, pltt et plt1d, verifie que le
8; champ donne a bien une taille compatible avec le domaine et fait au
9; besoin les moyennes pour ressortir en fin de fonction un tableau 2d
10; si on fait un plot du type: 'xy', 'xz', 'xt', 'yz', 'yt', 'zt' ou un
11; tableau 1d si on fait un plot du type 'x', 'y', 'z', 't'.
12;
13; CATEGORY:en entree de plt, pltz, pltt et plt1d
14;
15; CALLING SEQUENCE:res=checkfield(field, procedure)
16;
17; INPUTS:
18;        filed: un champ recomdant aux criteres de litchamp.pro, cf.
19;        IDL>xhelp,'litchamp'
20;
21; KEYWORD PARAMETERS:
22;
23;         /WDEPTH: to specify that the field is at W depth instad of T
24;         depth (automatically activated if vargrid eq 'W')
25;
26; OUTPUTS:
27;
28; COMMON BLOCKS:common.pro
29;
30; SIDE EFFECTS:
31;
32; RESTRICTIONS:
33;
34; EXAMPLE:
35;
36; MODIFICATION HISTORY:Sebastien Masson (smasson@lodyc.jussieu.fr)
37;                      08/02/2000
38;-
39;------------------------------------------------------------
40;------------------------------------------------------------
41FUNCTION err_1d, type, n1, name, n2
42;
43  compile_opt idl2, strictarrsubs
44;
45  return, report(['Error in "' + type + '" type plot with a 1D input array:' $
46                  , 'the number of elements of the input vector ('+strtrim(n1, 1)+') ' $
47                  , 'is not equal to ' + name + ' ('+strtrim(n2, 1)+')'], /simple)
48END
49;
50FUNCTION err_2d, type, sz, nx, ny, nz
51;
52  compile_opt idl2, strictarrsubs
53;
54  @cm_4mesh
55  @cm_4cal
56  return, report(['Error in "' + type + '" type plot with a 2D input array:' $
57                  , 'the array dimensions ' + tostr(sz[1:2]) + ' are incompatible' $
58                  , 'with the the domain dimensions ' $
59                  , '[jpi/nx, jpj/ny, jpk/nz, jpt] = [' $
60                  + strtrim(jpi, 1) + '/' + strtrim(nx, 1) $
61                  + ', ' + strtrim(jpj, 1) + '/' + strtrim(ny, 1) $
62                  + ', ' + strtrim(jpk, 1) + '/' + strtrim(nz, 1) $
63                  + ', ' + strtrim(jpt, 1) + ']'], /simple)
64END
65;
66FUNCTION err_3d, type, sz, nx, ny, nz
67;
68  compile_opt idl2, strictarrsubs
69;
70  @cm_4mesh
71  @cm_4cal
72  return, report(['Error in "' + type + '" type plot with a 3D input array:' $
73                  , 'the array dimensions ' + tostr(sz[1:3]) + ' are incompatible' $
74                  , 'with the the domain dimensions ' $
75                  , '[jpi/nx, jpj/ny, jpk/nz, jpt] = [' $
76                  + strtrim(jpi, 1) + '/' + strtrim(nx, 1) $
77                  + ', ' + strtrim(jpj, 1) + '/' + strtrim(ny, 1) $
78                  + ', ' + strtrim(jpk, 1) + '/' + strtrim(nz, 1) $
79                  + ', ' + strtrim(jpt, 1) + ']'], /simple)
80END
81;--------------------------------------------------------------
82;
83FUNCTION checkfield, field, procedure, TYPE = type, BOXZOOM = boxzoom, DIREC = direc, NOQUESTION = noquestion, VECTEUR = vecteur, WDEPTH = wdepth, _EXTRA = ex
84;--------------------------------------------------------------
85;
86  compile_opt idl2, strictarrsubs
87;
88; include commons
89@cm_4mesh
90@cm_4cal
91@cm_4data
92  IF NOT keyword_set(key_forgetold) THEN BEGIN
93@updatenew
94@updatekwd
95  ENDIF
96;--------------------------------------------------------------
97; I1) lecture du champ
98;--------------------------------------------------------------
99  if n_elements(field) EQ 0 then return, report('field undefined')
100  arr = litchamp(field)
101; first check
102  IF n_elements(arr) EQ 1 THEN BEGIN
103    if arr EQ -1 then $
104      return, report('Error: input array = -1. Maybe the reading did ont perform well...', /simple) $
105    ELSE return, report('Error: input array is a scalar', /simple)     
106  ENDIF
107  nan = total(finite(arr, /nan)) < 1
108;---------------------------------------------------------------
109; redefinition du domaine
110;---------------------------------------------------------------
111  minprof = 0.
112  profdefault = 200.
113;
114  Case n_elements(boxzoom) OF
115    0:
116    1:localbox = [minprof, boxzoom[0]]
117    2:localbox = boxzoom
118    4:if strpos(type, 'z') NE -1 THEN $
119      localbox = [boxzoom, minprof, profdefault] ELSE localbox = boxzoom
120    5:localbox = [Boxzoom[0:3], minprof, Boxzoom[4]]
121    6:localbox = boxzoom
122    Else: return, report('Bad definition of boxzoom')
123  ENDCASE
124;
125  if keyword_set(localbox) then BEGIN
126    if keyword_set(vecteur) then grillechoice = [vargrid, 'T', 'U', 'V'] $
127    ELSE grillechoice = [vargrid, 'T']
128    if keyword_set(wdepth) then grillechoice = [grillechoice, 'W']
129    domdef, localbox, GRIDTYPE = grillechoice, _extra = ex
130  ENDIF
131;
132; la procedure domdef determine les elements qui sont a l''interieur
133; de la boxzoom.
134; si on fait un plot contenant l''axe z:
135; Suivant l''axe z si on veut par ex faire un dessin
136; entre 0 et 1000 il se peut que l''on selectionne les niveaux
137; correspondants aux profondeurs comprises entre 0 et 900m (vu la
138; discretisation assez lache de cet axe qd on atteint des profondeurs
139; elevees). Pour ne pas que le dessin s''arrete a 900 mais bien a
140; 1000, on va aller chercher le niveau au dessous de 1000, d''ou la
141; manip suivante sur la boxzoom: l''approfondir de 1 niveau sur la
142; verticale (si possible) sans changer les y range.
143  if strpos(type, 'z') NE -1 THEN BEGIN
144    if NOT keyword_set(localbox) then BEGIN
145      localbox = [minprof, profdefault]
146      if keyword_set(wdepth) then grillechoice = 'W' $
147      ELSE grillechoice = vargrid
148      domdef, localbox, GRIDTYPE = grillechoice
149    END
150    nelbox = n_elements(localbox)
151;on garde les yranges (axe z) avant de changer la boxzoom.
152    !y.range = [localbox[nelbox-1], localbox[nelbox-2]]
153    if vargrid EQ 'W' OR keyword_set(wdepth) then BEGIN
154      firstzw = 0 > (firstzw-1)
155      lastzw = (lastzw+1) < (jpk-1)
156      nzw = lastzw - firstzw + 1
157    ENDIF ELSE BEGIN
158      firstzt = 0 > (firstzt-1)
159      lastzt = (lastzt+1) < (jpk-1)
160      nzt = lastzt - firstzt + 1
161    ENDELSE
162    @updateold
163  ENDIF
164; make the automatic definition of type for pltz if type is not specified.
165  IF type EQ 'z' AND procedure EQ 'pltz' THEN $
166    if (lon2-lon1) gt (lat2-lat1) then type = 'xz' else type = 'yz'
167; make the automatic definition of type for pltt if type is not specified.
168  IF type EQ 'unkownpltt' AND procedure EQ 'pltt' THEN $
169    if (lon2-lon1) gt (lat2-lat1) then type = 'xt' else type = 'yt'
170;--------------------------------------------------------------
171; verification de la taille du tableau d''entree et de la valeur de type
172;--------------------------------------------------------------
173  grille, -1, -1, -1, -1, nx, ny, nz, firstx, firsty $
174    , firstz, lastx, lasty, lastz, WDEPTH = wdepth
175;--------------------------------------------------------------
176; basic checks
177;--------------------------------------------------------------
178  CASE 1 OF
179    nx EQ 1: IF strpos(type, 'x') NE -1 THEN return, report('Error: impossible to make a "' + type + '" type plot with nx = 1 ', /simple)
180    ny EQ 1: IF strpos(type, 'y') NE -1 THEN return, report('Error: impossible to make a "' + type + '" type plot with ny = 1 ', /simple)
181    nz EQ 1: IF strpos(type, 'z') NE -1 THEN return, report('Error: impossible to make a "' + type + '" type plot with nz = 1 ', /simple)
182    jpt EQ 1: IF strpos(type, 't') NE -1 THEN return, report('Error: impossible to make a "' + type + '" type plot with jpt = 1 ', /simple)
183    ELSE:
184  ENDCASE
185;--------------------------------------------------------------
186; is the size of the array compatible with teh domain?
187;--------------------------------------------------------------
188  arr = fitintobox(temporary(arr), nx, ny, nz, firstx, firsty $
189    , firstz, lastx, lasty, lastz)
190;--------------------------------------------------------------
191  sz = size(arr)
192  case sz[0] of
193;--------------------------------------------------------------
194    0:return, arr
195;--------------------------------------------------------------
196    1:BEGIN
197      nele = n_elements(arr)
198      case type of
199        't':if jpt NE nele THEN return, err_1d(type, nele, 'jpt', jpt)
200        'x':IF  nx NE nele THEN return, err_1d(type, nele,  'nx',  nx)
201        'y':IF  ny NE nele THEN return, err_1d(type, nele,  'ny',  ny)
202        'z':IF  nz NE nele THEN return, err_1d(type, nele,  'nz',  nx)
203        ELSE:return, report(['Error: ' $
204                            , 'Impossible to make a "'+type+'" plot with a 1D array'], /simple)
205      ENDCASE
206    END
207;--------------------------------------------------------------
208    2:BEGIN
209      case type of
210        'x':BEGIN
211          case 1 of
212            sz[1] EQ nx AND sz[2] EQ ny:direc = 'y' ; xy array
213            sz[1] EQ nx AND ny EQ 1 AND sz[2] EQ nz:direc = 'z' ; x(y)z array
214            sz[1] EQ nx AND sz[2] EQ jpt:direc = 't' ; xt array
215            ELSE:return, err_2d(type, sz, nx, ny, nz)
216          endcase
217        end
218        'y':BEGIN
219          case 1 of
220            sz[1] EQ nx AND sz[2] EQ ny:direc = 'x' ; xy array
221            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ nz:direc = 'z' ; (x)yz array
222            sz[1] EQ ny AND sz[2] EQ jpt:direc = 't' ; yt array
223            ELSE:return, err_2d(type, sz, nx, ny, nz)
224          endcase
225        END
226        'z':BEGIN
227          case 1 of
228            sz[1] EQ nx AND ny EQ 1 AND sz[2] EQ nz:direc = 'x' ; x(y)z array
229            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ nz:direc = 'y' ; (x)yz array
230            sz[1] EQ nz AND sz[2] EQ jpt:direc = 't' ; zt array
231            ELSE:return, err_2d(type, sz, nx, ny, nz)
232          endcase
233        END
234        't':BEGIN
235          case 1 OF
236            sz[1] EQ nx AND sz[2] EQ jpt:direc = 'x' ; xt array
237            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ jpt:direc = 'y' ; (x)yt array
238            nx EQ 1 AND ny EQ 1 AND sz[1] EQ nz AND sz[2] EQ jpt:direc = 'z' ; (x)(y)zt array
239            ELSE:return, err_2d(type, sz, nx, ny, nz)
240          ENDCASE
241        END
242        'xy':IF sz[1] NE nx OR sz[2] ne  ny THEN return, err_2d(type, sz, nx, ny, nz) ; xy array
243        'xz':IF sz[1] NE nx OR sz[2] ne  nz THEN return, err_2d(type, sz, nx, ny, nz) ; xz array
244        'yz':IF sz[1] NE ny OR sz[2] NE  nz THEN return, err_2d(type, sz, nx, ny, nz) ; yz array
245        'xt':IF sz[1] NE nx OR sz[2] NE jpt THEN return, err_2d(type, sz, nx, ny, nz) ; xt array
246        'yt':IF sz[1] NE ny OR sz[2] NE jpt THEN return, err_2d(type, sz, nx, ny, nz) ; yt array
247        'zt':IF sz[1] NE nz OR sz[2] NE jpt THEN return, err_2d(type, sz, nx, ny, nz) ; zt array
248      ENDCASE
249    END
250;--------------------------------------------------------------
251    3:BEGIN
252      case type of
253        'x':BEGIN
254          case 1 of
255            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ nz:direc = 'yz' ; xyz array
256            sz[1] EQ nx AND ny EQ 1 AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'zt' ; x(y)zt array
257            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ jpt:direc = 'yt' ; xyt array
258            ELSE:return, err_3d(type, sz, nx, ny, nz)
259          endcase
260        END
261        'y':BEGIN
262          case 1 of
263            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ nz:direc = 'xz' ; xyz array
264            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'zt' ; (x)yzt array
265            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ jpt:direc = 'xt' ; xyt array
266            ELSE:return, err_3d(type, sz, nx, ny, nz)
267          endcase
268        END
269        'z':BEGIN
270          case 1 of
271            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ nz:direc = 'xy' ; xyz array
272            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'yt' ; (x)yzt array
273            sz[1] EQ nx AND ny EQ 1 AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'xt' ; x(y)zt array
274            ELSE:return, err_3d(type, sz, nx, ny, nz)
275          endcase
276        END
277        't':BEGIN
278          case 1 of
279            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ jpt:direc = 'xy' ; xyt array
280            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'yz' ; (x)yzt array
281            sz[1] EQ nx AND ny EQ 1 AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'xz' ; x(y)zt array
282            ELSE:return, err_3d(type, sz, nx, ny, nz)
283          endcase
284        END
285        'xy':BEGIN
286          case 1 OF
287            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ  nz:direc = 'z' ; xyz array
288            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ jpt:direc = 't' ; xyt array
289            ELSE:return, err_3d(type, sz, nx, ny, nz)
290          endcase
291        END
292        'xz':BEGIN
293          case 1 of
294            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ  nz:direc = 'y' ; xyz array
295            sz[1] EQ nx AND ny EQ 1 AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 't' ; x(y)zt
296            ELSE:return, err_3d(type, sz, nx, ny, nz)
297          endcase
298        END
299        'yz':BEGIN
300          case 1 of
301            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ  nz:direc = 'x' ; xyz array
302            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 't' ; (x)yzt
303            ELSE:return, err_3d(type, sz, nx, ny, nz)
304          endcase
305        END
306        'xt':BEGIN
307          case 1 of
308            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ jpt:direc = 'y' ; xyt array
309            sz[1] EQ nx AND ny EQ 1 AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'z' ; x(y)zt array
310            ELSE:return, err_3d(type, sz, nx, ny, nz)
311          endcase
312        END
313        'yt':BEGIN
314          case 1 of
315            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ jpt:direc = 'x' ; xyt array
316            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'z' ; (x)yzt array
317            ELSE:return, err_3d(type, sz, nx, ny, nz)
318          endcase
319        END
320        'zt':BEGIN
321          case 1 of
322            sz[1] EQ nx AND ny EQ 1 AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'x' ; x(y)zt array
323            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'y' ; (x)yzt array
324            ELSE:return, err_3d(type, sz, nx, ny, nz)
325          ENDCASE
326        END
327      ENDCASE
328    END
329;--------------------------------------------------------------
330    4:BEGIN
331      CASE type OF
332        'x':direc = 'yzt'
333        'y':direc = 'xzt'
334        'z':direc = 'xyt'
335        't':direc = 'xyz'
336        'xy':direc = 'zt'
337        'xz':direc = 'yt'
338        'yz':direc = 'xt'
339        'xt':direc = 'yz'
340        'yt':direc = 'xz'
341        'zt':direc = 'xy'
342      ENDCASE
343    END
344  ENDCASE
345;--------------------------------------------------------------
346  IF keyword_set(direc) THEN BEGIN
347    IF strpos(direc, 't') NE -1 OR strpos(type, 't') NE -1 THEN $
348      arr = grossemoyenne(temporary(arr), direc, boxzoom = localbox $
349                          , NAN = nan, /NODOMDEF, WDEPTH = wdepth, _extra = ex) $
350    ELSE arr = moyenne(temporary(arr), direc, boxzoom = localbox $
351                       , NAN = nan, /NODOMDEF, WDEPTH = wdepth, _extra = ex)
352  ENDIF
353;--------------------------------------------------------------
354;--------------------------------------------------------------
355;--------------------------------------------------------------
356;--------------------------------------------------------------
357  RETURN, arr
358END
Note: See TracBrowser for help on using the repository browser.