Index: trunk/tools/nc_var_tools.py
===================================================================
--- trunk/tools/nc_var_tools.py	(revision 285)
+++ trunk/tools/nc_var_tools.py	(revision 286)
@@ -10539,4 +10539,34 @@
 # Too optimistic, but at this stage...
             dimz = varobj.shape[1]
+
+            if not objofile.dimensions.has_key('z'):
+                varzobj = objfile.variables[zn]
+                if len(varzobj.shape) == 1:
+                    dimz = varzobj.shape
+                    zvals = varzobj[:]
+                elif len(varzobj.shape) == 2:
+                    dimz = varzobj.shape[1]
+                    zvals = varzobj[0,:]
+                elif len(varzobj.shape) == 3:
+                    dimz = varzobj.shape[2]
+                    zvals = varzobj[0,0,:]
+
+                objofile.createDimension('z', dimz)
+                newvar = objofile.createVariable(zn, 'f4', ('z'),fill_value=fillValue)
+                if searchInlist(varzobj.ncattrs(),'standard_name'):
+                    vsname = varzobj.getncattr('standard_name')
+                else:
+                    vsname = variables_values(varn)[1]
+                if searchInlist(varzobj.ncattrs(),'long_name'):
+                    vlname = varzobj.getncattr('long_name')
+                else:
+                    vlname = variables_values(varn)[4].replace('|',' ')
+                if searchInlist(varzobj.ncattrs(),'units'):
+                    vunits = varzobj.getncattr('units')
+                else:
+                    vunits = variables_values(varn)[5].replace('|',' ')
+    
+                newattr = basicvardef(newvar, vsname, vlname, vunits)
+                newvar[:] = zvals
  
             varvals = np.ones(tuple([Ttraj,dimz,boxs,boxs]), dtype=np.float)
@@ -10558,5 +10588,7 @@
                 cslicev = []
                 cslice2D = []
+                cslice2Dhor = []
                 cslicevnoT = []
+                cslicevnoThor = []
 
                 slicev.append(gtrajvals[it,0])
@@ -10641,10 +10673,16 @@
                     cslice2D.append(slice(0,cyrangeslice[it][1]-cyrangeslice[it][0]))
                     cslice2D.append(slice(0,cxrangeslice[it][1]-cxrangeslice[it][0]))
+                    cslice2Dhor.append(slice(0, cyrangeslice[it][1] -                \
+                      cyrangeslice[it][0]))
+                    cslice2Dhor.append(slice(0, cxrangeslice[it][1] -                \
+                      cxrangeslice[it][0]))
 
                     rvarvalst = np.ones((dimz,Nrad*2+1,Nrad*2+1),dtype=np.float)*    \
                       fillValue
                     rvarvalst[tuple(cslice2D)] = varobj[tuple(cslicev)]
-                    rvarvalst[tuple(cslice2D)] = np.where(circdist[tuple(cslice2D)]>\
-                      np.float(Nrad), fillValue, rvarvalst[tuple(cslice2D)])
+                    for iz in range(dimz):
+                        zslice = [slice(iz)]+cslice2Dhor
+                        rvarvalst[iz,:,:] = np.where(circdist[tuple(cslice2Dhor)] >  \
+                          np.float(Nrad), fillValue, rvarvalst[iz,:,:]) 
 
                     rvarvals[it,:,:,:] = rvarvalst
@@ -10663,13 +10701,17 @@
 
                 else:
-                    cslicev.append(0,dimz)
+                    cslicev.append(slice(0,dimz))
                     cslicev.append(slice(gtrajvals[it,2]-Nrad,gtrajvals[it,2]+Nrad+1))
                     cslicev.append(slice(gtrajvals[it,1]-Nrad,gtrajvals[it,1]+Nrad+1))
-                    cslicevnoT.append(0,dimz)
+                    cslicevnoT.append(slice(0,dimz))
                     cslicevnoT.append(slice(gtrajvals[it,2]-Nrad, gtrajvals[it,2]+   \
                       Nrad+1))
                     cslicevnoT.append(slice(gtrajvals[it,1]-Nrad, gtrajvals[it,1]+   \
                       Nrad+1))
-                    cslice2D.append(0,dimz)
+                    cslicevnoThor.append(slice(gtrajvals[it,2]-Nrad, gtrajvals[it,2]+   \
+                      Nrad+1))
+                    cslicevnoThor.append(slice(gtrajvals[it,1]-Nrad, gtrajvals[it,1]+   \
+                      Nrad+1))
+                    cslice2D.append(slice(0,dimz))
                     cslice2D.append(slice(gtrajvals[it,2]-Nrad,gtrajvals[it,2]+Nrad+ \
                       1))
@@ -10678,7 +10720,10 @@
 
                     rvarvalst = varobj[tuple(cslicev)]
-                    cdist = circdist[tuple(cslicevnoT)]
+                    cdist = circdist[tuple(cslicevnoThor)]
 # circle values
-                    rvarvalst = np.where(cdist > np.float(Nrad),fillValue,rvarvalst)
+                    for iz in range(dimz):
+                        zslice = [slice(iz)]+cslicevnoThor
+                        rvarvalst[iz,:,:] = np.where(circdist[tuple(cslicevnoThor)] >\
+                          np.float(Nrad), fillValue, rvarvalst[iz,:,:]) 
 
                     rvarvals[it,:,:,:] = rvarvalst
@@ -10694,5 +10739,5 @@
                         rstatvarvals[it,iz,4] = maskedvals2[iz,:,:].mean()
                         rstatvarvals[it,iz,5] = np.sqrt(rstatvarvals[it,iz,4] -      \
-                          rstatvarvals[it,iz,3]*rstatvarvals[it,:,3])
+                          rstatvarvals[it,iz,3]*rstatvarvals[it,iz,3])
 
 #            print 'statistics:',rstatvarvals[it,:] 
