Index: trunk/tools/validation_sim.py
===================================================================
--- trunk/tools/validation_sim.py	(revision 515)
+++ trunk/tools/validation_sim.py	(revision 516)
@@ -1120,8 +1120,8 @@
     return
 
-def getting_ValidationValues(okind, dimt0, ds, trjpos, ovs, ovo, tvalues, oFill, Ng, kvals):
+def getting_ValidationValues(okind, dimt, ds, trjpos, ovs, ovo, tvalues, oFill, Ng, kvals):
     """ Function to get the values to validate accroding to the type of observation
       okind= observational kind
-      dimt0= initial number of values to retrieve
+      dimt= 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)
@@ -1147,16 +1147,25 @@
 
     if kvals == 'instantaneous':
-        dimt = dimt0
+        dimtf = dimt
     elif kvals == 'tbackwardSmean':
         print '  ' + fname + ':',kvals,'!!'
         uniqt = np.unique(tvalues[:,3])
-        dimt = len(uniqt)
-        print '    initially we got',dimt0,'values which will become',dimt
+        dimtf = len(uniqt)
+        print '    initially we got',dimt,'values which will become',dimtf
+        postf = {}
+        for it in range(dimtf):
+            if it == 0:
+                postf[uniqt[it]] = [0,0]
+            else:
+                posprev = postf[uniqt[it-1]][1]
+                posit = tvalues[:,3].index(uniqt[it])
+                postf[uniqt[it]] = [posprev, posit]
+        print postf
         quit()
     elif kvals == 'tbackwardOmean':
         print '  ' + fname + ':',kvals,'!!'
         uniqt = np.unique(tvalues[:,2])
-        dimt = len(uniqt)
-        print '     initially we got',dimt0,'values which will become',dimt
+        dimtf = len(uniqt)
+        print '     initially we got',dimt,'values which will become',dimtf
     else:
         print errormsg
@@ -1166,6 +1175,5 @@
 # Simulated values spatially around
     if ds.has_key('Z'):
-        soSvalues = np.zeros((dimt, Ng*2+1, Ng*2+1, Ng*2+1),            \
-          dtype = np.float)
+        soSvalues = np.zeros((dimt, Ng*2+1, Ng*2+1, Ng*2+1), dtype = np.float)
         if okind == 'trajectory':
             trjs = np.zeros((4,dimt), dtype=int)
@@ -1187,12 +1195,11 @@
     if okind == 'multi-points':
         for it in range(dimt):
-            slicev = ds['X'][0] + ':' + str(trjpos[2,it]) + '|' +                 \
-              ds['Y'][0]+ ':' + str(trjpos[1,it]) + '|' +                         \
-              ds['T'][0]+ ':' + str(tvalues[it][0])
+            slicev = ds['X'][0] + ':' + str(trjpos[2,it]) + '|' +  ds['Y'][0] +      \
+              ':' + str(trjpos[1,it]) + '|' + ds['T'][0]+ ':' + str(tvalues[it][0])
             slicevar, dimslice = slice_variable(ovs, slicev)
             sovalues.append([ slicevar, ovo[tvalues[it][1]]])
-            slicev = ds['X'][0] + ':' + str(trjpos[2,it]-Ng) + '@' +           \
-              str(trjpos[2,it]+Ng) + '|' + ds['Y'][0] + ':' +                  \
-              str(trjpos[1,it]-Ng) + '@' + str(trjpos[1,it]+Ng) + '|' +      \
+            slicev = ds['X'][0] + ':' + str(trjpos[2,it]-Ng) + '@' +                 \
+              str(trjpos[2,it]+Ng) + '|' + ds['Y'][0] + ':' +                        \
+              str(trjpos[1,it]-Ng) + '@' + str(trjpos[1,it]+Ng) + '|' +              \
               ds['T'][0]+':'+str(tvalues[it][0])
             slicevar, dimslice = slice_variable(ovs, slicev)
@@ -1203,6 +1210,6 @@
             ito = int(tvalues[it,1])
             if valdimsim.has_key('X') and valdimsim.has_key('Y'):
-                slicev = ds['X'][0] + ':' + str(stationpos[1]) + '|' +             \
-                  ds['Y'][0] + ':' + str(stationpos[0]) + '|' +                    \
+                slicev = ds['X'][0] + ':' + str(stationpos[1]) + '|' +               \
+                  ds['Y'][0] + ':' + str(stationpos[0]) + '|' +                      \
                   ds['T'][0] + ':' + str(int(tvalues[it][0]))
             else:
@@ -1216,7 +1223,7 @@
                 sovalues.append([ slicevar, ovo[int(ito)]])
             if valdimsim.has_key('X') and valdimsim.has_key('Y'):
-                slicev = ds['X'][0] + ':' + str(stationpos[1]-Ng) + '@' +       \
-                  str(stationpos[1]+Ng+1) + '|' + ds['Y'][0] + ':' +            \
-                  str(stationpos[0]-Ng) + '@' + str(stationpos[0]+Ng+1) + '|' +\
+                slicev = ds['X'][0] + ':' + str(stationpos[1]-Ng) + '@' +            \
+                  str(stationpos[1]+Ng+1) + '|' + ds['Y'][0] + ':' +                 \
+                  str(stationpos[0]-Ng) + '@' + str(stationpos[0]+Ng+1) + '|' +      \
                   ds['T'][0] + ':' + str(int(tvalues[it,0]))
             else:
@@ -1250,9 +1257,9 @@
                 ito = int(tvalues[it,1])
                 if notfound[ito] == 0:
-                    trjpos[2,ito] = index_mat(valdimsim['Z'][tvalues[it,0],:,  \
+                    trjpos[2,ito] = index_mat(valdimsim['Z'][tvalues[it,0],:,        \
                       trjpos[1,ito],trjpos[0,ito]], valdimobs['Z'][ito])
-                    slicev = ds['X'][0]+':'+str(trjpos[0,ito]) + '|' +            \
-                      ds['Y'][0]+':'+str(trjpos[1,ito]) + '|' +                   \
-                      ds['Z'][0]+':'+str(trjpos[2,ito]) + '|' +                   \
+                    slicev = ds['X'][0]+':'+str(trjpos[0,ito]) + '|' +               \
+                      ds['Y'][0]+':'+str(trjpos[1,ito]) + '|' +                      \
+                      ds['Z'][0]+':'+str(trjpos[2,ito]) + '|' +                      \
                       ds['T'][0]+':'+str(int(tvalues[it,0]))
                     slicevar, dimslice = slice_variable(ovs, slicev)
@@ -1265,7 +1272,7 @@
                     maxz = np.min([trjpos[2,ito]+Ng+1,ovs.shape[1]])
 
-                    slicev = ds['X'][0] + ':' + str(minx) + '@' + str(maxx) + '|' +\
-                      ds['Y'][0] + ':' + str(miny) + '@' + str(maxy) + '|' +       \
-                      ds['Z'][0] + ':' + str(minz) + '@' + str(maxz) + '|' +       \
+                    slicev = ds['X'][0] + ':' + str(minx) + '@' + str(maxx) + '|' +  \
+                      ds['Y'][0] + ':' + str(miny) + '@' + str(maxy) + '|' +         \
+                      ds['Z'][0] + ':' + str(minz) + '@' + str(maxz) + '|' +         \
                       ds['T'][0] + ':' + str(int(tvalues[it,0]))
                     slicevar, dimslice = slice_variable(ovs, slicev)
@@ -1285,5 +1292,5 @@
                 else:
                     sovalues.append([fillValueF, fillValueF])
-                    soSvalues[it,:,:,:]= np.ones((Ng*2+1,Ng*2+1,Ng*2+1),         \
+                    soSvalues[it,:,:,:]= np.ones((Ng*2+1,Ng*2+1,Ng*2+1),             \
                       dtype = np.float)*fillValueF
 # 2D trajectory
@@ -1292,12 +1299,12 @@
                 if notfound[it] == 0:
                     ito = tvalues[it,1]
-                    slicev = ds['X'][0]+':'+str(trjpos[2,ito]) + '|' +            \
-                      ds['Y'][0]+':'+str(trjpos[1,ito]) + '|' +                   \
+                    slicev = ds['X'][0]+':'+str(trjpos[2,ito]) + '|' +               \
+                      ds['Y'][0]+':'+str(trjpos[1,ito]) + '|' +                      \
                       ds['T'][0]+':'+str(tvalues[ito,0])
                     slicevar, dimslice = slice_variable(ovs, slicev)
                     sovalues.append([ slicevar, ovo[tvalues[it,1]]])
-                    slicev = ds['X'][0] + ':' + str(trjpos[0,it]-Ng) + '@' +   \
-                      str(trjpos[0,it]+Ng) + '|' + ds['Y'][0] + ':' +          \
-                      str(trjpos[1,it]-Ng) + '@' + str(trjpos[1,it]+Ng) +    \
+                    slicev = ds['X'][0] + ':' + str(trjpos[0,it]-Ng) + '@' +         \
+                      str(trjpos[0,it]+Ng) + '|' + ds['Y'][0] + ':' +                \
+                      str(trjpos[1,it]-Ng) + '@' + str(trjpos[1,it]+Ng) +            \
                       '|' + ds['T'][0] + ':' + str(tvalues[it,0])
                     slicevar, dimslice = slice_variable(ovs, slicev)
@@ -1305,5 +1312,5 @@
                 else:
                     sovalues.append([fillValue, fillValue])
-                    soSvalues[it,:,:] = np.ones((Ng*2+1,Ng*2+1),           \
+                    soSvalues[it,:,:] = np.ones((Ng*2+1,Ng*2+1),                     \
                       dtype = np.float)*fillValueF
                 print sovalues[varsimobs][:][it]
@@ -1312,4 +1319,40 @@
         print '  ' + fname + ": observatino kind '" + okind + "' not ready!!"
         quit(-1)
+
+# Re-arranging final values 
+##
+    if kvals == 'instantaneous':
+        return sovalues, soSvalues, soTvalues, soTtvalues, trjs
+
+    elif kvals == 'tbackwardSmean':
+        fsovalues = []
+        if ds.has_key('Z'):
+            fsoSvalues = np.zeros((dimtf, Ng*2+1, Ng*2+1, Ng*2+1), dtype = np.float)
+            if okind == 'trajectory':
+                ftrjs = np.zeros((4,dimtf), dtype=int)
+            else:
+                ftrjs = None
+        else:
+            fsoSvalues = np.zeros((dimtf, Ng*2+1, Ng*2+1), dtype = np.float)
+            if okind == 'trajectory':
+                ftrjs = np.zeros((3,dimtf), dtype=int)
+            else:
+                ftrjs = None
+
+        if okind == 'single-station':
+            fsoTvalues = {}
+            fsoTtvalues = np.zeros((dimtf,2), dtype=np.float)
+        else:
+            None
+
+        for it in range(dimtf):
+            tv = uniqt(it)
+            
+
+    elif kvals == 'tbackwardOmean':
+        print '  ' + fname + ':',kvals,'!!'
+        uniqt = np.unique(tvalues[:,2])
+        dimtf = len(uniqt)
+        print '     initially we got',dimt,'values which will become',dimtf
 
 
