1 #include <cstdlib> // pour l'acces à EXIT_SUCCESS et EXIT_FAILURE
3 #include "MEDMEM_Array.hxx"
4 using namespace MEDMEM;
6 int main (int argc, char ** argv)
9 int SpaceDimension = 3;
10 int NumberOfNodes = 4;
11 MEDARRAY<int> * myArray = new MEDARRAY<int>(SpaceDimension,NumberOfNodes,MED_FULL_INTERLACE) ;
12 ASSERT(myArray != NULL);
14 int * value = myArray->get(MED_FULL_INTERLACE) ;
17 for (int i=0; i<SpaceDimension*NumberOfNodes; i++)
23 leadingValue = myArray->getLeadingValue() ;
24 ASSERT (leadingValue == SpaceDimension);
26 catch ( const std::exception &e )
28 cout << "-------------------------------" << endl;
29 cout << " Pb au getLeadingValue() " << endl;
30 cout << "-------------------------------" << endl;
31 MESSAGE( "catched exception : " << e.what() ) ;
36 cout << "-------------------------------" << endl;
37 cout << " Pb au getLeadingValue() " << endl;
38 cout << "-------------------------------" << endl;
45 lengthValue = myArray->getLengthValue() ;
46 ASSERT(lengthValue == NumberOfNodes)
48 catch ( const std::exception &e )
50 cout << "-------------------------------" << endl;
51 cout << " Pb au getLengthValue() " << endl;
52 cout << "-------------------------------" << endl;
53 MESSAGE( "catched exception : " << e.what() ) ;
58 cout << "-------------------------------" << endl;
59 cout << " Pb au getLengthValue() " << endl;
60 cout << "-------------------------------" << endl;
64 cout << "Show all using getI and full interlace :" << endl;
65 for (int i=1; i<=lengthValue; i++)
69 int * node = myArray->getI(MED_FULL_INTERLACE,i) ;
71 for (int j=0;j<leadingValue;j++)
72 cout << node[j] << " " ;
75 catch ( const std::exception &e )
77 cout << "-------------------------------" << endl;
78 cout << " Pb au getI() valeur de i " << i << endl;
79 cout << "-------------------------------" << endl;
80 MESSAGE( "catched exception : " << e.what() ) ;
85 cout << "-------------------------------" << endl;
86 cout << " Pb au getI() valeur de i " << i << endl;
87 cout << "-------------------------------" << endl;
92 cout << "Show all using getI and no interlace :" << endl;
93 for (int i=1; i<=leadingValue; i++)
97 int * node = myArray->getI(MED_NO_INTERLACE,i) ;
99 for (int j=0;j<lengthValue;j++)
100 cout << node[j] << " " ;
103 catch ( const std::exception &e )
105 cout << "-------------------------------" << endl;
106 cout << " Pb au getI() valeur de i " << i << endl;
107 cout << "-------------------------------" << endl;
108 MESSAGE( "catched exception : " << e.what() ) ;
109 return EXIT_FAILURE ;
113 cout << "-------------------------------" << endl;
114 cout << " Pb au getI() valeur de i " << i << endl;
115 cout << "-------------------------------" << endl;
116 return EXIT_FAILURE ;
120 cout << "Show all using getIJ :" << endl;
121 for (int i=1; i<=lengthValue ; i++)
127 for (j=1;j<leadingValue+1;j++)
128 cout << myArray->getIJ(i,j) << " " ;
131 catch ( const std::exception &e )
133 cout << "-------------------------------" << endl;
134 cout << " Pb au getIJ() i " << i << " j " << j << endl;
135 cout << "-------------------------------" << endl;
136 MESSAGE( "catched exception : " << e.what() ) ;
137 return EXIT_FAILURE ;
141 cout << "-------------------------------" << endl;
142 cout << " Pb au getIJ() i " << i << " j " << j << endl;
143 cout << "-------------------------------" << endl;
144 return EXIT_FAILURE ;
148 cout << "Show all using get and MED_NO_INTERLACE :" << endl;
151 int * NoInterlaceArray = myArray->get(MED_NO_INTERLACE) ;
152 for (int i=0; i<lengthValue ; i++)
155 for (int j=0;j<leadingValue;j++)
156 cout << NoInterlaceArray[j*lengthValue+i] << " " ;
160 catch ( const std::exception &e )
162 cout << "-------------------------------" << endl;
163 cout << " Pb au get " << endl;
164 cout << "-------------------------------" << endl;
165 MESSAGE( "catched exception : " << e.what() ) ;
166 return EXIT_FAILURE ;
170 cout << "---------------" << endl;
171 cout << " Pb au get " << endl;
172 cout << "---------------" << endl;
173 return EXIT_FAILURE ;
177 cout << endl << endl << "Tests des fonctions Set " << endl;
179 int * myNewInt = new int[SpaceDimension*NumberOfNodes];
180 for (int i=0; i<SpaceDimension*NumberOfNodes; i++)
187 myArray->set(MED_FULL_INTERLACE, myNewInt);
189 catch ( const std::exception &e )
191 cout << "-------------------------------" << endl;
192 cout << " Pb au set " << endl;
193 cout << "-------------------------------" << endl;
194 MESSAGE( "catched exception : " << e.what() ) ;
195 return EXIT_FAILURE ;
199 cout << "---------------" << endl;
200 cout << " Pb au set " << endl;
201 cout << "---------------" << endl;
202 return EXIT_FAILURE ;
206 cout << "Nouvelles valeurs (x10) : get avec Full interlace : " << endl;
210 myNewValue = myArray->get(MED_FULL_INTERLACE) ;
211 ASSERT(myNewValue!= NULL);
213 catch ( const std::exception &e )
215 cout << "-----------------" << endl;
216 cout << " Pb au get " << endl;
217 cout << "-----------------" << endl;
218 MESSAGE( "catched exception : " << e.what() ) ;
219 return EXIT_FAILURE ;
223 cout << "---------------" << endl;
224 cout << " Pb au get " << endl;
225 cout << "---------------" << endl;
229 for (int i=0; i<SpaceDimension*NumberOfNodes; i++)
230 cout << myNewValue[i]<< " " ;
234 int * myNewLine = new int[SpaceDimension];
235 for (int i = 0; i < SpaceDimension; i++)
236 myNewLine[i] = i * 100;
240 myArray->setI(MED_FULL_INTERLACE, 1, myNewLine);
242 catch ( const std::exception &e )
244 cout << "-------------------------------" << endl;
245 cout << " Pb au getLengthValue() " << endl;
246 cout << "-------------------------------" << endl;
247 MESSAGE( "catched exception : " << e.what() ) ;
248 return EXIT_FAILURE ;
252 cout << "---------------" << endl;
253 cout << " Pb au setI " << endl;
254 cout << "---------------" << endl;
260 myNewValue = myArray->getI(MED_FULL_INTERLACE,1) ;
261 ASSERT(myNewValue!= NULL);
263 catch ( const std::exception &e )
265 cout << "-------------------------------" << endl;
266 cout << " Pb au getLengthValue() " << endl;
267 cout << "-------------------------------" << endl;
268 MESSAGE( "catched exception : " << e.what() ) ;
269 return EXIT_FAILURE ;
273 cout << "---------------" << endl;
274 cout << " Pb au getI " << endl;
275 cout << "---------------" << endl;
278 cout << endl << " Nouvelles valeurs (x100) sur la 1ere ligne: get avec Full interlace : ";
279 cout << endl << " - ";
280 for (int i=0; i<SpaceDimension; i++)
281 cout << myNewValue[i]<< " " ;
286 myArray->setIJ(1,1,1992);
288 catch ( const std::exception &e )
290 cout << "---------------------------" << endl;
291 cout << " Pb au setIJ() de 1 , 1 " << endl;
292 cout << "---------------------------" << endl;
293 MESSAGE( "catched exception : " << e.what() ) ;
294 return EXIT_FAILURE ;
298 cout << "-----------------------------" << endl;
299 cout << " Pb au setIJ() de 1 , 1 " << endl;
300 cout << "-----------------------------" << endl;
303 cout << "Nouvelle valeur avec setIJ et getIJ" << endl;
304 cout << " - " << myArray->getIJ(1,1) << endl;
307 return EXIT_SUCCESS ;
311 inline medModeSwitch getMode() const ;