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