Index: trunk/tools/validation_sim.py
===================================================================
--- trunk/tools/validation_sim.py	(revision 600)
+++ trunk/tools/validation_sim.py	(revision 601)
@@ -93,4 +93,152 @@
 
     return
+
+def CFtimes_datetime_NOfile(times, units, calendar):
+    """ Provide date/time array from velues of netCDF CF-compilant time variable
+    times= time values
+    units= CF units of the variable time
+    output:
+      array(dimt, 0) = year
+      array(dimt, 1) = month
+      array(dimt, 2) = day
+      array(dimt, 3) = hour
+      array(dimt, 4) = minute
+      array(dimt, 5) = second
+    """
+    import datetime as dt
+    fname = 'CFtimes_datetime_NOfile'
+
+    txtunits = units.split(' ')
+    tunits = 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:
+#        print '  refdate with time!'
+        refdate = datetimeStr_datetime(txtunits[len(txtunits) - 2] + '_' + Srefdate)
+    else:
+        refdate = dateStr_date(Srefdate)
+
+    dimt = len(times)
+    realdates = np.zeros((dimt, 6), dtype=int)
+
+    secsDay=3600*24.
+
+# Checking calendar! 
+## 
+    y360 = False
+    daycal360 = ['earth_360d', '360d', '360days', '360_day']
+    if searchInlist(daycal360,calendar):
+        print warnmsg
+        print '  ' + fname + ': calendar of 12 months of 30 days !!'
+        y360 = True
+
+## Not in timedelta
+#    if tunits == 'years':
+#        for it in range(dimt):
+#            realdate = refdate + dt.timedelta(years=float(times[it]))
+#            realdates[it] = int(realdate.year)
+#    elif tunits == 'months':
+#        for it in range(dimt):
+#            realdate = refdate + dt.timedelta(months=float(times[it]))
+#            realdates[it] = int(realdate.year)
+    if y360:
+        if tunits == 'weeks':
+            for it in range(dimt):
+                deltat = dt.timedelta(weeks=float(times[it]))
+                Tsecs = deltat.days*secsDay + deltat.seconds + deltat.microseconds/1000.
+                realdates[it,:] = date_juliandate(refdate.year,Tsecs)
+        elif tunits == 'days':
+            for it in range(dimt):
+                deltat = dt.timedelta(days=float(times[it]))
+                Tsecs = deltat.days*secsDay + deltat.seconds + deltat.microseconds/1000.
+                realdates[it,:] = date_juliandate(refdate.year,Tsecs)
+        elif tunits == 'hours':
+           for it in range(dimt):
+                realdate = dt.timedelta(hours=float(times[it]))
+                Tsecs = deltat.days*secsDay + deltat.seconds + deltat.microseconds/1000.
+                realdates[it,:] = date_juliandate(refdate.year,Tsecs)
+        elif tunits == 'minutes':
+           for it in range(dimt):
+                realdate = dt.timedelta(minutes=float(times[it]))
+                Tsecs = deltat.days*secsDay + deltat.seconds + deltat.microseconds/1000.
+                realdates[it,:] = date_juliandate(refdate.year,Tsecs)
+        elif tunits == 'seconds':
+           for it in range(dimt):
+                realdate = dt.timedelta(seconds=float(times[it]))
+                Tsecs = deltat.days*secsDay + deltat.seconds + deltat.microseconds/1000.
+                realdates[it,:] = date_juliandate(refdate.year,Tsecs)
+        elif tunits == 'miliseconds':
+           for it in range(dimt):
+                realdate = dt.timedelta(miliseconds=float(times[it]))
+                Tsecs = deltat.days*secsDay + deltat.seconds + deltat.microseconds/1000.
+                realdates[it,:] = date_juliandate(refdate.year,Tsecs)
+        else:
+              print errormsg
+              print '    CFtimes_datetime: time units "' + tunits + '" not ready!!!!'
+              quit(-1)
+    else:
+        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
 
 def index_3mat(matA,matB,matC,val):
@@ -1787,4 +1935,16 @@
 simobstimes = coincident_CFtimes(tsim, obstunits, simtunits)
 
+iobst = CFtimes_datetime_NOfile([valdimobs['T'][0]], obstunits, 'standard')
+fobst = CFtimes_datetime_NOfile([valdimobs['T'][dimtobs-1]], obstunits, 'standard')
+isimt = CFtimes_datetime_NOfile([simobstimes[0]], obstunits, 'standard')
+fsimt = CFtimes_datetime_NOfile([simobstimes[dimtsim-1]], obstunits, 'standard')
+print 'check of times _______'
+print '  * Observations'
+print '     - first time:', iobst
+print '     - last time:', fobst
+print '  * Simulations'
+print '     - first time:', isimt
+print '     - last time:', fsimt
+
 #
 ## Looking for exact/near times
@@ -1808,5 +1968,5 @@
     print '  ' + main + ': no exact values found!'
     Nexactt = 0
-    quit(-1)
+#    quit(-1)
 else:
     Nexactt = len(exacttvalues[:,0])
@@ -1838,4 +1998,5 @@
 closesttvalues = np.array(closesttvalues0, dtype=np.float)
 
+print 'closesttvales shape:',closesttvalues.shape
 Nclosest = len(closesttvalues[:,0])
 print main + ': found',Nclosest,'Simulation time-values closest to observations'
