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