source: trunk/SRC/ToBeReviewed/CALCULS/moyenne.pro @ 114

Last change on this file since 114 was 114, checked in by smasson, 18 years ago

new compilation options (compile_opt idl2, strictarrsubs) in each routine

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 25.2 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5; NAME: moyenne
6;
7; PURPOSE:  averages a 2- or 3-d field over a selected
8;           geographical area and along one ore more
9;           selected axes (x, y or z)
10;
11; CATEGORY:
12;
13; CALLING SEQUENCE: result = moyenne(tab,'direc',BOXZOOM=boxzoom)
14;
15; INPUTS:       tab = 2 or 3d field
16;               direc = 'x' 'y' 'z' 'xy' 'xz' 'yz' or 'xyz'
17;
18; KEYWORD PARAMETERS:
19;
20;               BOXZOOM = [xmin,xmax,ymin,ymax (,(zmin,)zmax)] pour plus
21;               de detail cf domdef.
22;               boxzoom peut prendre 5 formes:
23;               [vert2], [vert1, vert2],[lon1, lon2, lat1, lat2], 
24;               [lon1, lon2, lat1, lat2, vert2],[lon1, lon2, lat1,
25;               lat2, vert1,vert2]
26;
27;               NAN: not a number, a activer si l''on peut faire veut
28;               faire une moyenne sans tenir compte de certaines
29;               valeurs masques de tab.
30;               si les valeurs masques de tab sont la valeur consacree
31;               par IDL (!values.f_nan), il suffit de mettre /NAN.
32;               si les valeurs masques de tab on pour valeur a (a doit
33;               etre differente de 1 (correspond a nan =
34;               !values.f_nan) et de 0 (qui desactive nan)
35;               il faut mettre NAN=a.
36;               Rq: en sorties les points de result qui sont NAN
37;               auront pour valeur a ou !values.f_nan.
38;
39;               NODOMDEF: activer si l''on ne veut pas passer ds
40;               domdef bien que le mot cle boxzoom soit present (comme
41;               c''est le cas qd moyenne est appelee via checkfield)
42;           
43;               INTEGRATION: pour faire une integrale plutot qu''une moyenne
44;
45;         /WDEPTH: to specify that the field is at W depth instad of T
46;         depth (automatically activated if vargrid eq 'W')
47;           
48; OUTPUTS:  result:un tableau
49;
50; COMMON BLOCKS:
51;       common   domdef
52;
53; SIDE EFFECTS:met les valeurs correspondants a la terre a 1e20
54;
55; RESTRICTIONS:
56;
57; EXAMPLE:
58;
59; MODIFICATION HISTORY: Jerome Vialard (jv@lodyc.jussieu.fr)
60;                       2/7/98
61;                       Sebastien Masson (smasson@lodyc.jussieu.fr)
62;                       mise au propre de certains truc (les terres...)
63;                       14/8/98
64;                       15/1/98
65;                       11/3/99 adaptation pour NAN
66;                       28/7/99 moyennes tableaux 1d
67;-
68;------------------------------------------------------------
69;------------------------------------------------------------
70; PLAN DU PROGRAMME:
71;------------------------------------------------------------
72;------------------------------------------------------------
73;I) preliminaires
74;   I.1) determination des directions de moyennes d''apres direc
75;   I.2) verification de la taille du tableau d''entree
76;   I.3) obtention des facteurs d''echelles et du masque sur le sous
77;   domaine concerne par la moyenne
78;  ) moyennes pour les tableaux 1d (x,y)
79;II) moyennes pour les tableaux 2d (x,y)
80;   II.1) verification de la coherence de la taille du tableau a
81;   moyenner
82;   II.2) differents types de moyennes possibles
83;III) moyennes pour les tableaux 3d (x,y,z)
84;   III.1) verification de la coherence de la taille du tableau a
85;   moyenner
86;   III.2) differents types de moyennes possibles
87;IV ) finitions
88;   IV.1) on masque les terres par une valeur a 1e+20
89;   IV.2) on remplace, quand nan ne 1, !values.f_nan par nan
90;   IV.3) on revient au sous domaine initial.
91;------------------------------------------------------------
92;------------------------------------------------------------
93function moyenne, tab, direc, BOXZOOM = boxzoom, INTEGRATION = integration $
94                  , NAN = nan, NODOMDEF = nodomdef, WDEPTH = wdepth $
95                  , _extra = ex
96;---------------------------------------------------------
97;
98  compile_opt idl2, strictarrsubs
99;
100@cm_4mesh
101@cm_4data
102@cm_4cal
103  IF NOT keyword_set(key_forgetold) THEN BEGIN
104@updatenew
105@updatekwd
106  ENDIF
107;---------------------------------------------------------
108  tempsun = systime(1)          ; pour key_performance
109;------------------------------------------------------------
110;I) preliminaires
111;------------------------------------------------------------
112  dirt = 0
113  dirx = 0
114  diry = 0
115  dirz = 0
116;------------------------------------------------------------
117; I.1) direction(s) suivants lesquelles on integre
118;------------------------------------------------------------
119  if ( strpos(direc, 't') ge 0 ) then dirt = 1
120  if ( strpos(direc, 'x') ge 0 ) then dirx = 1
121  if ( strpos(direc, 'y') ge 0 ) then diry = 1
122  if ( strpos(direc, 'z') ge 0 ) then dirz = 1
123  if (dirx eq 0 and diry eq 0 and dirz eq 0) then return, tab
124;------------------------------------------------------------
125; I.2) verification de la taille du tableau d'entree
126;------------------------------------------------------------
127  taille = size(tab)
128  case 1 of
129    taille[0] eq 1 :dim = '1d'
130    taille[0] eq 2 :BEGIN
131      dim = '2d'
132      if dirx eq 0 and diry eq 0 then return, tab
133    END
134    taille[0] eq 3 :BEGIN
135      dim = '3d'
136      if dirx eq 0 and diry eq 0 and dirz eq 0 then return, tab
137    END
138    else : return, report('Le tableau d''entree doit etre a 2 ou 3 dimensions s''il contient une dim temporelle utiliser grossemoyenne')
139  endcase
140;------------------------------------------------------------
141;   I.3) obtention des facteurs d''echelles et du masque sur le sous
142;   domaine concerne par la moyenne
143; redefinition du domaine ajuste a boxzoom (a 6 elements)
144; ceci va nous permetre de faire les calcules que sur le sous domaine
145; comcerne par la moyenne. domdef, suivit de grille nous donne tous
146; les tableaux de la grille sur le sous domaine
147;------------------------------------------------------------
148  if keyword_set(boxzoom) then BEGIN
149    Case 1 Of
150      N_Elements(Boxzoom) Eq 1:bte = [lon1, lon2, lat1, lat2, 0., boxzoom[0]]
151      N_Elements(Boxzoom) Eq 2:bte = [lon1, lon2, lat1, lat2, boxzoom[0], boxzoom[1]]
152      N_Elements(Boxzoom) Eq 4:bte = [Boxzoom, vert1, vert2]
153      N_Elements(Boxzoom) Eq 5:bte = [Boxzoom[0:3], 0, Boxzoom[4]]
154      N_Elements(Boxzoom) Eq 6:bte = Boxzoom
155      Else: return, report('Mauvaise Definition de Boxzoom')
156    endcase
157    if NOT keyword_set(nodomdef) then BEGIN
158      savedbox = 1b
159      saveboxparam, 'boxparam4moyenne.dat'
160      domdef, bte, GRIDTYPE = vargrid, _extra = ex
161    ENDIF
162  ENDIF
163;---------------------------------------------------------------
164; attribution du mask et des tableaux de longitude et latitude...
165;---------------------------------------------------------------
166  IF vargrid EQ 'W' THEN wdepth = 1
167  grille, mask, glam, gphi, gdep, nx, ny, nz, firstx, firsty, firstz, lastx, lasty, lastz, e1, e2, e3, WDEPTH = wdepth
168;------------------------------------------------------------
169;------------------------------------------------------------
170; II) Cas du tableau 1d
171;------------------------------------------------------------
172;------------------------------------------------------------
173  if dim EQ '1d' then BEGIN
174    if n_elements(tab) NE nx*ny AND n_elements(tab) NE nx*ny*nz then BEGIN
175      if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat'
176      return, report('Probleme d''adequation entre les tailles du domaine et de la boxzoom.')
177    ENDIF
178    case 1 of
179      nx EQ 1 AND ny EQ 1:BEGIN ;vecteur suivant z
180        case n_elements(tab) of
181          jpk:res = tab[firstz:lastz]
182          nz:res = tab
183          ELSE:BEGIN
184            if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat'
185            return, report('Probleme d''adequation entre les tailles du domaine et de la boxzoom.')
186          END
187        ENDCASE
188        if dirz EQ 1 then BEGIN
189          dim = '3d'
190          taille = size(reform(res, nx, ny, nz))
191        ENDIF ELSE BEGIN
192          if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat'
193          return, res
194        ENDELSE
195      END
196      ny EQ 1:BEGIN             ;vecteur suivant x
197        case n_elements(tab) of
198          jpi:res = tab[firstx:lastx]
199          nx:res = tab
200          ELSE:BEGIN
201            if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat'
202            return, report('Probleme d''adequation entre les tailles du domaine et de la boxzoom.')
203          END
204        ENDCASE
205        if dirx EQ 1 then BEGIN
206          dim = '2d'
207          taille = size(reform(res, nx, ny))
208        ENDIF ELSE BEGIN
209          if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat'
210          return, res
211        ENDELSE
212      END
213      nx EQ 1:BEGIN             ;vecteur suivant y
214        case n_elements(tab) of
215          jpj:res = tab[firsty:lasty]
216          ny:res = tab
217          ELSE:BEGIN
218            if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat'
219            return, report('Probleme d''adequation entre les tailles du domaine et de la boxzoom.')
220          END
221        ENDCASE
222        if diry EQ 1 then BEGIN
223          dim = '2d'
224          taille = size(reform(res, nx, ny))
225        ENDIF ELSE BEGIN
226          if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat'
227          return, res
228        ENDELSE
229      END
230    endcase
231  endif
232;------------------------------------------------------------
233;------------------------------------------------------------
234; II) Cas du tableau 2d
235;------------------------------------------------------------
236;------------------------------------------------------------
237  if (dim eq '2d') then begin
238;---------------------------------------------------------------
239;   II.1) verification de la coherence de la taille du tableau a
240;   moyenner
241; verification de la coherence entre la taille du tableau et le
242; domaine definit par domdef
243; le tableau en entree doit avoir soit la taille du domaine total
244; (jpi,jpj) soit celle du domaine reduit (nx,ny)
245;---------------------------------------------------------------
246    case 1 of
247      taille[1] eq jpi and taille[2] eq jpj: $
248        res = tab[firstx:lastx, firsty:lasty]
249      taille[1] eq  nx and taille[2] eq  ny:res = tab
250      else:BEGIN
251        if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat'
252        return, report('Probleme d''adequation entre les tailles du domaine nx*ny '+strtrim(nx, 1)+'*'+strtrim(ny, 1)+' et du tableau '+strtrim(taille[1], 1)+'*'+strtrim(taille[2], 1))
253      END
254    ENDCASE
255    if keyword_set(nan) NE 0 then BEGIN
256      if nan NE 1 then BEGIN    ; si nan n''est pas !values.f_nan
257; on le met a !values.f_nan
258        if abs(nan) LT 1e6 then notanumber = where(res EQ nan) $
259        ELSE notanumber = where(abs(res) GT abs(nan)/10.)
260        if notanumber[0] NE -1 then res[temporary(notanumber)] = !values.f_nan
261      ENDIF
262    ENDIF
263;---------------------------------------------------------------
264; rq IL FAUT FAIRE ATTENTION AUX CAS OU LA DIM A MOYENNER = 1, ET
265; S'ASSURER QU'ELLE EXISTE BIEN. D'OU LES reform(...,nx,ny,...) QUI
266; PEUVENT SEMBLER INUTILE AU DEPART
267;---------------------------------------------------------------
268    if nx EQ 1 OR ny EQ 1 then BEGIN
269      res = reform(res, nx, ny, /over)
270      e1 =  reform(e1, nx, ny, /over)
271      e2 =  reform(e2, nx, ny, /over)
272    endif
273    if nx EQ 1 OR ny EQ 1 OR nz EQ 1 THEN $
274      mask =  reform(mask, nx, ny, nz, /over)
275;---------------------------------------------------------------
276; II.3) differents types de moyennes
277;---------------------------------------------------------------
278    mask = mask[*, *, 0]
279    if keyword_set(nan) NE 0 then msknan = finite(res) ELSE msknan = -1
280    case 1 of
281      (dirx eq 1) and (diry eq 0) : begin
282        e = e1*mask
283        if keyword_set(integration) then divi = 1 $
284        else begin
285          divi = e
286          IF msknan[0] NE -1 THEN divi = temporary(divi)*msknan
287          if ny EQ 1 then divi = reform(divi, nx, ny, /over)
288          divi = total(divi, 1)
289        endelse
290        res = res*e
291        if ny EQ 1 then res = reform(res, nx, ny, /over)
292        res = total(res, 1, nan = nan)/(divi > 1.)
293        if msknan[0] NE -1 then begin
294          testnan  = msknan*mask
295          if ny EQ 1 then testnan = reform(testnan, nx, ny, /over)
296          testnan = total(testnan, 1)+(total(mask, 1) EQ 0)
297        endif
298      end
299      (dirx eq 0) and (diry eq 1) : begin
300        e = e2*mask
301        if keyword_set(integration) then divi = 1 $
302        else begin
303          divi = e
304          IF msknan[0] NE -1 THEN divi = temporary(divi)*msknan
305          if ny EQ 1 then divi = reform(divi, nx, ny, /over)
306          divi = total(divi, 2)
307        endelse
308        res = res*e
309        if ny EQ 1 then res = reform(res, nx, ny, /over)
310        res = total(res, 2, nan = nan)/(divi > 1.)
311        if msknan[0] NE -1 then begin
312          testnan  = msknan*mask
313          if ny EQ 1 then testnan  = reform(testnan, nx, ny, /over)
314          testnan = total(testnan, 2)+(total(mask, 2) EQ 0)
315        endif
316      end
317      (dirx eq 1) and (diry eq 1) : begin
318        if keyword_set(integration) then divi = 1 else BEGIN
319          IF msknan[0] NE -1 THEN divi = total(e1*e2*mask*msknan) $
320          ELSE divi = total(e1*e2*mask)
321        ENDELSE
322        res = total(res*e1*e2*mask, nan = nan)/(divi > 1.)
323        if msknan[0] NE -1 then begin
324          testnan  = msknan*mask
325          testnan = total(testnan)+(total(mask) EQ 0)
326        endif
327      end
328    endcase
329  endif
330;------------------------------------------------------------
331;------------------------------------------------------------
332; III) Cas du tableau 3d
333;------------------------------------------------------------
334;------------------------------------------------------------
335  if (dim eq '3d') then begin
336;---------------------------------------------------------------
337; III.1) verification de la coherence de la taille du tableau a
338; moyenner
339; verification de la coherence entre la taille du tableau et le
340; domaine definit par domdef
341; le tableau en entree doit avoir soit la taille du domaine total
342; (jpi,jpj,jpk) soit celle du domaine reduit (nx,ny,ny)
343;---------------------------------------------------------------
344    case 1 of
345      taille[1] eq jpi and taille[2] eq jpj and taille[3] eq jpk: $
346        res = tab[firstx:lastx, firsty:lasty, firstz:lastz]
347      taille[1] eq jpi and taille[2] eq jpj and taille[3] eq nz: $
348        res = tab[firstx:lastx, firsty:lasty, *]
349      taille[1] EQ  nx and taille[2] eq  ny and taille[3] eq nz :res = tab
350      taille[1] EQ  nx and taille[2] eq  ny and taille[3] eq jpk : $
351        res = tab[*, *, firstz:lastz]
352      else:BEGIN
353        if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat'
354        return, report('Probleme d''adequation entre les tailles du domaine nx*ny*nz '+strtrim(nx, 1)+'*'+strtrim(ny, 1)+'*'+strtrim(nz, 1)+' et du tableau '+strtrim(taille[1], 1)+'*'+strtrim(taille[2], 1)+'*'+strtrim(taille[3], 1))
355      END
356    endcase
357    if keyword_set(nan) NE 0 then BEGIN
358      if nan NE 1 then BEGIN    ; si nan n''est pas !values.f_nan
359; on le met a !values.f_nan
360        if abs(nan) LT 1e6 then notanumber = where(res EQ nan) $
361        ELSE notanumber = where(abs(res) GT abs(nan)/10.)
362        if notanumber[0] NE -1 then res[temporary(notanumber)] = !values.f_nan
363      ENDIF
364    ENDIF
365;---------------------------------------------------------------
366; rq IL FAUT FAIRE ATTENTION AUX CAS OU LA DIM A MOYENNER = 1, ET
367; S'ASSURER QU'ELLE EXISTE BIEN. D'OU LES reform(...,nx,ny,...) QUI
368; PEUVENT SEMBLER INUTILE AU DEPART
369;---------------------------------------------------------------
370    if nx EQ 1 OR ny EQ 1 OR nz EQ 1 then BEGIN
371      res = reform(res, nx, ny, nz, /over)
372      e1 =  reform(e1, nx, ny, /over)
373      e2 =  reform(e2, nx, ny, /over)
374    endif
375    if nx EQ 1 OR ny EQ 1 OR nz EQ 1 THEN $
376      mask =  reform(mask, nx, ny, nz, /over)
377    IF keyword_set(key_partialstep) THEN BEGIN
378; the top of the ocean floor is
379      IF vargrid EQ 'T' OR vargrid EQ 'W' THEN bottom = total(mask, 3) $
380      ELSE bottom = total(tmask[firstx:lastx, firsty:lasty, firstz:lastz], 3)
381; we suppress columns with only ocean or land
382      good = where(bottom NE 0 AND bottom NE nz)
383; the bottom of the ocean in 3D index is:
384      bottom = lindgen(nx*ny)+(temporary(bottom)-1L)*nx*ny
385      IF good[0] NE -1 THEN bottom = bottom[good] $
386      ELSE bottom = -1
387    ENDIF ELSE bottom = -1
388;---------------------------------------------------------------
389; III.2) differents types de moyennes
390;---------------------------------------------------------------
391    if keyword_set(nan) NE 0 then msknan = finite(res) ELSE msknan = -1
392    case 1 of
393      (dirx eq 1) and (diry eq 0) and (dirz eq 0) : begin
394        e13 = e1[*]#replicate(1., nz)
395        e13 = reform(e13, nx, ny, nz, /over)
396        IF keyword_set(key_partialstep) AND bottom[0] NE -1 $
397          AND nx NE 1 THEN BEGIN
398          IF msknan[0] EQ -1 THEN BEGIN
399            msknan = replicate(1b, nx, ny, nz)
400            nan = 1
401          endif
402          msknan[bottom] = 0
403          res[bottom] = !values.f_nan
404        ENDIF
405        if keyword_set(integration) then divi = 1 else begin
406          divi = e13*mask
407          IF msknan[0] NE -1 THEN divi = temporary(divi)*msknan
408          if nz EQ 1 then divi = reform(divi, nx, ny, nz, /over)
409          divi = total(divi, 1)
410        ENDELSE
411        res = res*e13*mask
412        if nz EQ 1 then res = reform(res, nx, ny, nz, /over)
413        res = total(res, 1, nan = nan)/(divi > 1.)
414        e13 = 1
415        if msknan[0] NE -1 then begin
416          testnan  = msknan*mask
417          if nz EQ 1 then testnan  = reform(testnan, nx, ny, nz, /over)
418          testnan = total(testnan, 1)+(total(mask, 1) EQ 0)
419        endif
420      end
421      (dirx eq 0) and (diry eq 1) and (dirz eq 0) : begin
422        e23 = e2[*]#replicate(1., nz)
423        e23 = reform(e23, nx, ny, nz, /over)
424        IF keyword_set(key_partialstep) AND bottom[0] NE -1 $
425          AND ny NE 1 THEN BEGIN
426          IF msknan[0] EQ -1 THEN BEGIN
427            msknan = replicate(1b, nx, ny, nz)
428            nan = 1
429          endif
430          msknan[bottom] = 0
431          res[bottom] = !values.f_nan
432        ENDIF
433        if keyword_set(integration) then divi = 1 else begin
434          divi = e23*mask
435          IF msknan[0] NE -1 THEN divi = temporary(divi)*msknan
436          if nz EQ 1 then divi = reform(divi, nx, ny, nz, /over)
437          divi = total(divi, 2)
438        ENDELSE
439        res = res*e23*mask
440        if nz EQ 1 then res = reform(res, nx, ny, nz, /over)
441        res = total(res, 2, nan = nan)/(divi > 1.)
442        e23 = 1
443        if msknan[0] NE -1 then begin
444          testnan  = msknan*mask
445          if nz EQ 1 then testnan = reform(testnan, nx, ny, nz, /over)
446          testnan = total(testnan, 2)+(total(mask, 2) EQ 0)
447        endif
448      end
449      (dirx eq 0) and (diry eq 0) and (dirz eq 1) : begin
450        e33 = replicate(1, 1.*nx*ny)#e3
451        e33 = reform(e33, nx, ny, nz, /over)
452        IF keyword_set(key_partialstep) AND bottom[0] NE -1 THEN BEGIN
453          IF keyword_set(wdepth) THEN $
454            e33[bottom] = (e3w_ps[firstx:lastx, firsty:lasty])[temporary(good)] $
455          ELSE e33[bottom] = (e3t_ps[firstx:lastx, firsty:lasty])[temporary(good)]
456        ENDIF
457        if keyword_set(integration) then divi = 1 else begin
458          divi = e33*mask
459          if msknan[0] NE -1 then divi = temporary(divi)*msknan
460          if nz EQ 1 then divi = reform(divi, nx, ny, nz, /over)
461          divi = total(divi, 3)
462        ENDELSE
463        res = res*e33*mask
464        if nz EQ 1 then res = reform(res, nx, ny, nz, /over)
465        res = total(res, 3, nan = nan)/(divi > 1.)
466        e33 = 1
467        if msknan[0] NE -1 then begin
468          testnan  = msknan*mask
469          if nz EQ 1 then testnan  = reform(testnan, nx, ny, nz, /over)
470          testnan = total(testnan, 3)+(total(mask, 3) EQ 0)
471        endif
472      end
473      (dirx eq 1) and (diry eq 1) and (dirz eq 0) : begin
474        e123 = (e1*e2)[*]#replicate(1., nz)
475        e123 = reform(e123, nx, ny, nz, /over)
476        IF keyword_set(key_partialstep) AND bottom[0] NE -1 $
477          AND nx*ny NE 1 THEN BEGIN
478          IF msknan[0] EQ -1 THEN BEGIN
479            msknan = replicate(1b, nx, ny, nz)
480            nan = 1
481          endif
482          msknan[bottom] = 0
483          res[bottom] = !values.f_nan
484        ENDIF
485        if keyword_set(integration) then divi = 1 else BEGIN
486          divi = e123*mask
487          IF msknan[0] NE -1 THEN divi = temporary(divi)*msknan
488          if nz EQ 1 then divi = reform(divi, nx, ny, nz, /over)
489          divi = total(total(divi, 1), 1)
490        ENDELSE
491        res = res*e123*mask
492        if nz EQ 1 then res = reform(res, nx, ny, nz, /over)
493        res = total(total(res, 1, nan = nan), 1, nan = nan) / (divi > 1.)
494        e123 = 1
495        if msknan[0] NE -1 then begin
496          testnan  = msknan*mask
497          if nz EQ 1 then testnan  = reform(testnan, nx, ny, nz, /over)
498          testnan = total(total(testnan, 1), 1)+(total(total(mask, 1), 1) EQ 0)
499        endif
500      end
501      (dirx eq 1) and (diry eq 0) and (dirz eq 1) : begin
502        e133 = e1[*]#e3
503        e133 = reform(e133, nx, ny, nz, /over)
504        IF keyword_set(key_partialstep) AND bottom[0] NE -1 THEN BEGIN
505          IF keyword_set(wdepth) THEN $
506            e133[bottom] = (e1*e3w_ps[firstx:lastx, firsty:lasty])[temporary(good)] $
507          ELSE e133[bottom] = (e1*e3t_ps[firstx:lastx, firsty:lasty])[temporary(good)]
508        ENDIF
509        if keyword_set(integration) then divi = 1 else BEGIN
510          divi = e133*mask
511          if msknan[0] NE -1 then divi = temporary(divi)*msknan
512          if nz EQ 1 then divi = reform(divi, nx, ny, nz, /over)
513          divi = total(total(divi, 1), 2)
514        ENDELSE
515        res = res*e133*mask
516        if nz EQ 1 then res = reform(res, nx, ny, nz, /over)
517        res = total(total(res, 1, nan = nan), 2, nan = nan) / (divi > 1.)
518        e133 = 1
519        if msknan[0] NE -1 then begin
520          testnan  = msknan*mask
521          if nz EQ 1 then testnan  = reform(testnan, nx, ny, nz, /over)
522          testnan = total(total(testnan, 1), 2)+(total(total(mask, 1), 2) EQ 0)
523        endif
524      end
525      (dirx eq 0) and (diry eq 1) and (dirz eq 1) : begin
526        e233 = e2[*]#e3
527        e233 = reform(e233, nx, ny, nz, /over)
528        IF keyword_set(key_partialstep) AND bottom[0] NE -1 THEN BEGIN
529          IF keyword_set(wdepth) THEN $
530            e233[bottom] = (e2*e3w_ps[firstx:lastx, firsty:lasty])[temporary(good)] $
531          ELSE e233[bottom] = (e2*e3t_ps[firstx:lastx, firsty:lasty])[temporary(good)]
532        ENDIF
533        if keyword_set(integration) then divi = 1 else BEGIN
534          divi = e233*mask
535          if msknan[0] NE -1 then divi = temporary(divi)*msknan
536          if nz EQ 1 then divi = reform(divi, nx, ny, nz, /over)
537          divi = total(total(divi, 2), 2)
538        ENDELSE
539        res = res*e233*mask
540        if nz EQ 1 then res = reform(res, nx, ny, nz, /over)
541        res = total(total(res, 2, nan = nan), 2, nan = nan) / (divi > 1.)
542        e233 = 1
543        if msknan[0] NE -1 then begin
544          testnan  = msknan*mask
545          if nz EQ 1 then testnan  = reform(testnan, nx, ny, nz, /over)
546          testnan = total(total(testnan, 2), 2)+(total(total(mask, 2), 2) EQ 0)
547        endif
548      end
549      (dirx eq 1) and (diry eq 1) and (dirz eq 1) : begin
550        e1233 = (e1*e2)[*]#e3
551        e1233 = reform(e1233, nx, ny, nz, /over)
552        IF keyword_set(key_partialstep) AND bottom[0] NE -1 THEN BEGIN
553          IF keyword_set(wdepth) THEN $
554            e1233[bottom] = (e1*e2*e3w_ps[firstx:lastx, firsty:lasty])[temporary(good)] $
555          ELSE e1233[bottom] = (e1*e2*e3t_ps[firstx:lastx, firsty:lasty])[temporary(good)]
556        ENDIF
557        if keyword_set(integration) then divi = 1 else BEGIN
558          if msknan[0] NE -1 then divi = total(e1233*mask*msknan) $
559          ELSE divi = total(e1233*mask)
560        ENDELSE
561        res = total(res*e1233*mask, nan = nan) / (divi > 1.)
562        e1233 = 1
563        if msknan[0] NE -1 then begin
564          testnan  = msknan*mask
565          testnan = total(testnan)+(total(mask) EQ 0)
566        endif
567      end
568    endcase
569  endif
570;------------------------------------------------------------
571;------------------------------------------------------------
572;IV ) finitions
573;------------------------------------------------------------
574;------------------------------------------------------------
575; IV.1) on masque les terres par une valeur a 1e+20
576;------------------------------------------------------------
577  valmask = 1e+20
578  terre = where(divi EQ 0)
579  IF terre[0] NE -1 THEN BEGIN
580    res[terre] = 1e+20
581  ENDIF 
582;------------------------------------------------------------
583; IV.2) on remplace, quand nan ne 1, !values.f_nan par nan
584;------------------------------------------------------------
585  if keyword_set(nan) NE 0 then BEGIN
586    puttonan = where(testnan EQ 0)
587    if puttonan[0] NE -1 then res[puttonan] = !values.f_nan
588    if nan NE 1 then BEGIN
589      notanumber = where(finite(res) eq 0)
590      if notanumber[0] NE -1 then res[notanumber] = nan
591    ENDIF
592  ENDIF
593;------------------------------------------------------------
594; IV.3) on se remplace ds le sous domaine qui etait definit a l''entree de
595; moyenne
596;------------------------------------------------------------
597  if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat'
598;------------------------------------------------------------
599  if keyword_set(key_performance) THEN print, 'temps moyenne', systime(1)-tempsun
600  return, res
601;------------------------------------------------------------
602;------------------------------------------------------------
603end
Note: See TracBrowser for help on using the repository browser.