Index: trunk/tools/nc_var_tools.py
===================================================================
--- trunk/tools/nc_var_tools.py	(revision 315)
+++ trunk/tools/nc_var_tools.py	(revision 316)
@@ -11969,5 +11969,5 @@
           dimensions of the resultant operation
       ncfile= netCDF file
-      varn= variable name
+      varn= ',' list of variable names ('all' for all)
     """
 
@@ -11984,20 +11984,20 @@
     dimvn = values.split(',')[3]
 
+    objnc = NetCDFFile(ncfile, 'r')
+
+    if varn.find(',') != -1:
+        if varn == 'all':
+            varns = objnc.variables
+        else:
+            varns = varn.split(',')
+    else:
+        varns = [varn]
+   
     ofile = 'file_oper_alongdims_' + operkind + '.nc'
 
-    objnc = NetCDFFile(ncfile, 'r')
-
-    if not objnc.variables.has_key(varn):
-        print errormsg
-        print '  ' + fname + ': netCDF file "' + ncfile +                            \
-          '" does not have variable "' + varn + '" !!!!'
-        quit(-1)
-
-    objvar = objnc.variables[varn]
-
-    newvarv, newvardimns = operation_alongdims(objvar,dimvals,dimsoper,operkind)
-
-    print 'dimsoper:',dimsoper
-    print 'newvar shape',newvarv.shape,'newvardims:',newvardimns
+    if dimsoper.find(':') != -1:
+        dimstouse = dimsoper.split(':')
+    else:
+        dimstouse = [dimsoper]
 
 # Creation of output file
@@ -12006,73 +12006,105 @@
     objnewnc = NetCDFFile(ofile, 'w')
 
+    print '  ' + fname + ": '" + operkind + "' with:",dimsoper,'_______'
+    for vn in varns:
+        print "'" + vn + "' ... .. ."
+
+        if not objnc.variables.has_key(vn):
+            print errormsg
+            print '  ' + fname + ': netCDF file "' + ncfile +                        \
+              '" does not have variable "' + vn + '" !!!!'
+            quit(-1)
+
+# Variable
+        objvar = objnc.variables[vn]
+
+        allfound = True
+        for idimt in dimstouse:
+            if not searchInlist(objvar.dimensions, idimt):
+                allfound = False
+                break
+
+        if not allfound:
+            print warnmsg
+            print '  ' + fname + ": variable '" + vn + "' (", objvar.dimensions,     \
+              ') does not have all the equired dimensions:', dimstouse, '!!'
+            print '    skipping it'
+            
+        else:
+            newvarv, newvardimns=operation_alongdims(objvar,dimvals,dimsoper,operkind)
+
 # Dimensions
-    for idim in range(len(newvardimns)):
-        objdim = objnc.dimensions[newvardimns[idim]]
-        if objdim.isunlimited():
-            objnewnc.createDimension(newvardimns[idim], None)
-        else:
-            objnewnc.createDimension(newvardimns[idim], len(objdim))
+            for idim in range(len(newvardimns)):
+                objdim = objnc.dimensions[newvardimns[idim]]
+                if not objnewnc.dimensions.has_key(newvardimns[idim]):
+                    if objdim.isunlimited():
+                        objnewnc.createDimension(newvardimns[idim], None)
+                    else:
+                        objnewnc.createDimension(newvardimns[idim], len(objdim))
 
 # Variables with dimension values
-    vardims = dimvn.split(':')
-    for ivdim in range(len(vardims)):
-        objvdim = objnc.variables[vardims[ivdim]]
-        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: dimvslice.append(len(objnc.dimensions[dimsvdim[idmvd]])/2)
-
-        newvar = objnewnc.createVariable(vardims[ivdim], 'f8', tuple(dimvdims))
-        newvar[:] = objvdim[tuple(dimvslice)]
-        dimvattrs = objvdim.ncattrs()
-        for attrn in dimvattrs:
-            attrv = objvdim.getncattr(attrn)
-            newattr = set_attribute(newvar,attrn,attrv)
+            vardims = dimvn.split(':')
+            for ivdim in range(len(vardims)):
+                if not objnewnc.variables.has_key(vardims[ivdim]):
+                    objvdim = objnc.variables[vardims[ivdim]]
+                    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: 
+                            dimvslice.append(len(objnc.dimensions[dimsvdim[idmvd]])/2)
+    
+                    newvar = objnewnc.createVariable(vardims[ivdim], 'f8', 
+                      tuple(dimvdims))
+                    newvar[:] = objvdim[tuple(dimvslice)]
+                    dimvattrs = objvdim.ncattrs()
+                    for attrn in dimvattrs:
+                        attrv = objvdim.getncattr(attrn)
+                        newattr = set_attribute(newvar,attrn,attrv)
 
 # new variable
-    oldvarattr = objvar.ncattrs()
-
-    varname = variables_values(varn)[0]
-    if searchInlist(oldvarattr, 'standard_name'):
-        stdname = objvar.getncattr('standard_name')
-    else:
-        stdname = variables_values(varn)[1]
-
-    if searchInlist(oldvarattr, 'long_name'):
-        lname = objvar.getncattr('long_name')
-    else:
-        lname = variables_values(varn)[4].replace('|',' ')
-
-    if searchInlist(oldvarattr, 'units'):
-        uname = objvar.getncattr('units')
-    else:
-        uname = variables_values(varn)[5]
-
-    dimsoperS = numVector_String(dimsoper.split(':'),', ')
-
-    newvar = objnewnc.createVariable(varname + operkind, 'f4', tuple(newvardimns))
-    newattr = basicvardef(newvar, stdname + operkind, lname + ' '+  operkind +       \
-      ' along ' + dimsoperS, uname)
-
-    newvar[:] = newvarv
-    for idim in range(len(objvar.shape)):
-        dimn = dimvals.split('|')[idim].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)
-
+            oldvarattr = objvar.ncattrs()
+    
+            varname = variables_values(vn)[0]
+            if searchInlist(oldvarattr, 'standard_name'):
+                stdname = objvar.getncattr('standard_name')
+            else:
+                stdname = variables_values(vn)[1]
+        
+            if searchInlist(oldvarattr, 'long_name'):
+                lname = objvar.getncattr('long_name')
+            else:
+                lname = variables_values(vn)[4].replace('|',' ')
+
+            if searchInlist(oldvarattr, 'units'):
+                uname = objvar.getncattr('units')
+            else:
+                uname = variables_values(vn)[5]
+
+            dimsoperS = numVector_String(dimsoper.split(':'),', ')
+    
+            newvar = objnewnc.createVariable(varname + operkind, 'f4', 
+              tuple(newvardimns))
+            newattr = basicvardef(newvar, stdname + operkind, lname + ' '+ operkind +\
+              ' along ' + dimsoperS, uname)
+
+            newvar[:] = newvarv
+            for idim in range(len(objvar.shape)):
+                dimn = dimvals.split('|')[idim].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')
@@ -12100,4 +12132,7 @@
 
     return 
+
+#file_oper_alongdims('Time:-1|bottom_top:-1|south_north:-1|west_east:-1,bottom_top,sum,Times:XLAT:XLONG', 
+#  '/home/lluis/PY/wrfout_d01_2001-11-11_00:00:00.tests', 'QVAPOR')
 
 #file_oper_alongdims('time:-1|z:-1|x:-1|y:-1,time:y,mean,pressure:lat', '/home/lluis/etudes/WRF_LMDZ/WaquaL/WRF_LMDZ/AR40/vertical_interpolation_WRFp.nc', 'WRFt')
