Index: trunk/tools/generic_tools.py
===================================================================
--- trunk/tools/generic_tools.py	(revision 2466)
+++ trunk/tools/generic_tools.py	(revision 2467)
@@ -86,5 +86,7 @@
 # chainSnum_levnext: Function to provide the next value for a given level from a chainStrnum hirerarchy of numbers
 # chainSnum_num: Function to pass a `ChainStrNum' string to a number
+# change_CFcalendar: Changing CF-time values to a new calendar
 # change_CFRefdate: Change CF-time values with a new reference date
+# change_CFTunits: Change CF-time values to a new temporal units
 # changedate360: Class to change a date  on a 360 days/yr (or 12 30-days months) calendar
 # check_timestep: Function to check if a time-units are 'timestep' based. If it's the case, transform them
@@ -16245,7 +16247,7 @@
       newSrefdate: new CF refDate [YYYY]-[MM]-[HH] [HH]:[MM]:[SS]
     >>> times = [15.5, 45, 74.5, 105, 135.5, 166, 196.5, 227.5, 258, 288.5, 319]
-    >>> change_CFRefdate(times, '1850-01-01 00:00:00', '1949-12-01 00:00:00')
-    [-36478.5 -36449.  -36419.5 -36389.  -36358.5 -36328.  -36297.5 -36266.5
-      -36236.  -36205.5 -36175. ]
+    >>> change_CFRefdate(times, 'days since 1850-01-01 00:00:00', '1949-12-01 00:00:00')
+    array([-36478.5 -36449.  -36419.5 -36389.  -36358.5 -36328.  -36297.5 -36266.5
+      -36236.  -36205.5 -36175. ]), 'days since 1949-12-01 00:00:00'
     """
     fname = 'change_CFRefedate'
@@ -16342,9 +16344,120 @@
     newtimevals = newtimevals - newdays
 
+    newcftimeu = origtunits + ' since ' + newSrefdate
+
+    return newtimevals, newcftimeu
+
+def change_CFTunits(timevals, origcftimeu, newtunits):
+    """ Change CF-time values to a new temporal units
+       NOTE: CF-times does not authorize timeu = 'month'
+      timevals: actual CF time-values
+      origcftimeu: current original CF-time values [timeu] since [Refdate]
+      newtunits: new time units. Accepted ones: 'weeks', 'days', 'hours', 'minutes', 
+        'seconds'
+    >>> times = [15.5, 45, 74.5, 105, 135.5, 166, 196.5, 227.5, 258, 288.5, 319]
+    >>> change_CFTunits(times, 'days since 1850-01-01 00:00:00', 'minutes')
+    array([  22320.,   64800.,  107280.,  151200.,  195120.,  239040.,
+      282960.,  327600.,  371520.,  415440.,  459360.]), 'minutes since 1850-01-01 00:00:00'
+    """
+    fname = 'change_CFTunits'
+
+    availtu = ['weeks', 'days', 'hours', 'minutes', 'seconds']
+
+    # original
+    origtv = origcftimeu.split(' ')
+    origtunits = origtv[0]
+    if len(origtv) == 4:
+        origSrefdate = origtv[2] + ' ' + origtv[3]
+    else:
+        print warnmsg
+        print '  ' + fname + ": original time units wihout time !!"
+        print "   adding it as '00:00:00'"
+        origSrefdate = origtv[2] + ' 00:00:00'
+
+    # From original to days
+    if origtunits == 'weeks':
+        odaysdtr = 7.
+    elif origtunits == 'days':
+        odaysdtr = 1.
+    elif origtunits == 'hours':
+        odaysdtr = 1./24.
+    elif origtunits == 'minutes':
+        odaysdtr = 1./(24.*60.)
+    elif origtunits == 'seconds':
+        odaysdtr = 1./(24.*3600.)
+    else:
+        print errormsg
+        print '  ' + fname + ": original time-units '" + origtunits + "' not ready !!"
+        print '    available ones: ', availtu
+        quit(-1)
+
+    # From days to new
+    if newtunits == 'weeks':
+        ndaysdtr = 1. / 7.
+    elif newtunits == 'days':
+        ndaysdtr = 1.
+    elif newtunits == 'hours':
+        ndaysdtr = 24.
+    elif newtunits == 'minutes':
+        ndaysdtr = 24. * 60.
+    elif newtunits == 'seconds':
+        ndaysdtr = 24. * 3600.
+    else:
+        print errormsg
+        print '  ' + fname + ": new time-units '" + newtunits + "' not ready !!"
+        print '    available ones: ', availtu
+        quit(-1)
+
+    # Conversion orig-new
+    conversion = odaysdtr*ndaysdtr
+
+    if type(timevals) != type(np.ones((2), dtype=int)):
+        newtimevals = np.array(timevals, dtype=np.float64)
+        newtimevals = newtimevals*conversion
+    else:
+        newtimevals = timevals*conversion
+
+    newcftimeu = newtunits + ' since ' + origSrefdate
+
+    return newtimevals, newcftimeu, 
+
+def change_CFcalendar(timevals, origcftimeu, origcal, newcal='gregorian'):
+    """ Changing CF-time values to a new calendar
+      timevals: actual CF time-values
+      origcftimeu: current original CF-time values [timeu] since [Refdate]
+      newcal: new calendar. Accepted ones: 'gregorian', 'standard'
+    >>> times = [15.5, 45, 74.5, 105, 135.5, 166, 196.5, 227.5, 258, 288.5, 319]
+    >>> change_CFcalendar(times, 'days since 1850-01-01 00:00:00', 'noleap', 'gregorian')
+    [  15.5   45.    74.5  105.   135.5  166.   196.5  227.5  258.   288.5
+      319. ]
+    >>> times = [56649.5, 56680, 56710.5, 56741, 56771.5, 56802.5, 56833, 56863.5, 56894, 56924.5]
+    >>> change_CFcalendar(times, 'days since 1850-01-01 00:00:00', 'noleap', 'gregorian')
+    [ 56687.5  56718.   56748.5  56779.   56809.5  56840.5  56871.   56901.5
+      56932.   56962.5]
+    """
+    fname = 'change_CFcalendar'
+    availorigcal = ['noleap', '365d']
+    availnewcal = ['gregorian', 'standard']
+
+    # If the calendar is not gregorian, it needs to be fixed from origSrefdate!
+    if origcal == 'noleap' or origcal == '365d':
+        print '  ' + fname + ": found non-standard calendar '" + origcal + "' !!"
+        if newcal == 'gregorian' or newcal == 'standard':
+            # Imposing to gregorian calendar
+            newtimevals = gen_impose_gregorian(timevals, origcftimeu, origcal)     
+        else:
+            print errormsg
+            print '  ' + fname + ": new calendar '" + newcal + "' not ready !!"
+            print '    avaialable ones:', availnewcal
+            quit(-1)
+
+    else:
+        print errormsg
+        print '  ' + fname + ": original calendar '" + origcal + "' not ready !!"
+        print '    avaialable ones:', availorigcal
+        quit(-1)
+
     return newtimevals
 
-times = [15.5, 45, 74.5, 105, 135.5, 166, 196.5, 227.5, 258, 288.5, 319]
-print change_CFRefdate(times, 'days since 1850-01-01 00:00:00', '1949-12-01 00:00:00')
-
 #quit()
 
