Index: trunk/SophyaPI/PIext/pawexecut.cc
===================================================================
--- trunk/SophyaPI/PIext/pawexecut.cc	(revision 2707)
+++ trunk/SophyaPI/PIext/pawexecut.cc	(revision 2708)
@@ -30,4 +30,13 @@
 
 /* Reza + cmv  13/10/99 */
+
+inline bool __vector_sort_up_r8(r_8 x1,r_8 x2) {return x1<x2;}
+inline bool __vector_sort_down_r8(r_8 x1,r_8 x2) {return x1>x2;}
+inline bool __vector_sort_up_r4(r_4 x1,r_4 x2) {return x1<x2;}
+inline bool __vector_sort_down_r4(r_4 x1,r_4 x2) {return x1>x2;}
+inline bool __vector_sort_up_i4(int_4 x1,int_4 x2) {return x1<x2;}
+inline bool __vector_sort_down_i4(int_4 x1,int_4 x2) {return x1>x2;}
+inline bool __vector_sort_up_u8(uint_8 x1,uint_8 x2) {return x1<x2;}
+inline bool __vector_sort_down_u8(uint_8 x1,uint_8 x2) {return x1>x2;}
 
 uint_4 PAWExecutor::autoc_counter_ = 0;
@@ -117,5 +126,4 @@
 piac->RegisterCommand(kw,usage,this,hgrp);
 
-//#ifndef SANS_EVOLPLANCK
 kw = "v/integ";
 usage = "Integrate a TVector / vector";
@@ -124,5 +132,10 @@
 usage += "\n  Related commands: h/integ h/deriv v/deriv";
 piac->RegisterCommand(kw,usage,this,hgrp);
-//#endif
+
+kw = "v/sort";
+usage = "Sort a vector into itself";
+usage += "\n v/sort namevec [+1/-1]";
+usage += "\n \"+1\" means increasing order, \"-1\" decreasing order";
+piac->RegisterCommand(kw,usage,this,hgrp);
 
 kw = "h/deriv";
@@ -132,5 +145,4 @@
 piac->RegisterCommand(kw,usage,this,hgrp);
 
-//#ifndef SANS_EVOLPLANCK
 kw = "v/deriv";
 usage = "Derivate a TVector / vector";
@@ -141,5 +153,4 @@
 usage += "\n  Related commands: h/integ h/deriv v/integ";
 piac->RegisterCommand(kw,usage,this,hgrp);
-//#endif
 
 kw = "h/rebin";
@@ -274,14 +285,12 @@
 } else if(kw == "h/integ") {
   h_integ(tokens); return(0);
-  //#ifndef SANS_EVOLPLANCK
 } else if(kw == "v/integ") {
   v_integ(tokens); return(0);
-  //#endif
+} else if(kw == "v/sort") {
+  v_sort(tokens); return(0);
 } else if(kw == "h/deriv") {
   h_deriv(tokens); return(0);
-  //#ifndef SANS_EVOLPLANCK
 } else if(kw == "v/deriv") {
   v_deriv(tokens); return(0);
-  //#endif
 } else if(kw == "h/rebin") {
   h_rebin(tokens); return(0);
@@ -737,11 +746,5 @@
      {line[lc-1]='\0'; lc = strlen(line); if(lc<1) continue;}
 
-   // On vire les blancs au debut et a la fin
-   char *newline = line;
-   for(int i=0;i<lc;i++) if(newline[i]!=' ') {newline = &line[i]; break;}
-   lc = strlen(newline); if(lc<1) continue;
-   for(int i=lc-1;i>=0;i--) if(newline[i]==' ') newline[i]='\0'; else break;
-   lc = strlen(newline); if(lc<1) continue;
-   string const sline(newline);
+   string const sline(line);
    //cout<<"\'"<<sline<<"\'  lc="<<lc<<endl;
 
@@ -790,6 +793,8 @@
    // Decodage de la ligne
    vector<string> vs;
-   FillVStringFrString(sline,vs,separator);
+   //FillVStringFrString(sline,vs,separator);
+   SplitStringToVString(sline,vs,separator);
    int lvs = vs.size();
+   //for(int i=0;i<lvs;i++) cout<<"|"<<vs[i]<<"| "; cout<<endl;
    if(lvs<numcolmaxi) continue; // Pas assez de champs decodes, mauvaise ligne
 
@@ -954,4 +959,69 @@
 norm /= (*v)(n-1);
 for(uint_4 i=0;i<n;i++) (*v)(i) *= norm;
+}
+
+/* methode */
+void PAWExecutor::v_sort(vector<string>& tokens)
+// Pour sort in-place d'un vecteur ascendant ou descendant
+{
+ if(tokens.size()<1)
+   {cout<<"Usage: v/sort namevec [+1/-1]"<<endl; return;}
+ NamedObjMgr omg;
+ AnyDataObj* mobj = omg.GetObj(tokens[0]);
+ if(mobj==NULL)
+   {cout<<"PAWExecutor::v_sort Error: unknow object"<<tokens[0]<<endl;
+   return;}
+
+ bool up = true;
+ if(tokens.size()>=2) if(atoi(tokens[1].c_str())<0) up=false;
+
+ {
+ TVector<r_8>* v = dynamic_cast<TVector<r_8>*>(mobj);
+ if(v) {
+   if(v->Size()==0) return;
+   if(up) stable_sort(v->Data(), v->Data()+v->Size(), __vector_sort_up_r8);
+     else stable_sort(v->Data(), v->Data()+v->Size(), __vector_sort_down_r8);
+   cout<<"median is: "<<0.5*((*v)(v->Size()/2)+(*v)((v->Size()-1)/2))<<endl;
+   return;
+ }
+ }
+
+ {
+ TVector<r_4>* v = dynamic_cast<TVector<r_4>*>(mobj);
+ if(v) {
+   if(v->Size()==0) return;
+   if(up) stable_sort(v->Data(), v->Data()+v->Size(), __vector_sort_up_r4);
+     else stable_sort(v->Data(), v->Data()+v->Size(), __vector_sort_down_r4);
+   cout<<"median is: "<<0.5*((*v)(v->Size()/2)+(*v)((v->Size()-1)/2))<<endl;
+   return;
+ }
+ }
+
+ {
+ TVector<int_4>* v = dynamic_cast<TVector<int_4>*>(mobj);
+ if(v) {
+   if(v->Size()==0) return;
+   if(up) stable_sort(v->Data(), v->Data()+v->Size(), __vector_sort_up_i4);
+     else stable_sort(v->Data(), v->Data()+v->Size(), __vector_sort_down_i4);
+   cout<<"median is: "<<0.5*((*v)(v->Size()/2)+(*v)((v->Size()-1)/2))<<endl;
+   return;
+ }
+ }
+
+ {
+ TVector<uint_8>* v = dynamic_cast<TVector<uint_8>*>(mobj);
+ if(v) {
+   if(v->Size()==0) return;
+   if(up) stable_sort(v->Data(), v->Data()+v->Size(), __vector_sort_up_u8);
+     else stable_sort(v->Data(), v->Data()+v->Size(), __vector_sort_down_u8);
+   cout<<"median is: "<<0.5*((*v)(v->Size()/2)+(*v)((v->Size()-1)/2))<<endl;
+   return;
+ }
+ }
+
+ cout<<"PAWExecutor::v_sort Error: "<<tokens[0]
+     <<" not a TVector or not a supported TVector<TYPE>"<<endl;
+ return;
+
 }
 
