]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
*** empty log message ***
authorageay <ageay>
Mon, 8 Feb 2010 08:40:38 +0000 (08:40 +0000)
committerageay <ageay>
Mon, 8 Feb 2010 08:40:38 +0000 (08:40 +0000)
13 files changed:
src/MEDCoupling/MEDCouplingUMesh.cxx
src/MEDCoupling/MEDCouplingUMesh.hxx
src/MEDCoupling/Test/MEDCouplingBasicsTest.cxx
src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx
src/MEDLoader/MEDLoader.cxx
src/MEDLoader/MEDLoader.hxx
src/MEDLoader/MEDLoaderBase.cxx [new file with mode: 0644]
src/MEDLoader/MEDLoaderBase.hxx [new file with mode: 0644]
src/MEDLoader/Makefile.am
src/MEDLoader/Swig/libMEDLoader_Swig.i
src/ParaMEDLoader/ParaMEDLoader.cxx
src/ParaMEDMEMTest/ParaMEDMEMTest_InterpKernelDEC.cxx
src/ParaMEDMEMTest/ParaMEDMEMTest_MEDLoader.cxx

index 5397203af3774ab3c85117c5a04184175e8149fd..330a15266f8b1fabe49df3a13b213ccfb0705390 100644 (file)
@@ -842,6 +842,36 @@ void MEDCouplingUMesh::checkButterflyCells(std::vector<int>& cells) const
     }
 }
 
+namespace ParaMEDMEMImpl
+{
+  class ConnReader
+  {
+  public:
+    ConnReader(const int *c, int val):_conn(c),_val(val) { }
+    bool operator() (const int& pos) { return _conn[pos]!=_val; }
+  private:
+    const int *_conn;
+    int _val;
+  };
+}
+
+bool MEDCouplingUMesh::checkConsecutiveCellTypes() const
+{
+  const int *conn=_nodal_connec->getConstPointer();
+  const int *connI=_nodal_connec_index->getConstPointer();
+  int nbOfCells=getNumberOfCells();
+  std::set<INTERP_KERNEL::NormalizedCellType> types;
+  for(const int *i=connI;i!=connI+nbOfCells;)
+    {
+      INTERP_KERNEL::NormalizedCellType curType=(INTERP_KERNEL::NormalizedCellType)conn[*i];
+      if(types.find(curType)!=types.end())
+            return false;
+      types.insert(curType);
+      i=std::find_if(i+1,connI+nbOfCells,ParaMEDMEMImpl::ConnReader(conn,(int)curType));
+    }
+  return true;
+}
+
 MEDCouplingMesh *MEDCouplingUMesh::mergeMyselfWith(const MEDCouplingMesh *other) const
 {
   if(other->getType()!=UNSTRUCTURED)
@@ -880,6 +910,7 @@ DataArrayDouble *MEDCouplingUMesh::getBarycenterAndOwner() const
 MEDCouplingUMesh *MEDCouplingUMesh::mergeUMeshes(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2)
 {
   MEDCouplingUMesh *ret=MEDCouplingUMesh::New();
+  ret->setName("merge");
   DataArrayDouble *pts=mergeNodesArray(mesh1,mesh2);
   ret->setCoords(pts);
   pts->decrRef();
index cc426d0ed5557da81a59c5aeb641e3cb9df9225f..7743d2e9991997a51aea6730850db5a9808e883f 100644 (file)
@@ -70,6 +70,7 @@ namespace ParaMEDMEM
     void giveElemsInBoundingBox(const double *bbox, double eps, std::vector<int>& elems);
     MEDCouplingFieldDouble *getMeasureField(bool isAbs) const;
     void checkButterflyCells(std::vector<int>& cells) const;
+    bool checkConsecutiveCellTypes() const;
     MEDCouplingMesh *mergeMyselfWith(const MEDCouplingMesh *other) const;
     DataArrayDouble *getBarycenterAndOwner() const;
     static MEDCouplingUMesh *mergeUMeshes(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2);
index d0a9b9a733bbbff6828145014dd01fab80786721..1951816c0554abfce7622abd9da6838d8afb906e 100644 (file)
@@ -1307,6 +1307,16 @@ void MEDCouplingBasicsTest::testMergeNodesOnField()
   targetMesh->decrRef();
 }
 
+void MEDCouplingBasicsTest::testCheckConsecutiveCellTypes()
+{
+  MEDCouplingUMesh *sourceMesh=build2DSourceMesh_1();
+  MEDCouplingUMesh *targetMesh=build2DTargetMesh_1();
+  CPPUNIT_ASSERT(sourceMesh->checkConsecutiveCellTypes());
+  CPPUNIT_ASSERT(!targetMesh->checkConsecutiveCellTypes());
+  targetMesh->decrRef();
+  sourceMesh->decrRef();
+}
+
 void MEDCouplingBasicsTest::test2DInterpP0P0_1()
 {
   MEDCouplingUMesh *sourceMesh=build2DSourceMesh_1();
index 0502c198f974430ad5319d7646224987dfcf015b..ef9558d4bc55af3ff4bd18f0adf94bce704b36a9 100644 (file)
@@ -58,6 +58,7 @@ namespace ParaMEDMEM
     CPPUNIT_TEST( testApplyFunc );
     CPPUNIT_TEST( testOperationsOnFields );
     CPPUNIT_TEST( testMergeNodesOnField );
+    CPPUNIT_TEST( testCheckConsecutiveCellTypes );
     CPPUNIT_TEST( test2DInterpP0P0_1 );
     CPPUNIT_TEST( test2DInterpP0P0PL_1 );
     CPPUNIT_TEST( test2DInterpP0P0PL_2 );
@@ -135,6 +136,7 @@ namespace ParaMEDMEM
     void testApplyFunc();
     void testOperationsOnFields();
     void testMergeNodesOnField();
+    void testCheckConsecutiveCellTypes();
     void test2DInterpP0P0_1();
     void test2DInterpP0P0PL_1();
     void test2DInterpP0P0PL_2();
index 6d09a3e751f868b0a56947137df77cbae1844df5..5d3be43c3a0ce2e830ec0bb515f859557eea4db7 100644 (file)
@@ -17,6 +17,7 @@
 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 #include "MEDLoader.hxx"
+#include "MEDLoaderBase.hxx"
 #include "CellModel.hxx"
 #include "MEDCouplingUMesh.hxx"
 #include "MEDCouplingMemArray.hxx"
@@ -73,6 +74,40 @@ INTERP_KERNEL::NormalizedCellType typmai2[MED_NBR_GEOMETRIE_MAILLE+2] = { INTERP
                                                                           INTERP_KERNEL::NORM_POLYGON,
                                                                           INTERP_KERNEL::NORM_POLYHED };
 
+med_geometrie_element typmai3[32] = { MED_POINT1,//0
+                                      MED_SEG2,//1
+                                      MED_SEG3,//2
+                                      MED_TRIA3,//3
+                                      MED_QUAD4,//4
+                                      MED_POLYGONE,//5
+                                      MED_TRIA6,//6
+                                      MED_NONE,//7
+                                      MED_QUAD8,//8
+                                      MED_NONE,//9
+                                      MED_NONE,//10
+                                      MED_NONE,//11
+                                      MED_NONE,//12
+                                      MED_NONE,//13
+                                      MED_TETRA4,//14
+                                      MED_PYRA5,//15
+                                      MED_PENTA6,//16
+                                      MED_NONE,//17
+                                      MED_HEXA8,//18
+                                      MED_NONE,//19
+                                      MED_TETRA10,//20
+                                      MED_NONE,//21
+                                      MED_NONE,//22
+                                      MED_PYRA13,//23
+                                      MED_NONE,//24
+                                      MED_PENTA15,//25
+                                      MED_NONE,//26
+                                      MED_NONE,//27
+                                      MED_NONE,//28
+                                      MED_NONE,//29
+                                      MED_HEXA20,//30
+                                      MED_POLYEDRE//31
+};
+
 using namespace ParaMEDMEM;
 
 namespace MEDLoaderNS
@@ -85,6 +120,16 @@ namespace MEDLoaderNS
   private:
     double *_ptr;
   };
+  class ConnReaderML
+  {
+  public:
+    ConnReaderML(const int *c, int val):_conn(c),_val(val) { }
+    bool operator() (const int& pos) { return _conn[pos]!=_val; }
+  private:
+    const int *_conn;
+    int _val;
+  };
   
   std::string buildStringFromFortran(const char *expr, int lgth);
   std::vector<std::string> getMeshNamesFid(med_idt fid);
@@ -110,6 +155,10 @@ namespace MEDLoaderNS
   int buildMEDSubConnectivityOfOneTypeStaticTypes(DataArrayInt *conn, DataArrayInt *connIndex, INTERP_KERNEL::NormalizedCellType type, std::vector<int>& conn4MEDFile);
   ParaMEDMEM::MEDCouplingFieldDouble *readFieldDoubleLev1(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order,
                                                           ParaMEDMEM::TypeOfField typeOfOutField);
+  void appendFieldDirectly(const char *fileName, ParaMEDMEM::MEDCouplingFieldDouble *f);
+  void prepareCellFieldDoubleForWriting(const ParaMEDMEM::MEDCouplingFieldDouble *f, std::list<MEDLoader::MEDFieldDoublePerCellType>& split);
+  void writeUMeshDirectly(const char *fileName, ParaMEDMEM::MEDCouplingUMesh *mesh, bool forceFromScratch);
+  void writeFieldAndMeshDirectly(const char *fileName, ParaMEDMEM::MEDCouplingFieldDouble *f, bool forceFromScratch);
 }
 
 const char WHITE_SPACES[]=" \n";
@@ -144,7 +193,7 @@ void MEDLoader::MEDConnOfOneElemType::releaseArray()
   delete [] _global;
 }
 
-MEDLoader::MEDFieldDoublePerCellType::MEDFieldDoublePerCellType(INTERP_KERNEL::NormalizedCellType type, double *values, int ncomp, int nval):_nval(nval),_ncomp(ncomp),_values(values),_type(type)
+MEDLoader::MEDFieldDoublePerCellType::MEDFieldDoublePerCellType(INTERP_KERNEL::NormalizedCellType type, double *values, int ncomp, int ntuple):_ntuple(ntuple),_ncomp(ncomp),_values(values),_type(type)
 {
 }
 
@@ -460,6 +509,23 @@ void MEDLoaderNS::readFieldDoubleDataInMedFile(const char *fileName, const char
                 {
                   int nval=MEDnVal(fid,(char *)fieldName,tabEnt[typeOfOutField],tabType[typeOfOutField][j],iteration,order,(char *)meshName,MED_COMPACT);
                   double *valr=new double[ncomp*nval];
+                  //
+                  med_int ngauss=0;
+                  med_int numdt=0,numo=0,nbrefmaa;
+                  char dt_unit[MED_TAILLE_PNOM+1]="";
+                  char maa_ass[MED_TAILLE_NOM+1]="";
+                  med_float dt=0.0;
+                  med_booleen local;
+                  med_int nbPdt=MEDnPasdetemps(fid,(char *)fieldName,MED_MAILLE,tabType[typeOfOutField][j]);
+                  bool found2=false;
+                  for(int k=0;k<nbPdt && !found2;k++)
+                    {
+                      MEDpasdetempsInfo(fid,(char *)fieldName,MED_MAILLE,tabType[typeOfOutField][j],k+1,&ngauss,
+                                        &numdt,&numo,dt_unit,&dt,maa_ass,&local,&nbrefmaa);
+                      found2=(numdt==iteration && numo==order);
+                      if(found2)
+                        time=dt;
+                    }
                   MEDchampLire(fid,(char *)meshName,(char *)fieldName,(unsigned char*)valr,MED_FULL_INTERLACE,MED_ALL,locname,
                                pflname,MED_COMPACT,tabEnt[typeOfOutField],tabType[typeOfOutField][j],iteration,order);
                   field.push_back(MEDLoader::MEDFieldDoublePerCellType(typmai2[j],valr,ncomp,nval));
@@ -1052,9 +1118,9 @@ ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldDoubleNode(const char *f
   return MEDLoaderNS::readFieldDoubleLev1(fileName,meshName,meshDimRelToMax,fieldName,iteration,order,ON_NODES);
 }
 
-void MEDLoader::WriteUMesh(const char *fileName, ParaMEDMEM::MEDCouplingUMesh *mesh)
+void MEDLoaderNS::writeUMeshDirectly(const char *fileName, ParaMEDMEM::MEDCouplingUMesh *mesh, bool forceFromScratch)
 {
-  med_idt fid=MEDouvrir((char *)fileName,MED_CREATION);
+  med_idt fid=MEDouvrir((char *)fileName,forceFromScratch?MED_CREATION:MED_LECTURE_ECRITURE);
   std::string meshName(mesh->getName());
   if(meshName=="")
     {
@@ -1104,6 +1170,169 @@ void MEDLoader::WriteUMesh(const char *fileName, ParaMEDMEM::MEDCouplingUMesh *m
   MEDfermer(fid);
 }
 
-void MEDLoader::WriteField(const char *fileName, ParaMEDMEM::MEDCouplingFieldDouble *f)
+void MEDLoaderNS::appendFieldDirectly(const char *fileName, ParaMEDMEM::MEDCouplingFieldDouble *f)
+{
+  med_idt fid=MEDouvrir((char *)fileName,MED_LECTURE_ECRITURE);
+  int nbComp=f->getNumberOfComponents();
+  char *comp=new char[nbComp*MED_TAILLE_PNOM+1];
+  std::fill(comp,comp+nbComp*MED_TAILLE_PNOM,' ');
+  comp[nbComp*MED_TAILLE_PNOM]='\0';
+  char *unit=new char[nbComp*MED_TAILLE_PNOM+1];
+  std::fill(unit,unit+nbComp*MED_TAILLE_PNOM,' ');
+  unit[nbComp*MED_TAILLE_PNOM]='\0';
+  MEDchampCr(fid,(char *)f->getName(),MED_FLOAT64,comp,unit,nbComp);
+  med_int numdt,numo;
+  med_float dt;
+  ParaMEDMEM::TypeOfTimeDiscretization td=f->getTimeDiscretization();
+  if(td==ParaMEDMEM::NO_TIME)
+    {
+      numdt=MED_NOPDT; numo=MED_NONOR; dt=0.0;
+    }
+  else if(td==ParaMEDMEM::ONE_TIME)
+    {
+      int tmp1,tmp2;
+      double tmp0=f->getTime(tmp1,tmp2);
+      numdt=(med_int)tmp1; numo=(med_int)tmp2;
+      dt=(med_float)tmp0;
+    }
+  const double *pt=f->getArray()->getConstPointer();
+  switch(f->getTypeOfField())
+    {
+    case ParaMEDMEM::ON_CELLS:
+      {
+        std::list<MEDLoader::MEDFieldDoublePerCellType> split;
+        prepareCellFieldDoubleForWriting(f,split);
+        for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=split.begin();iter!=split.end();iter++)
+          {
+            char nommaa[MED_TAILLE_NOM+1];
+            std::fill(nommaa,nommaa+MED_TAILLE_NOM,' '); nommaa[MED_TAILLE_NOM]='\0';
+            strcpy(nommaa,f->getMesh()->getName());
+            MEDchampEcr(fid,(char *)nommaa,(char *)f->getName(),(unsigned char*)pt,MED_FULL_INTERLACE,(*iter).getNbOfTuple(),
+                        (char *)MED_NOGAUSS,MED_ALL,(char *)MED_NOPFL,MED_NO_PFLMOD,MED_MAILLE,
+                        typmai3[(int)(*iter).getType()],numdt,(char *)"",dt,numo);
+            pt+=(*iter).getNbOfTuple()*nbComp;
+          }
+        break;
+      }
+    case ParaMEDMEM::ON_NODES:
+      {
+        int nbOfTuples=f->getArray()->getNumberOfTuples();
+        MEDchampEcr(fid,(char *)f->getMesh()->getName(),(char *)f->getName(),(unsigned char*)pt,MED_FULL_INTERLACE,nbOfTuples,(char *)MED_NOGAUSS,
+                    MED_ALL,(char *)MED_NOPFL,MED_NO_PFLMOD,MED_NOEUD,MED_NONE,numdt,(char *)"",dt,numo);
+        break;
+      }
+    default:
+      throw INTERP_KERNEL::Exception("Not managed this type of FIELD !");
+    }
+  delete [] comp;
+  delete [] unit;
+  MEDfermer(fid);
+}
+
+void MEDLoaderNS::prepareCellFieldDoubleForWriting(const ParaMEDMEM::MEDCouplingFieldDouble *f, std::list<MEDLoader::MEDFieldDoublePerCellType>& split)
+{
+  int nbComp=f->getNumberOfComponents();
+  const MEDCouplingMesh *mesh=f->getMesh();
+  const MEDCouplingUMesh *meshC=dynamic_cast<const MEDCouplingUMesh *>(mesh);
+  if(!meshC)
+    throw INTERP_KERNEL::Exception("Not implemented yet for not unstructured mesh !");
+  if(!meshC->checkConsecutiveCellTypes())
+    throw INTERP_KERNEL::Exception("Unstructuded mesh has not consecutive cell types !");
+  const int *connI=meshC->getNodalConnectivityIndex()->getConstPointer();
+  const int *conn=meshC->getNodalConnectivity()->getConstPointer();
+  int nbOfCells=meshC->getNumberOfCells();
+  INTERP_KERNEL::NormalizedCellType curType;
+  for(const int *pt=connI;pt!=connI+nbOfCells;)
+    {
+      curType=(INTERP_KERNEL::NormalizedCellType)conn[*pt];
+      const int *pt2=std::find_if(pt+1,connI+nbOfCells,ConnReaderML(conn,(int)curType));
+      split.push_back(MEDLoader::MEDFieldDoublePerCellType(curType,0,nbComp,pt2-pt));
+      pt=pt2;
+    }
+}
+
+void MEDLoaderNS::writeFieldAndMeshDirectly(const char *fileName, ParaMEDMEM::MEDCouplingFieldDouble *f, bool forceFromScratch)
+{
+  MEDCouplingUMesh *mesh=dynamic_cast<MEDCouplingUMesh *>((MEDCouplingMesh *)f->getMesh());
+  writeUMeshDirectly(fileName,mesh,forceFromScratch);
+  appendFieldDirectly(fileName,f);
+}
+
+void MEDLoader::WriteUMesh(const char *fileName, ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch)
 {
+  int status=MEDLoaderBase::getStatusOfFile(fileName);
+  if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
+    {
+      std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
+      throw INTERP_KERNEL::Exception(oss.str().c_str());
+    }
+  if(writeFromScratch)
+    {
+      MEDLoaderNS::writeUMeshDirectly(fileName,mesh,true);
+      return ;
+    }
+  if(status==MEDLoaderBase::NOT_EXIST)
+    {
+      MEDLoaderNS::writeUMeshDirectly(fileName,mesh,true);
+      return;
+    }
+  else
+    {
+      std::vector<std::string> meshNames=GetMeshNames(fileName);
+      std::string fileNameCpp(mesh->getName());
+      if(std::find(meshNames.begin(),meshNames.end(),fileNameCpp)==meshNames.end())
+        MEDLoaderNS::writeUMeshDirectly(fileName,mesh,false);
+      else
+        {
+          std::ostringstream oss; oss << "File \'" << fileName << "\' already exists and has already a mesh called \"";
+          oss << fileNameCpp << "\" !";
+          throw INTERP_KERNEL::Exception(oss.str().c_str());
+        }
+    }
+}
+
+void MEDLoader::WriteField(const char *fileName, ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch)
+{
+  f->checkCoherency();
+  int status=MEDLoaderBase::getStatusOfFile(fileName);
+  if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
+    {
+      std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
+      throw INTERP_KERNEL::Exception(oss.str().c_str());
+    }
+  if(writeFromScratch)
+    {
+      MEDLoaderNS::writeFieldAndMeshDirectly(fileName,f,true);
+     return ;
+    }
+  if(status==MEDLoaderBase::NOT_EXIST)
+    {
+     MEDLoaderNS::writeFieldAndMeshDirectly(fileName,f,true);
+     return ;
+    }
+  else
+    {
+      std::vector<std::string> meshNames=GetMeshNames(fileName);
+      std::string fileNameCpp(f->getMesh()->getName());
+      if(std::find(meshNames.begin(),meshNames.end(),fileNameCpp)==meshNames.end())
+        MEDLoaderNS::writeFieldAndMeshDirectly(fileName,f,false);
+      else
+        {
+          std::ostringstream oss; oss << "File \'" << fileName << "\' already exists and has already a mesh called \"";
+          oss << fileNameCpp << "\" !";
+          throw INTERP_KERNEL::Exception(oss.str().c_str()); 
+        }
+    }
+}
+
+void MEDLoader::WriteFieldUsingAlreadyWrittenMesh(const char *fileName, ParaMEDMEM::MEDCouplingFieldDouble *f)
+{
+  f->checkCoherency();
+  int status=MEDLoaderBase::getStatusOfFile(fileName);
+  if(status!=MEDLoaderBase::EXIST_RW)
+    {
+      std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions or not exists !";
+      throw INTERP_KERNEL::Exception(oss.str().c_str());
+    }
+  MEDLoaderNS::appendFieldDirectly(fileName,f);
 }
index 71065e2174f6ea39a700a542b5b501b4bd89a16b..b79779266c8ef217a5230e05bacc475a21a2fe1f 100644 (file)
@@ -60,15 +60,15 @@ public:
   class MEDFieldDoublePerCellType
   {
   public:
-    MEDFieldDoublePerCellType(INTERP_KERNEL::NormalizedCellType type, double *values, int ncomp, int nval);
+    MEDFieldDoublePerCellType(INTERP_KERNEL::NormalizedCellType type, double *values, int ncomp, int ntuple);
     INTERP_KERNEL::NormalizedCellType getType() const { return _type; }
     int getNbComp() const { return _ncomp; }
-    int getNbOfTuple() const { return _nval; }
-    int getNbOfValues() const { return _ncomp*_nval; }
+    int getNbOfTuple() const { return _ntuple; }
+    int getNbOfValues() const { return _ncomp*_ntuple; }
     double *getArray() const { return _values; }
     void releaseArray();
   private:
-    int _nval;
+    int _ntuple;
     int _ncomp;
     double *_values;
     INTERP_KERNEL::NormalizedCellType _type;
@@ -87,8 +87,9 @@ public:
   static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFile(const char *fileName, int meshDimRelToMax=0) throw(INTERP_KERNEL::Exception);
   static ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldDoubleCell(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order);
   static ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldDoubleNode(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order);
-  static void WriteUMesh(const char *fileName, ParaMEDMEM::MEDCouplingUMesh *mesh);
-  static void WriteField(const char *fileName, ParaMEDMEM::MEDCouplingFieldDouble *f);
+  static void WriteUMesh(const char *fileName, ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch);
+  static void WriteField(const char *fileName, ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch);
+  static void WriteFieldUsingAlreadyWrittenMesh(const char *fileName, ParaMEDMEM::MEDCouplingFieldDouble *f);
 private:
   MEDLoader();
 };
diff --git a/src/MEDLoader/MEDLoaderBase.cxx b/src/MEDLoader/MEDLoaderBase.cxx
new file mode 100644 (file)
index 0000000..09909b3
--- /dev/null
@@ -0,0 +1,60 @@
+//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+#include "MEDLoaderBase.hxx"
+#include "InterpKernelException.hxx"
+
+#include <fstream>
+
+int MEDLoaderBase::getStatusOfFile(const char *fileName)
+{
+  std::ifstream ifs;
+  ifs.open(fileName);
+  unsigned int res=0;
+  if((ifs.rdstate() & std::ifstream::failbit)!=0)
+    {
+      res+=1;
+      ifs.close();
+    }
+  std::ofstream ofs(fileName,std::ios_base::app);
+  if((ofs.rdstate() & std::ofstream::failbit)!=0)
+    {
+      ofs.close();
+      res+=2;
+    }
+  switch(res)
+    {
+    case 0:
+      return EXIST_RW;
+    case 1:
+      {
+        std::ifstream ifs2;
+        ifs2.open(fileName);
+        if((ifs2.rdstate() & std::ifstream::failbit)!=0)
+          return EXIST_WRONLY;
+        else
+          return NOT_EXIST;
+      }
+    case 2:
+      return EXIST_RDONLY;
+    case 3:
+      return DIR_LOCKED;
+    default:
+      throw INTERP_KERNEL::Exception("Internal error !");
+    }
+}
diff --git a/src/MEDLoader/MEDLoaderBase.hxx b/src/MEDLoader/MEDLoaderBase.hxx
new file mode 100644 (file)
index 0000000..e5d8ad9
--- /dev/null
@@ -0,0 +1,34 @@
+//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+#ifndef __MEDLOADERBASE_HXX__
+#define __MEDLOADERBASE_HXX__
+
+class MEDLoaderBase
+{
+public:
+  static int getStatusOfFile(const char *fileName);
+public:
+  static const int EXIST_RW=0;
+  static const int NOT_EXIST=1;
+  static const int EXIST_RDONLY=2;
+  static const int EXIST_WRONLY=3;
+  static const int DIR_LOCKED=4;
+};
+
+#endif
index 6409c4bc14f2fb09dbdaffa1da7792c5c2df9cb4..c901dc99d342f82fd41e3e7d7981963d215f72c6 100755 (executable)
@@ -27,10 +27,10 @@ endif
 lib_LTLIBRARIES = libmedloader.la
 
 salomeinclude_HEADERS= \
-MEDLoader.hxx
+MEDLoader.hxx MEDLoaderBase.hxx
 
 dist_libmedloader_la_SOURCES= \
-MEDLoader.cxx
+MEDLoader.cxx MEDLoaderBase.cxx
 
 libmedloader_la_CPPFLAGS= $(MPI_INCLUDES) $(MED2_INCLUDES) $(HDF5_INCLUDES) @CXXTMPDPTHFLAGS@ \
        -I$(srcdir)/../INTERP_KERNEL \
index b4994f056387e7433427cac61416c989fbde1d16..a96de033c512a665694aa8dd134bed88ee3389e0 100644 (file)
@@ -65,4 +65,7 @@ public:
   static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFile(const char *fileName, const char *meshName, int meshDimRelToMax=0) throw(INTERP_KERNEL::Exception);
   static ParaMEDMEM::MEDCouplingUMesh *ReadUMeshFromFile(const char *fileName, int meshDimRelToMax=0) throw(INTERP_KERNEL::Exception);
   static ParaMEDMEM::MEDCouplingFieldDouble *ReadFieldDoubleCell(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order);
+  static void WriteUMesh(const char *fileName, ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch);
+  static void WriteField(const char *fileName, ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch);
+  static void WriteFieldUsingAlreadyWrittenMesh(const char *fileName, ParaMEDMEM::MEDCouplingFieldDouble *f);
 };
index e0140961160b7ea1b3924fb57da603ef8ba4d04b..dcf420744cf497a058139cf6b683941b0bf4e748 100644 (file)
@@ -45,7 +45,7 @@ void ParaMEDLoader::WriteParaMesh(const char *fileName, ParaMEDMEM::ParaMESH *me
     }
   if(myRank==0)
     WriteMasterFile(fileName,fileNames,mesh->getCellMesh()->getName());
-  MEDLoader::WriteUMesh(fileNames[myRank].c_str(),dynamic_cast<MEDCouplingUMesh *>(mesh->getCellMesh()));
+  MEDLoader::WriteUMesh(fileNames[myRank].c_str(),dynamic_cast<MEDCouplingUMesh *>(mesh->getCellMesh()),true);
 }
 
 /*!
index a195446d58f57158fc8144f2d0b936eb443b8058..5e6aeef7f9ec97fd2db8b21eeab0b18743bd7257 100644 (file)
@@ -218,14 +218,14 @@ void ParaMEDMEMTest::testInterpKernelDEC_2D_(const char *srcMeth, const char *ta
       ostringstream filename;
       filename<<"./sourcesquareb_"<<source_group->myRank()+1;
       aRemover.Register(filename.str().c_str());
-      MEDLoader::WriteField("./sourcesquareb",parafield->getField());
+      //MEDLoader::WriteField("./sourcesquareb",parafield->getField());
    
       dec.recvData();
       cout <<"writing"<<endl;
       ParaMEDLoader::WriteParaMesh("./sourcesquare",paramesh);
       if (source_group->myRank()==0)
         aRemover.Register("./sourcesquare");
-      MEDLoader::WriteField("./sourcesquare",parafield->getField());
+      //MEDLoader::WriteField("./sourcesquare",parafield->getField());
       
      
       filename<<"./sourcesquare_"<<source_group->myRank()+1;
@@ -248,7 +248,7 @@ void ParaMEDMEMTest::testInterpKernelDEC_2D_(const char *srcMeth, const char *ta
 
       dec.recvData();
       ParaMEDLoader::WriteParaMesh("./targetsquareb",paramesh);
-      MEDLoader::WriteField("./targetsquareb",parafield->getField());
+      //MEDLoader::WriteField("./targetsquareb",parafield->getField());
       if (target_group->myRank()==0)
         aRemover.Register("./targetsquareb");
       ostringstream filename;
@@ -256,7 +256,7 @@ void ParaMEDMEMTest::testInterpKernelDEC_2D_(const char *srcMeth, const char *ta
       aRemover.Register(filename.str().c_str());
       dec.sendData();
       ParaMEDLoader::WriteParaMesh("./targetsquare",paramesh);
-      MEDLoader::WriteField("./targetsquare",parafield->getField());
+      //MEDLoader::WriteField("./targetsquare",parafield->getField());
       
       if (target_group->myRank()==0)
         aRemover.Register("./targetsquareb");
@@ -580,14 +580,14 @@ void ParaMEDMEMTest::testInterpKernelDEC_3D_(const char *srcMeth, const char *ta
       ostringstream filename;
       filename<<"./sourcesquareb_"<<source_group->myRank()+1;
       aRemover.Register(filename.str().c_str());
-      MEDLoader::WriteField("./sourcesquareb",parafield->getField());
+      //MEDLoader::WriteField("./sourcesquareb",parafield->getField());
    
       dec.recvData();
       cout <<"writing"<<endl;
       ParaMEDLoader::WriteParaMesh("./sourcesquare",paramesh);
       if (source_group->myRank()==0)
         aRemover.Register("./sourcesquare");
-      MEDLoader::WriteField("./sourcesquare",parafield->getField());
+      //MEDLoader::WriteField("./sourcesquare",parafield->getField());
       
      
       filename<<"./sourcesquare_"<<source_group->myRank()+1;
@@ -606,7 +606,7 @@ void ParaMEDMEMTest::testInterpKernelDEC_3D_(const char *srcMeth, const char *ta
 
       dec.recvData();
       ParaMEDLoader::WriteParaMesh("./targetsquareb",paramesh);
-      MEDLoader::WriteField("./targetsquareb",parafield->getField());
+      //MEDLoader::WriteField("./targetsquareb",parafield->getField());
       if (target_group->myRank()==0)
         aRemover.Register("./targetsquareb");
       ostringstream filename;
@@ -614,7 +614,7 @@ void ParaMEDMEMTest::testInterpKernelDEC_3D_(const char *srcMeth, const char *ta
       aRemover.Register(filename.str().c_str());
       dec.sendData();
       ParaMEDLoader::WriteParaMesh("./targetsquare",paramesh);
-      MEDLoader::WriteField("./targetsquare",parafield->getField());
+      //MEDLoader::WriteField("./targetsquare",parafield->getField());
       
       if (target_group->myRank()==0)
         aRemover.Register("./targetsquareb");
index c8b5a923ac7c3cb3bebc395d72035ec093764521..b496f584668e852ed1beb4114d8836602e5803f8 100644 (file)
@@ -395,7 +395,7 @@ void ParaMEDMEMTest::testMEDLoaderWrite1()
   bool normalThrow=false;
   try
     {
-      MEDLoader::WriteUMesh(outFileName.c_str(),mesh);
+      MEDLoader::WriteUMesh(outFileName.c_str(),mesh,true);
     }
   catch(INTERP_KERNEL::Exception& e)
     {
@@ -403,7 +403,7 @@ void ParaMEDMEMTest::testMEDLoaderWrite1()
     }
   CPPUNIT_ASSERT(normalThrow);
   mesh->setName(meshName);
-  MEDLoader::WriteUMesh(outFileName.c_str(),mesh);
+  MEDLoader::WriteUMesh(outFileName.c_str(),mesh,true);
   mesh->decrRef();
   //
   mesh=MEDLoader::ReadUMeshFromFile(outFileName.c_str(),meshName,0);
@@ -429,7 +429,7 @@ void ParaMEDMEMTest::testMEDLoaderPolygonWrite()
   MEDCouplingUMesh *mesh=MEDLoader::ReadUMeshFromFile(fileName.c_str(),meshNames[0].c_str(),0);
   mesh->checkCoherency();
   string outFileName=makeTmpFile("toto22138.med");
-  MEDLoader::WriteUMesh(outFileName.c_str(),mesh);
+  MEDLoader::WriteUMesh(outFileName.c_str(),mesh,true);
   //
   MEDCouplingUMesh *mesh2=MEDLoader::ReadUMeshFromFile(outFileName.c_str(),meshNames[0].c_str(),0);
   //