Back to index

salome-med  6.5.0
test_copie_medarray.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 /* Programme de test du constructeur de copies de la classe MEDARRAY de MEDMEM
00023    jroy - 16/12/2002 */
00024 
00025 #include <string>
00026 
00027 #include <math.h>
00028 #include <stdlib.h>
00029 
00030 #include "MEDMEM_Exception.hxx"
00031 #include "MEDMEM_Mesh.hxx"
00032 #include "MEDMEM_Family.hxx"
00033 #include "MEDMEM_Group.hxx"
00034 
00035 #include "MEDMEM_MedMeshDriver.hxx"
00036 #include "MEDMEM_MedFieldDriver.hxx"
00037 #include "MEDMEM_Support.hxx"
00038 #include "MEDMEM_Field.hxx"
00039 #include "MEDMEM_define.hxx"
00040 
00041 using namespace std;
00042 using namespace MEDMEM;
00043 using namespace MED_EN;
00044 
00045 static void affiche_medarray(MEDARRAY<double> & myMedArray)
00046 {
00047   int numberof ;
00048   MESSAGE_MED("Show all 1 :");
00049   numberof = myMedArray.getLeadingValue() ;
00050   for (int i=1; i<=myMedArray.getLengthValue() ; i++) {
00051     const double * node = myMedArray.getRow(i) ;
00052     cout << " - " ;
00053     for (int j=0;j<numberof;j++)
00054       cout << node[j] << " " ;
00055     cout << endl ;
00056   }
00057   MESSAGE_MED("Show all 2 :");
00058   numberof = myMedArray.getLengthValue() ;
00059   for (int i=1; i<=myMedArray.getLeadingValue() ; i++) {
00060     const double * node = myMedArray.getColumn(i) ;
00061     cout << " - " ;
00062     for (int j=0;j<numberof;j++)
00063       cout << node[j] << " " ;
00064     cout << endl ;
00065   }
00066   MESSAGE_MED("Show all 3 :");
00067   numberof = myMedArray.getLeadingValue() ;
00068   for (int i=1; i<=myMedArray.getLengthValue() ; i++) {
00069     cout << " - " ;
00070     for (int j=1;j<numberof+1;j++)
00071       cout << myMedArray.getIJ(i,j) << " " ;
00072     cout << endl ;
00073   }
00074 
00075   MESSAGE_MED("Show all 0 :");
00076   numberof = myMedArray.getLeadingValue() ;
00077   int length = myMedArray.getLengthValue() ;
00078   const double * NoInterlaceArray = myMedArray.get(MED_NO_INTERLACE) ;
00079   for (int i=0; i<length ; i++) {
00080     cout << " - " ;
00081     for (int j=0;j<numberof;j++)
00082       cout << NoInterlaceArray[j*length+i] << " " ;
00083     cout << endl ;
00084   }
00085 
00086 
00087   /*
00088   cout << "Nombre de lignes : " << myMedArray.getLengthValue() << endl;
00089   cout << "Nombre de colonnes : " << myMedArray.getLeadingValue() << endl;
00090   cout << "Mode d'écriture en mémoire : " << myMedArray.getMode() << endl;
00091   cout << "Valeurs (_valuesDefault) :" << endl;
00092 
00093   for (med_int i=1; i<=myMedArray.getLengthValue(); i++) {
00094     for (med_int j=1; j<=myMedArray.getLeadingValue(); j++)
00095       cout << i << "  " << j << "    " << myMedArray.getIJ(i,j) << " " << endl;
00096   }
00097   */
00098 }
00099 
00100 
00101 int main (int argc, char ** argv) {
00102   /*
00103   if ((argc !=3) && (argc != 4)) {
00104     cerr << "Usage : " << argv[0] 
00105          << " filename meshname fieldname" << endl << endl;
00106     exit(-1);
00107   }
00108   */
00109   const med_int nb_noeuds = 8;
00110   const med_int dimension = 3;
00111   const medModeSwitch mode = MED_NO_INTERLACE;
00112 
00113 
00114   MEDARRAY<double> * myMedArray = new MEDARRAY<double>(dimension,nb_noeuds,mode);
00115   for (med_int i=1; i<=myMedArray->getLengthValue(); i++) {
00116     for (med_int j=1; j<=myMedArray->getLeadingValue(); j++)
00117       myMedArray->setIJ(i,j,(double) rand());
00118   };
00119 
00120   affiche_medarray(* myMedArray);
00121   MEDARRAY<double> * myMedArray2 = new MEDARRAY<double>(* myMedArray,false);
00122   delete myMedArray;
00123   affiche_medarray(* myMedArray2);
00124   MEDARRAY<double> * myMedArray3 = new MEDARRAY<double>(10,20);
00125   (* myMedArray3) = (* myMedArray2) ;
00126   delete myMedArray2;
00127   affiche_medarray(* myMedArray3);
00128   delete myMedArray3;
00129 
00130   return 0;
00131 }