Salome HOME
Final version of the V2_2_0 in the main trunk of the CVS tree.
[modules/med.git] / src / MEDMEM / tests / testUCoordinate.cxx
1 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
19 //
20 //
21 //
22 //  File   : testUCoordinate.cxx
23 //  Module : MED
24
25 #include <cstdlib>
26 #include <cmath>
27 #include "utilities.h"
28
29 #include "MEDMEM_define.hxx"
30 #include "MEDMEM_Array.hxx"
31 #include "MEDMEM_Coordinate.hxx"
32 #include <string> 
33
34 using namespace std;
35 using namespace MEDMEM;
36
37 void usage(char * name)
38 {
39   cout << "    " << name << endl;
40 }
41
42 int main (int argc, char ** argv)
43 {
44  
45
46   if (argc < 1) usage(argv[0]);
47
48   const double pouieme = 0.009; 
49
50   cout << "COORDINATE Test" << endl;
51   cout << "---------------" << endl;
52
53   int SpaceDim = 3;
54   int NbOfNodes = 5;
55
56   string * noms = new string[3];
57   noms[0]=" X ";
58   noms[1]=" Y ";
59   noms[2]=" Z ";
60
61   string  units[3];
62   units[0]=" m ";
63   units[1]=" m ";
64   units[2]=" m ";
65
66   int * numbers=new int[5];
67   for (int i=0; i< 5; i++) numbers[i] =10+i;
68
69   MED_EN::medModeSwitch ModeFull=MED_EN::MED_FULL_INTERLACE;
70   MED_EN::medModeSwitch ModeNo=MED_EN::MED_NO_INTERLACE;
71   double coor[15] = {0,0,0,0,0,1,0,1,0,1,0,0,0.5,0.5,0.5} ;
72   ASSERT(SpaceDim*NbOfNodes == 15);
73
74
75   cout << "      - mode : MED_FULL_INTERLACE"  << endl;
76   cout << "      - dimension de l espace : " << SpaceDim << endl;
77   cout << "      - nombre de noeuds : " << NbOfNodes << endl;
78   
79   double * coor1 = new  double[SpaceDim*NbOfNodes];
80   for( int k=0 ; k<SpaceDim*NbOfNodes ; k++ ) 
81         coor1[k] = coor[k] ;
82
83   MEDARRAY<double>* CoordinateArray = new MEDARRAY<double>(coor1,SpaceDim,NbOfNodes,ModeFull);
84   COORDINATE mycoo;
85   try
86   {
87         mycoo.setCoordinates(CoordinateArray);
88   }
89   catch ( const std::exception &e )
90   {
91         cout << "-------------------------------" << endl;
92         cout << "pb avec setCoordinates" << endl;
93         cout << "-------------------------------" << endl;
94         MESSAGE( "catched exception : " << e.what() ) ;
95         return EXIT_FAILURE ;
96   }
97   catch (...)
98   {
99         cout << "-------------------------------" << endl;
100         cout << "pb avec setCoordinates" << endl;
101         cout << "-------------------------------" << endl;
102         return EXIT_FAILURE ;
103   };
104
105   //--------------------------------------------------------------------//
106   //                    Tests des methodes                              //
107   //                                                                    //
108   // - setCoordinatesNames                                              //
109   // - setCoordinatesUnits                                              //
110   // - setCoordinatesSystem                                             //
111   // - setNodesNumbers                                                  //
112   //                                                                    //
113   //--------------------------------------------------------------------//
114   try
115   {
116         mycoo.setCoordinatesNames(noms);
117   }
118   catch ( const std::exception &e )
119   {
120         cout << "-------------------------------" << endl;
121         cout << "pb avec setCoordinatesNames" << endl;
122         cout << "-------------------------------" << endl;
123         MESSAGE( "catched exception : " << e.what() ) ;
124         return EXIT_FAILURE ;
125   }
126   catch (...)
127   {
128         cout << "-------------------------------" << endl;
129         cout << "pb avec setCoordinatesNames" << endl;
130         cout << "-------------------------------" << endl;
131         return EXIT_FAILURE ;
132   };
133
134   try
135   {
136         mycoo.setCoordinatesUnits(units);
137   }
138   catch ( const std::exception &e )
139   {
140         cout << "-------------------------------" << endl;
141         cout << "pb avec setCoordinatesUnits" << endl;
142         cout << "-------------------------------" << endl;
143         MESSAGE( "catched exception : " << e.what() ) ;
144         return EXIT_FAILURE ;
145   }
146   catch (...)
147   {
148         cout << "-------------------------------" << endl;
149         cout << "pb avec setCoordinatesUnits" << endl;
150         cout << "-------------------------------" << endl;
151         return EXIT_FAILURE ;
152   };
153
154   try
155   {
156         mycoo.setCoordinatesSystem("cartesien");
157   }
158   catch ( const std::exception &e )
159   {
160         cout << "-------------------------------" << endl;
161         cout << "pb avec setCoordinatesSystem" << endl;
162         cout << "-------------------------------" << endl;
163         MESSAGE( "catched exception : " << e.what() ) ;
164         return EXIT_FAILURE ;
165   }
166   catch (...)
167   {
168         cout << "-------------------------------" << endl;
169         cout << "pb avec setCoordinatesSystem" << endl;
170         cout << "-------------------------------" << endl;
171         return EXIT_FAILURE ;
172   };
173
174   try
175   {
176         mycoo.setNodesNumbers(numbers);
177   }
178   catch ( const std::exception &e )
179   {
180         cout << "-------------------------------" << endl;
181         cout << "pb avec setNodesNumbers" << endl;
182         cout << "-------------------------------" << endl;
183         MESSAGE( "catched exception : " << e.what() ) ;
184         return EXIT_FAILURE ;
185   }
186   catch (...)
187   {
188         cout << "-------------------------------" << endl;
189         cout << "pb avec setNodesNumbers" << endl;
190         cout << "-------------------------------" << endl;
191         return EXIT_FAILURE ;
192   };
193   
194   //--------------------------------------------------------------------//
195   //                    Tests des methodes                              //
196   //                                                                    //
197   // - getCoordinatesNames                                              //
198   // - getCoordinatesUnits                                              //
199   // - getCoordinatesUnit                                               //
200   // - getCoordinatesSystem                                             //
201   // - getNodesNumbers                                                  //
202   //                                                                    //
203   //--------------------------------------------------------------------//
204
205   cout << endl << " Relecture des Coordonnees" << endl << endl;
206
207   try
208   {
209         cout << "  Le systeme est : " << mycoo.getCoordinatesSystem() << endl;
210   }
211   catch ( const std::exception &e )
212   {
213         cout << "-------------------------------" << endl;
214         cout << "pb avec getCoordinatesSystem" << endl;
215         cout << "-------------------------------" << endl;
216         MESSAGE( "catched exception : " << e.what() ) ;
217         return EXIT_FAILURE ;
218   }
219   catch (...)
220   {
221         cout << "-------------------------------" << endl;
222         cout << "pb avec getCoordinatesSystem" << endl;
223         cout << "-------------------------------" << endl;
224         return EXIT_FAILURE ;
225   };
226
227   const string * units2;
228   try
229   {
230         units2=mycoo.getCoordinatesUnits();
231         for (int axe = 0; axe < SpaceDim; axe++)
232         {
233                 try
234                 {
235                         string  verif = mycoo.getCoordinateUnit(axe+1);
236                         if (verif != units2[axe]) 
237                                 cout << "Pb avec les noms des axes" << endl;
238                 }
239                 catch ( const std::exception &e )
240                 {
241                         cout << "-------------------------" << endl;
242                         cout << "pb avec getCoordinateUnit" << endl;
243                         cout << "-------------------------" << endl;
244                         MESSAGE( "catched exception : " << e.what() ) ;
245                         return EXIT_FAILURE ;
246                 }
247                 catch (...)
248                 {
249                         cout << "-------------------------" << endl;
250                         cout << "pb avec getCoordinateUnit" << endl;
251                         cout << "-------------------------" << endl;
252                         return EXIT_FAILURE ;
253                 };
254         }
255   }
256   catch ( const std::exception &e )
257   {
258         cout << "---------------------------" << endl;
259         cout << "pb avec getCoordinatesUnits" << endl;
260         cout << "---------------------------" << endl;
261         MESSAGE( "catched exception : " << e.what() ) ;
262         return EXIT_FAILURE ;
263   }
264   catch (...)
265   {
266         cout << "---------------------------" << endl;
267         cout << "pb avec getCoordinatesUnits" << endl;
268         cout << "---------------------------" << endl;
269         return EXIT_FAILURE ;
270   };
271
272   const string * noms2;
273   try
274   {
275         noms2=mycoo.getCoordinatesNames();
276         for (int axe = 0; axe < SpaceDim; axe++)
277         {
278                 try
279                 {
280                         string  verif = mycoo.getCoordinateName(axe+1);
281                         if (verif != noms2[axe]) 
282                                 cout << "Pb avec les noms des axes" << endl;
283                 }
284                 catch ( const std::exception &e )
285                 {
286                         cout << "-------------------------" << endl;
287                         cout << "pb avec getCoordinateName" << endl;
288                         cout << "-------------------------" << endl;
289                         MESSAGE( "catched exception : " << e.what() ) ;
290                         return EXIT_FAILURE ;
291                 }
292                 catch (...)
293                 {
294                         cout << "-------------------------" << endl;
295                         cout << "pb avec getCoordinateName" << endl;
296                         cout << "-------------------------" << endl;
297                         return EXIT_FAILURE ;
298                 };
299         }
300   }
301   catch ( const std::exception &e )
302   {
303         cout << "---------------------------" << endl;
304         cout << "pb avec getCoordinatesNames" << endl;
305         cout << "---------------------------" << endl;
306         MESSAGE( "catched exception : " << e.what() ) ;
307         return EXIT_FAILURE ;
308   }
309   catch (...)
310   {
311         cout << "---------------------------" << endl;
312         cout << "pb avec getCoordinatesNames" << endl;
313         cout << "---------------------------" << endl;
314         return EXIT_FAILURE ;
315   };
316
317
318   try
319   {
320         const double * coor2=mycoo.getCoordinates(ModeFull);
321
322         for (int axe = 0; axe < SpaceDim; axe++)
323         {
324
325                 cout << "Coordonnees sur l'Axe : " <<  noms2[axe] ;
326                 cout << " dont l unite est " << units2[axe] << endl;
327
328                 try
329                 {
330                         const double * coor3=mycoo.getCoordinateAxis(axe+1);
331                         for (int num=0; num < NbOfNodes; num++)
332                         {
333                                 try
334                                 {
335                                         const double d = mycoo.getCoordinate(num + 1,axe+1);
336                                         cout << d <<" , ";
337                                         ASSERT(fabs(d - coor3[num])  < pouieme);
338                                         ASSERT(fabs(d - coor2[(num * SpaceDim)+axe]) < pouieme);
339                                         ASSERT(fabs(d - coor [(num * SpaceDim)+axe]) < pouieme);
340                                 }
341                                 catch ( const std::exception &e )
342                                 {
343                                         cout << "----------------------" << endl;
344                                         cout << "pb avec getCoordinates" << endl;
345                                         cout << "----------------------" << endl;
346                                         MESSAGE( "catched exception : " << e.what() ) ;
347                                         return EXIT_FAILURE ;
348                                 }
349                                 catch (...)
350                                 {
351                                         cout << "----------------------" << endl;
352                                         cout << "pb avec getCoordinates" << endl;
353                                         cout << "----------------------" << endl;
354                                         return EXIT_FAILURE ;
355                                 };
356                         }
357                         cout << endl;
358                 }
359                 catch ( const std::exception &e )
360                 {
361                         cout << "-------------------------" << endl;
362                         cout << "pb avec getCoordinateAxis" << endl;
363                         cout << "-------------------------" << endl;
364                         MESSAGE( "catched exception : " << e.what() ) ;
365                         return EXIT_FAILURE ;
366                 }
367                 catch (...)
368                 {
369                         cout << "-------------------------" << endl;
370                         cout << "pb avec getCoordinateAxis" << endl;
371                         cout << "-------------------------" << endl;
372                         return EXIT_FAILURE ;
373                 }
374         }
375   }
376   catch ( const std::exception &e )
377   {
378         cout << "----------------------" << endl;
379         cout << "pb avec getCoordinates" << endl;
380         cout << "----------------------" << endl;
381         MESSAGE( "catched exception : " << e.what() ) ;
382         return EXIT_FAILURE ;
383   }
384   catch (...)
385   {
386         cout << "----------------------" << endl;
387         cout << "pb avec getCoordinates" << endl;
388         cout << "----------------------" << endl;
389         return EXIT_FAILURE ;
390   };
391
392
393   delete [] noms ;
394   delete [] numbers;
395   delete [] coor1;
396
397   delete CoordinateArray ;
398
399   MESSAGE("FIN normale du traitement");
400   return EXIT_SUCCESS ;
401 }
402