From: ageay Date: Fri, 17 Feb 2012 07:25:54 +0000 (+0000) Subject: All classes potentially subwriters have a write* method having fid in input. X-Git-Tag: V6_main_FINAL~849 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7c986c8ea5891034b5a7f6cbec10a64b4d9ab716;p=tools%2Fmedcoupling.git All classes potentially subwriters have a write* method having fid in input. --- diff --git a/src/MEDLoader/MEDFileData.cxx b/src/MEDLoader/MEDFileData.cxx index 67ad6a0a3..b4fde8a2a 100644 --- a/src/MEDLoader/MEDFileData.cxx +++ b/src/MEDLoader/MEDFileData.cxx @@ -113,11 +113,12 @@ catch(INTERP_KERNEL::Exception& e) void MEDFileData::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception) { + med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod); const MEDFileMeshes *ms=_meshes; if(ms) - ms->write(fileName,mode); - int mode2=mode==2?0:mode; + ms->write(fid); const MEDFileFields *fs=_fields; if(fs) - fs->write(fileName,mode2); + fs->writeLL(fid); } diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index 773be4fec..804e6fd30 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -2311,10 +2311,8 @@ MEDFileField1TS *MEDFileField1TS::New() return new MEDFileField1TS; } -void MEDFileField1TS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception) +void MEDFileField1TS::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception) { - med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode); - MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod); int nbComp=_infos.size(); INTERP_KERNEL::AutoPtr comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE); INTERP_KERNEL::AutoPtr unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE); @@ -2330,6 +2328,13 @@ void MEDFileField1TS::write(const char *fileName, int mode) const throw(INTERP_K throw INTERP_KERNEL::Exception("MEDFileField1TS::write : MED file does not accept field with empty name !"); MEDfieldCr(fid,_name.c_str(),MED_FLOAT64,nbComp,comp,unit,getDtUnit().c_str(),getMeshName().c_str()); writeGlobals(fid,*this); + MEDFileField1TSWithoutDAS::writeLL(fid); +} + +void MEDFileField1TS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception) +{ + med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod); writeLL(fid); } @@ -2798,11 +2803,16 @@ std::string MEDFileFieldMultiTS::simpleRepr() const return oss.str(); } +void MEDFileFieldMultiTS::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception) +{ + writeGlobals(fid,*this); + MEDFileFieldMultiTSWithoutDAS::writeLL(fid); +} + void MEDFileFieldMultiTS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception) { med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode); MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod); - writeGlobals(fid,*this); writeLL(fid); } @@ -3047,11 +3057,9 @@ catch(INTERP_KERNEL::Exception& e) throw e; } -void MEDFileFields::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception) +void MEDFileFields::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception) { int i=0; - med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode); - MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod); writeGlobals(fid,*this); for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++) { @@ -3066,6 +3074,13 @@ void MEDFileFields::write(const char *fileName, int mode) const throw(INTERP_KER } } +void MEDFileFields::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception) +{ + med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod); + writeLL(fid); +} + std::vector MEDFileFields::getPflsReallyUsed() const { std::vector ret; diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index 5d3f44d4f..7c8b396de 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -330,7 +330,7 @@ namespace ParaMEDMEM // static MEDFileField1TSWithoutDAS *New(const char *fieldName, int csit, int iteration, int order, const std::vector& infos); void finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception); - void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); + virtual void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); std::vector getPflsReallyUsed2() const; std::vector getLocsReallyUsed2() const; static void CheckMeshDimRel(int meshDimRelToMax) throw(INTERP_KERNEL::Exception); @@ -384,6 +384,7 @@ namespace ParaMEDMEM void setFieldNoProfileSBT(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception); void setFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception); private: + void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); std::vector getPflsReallyUsed() const; std::vector getLocsReallyUsed() const; MEDFileField1TS(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception); @@ -398,7 +399,7 @@ namespace ParaMEDMEM std::vector< std::pair > getIterations() const; std::vector< std::vector > getTypesOfFieldAvailable() const throw(INTERP_KERNEL::Exception); std::vector< std::vector > getFieldSplitedByType(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); - void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); + virtual void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); std::string getName() const; std::vector< std::pair > getTimeSteps(std::vector& ret1) const throw(INTERP_KERNEL::Exception); std::string getMeshName() const throw(INTERP_KERNEL::Exception); @@ -435,6 +436,7 @@ namespace ParaMEDMEM static MEDFileFieldMultiTS *New(const MEDFileFieldMultiTSWithoutDAS& other); std::string simpleRepr() const; void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); + void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, int renumPol=0) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldAtTopLevel(TypeOfField type, int iteration, int order, int renumPol=0) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, const MEDFileMesh *mesh, int renumPol=0) const throw(INTERP_KERNEL::Exception); @@ -462,6 +464,7 @@ namespace ParaMEDMEM static MEDFileFields *New(); static MEDFileFields *New(const char *fileName) throw(INTERP_KERNEL::Exception); void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); + void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); int getNumberOfFields() const; std::vector getFieldsNames() const throw(INTERP_KERNEL::Exception); std::string simpleRepr() const; diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index 9653ab1d8..bc19d8f8a 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -107,6 +107,24 @@ MEDFileMesh *MEDFileMesh::New(const char *fileName, const char *mName, int dt, i } } +void MEDFileMesh::write(med_idt fid) const throw(INTERP_KERNEL::Exception) +{ + if(!existsFamily(0)) + const_cast(this)->addFamily(DFT_FAM_NAME,0); + if(_name.empty()) + throw INTERP_KERNEL::Exception("MEDFileMesh : name is empty. MED file ask for a NON EMPTY name !"); + writeLL(fid); +} + +void MEDFileMesh::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception) +{ + med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod); + std::ostringstream oss; oss << "MEDFileMesh : error on attempt to write in file : \"" << fileName << "\""; + MEDFileUtilities::CheckMEDCode(fid,fid,oss.str().c_str()); + write(fid); +} + bool MEDFileMesh::isEqual(const MEDFileMesh *other, double eps, std::string& what) const { if(_order!=other->_order) @@ -1005,16 +1023,8 @@ MEDFileUMesh::~MEDFileUMesh() { } -void MEDFileUMesh::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception) +void MEDFileUMesh::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception) { - if(_name.empty()) - throw INTERP_KERNEL::Exception("MEDFileUMesh : name is empty. MED file ask for a NON EMPTY name !"); - if(!existsFamily(0)) - (const_cast(this))->addFamily(DFT_FAM_NAME,0); - med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode); - MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod); - std::ostringstream oss; oss << "MEDFileUMesh : error on attempt to write in file : \"" << fileName << "\""; - MEDFileUtilities::CheckMEDCode(fid,fid,oss.str().c_str()); const DataArrayDouble *coo=_coords; INTERP_KERNEL::AutoPtr maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); INTERP_KERNEL::AutoPtr desc=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE); @@ -2002,16 +2012,8 @@ void MEDFileCMesh::setMesh(MEDCouplingCMesh *m) throw(INTERP_KERNEL::Exception) _cmesh=m; } -void MEDFileCMesh::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception) +void MEDFileCMesh::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception) { - if(_name.empty()) - throw INTERP_KERNEL::Exception("MEDFileCMesh : name is empty. MED file ask for a NON EMPTY name !"); - if(!existsFamily(0)) - (const_cast(this))->addFamily(DFT_FAM_NAME,0); - med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode); - MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod); - std::ostringstream oss; oss << "MEDFileCMesh : error on attempt to write in file : \"" << fileName << "\""; - MEDFileUtilities::CheckMEDCode(fid,fid,oss.str().c_str()); INTERP_KERNEL::AutoPtr maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); INTERP_KERNEL::AutoPtr desc=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE); INTERP_KERNEL::AutoPtr dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE); @@ -2251,15 +2253,24 @@ void MEDFileMeshMultiTS::setOneTimeStep(MEDFileMesh *mesh1TimeStep) throw(INTERP _mesh_one_ts[0]=mesh1TimeStep; } -void MEDFileMeshMultiTS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception) +void MEDFileMeshMultiTS::write(med_idt fid) const throw(INTERP_KERNEL::Exception) { for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_mesh_one_ts.begin();it!=_mesh_one_ts.end();it++) { (*it)->copyOptionsFrom(*this); - (*it)->write(fileName,mode); + (*it)->write(fid); } } +void MEDFileMeshMultiTS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception) +{ + med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod); + std::ostringstream oss; oss << "MEDFileMesh : error on attempt to write in file : \"" << fileName << "\""; + MEDFileUtilities::CheckMEDCode(fid,fid,oss.str().c_str()); + write(fid); +} + void MEDFileMeshMultiTS::loadFromFile(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception) {//for the moment to be improved _mesh_one_ts.resize(1); @@ -2312,20 +2323,26 @@ MEDFileMeshes *MEDFileMeshes::New(const char *fileName) throw(INTERP_KERNEL::Exc return new MEDFileMeshes(fileName); } -void MEDFileMeshes::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception) +void MEDFileMeshes::write(med_idt fid) const throw(INTERP_KERNEL::Exception) { checkCoherency(); - int i=0; - for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_meshes.begin();it!=_meshes.end();it++,i++) + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_meshes.begin();it!=_meshes.end();it++) { - int mode2=mode; - if(mode==2 && i>0) - mode2=0; (*it)->copyOptionsFrom(*this); - (*it)->write(fileName,mode2); + (*it)->write(fid); } } +void MEDFileMeshes::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception) +{ + med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode); + MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod); + std::ostringstream oss; oss << "MEDFileMesh : error on attempt to write in file : \"" << fileName << "\""; + MEDFileUtilities::CheckMEDCode(fid,fid,oss.str().c_str()); + checkCoherency(); + write(fid); +} + int MEDFileMeshes::getNumberOfMeshes() const throw(INTERP_KERNEL::Exception) { return _meshes.size(); diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index 62f0bf4ce..99bb2ba25 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -53,7 +53,8 @@ namespace ParaMEDMEM const char *getTimeUnit() const { return _dt_unit.c_str(); } virtual std::vector getNonEmptyLevels() const = 0; virtual std::vector getNonEmptyLevelsExt() const = 0; - virtual void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception) = 0; + virtual void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); + virtual void write(med_idt fid) const throw(INTERP_KERNEL::Exception); virtual int getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) = 0; virtual MEDCouplingMesh *getGenMeshAtLevel(int meshDimRelToMax, bool renum=false) const throw(INTERP_KERNEL::Exception) = 0; // @@ -62,7 +63,7 @@ namespace ParaMEDMEM bool existsFamily(int famId) const; bool existsFamily(const char *familyName) const; void setFamilyId(const char *familyName, int id); - void addFamily(const char *familyName, int id) throw(INTERP_KERNEL::Exception); + virtual void addFamily(const char *familyName, int id) throw(INTERP_KERNEL::Exception); void addGrpOnFamily(const char *grpName, const char *famName) throw(INTERP_KERNEL::Exception); void setFamilyInfo(const std::map& info); void setGroupInfo(const std::map >&info); @@ -108,6 +109,7 @@ namespace ParaMEDMEM virtual DataArrayInt *getNodeFamiliesArr(const std::vector& fams, bool renum=false) const throw(INTERP_KERNEL::Exception); protected: MEDFileMesh(); + virtual void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception) = 0; void dealWithTinyInfo(const MEDCouplingMesh *m) throw(INTERP_KERNEL::Exception); virtual void synchronizeTinyInfoOnLeaves() const = 0; void getFamilyRepr(std::ostream& oss) const; @@ -140,7 +142,6 @@ namespace ParaMEDMEM void clearNonDiscrAttributes() const; ~MEDFileUMesh(); // - void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); int getMeshDimension() const throw(INTERP_KERNEL::Exception); int getSpaceDimension() const throw(INTERP_KERNEL::Exception); std::string simpleRepr() const; @@ -187,6 +188,7 @@ namespace ParaMEDMEM void setGroupsOnSetMesh(int meshDimRelToMax, const std::vector& ms, bool renum) throw(INTERP_KERNEL::Exception); void optimizeFamilies() throw(INTERP_KERNEL::Exception); private: + void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); MEDFileUMesh(); MEDFileUMesh(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception); void loadUMeshFromFile(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception); @@ -220,7 +222,6 @@ namespace ParaMEDMEM const MEDCouplingCMesh *getMesh() const; MEDCouplingMesh *getGenMeshAtLevel(int meshDimRelToMax, bool renum=false) const throw(INTERP_KERNEL::Exception); void setMesh(MEDCouplingCMesh *m) throw(INTERP_KERNEL::Exception); - void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); int getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); DataArrayInt *getFamiliesArr(int meshDimRelToMaxExt, const std::vector& fams, bool renum=false) const throw(INTERP_KERNEL::Exception); void setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception); @@ -231,6 +232,7 @@ namespace ParaMEDMEM const DataArrayInt *getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); const DataArrayInt *getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); private: + void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); MEDFileCMesh(); void synchronizeTinyInfoOnLeaves() const; MEDFileCMesh(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception); @@ -254,6 +256,7 @@ namespace ParaMEDMEM static MEDFileMeshMultiTS *New(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception); const char *getName() const throw(INTERP_KERNEL::Exception); MEDFileMesh *getOneTimeStep() const throw(INTERP_KERNEL::Exception); + void write(med_idt fid) const throw(INTERP_KERNEL::Exception); void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); void setOneTimeStep(MEDFileMesh *mesh1TimeStep) throw(INTERP_KERNEL::Exception); private: @@ -273,6 +276,7 @@ namespace ParaMEDMEM std::string simpleRepr() const; void simpleReprWithoutHeader(std::ostream& oss) const; void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); + void write(med_idt fid) const throw(INTERP_KERNEL::Exception); int getNumberOfMeshes() const throw(INTERP_KERNEL::Exception); MEDFileMesh *getMeshAtPos(int i) const throw(INTERP_KERNEL::Exception); MEDFileMesh *getMeshWithName(const char *mname) const throw(INTERP_KERNEL::Exception);