Index: trunk/tools/nc_var_tools.py
===================================================================
--- trunk/tools/nc_var_tools.py	(revision 2295)
+++ trunk/tools/nc_var_tools.py	(revision 2296)
@@ -27544,5 +27544,5 @@
     Ngridsin = Ngridsint.transpose()
     gridsin = gridsint.transpose()
-    percens = areast.transpose()
+    areas = areast.transpose()
     percens = percenst.transpose()
 
@@ -28289,5 +28289,5 @@
 
             gridsin = np.zeros((2,Ngridsinmax,1,Nslices), dtype=int)
-            areas = np.ones(tuple(varfinalshape), dtype=np.float)
+            areas = np.ones(tuple(varfinalshape), dtype=np.float)*gen.fillValueF
             percens = np.zeros((Ngridsinmax,1,Nslices), dtype=np.float)
             
@@ -28327,38 +28327,42 @@
                     gridsin[1,0:Nt,0,islc] = ainds[1,0:Nt]
                     percens[0:Nt,0,islc] = 1.
-
-                # Values for file
-                dxref = Nslices
-                dyref = 1
-                dxget = 1
-                dyget = 1
-
-                dref = ['fake', dn]
-                sref = [1, Nslices]
-                dget = ['fake']
-                sget = [1]
-                if not gen.searchInlist(onewnc.dimensions, 'fake'): 
-                    newdim = onewnc.createDimension('fake',1)
-                    newdim = onewnc.createDimension('slice_fake',1)
-                    newdim = onewnc.createDimension('fakebnds',4)
-                    newvar = onewnc.createVariable('fake','f',('fake'))
-                    newvar[:] = [0.]
-                    basicvardef(newvar, 'fake', 'fake variable for transforming ' +  \
-                      '1D variable without bounds', '-')
-                    newvar = onewnc.createVariable('slice_fake','f',('slice_fake'))
-                    newvar[:] = [0.]
-                    basicvardef(newvar, 'slice_fake', 'slicing along fake variable '+\
-                      'for transforming variable without bounds', '-')
-                    newvar = onewnc.createVariable('slice_fake_bnds','f',            \
-                      ('fakebnds','fake'))
-                    fakebnds = np.zeros((4,1), dtype=np.float)
-                    fakebnds[0,0] = -1
-                    fakebnds[1,0] = 1
-                    fakebnds[2,0] = 1
-                    fakebnds[3,0] = -1
-                    newvar[:] = fakebnds
-                    basicvardef(newvar, 'slice_fake', 'slicing along fake variable '+\
-                      'for transforming variable without bounds', '-')
-                    onewnc.sync()
+                    for iv in range(Nt):
+                        i = ainds[0,iv]
+                        j = ainds[1,iv]
+                        areas[j,i] = 1.
+
+            # Values for file
+            dxref = Nslices
+            dyref = 1
+            dxget = 1
+            dyget = 1
+
+            dref = ['fake', dn]
+            sref = [1, Nslices]
+            dget = ['fake']
+            sget = [1]
+            if not gen.searchInlist(onewnc.dimensions, 'fake'): 
+                newdim = onewnc.createDimension('fake',1)
+                newdim = onewnc.createDimension('slice_fake',1)
+                newdim = onewnc.createDimension('fakebnds',4)
+                newvar = onewnc.createVariable('fake','f',('fake'))
+                newvar[:] = [0.]
+                basicvardef(newvar, 'fake', 'fake variable for transforming ' +  \
+                  '1D variable without bounds', '-')
+                newvar = onewnc.createVariable('slice_fake','f',('slice_fake'))
+                newvar[:] = [0.]
+                basicvardef(newvar, 'slice_fake', 'slicing along fake variable '+\
+                  'for transforming variable without bounds', '-')
+                newvar = onewnc.createVariable('slice_fake_bnds','f',            \
+                  ('fakebnds','fake'))
+                fakebnds = np.zeros((4,1), dtype=np.float)
+                fakebnds[0,0] = -1
+                fakebnds[1,0] = 1
+                fakebnds[2,0] = 1
+                fakebnds[3,0] = -1
+                newvar[:] = fakebnds
+                basicvardef(newvar, 'slice_fake', 'slicing along fake variable '+\
+                  'for transforming variable without bounds', '-')
+                onewnc.sync()
 
         if not gen.searchInlist(newslcvarns,dn):
@@ -28395,5 +28399,5 @@
             newvar[:] = Ngridsin[:]
             basicvardef(newvar, dn+'Ngrid', "number of grids cells from " +          \
-              ".get. laying within .ref.", '-')
+              dn + " laying within slice", '-')
             newvar.setncattr('coordinates',' '.join(Scgrid[::-1]))
     
@@ -28401,10 +28405,11 @@
               fill_value=gen.fillValueI)
             basicvardef(innewvar, dn+'gridin', "coordinates of the grids " +         \
-              "cells from .get. laying within .ref.",'-')
+              "cells from " + dn + " laying within slice",'-')
             innewvar.setncattr('coordinates',' '.join(Scgrid[::-1]))
 
-            anewvar = onewnc.createVariable(dn+'gridarea','f',tuple(varfinaldims))
+            anewvar = onewnc.createVariable(dn+'gridarea','f',tuple(varfinaldims),   \
+              fill_value = gen.fillValueF)
             basicvardef(anewvar ,dn+'gridarea', "area of the grids cells from " +    \
-             ".get.", vu)
+             dn, vu)
             anewvar.setncattr('coordinates',' '.join(varfinaldims[::-1]))
             anewvar[:] = areas[:]
@@ -28418,6 +28423,7 @@
               fill_value=gen.fillValueF)
             basicvardef(pnewvar ,dn+'gridpercen', "percentages of the " +            \
-             "grids cells from .get. laying within .ref.", '1')
+             "grids cells from " + dn + " laying within slice", '1')
             pnewvar.setncattr('coordinates',' '.join(Scgrid[::-1]))
+            onewnc.sync()
 
             if len(dv.shape) == 1:
@@ -28445,5 +28451,6 @@
                         #apolygon[2,1] = refblat1D[j,0]
                         #apolygon[3,1] = refblat1D[j,0]
-                        #ap = np.abs(fsci.module_scientific.shoelace_area_polygon(nvertex=4, poly=apolygon))
+                        #ap = np.abs(fsci.module_scientific.shoelace_area_polygon(   \
+                        #  nvertex=4, poly=apolygon))
                         innewvar[:,0:Ngridsin[j,i],j,i] =                            \
                           gridsin[:,0:Ngridsin[j,i],j,i]
@@ -28458,20 +28465,14 @@
                             apolygon[:,1] = ydimvarbnds2D[:,iy,ix]
                             ag = np.abs(fsci.module_scientific.shoelace_area_polygon(nvertex=4, poly=apolygon))
-                            if varn == 'HGT':
-                                print 'Lluis ref dy:', dyref, 'dx:', dxref 
-                                print '  lluis iv:', iv, ':', iy, ix, '<>', apolygon[1:3,0],'x',apolygon[2:4,1],'ag:', ag, 'areas:', areas[iy,ix], 'percens:', percens[iv,j,i]
                             slicearea = slicearea + ag*percens[iv,j,i]
                             aa = aa + areas[iy,ix]
                             pp = pp + percens[iv,j,i]
                         aanewvar[j,i]= slicearea
-                        #print '  areas Lluis =', refblon1D[i,:], 'x', refblat1D[j,:], \
-                        #  'j i:', j,i, 'ap', ap, 'aanewvar:', slicearea, 'aa:', aa, 'pp:', pp
-                        if varn == 'HGT':
-                            print '  areas Lluis =', refblon1D[i,:], 'x', refblat1D[j,:], \
-                              'j i:', j,i, 'aanewvar:', slicearea, 'aa:', aa, 'pp:', pp
+                        # This should be true for the regular lon/lat projections
                         #if slicearea > ap: quit()
 
             onewnc.sync()
 
+    onewnc.sync()
     # Getting full slice
     # NOTE: for simplicity let's assume that there is only one slice with bounds !!
@@ -28495,6 +28496,8 @@
     sliceNA = osliceNA[:]
     sliceinA = osliceinA[:]
+    sliceaA = osliceaA[:]
     sliceNB = osliceNB[:]
     sliceinB = osliceinB[:]
+    sliceaB = osliceaB[:]
 
     dxA = osliceNA.shape[1]
@@ -28523,4 +28526,8 @@
 
     # Remembering that it is python (C-like...)
+    iA = 1
+    jA = 4
+    iB = 0
+    jB = 0
     inpointsA = inpointsA-1
     inpointsB = inpointsB-1
@@ -28545,4 +28552,10 @@
     innewvar.setncattr('coordinates',' '.join(Srgrid[::-1]))
 
+    aanewvar = onewnc.createVariable(dn+'area','f',tuple(Srgrid),                    \
+      fill_value=gen.fillValueF)
+    basicvardef(aanewvar ,dn+'area', "area of the join slice " + newslcvarns[0] +    \
+      " & " + newslcvarns[1], vu)
+    aanewvar.setncattr('coordinates',' '.join(Srgrid[::-1]))
+
     anewvar = onewnc.createVariable(dn+'gridarea','f',tuple(Srgrid),                 \
       fill_value=gen.fillValueF)
@@ -28551,9 +28564,8 @@
     anewvar.setncattr('coordinates',' '.join(Srgrid[::-1]))
 
-    print 'Lluis Spgrid:', Spgrid
     pnewvar = onewnc.createVariable(dn+'gridpercen','f',tuple(Spgrid),               \
       fill_value=gen.fillValueF)
     basicvardef(pnewvar ,dn+'gridpercen', "percentages of the " +                    \
-      "grids cells from .get. laying within .ref.", '1')
+      "grids cells from " + newslcvarns[0] + " laying within " + newslcvarns[1], '1')
     pnewvar.setncattr('coordinates',' '.join(Scgrid[::-1]))
 
@@ -28564,4 +28576,5 @@
                     Nin = NpointsAB[jB,iB,jA,iA]
                     innewvar[:,0:Nin,jB,iB,jA,iA] = pointsAB[:,0:Nin,jB,iB,jA,iA]
+                    slicearea = 0.
                     for iv in range(Nin):
                         pA = oslicepA[inpointsA[iv,jA,iA],jA,iA]
@@ -28574,5 +28587,9 @@
                         iyB = sliceinB[0,inpointsB[iv,jB,iB],jB,iB]
                         aB = osliceaB[iyB,ixB]
-                        anewvar[jB,iB,jA,iA]= (aA*pA)*(aB*pB)
+                        # I do not understand why this is needed !!
+                        if aA != gen.mamat[1] and aB != gen.mamat[1]: 
+                            anewvar[jB,iB,jA,iA]= (aA*pA)*(aB*pB)
+                            slicearea = slicearea + (aA*pA)*(aB*pB)
+                        aanewvar[jB,iB,jA,iA]= slicearea
 
     onewnc.sync()
