Back to index

salome-med  6.5.0
MEDCouplingMemArray.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "MEDCouplingMemArray.txx"
00021 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
00022 
00023 #include "GenMathFormulae.hxx"
00024 #include "InterpKernelExprParser.hxx"
00025 
00026 #include <set>
00027 #include <cmath>
00028 #include <limits>
00029 #include <numeric>
00030 #include <functional>
00031 
00032 typedef double (*MYFUNCPTR)(double);
00033 
00034 using namespace ParaMEDMEM;
00035 
00036 template<int SPACEDIM>
00037 void DataArrayDouble::findCommonTuplesAlg(std::vector<double>& bbox,
00038                                           int nbNodes, int limitNodeId, double prec, std::vector<int>& c, std::vector<int>& cI) const
00039 {
00040   const double *coordsPtr=getConstPointer();
00041   BBTree<SPACEDIM,int> myTree(&bbox[0],0,0,nbNodes,-prec);
00042   double bb[2*SPACEDIM];
00043   double prec2=prec*prec;
00044   std::vector<bool> isDone(nbNodes);
00045   for(int i=0;i<nbNodes;i++)
00046     {
00047       if(!isDone[i])
00048         {
00049           for(int j=0;j<SPACEDIM;j++)
00050             {
00051               bb[2*j]=coordsPtr[SPACEDIM*i+j];
00052               bb[2*j+1]=coordsPtr[SPACEDIM*i+j];
00053             }
00054           std::vector<int> intersectingElems;
00055           myTree.getIntersectingElems(bb,intersectingElems);
00056           if(intersectingElems.size()>1)
00057             {
00058               std::vector<int> commonNodes;
00059               for(std::vector<int>::const_iterator it=intersectingElems.begin();it!=intersectingElems.end();it++)
00060                 if(*it!=i)
00061                   if(*it>=limitNodeId)
00062                     if(INTERP_KERNEL::distance2<SPACEDIM>(coordsPtr+SPACEDIM*i,coordsPtr+SPACEDIM*(*it))<prec2)
00063                       {
00064                         commonNodes.push_back(*it);
00065                         isDone[*it]=true;
00066                       }
00067               if(!commonNodes.empty())
00068                 {
00069                   cI.push_back(cI.back()+(int)commonNodes.size()+1);
00070                   c.push_back(i);
00071                   c.insert(c.end(),commonNodes.begin(),commonNodes.end());
00072                 }
00073             }
00074         }
00075     }
00076 }
00077 
00078 void DataArray::setName(const char *name)
00079 {
00080   _name=name;
00081 }
00082 
00083 void DataArray::copyStringInfoFrom(const DataArray& other) throw(INTERP_KERNEL::Exception)
00084 {
00085   if(_info_on_compo.size()!=other._info_on_compo.size())
00086     throw INTERP_KERNEL::Exception("Size of arrays mismatches on copyStringInfoFrom !");
00087   _name=other._name;
00088   _info_on_compo=other._info_on_compo;
00089 }
00090 
00091 void DataArray::copyPartOfStringInfoFrom(const DataArray& other, const std::vector<int>& compoIds) throw(INTERP_KERNEL::Exception)
00092 {
00093   int nbOfCompoOth=other.getNumberOfComponents();
00094   std::size_t newNbOfCompo=compoIds.size();
00095   for(std::size_t i=0;i<newNbOfCompo;i++)
00096     if(compoIds[i]>=nbOfCompoOth || compoIds[i]<0)
00097       {
00098         std::ostringstream oss; oss << "Specified component id is out of range (" << compoIds[i] << ") compared with nb of actual components (" << nbOfCompoOth << ")";
00099         throw INTERP_KERNEL::Exception(oss.str().c_str());
00100       }
00101   for(std::size_t i=0;i<newNbOfCompo;i++)
00102     setInfoOnComponent((int)i,other.getInfoOnComponent(compoIds[i]).c_str());
00103 }
00104 
00105 void DataArray::copyPartOfStringInfoFrom2(const std::vector<int>& compoIds, const DataArray& other) throw(INTERP_KERNEL::Exception)
00106 {
00107   int nbOfCompo=getNumberOfComponents();
00108   std::size_t partOfCompoToSet=compoIds.size();
00109   if((int)partOfCompoToSet!=other.getNumberOfComponents())
00110     throw INTERP_KERNEL::Exception("Given compoIds has not the same size as number of components of given array !");
00111   for(std::size_t i=0;i<partOfCompoToSet;i++)
00112     if(compoIds[i]>=nbOfCompo || compoIds[i]<0)
00113       {
00114         std::ostringstream oss; oss << "Specified component id is out of range (" << compoIds[i] << ") compared with nb of actual components (" << nbOfCompo << ")";
00115         throw INTERP_KERNEL::Exception(oss.str().c_str());
00116       }
00117   for(std::size_t i=0;i<partOfCompoToSet;i++)
00118     setInfoOnComponent(compoIds[i],other.getInfoOnComponent((int)i).c_str());
00119 }
00120 
00121 bool DataArray::areInfoEquals(const DataArray& other) const
00122 {
00123   if(_nb_of_tuples!=other._nb_of_tuples)
00124     return false;
00125   if(_name!=other._name)
00126     return false;
00127   return _info_on_compo==other._info_on_compo;
00128 }
00129 
00130 void DataArray::reprWithoutNameStream(std::ostream& stream) const
00131 {
00132   stream << "Number of components : "<< getNumberOfComponents() << "\n";
00133   stream << "Info of these components : ";
00134   for(std::vector<std::string>::const_iterator iter=_info_on_compo.begin();iter!=_info_on_compo.end();iter++)
00135     stream << "\"" << *iter << "\"   ";
00136   stream << "\n";
00137 }
00138 
00139 void DataArray::setInfoOnComponents(const std::vector<std::string>& info) throw(INTERP_KERNEL::Exception)
00140 {
00141   if(getNumberOfComponents()!=(int)info.size())
00142     {
00143       std::ostringstream oss; oss << "DataArray::setInfoOnComponents : input is of size " << info.size() << " whereas number of components is equal to " << getNumberOfComponents() << " !";
00144       throw INTERP_KERNEL::Exception(oss.str().c_str());
00145     }
00146   _info_on_compo=info;
00147 }
00148 
00149 std::vector<std::string> DataArray::getVarsOnComponent() const
00150 {
00151   int nbOfCompo=(int)_info_on_compo.size();
00152   std::vector<std::string> ret(nbOfCompo);
00153   for(int i=0;i<nbOfCompo;i++)
00154     ret[i]=getVarOnComponent(i);
00155   return ret;
00156 }
00157 
00158 std::vector<std::string> DataArray::getUnitsOnComponent() const
00159 {
00160   int nbOfCompo=(int)_info_on_compo.size();
00161   std::vector<std::string> ret(nbOfCompo);
00162   for(int i=0;i<nbOfCompo;i++)
00163     ret[i]=getUnitOnComponent(i);
00164   return ret;
00165 }
00166 
00167 std::string DataArray::getInfoOnComponent(int i) const throw(INTERP_KERNEL::Exception)
00168 {
00169   if(i<(int)_info_on_compo.size() && i>=0)
00170     return _info_on_compo[i];
00171   else
00172     {
00173       std::ostringstream oss; oss << "DataArray::getInfoOnComponent : Specified component id is out of range (" << i << ") compared with nb of actual components (" << (int) _info_on_compo.size();
00174       throw INTERP_KERNEL::Exception(oss.str().c_str());
00175     }
00176 }
00177 
00182 std::string DataArray::getVarOnComponent(int i) const throw(INTERP_KERNEL::Exception)
00183 {
00184   if(i<(int)_info_on_compo.size() && i>=0)
00185     {
00186       return GetVarNameFromInfo(_info_on_compo[i]);
00187     }
00188   else
00189     {
00190       std::ostringstream oss; oss << "DataArray::getVarOnComponent : Specified component id is out of range  (" << i << ") compared with nb of actual components (" << (int) _info_on_compo.size();
00191       throw INTERP_KERNEL::Exception(oss.str().c_str());
00192     }
00193 }
00194 
00199 std::string DataArray::getUnitOnComponent(int i) const throw(INTERP_KERNEL::Exception)
00200 {
00201   if(i<(int)_info_on_compo.size() && i>=0)
00202     {
00203       return GetUnitFromInfo(_info_on_compo[i]);
00204     }
00205   else
00206     {
00207       std::ostringstream oss; oss << "DataArray::getUnitOnComponent : Specified component id is out of range  (" << i << ") compared with nb of actual components (" << (int) _info_on_compo.size();
00208       throw INTERP_KERNEL::Exception(oss.str().c_str());
00209     }
00210 }
00211 
00212 std::string DataArray::GetVarNameFromInfo(const std::string& info) throw(INTERP_KERNEL::Exception)
00213 {
00214   std::size_t p1=info.find_last_of('[');
00215   std::size_t p2=info.find_last_of(']');
00216   if(p1==std::string::npos || p2==std::string::npos)
00217     return info;
00218   if(p1>p2)
00219     return info;
00220   if(p1==0)
00221     return std::string();
00222   std::size_t p3=info.find_last_not_of(' ',p1-1);
00223   return info.substr(0,p3+1);
00224 }
00225 
00226 std::string DataArray::GetUnitFromInfo(const std::string& info) throw(INTERP_KERNEL::Exception)
00227 {
00228   std::size_t p1=info.find_last_of('[');
00229   std::size_t p2=info.find_last_of(']');
00230   if(p1==std::string::npos || p2==std::string::npos)
00231     return std::string();
00232   if(p1>p2)
00233     return std::string();
00234   return info.substr(p1+1,p2-p1-1);
00235 }
00236 
00237 void DataArray::setInfoOnComponent(int i, const char *info) throw(INTERP_KERNEL::Exception)
00238 {
00239   if(i<(int)_info_on_compo.size() && i>=0)
00240     _info_on_compo[i]=info;
00241   else
00242     {
00243       std::ostringstream oss; oss << "DataArray::setInfoOnComponent : Specified component id is out of range  (" << i << ") compared with nb of actual components (" << (int) _info_on_compo.size();
00244       throw INTERP_KERNEL::Exception(oss.str().c_str());
00245     }
00246 }
00247 
00248 void DataArray::checkNbOfTuplesAndComp(const DataArray& other, const char *msg) const throw(INTERP_KERNEL::Exception)
00249 {
00250    if(getNumberOfTuples()!=other.getNumberOfTuples())
00251     {
00252       std::ostringstream oss; oss << msg << " : mismatch number of tuples : expected " <<  other.getNumberOfTuples() << " having " << getNumberOfTuples() << " !";
00253       throw INTERP_KERNEL::Exception(oss.str().c_str());
00254     }
00255   if(getNumberOfComponents()!=other.getNumberOfComponents())
00256     {
00257       std::ostringstream oss; oss << msg << " : mismatch number of components : expected " << other.getNumberOfComponents() << " having " << getNumberOfComponents() << " !";
00258       throw INTERP_KERNEL::Exception(oss.str().c_str());
00259     }
00260 }
00261 
00262 void DataArray::checkNbOfTuplesAndComp(int nbOfTuples, int nbOfCompo, const char *msg) const throw(INTERP_KERNEL::Exception)
00263 {
00264   if(getNumberOfTuples()!=nbOfTuples)
00265     {
00266       std::ostringstream oss; oss << msg << " : mismatch number of tuples : expected " <<  nbOfTuples << " having " << getNumberOfTuples() << " !";
00267       throw INTERP_KERNEL::Exception(oss.str().c_str());
00268     }
00269   if(getNumberOfComponents()!=nbOfCompo)
00270     {
00271       std::ostringstream oss; oss << msg << " : mismatch number of components : expected " << nbOfCompo << " having " << getNumberOfComponents() << " !";
00272       throw INTERP_KERNEL::Exception(oss.str().c_str());
00273     }
00274 }
00275 
00276 void DataArray::checkNbOfElems(int nbOfElems, const char *msg) const throw(INTERP_KERNEL::Exception)
00277 {
00278   if(getNbOfElems()!=nbOfElems)
00279     {
00280       std::ostringstream oss; oss << msg << " : mismatch number of elems : Expected " << nbOfElems << " having " << getNbOfElems() << " !";
00281       throw INTERP_KERNEL::Exception(oss.str().c_str());
00282     }
00283 }
00284 
00285 void DataArray::CheckValueInRange(int ref, int value, const char *msg) throw(INTERP_KERNEL::Exception)
00286 {
00287   if(value<0 || value>=ref)
00288     {
00289       std::ostringstream oss; oss << "DataArray::CheckValueInRange : " << msg  << " ! Expected in range [0," << ref << "[ having " << value << " !";
00290       throw INTERP_KERNEL::Exception(oss.str().c_str());
00291     }
00292 }
00293 
00294 void DataArray::CheckClosingParInRange(int ref, int value, const char *msg) throw(INTERP_KERNEL::Exception)
00295 {
00296   if(value<0 || value>ref)
00297     {
00298       std::ostringstream oss; oss << "DataArray::CheckClosingParInRange : " << msg  << " ! Expected a range in [0," << ref << "] having closing open parenthesis " << value << " !";
00299       throw INTERP_KERNEL::Exception(oss.str().c_str());
00300     }
00301 }
00302 
00303 int DataArray::GetNumberOfItemGivenBES(int begin, int end, int step, const char *msg) throw(INTERP_KERNEL::Exception)
00304 {
00305   if(end<begin)
00306     {
00307       std::ostringstream oss; oss << msg << " : end before begin !";
00308       throw INTERP_KERNEL::Exception(oss.str().c_str());
00309     }
00310   if(step<=0)
00311     {
00312       std::ostringstream oss; oss << msg << " : invalid step should be > 0 !";
00313       throw INTERP_KERNEL::Exception(oss.str().c_str());
00314     }
00315   return (end-1-begin)/step+1;
00316 }
00317 
00318 int DataArray::GetNumberOfItemGivenBESRelative(int begin, int end, int step, const char *msg) throw(INTERP_KERNEL::Exception)
00319 {
00320   if(step==0)
00321     throw INTERP_KERNEL::Exception("DataArray::GetNumberOfItemGivenBES : step=0 is not allowed !");
00322   if(end<begin && step>0)
00323     {
00324       std::ostringstream oss; oss << msg << " : end before begin whereas step is positive !";
00325       throw INTERP_KERNEL::Exception(oss.str().c_str());
00326     }
00327   if(begin<end && step<0)
00328     {
00329       std::ostringstream oss; oss << msg << " : invalid step should be > 0 !";
00330       throw INTERP_KERNEL::Exception(oss.str().c_str());
00331     }
00332   if(begin!=end)
00333     return (std::max(begin,end)-1-std::min(begin,end))/std::abs(step)+1;
00334   else
00335     return 0;
00336 }
00337 
00338 DataArrayDouble *DataArrayDouble::New()
00339 {
00340   return new DataArrayDouble;
00341 }
00342 
00343 bool DataArrayDouble::isAllocated() const
00344 {
00345   return getConstPointer()!=0;
00346 }
00347 
00348 void DataArrayDouble::checkAllocated() const throw(INTERP_KERNEL::Exception)
00349 {
00350   if(!isAllocated())
00351     throw INTERP_KERNEL::Exception("DataArrayDouble::checkAllocated : Array is defined but not allocated ! Call alloc or setValues method first !");
00352 }
00353 
00360 void DataArrayDouble::setInfoAndChangeNbOfCompo(const std::vector<std::string>& info) throw(INTERP_KERNEL::Exception)
00361 {
00362   if(getNumberOfComponents()!=(int)info.size())
00363     {
00364       if(!isAllocated())
00365         _info_on_compo=info;
00366       else
00367         {
00368           std::ostringstream oss; oss << "DataArrayDouble::setInfoAndChangeNbOfCompo : input is of size " << info.size() << " whereas number of components is equal to " << getNumberOfComponents() << "  and this is already allocated !";
00369           throw INTERP_KERNEL::Exception(oss.str().c_str());
00370         }
00371     }
00372   else
00373     _info_on_compo=info;
00374 }
00375 
00380 double DataArrayDouble::doubleValue() const throw(INTERP_KERNEL::Exception)
00381 {
00382   if(isAllocated())
00383     {
00384       if(getNbOfElems()==1)
00385         {
00386           return *getConstPointer();
00387         }
00388       else
00389         throw INTERP_KERNEL::Exception("DataArrayDouble::doubleValue : DataArrayDouble instance is allocated but number of elements is not equal to 1 !");
00390     }
00391   else
00392     throw INTERP_KERNEL::Exception("DataArrayDouble::doubleValue : DataArrayDouble instance is not allocated !");
00393 }
00394 
00399 bool DataArrayDouble::empty() const throw(INTERP_KERNEL::Exception)
00400 {
00401   checkAllocated();
00402   return getNumberOfTuples()==0;
00403 }
00404 
00405 DataArrayDouble *DataArrayDouble::deepCpy() const
00406 {
00407   return new DataArrayDouble(*this);
00408 }
00409 
00410 DataArrayDouble *DataArrayDouble::performCpy(bool dCpy) const
00411 {
00412   if(dCpy)
00413     return deepCpy();
00414   else
00415     {
00416       incrRef();
00417       return const_cast<DataArrayDouble *>(this);
00418     }
00419 }
00420 
00421 void DataArrayDouble::cpyFrom(const DataArrayDouble& other) throw(INTERP_KERNEL::Exception)
00422 {
00423   other.checkAllocated();
00424   int nbOfTuples=other.getNumberOfTuples();
00425   int nbOfComp=other.getNumberOfComponents();
00426   allocIfNecessary(nbOfTuples,nbOfComp);
00427   int nbOfElems=nbOfTuples*nbOfComp;
00428   double *pt=getPointer();
00429   const double *ptI=other.getConstPointer();
00430   for(int i=0;i<nbOfElems;i++)
00431     pt[i]=ptI[i];
00432   copyStringInfoFrom(other);
00433 }
00434 
00435 void DataArrayDouble::allocIfNecessary(int nbOfTuple, int nbOfCompo)
00436 {
00437   if(isAllocated())
00438     {
00439       if(nbOfTuple!=getNumberOfTuples() || nbOfCompo!=getNumberOfComponents())
00440         alloc(nbOfTuple,nbOfCompo);
00441     }
00442   else
00443     alloc(nbOfTuple,nbOfCompo);
00444 }
00445 
00446 void DataArrayDouble::alloc(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception)
00447 {
00448   if(nbOfTuple<0 || nbOfCompo<0)
00449     throw INTERP_KERNEL::Exception("DataArrayDouble::alloc : request for negative length of data !");
00450   _nb_of_tuples=nbOfTuple;
00451   _info_on_compo.resize(nbOfCompo);
00452   _mem.alloc(nbOfCompo*_nb_of_tuples);
00453   declareAsNew();
00454 }
00455 
00456 void DataArrayDouble::fillWithZero() throw(INTERP_KERNEL::Exception)
00457 {
00458   checkAllocated();
00459   _mem.fillWithValue(0.);
00460   declareAsNew();
00461 }
00462 
00463 void DataArrayDouble::fillWithValue(double val) throw(INTERP_KERNEL::Exception)
00464 {
00465   checkAllocated();
00466   _mem.fillWithValue(val);
00467   declareAsNew();
00468 }
00469 
00470 void DataArrayDouble::iota(double init) throw(INTERP_KERNEL::Exception)
00471 {
00472   checkAllocated();
00473   if(getNumberOfComponents()!=1)
00474     throw INTERP_KERNEL::Exception("DataArrayDouble::iota : works only for arrays with only one component, you can call 'rearrange' method before !");
00475   double *ptr=getPointer();
00476   int ntuples=getNumberOfTuples();
00477   for(int i=0;i<ntuples;i++)
00478     ptr[i]=init+double(i);
00479   declareAsNew();
00480 }
00481 
00482 bool DataArrayDouble::isUniform(double val, double eps) const throw(INTERP_KERNEL::Exception)
00483 {
00484   checkAllocated();
00485   if(getNumberOfComponents()!=1)
00486     throw INTERP_KERNEL::Exception("DataArrayDouble::isUniform : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before !");
00487   int nbOfTuples=getNumberOfTuples();
00488   const double *w=getConstPointer();
00489   const double *end2=w+nbOfTuples;
00490   const double vmin=val-eps;
00491   const double vmax=val+eps;
00492   for(;w!=end2;w++)
00493     if(*w<vmin || *w>vmax)
00494       return false;
00495   return true;
00496 }
00497 
00498 void DataArrayDouble::sort() throw(INTERP_KERNEL::Exception)
00499 {
00500   checkAllocated();
00501   if(getNumberOfComponents()!=1)
00502     throw INTERP_KERNEL::Exception("DataArrayDouble::sort : only supported with 'this' array with ONE component !");
00503   _mem.sort();
00504 }
00505 
00506 void DataArrayDouble::reverse() throw(INTERP_KERNEL::Exception)
00507 {
00508   checkAllocated();
00509   if(getNumberOfComponents()!=1)
00510     throw INTERP_KERNEL::Exception("DataArrayDouble::reverse : only supported with 'this' array with ONE component !");
00511   _mem.reverse();
00512 }
00513 
00519  void DataArrayDouble::checkMonotonic(bool increasing, double eps) const throw(INTERP_KERNEL::Exception)
00520 {
00521   if(!isMonotonic(increasing, eps))
00522     {
00523       if (increasing)
00524         {
00525           throw INTERP_KERNEL::Exception("DataArrayDouble::checkMonotonic : 'this' is not INCREASING monotonic !");
00526         }
00527       else
00528         {
00529           throw INTERP_KERNEL::Exception("DataArrayDouble::checkMonotonic : 'this' is not DECREASING monotonic !");
00530         }
00531     }
00532 }
00533 
00538 bool DataArrayDouble::isMonotonic(bool increasing, double eps) const throw(INTERP_KERNEL::Exception)
00539 {
00540   checkAllocated();
00541   if(getNumberOfComponents()!=1)
00542     throw INTERP_KERNEL::Exception("DataArrayDouble::isMonotonic : only supported with 'this' array with ONE component !");
00543   int nbOfElements=getNumberOfTuples();
00544   const double *ptr=getConstPointer();
00545   if(nbOfElements==0)
00546     return true;
00547   double ref=ptr[0];
00548   double absEps=fabs(eps);
00549   if (increasing)
00550     {
00551       for(int i=1;i<nbOfElements;i++)
00552         {
00553           if(ptr[i]<(ref+absEps)) return false;
00554           ref=ptr[i];
00555         }
00556       return true;
00557     }
00558   else
00559     {
00560       for(int i=1;i<nbOfElements;i++)
00561         {
00562           if(ptr[i]>(ref-absEps)) return false;
00563           ref=ptr[i];
00564         }
00565       return true;
00566     }
00567 }
00568 
00569 std::string DataArrayDouble::repr() const
00570 {
00571   std::ostringstream ret;
00572   reprStream(ret);
00573   return ret.str();
00574 }
00575 
00576 std::string DataArrayDouble::reprZip() const
00577 {
00578   std::ostringstream ret;
00579   reprZipStream(ret);
00580   return ret.str();
00581 }
00582 
00583 void DataArrayDouble::writeVTK(std::ostream& ofs, int indent, const char *nameInFile) const throw(INTERP_KERNEL::Exception)
00584 {
00585   std::string idt(indent,' ');
00586   ofs.precision(15);
00587   ofs << idt << "<DataArray type=\"Float32\" Name=\"" << nameInFile << "\" NumberOfComponents=\"" << getNumberOfComponents() << "\"";
00588   ofs << " format=\"ascii\" RangeMin=\"" << getMinValueInArray() << "\" RangeMax=\"" << getMaxValueInArray() << "\">\n" << idt;
00589   std::copy(begin(),end(),std::ostream_iterator<double>(ofs," "));
00590   ofs << std::endl << idt << "</DataArray>\n";
00591 }
00592 
00593 void DataArrayDouble::reprStream(std::ostream& stream) const
00594 {
00595   stream << "Name of double array : \"" << _name << "\"\n";
00596   reprWithoutNameStream(stream);
00597 }
00598 
00599 void DataArrayDouble::reprZipStream(std::ostream& stream) const
00600 {
00601   stream << "Name of double array : \"" << _name << "\"\n";
00602   reprZipWithoutNameStream(stream);
00603 }
00604 
00605 void DataArrayDouble::reprWithoutNameStream(std::ostream& stream) const
00606 {
00607   DataArray::reprWithoutNameStream(stream);
00608   stream.precision(15);
00609   _mem.repr(getNumberOfComponents(),stream);
00610 }
00611 
00612 void DataArrayDouble::reprZipWithoutNameStream(std::ostream& stream) const
00613 {
00614   DataArray::reprWithoutNameStream(stream);
00615   stream.precision(15);
00616   _mem.reprZip(getNumberOfComponents(),stream);
00617 }
00618 
00619 bool DataArrayDouble::isEqual(const DataArrayDouble& other, double prec) const
00620 {
00621   if(!areInfoEquals(other))
00622     return false;
00623   return _mem.isEqual(other._mem,prec);
00624 }
00625 
00626 bool DataArrayDouble::isEqualWithoutConsideringStr(const DataArrayDouble& other, double prec) const
00627 {
00628   return _mem.isEqual(other._mem,prec);
00629 }
00630 
00631 void DataArrayDouble::reAlloc(int nbOfTuples) throw(INTERP_KERNEL::Exception)
00632 {
00633   checkAllocated();
00634   _mem.reAlloc((int)(_info_on_compo.size())*nbOfTuples);
00635   _nb_of_tuples=nbOfTuples;
00636   declareAsNew();
00637 }
00638 
00639 DataArrayInt *DataArrayDouble::convertToIntArr() const
00640 {
00641   DataArrayInt *ret=DataArrayInt::New();
00642   ret->alloc(getNumberOfTuples(),getNumberOfComponents());
00643   int nbOfVals=getNbOfElems();
00644   const double *src=getConstPointer();
00645   int *dest=ret->getPointer();
00646   std::copy(src,src+nbOfVals,dest);
00647   ret->copyStringInfoFrom(*this);
00648   return ret;
00649 }
00650 
00651 DataArrayDouble *DataArrayDouble::fromNoInterlace() const throw(INTERP_KERNEL::Exception)
00652 {
00653   if(_mem.isNull())
00654     throw INTERP_KERNEL::Exception("DataArrayDouble::fromNoInterlace : Not defined array !");
00655   double *tab=_mem.fromNoInterlace(getNumberOfComponents());
00656   DataArrayDouble *ret=DataArrayDouble::New();
00657   ret->useArray(tab,true,CPP_DEALLOC,getNumberOfTuples(),getNumberOfComponents());
00658   return ret;
00659 }
00660 
00661 DataArrayDouble *DataArrayDouble::toNoInterlace() const throw(INTERP_KERNEL::Exception)
00662 {
00663   if(_mem.isNull())
00664     throw INTERP_KERNEL::Exception("DataArrayDouble::fromNoInterlace : Not defined array !");
00665   double *tab=_mem.toNoInterlace(getNumberOfComponents());
00666   DataArrayDouble *ret=DataArrayDouble::New();
00667   ret->useArray(tab,true,CPP_DEALLOC,getNumberOfTuples(),getNumberOfComponents());
00668   return ret;
00669 }
00670 
00675 void DataArrayDouble::renumberInPlace(const int *old2New)
00676 {
00677   int nbTuples=getNumberOfTuples();
00678   int nbOfCompo=getNumberOfComponents();
00679   double *tmp=new double[nbTuples*nbOfCompo];
00680   const double *iptr=getConstPointer();
00681   for(int i=0;i<nbTuples;i++)
00682     std::copy(iptr+nbOfCompo*i,iptr+nbOfCompo*(i+1),tmp+nbOfCompo*old2New[i]);
00683   std::copy(tmp,tmp+nbTuples*nbOfCompo,getPointer());
00684   delete [] tmp;
00685   declareAsNew();
00686 }
00687 
00692 void DataArrayDouble::renumberInPlaceR(const int *new2Old)
00693 {
00694   int nbTuples=getNumberOfTuples();
00695   int nbOfCompo=getNumberOfComponents();
00696   double *tmp=new double[nbTuples*nbOfCompo];
00697   const double *iptr=getConstPointer();
00698   for(int i=0;i<nbTuples;i++)
00699     std::copy(iptr+nbOfCompo*new2Old[i],iptr+nbOfCompo*(new2Old[i]+1),tmp+nbOfCompo*i);
00700   std::copy(tmp,tmp+nbTuples*nbOfCompo,getPointer());
00701   delete [] tmp;
00702   declareAsNew();
00703 }
00704 
00709 DataArrayDouble *DataArrayDouble::renumber(const int *old2New) const
00710 {
00711   int nbTuples=getNumberOfTuples();
00712   int nbOfCompo=getNumberOfComponents();
00713   DataArrayDouble *ret=DataArrayDouble::New();
00714   ret->alloc(nbTuples,nbOfCompo);
00715   ret->copyStringInfoFrom(*this);
00716   const double *iptr=getConstPointer();
00717   double *optr=ret->getPointer();
00718   for(int i=0;i<nbTuples;i++)
00719     std::copy(iptr+nbOfCompo*i,iptr+nbOfCompo*(i+1),optr+nbOfCompo*old2New[i]);
00720   ret->copyStringInfoFrom(*this);
00721   return ret;
00722 }
00723 
00728 DataArrayDouble *DataArrayDouble::renumberR(const int *new2Old) const
00729 {
00730   int nbTuples=getNumberOfTuples();
00731   int nbOfCompo=getNumberOfComponents();
00732   DataArrayDouble *ret=DataArrayDouble::New();
00733   ret->alloc(nbTuples,nbOfCompo);
00734   ret->copyStringInfoFrom(*this);
00735   const double *iptr=getConstPointer();
00736   double *optr=ret->getPointer();
00737   for(int i=0;i<nbTuples;i++)
00738     std::copy(iptr+nbOfCompo*new2Old[i],iptr+nbOfCompo*(new2Old[i]+1),optr+i*nbOfCompo);
00739   ret->copyStringInfoFrom(*this);
00740   return ret;
00741 }
00742 
00749 DataArrayDouble *DataArrayDouble::renumberAndReduce(const int *old2New, int newNbOfTuple) const
00750 {
00751   int nbTuples=getNumberOfTuples();
00752   int nbOfCompo=getNumberOfComponents();
00753   DataArrayDouble *ret=DataArrayDouble::New();
00754   ret->alloc(newNbOfTuple,nbOfCompo);
00755   const double *iptr=getConstPointer();
00756   double *optr=ret->getPointer();
00757   for(int i=0;i<nbTuples;i++)
00758     {
00759       int w=old2New[i];
00760       if(w>=0)
00761         std::copy(iptr+i*nbOfCompo,iptr+(i+1)*nbOfCompo,optr+w*nbOfCompo);
00762     }
00763   ret->copyStringInfoFrom(*this);
00764   return ret;
00765 }
00766 
00771 DataArrayDouble *DataArrayDouble::selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const
00772 {
00773   DataArrayDouble *ret=DataArrayDouble::New();
00774   int nbComp=getNumberOfComponents();
00775   ret->alloc((int)std::distance(new2OldBg,new2OldEnd),nbComp);
00776   ret->copyStringInfoFrom(*this);
00777   double *pt=ret->getPointer();
00778   const double *srcPt=getConstPointer();
00779   int i=0;
00780   for(const int *w=new2OldBg;w!=new2OldEnd;w++,i++)
00781     std::copy(srcPt+(*w)*nbComp,srcPt+((*w)+1)*nbComp,pt+i*nbComp);
00782   ret->copyStringInfoFrom(*this);
00783   return ret;
00784 }
00785 
00789 DataArrayDouble *DataArrayDouble::selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const throw(INTERP_KERNEL::Exception)
00790 {
00791   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
00792   int nbComp=getNumberOfComponents();
00793   int oldNbOfTuples=getNumberOfTuples();
00794   ret->alloc((int)std::distance(new2OldBg,new2OldEnd),nbComp);
00795   ret->copyStringInfoFrom(*this);
00796   double *pt=ret->getPointer();
00797   const double *srcPt=getConstPointer();
00798   int i=0;
00799   for(const int *w=new2OldBg;w!=new2OldEnd;w++,i++)
00800     if(*w>=0 && *w<oldNbOfTuples)
00801       std::copy(srcPt+(*w)*nbComp,srcPt+((*w)+1)*nbComp,pt+i*nbComp);
00802     else
00803       throw INTERP_KERNEL::Exception("DataArrayInt::selectByTupleIdSafe : some ids has been detected to be out of [0,this->getNumberOfTuples) !");
00804   ret->copyStringInfoFrom(*this);
00805   ret->incrRef();
00806   return ret;
00807 }
00808 
00814 DataArrayDouble *DataArrayDouble::selectByTupleId2(int bg, int end2, int step) const throw(INTERP_KERNEL::Exception)
00815 {
00816   if(end2<bg)
00817     throw INTERP_KERNEL::Exception("DataArrayDouble::selectByTupleId2 : end before begin !");
00818   if(step<=0)
00819     throw INTERP_KERNEL::Exception("DataArrayDouble::selectByTupleId2 : invalid step should > 0 !");
00820   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
00821   int nbComp=getNumberOfComponents();
00822   int newNbOfTuples=(end2-1-bg)/step+1;
00823   ret->alloc(newNbOfTuples,nbComp);
00824   double *pt=ret->getPointer();
00825   const double *srcPt=getConstPointer()+bg*nbComp;
00826   for(int i=0;i<newNbOfTuples;i++,srcPt+=step*nbComp)
00827     std::copy(srcPt,srcPt+nbComp,pt+i*nbComp);
00828   ret->copyStringInfoFrom(*this);
00829   ret->incrRef();
00830   return ret;
00831 }
00832 
00838 DataArrayDouble *DataArrayDouble::selectByTupleRanges(const std::vector<std::pair<int,int> >& ranges) const throw(INTERP_KERNEL::Exception)
00839 {
00840   checkAllocated();
00841   int nbOfComp=getNumberOfComponents();
00842   int nbOfTuplesThis=getNumberOfTuples();
00843   if(ranges.empty())
00844     {
00845       DataArrayDouble *ret=DataArrayDouble::New();
00846       ret->alloc(0,nbOfComp);
00847       ret->copyStringInfoFrom(*this);
00848       return ret;
00849     }
00850   int ref=ranges.front().first;
00851   int nbOfTuples=0;
00852   bool isIncreasing=true;
00853   for(std::vector<std::pair<int,int> >::const_iterator it=ranges.begin();it!=ranges.end();it++)
00854     {
00855       if((*it).first<=(*it).second)
00856         {
00857           if((*it).first>=0 && (*it).second<=nbOfTuplesThis)
00858             {
00859               nbOfTuples+=(*it).second-(*it).first;
00860               if(isIncreasing)
00861                 isIncreasing=ref<=(*it).first;
00862               ref=(*it).second;
00863             }
00864           else
00865             {
00866               std::ostringstream oss; oss << "DataArrayDouble::selectByTupleRanges : on range #" << std::distance(ranges.begin(),it);
00867               oss << " (" << (*it).first << "," << (*it).second << ") is greater than number of tuples of this :" << nbOfTuples << " !";
00868               throw INTERP_KERNEL::Exception(oss.str().c_str());
00869             }
00870         }
00871       else
00872         {
00873           std::ostringstream oss; oss << "DataArrayDouble::selectByTupleRanges : on range #" << std::distance(ranges.begin(),it);
00874           oss << " (" << (*it).first << "," << (*it).second << ") end is before begin !";
00875           throw INTERP_KERNEL::Exception(oss.str().c_str());
00876         }
00877     }
00878   if(isIncreasing && nbOfTuplesThis==nbOfTuples)
00879     return deepCpy();
00880   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret=DataArrayDouble::New();
00881   ret->alloc(nbOfTuples,nbOfComp);
00882   ret->copyStringInfoFrom(*this);
00883   const double *src=getConstPointer();
00884   double *work=ret->getPointer();
00885   for(std::vector<std::pair<int,int> >::const_iterator it=ranges.begin();it!=ranges.end();it++)
00886     work=std::copy(src+(*it).first*nbOfComp,src+(*it).second*nbOfComp,work);
00887   ret->incrRef();
00888   return ret;
00889 }
00890 
00896 DataArrayDouble *DataArrayDouble::substr(int tupleIdBg, int tupleIdEnd) const throw(INTERP_KERNEL::Exception)
00897 {
00898   int nbt=getNumberOfTuples();
00899   if(tupleIdBg<0)
00900     throw INTERP_KERNEL::Exception("DataArrayInt::substr : The tupleIdBg parameter must be greater than 0 !");
00901   if(tupleIdBg>nbt)
00902     throw INTERP_KERNEL::Exception("DataArrayInt::substr : The tupleIdBg parameter is greater than number of tuples !");
00903   int trueEnd=tupleIdEnd;
00904   if(tupleIdEnd!=-1)
00905     {
00906       if(tupleIdEnd>nbt)
00907         throw INTERP_KERNEL::Exception("DataArrayInt::substr : The tupleIdBg parameter is greater or equal than number of tuples !");
00908     }
00909   else
00910     trueEnd=nbt;
00911   int nbComp=getNumberOfComponents();
00912   DataArrayDouble *ret=DataArrayDouble::New();
00913   ret->alloc(trueEnd-tupleIdBg,nbComp);
00914   ret->copyStringInfoFrom(*this);
00915   std::copy(getConstPointer()+tupleIdBg*nbComp,getConstPointer()+trueEnd*nbComp,ret->getPointer());
00916   return ret;
00917 }
00918 
00924 DataArrayDouble *DataArrayDouble::changeNbOfComponents(int newNbOfComp, double dftValue) const throw(INTERP_KERNEL::Exception)
00925 {
00926   checkAllocated();
00927   DataArrayDouble *ret=DataArrayDouble::New();
00928   ret->alloc(getNumberOfTuples(),newNbOfComp);
00929   const double *oldc=getConstPointer();
00930   double *nc=ret->getPointer();
00931   int nbOfTuples=getNumberOfTuples();
00932   int oldNbOfComp=getNumberOfComponents();
00933   int dim=std::min(oldNbOfComp,newNbOfComp);
00934   for(int i=0;i<nbOfTuples;i++)
00935     {
00936       int j=0;
00937       for(;j<dim;j++)
00938         nc[newNbOfComp*i+j]=oldc[i*oldNbOfComp+j];
00939       for(;j<newNbOfComp;j++)
00940         nc[newNbOfComp*i+j]=dftValue;
00941     }
00942   ret->setName(getName().c_str());
00943   for(int i=0;i<dim;i++)
00944     ret->setInfoOnComponent(i,getInfoOnComponent(i).c_str());
00945   ret->setName(getName().c_str());
00946   return ret;
00947 }
00948 
00956 void DataArrayDouble::rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception)
00957 {
00958   checkAllocated();
00959   int nbOfElems=getNbOfElems();
00960   if(nbOfElems%newNbOfCompo!=0)
00961     throw INTERP_KERNEL::Exception("DataArrayDouble::rearrange : nbOfElems%newNbOfCompo!=0 !");
00962   _nb_of_tuples=nbOfElems/newNbOfCompo;
00963   _info_on_compo.clear();
00964   _info_on_compo.resize(newNbOfCompo);
00965   declareAsNew();
00966 }
00967 
00973 void DataArrayDouble::transpose() throw(INTERP_KERNEL::Exception)
00974 {
00975   checkAllocated();
00976   int nbOfTuples=getNumberOfTuples();
00977   rearrange(nbOfTuples);
00978 }
00979 
00980 DataArrayDouble *DataArrayDouble::keepSelectedComponents(const std::vector<int>& compoIds) const throw(INTERP_KERNEL::Exception)
00981 {
00982   checkAllocated();
00983   MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret(DataArrayDouble::New());
00984   std::size_t newNbOfCompo=compoIds.size();
00985   int oldNbOfCompo=getNumberOfComponents();
00986   for(std::vector<int>::const_iterator it=compoIds.begin();it!=compoIds.end();it++)
00987     if((*it)<0 || (*it)>=oldNbOfCompo)
00988       {
00989         std::ostringstream oss; oss << "DataArrayDouble::keepSelectedComponents : invalid requested component : " << *it << " whereas it should be in [0," << oldNbOfCompo << ") !";
00990         throw INTERP_KERNEL::Exception(oss.str().c_str());
00991       }
00992   int nbOfTuples=getNumberOfTuples();
00993   ret->alloc(nbOfTuples,(int)newNbOfCompo);
00994   ret->copyPartOfStringInfoFrom(*this,compoIds);
00995   const double *oldc=getConstPointer();
00996   double *nc=ret->getPointer();
00997   for(int i=0;i<nbOfTuples;i++)
00998     for(std::size_t j=0;j<newNbOfCompo;j++,nc++)
00999       *nc=oldc[i*oldNbOfCompo+compoIds[j]];
01000   ret->incrRef();
01001   return ret;
01002 }
01003 
01010 void DataArrayDouble::meldWith(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception)
01011 {
01012   checkAllocated();
01013   other->checkAllocated();
01014   int nbOfTuples=getNumberOfTuples();
01015   if(nbOfTuples!=other->getNumberOfTuples())
01016     throw INTERP_KERNEL::Exception("DataArrayDouble::meldWith : mismatch of number of tuples !");
01017   int nbOfComp1=getNumberOfComponents();
01018   int nbOfComp2=other->getNumberOfComponents();
01019   double *newArr=new double[nbOfTuples*(nbOfComp1+nbOfComp2)];
01020   double *w=newArr;
01021   const double *inp1=getConstPointer();
01022   const double *inp2=other->getConstPointer();
01023   for(int i=0;i<nbOfTuples;i++,inp1+=nbOfComp1,inp2+=nbOfComp2)
01024     {
01025       w=std::copy(inp1,inp1+nbOfComp1,w);
01026       w=std::copy(inp2,inp2+nbOfComp2,w);
01027     }
01028   useArray(newArr,true,CPP_DEALLOC,nbOfTuples,nbOfComp1+nbOfComp2);
01029   std::vector<int> compIds(nbOfComp2);
01030   for(int i=0;i<nbOfComp2;i++)
01031     compIds[i]=nbOfComp1+i;
01032   copyPartOfStringInfoFrom2(compIds,*other);
01033 }
01034 
01050 void DataArrayDouble::findCommonTuples(double prec, int limitTupleId, DataArrayInt *&comm, DataArrayInt *&commIndex) const throw(INTERP_KERNEL::Exception)
01051 {
01052   checkAllocated();
01053   int nbOfCompo=getNumberOfComponents();
01054   if ((nbOfCompo<1) || (nbOfCompo>3)) //test before work
01055     throw INTERP_KERNEL::Exception("DataArrayDouble::findCommonTuples : Unexpected spacedim of coords. Must be 1, 2 or 3.");
01056   
01057   int nbOfTuples=getNumberOfTuples();
01058   comm=DataArrayInt::New();
01059   commIndex=DataArrayInt::New();
01060   //
01061   std::vector<double> bbox(2*nbOfTuples*nbOfCompo);
01062   const double *coordsPtr=getConstPointer();
01063   for(int i=0;i<nbOfTuples;i++)
01064     {
01065       for(int j=0;j<nbOfCompo;j++)
01066         {
01067           bbox[2*nbOfCompo*i+2*j]=coordsPtr[nbOfCompo*i+j];
01068           bbox[2*nbOfCompo*i+2*j+1]=coordsPtr[nbOfCompo*i+j];
01069         }
01070     }
01071   //
01072   std::vector<int> c,cI(1);
01073   switch(nbOfCompo)
01074     {
01075     case 3:
01076       findCommonTuplesAlg<3>(bbox,nbOfTuples,limitTupleId,prec,c,cI);
01077       break;
01078     case 2:
01079       findCommonTuplesAlg<2>(bbox,nbOfTuples,limitTupleId,prec,c,cI);
01080       break;
01081     case 1:
01082       findCommonTuplesAlg<1>(bbox,nbOfTuples,limitTupleId,prec,c,cI);
01083       break;
01084     //default: test yet
01085     }
01086   commIndex->alloc((int)cI.size(),1);
01087   std::copy(cI.begin(),cI.end(),commIndex->getPointer());
01088   comm->alloc(cI.back(),1);
01089   std::copy(c.begin(),c.end(),comm->getPointer());
01090 }
01091 
01101 DataArrayDouble *DataArrayDouble::getDifferentValues(double prec, int limitTupleId) const throw(INTERP_KERNEL::Exception)
01102 {
01103   DataArrayInt *c0=0,*cI0=0;
01104   findCommonTuples(prec,limitTupleId,c0,cI0);
01105   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c(c0),cI(cI0);
01106   int newNbOfTuples=-1;
01107   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n=DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(getNumberOfTuples(),c0,cI0,newNbOfTuples);
01108   return renumberAndReduce(o2n->getConstPointer(),newNbOfTuples);
01109 }
01110 
01111 void DataArrayDouble::setSelectedComponents(const DataArrayDouble *a, const std::vector<int>& compoIds) throw(INTERP_KERNEL::Exception)
01112 {
01113   copyPartOfStringInfoFrom2(compoIds,*a);
01114   std::size_t partOfCompoSz=compoIds.size();
01115   int nbOfCompo=getNumberOfComponents();
01116   int nbOfTuples=getNumberOfTuples();
01117   const double *ac=a->getConstPointer();
01118   double *nc=getPointer();
01119   for(int i=0;i<nbOfTuples;i++)
01120     for(std::size_t j=0;j<partOfCompoSz;j++,ac++)
01121       nc[nbOfCompo*i+compoIds[j]]=*ac;
01122 }
01123 
01128 void DataArrayDouble::setPartOfValues1(const DataArrayDouble *a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
01129 {
01130   const char msg[]="DataArrayDouble::setPartOfValues1";
01131   checkAllocated();
01132   a->checkAllocated();
01133   int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
01134   int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
01135   int nbComp=getNumberOfComponents();
01136   int nbOfTuples=getNumberOfTuples();
01137   DataArray::CheckValueInRange(nbOfTuples,bgTuples,"invalid begin tuple value");
01138   DataArray::CheckClosingParInRange(nbOfTuples,endTuples,"invalid end tuple value");
01139   DataArray::CheckValueInRange(nbComp,bgComp,"invalid begin component value");
01140   DataArray::CheckClosingParInRange(nbComp,endComp,"invalid end component value");
01141   a->checkNbOfElems(newNbOfTuples*newNbOfComp,msg);
01142   if(strictCompoCompare)
01143     a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
01144   double *pt=getPointer()+bgTuples*nbComp+bgComp;
01145   const double *srcPt=a->getConstPointer();
01146   for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
01147     for(int j=0;j<newNbOfComp;j++,srcPt++)
01148       pt[j*stepComp]=*srcPt;
01149 }
01150 
01154 void DataArrayDouble::setPartOfValuesSimple1(double a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception)
01155 {
01156   const char msg[]="DataArrayDouble::setPartOfValuesSimple1";
01157   checkAllocated();
01158   int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
01159   int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
01160   int nbComp=getNumberOfComponents();
01161   int nbOfTuples=getNumberOfTuples();
01162   DataArray::CheckValueInRange(nbOfTuples,bgTuples,"invalid begin tuple value");
01163   DataArray::CheckClosingParInRange(nbOfTuples,endTuples,"invalid end tuple value");
01164   DataArray::CheckValueInRange(nbComp,bgComp,"invalid begin component value");
01165   DataArray::CheckClosingParInRange(nbComp,endComp,"invalid end component value");
01166   double *pt=getPointer()+bgTuples*nbComp+bgComp;
01167   for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
01168     for(int j=0;j<newNbOfComp;j++)
01169       pt[j*stepComp]=a;
01170 }
01171 
01176 void DataArrayDouble::setPartOfValues2(const DataArrayDouble *a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
01177 {
01178   const char msg[]="DataArrayDouble::setPartOfValues2";
01179   checkAllocated();
01180   a->checkAllocated();
01181   int nbComp=getNumberOfComponents();
01182   int nbOfTuples=getNumberOfTuples();
01183   for(const int *z=bgComp;z!=endComp;z++)
01184     DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
01185   int newNbOfTuples=(int)std::distance(bgTuples,endTuples);
01186   int newNbOfComp=(int)std::distance(bgComp,endComp);
01187   bool assignTech=true;
01188   if(a->getNbOfElems()==newNbOfTuples*newNbOfComp)
01189     {
01190       if(strictCompoCompare)
01191         a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
01192     }
01193   else
01194     {
01195       a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
01196       assignTech=false;
01197     }
01198   double *pt=getPointer();
01199   const double *srcPt=a->getConstPointer();
01200   if(assignTech)
01201     {    
01202       for(const int *w=bgTuples;w!=endTuples;w++)
01203         {
01204           DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
01205           for(const int *z=bgComp;z!=endComp;z++,srcPt++)
01206             {    
01207               pt[(*w)*nbComp+(*z)]=*srcPt;
01208             }
01209         }
01210     }
01211   else
01212     {
01213       for(const int *w=bgTuples;w!=endTuples;w++)
01214         {
01215           const double *srcPt2=srcPt;
01216           DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
01217           for(const int *z=bgComp;z!=endComp;z++,srcPt2++)
01218             {    
01219               pt[(*w)*nbComp+(*z)]=*srcPt2;
01220             }
01221         }
01222     }
01223 }
01224 
01228 void DataArrayDouble::setPartOfValuesSimple2(double a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp) throw(INTERP_KERNEL::Exception)
01229 {
01230   checkAllocated();
01231   int nbComp=getNumberOfComponents();
01232   int nbOfTuples=getNumberOfTuples();
01233   for(const int *z=bgComp;z!=endComp;z++)
01234     DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
01235   double *pt=getPointer();
01236   for(const int *w=bgTuples;w!=endTuples;w++)
01237     for(const int *z=bgComp;z!=endComp;z++)
01238       {
01239         DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
01240         pt[(*w)*nbComp+(*z)]=a;
01241       }
01242 }
01243 
01248 void DataArrayDouble::setPartOfValues3(const DataArrayDouble *a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
01249 {
01250   const char msg[]="DataArrayDouble::setPartOfValues3";
01251   checkAllocated();
01252   a->checkAllocated();
01253   int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
01254   int nbComp=getNumberOfComponents();
01255   int nbOfTuples=getNumberOfTuples();
01256   DataArray::CheckValueInRange(nbComp,bgComp,"invalid begin component value");
01257   DataArray::CheckClosingParInRange(nbComp,endComp,"invalid end component value");
01258   int newNbOfTuples=(int)std::distance(bgTuples,endTuples);
01259   bool assignTech=true;
01260   if(a->getNbOfElems()==newNbOfTuples*newNbOfComp)
01261     {
01262       if(strictCompoCompare)
01263         a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
01264     }
01265   else
01266     {
01267       a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
01268       assignTech=false;
01269     }
01270   double *pt=getPointer()+bgComp;
01271   const double *srcPt=a->getConstPointer();
01272   if(assignTech)
01273     {
01274       for(const int *w=bgTuples;w!=endTuples;w++)
01275         for(int j=0;j<newNbOfComp;j++,srcPt++)
01276           {
01277             DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
01278             pt[(*w)*nbComp+j*stepComp]=*srcPt;
01279           }
01280     }
01281   else
01282     {
01283       for(const int *w=bgTuples;w!=endTuples;w++)
01284         {
01285           const double *srcPt2=srcPt;
01286           for(int j=0;j<newNbOfComp;j++,srcPt2++)
01287             {
01288               DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
01289               pt[(*w)*nbComp+j*stepComp]=*srcPt2;
01290             }
01291         }
01292     }
01293 }
01294 
01298 void DataArrayDouble::setPartOfValuesSimple3(double a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception)
01299 {
01300   const char msg[]="DataArrayDouble::setPartOfValuesSimple3";
01301   checkAllocated();
01302   int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
01303   int nbComp=getNumberOfComponents();
01304   int nbOfTuples=getNumberOfTuples();
01305   DataArray::CheckValueInRange(nbComp,bgComp,"invalid begin component value");
01306   DataArray::CheckClosingParInRange(nbComp,endComp,"invalid end component value");
01307   double *pt=getPointer()+bgComp;
01308   for(const int *w=bgTuples;w!=endTuples;w++)
01309     for(int j=0;j<newNbOfComp;j++)
01310       {
01311         DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
01312         pt[(*w)*nbComp+j*stepComp]=a;
01313       }
01314 }
01315 
01321 void DataArrayDouble::setPartOfValuesAdv(const DataArrayDouble *a, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception)
01322 {
01323   checkAllocated();
01324   a->checkAllocated();
01325   tuplesSelec->checkAllocated();
01326   int nbOfComp=getNumberOfComponents();
01327   if(nbOfComp!=a->getNumberOfComponents())
01328     throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValuesAdv : This and a do not have the same number of components !");
01329   if(tuplesSelec->getNumberOfComponents()!=2)
01330     throw INTERP_KERNEL::Exception("DataArrayDouble::setPartOfValuesAdv : Expecting to have a tuple selector DataArrayInt instance with exactly 2 components !");
01331   int thisNt=getNumberOfTuples();
01332   int aNt=a->getNumberOfTuples();
01333   double *valsToSet=getPointer();
01334   const double *valsSrc=a->getConstPointer();
01335   for(const int *tuple=tuplesSelec->begin();tuple!=tuplesSelec->end();tuple+=2)
01336     {
01337       if(tuple[1]>=0 && tuple[1]<aNt)
01338         {
01339           if(tuple[0]>=0 && tuple[0]<thisNt)
01340             std::copy(valsSrc+nbOfComp*tuple[1],valsSrc+nbOfComp*(tuple[1]+1),valsToSet+nbOfComp*tuple[0]);
01341           else
01342             {
01343               std::ostringstream oss; oss << "DataArrayDouble::setPartOfValuesAdv : Tuple #" << std::distance(tuplesSelec->begin(),tuple)/2;
01344               oss << " of 'tuplesSelec' request of tuple id #" << tuple[0] << " in 'this' ! It should be in [0," << thisNt << ") !";
01345               throw INTERP_KERNEL::Exception(oss.str().c_str());
01346             }
01347         }
01348       else
01349         {
01350           std::ostringstream oss; oss << "DataArrayDouble::setPartOfValuesAdv : Tuple #" << std::distance(tuplesSelec->begin(),tuple)/2;
01351           oss << " of 'tuplesSelec' request of tuple id #" << tuple[1] << " in 'a' ! It should be in [0," << aNt << ") !";
01352           throw INTERP_KERNEL::Exception(oss.str().c_str());
01353         }
01354     }
01355 }
01356 
01363 void DataArrayDouble::setContigPartOfSelectedValues(int tupleIdStart, const DataArrayDouble *a, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception)
01364 {
01365   checkAllocated();
01366   a->checkAllocated();
01367   tuplesSelec->checkAllocated();
01368   int nbOfComp=getNumberOfComponents();
01369   if(nbOfComp!=a->getNumberOfComponents())
01370     throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues : This and a do not have the same number of components !");
01371   if(tuplesSelec->getNumberOfComponents()!=1)
01372     throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues : Expecting to have a tuple selector DataArrayInt instance with exactly 1 component !");
01373   int thisNt=getNumberOfTuples();
01374   int aNt=a->getNumberOfTuples();
01375   int nbOfTupleToWrite=tuplesSelec->getNumberOfTuples();
01376   double *valsToSet=getPointer()+tupleIdStart*nbOfComp;
01377   if(tupleIdStart+nbOfTupleToWrite>thisNt)
01378     throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues : invalid number range of values to write !");
01379   const double *valsSrc=a->getConstPointer();
01380   for(const int *tuple=tuplesSelec->begin();tuple!=tuplesSelec->end();tuple++,valsToSet+=nbOfComp)
01381     {
01382       if(*tuple>=0 && *tuple<aNt)
01383         {
01384           std::copy(valsSrc+nbOfComp*(*tuple),valsSrc+nbOfComp*(*tuple+1),valsToSet);
01385         }
01386       else
01387         {
01388           std::ostringstream oss; oss << "DataArrayDouble::setContigPartOfSelectedValues : Tuple #" << std::distance(tuplesSelec->begin(),tuple);
01389           oss << " of 'tuplesSelec' request of tuple id #" << *tuple << " in 'a' ! It should be in [0," << aNt << ") !";
01390           throw INTERP_KERNEL::Exception(oss.str().c_str());
01391         }
01392     }
01393 }
01394 
01401 void DataArrayDouble::setContigPartOfSelectedValues2(int tupleIdStart, const DataArrayDouble *a, int bg, int end2, int step) throw(INTERP_KERNEL::Exception)
01402 {
01403   checkAllocated();
01404   a->checkAllocated();
01405   int nbOfComp=getNumberOfComponents();
01406   const char msg[]="DataArrayDouble::setContigPartOfSelectedValues2";
01407   int nbOfTupleToWrite=DataArray::GetNumberOfItemGivenBES(bg,end2,step,msg);
01408   if(nbOfComp!=a->getNumberOfComponents())
01409     throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues2 : This and a do not have the same number of components !");
01410   int thisNt=getNumberOfTuples();
01411   int aNt=a->getNumberOfTuples();
01412   double *valsToSet=getPointer()+tupleIdStart*nbOfComp;
01413   if(tupleIdStart+nbOfTupleToWrite>thisNt)
01414     throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues2 : invalid number range of values to write !");
01415   if(end2>aNt)
01416     throw INTERP_KERNEL::Exception("DataArrayDouble::setContigPartOfSelectedValues2 : invalid range of values to read !");
01417   const double *valsSrc=a->getConstPointer()+bg*nbOfComp;
01418   for(int i=0;i<nbOfTupleToWrite;i++,valsToSet+=nbOfComp,valsSrc+=step*nbOfComp)
01419     {
01420       std::copy(valsSrc,valsSrc+nbOfComp,valsToSet);
01421     }
01422 }
01423 
01429 double DataArrayDouble::getIJSafe(int tupleId, int compoId) const throw(INTERP_KERNEL::Exception)
01430 {
01431   checkAllocated();
01432   if(tupleId<0 || tupleId>=getNumberOfTuples())
01433     {
01434       std::ostringstream oss; oss << "DataArrayDouble::getIJSafe : request for tupleId " << tupleId << " should be in [0," << getNumberOfTuples() << ") !";
01435       throw INTERP_KERNEL::Exception(oss.str().c_str());
01436     }
01437   if(compoId<0 || compoId>=getNumberOfComponents())
01438     {
01439       std::ostringstream oss; oss << "DataArrayDouble::getIJSafe : request for compoId " << compoId << " should be in [0," << getNumberOfComponents() << ") !";
01440       throw INTERP_KERNEL::Exception(oss.str().c_str());
01441     }
01442   return _mem[tupleId*((int)_info_on_compo.size())+compoId];
01443 }
01444 
01450 double DataArrayDouble::back() const throw(INTERP_KERNEL::Exception)
01451 {
01452   checkAllocated();
01453   if(getNumberOfComponents()!=1)
01454     throw INTERP_KERNEL::Exception("DataArrayDouble::back : number of components not equal to one !");
01455   int nbOfTuples=getNumberOfTuples();
01456   if(nbOfTuples<1)
01457     throw INTERP_KERNEL::Exception("DataArrayDouble::back : number of tuples must be >= 1 !");
01458   return *(getConstPointer()+nbOfTuples-1);
01459 }
01460 
01461 void DataArrayDouble::SetArrayIn(DataArrayDouble *newArray, DataArrayDouble* &arrayToSet)
01462 {
01463   if(newArray!=arrayToSet)
01464     {
01465       if(arrayToSet)
01466         arrayToSet->decrRef();
01467       arrayToSet=newArray;
01468       if(arrayToSet)
01469         arrayToSet->incrRef();
01470     }
01471 }
01472 
01473 void DataArrayDouble::useArray(const double *array, bool ownership,  DeallocType type, int nbOfTuple, int nbOfCompo)
01474 {
01475   _nb_of_tuples=nbOfTuple;
01476   _info_on_compo.resize(nbOfCompo);
01477   _mem.useArray(array,ownership,type,nbOfTuple*nbOfCompo);
01478   declareAsNew();
01479 }
01480 
01481 void DataArrayDouble::checkNoNullValues() const throw(INTERP_KERNEL::Exception)
01482 {
01483   const double *tmp=getConstPointer();
01484   int nbOfElems=getNbOfElems();
01485   const double *where=std::find(tmp,tmp+nbOfElems,0.);
01486   if(where!=tmp+nbOfElems)
01487     throw INTERP_KERNEL::Exception("A value 0.0 have been detected !");
01488 }
01489 
01498 void DataArrayDouble::getMinMaxPerComponent(double *bounds) const throw(INTERP_KERNEL::Exception)
01499 {
01500   checkAllocated();
01501   int dim=getNumberOfComponents();
01502   for (int idim=0; idim<dim; idim++)
01503     {
01504       bounds[idim*2]=std::numeric_limits<double>::max();
01505       bounds[idim*2+1]=-std::numeric_limits<double>::max();
01506     } 
01507   const double *ptr=getConstPointer();
01508   int nbOfTuples=getNumberOfTuples();
01509   for(int i=0;i<nbOfTuples;i++)
01510     {
01511       for(int idim=0;idim<dim;idim++)
01512         {
01513           if(bounds[idim*2]>ptr[i*dim+idim])
01514             {
01515               bounds[idim*2]=ptr[i*dim+idim];
01516             }
01517           if(bounds[idim*2+1]<ptr[i*dim+idim])
01518             {
01519               bounds[idim*2+1]=ptr[i*dim+idim];
01520             }
01521         }
01522     }
01523 }
01524 
01525 double DataArrayDouble::getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exception)
01526 {
01527   if(getNumberOfComponents()!=1)
01528     throw INTERP_KERNEL::Exception("DataArrayDouble::getMaxValue : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before or call 'getMaxValueInArray' method !");
01529   int nbOfTuples=getNumberOfTuples();
01530   if(nbOfTuples<=0)
01531     throw INTERP_KERNEL::Exception("DataArrayDouble::getMaxValue : array exists but number of tuples must be > 0 !");
01532   const double *vals=getConstPointer();
01533   const double *loc=std::max_element(vals,vals+nbOfTuples);
01534   tupleId=(int)std::distance(vals,loc);
01535   return *loc;
01536 }
01537 
01541 double DataArrayDouble::getMaxValueInArray() const throw(INTERP_KERNEL::Exception)
01542 {
01543   checkAllocated();
01544   const double *loc=std::max_element(begin(),end());
01545   return *loc;
01546 }
01547 
01548 double DataArrayDouble::getMaxValue2(DataArrayInt*& tupleIds) const throw(INTERP_KERNEL::Exception)
01549 {
01550   int tmp;
01551   tupleIds=0;
01552   double ret=getMaxValue(tmp);
01553   tupleIds=getIdsInRange(ret,ret);
01554   return ret;
01555 }
01556 
01557 double DataArrayDouble::getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception)
01558 {
01559   if(getNumberOfComponents()!=1)
01560     throw INTERP_KERNEL::Exception("DataArrayDouble::getMinValue : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before call 'getMinValueInArray' method !");
01561   int nbOfTuples=getNumberOfTuples();
01562   if(nbOfTuples<=0)
01563     throw INTERP_KERNEL::Exception("DataArrayDouble::getMinValue : array exists but number of tuples must be > 0 !");
01564   const double *vals=getConstPointer();
01565   const double *loc=std::min_element(vals,vals+nbOfTuples);
01566   tupleId=(int)std::distance(vals,loc);
01567   return *loc;
01568 }
01569 
01573 double DataArrayDouble::getMinValueInArray() const throw(INTERP_KERNEL::Exception)
01574 {
01575   checkAllocated();
01576   const double *loc=std::min_element(begin(),end());
01577   return *loc;
01578 }
01579 
01580 double DataArrayDouble::getMinValue2(DataArrayInt*& tupleIds) const throw(INTERP_KERNEL::Exception)
01581 {
01582   int tmp;
01583   tupleIds=0;
01584   double ret=getMinValue(tmp);
01585   tupleIds=getIdsInRange(ret,ret);
01586   return ret;
01587 }
01588 
01589 double DataArrayDouble::getAverageValue() const throw(INTERP_KERNEL::Exception)
01590 {
01591   if(getNumberOfComponents()!=1)
01592     throw INTERP_KERNEL::Exception("DataArrayDouble::getAverageValue : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before !");
01593   int nbOfTuples=getNumberOfTuples();
01594   if(nbOfTuples<=0)
01595     throw INTERP_KERNEL::Exception("DataArrayDouble::getAverageValue : array exists but number of tuples must be > 0 !");
01596   const double *vals=getConstPointer();
01597   double ret=std::accumulate(vals,vals+nbOfTuples,0.);
01598   return ret/nbOfTuples;
01599 }
01600 
01601 double DataArrayDouble::norm2() const throw(INTERP_KERNEL::Exception)
01602 {
01603   checkAllocated();
01604   double ret=0.;
01605   int nbOfElems=getNbOfElems();
01606   const double *pt=getConstPointer();
01607   for(int i=0;i<nbOfElems;i++,pt++)
01608     ret+=(*pt)*(*pt);
01609   return sqrt(ret);
01610 }
01611 
01612 double DataArrayDouble::normMax() const throw(INTERP_KERNEL::Exception)
01613 {
01614   checkAllocated();
01615   double ret=-1.;
01616   int nbOfElems=getNbOfElems();
01617   const double *pt=getConstPointer();
01618   for(int i=0;i<nbOfElems;i++,pt++)
01619     {
01620       double val=std::abs(*pt);
01621       if(val>ret)
01622         ret=val;
01623     }
01624   return ret;
01625 }
01626 
01627 void DataArrayDouble::accumulate(double *res) const throw(INTERP_KERNEL::Exception)
01628 {
01629   checkAllocated();
01630   const double *ptr=getConstPointer();
01631   int nbTuple=getNumberOfTuples();
01632   int nbComps=getNumberOfComponents();
01633   std::fill(res,res+nbComps,0.);
01634   for(int i=0;i<nbTuple;i++)
01635     std::transform(ptr+i*nbComps,ptr+(i+1)*nbComps,res,res,std::plus<double>());
01636 }
01637 
01638 double DataArrayDouble::accumulate(int compId) const throw(INTERP_KERNEL::Exception)
01639 {
01640   checkAllocated();
01641   const double *ptr=getConstPointer();
01642   int nbTuple=getNumberOfTuples();
01643   int nbComps=getNumberOfComponents();
01644   if(compId>=nbComps)
01645     throw INTERP_KERNEL::Exception("DataArrayDouble::accumulate : Invalid compId specified : No such nb of components !");
01646   double ret=0.;
01647   for(int i=0;i<nbTuple;i++)
01648     ret+=ptr[i*nbComps+compId];
01649   return ret;
01650 }
01651 
01652 DataArrayDouble *DataArrayDouble::fromPolarToCart() const throw(INTERP_KERNEL::Exception)
01653 {
01654   int nbOfComp=getNumberOfComponents();
01655   if(nbOfComp!=2)
01656     throw INTERP_KERNEL::Exception("DataArrayDouble::fromPolarToCart : must be an array with exactly 2 components !");
01657   int nbOfTuple=getNumberOfTuples();
01658   DataArrayDouble *ret=DataArrayDouble::New();
01659   ret->alloc(nbOfTuple,2);
01660   double *w=ret->getPointer();
01661   const double *wIn=getConstPointer();
01662   for(int i=0;i<nbOfTuple;i++,w+=2,wIn+=2)
01663     {
01664       w[0]=wIn[0]*cos(wIn[1]);
01665       w[1]=wIn[0]*sin(wIn[1]);
01666     }
01667   return ret;
01668 }
01669 
01670 DataArrayDouble *DataArrayDouble::fromCylToCart() const throw(INTERP_KERNEL::Exception)
01671 {
01672   int nbOfComp=getNumberOfComponents();
01673   if(nbOfComp!=3)
01674     throw INTERP_KERNEL::Exception("DataArrayDouble::fromCylToCart : must be an array with exactly 3 components !");
01675   int nbOfTuple=getNumberOfTuples();
01676   DataArrayDouble *ret=DataArrayDouble::New();
01677   ret->alloc(getNumberOfTuples(),3);
01678   double *w=ret->getPointer();
01679   const double *wIn=getConstPointer();
01680   for(int i=0;i<nbOfTuple;i++,w+=3,wIn+=3)
01681     {
01682       w[0]=wIn[0]*cos(wIn[1]);
01683       w[1]=wIn[0]*sin(wIn[1]);
01684       w[2]=wIn[2];
01685     }
01686   ret->setInfoOnComponent(2,getInfoOnComponent(2).c_str());
01687   return ret;
01688 }
01689 
01690 DataArrayDouble *DataArrayDouble::fromSpherToCart() const throw(INTERP_KERNEL::Exception)
01691 {
01692   int nbOfComp=getNumberOfComponents();
01693   if(nbOfComp!=3)
01694     throw INTERP_KERNEL::Exception("DataArrayDouble::fromSpherToCart : must be an array with exactly 3 components !");
01695   int nbOfTuple=getNumberOfTuples();
01696   DataArrayDouble *ret=DataArrayDouble::New();
01697   ret->alloc(getNumberOfTuples(),3);
01698   double *w=ret->getPointer();
01699   const double *wIn=getConstPointer();
01700   for(int i=0;i<nbOfTuple;i++,w+=3,wIn+=3)
01701     {
01702       w[0]=wIn[0]*cos(wIn[2])*sin(wIn[1]);
01703       w[1]=wIn[0]*sin(wIn[2])*sin(wIn[1]);
01704       w[2]=wIn[0]*cos(wIn[1]);
01705     }
01706   return ret;
01707 }
01708 
01709 DataArrayDouble *DataArrayDouble::doublyContractedProduct() const throw(INTERP_KERNEL::Exception)
01710 {
01711   int nbOfComp=getNumberOfComponents();
01712   if(nbOfComp!=6)
01713     throw INTERP_KERNEL::Exception("DataArrayDouble::doublyContractedProduct : must be an array with exactly 6 components !");
01714   DataArrayDouble *ret=DataArrayDouble::New();
01715   int nbOfTuple=getNumberOfTuples();
01716   ret->alloc(nbOfTuple,1);
01717   const double *src=getConstPointer();
01718   double *dest=ret->getPointer();
01719   for(int i=0;i<nbOfTuple;i++,dest++,src+=6)
01720     *dest=src[0]*src[0]+src[1]*src[1]+src[2]*src[2]+2.*src[3]*src[3]+2.*src[4]*src[4]+2.*src[5]*src[5];
01721   return ret;
01722 }
01723 
01724 DataArrayDouble *DataArrayDouble::determinant() const throw(INTERP_KERNEL::Exception)
01725 {
01726   checkAllocated();
01727   DataArrayDouble *ret=DataArrayDouble::New();
01728   int nbOfTuple=getNumberOfTuples();
01729   ret->alloc(nbOfTuple,1);
01730   const double *src=getConstPointer();
01731   double *dest=ret->getPointer();
01732   switch(getNumberOfComponents())
01733     {
01734     case 6:
01735       for(int i=0;i<nbOfTuple;i++,dest++,src+=6)
01736         *dest=src[0]*src[1]*src[2]+2.*src[4]*src[5]*src[3]-src[0]*src[4]*src[4]-src[2]*src[3]*src[3]-src[1]*src[5]*src[5];
01737       return ret;
01738     case 4:
01739       for(int i=0;i<nbOfTuple;i++,dest++,src+=4)
01740         *dest=src[0]*src[3]-src[1]*src[2];
01741       return ret;
01742     case 9:
01743       for(int i=0;i<nbOfTuple;i++,dest++,src+=9)
01744         *dest=src[0]*src[4]*src[8]+src[1]*src[5]*src[6]+src[2]*src[3]*src[7]-src[0]*src[5]*src[7]-src[1]*src[3]*src[8]-src[2]*src[4]*src[6];
01745       return ret;
01746     default:
01747       ret->decrRef();
01748       throw INTERP_KERNEL::Exception("DataArrayDouble::determinant : Invalid number of components ! must be in 4,6,9 !");
01749     }
01750 }
01751 
01752 DataArrayDouble *DataArrayDouble::eigenValues() const throw(INTERP_KERNEL::Exception)
01753 {
01754   int nbOfComp=getNumberOfComponents();
01755   if(nbOfComp!=6)
01756     throw INTERP_KERNEL::Exception("DataArrayDouble::eigenValues : must be an array with exactly 6 components !");
01757   DataArrayDouble *ret=DataArrayDouble::New();
01758   int nbOfTuple=getNumberOfTuples();
01759   ret->alloc(nbOfTuple,3);
01760   const double *src=getConstPointer();
01761   double *dest=ret->getPointer();
01762   for(int i=0;i<nbOfTuple;i++,dest+=3,src+=6)
01763     INTERP_KERNEL::computeEigenValues6(src,dest);
01764   return ret;
01765 }
01766 
01767 DataArrayDouble *DataArrayDouble::eigenVectors() const throw(INTERP_KERNEL::Exception)
01768 {
01769   int nbOfComp=getNumberOfComponents();
01770   if(nbOfComp!=6)
01771     throw INTERP_KERNEL::Exception("DataArrayDouble::eigenVectors : must be an array with exactly 6 components !");
01772   DataArrayDouble *ret=DataArrayDouble::New();
01773   int nbOfTuple=getNumberOfTuples();
01774   ret->alloc(nbOfTuple,9);
01775   const double *src=getConstPointer();
01776   double *dest=ret->getPointer();
01777   for(int i=0;i<nbOfTuple;i++,src+=6)
01778     {
01779       double tmp[3];
01780       INTERP_KERNEL::computeEigenValues6(src,tmp);
01781       for(int j=0;j<3;j++,dest+=3)
01782         INTERP_KERNEL::computeEigenVectorForEigenValue6(src,tmp[j],1e-12,dest);
01783     }
01784   return ret;
01785 }
01786 
01787 DataArrayDouble *DataArrayDouble::inverse() const throw(INTERP_KERNEL::Exception)
01788 {
01789   int nbOfComp=getNumberOfComponents();
01790   if(nbOfComp!=6 && nbOfComp!=9 && nbOfComp!=4)
01791     throw INTERP_KERNEL::Exception("DataArrayDouble::inversion : must be an array with 4,6 or 9 components !");
01792   DataArrayDouble *ret=DataArrayDouble::New();
01793   int nbOfTuple=getNumberOfTuples();
01794   ret->alloc(nbOfTuple,nbOfComp);
01795   const double *src=getConstPointer();
01796   double *dest=ret->getPointer();
01797 if(nbOfComp==6)
01798     for(int i=0;i<nbOfTuple;i++,dest+=6,src+=6)
01799       {
01800         double det=src[0]*src[1]*src[2]+2.*src[4]*src[5]*src[3]-src[0]*src[4]*src[4]-src[2]*src[3]*src[3]-src[1]*src[5]*src[5];
01801         dest[0]=(src[1]*src[2]-src[4]*src[4])/det;
01802         dest[1]=(src[0]*src[2]-src[5]*src[5])/det;
01803         dest[2]=(src[0]*src[1]-src[3]*src[3])/det;
01804         dest[3]=(src[5]*src[4]-src[3]*src[2])/det;
01805         dest[4]=(src[5]*src[3]-src[0]*src[4])/det;
01806         dest[5]=(src[3]*src[4]-src[1]*src[5])/det;
01807       }
01808   else if(nbOfComp==4)
01809     for(int i=0;i<nbOfTuple;i++,dest+=4,src+=4)
01810       {
01811         double det=src[0]*src[3]-src[1]*src[2];
01812         dest[0]=src[3]/det;
01813         dest[1]=-src[1]/det;
01814         dest[2]=-src[2]/det;
01815         dest[3]=src[0]/det;
01816       }
01817   else
01818     for(int i=0;i<nbOfTuple;i++,dest+=9,src+=9)
01819       {
01820         double det=src[0]*src[4]*src[8]+src[1]*src[5]*src[6]+src[2]*src[3]*src[7]-src[0]*src[5]*src[7]-src[1]*src[3]*src[8]-src[2]*src[4]*src[6];
01821         dest[0]=(src[4]*src[8]-src[7]*src[5])/det;
01822         dest[1]=(src[7]*src[2]-src[1]*src[8])/det;
01823         dest[2]=(src[1]*src[5]-src[4]*src[2])/det;
01824         dest[3]=(src[6]*src[5]-src[3]*src[8])/det;
01825         dest[4]=(src[0]*src[8]-src[6]*src[2])/det;
01826         dest[5]=(src[2]*src[3]-src[0]*src[5])/det;
01827         dest[6]=(src[3]*src[7]-src[6]*src[4])/det;
01828         dest[7]=(src[6]*src[1]-src[0]*src[7])/det;
01829         dest[8]=(src[0]*src[4]-src[1]*src[3])/det;
01830       }
01831   return ret;
01832 }
01833 
01834 DataArrayDouble *DataArrayDouble::trace() const throw(INTERP_KERNEL::Exception)
01835 {
01836   int nbOfComp=getNumberOfComponents();
01837   if(nbOfComp!=6 && nbOfComp!=9 && nbOfComp!=4)
01838     throw INTERP_KERNEL::Exception("DataArrayDouble::trace : must be an array with 4,6 or 9 components !");
01839   DataArrayDouble *ret=DataArrayDouble::New();
01840   int nbOfTuple=getNumberOfTuples();
01841   ret->alloc(nbOfTuple,1);
01842   const double *src=getConstPointer();
01843   double *dest=ret->getPointer();
01844   if(nbOfComp==6)
01845     for(int i=0;i<nbOfTuple;i++,dest++,src+=6)
01846       *dest=src[0]+src[1]+src[2];
01847   else if(nbOfComp==4)
01848     for(int i=0;i<nbOfTuple;i++,dest++,src+=4)
01849       *dest=src[0]+src[3];
01850   else
01851     for(int i=0;i<nbOfTuple;i++,dest++,src+=9)
01852       *dest=src[0]+src[4]+src[8];
01853   return ret;
01854 }
01855 
01856 DataArrayDouble *DataArrayDouble::deviator() const throw(INTERP_KERNEL::Exception)
01857 {
01858   int nbOfComp=getNumberOfComponents();
01859   if(nbOfComp!=6)
01860     throw INTERP_KERNEL::Exception("DataArrayDouble::deviator : must be an array with exactly 6 components !");
01861   DataArrayDouble *ret=DataArrayDouble::New();
01862   int nbOfTuple=getNumberOfTuples();
01863   ret->alloc(nbOfTuple,6);
01864   const double *src=getConstPointer();
01865   double *dest=ret->getPointer();
01866   for(int i=0;i<nbOfTuple;i++,dest+=6,src+=6)
01867     {
01868       double tr=(src[0]+src[1]+src[2])/3.;
01869       dest[0]=src[0]-tr;
01870       dest[1]=src[1]-tr;
01871       dest[2]=src[2]-tr;
01872       dest[3]=src[3];
01873       dest[4]=src[4];
01874       dest[5]=src[5];
01875     }
01876   return ret;
01877 }
01878 
01879 DataArrayDouble *DataArrayDouble::magnitude() const throw(INTERP_KERNEL::Exception)
01880 {
01881   checkAllocated();
01882   int nbOfComp=getNumberOfComponents();
01883   DataArrayDouble *ret=DataArrayDouble::New();
01884   int nbOfTuple=getNumberOfTuples();
01885   ret->alloc(nbOfTuple,1);
01886   const double *src=getConstPointer();
01887   double *dest=ret->getPointer();
01888   for(int i=0;i<nbOfTuple;i++,dest++)
01889     {
01890       double sum=0.;
01891       for(int j=0;j<nbOfComp;j++,src++)
01892         sum+=(*src)*(*src);
01893       *dest=sqrt(sum);
01894     }
01895   return ret;
01896 }
01897 
01898 DataArrayDouble *DataArrayDouble::maxPerTuple() const throw(INTERP_KERNEL::Exception)
01899 {
01900   checkAllocated();
01901   int nbOfComp=getNumberOfComponents();
01902   DataArrayDouble *ret=DataArrayDouble::New();
01903   int nbOfTuple=getNumberOfTuples();
01904   ret->alloc(nbOfTuple,1);
01905   const double *src=getConstPointer();
01906   double *dest=ret->getPointer();
01907   for(int i=0;i<nbOfTuple;i++,dest++,src+=nbOfComp)
01908     *dest=*std::max_element(src,src+nbOfComp);
01909   return ret;
01910 }
01911 
01912 void DataArrayDouble::sortPerTuple(bool asc) throw(INTERP_KERNEL::Exception)
01913 {
01914   checkAllocated();
01915   double *pt=getPointer();
01916   int nbOfTuple=getNumberOfTuples();
01917   int nbOfComp=getNumberOfComponents();
01918   if(asc)
01919     for(int i=0;i<nbOfTuple;i++,pt+=nbOfComp)
01920       std::sort(pt,pt+nbOfComp);
01921   else
01922     for(int i=0;i<nbOfTuple;i++,pt+=nbOfComp)
01923       std::sort(pt,pt+nbOfComp,std::greater<double>());
01924   declareAsNew();
01925 }
01926 
01927 void DataArrayDouble::abs() throw(INTERP_KERNEL::Exception)
01928 {
01929   checkAllocated();
01930   double *ptr=getPointer();
01931   int nbOfElems=getNbOfElems();
01932   std::transform(ptr,ptr+nbOfElems,ptr,std::ptr_fun<double,double>(fabs));
01933 }
01934 
01935 void DataArrayDouble::applyLin(double a, double b, int compoId) throw(INTERP_KERNEL::Exception)
01936 {
01937   checkAllocated();
01938   double *ptr=getPointer()+compoId;
01939   int nbOfComp=getNumberOfComponents();
01940   int nbOfTuple=getNumberOfTuples();
01941   for(int i=0;i<nbOfTuple;i++,ptr+=nbOfComp)
01942     *ptr=a*(*ptr)+b;
01943   declareAsNew();
01944 }
01945 
01946 void DataArrayDouble::applyLin(double a, double b) throw(INTERP_KERNEL::Exception)
01947 {
01948   checkAllocated();
01949   double *ptr=getPointer();
01950   int nbOfElems=getNbOfElems();
01951   for(int i=0;i<nbOfElems;i++,ptr++)
01952     *ptr=a*(*ptr)+b;
01953   declareAsNew();
01954 }
01955 
01961 void DataArrayDouble::applyInv(double numerator) throw(INTERP_KERNEL::Exception)
01962 {
01963   checkAllocated();
01964   double *ptr=getPointer();
01965   int nbOfElems=getNbOfElems();
01966   for(int i=0;i<nbOfElems;i++,ptr++)
01967     {
01968       if(std::abs(*ptr)>std::numeric_limits<double>::min())
01969         {
01970           *ptr=numerator/(*ptr);
01971         }
01972       else
01973         {
01974           std::ostringstream oss; oss << "DataArrayDouble::applyInv : presence of null value in tuple #" << i/getNumberOfComponents() << " component #" << i%getNumberOfComponents();
01975           oss << " !";
01976           throw INTERP_KERNEL::Exception(oss.str().c_str());
01977         }
01978     }
01979   declareAsNew();
01980 }
01981 
01986 DataArrayDouble *DataArrayDouble::negate() const throw(INTERP_KERNEL::Exception)
01987 {
01988   checkAllocated();
01989   DataArrayDouble *newArr=DataArrayDouble::New();
01990   int nbOfTuples=getNumberOfTuples();
01991   int nbOfComp=getNumberOfComponents();
01992   newArr->alloc(nbOfTuples,nbOfComp);
01993   const double *cptr=getConstPointer();
01994   std::transform(cptr,cptr+nbOfTuples*nbOfComp,newArr->getPointer(),std::negate<double>());
01995   newArr->copyStringInfoFrom(*this);
01996   return newArr;
01997 }
01998 
01999 DataArrayDouble *DataArrayDouble::applyFunc(int nbOfComp, FunctionToEvaluate func) const throw(INTERP_KERNEL::Exception)
02000 {
02001   checkAllocated();
02002   DataArrayDouble *newArr=DataArrayDouble::New();
02003   int nbOfTuples=getNumberOfTuples();
02004   int oldNbOfComp=getNumberOfComponents();
02005   newArr->alloc(nbOfTuples,nbOfComp);
02006   const double *ptr=getConstPointer();
02007   double *ptrToFill=newArr->getPointer();
02008   for(int i=0;i<nbOfTuples;i++)
02009     {
02010       if(!func(ptr+i*oldNbOfComp,ptrToFill+i*nbOfComp))
02011         {
02012           std::ostringstream oss; oss << "For tuple # " << i << " with value (";
02013           std::copy(ptr+oldNbOfComp*i,ptr+oldNbOfComp*(i+1),std::ostream_iterator<double>(oss,", "));
02014           oss << ") : Evaluation of function failed !";
02015           newArr->decrRef();
02016           throw INTERP_KERNEL::Exception(oss.str().c_str());
02017         }
02018     }
02019   return newArr;
02020 }
02021 
02026 DataArrayDouble *DataArrayDouble::applyFunc(int nbOfComp, const char *func) const throw(INTERP_KERNEL::Exception)
02027 {
02028   checkAllocated();
02029   INTERP_KERNEL::ExprParser expr(func);
02030   expr.parse();
02031   std::set<std::string> vars;
02032   expr.getTrueSetOfVars(vars);
02033   int oldNbOfComp=getNumberOfComponents();
02034   if((int)vars.size()>oldNbOfComp)
02035     {
02036       std::ostringstream oss; oss << "The field has " << oldNbOfComp << " components and there are ";
02037       oss << vars.size() << " variables : ";
02038       std::copy(vars.begin(),vars.end(),std::ostream_iterator<std::string>(oss," "));
02039       throw INTERP_KERNEL::Exception(oss.str().c_str());
02040     }
02041   std::vector<std::string> varsV(vars.begin(),vars.end());
02042   expr.prepareExprEvaluation(varsV);
02043   //
02044   DataArrayDouble *newArr=DataArrayDouble::New();
02045   int nbOfTuples=getNumberOfTuples();
02046   newArr->alloc(nbOfTuples,nbOfComp);
02047   const double *ptr=getConstPointer();
02048   double *ptrToFill=newArr->getPointer();
02049   for(int i=0;i<nbOfTuples;i++)
02050     {
02051       try
02052         {
02053           expr.evaluateExpr(nbOfComp,ptr+i*oldNbOfComp,ptrToFill+i*nbOfComp);
02054         }
02055       catch(INTERP_KERNEL::Exception& e)
02056         {
02057           std::ostringstream oss; oss << "For tuple # " << i << " with value (";
02058           std::copy(ptr+oldNbOfComp*i,ptr+oldNbOfComp*(i+1),std::ostream_iterator<double>(oss,", "));
02059           oss << ") : Evaluation of function failed !" << e.what();
02060           newArr->decrRef();
02061           throw INTERP_KERNEL::Exception(oss.str().c_str());
02062         }
02063     }
02064   return newArr;
02065 }
02066 
02067 DataArrayDouble *DataArrayDouble::applyFunc(const char *func) const throw(INTERP_KERNEL::Exception)
02068 {
02069   checkAllocated();
02070   INTERP_KERNEL::ExprParser expr(func);
02071   expr.parse();
02072   expr.prepareExprEvaluationVec();
02073   //
02074   DataArrayDouble *newArr=DataArrayDouble::New();
02075   int nbOfTuples=getNumberOfTuples();
02076   int nbOfComp=getNumberOfComponents();
02077   newArr->alloc(nbOfTuples,nbOfComp);
02078   const double *ptr=getConstPointer();
02079   double *ptrToFill=newArr->getPointer();
02080   for(int i=0;i<nbOfTuples;i++)
02081     {
02082       try
02083         {
02084           expr.evaluateExpr(nbOfComp,ptr+i*nbOfComp,ptrToFill+i*nbOfComp);
02085         }
02086       catch(INTERP_KERNEL::Exception& e)
02087         {
02088           std::ostringstream oss; oss << "For tuple # " << i << " with value (";
02089           std::copy(ptr+nbOfComp*i,ptr+nbOfComp*(i+1),std::ostream_iterator<double>(oss,", "));
02090           oss << ") : Evaluation of function failed ! " << e.what();
02091           newArr->decrRef();
02092           throw INTERP_KERNEL::Exception(oss.str().c_str());
02093         }
02094     }
02095   return newArr;
02096 }
02097 
02102 DataArrayDouble *DataArrayDouble::applyFunc2(int nbOfComp, const char *func) const throw(INTERP_KERNEL::Exception)
02103 {
02104   checkAllocated();
02105   INTERP_KERNEL::ExprParser expr(func);
02106   expr.parse();
02107   std::set<std::string> vars;
02108   expr.getTrueSetOfVars(vars);
02109   int oldNbOfComp=getNumberOfComponents();
02110   if((int)vars.size()>oldNbOfComp)
02111     {
02112       std::ostringstream oss; oss << "The field has " << oldNbOfComp << " components and there are ";
02113       oss << vars.size() << " variables : ";
02114       std::copy(vars.begin(),vars.end(),std::ostream_iterator<std::string>(oss," "));
02115       throw INTERP_KERNEL::Exception(oss.str().c_str());
02116     }
02117   expr.prepareExprEvaluation(getVarsOnComponent());
02118   //
02119   DataArrayDouble *newArr=DataArrayDouble::New();
02120   int nbOfTuples=getNumberOfTuples();
02121   newArr->alloc(nbOfTuples,nbOfComp);
02122   const double *ptr=getConstPointer();
02123   double *ptrToFill=newArr->getPointer();
02124   for(int i=0;i<nbOfTuples;i++)
02125     {
02126       try
02127         {
02128           expr.evaluateExpr(nbOfComp,ptr+i*oldNbOfComp,ptrToFill+i*nbOfComp);
02129         }
02130       catch(INTERP_KERNEL::Exception& e)
02131         {
02132           std::ostringstream oss; oss << "For tuple # " << i << " with value (";
02133           std::copy(ptr+oldNbOfComp*i,ptr+oldNbOfComp*(i+1),std::ostream_iterator<double>(oss,", "));
02134           oss << ") : Evaluation of function failed !" << e.what();
02135           newArr->decrRef();
02136           throw INTERP_KERNEL::Exception(oss.str().c_str());
02137         }
02138     }
02139   return newArr;
02140 }
02141 
02146 DataArrayDouble *DataArrayDouble::applyFunc3(int nbOfComp, const std::vector<std::string>& varsOrder, const char *func) const throw(INTERP_KERNEL::Exception)
02147 {
02148   checkAllocated();
02149   INTERP_KERNEL::ExprParser expr(func);
02150   expr.parse();
02151   std::set<std::string> vars;
02152   expr.getTrueSetOfVars(vars);
02153   int oldNbOfComp=getNumberOfComponents();
02154   if((int)vars.size()>oldNbOfComp)
02155     {
02156       std::ostringstream oss; oss << "The field has " << oldNbOfComp << " components and there are ";
02157       oss << vars.size() << " variables : ";
02158       std::copy(vars.begin(),vars.end(),std::ostream_iterator<std::string>(oss," "));
02159       throw INTERP_KERNEL::Exception(oss.str().c_str());
02160     }
02161   expr.prepareExprEvaluation(varsOrder);
02162   //
02163   DataArrayDouble *newArr=DataArrayDouble::New();
02164   int nbOfTuples=getNumberOfTuples();
02165   newArr->alloc(nbOfTuples,nbOfComp);
02166   const double *ptr=getConstPointer();
02167   double *ptrToFill=newArr->getPointer();
02168   for(int i=0;i<nbOfTuples;i++)
02169     {
02170       try
02171         {
02172           expr.evaluateExpr(nbOfComp,ptr+i*oldNbOfComp,ptrToFill+i*nbOfComp);
02173         }
02174       catch(INTERP_KERNEL::Exception& e)
02175         {
02176           std::ostringstream oss; oss << "For tuple # " << i << " with value (";
02177           std::copy(ptr+oldNbOfComp*i,ptr+oldNbOfComp*(i+1),std::ostream_iterator<double>(oss,", "));
02178           oss << ") : Evaluation of function failed !" << e.what();
02179           newArr->decrRef();
02180           throw INTERP_KERNEL::Exception(oss.str().c_str());
02181         }
02182     }
02183   return newArr;
02184 }
02185 
02186 void DataArrayDouble::applyFuncFast32(const char *func) throw(INTERP_KERNEL::Exception)
02187 {
02188   checkAllocated();
02189   INTERP_KERNEL::ExprParser expr(func);
02190   expr.parse();
02191   char *funcStr=expr.compileX86();
02192   MYFUNCPTR funcPtr;
02193   *((void **)&funcPtr)=funcStr;//he he...
02194   //
02195   double *ptr=getPointer();
02196   int nbOfComp=getNumberOfComponents();
02197   int nbOfTuples=getNumberOfTuples();
02198   int nbOfElems=nbOfTuples*nbOfComp;
02199   for(int i=0;i<nbOfElems;i++,ptr++)
02200     *ptr=funcPtr(*ptr);
02201   declareAsNew();
02202 }
02203 
02204 void DataArrayDouble::applyFuncFast64(const char *func) throw(INTERP_KERNEL::Exception)
02205 {
02206   checkAllocated();
02207   INTERP_KERNEL::ExprParser expr(func);
02208   expr.parse();
02209   char *funcStr=expr.compileX86_64();
02210   MYFUNCPTR funcPtr;
02211   *((void **)&funcPtr)=funcStr;//he he...
02212   //
02213   double *ptr=getPointer();
02214   int nbOfComp=getNumberOfComponents();
02215   int nbOfTuples=getNumberOfTuples();
02216   int nbOfElems=nbOfTuples*nbOfComp;
02217   for(int i=0;i<nbOfElems;i++,ptr++)
02218     *ptr=funcPtr(*ptr);
02219   declareAsNew();
02220 }
02221 
02222 DataArrayDoubleIterator *DataArrayDouble::iterator()
02223 {
02224   return new DataArrayDoubleIterator(this);
02225 }
02226 
02227 DataArrayInt *DataArrayDouble::getIdsInRange(double vmin, double vmax) const throw(INTERP_KERNEL::Exception)
02228 {
02229   if(getNumberOfComponents()!=1)
02230     throw INTERP_KERNEL::Exception("DataArrayDouble::getIdsInRange : this must have exactly one component !");
02231   const double *cptr=getConstPointer();
02232   std::vector<int> res;
02233   int nbOfTuples=getNumberOfTuples();
02234   for(int i=0;i<nbOfTuples;i++,cptr++)
02235     if(*cptr>=vmin && *cptr<=vmax)
02236       res.push_back(i);
02237   DataArrayInt *ret=DataArrayInt::New();
02238   ret->alloc((int)res.size(),1);
02239   std::copy(res.begin(),res.end(),ret->getPointer());
02240   return ret;
02241 }
02242 
02243 DataArrayDouble *DataArrayDouble::Aggregate(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
02244 {
02245   std::vector<const DataArrayDouble *> tmp(2);
02246   tmp[0]=a1; tmp[1]=a2;
02247   return Aggregate(tmp);
02248 }
02249 
02250 DataArrayDouble *DataArrayDouble::Aggregate(const std::vector<const DataArrayDouble *>& a) throw(INTERP_KERNEL::Exception)
02251 {
02252   if(a.empty())
02253     throw INTERP_KERNEL::Exception("DataArrayDouble::Aggregate : input list must be NON EMPTY !");
02254   std::vector<const DataArrayDouble *>::const_iterator it=a.begin();
02255   int nbOfComp=(*it)->getNumberOfComponents();
02256   int nbt=(*it++)->getNumberOfTuples();
02257   for(int i=1;it!=a.end();it++,i++)
02258     {
02259       if((*it)->getNumberOfComponents()!=nbOfComp)
02260         throw INTERP_KERNEL::Exception("DataArrayDouble::Aggregate : Nb of components mismatch for array aggregation !");
02261       nbt+=(*it)->getNumberOfTuples();
02262     }
02263   DataArrayDouble *ret=DataArrayDouble::New();
02264   ret->alloc(nbt,nbOfComp);
02265   double *pt=ret->getPointer();
02266   for(it=a.begin();it!=a.end();it++)
02267     pt=std::copy((*it)->getConstPointer(),(*it)->getConstPointer()+(*it)->getNbOfElems(),pt);
02268   ret->copyStringInfoFrom(*(a[0]));
02269   return ret;
02270 }
02271 
02272 DataArrayDouble *DataArrayDouble::Meld(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
02273 {
02274   std::vector<const DataArrayDouble *> arr(2);
02275   arr[0]=a1; arr[1]=a2;
02276   return Meld(arr);
02277 }
02278 
02279 DataArrayDouble *DataArrayDouble::Meld(const std::vector<const DataArrayDouble *>& a) throw(INTERP_KERNEL::Exception)
02280 {
02281   if(a.empty())
02282     throw INTERP_KERNEL::Exception("DataArrayDouble::Meld : array must be NON empty !");
02283   std::vector<const DataArrayDouble *>::const_iterator it;
02284   for(it=a.begin();it!=a.end();it++)
02285     (*it)->checkAllocated();
02286   it=a.begin();
02287   int nbOfTuples=(*it)->getNumberOfTuples();
02288   std::vector<int> nbc(a.size());
02289   std::vector<const double *> pts(a.size());
02290   nbc[0]=(*it)->getNumberOfComponents();
02291   pts[0]=(*it++)->getConstPointer();
02292   for(int i=1;it!=a.end();it++,i++)
02293     {
02294       if(nbOfTuples!=(*it)->getNumberOfTuples())
02295         throw INTERP_KERNEL::Exception("DataArrayDouble::Meld : mismatch of number of tuples !");
02296       nbc[i]=(*it)->getNumberOfComponents();
02297       pts[i]=(*it)->getConstPointer();
02298     }
02299   int totalNbOfComp=std::accumulate(nbc.begin(),nbc.end(),0);
02300   DataArrayDouble *ret=DataArrayDouble::New();
02301   ret->alloc(nbOfTuples,totalNbOfComp);
02302   double *retPtr=ret->getPointer();
02303   for(int i=0;i<nbOfTuples;i++)
02304     for(int j=0;j<(int)a.size();j++)
02305       {
02306         retPtr=std::copy(pts[j],pts[j]+nbc[j],retPtr);
02307         pts[j]+=nbc[j];
02308       }
02309   int k=0;
02310   for(int i=0;i<(int)a.size();i++)
02311     for(int j=0;j<nbc[i];j++,k++)
02312       ret->setInfoOnComponent(k,a[i]->getInfoOnComponent(j).c_str());
02313   return ret;
02314 }
02315 
02316 DataArrayDouble *DataArrayDouble::Dot(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
02317 {
02318   a1->checkAllocated();
02319   a2->checkAllocated();
02320   int nbOfComp=a1->getNumberOfComponents();
02321   if(nbOfComp!=a2->getNumberOfComponents())
02322     throw INTERP_KERNEL::Exception("Nb of components mismatch for array Dot !");
02323   int nbOfTuple=a1->getNumberOfTuples();
02324   if(nbOfTuple!=a2->getNumberOfTuples())
02325     throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Dot !");
02326   DataArrayDouble *ret=DataArrayDouble::New();
02327   ret->alloc(nbOfTuple,1);
02328   double *retPtr=ret->getPointer();
02329   const double *a1Ptr=a1->getConstPointer();
02330   const double *a2Ptr=a2->getConstPointer();
02331   for(int i=0;i<nbOfTuple;i++)
02332     {
02333       double sum=0.;
02334       for(int j=0;j<nbOfComp;j++)
02335         sum+=a1Ptr[i*nbOfComp+j]*a2Ptr[i*nbOfComp+j];
02336       retPtr[i]=sum;
02337     }
02338   ret->setInfoOnComponent(0,a1->getInfoOnComponent(0).c_str());
02339   ret->setName(a1->getName().c_str());
02340   return ret;
02341 }
02342 
02343 DataArrayDouble *DataArrayDouble::CrossProduct(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
02344 {
02345   int nbOfComp=a1->getNumberOfComponents();
02346   if(nbOfComp!=a2->getNumberOfComponents())
02347     throw INTERP_KERNEL::Exception("Nb of components mismatch for array crossProduct !");
02348   if(nbOfComp!=3)
02349     throw INTERP_KERNEL::Exception("Nb of components must be equal to 3 for array crossProduct !");
02350   int nbOfTuple=a1->getNumberOfTuples();
02351   if(nbOfTuple!=a2->getNumberOfTuples())
02352     throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array crossProduct !");
02353   DataArrayDouble *ret=DataArrayDouble::New();
02354   ret->alloc(nbOfTuple,3);
02355   double *retPtr=ret->getPointer();
02356   const double *a1Ptr=a1->getConstPointer();
02357   const double *a2Ptr=a2->getConstPointer();
02358   for(int i=0;i<nbOfTuple;i++)
02359     {
02360       retPtr[3*i]=a1Ptr[3*i+1]*a2Ptr[3*i+2]-a1Ptr[3*i+2]*a2Ptr[3*i+1];
02361       retPtr[3*i+1]=a1Ptr[3*i+2]*a2Ptr[3*i]-a1Ptr[3*i]*a2Ptr[3*i+2];
02362       retPtr[3*i+2]=a1Ptr[3*i]*a2Ptr[3*i+1]-a1Ptr[3*i+1]*a2Ptr[3*i];
02363     }
02364   ret->copyStringInfoFrom(*a1);
02365   return ret;
02366 }
02367 
02368 DataArrayDouble *DataArrayDouble::Max(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
02369 {
02370   int nbOfComp=a1->getNumberOfComponents();
02371   if(nbOfComp!=a2->getNumberOfComponents())
02372     throw INTERP_KERNEL::Exception("Nb of components mismatch for array Max !");
02373   int nbOfTuple=a1->getNumberOfTuples();
02374   if(nbOfTuple!=a2->getNumberOfTuples())
02375     throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Max !");
02376   DataArrayDouble *ret=DataArrayDouble::New();
02377   ret->alloc(nbOfTuple,nbOfComp);
02378   double *retPtr=ret->getPointer();
02379   const double *a1Ptr=a1->getConstPointer();
02380   const double *a2Ptr=a2->getConstPointer();
02381   int nbElem=nbOfTuple*nbOfComp;
02382   for(int i=0;i<nbElem;i++)
02383     retPtr[i]=std::max(a1Ptr[i],a2Ptr[i]);
02384   ret->copyStringInfoFrom(*a1);
02385   return ret;
02386 }
02387 
02388 DataArrayDouble *DataArrayDouble::Min(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
02389 {
02390   int nbOfComp=a1->getNumberOfComponents();
02391   if(nbOfComp!=a2->getNumberOfComponents())
02392     throw INTERP_KERNEL::Exception("Nb of components mismatch for array min !");
02393   int nbOfTuple=a1->getNumberOfTuples();
02394   if(nbOfTuple!=a2->getNumberOfTuples())
02395     throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array min !");
02396   DataArrayDouble *ret=DataArrayDouble::New();
02397   ret->alloc(nbOfTuple,nbOfComp);
02398   double *retPtr=ret->getPointer();
02399   const double *a1Ptr=a1->getConstPointer();
02400   const double *a2Ptr=a2->getConstPointer();
02401   int nbElem=nbOfTuple*nbOfComp;
02402   for(int i=0;i<nbElem;i++)
02403     retPtr[i]=std::min(a1Ptr[i],a2Ptr[i]);
02404   ret->copyStringInfoFrom(*a1);
02405   return ret;
02406 }
02407 
02408 DataArrayDouble *DataArrayDouble::Add(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
02409 {
02410   int nbOfTuple=a1->getNumberOfTuples();
02411   int nbOfTuple2=a2->getNumberOfTuples();
02412   int nbOfComp=a1->getNumberOfComponents();
02413   int nbOfComp2=a2->getNumberOfComponents();
02414   if(nbOfTuple!=nbOfTuple2)
02415     throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Add !");
02416   DataArrayDouble *ret=0;
02417   if(nbOfComp==nbOfComp2)
02418     {
02419       ret=DataArrayDouble::New();
02420       ret->alloc(nbOfTuple,nbOfComp);
02421       std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::plus<double>());
02422       ret->copyStringInfoFrom(*a1);
02423     }
02424   else
02425     {
02426       int nbOfCompMin,nbOfCompMax;
02427       const DataArrayDouble *aMin, *aMax;
02428       if(nbOfComp>nbOfComp2)
02429         {
02430           nbOfCompMin=nbOfComp2; nbOfCompMax=nbOfComp;
02431           aMin=a2; aMax=a1;
02432         }
02433       else
02434         {
02435           nbOfCompMin=nbOfComp; nbOfCompMax=nbOfComp2;
02436           aMin=a1; aMax=a2;
02437         }
02438       if(nbOfCompMin==1)
02439         {
02440           ret=DataArrayDouble::New();
02441           ret->alloc(nbOfTuple,nbOfCompMax);
02442           const double *aMinPtr=aMin->getConstPointer();
02443           const double *aMaxPtr=aMax->getConstPointer();
02444           double *res=ret->getPointer();
02445           for(int i=0;i<nbOfTuple;i++)
02446             res=std::transform(aMaxPtr+i*nbOfCompMax,aMaxPtr+(i+1)*nbOfCompMax,res,std::bind2nd(std::plus<double>(),aMinPtr[i]));
02447           ret->copyStringInfoFrom(*aMax);
02448         }
02449       else
02450         throw INTERP_KERNEL::Exception("Nb of components mismatch for array Add !");
02451     }
02452   return ret;
02453 }
02454 
02455 void DataArrayDouble::addEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception)
02456 {
02457   const char *msg="Nb of tuples mismatch for DataArrayDouble::addEqual  !";
02458   int nbOfTuple=getNumberOfTuples();
02459   int nbOfTuple2=other->getNumberOfTuples();
02460   int nbOfComp=getNumberOfComponents();
02461   int nbOfComp2=other->getNumberOfComponents();
02462   if(nbOfTuple==nbOfTuple2)
02463     {
02464       if(nbOfComp==nbOfComp2)
02465         {
02466           std::transform(begin(),end(),other->begin(),getPointer(),std::plus<double>());
02467         }
02468       else if(nbOfComp2==1)
02469         {
02470           double *ptr=getPointer();
02471           const double *ptrc=other->getConstPointer();
02472           for(int i=0;i<nbOfTuple;i++)
02473             std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::plus<double>(),*ptrc++));
02474         }
02475       else
02476         throw INTERP_KERNEL::Exception(msg);
02477     }
02478   else if(nbOfTuple2==1)
02479     {
02480       if(nbOfComp2==nbOfComp)
02481         {
02482           double *ptr=getPointer();
02483           const double *ptrc=other->getConstPointer();
02484           for(int i=0;i<nbOfTuple;i++)
02485             std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::plus<double>());
02486         }
02487       else
02488         throw INTERP_KERNEL::Exception(msg);
02489     }
02490   else
02491     throw INTERP_KERNEL::Exception(msg);
02492   declareAsNew();
02493 }
02494 
02495 DataArrayDouble *DataArrayDouble::Substract(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
02496 {
02497   int nbOfTuple=a2->getNumberOfTuples();
02498   int nbOfComp=a2->getNumberOfComponents();
02499   a1->checkNbOfTuplesAndComp(nbOfTuple,nbOfComp,"Nb of components mismatch for array Substract !");
02500   DataArrayDouble *ret=DataArrayDouble::New();
02501   ret->alloc(nbOfTuple,nbOfComp);
02502   std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::minus<double>());
02503   ret->copyStringInfoFrom(*a1);
02504   return ret;
02505 }
02506 
02507 void DataArrayDouble::substractEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception)
02508 {
02509   const char *msg="Nb of tuples mismatch for DataArrayDouble::substractEqual  !";
02510   int nbOfTuple=getNumberOfTuples();
02511   int nbOfTuple2=other->getNumberOfTuples();
02512   int nbOfComp=getNumberOfComponents();
02513   int nbOfComp2=other->getNumberOfComponents();
02514   if(nbOfTuple==nbOfTuple2)
02515     {
02516       if(nbOfComp==nbOfComp2)
02517         {
02518           std::transform(begin(),end(),other->begin(),getPointer(),std::minus<double>());
02519         }
02520       else if(nbOfComp2==1)
02521         {
02522           double *ptr=getPointer();
02523           const double *ptrc=other->getConstPointer();
02524           for(int i=0;i<nbOfTuple;i++)
02525             std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::minus<double>(),*ptrc++)); 
02526         }
02527       else
02528         throw INTERP_KERNEL::Exception(msg);
02529     }
02530   else if(nbOfTuple2==1)
02531     {
02532       if(nbOfComp2==nbOfComp)
02533         {
02534           double *ptr=getPointer();
02535           const double *ptrc=other->getConstPointer();
02536           for(int i=0;i<nbOfTuple;i++)
02537             std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::minus<double>());
02538         }
02539       else
02540         throw INTERP_KERNEL::Exception(msg);
02541     }
02542   else
02543     throw INTERP_KERNEL::Exception(msg);
02544   declareAsNew();
02545 }
02546 
02547 DataArrayDouble *DataArrayDouble::Multiply(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
02548 {
02549   int nbOfTuple=a1->getNumberOfTuples();
02550   int nbOfTuple2=a2->getNumberOfTuples();
02551   int nbOfComp=a1->getNumberOfComponents();
02552   int nbOfComp2=a2->getNumberOfComponents();
02553   if(nbOfTuple!=nbOfTuple2)
02554     throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Multiply !");
02555   DataArrayDouble *ret=0;
02556   if(nbOfComp==nbOfComp2)
02557     {
02558       ret=DataArrayDouble::New();
02559       ret->alloc(nbOfTuple,nbOfComp);
02560       std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::multiplies<double>());
02561       ret->copyStringInfoFrom(*a1);
02562     }
02563   else
02564     {
02565       int nbOfCompMin,nbOfCompMax;
02566       const DataArrayDouble *aMin, *aMax;
02567       if(nbOfComp>nbOfComp2)
02568         {
02569           nbOfCompMin=nbOfComp2; nbOfCompMax=nbOfComp;
02570           aMin=a2; aMax=a1;
02571         }
02572       else
02573         {
02574           nbOfCompMin=nbOfComp; nbOfCompMax=nbOfComp2;
02575           aMin=a1; aMax=a2;
02576         }
02577       if(nbOfCompMin==1)
02578         {
02579           ret=DataArrayDouble::New();
02580           ret->alloc(nbOfTuple,nbOfCompMax);
02581           const double *aMinPtr=aMin->getConstPointer();
02582           const double *aMaxPtr=aMax->getConstPointer();
02583           double *res=ret->getPointer();
02584           for(int i=0;i<nbOfTuple;i++)
02585             res=std::transform(aMaxPtr+i*nbOfCompMax,aMaxPtr+(i+1)*nbOfCompMax,res,std::bind2nd(std::multiplies<double>(),aMinPtr[i]));
02586           ret->copyStringInfoFrom(*aMax);
02587         }
02588       else
02589         throw INTERP_KERNEL::Exception("Nb of components mismatch for array Multiply !");
02590     }
02591   return ret;
02592 }
02593 
02594 void DataArrayDouble::multiplyEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception)
02595 {
02596   const char *msg="Nb of tuples mismatch for DataArrayDouble::multiplyEqual !";
02597   int nbOfTuple=getNumberOfTuples();
02598   int nbOfTuple2=other->getNumberOfTuples();
02599   int nbOfComp=getNumberOfComponents();
02600   int nbOfComp2=other->getNumberOfComponents();
02601   if(nbOfTuple==nbOfTuple2)
02602     {
02603       if(nbOfComp==nbOfComp2)
02604         {
02605           std::transform(begin(),end(),other->begin(),getPointer(),std::multiplies<double>());
02606         }
02607       else if(nbOfComp2==1)
02608         {
02609           double *ptr=getPointer();
02610           const double *ptrc=other->getConstPointer();
02611           for(int i=0;i<nbOfTuple;i++)
02612             std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::multiplies<double>(),*ptrc++));
02613         }
02614       else
02615         throw INTERP_KERNEL::Exception(msg);
02616     }
02617   else if(nbOfTuple2==1)
02618     {
02619       if(nbOfComp2==nbOfComp)
02620         {
02621           double *ptr=getPointer();
02622           const double *ptrc=other->getConstPointer();
02623           for(int i=0;i<nbOfTuple;i++)
02624             std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::multiplies<double>());
02625         }
02626       else
02627         throw INTERP_KERNEL::Exception(msg);
02628     }
02629   else
02630     throw INTERP_KERNEL::Exception(msg);
02631   declareAsNew();
02632 }
02633 
02634 DataArrayDouble *DataArrayDouble::Divide(const DataArrayDouble *a1, const DataArrayDouble *a2) throw(INTERP_KERNEL::Exception)
02635 {
02636   int nbOfTuple=a1->getNumberOfTuples();
02637   int nbOfTuple2=a2->getNumberOfTuples();
02638   int nbOfComp=a1->getNumberOfComponents();
02639   int nbOfComp2=a2->getNumberOfComponents();
02640   if(nbOfTuple!=nbOfTuple2)
02641     throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Divide !");
02642   DataArrayDouble *ret=0;
02643   if(nbOfComp==nbOfComp2)
02644     {
02645       ret=DataArrayDouble::New();
02646       ret->alloc(nbOfTuple,nbOfComp);
02647       std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::divides<double>());
02648       ret->copyStringInfoFrom(*a1);
02649     }
02650   else
02651     {
02652       if(nbOfComp2==1)
02653         {
02654           ret=DataArrayDouble::New();
02655           ret->alloc(nbOfTuple,nbOfComp);
02656           const double *a2Ptr=a2->getConstPointer();
02657           const double *a1Ptr=a1->getConstPointer();
02658           double *res=ret->getPointer();
02659           for(int i=0;i<nbOfTuple;i++)
02660             res=std::transform(a1Ptr+i*nbOfComp,a1Ptr+(i+1)*nbOfComp,res,std::bind2nd(std::divides<double>(),a2Ptr[i]));
02661           ret->copyStringInfoFrom(*a1);
02662         }
02663       else
02664         throw INTERP_KERNEL::Exception("Nb of components mismatch for array Divide !");
02665     }
02666   return ret;
02667 }
02668 
02669 void DataArrayDouble::divideEqual(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception)
02670 {
02671   const char *msg="Nb of tuples mismatch for DataArrayDouble::divideEqual !";
02672   int nbOfTuple=getNumberOfTuples();
02673   int nbOfTuple2=other->getNumberOfTuples();
02674   int nbOfComp=getNumberOfComponents();
02675   int nbOfComp2=other->getNumberOfComponents();
02676   if(nbOfTuple==nbOfTuple2)
02677     {
02678       if(nbOfComp==nbOfComp2)
02679         {
02680           std::transform(begin(),end(),other->begin(),getPointer(),std::divides<double>());
02681         }
02682       else if(nbOfComp2==1)
02683         {
02684           double *ptr=getPointer();
02685           const double *ptrc=other->getConstPointer();
02686           for(int i=0;i<nbOfTuple;i++)
02687             std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::divides<double>(),*ptrc++));
02688         }
02689       else
02690         throw INTERP_KERNEL::Exception(msg);
02691     }
02692   else if(nbOfTuple2==1)
02693     {
02694       if(nbOfComp2==nbOfComp)
02695         {
02696           double *ptr=getPointer();
02697           const double *ptrc=other->getConstPointer();
02698           for(int i=0;i<nbOfTuple;i++)
02699             std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::divides<double>());
02700         }
02701       else
02702         throw INTERP_KERNEL::Exception(msg);
02703     }
02704   else
02705     throw INTERP_KERNEL::Exception(msg);
02706   declareAsNew();
02707 }
02708 
02713 void DataArrayDouble::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
02714 {
02715   tinyInfo.resize(2);
02716   if(isAllocated())
02717     {
02718       tinyInfo[0]=getNumberOfTuples();
02719       tinyInfo[1]=getNumberOfComponents();
02720     }
02721   else
02722     {
02723       tinyInfo[0]=-1;
02724       tinyInfo[1]=-1;
02725     }
02726 }
02727 
02732 void DataArrayDouble::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
02733 {
02734   if(isAllocated())
02735     {
02736       int nbOfCompo=getNumberOfComponents();
02737       tinyInfo.resize(nbOfCompo+1);
02738       tinyInfo[0]=getName();
02739       for(int i=0;i<nbOfCompo;i++)
02740         tinyInfo[i+1]=getInfoOnComponent(i);
02741     }
02742   else
02743     {
02744       tinyInfo.resize(1);
02745       tinyInfo[0]=getName();
02746     }
02747 }
02748 
02753 bool DataArrayDouble::resizeForUnserialization(const std::vector<int>& tinyInfoI)
02754 {
02755   int nbOfTuple=tinyInfoI[0];
02756   int nbOfComp=tinyInfoI[1];
02757   if(nbOfTuple!=-1 || nbOfComp!=-1)
02758     {
02759       alloc(nbOfTuple,nbOfComp);
02760       return true;
02761     }
02762   return false;
02763 }
02764 
02768 void DataArrayDouble::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<std::string>& tinyInfoS)
02769 {
02770   setName(tinyInfoS[0].c_str());
02771   if(isAllocated())
02772     {
02773       int nbOfCompo=getNumberOfComponents();
02774       for(int i=0;i<nbOfCompo;i++)
02775         setInfoOnComponent(i,tinyInfoS[i+1].c_str());
02776     }
02777 }
02778 
02779 DataArrayDoubleIterator::DataArrayDoubleIterator(DataArrayDouble *da):_da(da),_tuple_id(0),_nb_comp(0),_nb_tuple(0)
02780 {
02781   if(_da)
02782     {
02783       _da->incrRef();
02784       if(_da->isAllocated())
02785         {
02786           _nb_comp=da->getNumberOfComponents();
02787           _nb_tuple=da->getNumberOfTuples();
02788           _pt=da->getPointer();
02789         }
02790     }
02791 }
02792 
02793 DataArrayDoubleIterator::~DataArrayDoubleIterator()
02794 {
02795   if(_da)
02796     _da->decrRef();
02797 }
02798 
02799 DataArrayDoubleTuple *DataArrayDoubleIterator::nextt()
02800 {
02801   if(_tuple_id<_nb_tuple)
02802     {
02803       _tuple_id++;
02804       DataArrayDoubleTuple *ret=new DataArrayDoubleTuple(_pt,_nb_comp);
02805       _pt+=_nb_comp;
02806       return ret;
02807     }
02808   else
02809     return 0;
02810 }
02811 
02812 DataArrayDoubleTuple::DataArrayDoubleTuple(double *pt, int nbOfComp):_pt(pt),_nb_of_compo(nbOfComp)
02813 {
02814 }
02815 
02816 
02817 std::string DataArrayDoubleTuple::repr() const
02818 {
02819   std::ostringstream oss; oss.precision(15); oss << "(";
02820   for(int i=0;i<_nb_of_compo-1;i++)
02821     oss << _pt[i] << ", ";
02822   oss << _pt[_nb_of_compo-1] << ")";
02823   return oss.str();
02824 }
02825 
02826 double DataArrayDoubleTuple::doubleValue() const throw(INTERP_KERNEL::Exception)
02827 {
02828   if(_nb_of_compo==1)
02829     return *_pt;
02830   throw INTERP_KERNEL::Exception("DataArrayDoubleTuple::doubleValue : DataArrayDoubleTuple instance has not exactly 1 component -> Not possible to convert it into a double precision float !");
02831 }
02832 
02839 DataArrayDouble *DataArrayDoubleTuple::buildDADouble(int nbOfTuples, int nbOfCompo) const throw(INTERP_KERNEL::Exception)
02840 {
02841   if((_nb_of_compo==nbOfCompo && nbOfTuples==1) || (_nb_of_compo==nbOfTuples && nbOfCompo==1))
02842     {
02843       DataArrayDouble *ret=DataArrayDouble::New();
02844       ret->useArray(_pt,false,CPP_DEALLOC,nbOfTuples,nbOfCompo);
02845       return ret;
02846     }
02847   else
02848     {
02849       std::ostringstream oss; oss << "DataArrayDoubleTuple::buildDADouble : unable to build a requested DataArrayDouble instance with nbofTuple=" << nbOfTuples << " and nbOfCompo=" << nbOfCompo;
02850       oss << ".\nBecause the number of elements in this is " << _nb_of_compo << " !";
02851       throw INTERP_KERNEL::Exception(oss.str().c_str());
02852     }
02853 }
02854 
02855 DataArrayInt *DataArrayInt::New()
02856 {
02857   return new DataArrayInt;
02858 }
02859 
02860 bool DataArrayInt::isAllocated() const
02861 {
02862   return getConstPointer()!=0;
02863 }
02864 
02865 void DataArrayInt::checkAllocated() const throw(INTERP_KERNEL::Exception)
02866 {
02867   if(!isAllocated())
02868     throw INTERP_KERNEL::Exception("DataArrayInt::checkAllocated : Array is defined but not allocated ! Call alloc or setValues method first !");
02869 }
02870 
02877 void DataArrayInt::setInfoAndChangeNbOfCompo(const std::vector<std::string>& info) throw(INTERP_KERNEL::Exception)
02878 {
02879   if(getNumberOfComponents()!=(int)info.size())
02880     {
02881       if(!isAllocated())
02882         _info_on_compo=info;
02883       else
02884         {
02885           std::ostringstream oss; oss << "DataArrayInt::setInfoAndChangeNbOfCompo : input is of size " << info.size() << " whereas number of components is equal to " << getNumberOfComponents() << "  and this is already allocated !";
02886           throw INTERP_KERNEL::Exception(oss.str().c_str());
02887         }
02888     }
02889   else
02890     _info_on_compo=info;
02891 }
02892 
02897 int DataArrayInt::intValue() const throw(INTERP_KERNEL::Exception)
02898 {
02899   if(isAllocated())
02900     {
02901       if(getNbOfElems()==1)
02902         {
02903           return *getConstPointer();
02904         }
02905       else
02906         throw INTERP_KERNEL::Exception("DataArrayInt::intValue : DataArrayInt instance is allocated but number of elements is not equal to 1 !");
02907     }
02908   else
02909     throw INTERP_KERNEL::Exception("DataArrayInt::intValue : DataArrayInt instance is not allocated !");
02910 }
02911 
02915 int DataArrayInt::getHashCode() const throw(INTERP_KERNEL::Exception)
02916 {
02917   checkAllocated();
02918   int nbOfElems=getNbOfElems();
02919   int ret=nbOfElems*65536;
02920   int delta=3;
02921   if(nbOfElems>48)
02922     delta=nbOfElems/8;
02923   int ret0=0;
02924   const int *pt=begin();
02925   for(int i=0;i<nbOfElems;i+=delta)
02926     ret0+=pt[i] & 0x1FFF;
02927   return ret+ret0;
02928 }
02929 
02934 bool DataArrayInt::empty() const throw(INTERP_KERNEL::Exception)
02935 {
02936   checkAllocated();
02937   return getNumberOfTuples()==0;
02938 }
02939 
02940 DataArrayInt *DataArrayInt::deepCpy() const
02941 {
02942   return new DataArrayInt(*this);
02943 }
02944 
02945 DataArrayInt *DataArrayInt::performCpy(bool dCpy) const
02946 {
02947   if(dCpy)
02948     return deepCpy();
02949   else
02950     {
02951       incrRef();
02952       return const_cast<DataArrayInt *>(this);
02953     }
02954 }
02955 
02956 void DataArrayInt::cpyFrom(const DataArrayInt& other) throw(INTERP_KERNEL::Exception)
02957 {
02958   other.checkAllocated();
02959   int nbOfTuples=other.getNumberOfTuples();
02960   int nbOfComp=other.getNumberOfComponents();
02961   allocIfNecessary(nbOfTuples,nbOfComp);
02962   int nbOfElems=nbOfTuples*nbOfComp;
02963   int *pt=getPointer();
02964   const int *ptI=other.getConstPointer();
02965   for(int i=0;i<nbOfElems;i++)
02966     pt[i]=ptI[i];
02967   copyStringInfoFrom(other);
02968 }
02969 
02970 void DataArrayInt::allocIfNecessary(int nbOfTuple, int nbOfCompo)
02971 {
02972   if(isAllocated())
02973     {
02974       if(nbOfTuple!=getNumberOfTuples() || nbOfCompo!=getNumberOfComponents())
02975         alloc(nbOfTuple,nbOfCompo);
02976     }
02977   else
02978     alloc(nbOfTuple,nbOfCompo);
02979 }
02980 
02981 void DataArrayInt::alloc(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exception)
02982 {
02983   if(nbOfTuple<0 || nbOfCompo<0)
02984     throw INTERP_KERNEL::Exception("DataArrayDouble::alloc : request for negative length of data !");
02985   _nb_of_tuples=nbOfTuple;
02986   _info_on_compo.resize(nbOfCompo);
02987   _mem.alloc(nbOfCompo*_nb_of_tuples);
02988   declareAsNew();
02989 }
02990 
02991 void DataArrayInt::fillWithZero() throw(INTERP_KERNEL::Exception)
02992 {
02993   checkAllocated();
02994   _mem.fillWithValue(0);
02995   declareAsNew();
02996 }
02997 
02998 void DataArrayInt::fillWithValue(int val) throw(INTERP_KERNEL::Exception)
02999 {
03000   checkAllocated();
03001   _mem.fillWithValue(val);
03002   declareAsNew();
03003 }
03004 
03005 void DataArrayInt::iota(int init) throw(INTERP_KERNEL::Exception)
03006 {
03007   checkAllocated();
03008   if(getNumberOfComponents()!=1)
03009     throw INTERP_KERNEL::Exception("DataArrayInt::iota : works only for arrays with only one component, you can call 'rearrange' method before !");
03010   int *ptr=getPointer();
03011   int ntuples=getNumberOfTuples();
03012   for(int i=0;i<ntuples;i++)
03013     ptr[i]=init+i;
03014   declareAsNew();
03015 }
03016 
03017 std::string DataArrayInt::repr() const
03018 {
03019   std::ostringstream ret;
03020   reprStream(ret);
03021   return ret.str();
03022 }
03023 
03024 std::string DataArrayInt::reprZip() const
03025 {
03026   std::ostringstream ret;
03027   reprZipStream(ret);
03028   return ret.str();
03029 }
03030 
03031 void DataArrayInt::writeVTK(std::ostream& ofs, int indent, const char *type, const char *nameInFile) const throw(INTERP_KERNEL::Exception)
03032 {
03033   std::string idt(indent,' ');
03034   ofs << idt << "<DataArray type=\"" << type << "\" Name=\"" << nameInFile << "\" NumberOfComponents=\"" << getNumberOfComponents() << "\"";
03035   ofs << " format=\"ascii\" RangeMin=\"" << getMinValueInArray() << "\" RangeMax=\"" << getMaxValueInArray() << "\">\n" << idt;
03036   std::copy(begin(),end(),std::ostream_iterator<int>(ofs," "));
03037   ofs << std::endl << idt << "</DataArray>\n";
03038 }
03039 
03040 void DataArrayInt::reprStream(std::ostream& stream) const
03041 {
03042   stream << "Name of int array : \"" << _name << "\"\n";
03043   reprWithoutNameStream(stream);
03044 }
03045 
03046 void DataArrayInt::reprZipStream(std::ostream& stream) const
03047 {
03048   stream << "Name of int array : \"" << _name << "\"\n";
03049   reprZipWithoutNameStream(stream);
03050 }
03051 
03052 void DataArrayInt::reprWithoutNameStream(std::ostream& stream) const
03053 {
03054   DataArray::reprWithoutNameStream(stream);
03055   _mem.repr(getNumberOfComponents(),stream);
03056 }
03057 
03058 void DataArrayInt::reprZipWithoutNameStream(std::ostream& stream) const
03059 {
03060   DataArray::reprWithoutNameStream(stream);
03061   _mem.reprZip(getNumberOfComponents(),stream);
03062 }
03063 
03071 void DataArrayInt::transformWithIndArr(const int *indArrBg, const int *indArrEnd) throw(INTERP_KERNEL::Exception)
03072 {
03073   if(getNumberOfComponents()!=1)
03074     throw INTERP_KERNEL::Exception("Call transformWithIndArr method on DataArrayInt with only one component, you can call 'rearrange' method before !");
03075   int nbElemsIn=(int)std::distance(indArrBg,indArrEnd);
03076   int nbOfTuples=getNumberOfTuples();
03077   int *pt=getPointer();
03078   for(int i=0;i<nbOfTuples;i++,pt++)
03079     {
03080       if(*pt>=0 && *pt<nbElemsIn)
03081         *pt=indArrBg[*pt];
03082       else
03083         {
03084           std::ostringstream oss; oss << "DataArrayInt::transformWithIndArr : error on tuple #" << i << " value is " << *pt << " and indirectionnal array as a size equal to " << nbElemsIn;
03085           throw INTERP_KERNEL::Exception(oss.str().c_str());
03086         }
03087     }
03088   declareAsNew();
03089 }
03090 
03108 void DataArrayInt::splitByValueRange(const int *arrBg, const int *arrEnd,
03109                                      DataArrayInt *& castArr, DataArrayInt *& rankInsideCast, DataArrayInt *& castsPresent) const throw(INTERP_KERNEL::Exception)
03110 {
03111   if(getNumberOfComponents()!=1)
03112     throw INTERP_KERNEL::Exception("Call splitByValueRange  method on DataArrayInt with only one component, you can call 'rearrange' method before !");
03113   int nbOfTuples=getNumberOfTuples();
03114   std::size_t nbOfCast=std::distance(arrBg,arrEnd);
03115   if(nbOfCast<2)
03116     throw INTERP_KERNEL::Exception("DataArrayInt::splitByValueRange : The input array giving the cast range values should be of size >=2 !");
03117   nbOfCast--;
03118   const int *work=getConstPointer();
03119   typedef std::reverse_iterator<const int *> rintstart;
03120   rintstart bg(arrEnd);//OK no problem because size of 'arr' is greater of equal 2
03121   rintstart end2(arrBg);
03122   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret1=DataArrayInt::New();
03123   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret2=DataArrayInt::New();
03124   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret3=DataArrayInt::New();
03125   ret1->alloc(nbOfTuples,1);
03126   ret2->alloc(nbOfTuples,1);
03127   int *ret1Ptr=ret1->getPointer();
03128   int *ret2Ptr=ret2->getPointer();
03129   std::set<std::size_t> castsDetected;
03130   for(int i=0;i<nbOfTuples;i++)
03131     {
03132       rintstart res=std::find_if(bg,end2,std::bind2nd(std::less_equal<int>(), work[i]));
03133       std::size_t pos=std::distance(bg,res);
03134       std::size_t pos2=nbOfCast-pos;
03135       if(pos2<nbOfCast)
03136         {
03137           ret1Ptr[i]=(int)pos2;
03138           ret2Ptr[i]=work[i]-arrBg[pos2];
03139           castsDetected.insert(pos2);
03140         }
03141       else
03142         {
03143           std::ostringstream oss; oss << "DataArrayInt::splitByValueRange : At rank #" << i << " the value is " << work[i] << " whereas the last value is " << *bg;
03144           throw INTERP_KERNEL::Exception(oss.str().c_str());
03145         }
03146     }
03147   ret3->alloc((int)castsDetected.size(),1);
03148   std::copy(castsDetected.begin(),castsDetected.end(),ret3->getPointer());
03149   ret1->incrRef();
03150   castArr=ret1;
03151   ret2->incrRef();
03152   rankInsideCast=ret2;
03153   ret3->incrRef();
03154   castsPresent=ret3;
03155 }
03156 
03165 DataArrayInt *DataArrayInt::transformWithIndArrR(const int *indArrBg, const int *indArrEnd) const throw(INTERP_KERNEL::Exception)
03166 {
03167   if(getNumberOfComponents()!=1)
03168     throw INTERP_KERNEL::Exception("Call transformWithIndArrR method on DataArrayInt with only one component, you can call 'rearrange' method before !");
03169   int nbElemsIn=(int)std::distance(indArrBg,indArrEnd);
03170   int nbOfTuples=getNumberOfTuples();
03171   const int *pt=getConstPointer();
03172   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
03173   ret->alloc(nbOfTuples,1);
03174   ret->fillWithValue(-1);
03175   int *tmp=ret->getPointer();
03176   for(int i=0;i<nbOfTuples;i++,pt++)
03177     {
03178       int pos=indArrBg[*pt];
03179       if(pos>=0 && pos<nbElemsIn)
03180         tmp[pos]=i;
03181       else
03182         {
03183           std::ostringstream oss; oss << "DataArrayInt::transformWithIndArrR : error on tuple #" << i << " value is " << *pt << " and indirectionnal array as a size equal to " << nbElemsIn;
03184           throw INTERP_KERNEL::Exception(oss.str().c_str());
03185         }
03186     }
03187   ret->incrRef();
03188   return ret;
03189 }
03190 
03194 DataArrayInt *DataArrayInt::invertArrayO2N2N2O(int newNbOfElem) const
03195 {
03196   DataArrayInt *ret=DataArrayInt::New();
03197   ret->alloc(newNbOfElem,1);
03198   int nbOfOldNodes=getNumberOfTuples();
03199   const int *old2New=getConstPointer();
03200   int *pt=ret->getPointer();
03201   for(int i=0;i!=nbOfOldNodes;i++)
03202     if(old2New[i]!=-1)
03203       pt[old2New[i]]=i;
03204   return ret;
03205 }
03206 
03210 DataArrayInt *DataArrayInt::invertArrayN2O2O2N(int oldNbOfElem) const
03211 {
03212   DataArrayInt *ret=DataArrayInt::New();
03213   ret->alloc(oldNbOfElem,1);
03214   const int *new2Old=getConstPointer();
03215   int *pt=ret->getPointer();
03216   std::fill(pt,pt+oldNbOfElem,-1);
03217   int nbOfNewElems=getNumberOfTuples();
03218   for(int i=0;i<nbOfNewElems;i++)
03219     pt[new2Old[i]]=i;
03220   return ret;
03221 }
03222 
03223 bool DataArrayInt::isEqual(const DataArrayInt& other) const
03224 {
03225   if(!areInfoEquals(other))
03226     return false;
03227   return _mem.isEqual(other._mem,0);
03228 }
03229 
03230 bool DataArrayInt::isEqualWithoutConsideringStr(const DataArrayInt& other) const
03231 {
03232   return _mem.isEqual(other._mem,0);
03233 }
03234 
03235 bool DataArrayInt::isEqualWithoutConsideringStrAndOrder(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception)
03236 {
03237   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> a=deepCpy();
03238   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> b=other.deepCpy();
03239   a->sort();
03240   b->sort();
03241   return a->isEqualWithoutConsideringStr(*b);
03242 }
03243 
03244 void DataArrayInt::sort() throw(INTERP_KERNEL::Exception)
03245 {
03246   checkAllocated();
03247   if(getNumberOfComponents()!=1)
03248     throw INTERP_KERNEL::Exception("DataArrayInt::sort : only supported with 'this' array with ONE component !");
03249   _mem.sort();
03250 }
03251 
03252 void DataArrayInt::reverse() throw(INTERP_KERNEL::Exception)
03253 {
03254   checkAllocated();
03255   if(getNumberOfComponents()!=1)
03256     throw INTERP_KERNEL::Exception("DataArrayInt::reverse : only supported with 'this' array with ONE component !");
03257   _mem.reverse();
03258 }
03259 
03267 DataArrayInt *DataArrayInt::buildPermutationArr(const DataArrayInt& other) const throw(INTERP_KERNEL::Exception)
03268 {
03269   if(getNumberOfComponents()!=1 || other.getNumberOfComponents()!=1)
03270     throw INTERP_KERNEL::Exception("DataArrayInt::buildPermutationArr : 'this' and 'other' have to have exactly ONE component !");
03271   int nbTuple=getNumberOfTuples();
03272   if(nbTuple!=other.getNumberOfTuples())
03273     throw INTERP_KERNEL::Exception("DataArrayInt::buildPermutationArr : 'this' and 'other' must have the same number of tuple !");
03274   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
03275   ret->alloc(nbTuple,1);
03276   ret->fillWithValue(-1);
03277   const int *pt=getConstPointer();
03278   std::map<int,int> mm;
03279   for(int i=0;i<nbTuple;i++)
03280     mm[pt[i]]=i;
03281   pt=other.getConstPointer();
03282   int *retToFill=ret->getPointer();
03283   for(int i=0;i<nbTuple;i++)
03284     {
03285       std::map<int,int>::const_iterator it=mm.find(pt[i]);
03286       if(it==mm.end())
03287         {
03288           std::ostringstream oss; oss << "DataArrayInt::buildPermutationArr : Arrays mismatch : element (" << pt[i] << ") in 'other' not findable in 'this' !";
03289           throw INTERP_KERNEL::Exception(oss.str().c_str());
03290         }
03291       retToFill[i]=(*it).second;
03292     }
03293   ret->incrRef();
03294   return ret;
03295 }
03296 
03297 void DataArrayInt::useArray(const int *array, bool ownership,  DeallocType type, int nbOfTuple, int nbOfCompo)
03298 {
03299   _nb_of_tuples=nbOfTuple;
03300   _info_on_compo.resize(nbOfCompo);
03301   _mem.useArray(array,ownership,type,nbOfTuple*nbOfCompo);
03302   declareAsNew();
03303 }
03304 
03305 DataArrayInt *DataArrayInt::fromNoInterlace() const throw(INTERP_KERNEL::Exception)
03306 {
03307   if(_mem.isNull())
03308     throw INTERP_KERNEL::Exception("DataArrayInt::fromNoInterlace : Not defined array !");
03309   int *tab=_mem.fromNoInterlace(getNumberOfComponents());
03310   DataArrayInt *ret=DataArrayInt::New();
03311   ret->useArray(tab,true,CPP_DEALLOC,getNumberOfTuples(),getNumberOfComponents());
03312   return ret;
03313 }
03314 
03315 DataArrayInt *DataArrayInt::toNoInterlace() const throw(INTERP_KERNEL::Exception)
03316 {
03317   if(_mem.isNull())
03318     throw INTERP_KERNEL::Exception("DataArrayInt::toNoInterlace : Not defined array !");
03319   int *tab=_mem.toNoInterlace(getNumberOfComponents());
03320   DataArrayInt *ret=DataArrayInt::New();
03321   ret->useArray(tab,true,CPP_DEALLOC,getNumberOfTuples(),getNumberOfComponents());
03322   return ret;
03323 }
03324 
03325 void DataArrayInt::renumberInPlace(const int *old2New)
03326 {
03327   int nbTuples=getNumberOfTuples();
03328   int nbOfCompo=getNumberOfComponents();
03329   int *tmp=new int[nbTuples*nbOfCompo];
03330   const int *iptr=getConstPointer();
03331   for(int i=0;i<nbTuples;i++)
03332     std::copy(iptr+nbOfCompo*i,iptr+nbOfCompo*(i+1),tmp+nbOfCompo*old2New[i]);
03333   std::copy(tmp,tmp+nbTuples*nbOfCompo,getPointer());
03334   delete [] tmp;
03335   declareAsNew();
03336 }
03337 
03338 void DataArrayInt::renumberInPlaceR(const int *new2Old)
03339 {
03340   int nbTuples=getNumberOfTuples();
03341   int nbOfCompo=getNumberOfComponents();
03342   int *tmp=new int[nbTuples*nbOfCompo];
03343   const int *iptr=getConstPointer();
03344   for(int i=0;i<nbTuples;i++)
03345     std::copy(iptr+nbOfCompo*new2Old[i],iptr+nbOfCompo*(new2Old[i]+1),tmp+nbOfCompo*i);
03346   std::copy(tmp,tmp+nbTuples*nbOfCompo,getPointer());
03347   delete [] tmp;
03348   declareAsNew();
03349 }
03350 
03356 DataArrayInt *DataArrayInt::renumber(const int *old2New) const
03357 {
03358   int nbTuples=getNumberOfTuples();
03359   int nbOfCompo=getNumberOfComponents();
03360   DataArrayInt *ret=DataArrayInt::New();
03361   ret->alloc(nbTuples,nbOfCompo);
03362   ret->copyStringInfoFrom(*this);
03363   const int *iptr=getConstPointer();
03364   int *optr=ret->getPointer();
03365   for(int i=0;i<nbTuples;i++)
03366     std::copy(iptr+nbOfCompo*i,iptr+nbOfCompo*(i+1),optr+nbOfCompo*old2New[i]);
03367   ret->copyStringInfoFrom(*this);
03368   return ret;
03369 }
03370 
03371 DataArrayInt *DataArrayInt::renumberR(const int *new2Old) const
03372 {
03373   int nbTuples=getNumberOfTuples();
03374   int nbOfCompo=getNumberOfComponents();
03375   DataArrayInt *ret=DataArrayInt::New();
03376   ret->alloc(nbTuples,nbOfCompo);
03377   ret->copyStringInfoFrom(*this);
03378   const int *iptr=getConstPointer();
03379   int *optr=ret->getPointer();
03380   for(int i=0;i<nbTuples;i++)
03381     std::copy(iptr+nbOfCompo*new2Old[i],iptr+nbOfCompo*(new2Old[i]+1),optr+nbOfCompo*i);
03382   ret->copyStringInfoFrom(*this);
03383   return ret;
03384 }
03385 
03392 DataArrayInt *DataArrayInt::renumberAndReduce(const int *old2New, int newNbOfTuple) const
03393 {
03394   int nbTuples=getNumberOfTuples();
03395   int nbOfCompo=getNumberOfComponents();
03396   DataArrayInt *ret=DataArrayInt::New();
03397   ret->alloc(newNbOfTuple,nbOfCompo);
03398   const int *iptr=getConstPointer();
03399   int *optr=ret->getPointer();
03400   for(int i=0;i<nbTuples;i++)
03401     {
03402       int w=old2New[i];
03403       if(w>=0)
03404         std::copy(iptr+i*nbOfCompo,iptr+(i+1)*nbOfCompo,optr+w*nbOfCompo);
03405     }
03406   ret->copyStringInfoFrom(*this);
03407   return ret;
03408 }
03409 
03414 DataArrayInt *DataArrayInt::selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const
03415 {
03416   DataArrayInt *ret=DataArrayInt::New();
03417   int nbComp=getNumberOfComponents();
03418   ret->alloc((int)std::distance(new2OldBg,new2OldEnd),nbComp);
03419   ret->copyStringInfoFrom(*this);
03420   int *pt=ret->getPointer();
03421   const int *srcPt=getConstPointer();
03422   int i=0;
03423   for(const int *w=new2OldBg;w!=new2OldEnd;w++,i++)
03424     std::copy(srcPt+(*w)*nbComp,srcPt+((*w)+1)*nbComp,pt+i*nbComp);
03425   ret->copyStringInfoFrom(*this);
03426   return ret;
03427 }
03428 
03432 DataArrayInt *DataArrayInt::selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const throw(INTERP_KERNEL::Exception)
03433 {
03434   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
03435   int nbComp=getNumberOfComponents();
03436   int oldNbOfTuples=getNumberOfTuples();
03437   ret->alloc((int)std::distance(new2OldBg,new2OldEnd),nbComp);
03438   ret->copyStringInfoFrom(*this);
03439   int *pt=ret->getPointer();
03440   const int *srcPt=getConstPointer();
03441   int i=0;
03442   for(const int *w=new2OldBg;w!=new2OldEnd;w++,i++)
03443     if(*w>=0 && *w<oldNbOfTuples)
03444       std::copy(srcPt+(*w)*nbComp,srcPt+((*w)+1)*nbComp,pt+i*nbComp);
03445     else
03446       throw INTERP_KERNEL::Exception("DataArrayInt::selectByTupleIdSafe : some ids has been detected to be out of [0,this->getNumberOfTuples) !");
03447   ret->copyStringInfoFrom(*this);
03448   ret->incrRef();
03449   return ret;
03450 }
03451 
03457 DataArrayInt *DataArrayInt::selectByTupleId2(int bg, int end2, int step) const throw(INTERP_KERNEL::Exception)
03458 {
03459   if(end2<bg)
03460     throw INTERP_KERNEL::Exception("DataArrayInt::selectByTupleId2 : end before begin !");
03461   if(step<=0)
03462     throw INTERP_KERNEL::Exception("DataArrayInt::selectByTupleId2 : invalid step should > 0 !");
03463   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
03464   int nbComp=getNumberOfComponents();
03465   int newNbOfTuples=(end2+1-bg)/step-1;
03466   ret->alloc(newNbOfTuples,nbComp);
03467   int *pt=ret->getPointer();
03468   const int *srcPt=getConstPointer()+bg*nbComp;
03469   for(int i=0;i<newNbOfTuples;i++,srcPt+=step*nbComp)
03470     std::copy(srcPt,srcPt+nbComp,pt+i*nbComp);
03471   ret->copyStringInfoFrom(*this);
03472   ret->incrRef();
03473   return ret;
03474 }
03475 
03481 DataArrayInt *DataArrayInt::selectByTupleRanges(const std::vector<std::pair<int,int> >& ranges) const throw(INTERP_KERNEL::Exception)
03482 {
03483   checkAllocated();
03484   int nbOfComp=getNumberOfComponents();
03485   int nbOfTuplesThis=getNumberOfTuples();
03486   if(ranges.empty())
03487     {
03488       DataArrayInt *ret=DataArrayInt::New();
03489       ret->alloc(0,nbOfComp);
03490       ret->copyStringInfoFrom(*this);
03491       return ret;
03492     }
03493   int ref=ranges.front().first;
03494   int nbOfTuples=0;
03495   bool isIncreasing=true;
03496   for(std::vector<std::pair<int,int> >::const_iterator it=ranges.begin();it!=ranges.end();it++)
03497     {
03498       if((*it).first<=(*it).second)
03499         {
03500           if((*it).first>=0 && (*it).second<=nbOfTuplesThis)
03501             {
03502               nbOfTuples+=(*it).second-(*it).first;
03503               if(isIncreasing)
03504                 isIncreasing=ref<=(*it).first;
03505               ref=(*it).second;
03506             }
03507           else
03508             {
03509               std::ostringstream oss; oss << "DataArrayInt::selectByTupleRanges : on range #" << std::distance(ranges.begin(),it);
03510               oss << " (" << (*it).first << "," << (*it).second << ") is greater than number of tuples of this :" << nbOfTuples << " !";
03511               throw INTERP_KERNEL::Exception(oss.str().c_str());
03512             }
03513         }
03514       else
03515         {
03516           std::ostringstream oss; oss << "DataArrayInt::selectByTupleRanges : on range #" << std::distance(ranges.begin(),it);
03517           oss << " (" << (*it).first << "," << (*it).second << ") end is before begin !";
03518           throw INTERP_KERNEL::Exception(oss.str().c_str());
03519         }
03520     }
03521   if(isIncreasing && nbOfTuplesThis==nbOfTuples)
03522     return deepCpy();
03523   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
03524   ret->alloc(nbOfTuples,nbOfComp);
03525   ret->copyStringInfoFrom(*this);
03526   const int *src=getConstPointer();
03527   int *work=ret->getPointer();
03528   for(std::vector<std::pair<int,int> >::const_iterator it=ranges.begin();it!=ranges.end();it++)
03529     work=std::copy(src+(*it).first*nbOfComp,src+(*it).second*nbOfComp,work);
03530   ret->incrRef();
03531   return ret;
03532 }
03533 
03541 DataArrayInt *DataArrayInt::checkAndPreparePermutation() const throw(INTERP_KERNEL::Exception)
03542 {
03543   checkAllocated();
03544   if(getNumberOfComponents()!=1)
03545     throw INTERP_KERNEL::Exception("DataArrayInt::checkAndPreparePermutation : number of components must == 1 !");
03546   int nbTuples=getNumberOfTuples();
03547   const int *pt=getConstPointer();
03548   int *pt2=CheckAndPreparePermutation(pt,pt+nbTuples);
03549   DataArrayInt *ret=DataArrayInt::New();
03550   ret->useArray(pt2,true,CPP_DEALLOC,nbTuples,1);
03551   return ret;
03552 }
03553 
03565 void DataArrayInt::changeSurjectiveFormat(int targetNb, DataArrayInt *&arr, DataArrayInt *&arrI) const throw(INTERP_KERNEL::Exception)
03566 {
03567   checkAllocated();
03568   if(getNumberOfComponents()!=1)
03569     throw INTERP_KERNEL::Exception("DataArrayInt::changeSurjectiveFormat : number of components must == 1 !");
03570   int nbOfTuples=getNumberOfTuples();
03571   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New());
03572   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> retI(DataArrayInt::New());
03573   retI->alloc(targetNb+1,1);
03574   const int *input=getConstPointer();
03575   std::vector< std::vector<int> > tmp(targetNb);
03576   for(int i=0;i<nbOfTuples;i++)
03577     {
03578       int tmp2=input[i];
03579       if(tmp2<targetNb)
03580         tmp[tmp2].push_back(i);
03581       else
03582         {
03583           std::ostringstream oss; oss << "DataArrayInt::changeSurjectiveFormat : At pos " << i << " presence of element " << tmp2 << " higher than " << targetNb;
03584           throw INTERP_KERNEL::Exception(oss.str().c_str());
03585         }
03586     }
03587   int *retIPtr=retI->getPointer();
03588   *retIPtr=0;
03589   for(std::vector< std::vector<int> >::const_iterator it1=tmp.begin();it1!=tmp.end();it1++,retIPtr++)
03590     retIPtr[1]=retIPtr[0]+(int)((*it1).size());
03591   if(nbOfTuples!=retI->getIJ(targetNb,0))
03592     throw INTERP_KERNEL::Exception("DataArrayInt::changeSurjectiveFormat : big problem should never happen !");
03593   ret->alloc(nbOfTuples,1);
03594   int *retPtr=ret->getPointer();
03595   for(std::vector< std::vector<int> >::const_iterator it1=tmp.begin();it1!=tmp.end();it1++)
03596     retPtr=std::copy((*it1).begin(),(*it1).end(),retPtr);
03597   ret->incrRef();
03598   retI->incrRef();
03599   arr=ret;
03600   arrI=retI;
03601 }
03602 
03614 DataArrayInt *DataArrayInt::BuildOld2NewArrayFromSurjectiveFormat2(int nbOfOldTuples, const DataArrayInt *arr, const DataArrayInt *arrI, int &newNbOfTuples) throw(INTERP_KERNEL::Exception)
03615 {
03616   DataArrayInt *ret=DataArrayInt::New();
03617   ret->alloc(nbOfOldTuples,1);
03618   int *pt=ret->getPointer();
03619   std::fill(pt,pt+nbOfOldTuples,-1);
03620   int nbOfGrps=arrI->getNumberOfTuples()-1;
03621   const int *cIPtr=arrI->getConstPointer();
03622   const int *cPtr=arr->getConstPointer();
03623   for(int i=0;i<nbOfGrps;i++)
03624     pt[cPtr[cIPtr[i]]]=-(i+2);
03625   int newNb=0;
03626   for(int iNode=0;iNode<nbOfOldTuples;iNode++)
03627     {
03628       if(pt[iNode]<0)
03629         {
03630           if(pt[iNode]==-1)
03631             pt[iNode]=newNb++;
03632           else
03633             {
03634               int grpId=-(pt[iNode]+2);
03635               for(int j=cIPtr[grpId];j<cIPtr[grpId+1];j++)
03636                 pt[cPtr[j]]=newNb;
03637               newNb++;
03638             }
03639         }
03640     }
03641   newNbOfTuples=newNb;
03642   return ret;
03643 }
03644 
03655 DataArrayInt *DataArrayInt::buildPermArrPerLevel() const throw(INTERP_KERNEL::Exception)
03656 {
03657   checkAllocated();
03658   if(getNumberOfComponents()!=1)
03659     throw INTERP_KERNEL::Exception("DataArrayInt::buildPermArrPerLevel : number of components must == 1 !");
03660   int nbOfTuples=getNumberOfTuples();
03661   const int *pt=getConstPointer();
03662   std::map<int,int> m;
03663   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
03664   ret->alloc(nbOfTuples,1);
03665   int *opt=ret->getPointer();
03666   for(int i=0;i<nbOfTuples;i++,pt++,opt++)
03667     {
03668       int val=*pt;
03669       std::map<int,int>::iterator it=m.find(val);
03670       if(it!=m.end())
03671         {
03672           *opt=(*it).second;
03673           (*it).second++;
03674         }
03675       else
03676         {
03677           *opt=0;
03678           m.insert(std::pair<int,int>(val,1));
03679         }
03680     }
03681   int sum=0;
03682   for(std::map<int,int>::iterator it=m.begin();it!=m.end();it++)
03683     {
03684       int vt=(*it).second;
03685       (*it).second=sum;
03686       sum+=vt;
03687     }
03688   pt=getConstPointer();
03689   opt=ret->getPointer();
03690   for(int i=0;i<nbOfTuples;i++,pt++,opt++)
03691     *opt+=m[*pt];
03692   //
03693   ret->incrRef();
03694   return ret;
03695 }
03696 
03702 bool DataArrayInt::isIdentity() const throw(INTERP_KERNEL::Exception)
03703 {
03704   checkAllocated();
03705   if(getNumberOfComponents()!=1)
03706     return false;
03707   int nbOfTuples=getNumberOfTuples();
03708   const int *pt=getConstPointer();
03709   for(int i=0;i<nbOfTuples;i++,pt++)
03710     if(*pt!=i)
03711       return false;
03712   return true;
03713 }
03714 
03715 bool DataArrayInt::isUniform(int val) const throw(INTERP_KERNEL::Exception)
03716 {
03717   checkAllocated();
03718   if(getNumberOfComponents()!=1)
03719     throw INTERP_KERNEL::Exception("DataArrayInt::isUniform : must be applied on DataArrayInt with only one component, you can call 'rearrange' method before !");
03720   int nbOfTuples=getNumberOfTuples();
03721   const int *w=getConstPointer();
03722   const int *end2=w+nbOfTuples;
03723   for(;w!=end2;w++)
03724     if(*w!=val)
03725       return false;
03726   return true;
03727 }
03728 
03729 DataArrayDouble *DataArrayInt::convertToDblArr() const
03730 {
03731   checkAllocated();
03732   DataArrayDouble *ret=DataArrayDouble::New();
03733   ret->alloc(getNumberOfTuples(),getNumberOfComponents());
03734   int nbOfVals=getNbOfElems();
03735   const int *src=getConstPointer();
03736   double *dest=ret->getPointer();
03737   std::copy(src,src+nbOfVals,dest);
03738   ret->copyStringInfoFrom(*this);
03739   return ret;
03740 }
03741 
03747 DataArrayInt *DataArrayInt::substr(int tupleIdBg, int tupleIdEnd) const throw(INTERP_KERNEL::Exception)
03748 {
03749   int nbt=getNumberOfTuples();
03750   if(tupleIdBg<0)
03751     throw INTERP_KERNEL::Exception("DataArrayInt::substr : The tupleIdBg parameter must be greater than 0 !");
03752   if(tupleIdBg>nbt)
03753     throw INTERP_KERNEL::Exception("DataArrayInt::substr : The tupleIdBg parameter is greater than number of tuples !");
03754   int trueEnd=tupleIdEnd;
03755   if(tupleIdEnd!=-1)
03756     {
03757       if(tupleIdEnd>nbt)
03758         throw INTERP_KERNEL::Exception("DataArrayInt::substr : The tupleIdBg parameter is greater or equal than number of tuples !");
03759     }
03760   else
03761     trueEnd=nbt;
03762   int nbComp=getNumberOfComponents();
03763   DataArrayInt *ret=DataArrayInt::New();
03764   ret->alloc(trueEnd-tupleIdBg,nbComp);
03765   ret->copyStringInfoFrom(*this);
03766   std::copy(getConstPointer()+tupleIdBg*nbComp,getConstPointer()+trueEnd*nbComp,ret->getPointer());
03767   return ret;
03768 }
03769 
03777 void DataArrayInt::rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception)
03778 {
03779   checkAllocated();
03780   int nbOfElems=getNbOfElems();
03781   if(nbOfElems%newNbOfCompo!=0)
03782     throw INTERP_KERNEL::Exception("DataArrayInt::rearrange : nbOfElems%newNbOfCompo!=0 !");
03783   _nb_of_tuples=nbOfElems/newNbOfCompo;
03784   _info_on_compo.clear();
03785   _info_on_compo.resize(newNbOfCompo);
03786   declareAsNew();
03787 }
03788 
03794 void DataArrayInt::transpose() throw(INTERP_KERNEL::Exception)
03795 {
03796   checkAllocated();
03797   int nbOfTuples=getNumberOfTuples();
03798   rearrange(nbOfTuples);
03799 }
03800 
03806 DataArrayInt *DataArrayInt::changeNbOfComponents(int newNbOfComp, int dftValue) const throw(INTERP_KERNEL::Exception)
03807 {
03808   checkAllocated();
03809   DataArrayInt *ret=DataArrayInt::New();
03810   ret->alloc(getNumberOfTuples(),newNbOfComp);
03811   const int *oldc=getConstPointer();
03812   int *nc=ret->getPointer();
03813   int nbOfTuples=getNumberOfTuples();
03814   int oldNbOfComp=getNumberOfComponents();
03815   int dim=std::min(oldNbOfComp,newNbOfComp);
03816   for(int i=0;i<nbOfTuples;i++)
03817     {
03818       int j=0;
03819       for(;j<dim;j++)
03820         nc[newNbOfComp*i+j]=oldc[i*oldNbOfComp+j];
03821       for(;j<newNbOfComp;j++)
03822         nc[newNbOfComp*i+j]=dftValue;
03823     }
03824   ret->setName(getName().c_str());
03825   for(int i=0;i<dim;i++)
03826     ret->setInfoOnComponent(i,getInfoOnComponent(i).c_str());
03827   ret->setName(getName().c_str());
03828   return ret;
03829 }
03830 
03831 void DataArrayInt::reAlloc(int nbOfTuples) throw(INTERP_KERNEL::Exception)
03832 {
03833   checkAllocated();
03834   _mem.reAlloc((int)_info_on_compo.size()*nbOfTuples);
03835   _nb_of_tuples=nbOfTuples;
03836   declareAsNew();
03837 }
03838 
03839 DataArrayInt *DataArrayInt::keepSelectedComponents(const std::vector<int>& compoIds) const throw(INTERP_KERNEL::Exception)
03840 {
03841   checkAllocated();
03842   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New());
03843   int newNbOfCompo=(int)compoIds.size();
03844   int oldNbOfCompo=getNumberOfComponents();
03845   for(std::vector<int>::const_iterator it=compoIds.begin();it!=compoIds.end();it++)
03846     DataArray::CheckValueInRange(oldNbOfCompo,(*it),"keepSelectedComponents invalid requested component");
03847   int nbOfTuples=getNumberOfTuples();
03848   ret->alloc(nbOfTuples,newNbOfCompo);
03849   ret->copyPartOfStringInfoFrom(*this,compoIds);
03850   const int *oldc=getConstPointer();
03851   int *nc=ret->getPointer();
03852   for(int i=0;i<nbOfTuples;i++)
03853     for(int j=0;j<newNbOfCompo;j++,nc++)
03854       *nc=oldc[i*oldNbOfCompo+compoIds[j]];
03855   ret->incrRef();
03856   return ret;
03857 }
03858 
03865 void DataArrayInt::meldWith(const DataArrayInt *other) throw(INTERP_KERNEL::Exception)
03866 {
03867   checkAllocated();
03868   other->checkAllocated();
03869   int nbOfTuples=getNumberOfTuples();
03870   if(nbOfTuples!=other->getNumberOfTuples())
03871     throw INTERP_KERNEL::Exception("DataArrayInt::meldWith : mismatch of number of tuples !");
03872   int nbOfComp1=getNumberOfComponents();
03873   int nbOfComp2=other->getNumberOfComponents();
03874   int *newArr=new int[nbOfTuples*(nbOfComp1+nbOfComp2)];
03875   int *w=newArr;
03876   const int *inp1=getConstPointer();
03877   const int *inp2=other->getConstPointer();
03878   for(int i=0;i<nbOfTuples;i++,inp1+=nbOfComp1,inp2+=nbOfComp2)
03879     {
03880       w=std::copy(inp1,inp1+nbOfComp1,w);
03881       w=std::copy(inp2,inp2+nbOfComp2,w);
03882     }
03883   useArray(newArr,true,CPP_DEALLOC,nbOfTuples,nbOfComp1+nbOfComp2);
03884   std::vector<int> compIds(nbOfComp2);
03885   for(int i=0;i<nbOfComp2;i++)
03886     compIds[i]=nbOfComp1+i;
03887   copyPartOfStringInfoFrom2(compIds,*other);
03888 }
03889 
03890 void DataArrayInt::setSelectedComponents(const DataArrayInt *a, const std::vector<int>& compoIds) throw(INTERP_KERNEL::Exception)
03891 {
03892   copyPartOfStringInfoFrom2(compoIds,*a);
03893   std::size_t partOfCompoSz=compoIds.size();
03894   int nbOfCompo=getNumberOfComponents();
03895   int nbOfTuples=getNumberOfTuples();
03896   const int *ac=a->getConstPointer();
03897   int *nc=getPointer();
03898   for(int i=0;i<nbOfTuples;i++)
03899     for(std::size_t j=0;j<partOfCompoSz;j++,ac++)
03900       nc[nbOfCompo*i+compoIds[j]]=*ac;
03901 }
03902 
03907 void DataArrayInt::setPartOfValues1(const DataArrayInt *a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
03908 {
03909   const char msg[]="DataArrayInt::setPartOfValues1";
03910   checkAllocated();
03911   a->checkAllocated();
03912   int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
03913   int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
03914   int nbComp=getNumberOfComponents();
03915   int nbOfTuples=getNumberOfTuples();
03916   DataArray::CheckValueInRange(nbOfTuples,bgTuples,"invalid begin tuple value");
03917   DataArray::CheckClosingParInRange(nbOfTuples,endTuples,"invalid end tuple value");
03918   DataArray::CheckValueInRange(nbComp,bgComp,"invalid begin component value");
03919   DataArray::CheckClosingParInRange(nbComp,endComp,"invalid end component value");
03920   a->checkNbOfElems(newNbOfTuples*newNbOfComp,msg);
03921   if(strictCompoCompare)
03922     a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
03923   int *pt=getPointer()+bgTuples*nbComp+bgComp;
03924   const int *srcPt=a->getConstPointer();
03925   for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
03926     for(int j=0;j<newNbOfComp;j++,srcPt++)
03927       pt[j*stepComp]=*srcPt;
03928 }
03929 
03933 void DataArrayInt::setPartOfValuesSimple1(int a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception)
03934 {
03935   const char msg[]="DataArrayInt::setPartOfValuesSimple1";
03936   checkAllocated();
03937   int newNbOfTuples=DataArray::GetNumberOfItemGivenBES(bgTuples,endTuples,stepTuples,msg);
03938   int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
03939   int nbComp=getNumberOfComponents();
03940   int nbOfTuples=getNumberOfTuples();
03941   DataArray::CheckValueInRange(nbOfTuples,bgTuples,"invalid begin tuple value");
03942   DataArray::CheckClosingParInRange(nbOfTuples,endTuples,"invalid end tuple value");
03943   DataArray::CheckValueInRange(nbComp,bgComp,"invalid begin component value");
03944   DataArray::CheckClosingParInRange(nbComp,endComp,"invalid end component value");
03945   int *pt=getPointer()+bgTuples*nbComp+bgComp;
03946   for(int i=0;i<newNbOfTuples;i++,pt+=stepTuples*nbComp)
03947     for(int j=0;j<newNbOfComp;j++)
03948       pt[j*stepComp]=a;
03949 }
03950 
03955 void DataArrayInt::setPartOfValues2(const DataArrayInt *a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
03956 {
03957   const char msg[]="DataArrayInt::setPartOfValues2";
03958   checkAllocated();
03959   a->checkAllocated();
03960   int nbComp=getNumberOfComponents();
03961   int nbOfTuples=getNumberOfTuples();
03962   for(const int *z=bgComp;z!=endComp;z++)
03963     DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
03964   int newNbOfTuples=(int)std::distance(bgTuples,endTuples);
03965   int newNbOfComp=(int)std::distance(bgComp,endComp);
03966   bool assignTech=true;
03967   if(a->getNbOfElems()==newNbOfTuples*newNbOfComp)
03968     {
03969       if(strictCompoCompare)
03970         a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
03971     }
03972   else
03973     {
03974       a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
03975       assignTech=false;
03976     }
03977   int *pt=getPointer();
03978   const int *srcPt=a->getConstPointer();
03979   if(assignTech)
03980     {    
03981       for(const int *w=bgTuples;w!=endTuples;w++)
03982         {
03983           DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
03984           for(const int *z=bgComp;z!=endComp;z++,srcPt++)
03985             {    
03986               pt[(*w)*nbComp+(*z)]=*srcPt;
03987             }
03988         }
03989     }
03990   else
03991     {
03992       for(const int *w=bgTuples;w!=endTuples;w++)
03993         {
03994           const int *srcPt2=srcPt;
03995           DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
03996           for(const int *z=bgComp;z!=endComp;z++,srcPt2++)
03997             {    
03998               pt[(*w)*nbComp+(*z)]=*srcPt2;
03999             }
04000         }
04001     }
04002 }
04003 
04007 void DataArrayInt::setPartOfValuesSimple2(int a, const int *bgTuples, const int *endTuples, const int *bgComp, const int *endComp) throw(INTERP_KERNEL::Exception)
04008 {
04009   checkAllocated();
04010   int nbComp=getNumberOfComponents();
04011   int nbOfTuples=getNumberOfTuples();
04012   for(const int *z=bgComp;z!=endComp;z++)
04013     DataArray::CheckValueInRange(nbComp,*z,"invalid component id");
04014   int *pt=getPointer();
04015   for(const int *w=bgTuples;w!=endTuples;w++)
04016     for(const int *z=bgComp;z!=endComp;z++)
04017       {
04018         DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
04019         pt[(*w)*nbComp+(*z)]=a;
04020       }
04021 }
04022 
04027 void DataArrayInt::setPartOfValues3(const DataArrayInt *a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare) throw(INTERP_KERNEL::Exception)
04028 {
04029   const char msg[]="DataArrayInt::setPartOfValues3";
04030   checkAllocated();
04031   a->checkAllocated();
04032   int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
04033   int nbComp=getNumberOfComponents();
04034   int nbOfTuples=getNumberOfTuples();
04035   DataArray::CheckValueInRange(nbComp,bgComp,"invalid begin component value");
04036   DataArray::CheckClosingParInRange(nbComp,endComp,"invalid end component value");
04037   int newNbOfTuples=(int)std::distance(bgTuples,endTuples);
04038   bool assignTech=true;
04039   if(a->getNbOfElems()==newNbOfTuples*newNbOfComp)
04040     {
04041       if(strictCompoCompare)
04042         a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg);
04043     }
04044   else
04045     {
04046       a->checkNbOfTuplesAndComp(1,newNbOfComp,msg);
04047       assignTech=false;
04048     }
04049   int *pt=getPointer()+bgComp;
04050   const int *srcPt=a->getConstPointer();
04051   if(assignTech)
04052     {
04053       for(const int *w=bgTuples;w!=endTuples;w++)
04054         for(int j=0;j<newNbOfComp;j++,srcPt++)
04055           {
04056             DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
04057             pt[(*w)*nbComp+j*stepComp]=*srcPt;
04058           }
04059     }
04060   else
04061     {
04062       for(const int *w=bgTuples;w!=endTuples;w++)
04063         {
04064           const int *srcPt2=srcPt;
04065           for(int j=0;j<newNbOfComp;j++,srcPt2++)
04066             {
04067               DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
04068               pt[(*w)*nbComp+j*stepComp]=*srcPt2;
04069             }
04070         }
04071     }
04072 }
04073 
04077 void DataArrayInt::setPartOfValuesSimple3(int a, const int *bgTuples, const int *endTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception)
04078 {
04079   const char msg[]="DataArrayInt::setPartOfValuesSimple3";
04080   checkAllocated();
04081   int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg);
04082   int nbComp=getNumberOfComponents();
04083   int nbOfTuples=getNumberOfTuples();
04084   DataArray::CheckValueInRange(nbComp,bgComp,"invalid begin component value");
04085   DataArray::CheckClosingParInRange(nbComp,endComp,"invalid end component value");
04086   int *pt=getPointer()+bgComp;
04087   for(const int *w=bgTuples;w!=endTuples;w++)
04088     for(int j=0;j<newNbOfComp;j++)
04089       {
04090         DataArray::CheckValueInRange(nbOfTuples,*w,"invalid tuple id");
04091         pt[(*w)*nbComp+j*stepComp]=a;
04092       }
04093 }
04094 
04100 void DataArrayInt::setPartOfValuesAdv(const DataArrayInt *a, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception)
04101 {
04102   checkAllocated();
04103   a->checkAllocated();
04104   tuplesSelec->checkAllocated();
04105   int nbOfComp=getNumberOfComponents();
04106   if(nbOfComp!=a->getNumberOfComponents())
04107     throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValuesAdv : This and a do not have the same number of components !");
04108   if(tuplesSelec->getNumberOfComponents()!=2)
04109     throw INTERP_KERNEL::Exception("DataArrayInt::setPartOfValuesAdv : Expecting to have a tuple selector DataArrayInt instance with exactly 2 components !");
04110   int thisNt=getNumberOfTuples();
04111   int aNt=a->getNumberOfTuples();
04112   int *valsToSet=getPointer();
04113   const int *valsSrc=a->getConstPointer();
04114   for(const int *tuple=tuplesSelec->begin();tuple!=tuplesSelec->end();tuple+=2)
04115     {
04116       if(tuple[1]>=0 && tuple[1]<aNt)
04117         {
04118           if(tuple[0]>=0 && tuple[0]<thisNt)
04119             std::copy(valsSrc+nbOfComp*tuple[1],valsSrc+nbOfComp*(tuple[1]+1),valsToSet+nbOfComp*tuple[0]);
04120           else
04121             {
04122               std::ostringstream oss; oss << "DataArrayInt::setPartOfValuesAdv : Tuple #" << std::distance(tuplesSelec->begin(),tuple)/2;
04123               oss << " of 'tuplesSelec' request of tuple id #" << tuple[0] << " in 'this' ! It should be in [0," << thisNt << ") !";
04124               throw INTERP_KERNEL::Exception(oss.str().c_str());
04125             }
04126         }
04127       else
04128         {
04129           std::ostringstream oss; oss << "DataArrayInt::setPartOfValuesAdv : Tuple #" << std::distance(tuplesSelec->begin(),tuple)/2;
04130           oss << " of 'tuplesSelec' request of tuple id #" << tuple[1] << " in 'a' ! It should be in [0," << aNt << ") !";
04131           throw INTERP_KERNEL::Exception(oss.str().c_str());
04132         }
04133     }
04134 }
04135 
04142 void DataArrayInt::setContigPartOfSelectedValues(int tupleIdStart, const DataArrayInt*a, const DataArrayInt *tuplesSelec) throw(INTERP_KERNEL::Exception)
04143 {
04144   checkAllocated();
04145   a->checkAllocated();
04146   tuplesSelec->checkAllocated();
04147   int nbOfComp=getNumberOfComponents();
04148   if(nbOfComp!=a->getNumberOfComponents())
04149     throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues : This and a do not have the same number of components !");
04150   if(tuplesSelec->getNumberOfComponents()!=1)
04151     throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues : Expecting to have a tuple selector DataArrayInt instance with exactly 1 component !");
04152   int thisNt=getNumberOfTuples();
04153   int aNt=a->getNumberOfTuples();
04154   int nbOfTupleToWrite=tuplesSelec->getNumberOfTuples();
04155   int *valsToSet=getPointer()+tupleIdStart*nbOfComp;
04156   if(tupleIdStart+nbOfTupleToWrite>thisNt)
04157     throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues : invalid number range of values to write !");
04158   const int *valsSrc=a->getConstPointer();
04159   for(const int *tuple=tuplesSelec->begin();tuple!=tuplesSelec->end();tuple++,valsToSet+=nbOfComp)
04160     {
04161       if(*tuple>=0 && *tuple<aNt)
04162         {
04163           std::copy(valsSrc+nbOfComp*(*tuple),valsSrc+nbOfComp*(*tuple+1),valsToSet);
04164         }
04165       else
04166         {
04167           std::ostringstream oss; oss << "DataArrayInt::setContigPartOfSelectedValues : Tuple #" << std::distance(tuplesSelec->begin(),tuple);
04168           oss << " of 'tuplesSelec' request of tuple id #" << *tuple << " in 'a' ! It should be in [0," << aNt << ") !";
04169           throw INTERP_KERNEL::Exception(oss.str().c_str());
04170         }
04171     }
04172 }
04173 
04180 void DataArrayInt::setContigPartOfSelectedValues2(int tupleIdStart, const DataArrayInt *a, int bg, int end2, int step) throw(INTERP_KERNEL::Exception)
04181 {
04182   checkAllocated();
04183   a->checkAllocated();
04184   int nbOfComp=getNumberOfComponents();
04185   const char msg[]="DataArrayInt::setContigPartOfSelectedValues2";
04186   int nbOfTupleToWrite=DataArray::GetNumberOfItemGivenBES(bg,end2,step,msg);
04187   if(nbOfComp!=a->getNumberOfComponents())
04188     throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues2 : This and a do not have the same number of components !");
04189   int thisNt=getNumberOfTuples();
04190   int aNt=a->getNumberOfTuples();
04191   int *valsToSet=getPointer()+tupleIdStart*nbOfComp;
04192   if(tupleIdStart+nbOfTupleToWrite>thisNt)
04193     throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues2 : invalid number range of values to write !");
04194   if(end2>aNt)
04195     throw INTERP_KERNEL::Exception("DataArrayInt::setContigPartOfSelectedValues2 : invalid range of values to read !");
04196   const int *valsSrc=a->getConstPointer()+bg*nbOfComp;
04197   for(int i=0;i<nbOfTupleToWrite;i++,valsToSet+=nbOfComp,valsSrc+=step*nbOfComp)
04198     {
04199       std::copy(valsSrc,valsSrc+nbOfComp,valsToSet);
04200     }
04201 }
04202 
04208 int DataArrayInt::getIJSafe(int tupleId, int compoId) const throw(INTERP_KERNEL::Exception)
04209 {
04210   checkAllocated();
04211   if(tupleId<0 || tupleId>=getNumberOfTuples())
04212     {
04213       std::ostringstream oss; oss << "DataArrayInt::getIJSafe : request for tupleId " << tupleId << " should be in [0," << getNumberOfTuples() << ") !";
04214       throw INTERP_KERNEL::Exception(oss.str().c_str());
04215     }
04216   if(compoId<0 || compoId>=getNumberOfComponents())
04217     {
04218       std::ostringstream oss; oss << "DataArrayInt::getIJSafe : request for compoId " << compoId << " should be in [0," << getNumberOfComponents() << ") !";
04219       throw INTERP_KERNEL::Exception(oss.str().c_str());
04220     }
04221   return _mem[tupleId*((int)_info_on_compo.size())+compoId];
04222 }
04223 
04229 int DataArrayInt::back() const throw(INTERP_KERNEL::Exception)
04230 {
04231   checkAllocated();
04232   if(getNumberOfComponents()!=1)
04233     throw INTERP_KERNEL::Exception("DataArrayInt::back : number of components not equal to one !");
04234   int nbOfTuples=getNumberOfTuples();
04235   if(nbOfTuples<1)
04236     throw INTERP_KERNEL::Exception("DataArrayInt::back : number of tuples must be >= 1 !");
04237   return *(getConstPointer()+nbOfTuples-1);
04238 }
04239 
04240 void DataArrayInt::SetArrayIn(DataArrayInt *newArray, DataArrayInt* &arrayToSet)
04241 {
04242   if(newArray!=arrayToSet)
04243     {
04244       if(arrayToSet)
04245         arrayToSet->decrRef();
04246       arrayToSet=newArray;
04247       if(arrayToSet)
04248         arrayToSet->incrRef();
04249     }
04250 }
04251 
04252 DataArrayIntIterator *DataArrayInt::iterator()
04253 {
04254   return new DataArrayIntIterator(this);
04255 }
04256 
04257 DataArrayInt *DataArrayInt::getIdsEqual(int val) const throw(INTERP_KERNEL::Exception)
04258 {
04259   if(getNumberOfComponents()!=1)
04260     throw INTERP_KERNEL::Exception("DataArrayInt::getIdsEqual : the array must have only one component, you can call 'rearrange' method before !");
04261   const int *cptr=getConstPointer();
04262   std::vector<int> res;
04263   int nbOfTuples=getNumberOfTuples();
04264   for(int i=0;i<nbOfTuples;i++,cptr++)
04265     if(*cptr==val)
04266       res.push_back(i);
04267   DataArrayInt *ret=DataArrayInt::New();
04268   ret->alloc((int)res.size(),1);
04269   std::copy(res.begin(),res.end(),ret->getPointer());
04270   return ret;
04271 }
04272 
04273 DataArrayInt *DataArrayInt::getIdsNotEqual(int val) const throw(INTERP_KERNEL::Exception)
04274 {
04275   if(getNumberOfComponents()!=1)
04276     throw INTERP_KERNEL::Exception("DataArrayInt::getIdsNotEqual : the array must have only one component, you can call 'rearrange' method before !");
04277   const int *cptr=getConstPointer();
04278   std::vector<int> res;
04279   int nbOfTuples=getNumberOfTuples();
04280   for(int i=0;i<nbOfTuples;i++,cptr++)
04281     if(*cptr!=val)
04282       res.push_back(i);
04283   DataArrayInt *ret=DataArrayInt::New();
04284   ret->alloc((int)res.size(),1);
04285   std::copy(res.begin(),res.end(),ret->getPointer());
04286   return ret;
04287 }
04288 
04295 int DataArrayInt::changeValue(int oldValue, int newValue) throw(INTERP_KERNEL::Exception)
04296 {
04297   if(getNumberOfComponents()!=1)
04298     throw INTERP_KERNEL::Exception("DataArrayInt::changeValue : the array must have only one component, you can call 'rearrange' method before !");
04299   checkAllocated();
04300   int *start=getPointer();
04301   int *end2=start+getNbOfElems();
04302   int ret=0;
04303   for(int *val=start;val!=end2;val++)
04304     {
04305       if(*val==oldValue)
04306         {
04307           *val=newValue;
04308           ret++;
04309         }
04310     }
04311   return ret;
04312 }
04313 
04314 DataArrayInt *DataArrayInt::getIdsEqualList(const std::vector<int>& vals) const throw(INTERP_KERNEL::Exception)
04315 {
04316   if(getNumberOfComponents()!=1)
04317     throw INTERP_KERNEL::Exception("DataArrayInt::getIdsEqualList : the array must have only one component, you can call 'rearrange' method before !");
04318   std::set<int> vals2(vals.begin(),vals.end());
04319   const int *cptr=getConstPointer();
04320   std::vector<int> res;
04321   int nbOfTuples=getNumberOfTuples();
04322   for(int i=0;i<nbOfTuples;i++,cptr++)
04323     if(vals2.find(*cptr)!=vals2.end())
04324       res.push_back(i);
04325   DataArrayInt *ret=DataArrayInt::New();
04326   ret->alloc((int)res.size(),1);
04327   std::copy(res.begin(),res.end(),ret->getPointer());
04328   return ret;
04329 }
04330 
04331 DataArrayInt *DataArrayInt::getIdsNotEqualList(const std::vector<int>& vals) const throw(INTERP_KERNEL::Exception)
04332 {
04333   if(getNumberOfComponents()!=1)
04334     throw INTERP_KERNEL::Exception("DataArrayInt::getIdsNotEqualList : the array must have only one component, you can call 'rearrange' method before !");
04335   std::set<int> vals2(vals.begin(),vals.end());
04336   const int *cptr=getConstPointer();
04337   std::vector<int> res;
04338   int nbOfTuples=getNumberOfTuples();
04339   for(int i=0;i<nbOfTuples;i++,cptr++)
04340     if(vals2.find(*cptr)==vals2.end())
04341       res.push_back(i);
04342   DataArrayInt *ret=DataArrayInt::New();
04343   ret->alloc((int)res.size(),1);
04344   std::copy(res.begin(),res.end(),ret->getPointer());
04345   return ret;
04346 }
04347 
04353 bool DataArrayInt::presenceOfValue(const std::vector<int>& vals) const throw(INTERP_KERNEL::Exception)
04354 {
04355   if(getNumberOfComponents()!=1)
04356     throw INTERP_KERNEL::Exception("DataArrayInt::presenceOfValue : the array must have only one component, you can call 'rearrange' method before !");
04357   std::set<int> vals2(vals.begin(),vals.end());
04358   const int *cptr=getConstPointer();
04359   int nbOfTuples=getNumberOfTuples();
04360   bool found=false;
04361   for(const int *w=cptr;w!=cptr+nbOfTuples && !found;w++)
04362     found=(vals2.find(*w)!=vals2.end());
04363   return found;
04364 }
04365 
04366 DataArrayInt *DataArrayInt::Aggregate(const DataArrayInt *a1, const DataArrayInt *a2, int offsetA2)
04367 {
04368   int nbOfComp=a1->getNumberOfComponents();
04369   if(nbOfComp!=a2->getNumberOfComponents())
04370     throw INTERP_KERNEL::Exception("Nb of components mismatch for array Aggregation !");
04371   int nbOfTuple1=a1->getNumberOfTuples();
04372   int nbOfTuple2=a2->getNumberOfTuples();
04373   DataArrayInt *ret=DataArrayInt::New();
04374   ret->alloc(nbOfTuple1+nbOfTuple2-offsetA2,nbOfComp);
04375   int *pt=std::copy(a1->getConstPointer(),a1->getConstPointer()+nbOfTuple1*nbOfComp,ret->getPointer());
04376   std::copy(a2->getConstPointer()+offsetA2*nbOfComp,a2->getConstPointer()+nbOfTuple2*nbOfComp,pt);
04377   ret->copyStringInfoFrom(*a1);
04378   return ret;
04379 }
04380 
04381 DataArrayInt *DataArrayInt::Aggregate(const std::vector<const DataArrayInt *>& a) throw(INTERP_KERNEL::Exception)
04382 {
04383   if(a.empty())
04384     throw INTERP_KERNEL::Exception("DataArrayInt::Aggregate : input list must be NON EMPTY !");
04385   std::vector<const DataArrayInt *>::const_iterator it=a.begin();
04386   int nbOfComp=(*it)->getNumberOfComponents();
04387   int nbt=(*it++)->getNumberOfTuples();
04388   for(int i=1;it!=a.end();it++,i++)
04389     {
04390       if((*it)->getNumberOfComponents()!=nbOfComp)
04391         throw INTERP_KERNEL::Exception("DataArrayInt::Aggregate : Nb of components mismatch for array aggregation !");
04392       nbt+=(*it)->getNumberOfTuples();
04393     }
04394   DataArrayInt *ret=DataArrayInt::New();
04395   ret->alloc(nbt,nbOfComp);
04396   int *pt=ret->getPointer();
04397   for(it=a.begin();it!=a.end();it++)
04398     pt=std::copy((*it)->getConstPointer(),(*it)->getConstPointer()+(*it)->getNbOfElems(),pt);
04399   ret->copyStringInfoFrom(*(a[0]));
04400   return ret;
04401 }
04402 
04403 int DataArrayInt::getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exception)
04404 {
04405   if(getNumberOfComponents()!=1)
04406     throw INTERP_KERNEL::Exception("DataArrayInt::getMaxValue : must be applied on DataArrayInt with only one component !");
04407   int nbOfTuples=getNumberOfTuples();
04408   if(nbOfTuples<=0)
04409     throw INTERP_KERNEL::Exception("DataArrayInt::getMaxValue : array exists but number of tuples must be > 0 !");
04410   const int *vals=getConstPointer();
04411   const int *loc=std::max_element(vals,vals+nbOfTuples);
04412   tupleId=(int)std::distance(vals,loc);
04413   return *loc;
04414 }
04415 
04419 int DataArrayInt::getMaxValueInArray() const throw(INTERP_KERNEL::Exception)
04420 {
04421   checkAllocated();
04422   const int *loc=std::max_element(begin(),end());
04423   return *loc;
04424 }
04425 
04426 int DataArrayInt::getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception)
04427 {
04428   if(getNumberOfComponents()!=1)
04429     throw INTERP_KERNEL::Exception("DataArrayInt::getMaxValue : must be applied on DataArrayInt with only one component !");
04430   int nbOfTuples=getNumberOfTuples();
04431   if(nbOfTuples<=0)
04432     throw INTERP_KERNEL::Exception("DataArrayInt::getMaxValue : array exists but number of tuples must be > 0 !");
04433   const int *vals=getConstPointer();
04434   const int *loc=std::min_element(vals,vals+nbOfTuples);
04435   tupleId=(int)std::distance(vals,loc);
04436   return *loc;
04437 }
04438 
04442 int DataArrayInt::getMinValueInArray() const throw(INTERP_KERNEL::Exception)
04443 {
04444   checkAllocated();
04445   const int *loc=std::min_element(begin(),end());
04446   return *loc;
04447 }
04448 
04449 void DataArrayInt::abs() throw(INTERP_KERNEL::Exception)
04450 {
04451   checkAllocated();
04452   int *ptr=getPointer();
04453   int nbOfElems=getNbOfElems();
04454   std::transform(ptr,ptr+nbOfElems,ptr,std::ptr_fun<int,int>(std::abs));
04455 }
04456 
04457 void DataArrayInt::applyLin(int a, int b, int compoId) throw(INTERP_KERNEL::Exception)
04458 {
04459   checkAllocated();
04460   int *ptr=getPointer()+compoId;
04461   int nbOfComp=getNumberOfComponents();
04462   int nbOfTuple=getNumberOfTuples();
04463   for(int i=0;i<nbOfTuple;i++,ptr+=nbOfComp)
04464     *ptr=a*(*ptr)+b;
04465   declareAsNew();
04466 }
04467 
04468 void DataArrayInt::applyLin(int a, int b) throw(INTERP_KERNEL::Exception)
04469 {
04470   checkAllocated();
04471   int *ptr=getPointer();
04472   int nbOfElems=getNbOfElems();
04473   for(int i=0;i<nbOfElems;i++,ptr++)
04474     *ptr=a*(*ptr)+b;
04475   declareAsNew();
04476 }
04477 
04482 DataArrayInt *DataArrayInt::negate() const throw(INTERP_KERNEL::Exception)
04483 {
04484   checkAllocated();
04485   DataArrayInt *newArr=DataArrayInt::New();
04486   int nbOfTuples=getNumberOfTuples();
04487   int nbOfComp=getNumberOfComponents();
04488   newArr->alloc(nbOfTuples,nbOfComp);
04489   const int *cptr=getConstPointer();
04490   std::transform(cptr,cptr+nbOfTuples*nbOfComp,newArr->getPointer(),std::negate<int>());
04491   newArr->copyStringInfoFrom(*this);
04492   return newArr;
04493 }
04494 
04500 void DataArrayInt::applyInv(int numerator) throw(INTERP_KERNEL::Exception)
04501 {
04502   checkAllocated();
04503   int *ptr=getPointer();
04504   int nbOfElems=getNbOfElems();
04505   for(int i=0;i<nbOfElems;i++,ptr++)
04506     {
04507       if(*ptr!=0)
04508         {
04509           *ptr=numerator/(*ptr);
04510         }
04511       else
04512         {
04513           std::ostringstream oss; oss << "DataArrayInt::applyInv : presence of null value in tuple #" << i/getNumberOfComponents() << " component #" << i%getNumberOfComponents();
04514           oss << " !";
04515           throw INTERP_KERNEL::Exception(oss.str().c_str());
04516         }
04517     }
04518   declareAsNew();
04519 }
04520 
04521 void DataArrayInt::applyDivideBy(int val) throw(INTERP_KERNEL::Exception)
04522 {
04523   if(val==0)
04524     throw INTERP_KERNEL::Exception("DataArrayInt::applyDivideBy : Trying to divide by 0 !");
04525   checkAllocated();
04526   int *ptr=getPointer();
04527   int nbOfElems=getNbOfElems();
04528   std::transform(ptr,ptr+nbOfElems,ptr,std::bind2nd(std::divides<int>(),val));
04529   declareAsNew();
04530 }
04531 
04532 void DataArrayInt::applyModulus(int val) throw(INTERP_KERNEL::Exception)
04533 {
04534   if(val<=0)
04535     throw INTERP_KERNEL::Exception("DataArrayInt::applyDivideBy : Trying to operate modulus on value <= 0 !");
04536   checkAllocated();
04537   int *ptr=getPointer();
04538   int nbOfElems=getNbOfElems();
04539   std::transform(ptr,ptr+nbOfElems,ptr,std::bind2nd(std::modulus<int>(),val));
04540   declareAsNew();
04541 }
04542 
04548 void DataArrayInt::applyRModulus(int val) throw(INTERP_KERNEL::Exception)
04549 {
04550   checkAllocated();
04551   int *ptr=getPointer();
04552   int nbOfElems=getNbOfElems();
04553   for(int i=0;i<nbOfElems;i++,ptr++)
04554     {
04555       if(*ptr>0)
04556         {
04557           *ptr=val%(*ptr);
04558         }
04559       else
04560         {
04561           std::ostringstream oss; oss << "DataArrayInt::applyRModulus : presence of value <=0 in tuple #" << i/getNumberOfComponents() << " component #" << i%getNumberOfComponents();
04562           oss << " !";
04563           throw INTERP_KERNEL::Exception(oss.str().c_str());
04564         }
04565     }
04566   declareAsNew();
04567 }
04568 
04569 DataArrayInt *DataArrayInt::Meld(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception)
04570 {
04571   std::vector<const DataArrayInt *> arr(2);
04572   arr[0]=a1; arr[1]=a2;
04573   return Meld(arr);
04574 }
04575 
04576 DataArrayInt *DataArrayInt::Meld(const std::vector<const DataArrayInt *>& a) throw(INTERP_KERNEL::Exception)
04577 {
04578   if(a.empty())
04579     throw INTERP_KERNEL::Exception("DataArrayInt::Meld : array must be NON empty !");
04580   std::vector<const DataArrayInt *>::const_iterator it;
04581   for(it=a.begin();it!=a.end();it++)
04582     (*it)->checkAllocated();
04583   it=a.begin();
04584   int nbOfTuples=(*it)->getNumberOfTuples();
04585   std::vector<int> nbc(a.size());
04586   std::vector<const int *> pts(a.size());
04587   nbc[0]=(*it)->getNumberOfComponents();
04588   pts[0]=(*it++)->getConstPointer();
04589   for(int i=1;it!=a.end();it++,i++)
04590     {
04591       if(nbOfTuples!=(*it)->getNumberOfTuples())
04592         throw INTERP_KERNEL::Exception("DataArrayInt::meld : mismatch of number of tuples !");
04593       nbc[i]=(*it)->getNumberOfComponents();
04594       pts[i]=(*it)->getConstPointer();
04595     }
04596   int totalNbOfComp=std::accumulate(nbc.begin(),nbc.end(),0);
04597   DataArrayInt *ret=DataArrayInt::New();
04598   ret->alloc(nbOfTuples,totalNbOfComp);
04599   int *retPtr=ret->getPointer();
04600   for(int i=0;i<nbOfTuples;i++)
04601     for(int j=0;j<(int)a.size();j++)
04602       {
04603         retPtr=std::copy(pts[j],pts[j]+nbc[j],retPtr);
04604         pts[j]+=nbc[j];
04605       }
04606   int k=0;
04607   for(int i=0;i<(int)a.size();i++)
04608     for(int j=0;j<nbc[i];j++,k++)
04609       ret->setInfoOnComponent(k,a[i]->getInfoOnComponent(j).c_str());
04610   return ret;
04611 }
04612 
04622 DataArrayInt *DataArrayInt::MakePartition(const std::vector<const DataArrayInt *>& groups, int newNb, std::vector< std::vector<int> >& fidsOfGroups)
04623 {
04624   DataArrayInt *ret=DataArrayInt::New();
04625   ret->alloc(newNb,1);
04626   int *retPtr=ret->getPointer();
04627   std::fill(retPtr,retPtr+newNb,0);
04628   int fid=1;
04629   for(std::vector<const DataArrayInt *>::const_iterator iter=groups.begin();iter!=groups.end();iter++)
04630     {
04631       const int *ptr=(*iter)->getConstPointer();
04632       int nbOfElem=(*iter)->getNbOfElems();
04633       int sfid=fid;
04634       for(int j=0;j<sfid;j++)
04635         {
04636           bool found=false;
04637           for(int i=0;i<nbOfElem;i++)
04638             {
04639               if(retPtr[ptr[i]]==j)
04640                 {
04641                   retPtr[ptr[i]]=fid;
04642                   found=true;
04643                 }
04644             }
04645           if(found)
04646             fid++;
04647         }
04648     }
04649   fidsOfGroups.clear();
04650   fidsOfGroups.resize(groups.size());
04651   int grId=0;
04652   for(std::vector<const DataArrayInt *>::const_iterator iter=groups.begin();iter!=groups.end();iter++,grId++)
04653     {
04654       std::set<int> tmp;
04655       const int *ptr=(*iter)->getConstPointer();
04656       int nbOfElem=(*iter)->getNbOfElems();
04657       for(const int *p=ptr;p!=ptr+nbOfElem;p++)
04658         tmp.insert(retPtr[*p]);
04659       fidsOfGroups[grId].insert(fidsOfGroups[grId].end(),tmp.begin(),tmp.end());
04660     }
04661   return ret;
04662 }
04663 
04664 DataArrayInt *DataArrayInt::BuildUnion(const std::vector<const DataArrayInt *>& a) throw(INTERP_KERNEL::Exception)
04665 {
04666   int valm=std::numeric_limits<int>::max();
04667   for(std::vector<const DataArrayInt *>::const_iterator it=a.begin();it!=a.end();it++)
04668     {
04669       (*it)->checkAllocated();
04670       if((*it)->getNumberOfComponents()!=1)
04671         throw INTERP_KERNEL::Exception("DataArrayInt::BuildUnion : only single component allowed !");
04672       int tmp1;
04673       valm=std::min((*it)->getMinValue(tmp1),valm);
04674     }
04675   if(valm<0)
04676     throw INTERP_KERNEL::Exception("DataArrayInt::BuildUnion : a negative value has been detected !");
04677   //
04678   std::set<int> r;
04679   for(std::vector<const DataArrayInt *>::const_iterator it=a.begin();it!=a.end();it++)
04680     {
04681       const int *pt=(*it)->getConstPointer();
04682       int nbOfTuples=(*it)->getNumberOfTuples();
04683       r.insert(pt,pt+nbOfTuples);
04684     }
04685   DataArrayInt *ret=DataArrayInt::New();
04686   ret->alloc((int)r.size(),1);
04687   std::copy(r.begin(),r.end(),ret->getPointer());
04688   return ret;
04689 }
04690 
04691 DataArrayInt *DataArrayInt::BuildIntersection(const std::vector<const DataArrayInt *>& a) throw(INTERP_KERNEL::Exception)
04692 {
04693   int valm=std::numeric_limits<int>::max();
04694   for(std::vector<const DataArrayInt *>::const_iterator it=a.begin();it!=a.end();it++)
04695     {
04696       (*it)->checkAllocated();
04697       if((*it)->getNumberOfComponents()!=1)
04698         throw INTERP_KERNEL::Exception("DataArrayInt::BuildUnion : only single component allowed !");
04699       int tmp1;
04700       valm=std::min((*it)->getMinValue(tmp1),valm);
04701     }
04702   if(valm<0)
04703     throw INTERP_KERNEL::Exception("DataArrayInt::BuildUnion : a negative value has been detected !");
04704   //
04705   std::set<int> r;
04706   for(std::vector<const DataArrayInt *>::const_iterator it=a.begin();it!=a.end();it++)
04707     {
04708       const int *pt=(*it)->getConstPointer();
04709       int nbOfTuples=(*it)->getNumberOfTuples();
04710       std::set<int> s1(pt,pt+nbOfTuples);
04711       if(it!=a.begin())
04712         {
04713           std::set<int> r2;
04714           std::set_intersection(r.begin(),r.end(),s1.begin(),s1.end(),inserter(r2,r2.end()));
04715           r=r2;
04716         }
04717       else
04718         r=s1;
04719     }
04720   DataArrayInt *ret=DataArrayInt::New();
04721   ret->alloc((int)r.size(),1);
04722   std::copy(r.begin(),r.end(),ret->getPointer());
04723   return ret;
04724 }
04725 
04726 DataArrayInt *DataArrayInt::buildComplement(int nbOfElement) const throw(INTERP_KERNEL::Exception)
04727 {
04728    checkAllocated();
04729    if(getNumberOfComponents()!=1)
04730      throw INTERP_KERNEL::Exception("DataArrayInt::buildComplement : only single component allowed !");
04731    std::vector<bool> tmp(nbOfElement);
04732    const int *pt=getConstPointer();
04733    int nbOfTuples=getNumberOfTuples();
04734    for(const int *w=pt;w!=pt+nbOfTuples;w++)
04735      if(*w>=0 && *w<nbOfElement)
04736        tmp[*w]=true;
04737      else
04738        throw INTERP_KERNEL::Exception("DataArrayInt::buildComplement : an element is not in valid range : [0,nbOfElement) !");
04739    int nbOfRetVal=(int)std::count(tmp.begin(),tmp.end(),false);
04740    DataArrayInt *ret=DataArrayInt::New();
04741    ret->alloc(nbOfRetVal,1);
04742    int j=0;
04743    int *retPtr=ret->getPointer();
04744    for(int i=0;i<nbOfElement;i++)
04745      if(!tmp[i])
04746        retPtr[j++]=i;
04747    return ret;
04748 }
04749 
04750 DataArrayInt *DataArrayInt::buildSubstraction(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception)
04751 {
04752   checkAllocated();
04753   other->checkAllocated();
04754   if(getNumberOfComponents()!=1)
04755      throw INTERP_KERNEL::Exception("DataArrayInt::buildSubstraction : only single component allowed !");
04756   if(other->getNumberOfComponents()!=1)
04757      throw INTERP_KERNEL::Exception("DataArrayInt::buildSubstraction : only single component allowed for other type !");
04758   const int *pt=getConstPointer();
04759   int nbOfTuples=getNumberOfTuples();
04760   std::set<int> s1(pt,pt+nbOfTuples);
04761   pt=other->getConstPointer();
04762   nbOfTuples=other->getNumberOfTuples();
04763   std::set<int> s2(pt,pt+nbOfTuples);
04764   std::vector<int> r;
04765   std::set_difference(s1.begin(),s1.end(),s2.begin(),s2.end(),std::back_insert_iterator< std::vector<int> >(r));
04766   DataArrayInt *ret=DataArrayInt::New();
04767   ret->alloc((int)r.size(),1);
04768   std::copy(r.begin(),r.end(),ret->getPointer());
04769   return ret;
04770 }
04771 
04772 DataArrayInt *DataArrayInt::buildUnion(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception)
04773 {
04774   std::vector<const DataArrayInt *>arrs(2);
04775   arrs[0]=this; arrs[1]=other;
04776   return BuildUnion(arrs);
04777 }
04778 
04779 DataArrayInt *DataArrayInt::buildIntersection(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception)
04780 {
04781   std::vector<const DataArrayInt *>arrs(2);
04782   arrs[0]=this; arrs[1]=other;
04783   return BuildIntersection(arrs);
04784 }
04785 
04794 DataArrayInt *DataArrayInt::deltaShiftIndex() const throw(INTERP_KERNEL::Exception)
04795 {
04796   checkAllocated();
04797   if(getNumberOfComponents()!=1)
04798      throw INTERP_KERNEL::Exception("DataArrayInt::deltaShiftIndex : only single component allowed !");
04799   int nbOfTuples=getNumberOfTuples();
04800   if(nbOfTuples<2)
04801     throw INTERP_KERNEL::Exception("DataArrayInt::deltaShiftIndex : 1 tuple at least must be present in 'this' !");
04802   const int *ptr=getConstPointer();
04803   DataArrayInt *ret=DataArrayInt::New();
04804   ret->alloc(nbOfTuples-1,1);
04805   int *out=ret->getPointer();
04806   std::transform(ptr+1,ptr+nbOfTuples,ptr,out,std::minus<int>());
04807   return ret;
04808 }
04809 
04816 void DataArrayInt::computeOffsets() throw(INTERP_KERNEL::Exception)
04817 {
04818   checkAllocated();
04819   if(getNumberOfComponents()!=1)
04820      throw INTERP_KERNEL::Exception("DataArrayInt::computeOffsets : only single component allowed !");
04821   int nbOfTuples=getNumberOfTuples();
04822   if(nbOfTuples==0)
04823     return ;
04824   int *work=getPointer();
04825   int tmp=work[0];
04826   work[0]=0;
04827   for(int i=1;i<nbOfTuples;i++)
04828     {
04829       int tmp2=work[i];
04830       work[i]=work[i-1]+tmp;
04831       tmp=tmp2;
04832     }
04833   declareAsNew();
04834 }
04835 
04843 void DataArrayInt::computeOffsets2() throw(INTERP_KERNEL::Exception)
04844 {
04845   checkAllocated();
04846   if(getNumberOfComponents()!=1)
04847     throw INTERP_KERNEL::Exception("DataArrayInt::computeOffsets2 : only single component allowed !");
04848   int nbOfTuples=getNumberOfTuples();
04849   int *ret=new int[nbOfTuples+1];
04850   if(nbOfTuples==0)
04851     return ;
04852   const int *work=getConstPointer();
04853   ret[0]=0;
04854   for(int i=0;i<nbOfTuples;i++)
04855     ret[i+1]=work[i]+ret[i];
04856   useArray(ret,true,CPP_DEALLOC,nbOfTuples+1,1);
04857   declareAsNew();
04858 }
04859 
04866 DataArrayInt *DataArrayInt::buildExplicitArrByRanges(const DataArrayInt *offsets) const throw(INTERP_KERNEL::Exception)
04867 {
04868   checkAllocated();
04869   if(getNumberOfComponents()!=1)
04870      throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrByRanges : only single component allowed !");
04871   offsets->checkAllocated();
04872   if(offsets->getNumberOfComponents()!=1)
04873      throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrByRanges : input array should have only single component !");
04874   int othNbTuples=offsets->getNumberOfTuples()-1;
04875   int nbOfTuples=getNumberOfTuples();
04876   int retNbOftuples=0;
04877   const int *work=getConstPointer();
04878   const int *offPtr=offsets->getConstPointer();
04879   for(int i=0;i<nbOfTuples;i++)
04880     {
04881       int val=work[i];
04882       if(val>=0 && val<othNbTuples)
04883         {
04884           int delta=offPtr[val+1]-offPtr[val];
04885           if(delta>=0)
04886             retNbOftuples+=delta;
04887           else
04888             {
04889               std::ostringstream oss; oss << "DataArrayInt::buildExplicitArrByRanges : Tuple #" << val << " of offset array has a delta < 0 !";
04890               throw INTERP_KERNEL::Exception(oss.str().c_str());
04891             }
04892         }
04893       else
04894         {
04895           std::ostringstream oss; oss << "DataArrayInt::buildExplicitArrByRanges : Tuple #" << i << " in this contains " << val;
04896           oss << " whereas offsets array is of size " << othNbTuples+1 << " !";
04897           throw INTERP_KERNEL::Exception(oss.str().c_str());
04898         }
04899     }
04900   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
04901   ret->alloc(retNbOftuples,1);
04902   int *retPtr=ret->getPointer();
04903   for(int i=0;i<nbOfTuples;i++)
04904     {
04905       int val=work[i];
04906       int start=offPtr[val];
04907       int off=offPtr[val+1]-start;
04908       for(int j=0;j<off;j++,retPtr++)
04909         *retPtr=start+j;
04910     }
04911   ret->incrRef();
04912   return ret;
04913 }
04914 
04918 std::set<int> DataArrayInt::getDifferentValues() const throw(INTERP_KERNEL::Exception)
04919 {
04920   checkAllocated();
04921   std::set<int> ret;
04922   ret.insert(getConstPointer(),getConstPointer()+getNbOfElems());
04923   return ret;
04924 }
04925 
04926 DataArrayInt *DataArrayInt::Add(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception)
04927 {
04928   int nbOfTuple=a1->getNumberOfTuples();
04929   int nbOfTuple2=a2->getNumberOfTuples();
04930   int nbOfComp=a1->getNumberOfComponents();
04931   int nbOfComp2=a2->getNumberOfComponents();
04932   if(nbOfTuple!=nbOfTuple2)
04933     throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Add !");
04934   DataArrayInt *ret=0;
04935   if(nbOfComp==nbOfComp2)
04936     {
04937       ret=DataArrayInt::New();
04938       ret->alloc(nbOfTuple,nbOfComp);
04939       std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::plus<int>());
04940       ret->copyStringInfoFrom(*a1);
04941     }
04942   else
04943     {
04944       int nbOfCompMin,nbOfCompMax;
04945       const DataArrayInt *aMin, *aMax;
04946       if(nbOfComp>nbOfComp2)
04947         {
04948           nbOfCompMin=nbOfComp2; nbOfCompMax=nbOfComp;
04949           aMin=a2; aMax=a1;
04950         }
04951       else
04952         {
04953           nbOfCompMin=nbOfComp; nbOfCompMax=nbOfComp2;
04954           aMin=a1; aMax=a2;
04955         }
04956       if(nbOfCompMin==1)
04957         {
04958           ret=DataArrayInt::New();
04959           ret->alloc(nbOfTuple,nbOfCompMax);
04960           const int *aMinPtr=aMin->getConstPointer();
04961           const int *aMaxPtr=aMax->getConstPointer();
04962           int *res=ret->getPointer();
04963           for(int i=0;i<nbOfTuple;i++)
04964             res=std::transform(aMaxPtr+i*nbOfCompMax,aMaxPtr+(i+1)*nbOfCompMax,res,std::bind2nd(std::plus<int>(),aMinPtr[i]));
04965           ret->copyStringInfoFrom(*aMax);
04966         }
04967       else
04968         throw INTERP_KERNEL::Exception("Nb of components mismatch for array Add !");
04969     }
04970   return ret;
04971 }
04972 
04973 void DataArrayInt::addEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception)
04974 {
04975   const char *msg="Nb of tuples mismatch for DataArrayInt::addEqual  !";
04976   int nbOfTuple=getNumberOfTuples();
04977   int nbOfTuple2=other->getNumberOfTuples();
04978   int nbOfComp=getNumberOfComponents();
04979   int nbOfComp2=other->getNumberOfComponents();
04980   if(nbOfTuple==nbOfTuple2)
04981     {
04982       if(nbOfComp==nbOfComp2)
04983         {
04984           std::transform(begin(),end(),other->begin(),getPointer(),std::plus<int>());
04985         }
04986       else if(nbOfComp2==1)
04987         {
04988           int *ptr=getPointer();
04989           const int *ptrc=other->getConstPointer();
04990           for(int i=0;i<nbOfTuple;i++)
04991             std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::plus<int>(),*ptrc++));
04992         }
04993       else
04994         throw INTERP_KERNEL::Exception(msg);
04995     }
04996   else if(nbOfTuple2==1)
04997     {
04998       if(nbOfComp2==nbOfComp)
04999         {
05000           int *ptr=getPointer();
05001           const int *ptrc=other->getConstPointer();
05002           for(int i=0;i<nbOfTuple;i++)
05003             std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::plus<int>());
05004         }
05005       else
05006         throw INTERP_KERNEL::Exception(msg);
05007     }
05008   else
05009     throw INTERP_KERNEL::Exception(msg);
05010   declareAsNew();
05011 }
05012 
05013 DataArrayInt *DataArrayInt::Substract(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception)
05014 {
05015   int nbOfTuple=a2->getNumberOfTuples();
05016   int nbOfComp=a2->getNumberOfComponents();
05017   a1->checkNbOfTuplesAndComp(nbOfTuple,nbOfComp,"Nb of components mismatch for array Substract !");
05018   DataArrayInt *ret=DataArrayInt::New();
05019   ret->alloc(nbOfTuple,nbOfComp);
05020   std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::minus<int>());
05021   ret->copyStringInfoFrom(*a1);
05022   return ret;
05023 }
05024 
05025 void DataArrayInt::substractEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception)
05026 {
05027   const char *msg="Nb of tuples mismatch for DataArrayInt::substractEqual  !";
05028   int nbOfTuple=getNumberOfTuples();
05029   int nbOfTuple2=other->getNumberOfTuples();
05030   int nbOfComp=getNumberOfComponents();
05031   int nbOfComp2=other->getNumberOfComponents();
05032   if(nbOfTuple==nbOfTuple2)
05033     {
05034       if(nbOfComp==nbOfComp2)
05035         {
05036           std::transform(begin(),end(),other->begin(),getPointer(),std::minus<int>());
05037         }
05038       else if(nbOfComp2==1)
05039         {
05040           int *ptr=getPointer();
05041           const int *ptrc=other->getConstPointer();
05042           for(int i=0;i<nbOfTuple;i++)
05043             std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::minus<int>(),*ptrc++));
05044         }
05045       else
05046         throw INTERP_KERNEL::Exception(msg);
05047     }
05048   else if(nbOfTuple2==1)
05049     {
05050       int *ptr=getPointer();
05051       const int *ptrc=other->getConstPointer();
05052       for(int i=0;i<nbOfTuple;i++)
05053         std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::minus<int>());
05054     }
05055   else
05056     throw INTERP_KERNEL::Exception(msg);
05057   declareAsNew();
05058 }
05059 
05060 DataArrayInt *DataArrayInt::Multiply(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception)
05061 {
05062   int nbOfTuple=a1->getNumberOfTuples();
05063   int nbOfTuple2=a2->getNumberOfTuples();
05064   int nbOfComp=a1->getNumberOfComponents();
05065   int nbOfComp2=a2->getNumberOfComponents();
05066   if(nbOfTuple!=nbOfTuple2)
05067     throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Multiply !");
05068   DataArrayInt *ret=0;
05069   if(nbOfComp==nbOfComp2)
05070     {
05071       ret=DataArrayInt::New();
05072       ret->alloc(nbOfTuple,nbOfComp);
05073       std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::multiplies<int>());
05074       ret->copyStringInfoFrom(*a1);
05075     }
05076   else
05077     {
05078       int nbOfCompMin,nbOfCompMax;
05079       const DataArrayInt *aMin, *aMax;
05080       if(nbOfComp>nbOfComp2)
05081         {
05082           nbOfCompMin=nbOfComp2; nbOfCompMax=nbOfComp;
05083           aMin=a2; aMax=a1;
05084         }
05085       else
05086         {
05087           nbOfCompMin=nbOfComp; nbOfCompMax=nbOfComp2;
05088           aMin=a1; aMax=a2;
05089         }
05090       if(nbOfCompMin==1)
05091         {
05092           ret=DataArrayInt::New();
05093           ret->alloc(nbOfTuple,nbOfCompMax);
05094           const int *aMinPtr=aMin->getConstPointer();
05095           const int *aMaxPtr=aMax->getConstPointer();
05096           int *res=ret->getPointer();
05097           for(int i=0;i<nbOfTuple;i++)
05098             res=std::transform(aMaxPtr+i*nbOfCompMax,aMaxPtr+(i+1)*nbOfCompMax,res,std::bind2nd(std::multiplies<int>(),aMinPtr[i]));
05099           ret->copyStringInfoFrom(*aMax);
05100         }
05101       else
05102         throw INTERP_KERNEL::Exception("Nb of components mismatch for array Multiply !");
05103     }
05104   return ret;
05105 }
05106 
05107 void DataArrayInt::multiplyEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception)
05108 {
05109   const char *msg="Nb of tuples mismatch for DataArrayInt::multiplyEqual !";
05110   int nbOfTuple=getNumberOfTuples();
05111   int nbOfTuple2=other->getNumberOfTuples();
05112   int nbOfComp=getNumberOfComponents();
05113   int nbOfComp2=other->getNumberOfComponents();
05114   if(nbOfTuple==nbOfTuple2)
05115     {
05116       if(nbOfComp==nbOfComp2)
05117         {
05118           std::transform(begin(),end(),other->begin(),getPointer(),std::multiplies<int>());
05119         }
05120       else if(nbOfComp2==1)
05121         {
05122           int *ptr=getPointer();
05123           const int *ptrc=other->getConstPointer();
05124           for(int i=0;i<nbOfTuple;i++)
05125             std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::multiplies<int>(),*ptrc++));    
05126         }
05127       else
05128         throw INTERP_KERNEL::Exception(msg);
05129     }
05130   else if(nbOfTuple2==1)
05131     {
05132       if(nbOfComp2==nbOfComp)
05133         {
05134           int *ptr=getPointer();
05135           const int *ptrc=other->getConstPointer();
05136           for(int i=0;i<nbOfTuple;i++)
05137             std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::multiplies<int>());
05138         }
05139       else
05140         throw INTERP_KERNEL::Exception(msg);
05141     }
05142   else
05143     throw INTERP_KERNEL::Exception(msg);
05144   declareAsNew();
05145 }
05146 
05147 DataArrayInt *DataArrayInt::Divide(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception)
05148 {
05149   int nbOfTuple=a1->getNumberOfTuples();
05150   int nbOfTuple2=a2->getNumberOfTuples();
05151   int nbOfComp=a1->getNumberOfComponents();
05152   int nbOfComp2=a2->getNumberOfComponents();
05153   if(nbOfTuple!=nbOfTuple2)
05154     throw INTERP_KERNEL::Exception("Nb of tuples mismatch for array Divide !");
05155   DataArrayInt *ret=0;
05156   if(nbOfComp==nbOfComp2)
05157     {
05158       ret=DataArrayInt::New();
05159       ret->alloc(nbOfTuple,nbOfComp);
05160       std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::divides<int>());
05161       ret->copyStringInfoFrom(*a1);
05162     }
05163   else
05164     {
05165       if(nbOfComp2==1)
05166         {
05167           ret=DataArrayInt::New();
05168           ret->alloc(nbOfTuple,nbOfComp);
05169           const int *a2Ptr=a2->getConstPointer();
05170           const int *a1Ptr=a1->getConstPointer();
05171           int *res=ret->getPointer();
05172           for(int i=0;i<nbOfTuple;i++)
05173             res=std::transform(a1Ptr+i*nbOfComp,a1Ptr+(i+1)*nbOfComp,res,std::bind2nd(std::divides<int>(),a2Ptr[i]));
05174           ret->copyStringInfoFrom(*a1);
05175         }
05176       else
05177         throw INTERP_KERNEL::Exception("Nb of components mismatch for array Divide !");
05178     }
05179   return ret;
05180 }
05181 
05182 void DataArrayInt::divideEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception)
05183 {
05184   const char *msg="Nb of tuples mismatch for DataArrayInt::divideEqual !";
05185   int nbOfTuple=getNumberOfTuples();
05186   int nbOfTuple2=other->getNumberOfTuples();
05187   int nbOfComp=getNumberOfComponents();
05188   int nbOfComp2=other->getNumberOfComponents();
05189   if(nbOfTuple==nbOfTuple2)
05190     {
05191       if(nbOfComp==nbOfComp2)
05192         {
05193           std::transform(begin(),end(),other->begin(),getPointer(),std::divides<int>());
05194         }
05195       else if(nbOfComp2==1)
05196         {
05197           int *ptr=getPointer();
05198           const int *ptrc=other->getConstPointer();
05199           for(int i=0;i<nbOfTuple;i++)
05200             std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::divides<int>(),*ptrc++));
05201         }
05202       else
05203         throw INTERP_KERNEL::Exception(msg);
05204     }
05205   else if(nbOfTuple2==1)
05206     {
05207       if(nbOfComp2==nbOfComp)
05208         {
05209           int *ptr=getPointer();
05210           const int *ptrc=other->getConstPointer();
05211           for(int i=0;i<nbOfTuple;i++)
05212             std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::divides<int>());
05213         }
05214       else
05215         throw INTERP_KERNEL::Exception(msg);
05216     }
05217   else
05218     throw INTERP_KERNEL::Exception(msg);
05219   declareAsNew();
05220 }
05221 
05222 DataArrayInt *DataArrayInt::Modulus(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception)
05223 {
05224   int nbOfTuple=a2->getNumberOfTuples();
05225   int nbOfComp=a2->getNumberOfComponents();
05226   a1->checkNbOfTuplesAndComp(nbOfTuple,nbOfComp,"Nb of components mismatch for array Modulus");
05227   DataArrayInt *ret=DataArrayInt::New();
05228   ret->alloc(nbOfTuple,nbOfComp);
05229   std::transform(a1->begin(),a1->end(),a2->begin(),ret->getPointer(),std::modulus<int>());
05230   ret->copyStringInfoFrom(*a1);
05231   return ret;
05232 }
05233 
05234 void DataArrayInt::modulusEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception)
05235 {
05236   const char *msg="Nb of tuples mismatch for DataArrayInt::modulusEqual !";
05237   int nbOfTuple=getNumberOfTuples();
05238   int nbOfTuple2=other->getNumberOfTuples();
05239   int nbOfComp=getNumberOfComponents();
05240   int nbOfComp2=other->getNumberOfComponents();
05241   if(nbOfTuple==nbOfTuple2)
05242     {
05243       if(nbOfComp==nbOfComp2)
05244         {
05245           std::transform(begin(),end(),other->begin(),getPointer(),std::modulus<int>());
05246         }
05247       else if(nbOfComp2==1)
05248         {
05249           if(nbOfComp2==nbOfComp)
05250             {
05251               int *ptr=getPointer();
05252               const int *ptrc=other->getConstPointer();
05253               for(int i=0;i<nbOfTuple;i++)
05254                 std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptr+i*nbOfComp,std::bind2nd(std::modulus<int>(),*ptrc++));
05255             }
05256           else
05257             throw INTERP_KERNEL::Exception(msg);
05258         }
05259       else
05260         throw INTERP_KERNEL::Exception(msg);
05261     }
05262   else if(nbOfTuple2==1)
05263     {
05264       int *ptr=getPointer();
05265       const int *ptrc=other->getConstPointer();
05266       for(int i=0;i<nbOfTuple;i++)
05267         std::transform(ptr+i*nbOfComp,ptr+(i+1)*nbOfComp,ptrc,ptr+i*nbOfComp,std::modulus<int>());
05268     }
05269   else
05270     throw INTERP_KERNEL::Exception(msg);
05271   declareAsNew();
05272 }
05273 
05274 int *DataArrayInt::CheckAndPreparePermutation(const int *start, const int *end)
05275 {
05276   std::size_t sz=std::distance(start,end);
05277   int *ret=new int[sz];
05278   int *work=new int[sz];
05279   std::copy(start,end,work);
05280   std::sort(work,work+sz);
05281   if(std::unique(work,work+sz)!=work+sz)
05282     {
05283       delete [] work;
05284       delete [] ret;
05285       throw INTERP_KERNEL::Exception("Some elements are equals in the specified array !");
05286     }
05287   int *iter2=ret;
05288   for(const int *iter=start;iter!=end;iter++,iter2++)
05289     *iter2=(int)std::distance(work,std::find(work,work+sz,*iter));
05290   delete [] work;
05291   return ret;
05292 }
05293 
05294 DataArrayInt *DataArrayInt::Range(int begin, int end, int step) throw(INTERP_KERNEL::Exception)
05295 {
05296   int nbOfTuples=GetNumberOfItemGivenBESRelative(begin,end,step,"DataArrayInt::Range");
05297   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
05298   ret->alloc(nbOfTuples,1);
05299   int *ptr=ret->getPointer();
05300   if(step>0)
05301     {
05302       for(int i=begin;i<end;i+=step,ptr++)
05303         *ptr=i;
05304     }
05305   else
05306     {
05307       for(int i=begin;i>end;i+=step,ptr++)
05308         *ptr=i;
05309     }
05310   ret->incrRef();
05311   return ret;
05312 }
05313 
05318 void DataArrayInt::getTinySerializationIntInformation(std::vector<int>& tinyInfo) const
05319 {
05320   tinyInfo.resize(2);
05321   if(isAllocated())
05322     {
05323       tinyInfo[0]=getNumberOfTuples();
05324       tinyInfo[1]=getNumberOfComponents();
05325     }
05326   else
05327     {
05328       tinyInfo[0]=-1;
05329       tinyInfo[1]=-1;
05330     }
05331 }
05332 
05337 void DataArrayInt::getTinySerializationStrInformation(std::vector<std::string>& tinyInfo) const
05338 {
05339   if(isAllocated())
05340     {
05341       int nbOfCompo=getNumberOfComponents();
05342       tinyInfo.resize(nbOfCompo+1);
05343       tinyInfo[0]=getName();
05344       for(int i=0;i<nbOfCompo;i++)
05345         tinyInfo[i+1]=getInfoOnComponent(i);
05346     }
05347   else
05348     {
05349       tinyInfo.resize(1);
05350       tinyInfo[0]=getName();
05351     }
05352 }
05353 
05358 bool DataArrayInt::resizeForUnserialization(const std::vector<int>& tinyInfoI)
05359 {
05360   int nbOfTuple=tinyInfoI[0];
05361   int nbOfComp=tinyInfoI[1];
05362   if(nbOfTuple!=-1 || nbOfComp!=-1)
05363     {
05364       alloc(nbOfTuple,nbOfComp);
05365       return true;
05366     }
05367   return false;
05368 }
05369 
05374 void DataArrayInt::finishUnserialization(const std::vector<int>& tinyInfoI, const std::vector<std::string>& tinyInfoS)
05375 {
05376   setName(tinyInfoS[0].c_str());
05377   if(isAllocated())
05378     {
05379       int nbOfCompo=getNumberOfComponents();
05380       for(int i=0;i<nbOfCompo;i++)
05381         setInfoOnComponent(i,tinyInfoS[i+1].c_str());
05382     }
05383 }
05384 
05385 DataArrayIntIterator::DataArrayIntIterator(DataArrayInt *da):_da(da),_pt(0),_tuple_id(0),_nb_comp(0),_nb_tuple(0)
05386 {
05387   if(_da)
05388     {
05389       _da->incrRef();
05390       if(_da->isAllocated())
05391         {
05392           _nb_comp=da->getNumberOfComponents();
05393           _nb_tuple=da->getNumberOfTuples();
05394           _pt=da->getPointer();
05395         }
05396     }
05397 }
05398 
05399 DataArrayIntIterator::~DataArrayIntIterator()
05400 {
05401   if(_da)
05402     _da->decrRef();
05403 }
05404 
05405 DataArrayIntTuple *DataArrayIntIterator::nextt()
05406 {
05407   if(_tuple_id<_nb_tuple)
05408     {
05409       _tuple_id++;
05410       DataArrayIntTuple *ret=new DataArrayIntTuple(_pt,_nb_comp);
05411       _pt+=_nb_comp;
05412       return ret;
05413     }
05414   else
05415     return 0;
05416 }
05417 
05418 DataArrayIntTuple::DataArrayIntTuple(int *pt, int nbOfComp):_pt(pt),_nb_of_compo(nbOfComp)
05419 {
05420 }
05421 
05422 std::string DataArrayIntTuple::repr() const
05423 {
05424   std::ostringstream oss; oss << "(";
05425   for(int i=0;i<_nb_of_compo-1;i++)
05426     oss << _pt[i] << ", ";
05427   oss << _pt[_nb_of_compo-1] << ")";
05428   return oss.str();
05429 }
05430 
05431 int DataArrayIntTuple::intValue() const throw(INTERP_KERNEL::Exception)
05432 {
05433   if(_nb_of_compo==1)
05434     return *_pt;
05435   throw INTERP_KERNEL::Exception("DataArrayIntTuple::intValue : DataArrayIntTuple instance has not exactly 1 component -> Not possible to convert it into an integer !");
05436 }
05437 
05444 DataArrayInt *DataArrayIntTuple::buildDAInt(int nbOfTuples, int nbOfCompo) const throw(INTERP_KERNEL::Exception)
05445 {
05446   if((_nb_of_compo==nbOfCompo && nbOfTuples==1) || (_nb_of_compo==nbOfTuples && nbOfCompo==1))
05447     {
05448       DataArrayInt *ret=DataArrayInt::New();
05449       ret->useArray(_pt,false,CPP_DEALLOC,nbOfTuples,nbOfCompo);
05450       return ret;
05451     }
05452   else
05453     {
05454       std::ostringstream oss; oss << "DataArrayIntTuple::buildDAInt : unable to build a requested DataArrayInt instance with nbofTuple=" << nbOfTuples << " and nbOfCompo=" << nbOfCompo;
05455       oss << ".\nBecause the number of elements in this is " << _nb_of_compo << " !";
05456       throw INTERP_KERNEL::Exception(oss.str().c_str());
05457     }
05458 }