Salome HOME
10bdcbcd6c417678f305c9bb8e345e10bbb9dec3
[modules/med.git] / src / MEDMEMBinTest / test_gibi_driver.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 #include "MEDMEM_GibiMeshDriver.hxx"
23 #include "MEDMEM_Mesh.hxx"
24 #include "MEDMEM_DriverFactory.hxx"
25
26 using namespace std;
27 using namespace MEDMEM;
28 using namespace MED_EN;
29 using namespace DRIVERFACTORY;
30
31 int main (int argc, char ** argv)
32 {
33     /* process the arguments */
34     if (argc != 2) 
35     {
36         cerr << "Usage : " << argv[0] 
37         << " Gibifilename" << endl << endl
38         << "-> lit le fichier gibi filename ,crée 2 fichiers : MED et VTK" << endl;
39         exit(-1);
40     }
41
42     string gibifilename  = argv[1];
43
44     // Construction des noms de fichier
45     const string ext=".sauve";
46     string::size_type pos=gibifilename.find(ext,0);
47     string basename (gibifilename, 0, pos); // nom sans extension
48     string medfile21=basename+"_V21.med"; // nom fichier med 2.1 à creer
49     string medfile22=basename+"_V22.med"; // nom fichier med 2.2 à creer
50     string vtkfile=basename+".vtk"; // nom fichier vtk à creer
51     string::size_type pos1=gibifilename.rfind('/');
52     string meshName (gibifilename,pos1+1,pos-pos1-1); // get rid of directory & extension
53     cout << meshName << endl;
54
55     // lecture du fichier gibi
56     // MESH * myMesh= new MESH(GIBI_DRIVER,gibifilename);
57     MESH * myMesh= new MESH; 
58     GIBI_MESH_RDONLY_DRIVER myGibiMeshDriver(gibifilename, myMesh) ;
59     myGibiMeshDriver.open() ;
60     myGibiMeshDriver.read() ;
61     myGibiMeshDriver.close() ;
62
63     cout << "Impression de MESH : " << endl;
64     cout << *myMesh;
65
66     cout << "creation du fichier med 22 : " << endl;
67     int idMed22 = myMesh->addDriver(MED_DRIVER, medfile22, meshName);
68     myMesh->write(idMed22) ;
69
70     // creation d'un fichier vtk
71     cout << "creation d'un fichier vtk : " << endl;
72     int idVtk = myMesh->addDriver(VTK_DRIVER, vtkfile, meshName);
73     myMesh->write(idVtk) ;
74     myMesh->removeReference();
75
76     // remontée mémoire du fichier med 22
77     myMesh= new MESH(MED_DRIVER,medfile22,meshName);
78
79     myMesh->removeReference();
80 }