Index: /IOIPSL/trunk/src/histcom.f90
===================================================================
--- /IOIPSL/trunk/src/histcom.f90	(revision 1926)
+++ /IOIPSL/trunk/src/histcom.f90	(revision 1927)
@@ -9,5 +9,5 @@
 !-
   USE stringop, ONLY : nocomma,cmpblank,findpos,find_str,strlowercase
-  USE mathelp,  ONLY : mathop,moycum,buildop
+  USE mathelp,  ONLY : mathop,moycum,moycum_index,buildop
   USE fliocom,  ONLY : flio_dom_file,flio_dom_att
   USE calendar
@@ -1206,5 +1206,5 @@
  &    .AND.(TRIM(W_F(idf)%W_V(iv)%topp) /= "never") )THEN
     ALLOCATE(W_F(idf)%W_V(iv)%t_bf(buff_sz))
-    W_F(idf)%W_V(iv)%t_bf(:) = 0.
+    W_F(idf)%W_V(iv)%t_bf(:) = missing_val
     IF (l_dbg) THEN
       WRITE(ipslout,*) "histdef : 3.0 allocating time_buffer for", &
@@ -1892,4 +1892,5 @@
   INTEGER,DIMENSION(4) :: corner,edges
   INTEGER :: itime
+  LOGICAL :: flag
 !-
   REAL :: rtime
@@ -2052,6 +2053,33 @@
     IF (     (TRIM(tmp_opp) /= "inst") &
  &      .AND.(TRIM(tmp_opp) /= "once") ) THEN
-      CALL moycum(tmp_opp,tsz,W_F(idf)%W_V(iv)%t_bf, &
- &           tbf_2,W_F(idf)%W_V(iv)%nb_opp)
+
+!-
+!------ 5.1 Check if scatter operation is performed
+!-      
+       flag = .FALSE. 
+       DO io = 1, nbopp_max
+          IF ( INDEX(TRIM(W_F(idf)%W_V(iv)%sopp(io)),'scatter') > 0 ) THEN 
+             flag = .TRUE. 
+          END IF
+       END DO
+
+       IF ( flag ) THEN
+!-
+!------ 5.2  Enter moycum_index only if a scatter operation is performed
+!-         
+          IF (l_dbg) &
+               & WRITE(ipslout,*) "histwrite: 5.2 moycum_index",nbindex,nx,ny,nz
+          CALL moycum_index(tmp_opp, W_F(idf)%W_V(iv)%t_bf, &
+ &             tbf_2, W_F(idf)%W_V(iv)%nb_opp, nbindex, nindex)
+       ELSE
+!-
+!------ 5.3  Enter moycum otherwise
+!-
+          IF (l_dbg) &
+               & WRITE(ipslout,*) "histwrite: 5.3 moycum",nbindex,nx,ny
+          CALL moycum(tmp_opp,tsz,W_F(idf)%W_V(iv)%t_bf, &
+               &           tbf_2,W_F(idf)%W_V(iv)%nb_opp)
+       END IF
+
     ENDIF
 !-
Index: /IOIPSL/trunk/src/mathelp.f90
===================================================================
--- /IOIPSL/trunk/src/mathelp.f90	(revision 1926)
+++ /IOIPSL/trunk/src/mathelp.f90	(revision 1927)
@@ -10,5 +10,5 @@
 !-
   PRIVATE
-  PUBLIC :: mathop,moycum,buildop
+  PUBLIC :: mathop,moycum,moycum_index,buildop
 !-
   INTERFACE mathop
@@ -3119,4 +3119,82 @@
 END SUBROUTINE moycum
 !===
+SUBROUTINE moycum_index( opp, px, py, pwx, nbi, ind )
+!---------------------------------------------------------------------
+!- Does time operations on index points 
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+
+  !! 0. Parameters and variables declaration
+
+  !! 0.1 Input variables
+
+  CHARACTER(LEN=7), INTENT(in)        :: opp  !! Operation performed
+  INTEGER, INTENT(in)                 :: nbi  !! Size of index vector
+  INTEGER, DIMENSION(nbi), INTENT(in) :: ind  !! Index vector
+  REAL, DIMENSION(:), INTENT(in)      :: py   !! Vector containing the 
+                                              !! previous values of px
+                                              !! Warning : due to memory 
+                                              !! optimization, we have
+                                              !! generally SIZE(px) /= SIZE(py)  
+  INTEGER, INTENT(in)                 :: pwx  !! Used to calculate average value                             
+
+  !! 0.3 Modified variables
+
+  REAL, DIMENSION(:), INTENT(inout)   :: px   !! Result
+
+  !! 0.4 Local variables
+
+  INTEGER :: ig                               !! Index
+
+!---------------------------------------------------------------------
+
+  !! Perform operations only if the values of ind don't exceed the size of px 
+
+  IF ( MAXVAL(ind) > SIZE(px) ) THEN
+     CALL ipslerr(3,"moycum_index", &
+          & "the index vector is out of range for px", &
+          & "Indexation vector problem. We stop", " " )
+  END IF
+
+  IF (pwx /= 0) THEN
+     IF      (opp == 'ave') THEN
+        DO ig = 1,nbi
+           px(ind(ig)) = (px(ind(ig))*pwx + py(ind(ig)))/REAL(pwx+1)
+        END DO
+     ELSE IF (opp == 't_sum') THEN
+        DO ig = 1,nbi
+           px(ind(ig)) = px(ind(ig)) + py(ind(ig))
+        END DO
+     ELSE IF ( (opp == 'l_min').OR.(opp == 't_min') ) THEN
+        DO ig = 1,nbi
+           px(ind(ig)) = MIN(px(ind(ig)),py(ind(ig)))
+        END DO
+     ELSE IF ( (opp == 'l_max').OR.(opp == 't_max') ) THEN
+        DO ig = 1,nbi
+           px(ind(ig)) = MAX(px(ind(ig)),py(ind(ig)))
+        END DO
+     ELSE
+        CALL ipslerr(3,"moycum_index",'Unknown time operation',opp,' ')
+     END IF
+  ELSE
+    IF      (opp == 'l_min') THEN
+       DO ig = 1,nbi
+          px(ind(ig)) = MIN(px(ind(ig)),py(ind(ig)))
+       END DO
+    ELSE IF (opp == 'l_max') THEN
+       DO ig = 1,nbi
+          px(ind(ig)) = MAX(px(ind(ig)),py(ind(ig)))
+       END DO
+    ELSE
+       DO ig = 1,nbi
+          px(ind(ig)) = py(ind(ig))
+       END DO
+    ENDIF
+ END IF
+
+END SUBROUTINE moycum_index
+
+
 !-----------------
 END MODULE mathelp
