1 // MED MEDMEM : MED files in memory
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : test_copie_field_.cxx
27 /* Programme de test du constructeur de copies de la classe FIELD_ de MEDMEM
35 #include "MEDMEM_Exception.hxx"
36 #include "MEDMEM_Mesh.hxx"
37 #include "MEDMEM_Family.hxx"
38 #include "MEDMEM_Group.hxx"
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"
47 void affiche_field(FIELD_ * myField, const SUPPORT * mySupport)
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;
58 cout << "- iteration :" << endl ;
59 cout << " - numero : " << myField->getIterationNumber()<< endl ;
60 cout << " - ordre : " << myField->getOrderNumber()<< endl ;
61 cout << " - temps : " << myField->getTime()<< endl ;
63 cout << "- Type : " << myField->getValueType()<< endl;
65 cout << "- Valeurs :"<<endl;
66 int NumberOf = mySupport->getNumberOfElements(MED_ALL_ELEMENTS);
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]<< " ";
75 cout << "- Adresse support : " << mySupport << endl;
79 int main (int argc, char ** argv) {
83 if ((argc !=3) && (argc != 4)) {
84 cerr << "Usage : " << argv[0]
85 << " filename meshname fieldname" << endl << endl;
89 string filename = argv[1] ;
90 string meshname = argv[2] ;
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);
99 myMeshDriver.close() ;
101 // int drv = myMesh->addDriver(MED_DRIVER,"sortie.med",meshname);
102 // myMesh->write(drv);
107 // if (argc < 4) return 0;
111 if (argc != 4) exit(0) ;
112 // else we have a field !
114 string fieldname = argv[3];
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);
122 myField->setName(fieldname);
123 myField->setSupport(mySupport);
124 MED_FIELD_RDONLY_DRIVER<double> myFieldDriver(filename,myField) ;
125 myFieldDriver.setFieldName(fieldname);
126 myFieldDriver.open() ;
129 myFieldDriver.read() ;
132 mySupport = new SUPPORT(myMesh,"On_all_node",MED_NODE);
133 myField->setSupport(mySupport);
135 myFieldDriver.read() ;
137 cout << "Field " << fieldname << " not found !!!" << endl ;
142 myFieldDriver.close() ;
144 FIELD_ * pt_field_ = myField;
145 affiche_field(pt_field_, mySupport);
146 FIELD_ * pt_field_2 = new FIELD_(* pt_field_);
148 affiche_field(pt_field_2, pt_field_2->getSupport());