Index: trunk/SophyaPI/PIext/pawexecut.cc
===================================================================
--- trunk/SophyaPI/PIext/pawexecut.cc	(revision 1078)
+++ trunk/SophyaPI/PIext/pawexecut.cc	(revision 1079)
@@ -146,4 +146,32 @@
 usage += "\n The non-adressed content of obj?Dfrom is left unchanged";
 usage += "\n  Related commands: copy";  
+piac->RegisterCommand(kw,usage,this,hgrp);
+
+kw = "h/set/err";
+usage = "Set Histo,Histo2D errors for range of bins or range of values";
+usage += "\n h/set/err namehisto setvalue i1[:i2]  [j1[:j2]]";
+usage += "\n     set error to setvalue for bin range i1:i2  j1:j2";
+usage += "\n h/set/err namehisto setvalue v v1:v2";
+usage += "\n     set error to setvalue for content values range v1:v2";
+usage += "\n h/set/err namehisto setvalue e e1:e2";
+usage += "\n     set error to setvalue for error values range v1:v2";
+usage += "\n  Related commands: h/set/cont";  
+piac->RegisterCommand(kw,usage,this,hgrp);
+
+kw = "h/set/cont";
+usage = "Set Histo,Histo2D content for range of bins or range of values";
+usage += "\n h/set/cont namehisto setvalue i1[:i2]  [j1[:j2]]";
+usage += "\n     set content to setvalue for bin range i1:i2  j1:j2";
+usage += "\n h/set/cont namehisto setvalue v v1:v2";
+usage += "\n     set content to setvalue for content values range v1:v2";
+usage += "\n h/set/cont namehisto setvalue e e1:e2";
+usage += "\n     set content to setvalue for error values range v1:v2";
+usage += "\n  Related commands: h/set/err";  
+piac->RegisterCommand(kw,usage,this,hgrp);
+
+kw = "h/err";
+usage = "Set Histo,Histo2D error to function of bin content value";
+usage += "\n h/err namehisto expr_func";
+usage += "\n  Related commands: h/set/err";  
 piac->RegisterCommand(kw,usage,this,hgrp);
 
@@ -184,4 +212,12 @@
 } else if(kw == "h/copy") {
   h_copy(tokens); return(0);
+} else if(kw == "h/set/err") {
+  string dum = "err";
+  h_set(dum,tokens); return(0);
+} else if(kw == "h/set/cont") {
+  string dum = "cont";
+  h_set(dum,tokens); return(0);
+} else if(kw == "h/err") {
+  h_err(tokens); return(0);
 } else return(1); 
 }
@@ -902,5 +938,5 @@
 // Le contenu de obj?Dfrom non adresse reste le meme
 {
-  int tks = tokens.size();
+int tks = tokens.size();
 if(tks<2)
   {cout<<"Usage: h_copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]"<<endl;
@@ -1040,2 +1076,150 @@
 return;
 }
+
+/* methode */
+void PAWExecutor::h_set(string dum,vector<string>& tokens)
+// Mise de valeurs/erreurs d'un histo 1D ou 2D a une valeur donnee
+// dum = err  : on change les valeurs des erreurs
+//       cont : on change les valeurs du contenu des bins
+// tokens[0] : nom de l'histogramme
+// tokens[1] : valeur de remplacement
+// tokens[2-3] : i1:i2 j1:j2  intervalle des bins qui doivent etre remplace
+//             : v v1:v2  remplacement des bins ayant une valeur dans cet intervalle
+//             : e e1:e2  remplacement des bins ayant une erreur dans cet intervalle
+{
+int tks = tokens.size();
+if(tks<3)
+  {cout<<"Usage: h/set/[err,cont] namehisto setvalue i1[:i2]  [j1[:j2]]\n"
+       <<"                                           v v1:v2\n"
+       <<"                                           e e1:e2"
+       <<endl; return;}
+
+// Decodage arguments
+bool replerr = false; if(dum=="err") replerr = true;
+float setval = (float) atof(tokens[1].c_str());
+int testcont=0; if(tokens[2]=="v") testcont=1; if(tokens[2]=="e") testcont=2;
+int_4 i1=-1, i2=-1, j1=-1, j2=-1;
+float v1=0., v2=0.;
+if(testcont==0) {
+  sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
+  if(tks>3) sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2);
+} else {
+  if(tks<=3)
+    {cout<<"PAWExecutor::h_set Error: h/set/... v v1:v2, please give v1:v2"<<endl;
+    return;}
+  sscanf(tokens[3].c_str(),"%f:%f",&v1,&v2);
+}
+
+if(replerr) {if(setval<0.) setval = 0.; else setval *= setval;}
+if(testcont!=0 && v2<v1)
+  {cout<<"PAWExecutor::h_set Error: bad value range="<<v1<<","<<v2<<endl; return;}
+
+// identification objet
+NamedObjMgr omg;
+AnyDataObj* mobj = omg.GetObj(tokens[0]);
+if( mobj==NULL)
+  {cout<<"PAWExecutor::h_set Error: unknow object "<<tokens[0]<<endl;
+  return;}
+
+// Traitement
+if(typeid(*mobj) == typeid(Histo)) {  // Histo 1D
+  Histo* h  = dynamic_cast<Histo*>(mobj);
+  if( (replerr || testcont==2) && !(h->HasErrors()) )
+    {cout<<"PAWExecutor::h_set Error: histogram has no errors"<<endl; return;}
+  if(testcont!=0) {i1=0; i2=h->NBins()-1;}
+  if(i1<0 || i1>=h->NBins())
+    {cout<<"PAWExecutor::h_set Error: bad bin range i1="<<i1<<endl; return;}
+  if(i2<i1) i2=i1; if(i2>=h->NBins()) i2=h->NBins()-1;
+  for(int i=i1;i<=i2;i++) {
+    bool change = true;
+    if(testcont==1) {if((*h)(i)<v1 || (*h)(i)>v2) change = false;}
+    else if(testcont==2) {if(h->Error(i)<v1 || h->Error(i)>v2) change = false;}
+    if(!change) continue;
+    if(replerr) h->Error2(i) = setval; else (*h)(i) = setval;
+  }
+
+} else if(typeid(*mobj) == typeid(Histo2D)) {  // Histo 2D
+  Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
+  if( (replerr || testcont==2) && !(h2->HasErrors()) )
+    {cout<<"PAWExecutor::h_set Error: histogram has no errors"<<endl; return;}
+  if(testcont!=0) {i1=0; i2=h2->NBinX()-1;j1=0; j2=h2->NBinY()-1;}
+  if(i1<0 || i1>=h2->NBinX() || j1<0 || j1>=h2->NBinY())
+    {cout<<"PAWExecutor::h_set Error: bad bin range i1,j1="<<i1<<","<<j1<<endl; return;}
+  if(i2<i1) i2=i1; if(i2>=h2->NBinX()) i2=h2->NBinX()-1;
+  if(j2<j1) j2=j1; if(j2>=h2->NBinY()) j2=h2->NBinY()-1;
+  for(int i=i1;i<=i2;i++) for(int j=j1;j<=j2;j++) {
+    bool change = true;
+    if(testcont==1) {if((*h2)(i,j)<v1 || (*h2)(i,j)>v2) change = false;}
+    else if(testcont==2) {if(h2->Error(i,j)<v1 || h2->Error(i,j)>v2) change = false;}
+    if(!change) continue;
+    if(replerr) h2->Error2(i,j) = setval; else (*h2)(i,j) = setval;
+  }
+
+} else {
+  cout<<"PAWExecutor::h_set Error: type mismatch for Histo/Histo2D\n"
+    <<typeid(*mobj).name()<<endl;
+  return;
+}
+
+}
+
+/* methode */
+void PAWExecutor::h_err(vector<string>& tokens)
+// Mise des erreurs d'un histo 1D ou 2D a une valeur
+// donnee par une fonction de la valeur du bin
+// tokens[0] : nom de l'histogramme
+// tokens[1] : expression de la fonction
+{
+if(tokens.size()<2)
+  {cout<<"Usage: h/err namehisto expr_func"<<endl; return;}
+
+// identification objet
+NamedObjMgr omg;
+AnyDataObj* mobj = omg.GetObj(tokens[0]);
+if( mobj==NULL)
+  {cout<<"PAWExecutor::h_err Error: unknow object "<<tokens[0]<<endl;
+  return;}
+
+// Fonction
+FILE *fip = NULL;
+string expfunc = ""; {for(int i=1;i<(int)tokens.size();i++) expfunc += tokens[i];}
+string fname = "func1or2_pia_dl.c";
+string func = "func1or2_pia_dl_func";
+if((fip = fopen(fname.c_str(), "w")) == NULL)
+  {cout<<"PAWExecutor::h_err Error: open function file "<<fname<<endl;
+  return;}
+fprintf(fip,"#include <math.h>\n");
+fprintf(fip,"double %s(double x) \n{\n",func.c_str());
+fprintf(fip,"return(%s); \n}\n", expfunc.c_str());
+fclose(fip);
+DlFunctionOfX f = (DlFunctionOfX) omg.GetServiceObj()->LinkFunctionFromFile(fname,func);
+if(!f) 
+  {cout<<"PAWExecutor::h_err Error: bad function "<<func<<","<<fname<<endl;
+  return;}
+
+// Traitement
+if(typeid(*mobj) == typeid(Histo)) {  // Histo 1D
+  Histo* h  = dynamic_cast<Histo*>(mobj);
+  if(!(h->HasErrors())) h->Errors();
+  for(int i=0;i<h->NBins();i++) {
+    double x = (double) (*h)(i);
+    double e = f(x);
+    h->SetErr2(i,e*e); 
+  }
+
+} else if(typeid(*mobj) == typeid(Histo2D)) {  // Histo 2D
+  Histo2D* h2 = dynamic_cast<Histo2D*>(mobj);
+  if(!(h2->HasErrors())) h2->Errors();
+  for(int i=0;i<h2->NBinX();i++) for(int j=0;j<h2->NBinY();j++) {
+    double x = (double) (*h2)(i,j);
+    double e = f(x);
+    h2->Error2(i,j) = e*e; 
+  }
+
+} else {
+  cout<<"PAWExecutor::h_err Error: type mismatch for Histo/Histo2D\n"
+    <<typeid(*mobj).name()<<endl;
+  return;
+}
+
+}
Index: trunk/SophyaPI/PIext/pawexecut.h
===================================================================
--- trunk/SophyaPI/PIext/pawexecut.h	(revision 1078)
+++ trunk/SophyaPI/PIext/pawexecut.h	(revision 1079)
@@ -33,4 +33,6 @@
   void h_get_vec(vector<string>& tokens);
   void h_copy(vector<string>& tokens);
+  void h_set(string dum,vector<string>& tokens);
+  void h_err(vector<string>& tokens);
   int  decodepawstring(string tokens,string& nameobj
                       ,string& xexp,string& yexp,string& zexp);
