Index: trunk/tools/nc_var_tools.py
===================================================================
--- trunk/tools/nc_var_tools.py	(revision 875)
+++ trunk/tools/nc_var_tools.py	(revision 876)
@@ -8975,47 +8975,32 @@
 # Variables with dimension values
             vardims = dimvn.split(':')
-            for ivdim in range(len(vardims)):
-                if not objnewnc.variables.has_key(vardims[ivdim]):
-                    objvdim = objnc.variables[vardims[ivdim]]
+            Nvardims = len(vardims)
+            for ivd in range(Nvardims):
+                if not objnewnc.variables.has_key(vardims[ivd]):
+                    objvdim = objnc.variables[vardims[ivd]]
+                    coinvardims = objvdim.dimensions
+
+                    # Introducing only that variable dimensions with coincident dims
+                    toadd = False
+                    for vdn in coinvardims:
+                        if gen.searchInlist(newvardimns, vdn): toadd = True
+
                     vdimtype = objvdim.dtype
-                    newdimvarv, newdimvardimns=operation_alongdims(objvdim,dimvals,dimsoper,operkind)
+                    if toadd:
+                        newdvarv, newdvards=operation_alongdims(objvdim,dimvals,     \
+                          dimsoper,operkind)
 
 # Introducing only that dimension variables with any dimension after the operation
-                    if len(newdimvardimns) > 0:
-
-# Old method introducing new dimension if needed
-##                    dimsvdim = objvdim.dimensions
-##                    dimvslice = []
-##                    dimvdims = []
-##                    for idmvd in range(len(dimsvdim)):
-##                        found = False
-##                        for idimv in range(len(newvardimns)):
-##                            if dimsvdim[idmvd] == newvardimns[idimv]:
-##                                dimvslice.append(slice(0,objvdim.shape[idmvd]))
-##                                dimvdims.append(dimsvdim[idmvd])
-##                                found = True
-##                                break
-##                        if not found: 
-##                            print warnmsg
-##                            print '  ' + fname + ": dimension '" + dimsvdim[idmvd] + \
-##                              "' not found !!"
-##                            print "    adding it for variable dimension: '" +         \
-##                              vardims[ivdim] + "'"
-##                            if not objnewnc.dimensions.has_key(dimsvdim[idmvd]):
-##                                dsize = len(objnc.dimensions[dimsvdim[idmvd]])
-##                                objnewnc.createDimension(dimsvdim[idmvd], dsize)
-##                            dimvslice.append(slice(len(objnc.dimensions[dimsvdim[idmvd]])))
-##                            dimvdims.append(dimsvdim[idmvd])
-
-                        newvar = objnewnc.createVariable(vardims[ivdim], vdimtype,   \
-                          tuple(newdimvardimns))
-                        newvar[:] = newdimvarv
-                        dimvattrs = objvdim.ncattrs()
-                        for attrn in dimvattrs:
-                            attrv = objvdim.getncattr(attrn)
-                            newattr = set_attribute(newvar,attrn,attrv)
-
-                        newattr = set_attribute(newvar, 'operation:',  operkind +    \
-                          ' along ' + dimsoperS)
+                        if len(newdvards) > 0:
+                            newvar = objnewnc.createVariable(vardims[ivd],           \
+                              vdimtype, tuple(newdvards))
+                            newvar[:] = newdvarv
+                            dimvattrs = objvdim.ncattrs()
+                            for attrn in dimvattrs:
+                                attrv = objvdim.getncattr(attrn)
+                                newattr = set_attribute(newvar,attrn,attrv)
+
+                            newattr = set_attribute(newvar, 'operation', operkind +  \
+                              ' along ' + dimsoperS)
 
 # new variable
