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
RevLine 
[2]1;+
2;
[223]3; @file_comments
[142]4; averages a 2- or 3-d field over a selected
[268]5;           geographical area and along one or more
[2]6;           selected axes (x, y or z)
7;
[142]8; @categories
[2]9;
[163]10; @param TAB {in}{required}
[142]11; 2 or 3d field
[2]12;
[142]13; @param DIREC {in}{required}
14; 'x' 'y' 'z' 'xy' 'xz' 'yz' or 'xyz'
[2]15;
[223]16; @keyword BOXZOOM
[254]17; [xmin,xmax,ymin,ymax (,(zmin,)zmax)] to more details, see <pro>domdef</pro>
[223]18; boxzoom can have 5 forms:
[163]19;  [vert2],
20;  [vert1, vert2],
[223]21;  [lon1, lon2, lat1, lat2],
[163]22;  [lon1, lon2, lat1, lat2, vert2],
23;  [lon1, lon2, lat1, lat2, vert1,vert2]
[2]24;
[223]25; @keyword NAN
[142]26; not a number, we activate it if we want to average without considerate some masked values of TAB.
[163]27; If masked values of TAB are values consecrated by IDL(!values.f_nan), we just have to put NAN.
[142]28; If masked values of TAB are valued a (a must be different of 1, corresponding to nan =
[223]29; !values.f_nan and of 0, which desactivate nan). We have to put NAN=a.
[163]30; Comment: In output, result points which are NAN will be valued a or !values.f_nan.
[223]31;
[142]32; @keyword NODOMDEF
[237]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>)
[2]36;
[223]37; @keyword INTEGRATION
[142]38; To make an integral rather than an average
[223]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;
[142]44; @returns
[223]45; An array
[2]46;
[142]47; @uses
48; common
[254]49; <pro>domdef</pro>
[2]50;
[223]51; @restrictions
52; Put values corresponding to land at 1.e20
[2]53;
[142]54; @history
[157]55;  Jerome Vialard (jv\@lodyc.jussieu.fr)
[2]56;                       2/7/98
[157]57;                       Sebastien Masson (smasson\@lodyc.jussieu.fr)
[2]58;                       14/8/98
59;                       15/1/98
[142]60;                       11/3/99 adaptation for NAN
61;                       28/7/99 Averages 1d arrays
62;
63; @version
64; $Id$
65;
[2]66;-
[231]67;
[232]68FUNCTION moyenne, tab, direc, BOXZOOM = boxzoom, INTEGRATION = integration $
[25]69                  , NAN = nan, NODOMDEF = nodomdef, WDEPTH = wdepth $
[232]70                  , _EXTRA = ex
[114]71;
72  compile_opt idl2, strictarrsubs
73;
[25]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;---------------------------------------------------------
[142]82  tempsun = systime(1)          ; To key_performance
[2]83;------------------------------------------------------------
[142]84;I) preliminaries
[2]85;------------------------------------------------------------
[25]86  dirt = 0
87  dirx = 0
88  diry = 0
89  dirz = 0
[2]90;------------------------------------------------------------
[142]91; I.1) Directions(s) we follow to integrate
[2]92;------------------------------------------------------------
[25]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
[2]98;------------------------------------------------------------
[142]99; I.2) verification of the input array's size
[2]100;------------------------------------------------------------
[25]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
[223]112    else : return, report('Array must have 2 or 3 dimensions if there is a time dimension use grossemoyenne')
[25]113  endcase
[2]114;------------------------------------------------------------
[142]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.
[223]118; Domdef, followed by grid give us all arrays of the grid on the subdomain
[2]119;------------------------------------------------------------
[223]120  if keyword_set(boxzoom) then BEGIN
[25]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
[223]127      Else: return, report('Bad definition of Boxzoom')
[25]128    endcase
[223]129    if NOT keyword_set(nodomdef) then BEGIN
[25]130      savedbox = 1b
131      saveboxparam, 'boxparam4moyenne.dat'
132      domdef, bte, GRIDTYPE = vargrid, _extra = ex
[223]133    ENDIF
134  ENDIF
[2]135;---------------------------------------------------------------
[142]136; attribution of the mask and of longitude and latitude arrays...
[2]137;---------------------------------------------------------------
[25]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
[2]140;------------------------------------------------------------
141;------------------------------------------------------------
[142]142; II) Case of the 1d array
[2]143;------------------------------------------------------------
144;------------------------------------------------------------
[25]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
[142]151      nx EQ 1 AND ny EQ 1:BEGIN ;vector following z
[25]152        case n_elements(tab) of
153          jpk:res = tab[firstz:lastz]
154          nz:res = tab
[223]155          ELSE:BEGIN
[25]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
[223]160        if dirz EQ 1 then BEGIN
161          dim = '3d'
[25]162          taille = size(reform(res, nx, ny, nz))
163        ENDIF ELSE BEGIN
164          if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat'
165          return, res
[223]166        ENDELSE
[25]167      END
[142]168      ny EQ 1:BEGIN             ;vector following x
[25]169        case n_elements(tab) of
170          jpi:res = tab[firstx:lastx]
171          nx:res = tab
[223]172          ELSE:BEGIN
[25]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
[223]177        if dirx EQ 1 then BEGIN
178          dim = '2d'
[25]179          taille = size(reform(res, nx, ny))
[223]180        ENDIF ELSE BEGIN
[25]181          if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat'
182          return, res
183        ENDELSE
184      END
[142]185      nx EQ 1:BEGIN             ;vector following y
[25]186        case n_elements(tab) of
187          jpj:res = tab[firsty:lasty]
188          ny:res = tab
[223]189          ELSE:BEGIN
[25]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))
[223]197        ENDIF ELSE BEGIN
[25]198          if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat'
199          return, res
[223]200        ENDELSE
[25]201      END
202    endcase
203  endif
[2]204;------------------------------------------------------------
205;------------------------------------------------------------
[142]206; II) Case of the 2d array
[2]207;------------------------------------------------------------
208;------------------------------------------------------------
[25]209  if (dim eq '2d') then begin
[2]210;---------------------------------------------------------------
[142]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
[223]213; The input array must have either the total domain's size (jpi,jpj) or this
[142]214; one of the reduced domain (nx,ny)
[2]215;---------------------------------------------------------------
[25]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
[223]220      else:BEGIN
[25]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
[223]225    if keyword_set(nan) NE 0 then BEGIN
226      if nan NE 1 then BEGIN    ; If nan is not !values.f_nan
[142]227; we put it at !values.f_nan
[25]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
[2]231      ENDIF
[25]232    ENDIF
[2]233;---------------------------------------------------------------
[223]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
[142]236; LOOK USELESS AT THE BEGINNING
[2]237;---------------------------------------------------------------
[223]238    if nx EQ 1 OR ny EQ 1 then BEGIN
[25]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)
[2]245;---------------------------------------------------------------
[142]246; II.3) Different types of average
[2]247;---------------------------------------------------------------
[25]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 $
[223]254        else begin
[25]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 $
[223]272        else begin
[25]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
[223]288        if keyword_set(integration) then divi = 1 else BEGIN
[25]289          IF msknan[0] NE -1 THEN divi = total(e1*e2*mask*msknan) $
290          ELSE divi = total(e1*e2*mask)
[223]291        ENDELSE
[25]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
[2]300;------------------------------------------------------------
301;------------------------------------------------------------
[142]302; III) Case 3d arrays series (tab4d)
[2]303;------------------------------------------------------------
304;------------------------------------------------------------
[25]305  if (dim eq '3d') then begin
[2]306;---------------------------------------------------------------
[223]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)
[142]311; or this one of the reduced domain (nx,ny,ny)
[2]312;---------------------------------------------------------------
[25]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]
[223]321      else:BEGIN
[25]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
[223]326    if keyword_set(nan) NE 0 then BEGIN
327      if nan NE 1 then BEGIN    ; if nan is not !values.f_nan
[142]328; we put it at !values.f_nan
[25]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
[2]332      ENDIF
[25]333    ENDIF
[2]334;---------------------------------------------------------------
[223]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
[142]337; LOOK USELESS AT THE BEGINNING
[2]338;---------------------------------------------------------------
[223]339    if nx EQ 1 OR ny EQ 1 OR nz EQ 1 then BEGIN
[25]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) $
[223]349      ELSE bottom = total(tmask[firstx:lastx, firsty:lasty, firstz:lastz], 3)
350; we suppress columns with only ocean or land
[25]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
[2]357;---------------------------------------------------------------
[142]358; III.2) different average types
[2]359;---------------------------------------------------------------
[25]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
[223]367          IF msknan[0] EQ -1 THEN BEGIN
[25]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
[223]395          IF msknan[0] EQ -1 THEN BEGIN
[25]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
[223]447          IF msknan[0] EQ -1 THEN BEGIN
[25]448            msknan = replicate(1b, nx, ny, nz)
449            nan = 1
450          endif
451          msknan[bottom] = 0
452          res[bottom] = !values.f_nan
453        ENDIF
[223]454        if keyword_set(integration) then divi = 1 else BEGIN
[25]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
[223]478        if keyword_set(integration) then divi = 1 else BEGIN
[25]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
[223]502        if keyword_set(integration) then divi = 1 else BEGIN
[25]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
[223]526        if keyword_set(integration) then divi = 1 else BEGIN
[25]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
[2]539;------------------------------------------------------------
540;------------------------------------------------------------
[142]541;IV ) finishing
[2]542;------------------------------------------------------------
543;------------------------------------------------------------
[142]544; IV.1) We mask land by a value equal to 1.e+20
[2]545;------------------------------------------------------------
[25]546  valmask = 1e+20
547  terre = where(divi EQ 0)
548  IF terre[0] NE -1 THEN BEGIN
[114]549    res[terre] = 1e+20
[223]550  ENDIF
[2]551;------------------------------------------------------------
[142]552; IV.2) We replace, when nan equal 1, !values.f_nan by nan
[2]553;------------------------------------------------------------
[223]554  if keyword_set(nan) NE 0 then BEGIN
[25]555    puttonan = where(testnan EQ 0)
556    if puttonan[0] NE -1 then res[puttonan] = !values.f_nan
[223]557    if nan NE 1 then BEGIN
[25]558      notanumber = where(finite(res) eq 0)
559      if notanumber[0] NE -1 then res[notanumber] = nan
560    ENDIF
561  ENDIF
[2]562;------------------------------------------------------------
[142]563; IV.3) We replace in the domain whch was defined at the entry of average
[2]564;------------------------------------------------------------
[25]565  if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat'
[2]566;------------------------------------------------------------
[223]567  if keyword_set(key_performance) THEN print, 'temps moyenne', systime(1)-tempsun
[25]568  return, res
[2]569;------------------------------------------------------------
570;------------------------------------------------------------
571end
Note: See TracBrowser for help on using the repository browser.