Index: /trunk/tools/nc_var_tools.py
===================================================================
--- /trunk/tools/nc_var_tools.py	(revision 882)
+++ /trunk/tools/nc_var_tools.py	(revision 883)
@@ -75,4 +75,5 @@
 # netcdf_fold_concatenation: Function to concatenate netCDF files in a given folder for a given set of variables
 # operation_alongdims: Function to operate along different dimensions of a variable
+# operdim: Function to operate along a series of dimensions
 # ovar_onc: Function to copy an object variable to a nother netcdf object
 # Partialmap_Entiremap: Function to transform from a partial global map (e.g.: only land points) to an entire one Coincidence of points is done throughout a first guess from fractions of the total domain of search
@@ -8756,4 +8757,44 @@
     return varvalues, dimnslice
 
+def operdim(varv, vardims, doper, oper):
+    """ Function to operate along a series of dimensions
+      varv: matrix values
+      vardims: dimension names of the variable
+      doper: names of the dimensions to operate
+      oper: operation to perform
+    """ 
+    fname = 'operdim'
+
+    operslice = []
+    for dn in vardims:
+        if not gen.searchInlist(doper, dn):
+            operslice.append(False)
+        else:
+            operslice.append(True)
+
+    operddims = []
+    noper = 0
+    for idim in range(len(varv.shape)):
+        if operslice[idim]:
+            if oper == 'max':
+                varoper = np.max(varv, axis=idim-noper)
+            elif oper == 'mean':
+                varoper = np.mean(varv, axis=idim-noper)
+            elif oper == 'mean2':
+                varoper = np.mean(varv, axis=idim-noper)
+            elif oper == 'min':
+                varoper = np.min(varv, axis=idim-noper)
+            elif oper == 'sum':
+                varoper = np.sum(varv, axis=idim-noper)
+            else:
+                print errormsg
+                print '  ' + fname + ': operation "' + oper + '" not ready!!'
+                quit(-1)
+            noper = noper + 1
+        else:
+            operddims.append(vardims[idim])
+            
+    return operedvals, opereddims
+
 def operation_alongdims(ovar,dimvals,dimsoper,opkind):
     """ Function to operate along different dimensions of a variable
@@ -8933,12 +8974,14 @@
 
 # Getting slice dimensions
-    dimslice = []
-    dimvalslice = []
+    dimslice = {}
     for dv in dimvals:
         dnv = dv.slice('|')[0]
         dvv = dv.slice('|')[1]
-        dimslice.append(dnv)
-        dimvalslice.append(dvv)
-
+        if dvv.find(':') != -1:
+            beg = int(dvv.slice(':')[0])
+            end = int(dvv.slice(':')[1])
+            dimslice[dnv] = [beg, end, 1]
+        else
+            dimslice[dnv] = int(dvv)
 
 # Creation of output file
@@ -8947,4 +8990,6 @@
 
     print '  ' + fname + ": '" + operkind + "' with:",dimsoper,'_______'
+    newNdim = 0
+    newNvar = 0
     for vn in varns:
         print "'" + vn + "' ... .. ."
@@ -8962,9 +9007,101 @@
 
         if tocopmute:
+            varslice, varsliceddims = VarSliceDict(ov,dimslice)
+            varvals0 = ov[tuple(varslice)]
+            varvals = np.squeeze(varvals0)
+
+            finalvarvals, finaldims = operdim(varvals, varsliceddims, dimsoper, operkind)
+
+            # Adding dimensions
+            idn = 0
+            for dn in finaldims:
+                if newNdim == 0:
+                    if not objnc.dimensions[dn].isunlimited:
+                        objnewnc.createDimension(dn, finalvarvals[idn])
+                    else:
+                        objnewnc.createDimension(dn, None)
+                    newNdim = newNdim + 1
+                else:
+                    if not gen.searchInlist(objnewnc, dn):
+                        if not objnc.dimensions[dn].isunlimited:
+                            objnewnc.createDimension(dn, finalvarvals[idn])
+                        else:
+                            objnewnc.createDimension(dn, None)
+                        newNdim = newNdim + 1
+                idn = idn + 1
+
+            # Adding variable
+            varinf = variable_inf(ov)
+            if varinf.FillValue is not None:
+                 newvar = objnewnc.createVariable(vn + oper, nctype(varinf.dtype),   \
+                   tuple(finaldims), fillValue=varinf.FillValue)
+            else:
+                 newvar = objnewnc.createVariable(vn + oper, nctype(varinf.dtype),   \
+                   tuple(finaldims))
+                newNvar = newNvar + 1
+
+# new variable
+            oldvarattr = ov.ncattrs()
+    
+            varname = gen.variables_values(vn)[0]
+            if gen.searchInlist(oldvarattr, 'standard_name'):
+                stdname = ov.getncattr('standard_name')
+            else:
+                stdname = gen.variables_values(vn)[1]
         
-
-
-
-    return
+            if gen.searchInlist(oldvarattr, 'long_name'):
+                lname = ov.getncattr('long_name')
+            else:
+                lname = gen.variables_values(vn)[4].replace('|',' ')
+
+            if gen.searchInlist(oldvarattr, 'units'):
+                uname = ov.getncattr('units')
+            else:
+                uname = gen.variables_values(vn)[5]
+    
+            newattr = basicvardef(newvar, stdname + operkind, lname + ' '+ operkind +\
+              ' along ' + dimsoperS, uname)
+
+            newvar[:] = newvarv
+            for idim in range(len(objvar.shape)):
+                if dimvals.find('|') != -1:
+                    dimn = dimvals.split('|')[idim].split(':')[0]
+                else:
+                    dimn = dimvals.split(':')[0]
+                dimv = '{:d}'.format(len(objnc.dimensions[dimn]))
+                if idim == 0:
+                    origdimsS = dimn + '(' + dimv + ')'
+                else:
+                    origdimsS = origdimsS + ' ' + dimn + '(' + dimv + ')'
+
+            newattr = set_attribute(newvar, 'orig_dimensions', origdimsS)
+    
+# global attributes
+    objnewnc.setncattr('author', 'L. Fita')
+    objnewnc.setncattr('institution', 'Laboratire de Meteorologie Dynamique')
+    objnewnc.setncattr('university', 'Pierre Marie Curie - Jussieu')
+    objnewnc.setncattr('center', 'Centre National de Recherches Scientifiques')
+    objnewnc.setncattr('city', 'Paris')
+    objnewnc.setncattr('country', 'France')
+    objnewnc.setncattr('script', 'nc_var_tools.py')
+    objnewnc.setncattr('function', 'file_oper_alongdims')
+    objnewnc.setncattr('version', '1.0')
+    objnewnc.setncattr('data_file', ncfile)
+
+    gorigattrs = objnc.ncattrs()
+    for attr in gorigattrs:
+        attrv = objnc.getncattr(attr)
+        atvar = set_attribute(objnewnc, attr, attrv)
+
+    objnc.close()
+
+    objnewnc.sync()
+    objnewnc.close()
+
+    print '  ' + fname + ': successful creation of file "' + ofile + '" !!!'
+
+    return 
+
+# LLUIS
 
 def file_oper_alongdims_old(values, ncfile, varn):
@@ -12861,4 +12998,7 @@
           [value] = int, a single value
           [value] = [beg, end, frq], from a beginning to an end with a given frequency
+      returning:
+        slicevals: list with the values of the slice
+        slicefinaldims: final dimensions of the slice (without monotonic dimensions)
     """
     fname = 'SliceVarDict'
@@ -12867,4 +13007,5 @@
 
     slicevals = []
+    slicefinaldims = []
     idim = 0
     for dim in ovar.dimensions:
@@ -12873,14 +13014,18 @@
             if type(dictv) == type([1]):
                 slicevals.append( slice(dictv[0], dictv[1], dictv[2]) )
+                slicefinaldims.append(dim)
             elif type(dictv) == type(int(1)):
                 if dictv == -1:
                     slicevals.append(slice(0,varshape[idim]))
+                    slicefinaldims.append(dim)
                 else
                     slicevals.append(dictv)
         else:
             slicevals.append(slice(0,varshape[idim]))
+            slicefinaldims.append(dim)
+
         idim = idim + 1
 
-    return slicevals
+    return slicevals, slicefinaldims
 
 def varDimension(oncf, dname):
