1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : testUCoordinate.cxx
25 #include "MEDMEM_Utilities.hxx"
27 #include "MEDMEM_define.hxx"
28 #include "MEDMEM_Array.hxx"
29 #include "MEDMEM_Coordinate.hxx"
35 using namespace MEDMEM;
37 static void usage(char * name)
39 cout << " " << name << endl;
42 int main (int argc, char ** argv)
46 if (argc < 1) usage(argv[0]);
48 cout << "COORDINATE Test" << endl;
49 cout << "---------------" << endl;
54 string * noms = new string[3];
64 int * numbers=new int[5];
65 for (int i=0; i< 5; i++) numbers[i] =10+i;
67 MED_EN::medModeSwitch ModeFull=MED_EN::MED_FULL_INTERLACE;
68 double coor[15] = {0,0,0,0,0,1,0,1,0,1,0,0,0.5,0.5,0.5} ;
69 ASSERT_MED(SpaceDim*NbOfNodes == 15);
72 cout << " - mode : MED_FULL_INTERLACE" << endl;
73 cout << " - dimension de l espace : " << SpaceDim << endl;
74 cout << " - nombre de noeuds : " << NbOfNodes << endl;
76 double * coor1 = new double[SpaceDim*NbOfNodes];
77 for( int k=0 ; k<SpaceDim*NbOfNodes ; k++ )
80 MEDARRAY<double>* CoordinateArray = new MEDARRAY<double>(coor1,SpaceDim,NbOfNodes,ModeFull);
84 mycoo.setCoordinates(CoordinateArray);
86 catch ( const std::exception &e )
88 cout << "-------------------------------" << endl;
89 cout << "pb avec setCoordinates" << endl;
90 cout << "-------------------------------" << endl;
91 MESSAGE_MED( "catched exception : " << e.what() ) ;
96 cout << "-------------------------------" << endl;
97 cout << "pb avec setCoordinates" << endl;
98 cout << "-------------------------------" << endl;
102 //--------------------------------------------------------------------//
103 // Tests des methodes //
105 // - setCoordinatesNames //
106 // - setCoordinatesUnits //
107 // - setCoordinatesSystem //
108 // - setNodesNumbers //
110 //--------------------------------------------------------------------//
113 mycoo.setCoordinatesNames(noms);
115 catch ( const std::exception &e )
117 cout << "-------------------------------" << endl;
118 cout << "pb avec setCoordinatesNames" << endl;
119 cout << "-------------------------------" << endl;
120 MESSAGE_MED( "catched exception : " << e.what() ) ;
121 return EXIT_FAILURE ;
125 cout << "-------------------------------" << endl;
126 cout << "pb avec setCoordinatesNames" << endl;
127 cout << "-------------------------------" << endl;
128 return EXIT_FAILURE ;
133 mycoo.setCoordinatesUnits(units);
135 catch ( const std::exception &e )
137 cout << "-------------------------------" << endl;
138 cout << "pb avec setCoordinatesUnits" << endl;
139 cout << "-------------------------------" << endl;
140 MESSAGE_MED( "catched exception : " << e.what() ) ;
141 return EXIT_FAILURE ;
145 cout << "-------------------------------" << endl;
146 cout << "pb avec setCoordinatesUnits" << endl;
147 cout << "-------------------------------" << endl;
148 return EXIT_FAILURE ;
153 mycoo.setCoordinatesSystem("cartesien");
155 catch ( const std::exception &e )
157 cout << "-------------------------------" << endl;
158 cout << "pb avec setCoordinatesSystem" << endl;
159 cout << "-------------------------------" << endl;
160 MESSAGE_MED( "catched exception : " << e.what() ) ;
161 return EXIT_FAILURE ;
165 cout << "-------------------------------" << endl;
166 cout << "pb avec setCoordinatesSystem" << endl;
167 cout << "-------------------------------" << endl;
168 return EXIT_FAILURE ;
173 mycoo.setNodesNumbers(numbers);
175 catch ( const std::exception &e )
177 cout << "-------------------------------" << endl;
178 cout << "pb avec setNodesNumbers" << endl;
179 cout << "-------------------------------" << endl;
180 MESSAGE_MED( "catched exception : " << e.what() ) ;
181 return EXIT_FAILURE ;
185 cout << "-------------------------------" << endl;
186 cout << "pb avec setNodesNumbers" << endl;
187 cout << "-------------------------------" << endl;
188 return EXIT_FAILURE ;
191 //--------------------------------------------------------------------//
192 // Tests des methodes //
194 // - getCoordinatesNames //
195 // - getCoordinatesUnits //
196 // - getCoordinatesUnit //
197 // - getCoordinatesSystem //
198 // - getNodesNumbers //
200 //--------------------------------------------------------------------//
202 cout << endl << " Relecture des Coordonnees" << endl << endl;
206 cout << " Le systeme est : " << mycoo.getCoordinatesSystem() << endl;
208 catch ( const std::exception &e )
210 cout << "-------------------------------" << endl;
211 cout << "pb avec getCoordinatesSystem" << endl;
212 cout << "-------------------------------" << endl;
213 MESSAGE_MED( "catched exception : " << e.what() ) ;
214 return EXIT_FAILURE ;
218 cout << "-------------------------------" << endl;
219 cout << "pb avec getCoordinatesSystem" << endl;
220 cout << "-------------------------------" << endl;
221 return EXIT_FAILURE ;
224 const string * units2;
227 units2=mycoo.getCoordinatesUnits();
228 for (int axe = 0; axe < SpaceDim; axe++)
232 string verif = mycoo.getCoordinateUnit(axe+1);
233 if (verif != units2[axe])
234 cout << "Pb avec les noms des axes" << endl;
236 catch ( const std::exception &e )
238 cout << "-------------------------" << endl;
239 cout << "pb avec getCoordinateUnit" << endl;
240 cout << "-------------------------" << endl;
241 MESSAGE_MED( "catched exception : " << e.what() ) ;
242 return EXIT_FAILURE ;
246 cout << "-------------------------" << endl;
247 cout << "pb avec getCoordinateUnit" << endl;
248 cout << "-------------------------" << endl;
249 return EXIT_FAILURE ;
253 catch ( const std::exception &e )
255 cout << "---------------------------" << endl;
256 cout << "pb avec getCoordinatesUnits" << endl;
257 cout << "---------------------------" << endl;
258 MESSAGE_MED( "catched exception : " << e.what() ) ;
259 return EXIT_FAILURE ;
263 cout << "---------------------------" << endl;
264 cout << "pb avec getCoordinatesUnits" << endl;
265 cout << "---------------------------" << endl;
266 return EXIT_FAILURE ;
269 const string * noms2;
272 noms2=mycoo.getCoordinatesNames();
273 for (int axe = 0; axe < SpaceDim; axe++)
277 string verif = mycoo.getCoordinateName(axe+1);
278 if (verif != noms2[axe])
279 cout << "Pb avec les noms des axes" << endl;
281 catch ( const std::exception &e )
283 cout << "-------------------------" << endl;
284 cout << "pb avec getCoordinateName" << endl;
285 cout << "-------------------------" << endl;
286 MESSAGE_MED( "catched exception : " << e.what() ) ;
287 return EXIT_FAILURE ;
291 cout << "-------------------------" << endl;
292 cout << "pb avec getCoordinateName" << endl;
293 cout << "-------------------------" << endl;
294 return EXIT_FAILURE ;
298 catch ( const std::exception &e )
300 cout << "---------------------------" << endl;
301 cout << "pb avec getCoordinatesNames" << endl;
302 cout << "---------------------------" << endl;
303 MESSAGE_MED( "catched exception : " << e.what() ) ;
304 return EXIT_FAILURE ;
308 cout << "---------------------------" << endl;
309 cout << "pb avec getCoordinatesNames" << endl;
310 cout << "---------------------------" << endl;
311 return EXIT_FAILURE ;
317 for (int axe = 0; axe < SpaceDim; axe++)
320 cout << "Coordonnees sur l'Axe : " << noms2[axe] ;
321 cout << " dont l unite est " << units2[axe] << endl;
325 for (int num=0; num < NbOfNodes; num++)
329 const double d = mycoo.getCoordinate(num + 1,axe+1);
331 ASSERT_MED(fabs(d - mycoo.getCoordinateAxis(axe+1)[num]) < pouieme);
332 ASSERT_MED(fabs(d - mycoo.getCoordinates(ModeFull)[(num * SpaceDim)+axe]) < pouieme);
333 ASSERT_MED(fabs(d - coor [(num * SpaceDim)+axe]) < pouieme);
335 catch ( const std::exception &e )
337 cout << "----------------------" << endl;
338 cout << "pb avec getCoordinates" << endl;
339 cout << "----------------------" << endl;
340 MESSAGE_MED( "catched exception : " << e.what() ) ;
341 return EXIT_FAILURE ;
345 cout << "----------------------" << endl;
346 cout << "pb avec getCoordinates" << endl;
347 cout << "----------------------" << endl;
348 return EXIT_FAILURE ;
353 catch ( const std::exception &e )
355 cout << "-------------------------" << endl;
356 cout << "pb avec getCoordinateAxis" << endl;
357 cout << "-------------------------" << endl;
358 MESSAGE_MED( "catched exception : " << e.what() ) ;
359 return EXIT_FAILURE ;
363 cout << "-------------------------" << endl;
364 cout << "pb avec getCoordinateAxis" << endl;
365 cout << "-------------------------" << endl;
366 return EXIT_FAILURE ;
370 catch ( const std::exception &e )
372 cout << "----------------------" << endl;
373 cout << "pb avec getCoordinates" << endl;
374 cout << "----------------------" << endl;
375 MESSAGE_MED( "catched exception : " << e.what() ) ;
376 return EXIT_FAILURE ;
380 cout << "----------------------" << endl;
381 cout << "pb avec getCoordinates" << endl;
382 cout << "----------------------" << endl;
383 return EXIT_FAILURE ;
391 delete CoordinateArray ;
393 MESSAGE_MED("FIN normale du traitement");
394 return EXIT_SUCCESS ;