Salome HOME
Copyrights update
[modules/med.git] / src / MEDMEM / test_copie_medarray.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
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.
8 // 
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.
13 //
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
17 //
18 // See http://www.salome-platform.org/
19 //
20 /* Programme de test du constructeur de copies de la classe MEDARRAY de MEDMEM
21    jroy - 16/12/2002 */
22
23 #include <string>
24
25 #include <math.h>
26 #include <stdlib.h>
27
28 #include "MEDMEM_Exception.hxx"
29 #include "MEDMEM_Mesh.hxx"
30 #include "MEDMEM_Family.hxx"
31 #include "MEDMEM_Group.hxx"
32
33 #include "MEDMEM_MedMeshDriver.hxx"
34 #include "MEDMEM_MedFieldDriver.hxx"
35 #include "MEDMEM_Support.hxx"
36 #include "MEDMEM_Field.hxx"
37 #include "MEDMEM_define.hxx"
38
39 using namespace std;
40 using namespace MEDMEM;
41 using namespace MED_EN;
42
43 void affiche_medarray(MEDARRAY<double> & myMedArray)
44 {
45   int numberof ;
46   MESSAGE("Show all 1 :");
47   numberof = myMedArray.getLeadingValue() ;
48   for (int i=1; i<=myMedArray.getLengthValue() ; i++) {
49     const double * node = myMedArray.getRow(i) ;
50     cout << " - " ;
51     for (int j=0;j<numberof;j++)
52       cout << node[j] << " " ;
53     cout << endl ;
54   }
55   MESSAGE("Show all 2 :");
56   numberof = myMedArray.getLengthValue() ;
57   for (int i=1; i<=myMedArray.getLeadingValue() ; i++) {
58     const double * node = myMedArray.getColumn(i) ;
59     cout << " - " ;
60     for (int j=0;j<numberof;j++)
61       cout << node[j] << " " ;
62     cout << endl ;
63   }
64   MESSAGE("Show all 3 :");
65   numberof = myMedArray.getLeadingValue() ;
66   for (int i=1; i<=myMedArray.getLengthValue() ; i++) {
67     cout << " - " ;
68     for (int j=1;j<numberof+1;j++)
69       cout << myMedArray.getIJ(i,j) << " " ;
70     cout << endl ;
71   }
72
73   MESSAGE("Show all 0 :");
74   numberof = myMedArray.getLeadingValue() ;
75   int length = myMedArray.getLengthValue() ;
76   const double * NoInterlaceArray = myMedArray.get(MED_NO_INTERLACE) ;
77   for (int i=0; i<length ; i++) {
78     cout << " - " ;
79     for (int j=0;j<numberof;j++)
80       cout << NoInterlaceArray[j*length+i] << " " ;
81     cout << endl ;
82   }
83
84
85   /*
86   cout << "Nombre de lignes : " << myMedArray.getLengthValue() << endl;
87   cout << "Nombre de colonnes : " << myMedArray.getLeadingValue() << endl;
88   cout << "Mode d'écriture en mémoire : " << myMedArray.getMode() << endl;
89   cout << "Valeurs (_valuesDefault) :" << endl;
90
91   for (med_int i=1; i<=myMedArray.getLengthValue(); i++) {
92     for (med_int j=1; j<=myMedArray.getLeadingValue(); j++)
93       cout << i << "  " << j << "    " << myMedArray.getIJ(i,j) << " " << endl;
94   }
95   */
96 }
97
98
99 int main (int argc, char ** argv) {
100   /*
101   if ((argc !=3) && (argc != 4)) {
102     cerr << "Usage : " << argv[0] 
103          << " filename meshname fieldname" << endl << endl;
104     exit(-1);
105   }
106   */
107   const med_int nb_noeuds = 8;
108   const med_int dimension = 3;
109   const medModeSwitch mode = MED_NO_INTERLACE;
110
111
112   MEDARRAY<double> * myMedArray = new MEDARRAY<double>(dimension,nb_noeuds,mode);
113   for (med_int i=1; i<=myMedArray->getLengthValue(); i++) {
114     for (med_int j=1; j<=myMedArray->getLeadingValue(); j++)
115       myMedArray->setIJ(i,j,(double) random());
116   };
117
118   affiche_medarray(* myMedArray);
119   MEDARRAY<double> * myMedArray2 = new MEDARRAY<double>(* myMedArray,false);
120   delete myMedArray;
121   affiche_medarray(* myMedArray2);
122   MEDARRAY<double> * myMedArray3 = new MEDARRAY<double>(10,20);
123   (* myMedArray3) = (* myMedArray2) ;
124   delete myMedArray2;
125   affiche_medarray(* myMedArray3);
126   delete myMedArray3;
127
128   return 0;
129 }