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