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