From: ageay Date: Tue, 21 Feb 2012 16:08:35 +0000 (+0000) Subject: Dealing with MED files with fields on int32. X-Git-Tag: V6_main_FINAL~833 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=600de345bfa23ce43f1631fc018dccd1bfe440df;p=tools%2Fmedcoupling.git Dealing with MED files with fields on int32. --- diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index 804e6fd30..238f8853f 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -297,9 +297,9 @@ void MEDFileFieldPerMeshPerTypePerDisc::assignNodeFieldNoProfile(const MEDCoupli _nval=field->getArray()->getNumberOfTuples(); } -MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(MEDFileFieldPerMeshPerType *fath, med_idt fid, TypeOfField type, int profileIt) throw(INTERP_KERNEL::Exception) +MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(MEDFileFieldPerMeshPerType *fath, med_idt fid, TypeOfField type, int profileIt, int ft) throw(INTERP_KERNEL::Exception) { - return new MEDFileFieldPerMeshPerTypePerDisc(fath,fid,type,profileIt); + return new MEDFileFieldPerMeshPerTypePerDisc(fath,fid,type,profileIt,ft); } MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int locId) @@ -307,7 +307,7 @@ MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(MEDFil return new MEDFileFieldPerMeshPerTypePerDisc(fath,type,locId); } -MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, med_idt fid, TypeOfField atype, int profileIt) throw(INTERP_KERNEL::Exception) +MEDFileFieldPerMeshPerTypePerDisc::MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, med_idt fid, TypeOfField atype, int profileIt, int ft) throw(INTERP_KERNEL::Exception) try:_type(atype),_father(fath),_profile_it(profileIt) { INTERP_KERNEL::AutoPtr locname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); @@ -326,8 +326,25 @@ try:_type(atype),_father(fath),_profile_it(profileIt) pflname,&profilesize,locname,&nbi); _arr=DataArrayDouble::New(); _arr->alloc(_nval*nbi,infos.size()); - MEDfieldValueWithProfileRd(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE, - pflname,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,reinterpret_cast(_arr->getPointer())); + switch(ft) + { + case 0: + { + MEDfieldValueWithProfileRd(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE, + pflname,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,reinterpret_cast(_arr->getPointer())); + break; + } + case 1: + { + INTERP_KERNEL::AutoPtr tmpp=new int[_nval*nbi*infos.size()]; + MEDfieldValueWithProfileRd(fid,fieldName.c_str(),iteration,order,menti,mgeoti,MED_COMPACT_PFLMODE, + pflname,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,reinterpret_cast((int *)tmpp)); + std::copy((const int *)tmpp,(const int *)tmpp+_nval*nbi*infos.size(),_arr->getPointer()); + break; + } + default: + throw INTERP_KERNEL::Exception("Error on array reading ! Unrecognized type of field ! Should be in FLOAT64 or INT32 !"); + } _profile=MEDLoaderBase::buildStringFromFortran(pflname,MED_NAME_SIZE); _localization=MEDLoaderBase::buildStringFromFortran(locname,MED_NAME_SIZE); if(type==ON_CELLS && !_localization.empty()) @@ -830,7 +847,7 @@ MEDFileFieldPerMeshPerType::MEDFileFieldPerMeshPerType(MEDFileFieldPerMesh *fath { } -void MEDFileFieldPerMeshPerType::finishLoading(med_idt fid, TypeOfField type) throw(INTERP_KERNEL::Exception) +void MEDFileFieldPerMeshPerType::finishLoading(med_idt fid, TypeOfField type, int ft) throw(INTERP_KERNEL::Exception) { INTERP_KERNEL::NormalizedCellType geoType=getGeoType(); INTERP_KERNEL::AutoPtr pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); @@ -841,7 +858,7 @@ void MEDFileFieldPerMeshPerType::finishLoading(med_idt fid, TypeOfField type) th _field_pm_pt_pd.resize(nbProfiles); for(int i=0;iassignNodeFieldProfile(pfl,field,glob); } -void MEDFileFieldPerMesh::finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception) +void MEDFileFieldPerMesh::finishLoading(med_idt fid, int ft) throw(INTERP_KERNEL::Exception) { INTERP_KERNEL::AutoPtr meshName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); INTERP_KERNEL::AutoPtr pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); @@ -967,7 +984,7 @@ void MEDFileFieldPerMesh::finishLoading(med_idt fid) throw(INTERP_KERNEL::Except _field_pm_pt.resize(_field_pm_pt.size()+1); _field_pm_pt.back()=MEDFileFieldPerMeshPerType::New(this,typmai2[i]); _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1); - _field_pm_pt.back()->finishLoading(fid,ON_CELLS); + _field_pm_pt.back()->finishLoading(fid,ON_CELLS,ft); } nbProfile=MEDfield23nProfile(fid,getName().c_str(),getIteration(),getOrder(),MED_NODE_ELEMENT,typmai[i],_mesh_csit,meshName,pflName,locName); if(nbProfile>0) @@ -975,7 +992,7 @@ void MEDFileFieldPerMesh::finishLoading(med_idt fid) throw(INTERP_KERNEL::Except _field_pm_pt.resize(_field_pm_pt.size()+1); _field_pm_pt.back()=MEDFileFieldPerMeshPerType::New(this,typmai2[i]); _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1); - _field_pm_pt.back()->finishLoading(fid,ON_GAUSS_NE); + _field_pm_pt.back()->finishLoading(fid,ON_GAUSS_NE,ft); } } int nbProfile=MEDfield23nProfile(fid,getName().c_str(),getIteration(),getOrder(),MED_NODE,MED_NONE,_mesh_csit,meshName,pflName,locName); @@ -984,7 +1001,7 @@ void MEDFileFieldPerMesh::finishLoading(med_idt fid) throw(INTERP_KERNEL::Except _field_pm_pt.resize(_field_pm_pt.size()+1); _field_pm_pt.back()=MEDFileFieldPerMeshPerType::New(this,INTERP_KERNEL::NORM_ERROR); _mesh_name=MEDLoaderBase::buildStringFromFortran(meshName,MED_NAME_SIZE+1); - _field_pm_pt.back()->finishLoading(fid,ON_NODES); + _field_pm_pt.back()->finishLoading(fid,ON_NODES,ft); } } @@ -1913,9 +1930,9 @@ std::vector MEDFileField1TSWithoutDAS::CheckSBTMesh(const MEDCouplingMesh * return code; } -MEDFileField1TSWithoutDAS *MEDFileField1TSWithoutDAS::New(const char *fieldName, int csit, int iteration, int order, const std::vector& infos) +MEDFileField1TSWithoutDAS *MEDFileField1TSWithoutDAS::New(const char *fieldName, int csit, int fieldtype, int iteration, int order, const std::vector& infos) { - return new MEDFileField1TSWithoutDAS(fieldName,csit,iteration,order,infos); + return new MEDFileField1TSWithoutDAS(fieldName,csit,fieldtype,iteration,order,infos); } void MEDFileField1TSWithoutDAS::copyTinyInfoFrom(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception) @@ -2022,7 +2039,7 @@ void MEDFileField1TSWithoutDAS::finishLoading(med_idt fid) throw(INTERP_KERNEL:: for(int i=0;ifinishLoading(fid); + _field_per_mesh[i]->finishLoading(fid,_field_type); } std::vector MEDFileField1TSWithoutDAS::getPflsReallyUsed2() const @@ -2255,12 +2272,12 @@ DataArrayDouble *MEDFileField1TSWithoutDAS::getUndergroundDataArrayExt(std::vect return _field_per_mesh[0]->getUndergroundDataArrayExt(entries); } -MEDFileField1TSWithoutDAS::MEDFileField1TSWithoutDAS(const char *fieldName, int csit, int iteration, int order, - const std::vector& infos):_name(fieldName),_infos(infos),_csit(csit),_iteration(iteration),_order(order) +MEDFileField1TSWithoutDAS::MEDFileField1TSWithoutDAS(const char *fieldName, int csit, int fieldtype, int iteration, int order, + const std::vector& infos):_name(fieldName),_infos(infos),_csit(csit),_field_type(fieldtype),_iteration(iteration),_order(order) { } -MEDFileField1TSWithoutDAS::MEDFileField1TSWithoutDAS() +MEDFileField1TSWithoutDAS::MEDFileField1TSWithoutDAS():_csit(-1),_field_type(-1) { } @@ -2339,7 +2356,7 @@ void MEDFileField1TS::write(const char *fileName, int mode) const throw(INTERP_K } MEDFileField1TS::MEDFileField1TS(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception) -try:MEDFileField1TSWithoutDAS(fieldName,-1,iteration,order,std::vector()),MEDFieldFieldGlobsReal(fileName) +try:MEDFileField1TSWithoutDAS(fieldName,-1,-1,iteration,order,std::vector()),MEDFieldFieldGlobsReal(fileName) { MEDFileUtilities::CheckFileForRead(fileName); MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); @@ -2388,6 +2405,7 @@ try:MEDFileField1TSWithoutDAS(fieldName,-1,iteration,order,std::vector(numdt,numit); @@ -2510,21 +2528,21 @@ void MEDFileField1TS::setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileField1TSWithoutDAS::setFieldProfile(field,mesh,meshDimRelToMax,profile,*this); } -MEDFileFieldMultiTSWithoutDAS *MEDFileFieldMultiTSWithoutDAS::New(med_idt fid, const char *fieldName, int id, const std::vector& infos, int nbOfStep) throw(INTERP_KERNEL::Exception) +MEDFileFieldMultiTSWithoutDAS *MEDFileFieldMultiTSWithoutDAS::New(med_idt fid, const char *fieldName, int id, int ft, const std::vector& infos, int nbOfStep) throw(INTERP_KERNEL::Exception) { - return new MEDFileFieldMultiTSWithoutDAS(fid,fieldName,id,infos,nbOfStep); + return new MEDFileFieldMultiTSWithoutDAS(fid,fieldName,id,ft,infos,nbOfStep); } -MEDFileFieldMultiTSWithoutDAS::MEDFileFieldMultiTSWithoutDAS() +MEDFileFieldMultiTSWithoutDAS::MEDFileFieldMultiTSWithoutDAS():_field_type(-1) { } -MEDFileFieldMultiTSWithoutDAS::MEDFileFieldMultiTSWithoutDAS(const char *fieldName):_name(fieldName) +MEDFileFieldMultiTSWithoutDAS::MEDFileFieldMultiTSWithoutDAS(const char *fieldName):_name(fieldName),_field_type(-1) { } -MEDFileFieldMultiTSWithoutDAS::MEDFileFieldMultiTSWithoutDAS(med_idt fid, const char *fieldName, int id, const std::vector& infos, int nbOfStep) throw(INTERP_KERNEL::Exception) -try:_name(fieldName),_infos(infos) +MEDFileFieldMultiTSWithoutDAS::MEDFileFieldMultiTSWithoutDAS(med_idt fid, const char *fieldName, int id, int ft, const std::vector& infos, int nbOfStep) throw(INTERP_KERNEL::Exception) +try:_name(fieldName),_infos(infos),_field_type(ft) { finishLoading(fid,nbOfStep); } @@ -2606,7 +2624,7 @@ void MEDFileFieldMultiTSWithoutDAS::finishLoading(med_idt fid, int nbPdt) throw( med_int meshIt=0,meshOrder=0; med_float dt=0.0; MEDfieldComputingStepMeshInfo(fid,_name.c_str(),i+1,&numdt,&numo,&dt,&meshIt,&meshOrder); - _time_steps[i]=MEDFileField1TSWithoutDAS::New(_name.c_str(),i+1,numdt,numo,_infos); + _time_steps[i]=MEDFileField1TSWithoutDAS::New(_name.c_str(),i+1,_field_type,numdt,numo,_infos); _time_steps[i]->finishLoading(fid); } } @@ -2936,6 +2954,7 @@ try:MEDFileFieldMultiTSWithoutDAS(fieldName),MEDFieldFieldGlobsReal(fileName) if(found) { nbstep2=nbOfStep; + _field_type=_field_type=MEDFileUtilities::TraduceFieldType(typcha); _infos.resize(ncomp); for(int j=0;j infos(ncomp); for(int j=0;j,std::pair > >& entries, double *vals) const; static int ConvertType(TypeOfField type, int locId) throw(INTERP_KERNEL::Exception); private: - MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, med_idt fid, TypeOfField type, int profileIt) throw(INTERP_KERNEL::Exception); + MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, med_idt fid, TypeOfField type, int profileIt, int ft) throw(INTERP_KERNEL::Exception); MEDFileFieldPerMeshPerTypePerDisc(MEDFileFieldPerMeshPerType *fath, TypeOfField type, int profileIt); private: TypeOfField _type; @@ -142,7 +142,7 @@ namespace ParaMEDMEM void assignNodeFieldNoProfile(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception); void assignNodeFieldProfile(const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception); const MEDFileFieldPerMesh *getFather() const; - void finishLoading(med_idt fid, TypeOfField type) throw(INTERP_KERNEL::Exception); + void finishLoading(med_idt fid, TypeOfField type, int ft) throw(INTERP_KERNEL::Exception); void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); void getDimension(int& dim) const; void fillTypesOfFieldAvailable(std::set& types) const throw(INTERP_KERNEL::Exception); @@ -185,7 +185,7 @@ namespace ParaMEDMEM void assignFieldNoProfileNoRenum(const std::vector& code, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception); void assignNodeFieldNoProfile(const MEDCouplingFieldDouble *field, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception); void assignNodeFieldProfile(const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, MEDFieldFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception); - void finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception); + void finishLoading(med_idt fid, int ft) throw(INTERP_KERNEL::Exception); void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); void fillTypesOfFieldAvailable(std::set& types) const throw(INTERP_KERNEL::Exception); std::vector< std::vector > getFieldSplitedByType(std::vector& types, std::vector< std::vector >& typesF, std::vector< std::vector >& pfls, std::vector< std::vector >& locs) const throw(INTERP_KERNEL::Exception); @@ -328,7 +328,7 @@ namespace ParaMEDMEM const std::vector& getInfo() const { return _infos; } std::vector& getInfo() { return _infos; } // - static MEDFileField1TSWithoutDAS *New(const char *fieldName, int csit, int iteration, int order, const std::vector& infos); + static MEDFileField1TSWithoutDAS *New(const char *fieldName, int csit, int fieldtype, int iteration, int order, const std::vector& infos); void finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception); virtual void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); std::vector getPflsReallyUsed2() const; @@ -351,7 +351,7 @@ namespace ParaMEDMEM protected: int addNewEntryIfNecessary(const MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception); int getMeshIdFromMeshName(const char *mName) const throw(INTERP_KERNEL::Exception); - MEDFileField1TSWithoutDAS(const char *fieldName, int csit, int iteration, int order, const std::vector& infos); + MEDFileField1TSWithoutDAS(const char *fieldName, int csit, int fieldtype, int iteration, int order, const std::vector& infos); public: MEDFileField1TSWithoutDAS(); protected: @@ -359,7 +359,10 @@ namespace ParaMEDMEM std::string _dt_unit; std::vector _infos; std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > > _field_per_mesh; - int _csit; + //! only useable on reading + mutable int _csit; + //! only useable on reading. 0 is for float, 1 for int32, 2 for int64 + mutable int _field_type; int _iteration; int _order; double _dt; @@ -394,7 +397,7 @@ namespace ParaMEDMEM class MEDLOADER_EXPORT MEDFileFieldMultiTSWithoutDAS : public RefCountObject, public MEDFileWritable { public: - static MEDFileFieldMultiTSWithoutDAS *New(med_idt fid, const char *fieldName, int id, const std::vector& infos, int nbOfStep) throw(INTERP_KERNEL::Exception); + static MEDFileFieldMultiTSWithoutDAS *New(med_idt fid, const char *fieldName, int id, int ft, const std::vector& infos, int nbOfStep) throw(INTERP_KERNEL::Exception); int getNumberOfTS() const; std::vector< std::pair > getIterations() const; std::vector< std::vector > getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception); @@ -415,13 +418,15 @@ namespace ParaMEDMEM std::string getDtUnit() const throw(INTERP_KERNEL::Exception); MEDFileFieldMultiTSWithoutDAS(); MEDFileFieldMultiTSWithoutDAS(const char *fieldName); - MEDFileFieldMultiTSWithoutDAS(med_idt fid, const char *fieldName, int id, const std::vector& infos, int nbOfStep) throw(INTERP_KERNEL::Exception); + MEDFileFieldMultiTSWithoutDAS(med_idt fid, const char *fieldName, int id, int ft, const std::vector& infos, int nbOfStep) throw(INTERP_KERNEL::Exception); void finishLoading(med_idt fid, int nbPdt) throw(INTERP_KERNEL::Exception); void copyTinyInfoFrom(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception); void checkCoherencyOfTinyInfo(const MEDCouplingFieldDouble *field) const throw(INTERP_KERNEL::Exception); protected: std::string _name; std::vector _infos; + //! only useable on reading. 0 is for float, 1 for int32, 2 for int64 + mutable int _field_type; std::vector< MEDCouplingAutoRefCountObjectPtr > _time_steps; }; diff --git a/src/MEDLoader/MEDFileUtilities.cxx b/src/MEDLoader/MEDFileUtilities.cxx index d7b785f63..49784d087 100644 --- a/src/MEDLoader/MEDFileUtilities.cxx +++ b/src/MEDLoader/MEDFileUtilities.cxx @@ -37,6 +37,21 @@ med_access_mode MEDFileUtilities::TraduceWriteMode(int medloaderwritemode) throw } } +int MEDFileUtilities::TraduceFieldType(med_field_type ft) throw(INTERP_KERNEL::Exception) +{ + switch(ft) + { + case MED_FLOAT64: + return 0; + case MED_INT32: + return 1; + case MED_INT64: + return 2; + default: + throw INTERP_KERNEL::Exception("Non supported field type ! Should be FLOAT64, INT32 or INT64 !"); + } +} + void MEDFileUtilities::CheckMEDCode(int code, med_idt fid, const char *msg) throw(INTERP_KERNEL::Exception) { if(code<0) diff --git a/src/MEDLoader/MEDFileUtilities.hxx b/src/MEDLoader/MEDFileUtilities.hxx index 435fa833a..0e636b592 100644 --- a/src/MEDLoader/MEDFileUtilities.hxx +++ b/src/MEDLoader/MEDFileUtilities.hxx @@ -31,6 +31,7 @@ extern "C" namespace MEDFileUtilities { med_access_mode TraduceWriteMode(int medloaderwritemode) throw(INTERP_KERNEL::Exception); + int TraduceFieldType(med_field_type ft) throw(INTERP_KERNEL::Exception); void CheckMEDCode(int code, med_idt fid, const char *msg) throw(INTERP_KERNEL::Exception); void CheckFileForRead(const char *fileName) throw(INTERP_KERNEL::Exception);