]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_MedMeshDriver22.cxx
Salome HOME
eb8c8756cd033bf34bf5f57b8bcba7505ecc024c
[modules/med.git] / src / MEDMEM / MEDMEM_MedMeshDriver22.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 #include "MEDMEM_MedMeshDriver22.hxx"
21
22 #include "MEDMEM_DriversDef.hxx"
23
24 #include "MEDMEM_Family.hxx"
25 #include "MEDMEM_Group.hxx"
26 #include "MEDMEM_Coordinate.hxx"
27 #include "MEDMEM_Connectivity.hxx"
28 #include "MEDMEM_Mesh.hxx"
29 #include "MEDMEM_CellModel.hxx"
30 #include "MEDMEM_Grid.hxx"
31
32 using namespace std;
33 using namespace MED_EN;
34 using namespace MEDMEM;
35
36 namespace med_2_2 {
37   extern "C" {
38     extern med_idt _MEDdatagroupOuvrir(med_idt pid, char *nom);
39     extern med_err _MEDdatagroupFermer(med_idt id);
40   }
41 }
42
43 // Every memory allocation made in the MedDriver members function are desallocated in the Mesh destructor 
44
45 MED_MESH_DRIVER22::MED_MESH_DRIVER22():  _medIdt(MED_INVALID)
46 {
47 }
48
49 MED_MESH_DRIVER22::MED_MESH_DRIVER22(const string & fileName,
50                                      MESH * ptrMesh,
51                                      MED_EN::med_mode_acces accessMode): 
52   _medIdt(MED_INVALID), MED_MESH_DRIVER(fileName,ptrMesh,accessMode)
53 {
54 }
55   
56 MED_MESH_DRIVER22::MED_MESH_DRIVER22(const MED_MESH_DRIVER22 & driver):
57   MED_MESH_DRIVER(driver),_medIdt(driver._medIdt)
58 {
59 }
60
61 MED_MESH_DRIVER22::~MED_MESH_DRIVER22()
62 {
63 }
64
65 void MED_MESH_DRIVER22::open()
66 {
67   const char * LOC = "MED_MESH_DRIVER22::open()" ;
68   BEGIN_OF(LOC);
69
70   MESSAGE(LOC<<" : _fileName.c_str : "<< _fileName.c_str()<<",mode : "<< _accessMode);
71   _medIdt = med_2_2::MEDouvrir( (const_cast <char *> (_fileName.c_str())),(med_2_2::med_mode_acces) _accessMode);
72   MESSAGE(LOC<<" _medIdt : "<< _medIdt );
73   if (_medIdt > 0) 
74     _status = MED_OPENED; 
75   else {
76     _medIdt = MED_INVALID;
77     _status = MED_CLOSED;
78     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Could not open file "<<_fileName<<" in mode "<<_accessMode));
79   }
80   
81   END_OF(LOC);
82 }
83   
84 void MED_MESH_DRIVER22::close()
85 {
86   const char * LOC = "MED_MESH_DRIVER22::close() " ;
87   BEGIN_OF(LOC);
88   int err = 0;
89   if ( _status == MED_OPENED) {
90     err = med_2_2::MEDfermer(_medIdt);
91     // san -- MED5873 : Calling H5close() here leads to failure of SALOMEDS::StudyManager_i::_SaveAs()
92     // method during study saving process. MEDfermer() seems sufficient for closing a file.
93     //H5close(); // If we call H5close() all the files are closed.
94     if (err != 0)
95       throw MEDEXCEPTION( LOCALIZED(STRING(LOC)
96                                     <<" Error when closing file !"
97                                     )
98                           );
99     MESSAGE(LOC <<": _medIdt= " << _medIdt );
100     MESSAGE(LOC<<": MEDfermer : err    = " << err );
101     _status = MED_CLOSED;
102     _medIdt = MED_INVALID;
103   }
104   END_OF(LOC);
105 }
106
107 //A FAIRE UTILISER LES MAPS...
108 const med_2_2::med_geometrie_element  MED_MESH_DRIVER22::all_cell_type[MED_NBR_GEOMETRIE_MAILLE]=
109   { med_2_2::MED_POINT1,med_2_2::MED_SEG2,med_2_2::MED_SEG3,med_2_2::MED_TRIA3,med_2_2::MED_QUAD4,med_2_2::MED_TRIA6,med_2_2::MED_QUAD8,
110     med_2_2::MED_TETRA4,med_2_2::MED_PYRA5,med_2_2::MED_PENTA6,med_2_2::MED_HEXA8,med_2_2::MED_TETRA10,med_2_2::MED_PYRA13,
111     med_2_2::MED_PENTA15, med_2_2::MED_HEXA20};
112
113 const char * const MED_MESH_DRIVER22::all_cell_type_tab [MED_NBR_GEOMETRIE_MAILLE]=
114   { "MED_POINT1","MED_SEG2","MED_SEG3","MED_TRIA3","MED_QUAD4","MED_TRIA6","MED_QUAD8",
115     "MED_TETRA4","MED_PYRA5","MED_PENTA6","MED_HEXA8","MED_TETRA10","MED_PYRA13",
116     "MED_PENTA15","MED_HEXA20"};
117
118
119 //---------------------------------- RDONLY PART -------------------------------------------------------------
120
121 MED_MESH_RDONLY_DRIVER22::MED_MESH_RDONLY_DRIVER22()
122 {
123 }
124   
125 MED_MESH_RDONLY_DRIVER22::MED_MESH_RDONLY_DRIVER22(const string & fileName,
126                                                    MESH * ptrMesh):
127   IMED_MESH_RDONLY_DRIVER(fileName,ptrMesh),MED_MESH_DRIVER22(fileName,ptrMesh,MED_RDONLY),MED_MESH_DRIVER(fileName,ptrMesh,MED_RDONLY)
128
129   MESSAGE("MED_MESH_RDONLY_DRIVER22::MED_MESH_RDONLY_DRIVER22(const string & fileName, MESH * ptrMesh) has been created");
130 }
131   
132 MED_MESH_RDONLY_DRIVER22::MED_MESH_RDONLY_DRIVER22(const MED_MESH_RDONLY_DRIVER22 & driver): 
133    IMED_MESH_RDONLY_DRIVER(driver),MED_MESH_DRIVER22(driver),MED_MESH_DRIVER(driver)
134 {
135 }
136
137 MED_MESH_RDONLY_DRIVER22::~MED_MESH_RDONLY_DRIVER22()
138 {
139   //MESSAGE("MED_MESH_RDONLY_DRIVER22::~MED_MESH_RDONLY_DRIVER() has been destroyed");
140 }
141
142 GENDRIVER * MED_MESH_RDONLY_DRIVER22::copy(void) const
143 {
144   return new MED_MESH_RDONLY_DRIVER22(*this);
145 }
146
147 void MED_MESH_RDONLY_DRIVER22::read(void)
148 {
149   const char * LOC = "MED_MESH_RDONLY_DRIVER22::read() : " ;
150   BEGIN_OF(LOC);
151   if (_status!=MED_OPENED)
152     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "The _idt of file " << _fileName << " is : " << _medIdt <<  " (the file is not opened)." )) ;
153
154   if ( ( _meshName.empty() ) && ( _ptrMesh->_name.empty() )    )
155     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)
156                                  <<" neither <meshName> is set in driver nor in object MESH.")) ;
157
158   // If _meshName is not set in driver, try to use _ptrMesh->_name
159   if ( ( _meshName.empty() ) && ( !_ptrMesh->_name.empty() )    )
160     _meshName=_ptrMesh->_name;
161
162   if ( _meshName.size() > MED_TAILLE_NOM )
163     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)
164                                  <<" <meshName> size in object driver MESH is > MED_TAILLE_NOM ."));
165
166
167   _ptrMesh->_name =  _meshName;
168
169   SCRUTE(_ptrMesh->getIsAGrid());
170
171   if (_ptrMesh->getIsAGrid())
172     {
173       getGRID( );
174
175       // always call getFAMILY : families are requiered !!!!
176
177 //        int nbFam = MEDnFam(_medIdt,
178 //                        const_cast <char *> (_meshName.c_str()),
179 //                        0,
180 //                        MED_FR::MED_FAMILLE);
181 //        if (nbFam > 0)
182         {
183 //        getFAMILY();
184     
185           if (getFAMILY()!=MED_VALID)
186             throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getFAMILY when the mesh is a grid")) ;
187
188           buildAllGroups(_ptrMesh->_groupNode,_ptrMesh->_familyNode) ;
189         }
190
191       END_OF(LOC);
192       return;
193     }
194
195   if (getCOORDINATE()!=MED_VALID)
196     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getCOORDINATE"  )) ;
197  
198   if (getCONNECTIVITY()!=MED_VALID)
199     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getCOONECTIVITY")) ;
200   
201   if (getFAMILY()!=MED_VALID)
202     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getFAMILY"      )) ;
203
204   updateFamily();
205
206   // we build all groups
207   // on node
208   buildAllGroups(_ptrMesh->_groupNode,_ptrMesh->_familyNode) ;
209   // on cell
210   buildAllGroups(_ptrMesh->_groupCell,_ptrMesh->_familyCell) ;
211
212   if (_ptrMesh->_meshDimension == 3)
213     // on face
214     buildAllGroups(_ptrMesh->_groupFace,_ptrMesh->_familyFace) ;
215   else if (_ptrMesh->_meshDimension == 2)
216     // on edge
217     buildAllGroups(_ptrMesh->_groupEdge,_ptrMesh->_familyEdge) ;
218
219 //   MESSAGE(LOC<<"Checking of CellModel !!!!!!!");
220
221 //   int nbOfTypes =  _ptrMesh->_connectivity->_numberOfTypes;
222 //    for(int i=0;i<nbOfTypes;i++)
223 //      {
224 //        MESSAGE(LOC << _ptrMesh->_connectivity->_type[i]) ;
225 //      }
226
227   END_OF(LOC);
228 }
229
230 //=======================================================================
231 //function : getGRID
232 //purpose  : 
233 //=======================================================================
234
235 void MED_MESH_RDONLY_DRIVER22::getGRID()
236 {
237   const char * LOC = "MED_MESH_RDONLY_DRIVER22::getGRID() : " ;
238   BEGIN_OF(LOC);
239   
240   if (_status!=MED_OPENED)
241     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "med file is not opened"));
242   
243   GRID * ptrGrid = (GRID *) _ptrMesh;
244     
245   SCRUTE(ptrGrid);
246
247   int err, i;
248
249   int numberOfMeshesInFile = med_2_2::MEDnMaa(_medIdt);
250
251   if (numberOfMeshesInFile == MED_INVALID)
252     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Problem in File where the mesh " << _meshName << " is supposed to be stored"));
253
254   for (int index = 0; index < numberOfMeshesInFile; index++)
255     {
256       char meshName[MED_TAILLE_NOM+1]="";
257       char meshDescription[MED_TAILLE_DESC+1]="";
258       int meshDim;
259       med_2_2::med_maillage meshType;
260
261       err = med_2_2::MEDmaaInfo(_medIdt, (index+1),meshName, &meshDim,
262                                &meshType, meshDescription) ;
263
264       MESSAGE(LOC<<": Mesh n°"<< (index+1) <<" nammed "<< meshName << " with the description " << meshDescription << " is structured");
265
266       if (_meshName == string(meshName))
267         {
268           _ptrMesh->_description = meshDescription;
269           _ptrMesh->_name = meshName;
270         }
271     }
272
273   MED_EN::med_grid_type gridType = ptrGrid->getGridType();
274
275   MESSAGE(LOC<<": Mesh processed is nammed "<< _ptrMesh->_name << " with the description " << _ptrMesh->_description << " is structured with the type " << gridType);
276
277   // Read the dimension of the mesh <_meshName>
278   int MeshDimension = med_2_2::MEDdimLire(_medIdt, const_cast <char *>
279                                          (_meshName.c_str())) ;
280
281   if (MeshDimension == MED_INVALID)
282     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "The mesh dimension |" <<
283                                  MeshDimension << "| seems to be incorrect " <<
284                                  "for the mesh : |" << _meshName << "|")) ;
285
286   _ptrMesh->_meshDimension = MeshDimension;
287
288   // Read or get the dimension of the space for the mesh <_meshName>
289   int SpaceDimension = MeshDimension;
290
291   int SpaceDimensionRead = med_2_2::MEDdimEspaceLire(_medIdt,
292                                                     const_cast <char *>
293                                                     (_meshName.c_str())) ;
294
295   if (SpaceDimensionRead != MED_INVALID) SpaceDimension = SpaceDimensionRead;
296
297   _ptrMesh->_spaceDimension = SpaceDimension;
298
299   med_2_2::med_repere rep ;
300   string tmp_nom_coord (MED_TAILLE_PNOM22*(_ptrMesh->_spaceDimension)+1,' ');
301   string tmp_unit_coord(MED_TAILLE_PNOM22*(_ptrMesh->_spaceDimension)+1,' ');
302   char * tmp_nom = (const_cast <char *> ( tmp_nom_coord.c_str())  ) ;
303   char * tmp_unit= (const_cast <char *> ( tmp_unit_coord.c_str()) ) ;
304
305   // Read Array length
306   int * ArrayLen[] = { & ptrGrid->_iArrayLength,
307                        & ptrGrid->_jArrayLength,
308                        & ptrGrid->_kArrayLength  };
309
310   MESSAGE(LOC << "The mesh is a " << _ptrMesh->_meshDimension << "D mesh on a " << _ptrMesh->_spaceDimension << "D space");
311
312   int NumberOfNodes;
313
314   //  if (gridType == MED_EN::MED_GRILLE_STANDARD)
315   if (gridType == MED_EN::MED_BODY_FITTED)
316     {
317       int * structure = new int[MeshDimension];
318
319       err = med_2_2::MEDstructureCoordLire(_medIdt,
320                                           const_cast <char *>
321                                           (_ptrMesh->_name.c_str()),
322                                           MeshDimension,structure);
323
324       if (err != MED_VALID)
325         throw MEDEXCEPTION(STRING(LOC) <<"Error in reading the structure of grid : |" << _meshName << "|" ) ;
326       
327       NumberOfNodes = 1;
328
329       for (int idim = 0; idim < MeshDimension; idim++)
330         {
331           MESSAGE(LOC<<"structure dim " << idim << " " << structure[idim]);
332
333           ArrayLen [idim][0] = structure[idim];
334           NumberOfNodes = NumberOfNodes*structure[idim];
335         }
336       
337       delete [] structure;
338
339 //       NumberOfNodes = MED_FR::MEDnEntMaa(_medIdt,
340 //                                       const_cast <char *>
341 //                                       (_ptrMesh->_name.c_str()),
342 //                                       MED_FR::MED_COOR,MED_FR::MED_NOEUD,
343 //                                       (MED_FR::med_geometrie_element) 0,
344 //                                       (MED_FR::med_connectivite) 0);
345
346       if ( NumberOfNodes == MED_INVALID )
347         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"The number of nodes |" <<
348                                      NumberOfNodes <<
349                                      "| seems to be incorrect "
350                                      << "for the mesh : |" <<
351                                      _meshName << "|" )) ;
352
353       _ptrMesh->_numberOfNodes = NumberOfNodes ;
354
355       // create coordinates and its structure
356       _ptrMesh->_coordinate = new COORDINATE(SpaceDimension,NumberOfNodes,
357                                              MED_EN::MED_FULL_INTERLACE);
358
359       err = MEDcoordLire(_medIdt,
360                          const_cast <char *> (_ptrMesh->_name.c_str()),
361                          _ptrMesh->_spaceDimension,
362                          //const_cast <double *> ( _ptrMesh->_coordinate->_coordinate->get(MED_EN::MED_FULL_INTERLACE) ),
363                          const_cast <double *> ( _ptrMesh->_coordinate->_coordinate.get(MED_EN::MED_FULL_INTERLACE) ),
364                          med_2_2::MED_FULL_INTERLACE,
365                          MED_ALL, // we read all the coordinates
366                          NULL,    // we don't use a profile
367                          0,       // so the profile's size is 0
368                          &rep,tmp_nom,tmp_unit);
369
370       if (err != MED_VALID)
371         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't read coordinates of the |" <<
372                                      NumberOfNodes << "| nodes for the mesh : |" <<
373                                      _meshName << "| of space dimension |" <<
374                                      SpaceDimension << "| with units names |" <<
375                                      tmp_nom << "| and units |" <<
376                                      tmp_unit << " |")) ;
377
378       ptrGrid->_is_coordinates_filled = true;
379     }
380   else if ((gridType == MED_EN::MED_CARTESIAN) ||
381            (gridType == MED_EN::MED_POLAR))
382     {
383       NumberOfNodes = 1;
384
385       double * Array[] = { (double*) 0, (double*) 0, (double*) 0 };
386
387       for (int idim = 0; idim < _ptrMesh->_meshDimension; ++idim)
388         {
389           med_2_2::med_table table;
390           if (idim == 0) table = med_2_2::MED_COOR_IND1;
391           else if (idim == 1) table = med_2_2::MED_COOR_IND2;
392           else if (idim == 2) table = med_2_2::MED_COOR_IND3;
393
394           int length = med_2_2::MEDnEntMaa(_medIdt,
395                                           const_cast <char *> (_ptrMesh->_name.c_str()),
396                                           table,med_2_2::MED_NOEUD,
397                                           med_2_2::MED_NONE,
398                                           med_2_2::MED_NOD);
399           if ( length <= MED_VALID )
400             throw MEDEXCEPTION(STRING(LOC) <<"The number of nodes |" << length <<
401                                "| seems to be incorrect "
402                                << "for the mesh : |" << _meshName << "|" ) ;
403           
404           ArrayLen [idim][0] = length;
405           NumberOfNodes *= length;
406
407           Array [idim] = new double [ length ];
408
409           err = med_2_2::MEDindicesCoordLire(_medIdt, const_cast <char *>
410                                             (_ptrMesh->_name.c_str()),
411                                             _ptrMesh->_meshDimension,
412                                             Array [idim], length, (idim+1),
413                                             tmp_nom+(idim*MED_TAILLE_PNOM22),
414                                             tmp_unit+(idim*MED_TAILLE_PNOM22));
415
416           if (err != MED_VALID)
417             throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Error in reading coordinates indices " <<
418                                          idim << "of the grid : |" <<
419                                          _meshName << "|" )) ;
420         }
421
422       ptrGrid->_iArray = Array[0];
423       ptrGrid->_jArray = Array[1];
424       ptrGrid->_kArray = Array[2];
425
426       _ptrMesh->_numberOfNodes = NumberOfNodes ;
427     
428       // create coordinates
429       _ptrMesh->_coordinate = new COORDINATE(SpaceDimension,NumberOfNodes,
430                                              MED_EN::MED_FULL_INTERLACE);
431
432       if (gridType == MED_EN::MED_CARTESIAN)
433         rep = med_2_2::MED_CART;
434       else if (gridType == MED_EN::MED_POLAR)
435         {
436           if (SpaceDimension == 2) rep = med_2_2::MED_CYL;
437           else if (SpaceDimension == 3) rep = med_2_2::MED_SPHER;
438         }
439     }
440   else
441     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<" bad grid type : " << gridType));
442
443   // set coordinate names
444
445   for (i=0; i<_ptrMesh->_spaceDimension; ++i ) {
446     string myStringName(tmp_nom_coord,i*MED_TAILLE_PNOM22,MED_TAILLE_PNOM22) ;
447     string myStringUnit(tmp_unit_coord,i*MED_TAILLE_PNOM22,MED_TAILLE_PNOM22) ;
448     // suppress space at the end
449     int j ;
450     for(j=MED_TAILLE_PNOM22-1;j>=0;j--)
451       if (myStringName[j] != ' ') break ;
452     _ptrMesh->_coordinate->_coordinateName[i]=string(myStringName,0,j+1);
453     for(j=MED_TAILLE_PNOM22-1;j>=0;j--)
454       if (myStringUnit[j] != ' ') break ;
455     _ptrMesh->_coordinate->_coordinateUnit[i]=string(myStringUnit,0,j+1);
456   }
457
458   string coordinateSystem = "UNDEFINED";
459
460   if( rep == med_2_2::MED_CART) coordinateSystem = "CARTESIAN";
461   else if ( rep == med_2_2::MED_CYL) coordinateSystem = "CYLINDRICAL";
462   else if ( rep == med_2_2::MED_SPHER) coordinateSystem = "SPHERICAL";
463
464   _ptrMesh->_coordinate->setCoordinatesSystem(coordinateSystem);
465
466   END_OF(LOC);
467 }
468
469 //=======================================================================
470 //function : getCOORDINATE
471 // A FAIRE : RENVOYER DU VOID
472 //=======================================================================
473 int  MED_MESH_RDONLY_DRIVER22::getCOORDINATE()
474 {
475   const char * LOC = "MED_MESH_RDONLY_DRIVER22::getCOORDINATE() : " ;
476
477   BEGIN_OF(LOC);
478
479   if (_status==MED_OPENED)
480     {
481       int err ;
482       
483   int numberOfMeshesInFile = med_2_2::MEDnMaa(_medIdt);
484
485   if (numberOfMeshesInFile == MED_INVALID)
486     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Problem in File where the mesh " << _meshName << " is supposed to be stored"));
487
488   for (int index = 0; index < numberOfMeshesInFile; index++)
489     {
490       char meshName[MED_TAILLE_NOM+1]="";
491       char meshDescription[MED_TAILLE_DESC+1]="";
492       int meshDim;
493       med_2_2::med_maillage meshType;
494
495       err = med_2_2::MEDmaaInfo(_medIdt, (index+1), meshName, &meshDim,
496                                &meshType, meshDescription) ;
497
498       MESSAGE(LOC<<": Mesh n°"<< (index+1) <<" nammed "<< meshName << " with the description " << meshDescription << " is structured");
499
500       if (_meshName == string(meshName))
501         {
502           _ptrMesh->_description = meshDescription;
503         }
504     }
505
506
507       // Read the dimension of the mesh <_meshName>
508       int MeshDimension = med_2_2::MEDdimLire(_medIdt, const_cast <char *>
509                                              (_meshName.c_str())) ;
510
511       if ( MeshDimension == MED_INVALID ) 
512         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "The mesh dimension |" <<
513                                      MeshDimension <<
514                                      "| seems to be incorrect " <<
515                                      "for the mesh : |" << _meshName << "|")) ;
516
517       _ptrMesh->_meshDimension = MeshDimension;
518
519       // Read or get the dimension of the space for the mesh <_meshName>
520       int SpaceDimension = MeshDimension;
521
522       int SpaceDimensionRead = med_2_2::MEDdimEspaceLire(_medIdt,
523                                                         const_cast <char *>
524                                                         (_meshName.c_str())) ;
525
526       if (SpaceDimensionRead  != MED_INVALID)
527         SpaceDimension = SpaceDimensionRead;
528
529       _ptrMesh->_spaceDimension = SpaceDimension;
530
531       // Read the number of nodes used in the mesh <_meshName>
532       // to be able to create a COORDINATE object
533       int NumberOfNodes=MEDnEntMaa(_medIdt,
534                                    const_cast <char *> (_meshName.c_str()),
535                                    med_2_2::MED_COOR,
536                                    med_2_2::MED_NOEUD,
537                                    (med_2_2::med_geometrie_element) MED_NONE,
538                                    (med_2_2::med_connectivite)      MED_NONE);
539       if ( NumberOfNodes <= MED_VALID )
540         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"The number of nodes |" << NumberOfNodes << "| seems to be incorrect "
541                                      << "for the mesh : |" << _meshName << "|" )) ;
542       _ptrMesh->_numberOfNodes = NumberOfNodes ;
543
544       // create a COORDINATE object
545       _ptrMesh->_coordinate = new COORDINATE(SpaceDimension, NumberOfNodes, MED_EN::MED_FULL_INTERLACE);
546       
547       med_2_2::med_repere rep ; // ATTENTION ---> DOIT ETRE INTEGRE DS MESH EF: FAIT NON?
548       string tmp_nom_coord (MED_TAILLE_PNOM22*(_ptrMesh->_spaceDimension)+1,'\0');
549       string tmp_unit_coord(MED_TAILLE_PNOM22*(_ptrMesh->_spaceDimension)+1,'\0');
550       char * tmp_nom = (const_cast <char *> ( tmp_nom_coord.c_str())  ) ;
551       char * tmp_unit= (const_cast <char *> ( tmp_unit_coord.c_str()) ) ;
552
553       err=MEDcoordLire(_medIdt,
554                        const_cast <char *> (_ptrMesh->_name.c_str()),
555                        _ptrMesh->_spaceDimension,
556                        //const_cast <double *> ( _ptrMesh->_coordinate->_coordinate->get(MED_EN::MED_FULL_INTERLACE) ),
557                        const_cast <double *> ( _ptrMesh->_coordinate->_coordinate.get(MED_EN::MED_FULL_INTERLACE) ),
558                        med_2_2::MED_FULL_INTERLACE,
559                        MED_ALL,                      // we read all the coordinates
560                        NULL,                         // we don't use a profile
561                        0,                            // so the profile's size is 0
562                        &rep,tmp_nom,tmp_unit);
563       if (err != MED_VALID)
564         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't read coordinates of the |" << NumberOfNodes << "| nodes "
565                                      << "for the mesh : |" << _meshName 
566                                      << "| of space dimension |" << SpaceDimension 
567                                      << "| with units names |"   << tmp_nom
568                                      << "| and units |"          << tmp_unit
569                                      << " |")) ;
570       
571
572       for (int i=0;i<_ptrMesh->_spaceDimension;i++) {
573         string myStringName(tmp_nom_coord,i*MED_TAILLE_PNOM22,MED_TAILLE_PNOM22) ;
574         string myStringUnit(tmp_unit_coord,i*MED_TAILLE_PNOM22,MED_TAILLE_PNOM22) ;
575         // suppress space at the end
576         int j ;
577         for(j=MED_TAILLE_PNOM22-1;j>=0;j--)
578           if (myStringName[j] != ' ') break ;
579         _ptrMesh->_coordinate->_coordinateName[i]=string(myStringName,0,j+1);
580         for(j=MED_TAILLE_PNOM22-1;j>=0;j--)
581           if (myStringUnit[j] != ' ') break ;
582         _ptrMesh->_coordinate->_coordinateUnit[i]=string(myStringUnit,0,j+1);
583       }
584
585       // Pourquoi le stocker sous forme de chaîne ?
586       switch (rep)
587         {
588         case med_2_2::MED_CART : 
589           {
590             _ptrMesh->_coordinate->_coordinateSystem = "CARTESIAN";
591             break ;
592           }
593         case med_2_2::MED_CYL :
594           {
595             _ptrMesh->_coordinate->_coordinateSystem = "CYLINDRICAL";
596             break ;
597           }
598         case med_2_2::MED_SPHER :
599           {
600             _ptrMesh->_coordinate->_coordinateSystem = "SPHERICAL";
601             break ;
602           }
603         default :
604           {
605             _ptrMesh->_coordinate->_coordinateSystem = "UNDEFINED"; // ?Erreur ?
606             break ;
607           }
608         }
609
610       // Read the unused optional node Names
611       char * tmp_node_name = new char[NumberOfNodes*MED_TAILLE_PNOM22+1];
612       tmp_node_name[NumberOfNodes]='\0' ;
613       err=MEDnomLire(_medIdt,const_cast <char*> (_ptrMesh->_name.c_str()),
614                      tmp_node_name,NumberOfNodes*MED_TAILLE_PNOM22,med_2_2::MED_NOEUD,
615                      (med_2_2::med_geometrie_element) MED_NONE);
616       if (err == MED_VALID) 
617         MESSAGE(LOC<<"MED_MESH_RDONLY_DRIVER::getNoeuds() : WARNING : Nodes have names but we do not read them !");
618       delete[] tmp_node_name ;
619
620
621       // ??? Read the unused optional node Numbers ???
622       med_2_2::med_int * tmp_node_number = new med_2_2::med_int[NumberOfNodes] ;
623       err=MEDnumLire(_medIdt,const_cast <char*> (_ptrMesh->_name.c_str()),
624                      tmp_node_number,NumberOfNodes,med_2_2::MED_NOEUD,(med_2_2::med_geometrie_element)0);
625       if (err == MED_VALID) {
626         // INFOS(LOC<<"WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING");
627         // INFOS(LOC<<"MED_MESH_RDONLY_DRIVER::getNoeuds() : WARNING : Nodes have numbers but we do not take care of them !");
628         // INFOS(LOC<<"WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING");
629         MESSAGE(LOC<<"MED_MESH_RDONLY_DRIVER::getNoeuds() : Nodes have numbers, we DO TAKE care of them !");
630         _ptrMesh->_coordinate->_nodeNumber.set(NumberOfNodes) ; 
631 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000)
632         for(med_2_2::med_int i2=0;i2<NumberOfNodes;i2++)
633           _ptrMesh->_coordinate->_nodeNumber[i2]=(int)(tmp_node_number[i2]);
634 #else
635         memcpy((int*)_ptrMesh->_coordinate->_nodeNumber,tmp_node_number,sizeof(int)*NumberOfNodes) ;
636 #endif
637         
638         //////////////////////////////////////////////////////////////////////////////////////
639         ///  Modification pour prise en compte de la numérotation optionnelle des noeuds   ///
640         //////////////////////////////////////////////////////////////////////////////////////
641         ///
642         /// Calcule _optionnalToCanonicNodesNumbers de telle sorte que _optionnalToCanonicNodesNumbers[OptionnalNumber]==CanonicNumber
643         
644 //      _ptrMesh->_arePresentOptionnalNodesNumbers=1;
645 //      for (int canonicNumber=1;canonicNumber<=NumberOfNodes;canonicNumber++) _ptrMesh->_optionnalToCanonicNodesNumbers[tmp_node_number[canonicNumber-1]]=canonicNumber;
646 // ICI RETOUR A LA NORMALE::: AUCUNE PRISE EN COMPTE D'UN NUMEROTATION OPTIONNEL
647         _ptrMesh->_arePresentOptionnalNodesNumbers=0;
648       } 
649       else _ptrMesh->_arePresentOptionnalNodesNumbers=0;
650
651         //////////////////////////////////////////////////////////////////////////////////////
652
653       delete[] tmp_node_number ;
654       
655       END_OF(LOC);
656       return MED_VALID;
657     }
658   return MED_ERROR;
659 }
660
661
662 int MED_MESH_RDONLY_DRIVER22::getCONNECTIVITY() 
663 {
664   const char * LOC = "MED_MESH_RDONLY_DRIVER22::getCONNECTIVITY : " ;
665   BEGIN_OF(LOC);
666
667   if (_status==MED_OPENED)
668     {
669
670       int err = 0 ;
671       // read MED_CELL connectivity
672       CONNECTIVITY * Connectivity     = new CONNECTIVITY(MED_CELL) ;
673       Connectivity->_numberOfNodes    = _ptrMesh->_numberOfNodes ;   // EF : Pourquoi cet attribut est-il dans MESH et non dans COORDINATE ?
674
675       // Try to read nodal connectivity of the cells <Connectivity->_nodal>
676       // then try to read descending connectivity    <Connectivity->_descending>
677       // if neither nodal nor descending connectivity exists
678       // throw an exception.
679       err = getNodalConnectivity(Connectivity) ;
680       if (err!=MED_VALID)
681         {
682           Connectivity->_typeConnectivity = MED_DESCENDING ;
683           err = getDescendingConnectivity(Connectivity) ;
684         }
685       else 
686         getDescendingConnectivity(Connectivity) ; // we read it if there is one
687       
688       if (err!=MED_VALID)
689         {
690           delete Connectivity ;
691           throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "We could not read " <<
692                                        "any Connectivity")) ;
693         }
694
695       if (Connectivity->_entityDimension != _ptrMesh->_meshDimension)
696         MESSAGE(LOC << "Small mesh dimension problem on the med file mounted in memory : diim stored " << _ptrMesh->_meshDimension << " dim computed using the connectivity " << Connectivity->_entityDimension);
697
698       _ptrMesh->_meshDimension = Connectivity->_entityDimension ; 
699
700       // At this point Connectivity->_typeConnectivity is either NODAL or DESCENDING
701       // If both connectivities are found Connectivity->_typeConnectivity is NODAL
702       // If space dimension is 3 
703       // try to read the nodal connectivity of the faces <ConnectivityFace->_nodal> then
704       // try to read the descending connectivity <ConnectivityFace->_descending>
705       // if there is no descending connectivity and the CELLS are
706       // defined in descending mode then throw an exception
707
708       // PROVISOIRE : if we have some face or edge in MED_MAILLE, we don't read more. There could not be have face or edge !!!!
709
710       if(Connectivity->_constituent==NULL) {
711
712       SCRUTE(_ptrMesh->_meshDimension);
713       SCRUTE(Connectivity->_entityDimension);
714       if (_ptrMesh->_meshDimension == 3) {
715         MESSAGE(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE DES FACES..." );
716         CONNECTIVITY * ConnectivityFace = new CONNECTIVITY(MED_EN::MED_FACE) ;
717         ConnectivityFace->_typeConnectivity = Connectivity->_typeConnectivity ; // NODAL or DESCENDING
718         SCRUTE(ConnectivityFace->_typeConnectivity);
719         if (Connectivity->_typeConnectivity == MED_DESCENDING) {
720           MESSAGE(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE DESCENDANTE DES FACES" );
721           err = getDescendingConnectivity(ConnectivityFace) ;
722           if (err!=MED_VALID)
723             throw MEDEXCEPTION ( LOCALIZED(STRING(LOC) << "No FACE in descending connectivity")) ;
724           getNodalConnectivity(ConnectivityFace) ; // if any !
725         } else {
726           MESSAGE(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE NODALE DES FACES" );
727           err = getNodalConnectivity(ConnectivityFace) ;
728           if (err!=MED_VALID) { // or error ????? we are in NODAL mode.
729             err = getDescendingConnectivity(ConnectivityFace) ;
730           } else
731             getDescendingConnectivity(ConnectivityFace); // if any !
732         }
733         if (err!=MED_VALID) {
734           delete ConnectivityFace ;
735           MESSAGE(LOC<<"No FACE defined.") ;
736         } else {
737           MESSAGE(LOC<<" SAUVEGARDE DE LA CONNECTIVITE DES FACES DANS L'OBJET CONNECTIVITY" );
738           Connectivity->_constituent=ConnectivityFace ; 
739         }
740       }
741
742       // read MED_EDGE connectivity
743       if (_ptrMesh->_meshDimension > 1) { // we are in 3 or 2D 
744         MESSAGE(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE DES ARRETES...." );
745         CONNECTIVITY * ConnectivityEdge = new CONNECTIVITY(MED_EDGE) ;
746         ConnectivityEdge->_typeConnectivity = Connectivity->_typeConnectivity ;
747         if (Connectivity->_typeConnectivity == MED_DESCENDING) {
748           MESSAGE(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE DESCENDANTE DES ARRETES" );
749           err = getDescendingConnectivity(ConnectivityEdge) ;
750           if (err!=MED_VALID)
751             throw MEDEXCEPTION ( LOCALIZED(STRING(LOC) << "No EDGE in descending connectivity")) ;
752           getNodalConnectivity(ConnectivityEdge) ; // if any !
753         } else {
754           MESSAGE(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE NODALE DES ARRETES" );
755           err = getNodalConnectivity(ConnectivityEdge) ;
756           if (err!=MED_VALID) { // or error ????? we are in NODAL mode.
757             err = getDescendingConnectivity(ConnectivityEdge) ;
758           } else
759             getDescendingConnectivity(ConnectivityEdge) ; // if any !
760         }
761         if (err!=MED_VALID) {
762           delete ConnectivityEdge ;
763           MESSAGE(LOC<<"No EDGE defined.") ;
764         } else {
765           if (_ptrMesh->_meshDimension == 3)
766             if (Connectivity->_constituent != NULL)
767               Connectivity->_constituent->_constituent=ConnectivityEdge ;
768             else
769               throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<< "EDGE defined but there are no FACE !")) ;
770           else { // IN 2D
771             MESSAGE(LOC<<" SAUVEGARDE DE LA CONNECTIVITE DES ARETES DANS L'OBJET CONNECTIVITY" );
772             Connectivity->_constituent=ConnectivityEdge ;
773           }
774         }
775       }
776       }
777       _ptrMesh->_connectivity  = Connectivity ;                                      
778
779       // all right !
780
781       // we have read all connectivity in file, now we must build descending connectivity if necessary !
782
783       // If connectivity descending is defined, we have nothing to do, all constituent are defined !
784       // If connectivity is only nodal, we must rebuild descending if we have some contituent !
785
786       //A FAIRE !!!!
787 //        if (Connectivity->_descending == NULL)
788 //      if (Connectivity->_constituent != NULL){
789 //        // update Connectivity->_constituent
790 //        CONNECTIVITY * myConstituentOld = Connectivity->_constituent ;
791 //        Connectivity->_constituent = (CONNECTIVITY *)NULL ;
792 //        Connectivity->calculateDescendingConnectivity() ;
793           
794 //      }
795       
796       END_OF(LOC);
797       return MED_VALID;
798     }
799   return MED_ERROR;
800 }
801
802 int MED_MESH_RDONLY_DRIVER22::getNodalConnectivity(CONNECTIVITY * Connectivity)
803 {
804   const char * LOC = "MED_MESH_RDONLY_DRIVER22::getNodalConnectivity : " ;
805   BEGIN_OF(LOC);
806
807   if (_status==MED_OPENED)
808     {
809       int spaceDimension = _ptrMesh->_spaceDimension;
810
811       // Get the type of entity to work on (previously set in the Connectivity Object)
812       med_2_2::med_entite_maillage Entity = (med_2_2::med_entite_maillage) Connectivity->getEntity();
813       
814       // Get the number of cells of each type & store it in <tmp_cells_count>.
815       int * tmp_cells_count = new int[MED_NBR_GEOMETRIE_MAILLE] ;
816       int i;
817       for (i=1;i<MED_NBR_GEOMETRIE_MAILLE;i++) 
818         {                       // EF :ON SCANNE DES GEOMETRIES INUTILES, UTILISER LES MAPS
819           tmp_cells_count[i]=MEDnEntMaa(_medIdt,(const_cast <char *> (_ptrMesh->_name.c_str())),
820                                         med_2_2::MED_CONN,(med_2_2::med_entite_maillage) Entity,
821                                         all_cell_type[i],med_2_2::MED_NOD); 
822
823
824           // Get the greatest dimension of the cells : Connectivity->_entityDimension
825           // We suppose there is no cells used as faces in MED 2.2.x , this is forbidden !!!
826           // In version prior to 2.2.x, it is possible
827           if (tmp_cells_count[i]>0) 
828             { 
829               Connectivity->_entityDimension=all_cell_type[i]/100;  
830               Connectivity->_numberOfTypes++;
831             }
832         }
833
834       
835
836       // begin classic geometric types
837       if (Connectivity->_numberOfTypes > 0)
838         {
839           // if MED version < 2.2.x, we read only entity with dimention = Connectivity->_entityDimension. Lesser dimension are face or edge !
840
841       med_int major, minor, release;
842
843       if ( med_2_2::MEDversionLire(_medIdt, &major, &minor, &release) != 0 )
844             {
845               // error : we suppose we have not a good med file !
846               delete[] tmp_cells_count ;
847               return MED_ERROR ;
848             }
849
850           // we get MED version number
851           // If MED version is < 2.2 then the cells which dimension
852           // is lesser than the main dimension ( Connectivity->_entityDimension )
853           // are either faces or edges
854
855           //        string medVersion(version_med);
856           //        int firstNumber = 
857           int * tmpEdgeCount = new int[MED_NBR_GEOMETRIE_MAILLE] ;
858           tmpEdgeCount[0]     = 0 ;
859           int numberOfEdgesTypes = 0;
860           int * tmpFaceCount = new int[MED_NBR_GEOMETRIE_MAILLE] ;
861           tmpFaceCount[0]     = 0 ;
862           int numberOfFacesTypes = 0;
863   
864 //       if ((version_med != "2.2")&(Entity==MED_FR::MED_MAILLE))
865 //      {
866 //        Connectivity->_numberOfTypes=0;
867         
868 //        for ( i=1;i<MED_NBR_GEOMETRIE_MAILLE;i++)
869 //          {
870 //            tmpFaceCount[i]=0;
871 //            tmpEdgeCount[i]=0;
872 //            if (tmp_cells_count[i]!=0)
873 //              {
874 //                int dimension = all_cell_type[i]/100 ;
875 //                if (Connectivity->_entityDimension==dimension) 
876 //                  Connectivity->_numberOfTypes++ ;
877             
878 //                if (dimension == 2)
879 //                  if (Connectivity->_entityDimension==3)
880 //                    {
881 //                      tmpFaceCount[i]=tmp_cells_count[i] ;
882 //                      tmp_cells_count[i]=0 ;
883 //                      numberOfFacesTypes++;
884 //                    }
885 //                if (dimension == 1)
886 //                  if (Connectivity->_entityDimension>dimension)
887 //                    {
888 //                      tmpEdgeCount[i]=tmp_cells_count[i] ;
889 //                      tmp_cells_count[i]=0;
890 //                      numberOfEdgesTypes++ ;
891 //                    }
892 //              }
893 //          }
894 //      }
895         
896       if (Entity==med_2_2::MED_MAILLE)
897         {
898               Connectivity->_numberOfTypes=0;
899         
900               for ( i=1;i<MED_NBR_GEOMETRIE_MAILLE;i++) 
901                 {
902                   tmpFaceCount[i]=0;
903                   tmpEdgeCount[i]=0;
904                   if (tmp_cells_count[i]!=0) 
905                     {
906                       int dimension = all_cell_type[i]/100 ;
907                       if (Connectivity->_entityDimension==dimension) 
908                         Connectivity->_numberOfTypes++ ;
909                 
910                       if (dimension == 2)
911                         if (Connectivity->_entityDimension==3) 
912                           {
913                             tmpFaceCount[i]=tmp_cells_count[i] ;
914                         //tmp_cells_count[i]=0 ;
915                         //Connectivity->_numberOfTypes++ ;
916                             numberOfFacesTypes++;
917                           }
918                       if (dimension == 1)
919                         if (Connectivity->_entityDimension>dimension) 
920                           {
921                             tmpEdgeCount[i]=tmp_cells_count[i] ;
922                         //tmp_cells_count[i]=0;
923                         //Connectivity->_numberOfTypes++ ;
924                             numberOfEdgesTypes++ ;
925                           }
926                     }
927                 }
928             }
929
930           // bloc to read CELL :
931           {
932             // Prepare an array of indexes on the different cell types to create a MEDSKYLINEARRAY
933             // We use <tmp_cells_count> to calculate <Connectivity->_count> then we release it
934             Connectivity->_geometricTypes = new MED_EN::medGeometryElement [Connectivity->_numberOfTypes]   ;  // Double emploi pour des raisons pratiques 
935             Connectivity->_type           = new CELLMODEL                  [Connectivity->_numberOfTypes]   ;  //
936             Connectivity->_count          = new int                        [Connectivity->_numberOfTypes+1] ;
937             Connectivity->_count[0]       = 1;
938             
939             int size = 0 ; 
940             int typeNumber=1 ;
941             int i;
942             for ( i=1;i<MED_NBR_GEOMETRIE_MAILLE;i++)  
943               { // no point1 cell type (?)
944             int dimension = all_cell_type[i]/100 ;
945             if ((tmp_cells_count[i]>0) && (Connectivity->_entityDimension == dimension))
946                   {
947                     Connectivity->_count[typeNumber]=Connectivity->_count[typeNumber-1]+tmp_cells_count[i];
948
949                     CELLMODEL t( (MED_EN::medGeometryElement) MED_MESH_DRIVER22::all_cell_type[i]) ;
950
951                 Connectivity->_type[typeNumber-1] = t ;
952             
953                     Connectivity->_geometricTypes[typeNumber-1]=( MED_EN::medGeometryElement) MED_MESH_DRIVER22::all_cell_type[i] ;
954             
955                     // probleme avec les mailles de dimension < a dimension du maillage :
956                     // Il faut oter le zero a la lecture est le remettre a l'ecriture : ce n'est pas fait !!!!! On interdit ce cas pour l'instant !!!
957
958               
959                     size+=tmp_cells_count[i]*((MED_MESH_DRIVER22::all_cell_type[i])%100) ;
960             
961                     MESSAGE(LOC
962                             << Connectivity->_count[typeNumber]-1 << " cells of type " 
963                             << all_cell_type_tab[i] ); 
964                     typeNumber++;
965                   }
966               }
967         
968             // Creation of the MEDSKYLINEARRAY
969             //Connectivity->_nodal = new MEDSKYLINEARRAY(Connectivity->_count[Connectivity->_numberOfTypes]-1,size) ; 
970             //int * NodalIndex = Connectivity->_nodal->getIndex() ;
971             int * NodalValue = new int[size] ;
972             int * NodalIndex = new int[Connectivity->_count[Connectivity->_numberOfTypes]] ;
973             NodalIndex[0]=1 ;
974         
975             // Fill the MEDSKYLINEARRAY by reading the MED file.
976             int j=0;
977             for ( i=0;i<Connectivity->_numberOfTypes;i++) 
978               {
979                 int multi = 0 ;
980                 med_2_2::med_geometrie_element med_type = (med_2_2::med_geometrie_element) Connectivity->_type[i].getType() ;
981                 //        if ( Connectivity->_type[i].getDimension() < Connectivity->_entityDimension) 
982                 //        if (Connectivity->_entity == MED_CELL)
983                 //          if ( Connectivity->_type[i].getDimension() < _ptrMesh->_spaceDimension) 
984                 //            multi=1;
985           
986                 //        int NumberOfCell = Connectivity->_count[i+1]-Connectivity->_count[i] ;
987                 int NumberOfNodeByCell = Connectivity->_type[i].getNumberOfNodes() ;
988           
989                 // initialise index
990                 for ( j=Connectivity->_count[i]; j<Connectivity->_count[i+1];j++)
991                   NodalIndex[j]=NodalIndex[j-1]+NumberOfNodeByCell ; 
992
993             int tmp_numberOfCells = Connectivity->_count[i+1]-Connectivity->_count[i] ;
994                 int * tmp_ConnectivityArray = new int[(NumberOfNodeByCell+multi)*tmp_numberOfCells];
995           
996                 //        int err=MEDconnLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
997             //                    Connectivity->_entityDimension,tmp_ConnectivityArray,
998                 //                            MED_FR::MED_FULL_INTERLACE,NULL,0,Entity,med_type,MED_FR::MED_NOD);
999             int err=MEDconnLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
1000                                 spaceDimension,tmp_ConnectivityArray,
1001                                     med_2_2::MED_FULL_INTERLACE,NULL,0,Entity,med_type,med_2_2::MED_NOD);
1002
1003             if ( err != MED_VALID)
1004               {
1005                 delete[] tmp_ConnectivityArray;
1006                 delete[] tmp_cells_count;
1007                 delete[] tmpFaceCount;
1008                 delete[] tmpEdgeCount;
1009                 MESSAGE(LOC<<": MEDconnLire returns "<<err) ;
1010                 return MED_ERROR ;
1011               }
1012
1013             int * ConnectivityArray = NodalValue + NodalIndex[Connectivity->_count[i]-1]-1 ;
1014
1015             // version originale sans prise en compte des numéros optionnels
1016             //
1017             for ( j=0; j<tmp_numberOfCells; j++) for (int k=0; k<NumberOfNodeByCell; k++) 
1018                   ConnectivityArray[j*NumberOfNodeByCell+k]=tmp_ConnectivityArray[j*(NumberOfNodeByCell+multi)+k] ;
1019
1020             //////////////////////////////////////////////////////////////////////////////
1021             // Modification pour prise en compte de la numérotation optionnelle des noeuds ///
1022             //////////////////////////////////////////////////////////////////////////////
1023             //
1024             // Rénumérote le tableau temporaire tmp_ConnectivityArray en utilisant _optionnalToCanonicNodesNumbers
1025             // Le traitement est identique à la version originelle s'il n'y a pas de numérotation optionnelle
1026                                                      
1027                                                        //       if (_ptrMesh->_arePresentOptionnalNodesNumbers==1) 
1028                                                        //               {
1029                                                        //               for ( j=0; j<tmp_numberOfCells; j++) for (int k=0; k<NumberOfNodeByCell; k++) 
1030                                                        //                       ConnectivityArray[j*NumberOfNodeByCell+k]=_ptrMesh->_optionnalToCanonicNodesNumbers[tmp_ConnectivityArray[j*(NumberOfNodeByCell+multi)+k]] ;
1031                                                        //               }
1032                                                        //       else
1033                                                        //               {
1034                                                        //               for ( j=0; j<tmp_numberOfCells; j++) for (int k=0; k<NumberOfNodeByCell; k++) 
1035                                                        //                       ConnectivityArray[j*NumberOfNodeByCell+k]=tmp_ConnectivityArray[j*(NumberOfNodeByCell+multi)+k] ;
1036                                                        //               }
1037             ////////////////////////////////////////////////////////////////////////////
1038         
1039                                                        delete[] tmp_ConnectivityArray;
1040   
1041               }
1042
1043             Connectivity->_nodal = new MEDSKYLINEARRAY(Connectivity->_count[Connectivity->_numberOfTypes]-1,
1044                                                        size,
1045                                                        NodalIndex,
1046                                                        NodalValue) ; 
1047
1048             delete[] NodalIndex;
1049             delete[] NodalValue;
1050
1051           } // end of bloc to read CELL
1052
1053
1054           // Get Face if any
1055           // ===============
1056      
1057           if (numberOfFacesTypes!=0) 
1058             {
1059
1060               // Create a CONNECTIVITY constituent to put in the top level CONNECTIVITY recursive class
1061               CONNECTIVITY * constituent = new CONNECTIVITY(numberOfFacesTypes,MED_EN::MED_FACE) ;
1062               constituent->_entityDimension = 2 ;
1063               constituent->_count[0]=1 ;
1064
1065               // In order to create the MEDSKYLINEARRAY of the constituent object we need :
1066               // 1:
1067               // To initialize the _count array of the constituent object (containning cumulated face count by geometric type)
1068               // _count[0]=1 and _count[_numberOfTypes] give the size of NodalIndex
1069               // 2:
1070               // To calculate the total number of face nodes whatever the geometric type is.
1071               // The result is the size of the array containning all the nodes : NodalValue
1072               // 3 :
1073               // To calculate the starting indexes of the different face types in NodalValue, 
1074               // this is the NodalIndex array.
1075         
1076               int size       = 0 ; 
1077               int typeNumber = 1 ;
1078               int i;
1079               for ( i=1; i < MED_NBR_GEOMETRIE_MAILLE; i++)
1080                 { // no point1 cell type (?)
1081                   if (tmpFaceCount[i]>0)
1082                     {
1083                       constituent->_count[typeNumber] = constituent->_count[typeNumber-1] + tmpFaceCount[i];
1084                       CELLMODEL t( (MED_EN::medGeometryElement) MED_MESH_DRIVER22::all_cell_type[i]) ;
1085                       constituent->_type[typeNumber-1]=t ;
1086             
1087                       constituent->_geometricTypes[typeNumber-1]=( MED_EN::medGeometryElement) MED_MESH_DRIVER22::all_cell_type[i] ;
1088             
1089                       size+=tmpFaceCount[i]*((MED_MESH_DRIVER22::all_cell_type[i])%100) ;
1090                       typeNumber++;
1091                     }
1092                 }
1093         
1094               // Creation of the MEDSKYLINEARRAY
1095               //constituent->_nodal = new MEDSKYLINEARRAY(constituent->_count[constituent->_numberOfTypes]-1,size) ; 
1096               //int * NodalIndex = constituent->_nodal->getIndex() ;
1097               int * NodalValue = new int[size] ;
1098               int * NodalIndex = new int[constituent->_count[constituent->_numberOfTypes]] ;
1099               NodalIndex[0]=1 ;
1100         
1101               // Fill the MEDSKYLINEARRAY by reading the MED file.
1102               for ( i=0; i<constituent->_numberOfTypes; i++) 
1103                 {
1104                   med_2_2::med_geometrie_element med_type = (med_2_2::med_geometrie_element) constituent->_type[i].getType() ;
1105
1106                   int NumberOfNodeByFace = constituent->_type[i].getNumberOfNodes() ;
1107           
1108                   // initialise NodalIndex
1109                   for (int j=constituent->_count[i]; j<constituent->_count[i+1];j++)
1110                     NodalIndex[j]=NodalIndex[j-1]+NumberOfNodeByFace ; 
1111           
1112           int tmp_numberOfFaces = constituent->_count[i+1]-constituent->_count[i] ;
1113           // Il faut ajouter 1 pour le zero a la lecture !!!
1114           // ATTENTION UNIQUEMENT POUR MED < 2.2.x
1115                   int * tmp_constituentArray = NULL;
1116
1117             MESSAGE(LOC << "Med file version used here " << major << " " << minor << " " << release);
1118
1119             if ((major == 2) && (minor <= 1))
1120                     tmp_constituentArray = new int[(NumberOfNodeByFace+1)*tmp_numberOfFaces] ;
1121             else if ((major == 2) && (minor >= 2))
1122                     {
1123                       tmp_constituentArray = new int[NumberOfNodeByFace*tmp_numberOfFaces] ;
1124             MESSAGE(LOC<<": WE ARE USING MED2.2 so there is no +1 for calculating the size of  tmp_constituentArray !") ;
1125           }
1126
1127                   int err=MEDconnLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
1128                                       Connectivity->_entityDimension,tmp_constituentArray,
1129                                       med_2_2::MED_FULL_INTERLACE,NULL,0,med_2_2::MED_MAILLE,med_type,med_2_2::MED_NOD);
1130
1131                   if ( err != MED_VALID) 
1132                     {
1133                       MESSAGE(LOC<<": MEDconnLire returns "<<err) ;
1134                       delete constituent ;
1135                       delete[] tmp_constituentArray;
1136                       delete[] tmpFaceCount;
1137                       delete[] tmpEdgeCount;
1138                       return MED_ERROR ;
1139                     }
1140
1141                   int * constituentArray = NodalValue + NodalIndex[constituent->_count[i]-1]-1 ;
1142           
1143           // version originale sans prise en compte des numéros optionnels
1144           //    
1145                   int multi = 0; // quand est-ce que multi vaut 1 ?? en MED-fichier < 2.2 ??
1146             MESSAGE(LOC << "Med file version used here " << major << " " << minor << " " << release);
1147
1148             if ((major == 2) && (minor <= 1))
1149               for (int j=0; j<tmp_numberOfFaces; j++)
1150                 for (int k=0; k<NumberOfNodeByFace; k++)
1151                   constituentArray[j*NumberOfNodeByFace+k]=tmp_constituentArray[j*(NumberOfNodeByFace+1)+k] ;
1152             else if ((major == 2) && (minor >= 2))
1153                   for (int j=0; j<tmp_numberOfFaces; j++)
1154                     for (int k=0; k<NumberOfNodeByFace; k++)
1155                   constituentArray[j*NumberOfNodeByFace+k]=tmp_constituentArray[j*(NumberOfNodeByFace+multi)+k] ;
1156
1157                   //////////////////////////////////////////////////////////////////////////////////////
1158                   ///  Modification pour prise en compte de la numérotation optionnelle des noeuds   ///
1159                       //////////////////////////////////////////////////////////////////////////////////////
1160                       ///
1161                       /// Rénumérote le tableau temporaire tmp_constituentArray en utilisant _optionnalToCanonicNodesNumbers
1162                       /// Le traitement est identique à la version originelle s'il n'y a pas de numérotation optionnelle
1163         
1164                       //        if (_ptrMesh->_arePresentOptionnalNodesNumbers) 
1165                       //                {
1166                       //                for (int j=0; j<tmp_numberOfFaces; j++) for (int k=0; k<NumberOfNodeByFace; k++)
1167                       //                        constituentArray[j*NumberOfNodeByFace+k]=_ptrMesh->_optionnalToCanonicNodesNumbers[tmp_constituentArray[j*(NumberOfNodeByFace+1)+k]] ;
1168                       //                }
1169                       //        else
1170                       //                {
1171                       //                for (int j=0; j<tmp_numberOfFaces; j++) for (int k=0; k<NumberOfNodeByFace; k++)
1172                       //                        constituentArray[j*NumberOfNodeByFace+k]=tmp_constituentArray[j*(NumberOfNodeByFace+1)+k] ;
1173                       //                }
1174         
1175                       //////////////////////////////////////////////////////////////////////////////////////
1176           
1177                       delete[] tmp_constituentArray;
1178                 }
1179         
1180               constituent->_nodal = new MEDSKYLINEARRAY(constituent->_count[constituent->_numberOfTypes]-1,
1181                                                         size,
1182                                                         NodalIndex,
1183                                                         NodalValue) ;
1184               delete[] NodalIndex ;
1185               delete[] NodalValue ;
1186
1187
1188               Connectivity->_constituent = constituent ;
1189             }
1190
1191           delete[] tmpFaceCount;
1192
1193
1194           // get Edge if any
1195           // ===============
1196           if (numberOfEdgesTypes!=0) 
1197             {
1198               CONNECTIVITY * constituent = new CONNECTIVITY(numberOfEdgesTypes,MED_EDGE) ;
1199               constituent->_entityDimension = 1 ;
1200               constituent->_count[0]=1 ;
1201
1202               int size = 0 ; 
1203               int typeNumber=1 ;
1204               // if you declare a variable <i> in two <for> initialization statement, 
1205               // compiler gcc2.95.3 says nothing but there are two <i> variables in the same block 
1206               //and the value you get in the common block seems to be the value of the first variable !
1207               int i; 
1208
1209               for ( i=1; i<MED_NBR_GEOMETRIE_MAILLE; i++)  
1210                 { // no point1 cell type (?)
1211                   if (tmpEdgeCount[i]>0) 
1212                     {
1213             
1214                       constituent->_count[typeNumber]=constituent->_count[typeNumber-1]+tmpEdgeCount[i];
1215                       CELLMODEL t( (MED_EN::medGeometryElement) MED_MESH_DRIVER22::all_cell_type[i]) ;
1216                       constituent->_type[typeNumber-1]=t ;
1217             
1218                       constituent->_geometricTypes[typeNumber-1]=( MED_EN::medGeometryElement) MED_MESH_DRIVER22::all_cell_type[i] ;
1219             
1220                       size+=tmpEdgeCount[i]*((MED_MESH_DRIVER22::all_cell_type[i])%100) ;
1221                       typeNumber++;
1222                     }
1223                 }
1224         
1225               // Creation of the MEDSKYLINEARRAY
1226               //constituent->_nodal = new MEDSKYLINEARRAY(constituent->_count[constituent->_numberOfTypes]-1,size) ; 
1227               //int * NodalIndex = constituent->_nodal->getIndex() ;
1228               int * NodalValue = new int[size] ;
1229               int * NodalIndex = new int[constituent->_count[constituent->_numberOfTypes]] ;
1230               NodalIndex[0]=1 ;
1231         
1232               // Fill the MEDSKYLINEARRAY by reading the MED file.
1233               for ( i=0; i<constituent->_numberOfTypes; i++) 
1234                 {
1235                   med_2_2::med_geometrie_element med_type = (med_2_2::med_geometrie_element) constituent->_type[i].getType() ;
1236
1237                   int NumberOfNodeByEdge = constituent->_type[i].getNumberOfNodes() ;
1238           
1239                   // initialise index
1240                   for (int j=constituent->_count[i]; j<constituent->_count[i+1];j++)
1241                     NodalIndex[j]=NodalIndex[j-1]+NumberOfNodeByEdge ; 
1242           
1243                   int tmp_numberOfEdges = constituent->_count[i+1]-constituent->_count[i] ;
1244                   // Il faut ajouter 1 pour le zero a la lecture !!!
1245
1246                   // ATTENTION UNIQUEMENT POUR MED < 2.2.x
1247                   int * tmp_constituentArray = NULL;
1248
1249               MESSAGE(LOC << "Med file version used here " << major << " " << minor << " " << release);
1250
1251               if ((major == 2) && (minor <= 1))
1252                     tmp_constituentArray = new int[(NumberOfNodeByEdge+1)*tmp_numberOfEdges] ;
1253               else if ((major == 2) && (minor >= 2))
1254                     {
1255                       tmp_constituentArray = new int[NumberOfNodeByEdge*tmp_numberOfEdges] ;
1256             MESSAGE(LOC<<": WE ARE USING MED2.2 so there is no +1 for calculating the size of  tmp_constituentArray !") ;
1257           }
1258           
1259                   int err=MEDconnLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
1260                                       spaceDimension,tmp_constituentArray,
1261                                       med_2_2::MED_FULL_INTERLACE,NULL,0,med_2_2::MED_MAILLE,med_type,med_2_2::MED_NOD);
1262                   if ( err != MED_VALID) 
1263                     {
1264                       MESSAGE(LOC<<": MEDconnLire returns "<<err) ;
1265                       delete constituent ;
1266                       delete[] tmp_constituentArray;
1267                       delete[] tmpEdgeCount;
1268                       return MED_ERROR ;
1269                     }
1270
1271                   int * constituentArray = NodalValue + NodalIndex[constituent->_count[i]-1]-1 ;
1272           
1273           // version originale sans prise en compte des numéros optionnels     
1274           //
1275                   int multi = 0; // quand est-ce que multi vaut 1 ?? en MED-fichier < 2.2 ??
1276               MESSAGE(LOC << "Med file version used here " << major << " " << minor << " " << release);
1277
1278               if ((major == 2) && (minor <= 1))
1279                   for (int j=0; j<tmp_numberOfEdges; j++)
1280                     for (int k=0; k<NumberOfNodeByEdge; k++)
1281                     constituentArray[j*NumberOfNodeByEdge+k]=tmp_constituentArray[j*(NumberOfNodeByEdge+multi)+k] ;
1282               else if ((major == 2) && (minor >= 2))
1283                 for (int j=0; j<tmp_numberOfEdges; j++)
1284                   for (int k=0; k<NumberOfNodeByEdge; k++)
1285                     constituentArray[j*NumberOfNodeByEdge+k]=tmp_constituentArray[j*(NumberOfNodeByEdge)+k] ;
1286
1287                   //////////////////////////////////////////////////////////////////////////////////////
1288                   ///  Modification pour prise en compte de la numérotation optionnelle des noeuds   ///
1289                       //////////////////////////////////////////////////////////////////////////////////////
1290                       ///
1291                       /// Rénumérote le tableau temporaire tmp_constituentArray en utilisant _optionnalToCanonicNodesNumbers
1292                       /// Le traitement est identique à la version originelle s'il n'y a pas de numérotation optionnelle
1293         
1294                       //        if (_ptrMesh->_arePresentOptionnalNodesNumbers) 
1295                       //                {
1296                       //                for (int j=0; j<tmp_numberOfEdges; j++) for (int k=0; k<NumberOfNodeByEdge; k++)
1297                       //                        constituentArray[j*NumberOfNodeByEdge+k]=_ptrMesh->_optionnalToCanonicNodesNumbers[tmp_constituentArray[j*(NumberOfNodeByEdge+1)+k]] ;
1298                       //                }
1299                       //        else
1300                       //                {
1301                       //                for (int j=0; j<tmp_numberOfEdges; j++) for (int k=0; k<NumberOfNodeByEdge; k++)
1302                       //                        constituentArray[j*NumberOfNodeByEdge+k]=tmp_constituentArray[j*(NumberOfNodeByEdge+1)+k] ;
1303                       //                }
1304         
1305                       //////////////////////////////////////////////////////////////////////////////////////
1306
1307                       delete[] tmp_constituentArray;
1308                 }
1309
1310               constituent->_nodal = new MEDSKYLINEARRAY(constituent->_count[constituent->_numberOfTypes]-1,
1311                                                         size,
1312                                                         NodalIndex,
1313                                                         NodalValue) ;
1314
1315               delete[] NodalIndex ;
1316               delete[] NodalValue ;
1317
1318               if (Connectivity->_entityDimension == 3) 
1319                 {
1320                   if (Connectivity->_constituent==NULL)
1321                     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Edges are defined but there are no Faces !"));
1322                   Connectivity->_constituent->_constituent = constituent ;
1323                 } else 
1324                   Connectivity->_constituent = constituent ;
1325             }
1326
1327           delete[] tmpEdgeCount; 
1328
1329       
1330         } // end classic geometric types
1331       delete[] tmp_cells_count;
1332
1333
1334
1335       // Lecture des polygones MED_CELL
1336       int NumberOfPolygons = MEDnEntMaa(_medIdt,
1337                                         const_cast <char *> (_ptrMesh->_name.c_str()),
1338                                         med_2_2::MED_CONN,
1339                                         Entity,
1340                                         med_2_2::MED_POLYGONE,
1341                                         med_2_2::MED_NOD);
1342
1343       // Correction to permit the loading of mesh dimensionned at 2 even
1344       // if it has only MED_POLYGON elements
1345
1346       if (NumberOfPolygons > 0)
1347         {
1348           if (Connectivity->_entityDimension < 2) Connectivity->_entityDimension = 2;
1349         }
1350
1351       if (NumberOfPolygons > 0)
1352         {
1353           // By consequence this exception will never occur
1354           if (Connectivity->_entityDimension == 1)
1355             throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"In a 2D mesh, polygons need at least one 2D cell of a classic geometric type !"));
1356           med_int ConnectivitySize;
1357           med_err err1 = MEDpolygoneInfo(_medIdt,
1358                                          const_cast <char *> (_ptrMesh->_name.c_str()),
1359                                          Entity,
1360                                          med_2_2::MED_NOD,
1361                                          &ConnectivitySize);
1362           if (err1 != MED_VALID)
1363             {
1364               MESSAGE(LOC<<": MEDpolygoneInfo returns "<<err1);
1365               return MED_ERROR;
1366             }
1367       
1368           med_int* PolygonsConnectivity = new med_int[ConnectivitySize];
1369           med_int* PolygonsConnectivityIndex = new med_int[NumberOfPolygons+1];
1370       
1371           med_err err2 = MEDpolygoneConnLire(_medIdt,
1372                                              const_cast <char *> (_ptrMesh->_name.c_str()),
1373                                              PolygonsConnectivityIndex,
1374                                              NumberOfPolygons+1,
1375                                              PolygonsConnectivity,
1376                                              Entity,
1377                                              med_2_2::MED_NOD);
1378           if (err2 != MED_VALID)
1379             {
1380               MESSAGE(LOC<<": MEDpolygoneConnLire returns "<<err2);
1381               return MED_ERROR;
1382             }
1383       
1384           if (Connectivity->_entityDimension == 2) // 2D mesh : polygons in Connectivity
1385             Connectivity->setPolygonsConnectivity(MED_NODAL,(medEntityMesh) Entity,PolygonsConnectivity,PolygonsConnectivityIndex,ConnectivitySize,NumberOfPolygons);
1386           else if (Connectivity->_entityDimension == 3)
1387             {
1388               if (Connectivity->_constituent == NULL) // 3D mesh : polygons in Connectivity->_constituent
1389                 Connectivity->_constituent = new CONNECTIVITY(MED_FACE);
1390               Connectivity->_constituent->setPolygonsConnectivity(MED_NODAL,MED_FACE,PolygonsConnectivity,PolygonsConnectivityIndex,ConnectivitySize,NumberOfPolygons);
1391             }
1392       
1393           delete[] PolygonsConnectivity;
1394           delete[] PolygonsConnectivityIndex;
1395         } // end polygons
1396   
1397
1398
1399       // Lecture des polyedres MED_CELL
1400       med_int NumberOfPolyhedron = MEDnEntMaa(_medIdt,
1401                                               const_cast <char *> (_ptrMesh->_name.c_str()),
1402                                               med_2_2::MED_CONN,
1403                                               Entity,
1404                                               med_2_2::MED_POLYEDRE,
1405                                               med_2_2::MED_NOD);
1406
1407       // Correction to permit the loading of mesh dimensionned at 3 even
1408       // if it has only MED_POLYEDRE elements
1409
1410       if (NumberOfPolyhedron > 0)
1411         {
1412           Connectivity->_entityDimension = 3;
1413         }
1414
1415       if (NumberOfPolyhedron > 0)
1416         {
1417           // By consequence this exception will never occur
1418           if (Connectivity->_entityDimension == 2 || Connectivity->_entityDimension == 1)
1419             throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"In a 3D mesh, polyhedron need at least one 3D cell of a classic geometric type !"));
1420           med_int FacesIndexSize, NumberOfNodes, NumberOfFaces;
1421           med_err err3 = MEDpolyedreInfo(_medIdt,
1422                                          const_cast <char *> (_ptrMesh->_name.c_str()),
1423                                          med_2_2::MED_NOD,
1424                                          &FacesIndexSize,
1425                                          &NumberOfNodes);
1426           NumberOfFaces = FacesIndexSize-1;
1427           if (err3 != MED_VALID)
1428             {
1429               MESSAGE(LOC<<": MEDpolyhedreInfo returns "<<err3);
1430               return MED_ERROR;
1431             }
1432       
1433           med_int* Nodes = new med_int[NumberOfNodes];
1434           med_int* FacesIndex = new med_int[NumberOfFaces+1];
1435           med_int* PolyhedronIndex = new med_int[NumberOfPolyhedron+1];
1436           
1437           med_err err4 = MEDpolyedreConnLire(_medIdt,
1438                                              const_cast <char *> (_ptrMesh->_name.c_str()),
1439                                              PolyhedronIndex,
1440                                              NumberOfPolyhedron+1,
1441                                              FacesIndex,
1442                                              NumberOfFaces+1,
1443                                              Nodes,
1444                                              med_2_2::MED_NOD);
1445           if (err4 != MED_VALID)
1446             {
1447               MESSAGE(LOC<<": MEDpolyedreConnLire returns "<<err4);
1448               return MED_ERROR;
1449             }
1450       
1451           Connectivity->setPolyhedronConnectivity(MED_NODAL,Nodes,PolyhedronIndex,NumberOfNodes,NumberOfPolyhedron,FacesIndex,NumberOfFaces);
1452           
1453           delete[] Nodes;
1454           delete[] FacesIndex;
1455           delete[] PolyhedronIndex;
1456         } // end polyhedron
1457
1458
1459
1460       // If there is no nodal connectivity, we return MED_ERROR !
1461       if (Connectivity->_numberOfTypes == 0 && NumberOfPolygons == 0 && NumberOfPolyhedron == 0)
1462         return MED_ERROR;
1463       else
1464         return MED_VALID;
1465
1466     }
1467   return MED_ERROR;
1468 }
1469
1470 int  MED_MESH_RDONLY_DRIVER22::getFAMILY() 
1471 {
1472   const char * LOC = "MED_MESH_RDONLY_DRIVER22::getFAMILY() : " ;
1473   BEGIN_OF(LOC);
1474
1475   if (_status==MED_OPENED)
1476     {
1477       int err = 0 ;
1478
1479       int * MEDArrayNodeFamily = NULL ;
1480       int ** MEDArrayCellFamily = NULL ;
1481       int ** MEDArrayFaceFamily = NULL ;
1482       int ** MEDArrayEdgeFamily = NULL ;
1483
1484     // NODE :
1485       MEDArrayNodeFamily = new int[_ptrMesh->getNumberOfNodes()] ;
1486
1487       err = getNodesFamiliesNumber(MEDArrayNodeFamily) ;
1488       // error only if (_status!=MED_OPENED), other case exeception !
1489       // CELL
1490
1491       MESSAGE(LOC << "error returned from getNodesFamiliesNumber " << err);
1492
1493       MEDArrayCellFamily = new int* [_ptrMesh->getNumberOfTypesWithPoly(MED_CELL)] ;
1494       // ET SI IL N'Y A PAS DE CELLS ?
1495
1496       medGeometryElement * myTypes = _ptrMesh->getTypesWithPoly(MED_CELL);
1497       for (int i=0;i<_ptrMesh->getNumberOfTypesWithPoly(MED_CELL);i++)
1498         MEDArrayCellFamily[i] = new
1499           int[_ptrMesh->getNumberOfElementsWithPoly(MED_CELL,myTypes[i])] ;
1500
1501       err = getCellsFamiliesNumber(MEDArrayCellFamily,
1502                                    _ptrMesh->_connectivity,MED_CELL) ;
1503       delete [] myTypes;
1504
1505       MESSAGE(LOC << "error returned from getCellsFamiliesNumber for Cells " << err);
1506
1507     if (_ptrMesh->_connectivity->_constituent != NULL)
1508       {
1509         if (_ptrMesh->_connectivity->_constituent->_entity == MED_EN::MED_FACE)
1510           {
1511             // FACE
1512             MEDArrayFaceFamily = new
1513               int* [_ptrMesh->getNumberOfTypesWithPoly(MED_FACE)] ;
1514
1515             myTypes = _ptrMesh->getTypesWithPoly(MED_FACE);
1516             for (int i=0;i<_ptrMesh->getNumberOfTypesWithPoly(MED_FACE);i++)
1517               MEDArrayFaceFamily[i] = new
1518                 int[_ptrMesh->getNumberOfElementsWithPoly(MED_FACE,myTypes[i])] ;
1519
1520             err =
1521               getCellsFamiliesNumber(MEDArrayFaceFamily,
1522                                      _ptrMesh->_connectivity->_constituent,MED_FACE) ;
1523             delete [] myTypes;
1524             MESSAGE(LOC << "error returned from getCellsFamiliesNumber for Faces " << err);
1525           }
1526         else
1527           {
1528             // EDGE in 2D
1529             MEDArrayEdgeFamily = new
1530               int* [_ptrMesh->getNumberOfTypes(MED_EDGE)] ;
1531
1532             const medGeometryElement *myTypes2 = _ptrMesh->getTypes(MED_EDGE);
1533             for (int i=0;i<_ptrMesh->getNumberOfTypes(MED_EDGE);i++)
1534               MEDArrayEdgeFamily[i] = new
1535                 int[_ptrMesh->getNumberOfElements(MED_EDGE,myTypes2[i])] ;
1536
1537             err =
1538               getCellsFamiliesNumber(MEDArrayEdgeFamily,
1539                                      _ptrMesh->_connectivity->_constituent,MED_FACE) ;
1540           
1541             MESSAGE(LOC << "error returned from getCellsFamiliesNumber for Edges in 2D " << err);
1542           }
1543         // EDGE in 3D
1544         if (_ptrMesh->_connectivity->_constituent->_constituent != NULL)
1545           {
1546             MEDArrayEdgeFamily = new
1547               int* [_ptrMesh->getNumberOfTypes(MED_EDGE)] ;
1548
1549             const medGeometryElement *myTypes2 = _ptrMesh->getTypes(MED_EDGE);
1550             for (int i=0;i<_ptrMesh->getNumberOfTypes(MED_EDGE);i++)
1551               MEDArrayEdgeFamily[i] = new
1552                 int[_ptrMesh->getNumberOfElements(MED_EDGE,myTypes2[i])] ;
1553
1554             err =
1555               getCellsFamiliesNumber(MEDArrayEdgeFamily,
1556                                      _ptrMesh->_connectivity->_constituent->_constituent,MED_EDGE);
1557             // we are in 3D !
1558         
1559             MESSAGE(LOC << "error returned from getCellsFamiliesNumber for Edges in 3D " << err);
1560
1561           }
1562       }
1563
1564     int NumberOfFamilies = med_2_2::MEDnFam(_medIdt, const_cast <char *>
1565                                            (_meshName.c_str())) ;
1566
1567     if ( NumberOfFamilies < 1 ) // at least family 0 must exist 
1568       throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"There is no FAMILY, FAMILY 0 must exists" ));
1569
1570     SCRUTE(NumberOfFamilies);
1571
1572     vector<FAMILY*> &NodeFamilyVector = _ptrMesh->_familyNode ;
1573     vector<FAMILY*> &CellFamilyVector = _ptrMesh->_familyCell ;
1574     vector<FAMILY*> &FaceFamilyVector = _ptrMesh->_familyFace ;
1575     vector<FAMILY*> &EdgeFamilyVector = _ptrMesh->_familyEdge ;
1576
1577     int numberOfNodesFamilies = 0 ;
1578     int numberOfCellsFamilies = 0 ;
1579     int numberOfFacesFamilies = 0 ;
1580     int numberOfEdgesFamilies = 0 ;
1581
1582     for (int i=0;i<NumberOfFamilies;i++)
1583       {
1584         int NumberOfAttributes = med_2_2::MEDnAttribut(_medIdt,
1585                                                       const_cast <char *>
1586                                                       (_meshName.c_str()),
1587                                                       (i+1));
1588       
1589       if (NumberOfAttributes < 0) 
1590         throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER22::getFAMILY() : NumberOfAttributes" );
1591
1592         int NumberOfGroups = med_2_2::MEDnGroupe(_medIdt, const_cast <char *>
1593                                                 (_meshName.c_str()),(i+1)) ;
1594
1595         if (NumberOfGroups < 0)
1596           throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER22::getFAMILY() : NumberOfGroups" );
1597       
1598         int FamilyIdentifier ;
1599         string FamilyName(MED_TAILLE_NOM,'\0');
1600         int *  AttributesIdentifier = new int[NumberOfAttributes] ;
1601         int *  AttributesValues     = new int[NumberOfAttributes] ;
1602         string AttributesDescription(MED_TAILLE_DESC*NumberOfAttributes,' ') ;
1603         string GroupsNames(MED_TAILLE_LNOM*NumberOfGroups+1,'\0') ;
1604         err = med_2_2::MEDfamInfo(_medIdt,const_cast <char *>
1605                                  (_meshName.c_str()),
1606                                  (i+1),const_cast <char *>
1607                                  (FamilyName.c_str()), &FamilyIdentifier,
1608                                  AttributesIdentifier,AttributesValues,
1609                                  const_cast <char *>
1610                                  (AttributesDescription.c_str()),
1611                                  &NumberOfAttributes, const_cast <char *>
1612                                  (GroupsNames.c_str()),&NumberOfGroups);
1613
1614
1615         SCRUTE(GroupsNames);
1616         SCRUTE(FamilyName);
1617         SCRUTE(err);
1618         SCRUTE(i);
1619
1620       if (err != MED_VALID)
1621         throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER22::getFAMILY() : ERROR when get FAMILY informations" );
1622
1623         if (FamilyIdentifier != 0 )
1624           {
1625             FAMILY * Family = new FAMILY(_ptrMesh,FamilyIdentifier,FamilyName,
1626                                          NumberOfAttributes,
1627                                          AttributesIdentifier,
1628                                          AttributesValues,
1629                                          AttributesDescription,
1630                                          NumberOfGroups,GroupsNames,
1631                                          MEDArrayNodeFamily,
1632                                          MEDArrayCellFamily,
1633                                          MEDArrayFaceFamily,
1634                                          MEDArrayEdgeFamily) ;
1635
1636             // All good ?
1637             // if nothing found, delete Family
1638
1639             if (Family->getNumberOfTypes() == 0)
1640               {
1641                 MESSAGE(LOC<<"Nothing found for family "<<FamilyName<<
1642                         " : skip");
1643                 delete Family;
1644               }
1645             else
1646               switch (Family->getEntity())
1647                 {
1648                 case MED_EN::MED_NODE :
1649                   NodeFamilyVector.push_back(Family) ;
1650                   numberOfNodesFamilies++ ;
1651                   break ;
1652                 case MED_EN::MED_CELL :
1653                   CellFamilyVector.push_back(Family) ;
1654                   numberOfCellsFamilies++ ;
1655                   break ;
1656                 case MED_EN::MED_FACE :
1657                   FaceFamilyVector.push_back(Family) ;
1658                   numberOfFacesFamilies++ ;
1659                   break ;
1660                 case MED_EN::MED_EDGE :
1661                   EdgeFamilyVector.push_back(Family) ;
1662                   numberOfEdgesFamilies++ ;
1663                   break ;
1664                 }
1665             //  MESSAGE(LOC << (*Family));
1666           }
1667
1668         delete [] AttributesIdentifier ;
1669         delete [] AttributesValues ;
1670       }
1671
1672     if (MEDArrayNodeFamily != NULL)
1673       delete[] MEDArrayNodeFamily ;
1674
1675     if (MEDArrayCellFamily != NULL)
1676       {
1677         for (int i=0;i<_ptrMesh->getNumberOfTypes(MED_CELL);i++)
1678           delete[] MEDArrayCellFamily[i] ;
1679         delete[] MEDArrayCellFamily ;
1680       }
1681
1682     if (MEDArrayFaceFamily != NULL)
1683       {
1684         for (int i=0;i<_ptrMesh->getNumberOfTypes(MED_FACE);i++)
1685           delete[] MEDArrayFaceFamily[i] ;
1686         delete[] MEDArrayFaceFamily ;
1687       }
1688
1689     if (MEDArrayEdgeFamily != NULL)
1690       {
1691         for (int i=0;i<_ptrMesh->getNumberOfTypes(MED_EDGE);i++)
1692           delete[] MEDArrayEdgeFamily[i] ;
1693         delete[] MEDArrayEdgeFamily ;
1694       }
1695
1696     END_OF(LOC);
1697     return MED_VALID ;
1698     }
1699
1700   return MED_ERROR;
1701 }
1702
1703 int  MED_MESH_RDONLY_DRIVER22::getNodesFamiliesNumber(int * MEDArrayNodeFamily)
1704 {
1705   const char * LOC = "MED_MESH_RDONLY_DRIVER22::getNodesFamiliesNumber() : " ;
1706
1707   BEGIN_OF(LOC);
1708
1709   if (_status==MED_OPENED)
1710     {
1711     int err = 0 ;
1712
1713       err = MEDfamLire(_medIdt, const_cast <char *>
1714                        (_ptrMesh->_name.c_str()), MEDArrayNodeFamily,
1715                        _ptrMesh->getNumberOfNodes(), med_2_2::MED_NOEUD,
1716                        (med_2_2::med_geometrie_element) MED_NONE);
1717
1718       if ( err != MED_VALID)
1719         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "There is no family for the |"<< _ptrMesh->getNumberOfNodes() << "| nodes in mesh |" << _ptrMesh->_name.c_str() << "|"));
1720
1721       END_OF(LOC);
1722       return MED_VALID;
1723     }
1724
1725   return MED_ERROR;
1726 }
1727
1728 int  MED_MESH_RDONLY_DRIVER22::getCellsFamiliesNumber(int **MEDArrayFamily,
1729                                                       CONNECTIVITY *Connectivity,
1730                                                       MED_EN::medEntityMesh entity) 
1731 {
1732   const char * LOC = "MED_MESH_RDONLY_DRIVER22::getCellsFamiliesNumber " ;
1733
1734   BEGIN_OF(LOC);
1735
1736   if (_status==MED_OPENED)
1737     {
1738     int i, err = 0 ;
1739     MED_EN::medGeometryElement *types=Connectivity->getGeometricTypesWithPoly(Connectivity->_entity);
1740     for (i=0;i<Connectivity->getNumberOfTypesWithPoly(Connectivity->_entity);i++)
1741       {
1742         int NumberOfCell=Connectivity->getNumberOfElementsWithPoly(Connectivity->_entity,types[i]);
1743         err=MEDfamLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
1744                        MEDArrayFamily[i],NumberOfCell,
1745                        (med_2_2::med_entite_maillage) Connectivity->_entity,
1746                        (med_2_2::med_geometrie_element)types[i]);
1747         if (err != MED_VALID)
1748           {
1749             err=MEDfamLire(_medIdt,const_cast <char *>
1750                            (_ptrMesh->_name.c_str()),
1751                            MEDArrayFamily[i],NumberOfCell,
1752                            med_2_2::MED_MAILLE,
1753                            (med_2_2::med_geometrie_element)types[i]);
1754             if (err != MED_VALID)
1755               throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Family not found for entity "<<Connectivity->_entity<<" and geometric type "<<Connectivity->_geometricTypes[i]));
1756           }
1757       }
1758     delete [] types;
1759     return MED_VALID;
1760     }
1761   return MED_ERROR;
1762 }
1763
1764 /*--------------------- WRONLY PART -------------------------------*/
1765
1766 MED_MESH_WRONLY_DRIVER22::MED_MESH_WRONLY_DRIVER22()
1767 {
1768 }
1769   
1770 MED_MESH_WRONLY_DRIVER22::MED_MESH_WRONLY_DRIVER22(const string & fileName,
1771                                                    MESH * ptrMesh):
1772   MED_MESH_DRIVER22(fileName,ptrMesh,MED_WRONLY),IMED_MESH_WRONLY_DRIVER(fileName,ptrMesh),MED_MESH_DRIVER(fileName,ptrMesh,MED_WRONLY)
1773 {
1774   MESSAGE("MED_MESH_WRONLY_DRIVER22::MED_MESH_WRONLY_DRIVER22(const string & fileName, MESH * ptrMesh) has been created");
1775 }
1776
1777 MED_MESH_WRONLY_DRIVER22::MED_MESH_WRONLY_DRIVER22(const MED_MESH_WRONLY_DRIVER22 & driver):
1778   IMED_MESH_WRONLY_DRIVER(driver),MED_MESH_DRIVER22(driver),MED_MESH_DRIVER(driver)
1779 {
1780 }
1781
1782 MED_MESH_WRONLY_DRIVER22::~MED_MESH_WRONLY_DRIVER22()
1783 {
1784   //MESSAGE("MED_MESH_WRONLY_DRIVER22::MED_MESH_WRONLY_DRIVER22(const string & fileName, MESH * ptrMesh) has been destroyed");
1785 }
1786
1787 GENDRIVER * MED_MESH_WRONLY_DRIVER22::copy(void) const
1788 {
1789   return new MED_MESH_WRONLY_DRIVER22(*this);
1790 }
1791
1792 void MED_MESH_WRONLY_DRIVER22::write(void) const
1793
1794   const char * LOC = "void MED_MESH_WRONLY_DRIVER22::write(void) const : ";
1795   BEGIN_OF(LOC);
1796
1797   // we must first create mesh !!
1798   MESSAGE(LOC << "MeshName : |" << _meshName << "| FileName : |"<<_fileName<<"| MedIdt : | "<< _medIdt << "|");
1799
1800   if (_status!=MED_OPENED)
1801     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "File "<<_fileName<<" is not open. Open it before write !"));
1802
1803   string fieldName;
1804   if ( ( _meshName.empty() ) && ( _ptrMesh->_name.empty() )    )
1805     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)
1806                                  <<" neither <meshName> is set in driver nor in object MESH.")) ;
1807
1808   // If _meshName is not set in driver, try to use _ptrmesh->_meshName
1809   if ( ( _meshName.empty() ) && ( !_ptrMesh->_name.empty() )    )
1810     _meshName=_ptrMesh->_name;
1811
1812   if ( _meshName.size() > MED_TAILLE_NOM )
1813     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)
1814                                  <<" <meshName> size in object driver MESH is > MED_TAILLE_NOM ."));
1815
1816
1817   if (_ptrMesh->getIsAGrid())
1818   {
1819     if ( writeGRID() != MED_VALID )
1820       throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeGRID()"  )) ;
1821   }
1822   else
1823   {
1824     if (writeCoordinates()!=MED_VALID)
1825       throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeCoordinates()"  )) ;
1826
1827     if (writeConnectivities(MED_EN::MED_CELL)!=MED_VALID)
1828       throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeConnectivities(MED_CELL)"  )) ;
1829     if (writeConnectivities(MED_EN::MED_FACE)!=MED_VALID)
1830       throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeConnectivities(MED_FACE)"  )) ;
1831     if (writeConnectivities(MED_EN::MED_EDGE)!=MED_VALID)
1832       throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeConnectivities(MED_EDGE)"  )) ;
1833   }
1834
1835   if (writeFamilyNumbers() !=MED_VALID)
1836     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilyNumbers()"  )) ;
1837   
1838
1839   // well we must first write zero family :
1840   if (_status==MED_OPENED) {
1841     int err ;
1842     // test if the family already exists (HDF trick waiting a MED evolution to be replaced)
1843     string dataGroupFam = "/ENS_MAA/"+_meshName+"/FAS/FAMILLE_ZERO/";  
1844     MESSAGE("|"<<dataGroupFam<<"|");
1845     err =med_2_2::_MEDdatagroupOuvrir(_medIdt,const_cast <char *> (dataGroupFam.c_str()) );
1846     if ( err < MED_VALID ) {
1847       SCRUTE(err);
1848
1849       char familyName[MED_TAILLE_NOM+1];
1850       //      strcpy(familyName,"FAMILLE_ZERO");
1851       err = med_2_2::MEDfamCr( _medIdt,
1852                               const_cast <char *> ( _meshName.c_str() ),
1853                               familyName, 0,
1854                               (int*)NULL, (int*)NULL, (char*)NULL, 0,
1855                               (char*)NULL, 0);
1856
1857       SCRUTE(familyName);
1858       
1859       if ( err != MED_VALID) 
1860         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't create family |FAMILLE_ZERO| with identifier |0| groups names || and  attributes descriptions ||")) ;
1861     }
1862     else
1863       med_2_2::_MEDdatagroupFermer(_medIdt);
1864      
1865   }
1866
1867   MESSAGE(LOC<<"writeFamilies(_ptrMesh->_familyNode)");
1868   if (writeFamilies(_ptrMesh->_familyNode) !=MED_VALID)
1869     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilies(_ptrMesh->_familyNode)"  )) ;
1870
1871   MESSAGE(LOC<<"writeFamilies(_ptrMesh->_familyCell)");
1872   if (writeFamilies(_ptrMesh->_familyCell) !=MED_VALID)
1873     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilies(_ptrMesh->_familyCell)"  )) ;
1874
1875   MESSAGE(LOC<<"writeFamilies(_ptrMesh->_familyFace)");
1876   if (writeFamilies(_ptrMesh->_familyFace) !=MED_VALID)
1877     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilies(_ptrMesh->_familyFace)"  )) ;
1878
1879   MESSAGE(LOC<<"writeFamilies(_ptrMesh->_familyEdge)");
1880   if (writeFamilies(_ptrMesh->_familyEdge) !=MED_VALID)
1881     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilies(_ptrMesh->_familyEdge)"  )) ;
1882
1883   END_OF(LOC);
1884
1885
1886 //=======================================================================
1887 //function : writeGRID
1888 //purpose  : 
1889 //=======================================================================
1890
1891 int MED_MESH_WRONLY_DRIVER22::writeGRID() const
1892 {
1893   const char * LOC = "MED_MESH_WRONLY_DRIVER22::writeGRID() : " ;
1894   BEGIN_OF(LOC);
1895   
1896   if (_status!=MED_OPENED)
1897   {
1898     MESSAGE (LOC<<" Not open !!!");
1899     return MED_ERROR;
1900   }
1901   GRID * ptrGrid = (GRID*) _ptrMesh;
1902   
1903   med_2_2::med_err err = MED_ERROR;
1904   med_2_2::med_repere rep;
1905   string tmp_name(_ptrMesh->_spaceDimension*MED_TAILLE_PNOM22,' ');
1906   string tmp_unit(_ptrMesh->_spaceDimension*MED_TAILLE_PNOM22,' ');
1907
1908   // Test if the mesh <_meshName> already exists
1909   // If it doesn't exists create it
1910   // If it already exists verify if its space and mesh dimensions are the same
1911   // as <_ptrMesh->_spaceDimension>, <_ptrMesh->_meshDimension> respectively
1912   // rem : <_meshName> is the driver meshName not <ptrMesh->_meshName>
1913
1914   int spaceDimension = med_2_2::MEDdimEspaceLire(_medIdt, const_cast <char *>
1915                                                 (_meshName.c_str()) );
1916
1917   int meshDimension = med_2_2::MEDdimLire(_medIdt, const_cast <char *>
1918                                          (_meshName.c_str()) );
1919
1920
1921   MESSAGE(LOC << "spacedim " << spaceDimension << " meshdim " << meshDimension);
1922
1923   MESSAGE(LOC << "From the mesh spacedim " << _ptrMesh->_spaceDimension << " meshdim " << _ptrMesh->_meshDimension);
1924
1925   if ((spaceDimension <= MED_VALID) && (meshDimension <= MED_VALID))
1926     {
1927       err = MEDmaaCr(_medIdt,
1928                      const_cast <char *> (_meshName.c_str()),
1929                      _ptrMesh->_meshDimension,med_2_2::MED_STRUCTURE,
1930                      const_cast <char *> (_ptrMesh->_description.c_str()));
1931
1932       meshDimension =  _ptrMesh->_meshDimension;
1933
1934       if (err != MED_VALID)
1935         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Unable to create Grid"));
1936       else 
1937         MESSAGE(LOC<<"Grid "<<_meshName<<" created in file "<<_fileName<<" !");
1938     }
1939   else if ((spaceDimension != _ptrMesh->_spaceDimension)  &&
1940            (meshDimension != _ptrMesh->_meshDimension))
1941     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Grid |" << _meshName.c_str() <<
1942                                  "| already exists in file |" << _fileName <<
1943                                  "| with space dimension |" << spaceDimension <<
1944                                  "| and mesh dimension |" << meshDimension <<
1945                                  "| but the space dimension and the mesh dimension of the mesh we want to write are respectively |"
1946                                  << _ptrMesh->_spaceDimension <<"|" <<
1947                                  _ptrMesh->_meshDimension <<"|" )) ;
1948
1949   MED_EN::med_grid_type gridType = ptrGrid->getGridType();
1950
1951   err = med_2_2::MEDnatureGrilleEcr(_medIdt,
1952                                    const_cast <char *> (_meshName.c_str()),
1953                                    (med_2_2::med_type_grille) gridType);
1954
1955   if (err != MED_VALID)
1956     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Unable to write the type of the Grid"));
1957
1958   // Recompose the <_spaceDimension> strings in 1 string 
1959   int lengthString ;
1960   string valueString ;
1961   for (int i=0;i<_ptrMesh->_spaceDimension;i++) {
1962     SCRUTE(i);
1963     valueString = _ptrMesh->_coordinate->_coordinateName[i] ;
1964     lengthString = (MED_TAILLE_PNOM22<valueString.size())?MED_TAILLE_PNOM22:valueString.size() ;
1965     tmp_name.replace(i*MED_TAILLE_PNOM22,i*MED_TAILLE_PNOM22+lengthString,valueString,0,lengthString);
1966     valueString = _ptrMesh->_coordinate->_coordinateUnit[i];
1967     lengthString = (MED_TAILLE_PNOM22<valueString.size())?MED_TAILLE_PNOM22:valueString.size() ;
1968     tmp_unit.replace(i*MED_TAILLE_PNOM22,i*MED_TAILLE_PNOM22+lengthString,valueString,0,lengthString);
1969   }
1970
1971   // Pourquoi le stocker sous forme de chaîne ?
1972   const string & coordinateSystem = _ptrMesh->_coordinate->_coordinateSystem;
1973   if      (coordinateSystem  == "CARTESIAN") 
1974     rep = med_2_2::MED_CART;
1975   else if ( coordinateSystem == "CYLINDRICAL")
1976     rep = med_2_2::MED_CYL;
1977   else if ( coordinateSystem == "SPHERICAL" )
1978     rep = med_2_2::MED_SPHER;
1979   else
1980     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Grid |" << _meshName.c_str() <<
1981                                  "| doesn't have a valid coordinate system : |" 
1982                                  << _ptrMesh->_coordinate->_coordinateSystem
1983                                  << "|" )) ;  
1984
1985   med_2_2::med_int ArrayLen[] = { (med_2_2::med_int) ptrGrid->_iArrayLength,
1986                      (med_2_2::med_int) ptrGrid->_jArrayLength,
1987                      (med_2_2::med_int) ptrGrid->_kArrayLength  };
1988   
1989   // Write node coordinates for MED_BODY_FITTED grid
1990   if (gridType == MED_EN::MED_BODY_FITTED)
1991     {
1992       // Write Coordinates and families
1993 //       double * coo = const_cast <double *>
1994 //      (_ptrMesh->_coordinate->getCoordinates(MED_EN::MED_FULL_INTERLACE));
1995
1996       err = MEDcoordEcr(_medIdt, const_cast <char *> (_meshName.c_str()),
1997                         _ptrMesh->_spaceDimension, 
1998                         //const_cast <double *> ( _ptrMesh->_coordinate->_coordinate->get(MED_EN::MED_FULL_INTERLACE) ), 
1999                         const_cast <double *> ( _ptrMesh->_coordinate->_coordinate.get(MED_EN::MED_FULL_INTERLACE) ), 
2000                         med_2_2::MED_FULL_INTERLACE, _ptrMesh->_numberOfNodes,
2001                         //  _ptrMesh->_coordinate->_numberOfNodes
2002                         rep, const_cast <char *> (tmp_name.c_str()), 
2003                         const_cast <char *> (tmp_unit.c_str()));
2004
2005       if (err != MED_VALID) 
2006         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write coordinates of the grid |" << _meshName.c_str() << "| in file |" << _fileName
2007                                      << "| with dimension |"  << _ptrMesh->_spaceDimension <<"| and" 
2008                                      << " with units names |"  << tmp_name
2009                                      << "| and units |"       << tmp_unit
2010                                      << " |")) ;
2011
2012       int* structure = new int [meshDimension];
2013
2014       for (int idim = 0; idim < meshDimension; ++idim)
2015         structure[idim] = ArrayLen [idim];
2016  
2017
2018       err = med_2_2::MEDstructureCoordEcr(_medIdt, const_cast <char *>
2019                                          (_meshName.c_str()), meshDimension,
2020                                          structure);
2021
2022       if (err != MED_VALID)
2023         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"error in writing the structure of the grid |" << _meshName.c_str()));
2024
2025       delete structure;
2026     }
2027   else if ((gridType == MED_EN::MED_CARTESIAN) ||
2028            (gridType == MED_EN::MED_POLAR))
2029     {
2030       // Write Arrays of Cartesian or Polar Grid
2031
2032       double * Array[] = { ptrGrid->_iArray,
2033                            ptrGrid->_jArray,
2034                            ptrGrid->_kArray };
2035
2036       for (int idim = 0; idim < _ptrMesh->_meshDimension; ++idim)
2037         {
2038           string str_name = string (tmp_name,idim*MED_TAILLE_PNOM22,
2039                                     MED_TAILLE_PNOM22);
2040           string str_unit = string (tmp_unit,idim*MED_TAILLE_PNOM22,
2041                                     MED_TAILLE_PNOM22);
2042
2043           err = med_2_2::MEDindicesCoordEcr(_medIdt, const_cast <char *>
2044                                            (_ptrMesh->_name.c_str()),
2045                                            _ptrMesh->_meshDimension,
2046                                            Array[idim], ArrayLen[idim],
2047                                            (idim+1), const_cast <char *>
2048                                            (str_name.c_str()),
2049                                            const_cast <char *>
2050                                            (str_unit.c_str()));
2051
2052           if (err != MED_VALID)
2053             throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<
2054                                          "Can't write grid coordinates for " <<
2055                                          idim << "-th dimention"));
2056         }
2057   } // end Write  Cartesian or Polar Grid
2058
2059   END_OF(LOC);
2060   return MED_VALID;
2061 }
2062
2063 //=======================================================================
2064 //function : writeCoordinates
2065 //purpose  : 
2066 //=======================================================================
2067
2068 int MED_MESH_WRONLY_DRIVER22::writeCoordinates() const {
2069  
2070   const char * LOC = "int MED_MESH_WRONLY_DRIVER22::writeCoordinates() const : ";
2071   BEGIN_OF(LOC);
2072
2073   med_2_2::med_err err = MED_ERROR;
2074   med_2_2::med_repere rep;
2075   string tmp_name(_ptrMesh->_spaceDimension*MED_TAILLE_PNOM22,' ');
2076   string tmp_unit(_ptrMesh->_spaceDimension*MED_TAILLE_PNOM22,' ');
2077     
2078   // Recompose the <_spaceDimension> strings in 1 string 
2079   int lengthString ;
2080   string valueString ;
2081   for (int i=0;i<_ptrMesh->_spaceDimension;i++) {
2082     valueString = _ptrMesh->_coordinate->_coordinateName[i] ;
2083     lengthString = (MED_TAILLE_PNOM22<valueString.size())?MED_TAILLE_PNOM22:valueString.size() ;
2084     tmp_name.replace(i*MED_TAILLE_PNOM22,i*MED_TAILLE_PNOM22+lengthString,valueString,0,lengthString);
2085     valueString = _ptrMesh->_coordinate->_coordinateUnit[i];
2086     lengthString = (MED_TAILLE_PNOM22<valueString.size())?MED_TAILLE_PNOM22:valueString.size() ;
2087     tmp_unit.replace(i*MED_TAILLE_PNOM22,i*MED_TAILLE_PNOM22+lengthString,valueString,0,lengthString);
2088   }
2089
2090   // Test if the mesh <_meshName> already exists
2091   // If it doesn't exists create it
2092   // If it already exists verify if its space and mesh dimensions are the same
2093   // as <_ptrMesh->_spaceDimension>, <_ptrMesh->_meshDimension> respectively
2094   // rem : <_meshName> is the driver meshName not <ptrMesh->_meshName>
2095
2096   int spaceDimension = med_2_2::MEDdimEspaceLire(_medIdt, const_cast <char *>
2097                                                 (_meshName.c_str()));
2098
2099   int meshDimension = med_2_2::MEDdimLire(_medIdt, const_cast <char *>
2100                                          (_meshName.c_str()) );
2101
2102   SCRUTE(spaceDimension);
2103   SCRUTE(meshDimension);
2104   SCRUTE(_ptrMesh->_spaceDimension);
2105   SCRUTE(_ptrMesh->_meshDimension);
2106
2107   if ((spaceDimension != MED_VALID) && (meshDimension < MED_VALID))
2108     {
2109       err = MEDmaaCr(_medIdt, const_cast <char *> (_meshName.c_str()),
2110                      _ptrMesh->_meshDimension, med_2_2::MED_NON_STRUCTURE,
2111                      const_cast <char *> (_ptrMesh->_description.c_str()));
2112
2113       if (err < MED_VALID)
2114         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Unable to create Mesh : |" << _meshName << "|"));
2115       else 
2116         MESSAGE(LOC<<"Mesh "<<_meshName<<" created in file "<<_fileName<<" !");
2117     }
2118   else if ((spaceDimension != _ptrMesh->_spaceDimension)  &&
2119            (meshDimension != _ptrMesh->_meshDimension))
2120     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Mesh |" << _meshName.c_str() <<
2121                                  "| already exists in file |" << _fileName <<
2122                                  "| with space dimension |" << spaceDimension <<
2123                                  "| and mesh dimension |" << meshDimension <<
2124                                  "| but the space dimension and the mesh dimension of the mesh we want to write are respectively |"
2125                                  << _ptrMesh->_spaceDimension <<"|" <<
2126                                  _ptrMesh->_meshDimension << "|")) ;
2127     
2128   // Pourquoi le stocker sous forme de chaîne ?
2129   const string & coordinateSystem = _ptrMesh->_coordinate->_coordinateSystem;
2130   if      (coordinateSystem  == "CARTESIAN") 
2131     rep = med_2_2::MED_CART;
2132   else if ( coordinateSystem == "CYLINDRICAL")
2133     rep = med_2_2::MED_CYL;
2134   else if ( coordinateSystem == "SPHERICAL" )
2135     rep = med_2_2::MED_SPHER;
2136   else
2137     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Mesh |" << _meshName.c_str() << "| doesn't have a valid coordinate system : |" 
2138                                  << _ptrMesh->_coordinate->_coordinateSystem
2139                                  << "|" )) ;  
2140       
2141 //   err = MEDcoordEcr(_medIdt, const_cast <char *> (_meshName.c_str()),
2142 //                  _ptrMesh->_spaceDimension, 
2143 //                  //const_cast <double *> ( _ptrMesh->_coordinate->_coordinate->get(MED_EN::MED_FULL_INTERLACE) ), 
2144 //                  const_cast <double *> ( _ptrMesh->_coordinate->_coordinate.get(MED_EN::MED_FULL_INTERLACE) ), 
2145 //                  MED_FR::MED_FULL_INTERLACE, 
2146 //                  _ptrMesh->_numberOfNodes,                 //  _ptrMesh->_coordinate->_numberOfNodes
2147 //                  MED_FR::MED_LECTURE_ECRITURE,    
2148 //                  rep,
2149 //                  const_cast <char *> (tmp_name.c_str()), 
2150 //                  const_cast <char *> (tmp_unit.c_str()) 
2151 //                  );
2152
2153   err = MEDcoordEcr(_medIdt, const_cast <char *> (_meshName.c_str()),
2154                     _ptrMesh->_spaceDimension, 
2155                     //const_cast <double *> ( _ptrMesh->_coordinate->_coordinate->get(MED_EN::MED_FULL_INTERLACE) ), 
2156                     const_cast <double *> ( _ptrMesh->_coordinate->_coordinate.get(MED_EN::MED_FULL_INTERLACE) ), 
2157                     med_2_2::MED_FULL_INTERLACE, _ptrMesh->_numberOfNodes,
2158                     //  _ptrMesh->_coordinate->_numberOfNodes
2159                     rep, const_cast <char *> (tmp_name.c_str()), 
2160                     const_cast <char *> (tmp_unit.c_str()));
2161
2162   if (err<0) 
2163     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write coordinates of mesh |" << _meshName.c_str() << "| in file |" << _fileName
2164                                  << "| with dimension |"  << _ptrMesh->_spaceDimension <<"| and" 
2165                                  << " with units names |"  << tmp_name
2166                                  << "| and units |"       << tmp_unit
2167                                  << " |")) ;    
2168     
2169
2170        //////////////////////////////////////////////////////////////////////////////////////
2171        ///  Modification pour prise en compte de la numérotation optionnelle des noeuds   ///
2172        //////////////////////////////////////////////////////////////////////////////////////
2173        ///
2174        /// Ecrit les numéros optionnels des noeuds
2175        /// Le traitement est identique à la version originelle s'il n'y a pas de numérotation optionnelle
2176
2177
2178       if (_ptrMesh->_arePresentOptionnalNodesNumbers==1) {
2179         
2180         err =  MEDnumEcr(_medIdt, const_cast <char *> (_meshName.c_str()),
2181                          const_cast <med_int *> (_ptrMesh->_coordinate->getNodesNumbers() ), 
2182                          _ptrMesh->_numberOfNodes, med_2_2::MED_NOEUD,
2183                          med_2_2::med_geometrie_element(0) );
2184
2185         if (err != MED_VALID) 
2186           throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write optionnal numbers of mesh |" << 
2187                                        _meshName.c_str() << "| in file |" <<
2188                                        _fileName  << " |")) ;
2189       }
2190       //////////////////////////////////////////////////////////////////////////////////////
2191
2192   END_OF(LOC);
2193     
2194   return MED_VALID;
2195 }
2196
2197
2198
2199
2200 int MED_MESH_WRONLY_DRIVER22::writeConnectivities(medEntityMesh entity) const 
2201 {
2202   const char * LOC="int MED_MESH_WRONLY_DRIVER22::writeConnectivities() const : ";
2203   BEGIN_OF(LOC);
2204
2205   med_2_2::med_err err;
2206   
2207   // REM SI LA METHODE EST APPELEE DIRECTEMENT ET QUE LE MAILLAGE N'EST PAS CREE IL Y A PB !
2208   // PG : IMPOSSIBLE : LA METHODE EST PRIVEE !
2209     
2210   // A FAIRE : A tester surtout dans les methodes de MESH.
2211   //    if ( _ptrMesh->_connectivity == (CONNECTIVITY *) MED_INVALID )
2212   if ( _ptrMesh->_connectivity == (CONNECTIVITY *) NULL )
2213     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "The connectivity is not defined in the MESH object ")) ;
2214
2215
2216   // Nodal connectivity for classic geometric types
2217   if   ( _ptrMesh->existConnectivity(MED_NODAL,entity) ) 
2218     {
2219
2220       int numberOfTypes           = _ptrMesh->getNumberOfTypes (entity) ;
2221       const medGeometryElement  * types = _ptrMesh->getTypes         (entity) ;
2222
2223       for (int i=0; i<numberOfTypes; i++) 
2224         {
2225
2226           int    numberOfElements = _ptrMesh->getNumberOfElements (entity,types[i]);
2227           const int * connectivity      = _ptrMesh->getConnectivity     (MED_EN::MED_FULL_INTERLACE, 
2228                                                                          MED_NODAL, entity, types[i]); // ?? et SI MED_NODAL n'existe pas, recalcul auto ??
2229       
2230           // Pour l'instant la class utilise le multi.....
2231           int multi = 0 ;
2232           //      if (entity==MED_EN::MED_CELL)
2233           //        if ( (types[i]/ 100) < _ptrMesh->_spaceDimension) 
2234           //          multi=1 ;
2235           int numberOfNodes = types[i]%100 ;
2236           int * connectivityArray = new int[numberOfElements*(numberOfNodes+multi)];
2237       
2238           // version originale sans prise en compte des numéros optionnels 
2239           //     
2240           for (int j=0 ; j<numberOfElements; j++) 
2241             {
2242               for (int k=0; k<numberOfNodes; k++)
2243                 connectivityArray[j*(numberOfNodes+multi)+k]=connectivity[j*numberOfNodes+k] ;
2244
2245               if (multi>0) connectivityArray[j*(numberOfNodes+multi)+numberOfNodes]=0;
2246             }
2247       
2248           //////////////////////////////////////////////////////////////////////////////////////
2249           ///  Modification pour prise en compte de la numérotation optionnelle des noeuds   ///
2250               //////////////////////////////////////////////////////////////////////////////////////
2251               ///
2252               /// Dénumérote les sommets des mailles pour leur rendre leurs numéros optionnels
2253               /// Le traitement est identique à la version originelle s'il n'y a pas de numérotation optionnelle
2254
2255               //        if (_ptrMesh->_arePresentOptionnalNodesNumbers==1) 
2256               //                {
2257               //                const int * nodesNumbers = _ptrMesh->_coordinate->getNodesNumbers();
2258               //                for (int j=0 ; j<numberOfElements; j++) 
2259               //                        {
2260               //                        for (int k=0; k<numberOfNodes; k++) connectivityArray[j*(numberOfNodes+multi)+k]=nodesNumbers[connectivity[j*numberOfNodes+k]-1] ;
2261               //                        if (multi>0) connectivityArray[j*(numberOfNodes+multi)+numberOfNodes]=0;
2262               //                        }
2263               //                }
2264               //        else
2265               //                {
2266               //                for (int j=0 ; j<numberOfElements; j++) 
2267               //                        {
2268               //                        for (int k=0; k<numberOfNodes; k++) connectivityArray[j*(numberOfNodes+multi)+k]=connectivity[j*numberOfNodes+k] ;
2269               //                        if (multi>0) connectivityArray[j*(numberOfNodes+multi)+numberOfNodes]=0;
2270               //                        }
2271               //                }
2272
2273               //////////////////////////////////////////////////////////////////////////////////////
2274       
2275               //       err = MEDconnEcr( _medIdt, const_cast <char *> ( _meshName.c_str()), _ptrMesh->_spaceDimension,
2276               //                        connectivityArray, MED_FR::MED_FULL_INTERLACE , numberOfElements,
2277               //                        MED_FR::MED_LECTURE_ECRITURE,
2278               //                        (MED_FR::med_entite_maillage  ) entity, 
2279               //                        (MED_FR::med_geometrie_element) types[i], MED_FR::MED_NOD );
2280
2281               //          err = MEDconnEcr(_medIdt, const_cast <char *> ( _meshName.c_str()),
2282               //                           _ptrMesh->_spaceDimension, connectivityArray,
2283               //                           MED_FR::MED_FULL_INTERLACE , numberOfElements,
2284               //                           (MED_FR::med_entite_maillage  ) entity, 
2285               //                           (MED_FR::med_geometrie_element) types[i],
2286               //                           med_2_2::MED_NOD);
2287               
2288               err = MEDconnEcr(_medIdt, const_cast <char *> ( _meshName.c_str()),
2289                                _ptrMesh->_spaceDimension, connectivityArray,
2290                                med_2_2::MED_FULL_INTERLACE , numberOfElements,
2291                                (med_2_2::med_entite_maillage  ) MED_CELL, 
2292                                (med_2_2::med_geometrie_element) types[i],
2293                                med_2_2::MED_NOD);
2294
2295               delete[] connectivityArray ;
2296
2297               if (err<0) // ETENDRE LES EXPLICATIONS
2298                 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write connectivities of mesh |" << _meshName.c_str() << "| in file |" << _fileName
2299                                              << "| with dimension |"  << _ptrMesh->_spaceDimension <<"| and" 
2300                                              ));
2301         }
2302
2303     }
2304
2305
2306   // Polygons writing
2307   if (_ptrMesh->existPolygonsConnectivity(MED_NODAL,entity))
2308     {
2309       err = MEDpolygoneConnEcr(_medIdt,
2310                                const_cast <char *> (_meshName.c_str()),
2311                                const_cast <med_int*> (_ptrMesh->getPolygonsConnectivityIndex(MED_NODAL,entity)),
2312                                _ptrMesh->getNumberOfPolygons()+1,
2313                                const_cast <med_int*> (_ptrMesh->getPolygonsConnectivity(MED_NODAL,entity)),
2314                                (med_2_2::med_entite_maillage) entity,
2315                                med_2_2::MED_NOD);
2316
2317       if (err<0)
2318         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write polygons nodal connectivities of mesh |" <<  _meshName.c_str() << "| in file |" << _fileName
2319                                              << "| with dimension |"  << _ptrMesh->_spaceDimension <<"| and" 
2320                                              ));
2321     }
2322
2323
2324   // Polyhedron writing
2325   if (_ptrMesh->existPolyhedronConnectivity(MED_NODAL,entity))
2326     {
2327       err = MEDpolyedreConnEcr(_medIdt,
2328                                const_cast <char *> (_meshName.c_str()),
2329                                const_cast <med_int*> (_ptrMesh->getPolyhedronIndex(MED_NODAL)),
2330                                _ptrMesh->getNumberOfPolyhedron()+1,
2331                                const_cast <med_int*> (_ptrMesh->getPolyhedronFacesIndex()),
2332                                _ptrMesh->getNumberOfPolyhedronFaces()+1,
2333                                const_cast <med_int*> (_ptrMesh->getPolyhedronConnectivity(MED_NODAL)),
2334                                med_2_2::MED_NOD);
2335
2336       if (err<0)
2337         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write polyhedron nodal connectivities of mesh |" << _meshName.c_str() << "| in file |" << _fileName
2338                                      << "| with dimension |"  << _ptrMesh->_spaceDimension <<"| and" 
2339                                              ));
2340     }
2341
2342
2343   // Descending connectivity for classic geometric types
2344   if   ( _ptrMesh->existConnectivity(MED_DESCENDING,entity) )
2345     {
2346       
2347       int numberOfTypes           = _ptrMesh->getNumberOfTypes (entity) ;
2348       const medGeometryElement  * types = _ptrMesh->getTypes         (entity) ;
2349       
2350       for (int i=0; i<numberOfTypes; i++)
2351         {
2352         
2353           int    numberOfElements = _ptrMesh->getNumberOfElements (entity,types[i]);
2354           const int * connectivity = _ptrMesh->getConnectivity(MED_EN::MED_FULL_INTERLACE, MED_DESCENDING, entity, types[i]); 
2355       
2356       // Pour l'instant la class utilise le multi.....
2357           //       err = MED_FR::MEDconnEcr( _medIdt,
2358           //                            const_cast <char *> ( _meshName.c_str()),
2359           //                            _ptrMesh->_spaceDimension,
2360           //                            const_cast <int *> (connectivity),
2361           //                            MED_FR::MED_FULL_INTERLACE,
2362           //                            numberOfElements,
2363           //                            MED_FR::MED_LECTURE_ECRITURE,
2364           //                            (MED_FR::med_entite_maillage  ) entity, 
2365           //                            (MED_FR::med_geometrie_element) types[i],
2366           //                            MED_FR::MED_DESC );
2367
2368           err = med_2_2::MEDconnEcr(_medIdt,
2369                                 const_cast <char *> ( _meshName.c_str()),
2370                                 _ptrMesh->_spaceDimension,
2371                                 const_cast <int *> (connectivity),
2372                                 med_2_2::MED_FULL_INTERLACE,
2373                                 numberOfElements,
2374                                 (med_2_2::med_entite_maillage  ) entity, 
2375                                 (med_2_2::med_geometrie_element) types[i],
2376                                 med_2_2::MED_DESC );
2377         
2378           if (err<0) // ETENDRE LES EXPLICATIONS
2379             throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write connectivities of mesh |" << _meshName.c_str() << "| in file |" << _fileName
2380                                          << "| with dimension |"  << _ptrMesh->_spaceDimension <<"| and" 
2381                                          )) ;
2382             
2383         }
2384     }
2385
2386
2387   // Polygons writing
2388   if (_ptrMesh->existPolygonsConnectivity(MED_DESCENDING,entity))
2389     {
2390       err = MEDpolygoneConnEcr(_medIdt,
2391                                const_cast <char *> (_meshName.c_str()),
2392                                const_cast <med_int*> (_ptrMesh->getPolygonsConnectivityIndex(MED_DESCENDING,entity)),
2393                                _ptrMesh->getNumberOfPolygons()+1,
2394                                const_cast <med_int*> (_ptrMesh->getPolygonsConnectivity(MED_DESCENDING,entity)),
2395                                (med_2_2::med_entite_maillage) entity,
2396                                med_2_2::MED_DESC);
2397
2398       if (err<0)
2399         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write polygons descending connectivities of mesh |" <<  _meshName.c_str() << "| in file |" << _fileName
2400                                              << "| with dimension |"  << _ptrMesh->_spaceDimension <<"| and" 
2401                                              ));
2402     }
2403
2404
2405   // Polyhedron writing
2406   if (_ptrMesh->existPolyhedronConnectivity(MED_DESCENDING,entity))
2407     {
2408       med_int NumberOfFaces = _ptrMesh->getPolyhedronIndex(MED_DESCENDING)[_ptrMesh->getNumberOfPolyhedron()]-1;
2409       vector<med_int> FacesGeometricTypes(NumberOfFaces,MED_POLYGON); // by default all polyhedron faces are polygons
2410
2411       err = MEDpolyedreConnEcr(_medIdt,
2412                                const_cast <char *> (_meshName.c_str()),
2413                                const_cast <med_int*> (_ptrMesh->getPolyhedronIndex(MED_DESCENDING)),
2414                                _ptrMesh->getNumberOfPolyhedron()+1,
2415                                &FacesGeometricTypes[0],
2416                                NumberOfFaces,
2417                                const_cast <med_int*> (_ptrMesh->getPolyhedronConnectivity(MED_DESCENDING)),
2418                                med_2_2::MED_DESC);
2419
2420       if (err<0)
2421         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write polyhedron descending connectivities of mesh |" << _meshName.c_str() << "| in file |" << _fileName
2422                                              << "| with dimension |"  << _ptrMesh->_spaceDimension <<"| and" 
2423                                              ));
2424     }
2425
2426
2427   END_OF(LOC);
2428   return MED_VALID;
2429 }
2430
2431 int MED_MESH_WRONLY_DRIVER22::writeFamilyNumbers() const {
2432   
2433   const char * LOC="int MED_MESH_WRONLY_DRIVER22::writeFamilyNumbers() const : ";
2434   BEGIN_OF(LOC);
2435
2436   med_2_2::med_err err;
2437   
2438   // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArrayNodeFamily DOIT ETRE ENLEVER DE LA CLASSE MESH
2439
2440   { // Node related block
2441     
2442     // We build the array from the families list objects :
2443     int NumberOfNodes = _ptrMesh->getNumberOfNodes() ;
2444     int * MEDArrayNodeFamily = new int[NumberOfNodes] ;
2445     // family 0 by default
2446     for (int i=0; i<NumberOfNodes; i++)
2447       MEDArrayNodeFamily[i]=0;
2448     //vector<FAMILY*> myFamilies = _ptrMesh->getFamilies(MED_NODE);
2449     vector<FAMILY*> * myFamilies = &_ptrMesh->_familyNode;
2450     int NumberOfNodesFamilies = myFamilies->size() ;
2451     //bool ToDestroy = false;
2452     if (0 == NumberOfNodesFamilies) {
2453       //ToDestroy = true ;
2454       vector<GROUP*> myGroups = _ptrMesh->getGroups(MED_NODE);
2455       int NumberOfGroups = myGroups.size() ;
2456       // build families from groups
2457       for (int i=0; i<NumberOfGroups; i++) {
2458         SUPPORT * mySupport = myGroups[i] ;
2459         FAMILY* myFamily = new FAMILY(*mySupport);
2460         myFamily->setIdentifier(i+1);
2461         myFamilies->push_back(myFamily);
2462       }
2463       NumberOfNodesFamilies=myFamilies->size() ;
2464     }
2465     for (int i=0 ; i<NumberOfNodesFamilies; i++) {
2466       //SCRUTE(i);
2467       //SCRUTE(myFamilies[i]->getName());
2468       int FamilyIdentifier = (*myFamilies)[i]->getIdentifier() ;
2469       int TotalNumber = (*myFamilies)[i]->getNumberOfElements(MED_ALL_ELEMENTS) ;
2470       if ((*myFamilies)[i]->isOnAllElements())
2471         for (int j=0; j<TotalNumber; j++)
2472           MEDArrayNodeFamily[j]=FamilyIdentifier;
2473       else {
2474         const int * Number = (*myFamilies)[i]->getNumber(MED_ALL_ELEMENTS) ;
2475         for (int j=0; j<TotalNumber; j++)
2476           MEDArrayNodeFamily[Number[j]-1]=FamilyIdentifier ;
2477       }
2478     }
2479
2480     for(int j=0; j<NumberOfNodes; j++) {
2481       SCRUTE(MEDArrayNodeFamily[j]);
2482     }
2483
2484 //     if ( !_ptrMesh->getIsAGrid() )
2485
2486       err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
2487                     MEDArrayNodeFamily, NumberOfNodes, med_2_2::MED_NOEUD,
2488                     (med_2_2::med_geometrie_element) MED_NONE);
2489
2490 //     else
2491 //       err = MEDfamGridEcr(_medIdt,
2492 //                        const_cast <char *> (_ptrMesh->_name.c_str()),
2493 //                        MEDArrayNodeFamily,
2494 //                        NumberOfNodes,
2495 //                        MED_FR::MED_LECTURE_ECRITURE,
2496 //                        MED_FR::MED_NOEUD);
2497
2498     if ( err != MED_VALID) 
2499       throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write node family for the |"<< NumberOfNodes
2500                                    << "| nodes in mesh |" 
2501                                    << _ptrMesh->_name.c_str() << "|" ));
2502     delete[] MEDArrayNodeFamily;
2503     //if (true == ToDestroy)
2504     //  for (int i=0; i<NumberOfNodesFamilies; i++)
2505     //    delete myFamilies[i];
2506   }
2507     
2508   { // CELLS RELATED BLOCK
2509     medEntityMesh entity=MED_EN::MED_CELL;
2510     // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArray____Family DOIT ETRE ENLEVER DE LA CLASSE MESH
2511     if  ( ( _ptrMesh->existConnectivity(MED_NODAL,entity) )|( _ptrMesh->existConnectivity(MED_DESCENDING,entity) ) ) { 
2512
2513       int numberOfTypes           = _ptrMesh->getNumberOfTypes (entity) ;
2514       const medGeometryElement  * types = _ptrMesh->getTypes         (entity) ;
2515
2516       // We build the array from the families list objects :
2517       int NumberOfElements = _ptrMesh->getNumberOfElements(entity, MED_ALL_ELEMENTS);
2518       int * MEDArrayFamily = new int[NumberOfElements] ;
2519       // family 0 by default
2520       for (int i=0; i<NumberOfElements; i++)
2521         MEDArrayFamily[i]=0;
2522       //vector<FAMILY*> myFamilies = _ptrMesh->getFamilies(entity);
2523       vector<FAMILY*> * myFamilies = &_ptrMesh->_familyCell ;
2524       int NumberOfFamilies = myFamilies->size() ;
2525       //bool ToDestroy = false;
2526       if (0 == NumberOfFamilies) {
2527         //ToDestroy = true ;
2528         vector<GROUP*> myGroups = _ptrMesh->getGroups(entity);
2529         int NumberOfGroups = myGroups.size() ;
2530         // build families from groups
2531         for (int i=0; i<NumberOfGroups; i++) {
2532           SCRUTE( myGroups[i]->getName() );
2533           SUPPORT * mySupport = myGroups[i] ;
2534           FAMILY* myFamily = new FAMILY(*mySupport);
2535           myFamily->setIdentifier(-i-1);
2536           myFamilies->push_back(myFamily);
2537         }
2538         NumberOfFamilies=myFamilies->size() ;
2539       }
2540       for (int i=0 ; i<NumberOfFamilies; i++) {
2541         int FamilyIdentifier = (*myFamilies)[i]->getIdentifier() ;
2542         int TotalNumber = (*myFamilies)[i]->getNumberOfElements(MED_ALL_ELEMENTS) ;
2543         if ((*myFamilies)[i]->isOnAllElements())
2544           for (int ii=0; ii<TotalNumber; ii++)
2545             MEDArrayFamily[ii]=FamilyIdentifier;
2546         else {
2547           const int * Number = (*myFamilies)[i]->getNumber(MED_ALL_ELEMENTS) ;
2548           for (int ii=0; ii<TotalNumber; ii++)
2549             MEDArrayFamily[Number[ii]-1]=FamilyIdentifier ;
2550         }
2551       }
2552
2553       const int * typeCount = _ptrMesh->getGlobalNumberingIndex(entity) ;
2554 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000)
2555         int lgth=NumberOfElements;
2556         med_2_2::med_int *temp=new med_2_2::med_int[lgth];
2557         for(int i2=0;i2<lgth;i2++)
2558           temp[i2]=(med_2_2::med_int) (MEDArrayFamily[i2]);
2559 #endif
2560       for (int i=0; i<numberOfTypes; i++) {
2561 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000)
2562         err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
2563                         temp+typeCount[i]-1,typeCount[i+1]-typeCount[i],
2564                         med_2_2::MED_REMP ,
2565                         (med_2_2::med_entite_maillage) entity,
2566                         (med_2_2::med_geometrie_element) types[i]
2567 );
2568 #else
2569         err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
2570                         (MEDArrayFamily+typeCount[i]-1),
2571                         (typeCount[i+1]-typeCount[i]),
2572                         (med_2_2::med_entite_maillage) entity,
2573                         (med_2_2::med_geometrie_element) types[i]); 
2574
2575         MESSAGE("OK "<<i);
2576         if ( err != MED_VALID) 
2577           throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write family for the |"<< _ptrMesh->getNumberOfElements(entity, types[i])
2578                                        << "| cells of geometric type |" << geoNames[types[i]] <<"|in mesh |"      
2579                                        << _ptrMesh->_name.c_str() << "|" ));   
2580       }
2581 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000)
2582       delete [] temp;
2583 #endif
2584       delete[] MEDArrayFamily ;
2585       //if (true == ToDestroy) {
2586       //  int NumberOfFamilies = myFamilies->size();
2587       //  for (int i=0; i<NumberOfFamilies; i++)
2588       //    delete myFamilies[i];
2589       //}
2590     }
2591   }
2592
2593   { // FACE RELATED BLOCK
2594     medEntityMesh entity=MED_EN::MED_FACE;
2595     // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArray____Family DOIT ETRE ENLEVER DE LA CLASSE MESH
2596     if  ( ( _ptrMesh->existConnectivity(MED_NODAL,entity) )|( _ptrMesh->existConnectivity(MED_DESCENDING,entity) ) ) { 
2597
2598       int numberOfTypes           = _ptrMesh->getNumberOfTypes (entity) ;
2599       const medGeometryElement  * types = _ptrMesh->getTypes         (entity) ;
2600       SCRUTE(numberOfTypes);
2601       
2602       int numberOfElements = _ptrMesh->getNumberOfElements(entity, MED_ALL_ELEMENTS) ;
2603       int * familyArray = new int[numberOfElements] ;
2604       for (int i=0;i<numberOfElements;i++)
2605         familyArray[i]=0;
2606
2607       int numberOfFamilies = _ptrMesh->getNumberOfFamilies(entity) ;
2608       //vector<FAMILY*> myFamilies = _ptrMesh->getFamilies(entity) ;
2609       vector<FAMILY*> * myFamilies = &_ptrMesh->_familyFace ;
2610       //bool ToDestroy = false;
2611       if (0 == numberOfFamilies) {
2612         //ToDestroy = true ;
2613         vector<GROUP*> myGroups = _ptrMesh->getGroups(entity);
2614         int NumberOfGroups = myGroups.size() ;
2615         // build families from groups
2616         for (int i=0; i<NumberOfGroups; i++) {
2617           SCRUTE( myGroups[i]->getName() );
2618           SUPPORT * mySupport = myGroups[i] ;
2619           FAMILY* myFamily = new FAMILY(*mySupport);
2620           myFamily->setIdentifier(-i-1000);
2621           myFamilies->push_back(myFamily);
2622         }
2623         numberOfFamilies=myFamilies->size() ;
2624       }
2625       for (int i=0;i<numberOfFamilies;i++) {
2626         int familyNumber = (*myFamilies)[i]->getIdentifier() ;
2627         int numberOfFamilyElements = (*myFamilies)[i]->getNumberOfElements(MED_ALL_ELEMENTS) ;
2628         if ((*myFamilies)[i]->isOnAllElements())
2629           for (int ii=0; ii<numberOfFamilyElements; ii++)
2630             familyArray[ii]=familyNumber;
2631         else {
2632           const int * myFamilyElements = (*myFamilies)[i]->getNumber(MED_ALL_ELEMENTS) ;
2633           for (int ii=0;ii<numberOfFamilyElements;ii++)
2634             familyArray[myFamilyElements[ii]-1]=familyNumber;
2635         }
2636       }
2637
2638       const int * typeCount = _ptrMesh->getGlobalNumberingIndex(entity) ;
2639 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000)
2640         int lgth=numberOfElements;
2641         med_2_2::med_int *temp=new med_2_2::med_int[lgth];
2642         for(int i2=0;i2<lgth;i2++)
2643           temp[i2]=(med_2_2::med_int) (familyArray[i2]);
2644 #endif
2645       for (int i=0; i<numberOfTypes; i++) {
2646         int typeNumberOfElements = typeCount[i+1] - typeCount[i] ;
2647
2648         err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
2649                         familyArray+typeCount[i]-1, typeNumberOfElements,
2650                         (med_2_2::med_entite_maillage) entity,
2651                         (med_2_2::med_geometrie_element) types[i]); 
2652 #endif
2653         if ( err != MED_VALID) 
2654           throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write family for the |"<< _ptrMesh->getNumberOfElements(entity, types[i])
2655                                        << "| faces of geometric type |" << geoNames[types[i]] <<"|in mesh |"      
2656                                        << _ptrMesh->_name.c_str() << "|" ));   
2657       }
2658 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000)
2659       delete [] temp;
2660 #endif
2661       delete[] familyArray ;
2662       //if (true == ToDestroy) {
2663       //  int NumberOfFamilies = myFamilies->size();
2664       //    for (int i=0; i<NumberOfFamilies; i++)
2665       //      delete myFamilies[i];
2666       //}
2667     }
2668   }
2669
2670   { // EDGE RELATED BLOCK
2671     //medEntityMesh entity=MED_EN::MED_FACE;
2672     medEntityMesh entity=MED_EN::MED_EDGE;
2673     // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArray____Family DOIT ETRE ENLEVER DE LA CLASSE MESH
2674     if  ( ( _ptrMesh->existConnectivity(MED_NODAL,entity) )|( _ptrMesh->existConnectivity(MED_DESCENDING,entity) ) ) { 
2675
2676       int numberOfTypes           = _ptrMesh->getNumberOfTypes (entity) ;
2677       const medGeometryElement  * types = _ptrMesh->getTypes         (entity) ;
2678       
2679       int numberOfElements = _ptrMesh->getNumberOfElements(entity, MED_ALL_ELEMENTS) ;
2680       int * familyArray = new int[numberOfElements] ;
2681       for (int i=0;i<numberOfElements;i++)
2682         familyArray[i]=0;
2683
2684       int numberOfFamilies = _ptrMesh->getNumberOfFamilies(entity) ;
2685       //vector<FAMILY*> myFamilies = _ptrMesh->getFamilies(entity) ;
2686       vector<FAMILY*> * myFamilies = &_ptrMesh->_familyEdge ;
2687       //bool ToDestroy = false;
2688       if (0 == numberOfFamilies) {
2689         //ToDestroy = true ;
2690         vector<GROUP*> myGroups = _ptrMesh->getGroups(entity);
2691         int NumberOfGroups = myGroups.size() ;
2692         // build families from groups
2693         for (int i=0; i<NumberOfGroups; i++) {
2694           SCRUTE( myGroups[i]->getName() );
2695           SUPPORT * mySupport = myGroups[i] ;
2696           FAMILY* myFamily = new FAMILY(*mySupport);
2697           myFamily->setIdentifier(-i-2000);
2698           myFamilies->push_back(myFamily);
2699         }
2700         numberOfFamilies=myFamilies->size() ;
2701       }
2702       for (int i=0;i<numberOfFamilies;i++) {
2703         int familyNumber = (*myFamilies)[i]->getIdentifier() ;
2704         int numberOfFamilyElements = (*myFamilies)[i]->getNumberOfElements(MED_ALL_ELEMENTS) ;
2705         if ((*myFamilies)[i]->isOnAllElements())
2706           for (int ii=0; ii<numberOfFamilyElements; ii++)
2707             familyArray[ii]=familyNumber;
2708         else {
2709           const int * myFamilyElements = (*myFamilies)[i]->getNumber(MED_ALL_ELEMENTS) ;
2710           for (int ii=0;ii<numberOfFamilyElements;ii++)
2711             familyArray[myFamilyElements[ii]-1]=familyNumber;
2712         }
2713       }
2714
2715       const int * typeCount = _ptrMesh->getGlobalNumberingIndex(entity) ;
2716 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000)
2717         int lgth=numberOfElements;
2718         med_2_2::med_int *temp=new med_2_2::med_int[lgth];
2719         for(int i2=0;i2<lgth;i2++)
2720           temp[i2]=(med_2_2::med_int) (familyArray[i2]);
2721 #endif
2722       for (int i=0; i<numberOfTypes; i++) {
2723         int typeNumberOfElements = typeCount[i+1] - typeCount[i] ;
2724
2725         err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
2726                         familyArray+typeCount[i]-1, typeNumberOfElements,
2727                         (med_2_2::med_entite_maillage) entity,
2728                         (med_2_2::med_geometrie_element) types[i]); 
2729
2730         if ( err != MED_VALID) 
2731           throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write family for the |"<< _ptrMesh->getNumberOfElements(entity, types[i])
2732                                        << "| edges of geometric type |" << geoNames[types[i]] <<"|in mesh |"      
2733                                        << _ptrMesh->_name.c_str() << "|" ));   
2734       }
2735 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000)
2736       delete [] temp;
2737 #endif
2738       delete[] familyArray ;
2739       //if (true == ToDestroy) {
2740       //  int NumberOfFamilies = myFamilies->size();
2741       //  for (int i=0; i<NumberOfFamilies; i++)
2742       //    delete myFamilies[i];
2743       //}
2744     }
2745   }
2746     
2747   END_OF(LOC);
2748   return MED_VALID;
2749 }
2750
2751 int MED_MESH_WRONLY_DRIVER22::writeFamilies(vector<FAMILY*> & families ) const
2752 {
2753   
2754   const char * LOC="int MED_MESH_WRONLY_DRIVER22::writeFamilies(vector<FAMILY*> families) const : ";
2755   BEGIN_OF(LOC);
2756
2757   med_2_2::med_err err;
2758   
2759   MESSAGE(LOC<<" families.size() :"<<families.size());
2760
2761   for (unsigned int i=0; i< families.size(); i++) {
2762
2763     int      numberOfAttributes         = families[i]->getNumberOfAttributes ();
2764     string   attributesDescriptions     = "";
2765
2766     // Recompose the attributes descriptions arg for MED
2767     for (int j=0; j < numberOfAttributes; j++) {
2768         
2769       string attributeDescription = families[i]->getAttributeDescription(j+1);
2770         
2771       if ( attributeDescription.size() > MED_TAILLE_DESC )
2772         throw MEDEXCEPTION( LOCALIZED(STRING(LOC) << "The size of the attribute description n° |" << j+1 << "| of the family |" << families[i]->getName()
2773                                       << "| with identifier |" << families[i]->getIdentifier()  << "| is |" 
2774                                       <<  attributeDescription.size()  <<"| and is more than |" <<  MED_TAILLE_DESC << "|")) ;
2775         
2776       attributesDescriptions += attributeDescription;
2777     }
2778       
2779
2780     int      numberOfGroups  = families[i]->getNumberOfGroups();
2781     string   groupsNames(numberOfGroups*MED_TAILLE_LNOM,'\0') ;
2782     // Recompose the groups names arg for MED
2783     for (int j=0; j < numberOfGroups; j++) {
2784
2785       string groupName = families[i]->getGroupName(j+1);
2786        
2787       if ( groupName.size() > MED_TAILLE_LNOM )
2788         throw MEDEXCEPTION( LOCALIZED(STRING(LOC) << "The size of the group name  n° |" << j+1 << "| of the family |" << families[i]->getName()
2789                                       << "| with identifier |" << families[i]->getIdentifier()  << "| is |" 
2790                                       <<  groupName.size()  <<"| and is more than |" << MED_TAILLE_LNOM << "|")) ;
2791         
2792
2793       int length = min(MED_TAILLE_LNOM,(int)groupName.size());
2794       groupsNames.replace(j*MED_TAILLE_LNOM,length, groupName,0,length);
2795       
2796     }
2797
2798     // test if the family already exists (HDF trick waiting a MED evolution to be replaced)
2799
2800     string dataGroupFam;
2801     if (families[i]->getEntity() == MED_NODE)
2802       dataGroupFam = "/ENS_MAA/"+_meshName+"/FAS/NOEUD/"+families[i]->getName()+"/";  
2803     else
2804       dataGroupFam = "/ENS_MAA/"+_meshName+"/FAS/ELEME/"+families[i]->getName()+"/"; 
2805
2806     SCRUTE("|"<<dataGroupFam<<"|");
2807     err = med_2_2::_MEDdatagroupOuvrir(_medIdt,const_cast <char *> (dataGroupFam.c_str()) ) ;
2808     if ( err < MED_VALID ) {
2809       SCRUTE(err);
2810
2811       MESSAGE(LOC<<"families[i]->getName().c_str() : "<<families[i]->getName().c_str());
2812       MESSAGE(LOC<<"_meshName.c_str() : "<<_meshName.c_str());
2813       MESSAGE(LOC<<"families[i]->getIdentifier() : "<<families[i]->getIdentifier());
2814       MESSAGE(LOC<<"numberOfAttributes : "<<numberOfAttributes);
2815         
2816       //MESSAGE(LOC<<"families[i]->getAttributesIdentifiers() : "<<families[i]->getAttributesIdentifiers()[0]);
2817       //MESSAGE(LOC<<"families[i]->getAttributesValues() : "<<families[i]->getAttributesValues()[0]);
2818       MESSAGE(LOC<<"attributesDescriptions.c_str() : "<<attributesDescriptions.c_str());
2819       MESSAGE(LOC<<"numberOfGroups : "<<numberOfGroups);
2820       MESSAGE(LOC<<"groupsNames.c_str() : "<<groupsNames.c_str());
2821 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000)
2822       int lgth=families[i]->getNumberOfAttributes();
2823       med_2_2::med_int *  AttributesIdentifier2 = new med_2_2::med_int[lgth] ;
2824       med_2_2::med_int *  AttributesValues2     = new med_2_2::med_int[lgth] ;
2825       for(med_2_2::med_int i2=0;i2<lgth;i2++)
2826         {
2827           AttributesIdentifier2[i2]=(med_2_2::med_int)(families[i]->getAttributesIdentifiers()[i2]);
2828           AttributesValues2[i2]=(med_2_2::med_int)(families[i]->getAttributesValues()[i2]);
2829         }
2830       err = med_2_2::MEDfamCr( _medIdt, 
2831                               const_cast <char *> ( _meshName.c_str() ),
2832                               const_cast <char *> ( families[i]->getName().c_str() ),
2833                               families[i]->getIdentifier(), 
2834                               AttributesIdentifier2,
2835                               AttributesValues2,
2836                               const_cast <char *> (attributesDescriptions.c_str()), 
2837                               numberOfAttributes,  
2838                               const_cast <char *> (groupsNames.c_str()), 
2839                               numberOfGroups);
2840       delete [] AttributesIdentifier2;
2841       delete [] AttributesValues2;
2842 #else
2843       err = med_2_2::MEDfamCr( _medIdt, 
2844                               const_cast <char *> ( _meshName.c_str() ),
2845                               const_cast <char *> ( families[i]->getName().c_str() ),
2846                               families[i]->getIdentifier(), 
2847                               (med_2_2::med_int*)families[i]->getAttributesIdentifiers(),
2848                               (med_2_2::med_int*)families[i]->getAttributesValues(),
2849                               const_cast <char *> (attributesDescriptions.c_str()), 
2850                               numberOfAttributes,  
2851                               const_cast <char *> (groupsNames.c_str()), 
2852                               numberOfGroups);
2853 #endif
2854       SCRUTE(err);
2855       if ( err != MED_VALID) 
2856         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't create family |" << families[i]->getName()
2857                                      << "| with identifier |" << families[i]->getIdentifier()  << "| groups names |" 
2858                                      << groupsNames  <<"| and  attributes descriptions |" << attributesDescriptions << "|")) ;
2859     }
2860     else
2861       med_2_2::_MEDdatagroupFermer(_medIdt);
2862
2863
2864   }
2865
2866   END_OF(LOC);
2867     
2868   return MED_VALID;
2869 }
2870
2871
2872 // A FAIRE POUR LES NOEUDS ET LES ELEMENTS ret = MEDfamEcr(
2873
2874
2875
2876 /*--------------------- RDWR PART -------------------------------*/
2877
2878 MED_MESH_RDWR_DRIVER22::MED_MESH_RDWR_DRIVER22()
2879 {
2880 }
2881
2882 MED_MESH_RDWR_DRIVER22::MED_MESH_RDWR_DRIVER22(const string & fileName,
2883                                                MESH * ptrMesh):
2884   MED_MESH_DRIVER(fileName,ptrMesh,MED_RDWR),
2885   IMED_MESH_RDONLY_DRIVER(fileName,ptrMesh),
2886   IMED_MESH_WRONLY_DRIVER(fileName,ptrMesh),
2887   IMED_MESH_RDWR_DRIVER(fileName,ptrMesh),
2888   MED_MESH_DRIVER22(fileName,ptrMesh,MED_RDWR),
2889   MED_MESH_RDONLY_DRIVER22(fileName,ptrMesh),
2890   MED_MESH_WRONLY_DRIVER22(fileName,ptrMesh)
2891 {
2892   MESSAGE("MED_MESH_RDWR_DRIVER22::MED_MESH_RDWR_DRIVER22(const string & fileName, MESH * ptrMesh) has been created");
2893 }
2894
2895 MED_MESH_RDWR_DRIVER22::MED_MESH_RDWR_DRIVER22(const MED_MESH_RDWR_DRIVER22 & driver):
2896   MED_MESH_DRIVER(driver),
2897   IMED_MESH_RDONLY_DRIVER(driver),
2898   IMED_MESH_WRONLY_DRIVER(driver),
2899   IMED_MESH_RDWR_DRIVER(driver),
2900   MED_MESH_DRIVER22(driver),
2901   MED_MESH_RDONLY_DRIVER22(driver),
2902   MED_MESH_WRONLY_DRIVER22(driver)
2903 {
2904 }
2905
2906 MED_MESH_RDWR_DRIVER22::~MED_MESH_RDWR_DRIVER22() {
2907   //MESSAGE("MED_MESH_RDWR_DRIVER22::MED_MESH_RDWR_DRIVER22(const string & fileName, MESH * ptrMesh) has been destroyed");
2908
2909   
2910 GENDRIVER * MED_MESH_RDWR_DRIVER22::copy(void) const
2911 {
2912   return new MED_MESH_RDWR_DRIVER22(*this);
2913 }
2914
2915 void MED_MESH_RDWR_DRIVER22::write(void) const
2916 {
2917   MED_MESH_WRONLY_DRIVER22::write();
2918 }
2919 void MED_MESH_RDWR_DRIVER22::read (void)
2920 {
2921   MED_MESH_RDONLY_DRIVER22::read();
2922 }
2923