Index: trunk/SophyaPI/PIext/pawexecut.cc
===================================================================
--- trunk/SophyaPI/PIext/pawexecut.cc	(revision 1070)
+++ trunk/SophyaPI/PIext/pawexecut.cc	(revision 1071)
@@ -136,8 +136,12 @@
 usage = "Copy content of object1 into objecft2";
 usage += "\n objects are Vector,Matrix,Histo,Histo2D";
-usage += "\n h/copy namefrom nametocopy [i1[:i2]] [j1[:j2]]";
-usage += "\n   copy obj1Dfrom(i1->i2) into obj1Dto";
-usage += "\n   copy obj2Dfrom(i1:j1->i2:j2) into obj2Dto";
-usage += "\n Warnig: elements from i1 to i2 included are copied";
+usage += "\n h/copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]";
+usage += "\n   copy obj1Dfrom(i1->i2) into obj1Dto(ic1->)";
+usage += "\n   copy obj2Dfrom(i1,j1->i2,j2) into obj2Dto(ic1,jc1->)";
+usage += "\n Warning: elements from i1 to i2 included are copied";
+usage += "\n If obj1Dto does not exist, is is created with size i2-i1+1";
+usage += "\n    or obj2Dto with size i2-i1+1,j2-j1+1";
+usage += "\n The adressed content of obj?Dfrom is overwritten";
+usage += "\n The non-adressed content of obj?Dfrom is left unchanged";
 usage += "\n  Related commands: copy";  
 piac->RegisterCommand(kw,usage,this,hgrp);
@@ -814,11 +818,16 @@
 // Pour copier un object dans un object
 // objects are Vector,Matrix,Histo,Histo2D
-//   h/copy namefrom nametocopy [i1[:i2]] [j1[:j2]]
-//   copy obj1Dfrom(i1->i2) into obj1Dto
-//   copy obj2Dfrom(i1:j1->i2:j2) into obj2Dto
+//   h/copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]
+//   copy obj1Dfrom(i1->i2) into obj1Dto(ic1->)
+//   copy obj2Dfrom(i1,j1->i2,j2) into obj2Dto(ic1,jc1->)
 // Attention: elements depuis i1 jusqu'a i2 COMPRIS
-{
-if(tokens.size()<2)
-  {cout<<"Usage: h_copy namefrom nametocopy [i1[:i2]] [j1[:j2]]"<<endl;
+// Si obj1Dto n'existe pas, il est cree avec une taille i2-i1+1
+//    ou obj2Dto avec une taille i2-i1+1,j2-j1+1
+// Le contenu de obj?Dfrom adresse est surecrit
+// Le contenu de obj?Dfrom non adresse reste le meme
+{
+  int tks = tokens.size();
+if(tks<2)
+  {cout<<"Usage: h_copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]"<<endl;
    return;}
 
@@ -828,17 +837,18 @@
   {cout<<"PAWExecutor::h_copy Error: unknow object "<<tokens[0]<<endl;
   return;}
+AnyDataObj* mobjv2 = omg.GetObj(tokens[1]);
+
+int_4 i1=0,i2=0, j1=0,j2=0, ic1=0,jc1=0, i,ii, j,jj, nx1,ny1, nx2,ny2;
 
 // Cas d'un Vector
 if(typeid(*mobjv1) == typeid(Vector)) {
-  Vector* v1 = dynamic_cast<Vector*>(mobjv1);
-  int_4 i1=0,i2=v1->NElts()-1;
-  if(tokens.size()>2) sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
-  if(i1<0) i1=0; if(i2>=(int_4)v1->NElts()) i2=v1->NElts()-1;
+  Vector* v1 = dynamic_cast<Vector*>(mobjv1); nx1 = (int_4)v1->NElts();
+  i2=nx1-1;
+  if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
+  if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1;
   if(i2<i1)
     {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2<<"] for NElts="
-         <<v1->NElts()<<endl; return;}
-  cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<") to "<<tokens[1]<<endl;
+         <<nx1<<endl; return;}
   Vector* v2 = NULL;
-  AnyDataObj* mobjv2 = omg.GetObj(tokens[1]);
   if(mobjv2==NULL)
     {v2 = new Vector(i2-i1+1); omg.AddObj(v2,tokens[1]);}
@@ -847,9 +857,12 @@
     {cout<<"PAWExecutor::h_copy Error: type mismatch for Vector "
          <<typeid(*mobjv2).name()<<endl; return;}
-  v2 = dynamic_cast<Vector*>(mobjv2);
-  if(i2-i1+1>(int_4)v2->NElts())
-    {cout<<"PAWExecutor::h_copy Error: Vector to copy to small "
-         <<v2->NElts()<<endl; return;}
-  for(int i=i1,ii=0;i<=i2;i++,ii++) (*v2)(ii) = (*v1)(i);
+  v2 = dynamic_cast<Vector*>(mobjv2); nx2 = (int_4)v2->NElts();
+  if(tks>4) if(tokens[4]!="!") sscanf(tokens[4].c_str(),"%d",&ic1);
+  if(ic1<0) ic1=0;
+  if(ic1>=nx2)
+    {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<"] for NElts="
+         <<nx2<<endl; return;}
+  cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<") to "<<tokens[1]<<"("<<ic1<<"->...)"<<endl;
+  for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++) (*v2)(ii) = (*v1)(i);
   return;
 }
@@ -857,14 +870,12 @@
 // Cas d'un Histo
 if(typeid(*mobjv1) == typeid(Histo)) {
-  Histo* v1 = dynamic_cast<Histo*>(mobjv1);
-  int_4 i1=0,i2=v1->NBins()-1;
-  if(tokens.size()>2) sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
-  if(i1<0) i1=0; if(i2>=(int_4)v1->NBins()) i2=v1->NBins()-1;
+  Histo* v1 = dynamic_cast<Histo*>(mobjv1); nx1 = (int_4)v1->NBins();
+  i2=nx1-1;
+  if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
+  if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1;
   if(i2<i1)
     {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2<<"] for NBins="
-         <<v1->NBins()<<endl; return;}
-  cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<") to "<<tokens[1]<<endl;
+         <<nx1<<endl; return;}
   Histo* v2 = NULL;
-  AnyDataObj* mobjv2 = omg.GetObj(tokens[1]);
   if(mobjv2==NULL)
     {v2 = new Histo(0.,(float)(i2-i1+1),i2-i1+1); omg.AddObj(v2,tokens[1]);}
@@ -873,9 +884,14 @@
     {cout<<"PAWExecutor::h_copy Error: type mismatch for Histo "
          <<typeid(*mobjv2).name()<<endl; return;}
-  v2 = dynamic_cast<Histo*>(mobjv2);
-  if(i2-i1+1>(int_4)v2->NBins())
-    {cout<<"PAWExecutor::h_copy Error: Histo to copy to small "
-         <<v2->NBins()<<endl; return;}
-  for(int i=i1,ii=0;i<=i2;i++,ii++) (*v2)(ii) = (*v1)(i);
+  v2 = dynamic_cast<Histo*>(mobjv2); nx2 = (int_4)v2->NBins();
+  if(v1->HasErrors() && !(v2->HasErrors())) v2->Errors();
+  if(tks>4) if(tokens[4]!="!") sscanf(tokens[4].c_str(),"%d",&ic1);
+  if(ic1<0) ic1=0;
+  if(ic1>=nx2)
+    {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<"] for NBins="
+         <<nx2<<endl; return;}
+  cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<") to "<<tokens[1]<<"("<<ic1<<"->...)"<<endl;
+  for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++)
+    {(*v2)(ii) = (*v1)(i); if(v1->HasErrors()) v2->Error2(ii) = v1->Error2(i);}
   return;
 }
@@ -883,17 +899,14 @@
 // Cas d'une Matrix
 if(typeid(*mobjv1) == typeid(Matrix)) {
-  Matrix* v1 = dynamic_cast<Matrix*>(mobjv1);
-  int_4 i1=0,i2=v1->NRows()-1, j1=0,j2=v1->NCol()-1;
-  if(tokens.size()>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
-  if(tokens.size()>3) sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2);
-  if(i1<0) i1=0; if(i2>=(int_4)v1->NRows()) i2=v1->NRows()-1;
-  if(j1<0) j1=0; if(j2>=(int_4)v1->NCol())  j2=v1->NCol()-1;
+  Matrix* v1 = dynamic_cast<Matrix*>(mobjv1); nx1=v1->NRows(); ny1=v1->NCol();
+  i2=nx1-1; j2=ny1-1;
+  if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
+  if(tks>3) if(tokens[3]!="!") sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2);
+  if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1; if(j1<0) j1=0; if(j2>=ny1) j2=ny1-1;
   if(i2<i1 || j2<j1)
     {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2
          <<"] , ["<<j1<<":"<<j2<<"] for NRows,NCol="
-         <<v1->NRows()<<" , "<<v1->NCol()<<endl; return;}
-  cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<","<<j1<<":"<<j2<<") to "<<tokens[1]<<endl;
+         <<nx1<<" , "<<ny1<<endl; return;}
   Matrix* v2 = NULL;
-  AnyDataObj* mobjv2 = omg.GetObj(tokens[1]);
   if(mobjv2==NULL)
     {v2 = new Matrix(i2-i1+1,j2-j1+1); omg.AddObj(v2,tokens[1]);}
@@ -902,10 +915,14 @@
     {cout<<"PAWExecutor::h_copy Error: type mismatch for Matrix "
          <<typeid(*mobjv2).name()<<endl; return;}
-  v2 = dynamic_cast<Matrix*>(mobjv2);
-  if(i2-i1+1>(int_4)v2->NRows() || j2-j1+1>(int_4)v2->NCol())
-    {cout<<"PAWExecutor::h_copy Error: Matrix to copy to small "
-         <<v2->NRows()<<","<<v2->NCol()<<endl; return;}
-  for(int i=i1,ii=0;i<=i2;i++,ii++)
-    for(int j=j1,jj=0;j<=j2;j++,jj++) (*v2)(ii,jj) = (*v1)(i,j);
+  v2 = dynamic_cast<Matrix*>(mobjv2); nx2=v2->NRows(); ny2=v2->NCol();
+  if(tks>4) if(tokens[4]!="!") sscanf(tokens[4].c_str(),"%d:%d",&ic1,&jc1);
+  if(ic1<0) ic1=0; if(jc1<0) jc1=0;
+  if(ic1>=nx2 || jc1>=ny2)
+    {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<","<<jc1
+         <<"] for NRows,NCol="<<nx2<<","<<ny2<<endl; return;}
+  cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<","<<j1<<":"<<j2
+      <<") to "<<tokens[1]<<"("<<ic1<<","<<jc1<<"->...)"<<endl;
+  for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++)
+    for(j=j1,jj=jc1; j<=j2 && j<ny1 && jj<ny2; j++,jj++) (*v2)(ii,jj) = (*v1)(i,j);
   return;
 }
@@ -913,17 +930,14 @@
 // Cas d'un Histo2D
 if(typeid(*mobjv1) == typeid(Histo2D)) {
-  Histo2D* v1 = dynamic_cast<Histo2D*>(mobjv1);
-  int_4 i1=0,i2=v1->NBinX()-1, j1=0,j2=v1->NBinY()-1;
-  if(tokens.size()>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
-  if(tokens.size()>3) sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2);
-  if(i1<0) i1=0; if(i2>=(int_4)v1->NBinX()) i2=v1->NBinX()-1;
-  if(j1<0) j1=0; if(j2>=(int_4)v1->NBinY())  j2=v1->NBinY()-1;
+  Histo2D* v1 = dynamic_cast<Histo2D*>(mobjv1); nx1=v1->NBinX(); ny1=v1->NBinY();
+  i2=nx1-1; j2=ny1-1;
+  if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
+  if(tks>3) if(tokens[3]!="!") sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2);
+  if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1; if(j1<0) j1=0; if(j2>=ny1) j2=ny1-1;
   if(i2<i1 || j2<j1)
     {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2
          <<"] , ["<<j1<<":"<<j2<<"] for NBinX,NBinY="
-         <<v1->NBinX()<<" , "<<v1->NBinY()<<endl; return;}
-  cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<","<<j1<<":"<<j2<<") to "<<tokens[1]<<endl;
+         <<nx1<<" , "<<ny1<<endl; return;}
   Histo2D* v2 = NULL;
-  AnyDataObj* mobjv2 = omg.GetObj(tokens[1]);
   if(mobjv2==NULL)
     {v2 = new Histo2D(0.,(float)(i2-i1+1),i2-i1+1,0.,(float)(j2-j1+1),j2-j1+1);
@@ -933,10 +947,16 @@
     {cout<<"PAWExecutor::h_copy Error: type mismatch for Histo2D"
          <<typeid(*mobjv2).name()<<endl; return;}
-  v2 = dynamic_cast<Histo2D*>(mobjv2);
-  if(i2-i1+1>(int_4)v2->NBinX() || j2-j1+1>(int_4)v2->NBinY())
-    {cout<<"PAWExecutor::h_copy Error: Histo2D to copy to small "
-         <<v2->NBinX()<<","<<v2->NBinY()<<endl; return;}
-  for(int i=i1,ii=0;i<=i2;i++,ii++)
-    for(int j=j1,jj=0;j<=j2;j++,jj++) (*v2)(ii,jj) = (*v1)(i,j);
+  v2 = dynamic_cast<Histo2D*>(mobjv2); nx2=v2->NBinX(); ny2=v2->NBinY();
+  if(v1->HasErrors() && !(v2->HasErrors())) v2->Errors();
+  if(tks>4) sscanf(tokens[4].c_str(),"%d:%d",&ic1,&jc1);
+  if(ic1<0) ic1=0; if(jc1<0) jc1=0;
+  if(ic1>=nx2 || jc1>=ny2)
+    {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<","<<jc1
+         <<"] for NBinX,NBinY="<<nx2<<","<<ny2<<endl; return;}
+  cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<","<<j1<<":"<<j2
+      <<") to "<<tokens[1]<<"("<<ic1<<","<<jc1<<"->...)"<<endl;
+  for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++)
+    for(j=j1,jj=jc1; j<=j2 && j<ny1 && jj<ny2; j++,jj++)
+      {(*v2)(ii,jj) = (*v1)(i,j); if(v1->HasErrors()) v2->Error2(ii,jj) = v1->Error2(i,j);}
   return;
 }
