]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/tests/testUArray.cxx.ok
Salome HOME
correct small problem from the version in the MedFileV2_2 branch.
[modules/med.git] / src / MEDMEM / tests / testUArray.cxx.ok
1 #include <cstdlib>      // pour l'acces à EXIT_SUCCESS et EXIT_FAILURE
2 #include "utilities.h"
3 #include "MEDMEM_Array.hxx"
4 using namespace MEDMEM;
5
6 int main (int argc, char ** argv) 
7 {
8
9   int SpaceDimension = 3;
10   int NumberOfNodes  = 4; 
11   MEDARRAY<int> * myArray = new MEDARRAY<int>(SpaceDimension,NumberOfNodes,MED_FULL_INTERLACE) ;
12   ASSERT(myArray != NULL);
13
14   int * value = myArray->get(MED_FULL_INTERLACE) ;
15   ASSERT(value!= NULL);
16
17   for (int i=0; i<SpaceDimension*NumberOfNodes; i++)
18     value[i]=i ; 
19   
20   int leadingValue;
21   try
22   {
23         leadingValue = myArray->getLeadingValue() ;
24         ASSERT (leadingValue == SpaceDimension);
25   }
26   catch ( const std::exception &e )
27   {
28         cout << "-------------------------------" << endl;
29         cout << "   Pb au getLeadingValue()     " << endl;
30         cout << "-------------------------------" << endl;
31         MESSAGE( "catched exception : " << e.what() ) ;
32         return EXIT_FAILURE ;
33   }
34   catch (...)
35   {
36         cout << "-------------------------------" << endl;
37         cout << "   Pb au getLeadingValue()     " << endl;
38         cout << "-------------------------------" << endl;
39         return EXIT_FAILURE ;
40   }
41
42   int lengthValue;
43   try
44   {
45         lengthValue = myArray->getLengthValue() ;
46         ASSERT(lengthValue == NumberOfNodes)
47   }
48   catch ( const std::exception &e )
49   {
50         cout << "-------------------------------" << endl;
51         cout << "   Pb au getLengthValue()     " << endl;
52         cout << "-------------------------------" << endl;
53         MESSAGE( "catched exception : " << e.what() ) ;
54         return EXIT_FAILURE ;
55   }
56   catch (...)
57   {
58         cout << "-------------------------------" << endl;
59         cout << "   Pb au getLengthValue()     " << endl;
60         cout << "-------------------------------" << endl;
61         return EXIT_FAILURE ;
62   }
63
64   cout << "Show all using getI and full interlace  :" << endl;
65   for (int i=1; i<=lengthValue; i++) 
66   {
67         try
68         {
69                 int * node = myArray->getI(MED_FULL_INTERLACE,i) ;
70                 cout << " - " ;
71                 for (int j=0;j<leadingValue;j++)
72                         cout << node[j] << " " ;
73                 cout << endl ;
74         }
75         catch ( const std::exception &e )
76         {
77                 cout << "-------------------------------" << endl;
78                 cout << "   Pb au getI()  valeur de i " << i << endl;
79                 cout << "-------------------------------" << endl;
80                 MESSAGE( "catched exception : " << e.what() ) ;
81                 return EXIT_FAILURE ;
82         }
83         catch (...)
84         {
85                 cout << "-------------------------------" << endl;
86                 cout << "   Pb au getI()  valeur de i " << i << endl;
87                 cout << "-------------------------------" << endl;
88                 return EXIT_FAILURE ;
89         }
90   }
91
92   cout << "Show all using getI and no interlace  :" << endl;
93   for (int i=1; i<=leadingValue; i++) 
94   {
95         try
96         {
97                 int * node = myArray->getI(MED_NO_INTERLACE,i) ;
98                 cout << " - " ;
99                 for (int j=0;j<lengthValue;j++)
100                         cout << node[j] << " " ;
101                 cout << endl ;
102         }
103         catch ( const std::exception &e )
104         {
105                 cout << "-------------------------------" << endl;
106                 cout << "   Pb au getI()  valeur de i " << i << endl;
107                 cout << "-------------------------------" << endl;
108                 MESSAGE( "catched exception : " << e.what() ) ;
109                 return EXIT_FAILURE ;
110         }
111         catch (...)
112         {
113                 cout << "-------------------------------" << endl;
114                 cout << "   Pb au getI()  valeur de i " << i << endl;
115                 cout << "-------------------------------" << endl;
116                 return EXIT_FAILURE ;
117         }
118   }
119
120   cout << "Show all using getIJ :" << endl;
121   for (int i=1; i<=lengthValue ; i++) 
122   {
123         int j;
124         try
125         {
126                 cout << " - " ;
127                 for (j=1;j<leadingValue+1;j++)
128                         cout << myArray->getIJ(i,j) << " " ;
129                 cout << endl ;
130         }
131         catch ( const std::exception &e )
132         {
133                 cout << "-------------------------------" << endl;
134                 cout << "   Pb au getIJ()  i " << i << " j " << j << endl;
135                 cout << "-------------------------------" << endl;
136                 MESSAGE( "catched exception : " << e.what() ) ;
137                 return EXIT_FAILURE ;
138         }
139         catch (...)
140         {
141                 cout << "-------------------------------" << endl;
142                 cout << "   Pb au getIJ()  i " << i << " j " << j << endl;
143                 cout << "-------------------------------" << endl;
144                 return EXIT_FAILURE ;
145         }
146   }
147
148   cout << "Show all using get and MED_NO_INTERLACE :" << endl;
149   try
150   {
151         int * NoInterlaceArray = myArray->get(MED_NO_INTERLACE) ;
152         for (int i=0; i<lengthValue ; i++) 
153         {
154                 cout << " - " ;
155                 for (int j=0;j<leadingValue;j++)
156                         cout << NoInterlaceArray[j*lengthValue+i] << " " ;
157                 cout << endl ;
158         }
159   }
160   catch ( const std::exception &e )
161   {
162         cout << "-------------------------------" << endl;
163         cout << "   Pb au get   " << endl;
164         cout << "-------------------------------" << endl;
165         MESSAGE( "catched exception : " << e.what() ) ;
166         return EXIT_FAILURE ;
167   }
168   catch (...)
169   {
170         cout << "---------------" << endl;
171         cout << "   Pb au get   " << endl;
172         cout << "---------------" << endl;
173         return EXIT_FAILURE ;
174   }
175
176
177   cout << endl << endl << "Tests des fonctions Set " << endl;
178
179   int * myNewInt = new int[SpaceDimension*NumberOfNodes];
180   for (int i=0; i<SpaceDimension*NumberOfNodes; i++)
181   {
182         myNewInt[i]=i*10 ; 
183   }
184
185   try
186   {
187         myArray->set(MED_FULL_INTERLACE, myNewInt);
188   }
189   catch ( const std::exception &e )
190   {
191         cout << "-------------------------------" << endl;
192         cout << "   Pb au set   " << endl;
193         cout << "-------------------------------" << endl;
194         MESSAGE( "catched exception : " << e.what() ) ;
195         return EXIT_FAILURE ;
196   }
197   catch (...)
198   {
199         cout << "---------------" << endl;
200         cout << "   Pb au set   " << endl;
201         cout << "---------------" << endl;
202         return EXIT_FAILURE ;
203    }
204   delete [] myNewInt;
205
206   cout << "Nouvelles valeurs (x10) : get avec Full interlace : " << endl;
207   int * myNewValue;
208   try
209   {
210          myNewValue = myArray->get(MED_FULL_INTERLACE) ;
211          ASSERT(myNewValue!= NULL);
212   }
213   catch ( const std::exception &e )
214   {
215         cout << "-----------------" << endl;
216         cout << "   Pb au get     " << endl;
217         cout << "-----------------" << endl;
218         MESSAGE( "catched exception : " << e.what() ) ;
219         return EXIT_FAILURE ;
220   }
221   catch (...)
222   {
223         cout << "---------------" << endl;
224         cout << "   Pb au get   " << endl;
225         cout << "---------------" << endl;
226   }
227
228   cout << " - ";
229   for (int i=0; i<SpaceDimension*NumberOfNodes; i++)
230         cout << myNewValue[i]<< " " ; 
231   cout << endl;
232
233
234   int * myNewLine = new int[SpaceDimension];
235   for (int i = 0; i < SpaceDimension; i++) 
236         myNewLine[i] = i * 100;
237
238   try
239   {
240         myArray->setI(MED_FULL_INTERLACE, 1, myNewLine);
241   }
242   catch ( const std::exception &e )
243   {
244         cout << "-------------------------------" << endl;
245         cout << "   Pb au getLengthValue()     " << endl;
246         cout << "-------------------------------" << endl;
247         MESSAGE( "catched exception : " << e.what() ) ;
248         return EXIT_FAILURE ;
249   }
250   catch (...)
251   {
252         cout << "---------------" << endl;
253         cout << "   Pb au setI   " << endl;
254         cout << "---------------" << endl;
255   }
256   delete [] myNewLine;
257
258   try
259   {
260          myNewValue = myArray->getI(MED_FULL_INTERLACE,1) ;
261          ASSERT(myNewValue!= NULL);
262   }
263   catch ( const std::exception &e )
264   {
265         cout << "-------------------------------" << endl;
266         cout << "   Pb au getLengthValue()     " << endl;
267         cout << "-------------------------------" << endl;
268         MESSAGE( "catched exception : " << e.what() ) ;
269         return EXIT_FAILURE ;
270   }
271   catch (...)
272   {
273         cout << "---------------" << endl;
274         cout << "   Pb au getI  " << endl;
275         cout << "---------------" << endl;
276   }
277
278   cout << endl << " Nouvelles valeurs (x100)  sur la 1ere ligne: get avec Full interlace : ";
279   cout << endl << " - ";
280   for (int i=0; i<SpaceDimension; i++)
281         cout << myNewValue[i]<< " " ; 
282   cout << endl;
283
284   try
285   {
286         myArray->setIJ(1,1,1992);
287   }
288   catch ( const std::exception &e )
289   {
290         cout << "---------------------------" << endl;
291         cout << "   Pb au setIJ()  de 1 , 1 "  << endl;
292         cout << "---------------------------" << endl;
293         MESSAGE( "catched exception : " << e.what() ) ;
294         return EXIT_FAILURE ;
295   }
296   catch (...)
297   {
298         cout << "-----------------------------" << endl;
299         cout << "   Pb au setIJ()  de 1 , 1 "  << endl;
300         cout << "-----------------------------" << endl;
301   }
302
303   cout << "Nouvelle valeur avec setIJ et getIJ" << endl;
304   cout << " - " << myArray->getIJ(1,1) << endl;
305
306   delete myArray;
307   return EXIT_SUCCESS ;
308 }
309   
310 /*
311   inline medModeSwitch getMode() const ;
312  
313 */