Index: /trunk/tools/generic_tools.py
===================================================================
--- /trunk/tools/generic_tools.py	(revision 2438)
+++ /trunk/tools/generic_tools.py	(revision 2439)
@@ -127,4 +127,6 @@
 #   a given character followig a given operation and a set of values
 # ijlonlat: Function to provide the imin,jmin imax,jmax of a lon,lat box
+# impose_gregorian: Function to impose gregorian calendar to a series of times with a 
+#   non-standard calendar
 # incomming_flow: Function to determine if a fgrid-flow inflows to the central grid point
 # index_flatten_mat: Function to provide the matrix coordinates of an index from its flatten version
@@ -15682,4 +15684,89 @@
     return newstring
 
+def impose_gregorian(timev, Tunits, cal):
+    """ Function to impose gregorian calendar to a series of times with a 
+        non-standard calendar
+      timev: list of values
+      Tunits: CF units of time [Tunits] since [DateRef]
+      cal: non standard calendar
+      >>> impose_gregorian(np.range(800,10000,100), 'days since 1949-12-01 00:00:00',
+        'noleap')
+      [ 800. 901.]
+    """
+    import datetime as dt
+    fname = 'impose_gregorian'
+
+    availTu = ['weeks', 'days', 'hours', 'minutes', 'seconds']
+    availcalendar = ['noleap', '365d']
+
+    lTunits = Tunits.split(' ')
+    NTunits = len(lTunits)
+    Tu = lTunits[0]
+    if NTunits < 4: 
+        print infmsg
+        print '  ' + fname + ": CF-time units without time, adding '00:00:00' !!"
+        Srefdate = lTunits[2] + ' 00:00:00'
+        refdate = dt.datetime.combine(dateStr_date(lTunits[2]),                      \
+          timeStr_time('00:00:00'))
+    else:
+        Srefdate = lTunits[2] + ' ' + lTunits[3]
+        refdate = dt.datetime.combine(dateStr_date(lTunits[2]),                      \
+          timeStr_time(lTunits[3]))
+
+    if type(timev) == type(range(2)):
+        dimt = len(timev)
+        timev = np.array(timev)
+    elif type(timev) == type(np.arange(2)):
+        dimt = timev.shape[0]
+    else:
+        print errormsg
+        print '  ' + fname + ": type of time values: '", type(timev), "' not ready !!"
+        print '    available ones:', type(range(2)), type(np.arange(2)) 
+
+    if Tu == 'weeks':
+        timevsecs = timev * 24. * 7 * 3600.
+    elif Tu == 'days':
+        timevsecs = timev * 24. * 3600.
+    elif Tu == 'hours':
+        timevsecs = timev * 3600.
+    elif Tu == 'minutes':
+        timevsecs = timev * 60.
+    elif Tu == 'seconds':
+        timevsecs = timev * 1.
+    else:
+        print errormsg
+        print '  ' + fname + ": CF time units '" + Tu + "' not ready !!"
+        print '    available ones:', availTu
+        quit(-1)
+
+    newtimes = np.zeros((dimt), dtype=np.float64)
+
+    yrref = refdate.year
+    if cal == 'noleap' or cal == '365d':
+        for it in range(dimt):
+            deltaT = dt.timedelta(seconds=timevsecs[it])
+            datetime = refdate + deltaT
+            yr = datetime.year
+            Nleapd = leapdays(yrref, yr)
+            if datetime.month <= 2 and days_month(yr, 2) > 28: Nleapd = Nleapd - 1
+            newtimes[it] = timevsecs[it] + Nleapd*24*3600.
+    else:
+        print errormsg
+        print '  ' + fname + ": calendar '" + cal + "' not ready !!"
+        print '    available ones:', availcalendar
+        quit(-1)
+        
+    # Re-transforming to the original units
+    if Tu == 'weeks':
+        newtimes = newtimes/(24.*7*3600.)
+    elif Tu == 'days':
+        newtimes = newtimes/(24.*3600.)
+    elif Tu == 'hours':
+        newtimes = newtimes/(24.*3600.)
+    elif Tu == 'minutes':
+        newtimes = newtimes/(60.)
+
+    return newtimes
+
 #quit()
 
