Index: trunk/tools/validation_sim.py
===================================================================
--- trunk/tools/validation_sim.py	(revision 495)
+++ trunk/tools/validation_sim.py	(revision 496)
@@ -1035,4 +1035,178 @@
     return
 
+def getting_ValidationValues(okind, dimt, ds, trjpos, ovs, ovo, tvalues, ofill, Ng):
+    """ Function to get the values to validate accroding to the type of observation
+      okind= observational kind
+      dimt= 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)
+      ovs= object with the values of the simulation
+      ovs= object with the values of the observations
+      tvalues= temporal values (sim. time step, obs. time step, sim t value, obs t value, t diff)
+      ofill= Fill Value for the observations
+      Ng= number of grid points around the observation
+    return:
+      sovalues= simulated values at the observation point and time
+      soSvalues= values Ngrid points around the simulated point
+      soTvalues= inital/ending period between two consecutive obsevations (for `single-station')
+      trjs= trajectory on the simulation space
+    """
+    fname = 'getting_ValidationValues'
+
+    sovalues = []
+
+# 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)
+        if okind == 'trajectory':
+            trjs = np.zeros((4,dimt), dtype=int)
+        else:
+            trjS = None
+    else:
+        soSvalues = np.zeros((dimt, Ng*2+1, Ng*2+1), dtype = np.float)
+        if okind == 'trajectory':
+            trjs = np.zeros((3,dimt), dtype=int)
+        else:
+            trjS = None
+
+    if okind == 'single-station':
+        soTvalues = {}
+        soTtvalues = np.zeros((dimt,2), dtype=np.float)
+    else:
+        None
+
+    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])
+            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) + '|' +      \
+              ds['T'][0]+':'+str(tvalues[it][0])
+            slicevar, dimslice = slice_variable(ovs, slicev)
+            soSvalues[it,:,:] = slicevar
+
+    elif okind == 'single-station':
+        for it in range(dimt):
+            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]) + '|' +                    \
+                  ds['T'][0] + ':' + str(int(tvalues[it][0]))
+            else:
+                slicev = ds['T'][0] + ':' + str(int(tvalues[it][0]))
+            slicevar, dimslice = slice_variable(ovs, slicev)
+            if ovo[int(ito)] == oFill or ovo[int(ito)] == '--':
+                sovalues.append([ slicevar, fillValueF])
+#            elif ovo[int(ito)] != ovo[int(ito)]: 
+#                sovalues.append([ slicevar, fillValueF])
+            else:
+                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) + '|' +\
+                  ds['T'][0] + ':' + str(int(tvalues[it,0]))
+            else:
+                slicev = ds['T'][0] + ':' + str(int(tvalues[it][0]))
+            slicevar, dimslice = slice_variable(ovs, slicev)
+            soSvalues[it,:,:] = slicevar
+
+            if it == 0:
+                itoi = 0
+                itof = int(tvalues[it,1]) / 2
+            elif it == dimt-1:
+                itoi = int( (ito + int(tvalues[it-1,1])) / 2)
+                itof = int(tvalues[it,1])
+            else:
+                itod = int( (ito - int(tvalues[it-1,1])) / 2 ) 
+                itoi = ito - itod
+                itod = int( (int(tvalues[it+1,1]) - ito) / 2 )
+                itof = ito + itod
+
+            slicev = ds['T'][1] + ':' + str(itoi) + '@' + str(itof + 1)
+
+            slicevar, dimslice = slice_variable(ovo, slicev)
+            soTvalues[str(it)] = slicevar
+
+            soTtvalues[it,0] = valdimobs['T'][itoi]
+            soTtvalues[it,1] = valdimobs['T'][itof]
+
+    elif okind == 'trajectory':
+        if ds.has_key('Z'):
+            for it in range(dimt):
+                ito = int(tvalues[it,1])
+                if notfound[ito] == 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]) + '|' +                   \
+                      ds['T'][0]+':'+str(int(tvalues[it,0]))
+                    slicevar, dimslice = slice_variable(ovs, slicev)
+                    sovalues.append([ slicevar, ovo[int(ito)]])
+                    minx = np.max([trjpos[0,ito]-Ng,0])
+                    maxx = np.min([trjpos[0,ito]+Ng+1,ovs.shape[3]])
+                    miny = np.max([trjpos[1,ito]-Ng,0])
+                    maxy = np.min([trjpos[1,ito]+Ng+1,ovs.shape[2]])
+                    minz = np.max([trjpos[2,ito]-Ng,0])
+                    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) + '|' +       \
+                      ds['T'][0] + ':' + str(int(tvalues[it,0]))
+                    slicevar, dimslice = slice_variable(ovs, slicev)
+
+                    sliceS = []
+                    sliceS.append(it)
+                    sliceS.append(slice(0,maxz-minz))
+                    sliceS.append(slice(0,maxy-miny))
+                    sliceS.append(slice(0,maxx-minx))
+
+                    soSvalues[tuple(sliceS)] = slicevar
+                    if ivar == 0:
+                        trjs[0,it] = trjpos[0,ito]
+                        trjs[1,it] = trjpos[1,ito]
+                        trjs[2,it] = trjpos[2,ito]
+                        trjs[3,it] = tvalues[it,0]
+                else:
+                    sovalues.append([fillValueF, fillValueF])
+                    soSvalues[it,:,:,:]= np.ones((Ng*2+1,Ng*2+1,Ng*2+1),         \
+                      dtype = np.float)*fillValueF
+# 2D trajectory
+        else:
+            for it in range(dimt):
+                if notfound[it] == 0:
+                    ito = tvalues[it,1]
+                    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) +    \
+                      '|' + ds['T'][0] + ':' + str(tvalues[it,0])
+                    slicevar, dimslice = slice_variable(ovs, slicev)
+                    soSvalues[it,:,:] = slicevar
+                else:
+                    sovalues.append([fillValue, fillValue])
+                    soSvalues[it,:,:] = np.ones((Ng*2+1,Ng*2+1),           \
+                      dtype = np.float)*fillValueF
+                print sovalues[varsimobs][:][it]
+    else:
+        print errormsg
+        print '  ' + fname + ": observatino kind '" + okind + "' not ready!!'
+        quit(-1)
+
+
+    return sovalues, soSvalues, soTvalues, trjs
+
+
 ####### ###### ##### #### ### ## #
 
@@ -1457,10 +1631,6 @@
 if dims.has_key('Z'):
     newdim = onewnc.createDimension('simtrj',4)
-    trjsim = np.zeros((4,Ncoindt), dtype=int)
-    trjsimval = np.zeros((4,Ncoindt), dtype=np.float)
 else:
     newdim = onewnc.createDimension('simtrj',3)
-    trjsim = np.zeros((3,Ncoindt), dtype=int)
-    trjsimval = np.zeros((3,Ncoindt), dtype=np.float)
 
 Nvars = len(valvars)
@@ -1498,4 +1668,10 @@
     if searchInlist(ovobs.ncattrs(),'_FillValue'): 
         oFillValue = ovobs.getncattr('_FillValue')
+
+    simobsvalues, simobsSvalues, simobsTvalues, trjsim =                             \
+        getting_ValidationValues(obskind, Ncoindt, dims, trajpos, ovsim, ovobs       \
+        coindtvalues, ofillValue, Ngrid):
+    quit(-1)
+
 
 # Simulated values spatially around coincident times
