Index: /trunk/tools/nc_var_tools.py
===================================================================
--- /trunk/tools/nc_var_tools.py	(revision 533)
+++ /trunk/tools/nc_var_tools.py	(revision 534)
@@ -2958,4 +2958,27 @@
     return timeinf
 
+def date_juliandate(rdate):
+    """ Function to transform from a standard date to a matrix julian day based one
+      rdate= `datetime' object to transform
+    """
+    import datetime as dt
+
+    fname = 'date_juliandate'
+
+    jday = int(rdate.timetuple().tm_yday)
+    rldate[0] = int(rdate.year)
+    rldate[1] = jday/30 + 1
+    rldate[2] = jday - (rldate[1]-1)*30
+    rldate[3] = int(rdate.hour)
+    rldate[4] = int(rdate.second)
+    rldate[5] = int(rdate.minute)
+
+    if rldate[2] < 0: 
+        print errormsg
+        print '  ' + fname + ': wrong date', rdate, 'it gives a negative',           \
+          rldate[2],'day!!'
+
+    return rldate
+
 def CFtimes_datetime(ncfile, tname):
     """ Provide date/time array from a file with a series of netCDF CF-compilant time variable
@@ -2999,4 +3022,14 @@
     realdates = np.zeros((dimt, 6), dtype=int)
 
+# Checking calendar! 
+## 
+    360daycal = ['earth_360d', '360d', '360days']
+    if searchInlist(attvar, 'calendar'):
+        calendar = times.getncattr('calendar')
+        if searchInlist(360daycal,calendar):
+            print warnmsg
+            print '  ' + fname + ': calendar of 12 months of 30 days !!'
+            360daycal = True
+
 ## Not in timedelta
 #    if tunits == 'years':
@@ -3008,63 +3041,93 @@
 #            realdate = refdate + dt.timedelta(months=float(times[it]))
 #            realdates[it] = int(realdate.year)
-    if tunits == 'weeks':
-        for it in range(dimt):
-            realdate = refdate + dt.timedelta(weeks=float(times[it]))
-            realdates[it,0] = int(realdate.year)
-            realdates[it,1] = int(realdate.month)
-            realdates[it,2] = int(realdate.day)
-            realdates[it,3] = int(realdate.hour)
-            realdates[it,4] = int(realdate.second)
-            realdates[it,5] = int(realdate.minute)
-    elif tunits == 'days':
-        for it in range(dimt):
-            realdate = refdate + dt.timedelta(days=float(times[it]))
-            realdates[it,0] = int(realdate.year)
-            realdates[it,1] = int(realdate.month)
-            realdates[it,2] = int(realdate.day)
-            realdates[it,3] = int(realdate.hour)
-            realdates[it,4] = int(realdate.second)
-            realdates[it,5] = int(realdate.minute)
-    elif tunits == 'hours':
-       for it in range(dimt):
-            realdate = refdate + dt.timedelta(hours=float(times[it]))
-            realdates[it,0] = int(realdate.year)
-            realdates[it,1] = int(realdate.month)
-            realdates[it,2] = int(realdate.day)
-            realdates[it,3] = int(realdate.hour)
-            realdates[it,4] = int(realdate.second)
-            realdates[it,5] = int(realdate.minute)
-    elif tunits == 'minutes':
-       for it in range(dimt):
-            realdate = refdate + dt.timedelta(minutes=float(times[it]))
-            realdates[it,0] = int(realdate.year)
-            realdates[it,1] = int(realdate.month)
-            realdates[it,2] = int(realdate.day)
-            realdates[it,3] = int(realdate.hour)
-            realdates[it,4] = int(realdate.second)
-            realdates[it,5] = int(realdate.minute)
-    elif tunits == 'seconds':
-       for it in range(dimt):
-            realdate = refdate + dt.timedelta(seconds=float(times[it]))
-            realdates[it,0] = int(realdate.year)
-            realdates[it,1] = int(realdate.month)
-            realdates[it,2] = int(realdate.day)
-            realdates[it,3] = int(realdate.hour)
-            realdates[it,4] = int(realdate.second)
-            realdates[it,5] = int(realdate.minute)
-    elif tunits == 'milliseconds':
-       for it in range(dimt):
-            realdate = refdate + dt.timedelta(milliseconds=float(times[it]))
-            realdates[it,0] = int(realdate.year)
-            realdates[it,1] = int(realdate.month)
-            realdates[it,2] = int(realdate.day)
-            realdates[it,3] = int(realdate.hour)
-            realdates[it,4] = int(realdate.second)
-            realdates[it,5] = int(realdate.minute)
+    if 360daycal:
+        if tunits == 'weeks':
+            for it in range(dimt):
+                realdate = refdate + dt.timedelta(weeks=float(times[it]))
+                realdates[it,:] = date_juliandate(realdate)
+        elif tunits == 'days':
+            for it in range(dimt):
+                realdate = refdate + dt.timedelta(days=float(times[it]))
+                realdates[it,:] = date_juliandate(realdate)
+        elif tunits == 'hours':
+           for it in range(dimt):
+                realdate = refdate + dt.timedelta(hours=float(times[it]))
+                realdates[it,:] = date_juliandate(realdate)
+        elif tunits == 'minutes':
+           for it in range(dimt):
+                realdate = refdate + dt.timedelta(minutes=float(times[it]))
+                realdates[it,:] = date_juliandate(realdate)
+        elif tunits == 'seconds':
+           for it in range(dimt):
+                realdate = refdate + dt.timedelta(seconds=float(times[it]))
+                realdates[it,:] = date_juliandate(realdate)
+        elif tunits == 'miliseconds':
+           for it in range(dimt):
+                realdate = refdate + dt.timedelta(miliseconds=float(times[it]))
+                realdates[it,:] = date_juliandate(realdate)
+        else:
+              print errormsg
+              print '    CFtimes_datetime: time units "' + tunits + '" not ready!!!!'
+              quit(-1)
     else:
-          print errormsg
-          print '    CFtimes_datetime: time units "' + tunits + '" not ready!!!!'
-          quit(-1)
-
+        if tunits == 'weeks':
+            for it in range(dimt):
+                realdate = refdate + dt.timedelta(weeks=float(times[it]))
+                realdates[it,0] = int(realdate.year)
+                realdates[it,1] = int(realdate.month)
+                realdates[it,2] = int(realdate.day)
+                realdates[it,3] = int(realdate.hour)
+                realdates[it,4] = int(realdate.second)
+                realdates[it,5] = int(realdate.minute)
+        elif tunits == 'days':
+            for it in range(dimt):
+                realdate = refdate + dt.timedelta(days=float(times[it]))
+                realdates[it,0] = int(realdate.year)
+                realdates[it,1] = int(realdate.month)
+                realdates[it,2] = int(realdate.day)
+                realdates[it,3] = int(realdate.hour)
+                realdates[it,4] = int(realdate.second)
+                realdates[it,5] = int(realdate.minute)
+        elif tunits == 'hours':
+           for it in range(dimt):
+                realdate = refdate + dt.timedelta(hours=float(times[it]))
+                realdates[it,0] = int(realdate.year)
+                realdates[it,1] = int(realdate.month)
+                realdates[it,2] = int(realdate.day)
+                realdates[it,3] = int(realdate.hour)
+                realdates[it,4] = int(realdate.second)
+                realdates[it,5] = int(realdate.minute)
+        elif tunits == 'minutes':
+           for it in range(dimt):
+                realdate = refdate + dt.timedelta(minutes=float(times[it]))
+                realdates[it,0] = int(realdate.year)
+                realdates[it,1] = int(realdate.month)
+                realdates[it,2] = int(realdate.day)
+                realdates[it,3] = int(realdate.hour)
+                realdates[it,4] = int(realdate.second)
+                realdates[it,5] = int(realdate.minute)
+        elif tunits == 'seconds':
+           for it in range(dimt):
+                realdate = refdate + dt.timedelta(seconds=float(times[it]))
+                realdates[it,0] = int(realdate.year)
+                realdates[it,1] = int(realdate.month)
+                realdates[it,2] = int(realdate.day)
+                realdates[it,3] = int(realdate.hour)
+                realdates[it,4] = int(realdate.second)
+                realdates[it,5] = int(realdate.minute)
+        elif tunits == 'milliseconds':
+           for it in range(dimt):
+                realdate = refdate + dt.timedelta(milliseconds=float(times[it]))
+                realdates[it,0] = int(realdate.year)
+                realdates[it,1] = int(realdate.month)
+                realdates[it,2] = int(realdate.day)
+                realdates[it,3] = int(realdate.hour)
+                realdates[it,4] = int(realdate.second)
+                realdates[it,5] = int(realdate.minute)
+        else:
+              print errormsg
+              print '    CFtimes_datetime: time units "' + tunits + '" not ready!!!!'
+              quit(-1)
+    
     return realdates
 
