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