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

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

typo and links in header in some pro files

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