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
25 #include <cstdlib> // pour l'acces à EXIT_SUCCESS et EXIT_FAILURE
26 #include "MEDMEM_Utilities.hxx"
27 #include "MEDMEM_Array.hxx"
30 using namespace MEDMEM;
32 void imprime(string titre,const int * myValues,const int * myOthers, int lignes, int colonnes)
34 cout << " " <<titre << endl<< endl;
35 cout << "Full Interlace : " << endl;
38 for (int i=0; i<lignes; i++)
41 for (int k=0; k< colonnes; k++)
43 cout << myValues[k + i * colonnes]<< " " ;
50 cout << "Pointeur Null : pas de valeur" << endl << endl;
53 cout << "No Interlace : " << endl;
57 for (int k=0; k< colonnes; k++)
60 for (int i=0; i<lignes; i++)
62 cout << myOthers[i + k*lignes]<< " " ;
69 cout << "Pointeur Null : pas de valeur" << endl << endl;
74 int main (int argc, char ** argv)
77 /* ---------------------------------------------------------- */
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 /* ---------------------------------------------------------- */
87 int SpaceDimension = 3;
88 int NumberOfNodes = 4;
92 MEDARRAY<int> * myArrayfull= new MEDARRAY<int>(SpaceDimension,NumberOfNodes,MED_EN::MED_FULL_INTERLACE);
93 ASSERT(myArrayfull != NULL);
95 const int * myValues = myArrayfull->get(MED_EN::MED_FULL_INTERLACE);
96 ASSERT(myValues!= NULL);
98 for (int i=0; i<NumberOfNodes; i++)
100 for (int k=0; k<SpaceDimension; k++)
102 //myValues[i* SpaceDimension +k]=i + 1;
103 myArrayfull->setIJ(i+1,k+1,i+1) ;
107 const int * myOthers = myArrayfull->get(MED_EN::MED_NO_INTERLACE) ;
108 ASSERT(myOthers != NULL);
110 imprime("Initialisation full interlace (xi=yi=zi=i+1)",myValues,myOthers,NumberOfNodes,SpaceDimension);
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);
117 for (int k=0; k<SpaceDimension; k++)
119 for (int i=0; i<NumberOfNodes; i++)
121 //myValuesno[i +k*NumberOfNodes]=k + 1;
122 myArrayno->setIJ(i+1,k+1,k+1) ;
126 const int * myOthersno = myArrayno->get(MED_EN::MED_FULL_INTERLACE) ;
127 ASSERT(myOthersno != NULL);
129 imprime("Initialisation no interlace (xi=yi=zi=i+1)",myOthersno,myValuesno,NumberOfNodes,SpaceDimension);
132 /* ---------------------------------------------------------- */
134 /* Tests des Fonctions Set */
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 /* ---------------------------------------------------------- */
143 int * myNewLine = new int[SpaceDimension];
144 for (int i = 0; i < SpaceDimension; i++)
145 myNewLine[i] = myValues[i] * 100;
148 myArrayfull->setI(1, myNewLine);
150 catch ( const std::exception &e )
152 cout << "--------------" << endl;
153 cout << " Pb au setI " << endl;
154 cout << "--------------" << endl;
155 MESSAGE( "catched exception : " << e.what() ) ;
156 return EXIT_FAILURE ;
160 cout << "---------------" << endl;
161 cout << " Pb au setI " << endl;
162 cout << "---------------" << endl;
166 imprime("1er element : coordonnees à 100",myValues,myOthers,NumberOfNodes,SpaceDimension);
168 int * myNewCol = new int[NumberOfNodes];
169 for (int i = 0; i < NumberOfNodes; i++)
173 myArrayno->setJ(1, myNewCol);
175 catch ( const std::exception &e )
177 cout << "--------------" << endl;
178 cout << " Pb au setJ " << endl;
179 cout << "--------------" << endl;
180 MESSAGE( "catched exception : " << e.what() ) ;
181 return EXIT_FAILURE ;
185 cout << "---------------" << endl;
186 cout << " Pb au setJ " << endl;
187 cout << "---------------" << endl;
191 imprime("1eres coordonnees à 100",myOthersno,myValuesno,NumberOfNodes,SpaceDimension);
195 myArrayfull->setIJ(1,2,1992);
197 catch ( const std::exception &e )
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 ;
207 cout << "-----------------------------" << endl;
208 cout << " Pb au setIJ() de 1 , 2 " << endl;
209 cout << "-----------------------------" << endl;
212 imprime("1er element : 2ieme coordonnee = 1992",myValues,myOthers,NumberOfNodes,SpaceDimension);
217 myArrayno->setIJ(1,2,1992);
219 catch ( const std::exception &e )
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 ;
229 cout << "-----------------------------" << endl;
230 cout << " Pb au setIJ() de 1 , 2 " << endl;
231 cout << "-----------------------------" << endl;
234 imprime("1er element : 2ieme coordonnee = 1992",myValues,myOthers,NumberOfNodes,SpaceDimension);
236 int * mynewvalues= new int [ NumberOfNodes*SpaceDimension ];
237 for (int i=0; i<NumberOfNodes*SpaceDimension; i++)
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);
247 catch ( const std::exception &e )
249 cout << "-------------" << endl;
250 cout << " Pb au set " << endl;
251 cout << "-------------" << endl;
252 MESSAGE( "catched exception : " << e.what() ) ;
253 return EXIT_FAILURE ;
257 cout << "--------------" << endl;
258 cout << " Pb au set " << endl;
259 cout << "--------------" << endl;
261 imprime("remise valeur a i sur myArrayfull med full interlace",myValues,myOthers,NumberOfNodes,SpaceDimension);
265 myArrayno->set(MED_EN::MED_FULL_INTERLACE,mynewvalues);
266 myValuesno = myArrayfull->get(MED_EN::MED_FULL_INTERLACE);
269 catch ( const std::exception &e )
271 cout << "-------------" << endl;
272 cout << " Pb au set " << endl;
273 cout << "-------------" << endl;
274 MESSAGE( "catched exception : " << e.what() ) ;
275 return EXIT_FAILURE ;
279 cout << "--------------" << endl;
280 cout << " Pb au setI " << endl;
281 cout << "--------------" << endl;
283 imprime("set full interlace de myArrayno",myValuesno,myOthersno,NumberOfNodes,SpaceDimension);
285 /* ---------------------------------------------------------- */
287 /* Tests des constructeurs */
288 /* Tests des Fonctions Get */
291 /* ---------------------------------------------------------- */
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);
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);
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);
307 imprime("tableau cible apres destruction tableau source",myValues,myOthers,NumberOfNodes,SpaceDimension);
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);
314 myArrayfull->setIJ(1,2,18);
315 imprime("change valeur tableau source, impression tableau cible",sharevalues,shareno,NumberOfNodes,SpaceDimension);
317 myArrayShare2->setIJ(1,2,19);
318 imprime("change valeur tableau cible, impression tableau source",myValues,myOthers,NumberOfNodes,SpaceDimension);
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);
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);
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);
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);
340 delete [] mynewvalues;
342 delete myArrayShare2;
343 delete myArrayShare3;
344 MESSAGE("FIN NORMALE DU TRAITEMENT");
345 return EXIT_SUCCESS ;
348 inline medModeSwitch getMode() const ;