Back to index

salome-med  6.5.0
Functions
duplicateMEDMESH.cxx File Reference
#include <string>
#include <deque>
#include "MEDMEM_Exception.hxx"
#include "MEDMEM_define.hxx"
#include "MEDMEM_Mesh.hxx"
#include "MEDMEM_Grid.hxx"
#include "MEDMEM_Family.hxx"
#include "MEDMEM_Support.hxx"
#include "MEDMEM_GenDriver.hxx"
#include "MEDMEM_MedMeshDriver.hxx"
#include "MEDMEM_MedFileBrowser.hxx"

Go to the source code of this file.

Functions

int main (int argc, char **argv)

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 40 of file duplicateMEDMESH.cxx.

{
  if ( argc < 3 ) {
    cout << "Usage: " << argv[0] << "<input med file> <output med file>" << endl;
    return -1;
  }
  string filenameIN = argv[1] ;
  string filenameOUT = argv[2] ;
    
  MEDFILEBROWSER myMed(filenameIN);

  // we read all meshes in filenameIN 
  try {
    
    // read all mesh
    MESSAGE_MED("Read all meshes :") ;
    int NumberOfMeshes = myMed.getNumberOfMeshes() ;
    MESSAGE_MED("Number of meshes : "<<NumberOfMeshes) ;
    vector<string> meshNames = myMed.getMeshNames() ;
    for (int i=0; i<NumberOfMeshes; i++)
    {
      GMESH* mesh = myMed.isStructuredMesh( meshNames[i] ) ? (GMESH*) new GRID : (GMESH*) new MESH;
      int drv = mesh->addDriver(MED_DRIVER, filenameIN, meshNames[i] );
      mesh->read(drv);
      MESSAGE_MED("  - Mesh "<<i+1<<", named "<<meshNames[i]<<" read !");
      MED_MESH_WRONLY_DRIVER myMeshDriver(filenameOUT,mesh);
      MESSAGE_MED("After declaration of MED_MESH_DRIVER");
      myMeshDriver.setMeshName(meshNames[i]);
      MESSAGE_MED("After setMeshName");
      myMeshDriver.open() ;
      MESSAGE_MED("After open");
      myMeshDriver.write() ;
      MESSAGE_MED("After write");
      myMeshDriver.close() ;
      MESSAGE_MED("After close");
      mesh->removeReference();
    }

  } catch (MEDEXCEPTION& ex){
    MESSAGE_MED(ex.what()) ;
    return -1;
  }
  return 0;
}