From: cvw Date: Thu, 16 Feb 2012 13:55:29 +0000 (+0000) Subject: modify Monotonic(bool increase, eps) X-Git-Tag: V6_main_FINAL~856 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3cdc446730b7cd1205e5a383773de2bfc9736989;p=tools%2Fmedcoupling.git modify Monotonic(bool increase, eps) --- diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index b89826c64..da0befe97 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -93,9 +93,9 @@ void DataArray::copyPartOfStringInfoFrom(const DataArray& other, const std::vect int nbOfCompoOth=other.getNumberOfComponents(); std::size_t newNbOfCompo=compoIds.size(); for(std::size_t i=0;i=nbOfCompoOth) + if(compoIds[i]>=nbOfCompoOth || compoIds[i]<0) { - std::ostringstream oss; oss << "Specified component ids is to high (" << compoIds[i] << ") compared with nb of actual components (" << nbOfCompoOth << ")"; + std::ostringstream oss; oss << "Specified component id is out of range (" << compoIds[i] << ") compared with nb of actual components (" << nbOfCompoOth << ")"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } for(std::size_t i=0;i& compoIds, cons if((int)partOfCompoToSet!=other.getNumberOfComponents()) throw INTERP_KERNEL::Exception("Given compoIds has not the same size as number of components of given array !"); for(std::size_t i=0;i=nbOfCompo) + if(compoIds[i]>=nbOfCompo || compoIds[i]<0) { - std::ostringstream oss; oss << "Specified component ids is to high (" << compoIds[i] << ") compared with nb of actual components (" << nbOfCompo << ")"; + std::ostringstream oss; oss << "Specified component id is out of range (" << compoIds[i] << ") compared with nb of actual components (" << nbOfCompo << ")"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } for(std::size_t i=0;i DataArray::getUnitsOnComponent() const std::string DataArray::getInfoOnComponent(int i) const throw(INTERP_KERNEL::Exception) { - if(i<(int)_info_on_compo.size()) + if(i<(int)_info_on_compo.size() && i>=0) return _info_on_compo[i]; else { - std::ostringstream oss; oss << "getInfoOnComponent : Invalid component id transmitted (" << i << ") >= " << (int) _info_on_compo.size(); + 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(); throw INTERP_KERNEL::Exception(oss.str().c_str()); } } @@ -181,13 +181,13 @@ std::string DataArray::getInfoOnComponent(int i) const throw(INTERP_KERNEL::Exce */ std::string DataArray::getVarOnComponent(int i) const throw(INTERP_KERNEL::Exception) { - if(i<(int)_info_on_compo.size()) + if(i<(int)_info_on_compo.size() && i>=0) { return GetVarNameFromInfo(_info_on_compo[i]); } else { - std::ostringstream oss; oss << "getVarOnComponent : Invalid component id transmitted (" << i << ") >= " << (int) _info_on_compo.size(); + 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(); throw INTERP_KERNEL::Exception(oss.str().c_str()); } } @@ -198,13 +198,13 @@ std::string DataArray::getVarOnComponent(int i) const throw(INTERP_KERNEL::Excep */ std::string DataArray::getUnitOnComponent(int i) const throw(INTERP_KERNEL::Exception) { - if(i<(int)_info_on_compo.size()) + if(i<(int)_info_on_compo.size() && i>=0) { return GetUnitFromInfo(_info_on_compo[i]); } else { - std::ostringstream oss; oss << "getUnitOnComponent : Invalid component id transmitted (" << i << ") >= " << (int) _info_on_compo.size(); + 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(); throw INTERP_KERNEL::Exception(oss.str().c_str()); } } @@ -236,11 +236,11 @@ std::string DataArray::GetUnitFromInfo(const std::string& info) throw(INTERP_KER void DataArray::setInfoOnComponent(int i, const char *info) throw(INTERP_KERNEL::Exception) { - if(i<(int)_info_on_compo.size()) + if(i<(int)_info_on_compo.size() && i>=0) _info_on_compo[i]=info; else { - std::ostringstream oss; oss << "setInfoOnComponent : Invalid component id transmitted (" << i << ") >= " << (int) _info_on_compo.size(); + 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(); throw INTERP_KERNEL::Exception(oss.str().c_str()); } } @@ -286,7 +286,7 @@ void DataArray::CheckValueInRange(int ref, int value, const char *msg) throw(INT { if(value<0 || value>=ref) { - std::ostringstream oss; oss << "DataArray::CheckValueInRange : " << msg << " ! Expected in range [0," << ref << ") having " << value << " !"; + std::ostringstream oss; oss << "DataArray::CheckValueInRange : " << msg << " ! Expected in range [0," << ref << "[ having " << value << " !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } } @@ -295,7 +295,7 @@ void DataArray::CheckClosingParInRange(int ref, int value, const char *msg) thro { if(value<0 || value>ref) { - std::ostringstream oss; oss << "DataArray::CheckClosingParInRange : " << msg << " ! Expected a range in [0," << ref << ") having closing open parenthesis " << value << " !"; + std::ostringstream oss; oss << "DataArray::CheckClosingParInRange : " << msg << " ! Expected a range in [0," << ref << "] having closing open parenthesis " << value << " !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } } @@ -382,24 +382,24 @@ void DataArrayDouble::alloc(int nbOfTuple, int nbOfCompo) void DataArrayDouble::fillWithZero() throw(INTERP_KERNEL::Exception) { - fillWithValue(0.); + checkAllocated(); + _mem.fillWithValue(0.); + declareAsNew(); } void DataArrayDouble::fillWithValue(double val) throw(INTERP_KERNEL::Exception) { - if(!getPointer()) - throw INTERP_KERNEL::Exception("DataArrayDouble::fillWithValue : allocate first !"); - _mem.fillWithValue(val); + checkAllocated(); + _mem.fillWithValue(val); declareAsNew(); } void DataArrayDouble::iota(double init) throw(INTERP_KERNEL::Exception) { - double *ptr=getPointer(); - if(!ptr) - throw INTERP_KERNEL::Exception("DataArrayDouble::iota : allocate first !"); + checkAllocated(); if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("DataArrayDouble::iota : works only for arrays with only one component, you can call 'rearrange' method before !"); + double *ptr=getPointer(); int ntuples=getNumberOfTuples(); for(int i=0;i(ref-absEps)) return false; + ref=ptr[i]; + } + return true; } - return true; } std::string DataArrayDouble::repr() const @@ -662,7 +691,7 @@ DataArrayDouble *DataArrayDouble::renumberAndReduce(const int *old2New, int newN /*! * This method is a generalization of DataArrayDouble::substr method because a not contigous range can be specified here. - * This method is equavalent to DataArrayDouble::renumberAndReduce except that convention in input is new2old and \b not old2new. + * This method is equivalent to DataArrayDouble::renumberAndReduce except that convention in input is new2old and \b not old2new. */ DataArrayDouble *DataArrayDouble::selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const { @@ -875,12 +904,15 @@ void DataArrayDouble::meldWith(const DataArrayDouble *other) throw(INTERP_KERNEL */ void DataArrayDouble::findCommonTuples(double prec, int limitTupleId, DataArrayInt *&comm, DataArrayInt *&commIndex) const throw(INTERP_KERNEL::Exception) { + checkAllocated(); + int nbOfCompo=getNumberOfComponents(); + if ((nbOfCompo<1) || (nbOfCompo>3)) //test before work + throw INTERP_KERNEL::Exception("DataArrayDouble::findCommonTuples : Unexpected spacedim of coords. Must be 1, 2 or 3."); + + int nbOfTuples=getNumberOfTuples(); comm=DataArrayInt::New(); commIndex=DataArrayInt::New(); // - checkAllocated(); - int nbOfTuples=getNumberOfTuples(); - int nbOfCompo=getNumberOfComponents(); std::vector bbox(2*nbOfTuples*nbOfCompo); const double *coordsPtr=getConstPointer(); for(int i=0;i(bbox,nbOfTuples,limitTupleId,prec,c,cI); break; - default: - throw INTERP_KERNEL::Exception("Unexpected spacedim of coords. Must be 1, 2 or 3."); + //default: test yet } commIndex->alloc((int)cI.size(),1); std::copy(cI.begin(),cI.end(),commIndex->getPointer()); @@ -2399,23 +2430,24 @@ void DataArrayInt::alloc(int nbOfTuple, int nbOfCompo) void DataArrayInt::fillWithZero() { + checkAllocated(); _mem.fillWithValue(0); declareAsNew(); } void DataArrayInt::fillWithValue(int val) { + checkAllocated(); _mem.fillWithValue(val); declareAsNew(); } void DataArrayInt::iota(int init) throw(INTERP_KERNEL::Exception) { - int *ptr=getPointer(); - if(!ptr) - throw INTERP_KERNEL::Exception("DataArrayInt::iota : allocate first !"); + checkAllocated(); if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("DataArrayInt::iota : works only for arrays with only one component, you can call 'rearrange' method before !"); + int *ptr=getPointer(); int ntuples=getNumberOfTuples(); for(int i=0;ialloc(getNumberOfTuples(),getNumberOfComponents()); int nbOfVals=getNbOfElems();