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

Last change on this file was 495, checked in by pinsard, 10 years ago

fix thanks to coding rules; typo; dupe empty lines; trailing blanks

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