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

Last change on this file since 223 was 223, checked in by pinsard, 17 years ago

improvements of some *.pro

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 23.5 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5;
6; @file_comments
7; 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; @categories
12;
13; @param TAB {in}{required}
14; 2 or 3d field
15;
16; @param DIREC {in}{required}
17; 'x' 'y' 'z' 'xy' 'xz' 'yz' or 'xyz'
18;
19; @keyword BOXZOOM
20; [xmin,xmax,ymin,ymax (,(zmin,)zmax)] to more details, see domdef
21; boxzoom can have 5 forms:
22;  [vert2],
23;  [vert1, vert2],
24;  [lon1, lon2, lat1, lat2],
25;  [lon1, lon2, lat1, lat2, vert2],
26;  [lon1, lon2, lat1, lat2, vert1,vert2]
27;
28; @keyword NAN
29; not a number, we activate it if we want to average without considerate some masked values of TAB.
30; If masked values of TAB are values consecrated by IDL(!values.f_nan), we just have to put NAN.
31; If masked values of TAB are valued a (a must be different of 1, corresponding to nan =
32; !values.f_nan and of 0, which desactivate nan). We have to put NAN=a.
33; Comment: In output, result points which are NAN will be valued a or !values.f_nan.
34;
35; @keyword NODOMDEF
36; We activate it if we do not want to pass in domdef even if the keyword boxzoom
37; is present (like when grossemoyenne is called via checkfield)
38;
39; @keyword INTEGRATION
40; To make an integral rather than an average
41;
42; @keyword WDEPTH
43; to specify that the field is at W depth instead of T
44; depth (automatically activated if vargrid eq 'W')
45;
46; @returns
47; An array
48;
49; @uses
50; common
51; domdef
52;
53; @restrictions
54; Put values corresponding to land at 1.e20
55;
56; @history
57;  Jerome Vialard (jv\@lodyc.jussieu.fr)
58;                       2/7/98
59;                       Sebastien Masson (smasson\@lodyc.jussieu.fr)
60;                       14/8/98
61;                       15/1/98
62;                       11/3/99 adaptation for NAN
63;                       28/7/99 Averages 1d arrays
64;
65; @version
66; $Id$
67;
68;-
69
70function moyenne, tab, direc, BOXZOOM = boxzoom, INTEGRATION = integration $
71                  , NAN = nan, NODOMDEF = nodomdef, WDEPTH = wdepth $
72                  , _extra = ex
73;---------------------------------------------------------
74;
75  compile_opt idl2, strictarrsubs
76;
77@cm_4mesh
78@cm_4data
79@cm_4cal
80  IF NOT keyword_set(key_forgetold) THEN BEGIN
81@updatenew
82@updatekwd
83  ENDIF
84;---------------------------------------------------------
85  tempsun = systime(1)          ; To key_performance
86;------------------------------------------------------------
87;I) preliminaries
88;------------------------------------------------------------
89  dirt = 0
90  dirx = 0
91  diry = 0
92  dirz = 0
93;------------------------------------------------------------
94; I.1) Directions(s) we follow to integrate
95;------------------------------------------------------------
96  if ( strpos(direc, 't') ge 0 ) then dirt = 1
97  if ( strpos(direc, 'x') ge 0 ) then dirx = 1
98  if ( strpos(direc, 'y') ge 0 ) then diry = 1
99  if ( strpos(direc, 'z') ge 0 ) then dirz = 1
100  if (dirx eq 0 and diry eq 0 and dirz eq 0) then return, tab
101;------------------------------------------------------------
102; I.2) verification of the input array's size
103;------------------------------------------------------------
104  taille = size(tab)
105  case 1 of
106    taille[0] eq 1 :dim = '1d'
107    taille[0] eq 2 :BEGIN
108      dim = '2d'
109      if dirx eq 0 and diry eq 0 then return, tab
110    END
111    taille[0] eq 3 :BEGIN
112      dim = '3d'
113      if dirx eq 0 and diry eq 0 and dirz eq 0 then return, tab
114    END
115    else : return, report('Array must have 2 or 3 dimensions if there is a time dimension use grossemoyenne')
116  endcase
117;------------------------------------------------------------
118;   I.3) Obtainment of scale's factors and of the mask on the subdomain concernedby the average.
119; Redefinition of the domain ajusted at boxzoom (at 6 elements)
120; This will allowed us to calculate only in the domain concerned by the average.
121; Domdef, followed by grid give us all arrays of the grid on the subdomain
122;------------------------------------------------------------
123  if keyword_set(boxzoom) then BEGIN
124    Case 1 Of
125      N_Elements(Boxzoom) Eq 1:bte = [lon1, lon2, lat1, lat2, 0., boxzoom[0]]
126      N_Elements(Boxzoom) Eq 2:bte = [lon1, lon2, lat1, lat2, boxzoom[0], boxzoom[1]]
127      N_Elements(Boxzoom) Eq 4:bte = [Boxzoom, vert1, vert2]
128      N_Elements(Boxzoom) Eq 5:bte = [Boxzoom[0:3], 0, Boxzoom[4]]
129      N_Elements(Boxzoom) Eq 6:bte = Boxzoom
130      Else: return, report('Bad definition of Boxzoom')
131    endcase
132    if NOT keyword_set(nodomdef) then BEGIN
133      savedbox = 1b
134      saveboxparam, 'boxparam4moyenne.dat'
135      domdef, bte, GRIDTYPE = vargrid, _extra = ex
136    ENDIF
137  ENDIF
138;---------------------------------------------------------------
139; attribution of the mask and of longitude and latitude arrays...
140;---------------------------------------------------------------
141  IF vargrid EQ 'W' THEN wdepth = 1
142  grille, mask, glam, gphi, gdep, nx, ny, nz, firstx, firsty, firstz, lastx, lasty, lastz, e1, e2, e3, WDEPTH = wdepth
143;------------------------------------------------------------
144;------------------------------------------------------------
145; II) Case of the 1d array
146;------------------------------------------------------------
147;------------------------------------------------------------
148  if dim EQ '1d' then BEGIN
149    if n_elements(tab) NE nx*ny AND n_elements(tab) NE nx*ny*nz then BEGIN
150      if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat'
151      return, report('Probleme d''adequation entre les tailles du domaine et de la boxzoom.')
152    ENDIF
153    case 1 of
154      nx EQ 1 AND ny EQ 1:BEGIN ;vector following z
155        case n_elements(tab) of
156          jpk:res = tab[firstz:lastz]
157          nz:res = tab
158          ELSE:BEGIN
159            if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat'
160            return, report('Probleme d''adequation entre les tailles du domaine et de la boxzoom.')
161          END
162        ENDCASE
163        if dirz EQ 1 then BEGIN
164          dim = '3d'
165          taille = size(reform(res, nx, ny, nz))
166        ENDIF ELSE BEGIN
167          if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat'
168          return, res
169        ENDELSE
170      END
171      ny EQ 1:BEGIN             ;vector following x
172        case n_elements(tab) of
173          jpi:res = tab[firstx:lastx]
174          nx:res = tab
175          ELSE:BEGIN
176            if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat'
177            return, report('Probleme d''adequation entre les tailles du domaine et de la boxzoom.')
178          END
179        ENDCASE
180        if dirx EQ 1 then BEGIN
181          dim = '2d'
182          taille = size(reform(res, nx, ny))
183        ENDIF ELSE BEGIN
184          if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat'
185          return, res
186        ENDELSE
187      END
188      nx EQ 1:BEGIN             ;vector following y
189        case n_elements(tab) of
190          jpj:res = tab[firsty:lasty]
191          ny:res = tab
192          ELSE:BEGIN
193            if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat'
194            return, report('Probleme d''adequation entre les tailles du domaine et de la boxzoom.')
195          END
196        ENDCASE
197        if diry EQ 1 then BEGIN
198          dim = '2d'
199          taille = size(reform(res, nx, ny))
200        ENDIF ELSE BEGIN
201          if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat'
202          return, res
203        ENDELSE
204      END
205    endcase
206  endif
207;------------------------------------------------------------
208;------------------------------------------------------------
209; II) Case of the 2d array
210;------------------------------------------------------------
211;------------------------------------------------------------
212  if (dim eq '2d') then begin
213;---------------------------------------------------------------
214;   II.1) verification of the coherence of the array's size to average
215; Verification of the coherence between the array's size and the domain defined by domdef
216; The input array must have either the total domain's size (jpi,jpj) or this
217; one of the reduced domain (nx,ny)
218;---------------------------------------------------------------
219    case 1 of
220      taille[1] eq jpi and taille[2] eq jpj: $
221        res = tab[firstx:lastx, firsty:lasty]
222      taille[1] eq  nx and taille[2] eq  ny:res = tab
223      else:BEGIN
224        if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat'
225        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))
226      END
227    ENDCASE
228    if keyword_set(nan) NE 0 then BEGIN
229      if nan NE 1 then BEGIN    ; If nan is not !values.f_nan
230; we put it at !values.f_nan
231        if abs(nan) LT 1e6 then notanumber = where(res EQ nan) $
232        ELSE notanumber = where(abs(res) GT abs(nan)/10.)
233        if notanumber[0] NE -1 then res[temporary(notanumber)] = !values.f_nan
234      ENDIF
235    ENDIF
236;---------------------------------------------------------------
237; Comment : WE HAVE TO BE CAREFUL ABOUT CASES WHERE THE DIMENSION TO AVERAGE = 1,
238; AND MAKE SURE THAT IT EXIST. THAT IS WHY WE USE reform(...,nx,ny,...) WHICH CAN
239; LOOK USELESS AT THE BEGINNING
240;---------------------------------------------------------------
241    if nx EQ 1 OR ny EQ 1 then BEGIN
242      res = reform(res, nx, ny, /over)
243      e1 =  reform(e1, nx, ny, /over)
244      e2 =  reform(e2, nx, ny, /over)
245    endif
246    if nx EQ 1 OR ny EQ 1 OR nz EQ 1 THEN $
247      mask =  reform(mask, nx, ny, nz, /over)
248;---------------------------------------------------------------
249; II.3) Different types of average
250;---------------------------------------------------------------
251    mask = mask[*, *, 0]
252    if keyword_set(nan) NE 0 then msknan = finite(res) ELSE msknan = -1
253    case 1 of
254      (dirx eq 1) and (diry eq 0) : begin
255        e = e1*mask
256        if keyword_set(integration) then divi = 1 $
257        else begin
258          divi = e
259          IF msknan[0] NE -1 THEN divi = temporary(divi)*msknan
260          if ny EQ 1 then divi = reform(divi, nx, ny, /over)
261          divi = total(divi, 1)
262        endelse
263        res = res*e
264        if ny EQ 1 then res = reform(res, nx, ny, /over)
265        res = total(res, 1, nan = nan)/(divi > 1.)
266        if msknan[0] NE -1 then begin
267          testnan  = msknan*mask
268          if ny EQ 1 then testnan = reform(testnan, nx, ny, /over)
269          testnan = total(testnan, 1)+(total(mask, 1) EQ 0)
270        endif
271      end
272      (dirx eq 0) and (diry eq 1) : begin
273        e = e2*mask
274        if keyword_set(integration) then divi = 1 $
275        else begin
276          divi = e
277          IF msknan[0] NE -1 THEN divi = temporary(divi)*msknan
278          if ny EQ 1 then divi = reform(divi, nx, ny, /over)
279          divi = total(divi, 2)
280        endelse
281        res = res*e
282        if ny EQ 1 then res = reform(res, nx, ny, /over)
283        res = total(res, 2, nan = nan)/(divi > 1.)
284        if msknan[0] NE -1 then begin
285          testnan  = msknan*mask
286          if ny EQ 1 then testnan  = reform(testnan, nx, ny, /over)
287          testnan = total(testnan, 2)+(total(mask, 2) EQ 0)
288        endif
289      end
290      (dirx eq 1) and (diry eq 1) : begin
291        if keyword_set(integration) then divi = 1 else BEGIN
292          IF msknan[0] NE -1 THEN divi = total(e1*e2*mask*msknan) $
293          ELSE divi = total(e1*e2*mask)
294        ENDELSE
295        res = total(res*e1*e2*mask, nan = nan)/(divi > 1.)
296        if msknan[0] NE -1 then begin
297          testnan  = msknan*mask
298          testnan = total(testnan)+(total(mask) EQ 0)
299        endif
300      end
301    endcase
302  endif
303;------------------------------------------------------------
304;------------------------------------------------------------
305; III) Case 3d arrays series (tab4d)
306;------------------------------------------------------------
307;------------------------------------------------------------
308  if (dim eq '3d') then begin
309;---------------------------------------------------------------
310; III.1) Verification of the coherence of the array to average size
311; Verification of the coherence between the array's size and the domain
312; defind by domdef
313; The input array must have either the total domain size (jpi,jpj,jpk)
314; or this one of the reduced domain (nx,ny,ny)
315;---------------------------------------------------------------
316    case 1 of
317      taille[1] eq jpi and taille[2] eq jpj and taille[3] eq jpk: $
318        res = tab[firstx:lastx, firsty:lasty, firstz:lastz]
319      taille[1] eq jpi and taille[2] eq jpj and taille[3] eq nz: $
320        res = tab[firstx:lastx, firsty:lasty, *]
321      taille[1] EQ  nx and taille[2] eq  ny and taille[3] eq nz :res = tab
322      taille[1] EQ  nx and taille[2] eq  ny and taille[3] eq jpk : $
323        res = tab[*, *, firstz:lastz]
324      else:BEGIN
325        if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat'
326        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))
327      END
328    endcase
329    if keyword_set(nan) NE 0 then BEGIN
330      if nan NE 1 then BEGIN    ; if nan is not !values.f_nan
331; we put it at !values.f_nan
332        if abs(nan) LT 1e6 then notanumber = where(res EQ nan) $
333        ELSE notanumber = where(abs(res) GT abs(nan)/10.)
334        if notanumber[0] NE -1 then res[temporary(notanumber)] = !values.f_nan
335      ENDIF
336    ENDIF
337;---------------------------------------------------------------
338; Comment : WE HAVE TO BE CAREFUL ABOUT CASES WHERE THE DIMENSION TO AVERAGE = 1,
339; AND MAKE SURE THAT IT EXIST. THAT IS WHY WE USE reform(...,nx,ny,...) WHICH CAN
340; LOOK USELESS AT THE BEGINNING
341;---------------------------------------------------------------
342    if nx EQ 1 OR ny EQ 1 OR nz EQ 1 then BEGIN
343      res = reform(res, nx, ny, nz, /over)
344      e1 =  reform(e1, nx, ny, /over)
345      e2 =  reform(e2, nx, ny, /over)
346    endif
347    if nx EQ 1 OR ny EQ 1 OR nz EQ 1 THEN $
348      mask =  reform(mask, nx, ny, nz, /over)
349    IF keyword_set(key_partialstep) THEN BEGIN
350; the top of the ocean floor is
351      IF vargrid EQ 'T' OR vargrid EQ 'W' THEN bottom = total(mask, 3) $
352      ELSE bottom = total(tmask[firstx:lastx, firsty:lasty, firstz:lastz], 3)
353; we suppress columns with only ocean or land
354      good = where(bottom NE 0 AND bottom NE nz)
355; the bottom of the ocean in 3D index is:
356      bottom = lindgen(nx*ny)+(temporary(bottom)-1L)*nx*ny
357      IF good[0] NE -1 THEN bottom = bottom[good] $
358      ELSE bottom = -1
359    ENDIF ELSE bottom = -1
360;---------------------------------------------------------------
361; III.2) different average types
362;---------------------------------------------------------------
363    if keyword_set(nan) NE 0 then msknan = finite(res) ELSE msknan = -1
364    case 1 of
365      (dirx eq 1) and (diry eq 0) and (dirz eq 0) : begin
366        e13 = e1[*]#replicate(1., nz)
367        e13 = reform(e13, nx, ny, nz, /over)
368        IF keyword_set(key_partialstep) AND bottom[0] NE -1 $
369          AND nx NE 1 THEN BEGIN
370          IF msknan[0] EQ -1 THEN BEGIN
371            msknan = replicate(1b, nx, ny, nz)
372            nan = 1
373          endif
374          msknan[bottom] = 0
375          res[bottom] = !values.f_nan
376        ENDIF
377        if keyword_set(integration) then divi = 1 else begin
378          divi = e13*mask
379          IF msknan[0] NE -1 THEN divi = temporary(divi)*msknan
380          if nz EQ 1 then divi = reform(divi, nx, ny, nz, /over)
381          divi = total(divi, 1)
382        ENDELSE
383        res = res*e13*mask
384        if nz EQ 1 then res = reform(res, nx, ny, nz, /over)
385        res = total(res, 1, nan = nan)/(divi > 1.)
386        e13 = 1
387        if msknan[0] NE -1 then begin
388          testnan  = msknan*mask
389          if nz EQ 1 then testnan  = reform(testnan, nx, ny, nz, /over)
390          testnan = total(testnan, 1)+(total(mask, 1) EQ 0)
391        endif
392      end
393      (dirx eq 0) and (diry eq 1) and (dirz eq 0) : begin
394        e23 = e2[*]#replicate(1., nz)
395        e23 = reform(e23, nx, ny, nz, /over)
396        IF keyword_set(key_partialstep) AND bottom[0] NE -1 $
397          AND ny 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 = e23*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, 2)
410        ENDELSE
411        res = res*e23*mask
412        if nz EQ 1 then res = reform(res, nx, ny, nz, /over)
413        res = total(res, 2, nan = nan)/(divi > 1.)
414        e23 = 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, 2)+(total(mask, 2) EQ 0)
419        endif
420      end
421      (dirx eq 0) and (diry eq 0) and (dirz eq 1) : begin
422        e33 = replicate(1, 1.*nx*ny)#e3
423        e33 = reform(e33, nx, ny, nz, /over)
424        IF keyword_set(key_partialstep) AND bottom[0] NE -1 THEN BEGIN
425          IF keyword_set(wdepth) THEN $
426            e33[bottom] = (e3w_ps[firstx:lastx, firsty:lasty])[temporary(good)] $
427          ELSE e33[bottom] = (e3t_ps[firstx:lastx, firsty:lasty])[temporary(good)]
428        ENDIF
429        if keyword_set(integration) then divi = 1 else begin
430          divi = e33*mask
431          if msknan[0] NE -1 then divi = temporary(divi)*msknan
432          if nz EQ 1 then divi = reform(divi, nx, ny, nz, /over)
433          divi = total(divi, 3)
434        ENDELSE
435        res = res*e33*mask
436        if nz EQ 1 then res = reform(res, nx, ny, nz, /over)
437        res = total(res, 3, nan = nan)/(divi > 1.)
438        e33 = 1
439        if msknan[0] NE -1 then begin
440          testnan  = msknan*mask
441          if nz EQ 1 then testnan  = reform(testnan, nx, ny, nz, /over)
442          testnan = total(testnan, 3)+(total(mask, 3) EQ 0)
443        endif
444      end
445      (dirx eq 1) and (diry eq 1) and (dirz eq 0) : begin
446        e123 = (e1*e2)[*]#replicate(1., nz)
447        e123 = reform(e123, nx, ny, nz, /over)
448        IF keyword_set(key_partialstep) AND bottom[0] NE -1 $
449          AND nx*ny NE 1 THEN BEGIN
450          IF msknan[0] EQ -1 THEN BEGIN
451            msknan = replicate(1b, nx, ny, nz)
452            nan = 1
453          endif
454          msknan[bottom] = 0
455          res[bottom] = !values.f_nan
456        ENDIF
457        if keyword_set(integration) then divi = 1 else BEGIN
458          divi = e123*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(total(divi, 1), 1)
462        ENDELSE
463        res = res*e123*mask
464        if nz EQ 1 then res = reform(res, nx, ny, nz, /over)
465        res = total(total(res, 1, nan = nan), 1, nan = nan) / (divi > 1.)
466        e123 = 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(total(testnan, 1), 1)+(total(total(mask, 1), 1) EQ 0)
471        endif
472      end
473      (dirx eq 1) and (diry eq 0) and (dirz eq 1) : begin
474        e133 = e1[*]#e3
475        e133 = reform(e133, nx, ny, nz, /over)
476        IF keyword_set(key_partialstep) AND bottom[0] NE -1 THEN BEGIN
477          IF keyword_set(wdepth) THEN $
478            e133[bottom] = (e1*e3w_ps[firstx:lastx, firsty:lasty])[temporary(good)] $
479          ELSE e133[bottom] = (e1*e3t_ps[firstx:lastx, firsty:lasty])[temporary(good)]
480        ENDIF
481        if keyword_set(integration) then divi = 1 else BEGIN
482          divi = e133*mask
483          if msknan[0] NE -1 then divi = temporary(divi)*msknan
484          if nz EQ 1 then divi = reform(divi, nx, ny, nz, /over)
485          divi = total(total(divi, 1), 2)
486        ENDELSE
487        res = res*e133*mask
488        if nz EQ 1 then res = reform(res, nx, ny, nz, /over)
489        res = total(total(res, 1, nan = nan), 2, nan = nan) / (divi > 1.)
490        e133 = 1
491        if msknan[0] NE -1 then begin
492          testnan  = msknan*mask
493          if nz EQ 1 then testnan  = reform(testnan, nx, ny, nz, /over)
494          testnan = total(total(testnan, 1), 2)+(total(total(mask, 1), 2) EQ 0)
495        endif
496      end
497      (dirx eq 0) and (diry eq 1) and (dirz eq 1) : begin
498        e233 = e2[*]#e3
499        e233 = reform(e233, nx, ny, nz, /over)
500        IF keyword_set(key_partialstep) AND bottom[0] NE -1 THEN BEGIN
501          IF keyword_set(wdepth) THEN $
502            e233[bottom] = (e2*e3w_ps[firstx:lastx, firsty:lasty])[temporary(good)] $
503          ELSE e233[bottom] = (e2*e3t_ps[firstx:lastx, firsty:lasty])[temporary(good)]
504        ENDIF
505        if keyword_set(integration) then divi = 1 else BEGIN
506          divi = e233*mask
507          if msknan[0] NE -1 then divi = temporary(divi)*msknan
508          if nz EQ 1 then divi = reform(divi, nx, ny, nz, /over)
509          divi = total(total(divi, 2), 2)
510        ENDELSE
511        res = res*e233*mask
512        if nz EQ 1 then res = reform(res, nx, ny, nz, /over)
513        res = total(total(res, 2, nan = nan), 2, nan = nan) / (divi > 1.)
514        e233 = 1
515        if msknan[0] NE -1 then begin
516          testnan  = msknan*mask
517          if nz EQ 1 then testnan  = reform(testnan, nx, ny, nz, /over)
518          testnan = total(total(testnan, 2), 2)+(total(total(mask, 2), 2) EQ 0)
519        endif
520      end
521      (dirx eq 1) and (diry eq 1) and (dirz eq 1) : begin
522        e1233 = (e1*e2)[*]#e3
523        e1233 = reform(e1233, nx, ny, nz, /over)
524        IF keyword_set(key_partialstep) AND bottom[0] NE -1 THEN BEGIN
525          IF keyword_set(wdepth) THEN $
526            e1233[bottom] = (e1*e2*e3w_ps[firstx:lastx, firsty:lasty])[temporary(good)] $
527          ELSE e1233[bottom] = (e1*e2*e3t_ps[firstx:lastx, firsty:lasty])[temporary(good)]
528        ENDIF
529        if keyword_set(integration) then divi = 1 else BEGIN
530          if msknan[0] NE -1 then divi = total(e1233*mask*msknan) $
531          ELSE divi = total(e1233*mask)
532        ENDELSE
533        res = total(res*e1233*mask, nan = nan) / (divi > 1.)
534        e1233 = 1
535        if msknan[0] NE -1 then begin
536          testnan  = msknan*mask
537          testnan = total(testnan)+(total(mask) EQ 0)
538        endif
539      end
540    endcase
541  endif
542;------------------------------------------------------------
543;------------------------------------------------------------
544;IV ) finishing
545;------------------------------------------------------------
546;------------------------------------------------------------
547; IV.1) We mask land by a value equal to 1.e+20
548;------------------------------------------------------------
549  valmask = 1e+20
550  terre = where(divi EQ 0)
551  IF terre[0] NE -1 THEN BEGIN
552    res[terre] = 1e+20
553  ENDIF
554;------------------------------------------------------------
555; IV.2) We replace, when nan equal 1, !values.f_nan by nan
556;------------------------------------------------------------
557  if keyword_set(nan) NE 0 then BEGIN
558    puttonan = where(testnan EQ 0)
559    if puttonan[0] NE -1 then res[puttonan] = !values.f_nan
560    if nan NE 1 then BEGIN
561      notanumber = where(finite(res) eq 0)
562      if notanumber[0] NE -1 then res[notanumber] = nan
563    ENDIF
564  ENDIF
565;------------------------------------------------------------
566; IV.3) We replace in the domain whch was defined at the entry of average
567;------------------------------------------------------------
568  if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat'
569;------------------------------------------------------------
570  if keyword_set(key_performance) THEN print, 'temps moyenne', systime(1)-tempsun
571  return, res
572;------------------------------------------------------------
573;------------------------------------------------------------
574end
Note: See TracBrowser for help on using the repository browser.