Salome HOME
MEDMEM suppression
[modules/med.git] / src / MEDMEMBinTest / duplicateMEDMESH.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include<string>
24 #include<deque>
25
26 #include "MEDMEM_Exception.hxx"
27 #include "MEDMEM_define.hxx"
28
29 #include "MEDMEM_Mesh.hxx"
30 #include "MEDMEM_Grid.hxx"
31 #include "MEDMEM_Family.hxx"
32 #include "MEDMEM_Support.hxx"
33
34 #include "MEDMEM_GenDriver.hxx"
35 #include "MEDMEM_MedMeshDriver.hxx"
36 #include "MEDMEM_MedFileBrowser.hxx"
37
38 using namespace std;
39 using namespace MEDMEM;
40 int main (int argc, char ** argv)
41 {
42   if ( argc < 3 ) {
43     cout << "Usage: " << argv[0] << "<input med file> <output med file>" << endl;
44     return -1;
45   }
46   string filenameIN = argv[1] ;
47   string filenameOUT = argv[2] ;
48     
49   MEDFILEBROWSER myMed(filenameIN);
50
51   // we read all meshes in filenameIN 
52   try {
53     
54     // read all mesh
55     MESSAGE_MED("Read all meshes :") ;
56     int NumberOfMeshes = myMed.getNumberOfMeshes() ;
57     MESSAGE_MED("Number of meshes : "<<NumberOfMeshes) ;
58     vector<string> meshNames = myMed.getMeshNames() ;
59     for (int i=0; i<NumberOfMeshes; i++)
60     {
61       GMESH* mesh = myMed.isStructuredMesh( meshNames[i] ) ? (GMESH*) new GRID : (GMESH*) new MESH;
62       int drv = mesh->addDriver(MED_DRIVER, filenameIN, meshNames[i] );
63       mesh->read(drv);
64       MESSAGE_MED("  - Mesh "<<i+1<<", named "<<meshNames[i]<<" read !");
65       MED_MESH_WRONLY_DRIVER myMeshDriver(filenameOUT,mesh);
66       MESSAGE_MED("After declaration of MED_MESH_DRIVER");
67       myMeshDriver.setMeshName(meshNames[i]);
68       MESSAGE_MED("After setMeshName");
69       myMeshDriver.open() ;
70       MESSAGE_MED("After open");
71       myMeshDriver.write() ;
72       MESSAGE_MED("After write");
73       myMeshDriver.close() ;
74       MESSAGE_MED("After close");
75       mesh->removeReference();
76     }
77
78   } catch (MEDEXCEPTION& ex){
79     MESSAGE_MED(ex.what()) ;
80     return -1;
81   }
82   return 0;
83 }