Index: trunk/SRC/ToBeReviewed/CALCULS/grossemoyenne.pro
===================================================================
--- trunk/SRC/ToBeReviewed/CALCULS/grossemoyenne.pro	(revision 163)
+++ trunk/SRC/ToBeReviewed/CALCULS/grossemoyenne.pro	(revision 223)
@@ -4,5 +4,5 @@
 ;+
 ;
-; @file_comments  
+; @file_comments
 ; averages a 3- or 4-d time series field over a selected
 ; geographical area or along the time axis. For one ore more
@@ -16,27 +16,31 @@
 ; @param DIREC {in}{required}
 ; 'x' 'y' 'z' 't' 'xy' 'xz' 'yz' 'xyz' 'xt' 'yt' 'zt'
-; 'xyt' 'xzt' 'yzt' or 'xyzt' 
-;
-; @keyword BOXZOOM  
+; 'xyt' 'xzt' 'yzt' or 'xyzt'
+;
+; @keyword BOXZOOM
 ; [xmin,xmax,ymin,ymax (,(zmin,)zmax)] to more details, see domdef
-; boxzoom can have 5 forms: 
-; [vert2], [vert1, vert2],[lon1, lon2, lat1, lat2],  
+; boxzoom can have 5 forms:
+; [vert2], [vert1, vert2],[lon1, lon2, lat1, lat2],
 ; [lon1, lon2, lat1, lat2, vert2],[lon1, lon2, lat1, lat2, vert1,vert2]
-;             
-; @keyword NAN 
-; not a number, we activate it if we want to average without considerate some masked values of TAB.
-; If masked values of TAB are values consecrated by IDL(!values.f_nan), wr just have to put NAN.
-; If masked values of TAB are valued a (a must be different of 1, corresponding to nan =
-; !values.f_nan and of 0, which desactivate nan). We have to put NAN=a. 
-; Comment: In output, rsult points which are NAN will be valued a or !values.f_nan.
-;            
+;
+; @keyword NAN
+; not a number, we activate it if we want to average without considerate some
+; masked values of TAB.
+; If masked values of TAB are values consecrated by IDL(!values.f_nan), we
+; just have to put NAN.
+; If masked values of TAB are valued a (a must be different of 1,
+; corresponding to nan = !values.f_nan and of 0, which desactivate nan).
+; We have to put NAN=a.
+; Comment: In output, rsult points which are NAN will be valued a or
+; !values.f_nan.
+;
 ; @keyword NODOMDEF
-; We activate it if we do not want to pass in domdef even if the keyword boxzoom 
-; is present (like when grossemoyenne is called via checkfield)
-;
-; @keyword INTEGRATION 
+; We activate it if we do not want to pass in domdef even if the keyword
+; boxzoom is present (like when grossemoyenne is called via checkfield)
+;
+; @keyword INTEGRATION
 ; To make an integral rather than an average
 ;
-; @keyword SPATIALFIRST 
+; @keyword SPATIALFIRST
 ; when performing at the same time
 ; spatial and temporal mean, grossemoyenne is assuming
@@ -48,26 +52,25 @@
 ; SPATIALFIRST is activated automatically.
 ;
-; @keyword TEMPORALFIRST 
+; @keyword TEMPORALFIRST
 ; to force to perform first temporal
-; mean even if nan is activated (see SPATIALFIRST
-; explanations...)
-;
-; 
-; @keyword WDEPTH 
-; to specify that the field is at W depth instead of T 
-; depth (automatically activated if vargrid eq 'W') 
+; mean even if nan is activated (see SPATIALFIRST explanations...)
+;
+; @keyword WDEPTH
+; to specify that the field is at W depth instead of T
+; depth (automatically activated if vargrid eq 'W')
 ;
 ; @uses
-; result:un tableau 
+; result:un tableau
 ; common
 ; domdef
 ;
-; @restrictions Put values corresponding to land at 1.e20
-;
-; @history 
+; @restrictions
+; Put values corresponding to land at 1.e20
+;
+; @history
 ; Jerome Vialard (jv\@lodyc.jussieu.fr)
 ;			2/7/98
 ;                       Sebastien Masson (smasson\@lodyc.jussieu.fr)
-; adaptation array containing a temporal dimension 
+; adaptation array containing a temporal dimension
 ;                       14/8/98
 ;                       15/1/98
@@ -118,15 +121,15 @@
   taille = size(tab)
   case 1 of
-    taille[0] eq 1 :return,  report('Le tableau n''a qu''une dimension, cas non traite!')
-    taille[0] eq 2 :return,  report('Le tableau n''a qu''deux dimension, cas non traite!')
-    taille[0] eq 3 :BEGIN 
+    taille[0] eq 1 :return,  report('array has only one dimension, not implemented!')
+    taille[0] eq 2 :return,  report('array has only two dimensions, not implemented!')
+    taille[0] eq 3 :BEGIN
       dim = '3d'
       if dirx eq 0 and diry eq 0 and dirt eq 0 then return, tab
     END
-    taille[0] eq 4 :BEGIN 
+    taille[0] eq 4 :BEGIN
       dim = '4d'
       if dirx eq 0 and diry eq 0 and dirz eq 0 and dirt eq 0 then return, tab
     END
-    else : return, report('Le tableau d entree doit etre a 3 ou 4 dimensions s''il ne contient pas de dim temporelle utiliser moyenne')
+    else : return, report('array must have 3 or 4 dimensions if there is not time dimension use moyenne')
   endcase
 ;------------------------------------------------------------
@@ -134,7 +137,7 @@
 ; Redefinition of the domain ajusted at boxzoom (at 6 elements)
 ; This will allowed us to calculate only in the domain concerned by the average.
-; Domdef, followed by grid give us all arrays of the grid on the subdomain 
-;------------------------------------------------------------
-  if keyword_set(boxzoom) then BEGIN 
+; Domdef, followed by grid give us all arrays of the grid on the subdomain
+;------------------------------------------------------------
+  if keyword_set(boxzoom) then BEGIN
     Case 1 Of
       N_Elements(Boxzoom) Eq 1: bte = [lon1, lon2, lat1, lat2, 0., boxzoom[0]]
@@ -145,10 +148,10 @@
       Else: return, report('Wrong Definition of Boxzoom')
     endcase
-    if NOT keyword_set(nodomdef) then BEGIN 
+    if NOT keyword_set(nodomdef) then BEGIN
       savedbox = 1b
       saveboxparam, 'boxparam4grmoyenne.dat'
       domdef, bte, GRIDTYPE = vargrid, _extra = ex
-    ENDIF 
-  ENDIF 
+    ENDIF
+  ENDIF
 ;---------------------------------------------------------------
 ; attribution of the mask and of longitude and latitude arrays...
@@ -159,5 +162,5 @@
 ;------------------------------------------------------------
   if dirt EQ 1 AND NOT keyword_set(spatialfirst) then begin
-    if dim EQ 3d then BEGIN 
+    if dim EQ 3d then BEGIN
       case 1 of
         taille[1] eq jpi and taille[2] eq jpj and taille[3] eq jpt: $
@@ -165,5 +168,5 @@
                     , firsty:firsty+ny-1, *]
         taille[1] EQ  nx and taille[2] eq  ny and taille[3] eq jpt:res = tab
-        else:BEGIN 
+        else:BEGIN
           if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4grmoyenne.dat'
           return, report('Probleme d''adequation entre les tailles du domaine nx*ny*jpt '+strtrim(nx, 1)+'*'+strtrim(ny, 1)+'*'+strtrim(jpt, 1)+' et du tableau '+strtrim(taille[1], 1)+'*'+strtrim(taille[2], 1)+'*'+strtrim(taille[3], 1))
@@ -179,5 +182,5 @@
           res = total(res, 3, nan = keyword_set(nan))/ (1 > divi)
           if notanum[0] NE -1 then res[temporary(notanum)] = !values.f_nan
-        ENDIF ELSE res = total(res, 3)/(1.*taille[3]) 
+        ENDIF ELSE res = total(res, 3)/(1.*taille[3])
       ENDELSE
     ENDIF ELSE BEGIN
@@ -190,5 +193,5 @@
         taille[1] EQ  nx and taille[2] eq  ny and taille[3] eq jpk and taille[4] eq jpt: $
           res = tab[*, *, firstz:lastz, *]
-        else:BEGIN 
+        else:BEGIN
            if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4grmoyenne.dat'
           return, report('Probleme d''adequation entre les tailles du domaine nx*ny*nz*jpt ' $
@@ -211,9 +214,9 @@
       ENDELSE
     ENDELSE
-    if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4grmoyenne.dat'    
+    if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4grmoyenne.dat'
     return,  moyenne(temporary(res), direc, BOXZOOM = boxzoom, NAN = nan, INTEGRATION = integration, NODOMDEF = nodomdef, WDEPTH = wdepth, _extra = ex)
   ENDIF ELSE res = tab
   IF jpt EQ 1 THEN BEGIN
-    if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4grmoyenne.dat'    
+    if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4grmoyenne.dat'
     return, moyenne(reform(res, /over), direc, BOXZOOM = boxzoom, NAN = nan, INTEGRATION = integration, NODOMDEF = nodomdef, WDEPTH = wdepth, _extra = ex)
   END
@@ -227,6 +230,6 @@
 ;   II.1) verification of the coherence of the array's size to average
 ; Verification of the coherence between the array's size and the domain defined by domdef
-; The input array must have either the total domain's size (jpi,jpj,jpt) or this 
-; one of the reduced domain (nx,ny,jpt)
+; The input array must have either the total domain's size (jpi,jpj,jpt) or
+; this one of the reduced domain (nx,ny,jpt)
 ;---------------------------------------------------------------
     case 1 of
@@ -235,11 +238,11 @@
                   , firsty:firsty+ny-1, *]
       taille[1] EQ  nx and taille[2] eq  ny and taille[3] eq jpt:res = tab
-      else:BEGIN 
+      else:BEGIN
         if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4grmoyenne.dat'
         return, report('Probleme d''adequation entre les tailles du domaine nx*ny*jpt '+strtrim(nx, 1)+'*'+strtrim(ny, 1)+'*'+strtrim(jpt, 1)+' et du tableau '+strtrim(taille[1], 1)+'*'+strtrim(taille[2], 1)+'*'+strtrim(taille[3], 1))
       enD
     endcase
-    if keyword_set(nan) NE 0 then BEGIN 
-      if nan NE 1 then BEGIN    ; If nan is not !values.f_nan 
+    if keyword_set(nan) NE 0 then BEGIN
+      if nan NE 1 then BEGIN    ; If nan is not !values.f_nan
 ; we put it at !values.f_nan
         if abs(nan) LT 1e6 then notanumber = where(res EQ nan) $
@@ -249,9 +252,9 @@
     ENDIF
 ;---------------------------------------------------------------
-; Comment : WE HAVE TO BE CAREFUL ABOUT CASES WHERE THE DIMENSION TO AVERAGE = 1, 
-; AND MAKE SURE THAT IT EXIST. THAT IS WHY WE USE reform(...,nx,ny,...) WHICH CAN 
-; LOOK USELESS AT THE BEGINNING
-;---------------------------------------------------------------
-    if nx EQ 1 OR ny EQ 1 then BEGIN 
+; Comment : WE HAVE TO BE CAREFUL ABOUT CASES WHERE THE DIMENSION TO
+; AVERAGE = 1, AND MAKE SURE THAT IT EXIST. THAT IS WHY WE USE
+; reform(...,nx,ny,...) WHICH CAN LOOK USELESS AT THE BEGINNING
+;---------------------------------------------------------------
+    if nx EQ 1 OR ny EQ 1 then BEGIN
       res = reform(res, nx, ny, jpt, /over)
       e1 =  reform(e1, nx, ny, /over)
@@ -270,5 +273,5 @@
         echelle = (temporary(e))[*]#replicate(1, jpt)
         echelle = reform(echelle, nx, ny, jpt, /over)
-        if keyword_set(integration) then divi = 1 ELSE BEGIN 
+        if keyword_set(integration) then divi = 1 ELSE BEGIN
           IF msknan[0] NE -1 THEN divi = total(echelle*msknan, 1) $
           ELSE divi = total(echelle, 1)
@@ -287,8 +290,8 @@
         echelle = (temporary(e))[*]#replicate(1, jpt)
         echelle = reform(echelle, nx, ny, jpt, /over)
-        if keyword_set(integration) then divi = 1 ELSE BEGIN 
+        if keyword_set(integration) then divi = 1 ELSE BEGIN
           IF msknan[0] NE -1 THEN divi = total(echelle*msknan, 2) $
           ELSE divi = total(echelle, 2)
-        ENDELSE 
+        ENDELSE
         res = total(temporary(res)*echelle, 2, nan = nan)/(divi > 1.)
         if msknan[0] NE -1 then begin
@@ -302,5 +305,5 @@
         echelle = (temporary(e1)*temporary(e2)*temporary(mask))[*]#replicate(1, jpt)
         echelle = reform(echelle, nx, ny, jpt, /over)
-        if keyword_set(integration) then divi = 1 ELSE BEGIN 
+        if keyword_set(integration) then divi = 1 ELSE BEGIN
           IF msknan[0] NE -1 THEN divi = total(total(echelle*msknan, 1), 1) $
           ELSE divi = total(total(echelle, 1), 1)
@@ -322,8 +325,8 @@
   if (dim eq '4d') then begin
 ;---------------------------------------------------------------
-; III.1) Verification of the coherence of the array to average size 
-; Verification of the coherence between the array's size and the domain 
-; defind by domdef 
-; The input array must have either the total domain size (jpi,jpj,jpk,jpt) 
+; III.1) Verification of the coherence of the array to average size
+; Verification of the coherence between the array's size and the domain
+; defind by domdef
+; The input array must have either the total domain size (jpi,jpj,jpk,jpt)
 ; or this one of the reduced domain (nx,ny,ny,jpt)
 ;---------------------------------------------------------------
@@ -336,5 +339,5 @@
       taille[1] EQ  nx and taille[2] eq  ny and taille[3] eq jpk and taille[4] eq jpt: $
         res = tab[*, *, firstz:lastz, *]
-      else:BEGIN 
+      else:BEGIN
         if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4grmoyenne.dat'
         return, report('Probleme d''adequation entre les tailles du domaine nx*ny*nz*jpt ' $
@@ -346,6 +349,6 @@
     endcase
     if nx EQ 1 OR ny EQ 1 OR nz EQ 1 OR jpt EQ 1 then res = reform(res, nx, ny, nz, jpt, /over)
-    if keyword_set(nan) NE 0 then BEGIN 
-      if nan NE 1 then BEGIN    ; if nan is not !values.f_nan 
+    if keyword_set(nan) NE 0 then BEGIN
+      if nan NE 1 then BEGIN    ; if nan is not !values.f_nan
 ; we put it at !values.f_nan
         if abs(nan) LT 1e6 then notanumber = where(res EQ nan) $
@@ -355,9 +358,9 @@
     ENDIF
 ;---------------------------------------------------------------
-; Comment : WE HAVE TO BE CAREFUL ABOUT CASES WHERE THE DIMENSION TO AVERAGE = 1, 
-; AND MAKE SURE THAT IT EXIST. THAT IS WHY WE USE reform(...,nx,ny,...) WHICH CAN 
-; LOOK USELESS AT THE BEGINNING
-;---------------------------------------------------------------
-    if nx EQ 1 OR ny EQ 1 OR nz EQ 1 then BEGIN 
+; Comment : WE HAVE TO BE CAREFUL ABOUT CASES WHERE THE DIMENSION TO
+; AVERAGE = 1, AND MAKE SURE THAT IT EXIST. THAT IS WHY WE USE
+; reform(...,nx,ny,...) WHICH CAN LOOK USELESS AT THE BEGINNING
+;---------------------------------------------------------------
+    if nx EQ 1 OR ny EQ 1 OR nz EQ 1 then BEGIN
       res = reform(res, nx, ny, nz, jpt, /over)
       mask =  reform(mask, nx, ny, nz, /over)
@@ -366,6 +369,6 @@
 ; the top of the ocean floor is
       IF vargrid EQ 'T' OR vargrid EQ 'W' THEN bottom = total(mask, 3) $
-      ELSE bottom = total(tmask[firstx:lastx, firsty:lasty, firstz:lastz], 3) 
-; we suppress columns with only ocean or land 
+      ELSE bottom = total(tmask[firstx:lastx, firsty:lasty, firstz:lastz], 3)
+; we suppress columns with only ocean or land
       good = where(bottom NE 0 AND bottom NE nz)
 ; the bottom of the ocean in 3D index is:
@@ -386,5 +389,5 @@
         IF keyword_set(key_partialstep) AND bottom[0] NE -1 $
           AND nx NE 1 THEN BEGIN
-          IF msknan[0] EQ -1 THEN BEGIN 
+          IF msknan[0] EQ -1 THEN BEGIN
             msknan = replicate(1b, nx, ny, nz, jpt)
             nan = 1
@@ -395,5 +398,5 @@
           res[temporary(bottom)] = !values.f_nan
         ENDIF
-        if keyword_set(integration) then divi = 1 ELSE begin 
+        if keyword_set(integration) then divi = 1 ELSE begin
           IF msknan[0] NE -1 THEN divi = total(echelle*msknan, 1) $
           ELSE divi = total(echelle, 1)
@@ -415,5 +418,5 @@
         IF keyword_set(key_partialstep) AND bottom[0] NE -1 $
           AND ny NE 1 THEN BEGIN
-          IF msknan[0] EQ -1 THEN BEGIN 
+          IF msknan[0] EQ -1 THEN BEGIN
             msknan = replicate(1b, nx, ny, nz)
             nan = 1
@@ -424,5 +427,5 @@
           res[temporary(bottom)] = !values.f_nan
         ENDIF
-        if keyword_set(integration) then divi = 1 ELSE begin 
+        if keyword_set(integration) then divi = 1 ELSE begin
           IF msknan[0] NE -1 THEN divi = total(echelle*msknan, 2) $
           ELSE divi = total(echelle, 2)
@@ -446,5 +449,5 @@
         echelle = (temporary(e33)*temporary(mask))[*]#replicate(1, jpt)
         echelle = reform(echelle, nx, ny, nz, jpt, /over)
-        if keyword_set(integration) then divi = 1 ELSE begin 
+        if keyword_set(integration) then divi = 1 ELSE begin
           IF msknan[0] NE -1 THEN divi = total(echelle*msknan, 3) $
           ELSE divi = total(echelle, 3)
@@ -467,5 +470,5 @@
         IF keyword_set(key_partialstep) AND bottom[0] NE -1 $
           AND nx*ny NE 1 THEN BEGIN
-          IF msknan[0] EQ -1 THEN BEGIN 
+          IF msknan[0] EQ -1 THEN BEGIN
             msknan = replicate(1b, nx, ny, nz)
             nan = 1
@@ -476,5 +479,5 @@
           res[temporary(bottom)] = !values.f_nan
         ENDIF
-        if keyword_set(integration) then divi = 1 ELSE begin 
+        if keyword_set(integration) then divi = 1 ELSE begin
           IF msknan[0] NE -1 THEN divi = total(total(echelle*msknan, 1), 1) $
           ELSE divi = total(total(echelle, 1), 1)
@@ -497,5 +500,5 @@
         echelle = (temporary(e133[*])*temporary(mask[*]))#replicate(1, jpt)
         echelle = reform(echelle, nx, ny, nz, jpt, /over)
-        if keyword_set(integration) then divi = 1 ELSE begin 
+        if keyword_set(integration) then divi = 1 ELSE begin
           IF msknan[0] NE -1 THEN divi = total(total(echelle*msknan, 1), 2) $
           ELSE divi = total(total(echelle, 1), 2)
@@ -518,5 +521,5 @@
         echelle = (temporary(e233[*])*temporary(mask[*]))#replicate(1, jpt)
         echelle = reform(echelle, nx, ny, nz, jpt, /over)
-        if keyword_set(integration) then divi = 1 ELSE begin 
+        if keyword_set(integration) then divi = 1 ELSE begin
           IF msknan[0] NE -1 THEN divi = total(total(echelle*msknan, 2), 2) $
           ELSE divi = total(total(echelle, 2), 2)
@@ -539,5 +542,5 @@
         echelle = (temporary(e1233[*])*temporary(mask[*]))#replicate(1, jpt)
         echelle = reform(echelle, nx, ny, nz, jpt, /over)
-        if keyword_set(integration) then divi = 1 ELSE begin 
+        if keyword_set(integration) then divi = 1 ELSE begin
           IF msknan[0] NE -1 THEN divi = total(total(total(echelle*msknan, 1), 1), 1) $
           ELSE divi = total(total(total(echelle, 1), 1), 1)
@@ -562,6 +565,6 @@
     tdim = size(res, /n_dimensions)
     if keyword_set(integration) then res = total(res, tdim, nan = nan) $
-    ELSE BEGIN 
-      if keyword_set(nan) then BEGIN 
+    ELSE BEGIN
+      if keyword_set(nan) then BEGIN
         testnan = testnan < 1
         testnan = total(temporary(testnan), tdim)
@@ -569,5 +572,5 @@
       ENDIF ELSE divi = jpt
       res = total(res, tdim, nan = nan)/(1 > divi)
-    ENDELSE 
+    ENDELSE
   ENDIF
 ;------------------------------------------------------------
@@ -580,14 +583,14 @@
   valmask = 1e+20
   terre = where(divi EQ 0)
-  IF terre[0] NE -1 THEN BEGIN 
+  IF terre[0] NE -1 THEN BEGIN
     res[temporary(terre)] = 1e+20
-  ENDIF 
+  ENDIF
 ;------------------------------------------------------------
 ; IV.2) We replace, when nan equal 1, !values.f_nan by nan
 ;------------------------------------------------------------
-  if keyword_set(nan) NE 0 then BEGIN 
+  if keyword_set(nan) NE 0 then BEGIN
     puttonan = where(temporary(testnan) EQ 0)
     if puttonan[0] NE -1 then res[temporary(puttonan)] = !values.f_nan
-    if nan NE 1 then BEGIN 
+    if nan NE 1 then BEGIN
       notanumber = where(finite(res) eq 0)
       if notanumber[0] NE -1 then res[temporary(notanumber)] = nan
@@ -599,5 +602,5 @@
   if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4grmoyenne.dat'
 ;------------------------------------------------------------
-  if keyword_set(key_performance) THEN print, 'temps grossemoyenne', systime(1)-tempsun 
+  if keyword_set(key_performance) THEN print, 'temps grossemoyenne', systime(1)-tempsun
   return, res
 ;------------------------------------------------------------
