Changeset 1071 in Sophya for trunk/SophyaPI


Ignore:
Timestamp:
Jul 13, 2000, 10:56:09 PM (25 years ago)
Author:
ercodmgr
Message:

h/copy cmv 13/7/00

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaPI/PIext/pawexecut.cc

    r1070 r1071  
    136136usage = "Copy content of object1 into objecft2";
    137137usage += "\n objects are Vector,Matrix,Histo,Histo2D";
    138 usage += "\n h/copy namefrom nametocopy [i1[:i2]] [j1[:j2]]";
    139 usage += "\n   copy obj1Dfrom(i1->i2) into obj1Dto";
    140 usage += "\n   copy obj2Dfrom(i1:j1->i2:j2) into obj2Dto";
    141 usage += "\n Warnig: elements from i1 to i2 included are copied";
     138usage += "\n h/copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]";
     139usage += "\n   copy obj1Dfrom(i1->i2) into obj1Dto(ic1->)";
     140usage += "\n   copy obj2Dfrom(i1,j1->i2,j2) into obj2Dto(ic1,jc1->)";
     141usage += "\n Warning: elements from i1 to i2 included are copied";
     142usage += "\n If obj1Dto does not exist, is is created with size i2-i1+1";
     143usage += "\n    or obj2Dto with size i2-i1+1,j2-j1+1";
     144usage += "\n The adressed content of obj?Dfrom is overwritten";
     145usage += "\n The non-adressed content of obj?Dfrom is left unchanged";
    142146usage += "\n  Related commands: copy"; 
    143147piac->RegisterCommand(kw,usage,this,hgrp);
     
    814818// Pour copier un object dans un object
    815819// objects are Vector,Matrix,Histo,Histo2D
    816 //   h/copy namefrom nametocopy [i1[:i2]] [j1[:j2]]
    817 //   copy obj1Dfrom(i1->i2) into obj1Dto
    818 //   copy obj2Dfrom(i1:j1->i2:j2) into obj2Dto
     820//   h/copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]
     821//   copy obj1Dfrom(i1->i2) into obj1Dto(ic1->)
     822//   copy obj2Dfrom(i1,j1->i2,j2) into obj2Dto(ic1,jc1->)
    819823// Attention: elements depuis i1 jusqu'a i2 COMPRIS
    820 {
    821 if(tokens.size()<2)
    822   {cout<<"Usage: h_copy namefrom nametocopy [i1[:i2]] [j1[:j2]]"<<endl;
     824// Si obj1Dto n'existe pas, il est cree avec une taille i2-i1+1
     825//    ou obj2Dto avec une taille i2-i1+1,j2-j1+1
     826// Le contenu de obj?Dfrom adresse est surecrit
     827// Le contenu de obj?Dfrom non adresse reste le meme
     828{
     829  int tks = tokens.size();
     830if(tks<2)
     831  {cout<<"Usage: h_copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]"<<endl;
    823832   return;}
    824833
     
    828837  {cout<<"PAWExecutor::h_copy Error: unknow object "<<tokens[0]<<endl;
    829838  return;}
     839AnyDataObj* mobjv2 = omg.GetObj(tokens[1]);
     840
     841int_4 i1=0,i2=0, j1=0,j2=0, ic1=0,jc1=0, i,ii, j,jj, nx1,ny1, nx2,ny2;
    830842
    831843// Cas d'un Vector
    832844if(typeid(*mobjv1) == typeid(Vector)) {
    833   Vector* v1 = dynamic_cast<Vector*>(mobjv1);
    834   int_4 i1=0,i2=v1->NElts()-1;
    835   if(tokens.size()>2) sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
    836   if(i1<0) i1=0; if(i2>=(int_4)v1->NElts()) i2=v1->NElts()-1;
     845  Vector* v1 = dynamic_cast<Vector*>(mobjv1); nx1 = (int_4)v1->NElts();
     846  i2=nx1-1;
     847  if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
     848  if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1;
    837849  if(i2<i1)
    838850    {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2<<"] for NElts="
    839          <<v1->NElts()<<endl; return;}
    840   cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<") to "<<tokens[1]<<endl;
     851         <<nx1<<endl; return;}
    841852  Vector* v2 = NULL;
    842   AnyDataObj* mobjv2 = omg.GetObj(tokens[1]);
    843853  if(mobjv2==NULL)
    844854    {v2 = new Vector(i2-i1+1); omg.AddObj(v2,tokens[1]);}
     
    847857    {cout<<"PAWExecutor::h_copy Error: type mismatch for Vector "
    848858         <<typeid(*mobjv2).name()<<endl; return;}
    849   v2 = dynamic_cast<Vector*>(mobjv2);
    850   if(i2-i1+1>(int_4)v2->NElts())
    851     {cout<<"PAWExecutor::h_copy Error: Vector to copy to small "
    852          <<v2->NElts()<<endl; return;}
    853   for(int i=i1,ii=0;i<=i2;i++,ii++) (*v2)(ii) = (*v1)(i);
     859  v2 = dynamic_cast<Vector*>(mobjv2); nx2 = (int_4)v2->NElts();
     860  if(tks>4) if(tokens[4]!="!") sscanf(tokens[4].c_str(),"%d",&ic1);
     861  if(ic1<0) ic1=0;
     862  if(ic1>=nx2)
     863    {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<"] for NElts="
     864         <<nx2<<endl; return;}
     865  cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<") to "<<tokens[1]<<"("<<ic1<<"->...)"<<endl;
     866  for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++) (*v2)(ii) = (*v1)(i);
    854867  return;
    855868}
     
    857870// Cas d'un Histo
    858871if(typeid(*mobjv1) == typeid(Histo)) {
    859   Histo* v1 = dynamic_cast<Histo*>(mobjv1);
    860   int_4 i1=0,i2=v1->NBins()-1;
    861   if(tokens.size()>2) sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
    862   if(i1<0) i1=0; if(i2>=(int_4)v1->NBins()) i2=v1->NBins()-1;
     872  Histo* v1 = dynamic_cast<Histo*>(mobjv1); nx1 = (int_4)v1->NBins();
     873  i2=nx1-1;
     874  if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
     875  if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1;
    863876  if(i2<i1)
    864877    {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2<<"] for NBins="
    865          <<v1->NBins()<<endl; return;}
    866   cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<") to "<<tokens[1]<<endl;
     878         <<nx1<<endl; return;}
    867879  Histo* v2 = NULL;
    868   AnyDataObj* mobjv2 = omg.GetObj(tokens[1]);
    869880  if(mobjv2==NULL)
    870881    {v2 = new Histo(0.,(float)(i2-i1+1),i2-i1+1); omg.AddObj(v2,tokens[1]);}
     
    873884    {cout<<"PAWExecutor::h_copy Error: type mismatch for Histo "
    874885         <<typeid(*mobjv2).name()<<endl; return;}
    875   v2 = dynamic_cast<Histo*>(mobjv2);
    876   if(i2-i1+1>(int_4)v2->NBins())
    877     {cout<<"PAWExecutor::h_copy Error: Histo to copy to small "
    878          <<v2->NBins()<<endl; return;}
    879   for(int i=i1,ii=0;i<=i2;i++,ii++) (*v2)(ii) = (*v1)(i);
     886  v2 = dynamic_cast<Histo*>(mobjv2); nx2 = (int_4)v2->NBins();
     887  if(v1->HasErrors() && !(v2->HasErrors())) v2->Errors();
     888  if(tks>4) if(tokens[4]!="!") sscanf(tokens[4].c_str(),"%d",&ic1);
     889  if(ic1<0) ic1=0;
     890  if(ic1>=nx2)
     891    {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<"] for NBins="
     892         <<nx2<<endl; return;}
     893  cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<") to "<<tokens[1]<<"("<<ic1<<"->...)"<<endl;
     894  for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++)
     895    {(*v2)(ii) = (*v1)(i); if(v1->HasErrors()) v2->Error2(ii) = v1->Error2(i);}
    880896  return;
    881897}
     
    883899// Cas d'une Matrix
    884900if(typeid(*mobjv1) == typeid(Matrix)) {
    885   Matrix* v1 = dynamic_cast<Matrix*>(mobjv1);
    886   int_4 i1=0,i2=v1->NRows()-1, j1=0,j2=v1->NCol()-1;
    887   if(tokens.size()>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
    888   if(tokens.size()>3) sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2);
    889   if(i1<0) i1=0; if(i2>=(int_4)v1->NRows()) i2=v1->NRows()-1;
    890   if(j1<0) j1=0; if(j2>=(int_4)v1->NCol())  j2=v1->NCol()-1;
     901  Matrix* v1 = dynamic_cast<Matrix*>(mobjv1); nx1=v1->NRows(); ny1=v1->NCol();
     902  i2=nx1-1; j2=ny1-1;
     903  if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
     904  if(tks>3) if(tokens[3]!="!") sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2);
     905  if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1; if(j1<0) j1=0; if(j2>=ny1) j2=ny1-1;
    891906  if(i2<i1 || j2<j1)
    892907    {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2
    893908         <<"] , ["<<j1<<":"<<j2<<"] for NRows,NCol="
    894          <<v1->NRows()<<" , "<<v1->NCol()<<endl; return;}
    895   cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<","<<j1<<":"<<j2<<") to "<<tokens[1]<<endl;
     909         <<nx1<<" , "<<ny1<<endl; return;}
    896910  Matrix* v2 = NULL;
    897   AnyDataObj* mobjv2 = omg.GetObj(tokens[1]);
    898911  if(mobjv2==NULL)
    899912    {v2 = new Matrix(i2-i1+1,j2-j1+1); omg.AddObj(v2,tokens[1]);}
     
    902915    {cout<<"PAWExecutor::h_copy Error: type mismatch for Matrix "
    903916         <<typeid(*mobjv2).name()<<endl; return;}
    904   v2 = dynamic_cast<Matrix*>(mobjv2);
    905   if(i2-i1+1>(int_4)v2->NRows() || j2-j1+1>(int_4)v2->NCol())
    906     {cout<<"PAWExecutor::h_copy Error: Matrix to copy to small "
    907          <<v2->NRows()<<","<<v2->NCol()<<endl; return;}
    908   for(int i=i1,ii=0;i<=i2;i++,ii++)
    909     for(int j=j1,jj=0;j<=j2;j++,jj++) (*v2)(ii,jj) = (*v1)(i,j);
     917  v2 = dynamic_cast<Matrix*>(mobjv2); nx2=v2->NRows(); ny2=v2->NCol();
     918  if(tks>4) if(tokens[4]!="!") sscanf(tokens[4].c_str(),"%d:%d",&ic1,&jc1);
     919  if(ic1<0) ic1=0; if(jc1<0) jc1=0;
     920  if(ic1>=nx2 || jc1>=ny2)
     921    {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<","<<jc1
     922         <<"] for NRows,NCol="<<nx2<<","<<ny2<<endl; return;}
     923  cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<","<<j1<<":"<<j2
     924      <<") to "<<tokens[1]<<"("<<ic1<<","<<jc1<<"->...)"<<endl;
     925  for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++)
     926    for(j=j1,jj=jc1; j<=j2 && j<ny1 && jj<ny2; j++,jj++) (*v2)(ii,jj) = (*v1)(i,j);
    910927  return;
    911928}
     
    913930// Cas d'un Histo2D
    914931if(typeid(*mobjv1) == typeid(Histo2D)) {
    915   Histo2D* v1 = dynamic_cast<Histo2D*>(mobjv1);
    916   int_4 i1=0,i2=v1->NBinX()-1, j1=0,j2=v1->NBinY()-1;
    917   if(tokens.size()>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
    918   if(tokens.size()>3) sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2);
    919   if(i1<0) i1=0; if(i2>=(int_4)v1->NBinX()) i2=v1->NBinX()-1;
    920   if(j1<0) j1=0; if(j2>=(int_4)v1->NBinY())  j2=v1->NBinY()-1;
     932  Histo2D* v1 = dynamic_cast<Histo2D*>(mobjv1); nx1=v1->NBinX(); ny1=v1->NBinY();
     933  i2=nx1-1; j2=ny1-1;
     934  if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2);
     935  if(tks>3) if(tokens[3]!="!") sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2);
     936  if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1; if(j1<0) j1=0; if(j2>=ny1) j2=ny1-1;
    921937  if(i2<i1 || j2<j1)
    922938    {cout<<"PAWExecutor::h_copy Error: wrong range ["<<i1<<":"<<i2
    923939         <<"] , ["<<j1<<":"<<j2<<"] for NBinX,NBinY="
    924          <<v1->NBinX()<<" , "<<v1->NBinY()<<endl; return;}
    925   cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<","<<j1<<":"<<j2<<") to "<<tokens[1]<<endl;
     940         <<nx1<<" , "<<ny1<<endl; return;}
    926941  Histo2D* v2 = NULL;
    927   AnyDataObj* mobjv2 = omg.GetObj(tokens[1]);
    928942  if(mobjv2==NULL)
    929943    {v2 = new Histo2D(0.,(float)(i2-i1+1),i2-i1+1,0.,(float)(j2-j1+1),j2-j1+1);
     
    933947    {cout<<"PAWExecutor::h_copy Error: type mismatch for Histo2D"
    934948         <<typeid(*mobjv2).name()<<endl; return;}
    935   v2 = dynamic_cast<Histo2D*>(mobjv2);
    936   if(i2-i1+1>(int_4)v2->NBinX() || j2-j1+1>(int_4)v2->NBinY())
    937     {cout<<"PAWExecutor::h_copy Error: Histo2D to copy to small "
    938          <<v2->NBinX()<<","<<v2->NBinY()<<endl; return;}
    939   for(int i=i1,ii=0;i<=i2;i++,ii++)
    940     for(int j=j1,jj=0;j<=j2;j++,jj++) (*v2)(ii,jj) = (*v1)(i,j);
     949  v2 = dynamic_cast<Histo2D*>(mobjv2); nx2=v2->NBinX(); ny2=v2->NBinY();
     950  if(v1->HasErrors() && !(v2->HasErrors())) v2->Errors();
     951  if(tks>4) sscanf(tokens[4].c_str(),"%d:%d",&ic1,&jc1);
     952  if(ic1<0) ic1=0; if(jc1<0) jc1=0;
     953  if(ic1>=nx2 || jc1>=ny2)
     954    {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<<ic1<<","<<jc1
     955         <<"] for NBinX,NBinY="<<nx2<<","<<ny2<<endl; return;}
     956  cout<<"copy "<<tokens[0]<<"("<<i1<<":"<<i2<<","<<j1<<":"<<j2
     957      <<") to "<<tokens[1]<<"("<<ic1<<","<<jc1<<"->...)"<<endl;
     958  for(i=i1,ii=ic1; i<=i2 && i<nx1 && ii<nx2; i++,ii++)
     959    for(j=j1,jj=jc1; j<=j2 && j<ny1 && jj<ny2; j++,jj++)
     960      {(*v2)(ii,jj) = (*v1)(i,j); if(v1->HasErrors()) v2->Error2(ii,jj) = v1->Error2(i,j);}
    941961  return;
    942962}
Note: See TracChangeset for help on using the changeset viewer.