From 68e9885f3d7c5ce0edc068c9fbc987cf196f305f Mon Sep 17 00:00:00 2001 From: ageay Date: Mon, 8 Jul 2013 15:34:52 +0000 Subject: [PATCH] MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries --- src/MEDLoader/MEDFileField.cxx | 37 ++++++++++++++++++++++++++++ src/MEDLoader/MEDFileField.hxx | 1 + src/MEDLoader/Swig/MEDLoaderCommon.i | 23 +++++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index 2fcf6c868..745dea27b 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -8177,6 +8177,43 @@ MEDFileAnyTypeField1TS *MEDFileAnyTypeFieldMultiTS::getTimeStepGivenTime(double return getTimeStepAtPos(pos); } +/*! + * This method groups not null items in \a vectFMTS per time step series. Two time series are considered equal if the list of their pair of integers iteration,order are equal. + * The float64 value of time attached to the pair of integers are not considered here. + * + * \param [in] vectFMTS - vector of not null fields defined on a same global data pointer. + * \throw If there is a null pointer in \a vectFMTS. + */ +std::vector< std::vector > MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(const std::vector& vectFMTS) throw(INTERP_KERNEL::Exception) +{ + static const char msg[]="MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries : presence of null instance in input vector !"; + std::vector< std::vector > ret; + std::list lstFMTS(vectFMTS.begin(),vectFMTS.end()); + while(!lstFMTS.empty()) + { + std::list::iterator it(lstFMTS.begin()); + MEDFileAnyTypeFieldMultiTS *curIt(*it); + if(!curIt) + throw INTERP_KERNEL::Exception(msg); + std::vector< std::pair > refIts=curIt->getIterations(); + std::vector elt; + elt.push_back(curIt); it=lstFMTS.erase(it); + while(it!=lstFMTS.end()) + { + curIt=*it; + if(!curIt) + throw INTERP_KERNEL::Exception(msg); + std::vector< std::pair > curIts=curIt->getIterations(); + if(refIts==curIts) + { elt.push_back(curIt); it=lstFMTS.erase(it);} + else + it++; + } + ret.push_back(elt); + } + return ret; +} + MEDFileAnyTypeFieldMultiTSIterator *MEDFileAnyTypeFieldMultiTS::iterator() throw(INTERP_KERNEL::Exception) { return new MEDFileAnyTypeFieldMultiTSIterator(this); diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index aae7740b7..22ac23dea 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -913,6 +913,7 @@ namespace ParaMEDMEM virtual MEDFileAnyTypeField1TS *getTimeStepAtPos(int pos) const throw(INTERP_KERNEL::Exception) = 0; MEDFileAnyTypeField1TS *getTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception); MEDFileAnyTypeField1TS *getTimeStepGivenTime(double time, double eps=1e-8) const throw(INTERP_KERNEL::Exception); + static std::vector< std::vector > SplitIntoCommonTimeSeries(const std::vector& vectFMTS) throw(INTERP_KERNEL::Exception); public:// direct forwarding to MEDFileField1TSWithoutSDA instance _content std::string getName() const; void setName(const char *name); diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index a35f7f1c9..8dc2a6b88 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -1827,6 +1827,29 @@ namespace ParaMEDMEM convertFromPyObjVectorOfObj(li,SWIGTYPE_p_ParaMEDMEM__MEDFileAnyTypeField1TS,"MEDFileAnyTypeField1TS",tmp); self->pushBackTimeSteps(tmp); } + + static PyObject *MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(PyObject *li) throw(INTERP_KERNEL::Exception) + { + std::vector vectFMTS; + convertFromPyObjVectorOfObj(li,SWIGTYPE_p_ParaMEDMEM__MEDFileAnyTypeFieldMultiTS,"MEDFileAnyTypeFieldMultiTS",vectFMTS); + std::vector< std::vector > ret=MEDFileAnyTypeFieldMultiTS::SplitIntoCommonTimeSeries(vectFMTS); + std::size_t sz=ret.size(); + PyObject *retPy=PyList_New(sz); + for(std::size_t i=0;iincrRef(); + PyList_SetItem(ret1Py,j,convertMEDFileFieldMultiTS(elt,SWIG_POINTER_OWN | 0 )); + } + PyList_SetItem(retPy,i,ret1Py); + } + return retPy; + } } }; -- 2.30.2