1 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
22 // File : testUArray.cxx
26 #include <cstdlib> // pour l'acces à EXIT_SUCCESS et EXIT_FAILURE
27 #include "utilities.h"
28 #include "MEDMEM_Array.hxx"
29 using namespace MEDMEM;
31 void imprime(string titre,const int * myValues,const int * myOthers, int lignes, int colonnes)
33 cout << " " <<titre << endl<< endl;
34 cout << "Full Interlace : " << endl;
37 for (int i=0; i<lignes; i++)
40 for (int k=0; k< colonnes; k++)
42 cout << myValues[k + i * colonnes]<< " " ;
49 cout << "Pointeur Null : pas de valeur" << endl << endl;
52 cout << "No Interlace : " << endl;
56 for (int k=0; k< colonnes; k++)
59 for (int i=0; i<lignes; i++)
61 cout << myOthers[i + k*lignes]<< " " ;
68 cout << "Pointeur Null : pas de valeur" << endl << endl;
73 int main (int argc, char ** argv)
76 /* ---------------------------------------------------------- */
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 /* ---------------------------------------------------------- */
86 int SpaceDimension = 3;
87 int NumberOfNodes = 4;
91 MEDARRAY<int> * myArrayfull= new MEDARRAY<int>(SpaceDimension,NumberOfNodes,MED_FULL_INTERLACE);
92 ASSERT(myArrayfull != NULL);
94 const int * myValues = myArrayfull->get(MED_FULL_INTERLACE);
95 ASSERT(myValues!= NULL);
97 for (int i=0; i<NumberOfNodes; i++)
99 for (int k=0; k<SpaceDimension; k++)
101 //myValues[i* SpaceDimension +k]=i + 1;
102 myArrayfull->setIJ(i+1,k+1,i+1) ;
106 const int * myOthers = myArrayfull->get(MED_NO_INTERLACE) ;
107 ASSERT(myOthers != NULL);
109 imprime("Initialisation full interlace (xi=yi=zi=i+1)",myValues,myOthers,NumberOfNodes,SpaceDimension);
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);
116 for (int k=0; k<SpaceDimension; k++)
118 for (int i=0; i<NumberOfNodes; i++)
120 //myValuesno[i +k*NumberOfNodes]=k + 1;
121 myArrayno->setIJ(i+1,k+1,k+1) ;
125 const int * myOthersno = myArrayno->get(MED_FULL_INTERLACE) ;
126 ASSERT(myOthersno != NULL);
128 imprime("Initialisation no interlace (xi=yi=zi=i+1)",myOthersno,myValuesno,NumberOfNodes,SpaceDimension);
131 /* ---------------------------------------------------------- */
133 /* Tests des Fonctions Set */
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 /* ---------------------------------------------------------- */
142 int * myNewLine = new int[SpaceDimension];
143 for (int i = 0; i < SpaceDimension; i++)
144 myNewLine[i] = myValues[i] * 100;
147 myArrayfull->setI(1, myNewLine);
149 catch ( const std::exception &e )
151 cout << "--------------" << endl;
152 cout << " Pb au setI " << endl;
153 cout << "--------------" << endl;
154 MESSAGE( "catched exception : " << e.what() ) ;
155 return EXIT_FAILURE ;
159 cout << "---------------" << endl;
160 cout << " Pb au setI " << endl;
161 cout << "---------------" << endl;
165 imprime("1er element : coordonnees à 100",myValues,myOthers,NumberOfNodes,SpaceDimension);
167 int * myNewCol = new int[NumberOfNodes];
168 for (int i = 0; i < NumberOfNodes; i++)
172 myArrayno->setJ(1, myNewCol);
174 catch ( const std::exception &e )
176 cout << "--------------" << endl;
177 cout << " Pb au setJ " << endl;
178 cout << "--------------" << endl;
179 MESSAGE( "catched exception : " << e.what() ) ;
180 return EXIT_FAILURE ;
184 cout << "---------------" << endl;
185 cout << " Pb au setJ " << endl;
186 cout << "---------------" << endl;
190 imprime("1eres coordonnees à 100",myOthersno,myValuesno,NumberOfNodes,SpaceDimension);
194 myArrayfull->setIJ(1,2,1992);
196 catch ( const std::exception &e )
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 ;
206 cout << "-----------------------------" << endl;
207 cout << " Pb au setIJ() de 1 , 2 " << endl;
208 cout << "-----------------------------" << endl;
211 imprime("1er element : 2ieme coordonnee = 1992",myValues,myOthers,NumberOfNodes,SpaceDimension);
216 myArrayno->setIJ(1,2,1992);
218 catch ( const std::exception &e )
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 ;
228 cout << "-----------------------------" << endl;
229 cout << " Pb au setIJ() de 1 , 2 " << endl;
230 cout << "-----------------------------" << endl;
233 imprime("1er element : 2ieme coordonnee = 1992",myValues,myOthers,NumberOfNodes,SpaceDimension);
235 int * mynewvalues= new int [ NumberOfNodes*SpaceDimension ];
236 for (int i=0; i<NumberOfNodes*SpaceDimension; i++)
242 myArrayfull->set(MED_FULL_INTERLACE,mynewvalues);
243 myValues = myArrayfull->get(MED_FULL_INTERLACE);
244 myOthers = myArrayfull->get(MED_NO_INTERLACE);
246 catch ( const std::exception &e )
248 cout << "-------------" << endl;
249 cout << " Pb au set " << endl;
250 cout << "-------------" << endl;
251 MESSAGE( "catched exception : " << e.what() ) ;
252 return EXIT_FAILURE ;
256 cout << "--------------" << endl;
257 cout << " Pb au set " << endl;
258 cout << "--------------" << endl;
260 imprime("remise valeur a i sur myArrayfull med full interlace",myValues,myOthers,NumberOfNodes,SpaceDimension);
264 myArrayno->set(MED_FULL_INTERLACE,mynewvalues);
265 myValuesno = myArrayfull->get(MED_FULL_INTERLACE);
268 catch ( const std::exception &e )
270 cout << "-------------" << endl;
271 cout << " Pb au set " << endl;
272 cout << "-------------" << endl;
273 MESSAGE( "catched exception : " << e.what() ) ;
274 return EXIT_FAILURE ;
278 cout << "--------------" << endl;
279 cout << " Pb au setI " << endl;
280 cout << "--------------" << endl;
282 imprime("set full interlace de myArrayno",myValuesno,myOthersno,NumberOfNodes,SpaceDimension);
284 /* ---------------------------------------------------------- */
286 /* Tests des constructeurs */
287 /* Tests des Fonctions Get */
290 /* ---------------------------------------------------------- */
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);
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);
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);
306 imprime("tableau cible apres destruction tableau source",myValues,myOthers,NumberOfNodes,SpaceDimension);
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);
313 myArrayfull->setIJ(1,2,18);
314 imprime("change valeur tableau source, impression tableau cible",sharevalues,shareno,NumberOfNodes,SpaceDimension);
316 myArrayShare2->setIJ(1,2,19);
317 imprime("change valeur tableau cible, impression tableau source",myValues,myOthers,NumberOfNodes,SpaceDimension);
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);
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);
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);
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);
339 delete [] mynewvalues;
341 delete myArrayShare2;
342 delete myArrayShare3;
343 MESSAGE("FIN NORMALE DU TRAITEMENT");
344 return EXIT_SUCCESS ;
347 inline medModeSwitch getMode() const ;