]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/med2vtk.cxx
Salome HOME
remove a reference to the $MED_ROOT_DIR in the Makefile.in wich is useless
[modules/med.git] / src / MEDMEM / med2vtk.cxx
1 #include<string>
2 #include<deque>
3
4 #include "MEDMEM_Exception.hxx"
5 #include "MEDMEM_define.hxx"
6
7 #include "MEDMEM_Med.hxx"
8 #include "MEDMEM_Mesh.hxx"
9 #include "MEDMEM_Family.hxx"
10 #include "MEDMEM_Support.hxx"
11 #include "MEDMEM_Field.hxx"
12 #include "MEDMEM_VtkMedDriver.hxx"
13
14 #ifdef _DEBUG_
15 #include "LocalTraceCollector.hxx"
16 #endif /* ifdef _DEBUG_*/
17
18 using namespace std;
19 using namespace MEDMEM;
20 void usage(char * name)
21 {
22   cout << "  " << name << " <input med file> <output vtk file> " <<endl ;
23   cout << "    " << "(the two file name are mandatory)" << endl ;
24   exit(-1);
25 }
26
27 int main (int argc, char ** argv) {
28 #ifdef _DEBUG_
29   LocalTraceCollector::instance();
30 #endif /* ifdef _DEBUG_*/
31
32   if (argc != 3) usage(argv[0]);
33   
34   string filenameIN = argv[1] ;
35   string filenameOUT = argv[2] ;
36   
37   try {
38     /////////////////////////////////////////////////
39     // we read all meshes and fields in filenameIN //
40     /////////////////////////////////////////////////
41     MED myMed(MED_DRIVER,filenameIN) ;
42     
43     // read all meshes
44     ////////////////////
45
46     cout << "Read all meshes "  ;
47     int NumberOfMeshes = myMed.getNumberOfMeshes() ;
48     cout << "( "<<NumberOfMeshes << " ) :" << endl ;
49     deque<string> MeshName = myMed.getMeshNames() ;
50     for (int i=0; i<NumberOfMeshes; i++) {
51       myMed.getMesh(MeshName[i])->read() ;
52       cout << "  - Mesh "<<i+1<<", named "<<MeshName[i]<<" is read !" << endl;
53     }
54
55     // PROVISOIRE
56     ///////////////
57
58     // set support : support must be calculated with mesh information !!!
59     myMed.updateSupport() ;
60     
61     // read all fields
62     ////////////////////
63
64     cout << "Read all fields " ;
65     int NumberOfFields = myMed.getNumberOfFields() ;
66     cout << "( "<<NumberOfFields << " ) :" << endl;
67     deque<string> FieldName = myMed.getFieldNames() ;
68     for (int i=0; i<NumberOfFields; i++) {
69       deque<DT_IT_> FieldIteration = myMed.getFieldIteration(FieldName[i]) ;
70       cout << "  - Field "<<i+1<<", named "<<FieldName[i] << " :" << endl ;
71       int NumberOfIteration = FieldIteration.size() ;
72       cout << "    Number of iteration pair : "<< NumberOfIteration << endl;
73       for (int j=0; j<NumberOfIteration; j++) {
74         FIELD_ * myField = myMed.getField(FieldName[i],FieldIteration[j].dt,FieldIteration[j].it) ;
75         
76         myField->read() ;
77         cout << "    * Iteration "<<FieldIteration[j].dt<<" and  order number "<<FieldIteration[j].it<<" ) is read !" << endl;
78       }
79     }
80
81     //////////////////////////////////////////
82     // we write all in VTK file filenameOUT //
83     /////////////////////////////////////////
84     int id = myMed.addDriver(VTK_DRIVER,filenameOUT) ;
85     myMed.write(id) ;
86
87   } 
88   catch (MEDEXCEPTION& ex){
89     cout << ex.what() << endl ;
90   }
91
92 }