Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[modules/med.git] / src / MEDMEM / MEDMEM_MedMeshDriver.cxx
1 using namespace std;
2 #include "MEDMEM_MedMeshDriver.hxx"
3
4 #include "MEDMEM_DriversDef.hxx"
5
6 #include "MEDMEM_Family.hxx"
7 #include "MEDMEM_Group.hxx"
8 #include "MEDMEM_Coordinate.hxx"
9 #include "MEDMEM_Connectivity.hxx"
10 #include "MEDMEM_Mesh.hxx"
11 #include "MEDMEM_CellModel.hxx"
12
13 extern "C" {
14   extern med_idt _MEDdatagroupOuvrir(med_idt pid, char *nom);
15   extern med_err _MEDdatagroupFermer(med_idt id);
16 }
17 using namespace MED_FR;
18
19 // Every memory allocation made in the MedDriver members function are desallocated in the Mesh destructor 
20
21 void    MED_MESH_DRIVER::setMeshName(const string & meshName) { _meshName = meshName; };
22 string  MED_MESH_DRIVER::getMeshName() const { return _meshName; };
23
24 //---------------------------------- RDONLY PART -------------------------------------------------------------
25
26 //A FAIRE UTILISER LES MAPS...
27 const MED_FR::med_geometrie_element  MED_MESH_DRIVER::all_cell_type[MED_NBR_GEOMETRIE_MAILLE]=
28   { MED_FR::MED_POINT1,MED_FR::MED_SEG2,MED_FR::MED_SEG3,MED_FR::MED_TRIA3,MED_FR::MED_QUAD4,MED_FR::MED_TRIA6,MED_FR::MED_QUAD8,
29     MED_FR::MED_TETRA4,MED_FR::MED_PYRA5,MED_FR::MED_PENTA6,MED_FR::MED_HEXA8,MED_FR::MED_TETRA10,MED_FR::MED_PYRA13,
30     MED_FR::MED_PENTA15, MED_FR::MED_HEXA20};
31
32 const char * const MED_MESH_DRIVER::all_cell_type_tab [MED_NBR_GEOMETRIE_MAILLE]=
33   { "MED_POINT1","MED_SEG2","MED_SEG3","MED_TRIA3","MED_QUAD4","MED_TRIA6","MED_QUAD8",
34     "MED_TETRA4","MED_PYRA5","MED_PENTA6","MED_HEXA8","MED_TETRA10","MED_PYRA13",
35     "MED_PENTA15","MED_HEXA20"};
36
37
38
39
40 void MED_MESH_RDONLY_DRIVER::read(void)
41 {
42   const char * LOC = "MED_MESH_RDONLY_DRIVER::read() : " ;
43   BEGIN_OF(LOC);
44   if (_status!=MED_OPENED)
45     throw MEDEXCEPTION(" ");
46     //throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "The _idt of file " << _fileName << " is : " << _medIdt <<  " (the file is not opened)." )) ;
47
48   _ptrMesh->_name =  _meshName;
49   
50   if (getCOORDINATE()!=MED_VALID)
51     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getCOORDINATE"  )) ;
52  
53   if (getCONNECTIVITY()!=MED_VALID)
54     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getCOONECTIVITY")) ;
55   
56   if (getFAMILY()!=MED_VALID)
57     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getFAMILY"      )) ;
58   
59   updateFamily();
60
61   // we build all groups
62   // on node
63   buildAllGroups(_ptrMesh->_groupNode,_ptrMesh->_familyNode) ;
64   _ptrMesh->_numberOfNodesGroups = _ptrMesh->_groupNode.size() ;
65   // on cell
66   buildAllGroups(_ptrMesh->_groupCell,_ptrMesh->_familyCell) ;
67   _ptrMesh->_numberOfCellsGroups = _ptrMesh->_groupCell.size() ;
68   // on face
69   buildAllGroups(_ptrMesh->_groupFace,_ptrMesh->_familyFace) ;
70   _ptrMesh->_numberOfFacesGroups = _ptrMesh->_groupFace.size() ;
71   // on edge
72   buildAllGroups(_ptrMesh->_groupEdge,_ptrMesh->_familyEdge) ;
73   _ptrMesh->_numberOfEdgesGroups = _ptrMesh->_groupEdge.size() ;
74
75   MESSAGE(LOC<<"Checking of CellModel !!!!!!!");
76
77   int nbOfTypes =  _ptrMesh->_connectivity->_numberOfTypes;
78   for(int i=0;i<nbOfTypes;i++)
79     {
80       MESSAGE(LOC << _ptrMesh->_connectivity->_type[i]) ;
81     }
82
83   END_OF(LOC);
84 }
85
86
87 // A FAIRE : RENVOYER DU VOID
88 int  MED_MESH_RDONLY_DRIVER::getCOORDINATE()
89 {
90   const char * LOC = "MED_MESH_RDONLY_DRIVER::getCOORDINATE() : " ;
91   BEGIN_OF(LOC);
92
93   if (_status==MED_OPENED)
94     {
95       int err ;
96       
97       // Read the dimension of the space for the mesh <_meshName>
98       // to be able to create a COORDINATE object
99       int SpaceDimension = MEDdimLire(_medIdt,const_cast <char *> (_meshName.c_str())) ;
100       if ( SpaceDimension  <= MED_VALID ) 
101         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"The space dimension |" << SpaceDimension << "| seems to be incorrect "
102                                      << "for the mesh : |" << _meshName << "|")) ;
103       _ptrMesh->_spaceDimension = SpaceDimension ;
104
105       
106
107       // Read the number of nodes used in the mesh <_meshName>
108       // to be able to create a COORDINATE object
109       int NumberOfNodes=MEDnEntMaa(_medIdt,
110                                    const_cast <char *> (_meshName.c_str()),
111                                    MED_FR::MED_COOR,
112                                    MED_FR::MED_NOEUD,
113                                    (MED_FR::med_geometrie_element) MED_NONE,
114                                    (MED_FR::med_connectivite)      MED_NONE);
115       if ( NumberOfNodes <= MED_VALID )
116         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"The number of nodes |" << NumberOfNodes << "| seems to be incorrect "
117                                      << "for the mesh : |" << _meshName << "|" )) ;
118       _ptrMesh->_numberOfNodes = NumberOfNodes ;
119
120
121
122       // create a COORDINATE object
123       _ptrMesh->_coordinate = new COORDINATE(MED_EN::MED_FULL_INTERLACE, SpaceDimension, NumberOfNodes);
124       
125       MED_FR::med_repere rep ; // ATTENTION ---> DOIT ETRE INTEGRE DS MESH EF: FAIT NON?
126       string tmp_nom_coord (MED_TAILLE_PNOM*(_ptrMesh->_spaceDimension)+1,'\0');
127       string tmp_unit_coord(MED_TAILLE_PNOM*(_ptrMesh->_spaceDimension)+1,'\0');
128       char * tmp_nom = (const_cast <char *> ( tmp_nom_coord.c_str())  ) ;
129       char * tmp_unit= (const_cast <char *> ( tmp_unit_coord.c_str()) ) ;
130
131       err=MEDcoordLire(_medIdt,
132                        const_cast <char *> (_ptrMesh->_name.c_str()),
133                        _ptrMesh->_spaceDimension,
134                        const_cast <double *> ( _ptrMesh->_coordinate->_coordinate->get(MED_EN::MED_FULL_INTERLACE) ),
135                        MED_FR::MED_FULL_INTERLACE,
136                        MED_ALL,                      // we read all the coordinates
137                        NULL,                         // we don't use a profile
138                        0,                            // so the profile's size is 0
139                        &rep,tmp_nom,tmp_unit);
140       if (err != MED_VALID)
141         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't read coordinates of the |" << NumberOfNodes << "| nodes "
142                                      << "for the mesh : |" << _meshName 
143                                      << "| of space dimension |" << SpaceDimension 
144                                      << "| with units names |"   << tmp_nom
145                                      << "| and units |"          << tmp_unit
146                                      << " |")) ;
147       
148       for (int i=0;i<_ptrMesh->_spaceDimension;i++) {
149         // PG : What about blank !!!!!
150         _ptrMesh->_coordinate->_coordinateName[i]=string(tmp_nom,i*MED_TAILLE_PNOM,MED_TAILLE_PNOM) ;
151         _ptrMesh->_coordinate->_coordinateUnit[i]=string(tmp_unit,i*MED_TAILLE_PNOM,MED_TAILLE_PNOM);
152       }
153
154       // Pourquoi le stocker sous forme de chaîne ?
155       switch (rep)
156         {
157         case MED_FR::MED_CART : 
158           {
159             _ptrMesh->_coordinate->_coordinateSystem = "CARTESIAN";
160             break ;
161           }
162         case MED_FR::MED_CYL :
163           {
164             _ptrMesh->_coordinate->_coordinateSystem = "CYLINDRICAL";
165             break ;
166           }
167         case MED_FR::MED_SPHER :
168           {
169             _ptrMesh->_coordinate->_coordinateSystem = "SPHERICAL";
170             break ;
171           }
172         default :
173           {
174             _ptrMesh->_coordinate->_coordinateSystem = "UNDEFINED"; // ?Erreur ?
175             break ;
176           }
177         }
178
179       // Read the unused optionnal node Names
180       char * tmp_node_name = new char[NumberOfNodes*MED_TAILLE_PNOM+1];
181       tmp_node_name[NumberOfNodes]='\0' ;
182       err=MEDnomLire(_medIdt,const_cast <char*> (_ptrMesh->_name.c_str()),
183                      tmp_node_name,NumberOfNodes*MED_TAILLE_PNOM,MED_FR::MED_NOEUD,
184                      (MED_FR::med_geometrie_element) MED_NONE);
185       if (err == MED_VALID) 
186         INFOS(LOC<<"MED_MESH_RDONLY_DRIVER::getNoeuds() : WARNING : Nodes have names but we do not read them !");
187       delete[] tmp_node_name ;
188
189
190       // ??? Read the unused optionnal node Numbers ???
191       int * tmp_node_number = new int[NumberOfNodes] ;
192       err=MEDnumLire(_medIdt,const_cast <char*> (_ptrMesh->_name.c_str()),
193                      tmp_node_number,NumberOfNodes,MED_NOEUD,(MED_FR::med_geometrie_element)0);
194       if (err == MED_VALID) {
195         INFOS(LOC<<"WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING");
196         INFOS(LOC<<"MED_MESH_RDONLY_DRIVER::getNoeuds() : WARNING : Nodes have numbers but we do not take care of them !");
197         INFOS(LOC<<"WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING");
198         _ptrMesh->_coordinate->_nodeNumber = tmp_node_number ;
199       } else
200         delete[] tmp_node_number ;
201       
202       END_OF(LOC);
203       return MED_VALID;
204     }
205   return MED_ERROR;
206 }
207
208
209 int MED_MESH_RDONLY_DRIVER::getCONNECTIVITY() 
210 {
211   const char * LOC = "MED_MESH_RDONLY_DRIVER::getCONNECTIVITY : " ;
212   BEGIN_OF(LOC);
213
214   if (_status==MED_OPENED)
215     {
216
217       int err = 0 ;
218       // read MED_CELL connectivity
219       CONNECTIVITY * Connectivity     = new CONNECTIVITY(MED_CELL) ;
220       Connectivity->_numberOfNodes    = _ptrMesh->_numberOfNodes ;   // EF : Pourquoi cet attribut est-il dans MESH et non dans COORDINATE ?
221
222       // Try to read nodal connectivity of the cells <Connectivity->_nodal>
223       // then try to read descending connectivity    <Connectivity->_descending>
224       // if neither nodal nor descending connectivity exists
225       // throw an exception.
226       err = getNodalConnectivity(Connectivity) ;
227       if (err!=MED_VALID) {
228         Connectivity->_typeConnectivity = MED_DESCENDING ;
229         err = getDescendingConnectivity(Connectivity) ;
230       } else 
231         getDescendingConnectivity(Connectivity) ; // we read it if there is one
232       
233       if (err!=MED_VALID) {
234         delete Connectivity ;
235         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "We could not read any Connectivity")) ;
236       }
237
238       _ptrMesh->_meshDimension = Connectivity->_entityDimension ; 
239
240       // At this point Connectivity->_typeConnectivity is either NODAL or DESCENDING
241       // If both connectivities are found Connectivity->_typeConnectivity is NODAL
242       // If space dimension is 3 
243       // try to read the nodal connectivity of the faces <ConnectivityFace->_nodal> then
244       // try to read the descending connectivity <ConnectivityFace->_descending>
245       // if there is no descending connectivity and the CELLS are
246       // defined in descending mode then throw an exception
247
248       // PROVISOIRE : if we have some face or edge in MED_MAILLE, we don't read more. There could not be have face or edge !!!!
249
250       if(Connectivity->_constituent==NULL) {
251
252       SCRUTE(_ptrMesh->_meshDimension);
253       if (_ptrMesh->_meshDimension == 3) {
254         MESSAGE(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE DES FACES..." );
255         CONNECTIVITY * ConnectivityFace = new CONNECTIVITY(MED_EN::MED_FACE) ;
256         ConnectivityFace->_typeConnectivity = Connectivity->_typeConnectivity ; // NODAL or DESCENDING
257         SCRUTE(ConnectivityFace->_typeConnectivity);
258         if (Connectivity->_typeConnectivity == MED_DESCENDING) {
259           MESSAGE(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE DESCENDANTE DES FACES" );
260           err = getDescendingConnectivity(ConnectivityFace) ;
261           if (err!=MED_VALID)
262             throw MEDEXCEPTION ( LOCALIZED(STRING(LOC) << "No FACE in descending connectivity")) ;
263           getNodalConnectivity(ConnectivityFace) ; // if any !
264         } else {
265           MESSAGE(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE NODALE DES FACES" );
266           err = getNodalConnectivity(ConnectivityFace) ;
267           if (err!=MED_VALID) { // or error ????? we are in NODAL mode.
268             err = getDescendingConnectivity(ConnectivityFace) ;
269           } else
270             getDescendingConnectivity(ConnectivityFace); // if any !
271         }
272         if (err!=MED_VALID) {
273           delete ConnectivityFace ;
274           MESSAGE(LOC<<"No FACE defined.") ;
275         } else {
276           MESSAGE(LOC<<" SAUVEGARDE DE LA CONNECTIVITE DES FACES DANS L'OBJET CONNECTIVITY" );
277           Connectivity->_constituent=ConnectivityFace ; 
278         }
279       }
280       
281       // read MED_EDGE connectivity
282       if (_ptrMesh->_meshDimension > 1) { // we are in 3 or 2D 
283         MESSAGE(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE DES ARRETES...." );
284         CONNECTIVITY * ConnectivityEdge = new CONNECTIVITY(MED_EDGE) ;
285         ConnectivityEdge->_typeConnectivity = Connectivity->_typeConnectivity ;
286         if (Connectivity->_typeConnectivity == MED_DESCENDING) {
287           MESSAGE(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE DESCENDANTE DES ARRETES" );
288           err = getDescendingConnectivity(ConnectivityEdge) ;
289           if (err!=MED_VALID)
290             throw MEDEXCEPTION ( LOCALIZED(STRING(LOC) << "No EDGE in descending connectivity")) ;
291           getNodalConnectivity(ConnectivityEdge) ; // if any !
292         } else {
293           MESSAGE(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE NODALE DES ARRETES" );
294           err = getNodalConnectivity(ConnectivityEdge) ;
295           if (err!=MED_VALID) { // or error ????? we are in NODAL mode.
296             err = getDescendingConnectivity(ConnectivityEdge) ;
297           } else
298             getDescendingConnectivity(ConnectivityEdge) ; // if any !
299         }
300         if (err!=MED_VALID) {
301           delete ConnectivityEdge ;
302           MESSAGE(LOC<<"No EDGE defined.") ;
303         } else {
304           if (_ptrMesh->_meshDimension == 3)
305             if (Connectivity->_constituent != NULL)
306               Connectivity->_constituent->_constituent=ConnectivityEdge ;
307             else
308               throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<< "EDGE defined but there are no FACE !")) ;
309           else { // IN 2D
310             MESSAGE(LOC<<" SAUVEGARDE DE LA CONNECTIVITE DES ARETES DANS L'OBJET CONNECTIVITY" );
311             Connectivity->_constituent=ConnectivityEdge ;
312           }
313         }
314       }
315       }
316       _ptrMesh->_connectivity  = Connectivity ;                                      
317
318       // all right !
319
320       // we have read all connectivity in file, now we must build descending connectivity if necessary !
321
322       // If connectivity descending is defined, we have nothing to do, all constituent are defined !
323       // If connectivity is only nodal, we must rebuild descending if we have some contituent !
324
325       //A FAIRE !!!!
326 //        if (Connectivity->_descending == NULL)
327 //      if (Connectivity->_constituent != NULL){
328 //        // update Connectivity->_constituent
329 //        CONNECTIVITY * myConstituentOld = Connectivity->_constituent ;
330 //        Connectivity->_constituent = (CONNECTIVITY *)NULL ;
331 //        Connectivity->calculateDescendingConnectivity() ;
332           
333 //      }
334       
335       END_OF(LOC);
336       return MED_VALID;
337     }
338   return MED_ERROR;
339 }
340
341 int MED_MESH_RDONLY_DRIVER::getNodalConnectivity(CONNECTIVITY * Connectivity) 
342 {
343   const char * LOC = "MED_MESH_RDONLY_DRIVER::getNodalConnectivity : " ;
344   BEGIN_OF(LOC);
345   if (_status==MED_OPENED)
346     {
347       // Get the type of entity to work on (previously set in the Connectivity Object)
348       MED_FR::med_entite_maillage Entity = (MED_FR::med_entite_maillage) Connectivity->getEntity();
349
350       // Get the number of cells of each type & store it in <tmp_cells_count>.
351       int * tmp_cells_count = new int[MED_NBR_GEOMETRIE_MAILLE] ;
352       for (int i=1;i<MED_NBR_GEOMETRIE_MAILLE;i++) {                       // EF :ON SCANNE DES GEOMETRIES INUTILES, UTILISER LES MAPS
353         tmp_cells_count[i]=MEDnEntMaa(_medIdt,(const_cast <char *> (_ptrMesh->_name.c_str())),
354                                       MED_FR::MED_CONN,(MED_FR::med_entite_maillage) Entity,
355                                       all_cell_type[i],MED_FR::MED_NOD); 
356
357         // We suppose there is no cells used as faces, this is forbidden !!!
358
359         // Only in version 2.2.x of MED, but before, it's right :-(
360
361         if (tmp_cells_count[i]>0) { 
362           Connectivity->_entityDimension=all_cell_type[i]/100;  
363           Connectivity->_numberOfTypes++;
364         }
365       }
366       
367
368       // well if there is nothing, we quit !
369       if ( Connectivity->_numberOfTypes == 0 ) {
370         delete[] tmp_cells_count ;
371         return MED_ERROR ;
372       }
373
374       // if MED version < 2.2.x, we read only entity with dimention = Connectivity->_entityDimension. Lesser dimension are face or edge !
375
376       char version_med[10] ;
377       if ( MEDfichEntete(_medIdt,MED_FR::MED_VERSION,version_med) != 0 ){
378         // error : we suppose we have not a good med file !
379         delete[] tmp_cells_count ;
380         return MED_ERROR ;
381       }
382
383       // we get version number
384 //        string medVersion(version_med);
385 //        int firstNumber = 
386       int * tmp_edges_count = new int[MED_NBR_GEOMETRIE_MAILLE] ;
387       int numberOfEdgesTypes = 0;
388       int * tmp_faces_count = new int[MED_NBR_GEOMETRIE_MAILLE] ;
389       int numberOfFacesTypes = 0;
390       if ((version_med != "2.2")&(Entity==MED_MAILLE)) {
391         Connectivity->_numberOfTypes=0;
392         for (int i=1;i<MED_NBR_GEOMETRIE_MAILLE;i++) {
393           tmp_faces_count[i]=0;
394           tmp_edges_count[i]=0;
395           if (tmp_cells_count[i]!=0) {
396             int dimension = all_cell_type[i]/100 ;
397             if (Connectivity->_entityDimension==dimension) 
398               Connectivity->_numberOfTypes++ ;
399             
400             if (dimension == 2)
401               if (Connectivity->_entityDimension==3) {
402                 tmp_faces_count[i]=tmp_cells_count[i] ;
403                 tmp_cells_count[i]=0 ;
404                 numberOfFacesTypes++;
405               }
406             if (dimension == 1)
407               if (Connectivity->_entityDimension>dimension) {
408                 tmp_edges_count[i]=tmp_cells_count[i] ;
409                 tmp_cells_count[i]=0;
410                 numberOfEdgesTypes++ ;
411               }
412           }
413         }
414       }
415
416       // bloc to read CELL :
417       {
418       // Prepare an array of indexes on the different cell types to create a MEDSKYLINEARRAY
419       // We use <tmp_cells_count> to calculate <Connectivity->_count> then we release it
420         Connectivity->_geometricTypes = new MED_EN::medGeometryElement [Connectivity->_numberOfTypes]   ;  // Double emploi pour des raisons pratiques 
421         Connectivity->_type           = new CELLMODEL                  [Connectivity->_numberOfTypes]   ;  //
422         Connectivity->_count          = new int                        [Connectivity->_numberOfTypes+1] ;
423         Connectivity->_count[0]       = 1;
424         
425         int size = 0 ; 
426         int TypeNumber=1 ;
427         for (int i=1;i<MED_NBR_GEOMETRIE_MAILLE;i++)  { // no point1 cell type (?)
428           if (tmp_cells_count[i]>0) {
429             
430             Connectivity->_count[TypeNumber]=Connectivity->_count[TypeNumber-1]+tmp_cells_count[i];
431             
432             CELLMODEL t( (MED_EN::medGeometryElement) MED_MESH_DRIVER::all_cell_type[i]) ;
433             Connectivity->_type[TypeNumber-1]=t ;
434             
435             Connectivity->_geometricTypes[TypeNumber-1]=( MED_EN::medGeometryElement) MED_MESH_DRIVER::all_cell_type[i] ;
436             
437             // probleme avec les mailles de dimension < a dimension du maillage :
438             // 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 !!!
439
440               
441             size+=tmp_cells_count[i]*((MED_MESH_DRIVER::all_cell_type[i])%100) ;
442             
443             MESSAGE(LOC
444                     << Connectivity->_count[TypeNumber]-1 << " cells of type " 
445                     << all_cell_type_tab[i] ); 
446             TypeNumber++;
447           }
448         }
449         
450         // Creation of the MEDSKYLINEARRAY
451         Connectivity->_nodal = new MEDSKYLINEARRAY(Connectivity->_count[Connectivity->_numberOfTypes]-1,size) ; 
452         int * NodalIndex = Connectivity->_nodal->getIndex() ;
453         NodalIndex[0]=1 ;
454         
455         // Fill the MEDSKYLINEARRAY by reading the MED file.
456         for (int i=0;i<Connectivity->_numberOfTypes;i++) {
457           int multi = 0 ;
458           MED_FR::med_geometrie_element med_type = (MED_FR::med_geometrie_element) Connectivity->_type[i].getType() ;
459 //        if ( Connectivity->_type[i].getDimension() < Connectivity->_entityDimension) 
460           if (Connectivity->_entity == MED_CELL)
461             if ( Connectivity->_type[i].getDimension() < _ptrMesh->_spaceDimension) 
462               multi=1;
463           
464           //      int NumberOfCell = Connectivity->_count[i+1]-Connectivity->_count[i] ;
465           int NumberOfNodeByCell = Connectivity->_type[i].getNumberOfNodes() ;
466           
467           // initialise index
468           for (int j=Connectivity->_count[i]; j<Connectivity->_count[i+1];j++)
469             NodalIndex[j]=NodalIndex[j-1]+NumberOfNodeByCell ; 
470
471           int tmp_numberOfCells = Connectivity->_count[i+1]-Connectivity->_count[i] ;
472           int * tmp_ConnectivityArray = new int[(NumberOfNodeByCell+multi)*tmp_numberOfCells];
473           
474 //        int err=MEDconnLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
475 //                            Connectivity->_entityDimension,tmp_ConnectivityArray,
476 //                            MED_FR::MED_FULL_INTERLACE,NULL,0,Entity,med_type,MED_FR::MED_NOD);
477           int err=MEDconnLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
478                               _ptrMesh->_spaceDimension,tmp_ConnectivityArray,
479                               MED_FR::MED_FULL_INTERLACE,NULL,0,Entity,med_type,MED_FR::MED_NOD);
480           if ( err != MED_VALID) {
481             delete[] tmp_ConnectivityArray;
482             delete[] tmp_cells_count;
483             delete[] tmp_faces_count;
484             delete[] tmp_edges_count;
485             MESSAGE(LOC<<": MEDconnLire returns "<<err) ;
486             return MED_ERROR ;
487           }
488           int * ConnectivityArray = Connectivity->_nodal->getI(Connectivity->_count[i]) ;
489           for (int j=0; j<tmp_numberOfCells; j++)
490             for (int k=0; k<NumberOfNodeByCell; k++) 
491               ConnectivityArray[j*NumberOfNodeByCell+k]=tmp_ConnectivityArray[j*(NumberOfNodeByCell+multi)+k] ;
492
493           delete[] tmp_ConnectivityArray;
494   
495         }
496       } // end of bloc to read CELL
497
498       delete[] tmp_cells_count; 
499
500       // get Face if any
501       // ===============
502
503       if (numberOfFacesTypes!=0) {
504         CONNECTIVITY * constituent = new CONNECTIVITY(numberOfFacesTypes,MED_EN::MED_FACE) ;
505         constituent->_entityDimension = 2 ;
506         constituent->_count[0]=1 ;
507
508         int size = 0 ; 
509         int size_more_one = 0 ; 
510         int TypeNumber=1 ;
511         for (int i=1;i<MED_NBR_GEOMETRIE_MAILLE;i++)  { // no point1 cell type (?)
512           if (tmp_faces_count[i]>0) {
513             
514             constituent->_count[TypeNumber]=constituent->_count[TypeNumber-1]+tmp_faces_count[i];
515             CELLMODEL t( (MED_EN::medGeometryElement) MED_MESH_DRIVER::all_cell_type[i]) ;
516             constituent->_type[TypeNumber-1]=t ;
517             
518             constituent->_geometricTypes[TypeNumber-1]=( MED_EN::medGeometryElement) MED_MESH_DRIVER::all_cell_type[i] ;
519             
520             size+=tmp_faces_count[i]*((MED_MESH_DRIVER::all_cell_type[i])%100) ;
521             TypeNumber++;
522           }
523         }
524         
525         // Creation of the MEDSKYLINEARRAY
526         constituent->_nodal = new MEDSKYLINEARRAY(constituent->_count[constituent->_numberOfTypes]-1,size) ; 
527         int * NodalIndex = constituent->_nodal->getIndex() ;
528         NodalIndex[0]=1 ;
529         
530         // Fill the MEDSKYLINEARRAY by reading the MED file.
531         for (int i=0;i<constituent->_numberOfTypes;i++) {
532           MED_FR::med_geometrie_element med_type = (MED_FR::med_geometrie_element) constituent->_type[i].getType() ;
533
534           int NumberOfNodeByFace = constituent->_type[i].getNumberOfNodes() ;
535           
536           // initialise index
537           for (int j=constituent->_count[i]; j<constituent->_count[i+1];j++)
538             NodalIndex[j]=NodalIndex[j-1]+NumberOfNodeByFace ; 
539           
540           int tmp_numberOfFaces = constituent->_count[i+1]-constituent->_count[i] ;
541           // Il faut ajouter 1 pour le zero a la lecture !!!
542           int * tmp_constituentArray = new int[(NumberOfNodeByFace+1)*tmp_numberOfFaces] ;
543           
544           int err=MEDconnLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
545                               Connectivity->_entityDimension,tmp_constituentArray,
546                               MED_FR::MED_FULL_INTERLACE,NULL,0,MED_FR::MED_MAILLE,med_type,MED_FR::MED_NOD);
547           if ( err != MED_VALID) {
548             MESSAGE(LOC<<": MEDconnLire returns "<<err) ;
549             delete constituent ;
550             delete[] tmp_constituentArray;
551             delete[] tmp_faces_count;
552             delete[] tmp_edges_count;
553             return MED_ERROR ;
554           }
555
556           int * constituentArray = constituent->_nodal->getI(constituent->_count[i]) ;
557           for (int j=0; j<tmp_numberOfFaces; j++)
558             for (int k=0; k<NumberOfNodeByFace; k++)
559               constituentArray[j*NumberOfNodeByFace+k]=tmp_constituentArray[j*(NumberOfNodeByFace+1)+k] ;
560           
561           delete[] tmp_constituentArray;
562         }
563         
564         Connectivity->_constituent = constituent ;
565       }
566
567       delete[] tmp_faces_count;
568
569       // get Edge if any
570       // ===============
571       if (numberOfEdgesTypes!=0) {
572         CONNECTIVITY * constituent = new CONNECTIVITY(numberOfEdgesTypes,MED_EDGE) ;
573         constituent->_entityDimension = 2 ;
574         constituent->_count[0]=1 ;
575
576         int size = 0 ; 
577         int size_more_one = 0 ; 
578         int TypeNumber=1 ;
579         for (int i=1;i<MED_NBR_GEOMETRIE_MAILLE;i++)  { // no point1 cell type (?)
580           if (tmp_edges_count[i]>0) {
581             
582             constituent->_count[TypeNumber]=constituent->_count[TypeNumber-1]+tmp_edges_count[i];
583             CELLMODEL t( (MED_EN::medGeometryElement) MED_MESH_DRIVER::all_cell_type[i]) ;
584             constituent->_type[TypeNumber-1]=t ;
585             
586             constituent->_geometricTypes[TypeNumber-1]=( MED_EN::medGeometryElement) MED_MESH_DRIVER::all_cell_type[i] ;
587             
588             size+=tmp_edges_count[i]*((MED_MESH_DRIVER::all_cell_type[i])%100) ;
589             TypeNumber++;
590           }
591         }
592         
593         // Creation of the MEDSKYLINEARRAY
594         constituent->_nodal = new MEDSKYLINEARRAY(constituent->_count[constituent->_numberOfTypes]-1,size) ; 
595         int * NodalIndex = constituent->_nodal->getIndex() ;
596         NodalIndex[0]=1 ;
597         
598         // Fill the MEDSKYLINEARRAY by reading the MED file.
599         for (int i=0;i<constituent->_numberOfTypes;i++) {
600           MED_FR::med_geometrie_element med_type = (MED_FR::med_geometrie_element) constituent->_type[i].getType() ;
601
602           int NumberOfNodeByEdge = constituent->_type[i].getNumberOfNodes() ;
603           
604           // initialise index
605           for (int j=constituent->_count[i]; j<constituent->_count[i+1];j++)
606             NodalIndex[j]=NodalIndex[j-1]+NumberOfNodeByEdge ; 
607           
608           int tmp_numberOfEdges = constituent->_count[i+1]-constituent->_count[i] ;
609           // Il faut ajouter 1 pour le zero a la lecture !!!
610           int * tmp_constituentArray = new int[(NumberOfNodeByEdge+1)*tmp_numberOfEdges] ;
611           
612           int err=MEDconnLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
613                               Connectivity->_entityDimension,tmp_constituentArray,
614                               MED_FR::MED_FULL_INTERLACE,NULL,0,MED_FR::MED_MAILLE,med_type,MED_FR::MED_NOD);
615           if ( err != MED_VALID) {
616             MESSAGE(LOC<<": MEDconnLire returns "<<err) ;
617             delete constituent ;
618             delete[] tmp_constituentArray;
619             delete[] tmp_edges_count;
620             return MED_ERROR ;
621           }
622
623           int * constituentArray = constituent->_nodal->getI(constituent->_count[i]) ;
624           for (int j=0; j<tmp_numberOfEdges; j++)
625             for (int k=0; k<NumberOfNodeByEdge; k++)
626               constituentArray[j*NumberOfNodeByEdge+k]=tmp_constituentArray[j*(NumberOfNodeByEdge+1)+k] ;
627           
628           delete[] tmp_constituentArray;
629         }
630
631         if (Connectivity->_entityDimension == 3) {
632           if (Connectivity->_constituent==NULL)
633             throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Edges are defined but there are no Faces !"));
634           Connectivity->_constituent->_constituent = constituent ;
635         } else 
636           Connectivity->_constituent = constituent ;
637       }
638
639       delete[] tmp_edges_count; 
640       
641       return MED_VALID;
642     }
643   return MED_ERROR;
644 }
645
646 int MED_MESH_RDONLY_DRIVER::getDescendingConnectivity(CONNECTIVITY * Connectivity) 
647 {
648   const char * LOC = "MED_MESH_RDONLY_DRIVER::getDescendingConnectivity " ;
649   if (_status==MED_OPENED)
650     {
651       MESSAGE(LOC<<" Not implemented !");
652     }
653   return MED_ERROR;
654 }
655
656 //  int  MED_MESH_RDONLY_DRIVER::getElementFamilies(CONNECTIVITY * Connectivity)
657 //  {
658 //    int err = 0 ;
659 //    int NumberOfTypes = Connectivity->_numberOfTypes ;
660 //    int * Count = Connectivity->_count ;
661 //    medGeometryElement * GeometricTypes= Connectivity->_geometricTypes ;
662 //    int ** tmp_array = new int*[NumberOfTypes] ;
663 //    for (int i=0; i<NumberOfTypes; i++) 
664 //      tmp_array[i]=NULL ;
665 //    for (int i=0; i<NumberOfTypes; i++) {
666 //      int NumberOfElements = Count[i+1]-Count[i] ;
667 //      int * tmp_families_number = new int[NumberOfElements] ;
668 //      err = MEDfamLire(_medIdt,const_cast <char*> (_ptrMesh->_name.c_str()),
669 //                   tmp_families_number,NumberOfElements,
670 //                   Connectivity->_entity,GeometricTypes[i]);
671 //      tmp_array[i]=tmp_families_number ;
672 //      if (err != MED_VALID) {
673 //        for (int j=0; j<NumberOfTypes; j++)
674 //      if (tmp_array[j] != NULL)
675 //        delete[] tmp_array[j] ;
676 //        delete[] tmp_array ;
677 //        throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER::getElementFamilies : No Family in element GeometricTypes[i]");
678 //      }
679 //    }
680   
681 //    if (Connectivity->_entity == MED_CELL)
682 //      _ptrMesh->_MEDArrayCellFamily = tmp_array ;
683 //    else if (Connectivity->_entity == MED_FACE)
684 //      _ptrMesh->_MEDArrayFaceFamily = tmp_array ;
685 //    else if (Connectivity->_entity == MED_EDGE)
686 //      _ptrMesh->_MEDArrayEdgeFamily = tmp_array ;
687   
688 //    return MED_VALID ;
689 //  }
690
691 int  MED_MESH_RDONLY_DRIVER::getFAMILY() 
692 {
693   const char * LOC = "MED_MESH_RDONLY_DRIVER::getFAMILY() : " ;
694   BEGIN_OF(LOC);
695
696   if (_status==MED_OPENED) {
697     int err = 0 ;
698     // read number :
699     // NODE :
700     err = getNodesFamiliesNumber() ; // error only if (_status!=MED_OPENED), other case exeception !
701     // CELL
702     _ptrMesh->_MEDArrayCellFamily = new (int*)[_ptrMesh->_connectivity->_numberOfTypes] ; // ET SI IL N'Y A PAS DE CELLS ?
703     getCellsFamiliesNumber(_ptrMesh->_MEDArrayCellFamily,_ptrMesh->_connectivity) ;
704     if (_ptrMesh->_connectivity->_constituent != NULL) {
705       if (_ptrMesh->_connectivity->_constituent->_entity == MED_EN::MED_FACE) {
706         // FACE
707         _ptrMesh->_MEDArrayFaceFamily = new (int*)[_ptrMesh->_connectivity->_constituent->_numberOfTypes] ;
708         getCellsFamiliesNumber(_ptrMesh->_MEDArrayFaceFamily,_ptrMesh->_connectivity->_constituent) ;
709       } else {
710         // EDGE in 2D
711         _ptrMesh->_MEDArrayEdgeFamily = new (int*)[_ptrMesh->_connectivity->_constituent->_numberOfTypes] ;
712         getCellsFamiliesNumber(_ptrMesh->_MEDArrayEdgeFamily,_ptrMesh->_connectivity->_constituent) ;
713       }
714       // EDGE in 3D
715       if (_ptrMesh->_connectivity->_constituent->_constituent != NULL) {
716         _ptrMesh->_MEDArrayEdgeFamily = new (int*)[_ptrMesh->_connectivity->_constituent->_constituent->_numberOfTypes] ;
717         getCellsFamiliesNumber(_ptrMesh->_MEDArrayEdgeFamily,_ptrMesh->_connectivity->_constituent) ; // we are in 3D !
718       }
719     }
720
721     // Creation of the families
722     int NumberOfFamilies = MEDnFam(_medIdt,const_cast <char *> (_meshName.c_str()),0,MED_FR::MED_FAMILLE) ;
723     if ( NumberOfFamilies < 1 ) // at least family 0 must exist 
724       throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"There is no FAMILY, FAMILY 0 must exists" ));
725
726     vector<FAMILY*> &NodeFamilyVector = _ptrMesh->_familyNode ;
727     vector<FAMILY*> &CellFamilyVector = _ptrMesh->_familyCell ;
728     vector<FAMILY*> &FaceFamilyVector = _ptrMesh->_familyFace ;
729     vector<FAMILY*> &EdgeFamilyVector = _ptrMesh->_familyEdge ;
730
731     int numberOfNodesFamilies = 0 ;
732     int numberOfCellsFamilies = 0 ;
733     int numberOfFacesFamilies = 0 ;
734     int numberOfEdgesFamilies = 0 ;
735
736     for (int i=0;i<NumberOfFamilies;i++) {
737       
738       int NumberOfAttributes = MEDnFam(_medIdt,const_cast <char *> (_meshName.c_str()),i+1,MED_FR::MED_ATTR) ;
739       if (NumberOfAttributes < 0) 
740         throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER::getFAMILY() : NumberOfAttributes" );
741     
742       int NumberOfGroups = MEDnFam(_medIdt,const_cast <char *> (_meshName.c_str()),i+1,MED_FR::MED_GROUPE) ;
743       if (NumberOfGroups < 0)
744         throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER::getFAMILY() : NumberOfGroups" );
745       
746       int FamilyIdentifier ;
747       string FamilyName(MED_TAILLE_NOM,' ');
748       int *  AttributesIdentifier = new int[NumberOfAttributes] ;
749       int *  AttributesValues     = new int[NumberOfAttributes] ;
750       string AttributesDescription(MED_TAILLE_DESC*NumberOfAttributes,' ') ;
751       string GroupsNames(MED_TAILLE_LNOM*NumberOfGroups,' ') ;
752       err = MEDfamInfo(_medIdt,const_cast <char *> (_meshName.c_str()),
753                        i+1,const_cast <char *> (FamilyName.c_str()),
754                        &FamilyIdentifier,AttributesIdentifier,AttributesValues,
755                        const_cast <char *> (AttributesDescription.c_str()),
756                        &NumberOfAttributes,
757                        const_cast <char *> (GroupsNames.c_str()),&NumberOfGroups
758                        );
759       //SCRUTE(GroupsNames);
760       if (err != MED_VALID)
761         throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER::getFAMILY() : ERROR when get FAMILY informations" );
762       if (FamilyIdentifier != 0 ) {
763         FAMILY * Family = new FAMILY(_ptrMesh,FamilyIdentifier,FamilyName,
764                                      NumberOfAttributes,AttributesIdentifier,
765                                      AttributesValues,AttributesDescription,
766                                      NumberOfGroups,GroupsNames) ;
767         switch (Family->getEntity()) {
768         case MED_EN::MED_NODE :
769           NodeFamilyVector.push_back(Family) ;
770           numberOfNodesFamilies++ ;
771           break ;
772         case MED_EN::MED_CELL :
773           CellFamilyVector.push_back(Family) ;
774           numberOfCellsFamilies++ ;
775           break ;
776         case MED_EN::MED_FACE :
777           FaceFamilyVector.push_back(Family) ;
778           numberOfFacesFamilies++ ;
779           break ;
780         case MED_EN::MED_EDGE :
781           EdgeFamilyVector.push_back(Family) ;
782           numberOfEdgesFamilies++ ;
783           break ;
784         }
785       }
786     }
787     _ptrMesh->_numberOfNodesFamilies = numberOfNodesFamilies ;
788     _ptrMesh->_numberOfCellsFamilies = numberOfCellsFamilies ;
789     _ptrMesh->_numberOfFacesFamilies = numberOfFacesFamilies ;
790     _ptrMesh->_numberOfEdgesFamilies = numberOfEdgesFamilies ;
791     
792     END_OF(LOC);
793     return MED_VALID ;
794   }
795   return MED_ERROR;
796 }
797
798 int  MED_MESH_RDONLY_DRIVER::getNodesFamiliesNumber() 
799 {
800   const char * LOC = "MED_MESH_RDONLY_DRIVER::getNodesFamiliesNumber() : " ;
801   BEGIN_OF(LOC);
802   if (_status==MED_OPENED) {
803     int err = 0 ;
804     int * tmp_NodesFamilies = new int[_ptrMesh->getNumberOfNodes()] ;
805     err = MEDfamLire(_medIdt,(const_cast <char *> (_ptrMesh->_name.c_str())), 
806                      tmp_NodesFamilies, _ptrMesh->getNumberOfNodes(),
807                      MED_NOEUD,(enum MED_FR::med_geometrie_element) MED_NONE);
808     if ( err != MED_VALID) {
809       delete[] tmp_NodesFamilies ;
810       throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "There is no family for the |"<< _ptrMesh->getNumberOfNodes() 
811                                    << "| nodes in mesh |" 
812                                    << _ptrMesh->_name.c_str() << "|" ));
813     }
814     _ptrMesh->_MEDArrayNodeFamily = tmp_NodesFamilies ;
815     END_OF(LOC);
816     return MED_VALID;
817   }
818   return MED_ERROR;
819 }
820
821 int  MED_MESH_RDONLY_DRIVER::getCellsFamiliesNumber(int **MEDArrayFamily,CONNECTIVITY *Connectivity) 
822 {
823   const char * LOC = "MED_MESH_RDONLY_DRIVER::getCellsFamiliesNumber " ;
824   BEGIN_OF(LOC);
825
826   if (_status==MED_OPENED) {
827     int i, err = 0 ;
828     for (i=0;i<Connectivity->_numberOfTypes;i++)        {
829       int NumberOfCell = Connectivity->_count[i+1]-Connectivity->_count[i] ;
830       int * fam = new int[NumberOfCell] ;
831
832       err=MEDfamLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
833                      fam,NumberOfCell,
834                      (MED_FR::med_entite_maillage) Connectivity->_entity,
835                      (MED_FR::med_geometrie_element) Connectivity->_geometricTypes[i]);
836
837       // provisoire : si les faces ou les aretes sont des mailles !!!
838       if (err != MED_VALID) {
839         MESSAGE(LOC<<"search face/edge family on cell !!!");
840         err=MEDfamLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
841                        fam,NumberOfCell,
842                        MED_FR::MED_MAILLE,
843                        (MED_FR::med_geometrie_element) Connectivity->_geometricTypes[i]);
844       }
845
846       MEDArrayFamily[i]=fam ;
847       if (err != MED_VALID) 
848         throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Family not found for entity "<<Connectivity->_entity<<" and geometric type "<<Connectivity->_geometricTypes[i]));
849       
850     }
851     return MED_VALID;
852   }
853   return MED_ERROR;  
854 }
855
856 void MED_MESH_RDONLY_DRIVER::buildAllGroups(vector<GROUP*> & Groups, vector<FAMILY*> & Families) 
857 {
858   const char * LOC = "MED_MESH_RDONLY_DRIVER::buildAllGroups " ;
859   BEGIN_OF(LOC);
860
861   int numberOfFamilies = Families.size() ;
862   //SCRUTE(numberOfFamilies);
863   map< string,list<FAMILY*> > groupsNames ;
864   for(int i=0; i<numberOfFamilies; i++) {
865     FAMILY * myFamily = Families[i] ;
866     int numberOfGroups_ = myFamily->getNumberOfGroups();
867     //SCRUTE(i);
868     //SCRUTE(numberOfGroups_);
869     for (int j=0; j<numberOfGroups_; j++) {
870       //SCRUTE(j);
871       //SCRUTE(myFamily->getGroupName(j+1));
872       groupsNames[myFamily->getGroupName(j+1)].push_back(myFamily);
873     }
874   }
875   int numberOfGroups = groupsNames.size() ;
876   SCRUTE(numberOfGroups);
877   Groups.resize(numberOfGroups);
878   map< string,list<FAMILY*> >::const_iterator currentGroup ;
879   int it = 0 ;
880   for(currentGroup=groupsNames.begin();currentGroup!=groupsNames.end();currentGroup++) {
881     GROUP * myGroup = new GROUP((*currentGroup).first,(*currentGroup).second) ;
882 //     GROUP * myGroup = new GROUP() ;
883 //     myGroup->setName((*currentGroup).first);
884 //     SCRUTE(myGroup->getName());
885 //     //myGroup->setMesh(_ptrMesh);
886 //     myGroup->init((*currentGroup).second);
887     Groups[it]=myGroup;
888     //SCRUTE(it);
889     it++;
890   }
891
892   END_OF(LOC);
893 }
894
895 void MED_MESH_RDONLY_DRIVER::updateFamily()
896 {
897   const char * LOC = "MED_MESH_RDONLY_DRIVER::updateFamily() " ;
898   BEGIN_OF(LOC);
899
900   // we need to update family on constituent if we have constituent, but no 
901   // descending connectivity, so, we must calculate all constituent and
902   // numbering correctly family !
903   _ptrMesh->_connectivity->updateFamily(_ptrMesh->_familyFace) ; // in 2d, do nothing
904   _ptrMesh->_connectivity->updateFamily(_ptrMesh->_familyEdge) ; // in 3d, do nothing
905
906   END_OF(LOC);
907 }
908
909
910 void MED_MESH_RDONLY_DRIVER::write( void ) const { INFOS("MED_MESH_RDONLY_DRIVER::write : Can't write with a RDONLY driver !");}
911
912 /*--------------------- RDWR PART -------------------------------*/
913
914 void MED_MESH_RDWR_DRIVER::write(void) const { MED_MESH_WRONLY_DRIVER::write(); } 
915 void MED_MESH_RDWR_DRIVER::read (void)       { MED_MESH_RDONLY_DRIVER::read(); } 
916
917
918 /*--------------------- WRONLY PART -------------------------------*/
919 void MED_MESH_WRONLY_DRIVER::read (void)       {   INFOS("MED_MESH_WRONLY_DRIVER::write : Can't read with a WRONLY driver !");} 
920
921 void MED_MESH_WRONLY_DRIVER::write(void) const { 
922   const char * LOC = "void MED_MESH_WRONLY_DRIVER::write(void) const : ";
923   BEGIN_OF(LOC);
924
925   // we must first create mesh !!
926   MESSAGE(LOC << "MeshName : |" << _meshName << "| FileName : |"<<_fileName<<"| MedIdt : | "<< _medIdt << "|");
927
928   if (writeCoordinates()!=MED_VALID)
929     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeCoordinates()"  )) ;
930
931   if (writeConnectivities(MED_EN::MED_CELL)!=MED_VALID)
932     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeConnectivities(MED_CELL)"  )) ;
933   if (writeConnectivities(MED_EN::MED_FACE)!=MED_VALID)
934     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeConnectivities(MED_FACE)"  )) ;
935   if (writeConnectivities(MED_EN::MED_EDGE)!=MED_VALID)
936     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeConnectivities(MED_EDGE)"  )) ;
937
938   if (writeFamilyNumbers() !=MED_VALID)
939     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilyNumbers()"  )) ;
940  
941   // well we must first write zero family :
942   if (_status==MED_OPENED) {
943     int err ;
944     // test if the family already exists (HDF trick waiting a MED evolution to be replaced)
945     string dataGroupFam = "/ENS_MAA/"+_meshName+"/FAS/FAMILLE_0/";  
946     SCRUTE("|"<<dataGroupFam<<"|");
947     if ( err =_MEDdatagroupOuvrir(_medIdt,const_cast <char *> (dataGroupFam.c_str()) ) < MED_VALID ) {
948       SCRUTE(err);
949       
950       err = MEDfamCr( _medIdt, const_cast <char *> ( _meshName.c_str() ),
951                       "FAMILLE_0", 0,
952                       (int*)NULL, (int*)NULL, (char*)NULL, 0,
953                       (char*)NULL, 0);
954       
955       if ( err != MED_VALID) 
956         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't create family |FAMILLE_0| with identifier |0| groups names || and  attributes descriptions ||")) ;
957     }
958     else
959       _MEDdatagroupFermer(_medIdt);
960      
961   }
962
963   MESSAGE(LOC<<"writeFamilies(_ptrMesh->_familyNode)");
964   if (writeFamilies(_ptrMesh->_familyNode) !=MED_VALID)
965     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilies(_ptrMesh->_familyNode)"  )) ;
966
967   MESSAGE(LOC<<"writeFamilies(_ptrMesh->_familyCell)");
968   if (writeFamilies(_ptrMesh->_familyCell) !=MED_VALID)
969     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilies(_ptrMesh->_familyCell)"  )) ;
970
971   MESSAGE(LOC<<"writeFamilies(_ptrMesh->_familyFace)");
972   if (writeFamilies(_ptrMesh->_familyFace) !=MED_VALID)
973     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilies(_ptrMesh->_familyFace)"  )) ;
974
975   MESSAGE(LOC<<"writeFamilies(_ptrMesh->_familyEdge)");
976   if (writeFamilies(_ptrMesh->_familyEdge) !=MED_VALID)
977     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilies(_ptrMesh->_familyEdge)"  )) ;
978
979   END_OF(LOC);
980
981
982
983 int MED_MESH_WRONLY_DRIVER::writeCoordinates() const {
984  
985   const char * LOC = "int MED_MESH_WRONLY_DRIVER::writeCoordinates() const : ";
986   BEGIN_OF(LOC);
987   if (_status==MED_OPENED) {
988
989     MED_FR::med_err err = MED_ERROR;
990     MED_FR::med_repere rep;
991     string tmp_name,tmp_unit;
992     
993     // Recompose the <_spaceDimension> strings in 1 string 
994     for (int i=0;i<_ptrMesh->_spaceDimension;i++) {
995       tmp_name += _ptrMesh->_coordinate->_coordinateName[i]; 
996       tmp_unit += _ptrMesh->_coordinate->_coordinateUnit[i]; 
997
998     }
999
1000     // Test if the mesh <_meshName> already exists
1001     // If it doesn't exists create it
1002     // If it already exists verify if its dimension is the same as <_ptrMesh->_spaceDimension>
1003     // rem : <_meshName> is the driver meshName not <ptrMesh->_meshName>
1004     int dim = MEDdimLire(_medIdt, const_cast <char *> (_meshName.c_str()) );
1005     if (dim < MED_VALID) 
1006       if (MEDmaaCr(_medIdt,const_cast <char *> (_meshName.c_str()),_ptrMesh->_spaceDimension) != 0 )
1007         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Unable to create Mesh : |" << _meshName << "|"));
1008       else 
1009         {
1010           MESSAGE(LOC<<"Mesh "<<_meshName<<" created in file "<<_fileName<<" !");
1011         }
1012     else if (dim != _ptrMesh->_spaceDimension) 
1013       throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Mesh |" << _meshName.c_str() << "| already exists in file |" << _fileName
1014                                    << "| with dimension |" << dim << "| but the dimension of the mesh we want to write is |"
1015                                    << _ptrMesh->_spaceDimension <<"|" )) ;
1016     
1017     // Pourquoi le stocker sous forme de chaîne ?
1018     const string & coordinateSystem = _ptrMesh->_coordinate->_coordinateSystem;
1019     if      (coordinateSystem  == "CARTESIAN") 
1020       rep = MED_FR::MED_CART;
1021     else if ( coordinateSystem == "CYLINDRICAL")
1022       rep = MED_FR::MED_CYL;
1023     else if ( coordinateSystem == "SPHERICAL" )
1024       rep = MED_FR::MED_SPHER;
1025     else
1026       throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Mesh |" << _meshName.c_str() << "| doesn't have a valid coordinate system : |" 
1027                                    << _ptrMesh->_coordinate->_coordinateSystem
1028                                    << "|" )) ;  
1029       
1030     err = MEDcoordEcr(_medIdt, const_cast <char *> (_meshName.c_str()),
1031                       _ptrMesh->_spaceDimension, 
1032                       const_cast <double *> ( _ptrMesh->_coordinate->_coordinate->get(MED_EN::MED_FULL_INTERLACE) ), 
1033                       MED_FR::MED_FULL_INTERLACE, 
1034                       _ptrMesh->_numberOfNodes,                 //  _ptrMesh->_coordinate->_numberOfNodes
1035                       MED_FR::MED_REMP,    
1036                       rep,
1037                       const_cast <char *> (tmp_name.c_str()), 
1038                       const_cast <char *> (tmp_unit.c_str()) 
1039                       );  
1040
1041     if (err<0) 
1042       throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write coordinates of mesh |" << _meshName.c_str() << "| in file |" << _fileName
1043                                    << "| with dimension |"  << _ptrMesh->_spaceDimension <<"| and" 
1044                                    << " with units names |"  << tmp_name
1045                                    << "| and units |"       << tmp_unit
1046                                    << " |")) ;    
1047     
1048     END_OF(LOC);
1049     
1050     return MED_VALID;
1051   }
1052
1053   MESSAGE (LOC<<" Not open !!!");
1054   return MED_ERROR;
1055 }
1056
1057
1058
1059
1060 int MED_MESH_WRONLY_DRIVER::writeConnectivities(medEntityMesh entity) const {
1061   
1062   const char * LOC="int MED_MESH_WRONLY_DRIVER::writeConnectivities() const : ";
1063   BEGIN_OF(LOC);
1064
1065   MED_FR::med_err err;
1066   
1067   if (_status==MED_OPENED) {
1068     
1069     // REM SI LA METHODE EST APPELEE DIRECTEMENT ET QUE LE MAILLAGE N'EST PAS CREE IL Y A PB !
1070     
1071     // A FAIRE : A tester surtout dans les methodes de MESH.
1072     //    if ( _ptrMesh->_connectivity == (CONNECTIVITY *) MED_INVALID )
1073     if ( _ptrMesh->_connectivity == (CONNECTIVITY *) NULL )
1074       throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "The connectivity is not defined in the MESH object ")) ;
1075     
1076     if   ( _ptrMesh->existConnectivity(MED_NODAL,entity) ) { 
1077
1078       int numberOfTypes           = _ptrMesh->getNumberOfTypes (entity) ;
1079       medGeometryElement  * types = _ptrMesh->getTypes         (entity) ;
1080     
1081       for (int i=0; i<numberOfTypes; i++) {
1082       
1083         int    numberOfElements = _ptrMesh->getNumberOfElements (entity,types[i]);
1084         int * connectivity      = _ptrMesh->getConnectivity     (MED_EN::MED_FULL_INTERLACE, 
1085                                                                  MED_NODAL, entity, types[i]); // ?? et SI MED_NODAL n'existe pas, recalcul auto ??
1086       
1087         // Pour l'instant la class utilise le multi.....
1088         int multi = 0 ;
1089         if (entity==MED_EN::MED_CELL)
1090           if ( (types[i]/ 100) < _ptrMesh->_spaceDimension) 
1091             multi=1 ;
1092         int numberOfNodes = types[i]%100 ;
1093         int * connectivityArray = new int[numberOfElements*(numberOfNodes+multi)];
1094         for (int j=0 ; j<numberOfElements; j++) {
1095           for (int k=0; k<numberOfNodes; k++)
1096             connectivityArray[j*(numberOfNodes+multi)+k]=connectivity[j*numberOfNodes+k] ;
1097           if (multi>0)
1098             connectivityArray[j*(numberOfNodes+multi)+numberOfNodes]=0;
1099         }
1100         err = MEDconnEcr( _medIdt, const_cast <char *> ( _meshName.c_str()), _ptrMesh->_spaceDimension,
1101                           connectivityArray, MED_FR::MED_FULL_INTERLACE , numberOfElements,
1102                           MED_FR::MED_REMP,
1103                           (MED_FR::med_entite_maillage  ) entity, 
1104                           (MED_FR::med_geometrie_element) types[i], MED_NOD );
1105         delete[] connectivityArray ;
1106
1107         if (err<0) // ETENDRE LES EXPLICATIONS
1108           throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write connectivities of mesh |" << _meshName.c_str() << "| in file |" << _fileName
1109                                        << "| with dimension |"  << _ptrMesh->_spaceDimension <<"| and" 
1110                                        )) ;
1111       }
1112     }
1113     // Connctivity descending :
1114     if   ( _ptrMesh->existConnectivity(MED_DESCENDING,entity) ) { 
1115       
1116       int numberOfTypes           = _ptrMesh->getNumberOfTypes (entity) ;
1117       medGeometryElement  * types = _ptrMesh->getTypes         (entity) ;
1118       
1119       for (int i=0; i<numberOfTypes; i++) {
1120         
1121         int    numberOfElements = _ptrMesh->getNumberOfElements (entity,types[i]);
1122         int * connectivity = _ptrMesh->getConnectivity(MED_EN::MED_FULL_INTERLACE, MED_DESCENDING, entity, types[i]); 
1123       
1124         // Pour l'instant la class utilise le multi.....
1125         err = MEDconnEcr( _medIdt, const_cast <char *> ( _meshName.c_str()), _ptrMesh->_spaceDimension,
1126                           connectivity, MED_FR::MED_FULL_INTERLACE , numberOfElements,
1127                           MED_FR::MED_REMP,
1128                           (MED_FR::med_entite_maillage  ) entity, 
1129                           (MED_FR::med_geometrie_element) types[i], MED_DESC );
1130         
1131         if (err<0) // ETENDRE LES EXPLICATIONS
1132           throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write connectivities of mesh |" << _meshName.c_str() << "| in file |" << _fileName
1133                                        << "| with dimension |"  << _ptrMesh->_spaceDimension <<"| and" 
1134                                        )) ;
1135             
1136       }
1137     }
1138     END_OF(LOC);
1139     return MED_VALID;
1140   }
1141   return MED_ERROR;
1142 }
1143
1144 int MED_MESH_WRONLY_DRIVER::writeFamilyNumbers() const {
1145   
1146   const char * LOC="int MED_MESH_WRONLY_DRIVER::writeFamilyNumbers() const : ";
1147   BEGIN_OF(LOC);
1148
1149   MED_FR::med_err err;
1150   
1151   if (_status==MED_OPENED) {
1152
1153     // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArrayNodeFamily DOIT ETRE ENLEVER DE LA CLASSE MESH
1154     err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
1155                     _ptrMesh->_MEDArrayNodeFamily, _ptrMesh->getNumberOfNodes(),MED_FR::MED_REMP ,
1156                     MED_NOEUD,(enum MED_FR::med_geometrie_element) MED_NONE); 
1157     if ( err != MED_VALID) 
1158       throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write node family for the |"<< _ptrMesh->getNumberOfNodes() 
1159                                    << "| nodes in mesh |" 
1160                                    << _ptrMesh->_name.c_str() << "|" ));   
1161
1162
1163     { // CELLS RELATED BLOCK
1164       medEntityMesh entity=MED_EN::MED_CELL;
1165       // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArray____Family DOIT ETRE ENLEVER DE LA CLASSE MESH
1166       if  ( ( _ptrMesh->existConnectivity(MED_NODAL,entity) )|( _ptrMesh->existConnectivity(MED_DESCENDING,entity) ) ) { 
1167
1168         int numberOfTypes           = _ptrMesh->getNumberOfTypes (entity) ;
1169         medGeometryElement  * types = _ptrMesh->getTypes         (entity) ;
1170       
1171         for (int i=0; i<numberOfTypes; i++) {
1172
1173           err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
1174                           _ptrMesh->_MEDArrayCellFamily[i], _ptrMesh->getNumberOfElements(entity, types[i]),
1175                           MED_FR::MED_REMP ,
1176                           (MED_FR::med_entite_maillage) entity,
1177                           (MED_FR::med_geometrie_element) types[i]); 
1178         
1179           if ( err != MED_VALID) 
1180             throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write family for the |"<< _ptrMesh->getNumberOfElements(entity, types[i])
1181                                          << "| cells of geometric type |" << geoNames[ (MED_FR::med_geometrie_element) types[i]] <<"|in mesh |"      
1182                                          << _ptrMesh->_name.c_str() << "|" ));   
1183         }
1184       }
1185     }
1186
1187     { // FACE RELATED BLOCK
1188       medEntityMesh entity=MED_EN::MED_FACE;
1189       // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArray____Family DOIT ETRE ENLEVER DE LA CLASSE MESH
1190       if  ( ( _ptrMesh->existConnectivity(MED_NODAL,entity) )|( _ptrMesh->existConnectivity(MED_DESCENDING,entity) ) ) { 
1191
1192         int numberOfTypes           = _ptrMesh->getNumberOfTypes (entity) ;
1193         medGeometryElement  * types = _ptrMesh->getTypes         (entity) ;
1194       
1195         int numberOfElements = _ptrMesh->getNumberOfElements(entity, MED_ALL_ELEMENTS) ;
1196         int * familyArray = new int[numberOfElements] ;
1197         for (int i=0;i<numberOfElements;i++)
1198           familyArray[i]=0;
1199
1200         int numberOfFamilies = _ptrMesh->getNumberOfFamilies(entity) ;
1201         vector<FAMILY*> myFamilies = _ptrMesh->getFamilies(entity) ;
1202         for (int i=0;i<numberOfFamilies;i++) {
1203           int familyNumber = myFamilies[i]->getIdentifier() ;
1204           int numberOfFamilyElements = myFamilies[i]->getNumberOfElements(MED_ALL_ELEMENTS) ;
1205           int * myFamilyElements = myFamilies[i]->getNumber(MED_ALL_ELEMENTS) ;
1206           for (int ii=0;ii<numberOfFamilyElements;ii++)
1207               familyArray[myFamilyElements[ii]-1]=familyNumber;
1208         }
1209
1210         int * typeCount = _ptrMesh->getGlobalNumberingIndex(entity) ;
1211
1212         for (int i=0; i<numberOfTypes; i++) {
1213
1214           int typeNumberOfElements = typeCount[i+1] - typeCount[i] ;
1215           err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
1216                           familyArray+typeCount[i]-1, typeNumberOfElements,
1217                           MED_FR::MED_REMP ,
1218                           (MED_FR::med_entite_maillage) entity,
1219                           (MED_FR::med_geometrie_element) types[i]); 
1220
1221           if ( err != MED_VALID) 
1222             throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write family for the |"<< _ptrMesh->getNumberOfElements(entity, types[i])
1223                                          << "| faces of geometric type |" << geoNames[ (MED_FR::med_geometrie_element) types[i]] <<"|in mesh |"      
1224                                          << _ptrMesh->_name.c_str() << "|" ));   
1225         }
1226         delete[] familyArray ;
1227       }
1228     }
1229
1230     { // EDGE RELATED BLOCK
1231       //medEntityMesh entity=MED_EN::MED_FACE;
1232       medEntityMesh entity=MED_EN::MED_EDGE;
1233       // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArray____Family DOIT ETRE ENLEVER DE LA CLASSE MESH
1234       if  ( ( _ptrMesh->existConnectivity(MED_NODAL,entity) )|( _ptrMesh->existConnectivity(MED_DESCENDING,entity) ) ) { 
1235
1236         int numberOfTypes           = _ptrMesh->getNumberOfTypes (entity) ;
1237         medGeometryElement  * types = _ptrMesh->getTypes         (entity) ;
1238       
1239         int numberOfElements = _ptrMesh->getNumberOfElements(entity, MED_ALL_ELEMENTS) ;
1240         int * familyArray = new int[numberOfElements] ;
1241         for (int i=0;i<numberOfElements;i++)
1242           familyArray[i]=0;
1243
1244         int numberOfFamilies = _ptrMesh->getNumberOfFamilies(entity) ;
1245         vector<FAMILY*> myFamilies = _ptrMesh->getFamilies(entity) ;
1246         for (int i=0;i<numberOfFamilies;i++) {
1247           int familyNumber = myFamilies[i]->getIdentifier() ;
1248           int numberOfFamilyElements = myFamilies[i]->getNumberOfElements(MED_ALL_ELEMENTS) ;
1249           int * myFamilyElements = myFamilies[i]->getNumber(MED_ALL_ELEMENTS) ;
1250           for (int ii=0;ii<numberOfFamilyElements;ii++)
1251               familyArray[myFamilyElements[ii]-1]=familyNumber;
1252         }
1253
1254         int * typeCount = _ptrMesh->getGlobalNumberingIndex(entity) ;
1255
1256         for (int i=0; i<numberOfTypes; i++) {
1257
1258           int typeNumberOfElements = typeCount[i+1] - typeCount[i] ;
1259           err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
1260                           familyArray+typeCount[i]-1, typeNumberOfElements,
1261                           MED_FR::MED_REMP ,
1262                           (MED_FR::med_entite_maillage) entity,
1263                           (MED_FR::med_geometrie_element) types[i]); 
1264         
1265           if ( err != MED_VALID) 
1266             throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write family for the |"<< _ptrMesh->getNumberOfElements(entity, types[i])
1267                                          << "| edges of geometric type |" << geoNames[ (MED_FR::med_geometrie_element) types[i]] <<"|in mesh |"      
1268                                          << _ptrMesh->_name.c_str() << "|" ));   
1269         }
1270       }
1271     }
1272     
1273     END_OF(LOC);
1274     return MED_VALID;
1275   }
1276   return MED_ERROR;
1277 }
1278
1279
1280 int MED_MESH_WRONLY_DRIVER::writeFamilies(vector<FAMILY*> & families ) const {
1281   
1282   const char * LOC="int MED_MESH_WRONLY_DRIVER::writeFamilies(vector<FAMILY*> families) const : ";
1283   BEGIN_OF(LOC);
1284
1285   MED_FR::med_err err;
1286   
1287   if (_status==MED_OPENED) {
1288
1289     MESSAGE(LOC<<" families.size() :"<<families.size());
1290
1291     for (int i=0; i< families.size(); i++) {
1292
1293       int      numberOfAttributes         = families[i]->getNumberOfAttributes ();
1294       string   attributesDescriptions     = "";
1295
1296       // Recompose the attributes descriptions arg for MED
1297       for (int j=0; j < numberOfAttributes; j++) {
1298         
1299         string attributeDescription = families[i]->getAttributeDescription(j+1);
1300         
1301         if ( attributeDescription.size() > MED_TAILLE_DESC )
1302           throw MEDEXCEPTION( LOCALIZED(STRING(LOC) << "The size of the attribute description n° |" << j+1 << "| of the family |" << families[i]->getName()
1303                                         << "| with identifier |" << families[i]->getIdentifier()  << "| is |" 
1304                                         <<  attributeDescription.size()  <<"| and is more than |" <<  MED_TAILLE_DESC << "|")) ;
1305         
1306         attributesDescriptions += attributeDescription;
1307       }
1308       
1309
1310       int      numberOfGroups  = families[i]->getNumberOfGroups();
1311       string   groupsNames(numberOfGroups*MED_TAILLE_LNOM,'\0') ;
1312       // Recompose the groups names arg for MED
1313       for (int j=0; j < numberOfGroups; j++) {
1314
1315         string groupName = families[i]->getGroupName(j+1);
1316        
1317         if ( groupName.size() > MED_TAILLE_LNOM )
1318           throw MEDEXCEPTION( LOCALIZED(STRING(LOC) << "The size of the group name  n° |" << j+1 << "| of the family |" << families[i]->getName()
1319                                         << "| with identifier |" << families[i]->getIdentifier()  << "| is |" 
1320                                         <<  groupName.size()  <<"| and is more than |" << MED_TAILLE_LNOM << "|")) ;
1321         
1322
1323         int length = min(MED_TAILLE_LNOM,(int)groupName.size());
1324         groupsNames.replace(j*MED_TAILLE_LNOM,length, groupName,0,length);
1325       
1326       }
1327
1328       // test if the family already exists (HDF trick waiting a MED evolution to be replaced)
1329       string dataGroupFam = "/ENS_MAA/"+_meshName+"/FAS/"+families[i]->getName()+"/";  
1330       SCRUTE("|"<<dataGroupFam<<"|");
1331       if ( err =_MEDdatagroupOuvrir(_medIdt,const_cast <char *> (dataGroupFam.c_str()) ) < MED_VALID ) {
1332         SCRUTE(err);
1333
1334         MESSAGE(LOC<<"families[i]->getName().c_str() : "<<families[i]->getName().c_str());
1335         MESSAGE(LOC<<"_meshName.c_str() : "<<_meshName.c_str());
1336         MESSAGE(LOC<<"families[i]->getIdentifier() : "<<families[i]->getIdentifier());
1337         MESSAGE(LOC<<"families[i]->getAttributesIdentifiers() : "<<families[i]->getAttributesIdentifiers()[0]);
1338         MESSAGE(LOC<<"families[i]->getAttributesValues() : "<<families[i]->getAttributesValues()[0]);
1339         MESSAGE(LOC<<"attributesDescriptions.c_str() : "<<attributesDescriptions.c_str());
1340         MESSAGE(LOC<<"numberOfAttributes : "<<numberOfAttributes);
1341         MESSAGE(LOC<<"groupsNames.c_str() : "<<groupsNames.c_str());
1342         MESSAGE(LOC<<"numberOfGroups : "<<numberOfGroups);
1343
1344         err = MEDfamCr( _medIdt, 
1345                         const_cast <char *> ( _meshName.c_str() ),
1346                         const_cast <char *> ( families[i]->getName().c_str() ),
1347                         families[i]->getIdentifier(), 
1348                         families[i]->getAttributesIdentifiers(),
1349                         families[i]->getAttributesValues(),
1350                         const_cast <char *> (attributesDescriptions.c_str()), 
1351                         numberOfAttributes,  
1352                         const_cast <char *> (groupsNames.c_str()), 
1353                         numberOfGroups);
1354         SCRUTE(err);
1355         if ( err != MED_VALID) 
1356           throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't create family |" << families[i]->getName()
1357                                        << "| with identifier |" << families[i]->getIdentifier()  << "| groups names |" 
1358                                        << groupsNames  <<"| and  attributes descriptions |" << attributesDescriptions << "|")) ;
1359       }
1360       else
1361         _MEDdatagroupFermer(_medIdt);
1362
1363
1364     }
1365
1366     END_OF(LOC);
1367     
1368     return MED_VALID;
1369   }
1370   return MED_ERROR;
1371 }
1372
1373
1374 // A FAIRE POUR LES NOEUDS ET LES ELEMENTS ret = MEDfamEcr(