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