Salome HOME
c9e01580fed5c9ed0281a65d5a16e0319093d76e
[modules/med.git] / src / MEDMEMBinTest / test_affect_medarray.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 /* Programme de test du constructeur de copies de la classe MEDARRAY de MEDMEM
23    jroy - 16/12/2002 */
24
25 #include <string>
26
27 #include <math.h>
28 #include <stdlib.h>
29
30 #include "MEDMEM_Exception.hxx"
31 #include "MEDMEM_Mesh.hxx"
32 #include "MEDMEM_Family.hxx"
33 #include "MEDMEM_Group.hxx"
34
35 #include "MEDMEM_MedMeshDriver.hxx"
36 #include "MEDMEM_MedFieldDriver.hxx"
37 #include "MEDMEM_Support.hxx"
38 #include "MEDMEM_Field.hxx"
39 #include "MEDMEM_define.hxx"
40
41 using namespace std;
42 using namespace MEDMEM;
43 using namespace MED_EN;
44
45 static void affiche_medarray(MEDARRAY<double> & myMedArray)
46 {
47   int numberof ;
48   MESSAGE_MED("Show all 1 :");
49   numberof = myMedArray.getLeadingValue() ;
50   for (int i=1; i<=myMedArray.getLengthValue() ; i++) {
51     const double * node = myMedArray.getRow(i) ;
52     cout << " - " ;
53     for (int j=0;j<numberof;j++)
54       cout << node[j] << " " ;
55     cout << endl ;
56   }
57   MESSAGE_MED("Show all 2 :");
58   numberof = myMedArray.getLengthValue() ;
59   for (int i=1; i<=myMedArray.getLeadingValue() ; i++) {
60     const double * node = myMedArray.getColumn(i) ;
61     cout << " - " ;
62     for (int j=0;j<numberof;j++)
63       cout << node[j] << " " ;
64     cout << endl ;
65   }
66   MESSAGE_MED("Show all 3 :");
67   numberof = myMedArray.getLeadingValue() ;
68   for (int i=1; i<=myMedArray.getLengthValue() ; i++) {
69     cout << " - " ;
70     for (int j=1;j<numberof+1;j++)
71       cout << myMedArray.getIJ(i,j) << " " ;
72     cout << endl ;
73   }
74
75   MESSAGE_MED("Show all 0 :");
76   numberof = myMedArray.getLeadingValue() ;
77   int length = myMedArray.getLengthValue() ;
78   const double * NoInterlaceArray = myMedArray.get(MED_NO_INTERLACE) ;
79   for (int i=0; i<length ; i++) {
80     cout << " - " ;
81     for (int j=0;j<numberof;j++)
82       cout << NoInterlaceArray[j*length+i] << " " ;
83     cout << endl ;
84   }
85
86
87   /*
88   cout << "Nombre de lignes : " << myMedArray.getLengthValue() << endl;
89   cout << "Nombre de colonnes : " << myMedArray.getLeadingValue() << endl;
90   cout << "Mode d'écriture en mémoire : " << myMedArray.getMode() << endl;
91   cout << "Valeurs (_valuesDefault) :" << endl;
92
93   for (med_int i=1; i<=myMedArray.getLengthValue(); i++) {
94     for (med_int j=1; j<=myMedArray.getLeadingValue(); j++)
95       cout << i << "  " << j << "    " << myMedArray.getIJ(i,j) << " " << endl;
96   }
97   */
98 }
99
100
101 int main (int argc, char ** argv) {
102   /*
103   if ((argc !=3) && (argc != 4)) {
104     cerr << "Usage : " << argv[0] 
105          << " filename meshname fieldname" << endl << endl;
106     exit(-1);
107   }
108   */
109   const med_int nb_noeuds = 8;
110   const med_int dimension = 3;
111   const medModeSwitch mode = MED_NO_INTERLACE;
112
113
114   MEDARRAY<double> * myMedArray = new MEDARRAY<double>(dimension,nb_noeuds,mode);
115   for (med_int i=1; i<=myMedArray->getLengthValue(); i++) {
116     for (med_int j=1; j<=myMedArray->getLeadingValue(); j++)
117       myMedArray->setIJ(i,j,(double) rand());
118   };
119
120   affiche_medarray(* myMedArray);
121   MEDARRAY<double> * myMedArray2 = new MEDARRAY<double>();
122   * myMedArray2 = * myMedArray;
123   //  delete myMedArray;  // si on recopie les tableaux
124   affiche_medarray(* myMedArray2);
125   delete myMedArray;      // si on ne recopie pas les tableaux
126   delete myMedArray2;
127
128   return 0;
129 }