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