]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_MedMeshDriver22.cxx
Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/med.git] / src / MEDMEM / MEDMEM_MedMeshDriver22.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include "MEDMEM_MedMeshDriver.hxx"
23 #include "MEDMEM_GenDriver.hxx"
24 #include "MEDMEM_MedMeshDriver22.hxx"
25 #include "MEDMEM_DriversDef.hxx"
26
27 #include "MEDMEM_Family.hxx"
28 #include "MEDMEM_Group.hxx"
29 #include "MEDMEM_Coordinate.hxx"
30 #include "MEDMEM_Connectivity.hxx"
31 #include "MEDMEM_Mesh.hxx"
32 #include "MEDMEM_CellModel.hxx"
33 #include "MEDMEM_Grid.hxx"
34 #include "MEDMEM_MedVersion.hxx"
35
36 using namespace std;
37 using namespace MED_EN;
38 using namespace MEDMEM;
39
40 namespace med_2_3 {
41   extern "C" {
42     extern med_idt _MEDdatagroupOuvrir(med_idt pid, char *nom);
43     extern med_err _MEDdatagroupFermer(med_idt id);
44   }
45 }
46
47 // Every memory allocation made in the MedDriver members function are desallocated in the Mesh destructor
48
49 MED_MESH_DRIVER22::MED_MESH_DRIVER22():  _medIdt(MED_INVALID)
50 {
51 }
52
53 MED_MESH_DRIVER22::MED_MESH_DRIVER22(const string & fileName,
54                                      MESH * ptrMesh,
55                                      MED_EN::med_mode_acces accessMode):
56   _medIdt(MED_INVALID), MED_MESH_DRIVER(fileName,ptrMesh,accessMode)
57 {
58 }
59
60 MED_MESH_DRIVER22::MED_MESH_DRIVER22(const MED_MESH_DRIVER22 & driver):
61   MED_MESH_DRIVER(driver),_medIdt(driver._medIdt)
62 {
63 }
64
65 MED_MESH_DRIVER22::~MED_MESH_DRIVER22()
66 {
67 }
68
69 void MED_MESH_DRIVER22::open()
70 {
71   const char * LOC = "MED_MESH_DRIVER22::open()" ;
72   BEGIN_OF_MED(LOC);
73
74   int accessMode = getMedAccessMode( _accessMode, MED_EN::V22 );
75   MESSAGE_MED(LOC<<" : _fileName.c_str : "<< _fileName.c_str()<<",mode : "<< accessMode);
76   _medIdt = med_2_3::MEDouvrir( (const_cast <char *> (_fileName.c_str())),(med_2_3::med_mode_acces) accessMode);
77   MESSAGE_MED(LOC<<" _medIdt : "<< _medIdt );
78   if (_medIdt > 0) 
79     _status = MED_OPENED; 
80   else {
81     _medIdt = MED_INVALID;
82     _status = MED_CLOSED;
83     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Could not open file "<<_fileName<<" in mode "<<_accessMode));
84   }
85   
86   END_OF_MED(LOC);
87 }
88   
89 void MED_MESH_DRIVER22::close()
90 {
91   const char * LOC = "MED_MESH_DRIVER22::close() " ;
92   BEGIN_OF_MED(LOC);
93   int err = 0;
94   if ( _status == MED_OPENED) {
95     err = med_2_3::MEDfermer(_medIdt);
96     // san -- MED5873 : Calling H5close() here leads to failure of SALOMEDS::StudyManager_i::_SaveAs()
97     // method during study saving process. MEDfermer() seems sufficient for closing a file.
98     //H5close(); // If we call H5close() all the files are closed.
99     if (err != 0)
100       throw MEDEXCEPTION( LOCALIZED(STRING(LOC)
101                                     <<" Error when closing file !"
102                                     )
103                           );
104     MESSAGE_MED(LOC <<": _medIdt= " << _medIdt );
105     MESSAGE_MED(LOC<<": MEDfermer : err    = " << err );
106     _status = MED_CLOSED;
107     _medIdt = MED_INVALID;
108   }
109   END_OF_MED(LOC);
110 }
111
112 //A FAIRE UTILISER LES MAPS...
113 const med_2_3::med_geometrie_element  MED_MESH_DRIVER22::all_cell_type[MED_NBR_GEOMETRIE_MAILLE]=
114   { med_2_3::MED_POINT1,med_2_3::MED_SEG2,med_2_3::MED_SEG3,med_2_3::MED_TRIA3,med_2_3::MED_QUAD4,med_2_3::MED_TRIA6,med_2_3::MED_QUAD8,
115     med_2_3::MED_TETRA4,med_2_3::MED_PYRA5,med_2_3::MED_PENTA6,med_2_3::MED_HEXA8,med_2_3::MED_TETRA10,med_2_3::MED_PYRA13,
116     med_2_3::MED_PENTA15, med_2_3::MED_HEXA20};
117
118 const char * const MED_MESH_DRIVER22::all_cell_type_tab [MED_NBR_GEOMETRIE_MAILLE]=
119   { "MED_POINT1","MED_SEG2","MED_SEG3","MED_TRIA3","MED_QUAD4","MED_TRIA6","MED_QUAD8",
120     "MED_TETRA4","MED_PYRA5","MED_PENTA6","MED_HEXA8","MED_TETRA10","MED_PYRA13",
121     "MED_PENTA15","MED_HEXA20"};
122
123
124 //---------------------------------- RDONLY PART -------------------------------------------------------------
125
126 MED_MESH_RDONLY_DRIVER22::MED_MESH_RDONLY_DRIVER22():_computeFaces(true)
127 {
128   this->GENDRIVER::_accessMode = MED_EN::RDONLY;
129 }
130   
131 MED_MESH_RDONLY_DRIVER22::MED_MESH_RDONLY_DRIVER22(const string & fileName,
132                                                    MESH * ptrMesh):
133   IMED_MESH_RDONLY_DRIVER(fileName,ptrMesh),
134   MED_MESH_DRIVER22(fileName,ptrMesh,RDONLY),
135   MED_MESH_DRIVER(fileName,ptrMesh,RDONLY),
136   _computeFaces(true)
137
138   MESSAGE_MED("MED_MESH_RDONLY_DRIVER22::MED_MESH_RDONLY_DRIVER22(const string & fileName, MESH * ptrMesh) has been created");
139 }
140   
141 MED_MESH_RDONLY_DRIVER22::MED_MESH_RDONLY_DRIVER22(const MED_MESH_RDONLY_DRIVER22 & driver): 
142    IMED_MESH_RDONLY_DRIVER(driver),
143    MED_MESH_DRIVER22(driver),
144    MED_MESH_DRIVER(driver),
145    _computeFaces(driver._computeFaces)
146 {
147 }
148
149 MED_MESH_RDONLY_DRIVER22::~MED_MESH_RDONLY_DRIVER22()
150 {
151   //MESSAGE_MED("MED_MESH_RDONLY_DRIVER22::~MED_MESH_RDONLY_DRIVER() has been destroyed");
152 }
153
154 GENDRIVER * MED_MESH_RDONLY_DRIVER22::copy(void) const
155 {
156   return new MED_MESH_RDONLY_DRIVER22(*this);
157 }
158
159 void MED_MESH_RDONLY_DRIVER22::merge ( const GENDRIVER& driver )
160 {
161   MED_MESH_DRIVER::merge( driver );
162
163   const MED_MESH_RDONLY_DRIVER22* other =
164     dynamic_cast< const MED_MESH_RDONLY_DRIVER22* >( &driver );
165   if ( other ) {
166     _computeFaces = other->_computeFaces;
167   }
168 }
169
170 void MED_MESH_RDONLY_DRIVER22::read(void)
171 {
172   const char * LOC = "MED_MESH_RDONLY_DRIVER22::read() : " ;
173   BEGIN_OF_MED(LOC);
174   if (_status != MED_OPENED)
175     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "The _idt of file " << _fileName
176                                  << " is : " << _medIdt << " (the file is not opened)."));
177
178   if ( ( _meshName.empty() ) && ( _ptrMesh->_name.empty() ) )
179     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)
180                                  <<" neither <meshName> is set in driver nor in object MESH."));
181
182   // If _meshName is not set in driver, try to use _ptrMesh->_name
183   if ( ( _meshName.empty() ) && ( !_ptrMesh->_name.empty() ) )
184     _meshName = _ptrMesh->_name;
185
186   if ( _meshName.size() > MED_TAILLE_NOM )
187     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)
188                                  <<" <meshName> size in object driver MESH is > MED_TAILLE_NOM ."));
189
190   _ptrMesh->_name = _meshName;
191
192   // 0020058: Check version of med, which was used to save the file.
193   // 0020058: An assertion happens in MEDcoordLire(), if this version
194   // 0020058: is higher than the currently used version of med product.
195   med_2_3::med_int aMajor, aMinor, aRelease;
196   med_2_3::med_int aMajorCurr, aMinorCurr, aReleaseCurr;
197
198   med_err aRet = med_2_3::MEDversionLire(_medIdt, &aMajor, &aMinor, &aRelease);
199   med_2_3::MEDversionDonner(&aMajorCurr, &aMinorCurr, &aReleaseCurr);
200
201   int aVersionHex     = (aMajor << 16 | aMinor << 8 | aRelease);
202   int aVersionHexCurr = (aMajorCurr << 16 | aMinorCurr << 8 | aReleaseCurr);
203
204   if (aRet != 0 || aVersionHex > aVersionHexCurr)
205     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)
206           <<" cannot read a file of version higher than the currently used version of med."));
207   // 0020058: end of version check
208
209   SCRUTE_MED(_ptrMesh->getIsAGrid());
210
211   if (_ptrMesh->getIsAGrid())
212   {
213     getGRID();
214     {
215       if (getFAMILY() != MED_VALID)
216         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getFAMILY when the mesh is a grid")) ;
217       buildAllGroups(_ptrMesh->_groupNode, _ptrMesh->_familyNode);
218     }
219     END_OF_MED(LOC);
220     return;
221   }
222   else // check that the mesh is really unstructured (PAL14113)
223   {
224     char                  meshName[MED_TAILLE_NOM+1] = "";
225     char                  meshDescription[MED_TAILLE_DESC+1] = "";
226     med_2_3::med_int      meshDim;
227     med_2_3::med_maillage meshType;
228     int                   numberOfMeshes = med_2_3::MEDnMaa(_medIdt);
229
230     for (int i = 1; i <= numberOfMeshes; i++)
231     {
232       MEDmaaInfo(_medIdt, i, meshName, &meshDim, &meshType, meshDescription);
233       if (_meshName == string(meshName)) {
234         if (meshType == med_2_3::MED_STRUCTURE) {
235           throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<
236                                        "class GRID must be used for a structured mesh"));
237         }
238         else {
239           break;
240         }
241       }
242     }
243   }
244
245   if (getCOORDINATE() != MED_VALID)
246     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getCOORDINATE"  ));
247
248   if (getCONNECTIVITY() != MED_VALID)
249     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getCOONECTIVITY"));
250
251   if (getFAMILY() != MED_VALID)
252     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getFAMILY"      ));
253
254   if (_computeFaces)
255     updateFamily();
256
257   // we build all groups
258   // on node
259   buildAllGroups(_ptrMesh->_groupNode,_ptrMesh->_familyNode) ;
260   // on cell
261   buildAllGroups(_ptrMesh->_groupCell,_ptrMesh->_familyCell) ;
262
263   if (_ptrMesh->_meshDimension == 3)
264     // on face
265     buildAllGroups(_ptrMesh->_groupFace,_ptrMesh->_familyFace) ;
266 //   else if (_ptrMesh->_meshDimension == 2) -- PAL13414
267   if (_ptrMesh->_meshDimension > 1)
268     // on edge
269     buildAllGroups(_ptrMesh->_groupEdge,_ptrMesh->_familyEdge) ;
270
271   _ptrMesh->_name = healName( _ptrMesh->_name );
272 //   MESSAGE_MED(LOC<<"Checking of CellModel !!!!!!!");
273
274 //   int nbOfTypes =  _ptrMesh->_connectivity->_numberOfTypes;
275 //    for(int i=0;i<nbOfTypes;i++)
276 //      {
277 //        MESSAGE_MED(LOC << _ptrMesh->_connectivity->_type[i]) ;
278 //      }
279
280   END_OF_MED(LOC);
281 }
282
283 //=======================================================================
284 //function : getGRID
285 //purpose  : 
286 //=======================================================================
287
288 void MED_MESH_RDONLY_DRIVER22::getGRID()
289 {
290   const char * LOC = "MED_MESH_RDONLY_DRIVER22::getGRID() : " ;
291   BEGIN_OF_MED(LOC);
292   
293   if (_status!=MED_OPENED)
294     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "med file is not opened"));
295   
296   GRID * ptrGrid = (GRID *) _ptrMesh;
297     
298   SCRUTE_MED(ptrGrid);
299
300   int err, i;
301
302   int numberOfMeshesInFile = med_2_3::MEDnMaa(_medIdt);
303
304   if (numberOfMeshesInFile == MED_INVALID)
305     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Problem in File where the mesh " << _meshName << " is supposed to be stored"));
306
307   for (int index = 0; index < numberOfMeshesInFile; index++)
308     {
309       char meshName[MED_TAILLE_NOM+1]="";
310       char meshDescription[MED_TAILLE_DESC+1]="";
311 //CCRT      int meshDim;
312       med_2_3::med_int meshDim;
313       med_2_3::med_maillage meshType;
314
315       err = med_2_3::MEDmaaInfo(_medIdt, (index+1),meshName, &meshDim,
316                                &meshType, meshDescription) ;
317
318       MESSAGE_MED(LOC<<": Mesh n°"<< (index+1) <<" nammed "<< meshName << " with the description " << meshDescription << " is structured");
319
320       if (_meshName == string(meshName))
321         {
322           _ptrMesh->_description = meshDescription;
323           _ptrMesh->_name = meshName;
324         }
325     }
326
327   MED_EN::med_grid_type gridType = ptrGrid->getGridType();
328   if ( ptrGrid->_is_default_gridType )
329   {
330     med_2_3::med_type_grille type;
331     err = med_2_3::MEDnatureGrilleLire(_medIdt,
332                                        const_cast <char *>(_meshName.c_str()),
333                                        &type);
334     if (err != MED_VALID)
335       throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << ": can't get the nature of the grid which is the mesh n°" << i << " of the file |" << _fileName << "| !"));
336
337     gridType = ptrGrid->_gridType = (MED_EN::med_grid_type) type;
338     ptrGrid->_is_default_gridType = false;
339   }
340
341   MESSAGE_MED(LOC<<": Mesh processed is nammed "<< _ptrMesh->_name << " with the description " << _ptrMesh->_description << " is structured with the type " << gridType);
342
343   // Read the dimension of the mesh <_meshName>
344   int MeshDimension = med_2_3::MEDdimLire(_medIdt, const_cast <char *>
345                                          (_meshName.c_str())) ;
346
347   if (MeshDimension == MED_INVALID)
348     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "The mesh dimension |" <<
349                                  MeshDimension << "| seems to be incorrect " <<
350                                  "for the mesh : |" << _meshName << "|")) ;
351
352   _ptrMesh->_meshDimension = MeshDimension;
353
354   // Read or get the dimension of the space for the mesh <_meshName>
355   int SpaceDimension = MeshDimension;
356
357   int SpaceDimensionRead = med_2_3::MEDdimEspaceLire(_medIdt,
358                                                     const_cast <char *>
359                                                     (_meshName.c_str())) ;
360
361   if (SpaceDimensionRead != MED_INVALID) SpaceDimension = SpaceDimensionRead;
362
363   _ptrMesh->_spaceDimension = SpaceDimension;
364
365   med_2_3::med_repere rep ;
366   string tmp_nom_coord (MED_TAILLE_PNOM22*(_ptrMesh->_spaceDimension)+1,' ');
367   string tmp_unit_coord(MED_TAILLE_PNOM22*(_ptrMesh->_spaceDimension)+1,' ');
368   char * tmp_nom = (const_cast <char *> ( tmp_nom_coord.c_str())  ) ;
369   char * tmp_unit= (const_cast <char *> ( tmp_unit_coord.c_str()) ) ;
370
371   // Read Array length
372   int * ArrayLen[] = { & ptrGrid->_iArrayLength,
373                        & ptrGrid->_jArrayLength,
374                        & ptrGrid->_kArrayLength  };
375
376   MESSAGE_MED(LOC << "The mesh is a " << _ptrMesh->_meshDimension << "D mesh on a " << _ptrMesh->_spaceDimension << "D space");
377
378   int NumberOfNodes;
379
380   //  if (gridType == MED_EN::MED_GRILLE_STANDARD)
381   if (gridType == MED_EN::MED_BODY_FITTED)
382     {
383 //CCRT      int * structure = new int[MeshDimension];
384       med_2_3::med_int * structure = new med_2_3::med_int[MeshDimension];
385
386       err = med_2_3::MEDstructureCoordLire(_medIdt,
387                                           const_cast <char *>
388                                           (_ptrMesh->_name.c_str()),
389                                           MeshDimension,structure);
390
391       if (err != MED_VALID)
392         throw MEDEXCEPTION(STRING(LOC) <<"Error in reading the structure of grid : |" << _meshName << "|" ) ;
393       
394       NumberOfNodes = 1;
395
396       for (int idim = 0; idim < MeshDimension; idim++)
397         {
398           MESSAGE_MED(LOC<<"structure dim " << idim << " " << structure[idim]);
399
400           ArrayLen [idim][0] = structure[idim];
401           NumberOfNodes = NumberOfNodes*structure[idim];
402         }
403       
404       delete [] structure;
405
406 //       NumberOfNodes = MED_FR::MEDnEntMaa(_medIdt,
407 //                                       const_cast <char *>
408 //                                       (_ptrMesh->_name.c_str()),
409 //                                       MED_FR::MED_COOR,MED_FR::MED_NOEUD,
410 //                                       (MED_FR::med_geometrie_element) 0,
411 //                                       (MED_FR::med_connectivite) 0);
412
413       if ( NumberOfNodes == MED_INVALID )
414         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"The number of nodes |" <<
415                                      NumberOfNodes <<
416                                      "| seems to be incorrect "
417                                      << "for the mesh : |" <<
418                                      _meshName << "|" )) ;
419
420       _ptrMesh->_numberOfNodes = NumberOfNodes ;
421
422       // create coordinates and its structure
423       _ptrMesh->_coordinate = new COORDINATE(SpaceDimension,NumberOfNodes,
424                                              MED_EN::MED_FULL_INTERLACE);
425
426       err = MEDcoordLire(_medIdt,
427                          const_cast <char *> (_ptrMesh->_name.c_str()),
428                          _ptrMesh->_spaceDimension,
429                          //const_cast <double *> ( _ptrMesh->_coordinate->_coordinate->get(MED_EN::MED_FULL_INTERLACE) ),
430                          const_cast <double *> ( _ptrMesh->_coordinate->_coordinate.get(MED_EN::MED_FULL_INTERLACE) ),
431                          med_2_3::MED_FULL_INTERLACE,
432                          MED_ALL, // we read all the coordinates
433                          NULL,    // we don't use a profile
434                          0,       // so the profile's size is 0
435                          &rep,tmp_nom,tmp_unit);
436
437       if (err != MED_VALID)
438         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't read coordinates of the |" <<
439                                      NumberOfNodes << "| nodes for the mesh : |" <<
440                                      _meshName << "| of space dimension |" <<
441                                      SpaceDimension << "| with units names |" <<
442                                      tmp_nom << "| and units |" <<
443                                      tmp_unit << " |")) ;
444
445       ptrGrid->_is_coordinates_filled = true;
446     }
447   else if ((gridType == MED_EN::MED_CARTESIAN) ||
448            (gridType == MED_EN::MED_POLAR))
449     {
450       NumberOfNodes = 1;
451
452       double * Array[] = { (double*) 0, (double*) 0, (double*) 0 };
453
454       for (int idim = 0; idim < _ptrMesh->_meshDimension; ++idim)
455         {
456           med_2_3::med_table table;
457           if (idim == 0) table = med_2_3::MED_COOR_IND1;
458           else if (idim == 1) table = med_2_3::MED_COOR_IND2;
459           else if (idim == 2) table = med_2_3::MED_COOR_IND3;
460
461           int length = med_2_3::MEDnEntMaa(_medIdt,
462                                           const_cast <char *> (_ptrMesh->_name.c_str()),
463                                           table,med_2_3::MED_NOEUD,
464                                           med_2_3::MED_NONE,
465                                           med_2_3::MED_NOD);
466           if ( length <= MED_VALID )
467             throw MEDEXCEPTION(STRING(LOC) <<"The number of nodes |" << length <<
468                                "| seems to be incorrect "
469                                << "for the mesh : |" << _meshName << "|" ) ;
470           
471           ArrayLen [idim][0] = length;
472           NumberOfNodes *= length;
473
474           Array [idim] = new double [ length ];
475
476           err = med_2_3::MEDindicesCoordLire(_medIdt, const_cast <char *>
477                                             (_ptrMesh->_name.c_str()),
478                                             _ptrMesh->_meshDimension,
479                                             Array [idim], length, (idim+1),
480                                             tmp_nom+(idim*MED_TAILLE_PNOM22),
481                                             tmp_unit+(idim*MED_TAILLE_PNOM22));
482
483           if (err != MED_VALID)
484             throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Error in reading coordinates indices " <<
485                                          idim << "of the grid : |" <<
486                                          _meshName << "|" )) ;
487         }
488
489       ptrGrid->_iArray = Array[0];
490       ptrGrid->_jArray = Array[1];
491       ptrGrid->_kArray = Array[2];
492
493       _ptrMesh->_numberOfNodes = NumberOfNodes ;
494     
495       // create coordinates
496       _ptrMesh->_coordinate = new COORDINATE(SpaceDimension,NumberOfNodes,
497                                              MED_EN::MED_FULL_INTERLACE);
498
499       if (gridType == MED_EN::MED_CARTESIAN)
500         rep = med_2_3::MED_CART;
501       else if (gridType == MED_EN::MED_POLAR)
502         {
503           if (SpaceDimension == 2) rep = med_2_3::MED_CYL;
504           else if (SpaceDimension == 3) rep = med_2_3::MED_SPHER;
505         }
506     }
507   else
508     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<" bad grid type : " << gridType));
509
510   // set coordinate names
511
512   for (i=0; i<_ptrMesh->_spaceDimension; ++i ) {
513     string myStringName(tmp_nom_coord,i*MED_TAILLE_PNOM22,MED_TAILLE_PNOM22) ;
514     string myStringUnit(tmp_unit_coord,i*MED_TAILLE_PNOM22,MED_TAILLE_PNOM22) ;
515     // suppress space at the end
516     int j ;
517     for(j=MED_TAILLE_PNOM22-1;j>=0;j--)
518       if (myStringName[j] != ' ') break ;
519     _ptrMesh->_coordinate->_coordinateName[i]=string(myStringName,0,j+1);
520     for(j=MED_TAILLE_PNOM22-1;j>=0;j--)
521       if (myStringUnit[j] != ' ') break ;
522     _ptrMesh->_coordinate->_coordinateUnit[i]=string(myStringUnit,0,j+1);
523   }
524
525   string coordinateSystem = "UNDEFINED";
526
527   if( rep == med_2_3::MED_CART) coordinateSystem = "CARTESIAN";
528   else if ( rep == med_2_3::MED_CYL) coordinateSystem = "CYLINDRICAL";
529   else if ( rep == med_2_3::MED_SPHER) coordinateSystem = "SPHERICAL";
530
531   _ptrMesh->_coordinate->setCoordinatesSystem(coordinateSystem);
532
533   END_OF_MED(LOC);
534 }
535
536 //=======================================================================
537 //function : getCOORDINATE
538 // A FAIRE : RENVOYER DU VOID
539 //=======================================================================
540 int  MED_MESH_RDONLY_DRIVER22::getCOORDINATE()
541 {
542   const char * LOC = "MED_MESH_RDONLY_DRIVER22::getCOORDINATE() : " ;
543
544   BEGIN_OF_MED(LOC);
545
546   if (_status==MED_OPENED)
547   {
548     int err;
549
550     int numberOfMeshesInFile = med_2_3::MEDnMaa(_medIdt);
551
552     if (numberOfMeshesInFile == MED_INVALID)
553       throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Problem in File where the mesh " << _meshName
554                                    << " is supposed to be stored"));
555
556     for (int index = 0; index < numberOfMeshesInFile; index++)
557     {
558       char meshName[MED_TAILLE_NOM+1]="";
559       char meshDescription[MED_TAILLE_DESC+1]="";
560 //CCRT      int meshDim;
561       med_2_3::med_int meshDim;
562       med_2_3::med_maillage meshType;
563
564       err = med_2_3::MEDmaaInfo(_medIdt, (index+1), meshName, &meshDim,
565                                 &meshType, meshDescription) ;
566
567       MESSAGE_MED(LOC<<": Mesh n°"<< (index+1) <<" nammed "<< meshName
568                   << " with the description " << meshDescription << " is structured");
569
570       if (_meshName == string(meshName))
571       {
572         _ptrMesh->_description = meshDescription;
573       }
574     }
575
576     // Read the dimension of the mesh <_meshName>
577     int MeshDimension = med_2_3::MEDdimLire(_medIdt, const_cast <char *>
578                                             (_meshName.c_str())) ;
579
580     if ( MeshDimension == MED_INVALID )
581       throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "The mesh dimension |" << MeshDimension
582                                    << "| seems to be incorrect for the mesh : |" << _meshName << "|"));
583
584     _ptrMesh->_meshDimension = MeshDimension;
585
586     // Read or get the dimension of the space for the mesh <_meshName>
587     int SpaceDimension = MeshDimension;
588
589     int SpaceDimensionRead = med_2_3::MEDdimEspaceLire(_medIdt,
590                                                        const_cast <char *>
591                                                        (_meshName.c_str())) ;
592
593     if (SpaceDimensionRead  != MED_INVALID)
594       SpaceDimension = SpaceDimensionRead;
595
596     _ptrMesh->_spaceDimension = SpaceDimension;
597
598     // Read the number of nodes used in the mesh <_meshName>
599     // to be able to create a COORDINATE object
600     int NumberOfNodes=MEDnEntMaa(_medIdt,
601                                  const_cast <char *> (_meshName.c_str()),
602                                  med_2_3::MED_COOR,
603                                  med_2_3::MED_NOEUD,
604                                  (med_2_3::med_geometrie_element) MED_NONE,
605                                  (med_2_3::med_connectivite)      MED_NONE);
606     if ( NumberOfNodes <= MED_VALID )
607       throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"The number of nodes |" << NumberOfNodes
608                                    << "| seems to be incorrect for the mesh : |" << _meshName << "|" ));
609     _ptrMesh->_numberOfNodes = NumberOfNodes;
610
611     // create a COORDINATE object
612     if (_ptrMesh->_coordinate)
613       delete _ptrMesh->_coordinate;
614     _ptrMesh->_coordinate = new COORDINATE(SpaceDimension, NumberOfNodes, MED_EN::MED_FULL_INTERLACE);
615
616     med_2_3::med_repere rep; // ATTENTION ---> DOIT ETRE INTEGRE DS MESH EF: FAIT NON?
617     string tmp_nom_coord (MED_TAILLE_PNOM22*(_ptrMesh->_spaceDimension)+1,'\0');
618     string tmp_unit_coord(MED_TAILLE_PNOM22*(_ptrMesh->_spaceDimension)+1,'\0');
619     char * tmp_nom = (const_cast <char *> ( tmp_nom_coord.c_str())  ) ;
620     char * tmp_unit= (const_cast <char *> ( tmp_unit_coord.c_str()) ) ;
621
622     err=MEDcoordLire(_medIdt,
623                      const_cast <char *> (_ptrMesh->_name.c_str()),
624                      _ptrMesh->_spaceDimension,
625                      const_cast<double *>(_ptrMesh->_coordinate->_coordinate.get(MED_EN::MED_FULL_INTERLACE)),
626                      med_2_3::MED_FULL_INTERLACE,
627                      MED_ALL,                      // we read all the coordinates
628                      NULL,                         // we don't use a profile
629                      0,                            // so the profile's size is 0
630                      &rep,tmp_nom,tmp_unit);
631     if (err != MED_VALID)
632       throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't read coordinates of the |" << NumberOfNodes
633                                    << "| nodes for the mesh : |" << _meshName 
634                                    << "| of space dimension |" << SpaceDimension 
635                                    << "| with units names |"   << tmp_nom
636                                    << "| and units |"          << tmp_unit
637                                    << " |")) ;
638
639     for (int i=0;i<_ptrMesh->_spaceDimension;i++) {
640       string myStringName(tmp_nom_coord,i*MED_TAILLE_PNOM22,MED_TAILLE_PNOM22) ;
641       string myStringUnit(tmp_unit_coord,i*MED_TAILLE_PNOM22,MED_TAILLE_PNOM22) ;
642       // suppress space at the end
643       int j ;
644       for(j=MED_TAILLE_PNOM22-1;j>=0;j--)
645         if (myStringName[j] != ' ') break ;
646       _ptrMesh->_coordinate->_coordinateName[i]=string(myStringName,0,j+1);
647       for(j=MED_TAILLE_PNOM22-1;j>=0;j--)
648         if (myStringUnit[j] != ' ') break ;
649       _ptrMesh->_coordinate->_coordinateUnit[i]=string(myStringUnit,0,j+1);
650     }
651
652     // Pourquoi le stocker sous forme de chaîne ?
653     switch (rep)
654     {
655     case med_2_3::MED_CART : 
656       {
657         _ptrMesh->_coordinate->_coordinateSystem = "CARTESIAN";
658         break ;
659       }
660     case med_2_3::MED_CYL :
661       {
662         _ptrMesh->_coordinate->_coordinateSystem = "CYLINDRICAL";
663         break ;
664       }
665     case med_2_3::MED_SPHER :
666       {
667         _ptrMesh->_coordinate->_coordinateSystem = "SPHERICAL";
668         break ;
669       }
670     default :
671       {
672         _ptrMesh->_coordinate->_coordinateSystem = "UNDEFINED"; // ?Erreur ?
673         break ;
674       }
675     }
676
677     // Read the unused optional node Names
678     char * tmp_node_name = new char[NumberOfNodes*MED_TAILLE_PNOM22+1];
679     tmp_node_name[NumberOfNodes]='\0' ;
680     err=MEDnomLire(_medIdt,const_cast <char*> (_ptrMesh->_name.c_str()),
681                    tmp_node_name,NumberOfNodes*MED_TAILLE_PNOM22,med_2_3::MED_NOEUD,
682                    (med_2_3::med_geometrie_element) MED_NONE);
683     if (err == MED_VALID) 
684       MESSAGE_MED(LOC<<"MED_MESH_RDONLY_DRIVER::getNoeuds() : WARNING : Nodes have names but we do not read them !");
685     delete[] tmp_node_name ;
686
687     // ??? Read the unused optional node Numbers ???
688     med_2_3::med_int * tmp_node_number = new med_2_3::med_int[NumberOfNodes] ;
689     err=MEDnumLire(_medIdt,const_cast <char*> (_ptrMesh->_name.c_str()),
690                    tmp_node_number,NumberOfNodes,med_2_3::MED_NOEUD,(med_2_3::med_geometrie_element)0);
691     if (err == MED_VALID) {
692       // INFOS_MED(LOC<<"WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING");
693       // INFOS_MED(LOC<<"MED_MESH_RDONLY_DRIVER::getNoeuds() : WARNING : Nodes have numbers but we do not take care of them !");
694       // INFOS_MED(LOC<<"WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING");
695       MESSAGE_MED(LOC<<"MED_MESH_RDONLY_DRIVER::getNoeuds() : Nodes have numbers, we DO TAKE care of them !");
696       _ptrMesh->_coordinate->_nodeNumber.set(NumberOfNodes) ; 
697 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
698       for(med_2_3::med_int i2=0;i2<NumberOfNodes;i2++)
699         _ptrMesh->_coordinate->_nodeNumber[i2]=(int)(tmp_node_number[i2]);
700 #else
701       memcpy((int*)_ptrMesh->_coordinate->_nodeNumber,tmp_node_number,sizeof(int)*NumberOfNodes) ;
702 #endif
703
704       //////////////////////////////////////////////////////////////////////////////////////
705       ///  Modification pour prise en compte de la numérotation optionnelle des noeuds  ///
706       //////////////////////////////////////////////////////////////////////////////////////
707       ///
708       /// Calcule _optionnalToCanonicNodesNumbers de telle sorte que _optionnalToCanonicNodesNumbers[OptionnalNumber]==CanonicNumber
709
710       //        _ptrMesh->_arePresentOptionnalNodesNumbers=1;
711       //        for (int canonicNumber=1;canonicNumber<=NumberOfNodes;canonicNumber++) _ptrMesh->_optionnalToCanonicNodesNumbers[tmp_node_number[canonicNumber-1]]=canonicNumber;
712       // ICI RETOUR A LA NORMALE::: AUCUNE PRISE EN COMPTE D'UN NUMEROTATION OPTIONNEL
713       _ptrMesh->_arePresentOptionnalNodesNumbers=0;
714     }
715     else _ptrMesh->_arePresentOptionnalNodesNumbers=0;
716
717     //////////////////////////////////////////////////////////////////////////////////////
718
719     delete[] tmp_node_number;
720
721     END_OF_MED(LOC);
722     return MED_VALID;
723   }
724   return MED_ERROR;
725 }
726
727
728 int MED_MESH_RDONLY_DRIVER22::getCONNECTIVITY() 
729 {
730   const char * LOC = "MED_MESH_RDONLY_DRIVER22::getCONNECTIVITY : " ;
731   BEGIN_OF_MED(LOC);
732
733   if (_status==MED_OPENED)
734     {
735
736       int err = 0 ;
737       // read MED_CELL connectivity
738       CONNECTIVITY * Connectivity     = new CONNECTIVITY(MED_CELL) ;
739       Connectivity->_numberOfNodes    = _ptrMesh->_numberOfNodes ;   // EF : Pourquoi cet attribut est-il dans MESH et non dans COORDINATE ?
740
741       // Try to read nodal connectivity of the cells <Connectivity->_nodal>
742       // then try to read descending connectivity    <Connectivity->_descending>
743       // if neither nodal nor descending connectivity exists
744       // throw an exception.
745       err = getNodalConnectivity(Connectivity) ;
746       if (err!=MED_VALID)
747         {
748           Connectivity->_typeConnectivity = MED_DESCENDING ;
749           err = getDescendingConnectivity(Connectivity) ;
750         }
751       else 
752         getDescendingConnectivity(Connectivity) ; // we read it if there is one
753       
754       if (err!=MED_VALID)
755         {
756           delete Connectivity ;
757           throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "We could not read " <<
758                                        "any Connectivity")) ;
759         }
760
761       if (Connectivity->_entityDimension != _ptrMesh->_meshDimension)
762         MESSAGE_MED(LOC << "Small mesh dimension problem on the med file mounted in memory : diim stored " << _ptrMesh->_meshDimension << " dim computed using the connectivity " << Connectivity->_entityDimension);
763
764       _ptrMesh->_meshDimension = Connectivity->_entityDimension ; 
765
766       // At this point Connectivity->_typeConnectivity is either NODAL or DESCENDING
767       // If both connectivities are found Connectivity->_typeConnectivity is NODAL
768       // If space dimension is 3 
769       // try to read the nodal connectivity of the faces <ConnectivityFace->_nodal> then
770       // try to read the descending connectivity <ConnectivityFace->_descending>
771       // if there is no descending connectivity and the CELLS are
772       // defined in descending mode then throw an exception
773
774       // PROVISOIRE : if we have some face or edge in MED_MAILLE, we don't read more. There could not be have face or edge !!!!
775
776       if(Connectivity->_constituent==NULL) {
777
778       SCRUTE_MED(_ptrMesh->_meshDimension);
779       SCRUTE_MED(Connectivity->_entityDimension);
780       if (_ptrMesh->_meshDimension == 3) {
781         MESSAGE_MED(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE DES FACES..." );
782         CONNECTIVITY * ConnectivityFace = new CONNECTIVITY(MED_EN::MED_FACE) ;
783         ConnectivityFace->_typeConnectivity = Connectivity->_typeConnectivity ; // NODAL or DESCENDING
784         SCRUTE_MED(ConnectivityFace->_typeConnectivity);
785         if (Connectivity->_typeConnectivity == MED_DESCENDING) {
786           MESSAGE_MED(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE DESCENDANTE DES FACES" );
787           err = getDescendingConnectivity(ConnectivityFace) ;
788           if (err!=MED_VALID)
789             throw MEDEXCEPTION ( LOCALIZED(STRING(LOC) << "No FACE in descending connectivity")) ;
790           getNodalConnectivity(ConnectivityFace) ; // if any !
791         } else {
792           MESSAGE_MED(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE NODALE DES FACES" );
793           err = getNodalConnectivity(ConnectivityFace) ;
794           if (err!=MED_VALID) { // or error ????? we are in NODAL mode.
795             err = getDescendingConnectivity(ConnectivityFace) ;
796           } else
797             getDescendingConnectivity(ConnectivityFace); // if any !
798         }
799         if (err!=MED_VALID) {
800           delete ConnectivityFace ;
801           MESSAGE_MED(LOC<<"No FACE defined.") ;
802         } else {
803           MESSAGE_MED(LOC<<" SAUVEGARDE DE LA CONNECTIVITE DES FACES DANS L'OBJET CONNECTIVITY" );
804           delete Connectivity->_constituent;
805           Connectivity->_constituent=ConnectivityFace;
806         }
807       }
808
809       // read MED_EDGE connectivity
810       if (_ptrMesh->_meshDimension > 1) { // we are in 3 or 2D 
811         MESSAGE_MED(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE DES ARRETES...." );
812         CONNECTIVITY * ConnectivityEdge = new CONNECTIVITY(MED_EDGE) ;
813         ConnectivityEdge->_typeConnectivity = Connectivity->_typeConnectivity ;
814         if (Connectivity->_typeConnectivity == MED_DESCENDING) {
815           MESSAGE_MED(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE DESCENDANTE DES ARRETES" );
816           err = getDescendingConnectivity(ConnectivityEdge) ;
817           if (err!=MED_VALID)
818             throw MEDEXCEPTION ( LOCALIZED(STRING(LOC) << "No EDGE in descending connectivity")) ;
819           getNodalConnectivity(ConnectivityEdge) ; // if any !
820         } else {
821           MESSAGE_MED(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE NODALE DES ARRETES" );
822           err = getNodalConnectivity(ConnectivityEdge) ;
823           if (err!=MED_VALID) { // or error ????? we are in NODAL mode.
824             err = getDescendingConnectivity(ConnectivityEdge) ;
825           } else
826             getDescendingConnectivity(ConnectivityEdge) ; // if any !
827         }
828         if (err!=MED_VALID) {
829           delete ConnectivityEdge ;
830           MESSAGE_MED(LOC<<"No EDGE defined.") ;
831         } else {
832           if (_ptrMesh->_meshDimension == 3)
833             if (Connectivity->_constituent != NULL)
834               Connectivity->_constituent->_constituent=ConnectivityEdge ;
835             else
836               throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<< "EDGE defined but there are no FACE !")) ;
837           else { // IN 2D
838             MESSAGE_MED(LOC<<" SAUVEGARDE DE LA CONNECTIVITE DES ARETES DANS L'OBJET CONNECTIVITY" );
839             Connectivity->_constituent=ConnectivityEdge ;
840           }
841         }
842       }
843       }
844       if (_ptrMesh->_connectivity)
845         delete _ptrMesh->_connectivity;
846       _ptrMesh->_connectivity  = Connectivity ;                                      
847
848       // all right !
849
850       // we have read all connectivity in file, now we must build descending connectivity if necessary !
851
852       // If connectivity descending is defined, we have nothing to do, all constituent are defined !
853       // If connectivity is only nodal, we must rebuild descending if we have some contituent !
854
855       //A FAIRE !!!!
856 //        if (Connectivity->_descending == NULL)
857 //      if (Connectivity->_constituent != NULL){
858 //        // update Connectivity->_constituent
859 //        CONNECTIVITY * myConstituentOld = Connectivity->_constituent ;
860 //        Connectivity->_constituent = (CONNECTIVITY *)NULL ;
861 //        Connectivity->calculateDescendingConnectivity() ;
862           
863 //      }
864       
865   END_OF_MED(LOC);
866       return MED_VALID;
867     }
868   return MED_ERROR;
869 }
870
871 int MED_MESH_RDONLY_DRIVER22::getNodalConnectivity(CONNECTIVITY * Connectivity)
872 {
873   const char * LOC = "MED_MESH_RDONLY_DRIVER22::getNodalConnectivity : " ;
874   BEGIN_OF_MED(LOC);
875         
876   if (_status==MED_OPENED)
877     {
878       int spaceDimension = _ptrMesh->_spaceDimension;
879                         
880       // Get the type of entity to work on (previously set in the Connectivity Object)
881       med_2_3::med_entite_maillage Entity = (med_2_3::med_entite_maillage) Connectivity->getEntity();
882       
883       // Get the number of cells of each type & store it in <tmp_cells_count>.
884       int * tmp_cells_count = new int[MED_NBR_GEOMETRIE_MAILLE] ;
885       int i;
886       for (i=1;i<MED_NBR_GEOMETRIE_MAILLE;i++) 
887       {                       // EF :ON SCANNE DES GEOMETRIES INUTILES, UTILISER LES MAPS
888         tmp_cells_count[i]=MEDnEntMaa(_medIdt,(const_cast <char *> (_ptrMesh->_name.c_str())),
889                                       med_2_3::MED_CONN,(med_2_3::med_entite_maillage) Entity,
890                                       all_cell_type[i],med_2_3::MED_NOD); 
891                                 
892                                 
893         // Get the greatest dimension of the cells : Connectivity->_entityDimension
894         // We suppose there is no cells used as faces in MED 2.2.x , this is forbidden !!!
895         // In version prior to 2.2.x, it is possible
896         if (tmp_cells_count[i]>0) 
897         {
898           Connectivity->_entityDimension=all_cell_type[i]/100;
899           Connectivity->_numberOfTypes++;
900         }
901       }
902
903       {
904         // VBD fix to be able reading polygons and polyhedrons
905         // "in the case when the space dimension is 3 and the mesh dimension 2"
906
907         //checking for the number of polygons/polyhedra to get an appropriate mesh dimension
908         int nbpolygons=MEDnEntMaa(_medIdt,(const_cast <char *> (_ptrMesh->_name.c_str())),
909                                   med_2_3::MED_CONN,(med_2_3::med_entite_maillage) Entity,
910                                   med_2_3::MED_POLYGONE,med_2_3::MED_NOD);
911         if (nbpolygons>0)
912         {
913           if (Connectivity->_entityDimension<2)
914             Connectivity->_entityDimension=2;
915         }
916         int nbpolyhedra=MEDnEntMaa(_medIdt,(const_cast <char *> (_ptrMesh->_name.c_str())),
917                                    med_2_3::MED_CONN,(med_2_3::med_entite_maillage) Entity,
918                                    med_2_3::MED_POLYEDRE,med_2_3::MED_NOD);
919         if (nbpolyhedra>0)
920           Connectivity->_entityDimension=3;
921
922         //setting a correct mesh dimension as being the dimnsion corresponding to
923         // the highest dimension  element
924         if (Entity==med_2_3::MED_MAILLE)
925           _ptrMesh->_meshDimension = Connectivity->_entityDimension;
926       }
927
928       // begin classic geometric types
929       if (Connectivity->_numberOfTypes > 0)
930                                 {
931                                         // if MED version < 2.2.x, we read only entity with dimention = Connectivity->_entityDimension. Lesser dimension are face or edge !
932                                         
933           med_2_3::med_int major, minor, release;
934                                         
935           if ( med_2_3::MEDversionLire(_medIdt, &major, &minor, &release) != 0 )
936                                                 {
937                                                         // error : we suppose we have not a good med file !
938                                                         delete[] tmp_cells_count ;
939                                                         return MED_ERROR ;
940                                                 }
941                                         
942                                         // we get MED version number
943                                         // If MED version is < 2.2 then the cells which dimension
944                                         // is lesser than the main dimension ( Connectivity->_entityDimension )
945                                         // are either faces or edges
946                                         
947                                         int * tmpEdgeCount = new int[MED_NBR_GEOMETRIE_MAILLE] ;
948                                         tmpEdgeCount[0]     = 0 ;
949                                         int numberOfEdgesTypes = 0;
950                                         int * tmpFaceCount = new int[MED_NBR_GEOMETRIE_MAILLE] ;
951                                         tmpFaceCount[0]     = 0 ;
952                                         int numberOfFacesTypes = 0;
953                 
954                                         
955                                         if (Entity==med_2_3::MED_MAILLE)
956                                                 {
957                                                         Connectivity->_numberOfTypes=0;
958                                                         
959                                                         for ( i=1;i<MED_NBR_GEOMETRIE_MAILLE;i++) 
960                                                                 {
961                                                                         tmpFaceCount[i]=0;
962                                                                         tmpEdgeCount[i]=0;
963                                                                         if (tmp_cells_count[i]!=0) 
964                                                                                 {
965                                                                                         int dimension = all_cell_type[i]/100 ;
966                                                                                         if (Connectivity->_entityDimension==dimension) 
967                                                                                                 Connectivity->_numberOfTypes++ ;
968                                                                                         
969                                                                                         if (dimension == 2)
970                                                                                                 if (Connectivity->_entityDimension==3) 
971                                                                                                         {
972                                                                                                                 tmpFaceCount[i]=tmp_cells_count[i] ;
973                                                                                                                 //tmp_cells_count[i]=0 ;
974                                                                                                                 //Connectivity->_numberOfTypes++ ;
975                                                                                                                 numberOfFacesTypes++;
976                                                                                                         }
977                                                                                         if (dimension == 1)
978                                                                                                 if (Connectivity->_entityDimension>dimension) 
979                                                                                                         {
980                                                                                                                 tmpEdgeCount[i]=tmp_cells_count[i] ;
981                                                                                                                 //tmp_cells_count[i]=0;
982                                                                                                                 //Connectivity->_numberOfTypes++ ;
983                                                                                                                 numberOfEdgesTypes++ ;
984                                                                                                         }
985                                                                                 }
986                                                                 }
987                                                 }
988                                         
989                                         // bloc to read CELL :
990                                         {
991                                                 // Prepare an array of indexes on the different cell types to create a MEDSKYLINEARRAY
992                                                 // We use <tmp_cells_count> to calculate <Connectivity->_count> then we release it
993                                                 Connectivity->_geometricTypes = new MED_EN::medGeometryElement [Connectivity->_numberOfTypes]   ;  // Double emploi pour des raisons pratiques 
994                                                 Connectivity->_type           = new CELLMODEL                  [Connectivity->_numberOfTypes]   ;  //
995                                                 if(Connectivity->_count)
996                                                   delete [] Connectivity->_count;
997                                                 Connectivity->_count          = new int                        [Connectivity->_numberOfTypes+1] ;
998                                                 Connectivity->_count[0]       = 1;
999                                                 
1000                                                 int size = 0 ; 
1001                                                 int typeNumber=1 ;
1002                                                 int i;
1003                                                 for ( i=1;i<MED_NBR_GEOMETRIE_MAILLE;i++)  
1004                                                         { // no point1 cell type (?)
1005                                                                 int dimension = all_cell_type[i]/100 ;
1006                                                                 if ((tmp_cells_count[i]>0) && (Connectivity->_entityDimension == dimension))
1007                                                                         {
1008                                                                                 Connectivity->_count[typeNumber]=Connectivity->_count[typeNumber-1]+tmp_cells_count[i];
1009                                                                                 
1010                                                                                 CELLMODEL t( (MED_EN::medGeometryElement) MED_MESH_DRIVER22::all_cell_type[i]) ;
1011                                                                                 
1012                                                                                 Connectivity->_type[typeNumber-1] = t ;
1013                                                                                 
1014                                                                                 Connectivity->_geometricTypes[typeNumber-1]=( MED_EN::medGeometryElement) MED_MESH_DRIVER22::all_cell_type[i] ;
1015                                                                                 
1016                                                                                 // probleme avec les mailles de dimension < a dimension du maillage :
1017                                                                                 // 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 !!!
1018                                                                                 
1019                                                                                 
1020                                                                                 size+=tmp_cells_count[i]*((MED_MESH_DRIVER22::all_cell_type[i])%100) ;
1021                                                                                 
1022                                                                                 MESSAGE_MED(LOC
1023                                                                                                                 << Connectivity->_count[typeNumber]-1 << " cells of type " 
1024                                                                                                                 << all_cell_type_tab[i] ); 
1025                                                                                 typeNumber++;
1026                                                                         }
1027                                                         }
1028                                                 
1029                                                 // Creation of the MEDSKYLINEARRAY
1030                                                 //Connectivity->_nodal = new MEDSKYLINEARRAY(Connectivity->_count[Connectivity->_numberOfTypes]-1,size) ; 
1031             //int * NodalIndex = Connectivity->_nodal->getIndex() ;
1032                                                 int * NodalValue = new int[size] ;
1033                                                 int * NodalIndex = new int[Connectivity->_count[Connectivity->_numberOfTypes]] ;
1034                                                 NodalIndex[0]=1 ;
1035                                                 
1036                                                 // Fill the MEDSKYLINEARRAY by reading the MED file.
1037                                                 int j=0;
1038                                                 for ( i=0;i<Connectivity->_numberOfTypes;i++) 
1039                                                         {
1040                                                                 int multi = 0 ;
1041                                                                 med_2_3::med_geometrie_element med_type = (med_2_3::med_geometrie_element) Connectivity->_type[i].getType() ;
1042                                                                 //        if ( Connectivity->_type[i].getDimension() < Connectivity->_entityDimension) 
1043                                                                 //        if (Connectivity->_entity == MED_CELL)
1044                                                                 //          if ( Connectivity->_type[i].getDimension() < _ptrMesh->_spaceDimension) 
1045                                                                 //            multi=1;
1046                                                                 
1047                                                                 //        int NumberOfCell = Connectivity->_count[i+1]-Connectivity->_count[i] ;
1048                                                                 int NumberOfNodeByCell = Connectivity->_type[i].getNumberOfNodes() ;
1049                                                                 
1050                                                                 // initialise index
1051                                                                 for ( j=Connectivity->_count[i]; j<Connectivity->_count[i+1];j++)
1052                                                                         NodalIndex[j]=NodalIndex[j-1]+NumberOfNodeByCell ; 
1053                                                                 
1054                                                                 int tmp_numberOfCells = Connectivity->_count[i+1]-Connectivity->_count[i] ;
1055                                                                 //CCRT          int * tmp_ConnectivityArray = new int[(NumberOfNodeByCell+multi)*tmp_numberOfCells];
1056                                                                 med_2_3::med_int * tmp_ConnectivityArray = new med_2_3::med_int[(NumberOfNodeByCell+multi)*tmp_numberOfCells];
1057                                                                 int err=MEDconnLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
1058                                                                                                                                                 spaceDimension,tmp_ConnectivityArray,
1059                                                                                                                                                 med_2_3::MED_FULL_INTERLACE,NULL,0,Entity,med_type,med_2_3::MED_NOD);
1060                                                                 
1061                                                                 if ( err != MED_VALID)
1062                                                                         {
1063                                                                                 delete[] tmp_ConnectivityArray;
1064                                                                                 delete[] tmp_cells_count;
1065                                                                                 delete[] tmpFaceCount;
1066                                                                                 delete[] tmpEdgeCount;
1067                                                                                 MESSAGE_MED(LOC<<": MEDconnLire returns "<<err) ;
1068                                                                                 return MED_ERROR ;
1069                                                                         }
1070                                                                 
1071                                                                 int * ConnectivityArray = NodalValue + NodalIndex[Connectivity->_count[i]-1]-1 ;
1072                                                                 
1073                                                                 // version originale sans prise en compte des numéros optionnels
1074                                                                 //
1075                                                                 for ( j=0; j<tmp_numberOfCells; j++) for (int k=0; k<NumberOfNodeByCell; k++) 
1076                                                                         ConnectivityArray[j*NumberOfNodeByCell+k]=tmp_ConnectivityArray[j*(NumberOfNodeByCell+multi)+k] ;
1077                                                                 
1078                                                                 //////////////////////////////////////////////////////////////////////////////
1079                                                                 // Modification pour prise en compte de la numérotation optionnelle des noeuds ///
1080                                                                 //////////////////////////////////////////////////////////////////////////////
1081                                                                 //
1082                                                                 // Rénumérote le tableau temporaire tmp_ConnectivityArray en utilisant _optionnalToCanonicNodesNumbers
1083                                                                 // Le traitement est identique à la version originelle s'il n'y a pas de numérotation optionnelle
1084                                                      
1085                                                                 //      if (_ptrMesh->_arePresentOptionnalNodesNumbers==1) 
1086                                                                 //              {
1087                                                                 //              for ( j=0; j<tmp_numberOfCells; j++) for (int k=0; k<NumberOfNodeByCell; k++) 
1088                                                                 //                      ConnectivityArray[j*NumberOfNodeByCell+k]=_ptrMesh->_optionnalToCanonicNodesNumbers[tmp_ConnectivityArray[j*(NumberOfNodeByCell+multi)+k]] ;
1089                                                                 //              }
1090                                                                 //      else
1091                                                                 //              {
1092                                                                 //              for ( j=0; j<tmp_numberOfCells; j++) for (int k=0; k<NumberOfNodeByCell; k++) 
1093                                                                 //                      ConnectivityArray[j*NumberOfNodeByCell+k]=tmp_ConnectivityArray[j*(NumberOfNodeByCell+multi)+k] ;
1094                                                                 //              }
1095                                                                 ////////////////////////////////////////////////////////////////////////////
1096         
1097                                                                 delete[] tmp_ConnectivityArray;
1098   
1099                                                         }
1100
1101                                                 Connectivity->_nodal = new MEDSKYLINEARRAY(Connectivity->_count[Connectivity->_numberOfTypes]-1,
1102                                                                                                                                                                                                                          size,
1103                                                                                                                                                                                                                          NodalIndex,
1104                                                                                                                                                                                                                          NodalValue) ; 
1105
1106                                                 delete[] NodalIndex;
1107                                                 delete[] NodalValue;
1108
1109                                         } // end of bloc to read CELL
1110
1111
1112                                         // Get Face if any
1113                                         // ===============
1114      
1115                                         if (numberOfFacesTypes!=0) 
1116                                                 {
1117
1118                                                         // Create a CONNECTIVITY constituent to put in the top level CONNECTIVITY recursive class
1119                                                         CONNECTIVITY * constituent = new CONNECTIVITY(numberOfFacesTypes,MED_EN::MED_FACE) ;
1120                                                         constituent->_entityDimension = 2 ;
1121                                                         constituent->_count[0]=1 ;
1122
1123                                                         // In order to create the MEDSKYLINEARRAY of the constituent object we need :
1124                                                         // 1:
1125                                                         // To initialize the _count array of the constituent object (containning cumulated face count by geometric type)
1126                                                         // _count[0]=1 and _count[_numberOfTypes] give the size of NodalIndex
1127                                                         // 2:
1128                                                         // To calculate the total number of face nodes whatever the geometric type is.
1129                                                         // The result is the size of the array containning all the nodes : NodalValue
1130                                                         // 3 :
1131                                                         // To calculate the starting indexes of the different face types in NodalValue, 
1132                                                         // this is the NodalIndex array.
1133         
1134                                                         int size       = 0 ; 
1135                                                         int typeNumber = 1 ;
1136                                                         int i;
1137                                                         for ( i=1; i < MED_NBR_GEOMETRIE_MAILLE; i++)
1138                                                                 { // no point1 cell type (?)
1139                                                                         if (tmpFaceCount[i]>0)
1140                                                                                 {
1141                                                                                         constituent->_count[typeNumber] = constituent->_count[typeNumber-1] + tmpFaceCount[i];
1142                                                                                         CELLMODEL t( (MED_EN::medGeometryElement) MED_MESH_DRIVER22::all_cell_type[i]) ;
1143                                                                                         constituent->_type[typeNumber-1]=t ;
1144             
1145                                                                                         constituent->_geometricTypes[typeNumber-1]=( MED_EN::medGeometryElement) MED_MESH_DRIVER22::all_cell_type[i] ;
1146             
1147                                                                                         size+=tmpFaceCount[i]*((MED_MESH_DRIVER22::all_cell_type[i])%100) ;
1148                                                                                         typeNumber++;
1149                                                                                 }
1150                                                                 }
1151         
1152                                                         // Creation of the MEDSKYLINEARRAY
1153                                                         //constituent->_nodal = new MEDSKYLINEARRAY(constituent->_count[constituent->_numberOfTypes]-1,size) ; 
1154                                                         //int * NodalIndex = constituent->_nodal->getIndex() ;
1155                                                         int * NodalValue = new int[size] ;
1156                                                         int * NodalIndex = new int[constituent->_count[constituent->_numberOfTypes]] ;
1157                                                         NodalIndex[0]=1 ;
1158         
1159                                                         // Fill the MEDSKYLINEARRAY by reading the MED file.
1160                                                         for ( i=0; i<constituent->_numberOfTypes; i++) 
1161                                                                 {
1162                                                                         med_2_3::med_geometrie_element med_type = (med_2_3::med_geometrie_element) constituent->_type[i].getType() ;
1163
1164                                                                         int NumberOfNodeByFace = constituent->_type[i].getNumberOfNodes() ;
1165           
1166                                                                         // initialise NodalIndex
1167                                                                         for (int j=constituent->_count[i]; j<constituent->_count[i+1];j++)
1168                                                                                 NodalIndex[j]=NodalIndex[j-1]+NumberOfNodeByFace ; 
1169           
1170                                                                         int tmp_numberOfFaces = constituent->_count[i+1]-constituent->_count[i] ;
1171                                                                         // Il faut ajouter 1 pour le zero a la lecture !!!
1172                                                                         // ATTENTION UNIQUEMENT POUR MED < 2.2.x
1173                                                                         //CCRT            int * tmp_constituentArray = NULL;
1174                                                                         med_2_3::med_int * tmp_constituentArray = NULL;
1175
1176                                                                         MESSAGE_MED(LOC << "Med file version used here " << major << " " << minor << " " << release);
1177
1178                                                                         if ((major == 2) && (minor <= 1))
1179                                                                                 //CCRT              tmp_constituentArray = new int[(NumberOfNodeByFace+1)*tmp_numberOfFaces] ;
1180                                                                                 tmp_constituentArray = new med_2_3::med_int[(NumberOfNodeByFace+1)*tmp_numberOfFaces] ;
1181                                                                         else if ((major == 2) && (minor >= 2))
1182                                                                                 {
1183                                                                                         //CCRT                tmp_constituentArray = new int[NumberOfNodeByFace*tmp_numberOfFaces] ;
1184                                                                                         tmp_constituentArray = new med_2_3::med_int[NumberOfNodeByFace*tmp_numberOfFaces] ;
1185                                                                                         MESSAGE_MED(LOC<<": WE ARE USING MED2.2 so there is no +1 for calculating the size of  tmp_constituentArray !") ;
1186                                                                                 }
1187
1188                                                                         int err=MEDconnLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
1189                                                                                                                                                         Connectivity->_entityDimension,tmp_constituentArray,
1190                                                                                                                                                         med_2_3::MED_FULL_INTERLACE,NULL,0,med_2_3::MED_MAILLE,med_type,med_2_3::MED_NOD);
1191
1192                                                                         if ( err != MED_VALID) 
1193                                                                                 {
1194                                                                                         MESSAGE_MED(LOC<<": MEDconnLire returns "<<err) ;
1195                                                                                         delete constituent ;
1196                                                                                         delete[] tmp_constituentArray;
1197                                                                                         delete[] tmpFaceCount;
1198                                                                                         delete[] tmpEdgeCount;
1199                                                                                         return MED_ERROR ;
1200                                                                                 }
1201
1202                                                                         int * constituentArray = NodalValue + NodalIndex[constituent->_count[i]-1]-1 ;
1203           
1204                                                                         // version originale sans prise en compte des numéros optionnels
1205                                                                         //      
1206                                                                         int multi = 0; // quand est-ce que multi vaut 1 ?? en MED-fichier < 2.2 ??
1207                                                                         MESSAGE_MED(LOC << "Med file version used here " << major << " " << minor << " " << release);
1208
1209                                                                         if ((major == 2) && (minor <= 1))
1210                                                                                 for (int j=0; j<tmp_numberOfFaces; j++)
1211                                                                                         for (int k=0; k<NumberOfNodeByFace; k++)
1212                                                                                                 constituentArray[j*NumberOfNodeByFace+k]=tmp_constituentArray[j*(NumberOfNodeByFace+1)+k] ;
1213                                                                         else if ((major == 2) && (minor >= 2))
1214                                                                                 for (int j=0; j<tmp_numberOfFaces; j++)
1215                                                                                         for (int k=0; k<NumberOfNodeByFace; k++)
1216                                                                                                 constituentArray[j*NumberOfNodeByFace+k]=tmp_constituentArray[j*(NumberOfNodeByFace+multi)+k] ;
1217
1218                                                                         //////////////////////////////////////////////////////////////////////////////////////
1219                                                                         ///  Modification pour prise en compte de la numérotation optionnelle des noeuds   ///
1220                                                                                 //////////////////////////////////////////////////////////////////////////////////////
1221                                                                                 ///
1222                                                                                 /// Rénumérote le tableau temporaire tmp_constituentArray en utilisant _optionnalToCanonicNodesNumbers
1223                                                                                 /// Le traitement est identique à la version originelle s'il n'y a pas de numérotation optionnelle
1224         
1225                                                                                 //      if (_ptrMesh->_arePresentOptionnalNodesNumbers) 
1226                                                                                 //              {
1227                                                                                 //              for (int j=0; j<tmp_numberOfFaces; j++) for (int k=0; k<NumberOfNodeByFace; k++)
1228                                                                                 //                      constituentArray[j*NumberOfNodeByFace+k]=_ptrMesh->_optionnalToCanonicNodesNumbers[tmp_constituentArray[j*(NumberOfNodeByFace+1)+k]] ;
1229                                                                                 //              }
1230                                                                                 //      else
1231                                                                                 //              {
1232                                                                                 //              for (int j=0; j<tmp_numberOfFaces; j++) for (int k=0; k<NumberOfNodeByFace; k++)
1233                                                                                 //                      constituentArray[j*NumberOfNodeByFace+k]=tmp_constituentArray[j*(NumberOfNodeByFace+1)+k] ;
1234                                                                                 //              }
1235         
1236                                                                                 //////////////////////////////////////////////////////////////////////////////////////
1237           
1238                                                                                 delete[] tmp_constituentArray;
1239                                                                 }
1240         
1241                                                         constituent->_nodal = new MEDSKYLINEARRAY(constituent->_count[constituent->_numberOfTypes]-1,
1242                                                                                                                                                                                                                                 size,
1243                                                                                                                                                                                                                                 NodalIndex,
1244                                                                                                                                                                                                                                 NodalValue) ;
1245                                                         delete[] NodalIndex ;
1246                                                         delete[] NodalValue ;
1247
1248
1249                                                         Connectivity->_constituent = constituent ;
1250                                                 }
1251
1252                                         delete[] tmpFaceCount;
1253
1254
1255                                         // get Edge if any
1256                                         // ===============
1257                                         if (numberOfEdgesTypes!=0) 
1258                                                 {
1259                                                         CONNECTIVITY * constituent = new CONNECTIVITY(numberOfEdgesTypes,MED_EDGE) ;
1260                                                         constituent->_entityDimension = 1 ;
1261                                                         constituent->_count[0]=1 ;
1262
1263                                                         int size = 0 ; 
1264                                                         int typeNumber=1 ;
1265                                                         // if you declare a variable <i> in two <for> initialization statement, 
1266                                                         // compiler gcc2.95.3 says nothing but there are two <i> variables in the same block 
1267                                                         //and the value you get in the common block seems to be the value of the first variable !
1268                                                         int i; 
1269
1270                                                         for ( i=1; i<MED_NBR_GEOMETRIE_MAILLE; i++)  
1271                                                                 { // no point1 cell type (?)
1272                                                                         if (tmpEdgeCount[i]>0) 
1273                                                                                 {
1274             
1275                                                                                         constituent->_count[typeNumber]=constituent->_count[typeNumber-1]+tmpEdgeCount[i];
1276                                                                                         CELLMODEL t( (MED_EN::medGeometryElement) MED_MESH_DRIVER22::all_cell_type[i]) ;
1277                                                                                         constituent->_type[typeNumber-1]=t ;
1278             
1279                                                                                         constituent->_geometricTypes[typeNumber-1]=( MED_EN::medGeometryElement) MED_MESH_DRIVER22::all_cell_type[i] ;
1280             
1281                                                                                         size+=tmpEdgeCount[i]*((MED_MESH_DRIVER22::all_cell_type[i])%100) ;
1282                                                                                         typeNumber++;
1283                                                                                 }
1284                                                                 }
1285         
1286                                                         // Creation of the MEDSKYLINEARRAY
1287                                                         //constituent->_nodal = new MEDSKYLINEARRAY(constituent->_count[constituent->_numberOfTypes]-1,size) ; 
1288                                                         //int * NodalIndex = constituent->_nodal->getIndex() ;
1289                                                         int * NodalValue = new int[size] ;
1290                                                         int * NodalIndex = new int[constituent->_count[constituent->_numberOfTypes]] ;
1291                                                         NodalIndex[0]=1 ;
1292         
1293                                                         // Fill the MEDSKYLINEARRAY by reading the MED file.
1294                                                         for ( i=0; i<constituent->_numberOfTypes; i++) 
1295                                                                 {
1296                                                                         med_2_3::med_geometrie_element med_type = (med_2_3::med_geometrie_element) constituent->_type[i].getType() ;
1297
1298                                                                         int NumberOfNodeByEdge = constituent->_type[i].getNumberOfNodes() ;
1299           
1300                                                                         // initialise index
1301                                                                         for (int j=constituent->_count[i]; j<constituent->_count[i+1];j++)
1302                                                                                 NodalIndex[j]=NodalIndex[j-1]+NumberOfNodeByEdge ; 
1303           
1304                                                                         int tmp_numberOfEdges = constituent->_count[i+1]-constituent->_count[i] ;
1305                                                                         // Il faut ajouter 1 pour le zero a la lecture !!!
1306
1307                                                                         // ATTENTION UNIQUEMENT POUR MED < 2.2.x
1308                                                                         //CCRT            int * tmp_constituentArray = NULL;
1309                                                                         med_2_3::med_int * tmp_constituentArray = NULL;
1310
1311                                                                         MESSAGE_MED(LOC << "Med file version used here " << major << " " << minor << " " << release);
1312
1313                                                                         if ((major == 2) && (minor <= 1))
1314                                                                                 //CCRT              tmp_constituentArray = new int[(NumberOfNodeByEdge+1)*tmp_numberOfEdges] ;
1315                                                                                 tmp_constituentArray = new med_2_3::med_int[(NumberOfNodeByEdge+1)*tmp_numberOfEdges] ;
1316                                                                         else if ((major == 2) && (minor >= 2))
1317                                                                                 {
1318                                                                                         //CCRT                tmp_constituentArray = new int[NumberOfNodeByEdge*tmp_numberOfEdges] ;
1319                                                                                         tmp_constituentArray = new med_2_3::med_int[NumberOfNodeByEdge*tmp_numberOfEdges] ;
1320                                                                                         MESSAGE_MED(LOC<<": WE ARE USING MED2.2 so there is no +1 for calculating the size of  tmp_constituentArray !") ;
1321                                                                                 }
1322           
1323                                                                         int err=MEDconnLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
1324                                                                                                                                                         spaceDimension,tmp_constituentArray,
1325                                                                                                                                                         med_2_3::MED_FULL_INTERLACE,NULL,0,med_2_3::MED_MAILLE,med_type,med_2_3::MED_NOD);
1326                                                                         if ( err != MED_VALID) 
1327                                                                                 {
1328                                                                                         MESSAGE_MED(LOC<<": MEDconnLire returns "<<err) ;
1329                                                                                         delete constituent ;
1330                                                                                         delete[] tmp_constituentArray;
1331                                                                                         delete[] tmpEdgeCount;
1332                                                                                         return MED_ERROR ;
1333                                                                                 }
1334
1335                                                                         int * constituentArray = NodalValue + NodalIndex[constituent->_count[i]-1]-1 ;
1336           
1337                                                                         // version originale sans prise en compte des numéros optionnels       
1338                                                                         //
1339                                                                         int multi = 0; // quand est-ce que multi vaut 1 ?? en MED-fichier < 2.2 ??
1340                                                                         MESSAGE_MED(LOC << "Med file version used here " << major << " " << minor << " " << release);
1341
1342                                                                         if ((major == 2) && (minor <= 1))
1343                                                                                 for (int j=0; j<tmp_numberOfEdges; j++)
1344                                                                                         for (int k=0; k<NumberOfNodeByEdge; k++)
1345                                                                                                 constituentArray[j*NumberOfNodeByEdge+k]=tmp_constituentArray[j*(NumberOfNodeByEdge+multi)+k] ;
1346                                                                         else if ((major == 2) && (minor >= 2))
1347                                                                                 for (int j=0; j<tmp_numberOfEdges; j++)
1348                                                                                         for (int k=0; k<NumberOfNodeByEdge; k++)
1349                                                                                                 constituentArray[j*NumberOfNodeByEdge+k]=tmp_constituentArray[j*(NumberOfNodeByEdge)+k] ;
1350
1351                                                                         //////////////////////////////////////////////////////////////////////////////////////
1352                                                                         ///  Modification pour prise en compte de la numérotation optionnelle des noeuds   ///
1353                                                                                 //////////////////////////////////////////////////////////////////////////////////////
1354                                                                                 ///
1355                                                                                 /// Rénumérote le tableau temporaire tmp_constituentArray en utilisant _optionnalToCanonicNodesNumbers
1356                                                                                 /// Le traitement est identique à la version originelle s'il n'y a pas de numérotation optionnelle
1357         
1358                                                                                 //      if (_ptrMesh->_arePresentOptionnalNodesNumbers) 
1359                                                                                 //              {
1360                                                                                 //              for (int j=0; j<tmp_numberOfEdges; j++) for (int k=0; k<NumberOfNodeByEdge; k++)
1361                                                                                 //                      constituentArray[j*NumberOfNodeByEdge+k]=_ptrMesh->_optionnalToCanonicNodesNumbers[tmp_constituentArray[j*(NumberOfNodeByEdge+1)+k]] ;
1362                                                                                 //              }
1363                                                                                 //      else
1364                                                                                 //              {
1365                                                                                 //              for (int j=0; j<tmp_numberOfEdges; j++) for (int k=0; k<NumberOfNodeByEdge; k++)
1366                                                                                 //                      constituentArray[j*NumberOfNodeByEdge+k]=tmp_constituentArray[j*(NumberOfNodeByEdge+1)+k] ;
1367                                                                                 //              }
1368         
1369                                                                                 //////////////////////////////////////////////////////////////////////////////////////
1370
1371                                                                                 delete[] tmp_constituentArray;
1372                                                                 }
1373
1374                                                         constituent->_nodal = new MEDSKYLINEARRAY(constituent->_count[constituent->_numberOfTypes]-1,
1375                                                                                                                                                                                                                                 size,
1376                                                                                                                                                                                                                                 NodalIndex,
1377                                                                                                                                                                                                                                 NodalValue) ;
1378
1379                                                         delete[] NodalIndex ;
1380                                                         delete[] NodalValue ;
1381
1382                                                         if (Connectivity->_entityDimension == 3) 
1383                                                                 {
1384                                                                         if (Connectivity->_constituent==NULL)
1385                                                                                 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Edges are defined but there are no Faces !"));
1386                                                                         Connectivity->_constituent->_constituent = constituent ;
1387                                                                 } else 
1388                                                                 Connectivity->_constituent = constituent ;
1389                                                 }
1390                 
1391                                         delete[] tmpEdgeCount; 
1392                 
1393     
1394                                 } // end classic geometric types
1395       else
1396         {//Polyg/Polh only...
1397           delete [] Connectivity->_count;
1398           Connectivity->_count=new int[1];
1399           Connectivity->_count[0]=1;
1400         }
1401       delete[] tmp_cells_count;
1402                         
1403       int NumberOfPolygons  = MEDnEntMaa(_medIdt,
1404                                                                                                                                                                  const_cast <char *> (_ptrMesh->_name.c_str()),
1405                                                                                                                                                                  med_2_3::MED_CONN,
1406                                                                                                                                                                  med_2_3::MED_MAILLE,
1407                                                                                                                                                                  med_2_3::MED_POLYGONE,
1408                                                                                                                                                                  med_2_3::MED_NOD);
1409                         
1410                         // Correction to permit the loading of mesh dimensionned at 2 even
1411                         // if it has only MED_POLYGON elements
1412                         
1413                         if (NumberOfPolygons > 0)
1414         {
1415           if (Connectivity->_entityDimension < 2) Connectivity->_entityDimension = 2;
1416         }
1417                         
1418                         if (NumberOfPolygons > 0)
1419         {
1420           // By consequence this exception will never occur
1421           if (Connectivity->_entityDimension == 1)
1422             throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"In a 2D mesh, polygons need at least one 2D cell of a classic geometric type !"));
1423           med_2_3::med_int ConnectivitySize;
1424           med_2_3::med_err err1 = MEDpolygoneInfo(_medIdt,
1425                                                   const_cast <char *> (_ptrMesh->_name.c_str()),
1426                                                   med_2_3::MED_MAILLE,
1427                                                   med_2_3::MED_NOD,
1428                                                   &ConnectivitySize);
1429           if (err1 != MED_VALID)
1430                                                 {
1431                                                         MESSAGE_MED(LOC<<": MEDpolygoneInfo returns "<<err1);
1432                                                         return MED_ERROR;
1433                                                 }
1434                                         
1435           med_2_3::med_int* PolygonsConnectivity = new med_2_3::med_int[ConnectivitySize];
1436           med_2_3::med_int* PolygonsConnectivityIndex = new med_2_3::med_int[NumberOfPolygons+1];
1437                                         
1438           med_2_3::med_err err2 = MEDpolygoneConnLire(_medIdt,
1439                                                       const_cast <char *> (_ptrMesh->_name.c_str()),
1440                                                       PolygonsConnectivityIndex,
1441                                                       NumberOfPolygons+1,
1442                                                       PolygonsConnectivity,
1443                                                       med_2_3::MED_MAILLE,
1444                                                       med_2_3::MED_NOD);
1445           if (err2 != MED_VALID)
1446                                                 {
1447                                                         MESSAGE_MED(LOC<<": MEDpolygoneConnLire returns "<<err2);
1448                                                         return MED_ERROR;
1449                                                 }
1450
1451           if (Connectivity->_entityDimension == 2) // 2D mesh : polygons in Connectivity
1452                                                 {
1453                                                         //CCRT
1454 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
1455                                                         int* tmp_PolygonsConnectivity = new int[ConnectivitySize];
1456                                                         int i ;
1457                                                         for ( i = 0 ; i < ConnectivitySize ; i++ )
1458                                                                 tmp_PolygonsConnectivity[i] = PolygonsConnectivity[i] ;
1459
1460                                                         int* tmp_PolygonsConnectivityIndex = new int[NumberOfPolygons+1];
1461                                                         for ( i = 0 ; i < NumberOfPolygons+1 ; i++ )
1462                                                                 tmp_PolygonsConnectivityIndex[i] = PolygonsConnectivityIndex[i] ;
1463
1464                                                         Connectivity->setPolygonsConnectivity
1465                                                                 (MED_NODAL, (medEntityMesh) Entity, tmp_PolygonsConnectivity,
1466                                                                  tmp_PolygonsConnectivityIndex, ConnectivitySize, NumberOfPolygons);
1467
1468                                                         delete [] tmp_PolygonsConnectivity ;
1469                                                         delete [] tmp_PolygonsConnectivityIndex ;
1470 #else
1471                                                         Connectivity->setPolygonsConnectivity
1472                                                                 (MED_NODAL, (medEntityMesh) Entity, PolygonsConnectivity,
1473                                                                  PolygonsConnectivityIndex, ConnectivitySize, NumberOfPolygons);
1474 #endif
1475                                                 }
1476           else if (Connectivity->_entityDimension == 3)
1477                                                 {
1478                                                         if (Connectivity->_constituent == NULL) // 3D mesh : polygons in Connectivity->_constituent
1479                                                                 Connectivity->_constituent = new CONNECTIVITY(MED_FACE);
1480                                                         //CCRT
1481 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
1482                                                         int* tmp_PolygonsConnectivity = new int[ConnectivitySize];
1483                                                         int i ;
1484                                                         for ( i = 0 ; i < ConnectivitySize ; i++ )
1485                                                                 tmp_PolygonsConnectivity[i] = PolygonsConnectivity[i] ;
1486
1487                                                         int* tmp_PolygonsConnectivityIndex = new int[NumberOfPolygons+1];
1488                                                         for ( i = 0 ; i < NumberOfPolygons+1 ; i++ )
1489                                                                 tmp_PolygonsConnectivityIndex[i] = PolygonsConnectivityIndex[i] ;
1490
1491                                                         Connectivity->_constituent->setPolygonsConnectivity
1492                                                                 (MED_NODAL, MED_FACE, tmp_PolygonsConnectivity,
1493                                                                  tmp_PolygonsConnectivityIndex, ConnectivitySize, NumberOfPolygons);
1494
1495                                                         delete [] tmp_PolygonsConnectivity ;
1496                                                         delete [] tmp_PolygonsConnectivityIndex ;
1497 #else
1498                                                         Connectivity->_constituent->setPolygonsConnectivity
1499                                                                 (MED_NODAL, MED_FACE, PolygonsConnectivity,
1500                                                                  PolygonsConnectivityIndex, ConnectivitySize, NumberOfPolygons);
1501 #endif
1502                                                 }
1503
1504           delete[] PolygonsConnectivity;
1505           delete[] PolygonsConnectivityIndex;
1506         } // end polygons
1507                         
1508                         
1509       // Lecture des polyedres MED_CELL
1510       med_int NumberOfPolyhedron = MEDnEntMaa(_medIdt,
1511                                                                                                                                                                                         const_cast <char *> (_ptrMesh->_name.c_str()),
1512                                                                                                                                                                                         med_2_3::MED_CONN,
1513                                                                                                                                                                                         Entity,
1514                                                                                                                                                                                         med_2_3::MED_POLYEDRE,
1515                                                                                                                                                                                         med_2_3::MED_NOD);
1516
1517       // Correction to permit the loading of mesh dimensionned at 3 even
1518       // if it has only MED_POLYEDRE elements
1519
1520       if (NumberOfPolyhedron > 0)
1521                                 {
1522                                         Connectivity->_entityDimension = 3;
1523                                 }
1524
1525       if (NumberOfPolyhedron > 0)
1526                                 {
1527                                         // By consequence this exception will never occur
1528                                         if (Connectivity->_entityDimension == 2 || Connectivity->_entityDimension == 1)
1529                                                 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"In a 3D mesh, polyhedron need at least one 3D cell of a classic geometric type !"));
1530                                         med_2_3::med_int FacesIndexSize, NumberOfNodes, NumberOfFaces;
1531                                         med_2_3::med_err err3 = MEDpolyedreInfo(_medIdt,
1532                                                                                                                                                                                                         const_cast <char *> (_ptrMesh->_name.c_str()),
1533                                                                                                                                                                                                         med_2_3::MED_NOD,
1534                                                                                                                                                                                                         &FacesIndexSize,
1535                                                                                                                                                                                                         &NumberOfNodes);
1536                                         NumberOfFaces = FacesIndexSize-1;
1537                                         if (err3 != MED_VALID)
1538                                                 {
1539                                                         MESSAGE_MED(LOC<<": MEDpolyhedreInfo returns "<<err3);
1540                                                         return MED_ERROR;
1541                                                 }
1542       
1543                                         med_2_3::med_int* Nodes = new med_2_3::med_int[NumberOfNodes];
1544                                         med_2_3::med_int* FacesIndex = new med_2_3::med_int[NumberOfFaces+1];
1545                                         med_2_3::med_int* PolyhedronIndex = new med_2_3::med_int[NumberOfPolyhedron+1];
1546           
1547                                         med_2_3::med_err err4 = MEDpolyedreConnLire(_medIdt,
1548                                                                                                                                                                                                                         const_cast <char *> (_ptrMesh->_name.c_str()),
1549                                                                                                                                                                                                                         PolyhedronIndex,
1550                                                                                                                                                                                                                         NumberOfPolyhedron+1,
1551                                                                                                                                                                                                                         FacesIndex,
1552                                                                                                                                                                                                                         NumberOfFaces+1,
1553                                                                                                                                                                                                                         Nodes,
1554                                                                                                                                                                                                                         med_2_3::MED_NOD);
1555                                         if (err4 != MED_VALID)
1556                                                 {
1557                                                         MESSAGE_MED(LOC<<": MEDpolyedreConnLire returns "<<err4);
1558                                                         return MED_ERROR;
1559                                                 }
1560       
1561                                         //CCRT
1562 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
1563                                         int* tmp_Nodes = new int[NumberOfNodes];
1564           int i ;
1565           for ( i = 0 ; i < NumberOfNodes ; i++ )
1566                                                 tmp_Nodes[i] = Nodes[i] ;
1567                                         int* tmp_FacesIndex = new int[NumberOfFaces+1];
1568           for ( i = 0 ; i < NumberOfFaces+1 ; i++ )
1569                                                 tmp_FacesIndex[i] = FacesIndex[i] ;
1570                                         int* tmp_PolyhedronIndex = new int[NumberOfPolyhedron+1];
1571           for ( i = 0 ; i < NumberOfPolyhedron+1 ; i++ )
1572                                                 tmp_PolyhedronIndex[i] = PolyhedronIndex[i] ;
1573                                         Connectivity->setPolyhedronConnectivity(MED_NODAL,tmp_Nodes,tmp_PolyhedronIndex,NumberOfNodes,NumberOfPolyhedron,tmp_FacesIndex,NumberOfFaces);
1574                                         delete[] tmp_Nodes;
1575                                         delete[] tmp_FacesIndex;
1576                                         delete[] tmp_PolyhedronIndex;
1577 #else
1578                                         Connectivity->setPolyhedronConnectivity(MED_NODAL,Nodes,PolyhedronIndex,NumberOfNodes,NumberOfPolyhedron,FacesIndex,NumberOfFaces);
1579 #endif
1580           
1581                                         delete[] Nodes;
1582                                         delete[] FacesIndex;
1583                                         delete[] PolyhedronIndex;
1584                                 } // end polyhedron
1585
1586
1587
1588       // If there is no nodal connectivity, we return MED_ERROR !
1589       if (Connectivity->_numberOfTypes == 0 && NumberOfPolygons == 0 && NumberOfPolyhedron == 0)
1590                                 return MED_ERROR;
1591       else
1592                                 return MED_VALID;
1593
1594     }
1595   return MED_ERROR;
1596 }
1597
1598 int  MED_MESH_RDONLY_DRIVER22::getFAMILY() 
1599 {
1600   const char * LOC = "MED_MESH_RDONLY_DRIVER22::getFAMILY() : " ;
1601   BEGIN_OF_MED(LOC);
1602
1603   if (_status==MED_OPENED)
1604     {
1605       int err = 0 ;
1606
1607       int * MEDArrayNodeFamily = NULL ;
1608       int ** MEDArrayCellFamily = NULL ;
1609       int ** MEDArrayFaceFamily = NULL ;
1610       int ** MEDArrayEdgeFamily = NULL ;
1611
1612     // NODE :
1613       MEDArrayNodeFamily = new int[_ptrMesh->getNumberOfNodes()] ;
1614
1615       err = getNodesFamiliesNumber(MEDArrayNodeFamily) ;
1616       // error only if (_status!=MED_OPENED), other case exeception !
1617       // CELL
1618
1619       MESSAGE_MED(LOC << "error returned from getNodesFamiliesNumber " << err);
1620
1621       MEDArrayCellFamily = new int* [_ptrMesh->getNumberOfTypesWithPoly(MED_CELL)] ;
1622       // ET SI IL N'Y A PAS DE CELLS ?
1623
1624       medGeometryElement * myTypes = _ptrMesh->getTypesWithPoly(MED_CELL);
1625       for (int i=0;i<_ptrMesh->getNumberOfTypesWithPoly(MED_CELL);i++)
1626         MEDArrayCellFamily[i] = new
1627           int[_ptrMesh->getNumberOfElementsWithPoly(MED_CELL,myTypes[i])] ;
1628
1629       // assure connectivety exists in case of GRID
1630       _ptrMesh->getConnectivityptr(); //PAL14113
1631
1632       err = getCellsFamiliesNumber(MEDArrayCellFamily,
1633                                    _ptrMesh->_connectivity,MED_CELL) ;
1634       delete [] myTypes;
1635
1636       MESSAGE_MED(LOC << "error returned from getCellsFamiliesNumber for Cells " << err);
1637
1638     if (_ptrMesh->_connectivity->_constituent != NULL)
1639       {
1640         if (_ptrMesh->_connectivity->_constituent->_entity == MED_EN::MED_FACE)
1641           {
1642             // FACE
1643             MEDArrayFaceFamily = new
1644               int* [_ptrMesh->getNumberOfTypesWithPoly(MED_FACE)] ;
1645
1646             myTypes = _ptrMesh->getTypesWithPoly(MED_FACE);
1647             for (int i=0;i<_ptrMesh->getNumberOfTypesWithPoly(MED_FACE);i++) {
1648               int nbOfElements = _ptrMesh->_connectivity->_constituent->getNumberOfElementsWithPoly(MED_FACE,myTypes[i]);
1649               MEDArrayFaceFamily[i] = new int[nbOfElements];
1650             }
1651
1652             err =
1653               getCellsFamiliesNumber(MEDArrayFaceFamily,
1654                                      _ptrMesh->_connectivity->_constituent,MED_FACE) ;
1655             delete [] myTypes;
1656             MESSAGE_MED(LOC << "error returned from getCellsFamiliesNumber for Faces " << err);
1657           }
1658         else
1659           {
1660             // EDGE in 2D
1661             MEDArrayEdgeFamily = new
1662               int* [_ptrMesh->getNumberOfTypes(MED_EDGE)] ;
1663
1664             const medGeometryElement *myTypes2 = _ptrMesh->getTypes(MED_EDGE);
1665             for (int i=0;i<_ptrMesh->getNumberOfTypes(MED_EDGE);i++)
1666               MEDArrayEdgeFamily[i] = new
1667                 int[_ptrMesh->getNumberOfElements(MED_EDGE,myTypes2[i])] ;
1668
1669             err =
1670               getCellsFamiliesNumber(MEDArrayEdgeFamily,
1671                                      _ptrMesh->_connectivity->_constituent,MED_EDGE) ;
1672           
1673             MESSAGE_MED(LOC << "error returned from getCellsFamiliesNumber for Edges in 2D " << err);
1674           }
1675         // EDGE in 3D
1676         if (_ptrMesh->_connectivity->_constituent->_constituent != NULL)
1677           {
1678             MEDArrayEdgeFamily = new
1679               int* [_ptrMesh->getNumberOfTypes(MED_EDGE)] ;
1680
1681             const medGeometryElement *myTypes2 = _ptrMesh->getTypes(MED_EDGE);
1682             for (int i=0;i<_ptrMesh->getNumberOfTypes(MED_EDGE);i++) {
1683               int nbOfElements = _ptrMesh->_connectivity->_constituent->_constituent->getNumberOfElementsWithPoly(MED_EDGE,myTypes2[i]);
1684               MEDArrayEdgeFamily[i] = new int[nbOfElements] ;
1685             }
1686
1687             err =
1688               getCellsFamiliesNumber(MEDArrayEdgeFamily,
1689                                      _ptrMesh->_connectivity->_constituent->_constituent,MED_EDGE);
1690             // we are in 3D !
1691         
1692             MESSAGE_MED(LOC << "error returned from getCellsFamiliesNumber for Edges in 3D " << err);
1693
1694           }
1695       }
1696
1697     int NumberOfFamilies = med_2_3::MEDnFam(_medIdt, const_cast <char *>
1698                                            (_meshName.c_str())) ;
1699
1700     if ( NumberOfFamilies < 1 ) // at least family 0 must exist 
1701       throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"There is no FAMILY, FAMILY 0 must exists" ));
1702
1703     SCRUTE_MED(NumberOfFamilies);
1704
1705     vector<FAMILY*> &NodeFamilyVector = _ptrMesh->_familyNode ;
1706     vector<FAMILY*> &CellFamilyVector = _ptrMesh->_familyCell ;
1707     vector<FAMILY*> &FaceFamilyVector = _ptrMesh->_familyFace ;
1708     vector<FAMILY*> &EdgeFamilyVector = _ptrMesh->_familyEdge ;
1709
1710     int numberOfNodesFamilies = 0 ;
1711     int numberOfCellsFamilies = 0 ;
1712     int numberOfFacesFamilies = 0 ;
1713     int numberOfEdgesFamilies = 0 ;
1714
1715     for (int i=0;i<NumberOfFamilies;i++)
1716       {
1717 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
1718         med_2_3::med_int tmp_NumberOfAttributes = med_2_3::MEDnAttribut(_medIdt,
1719                                                                         const_cast <char *>(_meshName.c_str()),
1720                                                                         (i+1));
1721         med_2_3::med_int NumberOfAttributes = tmp_NumberOfAttributes ;
1722 #else
1723         int NumberOfAttributes = med_2_3::MEDnAttribut(_medIdt,
1724                                                       const_cast <char *>
1725                                                       (_meshName.c_str()),
1726                                                       (i+1));
1727 #endif
1728       
1729       if (NumberOfAttributes < 0) 
1730         throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER22::getFAMILY() : NumberOfAttributes" );
1731
1732 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
1733       med_2_3::med_int tmp_NumberOfGroups = med_2_3::MEDnGroupe(_medIdt, 
1734                                                                  const_cast <char *>(_meshName.c_str()),
1735                                                                 (i+1)) ;
1736       int NumberOfGroups = tmp_NumberOfGroups ;
1737 #else
1738       int NumberOfGroups = med_2_3::MEDnGroupe(_medIdt, 
1739                                                const_cast <char *>(_meshName.c_str()),
1740                                                (i+1)) ;
1741 #endif
1742
1743         if (NumberOfGroups < 0)
1744           throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER22::getFAMILY() : NumberOfGroups" );
1745       
1746         int FamilyIdentifier ;
1747         string FamilyName(MED_TAILLE_NOM,'\0');
1748         // 0020071: Crash of V4_1_4rc2 (of testMedMemGeneral.py)
1749         // Pb with Mistrat_import22.med: it's zero family has non-empty AttributesIdentifier's and
1750         // AttributesValues' but MEDnAttribut() returns 0 (0 is hardcoded for zero family).
1751         // So we allocate nothing but MEDfamInfo() reads file contents so overwritting
1752         // stranger's memory. Stupid solution: allocate more than MEDnAttribut()
1753         const int iSafe = 10;
1754         int *  AttributesIdentifier = new int[NumberOfAttributes+iSafe] ;
1755         int *  AttributesValues     = new int[NumberOfAttributes+iSafe] ;
1756         string AttributesDescription(MED_TAILLE_DESC*NumberOfAttributes,' ') ;
1757         string GroupsNames(MED_TAILLE_LNOM*NumberOfGroups+1,'\0') ;
1758 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
1759         med_2_3::med_int tmp_FamilyIdentifier ;
1760         med_2_3::med_int *  tmp_AttributesIdentifier = new med_2_3::med_int[NumberOfAttributes+iSafe] ;
1761         med_2_3::med_int *  tmp_AttributesValues     = new med_2_3::med_int[NumberOfAttributes+iSafe] ;
1762         err = med_2_3::MEDfamInfo(_medIdt,
1763                                   const_cast <char *>(_meshName.c_str()),
1764                                   (i+1),
1765                                   const_cast <char *>(FamilyName.c_str()), 
1766                                   &tmp_FamilyIdentifier,
1767                                   tmp_AttributesIdentifier,
1768                                   tmp_AttributesValues,
1769                                   const_cast <char *>(AttributesDescription.c_str()),
1770                                   &tmp_NumberOfAttributes, 
1771                                   const_cast <char *>(GroupsNames.c_str()),
1772                                   &tmp_NumberOfGroups);
1773         FamilyIdentifier = tmp_FamilyIdentifier ;
1774         int ii ;
1775         for ( ii = 0 ; ii < NumberOfAttributes ; ii++ ) {
1776            AttributesIdentifier[ii] = tmp_AttributesIdentifier[ii] ;
1777            AttributesValues[ii] = tmp_AttributesValues[ii] ;
1778         }
1779         NumberOfAttributes = tmp_NumberOfAttributes ;
1780         NumberOfGroups = tmp_NumberOfGroups ;
1781         delete [] tmp_AttributesIdentifier ;
1782         delete [] tmp_AttributesValues ;
1783 #else
1784         err = med_2_3::MEDfamInfo(_medIdt,const_cast <char *>
1785                                  (_meshName.c_str()),
1786                                  (i+1),const_cast <char *>
1787                                  (FamilyName.c_str()), &FamilyIdentifier,
1788                                  AttributesIdentifier,AttributesValues,
1789                                  const_cast <char *>
1790                                  (AttributesDescription.c_str()),
1791                                  &NumberOfAttributes, const_cast <char *>
1792                                  (GroupsNames.c_str()),&NumberOfGroups);
1793 #endif
1794
1795
1796         SCRUTE_MED(GroupsNames);
1797         SCRUTE_MED(FamilyName);
1798         SCRUTE_MED(err);
1799         SCRUTE_MED(i);
1800
1801       if (err != MED_VALID)
1802         throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER22::getFAMILY() : ERROR when get FAMILY informations" );
1803
1804         if (FamilyIdentifier != 0 )
1805           {
1806             FAMILY * Family = new FAMILY(_ptrMesh,FamilyIdentifier,FamilyName,
1807                                          NumberOfAttributes,
1808                                          AttributesIdentifier,
1809                                          AttributesValues,
1810                                          AttributesDescription,
1811                                          NumberOfGroups,GroupsNames,
1812                                          MEDArrayNodeFamily,
1813                                          MEDArrayCellFamily,
1814                                          MEDArrayFaceFamily,
1815                                          MEDArrayEdgeFamily) ;
1816
1817             // All good ?
1818             // if nothing found, delete Family
1819
1820                         /*! \todo TODO : once unit tests are ready, check that there is no side effect
1821                                 and let the driver read empty families by removing the if case of the
1822                                 few following lines */
1823
1824             if (Family->getNumberOfTypes() == 0)
1825               {
1826                 MESSAGE_MED(LOC<<"Nothing found for family "<<FamilyName<<
1827                         " : skip");
1828                 delete Family;
1829               }
1830             else
1831               switch (Family->getEntity())
1832                 {
1833                 case MED_EN::MED_NODE :
1834                   NodeFamilyVector.push_back(Family) ;
1835                   numberOfNodesFamilies++ ;
1836                   break ;
1837                 case MED_EN::MED_CELL :
1838                   CellFamilyVector.push_back(Family) ;
1839                   numberOfCellsFamilies++ ;
1840                   break ;
1841                 case MED_EN::MED_FACE :
1842                   FaceFamilyVector.push_back(Family) ;
1843                   numberOfFacesFamilies++ ;
1844                   break ;
1845                 case MED_EN::MED_EDGE :
1846                   EdgeFamilyVector.push_back(Family) ;
1847                   numberOfEdgesFamilies++ ;
1848                   break ;
1849                 }
1850             //  MESSAGE_MED(LOC << (*Family));
1851           }
1852
1853         delete [] AttributesIdentifier ;
1854         delete [] AttributesValues ;
1855       }
1856
1857     if (MEDArrayNodeFamily != NULL)
1858       delete[] MEDArrayNodeFamily ;
1859
1860     if (MEDArrayCellFamily != NULL)
1861       {
1862         for (int i=0; i<_ptrMesh->getNumberOfTypesWithPoly(MED_CELL); i++)
1863           delete[] MEDArrayCellFamily[i] ;
1864         delete[] MEDArrayCellFamily ;
1865       }
1866
1867     if (MEDArrayFaceFamily != NULL)
1868       {
1869         for (int i=0; i<_ptrMesh->getNumberOfTypesWithPoly(MED_FACE); i++)
1870           delete[] MEDArrayFaceFamily[i] ;
1871         delete[] MEDArrayFaceFamily ;
1872       }
1873
1874     if (MEDArrayEdgeFamily != NULL)
1875       {
1876         for (int i=0; i<_ptrMesh->getNumberOfTypesWithPoly(MED_EDGE); i++)
1877           delete[] MEDArrayEdgeFamily[i] ;
1878         delete[] MEDArrayEdgeFamily ;
1879       }
1880
1881   END_OF_MED(LOC);
1882     return MED_VALID ;
1883     }
1884
1885   return MED_ERROR;
1886 }
1887
1888 int  MED_MESH_RDONLY_DRIVER22::getNodesFamiliesNumber(int * MEDArrayNodeFamily)
1889 {
1890   const char * LOC = "MED_MESH_RDONLY_DRIVER22::getNodesFamiliesNumber() : " ;
1891
1892   BEGIN_OF_MED(LOC);
1893
1894   if (_status==MED_OPENED)
1895     {
1896     int err = 0 ;
1897
1898 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
1899       med_2_3::med_int * tmp_MEDArrayNodeFamily = new med_2_3::med_int[_ptrMesh->getNumberOfNodes()] ;
1900       err = MEDfamLire(_medIdt, const_cast <char *>
1901                        (_ptrMesh->_name.c_str()), tmp_MEDArrayNodeFamily,
1902                        _ptrMesh->getNumberOfNodes(), med_2_3::MED_NOEUD,
1903                        (med_2_3::med_geometrie_element) MED_NONE);
1904       int i ;
1905       for ( i = 0 ; i < _ptrMesh->getNumberOfNodes() ; i++ )
1906          MEDArrayNodeFamily[i] = tmp_MEDArrayNodeFamily[i] ;
1907 #else
1908       err = MEDfamLire(_medIdt, const_cast <char *>
1909                        (_ptrMesh->_name.c_str()), MEDArrayNodeFamily,
1910                        _ptrMesh->getNumberOfNodes(), med_2_3::MED_NOEUD,
1911                        (med_2_3::med_geometrie_element) MED_NONE);
1912 #endif
1913
1914       if ( err != MED_VALID)
1915         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "There is no family for the |"<< _ptrMesh->getNumberOfNodes() << "| nodes in mesh |" << _ptrMesh->_name.c_str() << "|"));
1916
1917   END_OF_MED(LOC);
1918       return MED_VALID;
1919     }
1920
1921   return MED_ERROR;
1922 }
1923
1924 int  MED_MESH_RDONLY_DRIVER22::getCellsFamiliesNumber(int **MEDArrayFamily,
1925                                                       CONNECTIVITY *Connectivity,
1926                                                       MED_EN::medEntityMesh entity) 
1927 {
1928   const char * LOC = "MED_MESH_RDONLY_DRIVER22::getCellsFamiliesNumber " ;
1929
1930   BEGIN_OF_MED(LOC);
1931
1932   if (_status==MED_OPENED)
1933     {
1934     int i, err = 0 ;
1935     MED_EN::medGeometryElement *types=Connectivity->getGeometricTypesWithPoly(Connectivity->_entity);
1936     for (i=0;i<Connectivity->getNumberOfTypesWithPoly(Connectivity->_entity);i++)
1937       {
1938         int NumberOfCell=Connectivity->getNumberOfElementsWithPoly(Connectivity->_entity,types[i]);
1939 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
1940         med_2_3::med_int * tmp_MEDArrayFamily = new med_2_3::med_int[NumberOfCell] ;
1941         err=MEDfamLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
1942                        tmp_MEDArrayFamily,NumberOfCell,
1943                        (med_2_3::med_entite_maillage) Connectivity->_entity,
1944                        (med_2_3::med_geometrie_element)types[i]);
1945         if (err != MED_VALID
1946             && !_ptrMesh->getIsAGrid()) // it's normal for a grid (PAL14113)
1947           {
1948             err=MEDfamLire(_medIdt,const_cast <char *>
1949                            (_ptrMesh->_name.c_str()),
1950                            tmp_MEDArrayFamily,NumberOfCell,
1951                            med_2_3::MED_MAILLE,
1952                            (med_2_3::med_geometrie_element)types[i]);
1953             if (err != MED_VALID )
1954               throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Family not found for entity "<<Connectivity->_entity<<" and geometric type "<<types[i]));
1955           }
1956         if (err == MED_VALID) {
1957           int ii ;
1958           for ( ii = 0 ; ii < NumberOfCell ; ii++ )
1959             MEDArrayFamily[i][ii] = tmp_MEDArrayFamily[ii] ;
1960         }
1961         delete [] tmp_MEDArrayFamily ;
1962 #else
1963         err=MEDfamLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
1964                        MEDArrayFamily[i],NumberOfCell,
1965                        (med_2_3::med_entite_maillage) Connectivity->_entity,
1966                        (med_2_3::med_geometrie_element)types[i]);
1967         if (err != MED_VALID
1968             && !_ptrMesh->getIsAGrid() ) // it's normal for a grid (PAL14113)
1969         {
1970             err=MEDfamLire(_medIdt,const_cast <char *>
1971                            (_ptrMesh->_name.c_str()),
1972                            MEDArrayFamily[i],NumberOfCell,
1973                            med_2_3::MED_MAILLE,
1974                            (med_2_3::med_geometrie_element)types[i]);
1975             if (err != MED_VALID)
1976               throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Family not found for entity "<<Connectivity->_entity<<" and geometric type "<<types[i]));
1977           }
1978 #endif
1979       }
1980     delete [] types;
1981     return err ? MED_INVALID : MED_VALID;
1982     }
1983   return MED_ERROR;
1984 }
1985
1986 /*--------------------- WRONLY PART -------------------------------*/
1987
1988 MED_MESH_WRONLY_DRIVER22::MED_MESH_WRONLY_DRIVER22()
1989 {
1990   this->GENDRIVER::_accessMode = MED_EN::WRONLY;
1991 }
1992   
1993 MED_MESH_WRONLY_DRIVER22::MED_MESH_WRONLY_DRIVER22(const string & fileName,
1994                                                                                                                                                                                                          MESH * ptrMesh, 
1995                                                                                                                                                                                                          MED_EN::med_mode_acces access):
1996   MED_MESH_DRIVER22(fileName,ptrMesh,access),IMED_MESH_WRONLY_DRIVER(fileName,ptrMesh),MED_MESH_DRIVER(fileName,ptrMesh,access)
1997 {
1998   MESSAGE_MED("MED_MESH_WRONLY_DRIVER22::MED_MESH_WRONLY_DRIVER22(const string & fileName, MESH * ptrMesh) has been created");
1999 }
2000
2001 MED_MESH_WRONLY_DRIVER22::MED_MESH_WRONLY_DRIVER22(const MED_MESH_WRONLY_DRIVER22 & driver):
2002   IMED_MESH_WRONLY_DRIVER(driver),MED_MESH_DRIVER22(driver),MED_MESH_DRIVER(driver)
2003 {
2004
2005 }
2006
2007 MED_MESH_WRONLY_DRIVER22::~MED_MESH_WRONLY_DRIVER22()
2008 {
2009   //MESSAGE_MED("MED_MESH_WRONLY_DRIVER22::MED_MESH_WRONLY_DRIVER22(const string & fileName, MESH * ptrMesh) has been destroyed");
2010  
2011 }
2012
2013 GENDRIVER * MED_MESH_WRONLY_DRIVER22::copy(void) const
2014 {
2015   return new MED_MESH_WRONLY_DRIVER22(*this);
2016 }
2017
2018 void MED_MESH_WRONLY_DRIVER22::write(void) const
2019
2020   
2021   if (_ptrMesh==NULL || _ptrMesh->getCoordinateptr()==NULL)
2022     throw MEDEXCEPTION("Error trying to write an empty mesh");
2023
2024   const char * LOC = "void MED_MESH_WRONLY_DRIVER22::write(void) const : ";
2025   BEGIN_OF_MED(LOC);
2026
2027   // we must first create mesh !!
2028   MESSAGE_MED(LOC << "MeshName : |" << _meshName << "| FileName : |"<<_fileName<<"| MedIdt : | "<< _medIdt << "|");
2029
2030   if (_status!=MED_OPENED)
2031     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "File "<<_fileName<<" is not open. Open it before write !"));
2032
2033  
2034   string fieldName;
2035   if ( ( _meshName.empty() ) && ( _ptrMesh->_name.empty() )    )
2036     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)
2037                                  <<" neither <meshName> is set in driver nor in object MESH.")) ;
2038
2039   // If _meshName is not set in driver, try to use _ptrmesh->_meshName
2040   if ( ( _meshName.empty() ) && ( !_ptrMesh->_name.empty() )    )
2041     _meshName = healName(_ptrMesh->_name );
2042
2043   if ( _meshName.size() > MED_TAILLE_NOM )
2044     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)
2045                                  <<" <meshName> size in object driver MESH is > MED_TAILLE_NOM ."));
2046
2047
2048   if (_ptrMesh->getIsAGrid())
2049   {
2050     if ( writeGRID() != MED_VALID )
2051       throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeGRID()"  )) ;
2052   }
2053   else
2054   {
2055     if (writeCoordinates()!=MED_VALID)
2056       throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeCoordinates()"  )) ;
2057
2058     if (writeConnectivities(MED_EN::MED_CELL)!=MED_VALID)
2059       throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeConnectivities(MED_CELL)"  )) ;
2060     if (writeConnectivities(MED_EN::MED_FACE)!=MED_VALID)
2061       throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeConnectivities(MED_FACE)"  )) ;
2062     if (writeConnectivities(MED_EN::MED_EDGE)!=MED_VALID)
2063       throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeConnectivities(MED_EDGE)"  )) ;
2064   }
2065
2066   if (writeFamilyNumbers() !=MED_VALID)
2067     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilyNumbers()"  )) ;
2068   
2069
2070   // well we must first write zero family :
2071   if (_status==MED_OPENED) {
2072     int err ;
2073     // test if the family already exists (HDF trick waiting a MED evolution to be replaced)
2074     string dataGroupFam = "/ENS_MAA/"+_meshName+"/FAS/FAMILLE_ZERO/";  
2075     MESSAGE_MED("|"<<dataGroupFam<<"|");
2076     err =med_2_3::_MEDdatagroupOuvrir(_medIdt,const_cast <char *> (dataGroupFam.c_str()) );
2077     if ( err < MED_VALID ) {
2078       SCRUTE_MED(err);
2079
2080       char familyName[MED_TAILLE_NOM+1];
2081       //      strcpy(familyName,"FAMILLE_ZERO");
2082       err = med_2_3::MEDfamCr( _medIdt,
2083                               const_cast <char *> ( _meshName.c_str() ),
2084                               familyName, 0,
2085 //CCRT                        (int*)NULL, (int*)NULL, (char*)NULL, 0,
2086                               (med_2_3::med_int*)NULL, (med_2_3::med_int*)NULL, (char*)NULL, 0,
2087                               (char*)NULL, 0);
2088
2089       SCRUTE_MED(familyName);
2090       
2091       if ( err != MED_VALID) 
2092         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't create family |FAMILLE_ZERO| with identifier |0| groups names || and  attributes descriptions ||")) ;
2093     }
2094     else
2095       med_2_3::_MEDdatagroupFermer(_medIdt);
2096      
2097   }
2098
2099   MESSAGE_MED(LOC<<"writeFamilies(_ptrMesh->_familyNode)");
2100   if (writeFamilies(_ptrMesh->_familyNode) !=MED_VALID)
2101     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilies(_ptrMesh->_familyNode)"  )) ;
2102
2103   MESSAGE_MED(LOC<<"writeFamilies(_ptrMesh->_familyCell)");
2104   if (writeFamilies(_ptrMesh->_familyCell) !=MED_VALID)
2105     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilies(_ptrMesh->_familyCell)"  )) ;
2106
2107   MESSAGE_MED(LOC<<"writeFamilies(_ptrMesh->_familyFace)");
2108   if (writeFamilies(_ptrMesh->_familyFace) !=MED_VALID)
2109     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilies(_ptrMesh->_familyFace)"  )) ;
2110
2111   MESSAGE_MED(LOC<<"writeFamilies(_ptrMesh->_familyEdge)");
2112   if (writeFamilies(_ptrMesh->_familyEdge) !=MED_VALID)
2113     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilies(_ptrMesh->_familyEdge)"  )) ;
2114        
2115   END_OF_MED(LOC);
2116
2117
2118 //=======================================================================
2119 //function : writeGRID
2120 //purpose  : 
2121 //=======================================================================
2122
2123 int MED_MESH_WRONLY_DRIVER22::writeGRID() const
2124 {
2125   const char * LOC = "MED_MESH_WRONLY_DRIVER22::writeGRID() : " ;
2126   BEGIN_OF_MED(LOC);
2127   
2128   if (_status!=MED_OPENED)
2129   {
2130     MESSAGE_MED (LOC<<" Not open !!!");
2131     return MED_ERROR;
2132   }
2133   GRID * ptrGrid = (GRID*) _ptrMesh;
2134   
2135   med_2_3::med_err err = MED_ERROR;
2136   med_2_3::med_repere rep;
2137   string tmp_name(_ptrMesh->_spaceDimension*MED_TAILLE_PNOM22,' ');
2138   string tmp_unit(_ptrMesh->_spaceDimension*MED_TAILLE_PNOM22,' ');
2139
2140   // Test if the mesh <_meshName> already exists
2141   // If it doesn't exists create it
2142   // If it already exists verify if its space and mesh dimensions are the same
2143   // as <_ptrMesh->_spaceDimension>, <_ptrMesh->_meshDimension> respectively
2144   // rem : <_meshName> is the driver meshName not <ptrMesh->_meshName>
2145
2146   int spaceDimension = med_2_3::MEDdimEspaceLire(_medIdt, const_cast <char *>
2147                                                 (_meshName.c_str()) );
2148
2149   int meshDimension = med_2_3::MEDdimLire(_medIdt, const_cast <char *>
2150                                          (_meshName.c_str()) );
2151
2152
2153   MESSAGE_MED(LOC << "spacedim " << spaceDimension << " meshdim " << meshDimension);
2154
2155   MESSAGE_MED(LOC << "From the mesh spacedim " << _ptrMesh->_spaceDimension << " meshdim " << _ptrMesh->_meshDimension);
2156
2157   if ((spaceDimension <= MED_VALID) && (meshDimension <= MED_VALID))
2158     {
2159       err = MEDmaaCr(_medIdt,
2160                      const_cast <char *> (_meshName.c_str()),
2161                      _ptrMesh->_meshDimension,med_2_3::MED_STRUCTURE,
2162                      const_cast <char *> (_ptrMesh->_description.c_str()));
2163
2164       meshDimension =  _ptrMesh->_meshDimension;
2165
2166       if (err != MED_VALID)
2167         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Unable to create Grid"));
2168       else 
2169         MESSAGE_MED(LOC<<"Grid "<<_meshName<<" created in file "<<_fileName<<" !");
2170     }
2171   else if ((spaceDimension != _ptrMesh->_spaceDimension)  &&
2172            (meshDimension != _ptrMesh->_meshDimension))
2173     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Grid |" << _meshName.c_str() <<
2174                                  "| already exists in file |" << _fileName <<
2175                                  "| with space dimension |" << spaceDimension <<
2176                                  "| and mesh dimension |" << meshDimension <<
2177                                  "| but the space dimension and the mesh dimension of the mesh we want to write are respectively |"
2178                                  << _ptrMesh->_spaceDimension <<"|" <<
2179                                  _ptrMesh->_meshDimension <<"|" )) ;
2180
2181   MED_EN::med_grid_type gridType = ptrGrid->getGridType();
2182
2183   err = med_2_3::MEDnatureGrilleEcr(_medIdt,
2184                                    const_cast <char *> (_meshName.c_str()),
2185                                    (med_2_3::med_type_grille) gridType);
2186
2187   if (err != MED_VALID)
2188     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Unable to write the type of the Grid"));
2189
2190   // Recompose the <_spaceDimension> strings in 1 string 
2191   int lengthString ;
2192   string valueString ;
2193   for (int i=0;i<_ptrMesh->_spaceDimension;i++) {
2194     SCRUTE_MED(i);
2195     valueString = _ptrMesh->_coordinate->_coordinateName[i] ;
2196     lengthString = (MED_TAILLE_PNOM22<valueString.size())?MED_TAILLE_PNOM22:valueString.size() ;
2197     tmp_name.replace(i*MED_TAILLE_PNOM22,i*MED_TAILLE_PNOM22+lengthString,valueString,0,lengthString);
2198     valueString = _ptrMesh->_coordinate->_coordinateUnit[i];
2199     lengthString = (MED_TAILLE_PNOM22<valueString.size())?MED_TAILLE_PNOM22:valueString.size() ;
2200     tmp_unit.replace(i*MED_TAILLE_PNOM22,i*MED_TAILLE_PNOM22+lengthString,valueString,0,lengthString);
2201   }
2202
2203   // Pourquoi le stocker sous forme de chaîne ?
2204   const string & coordinateSystem = _ptrMesh->_coordinate->_coordinateSystem;
2205   if      (coordinateSystem  == "CARTESIAN") 
2206     rep = med_2_3::MED_CART;
2207   else if ( coordinateSystem == "CYLINDRICAL")
2208     rep = med_2_3::MED_CYL;
2209   else if ( coordinateSystem == "SPHERICAL" )
2210     rep = med_2_3::MED_SPHER;
2211   else
2212     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Grid |" << _meshName.c_str() <<
2213                                  "| doesn't have a valid coordinate system : |" 
2214                                  << _ptrMesh->_coordinate->_coordinateSystem
2215                                  << "|" )) ;  
2216
2217   med_2_3::med_int ArrayLen[] = { (med_2_3::med_int) ptrGrid->_iArrayLength,
2218                      (med_2_3::med_int) ptrGrid->_jArrayLength,
2219                      (med_2_3::med_int) ptrGrid->_kArrayLength  };
2220   
2221   // Write node coordinates for MED_BODY_FITTED grid
2222   if (gridType == MED_EN::MED_BODY_FITTED)
2223     {
2224       // Write Coordinates and families
2225 //       double * coo = const_cast <double *>
2226 //      (_ptrMesh->_coordinate->getCoordinates(MED_EN::MED_FULL_INTERLACE));
2227
2228       err = MEDcoordEcr(_medIdt, const_cast <char *> (_meshName.c_str()),
2229                         _ptrMesh->_spaceDimension, 
2230                         //const_cast <double *> ( _ptrMesh->_coordinate->_coordinate->get(MED_EN::MED_FULL_INTERLACE) ), 
2231                         const_cast <double *> ( _ptrMesh->_coordinate->_coordinate.get(MED_EN::MED_FULL_INTERLACE) ), 
2232                         med_2_3::MED_FULL_INTERLACE, _ptrMesh->_numberOfNodes,
2233                         //  _ptrMesh->_coordinate->_numberOfNodes
2234                         rep, const_cast <char *> (tmp_name.c_str()), 
2235                         const_cast <char *> (tmp_unit.c_str()));
2236
2237       if (err != MED_VALID) 
2238         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write coordinates of the grid |" << _meshName.c_str() << "| in file |" << _fileName
2239                                      << "| with dimension |"  << _ptrMesh->_spaceDimension <<"| and" 
2240                                      << " with units names |"  << tmp_name
2241                                      << "| and units |"       << tmp_unit
2242                                      << " |")) ;
2243
2244 //CCRT      int* structure = new int [meshDimension];
2245       med_2_3::med_int* structure = new med_2_3::med_int [meshDimension];
2246
2247       for (int idim = 0; idim < meshDimension; ++idim)
2248         structure[idim] = ArrayLen [idim];
2249  
2250
2251       err = med_2_3::MEDstructureCoordEcr(_medIdt, const_cast <char *>
2252                                          (_meshName.c_str()), meshDimension,
2253                                          structure);
2254
2255       if (err != MED_VALID)
2256         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"error in writing the structure of the grid |" << _meshName.c_str()));
2257
2258       delete [] structure;
2259     }
2260   else if ((gridType == MED_EN::MED_CARTESIAN) ||
2261            (gridType == MED_EN::MED_POLAR))
2262     {
2263       // Write Arrays of Cartesian or Polar Grid
2264
2265       double * Array[] = { ptrGrid->_iArray,
2266                            ptrGrid->_jArray,
2267                            ptrGrid->_kArray };
2268
2269       for (int idim = 0; idim < _ptrMesh->_meshDimension; ++idim)
2270         {
2271           string str_name = string (tmp_name,idim*MED_TAILLE_PNOM22,
2272                                     MED_TAILLE_PNOM22);
2273           string str_unit = string (tmp_unit,idim*MED_TAILLE_PNOM22,
2274                                     MED_TAILLE_PNOM22);
2275
2276           err = med_2_3::MEDindicesCoordEcr(_medIdt, const_cast <char *>
2277                                            (_meshName.c_str()),
2278                                            _ptrMesh->_meshDimension,
2279                                            Array[idim], ArrayLen[idim],
2280                                            (idim+1), const_cast <char *>
2281                                            (str_name.c_str()),
2282                                            const_cast <char *>
2283                                            (str_unit.c_str()));
2284
2285           if (err != MED_VALID)
2286             throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<
2287                                          "Can't write grid coordinates for " <<
2288                                          idim << "-th dimention"));
2289         }
2290   } // end Write  Cartesian or Polar Grid
2291
2292   END_OF_MED(LOC);
2293   return MED_VALID;
2294 }
2295
2296 //=======================================================================
2297 //function : writeCoordinates
2298 //purpose  : 
2299 //=======================================================================
2300
2301 int MED_MESH_WRONLY_DRIVER22::writeCoordinates() const {
2302  
2303   const char * LOC = "int MED_MESH_WRONLY_DRIVER22::writeCoordinates() const : ";
2304   BEGIN_OF_MED(LOC);
2305
2306   med_2_3::med_err err = MED_ERROR;
2307   med_2_3::med_repere rep;
2308   string tmp_name(_ptrMesh->_spaceDimension*MED_TAILLE_PNOM22,' ');
2309   string tmp_unit(_ptrMesh->_spaceDimension*MED_TAILLE_PNOM22,' ');
2310     
2311   // Recompose the <_spaceDimension> strings in 1 string 
2312   int lengthString ;
2313   string valueString ;
2314   for (int i=0;i<_ptrMesh->_spaceDimension;i++) {
2315     valueString = _ptrMesh->_coordinate->_coordinateName[i] ;
2316     lengthString = (MED_TAILLE_PNOM22<valueString.size())?MED_TAILLE_PNOM22:valueString.size() ;
2317     tmp_name.replace(i*MED_TAILLE_PNOM22,i*MED_TAILLE_PNOM22+lengthString,valueString,0,lengthString);
2318     valueString = _ptrMesh->_coordinate->_coordinateUnit[i];
2319     lengthString = (MED_TAILLE_PNOM22<valueString.size())?MED_TAILLE_PNOM22:valueString.size() ;
2320     tmp_unit.replace(i*MED_TAILLE_PNOM22,i*MED_TAILLE_PNOM22+lengthString,valueString,0,lengthString);
2321   }
2322
2323   // Test if the mesh <_meshName> already exists
2324   // If it doesn't exists create it
2325   // If it already exists verify if its space and mesh dimensions are the same
2326   // as <_ptrMesh->_spaceDimension>, <_ptrMesh->_meshDimension> respectively
2327   // rem : <_meshName> is the driver meshName not <ptrMesh->_meshName>
2328
2329   int spaceDimension = med_2_3::MEDdimEspaceLire(_medIdt, const_cast <char *>
2330                                                 (_meshName.c_str()));
2331
2332   int meshDimension = med_2_3::MEDdimLire(_medIdt, const_cast <char *>
2333                                          (_meshName.c_str()) );
2334
2335   SCRUTE_MED(spaceDimension);
2336   SCRUTE_MED(meshDimension);
2337   SCRUTE_MED(_ptrMesh->_spaceDimension);
2338   SCRUTE_MED(_ptrMesh->_meshDimension);
2339
2340   if ((spaceDimension != MED_VALID) && (meshDimension < MED_VALID))
2341     {
2342       err = MEDmaaCr(_medIdt, const_cast <char *> (_meshName.c_str()),
2343                      _ptrMesh->_meshDimension, med_2_3::MED_NON_STRUCTURE,
2344                      const_cast <char *> (_ptrMesh->_description.c_str()));
2345
2346       if (err < MED_VALID)
2347         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Unable to create Mesh : |" << _meshName << "|"));
2348       else 
2349         MESSAGE_MED(LOC<<"Mesh "<<_meshName<<" created in file "<<_fileName<<" !");
2350
2351       // PAL14544. Write _spaceDimension if _spaceDimension != _meshDimension
2352       if ( _ptrMesh->_spaceDimension != _ptrMesh->_meshDimension )
2353       {
2354         err = med_2_3::MEDdimEspaceCr(_medIdt, const_cast <char *> (_meshName.c_str()),
2355                                       _ptrMesh->_spaceDimension);
2356         if (err < MED_VALID)
2357           throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write spaceDimension of Mesh : |"
2358                                        << _meshName << "|"));
2359       }
2360     }
2361   else if ((spaceDimension != _ptrMesh->_spaceDimension)  &&
2362            (meshDimension != _ptrMesh->_meshDimension))
2363     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Mesh |" << _meshName.c_str() <<
2364                                  "| already exists in file |" << _fileName <<
2365                                  "| with space dimension |" << spaceDimension <<
2366                                  "| and mesh dimension |" << meshDimension <<
2367                                  "| but the space dimension and the mesh dimension of the mesh we want to write are respectively |"
2368                                  << _ptrMesh->_spaceDimension <<"|" <<
2369                                  _ptrMesh->_meshDimension << "|")) ;
2370     
2371   // Pourquoi le stocker sous forme de chaîne ?
2372   const string & coordinateSystem = _ptrMesh->_coordinate->_coordinateSystem;
2373   if      (coordinateSystem  == "CARTESIAN") 
2374     rep = med_2_3::MED_CART;
2375   else if ( coordinateSystem == "CYLINDRICAL")
2376     rep = med_2_3::MED_CYL;
2377   else if ( coordinateSystem == "SPHERICAL" )
2378     rep = med_2_3::MED_SPHER;
2379   else
2380     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Mesh |" << _meshName.c_str() << "| doesn't have a valid coordinate system : |" 
2381                                  << _ptrMesh->_coordinate->_coordinateSystem
2382                                  << "|" )) ;  
2383       
2384 //   err = MEDcoordEcr(_medIdt, const_cast <char *> (_meshName.c_str()),
2385 //                  _ptrMesh->_spaceDimension, 
2386 //                  //const_cast <double *> ( _ptrMesh->_coordinate->_coordinate->get(MED_EN::MED_FULL_INTERLACE) ), 
2387 //                  const_cast <double *> ( _ptrMesh->_coordinate->_coordinate.get(MED_EN::MED_FULL_INTERLACE) ), 
2388 //                  MED_FR::MED_FULL_INTERLACE, 
2389 //                  _ptrMesh->_numberOfNodes,                 //  _ptrMesh->_coordinate->_numberOfNodes
2390 //                  MED_FR::MED_LECTURE_ECRITURE,    
2391 //                  rep,
2392 //                  const_cast <char *> (tmp_name.c_str()), 
2393 //                  const_cast <char *> (tmp_unit.c_str()) 
2394 //                  );
2395
2396   err = MEDcoordEcr(_medIdt, const_cast <char *> (_meshName.c_str()),
2397                     _ptrMesh->_spaceDimension, 
2398                     //const_cast <double *> ( _ptrMesh->_coordinate->_coordinate->get(MED_EN::MED_FULL_INTERLACE) ), 
2399                     const_cast <double *> ( _ptrMesh->_coordinate->_coordinate.get(MED_EN::MED_FULL_INTERLACE) ), 
2400                     med_2_3::MED_FULL_INTERLACE, _ptrMesh->_numberOfNodes,
2401                     //  _ptrMesh->_coordinate->_numberOfNodes
2402                     rep, const_cast <char *> (tmp_name.c_str()), 
2403                     const_cast <char *> (tmp_unit.c_str()));
2404
2405   if (err<0) 
2406     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write coordinates of mesh |" << _meshName.c_str() << "| in file |" << _fileName
2407                                  << "| with dimension |"  << _ptrMesh->_spaceDimension <<"| and" 
2408                                  << " with units names |"  << tmp_name
2409                                  << "| and units |"       << tmp_unit
2410                                  << " |")) ;    
2411     
2412
2413        //////////////////////////////////////////////////////////////////////////////////////
2414        ///  Modification pour prise en compte de la numérotation optionnelle des noeuds   ///
2415        //////////////////////////////////////////////////////////////////////////////////////
2416        ///
2417        /// Ecrit les numéros optionnels des noeuds
2418        /// Le traitement est identique à la version originelle s'il n'y a pas de numérotation optionnelle
2419
2420
2421       if (_ptrMesh->_arePresentOptionnalNodesNumbers==1) {
2422         
2423 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
2424         const int * NodesNumbers = _ptrMesh->_coordinate->getNodesNumbers() ;
2425         med_2_3::med_int * tmp_NodesNumbers = new med_2_3::med_int[_ptrMesh->_numberOfNodes] ;
2426         int ii ;
2427         for ( ii = 0 ; ii < _ptrMesh->_numberOfNodes ; ii++ )
2428            tmp_NodesNumbers[ii] = NodesNumbers[ii] ;
2429         err =  MEDnumEcr(_medIdt, const_cast <char *> (_meshName.c_str()),
2430                          tmp_NodesNumbers , 
2431                          _ptrMesh->_numberOfNodes, med_2_3::MED_NOEUD,
2432                          med_2_3::med_geometrie_element(0) );
2433         delete [] tmp_NodesNumbers ;
2434 #else
2435         err =  MEDnumEcr(_medIdt, const_cast <char *> (_meshName.c_str()),
2436                          const_cast <med_int *> (_ptrMesh->_coordinate->getNodesNumbers() ), 
2437                          _ptrMesh->_numberOfNodes, med_2_3::MED_NOEUD,
2438                          med_2_3::med_geometrie_element(0) );
2439 #endif
2440
2441         if (err != MED_VALID) 
2442           throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write optionnal numbers of mesh |" << 
2443                                        _meshName.c_str() << "| in file |" <<
2444                                        _fileName  << " |")) ;
2445       }
2446       //////////////////////////////////////////////////////////////////////////////////////
2447
2448   END_OF_MED(LOC);
2449     
2450   return MED_VALID;
2451 }
2452
2453
2454
2455
2456 int MED_MESH_WRONLY_DRIVER22::writeConnectivities(medEntityMesh entity) const 
2457 {
2458   const char * LOC="int MED_MESH_WRONLY_DRIVER22::writeConnectivities() const : ";
2459   BEGIN_OF_MED(LOC);
2460
2461   med_2_3::med_err err;
2462   
2463   // REM SI LA METHODE EST APPELEE DIRECTEMENT ET QUE LE MAILLAGE N'EST PAS CREE IL Y A PB !
2464   // PG : IMPOSSIBLE : LA METHODE EST PRIVEE !
2465     
2466   // A FAIRE : A tester surtout dans les methodes de MESH.
2467   //    if ( _ptrMesh->_connectivity == (CONNECTIVITY *) MED_INVALID )
2468   if ( _ptrMesh->_connectivity == (CONNECTIVITY *) NULL )
2469     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "The connectivity is not defined in the MESH object ")) ;
2470
2471
2472   // Nodal connectivity for classic geometric types
2473   if ( _ptrMesh->existConnectivity(MED_NODAL,entity) )
2474     {
2475       int numberOfTypes = _ptrMesh->getNumberOfTypes(entity);
2476       const medGeometryElement * types = _ptrMesh->getTypes(entity);
2477
2478       for (int i=0; i<numberOfTypes; i++)
2479         {
2480           int numberOfElements = _ptrMesh->getNumberOfElements(entity,types[i]);
2481           const int * connectivity = _ptrMesh->getConnectivity(MED_EN::MED_FULL_INTERLACE,
2482                                                                MED_NODAL, entity, types[i]); // ?? et SI MED_NODAL n'existe pas, recalcul auto ??
2483
2484           // Pour l'instant la class utilise le multi.....
2485           int multi = 0;
2486           //      if (entity==MED_EN::MED_CELL)
2487           //        if ( (types[i]/ 100) < _ptrMesh->_spaceDimension)
2488           //          multi=1;
2489           int numberOfNodes = types[i]%100;
2490 //CCRT    int * connectivityArray = new int[numberOfElements*(numberOfNodes+multi)];
2491           med_2_3::med_int * connectivityArray = new med_2_3::med_int[numberOfElements*(numberOfNodes+multi)];
2492
2493           // version originale sans prise en compte des numéros optionnels
2494           //
2495           for (int j=0 ; j<numberOfElements; j++)
2496             {
2497               for (int k=0; k<numberOfNodes; k++)
2498                 connectivityArray[j*(numberOfNodes+multi)+k] = connectivity[j*numberOfNodes+k];
2499
2500               if (multi>0) connectivityArray[j*(numberOfNodes+multi)+numberOfNodes] = 0;
2501             }
2502
2503           //////////////////////////////////////////////////////////////////////////////////////
2504           ///  Modification pour prise en compte de la numérotation optionnelle des noeuds  ///
2505           //////////////////////////////////////////////////////////////////////////////////////
2506           ///
2507           /// Dénumérote les sommets des mailles pour leur rendre leurs numéros optionnels
2508           /// Le traitement est identique à la version originelle s'il n'y a pas de numérotation optionnelle
2509
2510           //if (_ptrMesh->_arePresentOptionnalNodesNumbers==1)
2511           //{
2512           //  const int * nodesNumbers = _ptrMesh->_coordinate->getNodesNumbers();
2513           //  for (int j=0 ; j<numberOfElements; j++) 
2514           //  {
2515           //    for (int k=0; k<numberOfNodes; k++)
2516           //      connectivityArray[j*(numberOfNodes+multi)+k] =
2517           //        nodesNumbers[connectivity[j*numberOfNodes+k]-1];
2518           //    if (multi>0) connectivityArray[j*(numberOfNodes+multi)+numberOfNodes] = 0;
2519           //  }
2520           //}
2521           //else
2522           //{
2523           //  for (int j=0 ; j<numberOfElements; j++)
2524           //  {
2525           //    for (int k=0; k<numberOfNodes; k++)
2526           //      connectivityArray[j*(numberOfNodes+multi)+k] = connectivity[j*numberOfNodes+k];
2527           //    if (multi>0) connectivityArray[j*(numberOfNodes+multi)+numberOfNodes]=0;
2528           //  }
2529           //}
2530
2531           //////////////////////////////////////////////////////////////////////////////////////
2532
2533           //err = MEDconnEcr(_medIdt, const_cast <char *> (_meshName.c_str()),
2534           //                 _ptrMesh->_spaceDimension, connectivityArray,
2535           //                 MED_FR::MED_FULL_INTERLACE, numberOfElements,
2536           //                 MED_FR::MED_LECTURE_ECRITURE,
2537           //                 (MED_FR::med_entite_maillage  ) entity,
2538           //                 (MED_FR::med_geometrie_element) types[i], MED_FR::MED_NOD);
2539
2540           //err = MEDconnEcr(_medIdt, const_cast <char *> (_meshName.c_str()),
2541           //                 _ptrMesh->_spaceDimension, connectivityArray,
2542           //                 MED_FR::MED_FULL_INTERLACE, numberOfElements,
2543           //                 (MED_FR::med_entite_maillage  ) entity,
2544           //                 (MED_FR::med_geometrie_element) types[i], med_2_3::MED_NOD);
2545
2546           err = MEDconnEcr(_medIdt, const_cast <char *> (_meshName.c_str()),
2547                            _ptrMesh->_spaceDimension, connectivityArray,
2548                            med_2_3::MED_FULL_INTERLACE, numberOfElements,
2549                            //(med_2_3::med_entite_maillage) entity, because Med Memory works only in Nodal connectivity
2550                            (med_2_3::med_entite_maillage  ) MED_CELL,
2551                            (med_2_3::med_geometrie_element) types[i], med_2_3::MED_NOD);
2552           err = med_2_3::MEDdimEspaceCr
2553             (_medIdt, const_cast<char *>(_meshName.c_str()), _ptrMesh->_spaceDimension);
2554
2555           delete[] connectivityArray;
2556
2557           if (err<0) // ETENDRE LES EXPLICATIONS
2558             throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write connectivities of mesh |"
2559                                          << _meshName.c_str() << "| in file |" << _fileName
2560                                          << "| with dimension |"  << _ptrMesh->_spaceDimension <<"| and" 
2561                                          ));
2562         }
2563
2564     }
2565
2566
2567   // Polygons writing
2568   if (_ptrMesh->existPolygonsConnectivity(MED_NODAL,entity))
2569     {
2570       int nbPolygons = _ptrMesh->getNumberOfPolygons(entity);
2571       const int * PolygonsConnectivityIndex = _ptrMesh->getPolygonsConnectivityIndex(MED_NODAL,entity);
2572       const int * PolygonsConnectivity = _ptrMesh->getPolygonsConnectivity(MED_NODAL, entity);
2573
2574 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
2575       int ii, polygonsConnectivityLength = _ptrMesh->getPolygonsConnectivityLength(MED_NODAL, entity);
2576
2577       med_2_3::med_int * tmp_PolygonsConnectivityIndex = new med_2_3::med_int[nbPolygons + 1];
2578       for (ii = 0; ii < nbPolygons + 1; ii++)
2579         tmp_PolygonsConnectivityIndex[ii] = PolygonsConnectivityIndex[ii];
2580
2581       med_2_3::med_int * tmp_PolygonsConnectivity = new med_2_3::med_int[polygonsConnectivityLength];
2582       for (ii = 0; ii < polygonsConnectivityLength; ii++)
2583         tmp_PolygonsConnectivity[ii] = PolygonsConnectivity[ii];
2584
2585       err = MEDpolygoneConnEcr(_medIdt,
2586                                const_cast <char *> (_meshName.c_str()),
2587                                tmp_PolygonsConnectivityIndex,
2588                                nbPolygons + 1,
2589                                tmp_PolygonsConnectivity,
2590                                //(med_2_3::med_entite_maillage) entity,
2591                                //because Med Memory works only in Nodal connectivity
2592                                (med_2_3::med_entite_maillage) MED_CELL,
2593                                med_2_3::MED_NOD);
2594
2595       delete [] tmp_PolygonsConnectivityIndex;
2596       delete [] tmp_PolygonsConnectivity;
2597 #else
2598       err = MEDpolygoneConnEcr(_medIdt,
2599                                const_cast <char *> (_meshName.c_str()),
2600                                const_cast <med_int*> (PolygonsConnectivityIndex),
2601                                nbPolygons + 1,
2602                                const_cast <med_int*> (PolygonsConnectivity),
2603                                //(med_2_3::med_entite_maillage) entity,
2604                                //because Med Memory works only in Nodal connectivity
2605                                (med_2_3::med_entite_maillage) MED_CELL,
2606                                med_2_3::MED_NOD);
2607 #endif
2608
2609       if (err<0)
2610         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write polygons nodal connectivities of mesh |"
2611                                      <<  _meshName.c_str() << "| in file |" << _fileName
2612                                      << "| with dimension |"  << _ptrMesh->_spaceDimension <<"| and"
2613                                      ));
2614     }
2615
2616
2617   // Polyhedron writing
2618   if (_ptrMesh->existPolyhedronConnectivity(MED_NODAL,entity))
2619     {
2620       //int nbPolyhedron = _ptrMesh->getNumberOfPolyhedron(entity);
2621       int nbPolyhedron = _ptrMesh->getNumberOfPolyhedron();
2622       int nbPolyhedronFaces = _ptrMesh->getNumberOfPolyhedronFaces();
2623       const int * PolyhedronIndex = _ptrMesh->getPolyhedronIndex(MED_NODAL);
2624       const int * PolyhedronFacesIndex = _ptrMesh->getPolyhedronFacesIndex();
2625       const int * PolyhedronConnectivity = _ptrMesh->getPolyhedronConnectivity(MED_NODAL);
2626
2627 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
2628       int ii, polyhedronConnectivityLength = _ptrMesh->getPolyhedronConnectivityLength(MED_NODAL);
2629
2630       med_2_3::med_int * tmp_PolyhedronIndex = new med_2_3::med_int[nbPolyhedron + 1];
2631       for (ii = 0; ii < nbPolyhedron + 1; ii++)
2632          tmp_PolyhedronIndex[ii] = PolyhedronIndex[ii];
2633
2634       med_2_3::med_int * tmp_PolyhedronFacesIndex = new med_2_3::med_int[nbPolyhedronFaces + 1];
2635       for (ii = 0; ii < nbPolyhedronFaces + 1; ii++)
2636          tmp_PolyhedronFacesIndex[ii] = PolyhedronFacesIndex[ii];
2637
2638       med_2_3::med_int * tmp_PolyhedronConnectivity = new med_2_3::med_int[polyhedronConnectivityLength];
2639       for (ii = 0; ii < polyhedronConnectivityLength; ii++)
2640          tmp_PolyhedronConnectivity[ii] = PolyhedronConnectivity[ii];
2641
2642       err = MEDpolyedreConnEcr(_medIdt,
2643                                const_cast <char *> (_meshName.c_str()),
2644                                tmp_PolyhedronIndex,
2645                                nbPolyhedron + 1,
2646                                tmp_PolyhedronFacesIndex,
2647                                nbPolyhedronFaces + 1,
2648                                tmp_PolyhedronConnectivity,
2649                                med_2_3::MED_NOD);
2650
2651       delete [] tmp_PolyhedronIndex;
2652       delete [] tmp_PolyhedronFacesIndex;
2653       delete [] tmp_PolyhedronConnectivity;
2654 #else
2655       err = MEDpolyedreConnEcr(_medIdt,
2656                                const_cast <char *> (_meshName.c_str()),
2657                                const_cast <med_int*> (PolyhedronIndex),
2658                                nbPolyhedron + 1,
2659                                const_cast <med_int*> (PolyhedronFacesIndex),
2660                                nbPolyhedronFaces + 1,
2661                                const_cast <med_int*> (PolyhedronConnectivity),
2662                                med_2_3::MED_NOD);
2663 #endif
2664
2665       if (err<0)
2666         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write polyhedron nodal connectivities of mesh |"
2667                                      << _meshName.c_str() << "| in file |" << _fileName
2668                                      << "| with dimension |"  << _ptrMesh->_spaceDimension <<"| and"
2669                                      ));
2670     }
2671
2672
2673   // Descending connectivity for classic geometric types
2674   if ( _ptrMesh->existConnectivity(MED_DESCENDING,entity) )
2675     {
2676       int numberOfTypes                = _ptrMesh->getNumberOfTypes (entity) ;
2677       const medGeometryElement * types = _ptrMesh->getTypes         (entity) ;
2678       
2679       for (int i=0; i<numberOfTypes; i++)
2680         {
2681           int    numberOfElements = _ptrMesh->getNumberOfElements (entity,types[i]);
2682           const int * connectivity = _ptrMesh->getConnectivity(MED_EN::MED_FULL_INTERLACE, MED_DESCENDING, entity, types[i]); 
2683       
2684           // Pour l'instant la class utilise le multi.....
2685           //       err = MED_FR::MEDconnEcr( _medIdt,
2686           //                            const_cast <char *> ( _meshName.c_str()),
2687           //                            _ptrMesh->_spaceDimension,
2688           //                            const_cast <int *> (connectivity),
2689           //                            MED_FR::MED_FULL_INTERLACE,
2690           //                            numberOfElements,
2691           //                            MED_FR::MED_LECTURE_ECRITURE,
2692           //                            (MED_FR::med_entite_maillage  ) entity, 
2693           //                            (MED_FR::med_geometrie_element) types[i],
2694           //                            MED_FR::MED_DESC );
2695
2696 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
2697           int lgth = _ptrMesh->getConnectivityLength(MED_EN::MED_FULL_INTERLACE, MED_DESCENDING, entity, types[i]);
2698           med_2_3::med_int * tmp_Connectivity = new med_2_3::med_int[lgth] ;
2699           int ii ;
2700           for ( ii = 0 ; ii < lgth ; ii++ )
2701           tmp_Connectivity[ii] = connectivity[ii] ;
2702           err = med_2_3::MEDconnEcr(_medIdt,
2703                                     const_cast <char *> ( _meshName.c_str()),
2704                                     _ptrMesh->_spaceDimension,
2705                                     tmp_Connectivity,
2706                                     med_2_3::MED_FULL_INTERLACE,
2707                                     numberOfElements,
2708                                     //(med_2_3::med_entite_maillage  ) entity,
2709                                     //because Med Memory works only in Nodal connectivity
2710                                     (med_2_3::med_entite_maillage  ) MED_CELL,
2711                                     (med_2_3::med_geometrie_element) types[i],
2712                                     med_2_3::MED_DESC);
2713           delete [] tmp_Connectivity ;
2714 #else
2715           err = med_2_3::MEDconnEcr(_medIdt,
2716                                     const_cast <char *> ( _meshName.c_str()),
2717                                     _ptrMesh->_spaceDimension,
2718                                     const_cast <int *> (connectivity),
2719                                     med_2_3::MED_FULL_INTERLACE,
2720                                     numberOfElements,
2721                                     //(med_2_3::med_entite_maillage  ) entity,
2722                                     //because Med Memory works only in Nodal connectivity
2723                                     (med_2_3::med_entite_maillage  ) MED_CELL, 
2724                                     (med_2_3::med_geometrie_element) types[i],
2725                                     med_2_3::MED_DESC);
2726 #endif
2727         
2728           if (err<0) // ETENDRE LES EXPLICATIONS
2729             throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write connectivities of mesh |"
2730                                          << _meshName.c_str() << "| in file |" << _fileName
2731                                          << "| with dimension |"  << _ptrMesh->_spaceDimension <<"| and" 
2732                                          )) ;
2733             
2734         }
2735     }
2736
2737
2738   // Polygons writing
2739   if (_ptrMesh->existPolygonsConnectivity(MED_DESCENDING,entity))
2740     {
2741       int nbPolygons = _ptrMesh->getNumberOfPolygons(entity);
2742       // ??? //int nbPolygons = _ptrMesh->getNumberOfPolygons();
2743       const int * PolygonsConnectivityIndex = _ptrMesh->getPolygonsConnectivityIndex(MED_DESCENDING, entity);
2744       const int * PolygonsConnectivity = _ptrMesh->getPolygonsConnectivity(MED_DESCENDING, entity);
2745
2746 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
2747       int ii, polygonsConnectivityLength = _ptrMesh->getPolygonsConnectivityLength(MED_DESCENDING, entity);
2748
2749       med_2_3::med_int * tmp_PolygonsConnectivityIndex = new med_2_3::med_int[nbPolygons + 1];
2750       for (ii = 0; ii < nbPolygons + 1; ii++)
2751         tmp_PolygonsConnectivityIndex[ii] = PolygonsConnectivityIndex[ii];
2752
2753       med_2_3::med_int * tmp_PolygonsConnectivity = new med_2_3::med_int[polygonsConnectivityLength];
2754       for (ii = 0; ii < polygonsConnectivityLength; ii++)
2755         tmp_PolygonsConnectivity[ii] = PolygonsConnectivity[ii];
2756
2757       err = MEDpolygoneConnEcr(_medIdt,
2758                                const_cast <char *> (_meshName.c_str()),
2759                                tmp_PolygonsConnectivityIndex,
2760                                nbPolygons + 1,
2761                                tmp_PolygonsConnectivity,
2762                                //(med_2_3::med_entite_maillage) entity,
2763                                //because Med Memory works only in Nodal connectivity
2764                                (med_2_3::med_entite_maillage) MED_CELL,
2765                                med_2_3::MED_DESC);
2766
2767       delete [] tmp_PolygonsConnectivityIndex;
2768       delete [] tmp_PolygonsConnectivity;
2769 #else
2770       err = MEDpolygoneConnEcr(_medIdt,
2771                                const_cast <char *> (_meshName.c_str()),
2772                                const_cast <med_int*> (PolygonsConnectivityIndex),
2773                                nbPolygons + 1,
2774                                const_cast <med_int*> (PolygonsConnectivity),
2775                                //(med_2_3::med_entite_maillage) entity,
2776                                //because Med Memory works only in Nodal connectivity
2777                                (med_2_3::med_entite_maillage) entity,
2778                                med_2_3::MED_DESC);
2779 #endif
2780
2781       if (err<0)
2782         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write polygons descending connectivities of mesh |"
2783                                      <<  _meshName.c_str() << "| in file |" << _fileName
2784                                      << "| with dimension |"  << _ptrMesh->_spaceDimension <<"| and"
2785                                      ));
2786     }
2787
2788
2789   // Polyhedron writing
2790   if (_ptrMesh->existPolyhedronConnectivity(MED_DESCENDING, entity))
2791     {
2792       med_2_3::med_int nbPolyhedron = _ptrMesh->getNumberOfPolyhedron();
2793       med_2_3::med_int NumberOfFaces = _ptrMesh->getNumberOfPolyhedronFaces();
2794       // ??? //_ptrMesh->getPolyhedronIndex(MED_DESCENDING)[nbPolyhedron] - 1;
2795       // by default all polyhedron faces are polygons
2796       vector<med_2_3::med_int> FacesGeometricTypes (NumberOfFaces, MED_POLYGON);
2797       const int * PolyhedronIndex = _ptrMesh->getPolyhedronIndex(MED_DESCENDING);
2798       const int * PolyhedronConnectivity = _ptrMesh->getPolyhedronConnectivity(MED_DESCENDING);
2799
2800 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
2801       int ii, polyhedronConnectivityLength = _ptrMesh->getPolyhedronConnectivityLength(MED_DESCENDING);
2802
2803       med_2_3::med_int * tmp_PolyhedronIndex = new med_2_3::med_int[nbPolyhedron + 1];
2804       for (ii = 0; ii < nbPolyhedron + 1; ii++)
2805          tmp_PolyhedronIndex[ii] = PolyhedronIndex[ii];
2806
2807       med_2_3::med_int * tmp_PolyhedronConnectivity = new med_2_3::med_int[polyhedronConnectivityLength];
2808       for (ii = 0; ii < polyhedronConnectivityLength; ii++)
2809          tmp_PolyhedronConnectivity[ii] = PolyhedronConnectivity[ii];
2810
2811       err = MEDpolyedreConnEcr(_medIdt,
2812                                const_cast <char *> (_meshName.c_str()),
2813                                tmp_PolyhedronIndex,
2814                                nbPolyhedron + 1,
2815                                &FacesGeometricTypes[0],
2816                                NumberOfFaces,
2817                                tmp_PolyhedronConnectivity,
2818                                med_2_3::MED_DESC);
2819
2820       delete [] tmp_PolyhedronIndex;
2821       delete [] tmp_PolyhedronConnectivity;
2822 #else
2823       err = MEDpolyedreConnEcr(_medIdt,
2824                                const_cast <char *> (_meshName.c_str()),
2825                                const_cast <med_int*> (PolyhedronIndex),
2826                                nbPolyhedron + 1,
2827                                &FacesGeometricTypes[0],
2828                                NumberOfFaces,
2829                                const_cast <med_int*> (PolyhedronConnectivity),
2830                                med_2_3::MED_DESC);
2831 #endif
2832
2833       if (err<0)
2834         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write polyhedron descending connectivities of mesh |"
2835                                      << _meshName.c_str() << "| in file |" << _fileName
2836                                      << "| with dimension |"  << _ptrMesh->_spaceDimension <<"| and" 
2837                                      ));
2838     }
2839
2840
2841   END_OF_MED(LOC);
2842   return MED_VALID;
2843 }
2844
2845 /*!creates a vector of families from a vector of groups
2846  * 
2847  * \param myGroups input : vector of groups
2848  * \param myFamilies output vector of families
2849  * 
2850  * Routine is meant to be called to reconstruct families from existing groups
2851  * typically for writing meshes created by MEDMEM::MESHING containing overlapping groups 
2852  * 
2853  * if the groups do not overlap, the vector of families will have the same size
2854  * as the vector of groups
2855  * otherwise, the size of the family vector will be larger
2856 */      
2857
2858 void MED_MESH_WRONLY_DRIVER22::groupFamilyConverter(const vector <GROUP*>& myGroups, vector <FAMILY*>& myFamilies ) const 
2859 {
2860
2861   const char* LOC = "MED_MESH_WRONLY_DRIVER::groupFamilyConverter";
2862   BEGIN_OF_MED(LOC);
2863   if (myGroups.empty()) return;
2864         
2865 //      if (!myFamilies.empty())
2866 //      throw MEDEXCEPTION(LOCALIZED("Family vector must be empty on call "
2867 //      << "to groupFamilyConverter"));
2868 // 
2869  //mapping elements to all the groups containing it
2870         std::multimap <int,int> elem2groups;
2871         for (int igroup=0; igroup< myGroups.size(); igroup++)
2872         {
2873                 // if the support is on all Mesh elements
2874                 //all the items from 1 to nb are in the group
2875                 if (myGroups[igroup]->isOnAllElements())
2876                 {
2877                         for (int ielem = 0; ielem< myGroups[igroup]->getNumberOfElements(MED_ALL_ELEMENTS); ielem++)
2878                         {
2879                                 elem2groups.insert(make_pair(ielem+1, igroup));
2880                         }
2881                 }
2882                 //otherwise getNumber() gives the appropriate number of items
2883                 else
2884                 {
2885                         const int*Number = myGroups[igroup]->getNumber(MED_ALL_ELEMENTS) ;
2886                         for (int ielem = 0; ielem< myGroups[igroup]->getNumberOfElements(MED_ALL_ELEMENTS); ielem++)
2887                         {
2888                                 elem2groups.insert(make_pair(Number[ielem], igroup));
2889                         }
2890                 }
2891         }
2892         
2893         //creating a set of signatures for the groups intersections
2894         std::multimap<vector<int>,int> signatures;
2895         
2896         typedef multimap<int,int>::iterator MI;
2897         MI iter=elem2groups.begin();
2898         
2899         while (iter!=elem2groups.end())
2900         {
2901                 vector<int> sign (1, iter -> second );
2902                 int key = iter -> first;
2903                 iter ++;
2904                 while (iter!=elem2groups.end()&&iter-> first == key)
2905                 {
2906                         sign.push_back(iter -> second);
2907                         iter++;
2908                 }
2909                 signatures.insert(make_pair(sign,key));
2910         }
2911         
2912         elem2groups.clear();
2913         
2914         //creating the families from the signatures mapping
2915         //each signature will correspond to a new family
2916         std::multimap<vector<int>,int>::const_iterator iter_signatures = signatures.begin();
2917         
2918         //retrieving the entity type (all the groups have the same)
2919         // node families are numbered above 0
2920         // cell families are numbered from  -1 to -MAX_NB_GROUPS
2921         // face falimies are numbered from -MAX_NB_GROUPS-1 to -2*MAX_NB_GROUPS
2922         // edge families are numbered from -2*MAX_NB_GROUPS to -3*MAX_NB_GROUPS
2923         // MAX_NB_GROUPS is defined in MEDMEM_define.hxx
2924         
2925         medEntityMesh entity = myGroups[0]->getEntity();
2926         MESH* mesh=myGroups[0]->getMesh();
2927         
2928         int ifamily;
2929         switch (entity)
2930         {
2931                 case MED_NODE:
2932                         ifamily=1;
2933                         break;
2934                 case MED_CELL:
2935                         ifamily=-MAX_NB_GROUP;
2936                         break;
2937                 case MED_FACE:
2938                         ifamily=-2*MAX_NB_GROUP;
2939                         break;
2940                 case MED_EDGE:
2941                          ifamily=-3*MAX_NB_GROUP;
2942                         break;
2943         }
2944
2945         //browsing signatures to build all the families
2946         //each signature corresponds to a new family
2947
2948         while (iter_signatures!= signatures.end())
2949         {
2950                 const vector<int>& key= iter_signatures->first;
2951                 int size = signatures.count(key);
2952                 
2953                 list<int> numbers;
2954
2955                 for (int i=0; i< size; i++)
2956                 {
2957                         numbers.push_back(iter_signatures->second);
2958                         iter_signatures++;
2959                 }
2960                 
2961                 //TODO : see if build SupportOnElementFromElementList could not be built from another container
2962
2963                 // for nodes, the family is built directly from the node list
2964                 // for elements, it is built from the buildSupportOnElementsFromElementList
2965                 //               which allocates a support
2966                 FAMILY* myFamily;
2967                 if (entity!=MED_NODE)
2968                   {     
2969                     SUPPORT* support;
2970                     support=mesh->buildSupportOnElementsFromElementList(numbers, entity);
2971                     myFamily=new FAMILY(*support);
2972         delete support;
2973                   }
2974                 else
2975                   {
2976                     myFamily= new FAMILY();
2977                     myFamily->setMesh(mesh);
2978                     myFamily->fillFromNodeList(numbers);
2979                   }
2980         
2981         
2982                 // the identifier and the groups are set
2983                 myFamily->setIdentifier(ifamily);
2984                 myFamily->setNumberOfGroups(key.size());
2985                 char family_name[MED_TAILLE_NOM];
2986
2987                 //if the family has one group to which only one family
2988                 //is associated, the name of the family underlying the group
2989                 //is given back to the family
2990                 if (key.size()==1 && myGroups[key[0]]->getNumberOfFamilies()==0)
2991                         {
2992                                 vector<FAMILY*> families;
2993                                 families.push_back(myFamily);
2994                                 myGroups[key[0]]->setFamilies(families);
2995                                 //it is necessary to use strncpy because group and family
2996                                 //have different name sizes
2997                                 strncpy(family_name,myGroups[key[0]]->getName().c_str(),MED_TAILLE_NOM);
2998                                 family_name[MED_TAILLE_NOM-1]='\0';
2999                         }
3000                 else
3001                         sprintf(family_name,"family%d",ifamily);
3002         
3003                 myFamily->setName( healName( family_name ));
3004
3005                 string* groupnames=new string[key.size()];
3006                 //myFamily->getGroupsNames();
3007                 //groupnames.set(key.size());
3008
3009                 for (int igroup=0; igroup<key.size(); igroup++)
3010                 {
3011                   groupnames[igroup]=myGroups[key[igroup]]->getName();
3012                 }       
3013                 
3014                 myFamily->setGroupsNames(groupnames,true);
3015           
3016                 myFamilies.push_back(myFamily);
3017                 ifamily++;
3018         }
3019
3020         //adding empty families corresponding to empty groups
3021         for (int i=0; i<myGroups.size(); i++)
3022                 {
3023                         if (myGroups[i]->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)==0)
3024                                 {
3025                                         FAMILY* myFamily=new FAMILY(*(myGroups[i]));
3026                                         char family_name[MED_TAILLE_NOM];
3027                                         //it is necessary to use strncpy because group and family
3028                                         //have different name sizes
3029                                         strncpy(family_name,myGroups[i]->getName().c_str(),MED_TAILLE_NOM);
3030                                         family_name[MED_TAILLE_NOM-1]='\0';
3031                                         myFamily->setName( healName( family_name ));
3032                                         myFamily->setIdentifier(ifamily);
3033                                         ifamily++;
3034                                         vector<string> groupnames;
3035                                         groupnames.push_back(myGroups[i]->getName());
3036                                         myFamily->setNumberOfGroups(1);
3037                                         myFamily->setGroupsNames(&groupnames[0]);
3038                                         myFamilies.push_back(myFamily);
3039                                 }
3040                 }
3041   END_OF_MED(LOC);
3042 }
3043
3044 int MED_MESH_WRONLY_DRIVER22::writeFamilyNumbers() const {
3045   
3046   const char * LOC="int MED_MESH_WRONLY_DRIVER22::writeFamilyNumbers() const : ";
3047   BEGIN_OF_MED(LOC);
3048
3049   med_2_3::med_err err;
3050   
3051   // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArrayNodeFamily DOIT ETRE ENLEVER DE LA CLASSE MESH
3052
3053   { // Node related block
3054     
3055     // We build the array from the families list objects :
3056     int NumberOfNodes = _ptrMesh->getNumberOfNodes() ;
3057 //CCRT    int * MEDArrayNodeFamily = new int[NumberOfNodes] ;
3058     med_2_3::med_int * MEDArrayNodeFamily = new med_2_3::med_int[NumberOfNodes] ;
3059     // family 0 by default
3060     for (int i=0; i<NumberOfNodes; i++)
3061       MEDArrayNodeFamily[i]=0;
3062     //vector<FAMILY*> myFamilies = _ptrMesh->getFamilies(MED_NODE);
3063     vector<FAMILY*> * myFamilies = &_ptrMesh->_familyNode;
3064     int NumberOfNodesFamilies = myFamilies->size() ;
3065    // bool ToDestroy = false;
3066     if (0 == NumberOfNodesFamilies) {
3067    //   ToDestroy = true ;
3068       vector<GROUP*> myGroups = _ptrMesh->getGroups(MED_NODE);
3069       
3070       groupFamilyConverter(myGroups,*myFamilies);
3071                 
3072       NumberOfNodesFamilies=myFamilies->size() ;
3073     }
3074     for (int i=0 ; i<NumberOfNodesFamilies; i++) {
3075       //SCRUTE_MED(i);
3076       //SCRUTE_MED(myFamilies[i]->getName());
3077       int FamilyIdentifier = (*myFamilies)[i]->getIdentifier() ;
3078       int TotalNumber = (*myFamilies)[i]->getNumberOfElements(MED_ALL_ELEMENTS) ;
3079       if ((*myFamilies)[i]->isOnAllElements())
3080         for (int j=0; j<TotalNumber; j++)
3081           MEDArrayNodeFamily[j]=FamilyIdentifier;
3082       else {
3083         const int * Number = (*myFamilies)[i]->getNumber(MED_ALL_ELEMENTS) ;
3084         for (int j=0; j<TotalNumber; j++)
3085           MEDArrayNodeFamily[Number[j]-1]=FamilyIdentifier ;
3086       }
3087     }
3088
3089 //     for(int j=0; j<NumberOfNodes; j++) {
3090 //       SCRUTE_MED(MEDArrayNodeFamily[j]);
3091 //     }
3092
3093 //     if ( !_ptrMesh->getIsAGrid() )
3094
3095       err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
3096                     MEDArrayNodeFamily, NumberOfNodes, med_2_3::MED_NOEUD,
3097                     (med_2_3::med_geometrie_element) MED_NONE);
3098
3099 //     else
3100 //       err = MEDfamGridEcr(_medIdt,
3101 //                        const_cast <char *> (_ptrMesh->_name.c_str()),
3102 //                        MEDArrayNodeFamily,
3103 //                        NumberOfNodes,
3104 //                        MED_FR::MED_LECTURE_ECRITURE,
3105 //                        MED_FR::MED_NOEUD);
3106
3107     if ( err != MED_VALID) 
3108       throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write node family for the |"<< NumberOfNodes
3109                                    << "| nodes in mesh |" 
3110                                    << _ptrMesh->_name.c_str() << "|" ));
3111     delete[] MEDArrayNodeFamily;
3112 //if (true == ToDestroy)
3113 //  for (int i=0; i<NumberOfNodesFamilies; i++)
3114 //        delete (*myFamilies)[i];
3115   }
3116     
3117   { // CELLS RELATED BLOCK
3118     medEntityMesh entity=MED_EN::MED_CELL;
3119     // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArray____Family DOIT ETRE ENLEVER DE LA CLASSE MESH
3120     if ((_ptrMesh->getIsAGrid()) || // PAL18712, GRID::existConnectivity() calls GRID::fillConnectivity() but it is not needed for writing GRID
3121         (_ptrMesh->existConnectivityWithPoly(MED_NODAL,entity)) ||
3122         (_ptrMesh->existConnectivityWithPoly(MED_DESCENDING,entity)))
3123     {
3124       int numberOfTypes           = _ptrMesh->getNumberOfTypesWithPoly(entity) ;
3125       medGeometryElement  * types = _ptrMesh->getTypesWithPoly(entity) ;
3126
3127       // We build the array from the families list objects :
3128       //int NumberOfElements = _ptrMesh->getNumberOfElements(entity, MED_ALL_ELEMENTS);
3129       int NumberOfElements = _ptrMesh->getNumberOfElementsWithPoly(entity, MED_ALL_ELEMENTS);
3130       int * MEDArrayFamily = new int[NumberOfElements] ;
3131       // family 0 by default
3132       for (int i=0; i<NumberOfElements; i++)
3133         MEDArrayFamily[i]=0;
3134       //vector<FAMILY*> myFamilies = _ptrMesh->getFamilies(entity);
3135       vector<FAMILY*> * myFamilies = &_ptrMesh->_familyCell ;
3136       int NumberOfFamilies = myFamilies->size() ;
3137      // bool ToDestroy = false;
3138       if (0 == NumberOfFamilies) {
3139 //      ToDestroy = true ;
3140         vector<GROUP*> myGroups = _ptrMesh->getGroups(entity);
3141         groupFamilyConverter(myGroups,*myFamilies);
3142         NumberOfFamilies=myFamilies->size() ;
3143       }
3144       for (int i=0 ; i<NumberOfFamilies; i++) {
3145         int FamilyIdentifier = (*myFamilies)[i]->getIdentifier() ;
3146         int TotalNumber = (*myFamilies)[i]->getNumberOfElements(MED_ALL_ELEMENTS) ;
3147         if ((*myFamilies)[i]->isOnAllElements())
3148           for (int ii=0; ii<TotalNumber; ii++)
3149             MEDArrayFamily[ii]=FamilyIdentifier;
3150         else {
3151           const int * Number = (*myFamilies)[i]->getNumber(MED_ALL_ELEMENTS) ;
3152           for (int ii=0; ii<TotalNumber; ii++)
3153             MEDArrayFamily[Number[ii]-1]=FamilyIdentifier ;
3154         }
3155       }
3156
3157
3158
3159 //       for (int i=0; i<NumberOfElements; i++)
3160 //      SCRUTE_MED(MEDArrayFamily[i]);
3161
3162
3163       //const int * typeCount = _ptrMesh->getGlobalNumberingIndex(entity);
3164       int offset=0;
3165 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
3166         int lgth=NumberOfElements;
3167         med_2_3::med_int *temp=new med_2_3::med_int[lgth];
3168         for(int i2=0;i2<lgth;i2++)
3169           temp[i2]=(med_2_3::med_int) (MEDArrayFamily[i2]);
3170 #endif
3171       for (int i=0; i<numberOfTypes; i++) {
3172         int typeNumberOfElements=_ptrMesh->getNumberOfElementsWithPoly(entity,types[i]);
3173 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
3174         err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
3175                         //(temp+offset),(typeCount[i+1]-typeCount[i]),
3176                         (temp+offset), typeNumberOfElements,
3177                         //CCRT                  med_2_3::MED_REMP ,
3178 //                      (med_2_3::med_entite_maillage) entity, because Med Memory works only in Nodal connectivity
3179                         (med_2_3::med_entite_maillage) MED_CELL,
3180                         (med_2_3::med_geometrie_element) types[i]);
3181 #else
3182         err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
3183                         (MEDArrayFamily+offset),
3184                         typeNumberOfElements,
3185 //                      (med_2_3::med_entite_maillage) entity, because Med Memory works only in Nodal connectivity
3186                         (med_2_3::med_entite_maillage) MED_CELL,
3187                         (med_2_3::med_geometrie_element) types[i]);
3188 #endif
3189         MESSAGE_MED("OK "<<i);
3190         if ( err != MED_VALID)
3191           throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write family for the |"<< typeNumberOfElements
3192                                        << "| cells of geometric type |" << geoNames[types[i]] <<"|in mesh |"
3193                                        << _ptrMesh->_name.c_str() << "|" ));
3194         offset+=typeNumberOfElements;
3195       }
3196 //CCRT Clutter
3197 //CCRT#if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
3198 //CCRT      delete [] temp;
3199 //CCRT#endif
3200       delete[] MEDArrayFamily ;
3201       delete[] types;
3202 //      if (true == ToDestroy) {
3203 //        int NumberOfFamilies = myFamilies->size();
3204 //        for (int i=0; i<NumberOfFamilies; i++)
3205 //          delete (*myFamilies)[i];
3206 //      }
3207     }
3208   }
3209
3210   if (!_ptrMesh->getIsAGrid() || _ptrMesh->_meshDimension == 3 ) // for grid - only in 3D mesh
3211
3212   { // FACE RELATED BLOCK
3213     medEntityMesh entity=MED_EN::MED_FACE;
3214     // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArray____Family DOIT ETRE ENLEVER DE LA CLASSE MESH
3215     if ((_ptrMesh->getIsAGrid()) || // PAL18712, GRID::existConnectivity() calls GRID::fillConnectivity() but it is not needed for writing GRID
3216         (_ptrMesh->existConnectivityWithPoly(MED_NODAL,entity)) ||
3217         (_ptrMesh->existConnectivityWithPoly(MED_DESCENDING,entity)))
3218     {
3219       int numberOfTypes           = _ptrMesh->getNumberOfTypesWithPoly(entity) ;
3220       medGeometryElement  * types = _ptrMesh->getTypesWithPoly(entity) ;
3221       SCRUTE_MED(numberOfTypes);
3222       
3223       int numberOfElements = _ptrMesh->getNumberOfElementsWithPoly(entity, MED_ALL_ELEMENTS) ;
3224       int * familyArray = new int[numberOfElements] ;
3225       for (int i=0;i<numberOfElements;i++)
3226         familyArray[i]=0;
3227
3228       int numberOfFamilies = _ptrMesh->getNumberOfFamilies(entity) ;
3229       //vector<FAMILY*> myFamilies = _ptrMesh->getFamilies(entity) ;
3230       vector<FAMILY*> * myFamilies = &_ptrMesh->_familyFace ;
3231      // bool ToDestroy = false;
3232       if (0 == numberOfFamilies) {
3233         //ToDestroy = true ;
3234         vector<GROUP*> myGroups = _ptrMesh->getGroups(entity);
3235
3236         groupFamilyConverter(myGroups,*myFamilies);
3237         
3238         numberOfFamilies=myFamilies->size() ;
3239       }
3240       for (int i=0;i<numberOfFamilies;i++) {
3241         int familyNumber = (*myFamilies)[i]->getIdentifier() ;
3242         int numberOfFamilyElements = (*myFamilies)[i]->getNumberOfElements(MED_ALL_ELEMENTS) ;
3243         if ((*myFamilies)[i]->isOnAllElements())
3244           for (int ii=0; ii<numberOfFamilyElements; ii++)
3245             familyArray[ii]=familyNumber;
3246         else {
3247           const int * myFamilyElements = (*myFamilies)[i]->getNumber(MED_ALL_ELEMENTS) ;
3248           for (int ii=0;ii<numberOfFamilyElements;ii++)
3249             familyArray[myFamilyElements[ii]-1]=familyNumber;
3250         }
3251       }
3252
3253       for (int i=0;i<numberOfElements;i++)
3254         SCRUTE_MED(familyArray[i]);
3255
3256 //CCRT Clutter
3257 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
3258       int lgth=numberOfElements;
3259       med_2_3::med_int *temp=new med_2_3::med_int[lgth];
3260       for(int i2=0;i2<lgth;i2++)
3261         temp[i2]=(med_2_3::med_int) (familyArray[i2]);
3262 #endif
3263       SCRUTE_MED(numberOfTypes);
3264       int offset=0;
3265       for (int i=0; i<numberOfTypes; i++) {
3266         int typeNumberOfElements = _ptrMesh->getNumberOfElementsWithPoly(entity,types[i]) ;
3267         SCRUTE_MED(typeNumberOfElements);
3268         SCRUTE_MED(offset);
3269 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
3270         err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
3271                         (temp+offset), typeNumberOfElements,
3272 //                      (med_2_3::med_entite_maillage) entity, because Med Memory works only in Nodal connectivity
3273                         (med_2_3::med_entite_maillage) MED_CELL,
3274                         (med_2_3::med_geometrie_element) types[i]); 
3275 #else
3276         MESSAGE_MED("On est bien la !!! entity = " << entity << " type " << types[i]);
3277
3278         err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
3279                         (familyArray+offset), typeNumberOfElements,
3280 //                      (med_2_3::med_entite_maillage) entity, because Med Memory works only in Nodal connectivity
3281                         (med_2_3::med_entite_maillage) MED_CELL,
3282                         (med_2_3::med_geometrie_element) types[i]);
3283 #endif
3284         if ( err != MED_VALID)
3285           throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write family for the |"<< typeNumberOfElements
3286                                        << "| faces of geometric type |" << geoNames[types[i]] <<"|in mesh |"
3287                                        << _ptrMesh->_name.c_str() << "|" ));
3288         offset+=typeNumberOfElements;
3289       }
3290 //CCRT there was "temp" and "familyArray" for OSF, but only "familyArray" for Linux ...
3291 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
3292       delete [] temp;
3293 //CCRT#endif
3294 #endif
3295       delete[] familyArray ;
3296       delete[] types;
3297 //      if (true == ToDestroy) {
3298 //        int NumberOfFamilies = myFamilies->size();
3299 //          for (int i=0; i<NumberOfFamilies; i++)
3300 //            delete (*myFamilies)[i];
3301 //      }
3302     }
3303   }
3304
3305   if (!_ptrMesh->getIsAGrid() || _ptrMesh->_meshDimension > 1 ) // for grid - only in 3D and 2D mesh
3306
3307   { // EDGE RELATED BLOCK
3308     //medEntityMesh entity=MED_EN::MED_FACE;
3309     medEntityMesh entity=MED_EN::MED_EDGE;
3310     // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArray____Family DOIT ETRE ENLEVER DE LA CLASSE MESH
3311     if  ((_ptrMesh->getIsAGrid()) || // PAL18712, GRID::existConnectivity() calls GRID::fillConnectivity() but it is not needed for writing GRID
3312          ( _ptrMesh->existConnectivity(MED_NODAL,entity) ) ||
3313          ( _ptrMesh->existConnectivity(MED_DESCENDING,entity) ) ) { 
3314
3315       int numberOfTypes           = _ptrMesh->getNumberOfTypes (entity) ;
3316       const medGeometryElement  * types = _ptrMesh->getTypes         (entity) ;
3317       
3318       int numberOfElements = _ptrMesh->getNumberOfElements(entity, MED_ALL_ELEMENTS) ;
3319       int * familyArray = new int[numberOfElements] ;
3320       //      med_2_3::med_int * familyArray = new int[numberOfElements] ;
3321       for (int i=0;i<numberOfElements;i++)
3322         familyArray[i]=0;
3323
3324       int numberOfFamilies = _ptrMesh->getNumberOfFamilies(entity) ;
3325       //vector<FAMILY*> myFamilies = _ptrMesh->getFamilies(entity) ;
3326       vector<FAMILY*> * myFamilies = &_ptrMesh->_familyEdge ;
3327       //bool ToDestroy = false;
3328       if (0 == numberOfFamilies) {
3329         //ToDestroy = true ;
3330         vector<GROUP*> myGroups = _ptrMesh->getGroups(entity);
3331
3332         groupFamilyConverter(myGroups,*myFamilies);
3333         
3334         numberOfFamilies=myFamilies->size() ;
3335
3336       }
3337
3338       for (int i=0;i<numberOfFamilies;i++) {
3339         int familyNumber = (*myFamilies)[i]->getIdentifier() ;
3340         int numberOfFamilyElements = (*myFamilies)[i]->getNumberOfElements(MED_ALL_ELEMENTS) ;
3341         if ((*myFamilies)[i]->isOnAllElements())
3342           for (int ii=0; ii<numberOfFamilyElements; ii++)
3343             familyArray[ii]=familyNumber;
3344         else {
3345           const int * myFamilyElements = (*myFamilies)[i]->getNumber(MED_ALL_ELEMENTS) ;
3346           for (int ii=0;ii<numberOfFamilyElements;ii++)
3347             familyArray[myFamilyElements[ii]-1]=familyNumber;
3348         }
3349       }
3350
3351
3352       for (int i=0;i<numberOfElements;i++)
3353         SCRUTE_MED(familyArray[i]);
3354
3355
3356       const int * typeCount = _ptrMesh->getGlobalNumberingIndex(entity) ;
3357 //CCRT : clutter :
3358 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
3359       int lgth=numberOfElements;
3360       med_2_3::med_int *temp=new med_2_3::med_int[lgth];
3361       for(int i2=0;i2<lgth;i2++)
3362         temp[i2]=(med_2_3::med_int) (familyArray[i2]);
3363 #endif
3364       SCRUTE_MED(numberOfTypes);
3365
3366       for (int i=0; i<numberOfTypes; i++) {
3367         int typeNumberOfElements = typeCount[i+1] - typeCount[i] ;
3368         SCRUTE_MED(typeNumberOfElements);
3369         SCRUTE_MED(typeCount[i+1]);
3370         SCRUTE_MED(typeCount[i]);
3371 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
3372         err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
3373                         (temp+(typeCount[i]-1)), typeNumberOfElements,
3374 //                      (med_2_3::med_entite_maillage) entity, because Med Memory works only in Nodal connectivity
3375                         (med_2_3::med_entite_maillage) MED_CELL,
3376                         (med_2_3::med_geometrie_element) types[i]); 
3377 #else
3378         err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
3379                         (familyArray+(typeCount[i]-1)), typeNumberOfElements,
3380 //                      (med_2_3::med_entite_maillage) entity, because Med Memory works only in Nodal connectivity
3381                         (med_2_3::med_entite_maillage) MED_CELL,
3382                         (med_2_3::med_geometrie_element) types[i]);
3383 #endif
3384         if ( err != MED_VALID)
3385           throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write family for the |"<< _ptrMesh->getNumberOfElements(entity, types[i])
3386                                        << "| edges of geometric type |" << geoNames[types[i]] <<"|in mesh |"
3387                                        << _ptrMesh->_name.c_str() << "|" ));
3388       }
3389
3390 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
3391       delete [] temp;
3392 #endif
3393       delete[] familyArray ;
3394 //      if (true == ToDestroy) {
3395 //        int NumberOfFamilies = myFamilies->size();
3396 //        for (int i=0; i<NumberOfFamilies; i++)
3397 //          delete (*myFamilies)[i];
3398 //      }
3399     }
3400   }
3401     
3402   END_OF_MED(LOC);
3403   return MED_VALID;
3404 }
3405
3406 int MED_MESH_WRONLY_DRIVER22::writeFamilies(vector<FAMILY*> & families ) const
3407 {
3408
3409   const char * LOC="int MED_MESH_WRONLY_DRIVER22::writeFamilies(vector<FAMILY*> families) const : ";
3410   BEGIN_OF_MED(LOC);
3411
3412   med_2_3::med_err err;
3413
3414   MESSAGE_MED(LOC<<" families.size() :"<<families.size());
3415
3416   for (unsigned int i=0; i< families.size(); i++) {
3417
3418     int      numberOfAttributes = families[i]->getNumberOfAttributes ();
3419     string   attributesDescriptions (numberOfAttributes*MED_TAILLE_DESC,'\0');
3420
3421     // Recompose the attributes descriptions arg for MED
3422     for (int j=0; j < numberOfAttributes; j++)
3423     {
3424       string attributeDescription = families[i]->getAttributeDescription(j+1);
3425
3426       if ( attributeDescription.size() > MED_TAILLE_DESC )
3427         throw MEDEXCEPTION( LOCALIZED(STRING(LOC) << "The size of the attribute description n° |"
3428                                       << j+1 << "| of the family |" << families[i]->getName()
3429                                       << "| with identifier |" << families[i]->getIdentifier()
3430                                       << "| is |" << attributeDescription.size()
3431                                       <<"| and is more than |" <<  MED_TAILLE_DESC << "|"));
3432
3433       int length = min(MED_TAILLE_LNOM,(int)attributeDescription.size());
3434       attributesDescriptions.replace(j*MED_TAILLE_DESC,length, attributeDescription,0,length);
3435     }
3436
3437
3438     int      numberOfGroups  = families[i]->getNumberOfGroups();
3439     string   groupsNames(numberOfGroups*MED_TAILLE_LNOM,'\0');
3440
3441     // Recompose the groups names arg for MED
3442     for (int j=0; j < numberOfGroups; j++)
3443     {
3444       string groupName = families[i]->getGroupName(j+1);
3445
3446       if ( groupName.size() > MED_TAILLE_LNOM )
3447         throw MEDEXCEPTION( LOCALIZED(STRING(LOC) << "The size of the group name  n° |"
3448                                       << j+1 << "| of the family |" << families[i]->getName()
3449                                       << "| with identifier |" << families[i]->getIdentifier()
3450                                       << "| is |" << groupName.size()
3451                                       <<"| and is more than |" << MED_TAILLE_LNOM << "|"));
3452
3453       int length = min(MED_TAILLE_LNOM,(int)groupName.size());
3454       groupsNames.replace(j*MED_TAILLE_LNOM,length, groupName,0,length);
3455     }
3456
3457     // test if the family already exists (HDF trick waiting a MED evolution to be replaced)
3458
3459     string dataGroupFam;
3460     if (families[i]->getEntity() == MED_NODE)
3461       dataGroupFam = "/ENS_MAA/"+_meshName+"/FAS/NOEUD/"+families[i]->getName()+"/";  
3462     else
3463       dataGroupFam = "/ENS_MAA/"+_meshName+"/FAS/ELEME/"+families[i]->getName()+"/"; 
3464
3465     SCRUTE_MED("|"<<dataGroupFam<<"|");
3466     err = med_2_3::_MEDdatagroupOuvrir(_medIdt,const_cast <char *> (dataGroupFam.c_str()) ) ;
3467     if ( err < MED_VALID ) {
3468       SCRUTE_MED(err);
3469       if ( families[i]->getName().size() > MED_TAILLE_NOM )
3470         throw MEDEXCEPTION
3471           ( LOCALIZED(STRING(LOC) << "The size of the name of the family |" << i+1
3472                       << "| |" << families[i]->getName()
3473                       << "| with identifier |" << families[i]->getIdentifier()  << "| is |" 
3474                       <<  families[i]->getName().size()  <<"| and is more than |"
3475                       << MED_TAILLE_NOM << "|")) ;
3476
3477       MESSAGE_MED(LOC<<"families[i]->getName().c_str() : "<<families[i]->getName().c_str());
3478       MESSAGE_MED(LOC<<"_meshName.c_str() : "<<_meshName.c_str());
3479       MESSAGE_MED(LOC<<"families[i]->getIdentifier() : "<<families[i]->getIdentifier());
3480       MESSAGE_MED(LOC<<"numberOfAttributes : "<<numberOfAttributes);
3481         
3482       //MESSAGE_MED(LOC<<"families[i]->getAttributesIdentifiers() : "<<families[i]->getAttributesIdentifiers()[0]);
3483       //MESSAGE_MED(LOC<<"families[i]->getAttributesValues() : "<<families[i]->getAttributesValues()[0]);
3484       MESSAGE_MED(LOC<<"attributesDescriptions.c_str() : "<<attributesDescriptions.c_str());
3485       MESSAGE_MED(LOC<<"numberOfGroups : "<<numberOfGroups);
3486       MESSAGE_MED(LOC<<"groupsNames.c_str() : "<<groupsNames.c_str());
3487 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
3488       int lgth=families[i]->getNumberOfAttributes();
3489       med_2_3::med_int *  AttributesIdentifier2 = new med_2_3::med_int[lgth] ;
3490       med_2_3::med_int *  AttributesValues2     = new med_2_3::med_int[lgth] ;
3491       for(med_2_3::med_int i2=0;i2<lgth;i2++)
3492         {
3493           AttributesIdentifier2[i2]=(med_2_3::med_int)(families[i]->getAttributesIdentifiers()[i2]);
3494           AttributesValues2[i2]=(med_2_3::med_int)(families[i]->getAttributesValues()[i2]);
3495         }
3496       err = med_2_3::MEDfamCr( _medIdt, 
3497                               const_cast <char *> ( _meshName.c_str() ),
3498                               const_cast <char *> ( healName(families[i]->getName()).c_str() ),
3499                               families[i]->getIdentifier(), 
3500                               AttributesIdentifier2,
3501                               AttributesValues2,
3502                               const_cast <char *> (attributesDescriptions.c_str()), 
3503                               numberOfAttributes,  
3504                               const_cast <char *> (groupsNames.c_str()), 
3505                               numberOfGroups);
3506       delete [] AttributesIdentifier2;
3507       delete [] AttributesValues2;
3508 #else
3509       err = med_2_3::MEDfamCr( _medIdt, 
3510                               const_cast <char *> ( _meshName.c_str() ),
3511                               const_cast <char *> ( healName(families[i]->getName()).c_str() ),
3512                               families[i]->getIdentifier(), 
3513                               (med_2_3::med_int*)families[i]->getAttributesIdentifiers(),
3514                               (med_2_3::med_int*)families[i]->getAttributesValues(),
3515                               const_cast <char *> (attributesDescriptions.c_str()), 
3516                               numberOfAttributes,  
3517                               const_cast <char *> (groupsNames.c_str()), 
3518                               numberOfGroups);
3519 #endif
3520       SCRUTE_MED(err);
3521       if (err != MED_VALID) 
3522         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't create family |" << families[i]->getName()
3523                                      << "| with identifier |" << families[i]->getIdentifier()
3524                                      << "| groups names |" << groupsNames
3525                                      << "| and  attributes descriptions |" << attributesDescriptions << "|"));
3526     }
3527     else
3528       med_2_3::_MEDdatagroupFermer(_medIdt);
3529
3530   }
3531
3532   END_OF_MED(LOC);
3533
3534   return MED_VALID;
3535 }
3536
3537
3538 // A FAIRE POUR LES NOEUDS ET LES ELEMENTS ret = MEDfamEcr(
3539
3540
3541
3542 /*--------------------- RDWR PART -------------------------------*/
3543
3544 MED_MESH_RDWR_DRIVER22::MED_MESH_RDWR_DRIVER22()
3545 {
3546   this->GENDRIVER::_accessMode = MED_EN::RDWR;
3547 }
3548
3549 MED_MESH_RDWR_DRIVER22::MED_MESH_RDWR_DRIVER22(const string & fileName,
3550                                                MESH * ptrMesh):
3551   MED_MESH_DRIVER(fileName,ptrMesh,RDWR),
3552   IMED_MESH_RDONLY_DRIVER(fileName,ptrMesh),
3553   IMED_MESH_WRONLY_DRIVER(fileName,ptrMesh),
3554   IMED_MESH_RDWR_DRIVER(fileName,ptrMesh),
3555   MED_MESH_DRIVER22(fileName,ptrMesh,RDWR),
3556   MED_MESH_RDONLY_DRIVER22(fileName,ptrMesh),
3557   MED_MESH_WRONLY_DRIVER22(fileName,ptrMesh)
3558 {
3559   
3560   MESSAGE_MED("MED_MESH_RDWR_DRIVER22::MED_MESH_RDWR_DRIVER22(const string & fileName, MESH * ptrMesh) has been created");
3561 }
3562
3563 MED_MESH_RDWR_DRIVER22::MED_MESH_RDWR_DRIVER22(const MED_MESH_RDWR_DRIVER22 & driver):
3564   MED_MESH_DRIVER(driver),
3565   IMED_MESH_RDONLY_DRIVER(driver),
3566   IMED_MESH_WRONLY_DRIVER(driver),
3567   MED_MESH_DRIVER22(driver),
3568   MED_MESH_RDONLY_DRIVER22(driver),
3569   MED_MESH_WRONLY_DRIVER22(driver),
3570   IMED_MESH_RDWR_DRIVER(driver)
3571
3572 {
3573 }
3574
3575 MED_MESH_RDWR_DRIVER22::~MED_MESH_RDWR_DRIVER22() {
3576   //MESSAGE_MED("MED_MESH_RDWR_DRIVER22::MED_MESH_RDWR_DRIVER22(const string & fileName, MESH * ptrMesh) has been destroyed");
3577 }
3578
3579 GENDRIVER * MED_MESH_RDWR_DRIVER22::copy(void) const
3580 {
3581   return new MED_MESH_RDWR_DRIVER22(*this);
3582 }
3583
3584 void MED_MESH_RDWR_DRIVER22::write(void) const
3585 {
3586   MED_MESH_WRONLY_DRIVER22::write();
3587 }
3588 void MED_MESH_RDWR_DRIVER22::read (void)
3589 {
3590   MED_MESH_RDONLY_DRIVER22::read();
3591 }