Back to index

salome-med  6.5.0
testUArray.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 //  File   : testUArray.cxx
00021 //  Module : MED
00022 //
00023 #include <cstdlib>      // pour l'acces à EXIT_SUCCESS et EXIT_FAILURE
00024 #include "MEDMEM_Utilities.hxx"
00025 #include "MEDMEM_Array.hxx"
00026 
00027 using namespace std;
00028 using namespace MEDMEM;
00029 
00030 static void imprime(string titre,const int * myValues,const int * myOthers, int lignes, int colonnes)
00031 {
00032   cout << "             " <<titre << endl<< endl;
00033   cout << "Full Interlace : " << endl;
00034   if (myValues != NULL)
00035   {
00036         for (int i=0; i<lignes; i++)
00037         {
00038                 cout << " - ";
00039                 for (int k=0; k< colonnes; k++)
00040                 {
00041                         cout << myValues[k + i * colonnes]<< " " ; 
00042                 }
00043                 cout << endl;
00044         }
00045   }
00046   else
00047   {
00048                 cout << "Pointeur Null : pas de valeur" << endl << endl;
00049   }
00050   cout << endl;
00051   cout << "No Interlace : " << endl;
00052 
00053   if (myOthers != NULL)
00054   {
00055         for (int k=0; k< colonnes; k++)
00056         {
00057                 cout << " - ";
00058                 for (int i=0; i<lignes; i++)
00059                 {
00060                         cout << myOthers[i + k*lignes]<< " " ; 
00061                 }
00062                 cout << endl;
00063         }
00064   }
00065   else
00066   {
00067                 cout << "Pointeur Null : pas de valeur" << endl << endl;
00068   }
00069   cout << endl;
00070 }
00071 
00072 int main (int argc, char ** argv) 
00073 {
00074 
00075   /* ---------------------------------------------------------- */
00076   /*                                                            */
00077   /*                    INITIALISATION                          */
00078   /*                                                            */
00079   /* - constructeur new MEDARRAY<int>(int,int,mode)             */
00080   /* - get sur le pointeur MED_FULL_INTERLACE                   */
00081   /* - initialisation des valeurs (coordonnées ieme elt = I+1)  */
00082   /* - get sur le pointeur MED_NO_INTERLACE                     */
00083   /* ---------------------------------------------------------- */
00084 
00085   int SpaceDimension = 3;
00086   int NumberOfNodes  = 4; 
00087 
00088 
00089   
00090   MEDARRAY<int> * myArrayfull= new MEDARRAY<int>(SpaceDimension,NumberOfNodes,MED_EN::MED_FULL_INTERLACE);
00091   ASSERT_MED(myArrayfull != NULL);
00092 
00093   const int * myValues = myArrayfull->get(MED_EN::MED_FULL_INTERLACE);
00094   ASSERT_MED(myValues!= NULL);
00095 
00096   for (int i=0; i<NumberOfNodes; i++)
00097   {
00098         for (int k=0; k<SpaceDimension; k++)
00099         {
00100           //myValues[i* SpaceDimension +k]=i + 1; 
00101           myArrayfull->setIJ(i+1,k+1,i+1) ;
00102         }
00103   }
00104   
00105   const int * myOthers = myArrayfull->get(MED_EN::MED_NO_INTERLACE) ;
00106   ASSERT_MED(myOthers != NULL);
00107   
00108   imprime("Initialisation full interlace (xi=yi=zi=i+1)",myValues,myOthers,NumberOfNodes,SpaceDimension);
00109 
00110   MEDARRAY<int> * myArrayno= new MEDARRAY<int>(SpaceDimension,NumberOfNodes,MED_EN::MED_NO_INTERLACE);
00111   ASSERT_MED(myArrayno != NULL);
00112   const int * myValuesno = myArrayno->get(MED_EN::MED_NO_INTERLACE);
00113   ASSERT_MED(myValuesno!= NULL);
00114 
00115   for (int k=0; k<SpaceDimension; k++)
00116   {
00117         for (int i=0; i<NumberOfNodes; i++)
00118         {
00119           //myValuesno[i +k*NumberOfNodes]=k + 1; 
00120           myArrayno->setIJ(i+1,k+1,k+1) ;
00121         }
00122   }
00123   
00124   const int * myOthersno = myArrayno->get(MED_EN::MED_FULL_INTERLACE) ;
00125   ASSERT_MED(myOthersno != NULL);
00126 
00127   imprime("Initialisation no interlace (xi=yi=zi=i+1)",myOthersno,myValuesno,NumberOfNodes,SpaceDimension);
00128 
00129 
00130   /* ---------------------------------------------------------- */
00131   /*                                                            */
00132   /*                    Tests des Fonctions Set                 */
00133   /*                                                            */
00134   /* - setI sur l'element 1 avec des coordonnees a 100          */
00135   /* - setJ sur l'element 1 avec des coordonnees a 100          */
00136   /* - setIJ sur (1,2) avec une coordonnee = 1992               */
00137   /* - set   avec l ensemble des coordonnes remises à i              */
00138   /* ---------------------------------------------------------- */
00139 
00140 
00141   int * myNewLine = new int[SpaceDimension];
00142   for (int i = 0; i < SpaceDimension; i++) 
00143         myNewLine[i] = myValues[i] * 100;
00144   try
00145   {
00146         myArrayfull->setI(1, myNewLine);
00147   }
00148   catch ( const std::exception &e )
00149   {
00150         cout << "--------------" << endl;
00151         cout << "   Pb au setI " << endl;
00152         cout << "--------------" << endl;
00153         MESSAGE_MED( "catched exception : " << e.what() ) ;
00154         return EXIT_FAILURE ;
00155   }
00156   catch (...)
00157   {
00158         cout << "---------------" << endl;
00159         cout << "   Pb au setI   " << endl;
00160         cout << "---------------" << endl;
00161   }
00162 
00163   delete [] myNewLine;
00164   imprime("1er element : coordonnees à 100",myValues,myOthers,NumberOfNodes,SpaceDimension);
00165 
00166   int * myNewCol = new int[NumberOfNodes];
00167   for (int i = 0; i < NumberOfNodes; i++) 
00168         myNewCol[i] = 100;
00169   try
00170   {
00171         myArrayno->setJ(1, myNewCol);
00172   }
00173   catch ( const std::exception &e )
00174   {
00175         cout << "--------------" << endl;
00176         cout << "   Pb au setJ " << endl;
00177         cout << "--------------" << endl;
00178         MESSAGE_MED( "catched exception : " << e.what() ) ;
00179         return EXIT_FAILURE ;
00180   }
00181   catch (...)
00182   {
00183         cout << "---------------" << endl;
00184         cout << "   Pb au setJ   " << endl;
00185         cout << "---------------" << endl;
00186   }
00187 
00188   delete [] myNewCol;
00189   imprime("1eres  coordonnees à 100",myOthersno,myValuesno,NumberOfNodes,SpaceDimension);
00190 
00191   try
00192   {
00193         myArrayfull->setIJ(1,2,1992);
00194   }
00195   catch ( const std::exception &e )
00196   {
00197         cout << "---------------------------" << endl;
00198         cout << "   Pb au setIJ()  de 1 , 2 "  << endl;
00199         cout << "---------------------------" << endl;
00200         MESSAGE_MED( "catched exception : " << e.what() ) ;
00201         return EXIT_FAILURE ;
00202   }
00203   catch (...)
00204   {
00205         cout << "-----------------------------" << endl;
00206         cout << "   Pb au setIJ()  de 1 , 2 "  << endl;
00207         cout << "-----------------------------" << endl;
00208   }
00209 
00210   imprime("1er element : 2ieme coordonnee = 1992",myValues,myOthers,NumberOfNodes,SpaceDimension);
00211 
00212 
00213   try
00214   {
00215         myArrayno->setIJ(1,2,1992);
00216   }
00217   catch ( const std::exception &e )
00218   {
00219         cout << "---------------------------" << endl;
00220         cout << "   Pb au setIJ()  de 1 , 2 "  << endl;
00221         cout << "---------------------------" << endl;
00222         MESSAGE_MED( "catched exception : " << e.what() ) ;
00223         return EXIT_FAILURE ;
00224   }
00225   catch (...)
00226   {
00227         cout << "-----------------------------" << endl;
00228         cout << "   Pb au setIJ()  de 1 , 2 "  << endl;
00229         cout << "-----------------------------" << endl;
00230   }
00231 
00232   imprime("1er element : 2ieme coordonnee = 1992",myValues,myOthers,NumberOfNodes,SpaceDimension);
00233 
00234   int * mynewvalues= new int [ NumberOfNodes*SpaceDimension ];
00235   for (int i=0; i<NumberOfNodes*SpaceDimension; i++)
00236   {
00237         mynewvalues[i]=i;
00238   }
00239   try
00240   {
00241         myArrayfull->set(MED_EN::MED_FULL_INTERLACE,mynewvalues);
00242         myValues = myArrayfull->get(MED_EN::MED_FULL_INTERLACE);
00243         myOthers = myArrayfull->get(MED_EN::MED_NO_INTERLACE);
00244   }
00245   catch ( const std::exception &e )
00246   {
00247         cout << "-------------" << endl;
00248         cout << "   Pb au set "  << endl;
00249         cout << "-------------" << endl;
00250         MESSAGE_MED( "catched exception : " << e.what() ) ;
00251         return EXIT_FAILURE ;
00252   }
00253   catch (...)
00254   {
00255         cout << "--------------" << endl;
00256         cout << "   Pb au set "  << endl;
00257         cout << "--------------" << endl;
00258   }
00259   imprime("remise valeur a i sur myArrayfull med full interlace",myValues,myOthers,NumberOfNodes,SpaceDimension);
00260 
00261   try
00262   {
00263         myArrayno->set(MED_EN::MED_FULL_INTERLACE,mynewvalues);
00264         myValuesno = myArrayfull->get(MED_EN::MED_FULL_INTERLACE);
00265         myOthersno = NULL;
00266   }
00267   catch ( const std::exception &e )
00268   {
00269         cout << "-------------" << endl;
00270         cout << "   Pb au set "  << endl;
00271         cout << "-------------" << endl;
00272         MESSAGE_MED( "catched exception : " << e.what() ) ;
00273         return EXIT_FAILURE ;
00274   }
00275   catch (...)
00276   {
00277         cout << "--------------" << endl;
00278         cout << "   Pb au setI "  << endl;
00279         cout << "--------------" << endl;
00280   }
00281   imprime("set full interlace de myArrayno",myValuesno,myOthersno,NumberOfNodes,SpaceDimension);
00282 
00283   /* ---------------------------------------------------------- */
00284   /*                                                            */
00285   /*                Tests des constructeurs                     */
00286   /*                Tests des Fonctions Get                     */
00287   /*                                                            */
00288   /*                                                            */
00289   /* ---------------------------------------------------------- */
00290 
00291   MEDARRAY<int> * myArrayShare = new MEDARRAY<int>( *myArrayfull);
00292   const int * sharevalues = myArrayShare->get(MED_EN::MED_FULL_INTERLACE );
00293   const int * shareno = myArrayShare->get(MED_EN::MED_NO_INTERLACE);
00294   imprime("test contructeur par recopie non profonde",sharevalues,shareno,NumberOfNodes,SpaceDimension);
00295 
00296   myArrayfull->setIJ(1,2,1992);
00297   ASSERT_MED(myArrayShare->getIJ(1,2) == 1992);
00298   imprime("change valeur tableau source, impression tableau cible",sharevalues,shareno,NumberOfNodes,SpaceDimension);
00299 
00300   myArrayShare->setIJ(1,2,1995);
00301   ASSERT_MED(myArrayfull->getIJ(1,2) == 1995);
00302   imprime("change valeur tableau cible, impression tableau source",myValues,myOthers,NumberOfNodes,SpaceDimension);
00303 
00304   delete myArrayShare;
00305   imprime("tableau cible apres destruction tableau source",myValues,myOthers,NumberOfNodes,SpaceDimension);
00306 
00307   MEDARRAY<int> * myArrayShare2 = new MEDARRAY<int>( *myArrayfull,true);
00308   sharevalues = myArrayShare2->get(MED_EN::MED_FULL_INTERLACE );
00309   shareno = myArrayShare2->get(MED_EN::MED_NO_INTERLACE );
00310   imprime("test contructeur par recopie profonde",sharevalues,shareno,NumberOfNodes,SpaceDimension);
00311 
00312   myArrayfull->setIJ(1,2,18);
00313   imprime("change valeur tableau source, impression tableau cible",sharevalues,shareno,NumberOfNodes,SpaceDimension);
00314 
00315   myArrayShare2->setIJ(1,2,19);
00316   imprime("change valeur tableau cible, impression tableau source",myValues,myOthers,NumberOfNodes,SpaceDimension);
00317 
00318   myArrayno->set(MED_EN::MED_NO_INTERLACE,mynewvalues);
00319   myArrayno->setIJ(2,1,1);
00320   myValuesno = myArrayno->get(MED_EN::MED_NO_INTERLACE);
00321   myOthersno = myArrayno->get(MED_EN::MED_FULL_INTERLACE);
00322   imprime("Initialisation no interlace (0...11)",myOthersno,myValuesno,NumberOfNodes,SpaceDimension);
00323 
00324   MEDARRAY<int> * myArrayShare3 = new MEDARRAY<int>( *myArrayno);
00325   sharevalues = myArrayShare3->get(MED_EN::MED_FULL_INTERLACE);
00326   shareno = myArrayShare3->get(MED_EN::MED_NO_INTERLACE);
00327   imprime("test contructeur par recopie non profonde",sharevalues,shareno,NumberOfNodes,SpaceDimension);
00328 
00329   myArrayno->setIJ(1,2,1992);
00330   ASSERT_MED(myArrayShare3->getIJ(1,2) == 1992);
00331   imprime("change valeur tableau source, impression tableau cible",sharevalues,shareno,NumberOfNodes,SpaceDimension);
00332 
00333   myArrayShare3->setIJ(1,2,1995);
00334   ASSERT_MED(myArrayno->getIJ(1,2) == 1995);
00335   imprime("change valeur tableau cible, impression tableau source",myValuesno,myOthersno,NumberOfNodes,SpaceDimension);
00336 
00337   delete myArrayno;
00338   delete [] mynewvalues;
00339   delete myArrayfull;
00340   delete myArrayShare2;
00341   delete myArrayShare3;
00342   MESSAGE_MED("FIN NORMALE DU TRAITEMENT");
00343   return EXIT_SUCCESS ;
00344 }
00345 /*
00346   inline medModeSwitch getMode() const ;
00347 */