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"
30 void imprime(string titre,const int * myValues,const int * myOthers, int lignes, int colonnes)
32 cout << " " <<titre << endl<< endl;
33 cout << "Full Interlace : " << endl;
36 for (int i=0; i<lignes; i++)
39 for (int k=0; k< colonnes; k++)
41 cout << myValues[k + i * colonnes]<< " " ;
48 cout << "Pointeur Null : pas de valeur" << endl << endl;
51 cout << "No Interlace : " << endl;
55 for (int k=0; k< colonnes; k++)
58 for (int i=0; i<lignes; i++)
60 cout << myOthers[i + k*lignes]<< " " ;
67 cout << "Pointeur Null : pas de valeur" << endl << endl;
72 int main (int argc, char ** argv)
75 /* ---------------------------------------------------------- */
79 /* - constructeur new MEDARRAY<int>(int,int,mode) */
80 /* - get sur le pointeur MED_FULL_INTERLACE */
81 /* - initialisation des valeurs (coordonnées ieme elt = I+1) */
82 /* - get sur le pointeur MED_NO_INTERLACE */
83 /* ---------------------------------------------------------- */
85 int SpaceDimension = 3;
86 int NumberOfNodes = 4;
90 MEDARRAY<int> * myArrayfull= new MEDARRAY<int>(SpaceDimension,NumberOfNodes,MED_FULL_INTERLACE);
91 ASSERT(myArrayfull != NULL);
93 const int * myValues = myArrayfull->get(MED_FULL_INTERLACE);
94 ASSERT(myValues!= NULL);
96 for (int i=0; i<NumberOfNodes; i++)
98 for (int k=0; k<SpaceDimension; k++)
100 //myValues[i* SpaceDimension +k]=i + 1;
101 myArrayfull->setIJ(i+1,k+1,i+1) ;
105 const int * myOthers = myArrayfull->get(MED_NO_INTERLACE) ;
106 ASSERT(myOthers != NULL);
108 imprime("Initialisation full interlace (xi=yi=zi=i+1)",myValues,myOthers,NumberOfNodes,SpaceDimension);
110 MEDARRAY<int> * myArrayno= new MEDARRAY<int>(SpaceDimension,NumberOfNodes,MED_NO_INTERLACE);
111 ASSERT(myArrayno != NULL);
112 const int * myValuesno = myArrayno->get(MED_NO_INTERLACE);
113 ASSERT(myValuesno!= NULL);
115 for (int k=0; k<SpaceDimension; k++)
117 for (int i=0; i<NumberOfNodes; i++)
119 //myValuesno[i +k*NumberOfNodes]=k + 1;
120 myArrayno->setIJ(i+1,k+1,k+1) ;
124 const int * myOthersno = myArrayno->get(MED_FULL_INTERLACE) ;
125 ASSERT(myOthersno != NULL);
127 imprime("Initialisation no interlace (xi=yi=zi=i+1)",myOthersno,myValuesno,NumberOfNodes,SpaceDimension);
130 /* ---------------------------------------------------------- */
132 /* Tests des Fonctions Set */
134 /* - setI sur l'element 1 avec des coordonnees a 100 */
135 /* - setJ sur l'element 1 avec des coordonnees a 100 */
136 /* - setIJ sur (1,2) avec une coordonnee = 1992 */
137 /* - set avec l ensemble des coordonnes remises à i */
138 /* ---------------------------------------------------------- */
141 int * myNewLine = new int[SpaceDimension];
142 for (int i = 0; i < SpaceDimension; i++)
143 myNewLine[i] = myValues[i] * 100;
146 myArrayfull->setI(1, myNewLine);
148 catch ( const std::exception &e )
150 cout << "--------------" << endl;
151 cout << " Pb au setI " << endl;
152 cout << "--------------" << endl;
153 MESSAGE( "catched exception : " << e.what() ) ;
154 return EXIT_FAILURE ;
158 cout << "---------------" << endl;
159 cout << " Pb au setI " << endl;
160 cout << "---------------" << endl;
164 imprime("1er element : coordonnees à 100",myValues,myOthers,NumberOfNodes,SpaceDimension);
166 int * myNewCol = new int[NumberOfNodes];
167 for (int i = 0; i < NumberOfNodes; i++)
171 myArrayno->setJ(1, myNewCol);
173 catch ( const std::exception &e )
175 cout << "--------------" << endl;
176 cout << " Pb au setJ " << endl;
177 cout << "--------------" << endl;
178 MESSAGE( "catched exception : " << e.what() ) ;
179 return EXIT_FAILURE ;
183 cout << "---------------" << endl;
184 cout << " Pb au setJ " << endl;
185 cout << "---------------" << endl;
189 imprime("1eres coordonnees à 100",myOthersno,myValuesno,NumberOfNodes,SpaceDimension);
193 myArrayfull->setIJ(1,2,1992);
195 catch ( const std::exception &e )
197 cout << "---------------------------" << endl;
198 cout << " Pb au setIJ() de 1 , 2 " << endl;
199 cout << "---------------------------" << endl;
200 MESSAGE( "catched exception : " << e.what() ) ;
201 return EXIT_FAILURE ;
205 cout << "-----------------------------" << endl;
206 cout << " Pb au setIJ() de 1 , 2 " << endl;
207 cout << "-----------------------------" << endl;
210 imprime("1er element : 2ieme coordonnee = 1992",myValues,myOthers,NumberOfNodes,SpaceDimension);
215 myArrayno->setIJ(1,2,1992);
217 catch ( const std::exception &e )
219 cout << "---------------------------" << endl;
220 cout << " Pb au setIJ() de 1 , 2 " << endl;
221 cout << "---------------------------" << endl;
222 MESSAGE( "catched exception : " << e.what() ) ;
223 return EXIT_FAILURE ;
227 cout << "-----------------------------" << endl;
228 cout << " Pb au setIJ() de 1 , 2 " << endl;
229 cout << "-----------------------------" << endl;
232 imprime("1er element : 2ieme coordonnee = 1992",myValues,myOthers,NumberOfNodes,SpaceDimension);
234 int * mynewvalues= new int [ NumberOfNodes*SpaceDimension ];
235 for (int i=0; i<NumberOfNodes*SpaceDimension; i++)
241 myArrayfull->set(MED_FULL_INTERLACE,mynewvalues);
242 myValues = myArrayfull->get(MED_FULL_INTERLACE);
243 myOthers = myArrayfull->get(MED_NO_INTERLACE);
245 catch ( const std::exception &e )
247 cout << "-------------" << endl;
248 cout << " Pb au set " << endl;
249 cout << "-------------" << endl;
250 MESSAGE( "catched exception : " << e.what() ) ;
251 return EXIT_FAILURE ;
255 cout << "--------------" << endl;
256 cout << " Pb au set " << endl;
257 cout << "--------------" << endl;
259 imprime("remise valeur a i sur myArrayfull med full interlace",myValues,myOthers,NumberOfNodes,SpaceDimension);
263 myArrayno->set(MED_FULL_INTERLACE,mynewvalues);
264 myValuesno = myArrayfull->get(MED_FULL_INTERLACE);
267 catch ( const std::exception &e )
269 cout << "-------------" << endl;
270 cout << " Pb au set " << endl;
271 cout << "-------------" << endl;
272 MESSAGE( "catched exception : " << e.what() ) ;
273 return EXIT_FAILURE ;
277 cout << "--------------" << endl;
278 cout << " Pb au setI " << endl;
279 cout << "--------------" << endl;
281 imprime("set full interlace de myArrayno",myValuesno,myOthersno,NumberOfNodes,SpaceDimension);
283 /* ---------------------------------------------------------- */
285 /* Tests des constructeurs */
286 /* Tests des Fonctions Get */
289 /* ---------------------------------------------------------- */
291 MEDARRAY<int> * myArrayShare = new MEDARRAY<int>( *myArrayfull);
292 const int * sharevalues = myArrayShare->get(MED_FULL_INTERLACE);
293 const int * shareno = myArrayShare->get(MED_NO_INTERLACE);
294 imprime("test contructeur par recopie non profonde",sharevalues,shareno,NumberOfNodes,SpaceDimension);
296 myArrayfull->setIJ(1,2,1992);
297 ASSERT(myArrayShare->getIJ(1,2) == 1992);
298 imprime("change valeur tableau source, impression tableau cible",sharevalues,shareno,NumberOfNodes,SpaceDimension);
300 myArrayShare->setIJ(1,2,1995);
301 ASSERT(myArrayfull->getIJ(1,2) == 1995);
302 imprime("change valeur tableau cible, impression tableau source",myValues,myOthers,NumberOfNodes,SpaceDimension);
305 imprime("tableau cible apres destruction tableau source",myValues,myOthers,NumberOfNodes,SpaceDimension);
307 MEDARRAY<int> * myArrayShare2 = new MEDARRAY<int>( *myArrayfull,true);
308 sharevalues = myArrayShare2->get(MED_FULL_INTERLACE);
309 shareno = myArrayShare2->get(MED_NO_INTERLACE);
310 imprime("test contructeur par recopie profonde",sharevalues,shareno,NumberOfNodes,SpaceDimension);
312 myArrayfull->setIJ(1,2,18);
313 imprime("change valeur tableau source, impression tableau cible",sharevalues,shareno,NumberOfNodes,SpaceDimension);
315 myArrayShare2->setIJ(1,2,19);
316 imprime("change valeur tableau cible, impression tableau source",myValues,myOthers,NumberOfNodes,SpaceDimension);
318 myArrayno->set(MED_NO_INTERLACE,mynewvalues);
319 myArrayno->setIJ(2,1,1);
320 myValuesno = myArrayno->get(MED_NO_INTERLACE);
321 myOthersno = myArrayno->get(MED_FULL_INTERLACE);
322 imprime("Initialisation no interlace (0...11)",myOthersno,myValuesno,NumberOfNodes,SpaceDimension);
324 MEDARRAY<int> * myArrayShare3 = new MEDARRAY<int>( *myArrayno);
325 sharevalues = myArrayShare3->get(MED_FULL_INTERLACE);
326 shareno = myArrayShare3->get(MED_NO_INTERLACE);
327 imprime("test contructeur par recopie non profonde",sharevalues,shareno,NumberOfNodes,SpaceDimension);
329 myArrayno->setIJ(1,2,1992);
330 ASSERT(myArrayShare3->getIJ(1,2) == 1992);
331 imprime("change valeur tableau source, impression tableau cible",sharevalues,shareno,NumberOfNodes,SpaceDimension);
333 myArrayShare3->setIJ(1,2,1995);
334 ASSERT(myArrayno->getIJ(1,2) == 1995);
335 imprime("change valeur tableau cible, impression tableau source",myValuesno,myOthersno,NumberOfNodes,SpaceDimension);
338 delete [] mynewvalues;
340 delete myArrayShare2;
341 delete myArrayShare3;
342 MESSAGE("FIN NORMALE DU TRAITEMENT");
343 return EXIT_SUCCESS ;
346 inline medModeSwitch getMode() const ;