]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/tests/testUArray.cxx
Salome HOME
update after merging trhe branches CEA_V3_0_x, OCC_V3_1_0_a1_x, and the main
[modules/med.git] / src / MEDMEM / tests / testUArray.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   : testUArray.cxx
23 //  Module : MED
24
25 #include <cstdlib>      // pour l'acces à EXIT_SUCCESS et EXIT_FAILURE
26 #include "MEDMEM_Utilities.hxx"
27 #include "MEDMEM_Array.hxx"
28
29 using namespace std;
30 using namespace MEDMEM;
31
32 void imprime(string titre,const int * myValues,const int * myOthers, int lignes, int colonnes)
33 {
34   cout << "             " <<titre << endl<< endl;
35   cout << "Full Interlace : " << endl;
36   if (myValues != NULL)
37   {
38         for (int i=0; i<lignes; i++)
39         {
40                 cout << " - ";
41                 for (int k=0; k< colonnes; k++)
42                 {
43                         cout << myValues[k + i * colonnes]<< " " ; 
44                 }
45                 cout << endl;
46         }
47   }
48   else
49   {
50                 cout << "Pointeur Null : pas de valeur" << endl << endl;
51   }
52   cout << endl;
53   cout << "No Interlace : " << endl;
54
55   if (myOthers != NULL)
56   {
57         for (int k=0; k< colonnes; k++)
58         {
59                 cout << " - ";
60                 for (int i=0; i<lignes; i++)
61                 {
62                         cout << myOthers[i + k*lignes]<< " " ; 
63                 }
64                 cout << endl;
65         }
66   }
67   else
68   {
69                 cout << "Pointeur Null : pas de valeur" << endl << endl;
70   }
71   cout << endl;
72 }
73
74 int main (int argc, char ** argv) 
75 {
76
77   /* ---------------------------------------------------------- */
78   /*                                                            */
79   /*                    INITIALISATION                          */
80   /*                                                            */
81   /* - constructeur new MEDARRAY<int>(int,int,mode)             */
82   /* - get sur le pointeur MED_FULL_INTERLACE                   */
83   /* - initialisation des valeurs (coordonnées ieme elt = I+1)  */
84   /* - get sur le pointeur MED_NO_INTERLACE                     */
85   /* ---------------------------------------------------------- */
86
87   int SpaceDimension = 3;
88   int NumberOfNodes  = 4; 
89
90
91   
92   MEDARRAY<int> * myArrayfull= new MEDARRAY<int>(SpaceDimension,NumberOfNodes,MED_EN::MED_FULL_INTERLACE);
93   ASSERT(myArrayfull != NULL);
94
95   const int * myValues = myArrayfull->get(MED_EN::MED_FULL_INTERLACE);
96   ASSERT(myValues!= NULL);
97
98   for (int i=0; i<NumberOfNodes; i++)
99   {
100         for (int k=0; k<SpaceDimension; k++)
101         {
102           //myValues[i* SpaceDimension +k]=i + 1; 
103           myArrayfull->setIJ(i+1,k+1,i+1) ;
104         }
105   }
106   
107   const int * myOthers = myArrayfull->get(MED_EN::MED_NO_INTERLACE) ;
108   ASSERT(myOthers != NULL);
109   
110   imprime("Initialisation full interlace (xi=yi=zi=i+1)",myValues,myOthers,NumberOfNodes,SpaceDimension);
111
112   MEDARRAY<int> * myArrayno= new MEDARRAY<int>(SpaceDimension,NumberOfNodes,MED_EN::MED_NO_INTERLACE);
113   ASSERT(myArrayno != NULL);
114   const int * myValuesno = myArrayno->get(MED_EN::MED_NO_INTERLACE);
115   ASSERT(myValuesno!= NULL);
116
117   for (int k=0; k<SpaceDimension; k++)
118   {
119         for (int i=0; i<NumberOfNodes; i++)
120         {
121           //myValuesno[i +k*NumberOfNodes]=k + 1; 
122           myArrayno->setIJ(i+1,k+1,k+1) ;
123         }
124   }
125   
126   const int * myOthersno = myArrayno->get(MED_EN::MED_FULL_INTERLACE) ;
127   ASSERT(myOthersno != NULL);
128
129   imprime("Initialisation no interlace (xi=yi=zi=i+1)",myOthersno,myValuesno,NumberOfNodes,SpaceDimension);
130
131
132   /* ---------------------------------------------------------- */
133   /*                                                            */
134   /*                    Tests des Fonctions Set                 */
135   /*                                                            */
136   /* - setI sur l'element 1 avec des coordonnees a 100          */
137   /* - setJ sur l'element 1 avec des coordonnees a 100          */
138   /* - setIJ sur (1,2) avec une coordonnee = 1992               */
139   /* - set   avec l ensemble des coordonnes remises à i         */
140   /* ---------------------------------------------------------- */
141
142
143   int * myNewLine = new int[SpaceDimension];
144   for (int i = 0; i < SpaceDimension; i++) 
145         myNewLine[i] = myValues[i] * 100;
146   try
147   {
148         myArrayfull->setI(1, myNewLine);
149   }
150   catch ( const std::exception &e )
151   {
152         cout << "--------------" << endl;
153         cout << "   Pb au setI " << endl;
154         cout << "--------------" << endl;
155         MESSAGE( "catched exception : " << e.what() ) ;
156         return EXIT_FAILURE ;
157   }
158   catch (...)
159   {
160         cout << "---------------" << endl;
161         cout << "   Pb au setI   " << endl;
162         cout << "---------------" << endl;
163   }
164
165   delete [] myNewLine;
166   imprime("1er element : coordonnees à 100",myValues,myOthers,NumberOfNodes,SpaceDimension);
167
168   int * myNewCol = new int[NumberOfNodes];
169   for (int i = 0; i < NumberOfNodes; i++) 
170         myNewCol[i] = 100;
171   try
172   {
173         myArrayno->setJ(1, myNewCol);
174   }
175   catch ( const std::exception &e )
176   {
177         cout << "--------------" << endl;
178         cout << "   Pb au setJ " << endl;
179         cout << "--------------" << endl;
180         MESSAGE( "catched exception : " << e.what() ) ;
181         return EXIT_FAILURE ;
182   }
183   catch (...)
184   {
185         cout << "---------------" << endl;
186         cout << "   Pb au setJ   " << endl;
187         cout << "---------------" << endl;
188   }
189
190   delete [] myNewCol;
191   imprime("1eres  coordonnees à 100",myOthersno,myValuesno,NumberOfNodes,SpaceDimension);
192
193   try
194   {
195         myArrayfull->setIJ(1,2,1992);
196   }
197   catch ( const std::exception &e )
198   {
199         cout << "---------------------------" << endl;
200         cout << "   Pb au setIJ()  de 1 , 2 "  << endl;
201         cout << "---------------------------" << endl;
202         MESSAGE( "catched exception : " << e.what() ) ;
203         return EXIT_FAILURE ;
204   }
205   catch (...)
206   {
207         cout << "-----------------------------" << endl;
208         cout << "   Pb au setIJ()  de 1 , 2 "  << endl;
209         cout << "-----------------------------" << endl;
210   }
211
212   imprime("1er element : 2ieme coordonnee = 1992",myValues,myOthers,NumberOfNodes,SpaceDimension);
213
214
215   try
216   {
217         myArrayno->setIJ(1,2,1992);
218   }
219   catch ( const std::exception &e )
220   {
221         cout << "---------------------------" << endl;
222         cout << "   Pb au setIJ()  de 1 , 2 "  << endl;
223         cout << "---------------------------" << endl;
224         MESSAGE( "catched exception : " << e.what() ) ;
225         return EXIT_FAILURE ;
226   }
227   catch (...)
228   {
229         cout << "-----------------------------" << endl;
230         cout << "   Pb au setIJ()  de 1 , 2 "  << endl;
231         cout << "-----------------------------" << endl;
232   }
233
234   imprime("1er element : 2ieme coordonnee = 1992",myValues,myOthers,NumberOfNodes,SpaceDimension);
235
236   int * mynewvalues= new int [ NumberOfNodes*SpaceDimension ];
237   for (int i=0; i<NumberOfNodes*SpaceDimension; i++)
238   {
239         mynewvalues[i]=i;
240   }
241   try
242   {
243         myArrayfull->set(MED_EN::MED_FULL_INTERLACE,mynewvalues);
244         myValues = myArrayfull->get(MED_EN::MED_FULL_INTERLACE);
245         myOthers = myArrayfull->get(MED_EN::MED_NO_INTERLACE);
246   }
247   catch ( const std::exception &e )
248   {
249         cout << "-------------" << endl;
250         cout << "   Pb au set "  << endl;
251         cout << "-------------" << endl;
252         MESSAGE( "catched exception : " << e.what() ) ;
253         return EXIT_FAILURE ;
254   }
255   catch (...)
256   {
257         cout << "--------------" << endl;
258         cout << "   Pb au set "  << endl;
259         cout << "--------------" << endl;
260   }
261   imprime("remise valeur a i sur myArrayfull med full interlace",myValues,myOthers,NumberOfNodes,SpaceDimension);
262
263   try
264   {
265         myArrayno->set(MED_EN::MED_FULL_INTERLACE,mynewvalues);
266         myValuesno = myArrayfull->get(MED_EN::MED_FULL_INTERLACE);
267         myOthersno = NULL;
268   }
269   catch ( const std::exception &e )
270   {
271         cout << "-------------" << endl;
272         cout << "   Pb au set "  << endl;
273         cout << "-------------" << endl;
274         MESSAGE( "catched exception : " << e.what() ) ;
275         return EXIT_FAILURE ;
276   }
277   catch (...)
278   {
279         cout << "--------------" << endl;
280         cout << "   Pb au setI "  << endl;
281         cout << "--------------" << endl;
282   }
283   imprime("set full interlace de myArrayno",myValuesno,myOthersno,NumberOfNodes,SpaceDimension);
284
285   /* ---------------------------------------------------------- */
286   /*                                                            */
287   /*                Tests des constructeurs                     */
288   /*                Tests des Fonctions Get                     */
289   /*                                                            */
290   /*                                                            */
291   /* ---------------------------------------------------------- */
292
293   MEDARRAY<int> * myArrayShare = new MEDARRAY<int>( *myArrayfull);
294   const int * sharevalues = myArrayShare->get(MED_EN::MED_FULL_INTERLACE );
295   const int * shareno = myArrayShare->get(MED_EN::MED_NO_INTERLACE);
296   imprime("test contructeur par recopie non profonde",sharevalues,shareno,NumberOfNodes,SpaceDimension);
297
298   myArrayfull->setIJ(1,2,1992);
299   ASSERT(myArrayShare->getIJ(1,2) == 1992);
300   imprime("change valeur tableau source, impression tableau cible",sharevalues,shareno,NumberOfNodes,SpaceDimension);
301
302   myArrayShare->setIJ(1,2,1995);
303   ASSERT(myArrayfull->getIJ(1,2) == 1995);
304   imprime("change valeur tableau cible, impression tableau source",myValues,myOthers,NumberOfNodes,SpaceDimension);
305
306   delete myArrayShare;
307   imprime("tableau cible apres destruction tableau source",myValues,myOthers,NumberOfNodes,SpaceDimension);
308
309   MEDARRAY<int> * myArrayShare2 = new MEDARRAY<int>( *myArrayfull,true);
310   sharevalues = myArrayShare2->get(MED_EN::MED_FULL_INTERLACE );
311   shareno = myArrayShare2->get(MED_EN::MED_NO_INTERLACE );
312   imprime("test contructeur par recopie profonde",sharevalues,shareno,NumberOfNodes,SpaceDimension);
313
314   myArrayfull->setIJ(1,2,18);
315   imprime("change valeur tableau source, impression tableau cible",sharevalues,shareno,NumberOfNodes,SpaceDimension);
316
317   myArrayShare2->setIJ(1,2,19);
318   imprime("change valeur tableau cible, impression tableau source",myValues,myOthers,NumberOfNodes,SpaceDimension);
319
320   myArrayno->set(MED_EN::MED_NO_INTERLACE,mynewvalues);
321   myArrayno->setIJ(2,1,1);
322   myValuesno = myArrayno->get(MED_EN::MED_NO_INTERLACE);
323   myOthersno = myArrayno->get(MED_EN::MED_FULL_INTERLACE);
324   imprime("Initialisation no interlace (0...11)",myOthersno,myValuesno,NumberOfNodes,SpaceDimension);
325
326   MEDARRAY<int> * myArrayShare3 = new MEDARRAY<int>( *myArrayno);
327   sharevalues = myArrayShare3->get(MED_EN::MED_FULL_INTERLACE);
328   shareno = myArrayShare3->get(MED_EN::MED_NO_INTERLACE);
329   imprime("test contructeur par recopie non profonde",sharevalues,shareno,NumberOfNodes,SpaceDimension);
330
331   myArrayno->setIJ(1,2,1992);
332   ASSERT(myArrayShare3->getIJ(1,2) == 1992);
333   imprime("change valeur tableau source, impression tableau cible",sharevalues,shareno,NumberOfNodes,SpaceDimension);
334
335   myArrayShare3->setIJ(1,2,1995);
336   ASSERT(myArrayno->getIJ(1,2) == 1995);
337   imprime("change valeur tableau cible, impression tableau source",myValuesno,myOthersno,NumberOfNodes,SpaceDimension);
338
339   delete myArrayno;
340   delete [] mynewvalues;
341   delete myArrayfull;
342   delete myArrayShare2;
343   delete myArrayShare3;
344   MESSAGE("FIN NORMALE DU TRAITEMENT");
345   return EXIT_SUCCESS ;
346 }
347 /*
348   inline medModeSwitch getMode() const ;
349 */