Salome HOME
Copyrights update
[tools/medcoupling.git] / doc / MEDMEM / FIELDgeneral.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/
19 //
20 using namespace std;
21 #include "MEDMEM_Mesh.hxx"
22 #include "MEDMEM_Field.hxx"
23
24 using namespace MEDMEM;
25 using namespace MED_EN ;
26
27 int main (int argc, char ** argv) {
28
29   const string MedFile = "pointe.med" ;
30   const string MeshName = "maa1" ;
31   const string FieldName = "fieldcelldoublevector" ;
32
33   /* read MESH */
34   MESH * myMesh = new MESH(MED_DRIVER,MedFile,MeshName) ;
35   //  myMesh->read() ;
36
37   /* read FIELD */
38   // we need a support :
39   SUPPORT * mySupport = new SUPPORT(myMesh,"Support on all Cells",MED_CELL);
40   FIELD<double> myField(mySupport,MED_DRIVER,MedFile,FieldName) ;
41   //  myField.read() ;
42
43   /* what in Field ? */
44   // How many components
45   int NumberOfCompoennts = myField.getNumberOfComponents() ;
46
47   const string * ComponentsNames = myField.getComponentsNames();
48   const string * ComponentsDescriptions = myField.getComponentsDescriptions();
49   const string * ComponentsUnits = myField.getMEDComponentsUnits();
50
51   for(int i=0;i<NumberOfCompoennts; i++) {
52     cout << "Component " << i << " :" <<endl ;
53     cout << "  - name        : " << ComponentsNames[i] << endl ;
54     cout << "  - description : " << ComponentsDescriptions[i] << endl ;
55     cout << "  - unit        : " << ComponentsUnits[i] << endl ;
56   }
57
58   // Which iteration :
59   int IterationNumber = myField.getIterationNumber() ; // negative mean undefined
60   int OrderNumber = myField.getOrderNumber() ;
61   // internal iteration at this time iteration, negative mean undefined
62   double Time = myField.getTime() ;
63
64   cout << "Iteration " << IterationNumber << " at time " << Time <<
65     " (and order number " << OrderNumber << ")" << endl ;
66
67   // How many Value :
68   int NumberOfValue = mySupport->getNumberOfElements(MED_ALL_ELEMENTS);
69   // Value
70   const double * Value = myField.getValue(MED_FULL_INTERLACE);
71   for(int i=0; i<NumberOfValue; i++) {
72     for(int j=0; j<NumberOfCompoennts; j++)
73       cout << Value[i*NumberOfCompoennts+j] << " " ;
74     cout << endl ;
75   }
76
77   delete mySupport;
78   delete myMesh;
79
80   return 0 ;
81 }