Index: trunk/tools/nc_var_tools.py
===================================================================
--- trunk/tools/nc_var_tools.py	(revision 307)
+++ trunk/tools/nc_var_tools.py	(revision 308)
@@ -2647,47 +2647,54 @@
             self.attributes = attvar
             if not searchInlist(attvar, 'units'):
-                print errormsg
-                print '    cls_time_information: time variable "', tname, '" does not have attribute: "units"'
-                quit(-1)
+                print warnmsg
+                print '    cls_time_information: time variable "', tname,            \
+                  '" does not have attribute: "units"'
+                units = None
             else:
                 units = times.getncattr('units')
 
-            self.unitsval = units
-
-            if not searchInlist(attvar, 'calendar'):
-                print warnmsg
-                print '    cls_time_information: time variable "', tname, '" does not have attribute: "calendar"'
-                self.calendar = '-'
-            else:
-                self.calendar = times.getncattr('calendar')
+                self.unitsval = units
+
+                if not searchInlist(attvar, 'calendar'):
+                    print warnmsg
+                    print '    cls_time_information: time variable "', tname,            \
+                      '" does not have attribute: "calendar"'
+                    self.calendar = '-'
+                else:
+                    self.calendar = times.getncattr('calendar')
   
-            txtunits = units.split(' ')
-            self.units = txtunits[0]
-            Srefdate = txtunits[len(txtunits) - 1]
+                txtunits = units.split(' ')
+                self.units = txtunits[0]
+                Srefdate = txtunits[len(txtunits) - 1]
 # Does reference date contain a time value [YYYY]-[MM]-[DD] [HH]:[MI]:[SS]
 ##
-            timeval = Srefdate.find(':')
-
-            if not timeval == -1:
+                timeval = Srefdate.find(':')
+
+                if not timeval == -1:
 #        print '  refdate with time!'
-                self.refdate = datetimeStr_datetime(txtunits[len(txtunits) - 2] + '_' + Srefdate)
-                self.Urefdate = txtunits[len(txtunits) - 2] + ' ' + Srefdate
-            else:
-                self.refdate = datetimeStr_datetime(Srefdate + '_00:00:00')
-                self.Urefdate = Srefdate
-
-            self.Srefdate = self.refdate.strftime("%Y%m%d%H%M%S")
-            timev = times[:]
-
-            self.dimt = times.shape[0]
-            self.dt = timev[1]-timev[0]
-            self.firstTu = timev[0]
-            self.firstTt = timeref_datetime(self.refdate, self.firstTu, self.units)
-            self.firstTS = self.firstTt.strftime("%Y%m%d%H%M%S")
-            self.firstTm = timeref_datetime_mat(self.refdate, self.firstTu, self.units)
-            self.lastTu = timev[self.dimt-1]
-            self.lastTt = timeref_datetime(self.refdate, self.lastTu, self.units)
-            self.lastTS = self.lastTt.strftime("%Y%m%d%H%M%S")
-            self.lastTm = timeref_datetime_mat(self.refdate, self.lastTu, self.units)
+                    self.refdate = datetimeStr_datetime(txtunits[len(txtunits) - 2]+\
+                      '_' + Srefdate)
+                    self.Urefdate = txtunits[len(txtunits) - 2] + ' ' + Srefdate
+                else:
+                    self.refdate = datetimeStr_datetime(Srefdate + '_00:00:00')
+                    self.Urefdate = Srefdate
+
+                self.Srefdate = self.refdate.strftime("%Y%m%d%H%M%S")
+                timev = times[:]
+
+                self.dimt = times.shape[0]
+                self.dt = timev[1]-timev[0]
+                self.firstTu = timev[0]
+                self.firstTt = timeref_datetime(self.refdate, self.firstTu,self.units)
+                self.firstTS = self.firstTt.strftime("%Y%m%d%H%M%S")
+                self.firstTm = timeref_datetime_mat(self.refdate, self.firstTu,      \
+                  self.units)
+                self.lastTu = timev[self.dimt-1]
+                self.lastTt = timeref_datetime(self.refdate, self.lastTu, self.units)
+                self.lastTS = self.lastTt.strftime("%Y%m%d%H%M%S")
+                self.lastTm = timeref_datetime_mat(self.refdate, self.lastTu,        \
+                  self.units)
+
+        return
 
 def time_information(ncfu, tname):
@@ -11739,5 +11746,5 @@
     """ Function to return a slice of a given variable according to values to its 
       dimensions
-    slice_variable(varobj, dims)
+    slice_variable(varobj, dimslice)
       varobj= object wit the variable
       dimslice= [[dimname1]:[value1]|[[dimname2]:[value2], ...] pairs of dimension 
@@ -11746,5 +11753,5 @@
           * -1: all along the dimension
           * -9: last value of the dimension
-          * [beg]:[end] slice from [beg] to [end]
+          * [beg]@[end] slice from [beg] to [end]
     """
     fname = 'slice_variable'
@@ -11769,8 +11776,8 @@
             dimcutv = dimsl[idc].split(':')[1]
             if vardims[idd] == dimcutn: 
-                posfrac = dimcutv.find(':')
+                posfrac = dimcutv.find('@')
                 if posfrac != -1:
-                    inifrac = int(dimcutv.split(':')[0])
-                    endfrac = int(dimcutv.split(':')[1])
+                    inifrac = int(dimcutv.split('@')[0])
+                    endfrac = int(dimcutv.split('@')[1])
                     varvalsdim.append(slice(inifrac,endfrac))
                     dimnslice.append(vardims[idd])
@@ -13416,4 +13423,100 @@
 
     return
+
+def ncstediffp(values, ncfile, varn):
+    """ Function to compute differencies between time-steps (deacumulate) a netCDF file
+      new variables labelled [varn] + 'de'will be added to the file
+      values= [tdimn],[tvarn]
+        tdimn: name of the dimension time
+        tvarn: name of the variable time
+      ncfile= netCDF file to replace something
+      varn= ',' list of variables to deaccumulate ('all' for all)
+      ncstediffp('Time,Times', '/home/lluis/PY/wrfout_d01_2001-11-11_00:00:00.tests', 'Q2')
+    """
+    fname = 'ncstediffp'
+
+    if values == 'h':
+        print fname + '_____________________________________________________________'
+        print ncstediffp.__doc__
+        quit()
+
+    expectargs = '[tdimn],[tvarn]'
+ 
+    check_arguments(fname,len(expectargs.split(',')),values,',',expectargs)
+
+    tdimn = values.split(',')[0]
+    tvarn = values.split(',')[1]
+
+    onc = NetCDFFile(ncfile, 'a')
+
+    if varn.find(',') != -1:
+        if varn != 'all':
+            varns = varn.slipt(',')
+        else:
+            varns = onc.variables
+    else:
+        varns = [varn]
+
+    otdim = onc.dimensions[tdimn]
+    otvar = onc.variables[tvarn]
+    timeinf = cls_time_information(onc, tvarn)
+    
+    dimt = len(otdim)
+
+    print '  ' + fname + ': deaccumulating _______'
+    for vn in varns:
+        print "    '" + vn + "'"
+        ovar = onc.variables[vn]
+        varinf = variable_inf(ovar)
+
+        if not searchInlist(varinf.dimns, tdimn):
+            print warnmsg
+            print '  ' + fname  + ": variable '" + vn + "' has not time dimension '"+\
+              tdimn + "' !!"
+            print '    skipping it'
+        else:
+            slicefwd, dfwd = slice_variable(ovar, tdimn + ':1@'+str(dimt))
+            slicebck, dbck = slice_variable(ovar, tdimn + ':0@'+str(dimt-1))
+
+            print slicefwd[:,15,15] - slicebck[:,15,15]
+
+            deaccum = np.zeros((varinf.dims), dtype=varinf.dtype)
+            ddeaccum = []
+            for idv in range(varinf.Ndims):
+                if varinf.dimns[idv] == tdimn:
+                    ddeaccum.append(slice(1,varinf.dims[idv]))
+                else:
+                    ddeaccum.append(slice(0,varinf.dims[idv]))
+
+            deaccum[tuple(ddeaccum)] = slicefwd - slicebck
+
+            if not searchInlist(onc.variables, vn + 'de'):
+                if varinf.FillValue is not None:
+                    newvar = onc.createVariable(vn + 'de', varinf.dtype,             \
+                      tuple(varinf.dimns), fill_value = varinf.FillValue)
+                else:
+                    newvar = onc.createVariable(vn + 'de', varinf.dtype,             \
+                      tuple(varinf.dimns))
+                newvar[:] = deaccum
+            else:
+                devar = onc.variables[vn + 'de']
+                devar = deaccum
+
+            newattr = set_attribute(newvar, 'deaccumulated', 'True')
+            if timeinf.dt is not None:
+                newattr = set_attributek(newvar, 'time_step_diff', timeinf.dt,       \
+                  'npfloat')
+
+            for attrn in varinf.attributes:
+                attrv = ovar.getncattr(attrn)
+                newattr = set_attribute(newvar, attrn, attrv)
+
+        onc.sync()
+
+    onc.close()
+
+    return
+ncstediffp('Time,Times', '/home/lluis/PY/wrfout_d01_2001-11-11_00:00:00.tests', 'Q2')
+quit()
 
 #quit()
