Index: trunk/tools/validation_sim.py
===================================================================
--- trunk/tools/validation_sim.py	(revision 513)
+++ trunk/tools/validation_sim.py	(revision 514)
@@ -1120,8 +1120,8 @@
     return
 
-def getting_ValidationValues(okind, dimt, ds, trjpos, ovs, ovo, tvalues, oFill, Ng):
+def getting_ValidationValues(okind, dimt0, ds, trjpos, ovs, ovo, tvalues, oFill, Ng, kvals):
     """ Function to get the values to validate accroding to the type of observation
       okind= observational kind
-      dimt= number of values to retrieve
+      dimt0= initial number of values to retrieve
       ds= dictionary with the names of the dimensions (sim, obs)
       trjpos= positions of the multi-stations (t, Y, X) or trajectory ([Z], Y, X)
@@ -1131,4 +1131,8 @@
       oFill= Fill Value for the observations
       Ng= number of grid points around the observation
+      kvals= kind of values
+        'instantaneous':  values are taken as instantaneous values
+        'tbackwardSmean':  simulated values are taken as time averages from back to the point
+        'tbackwardOmean':  observed values are taken as time averages from back to the point
     return:
       sovalues= simulated values at the observation point and time
@@ -1141,4 +1145,20 @@
 
     sovalues = []
+
+    if kvals == 'instantaneous':
+        dimt = dimt0
+    elif kvals == 'tbackwardSmean':
+        print '  ' + fname + ':',kvals,'!!'
+        dimt = len(tvalues[:,3])
+        print '    : initially we got',dimt0,'values which will become',dimt
+        quit()
+    elif kvals == 'tbackwardOmean':
+        print '  ' + fname + ':',kvals,'!!'
+        dimt = len(tvalues[:,2])
+        print '    : initially we got',dimt0,'values which will become',dimt
+    else:
+        print errormsg
+        print '  ' + fname + ": kind of values '" + kvals + "' not ready!!"
+        quit(-1)
 
 # Simulated values spatially around
@@ -1810,10 +1830,10 @@
     Esimobsvalues, EsimobsSvalues, EsimobsTvalues, EsimobsTtvalues, trjsim =         \
         getting_ValidationValues(obskind, Nexactt, dims, trajpos, ovsim, ovobs,      \
-        exacttvalues, oFillValue, Ngrid)
+        exacttvalues, oFillValue, Ngrid, 'instantaneous')
 
 # Observed values temporally around coincident times
     simobsvalues, simobsSvalues, simobsTvalues, simobsTtvalues, trjsim =             \
         getting_ValidationValues(obskind, Ncoindt, dims, trajpos, ovsim, ovobs,      \
-        coindtvalues, oFillValue, Ngrid)
+        coindtvalues, oFillValue, Ngrid, 'tbackwardaverage')
 
 # Re-arranging values...
@@ -1968,5 +1988,30 @@
     simobsstats[1,12]=(simstats[1,0]-obsstats[1,0])/(0.5*(simstats[1,0]+obsstats[1,0]))
 
-# Statistics around sim values
+# Statistics around sim values exact
+    Earoundstats = np.zeros((5,Nexactt), dtype=np.float)
+    for it in range(Nexactt):
+        Earoundstats[0,it] = np.min(EsimobsSvalues[it,])
+        Earoundstats[1,it] = np.max(EsimobsSvalues[it,])
+        Earoundstats[2,it] = np.mean(EsimobsSvalues[it,])
+        Earoundstats[3,it] = np.mean(EsimobsSvalues[it,]*EsimobsSvalues[it,])
+        Earoundstats[4,it] = np.sqrt(Earoundstats[3,it] - Earoundstats[2,it]*        \
+          Earoundstats[2,it])
+
+# Statistics around obs values exact
+    Earoundostats = np.zeros((6,Nexactt), dtype=np.float)
+
+    for it in range(Nexactt):
+        obsmask = ma.masked_equal(EsimobsTvalues[str(it)], fillValueF)
+        obsmask2 = obsmask*obsmask
+
+        Earoundostats[0,it] = len(obsmask.flatten())
+        Earoundostats[1,it] = obsmask.min()
+        Earoundostats[2,it] = obsmask.max()
+        Earoundostats[3,it] = obsmask.mean()
+        Earoundostats[4,it] = obsmask2.mean()
+        Earoundostats[5,it] = np.sqrt(Earoundostats[4,it] - Earoundostats[3,it]*     \
+          Earoundostats[3,it])
+
+# Statistics around sim values between
     aroundstats = np.zeros((5,Ncoindt), dtype=np.float)
     for it in range(Ncoindt):
@@ -1978,5 +2023,5 @@
           aroundstats[2,it])
 
-# Statistics around obs values
+# Statistics around obs values between
     aroundostats = np.zeros((6,Ncoindt), dtype=np.float)
 
@@ -2022,5 +2067,20 @@
     newvar[:] = arrayvals[:,1]
 
-# Around values
+# Around values exact
+    if not onewnc.variables.has_key(valvars[ivar][0] + 'Earound'):
+        if dims.has_key('Z'):
+            if not onewnc.dimensions.has_key('zaround'):
+                newdim = onewnc.createDimension('zaround',Ngrid*2+1)
+                newvar = onewnc.createVariable(valvars[ivar][0] + 'Earound', 'f',    \
+                  ('time','zaround','yaround','xaround'), fill_value=fillValueF)
+        else:
+            newvar = onewnc.createVariable(valvars[ivar][0] + 'Earound', 'f',        \
+              ('time','yaround','xaround'), fill_value=fillValueF)
+
+        descvar = 'exact around simulated values +/- grid values: ' + valvars[ivar][0]
+        basicvardef(newvar, varsimobs + 'Earound', descvar, ovobs.getncattr('units'))
+        newvar[:] = EsimobsSvalues
+
+# Around values between
     if not onewnc.variables.has_key(valvars[ivar][0] + 'around'):
         if dims.has_key('Z'):
@@ -2028,5 +2088,5 @@
                 newdim = onewnc.createDimension('zaround',Ngrid*2+1)
                 newvar = onewnc.createVariable(valvars[ivar][0] + 'around', 'f',     \
-                  ('time','zaround','yaround','xaround'), fill_value=fillValueF)
+                  ('betweentime','zaround','yaround','xaround'),fill_value=fillValueF)
         else:
             newvar = onewnc.createVariable(valvars[ivar][0] + 'around', 'f',         \
@@ -2063,12 +2123,41 @@
         newvar[:] = simobsstats
 
-# around sim Statistics
+# around sim Statistics exact
+    if not searchInlist(onewnc.variables,valvars[ivar][0] + 'Estaround'):
+        newvar = onewnc.createVariable(valvars[ivar][0] + 'Estaround', 'f',          \
+          ('time','stats'), fill_value=fillValueF)
+        descvar = 'exact around (' +  str(Ngrid) + ', ' + str(Ngrid) +               \
+          ') simulated statisitcs: ' + valvars[ivar][0]
+        basicvardef(newvar, valvars[ivar][0] + 'Estaround', descvar,                 \
+          ovobs.getncattr('units'))
+        set_attribute(newvar, 'cell_methods', 'Etime_bnds')
+        newvar[:] = Earoundstats.transpose()
+
+    if not searchInlist(onewnc.variables, 'Etime_bnds'):
+        newvar = onewnc.createVariable('Etime_bnds','f8',('time','bnds'))
+        basicvardef(newvar, 'Etime_bnds', 'betweentime', obstunits )
+        set_attribute(newvar, 'calendar', 'standard')
+        newvar[:] = EsimobsTtvalues
+
+# around obs Statistics exact
+    if not searchInlist(onewnc.variables,valvars[ivar][1] + 'Estaround'):
+        newvar = onewnc.createVariable(valvars[ivar][1] + 'Estaround', 'f',          \
+          ('time','tstats'), fill_value=fillValueF)
+        descvar = 'exact around temporal observed statisitcs: ' + valvars[ivar][1]
+        basicvardef(newvar, valvars[ivar][1] + 'Estaround', descvar,                  \
+          ovobs.getncattr('units'))
+        set_attribute(newvar, 'cell_methods', 'Etime_bnds')
+
+        newvar[:] = aroundostats.transpose()
+
+# around sim Statistics between
     if not searchInlist(onewnc.variables,valvars[ivar][0] + 'staround'):
         newvar = onewnc.createVariable(valvars[ivar][0] + 'staround', 'f',           \
           ('betweentime','stats'), fill_value=fillValueF)
-        descvar = 'around (' +  str(Ngrid) + ', ' + str(Ngrid) +                     \
+        descvar = 'between around (' +  str(Ngrid) + ', ' + str(Ngrid) +             \
           ') simulated statisitcs: ' + valvars[ivar][0]
         basicvardef(newvar, valvars[ivar][0] + 'staround', descvar,                  \
           ovobs.getncattr('units'))
+        set_attribute(newvar, 'cell_methods', 'time_bnds')
         newvar[:] = aroundstats.transpose()
 
@@ -2079,13 +2168,12 @@
         newvar[:] = simobsTtvalues
 
-# around obs Statistics
+# around obs Statistics between
     if not searchInlist(onewnc.variables,valvars[ivar][1] + 'staround'):
         newvar = onewnc.createVariable(valvars[ivar][1] + 'staround', 'f',           \
           ('betweentime','tstats'), fill_value=fillValueF)
-        descvar = 'around temporal observed statisitcs: ' + valvars[ivar][1]
+        descvar = 'betweem around temporal observed statisitcs: ' + valvars[ivar][1]
         basicvardef(newvar, valvars[ivar][1] + 'staround', descvar,                  \
           ovobs.getncattr('units'))
-        set_attribute(newvar, 'cell_methods', 'statistics')
-
+        set_attribute(newvar, 'cell_methods', 'time_bnds')
         newvar[:] = aroundostats.transpose()
 
