]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/test_copie_field_.cxx
Salome HOME
sources v1.2
[modules/med.git] / src / MEDMEM / test_copie_field_.cxx
1 //  MED MEDMEM : MED files in memory
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : test_copie_field_.cxx
25 //  Module : MED
26
27 /* Programme de test du constructeur de copies de la classe FIELD_ de MEDMEM
28    jroy - 12/12/2002 */
29
30 #include<string>
31
32 #include <math.h>
33 #include <stdlib.h>
34
35 #include "MEDMEM_Exception.hxx"
36 #include "MEDMEM_Mesh.hxx"
37 #include "MEDMEM_Family.hxx"
38 #include "MEDMEM_Group.hxx"
39
40 #include "MEDMEM_MedMeshDriver.hxx"
41 #include "MEDMEM_MedFieldDriver.hxx"
42 #include "MEDMEM_Support.hxx"
43 #include "MEDMEM_Field.hxx"
44 #include "MEDMEM_define.hxx"
45
46
47 void affiche_field(FIELD_ * myField, const SUPPORT * mySupport)
48 {
49   cout << "Field "<< myField->getName() << " : " <<myField->getDescription() <<  endl ;
50   int NumberOfComponents = myField->getNumberOfComponents() ;
51   cout << "- Nombre de composantes : "<< NumberOfComponents << endl ;
52   for (int i=1; i<NumberOfComponents+1; i++) {
53     cout << "  - composante "<<i<<" :"<<endl ;
54     cout << "      - nom         : "<<myField->getComponentName(i)<< endl;
55     cout << "      - description : "<<myField->getComponentDescription(i) << endl;
56     cout << "      - units       : "<<myField->getMEDComponentUnit(i) << endl;
57   }
58   cout << "- iteration :" << endl ;
59   cout << "    - numero : " << myField->getIterationNumber()<< endl  ;
60   cout << "    - ordre  : " << myField->getOrderNumber()<< endl  ;
61   cout << "    - temps  : " << myField->getTime()<< endl  ;
62
63   cout << "- Type : " << myField->getValueType()<< endl;
64   /*
65   cout << "- Valeurs :"<<endl;
66   int NumberOf = mySupport->getNumberOfElements(MED_ALL_ELEMENTS);
67
68   for (int i=1; i<NumberOf+1; i++) {
69     double * value = myField->getValueI(MED_FULL_INTERLACE,i) ;
70     for (int j=0; j<NumberOfComponents; j++)
71       cout << value[j]<< " ";
72     cout<<endl;
73   }
74   */
75   cout << "- Adresse support : " << mySupport << endl;
76 }
77
78
79 int main (int argc, char ** argv) {
80
81   int read;
82
83   if ((argc !=3) && (argc != 4)) {
84     cerr << "Usage : " << argv[0] 
85          << " filename meshname fieldname" << endl << endl;
86     exit(-1);
87   }
88
89   string filename = argv[1] ;
90   string meshname = argv[2] ;
91
92   //  MESH * myMesh= new MESH(MED_DRIVER,filename,meshname) ;
93   MESH * myMesh= new MESH() ;
94   myMesh->setName(meshname);
95   MED_MESH_RDONLY_DRIVER myMeshDriver(filename,myMesh) ;
96   myMeshDriver.setMeshName(meshname);
97   myMeshDriver.open() ;
98   myMeshDriver.read() ;
99   myMeshDriver.close() ;
100
101   //    int drv = myMesh->addDriver(MED_DRIVER,"sortie.med",meshname);
102   //    myMesh->write(drv); 
103
104
105   
106
107   // if (argc < 4) return 0;
108
109   // read field :
110
111   if (argc != 4) exit(0) ;
112   // else we have a field !
113
114   string fieldname = argv[3];
115
116
117   //  SUPPORT * mySupport = new SUPPORT(myMesh,"On_all_node",MED_NODE);
118   SUPPORT * mySupport = new SUPPORT(myMesh,"On_all_cell",MED_CELL);
119   FIELD<double> * myField = new FIELD<double>() ;
120   myField->setValueType(MED_REEL64);
121
122   myField->setName(fieldname);
123   myField->setSupport(mySupport);
124   MED_FIELD_RDONLY_DRIVER<double> myFieldDriver(filename,myField) ;
125   myFieldDriver.setFieldName(fieldname);
126   myFieldDriver.open() ;
127
128   try {
129     myFieldDriver.read() ;
130   } catch (...) {
131     delete mySupport ;
132     mySupport = new SUPPORT(myMesh,"On_all_node",MED_NODE);
133     myField->setSupport(mySupport);
134     try {
135       myFieldDriver.read() ;
136     } catch (...) {
137       cout << "Field " << fieldname << " not found !!!" << endl ;
138       exit (-1) ;
139     }
140   }
141   
142   myFieldDriver.close() ;
143
144   FIELD_ * pt_field_ = myField;
145   affiche_field(pt_field_, mySupport);
146   FIELD_ * pt_field_2 = new FIELD_(* pt_field_);
147   delete myField;
148   affiche_field(pt_field_2, pt_field_2->getSupport());
149   
150   delete pt_field_2 ;
151
152   delete mySupport ;
153   delete myMesh ;
154
155   return 0;
156 }