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

Last change on this file since 424 was 424, checked in by smasson, 14 years ago

add keepbottom keyword in moyenne and grossemoyenne

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