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