From 706d60360e52537b49884c3f5a2d14e7ac27eba3 Mon Sep 17 00:00:00 2001 From: ageay Date: Wed, 26 Jun 2013 07:37:14 +0000 Subject: [PATCH] convertTo --- src/MEDLoader/MEDFileField.cxx | 162 ++++++++++++++++++++++++--- src/MEDLoader/MEDFileField.hxx | 19 +++- src/MEDLoader/Swig/MEDLoaderCommon.i | 4 + 3 files changed, 170 insertions(+), 15 deletions(-) diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index 590958004..6342343ac 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -3522,6 +3522,17 @@ void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other) //= MEDFileAnyTypeField1TSWithoutSDA +void MEDFileAnyTypeField1TSWithoutSDA::deepCpyLeavesFrom(const MEDFileAnyTypeField1TSWithoutSDA& other) throw(INTERP_KERNEL::Exception) +{ + _field_per_mesh.resize(other._field_per_mesh.size()); + std::size_t i=0; + for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=other._field_per_mesh.begin();it!=other._field_per_mesh.end();it++,i++) + { + if((const MEDFileFieldPerMesh *)*it) + _field_per_mesh[i]=(*it)->deepCpy(this); + } +} + /*! * Prints a string describing \a this field into a stream. This string is outputted * by \c print Python command. @@ -4562,6 +4573,20 @@ const char *MEDFileField1TSWithoutSDA::getTypeStr() const throw(INTERP_KERNEL::E return TYPE_STR; } +MEDFileIntField1TSWithoutSDA *MEDFileField1TSWithoutSDA::convertToInt() const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingAutoRefCountObjectPtr ret(new MEDFileIntField1TSWithoutSDA); + ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this); + ret->deepCpyLeavesFrom(*this); + const DataArrayDouble *arr(_arr); + if(arr) + { + MEDCouplingAutoRefCountObjectPtr arr2(arr->convertToIntArr()); + ret->setArray(arr2); + } + return ret.retn(); +} + /*! * Returns a pointer to the underground DataArrayDouble instance. So the * caller should not decrRef() it. This method allows for a direct access to the field @@ -4634,7 +4659,9 @@ MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA():MEDFileAnyTypeField1TSWit MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::shallowCpy() const throw(INTERP_KERNEL::Exception) { - return new MEDFileField1TSWithoutSDA(*this); + MEDCouplingAutoRefCountObjectPtr ret(new MEDFileField1TSWithoutSDA(*this)); + ret->deepCpyLeavesFrom(*this); + return ret.retn(); } MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCpy() const throw(INTERP_KERNEL::Exception) @@ -4642,12 +4669,6 @@ MEDFileAnyTypeField1TSWithoutSDA *MEDFileField1TSWithoutSDA::deepCpy() const thr MEDCouplingAutoRefCountObjectPtr ret=static_cast(shallowCpy()); if((const DataArrayDouble *)_arr) ret->_arr=_arr->deepCpy(); - std::size_t i=0; - for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,i++) - { - if((const MEDFileFieldPerMesh *)*it) - ret->_field_per_mesh[i]=(*it)->deepCpy((MEDFileField1TSWithoutSDA *)ret); - } return ret.retn(); } @@ -4720,6 +4741,20 @@ const char *MEDFileIntField1TSWithoutSDA::getTypeStr() const throw(INTERP_KERNEL return TYPE_STR; } +MEDFileField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::convertToDouble() const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingAutoRefCountObjectPtr ret(new MEDFileField1TSWithoutSDA); + ret->MEDFileAnyTypeField1TSWithoutSDA::operator =(*this); + ret->deepCpyLeavesFrom(*this); + const DataArrayInt *arr(_arr); + if(arr) + { + MEDCouplingAutoRefCountObjectPtr arr2(arr->convertToDblArr()); + ret->setArray(arr2); + } + return ret.retn(); +} + /*! * Returns a pointer to the underground DataArrayInt instance. So the * caller should not decrRef() it. This method allows for a direct access to the field @@ -4797,7 +4832,9 @@ DataArrayInt *MEDFileIntField1TSWithoutSDA::getUndergroundDataArrayIntExt(std::v MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::shallowCpy() const throw(INTERP_KERNEL::Exception) { - return new MEDFileIntField1TSWithoutSDA(*this); + MEDCouplingAutoRefCountObjectPtr ret(new MEDFileIntField1TSWithoutSDA(*this)); + ret->deepCpyLeavesFrom(*this); + return ret.retn(); } MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCpy() const throw(INTERP_KERNEL::Exception) @@ -4805,12 +4842,6 @@ MEDFileAnyTypeField1TSWithoutSDA *MEDFileIntField1TSWithoutSDA::deepCpy() const MEDCouplingAutoRefCountObjectPtr ret=static_cast(shallowCpy()); if((const DataArrayInt *)_arr) ret->_arr=_arr->deepCpy(); - std::size_t i=0; - for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++,i++) - { - if((const MEDFileFieldPerMesh *)*it) - ret->_field_per_mesh[i]=(*it)->deepCpy((MEDFileIntField1TSWithoutSDA *)ret); - } return ret.retn(); } @@ -5626,6 +5657,35 @@ MEDFileField1TS *MEDFileField1TS::New() return ret.retn(); } +/*! + * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied + * following the given input policy. + * + * \param [in] deepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations) + * By default (true) the globals are deeply copied. + * \return MEDFileIntField1TS * - a new object that is the result of the conversion of \a this to int32 field. + */ +MEDFileIntField1TS *MEDFileField1TS::convertToInt(bool deepCpyGlobs) const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingAutoRefCountObjectPtr ret; + const MEDFileAnyTypeField1TSWithoutSDA *content(_content); + if(content) + { + const MEDFileField1TSWithoutSDA *contc=dynamic_cast(content); + if(!contc) + throw INTERP_KERNEL::Exception("MEDFileField1TS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !"); + MEDCouplingAutoRefCountObjectPtr newc(contc->convertToInt()); + ret=static_cast(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileIntField1TSWithoutSDA *)newc,getFileName())); + } + else + ret=MEDFileIntField1TS::New(); + if(deepCpyGlobs) + ret->deepCpyGlobs(*this); + else + ret->shallowCpyGlobs(*this); + return ret.retn(); +} + const MEDFileField1TSWithoutSDA *MEDFileField1TS::contentNotNull() const throw(INTERP_KERNEL::Exception) { const MEDFileAnyTypeField1TSWithoutSDA *pt(_content); @@ -6035,6 +6095,35 @@ MEDFileAnyTypeField1TS *MEDFileIntField1TS::shallowCpy() const throw(INTERP_KERN return new MEDFileIntField1TS(*this); } +/*! + * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied + * following the given input policy. + * + * \param [in] deepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations) + * By default (true) the globals are deeply copied. + * \return MEDFileField1TS * - a new object that is the result of the conversion of \a this to float64 field. + */ +MEDFileField1TS *MEDFileIntField1TS::convertToDouble(bool deepCpyGlobs) const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingAutoRefCountObjectPtr ret; + const MEDFileAnyTypeField1TSWithoutSDA *content(_content); + if(content) + { + const MEDFileIntField1TSWithoutSDA *contc=dynamic_cast(content); + if(!contc) + throw INTERP_KERNEL::Exception("MEDFileIntField1TS::convertToInt : the content inside this is not INT32 ! This is incoherent !"); + MEDCouplingAutoRefCountObjectPtr newc(contc->convertToDouble()); + ret=static_cast(MEDFileAnyTypeField1TS::BuildNewInstanceFromContent((MEDFileField1TSWithoutSDA *)newc,getFileName())); + } + else + ret=MEDFileField1TS::New(); + if(deepCpyGlobs) + ret->deepCpyGlobs(*this); + else + ret->shallowCpyGlobs(*this); + return ret.retn(); +} + /*! * Adds a MEDCouplingFieldDouble to \a this. The underlying mesh of the given field is * checked if its elements are sorted suitable for writing to MED file ("STB" stands for @@ -7124,6 +7213,22 @@ std::vector< std::vector > MEDFileFieldMultiTSWithoutSDA::get return myF1TSC->getFieldSplitedByType2(mname,types,typesF,pfls,locs); } +MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const throw(INTERP_KERNEL::Exception) +{ + /*MEDCouplingAutoRefCountObjectPtr ret(new MEDFileIntFieldMultiTSWithoutSDA); + ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this); + ret->deepCpyLeavesFrom(*this); + const DataArrayDouble *arr(_arr); + if(arr) + { + MEDCouplingAutoRefCountObjectPtr arr2(arr->convertToIntArr()); + ret->setArray(arr2); + } + return ret.retn();*/ +} + +//= MEDFileAnyTypeFieldMultiTS + MEDFileAnyTypeFieldMultiTS::MEDFileAnyTypeFieldMultiTS() { } @@ -7739,6 +7844,35 @@ void MEDFileFieldMultiTS::checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1t throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::checkCoherencyOfType : the input field1TS is not a FLOAT64 type !"); } +/*! + * This method performs a copy with datatype modification ( float64->int32 ) of \a this. The globals information are copied + * following the given input policy. + * + * \param [in] deepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations) + * By default (true) the globals are deeply copied. + * \return MEDFileIntFieldMultiTS * - a new object that is the result of the conversion of \a this to int32 field. + */ +MEDFileIntFieldMultiTS *MEDFileFieldMultiTS::convertToInt(bool deepCpyGlobs) const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingAutoRefCountObjectPtr ret; + const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content); + if(content) + { + const MEDFileFieldMultiTSWithoutSDA *contc=dynamic_cast(content); + if(!contc) + throw INTERP_KERNEL::Exception("MEDFileFieldMultiTS::convertToInt : the content inside this is not FLOAT64 ! This is incoherent !"); + MEDCouplingAutoRefCountObjectPtr newc(contc->convertToInt()); + ret=static_cast(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileIntFieldMultiTSWithoutSDA *)newc,getFileName())); + } + else + ret=MEDFileIntFieldMultiTS::New(); + if(deepCpyGlobs) + ret->deepCpyGlobs(*this); + else + ret->shallowCpyGlobs(*this); + return ret.retn(); +} + /*! * Returns a new MEDFileField1TS holding data of a given time step of \a this field. * \param [in] pos - a time step id. diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index fdf54072f..dcb0253aa 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -478,6 +478,7 @@ namespace ParaMEDMEM // MEDFileFieldPerMeshPerTypePerDisc *getLeafGivenMeshAndTypeAndLocId(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId) throw(INTERP_KERNEL::Exception); const MEDFileFieldPerMeshPerTypePerDisc *getLeafGivenMeshAndTypeAndLocId(const char *mName, INTERP_KERNEL::NormalizedCellType typ, int locId) const throw(INTERP_KERNEL::Exception); + void deepCpyLeavesFrom(const MEDFileAnyTypeField1TSWithoutSDA& other) throw(INTERP_KERNEL::Exception); public: int getNumberOfComponents() const; const std::vector& getInfo() const; @@ -521,6 +522,8 @@ namespace ParaMEDMEM //! only useable on reading mutable int _csit; }; + + class MEDFileIntField1TSWithoutSDA; /*! * SDA is for Shared Data Arrays such as profiles. @@ -548,6 +551,7 @@ namespace ParaMEDMEM const DataArray *getOrCreateAndGetArray() const; DataArrayDouble *getOrCreateAndGetArrayDouble(); const DataArrayDouble *getOrCreateAndGetArrayDouble() const; + MEDFileIntField1TSWithoutSDA *convertToInt() const throw(INTERP_KERNEL::Exception); protected: MEDCouplingAutoRefCountObjectPtr< DataArrayDouble > _arr; public: @@ -575,6 +579,7 @@ namespace ParaMEDMEM const DataArrayInt *getOrCreateAndGetArrayInt() const; DataArrayInt *getUndergroundDataArrayInt() const throw(INTERP_KERNEL::Exception); DataArrayInt *getUndergroundDataArrayIntExt(std::vector< std::pair,std::pair > >& entries) const throw(INTERP_KERNEL::Exception); + MEDFileField1TSWithoutSDA *convertToDouble() const throw(INTERP_KERNEL::Exception); protected: MEDFileIntField1TSWithoutSDA(const char *fieldName, int csit, int iteration, int order, const std::vector& infos); protected: @@ -659,10 +664,13 @@ namespace ParaMEDMEM virtual med_field_type getMEDFileFieldType() const = 0; MEDFileAnyTypeField1TSWithoutSDA *contentNotNullBase() throw(INTERP_KERNEL::Exception); const MEDFileAnyTypeField1TSWithoutSDA *contentNotNullBase() const throw(INTERP_KERNEL::Exception); + //void setContent(MEDCouplingAutoRefCountObjectPtr newc); tony protected: MEDCouplingAutoRefCountObjectPtr _content; }; - + + class MEDFileIntField1TS; + /*! * User class. */ @@ -674,6 +682,8 @@ namespace ParaMEDMEM static MEDFileField1TS *New(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception); static MEDFileField1TS *New(const MEDFileField1TSWithoutSDA& other, bool shallowCopyOfContent); static MEDFileField1TS *New(); + MEDFileIntField1TS *convertToInt(bool deepCpyGlobs=true) const throw(INTERP_KERNEL::Exception); + // MEDCouplingFieldDouble *getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldAtTopLevel(TypeOfField type, int renumPol=0) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol=0) const throw(INTERP_KERNEL::Exception); @@ -714,6 +724,7 @@ namespace ParaMEDMEM static MEDFileIntField1TS *New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception); static MEDFileIntField1TS *New(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception); static MEDFileIntField1TS *New(const MEDFileIntField1TSWithoutSDA& other, bool shallowCopyOfContent); + MEDFileField1TS *convertToDouble(bool deepCpyGlobs=true) const throw(INTERP_KERNEL::Exception); MEDFileAnyTypeField1TS *shallowCpy() const throw(INTERP_KERNEL::Exception); // MEDCouplingFieldDouble *getFieldAtLevel(TypeOfField type, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol=0) const throw(INTERP_KERNEL::Exception); @@ -809,6 +820,8 @@ namespace ParaMEDMEM std::vector< MEDCouplingAutoRefCountObjectPtr > _time_steps; }; + class MEDFileIntFieldMultiTSWithoutSDA; + class MEDLOADER_EXPORT MEDFileFieldMultiTSWithoutSDA : public MEDFileAnyTypeFieldMultiTSWithoutSDA { public: @@ -818,6 +831,7 @@ namespace ParaMEDMEM MEDFileAnyTypeFieldMultiTSWithoutSDA *shallowCpy() const throw(INTERP_KERNEL::Exception); MEDFileAnyTypeFieldMultiTSWithoutSDA *createNew() const throw(INTERP_KERNEL::Exception); std::vector< std::vector > getFieldSplitedByType2(int iteration, int order, const char *mname, std::vector& types, std::vector< std::vector >& typesF, std::vector< std::vector >& pfls, std::vector< std::vector >& locs) const throw(INTERP_KERNEL::Exception); + MEDFileIntFieldMultiTSWithoutSDA *convertToInt() const throw(INTERP_KERNEL::Exception); protected: MEDFileFieldMultiTSWithoutSDA(const char *fieldName); MEDFileFieldMultiTSWithoutSDA(med_idt fid, const char *fieldName, med_field_type fieldTyp, const std::vector& infos, int nbOfStep, const std::string& dtunit) throw(INTERP_KERNEL::Exception); @@ -920,6 +934,8 @@ namespace ParaMEDMEM MEDCouplingAutoRefCountObjectPtr _content; }; + class MEDFileIntFieldMultiTS; + /*! * User class. */ @@ -932,6 +948,7 @@ namespace ParaMEDMEM static MEDFileFieldMultiTS *New(const MEDFileFieldMultiTSWithoutSDA& other, bool shallowCopyOfContent); MEDFileAnyTypeFieldMultiTS *shallowCpy() const throw(INTERP_KERNEL::Exception); void checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const throw(INTERP_KERNEL::Exception); + MEDFileIntFieldMultiTS *convertToInt(bool deepCpyGlobs=true) const throw(INTERP_KERNEL::Exception); // MEDFileAnyTypeField1TS *getTimeStepAtPos(int pos) const throw(INTERP_KERNEL::Exception); MEDFileAnyTypeField1TS *getTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index 7003e6752..7b6c5d3ca 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -144,8 +144,10 @@ using namespace ParaMEDMEM; %newobject ParaMEDMEM::MEDFileField1TS::getFieldOnMeshAtLevel; %newobject ParaMEDMEM::MEDFileField1TS::getFieldAtLevelOld; %newobject ParaMEDMEM::MEDFileField1TS::getUndergroundDataArray; +%newobject ParaMEDMEM::MEDFileField1TS::convertToInt; %newobject ParaMEDMEM::MEDFileIntField1TS::New; %newobject ParaMEDMEM::MEDFileIntField1TS::getUndergroundDataArray; +%newobject ParaMEDMEM::MEDFileIntField1TS::convertToDouble; %newobject ParaMEDMEM::MEDFileData::New; %newobject ParaMEDMEM::MEDFileData::deepCpy; @@ -1229,6 +1231,7 @@ namespace ParaMEDMEM static MEDFileField1TS *New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception); static MEDFileField1TS *New(const char *fileName) throw(INTERP_KERNEL::Exception); static MEDFileField1TS *New(); + MEDFileIntField1TS *convertToInt(bool deepCpyGlobs=true) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldAtLevel(TypeOfField type, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldAtTopLevel(TypeOfField type, int renumPol=0) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, const MEDCouplingMesh *mesh, int renumPol=0) const throw(INTERP_KERNEL::Exception); @@ -1362,6 +1365,7 @@ namespace ParaMEDMEM static MEDFileIntField1TS *New(const char *fileName) throw(INTERP_KERNEL::Exception); static MEDFileIntField1TS *New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception); static MEDFileIntField1TS *New(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception); + MEDFileField1TS *convertToDouble(bool deepCpyGlobs=true) const throw(INTERP_KERNEL::Exception); // void setFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals) throw(INTERP_KERNEL::Exception); void setFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception); -- 2.30.2