Index: /trunk/tools/nc_var_tools.py
===================================================================
--- /trunk/tools/nc_var_tools.py	(revision 281)
+++ /trunk/tools/nc_var_tools.py	(revision 282)
@@ -10371,4 +10371,6 @@
     trajvals = np.zeros((Ttraj,3), dtype=np.float)
 
+    it = 0
+    iline = 0
     for line in trajobj:
 
@@ -10495,9 +10497,8 @@
                 cyrangeslice2D.append([gtrajvals[it,2]-Nrad, gtrajvals[it,2]+Nrad + 1])
                 cxrangeslice2D.append([gtrajvals[it,1]-Nrad, gtrajvals[it,1]+Nrad + 1])
-
-        iline = iline + 1
+            it = it + 1
+            iline = iline + 1
 
     trajobj.close()
-
 # Creation of the netCDF file
 ##
@@ -10783,5 +10784,7 @@
             rstatvarvals = np.ones(tuple([Ttraj,6]), dtype=np.float)
 
-            for it in range(dimt):
+            for it0 in range(Ttraj):
+                it = Tbeg + it0
+
                 slicev = []
                 slice2D = []
@@ -10795,18 +10798,15 @@
                   or gtrajvals[it,1]-box2 < 0 or gtrajvals[it,1]+box2 + 1 > dimx + 1:
 # box values
-                    slicev.append(slice(yrangeslice[0][it],yrangeslice[1][it]))
-                    slicev.append(slice(xrangeslice[0][it],xrangeslice[1][it]))
-
-                    slicevnoT.append(slice(yrangeslice[0][it],yrangeslice[1][it]))
-                    slicevnoT.append(slice(xrangeslice[0][it],xrangeslice[1][it]))
-
-                    slice2D.append(slice(yrangeslice2D[0][it],yrangeslice2D[1][it]))
-                    slice2D.append(slice(xrangeslice2D[0][it],xrangeslice2D[1][it]))
+                    slicev.append(slice(yrangeslice[it][0],yrangeslice[it][1]))
+                    slicev.append(slice(xrangeslice[it][0],xrangeslice[it][1]))
+
+                    slicevnoT.append(slice(yrangeslice[it][0],yrangeslice[it][1]))
+                    slicevnoT.append(slice(xrangeslice[it][0],xrangeslice[it][1]))
+
+                    slice2D.append(slice(0,yrangeslice[it][1]-yrangeslice[it][0]))
+                    slice2D.append(slice(0,xrangeslice[it][1]-xrangeslice[it][0]))
 
                     rvarvalst = np.ones((Nrad*2+1, Nrad*2+1),dtype=np.float)*fillValue
 
-                    print it,'Lluis: shapes yrangeslice2D:',yrangeslice2D[it],'xrangeslice:',xrangeslice[it]
-                    print it,'Lluis: shapes slice2D:',slice2D,'slicev:',slicev
-                    print it,'Lluis: shapes varvalst:',varvalst.shape,'varobj:',varobj.shape
                     varvalst[tuple(slice2D)] = varobj[tuple(slicev)]
                     varvals[it,:,:] = varvalst
@@ -10841,5 +10841,4 @@
                       1))
 
-                    print 'Lluis: shapes obj:',varobj.shape,'slice:',slicev
                     varvalst = varobj[tuple(slicev)]
 # box values
@@ -10867,12 +10866,12 @@
                 if gtrajvals[it,2]-Nrad < 0 or gtrajvals[it,2]+Nrad + 1 > dimy + 1   \
                   or gtrajvals[it,1]-Nrad < 0 or gtrajvals[it,1]+Nrad + 1 > dimx + 1:
-                    cslicev.append(slice(cyrangeslice[it]))
-                    cslicev.append(slice(cxrangeslice[it]))
-
-                    cslicevnoT.append(slice(cyrangeslice[it]))
-                    cslicevnoT.append(slice(cxrangeslice[it]))
-
-                    cslice2D.append(slice(cyrangeslice2D[it]))
-                    cslice2D.append(slice(cxrangeslice2D[it]))
+                    cslicev.append(slice(cyrangeslice[it][0],cyrangeslice[it][1]))
+                    cslicev.append(slice(cxrangeslice[it][0],cxrangeslice[it][1]))
+
+                    cslicevnoT.append(slice(cyrangeslice[it][0],cyrangeslice[it][1]))
+                    cslicevnoT.append(slice(cxrangeslice[it][0],cxrangeslice[it][1]))
+
+                    cslice2D.append(slice(0,cyrangeslice[it][1]-cyrangeslice[it][0]))
+                    cslice2D.append(slice(0,cxrangeslice[it][1]-cxrangeslice[it][0]))
 
                     rvarvalst = np.ones((Nrad*2+1,Nrad*2+1),dtype=np.float)*fillValue
@@ -10910,6 +10909,4 @@
                     rvarvalst = np.where(cdist > np.float(Nrad),fillValue,rvarvalst)
 
-
-                    print 'Lluis shapes: rvarvals:',rvarvals[it,:,:].shape,'rvarvalst:',rvarvalst.shape
                     rvarvals[it,:,:] = rvarvalst
 
@@ -10996,5 +10993,5 @@
                 ist = ist + 1
 
-        if not objofile.has_key('trlon') and Nvardims == 3:
+        if not objofile.variables.has_key('trlon') and Nvardims == 3:
 # var dimensions
             newvar = objofile.createVariable('trlon', 'f8', ('time'))
