Back to index

salome-med  6.5.0
duplicateMEDMESH.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include<string>
00024 #include<deque>
00025 
00026 #include "MEDMEM_Exception.hxx"
00027 #include "MEDMEM_define.hxx"
00028 
00029 #include "MEDMEM_Mesh.hxx"
00030 #include "MEDMEM_Grid.hxx"
00031 #include "MEDMEM_Family.hxx"
00032 #include "MEDMEM_Support.hxx"
00033 
00034 #include "MEDMEM_GenDriver.hxx"
00035 #include "MEDMEM_MedMeshDriver.hxx"
00036 #include "MEDMEM_MedFileBrowser.hxx"
00037 
00038 using namespace std;
00039 using namespace MEDMEM;
00040 int main (int argc, char ** argv)
00041 {
00042   if ( argc < 3 ) {
00043     cout << "Usage: " << argv[0] << "<input med file> <output med file>" << endl;
00044     return -1;
00045   }
00046   string filenameIN = argv[1] ;
00047   string filenameOUT = argv[2] ;
00048     
00049   MEDFILEBROWSER myMed(filenameIN);
00050 
00051   // we read all meshes in filenameIN 
00052   try {
00053     
00054     // read all mesh
00055     MESSAGE_MED("Read all meshes :") ;
00056     int NumberOfMeshes = myMed.getNumberOfMeshes() ;
00057     MESSAGE_MED("Number of meshes : "<<NumberOfMeshes) ;
00058     vector<string> meshNames = myMed.getMeshNames() ;
00059     for (int i=0; i<NumberOfMeshes; i++)
00060     {
00061       GMESH* mesh = myMed.isStructuredMesh( meshNames[i] ) ? (GMESH*) new GRID : (GMESH*) new MESH;
00062       int drv = mesh->addDriver(MED_DRIVER, filenameIN, meshNames[i] );
00063       mesh->read(drv);
00064       MESSAGE_MED("  - Mesh "<<i+1<<", named "<<meshNames[i]<<" read !");
00065       MED_MESH_WRONLY_DRIVER myMeshDriver(filenameOUT,mesh);
00066       MESSAGE_MED("After declaration of MED_MESH_DRIVER");
00067       myMeshDriver.setMeshName(meshNames[i]);
00068       MESSAGE_MED("After setMeshName");
00069       myMeshDriver.open() ;
00070       MESSAGE_MED("After open");
00071       myMeshDriver.write() ;
00072       MESSAGE_MED("After write");
00073       myMeshDriver.close() ;
00074       MESSAGE_MED("After close");
00075       mesh->removeReference();
00076     }
00077 
00078   } catch (MEDEXCEPTION& ex){
00079     MESSAGE_MED(ex.what()) ;
00080     return -1;
00081   }
00082   return 0;
00083 }