Index: /trunk/tools/validation_sim.py
===================================================================
--- /trunk/tools/validation_sim.py	(revision 522)
+++ /trunk/tools/validation_sim.py	(revision 523)
@@ -1480,9 +1480,10 @@
 # Number of different statistics according to the temporal coincidence
 #  0: Exact time
-#  1: Simulation values between consecutive observed times
-Nstsim = 2
-
-stdescsim = ['E', 'B']
-Lstdescsim = ['exact time', 'between observational time-steps']
+#  1: Simulation values closest to observed times
+#  2: Simulation values between consecutive observed times
+Nstsim = 3
+
+stdescsim = ['E', 'C', 'B']
+Lstdescsim = ['exact time', 'cloest time', 'between observational time-steps']
 
 #######    #######
@@ -1772,8 +1773,39 @@
 print main + ': found',Nexactt,'Temporal same values in simulation and observations'
 
+# Sim Closest times
+##
+Nsimt = 0
+closesttvalues0 = []
+closesttvalues0st = []
+tsiminit = 0
+tsimend = 0
+
+dtsim = simobstimes[1] - simobstimes[0]
+
+for it in range(dimtsim):
+    ot = 0
+    for ito in range(ot,dimtobs-1):
+        if np.abs(valdimobs['T'][ito] - simobstimes[it]) <= dtsim/2.:
+            ot = ito
+            tdist = simobstimes[it] - valdimobs['T'][ito]
+            closesttvalues0.append([it, ito, simobstimes[it], valdimobs['T'][ito],     \
+              tdist])
+            Nsimt = Nsimt + 1
+            if tsiminit == 0: tsiminit=simobstimes[it]
+            tsimend = simobstimes[it]
+
+closesttvalues = np.array(closesttvalues0, dtype=np.float)
+
+Nclosest = len(closesttvalues[:,0])
+print main + ': found',Nclosest,'Simulation time-values closest to observations'
+
+if Nclosest == 0:
+    print warnmsg
+    print main + ': no cclosest times found !!'
+    print '  stopping it'
+    quit(-1)
+
 # Sim Coincident times
 ##
-sumsimval = 0.
-sum2simval = 0.
 Nsimt = 0
 coindtvalues0 = []
@@ -1827,5 +1859,5 @@
 newdim = onewnc.createDimension('stats',5)
 newdim = onewnc.createDimension('tstats',6)
-newdim = onewnc.createDimension('Nstsim', 2)
+newdim = onewnc.createDimension('Nstsim', 3)
 
 # Variable dimensions
@@ -1840,12 +1872,5 @@
 basicvardef(newvar, 'obstime', 'time observations for between values', obstunits)
 set_attribute(newvar, 'calendar', 'standard')
-set_attribute(newvar, 'bounds', 'time_bnds')
-newvar[:] = coindtvalues[:,3]
-
-newvar = onewnc.createVariable('betweentime','f8',('betweentime'))
-basicvardef(newvar, 'obstime', 'time simulations for between values', simtunits )
-set_attribute(newvar, 'calendar', 'standard')
-set_attribute(newvar, 'bounds', 'time_bnds')
-newvar[:] = coindtvalues[:,2]
+newvar[:] = closesttvalues[:,3]
 
 newvar = onewnc.createVariable('couple', 'c', ('couple','StrLength'))
@@ -1868,5 +1893,4 @@
 basicvardef(newvar, 'ksimstatistics', 'kind of simulated statitics', '-')
 writing_str_nc(newvar, Lstdescsim, StringLength)
-
 
 if obskind == 'trajectory':
@@ -1922,37 +1946,51 @@
         oFillValue = None
 
-# Observed values temporally exact times
-    Esimobsvalues, EsimobsSvalues, EsimobsTtvalues, trjsim =                         \
-        getting_ValidationValues(obskind, Nexactt, dims, trajpos, ovsim, ovobs,      \
-        exacttvalues, oFillValue, Ngrid, 'instantaneous')
-
+    for kst in range(Nstsim):
+
+        if stdescsim[kst] == 'E':
+# Observed and simualted exact times
+            simobsvalues, simobsSvalues, simobsTtvalues, trjsim =                    \
+              getting_ValidationValues(obskind, Nexactt, dims, trajpos, ovsim,       \
+              ovobs, exacttvalues, oFillValue, Ngrid, 'instantaneous')
+
+        elif = stdescsim[kst] == 'C':
+# Simualted closest to Observed times
+            simobsvalues, simobsSvalues, simobsTtvalues, trjsim =                    \
+              getting_ValidationValues(obskind, Nclosest, dims, trajpos, ovsim,      \
+              ovobs, closesttvalues, oFillValue, Ngrid, 'instantaneous')
+
+            newvar = onewnc.createVariable('closesttime','f8',('obstime'))
+            basicvardef(newvar, 'closesttime', 'time simulations closest to ' +      \
+              'observed values', simtunits )
+            set_attribute(newvar, 'calendar', 'standard')
+            newvar[:] = closesttvalues[:,2]
+
+        elif = stdescsim[kst] == 'B':
 # Observed values temporally around coincident times
-    simobsvalues, simobsSvalues, simobsTtvalues, trjsim =                            \
-        getting_ValidationValues(obskind, Ncoindt, dims, trajpos, ovsim, ovobs,      \
-        coindtvalues, oFillValue, Ngrid, 'tbackwardSmean')
+            simobsvalues, simobsSvalues, simobsTtvalues, trjsim =                    \
+              getting_ValidationValues(obskind, Ncoindt, dims, trajpos, ovsim, ovobs,\
+              coindtvalues, oFillValue, Ngrid, 'tbackwardSmean')
+
+            newvar = onewnc.createVariable('betweentime','f8',('betweentime'))
+            basicvardef(newvar, 'obstime', 'time simulations for between values',    \
+              simtunits )
+            set_attribute(newvar, 'calendar', 'standard')
+            set_attribute(newvar, 'bounds', 'time_bnds')
+            newvar[:] = simobsTtvalues[:,1]
 
 # Re-arranging values...
-    Earrayvals = np.array(Esimobsvalues)
     arrayvals = np.array(simobsvalues)
     if len(valvars[ivar]) > 2:
         const=np.float(valvars[ivar][3])
         if valvars[ivar][2] == 'sumc':
-            EsimobsSvalues = EsimobsSvalues + const
-            Earrayvals[:,0] = Earrayvals[:,0] + const
             simobsSvalues = simobsSvalues + const
             arrayvals[:,0] = arrayvals[:,0] + const
         elif valvars[ivar][2] == 'subc':
-            EsimobsSvalues = EsimobsSvalues - const
-            Earrayvals[:,0] = Earrayvals[:,0] - const
             simobsSvalues = simobsSvalues - const
             arrayvals[:,0] = arrayvals[:,0] - const
         elif valvars[ivar][2] == 'mulc':
-            EsimobsSvalues = EsimobsSvalues * const
-            Earrayvals[:,0] = Earrayvals[:,0] * const
             simobsSvalues = simobsSvalues * const
             arrayvals[:,0] = arrayvals[:,0] * const
         elif valvars[ivar][2] == 'divc':
-            EsimobsSvalues = EsimobsSvalues / const
-            Earrayvals[:,0] = Earrayvals[:,0] / const
             simobsSvalues = simobsSvalues / const
             arrayvals[:,0] = arrayvals[:,0] / const
