X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMEDCouplingMemArray.cxx;h=5006c10a8a7d002d5288c10e1a800c69207c5520;hb=9abc40a840f69fd7f07b356cd31876b64dc81e14;hp=9468ef0c0757e2496e096508ebae907a430ab112;hpb=b307fa3ee9c6d9e08082e2ccc832b28a17fd6d2c;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index 9468ef0c0..5006c10a8 100755 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2021 CEA/DEN, EDF R&D +// Copyright (C) 2007-2022 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -423,6 +423,29 @@ std::string DataArray::getUnitOnComponent(std::size_t i) const } } +/*! + * Split \a st string into chunks of sz characters each. + * Size of input \a st must a be a multiple of \a sz. If not an exception is thrown. + */ +std::vector DataArray::SplitStringInChuncks(const std::string st, std::size_t sz) +{ + std::size_t len = st.length(); + std::size_t nbOfCompo(len/sz); + if( nbOfCompo*sz != len) + { + THROW_IK_EXCEPTION("DataArray::SplitStringInChuncks : Length of input string (" << len << ") is not equal to " << nbOfCompo << "*" << sz << " !"); + } + std::vector ret(nbOfCompo); + for(std::size_t i = 0 ; i < nbOfCompo ; ++i) + { + std::string part = st.substr(i*sz,sz); + std::size_t p3=part.find_last_not_of(" \t"); + part = part.substr(0,p3+1); + ret[i] = part; + } + return ret; +} + /*! * Returns the var part of the full component information. * For example, if \a info == "SIGXY [N/m^2]", then this method returns "SIGXY". @@ -2314,16 +2337,7 @@ DataArrayDouble *DataArrayDouble::magnitude() const return ret; } -/*! - * Computes the maximal value within every tuple of \a this array. - * \return DataArrayDouble * - the new instance of DataArrayDouble containing the - * same number of tuples as \a this array and one component. - * The caller is to delete this result array using decrRef() as it is no more - * needed. - * \throw If \a this is not allocated. - * \sa DataArrayDouble::maxPerTupleWithCompoId - */ -DataArrayDouble *DataArrayDouble::maxPerTuple() const +DataArrayDouble *DataArrayDouble::operatePerTuple(std::function func) const { checkAllocated(); std::size_t nbOfComp(getNumberOfComponents()); @@ -2333,10 +2347,38 @@ DataArrayDouble *DataArrayDouble::maxPerTuple() const const double *src=getConstPointer(); double *dest=ret->getPointer(); for(mcIdType i=0;ioperatePerTuple([](const double *bg, const double *endd) { return *std::max_element(bg,endd); }); +} + +/*! + * Computes the minimal value within every tuple of \a this array. + * \return DataArrayDouble * - the new instance of DataArrayDouble containing the + * same number of tuples as \a this array and one component. + * The caller is to delete this result array using decrRef() as it is no more + * needed. + * \throw If \a this is not allocated. + * \sa DataArrayDouble::maxPerTuple + */ +DataArrayDouble *DataArrayDouble::minPerTuple() const +{ + return this->operatePerTuple([](const double *bg, const double *endd) { return *std::min_element(bg,endd); }); +} + /*! * Computes the maximal value within every tuple of \a this array and it returns the first component * id for each tuple that corresponds to the maximal value within the tuple.