Index: /trunk/tools/nc_var_tools.py
===================================================================
--- /trunk/tools/nc_var_tools.py	(revision 751)
+++ /trunk/tools/nc_var_tools.py	(revision 752)
@@ -12198,14 +12198,19 @@
             longvarname = 'using inverse of variable ' + varname + ' as space weights'
             if len(loopshape) == 1:
-                newvals = np.ones((loopshape[0]), dtype=np.float)*fillValueF
+                newvals = np.ones((loopshape[0]), dtype=np.float)*gen.fillValueF
+                newsumvals = np.ones((loopshape[0]), dtype=np.float)*gen.fillValueF
                 for id1 in range(loopshape[0]):
                     slicevalues = SliceVar(iovar,dimsloop,[id1])
                     slicewgt = SliceVar(iovarwgt,dimsloop,[id1])
                     TOTsumwgt = np.sum(1./ivarwgtv[tuple(slicewgt)])
+                    newsumvals[id1] = np.sum(ivarv[tuple(slicevalues)] /             \
+                      ivarwgtv[tuple(slicewgt)])
                     newvals[id1] = np.sum(ivarv[tuple(slicevalues)] /                \
                       ivarwgtv[tuple(slicewgt)]) / TOTsumwgt
             elif len(loopshape) == 2:
                 newvals = np.ones((loopshape[0],loopshape[1]),dtype=np.float)*       \
-                  fillValueF
+                  gen.fillValueF
+                newsumvals = np.ones((loopshape[0],loopshape[1]),dtype=np.float)*    \
+                  gen.fillValueF
                 for id1 in range(loopshape[0]):
                     for id2 in range(loopshape[1]):
@@ -12213,9 +12218,13 @@
                         slicewgt = SliceVar(iovarwgt,dimsloop,[id1,id2])
                         TOTsumwgt = np.sum(1./ivarwgtv[tuple(slicewgt)])
+                        newsumvals[id1,id2] = np.sum(ivarv[tuple(slicevalues)] /     \
+                          ivarwgtv[tuple(slicewgt)])
                         newvals[id1,id2] = np.sum(ivarv[tuple(slicevalues)] /        \
                           ivarwgtv[tuple(slicewgt)]) / TOTsumwgt
             elif len(loopshape) == 3:
                 newvals = np.ones((loopshape[0],loopshape[1],loopshape[2]),          \
-                  dtype=np.float)*fillValueF
+                  dtype=np.float)*gen.fillValueF
+                newsumvals = np.ones((loopshape[0],loopshape[1],loopshape[2]),       \
+                  dtype=np.float)*gen.fillValueF
                 for id1 in range(loopshape[0]):
                     for id2 in range(loopshape[1]):
@@ -12224,4 +12233,6 @@
                             slicewgt = SliceVar(iovarwgt,dimsloop,[id1,id2,id3])
                             TOTsumwgt = np.sum(1./ivarwgtv[tuple(slicewgt)])
+                            newsumvals[id1,id2,id3]=np.sum(ivarv[tuple(slicevalues)]/\
+                              ivarwgtv[tuple(slicewgt)])
                             newvals[id1,id2,id3]= np.sum(ivarv[tuple(slicevalues)]/  \
                               ivarwgtv[tuple(slicewgt)]) / TOTsumwgt
@@ -12230,14 +12241,19 @@
             longvarname = 'using variable ' + varname + ' as space weights'
             if len(loopshape) == 1:
-                newvals = np.ones((loopshape[0]), dtype=np.float)*fillValueF
+                newvals = np.ones((loopshape[0]), dtype=np.float)*gen.fillValueF
+                newsumvals = np.ones((loopshape[0]), dtype=np.float)*gen.fillValueF
                 for id1 in range(loopshape[0]):
                     slicevalues = SliceVar(iovar,dimsloop,[id1])
                     slicewgt = SliceVar(iovarwgt,dimsloop,[id1])
                     TOTsumwgt = np.sum(ivarwgtv[tuple(slicewgt)])
+                    newsumvals[id1] = np.sum(ivarv[tuple(slicevalues)]*              \
+                      ivarwgtv[tuple(slicewgt)])
                     newvals[id1] = np.sum(ivarv[tuple(slicevalues)]*                 \
                       ivarwgtv[tuple(slicewgt)]) / TOTsumwgt
             elif len(loopshape) == 2:
                 newvals = np.ones((loopshape[0],loopshape[1]), dtype=np.float)*      \
-                  fillValueF
+                  gen.fillValueF
+                newsumvals = np.ones((loopshape[0],loopshape[1]), dtype=np.float)*   \
+                  gen.fillValueF
                 for id1 in range(loopshape[0]):
                     for id2 in range(loopshape[1]):
@@ -12245,9 +12261,13 @@
                         slicewgt = SliceVar(iovarwgt,dimsloop,[id1,id2])
                         TOTsumwgt = np.sum(ivarwgtv[tuple(slicewgt)])
+                        newsumvals[id1,id2] = np.sum(ivarv[tuple(slicevalues)]*      \
+                          ivarwgtv[tuple(slicewgt)])
                         newvals[id1,id2] = np.sum(ivarv[tuple(slicevalues)]*         \
                           ivarwgtv[tuple(slicewgt)]) / TOTsumwgt
             elif len(loopshape) == 3:
                 newvals = np.ones((loopshape[0],loopshape[1],loopshape[2]),          \
-                  dtype=np.float)*fillValueF
+                  dtype=np.float)*gen.fillValueF
+                newsumvals = np.ones((loopshape[0],loopshape[1],loopshape[2]),       \
+                  dtype=np.float)*gen.fillValueF
                 for id1 in range(loopshape[0]):
                     for id2 in range(loopshape[1]):
@@ -12256,4 +12276,6 @@
                             slicewgt = SliceVar(iovarwgt,dimsloop,[id1,id2,id3])
                             TOTsumwgt = np.sum(ivarwgtv[tuple(slicewgt)])
+                            newsumvals[id1,id2,id3]=np.sum(ivarv[tuple(slicevalues)]*\
+                              ivarwgtv[tuple(slicewgt)])
                             newvals[id1,id2,id3]=np.sum(ivarv[tuple(slicevalues)]*   \
                               ivarwgtv[tuple(slicewgt)]) / TOTsumwgt
@@ -12264,12 +12286,17 @@
             if len(loopshape) == 1:
                 newvals = np.ones((loopshape[0]), dtype=np.float)*gen.fillValueF
+                newsumvals = np.ones((loopshape[0]), dtype=np.float)*gen.fillValueF
                 for id1 in range(loopshape[0]):
                     slicevalues = SliceVar(iovar,dimsloop,[id1])
                     slicewgt = SliceVar(iovarwgt1,dimsloop,[id1])
                     TOTsumwgt = np.sum(1./ivarwgtv[tuple(slicewgt)])
+                    newsumvals[id1] = np.sum(ivarv[tuple(slicevalues)] /             \
+                      ivarwgtv[tuple(slicewgt)])
                     newvals[id1] = np.sum(ivarv[tuple(slicevalues)] /                \
                       ivarwgtv[tuple(slicewgt)]) / TOTsumwgt
             elif len(loopshape) == 2:
                 newvals = np.ones((loopshape[0],loopshape[1]),dtype=np.float)*       \
+                  gen.fillValueF
+                newsumvals = np.ones((loopshape[0],loopshape[1]),dtype=np.float)*    \
                   gen.fillValueF
                 for id1 in range(loopshape[0]):
@@ -12278,8 +12305,12 @@
                         slicewgt = SliceVar(iovarwgt,dimsloop,[id1,id2])
                         TOTsumwgt = np.sum(1./ivarwgtv[tuple(slicewgt)])
+                        newsumvals[id1,id2] = np.sum(ivarv[tuple(slicevalues)] /     \
+                          ivarwgtv[tuple(slicewgt)])
                         newvals[id1,id2] = np.sum(ivarv[tuple(slicevalues)] /        \
                           ivarwgtv[tuple(slicewgt)]) / TOTsumwgt
             elif len(loopshape) == 3:
                 newvals = np.ones((loopshape[0],loopshape[1],loopshape[2]),          \
+                  dtype=np.float)*gen.fillValueF
+                newsumvals = np.ones((loopshape[0],loopshape[1],loopshape[2]),       \
                   dtype=np.float)*gen.fillValueF
                 for id1 in range(loopshape[0]):
@@ -12289,4 +12320,6 @@
                             slicewgt = SliceVar(iovarwgt,dimsloop,[id1,id2,id3])
                             TOTsumwgt = np.sum(1./ivarwgtv[tuple(slicewgt)])
+                            newsumvals[id1,id2,id3]=np.sum(ivarv[tuple(slicevalues)]/\
+                              ivarwgtv[tuple(slicewgt)])
                             newvals[id1,id2,id3]= np.sum(ivarv[tuple(slicevalues)]/  \
                               ivarwgtv[tuple(slicewgt)]) / TOTsumwgt
@@ -12315,8 +12348,7 @@
         TOTsumwgt = np.sum(ivarwgtv)
 
-        print 'Lluis len(looopshape):', len(loopshape)
         if len(loopshape) == 1:
-            newvals = np.ones((loopshape[0]), dtype=np.float)*fillValueF
-            newsumvals = np.ones((loopshape[0]), dtype=np.float)*fillValueF
+            newvals = np.ones((loopshape[0]), dtype=np.float)*gen.fillValueF
+            newsumvals = np.ones((loopshape[0]), dtype=np.float)*gen.fillValueF
             for id1 in range(loopshape[0]):
                 slicevalues = SliceVar(iovar,dimsloop,[id1])
@@ -12327,6 +12359,8 @@
                 newvals[id1] = newsumvals[id1]/TOTsumwgt
         elif len(loopshape) == 2:
-            newvals = np.ones((loopshape[0],loopshape[1]), dtype=np.float)*fillValueF
-            newsumvals = np.ones((loopshape[0],loopshape[1]), dtype=np.float)*fillValueF
+            newvals = np.ones((loopshape[0],loopshape[1]),                           \
+              dtype=np.float)*gen.fillValueF
+            newsumvals = np.ones((loopshape[0],loopshape[1]),                        \
+              dtype=np.float)*gen.fillValueF
             for id1 in range(loopshape[0]):
                 for id2 in range(loopshape[1]):
@@ -12339,7 +12373,7 @@
         elif len(loopshape) == 3:
             newvals = np.ones((loopshape[0],loopshape[1],loopshape[2]),              \
-              dtype=np.float)*fillValueF
+              dtype=np.float)*gen.fillValueF
             newsumvals = np.ones((loopshape[0],loopshape[1],loopshape[2]),           \
-              dtype=np.float)*fillValueF
+              dtype=np.float)*gen.fillValueF
             for id1 in range(loopshape[0]):
                 for id2 in range(loopshape[1]):
