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