Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/med.git] / src / MEDMEM / test_copie_fieldT.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/ or email : webmaster.salome@opencascade.com
19 //
20 /* Programme de test du constructeur de copies de la classe FIELD_ de MEDMEM
21    jroy - 12/12/2002 */
22
23 #include<string>
24
25 #include <math.h>
26 #include <stdlib.h>
27
28 #include "MEDMEM_Exception.hxx"
29 #include "MEDMEM_Mesh.hxx"
30 #include "MEDMEM_Family.hxx"
31 #include "MEDMEM_Group.hxx"
32
33 #include "MEDMEM_MedMeshDriver.hxx"
34 #include "MEDMEM_MedFieldDriver.hxx"
35 #include "MEDMEM_Support.hxx"
36 #include "MEDMEM_Field.hxx"
37 #include "MEDMEM_FieldConvert.hxx"
38 #include "MEDMEM_define.hxx"
39
40 using namespace std;
41 using namespace MEDMEM;
42 using namespace MED_EN;
43
44
45 void affiche_field_(FIELD_ * myField, const SUPPORT * mySupport)
46 {
47   cout << "Field "<< myField->getName() << " : " <<myField->getDescription() <<  endl ;
48   int NumberOfComponents = myField->getNumberOfComponents() ;
49   cout << "- Nombre de composantes : "<< NumberOfComponents << endl ;
50   for (int i=1; i<NumberOfComponents+1; i++) {
51     cout << "  - composante "<<i<<" :"<<endl ;
52     cout << "      - nom         : "<<myField->getComponentName(i)<< endl;
53     cout << "      - description : "<<myField->getComponentDescription(i) << endl;
54     cout << "      - units       : "<<myField->getMEDComponentUnit(i) << endl;
55   }
56   cout << "- iteration :" << endl ;
57   cout << "    - numero : " << myField->getIterationNumber()<< endl  ;
58   cout << "    - ordre  : " << myField->getOrderNumber()<< endl  ;
59   cout << "    - temps  : " << myField->getTime()<< endl  ;
60
61   cout << "- Type : " << myField->getValueType()<< endl;
62
63   cout << "- Adresse support : " << mySupport << endl;
64 }
65
66 template <class INTERLACING_TAG>
67 void affiche_fieldT(FIELD<double, INTERLACING_TAG> * myField,
68                     const SUPPORT * mySupport)
69 {
70   affiche_field_((FIELD_ *) myField, mySupport);
71
72   cout << "- Valeurs :"<<endl;
73   int NumberOf = mySupport->getNumberOfElements(MED_ALL_ELEMENTS);
74   int NumberOfComponents = myField->getNumberOfComponents() ;
75
76   if ( myField->getInterlacingType() == MED_EN::MED_FULL_INTERLACE ) {
77     for (int i=1; i<NumberOf+1; i++) {
78       const double * value = myField->getRow(i) ;
79       for (int j=0; j<NumberOfComponents; j++)
80         cout << value[j]<< " ";
81       cout<<endl;
82     }
83   }
84   else {
85     for (int j=1; j<NumberOfComponents+1; j++) {
86       const double * value = myField->getColumn(j) ;
87       for (int i=0; i<NumberOf; i++)
88         cout << value[i]<< " ";
89       cout<<endl;
90     }
91   }
92 }
93
94 int main (int argc, char ** argv) {
95   // int read; !! UNUSED VARIABLE !!
96
97   if ((argc !=3) && (argc != 4)) {
98     cerr << "Usage : " << argv[0] 
99          << " filename meshname fieldname" << endl << endl;
100     exit(-1);
101   }
102
103   string filename = argv[1] ;
104   string meshname = argv[2] ;
105
106   MESH * myMesh= new MESH() ;
107   myMesh->setName(meshname);
108   MED_MESH_RDONLY_DRIVER myMeshDriver(filename,myMesh) ;
109   myMeshDriver.setMeshName(meshname);
110   int current = myMesh->addDriver(myMeshDriver);
111   myMesh->read(current);
112
113   // read field :
114   if (argc != 4) exit(0) ;
115   // else we have a field !
116   string fieldname = argv[3];
117
118   FIELD<double> * myField ;
119   //  SUPPORT * mySupport = new SUPPORT(myMesh,"On_all_node",MED_NODE);
120   SUPPORT * mySupport = new SUPPORT(myMesh,"On_all_cell",MED_CELL);
121   try {
122     myField = new FIELD<double>(mySupport,MED_DRIVER,filename,fieldname) ;
123   } catch (...) {
124     delete mySupport ;
125     mySupport = new SUPPORT(myMesh,"On_all_node",MED_NODE);
126     try {
127       myField = new FIELD<double>(mySupport,MED_DRIVER,filename,fieldname) ;
128     } catch (...) {
129       cout << "Field double " << fieldname << " not found !!!" << endl ;
130       exit (-1) ;
131     }
132   }
133   
134   affiche_fieldT(myField, mySupport);
135   FIELD<double> * myField2 = new FIELD<double>(* myField); // Contructeur par recopie, sauf SUPPORT
136   delete myField; // Ne détruit pas le Support 
137   affiche_fieldT(myField2, myField2->getSupport());
138   FIELD<double,NoInterlace>   * myField3  = FieldConvert( *myField2 );
139   delete myField2;
140
141   affiche_fieldT(myField3, myField3->getSupport());
142   FIELD<double,FullInterlace> * myField4  = FieldConvert( *myField3 );
143   delete myField3;
144   affiche_fieldT(myField4, myField4->getSupport());
145   delete myField4;
146
147   FIELD<double,NoInterlace> * myField5 = new FIELD<double,NoInterlace>(mySupport,MED_DRIVER,filename,fieldname) ;
148   affiche_fieldT(myField5, myField5->getSupport());
149   delete myField5;
150
151   delete mySupport ;
152   delete myMesh ;
153
154   return 0;
155 }