From eb28fac501d4d7ed9c190a90c9f687adc3ffa8aa Mon Sep 17 00:00:00 2001 From: ageay Date: Thu, 25 Jul 2013 06:24:09 +0000 Subject: [PATCH] Target MEDReader --- src/MEDCoupling/MEDCouplingMemArray.cxx | 47 ++++++++++++++++++++++ src/MEDCoupling/MEDCouplingMemArray.hxx | 2 + src/MEDCoupling_Swig/MEDCouplingCommon.i | 1 + src/MEDCoupling_Swig/MEDCouplingMemArray.i | 11 +++-- src/MEDLoader/MEDFileFieldOverView.cxx | 1 + 5 files changed, 59 insertions(+), 3 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index bbeeaf46a..82082779f 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -379,6 +379,53 @@ std::string DataArray::GetUnitFromInfo(const std::string& info) throw(INTERP_KER return info.substr(p1+1,p2-p1-1); } +/*! + * Returns a new DataArray by concatenating all given arrays, so that (1) the number + * of tuples in the result array is a sum of the number of tuples of given arrays and (2) + * the number of component in the result array is same as that of each of given arrays. + * Info on components is copied from the first of the given arrays. Number of components + * in the given arrays must be the same. + * \param [in] arrs - a sequence of arrays to include in the result array. All arrays must have the same type. + * \return DataArray * - the new instance of DataArray (that can be either DataArrayInt, DataArrayDouble, DataArrayChar). + * The caller is to delete this result array using decrRef() as it is no more + * needed. + * \throw If all arrays within \a arrs are NULL. + * \throw If all not null arrays in \a arrs have not the same type. + * \throw If getNumberOfComponents() of arrays within \a arrs. + */ +DataArray *DataArray::Aggregate(const std::vector& arrs) throw(INTERP_KERNEL::Exception) +{ + std::vector arr2; + for(std::vector::const_iterator it=arrs.begin();it!=arrs.end();it++) + if(*it) + arr2.push_back(*it); + if(arr2.empty()) + throw INTERP_KERNEL::Exception("DataArray::Aggregate : only null instance in input vector !"); + std::vector arrd; + std::vector arri; + std::vector arrc; + for(std::vector::const_iterator it=arr2.begin();it!=arr2.end();it++) + { + const DataArrayDouble *a=dynamic_cast(*it); + if(a) + { arrd.push_back(a); continue; } + const DataArrayInt *b=dynamic_cast(*it); + if(b) + { arri.push_back(b); continue; } + const DataArrayChar *c=dynamic_cast(*it); + if(c) + { arrc.push_back(c); continue; } + throw INTERP_KERNEL::Exception("DataArray::Aggregate : presence of not null instance in inuput that is not in [DataArrayDouble, DataArrayInt, DataArrayChar] !"); + } + if(arr2.size()==arrd.size()) + return DataArrayDouble::Aggregate(arrd); + if(arr2.size()==arri.size()) + return DataArrayInt::Aggregate(arri); + if(arr2.size()==arrc.size()) + return DataArrayChar::Aggregate(arrc); + throw INTERP_KERNEL::Exception("DataArray::Aggregate : all input arrays must have the same type !"); +} + /*! * Sets information on a component specified by an index. * To know more on format of this information diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index fdf534775..9ef0b37de 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -152,6 +152,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT virtual DataArray *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const = 0; MEDCOUPLING_EXPORT virtual DataArray *selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const throw(INTERP_KERNEL::Exception) = 0; MEDCOUPLING_EXPORT virtual DataArray *selectByTupleId2(int bg, int end2, int step) const throw(INTERP_KERNEL::Exception) = 0; + MEDCOUPLING_EXPORT virtual void rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception) = 0; MEDCOUPLING_EXPORT void checkNbOfTuples(int nbOfTuples, const char *msg) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void checkNbOfComps(int nbOfCompo, const char *msg) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void checkNbOfTuplesAndComp(const DataArray& other, const char *msg) const throw(INTERP_KERNEL::Exception); @@ -163,6 +164,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT static int GetPosOfItemGivenBESRelativeNoThrow(int value, int begin, int end, int step) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT static std::string GetVarNameFromInfo(const std::string& info) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT static std::string GetUnitFromInfo(const std::string& info) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT static DataArray *Aggregate(const std::vector& arrs) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT virtual void reprStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception) = 0; MEDCOUPLING_EXPORT virtual void reprZipStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception) = 0; MEDCOUPLING_EXPORT virtual void reprWithoutNameStream(std::ostream& stream) const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index b1609b42e..c3eb0bf44 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -226,6 +226,7 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::DataArray::selectByTupleId; %newobject ParaMEDMEM::DataArray::selectByTupleIdSafe; %newobject ParaMEDMEM::DataArray::selectByTupleId2; +%newobject ParaMEDMEM::DataArray::Aggregate; %newobject ParaMEDMEM::DataArrayInt::New; %newobject ParaMEDMEM::DataArrayInt::__iter__; %newobject ParaMEDMEM::DataArrayInt::convertToDblArr; diff --git a/src/MEDCoupling_Swig/MEDCouplingMemArray.i b/src/MEDCoupling_Swig/MEDCouplingMemArray.i index 51b1f148f..f2837c8da 100644 --- a/src/MEDCoupling_Swig/MEDCouplingMemArray.i +++ b/src/MEDCoupling_Swig/MEDCouplingMemArray.i @@ -50,6 +50,7 @@ namespace ParaMEDMEM virtual std::size_t getNbOfElemAllocated() const throw(INTERP_KERNEL::Exception); virtual DataArray *deepCpy() const throw(INTERP_KERNEL::Exception); virtual DataArray *selectByTupleId2(int bg, int end2, int step) const throw(INTERP_KERNEL::Exception); + virtual void rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception); void checkNbOfTuples(int nbOfTuples, const char *msg) const throw(INTERP_KERNEL::Exception); void checkNbOfComps(int nbOfCompo, const char *msg) const throw(INTERP_KERNEL::Exception); void checkNbOfTuplesAndComp(const DataArray& other, const char *msg) const throw(INTERP_KERNEL::Exception); @@ -274,6 +275,13 @@ namespace ParaMEDMEM throw INTERP_KERNEL::Exception("DataArray::GetNumberOfItemGivenBESRelative (wrap) : the input slice contains some unknowns that can't be determined in static method !"); return DataArray::GetNumberOfItemGivenBESRelative(strt,stp,step,""); } + + static DataArray *Aggregate(PyObject *arrs) throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + convertFromPyObjVectorOfObj(arrs,SWIGTYPE_p_ParaMEDMEM__DataArray,"DataArray",tmp); + return DataArray::Aggregate(tmp); + } int getNumberOfItemGivenBES(PyObject *slic) const throw(INTERP_KERNEL::Exception) { @@ -332,7 +340,6 @@ namespace ParaMEDMEM DataArrayDouble *fromNoInterlace() const throw(INTERP_KERNEL::Exception); DataArrayDouble *toNoInterlace() const throw(INTERP_KERNEL::Exception); DataArrayDouble *substr(int tupleIdBg, int tupleIdEnd=-1) const throw(INTERP_KERNEL::Exception); - void rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception); void transpose() throw(INTERP_KERNEL::Exception); DataArrayDouble *changeNbOfComponents(int newNbOfComp, double dftValue) const throw(INTERP_KERNEL::Exception); void meldWith(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception); @@ -2323,7 +2330,6 @@ namespace ParaMEDMEM bool isIdentity() const throw(INTERP_KERNEL::Exception); bool isUniform(int val) const throw(INTERP_KERNEL::Exception); DataArrayInt *substr(int tupleIdBg, int tupleIdEnd=-1) const throw(INTERP_KERNEL::Exception); - void rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception); void transpose() throw(INTERP_KERNEL::Exception); DataArrayInt *changeNbOfComponents(int newNbOfComp, int dftValue) const throw(INTERP_KERNEL::Exception); void meldWith(const DataArrayInt *other) throw(INTERP_KERNEL::Exception); @@ -4535,7 +4541,6 @@ namespace ParaMEDMEM DataArrayChar *renumberR(const int *new2Old) const throw(INTERP_KERNEL::Exception); DataArrayChar *renumberAndReduce(const int *old2NewBg, int newNbOfTuple) const throw(INTERP_KERNEL::Exception); bool isUniform(char val) const throw(INTERP_KERNEL::Exception); - void rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception); DataArrayChar *substr(int tupleIdBg, int tupleIdEnd=-1) const throw(INTERP_KERNEL::Exception); DataArrayChar *changeNbOfComponents(int newNbOfComp, char dftValue) const throw(INTERP_KERNEL::Exception); void meldWith(const DataArrayChar *other) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDLoader/MEDFileFieldOverView.cxx b/src/MEDLoader/MEDFileFieldOverView.cxx index 8f8fceccf..3ae0584bc 100644 --- a/src/MEDLoader/MEDFileFieldOverView.cxx +++ b/src/MEDLoader/MEDFileFieldOverView.cxx @@ -1045,6 +1045,7 @@ DataArray *MEDMeshMultiLev::constructDataArray(const MEDFileField1TSStructItem& } throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 6 !"); } + return DataArray::Aggregate(arr); } } -- 2.39.2