1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/
20 #include "MEDMEM_MedMeshDriver22.hxx"
22 #include "MEDMEM_DriversDef.hxx"
24 #include "MEDMEM_Family.hxx"
25 #include "MEDMEM_Group.hxx"
26 #include "MEDMEM_Coordinate.hxx"
27 #include "MEDMEM_Connectivity.hxx"
28 #include "MEDMEM_Mesh.hxx"
29 #include "MEDMEM_CellModel.hxx"
30 #include "MEDMEM_Grid.hxx"
33 using namespace MED_EN;
34 using namespace MEDMEM;
38 extern med_idt _MEDdatagroupOuvrir(med_idt pid, char *nom);
39 extern med_err _MEDdatagroupFermer(med_idt id);
43 // Every memory allocation made in the MedDriver members function are desallocated in the Mesh destructor
45 MED_MESH_DRIVER22::MED_MESH_DRIVER22(): _medIdt(MED_INVALID)
49 MED_MESH_DRIVER22::MED_MESH_DRIVER22(const string & fileName,
51 MED_EN::med_mode_acces accessMode):
52 _medIdt(MED_INVALID), MED_MESH_DRIVER(fileName,ptrMesh,accessMode)
56 MED_MESH_DRIVER22::MED_MESH_DRIVER22(const MED_MESH_DRIVER22 & driver):
57 MED_MESH_DRIVER(driver),_medIdt(driver._medIdt)
61 MED_MESH_DRIVER22::~MED_MESH_DRIVER22()
65 void MED_MESH_DRIVER22::open()
67 const char * LOC = "MED_MESH_DRIVER22::open()" ;
70 MESSAGE(LOC<<" : _fileName.c_str : "<< _fileName.c_str()<<",mode : "<< _accessMode);
71 _medIdt = med_2_2::MEDouvrir( (const_cast <char *> (_fileName.c_str())),(med_2_2::med_mode_acces) _accessMode);
72 MESSAGE(LOC<<" _medIdt : "<< _medIdt );
76 _medIdt = MED_INVALID;
78 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Could not open file "<<_fileName<<" in mode "<<_accessMode));
84 void MED_MESH_DRIVER22::close()
86 const char * LOC = "MED_MESH_DRIVER22::close() " ;
89 if ( _status == MED_OPENED) {
90 err = med_2_2::MEDfermer(_medIdt);
91 // san -- MED5873 : Calling H5close() here leads to failure of SALOMEDS::StudyManager_i::_SaveAs()
92 // method during study saving process. MEDfermer() seems sufficient for closing a file.
93 //H5close(); // If we call H5close() all the files are closed.
95 throw MEDEXCEPTION( LOCALIZED(STRING(LOC)
96 <<" Error when closing file !"
99 MESSAGE(LOC <<": _medIdt= " << _medIdt );
100 MESSAGE(LOC<<": MEDfermer : err = " << err );
101 _status = MED_CLOSED;
102 _medIdt = MED_INVALID;
107 //A FAIRE UTILISER LES MAPS...
108 const med_2_2::med_geometrie_element MED_MESH_DRIVER22::all_cell_type[MED_NBR_GEOMETRIE_MAILLE]=
109 { med_2_2::MED_POINT1,med_2_2::MED_SEG2,med_2_2::MED_SEG3,med_2_2::MED_TRIA3,med_2_2::MED_QUAD4,med_2_2::MED_TRIA6,med_2_2::MED_QUAD8,
110 med_2_2::MED_TETRA4,med_2_2::MED_PYRA5,med_2_2::MED_PENTA6,med_2_2::MED_HEXA8,med_2_2::MED_TETRA10,med_2_2::MED_PYRA13,
111 med_2_2::MED_PENTA15, med_2_2::MED_HEXA20};
113 const char * const MED_MESH_DRIVER22::all_cell_type_tab [MED_NBR_GEOMETRIE_MAILLE]=
114 { "MED_POINT1","MED_SEG2","MED_SEG3","MED_TRIA3","MED_QUAD4","MED_TRIA6","MED_QUAD8",
115 "MED_TETRA4","MED_PYRA5","MED_PENTA6","MED_HEXA8","MED_TETRA10","MED_PYRA13",
116 "MED_PENTA15","MED_HEXA20"};
119 //---------------------------------- RDONLY PART -------------------------------------------------------------
121 MED_MESH_RDONLY_DRIVER22::MED_MESH_RDONLY_DRIVER22()
125 MED_MESH_RDONLY_DRIVER22::MED_MESH_RDONLY_DRIVER22(const string & fileName,
127 IMED_MESH_RDONLY_DRIVER(fileName,ptrMesh),MED_MESH_DRIVER22(fileName,ptrMesh,MED_RDONLY),MED_MESH_DRIVER(fileName,ptrMesh,MED_RDONLY)
129 MESSAGE("MED_MESH_RDONLY_DRIVER22::MED_MESH_RDONLY_DRIVER22(const string & fileName, MESH * ptrMesh) has been created");
132 MED_MESH_RDONLY_DRIVER22::MED_MESH_RDONLY_DRIVER22(const MED_MESH_RDONLY_DRIVER22 & driver):
133 IMED_MESH_RDONLY_DRIVER(driver),MED_MESH_DRIVER22(driver),MED_MESH_DRIVER(driver)
137 MED_MESH_RDONLY_DRIVER22::~MED_MESH_RDONLY_DRIVER22()
139 //MESSAGE("MED_MESH_RDONLY_DRIVER22::~MED_MESH_RDONLY_DRIVER() has been destroyed");
142 GENDRIVER * MED_MESH_RDONLY_DRIVER22::copy(void) const
144 return new MED_MESH_RDONLY_DRIVER22(*this);
147 void MED_MESH_RDONLY_DRIVER22::read(void)
149 const char * LOC = "MED_MESH_RDONLY_DRIVER22::read() : " ;
151 if (_status!=MED_OPENED)
152 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "The _idt of file " << _fileName << " is : " << _medIdt << " (the file is not opened)." )) ;
154 if ( ( _meshName.empty() ) && ( _ptrMesh->_name.empty() ) )
155 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)
156 <<" neither <meshName> is set in driver nor in object MESH.")) ;
158 // If _meshName is not set in driver, try to use _ptrMesh->_name
159 if ( ( _meshName.empty() ) && ( !_ptrMesh->_name.empty() ) )
160 _meshName=_ptrMesh->_name;
162 if ( _meshName.size() > MED_TAILLE_NOM )
163 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)
164 <<" <meshName> size in object driver MESH is > MED_TAILLE_NOM ."));
167 _ptrMesh->_name = _meshName;
169 SCRUTE(_ptrMesh->getIsAGrid());
171 if (_ptrMesh->getIsAGrid())
175 // always call getFAMILY : families are requiered !!!!
177 // int nbFam = MEDnFam(_medIdt,
178 // const_cast <char *> (_meshName.c_str()),
180 // MED_FR::MED_FAMILLE);
185 if (getFAMILY()!=MED_VALID)
186 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getFAMILY when the mesh is a grid")) ;
188 buildAllGroups(_ptrMesh->_groupNode,_ptrMesh->_familyNode) ;
195 if (getCOORDINATE()!=MED_VALID)
196 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getCOORDINATE" )) ;
198 if (getCONNECTIVITY()!=MED_VALID)
199 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getCOONECTIVITY")) ;
201 if (getFAMILY()!=MED_VALID)
202 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getFAMILY" )) ;
206 // we build all groups
208 buildAllGroups(_ptrMesh->_groupNode,_ptrMesh->_familyNode) ;
210 buildAllGroups(_ptrMesh->_groupCell,_ptrMesh->_familyCell) ;
212 if (_ptrMesh->_meshDimension == 3)
214 buildAllGroups(_ptrMesh->_groupFace,_ptrMesh->_familyFace) ;
215 else if (_ptrMesh->_meshDimension == 2)
217 buildAllGroups(_ptrMesh->_groupEdge,_ptrMesh->_familyEdge) ;
219 // MESSAGE(LOC<<"Checking of CellModel !!!!!!!");
221 // int nbOfTypes = _ptrMesh->_connectivity->_numberOfTypes;
222 // for(int i=0;i<nbOfTypes;i++)
224 // MESSAGE(LOC << _ptrMesh->_connectivity->_type[i]) ;
230 //=======================================================================
233 //=======================================================================
235 void MED_MESH_RDONLY_DRIVER22::getGRID()
237 const char * LOC = "MED_MESH_RDONLY_DRIVER22::getGRID() : " ;
240 if (_status!=MED_OPENED)
241 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "med file is not opened"));
243 GRID * ptrGrid = (GRID *) _ptrMesh;
249 int numberOfMeshesInFile = med_2_2::MEDnMaa(_medIdt);
251 if (numberOfMeshesInFile == MED_INVALID)
252 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Problem in File where the mesh " << _meshName << " is supposed to be stored"));
254 for (int index = 0; index < numberOfMeshesInFile; index++)
256 char meshName[MED_TAILLE_NOM+1]="";
257 char meshDescription[MED_TAILLE_DESC+1]="";
259 med_2_2::med_maillage meshType;
261 err = med_2_2::MEDmaaInfo(_medIdt, (index+1),meshName, &meshDim,
262 &meshType, meshDescription) ;
264 MESSAGE(LOC<<": Mesh n°"<< (index+1) <<" nammed "<< meshName << " with the description " << meshDescription << " is structured");
266 if (_meshName == string(meshName))
268 _ptrMesh->_description = meshDescription;
269 _ptrMesh->_name = meshName;
273 MED_EN::med_grid_type gridType = ptrGrid->getGridType();
275 MESSAGE(LOC<<": Mesh processed is nammed "<< _ptrMesh->_name << " with the description " << _ptrMesh->_description << " is structured with the type " << gridType);
277 // Read the dimension of the mesh <_meshName>
278 int MeshDimension = med_2_2::MEDdimLire(_medIdt, const_cast <char *>
279 (_meshName.c_str())) ;
281 if (MeshDimension == MED_INVALID)
282 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "The mesh dimension |" <<
283 MeshDimension << "| seems to be incorrect " <<
284 "for the mesh : |" << _meshName << "|")) ;
286 _ptrMesh->_meshDimension = MeshDimension;
288 // Read or get the dimension of the space for the mesh <_meshName>
289 int SpaceDimension = MeshDimension;
291 int SpaceDimensionRead = med_2_2::MEDdimEspaceLire(_medIdt,
293 (_meshName.c_str())) ;
295 if (SpaceDimensionRead != MED_INVALID) SpaceDimension = SpaceDimensionRead;
297 _ptrMesh->_spaceDimension = SpaceDimension;
299 med_2_2::med_repere rep ;
300 string tmp_nom_coord (MED_TAILLE_PNOM22*(_ptrMesh->_spaceDimension)+1,' ');
301 string tmp_unit_coord(MED_TAILLE_PNOM22*(_ptrMesh->_spaceDimension)+1,' ');
302 char * tmp_nom = (const_cast <char *> ( tmp_nom_coord.c_str()) ) ;
303 char * tmp_unit= (const_cast <char *> ( tmp_unit_coord.c_str()) ) ;
306 int * ArrayLen[] = { & ptrGrid->_iArrayLength,
307 & ptrGrid->_jArrayLength,
308 & ptrGrid->_kArrayLength };
310 MESSAGE(LOC << "The mesh is a " << _ptrMesh->_meshDimension << "D mesh on a " << _ptrMesh->_spaceDimension << "D space");
314 // if (gridType == MED_EN::MED_GRILLE_STANDARD)
315 if (gridType == MED_EN::MED_BODY_FITTED)
317 int * structure = new int[MeshDimension];
319 err = med_2_2::MEDstructureCoordLire(_medIdt,
321 (_ptrMesh->_name.c_str()),
322 MeshDimension,structure);
324 if (err != MED_VALID)
325 throw MEDEXCEPTION(STRING(LOC) <<"Error in reading the structure of grid : |" << _meshName << "|" ) ;
329 for (int idim = 0; idim < MeshDimension; idim++)
331 MESSAGE(LOC<<"structure dim " << idim << " " << structure[idim]);
333 ArrayLen [idim][0] = structure[idim];
334 NumberOfNodes = NumberOfNodes*structure[idim];
339 // NumberOfNodes = MED_FR::MEDnEntMaa(_medIdt,
340 // const_cast <char *>
341 // (_ptrMesh->_name.c_str()),
342 // MED_FR::MED_COOR,MED_FR::MED_NOEUD,
343 // (MED_FR::med_geometrie_element) 0,
344 // (MED_FR::med_connectivite) 0);
346 if ( NumberOfNodes == MED_INVALID )
347 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"The number of nodes |" <<
349 "| seems to be incorrect "
350 << "for the mesh : |" <<
351 _meshName << "|" )) ;
353 _ptrMesh->_numberOfNodes = NumberOfNodes ;
355 // create coordinates and its structure
356 _ptrMesh->_coordinate = new COORDINATE(SpaceDimension,NumberOfNodes,
357 MED_EN::MED_FULL_INTERLACE);
359 err = MEDcoordLire(_medIdt,
360 const_cast <char *> (_ptrMesh->_name.c_str()),
361 _ptrMesh->_spaceDimension,
362 //const_cast <double *> ( _ptrMesh->_coordinate->_coordinate->get(MED_EN::MED_FULL_INTERLACE) ),
363 const_cast <double *> ( _ptrMesh->_coordinate->_coordinate.get(MED_EN::MED_FULL_INTERLACE) ),
364 med_2_2::MED_FULL_INTERLACE,
365 MED_ALL, // we read all the coordinates
366 NULL, // we don't use a profile
367 0, // so the profile's size is 0
368 &rep,tmp_nom,tmp_unit);
370 if (err != MED_VALID)
371 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't read coordinates of the |" <<
372 NumberOfNodes << "| nodes for the mesh : |" <<
373 _meshName << "| of space dimension |" <<
374 SpaceDimension << "| with units names |" <<
375 tmp_nom << "| and units |" <<
378 ptrGrid->_is_coordinates_filled = true;
380 else if ((gridType == MED_EN::MED_CARTESIAN) ||
381 (gridType == MED_EN::MED_POLAR))
385 double * Array[] = { (double*) 0, (double*) 0, (double*) 0 };
387 for (int idim = 0; idim < _ptrMesh->_meshDimension; ++idim)
389 med_2_2::med_table table;
390 if (idim == 0) table = med_2_2::MED_COOR_IND1;
391 else if (idim == 1) table = med_2_2::MED_COOR_IND2;
392 else if (idim == 2) table = med_2_2::MED_COOR_IND3;
394 int length = med_2_2::MEDnEntMaa(_medIdt,
395 const_cast <char *> (_ptrMesh->_name.c_str()),
396 table,med_2_2::MED_NOEUD,
399 if ( length <= MED_VALID )
400 throw MEDEXCEPTION(STRING(LOC) <<"The number of nodes |" << length <<
401 "| seems to be incorrect "
402 << "for the mesh : |" << _meshName << "|" ) ;
404 ArrayLen [idim][0] = length;
405 NumberOfNodes *= length;
407 Array [idim] = new double [ length ];
409 err = med_2_2::MEDindicesCoordLire(_medIdt, const_cast <char *>
410 (_ptrMesh->_name.c_str()),
411 _ptrMesh->_meshDimension,
412 Array [idim], length, (idim+1),
413 tmp_nom+(idim*MED_TAILLE_PNOM22),
414 tmp_unit+(idim*MED_TAILLE_PNOM22));
416 if (err != MED_VALID)
417 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Error in reading coordinates indices " <<
418 idim << "of the grid : |" <<
419 _meshName << "|" )) ;
422 ptrGrid->_iArray = Array[0];
423 ptrGrid->_jArray = Array[1];
424 ptrGrid->_kArray = Array[2];
426 _ptrMesh->_numberOfNodes = NumberOfNodes ;
428 // create coordinates
429 _ptrMesh->_coordinate = new COORDINATE(SpaceDimension,NumberOfNodes,
430 MED_EN::MED_FULL_INTERLACE);
432 if (gridType == MED_EN::MED_CARTESIAN)
433 rep = med_2_2::MED_CART;
434 else if (gridType == MED_EN::MED_POLAR)
436 if (SpaceDimension == 2) rep = med_2_2::MED_CYL;
437 else if (SpaceDimension == 3) rep = med_2_2::MED_SPHER;
441 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<" bad grid type : " << gridType));
443 // set coordinate names
445 for (i=0; i<_ptrMesh->_spaceDimension; ++i ) {
446 string myStringName(tmp_nom_coord,i*MED_TAILLE_PNOM22,MED_TAILLE_PNOM22) ;
447 string myStringUnit(tmp_unit_coord,i*MED_TAILLE_PNOM22,MED_TAILLE_PNOM22) ;
448 // suppress space at the end
450 for(j=MED_TAILLE_PNOM22-1;j>=0;j--)
451 if (myStringName[j] != ' ') break ;
452 _ptrMesh->_coordinate->_coordinateName[i]=string(myStringName,0,j+1);
453 for(j=MED_TAILLE_PNOM22-1;j>=0;j--)
454 if (myStringUnit[j] != ' ') break ;
455 _ptrMesh->_coordinate->_coordinateUnit[i]=string(myStringUnit,0,j+1);
458 string coordinateSystem = "UNDEFINED";
460 if( rep == med_2_2::MED_CART) coordinateSystem = "CARTESIAN";
461 else if ( rep == med_2_2::MED_CYL) coordinateSystem = "CYLINDRICAL";
462 else if ( rep == med_2_2::MED_SPHER) coordinateSystem = "SPHERICAL";
464 _ptrMesh->_coordinate->setCoordinatesSystem(coordinateSystem);
469 //=======================================================================
470 //function : getCOORDINATE
471 // A FAIRE : RENVOYER DU VOID
472 //=======================================================================
473 int MED_MESH_RDONLY_DRIVER22::getCOORDINATE()
475 const char * LOC = "MED_MESH_RDONLY_DRIVER22::getCOORDINATE() : " ;
479 if (_status==MED_OPENED)
483 int numberOfMeshesInFile = med_2_2::MEDnMaa(_medIdt);
485 if (numberOfMeshesInFile == MED_INVALID)
486 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Problem in File where the mesh " << _meshName << " is supposed to be stored"));
488 for (int index = 0; index < numberOfMeshesInFile; index++)
490 char meshName[MED_TAILLE_NOM+1]="";
491 char meshDescription[MED_TAILLE_DESC+1]="";
493 med_2_2::med_maillage meshType;
495 err = med_2_2::MEDmaaInfo(_medIdt, (index+1), meshName, &meshDim,
496 &meshType, meshDescription) ;
498 MESSAGE(LOC<<": Mesh n°"<< (index+1) <<" nammed "<< meshName << " with the description " << meshDescription << " is structured");
500 if (_meshName == string(meshName))
502 _ptrMesh->_description = meshDescription;
507 // Read the dimension of the mesh <_meshName>
508 int MeshDimension = med_2_2::MEDdimLire(_medIdt, const_cast <char *>
509 (_meshName.c_str())) ;
511 if ( MeshDimension == MED_INVALID )
512 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "The mesh dimension |" <<
514 "| seems to be incorrect " <<
515 "for the mesh : |" << _meshName << "|")) ;
517 _ptrMesh->_meshDimension = MeshDimension;
519 // Read or get the dimension of the space for the mesh <_meshName>
520 int SpaceDimension = MeshDimension;
522 int SpaceDimensionRead = med_2_2::MEDdimEspaceLire(_medIdt,
524 (_meshName.c_str())) ;
526 if (SpaceDimensionRead != MED_INVALID)
527 SpaceDimension = SpaceDimensionRead;
529 _ptrMesh->_spaceDimension = SpaceDimension;
531 // Read the number of nodes used in the mesh <_meshName>
532 // to be able to create a COORDINATE object
533 int NumberOfNodes=MEDnEntMaa(_medIdt,
534 const_cast <char *> (_meshName.c_str()),
537 (med_2_2::med_geometrie_element) MED_NONE,
538 (med_2_2::med_connectivite) MED_NONE);
539 if ( NumberOfNodes <= MED_VALID )
540 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"The number of nodes |" << NumberOfNodes << "| seems to be incorrect "
541 << "for the mesh : |" << _meshName << "|" )) ;
542 _ptrMesh->_numberOfNodes = NumberOfNodes ;
544 // create a COORDINATE object
545 _ptrMesh->_coordinate = new COORDINATE(SpaceDimension, NumberOfNodes, MED_EN::MED_FULL_INTERLACE);
547 med_2_2::med_repere rep ; // ATTENTION ---> DOIT ETRE INTEGRE DS MESH EF: FAIT NON?
548 string tmp_nom_coord (MED_TAILLE_PNOM22*(_ptrMesh->_spaceDimension)+1,'\0');
549 string tmp_unit_coord(MED_TAILLE_PNOM22*(_ptrMesh->_spaceDimension)+1,'\0');
550 char * tmp_nom = (const_cast <char *> ( tmp_nom_coord.c_str()) ) ;
551 char * tmp_unit= (const_cast <char *> ( tmp_unit_coord.c_str()) ) ;
553 err=MEDcoordLire(_medIdt,
554 const_cast <char *> (_ptrMesh->_name.c_str()),
555 _ptrMesh->_spaceDimension,
556 //const_cast <double *> ( _ptrMesh->_coordinate->_coordinate->get(MED_EN::MED_FULL_INTERLACE) ),
557 const_cast <double *> ( _ptrMesh->_coordinate->_coordinate.get(MED_EN::MED_FULL_INTERLACE) ),
558 med_2_2::MED_FULL_INTERLACE,
559 MED_ALL, // we read all the coordinates
560 NULL, // we don't use a profile
561 0, // so the profile's size is 0
562 &rep,tmp_nom,tmp_unit);
563 if (err != MED_VALID)
564 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't read coordinates of the |" << NumberOfNodes << "| nodes "
565 << "for the mesh : |" << _meshName
566 << "| of space dimension |" << SpaceDimension
567 << "| with units names |" << tmp_nom
568 << "| and units |" << tmp_unit
572 for (int i=0;i<_ptrMesh->_spaceDimension;i++) {
573 string myStringName(tmp_nom_coord,i*MED_TAILLE_PNOM22,MED_TAILLE_PNOM22) ;
574 string myStringUnit(tmp_unit_coord,i*MED_TAILLE_PNOM22,MED_TAILLE_PNOM22) ;
575 // suppress space at the end
577 for(j=MED_TAILLE_PNOM22-1;j>=0;j--)
578 if (myStringName[j] != ' ') break ;
579 _ptrMesh->_coordinate->_coordinateName[i]=string(myStringName,0,j+1);
580 for(j=MED_TAILLE_PNOM22-1;j>=0;j--)
581 if (myStringUnit[j] != ' ') break ;
582 _ptrMesh->_coordinate->_coordinateUnit[i]=string(myStringUnit,0,j+1);
585 // Pourquoi le stocker sous forme de chaîne ?
588 case med_2_2::MED_CART :
590 _ptrMesh->_coordinate->_coordinateSystem = "CARTESIAN";
593 case med_2_2::MED_CYL :
595 _ptrMesh->_coordinate->_coordinateSystem = "CYLINDRICAL";
598 case med_2_2::MED_SPHER :
600 _ptrMesh->_coordinate->_coordinateSystem = "SPHERICAL";
605 _ptrMesh->_coordinate->_coordinateSystem = "UNDEFINED"; // ?Erreur ?
610 // Read the unused optional node Names
611 char * tmp_node_name = new char[NumberOfNodes*MED_TAILLE_PNOM22+1];
612 tmp_node_name[NumberOfNodes]='\0' ;
613 err=MEDnomLire(_medIdt,const_cast <char*> (_ptrMesh->_name.c_str()),
614 tmp_node_name,NumberOfNodes*MED_TAILLE_PNOM22,med_2_2::MED_NOEUD,
615 (med_2_2::med_geometrie_element) MED_NONE);
616 if (err == MED_VALID)
617 MESSAGE(LOC<<"MED_MESH_RDONLY_DRIVER::getNoeuds() : WARNING : Nodes have names but we do not read them !");
618 delete[] tmp_node_name ;
621 // ??? Read the unused optional node Numbers ???
622 med_2_2::med_int * tmp_node_number = new med_2_2::med_int[NumberOfNodes] ;
623 err=MEDnumLire(_medIdt,const_cast <char*> (_ptrMesh->_name.c_str()),
624 tmp_node_number,NumberOfNodes,med_2_2::MED_NOEUD,(med_2_2::med_geometrie_element)0);
625 if (err == MED_VALID) {
626 // INFOS(LOC<<"WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING");
627 // INFOS(LOC<<"MED_MESH_RDONLY_DRIVER::getNoeuds() : WARNING : Nodes have numbers but we do not take care of them !");
628 // INFOS(LOC<<"WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING");
629 MESSAGE(LOC<<"MED_MESH_RDONLY_DRIVER::getNoeuds() : Nodes have numbers, we DO TAKE care of them !");
630 _ptrMesh->_coordinate->_nodeNumber.set(NumberOfNodes) ;
631 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000)
632 for(med_2_2::med_int i2=0;i2<NumberOfNodes;i2++)
633 _ptrMesh->_coordinate->_nodeNumber[i2]=(int)(tmp_node_number[i2]);
635 memcpy((int*)_ptrMesh->_coordinate->_nodeNumber,tmp_node_number,sizeof(int)*NumberOfNodes) ;
638 //////////////////////////////////////////////////////////////////////////////////////
639 /// Modification pour prise en compte de la numérotation optionnelle des noeuds ///
640 //////////////////////////////////////////////////////////////////////////////////////
642 /// Calcule _optionnalToCanonicNodesNumbers de telle sorte que _optionnalToCanonicNodesNumbers[OptionnalNumber]==CanonicNumber
644 // _ptrMesh->_arePresentOptionnalNodesNumbers=1;
645 // for (int canonicNumber=1;canonicNumber<=NumberOfNodes;canonicNumber++) _ptrMesh->_optionnalToCanonicNodesNumbers[tmp_node_number[canonicNumber-1]]=canonicNumber;
646 // ICI RETOUR A LA NORMALE::: AUCUNE PRISE EN COMPTE D'UN NUMEROTATION OPTIONNEL
647 _ptrMesh->_arePresentOptionnalNodesNumbers=0;
649 else _ptrMesh->_arePresentOptionnalNodesNumbers=0;
651 //////////////////////////////////////////////////////////////////////////////////////
653 delete[] tmp_node_number ;
662 int MED_MESH_RDONLY_DRIVER22::getCONNECTIVITY()
664 const char * LOC = "MED_MESH_RDONLY_DRIVER22::getCONNECTIVITY : " ;
667 if (_status==MED_OPENED)
671 // read MED_CELL connectivity
672 CONNECTIVITY * Connectivity = new CONNECTIVITY(MED_CELL) ;
673 Connectivity->_numberOfNodes = _ptrMesh->_numberOfNodes ; // EF : Pourquoi cet attribut est-il dans MESH et non dans COORDINATE ?
675 // Try to read nodal connectivity of the cells <Connectivity->_nodal>
676 // then try to read descending connectivity <Connectivity->_descending>
677 // if neither nodal nor descending connectivity exists
678 // throw an exception.
679 err = getNodalConnectivity(Connectivity) ;
682 Connectivity->_typeConnectivity = MED_DESCENDING ;
683 err = getDescendingConnectivity(Connectivity) ;
686 getDescendingConnectivity(Connectivity) ; // we read it if there is one
690 delete Connectivity ;
691 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "We could not read " <<
692 "any Connectivity")) ;
695 if (Connectivity->_entityDimension != _ptrMesh->_meshDimension)
696 MESSAGE(LOC << "Small mesh dimension problem on the med file mounted in memory : diim stored " << _ptrMesh->_meshDimension << " dim computed using the connectivity " << Connectivity->_entityDimension);
698 _ptrMesh->_meshDimension = Connectivity->_entityDimension ;
700 // At this point Connectivity->_typeConnectivity is either NODAL or DESCENDING
701 // If both connectivities are found Connectivity->_typeConnectivity is NODAL
702 // If space dimension is 3
703 // try to read the nodal connectivity of the faces <ConnectivityFace->_nodal> then
704 // try to read the descending connectivity <ConnectivityFace->_descending>
705 // if there is no descending connectivity and the CELLS are
706 // defined in descending mode then throw an exception
708 // PROVISOIRE : if we have some face or edge in MED_MAILLE, we don't read more. There could not be have face or edge !!!!
710 if(Connectivity->_constituent==NULL) {
712 SCRUTE(_ptrMesh->_meshDimension);
713 SCRUTE(Connectivity->_entityDimension);
714 if (_ptrMesh->_meshDimension == 3) {
715 MESSAGE(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE DES FACES..." );
716 CONNECTIVITY * ConnectivityFace = new CONNECTIVITY(MED_EN::MED_FACE) ;
717 ConnectivityFace->_typeConnectivity = Connectivity->_typeConnectivity ; // NODAL or DESCENDING
718 SCRUTE(ConnectivityFace->_typeConnectivity);
719 if (Connectivity->_typeConnectivity == MED_DESCENDING) {
720 MESSAGE(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE DESCENDANTE DES FACES" );
721 err = getDescendingConnectivity(ConnectivityFace) ;
723 throw MEDEXCEPTION ( LOCALIZED(STRING(LOC) << "No FACE in descending connectivity")) ;
724 getNodalConnectivity(ConnectivityFace) ; // if any !
726 MESSAGE(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE NODALE DES FACES" );
727 err = getNodalConnectivity(ConnectivityFace) ;
728 if (err!=MED_VALID) { // or error ????? we are in NODAL mode.
729 err = getDescendingConnectivity(ConnectivityFace) ;
731 getDescendingConnectivity(ConnectivityFace); // if any !
733 if (err!=MED_VALID) {
734 delete ConnectivityFace ;
735 MESSAGE(LOC<<"No FACE defined.") ;
737 MESSAGE(LOC<<" SAUVEGARDE DE LA CONNECTIVITE DES FACES DANS L'OBJET CONNECTIVITY" );
738 Connectivity->_constituent=ConnectivityFace ;
742 // read MED_EDGE connectivity
743 if (_ptrMesh->_meshDimension > 1) { // we are in 3 or 2D
744 MESSAGE(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE DES ARRETES...." );
745 CONNECTIVITY * ConnectivityEdge = new CONNECTIVITY(MED_EDGE) ;
746 ConnectivityEdge->_typeConnectivity = Connectivity->_typeConnectivity ;
747 if (Connectivity->_typeConnectivity == MED_DESCENDING) {
748 MESSAGE(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE DESCENDANTE DES ARRETES" );
749 err = getDescendingConnectivity(ConnectivityEdge) ;
751 throw MEDEXCEPTION ( LOCALIZED(STRING(LOC) << "No EDGE in descending connectivity")) ;
752 getNodalConnectivity(ConnectivityEdge) ; // if any !
754 MESSAGE(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE NODALE DES ARRETES" );
755 err = getNodalConnectivity(ConnectivityEdge) ;
756 if (err!=MED_VALID) { // or error ????? we are in NODAL mode.
757 err = getDescendingConnectivity(ConnectivityEdge) ;
759 getDescendingConnectivity(ConnectivityEdge) ; // if any !
761 if (err!=MED_VALID) {
762 delete ConnectivityEdge ;
763 MESSAGE(LOC<<"No EDGE defined.") ;
765 if (_ptrMesh->_meshDimension == 3)
766 if (Connectivity->_constituent != NULL)
767 Connectivity->_constituent->_constituent=ConnectivityEdge ;
769 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<< "EDGE defined but there are no FACE !")) ;
771 MESSAGE(LOC<<" SAUVEGARDE DE LA CONNECTIVITE DES ARETES DANS L'OBJET CONNECTIVITY" );
772 Connectivity->_constituent=ConnectivityEdge ;
777 _ptrMesh->_connectivity = Connectivity ;
781 // we have read all connectivity in file, now we must build descending connectivity if necessary !
783 // If connectivity descending is defined, we have nothing to do, all constituent are defined !
784 // If connectivity is only nodal, we must rebuild descending if we have some contituent !
787 // if (Connectivity->_descending == NULL)
788 // if (Connectivity->_constituent != NULL){
789 // // update Connectivity->_constituent
790 // CONNECTIVITY * myConstituentOld = Connectivity->_constituent ;
791 // Connectivity->_constituent = (CONNECTIVITY *)NULL ;
792 // Connectivity->calculateDescendingConnectivity() ;
802 int MED_MESH_RDONLY_DRIVER22::getNodalConnectivity(CONNECTIVITY * Connectivity)
804 const char * LOC = "MED_MESH_RDONLY_DRIVER22::getNodalConnectivity : " ;
807 if (_status==MED_OPENED)
809 int spaceDimension = _ptrMesh->_spaceDimension;
811 // Get the type of entity to work on (previously set in the Connectivity Object)
812 med_2_2::med_entite_maillage Entity = (med_2_2::med_entite_maillage) Connectivity->getEntity();
814 // Get the number of cells of each type & store it in <tmp_cells_count>.
815 int * tmp_cells_count = new int[MED_NBR_GEOMETRIE_MAILLE] ;
817 for (i=1;i<MED_NBR_GEOMETRIE_MAILLE;i++)
818 { // EF :ON SCANNE DES GEOMETRIES INUTILES, UTILISER LES MAPS
819 tmp_cells_count[i]=MEDnEntMaa(_medIdt,(const_cast <char *> (_ptrMesh->_name.c_str())),
820 med_2_2::MED_CONN,(med_2_2::med_entite_maillage) Entity,
821 all_cell_type[i],med_2_2::MED_NOD);
824 // Get the greatest dimension of the cells : Connectivity->_entityDimension
825 // We suppose there is no cells used as faces in MED 2.2.x , this is forbidden !!!
826 // In version prior to 2.2.x, it is possible
827 if (tmp_cells_count[i]>0)
829 Connectivity->_entityDimension=all_cell_type[i]/100;
830 Connectivity->_numberOfTypes++;
836 // begin classic geometric types
837 if (Connectivity->_numberOfTypes > 0)
839 // if MED version < 2.2.x, we read only entity with dimention = Connectivity->_entityDimension. Lesser dimension are face or edge !
841 med_int major, minor, release;
843 if ( med_2_2::MEDversionLire(_medIdt, &major, &minor, &release) != 0 )
845 // error : we suppose we have not a good med file !
846 delete[] tmp_cells_count ;
850 // we get MED version number
851 // If MED version is < 2.2 then the cells which dimension
852 // is lesser than the main dimension ( Connectivity->_entityDimension )
853 // are either faces or edges
855 // string medVersion(version_med);
857 int * tmpEdgeCount = new int[MED_NBR_GEOMETRIE_MAILLE] ;
858 tmpEdgeCount[0] = 0 ;
859 int numberOfEdgesTypes = 0;
860 int * tmpFaceCount = new int[MED_NBR_GEOMETRIE_MAILLE] ;
861 tmpFaceCount[0] = 0 ;
862 int numberOfFacesTypes = 0;
864 // if ((version_med != "2.2")&(Entity==MED_FR::MED_MAILLE))
866 // Connectivity->_numberOfTypes=0;
868 // for ( i=1;i<MED_NBR_GEOMETRIE_MAILLE;i++)
870 // tmpFaceCount[i]=0;
871 // tmpEdgeCount[i]=0;
872 // if (tmp_cells_count[i]!=0)
874 // int dimension = all_cell_type[i]/100 ;
875 // if (Connectivity->_entityDimension==dimension)
876 // Connectivity->_numberOfTypes++ ;
878 // if (dimension == 2)
879 // if (Connectivity->_entityDimension==3)
881 // tmpFaceCount[i]=tmp_cells_count[i] ;
882 // tmp_cells_count[i]=0 ;
883 // numberOfFacesTypes++;
885 // if (dimension == 1)
886 // if (Connectivity->_entityDimension>dimension)
888 // tmpEdgeCount[i]=tmp_cells_count[i] ;
889 // tmp_cells_count[i]=0;
890 // numberOfEdgesTypes++ ;
896 if (Entity==med_2_2::MED_MAILLE)
898 Connectivity->_numberOfTypes=0;
900 for ( i=1;i<MED_NBR_GEOMETRIE_MAILLE;i++)
904 if (tmp_cells_count[i]!=0)
906 int dimension = all_cell_type[i]/100 ;
907 if (Connectivity->_entityDimension==dimension)
908 Connectivity->_numberOfTypes++ ;
911 if (Connectivity->_entityDimension==3)
913 tmpFaceCount[i]=tmp_cells_count[i] ;
914 //tmp_cells_count[i]=0 ;
915 //Connectivity->_numberOfTypes++ ;
916 numberOfFacesTypes++;
919 if (Connectivity->_entityDimension>dimension)
921 tmpEdgeCount[i]=tmp_cells_count[i] ;
922 //tmp_cells_count[i]=0;
923 //Connectivity->_numberOfTypes++ ;
924 numberOfEdgesTypes++ ;
930 // bloc to read CELL :
932 // Prepare an array of indexes on the different cell types to create a MEDSKYLINEARRAY
933 // We use <tmp_cells_count> to calculate <Connectivity->_count> then we release it
934 Connectivity->_geometricTypes = new MED_EN::medGeometryElement [Connectivity->_numberOfTypes] ; // Double emploi pour des raisons pratiques
935 Connectivity->_type = new CELLMODEL [Connectivity->_numberOfTypes] ; //
936 Connectivity->_count = new int [Connectivity->_numberOfTypes+1] ;
937 Connectivity->_count[0] = 1;
942 for ( i=1;i<MED_NBR_GEOMETRIE_MAILLE;i++)
943 { // no point1 cell type (?)
944 int dimension = all_cell_type[i]/100 ;
945 if ((tmp_cells_count[i]>0) && (Connectivity->_entityDimension == dimension))
947 Connectivity->_count[typeNumber]=Connectivity->_count[typeNumber-1]+tmp_cells_count[i];
949 CELLMODEL t( (MED_EN::medGeometryElement) MED_MESH_DRIVER22::all_cell_type[i]) ;
951 Connectivity->_type[typeNumber-1] = t ;
953 Connectivity->_geometricTypes[typeNumber-1]=( MED_EN::medGeometryElement) MED_MESH_DRIVER22::all_cell_type[i] ;
955 // probleme avec les mailles de dimension < a dimension du maillage :
956 // Il faut oter le zero a la lecture est le remettre a l'ecriture : ce n'est pas fait !!!!! On interdit ce cas pour l'instant !!!
959 size+=tmp_cells_count[i]*((MED_MESH_DRIVER22::all_cell_type[i])%100) ;
962 << Connectivity->_count[typeNumber]-1 << " cells of type "
963 << all_cell_type_tab[i] );
968 // Creation of the MEDSKYLINEARRAY
969 //Connectivity->_nodal = new MEDSKYLINEARRAY(Connectivity->_count[Connectivity->_numberOfTypes]-1,size) ;
970 //int * NodalIndex = Connectivity->_nodal->getIndex() ;
971 int * NodalValue = new int[size] ;
972 int * NodalIndex = new int[Connectivity->_count[Connectivity->_numberOfTypes]] ;
975 // Fill the MEDSKYLINEARRAY by reading the MED file.
977 for ( i=0;i<Connectivity->_numberOfTypes;i++)
980 med_2_2::med_geometrie_element med_type = (med_2_2::med_geometrie_element) Connectivity->_type[i].getType() ;
981 // if ( Connectivity->_type[i].getDimension() < Connectivity->_entityDimension)
982 // if (Connectivity->_entity == MED_CELL)
983 // if ( Connectivity->_type[i].getDimension() < _ptrMesh->_spaceDimension)
986 // int NumberOfCell = Connectivity->_count[i+1]-Connectivity->_count[i] ;
987 int NumberOfNodeByCell = Connectivity->_type[i].getNumberOfNodes() ;
990 for ( j=Connectivity->_count[i]; j<Connectivity->_count[i+1];j++)
991 NodalIndex[j]=NodalIndex[j-1]+NumberOfNodeByCell ;
993 int tmp_numberOfCells = Connectivity->_count[i+1]-Connectivity->_count[i] ;
994 int * tmp_ConnectivityArray = new int[(NumberOfNodeByCell+multi)*tmp_numberOfCells];
996 // int err=MEDconnLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
997 // Connectivity->_entityDimension,tmp_ConnectivityArray,
998 // MED_FR::MED_FULL_INTERLACE,NULL,0,Entity,med_type,MED_FR::MED_NOD);
999 int err=MEDconnLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
1000 spaceDimension,tmp_ConnectivityArray,
1001 med_2_2::MED_FULL_INTERLACE,NULL,0,Entity,med_type,med_2_2::MED_NOD);
1003 if ( err != MED_VALID)
1005 delete[] tmp_ConnectivityArray;
1006 delete[] tmp_cells_count;
1007 delete[] tmpFaceCount;
1008 delete[] tmpEdgeCount;
1009 MESSAGE(LOC<<": MEDconnLire returns "<<err) ;
1013 int * ConnectivityArray = NodalValue + NodalIndex[Connectivity->_count[i]-1]-1 ;
1015 // version originale sans prise en compte des numéros optionnels
1017 for ( j=0; j<tmp_numberOfCells; j++) for (int k=0; k<NumberOfNodeByCell; k++)
1018 ConnectivityArray[j*NumberOfNodeByCell+k]=tmp_ConnectivityArray[j*(NumberOfNodeByCell+multi)+k] ;
1020 //////////////////////////////////////////////////////////////////////////////
1021 // Modification pour prise en compte de la numérotation optionnelle des noeuds ///
1022 //////////////////////////////////////////////////////////////////////////////
1024 // Rénumérote le tableau temporaire tmp_ConnectivityArray en utilisant _optionnalToCanonicNodesNumbers
1025 // Le traitement est identique à la version originelle s'il n'y a pas de numérotation optionnelle
1027 // if (_ptrMesh->_arePresentOptionnalNodesNumbers==1)
1029 // for ( j=0; j<tmp_numberOfCells; j++) for (int k=0; k<NumberOfNodeByCell; k++)
1030 // ConnectivityArray[j*NumberOfNodeByCell+k]=_ptrMesh->_optionnalToCanonicNodesNumbers[tmp_ConnectivityArray[j*(NumberOfNodeByCell+multi)+k]] ;
1034 // for ( j=0; j<tmp_numberOfCells; j++) for (int k=0; k<NumberOfNodeByCell; k++)
1035 // ConnectivityArray[j*NumberOfNodeByCell+k]=tmp_ConnectivityArray[j*(NumberOfNodeByCell+multi)+k] ;
1037 ////////////////////////////////////////////////////////////////////////////
1039 delete[] tmp_ConnectivityArray;
1043 Connectivity->_nodal = new MEDSKYLINEARRAY(Connectivity->_count[Connectivity->_numberOfTypes]-1,
1048 delete[] NodalIndex;
1049 delete[] NodalValue;
1051 } // end of bloc to read CELL
1057 if (numberOfFacesTypes!=0)
1060 // Create a CONNECTIVITY constituent to put in the top level CONNECTIVITY recursive class
1061 CONNECTIVITY * constituent = new CONNECTIVITY(numberOfFacesTypes,MED_EN::MED_FACE) ;
1062 constituent->_entityDimension = 2 ;
1063 constituent->_count[0]=1 ;
1065 // In order to create the MEDSKYLINEARRAY of the constituent object we need :
1067 // To initialize the _count array of the constituent object (containning cumulated face count by geometric type)
1068 // _count[0]=1 and _count[_numberOfTypes] give the size of NodalIndex
1070 // To calculate the total number of face nodes whatever the geometric type is.
1071 // The result is the size of the array containning all the nodes : NodalValue
1073 // To calculate the starting indexes of the different face types in NodalValue,
1074 // this is the NodalIndex array.
1077 int typeNumber = 1 ;
1079 for ( i=1; i < MED_NBR_GEOMETRIE_MAILLE; i++)
1080 { // no point1 cell type (?)
1081 if (tmpFaceCount[i]>0)
1083 constituent->_count[typeNumber] = constituent->_count[typeNumber-1] + tmpFaceCount[i];
1084 CELLMODEL t( (MED_EN::medGeometryElement) MED_MESH_DRIVER22::all_cell_type[i]) ;
1085 constituent->_type[typeNumber-1]=t ;
1087 constituent->_geometricTypes[typeNumber-1]=( MED_EN::medGeometryElement) MED_MESH_DRIVER22::all_cell_type[i] ;
1089 size+=tmpFaceCount[i]*((MED_MESH_DRIVER22::all_cell_type[i])%100) ;
1094 // Creation of the MEDSKYLINEARRAY
1095 //constituent->_nodal = new MEDSKYLINEARRAY(constituent->_count[constituent->_numberOfTypes]-1,size) ;
1096 //int * NodalIndex = constituent->_nodal->getIndex() ;
1097 int * NodalValue = new int[size] ;
1098 int * NodalIndex = new int[constituent->_count[constituent->_numberOfTypes]] ;
1101 // Fill the MEDSKYLINEARRAY by reading the MED file.
1102 for ( i=0; i<constituent->_numberOfTypes; i++)
1104 med_2_2::med_geometrie_element med_type = (med_2_2::med_geometrie_element) constituent->_type[i].getType() ;
1106 int NumberOfNodeByFace = constituent->_type[i].getNumberOfNodes() ;
1108 // initialise NodalIndex
1109 for (int j=constituent->_count[i]; j<constituent->_count[i+1];j++)
1110 NodalIndex[j]=NodalIndex[j-1]+NumberOfNodeByFace ;
1112 int tmp_numberOfFaces = constituent->_count[i+1]-constituent->_count[i] ;
1113 // Il faut ajouter 1 pour le zero a la lecture !!!
1114 // ATTENTION UNIQUEMENT POUR MED < 2.2.x
1115 int * tmp_constituentArray = NULL;
1117 MESSAGE(LOC << "Med file version used here " << major << " " << minor << " " << release);
1119 if ((major == 2) && (minor <= 1))
1120 tmp_constituentArray = new int[(NumberOfNodeByFace+1)*tmp_numberOfFaces] ;
1121 else if ((major == 2) && (minor >= 2))
1123 tmp_constituentArray = new int[NumberOfNodeByFace*tmp_numberOfFaces] ;
1124 MESSAGE(LOC<<": WE ARE USING MED2.2 so there is no +1 for calculating the size of tmp_constituentArray !") ;
1127 int err=MEDconnLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
1128 Connectivity->_entityDimension,tmp_constituentArray,
1129 med_2_2::MED_FULL_INTERLACE,NULL,0,med_2_2::MED_MAILLE,med_type,med_2_2::MED_NOD);
1131 if ( err != MED_VALID)
1133 MESSAGE(LOC<<": MEDconnLire returns "<<err) ;
1134 delete constituent ;
1135 delete[] tmp_constituentArray;
1136 delete[] tmpFaceCount;
1137 delete[] tmpEdgeCount;
1141 int * constituentArray = NodalValue + NodalIndex[constituent->_count[i]-1]-1 ;
1143 // version originale sans prise en compte des numéros optionnels
1145 int multi = 0; // quand est-ce que multi vaut 1 ?? en MED-fichier < 2.2 ??
1146 MESSAGE(LOC << "Med file version used here " << major << " " << minor << " " << release);
1148 if ((major == 2) && (minor <= 1))
1149 for (int j=0; j<tmp_numberOfFaces; j++)
1150 for (int k=0; k<NumberOfNodeByFace; k++)
1151 constituentArray[j*NumberOfNodeByFace+k]=tmp_constituentArray[j*(NumberOfNodeByFace+1)+k] ;
1152 else if ((major == 2) && (minor >= 2))
1153 for (int j=0; j<tmp_numberOfFaces; j++)
1154 for (int k=0; k<NumberOfNodeByFace; k++)
1155 constituentArray[j*NumberOfNodeByFace+k]=tmp_constituentArray[j*(NumberOfNodeByFace+multi)+k] ;
1157 //////////////////////////////////////////////////////////////////////////////////////
1158 /// Modification pour prise en compte de la numérotation optionnelle des noeuds ///
1159 //////////////////////////////////////////////////////////////////////////////////////
1161 /// Rénumérote le tableau temporaire tmp_constituentArray en utilisant _optionnalToCanonicNodesNumbers
1162 /// Le traitement est identique à la version originelle s'il n'y a pas de numérotation optionnelle
1164 // if (_ptrMesh->_arePresentOptionnalNodesNumbers)
1166 // for (int j=0; j<tmp_numberOfFaces; j++) for (int k=0; k<NumberOfNodeByFace; k++)
1167 // constituentArray[j*NumberOfNodeByFace+k]=_ptrMesh->_optionnalToCanonicNodesNumbers[tmp_constituentArray[j*(NumberOfNodeByFace+1)+k]] ;
1171 // for (int j=0; j<tmp_numberOfFaces; j++) for (int k=0; k<NumberOfNodeByFace; k++)
1172 // constituentArray[j*NumberOfNodeByFace+k]=tmp_constituentArray[j*(NumberOfNodeByFace+1)+k] ;
1175 //////////////////////////////////////////////////////////////////////////////////////
1177 delete[] tmp_constituentArray;
1180 constituent->_nodal = new MEDSKYLINEARRAY(constituent->_count[constituent->_numberOfTypes]-1,
1184 delete[] NodalIndex ;
1185 delete[] NodalValue ;
1188 Connectivity->_constituent = constituent ;
1191 delete[] tmpFaceCount;
1196 if (numberOfEdgesTypes!=0)
1198 CONNECTIVITY * constituent = new CONNECTIVITY(numberOfEdgesTypes,MED_EDGE) ;
1199 constituent->_entityDimension = 1 ;
1200 constituent->_count[0]=1 ;
1204 // if you declare a variable <i> in two <for> initialization statement,
1205 // compiler gcc2.95.3 says nothing but there are two <i> variables in the same block
1206 //and the value you get in the common block seems to be the value of the first variable !
1209 for ( i=1; i<MED_NBR_GEOMETRIE_MAILLE; i++)
1210 { // no point1 cell type (?)
1211 if (tmpEdgeCount[i]>0)
1214 constituent->_count[typeNumber]=constituent->_count[typeNumber-1]+tmpEdgeCount[i];
1215 CELLMODEL t( (MED_EN::medGeometryElement) MED_MESH_DRIVER22::all_cell_type[i]) ;
1216 constituent->_type[typeNumber-1]=t ;
1218 constituent->_geometricTypes[typeNumber-1]=( MED_EN::medGeometryElement) MED_MESH_DRIVER22::all_cell_type[i] ;
1220 size+=tmpEdgeCount[i]*((MED_MESH_DRIVER22::all_cell_type[i])%100) ;
1225 // Creation of the MEDSKYLINEARRAY
1226 //constituent->_nodal = new MEDSKYLINEARRAY(constituent->_count[constituent->_numberOfTypes]-1,size) ;
1227 //int * NodalIndex = constituent->_nodal->getIndex() ;
1228 int * NodalValue = new int[size] ;
1229 int * NodalIndex = new int[constituent->_count[constituent->_numberOfTypes]] ;
1232 // Fill the MEDSKYLINEARRAY by reading the MED file.
1233 for ( i=0; i<constituent->_numberOfTypes; i++)
1235 med_2_2::med_geometrie_element med_type = (med_2_2::med_geometrie_element) constituent->_type[i].getType() ;
1237 int NumberOfNodeByEdge = constituent->_type[i].getNumberOfNodes() ;
1240 for (int j=constituent->_count[i]; j<constituent->_count[i+1];j++)
1241 NodalIndex[j]=NodalIndex[j-1]+NumberOfNodeByEdge ;
1243 int tmp_numberOfEdges = constituent->_count[i+1]-constituent->_count[i] ;
1244 // Il faut ajouter 1 pour le zero a la lecture !!!
1246 // ATTENTION UNIQUEMENT POUR MED < 2.2.x
1247 int * tmp_constituentArray = NULL;
1249 MESSAGE(LOC << "Med file version used here " << major << " " << minor << " " << release);
1251 if ((major == 2) && (minor <= 1))
1252 tmp_constituentArray = new int[(NumberOfNodeByEdge+1)*tmp_numberOfEdges] ;
1253 else if ((major == 2) && (minor >= 2))
1255 tmp_constituentArray = new int[NumberOfNodeByEdge*tmp_numberOfEdges] ;
1256 MESSAGE(LOC<<": WE ARE USING MED2.2 so there is no +1 for calculating the size of tmp_constituentArray !") ;
1259 int err=MEDconnLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
1260 spaceDimension,tmp_constituentArray,
1261 med_2_2::MED_FULL_INTERLACE,NULL,0,med_2_2::MED_MAILLE,med_type,med_2_2::MED_NOD);
1262 if ( err != MED_VALID)
1264 MESSAGE(LOC<<": MEDconnLire returns "<<err) ;
1265 delete constituent ;
1266 delete[] tmp_constituentArray;
1267 delete[] tmpEdgeCount;
1271 int * constituentArray = NodalValue + NodalIndex[constituent->_count[i]-1]-1 ;
1273 // version originale sans prise en compte des numéros optionnels
1275 int multi = 0; // quand est-ce que multi vaut 1 ?? en MED-fichier < 2.2 ??
1276 MESSAGE(LOC << "Med file version used here " << major << " " << minor << " " << release);
1278 if ((major == 2) && (minor <= 1))
1279 for (int j=0; j<tmp_numberOfEdges; j++)
1280 for (int k=0; k<NumberOfNodeByEdge; k++)
1281 constituentArray[j*NumberOfNodeByEdge+k]=tmp_constituentArray[j*(NumberOfNodeByEdge+multi)+k] ;
1282 else if ((major == 2) && (minor >= 2))
1283 for (int j=0; j<tmp_numberOfEdges; j++)
1284 for (int k=0; k<NumberOfNodeByEdge; k++)
1285 constituentArray[j*NumberOfNodeByEdge+k]=tmp_constituentArray[j*(NumberOfNodeByEdge)+k] ;
1287 //////////////////////////////////////////////////////////////////////////////////////
1288 /// Modification pour prise en compte de la numérotation optionnelle des noeuds ///
1289 //////////////////////////////////////////////////////////////////////////////////////
1291 /// Rénumérote le tableau temporaire tmp_constituentArray en utilisant _optionnalToCanonicNodesNumbers
1292 /// Le traitement est identique à la version originelle s'il n'y a pas de numérotation optionnelle
1294 // if (_ptrMesh->_arePresentOptionnalNodesNumbers)
1296 // for (int j=0; j<tmp_numberOfEdges; j++) for (int k=0; k<NumberOfNodeByEdge; k++)
1297 // constituentArray[j*NumberOfNodeByEdge+k]=_ptrMesh->_optionnalToCanonicNodesNumbers[tmp_constituentArray[j*(NumberOfNodeByEdge+1)+k]] ;
1301 // for (int j=0; j<tmp_numberOfEdges; j++) for (int k=0; k<NumberOfNodeByEdge; k++)
1302 // constituentArray[j*NumberOfNodeByEdge+k]=tmp_constituentArray[j*(NumberOfNodeByEdge+1)+k] ;
1305 //////////////////////////////////////////////////////////////////////////////////////
1307 delete[] tmp_constituentArray;
1310 constituent->_nodal = new MEDSKYLINEARRAY(constituent->_count[constituent->_numberOfTypes]-1,
1315 delete[] NodalIndex ;
1316 delete[] NodalValue ;
1318 if (Connectivity->_entityDimension == 3)
1320 if (Connectivity->_constituent==NULL)
1321 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Edges are defined but there are no Faces !"));
1322 Connectivity->_constituent->_constituent = constituent ;
1324 Connectivity->_constituent = constituent ;
1327 delete[] tmpEdgeCount;
1330 } // end classic geometric types
1331 delete[] tmp_cells_count;
1335 // Lecture des polygones MED_CELL
1336 int NumberOfPolygons = MEDnEntMaa(_medIdt,
1337 const_cast <char *> (_ptrMesh->_name.c_str()),
1340 med_2_2::MED_POLYGONE,
1343 // Correction to permit the loading of mesh dimensionned at 2 even
1344 // if it has only MED_POLYGON elements
1346 if (NumberOfPolygons > 0)
1348 if (Connectivity->_entityDimension < 2) Connectivity->_entityDimension = 2;
1351 if (NumberOfPolygons > 0)
1353 // By consequence this exception will never occur
1354 if (Connectivity->_entityDimension == 1)
1355 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"In a 2D mesh, polygons need at least one 2D cell of a classic geometric type !"));
1356 med_int ConnectivitySize;
1357 med_err err1 = MEDpolygoneInfo(_medIdt,
1358 const_cast <char *> (_ptrMesh->_name.c_str()),
1362 if (err1 != MED_VALID)
1364 MESSAGE(LOC<<": MEDpolygoneInfo returns "<<err1);
1368 med_int* PolygonsConnectivity = new med_int[ConnectivitySize];
1369 med_int* PolygonsConnectivityIndex = new med_int[NumberOfPolygons+1];
1371 med_err err2 = MEDpolygoneConnLire(_medIdt,
1372 const_cast <char *> (_ptrMesh->_name.c_str()),
1373 PolygonsConnectivityIndex,
1375 PolygonsConnectivity,
1378 if (err2 != MED_VALID)
1380 MESSAGE(LOC<<": MEDpolygoneConnLire returns "<<err2);
1384 if (Connectivity->_entityDimension == 2) // 2D mesh : polygons in Connectivity
1385 Connectivity->setPolygonsConnectivity(MED_NODAL,(medEntityMesh) Entity,PolygonsConnectivity,PolygonsConnectivityIndex,ConnectivitySize,NumberOfPolygons);
1386 else if (Connectivity->_entityDimension == 3)
1388 if (Connectivity->_constituent == NULL) // 3D mesh : polygons in Connectivity->_constituent
1389 Connectivity->_constituent = new CONNECTIVITY(MED_FACE);
1390 Connectivity->_constituent->setPolygonsConnectivity(MED_NODAL,MED_FACE,PolygonsConnectivity,PolygonsConnectivityIndex,ConnectivitySize,NumberOfPolygons);
1393 delete[] PolygonsConnectivity;
1394 delete[] PolygonsConnectivityIndex;
1399 // Lecture des polyedres MED_CELL
1400 med_int NumberOfPolyhedron = MEDnEntMaa(_medIdt,
1401 const_cast <char *> (_ptrMesh->_name.c_str()),
1404 med_2_2::MED_POLYEDRE,
1407 // Correction to permit the loading of mesh dimensionned at 3 even
1408 // if it has only MED_POLYEDRE elements
1410 if (NumberOfPolyhedron > 0)
1412 Connectivity->_entityDimension = 3;
1415 if (NumberOfPolyhedron > 0)
1417 // By consequence this exception will never occur
1418 if (Connectivity->_entityDimension == 2 || Connectivity->_entityDimension == 1)
1419 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"In a 3D mesh, polyhedron need at least one 3D cell of a classic geometric type !"));
1420 med_int FacesIndexSize, NumberOfNodes, NumberOfFaces;
1421 med_err err3 = MEDpolyedreInfo(_medIdt,
1422 const_cast <char *> (_ptrMesh->_name.c_str()),
1426 NumberOfFaces = FacesIndexSize-1;
1427 if (err3 != MED_VALID)
1429 MESSAGE(LOC<<": MEDpolyhedreInfo returns "<<err3);
1433 med_int* Nodes = new med_int[NumberOfNodes];
1434 med_int* FacesIndex = new med_int[NumberOfFaces+1];
1435 med_int* PolyhedronIndex = new med_int[NumberOfPolyhedron+1];
1437 med_err err4 = MEDpolyedreConnLire(_medIdt,
1438 const_cast <char *> (_ptrMesh->_name.c_str()),
1440 NumberOfPolyhedron+1,
1445 if (err4 != MED_VALID)
1447 MESSAGE(LOC<<": MEDpolyedreConnLire returns "<<err4);
1451 Connectivity->setPolyhedronConnectivity(MED_NODAL,Nodes,PolyhedronIndex,NumberOfNodes,NumberOfPolyhedron,FacesIndex,NumberOfFaces);
1454 delete[] FacesIndex;
1455 delete[] PolyhedronIndex;
1460 // If there is no nodal connectivity, we return MED_ERROR !
1461 if (Connectivity->_numberOfTypes == 0 && NumberOfPolygons == 0 && NumberOfPolyhedron == 0)
1470 int MED_MESH_RDONLY_DRIVER22::getFAMILY()
1472 const char * LOC = "MED_MESH_RDONLY_DRIVER22::getFAMILY() : " ;
1475 if (_status==MED_OPENED)
1479 int * MEDArrayNodeFamily = NULL ;
1480 int ** MEDArrayCellFamily = NULL ;
1481 int ** MEDArrayFaceFamily = NULL ;
1482 int ** MEDArrayEdgeFamily = NULL ;
1485 MEDArrayNodeFamily = new int[_ptrMesh->getNumberOfNodes()] ;
1487 err = getNodesFamiliesNumber(MEDArrayNodeFamily) ;
1488 // error only if (_status!=MED_OPENED), other case exeception !
1491 MESSAGE(LOC << "error returned from getNodesFamiliesNumber " << err);
1493 MEDArrayCellFamily = new int* [_ptrMesh->getNumberOfTypesWithPoly(MED_CELL)] ;
1494 // ET SI IL N'Y A PAS DE CELLS ?
1496 medGeometryElement * myTypes = _ptrMesh->getTypesWithPoly(MED_CELL);
1497 for (int i=0;i<_ptrMesh->getNumberOfTypesWithPoly(MED_CELL);i++)
1498 MEDArrayCellFamily[i] = new
1499 int[_ptrMesh->getNumberOfElementsWithPoly(MED_CELL,myTypes[i])] ;
1501 err = getCellsFamiliesNumber(MEDArrayCellFamily,
1502 _ptrMesh->_connectivity,MED_CELL) ;
1505 MESSAGE(LOC << "error returned from getCellsFamiliesNumber for Cells " << err);
1507 if (_ptrMesh->_connectivity->_constituent != NULL)
1509 if (_ptrMesh->_connectivity->_constituent->_entity == MED_EN::MED_FACE)
1512 MEDArrayFaceFamily = new
1513 int* [_ptrMesh->getNumberOfTypesWithPoly(MED_FACE)] ;
1515 myTypes = _ptrMesh->getTypesWithPoly(MED_FACE);
1516 for (int i=0;i<_ptrMesh->getNumberOfTypesWithPoly(MED_FACE);i++)
1517 MEDArrayFaceFamily[i] = new
1518 int[_ptrMesh->getNumberOfElementsWithPoly(MED_FACE,myTypes[i])] ;
1521 getCellsFamiliesNumber(MEDArrayFaceFamily,
1522 _ptrMesh->_connectivity->_constituent,MED_FACE) ;
1524 MESSAGE(LOC << "error returned from getCellsFamiliesNumber for Faces " << err);
1529 MEDArrayEdgeFamily = new
1530 int* [_ptrMesh->getNumberOfTypes(MED_EDGE)] ;
1532 const medGeometryElement *myTypes2 = _ptrMesh->getTypes(MED_EDGE);
1533 for (int i=0;i<_ptrMesh->getNumberOfTypes(MED_EDGE);i++)
1534 MEDArrayEdgeFamily[i] = new
1535 int[_ptrMesh->getNumberOfElements(MED_EDGE,myTypes2[i])] ;
1538 getCellsFamiliesNumber(MEDArrayEdgeFamily,
1539 _ptrMesh->_connectivity->_constituent,MED_FACE) ;
1541 MESSAGE(LOC << "error returned from getCellsFamiliesNumber for Edges in 2D " << err);
1544 if (_ptrMesh->_connectivity->_constituent->_constituent != NULL)
1546 MEDArrayEdgeFamily = new
1547 int* [_ptrMesh->getNumberOfTypes(MED_EDGE)] ;
1549 const medGeometryElement *myTypes2 = _ptrMesh->getTypes(MED_EDGE);
1550 for (int i=0;i<_ptrMesh->getNumberOfTypes(MED_EDGE);i++)
1551 MEDArrayEdgeFamily[i] = new
1552 int[_ptrMesh->getNumberOfElements(MED_EDGE,myTypes2[i])] ;
1555 getCellsFamiliesNumber(MEDArrayEdgeFamily,
1556 _ptrMesh->_connectivity->_constituent->_constituent,MED_EDGE);
1559 MESSAGE(LOC << "error returned from getCellsFamiliesNumber for Edges in 3D " << err);
1564 int NumberOfFamilies = med_2_2::MEDnFam(_medIdt, const_cast <char *>
1565 (_meshName.c_str())) ;
1567 if ( NumberOfFamilies < 1 ) // at least family 0 must exist
1568 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"There is no FAMILY, FAMILY 0 must exists" ));
1570 SCRUTE(NumberOfFamilies);
1572 vector<FAMILY*> &NodeFamilyVector = _ptrMesh->_familyNode ;
1573 vector<FAMILY*> &CellFamilyVector = _ptrMesh->_familyCell ;
1574 vector<FAMILY*> &FaceFamilyVector = _ptrMesh->_familyFace ;
1575 vector<FAMILY*> &EdgeFamilyVector = _ptrMesh->_familyEdge ;
1577 int numberOfNodesFamilies = 0 ;
1578 int numberOfCellsFamilies = 0 ;
1579 int numberOfFacesFamilies = 0 ;
1580 int numberOfEdgesFamilies = 0 ;
1582 for (int i=0;i<NumberOfFamilies;i++)
1584 int NumberOfAttributes = med_2_2::MEDnAttribut(_medIdt,
1586 (_meshName.c_str()),
1589 if (NumberOfAttributes < 0)
1590 throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER22::getFAMILY() : NumberOfAttributes" );
1592 int NumberOfGroups = med_2_2::MEDnGroupe(_medIdt, const_cast <char *>
1593 (_meshName.c_str()),(i+1)) ;
1595 if (NumberOfGroups < 0)
1596 throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER22::getFAMILY() : NumberOfGroups" );
1598 int FamilyIdentifier ;
1599 string FamilyName(MED_TAILLE_NOM,'\0');
1600 int * AttributesIdentifier = new int[NumberOfAttributes] ;
1601 int * AttributesValues = new int[NumberOfAttributes] ;
1602 string AttributesDescription(MED_TAILLE_DESC*NumberOfAttributes,' ') ;
1603 string GroupsNames(MED_TAILLE_LNOM*NumberOfGroups+1,'\0') ;
1604 err = med_2_2::MEDfamInfo(_medIdt,const_cast <char *>
1605 (_meshName.c_str()),
1606 (i+1),const_cast <char *>
1607 (FamilyName.c_str()), &FamilyIdentifier,
1608 AttributesIdentifier,AttributesValues,
1610 (AttributesDescription.c_str()),
1611 &NumberOfAttributes, const_cast <char *>
1612 (GroupsNames.c_str()),&NumberOfGroups);
1615 SCRUTE(GroupsNames);
1620 if (err != MED_VALID)
1621 throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER22::getFAMILY() : ERROR when get FAMILY informations" );
1623 if (FamilyIdentifier != 0 )
1625 FAMILY * Family = new FAMILY(_ptrMesh,FamilyIdentifier,FamilyName,
1627 AttributesIdentifier,
1629 AttributesDescription,
1630 NumberOfGroups,GroupsNames,
1634 MEDArrayEdgeFamily) ;
1637 // if nothing found, delete Family
1639 if (Family->getNumberOfTypes() == 0)
1641 MESSAGE(LOC<<"Nothing found for family "<<FamilyName<<
1646 switch (Family->getEntity())
1648 case MED_EN::MED_NODE :
1649 NodeFamilyVector.push_back(Family) ;
1650 numberOfNodesFamilies++ ;
1652 case MED_EN::MED_CELL :
1653 CellFamilyVector.push_back(Family) ;
1654 numberOfCellsFamilies++ ;
1656 case MED_EN::MED_FACE :
1657 FaceFamilyVector.push_back(Family) ;
1658 numberOfFacesFamilies++ ;
1660 case MED_EN::MED_EDGE :
1661 EdgeFamilyVector.push_back(Family) ;
1662 numberOfEdgesFamilies++ ;
1665 // MESSAGE(LOC << (*Family));
1668 delete [] AttributesIdentifier ;
1669 delete [] AttributesValues ;
1672 if (MEDArrayNodeFamily != NULL)
1673 delete[] MEDArrayNodeFamily ;
1675 if (MEDArrayCellFamily != NULL)
1677 for (int i=0;i<_ptrMesh->getNumberOfTypes(MED_CELL);i++)
1678 delete[] MEDArrayCellFamily[i] ;
1679 delete[] MEDArrayCellFamily ;
1682 if (MEDArrayFaceFamily != NULL)
1684 for (int i=0;i<_ptrMesh->getNumberOfTypes(MED_FACE);i++)
1685 delete[] MEDArrayFaceFamily[i] ;
1686 delete[] MEDArrayFaceFamily ;
1689 if (MEDArrayEdgeFamily != NULL)
1691 for (int i=0;i<_ptrMesh->getNumberOfTypes(MED_EDGE);i++)
1692 delete[] MEDArrayEdgeFamily[i] ;
1693 delete[] MEDArrayEdgeFamily ;
1703 int MED_MESH_RDONLY_DRIVER22::getNodesFamiliesNumber(int * MEDArrayNodeFamily)
1705 const char * LOC = "MED_MESH_RDONLY_DRIVER22::getNodesFamiliesNumber() : " ;
1709 if (_status==MED_OPENED)
1713 err = MEDfamLire(_medIdt, const_cast <char *>
1714 (_ptrMesh->_name.c_str()), MEDArrayNodeFamily,
1715 _ptrMesh->getNumberOfNodes(), med_2_2::MED_NOEUD,
1716 (med_2_2::med_geometrie_element) MED_NONE);
1718 if ( err != MED_VALID)
1719 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "There is no family for the |"<< _ptrMesh->getNumberOfNodes() << "| nodes in mesh |" << _ptrMesh->_name.c_str() << "|"));
1728 int MED_MESH_RDONLY_DRIVER22::getCellsFamiliesNumber(int **MEDArrayFamily,
1729 CONNECTIVITY *Connectivity,
1730 MED_EN::medEntityMesh entity)
1732 const char * LOC = "MED_MESH_RDONLY_DRIVER22::getCellsFamiliesNumber " ;
1736 if (_status==MED_OPENED)
1739 MED_EN::medGeometryElement *types=Connectivity->getGeometricTypesWithPoly(Connectivity->_entity);
1740 for (i=0;i<Connectivity->getNumberOfTypesWithPoly(Connectivity->_entity);i++)
1742 int NumberOfCell=Connectivity->getNumberOfElementsWithPoly(Connectivity->_entity,types[i]);
1743 err=MEDfamLire(_medIdt,const_cast <char *> (_ptrMesh->_name.c_str()),
1744 MEDArrayFamily[i],NumberOfCell,
1745 (med_2_2::med_entite_maillage) Connectivity->_entity,
1746 (med_2_2::med_geometrie_element)types[i]);
1747 if (err != MED_VALID)
1749 err=MEDfamLire(_medIdt,const_cast <char *>
1750 (_ptrMesh->_name.c_str()),
1751 MEDArrayFamily[i],NumberOfCell,
1752 med_2_2::MED_MAILLE,
1753 (med_2_2::med_geometrie_element)types[i]);
1754 if (err != MED_VALID)
1755 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Family not found for entity "<<Connectivity->_entity<<" and geometric type "<<Connectivity->_geometricTypes[i]));
1764 /*--------------------- WRONLY PART -------------------------------*/
1766 MED_MESH_WRONLY_DRIVER22::MED_MESH_WRONLY_DRIVER22()
1770 MED_MESH_WRONLY_DRIVER22::MED_MESH_WRONLY_DRIVER22(const string & fileName,
1772 MED_MESH_DRIVER22(fileName,ptrMesh,MED_WRONLY),IMED_MESH_WRONLY_DRIVER(fileName,ptrMesh),MED_MESH_DRIVER(fileName,ptrMesh,MED_WRONLY)
1774 MESSAGE("MED_MESH_WRONLY_DRIVER22::MED_MESH_WRONLY_DRIVER22(const string & fileName, MESH * ptrMesh) has been created");
1777 MED_MESH_WRONLY_DRIVER22::MED_MESH_WRONLY_DRIVER22(const MED_MESH_WRONLY_DRIVER22 & driver):
1778 IMED_MESH_WRONLY_DRIVER(driver),MED_MESH_DRIVER22(driver),MED_MESH_DRIVER(driver)
1782 MED_MESH_WRONLY_DRIVER22::~MED_MESH_WRONLY_DRIVER22()
1784 //MESSAGE("MED_MESH_WRONLY_DRIVER22::MED_MESH_WRONLY_DRIVER22(const string & fileName, MESH * ptrMesh) has been destroyed");
1787 GENDRIVER * MED_MESH_WRONLY_DRIVER22::copy(void) const
1789 return new MED_MESH_WRONLY_DRIVER22(*this);
1792 void MED_MESH_WRONLY_DRIVER22::write(void) const
1794 const char * LOC = "void MED_MESH_WRONLY_DRIVER22::write(void) const : ";
1797 // we must first create mesh !!
1798 MESSAGE(LOC << "MeshName : |" << _meshName << "| FileName : |"<<_fileName<<"| MedIdt : | "<< _medIdt << "|");
1800 if (_status!=MED_OPENED)
1801 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "File "<<_fileName<<" is not open. Open it before write !"));
1804 if ( ( _meshName.empty() ) && ( _ptrMesh->_name.empty() ) )
1805 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)
1806 <<" neither <meshName> is set in driver nor in object MESH.")) ;
1808 // If _meshName is not set in driver, try to use _ptrmesh->_meshName
1809 if ( ( _meshName.empty() ) && ( !_ptrMesh->_name.empty() ) )
1810 _meshName=_ptrMesh->_name;
1812 if ( _meshName.size() > MED_TAILLE_NOM )
1813 throw MEDEXCEPTION(LOCALIZED(STRING(LOC)
1814 <<" <meshName> size in object driver MESH is > MED_TAILLE_NOM ."));
1817 if (_ptrMesh->getIsAGrid())
1819 if ( writeGRID() != MED_VALID )
1820 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeGRID()" )) ;
1824 if (writeCoordinates()!=MED_VALID)
1825 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeCoordinates()" )) ;
1827 if (writeConnectivities(MED_EN::MED_CELL)!=MED_VALID)
1828 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeConnectivities(MED_CELL)" )) ;
1829 if (writeConnectivities(MED_EN::MED_FACE)!=MED_VALID)
1830 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeConnectivities(MED_FACE)" )) ;
1831 if (writeConnectivities(MED_EN::MED_EDGE)!=MED_VALID)
1832 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeConnectivities(MED_EDGE)" )) ;
1835 if (writeFamilyNumbers() !=MED_VALID)
1836 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilyNumbers()" )) ;
1839 // well we must first write zero family :
1840 if (_status==MED_OPENED) {
1842 // test if the family already exists (HDF trick waiting a MED evolution to be replaced)
1843 string dataGroupFam = "/ENS_MAA/"+_meshName+"/FAS/FAMILLE_ZERO/";
1844 MESSAGE("|"<<dataGroupFam<<"|");
1845 err =med_2_2::_MEDdatagroupOuvrir(_medIdt,const_cast <char *> (dataGroupFam.c_str()) );
1846 if ( err < MED_VALID ) {
1849 char familyName[MED_TAILLE_NOM+1];
1850 // strcpy(familyName,"FAMILLE_ZERO");
1851 err = med_2_2::MEDfamCr( _medIdt,
1852 const_cast <char *> ( _meshName.c_str() ),
1854 (int*)NULL, (int*)NULL, (char*)NULL, 0,
1859 if ( err != MED_VALID)
1860 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't create family |FAMILLE_ZERO| with identifier |0| groups names || and attributes descriptions ||")) ;
1863 med_2_2::_MEDdatagroupFermer(_medIdt);
1867 MESSAGE(LOC<<"writeFamilies(_ptrMesh->_familyNode)");
1868 if (writeFamilies(_ptrMesh->_familyNode) !=MED_VALID)
1869 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilies(_ptrMesh->_familyNode)" )) ;
1871 MESSAGE(LOC<<"writeFamilies(_ptrMesh->_familyCell)");
1872 if (writeFamilies(_ptrMesh->_familyCell) !=MED_VALID)
1873 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilies(_ptrMesh->_familyCell)" )) ;
1875 MESSAGE(LOC<<"writeFamilies(_ptrMesh->_familyFace)");
1876 if (writeFamilies(_ptrMesh->_familyFace) !=MED_VALID)
1877 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilies(_ptrMesh->_familyFace)" )) ;
1879 MESSAGE(LOC<<"writeFamilies(_ptrMesh->_familyEdge)");
1880 if (writeFamilies(_ptrMesh->_familyEdge) !=MED_VALID)
1881 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilies(_ptrMesh->_familyEdge)" )) ;
1886 //=======================================================================
1887 //function : writeGRID
1889 //=======================================================================
1891 int MED_MESH_WRONLY_DRIVER22::writeGRID() const
1893 const char * LOC = "MED_MESH_WRONLY_DRIVER22::writeGRID() : " ;
1896 if (_status!=MED_OPENED)
1898 MESSAGE (LOC<<" Not open !!!");
1901 GRID * ptrGrid = (GRID*) _ptrMesh;
1903 med_2_2::med_err err = MED_ERROR;
1904 med_2_2::med_repere rep;
1905 string tmp_name(_ptrMesh->_spaceDimension*MED_TAILLE_PNOM22,' ');
1906 string tmp_unit(_ptrMesh->_spaceDimension*MED_TAILLE_PNOM22,' ');
1908 // Test if the mesh <_meshName> already exists
1909 // If it doesn't exists create it
1910 // If it already exists verify if its space and mesh dimensions are the same
1911 // as <_ptrMesh->_spaceDimension>, <_ptrMesh->_meshDimension> respectively
1912 // rem : <_meshName> is the driver meshName not <ptrMesh->_meshName>
1914 int spaceDimension = med_2_2::MEDdimEspaceLire(_medIdt, const_cast <char *>
1915 (_meshName.c_str()) );
1917 int meshDimension = med_2_2::MEDdimLire(_medIdt, const_cast <char *>
1918 (_meshName.c_str()) );
1921 MESSAGE(LOC << "spacedim " << spaceDimension << " meshdim " << meshDimension);
1923 MESSAGE(LOC << "From the mesh spacedim " << _ptrMesh->_spaceDimension << " meshdim " << _ptrMesh->_meshDimension);
1925 if ((spaceDimension <= MED_VALID) && (meshDimension <= MED_VALID))
1927 err = MEDmaaCr(_medIdt,
1928 const_cast <char *> (_meshName.c_str()),
1929 _ptrMesh->_meshDimension,med_2_2::MED_STRUCTURE,
1930 const_cast <char *> (_ptrMesh->_description.c_str()));
1932 meshDimension = _ptrMesh->_meshDimension;
1934 if (err != MED_VALID)
1935 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Unable to create Grid"));
1937 MESSAGE(LOC<<"Grid "<<_meshName<<" created in file "<<_fileName<<" !");
1939 else if ((spaceDimension != _ptrMesh->_spaceDimension) &&
1940 (meshDimension != _ptrMesh->_meshDimension))
1941 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Grid |" << _meshName.c_str() <<
1942 "| already exists in file |" << _fileName <<
1943 "| with space dimension |" << spaceDimension <<
1944 "| and mesh dimension |" << meshDimension <<
1945 "| but the space dimension and the mesh dimension of the mesh we want to write are respectively |"
1946 << _ptrMesh->_spaceDimension <<"|" <<
1947 _ptrMesh->_meshDimension <<"|" )) ;
1949 MED_EN::med_grid_type gridType = ptrGrid->getGridType();
1951 err = med_2_2::MEDnatureGrilleEcr(_medIdt,
1952 const_cast <char *> (_meshName.c_str()),
1953 (med_2_2::med_type_grille) gridType);
1955 if (err != MED_VALID)
1956 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Unable to write the type of the Grid"));
1958 // Recompose the <_spaceDimension> strings in 1 string
1960 string valueString ;
1961 for (int i=0;i<_ptrMesh->_spaceDimension;i++) {
1963 valueString = _ptrMesh->_coordinate->_coordinateName[i] ;
1964 lengthString = (MED_TAILLE_PNOM22<valueString.size())?MED_TAILLE_PNOM22:valueString.size() ;
1965 tmp_name.replace(i*MED_TAILLE_PNOM22,i*MED_TAILLE_PNOM22+lengthString,valueString,0,lengthString);
1966 valueString = _ptrMesh->_coordinate->_coordinateUnit[i];
1967 lengthString = (MED_TAILLE_PNOM22<valueString.size())?MED_TAILLE_PNOM22:valueString.size() ;
1968 tmp_unit.replace(i*MED_TAILLE_PNOM22,i*MED_TAILLE_PNOM22+lengthString,valueString,0,lengthString);
1971 // Pourquoi le stocker sous forme de chaîne ?
1972 const string & coordinateSystem = _ptrMesh->_coordinate->_coordinateSystem;
1973 if (coordinateSystem == "CARTESIAN")
1974 rep = med_2_2::MED_CART;
1975 else if ( coordinateSystem == "CYLINDRICAL")
1976 rep = med_2_2::MED_CYL;
1977 else if ( coordinateSystem == "SPHERICAL" )
1978 rep = med_2_2::MED_SPHER;
1980 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Grid |" << _meshName.c_str() <<
1981 "| doesn't have a valid coordinate system : |"
1982 << _ptrMesh->_coordinate->_coordinateSystem
1985 med_2_2::med_int ArrayLen[] = { (med_2_2::med_int) ptrGrid->_iArrayLength,
1986 (med_2_2::med_int) ptrGrid->_jArrayLength,
1987 (med_2_2::med_int) ptrGrid->_kArrayLength };
1989 // Write node coordinates for MED_BODY_FITTED grid
1990 if (gridType == MED_EN::MED_BODY_FITTED)
1992 // Write Coordinates and families
1993 // double * coo = const_cast <double *>
1994 // (_ptrMesh->_coordinate->getCoordinates(MED_EN::MED_FULL_INTERLACE));
1996 err = MEDcoordEcr(_medIdt, const_cast <char *> (_meshName.c_str()),
1997 _ptrMesh->_spaceDimension,
1998 //const_cast <double *> ( _ptrMesh->_coordinate->_coordinate->get(MED_EN::MED_FULL_INTERLACE) ),
1999 const_cast <double *> ( _ptrMesh->_coordinate->_coordinate.get(MED_EN::MED_FULL_INTERLACE) ),
2000 med_2_2::MED_FULL_INTERLACE, _ptrMesh->_numberOfNodes,
2001 // _ptrMesh->_coordinate->_numberOfNodes
2002 rep, const_cast <char *> (tmp_name.c_str()),
2003 const_cast <char *> (tmp_unit.c_str()));
2005 if (err != MED_VALID)
2006 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write coordinates of the grid |" << _meshName.c_str() << "| in file |" << _fileName
2007 << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and"
2008 << " with units names |" << tmp_name
2009 << "| and units |" << tmp_unit
2012 int* structure = new int [meshDimension];
2014 for (int idim = 0; idim < meshDimension; ++idim)
2015 structure[idim] = ArrayLen [idim];
2018 err = med_2_2::MEDstructureCoordEcr(_medIdt, const_cast <char *>
2019 (_meshName.c_str()), meshDimension,
2022 if (err != MED_VALID)
2023 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"error in writing the structure of the grid |" << _meshName.c_str()));
2027 else if ((gridType == MED_EN::MED_CARTESIAN) ||
2028 (gridType == MED_EN::MED_POLAR))
2030 // Write Arrays of Cartesian or Polar Grid
2032 double * Array[] = { ptrGrid->_iArray,
2036 for (int idim = 0; idim < _ptrMesh->_meshDimension; ++idim)
2038 string str_name = string (tmp_name,idim*MED_TAILLE_PNOM22,
2040 string str_unit = string (tmp_unit,idim*MED_TAILLE_PNOM22,
2043 err = med_2_2::MEDindicesCoordEcr(_medIdt, const_cast <char *>
2044 (_ptrMesh->_name.c_str()),
2045 _ptrMesh->_meshDimension,
2046 Array[idim], ArrayLen[idim],
2047 (idim+1), const_cast <char *>
2050 (str_unit.c_str()));
2052 if (err != MED_VALID)
2053 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<
2054 "Can't write grid coordinates for " <<
2055 idim << "-th dimention"));
2057 } // end Write Cartesian or Polar Grid
2063 //=======================================================================
2064 //function : writeCoordinates
2066 //=======================================================================
2068 int MED_MESH_WRONLY_DRIVER22::writeCoordinates() const {
2070 const char * LOC = "int MED_MESH_WRONLY_DRIVER22::writeCoordinates() const : ";
2073 med_2_2::med_err err = MED_ERROR;
2074 med_2_2::med_repere rep;
2075 string tmp_name(_ptrMesh->_spaceDimension*MED_TAILLE_PNOM22,' ');
2076 string tmp_unit(_ptrMesh->_spaceDimension*MED_TAILLE_PNOM22,' ');
2078 // Recompose the <_spaceDimension> strings in 1 string
2080 string valueString ;
2081 for (int i=0;i<_ptrMesh->_spaceDimension;i++) {
2082 valueString = _ptrMesh->_coordinate->_coordinateName[i] ;
2083 lengthString = (MED_TAILLE_PNOM22<valueString.size())?MED_TAILLE_PNOM22:valueString.size() ;
2084 tmp_name.replace(i*MED_TAILLE_PNOM22,i*MED_TAILLE_PNOM22+lengthString,valueString,0,lengthString);
2085 valueString = _ptrMesh->_coordinate->_coordinateUnit[i];
2086 lengthString = (MED_TAILLE_PNOM22<valueString.size())?MED_TAILLE_PNOM22:valueString.size() ;
2087 tmp_unit.replace(i*MED_TAILLE_PNOM22,i*MED_TAILLE_PNOM22+lengthString,valueString,0,lengthString);
2090 // Test if the mesh <_meshName> already exists
2091 // If it doesn't exists create it
2092 // If it already exists verify if its space and mesh dimensions are the same
2093 // as <_ptrMesh->_spaceDimension>, <_ptrMesh->_meshDimension> respectively
2094 // rem : <_meshName> is the driver meshName not <ptrMesh->_meshName>
2096 int spaceDimension = med_2_2::MEDdimEspaceLire(_medIdt, const_cast <char *>
2097 (_meshName.c_str()));
2099 int meshDimension = med_2_2::MEDdimLire(_medIdt, const_cast <char *>
2100 (_meshName.c_str()) );
2102 SCRUTE(spaceDimension);
2103 SCRUTE(meshDimension);
2104 SCRUTE(_ptrMesh->_spaceDimension);
2105 SCRUTE(_ptrMesh->_meshDimension);
2107 if ((spaceDimension != MED_VALID) && (meshDimension < MED_VALID))
2109 err = MEDmaaCr(_medIdt, const_cast <char *> (_meshName.c_str()),
2110 _ptrMesh->_meshDimension, med_2_2::MED_NON_STRUCTURE,
2111 const_cast <char *> (_ptrMesh->_description.c_str()));
2113 if (err < MED_VALID)
2114 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Unable to create Mesh : |" << _meshName << "|"));
2116 MESSAGE(LOC<<"Mesh "<<_meshName<<" created in file "<<_fileName<<" !");
2118 else if ((spaceDimension != _ptrMesh->_spaceDimension) &&
2119 (meshDimension != _ptrMesh->_meshDimension))
2120 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Mesh |" << _meshName.c_str() <<
2121 "| already exists in file |" << _fileName <<
2122 "| with space dimension |" << spaceDimension <<
2123 "| and mesh dimension |" << meshDimension <<
2124 "| but the space dimension and the mesh dimension of the mesh we want to write are respectively |"
2125 << _ptrMesh->_spaceDimension <<"|" <<
2126 _ptrMesh->_meshDimension << "|")) ;
2128 // Pourquoi le stocker sous forme de chaîne ?
2129 const string & coordinateSystem = _ptrMesh->_coordinate->_coordinateSystem;
2130 if (coordinateSystem == "CARTESIAN")
2131 rep = med_2_2::MED_CART;
2132 else if ( coordinateSystem == "CYLINDRICAL")
2133 rep = med_2_2::MED_CYL;
2134 else if ( coordinateSystem == "SPHERICAL" )
2135 rep = med_2_2::MED_SPHER;
2137 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Mesh |" << _meshName.c_str() << "| doesn't have a valid coordinate system : |"
2138 << _ptrMesh->_coordinate->_coordinateSystem
2141 // err = MEDcoordEcr(_medIdt, const_cast <char *> (_meshName.c_str()),
2142 // _ptrMesh->_spaceDimension,
2143 // //const_cast <double *> ( _ptrMesh->_coordinate->_coordinate->get(MED_EN::MED_FULL_INTERLACE) ),
2144 // const_cast <double *> ( _ptrMesh->_coordinate->_coordinate.get(MED_EN::MED_FULL_INTERLACE) ),
2145 // MED_FR::MED_FULL_INTERLACE,
2146 // _ptrMesh->_numberOfNodes, // _ptrMesh->_coordinate->_numberOfNodes
2147 // MED_FR::MED_LECTURE_ECRITURE,
2149 // const_cast <char *> (tmp_name.c_str()),
2150 // const_cast <char *> (tmp_unit.c_str())
2153 err = MEDcoordEcr(_medIdt, const_cast <char *> (_meshName.c_str()),
2154 _ptrMesh->_spaceDimension,
2155 //const_cast <double *> ( _ptrMesh->_coordinate->_coordinate->get(MED_EN::MED_FULL_INTERLACE) ),
2156 const_cast <double *> ( _ptrMesh->_coordinate->_coordinate.get(MED_EN::MED_FULL_INTERLACE) ),
2157 med_2_2::MED_FULL_INTERLACE, _ptrMesh->_numberOfNodes,
2158 // _ptrMesh->_coordinate->_numberOfNodes
2159 rep, const_cast <char *> (tmp_name.c_str()),
2160 const_cast <char *> (tmp_unit.c_str()));
2163 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write coordinates of mesh |" << _meshName.c_str() << "| in file |" << _fileName
2164 << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and"
2165 << " with units names |" << tmp_name
2166 << "| and units |" << tmp_unit
2170 //////////////////////////////////////////////////////////////////////////////////////
2171 /// Modification pour prise en compte de la numérotation optionnelle des noeuds ///
2172 //////////////////////////////////////////////////////////////////////////////////////
2174 /// Ecrit les numéros optionnels des noeuds
2175 /// Le traitement est identique à la version originelle s'il n'y a pas de numérotation optionnelle
2178 if (_ptrMesh->_arePresentOptionnalNodesNumbers==1) {
2180 err = MEDnumEcr(_medIdt, const_cast <char *> (_meshName.c_str()),
2181 const_cast <med_int *> (_ptrMesh->_coordinate->getNodesNumbers() ),
2182 _ptrMesh->_numberOfNodes, med_2_2::MED_NOEUD,
2183 med_2_2::med_geometrie_element(0) );
2185 if (err != MED_VALID)
2186 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write optionnal numbers of mesh |" <<
2187 _meshName.c_str() << "| in file |" <<
2188 _fileName << " |")) ;
2190 //////////////////////////////////////////////////////////////////////////////////////
2200 int MED_MESH_WRONLY_DRIVER22::writeConnectivities(medEntityMesh entity) const
2202 const char * LOC="int MED_MESH_WRONLY_DRIVER22::writeConnectivities() const : ";
2205 med_2_2::med_err err;
2207 // REM SI LA METHODE EST APPELEE DIRECTEMENT ET QUE LE MAILLAGE N'EST PAS CREE IL Y A PB !
2208 // PG : IMPOSSIBLE : LA METHODE EST PRIVEE !
2210 // A FAIRE : A tester surtout dans les methodes de MESH.
2211 // if ( _ptrMesh->_connectivity == (CONNECTIVITY *) MED_INVALID )
2212 if ( _ptrMesh->_connectivity == (CONNECTIVITY *) NULL )
2213 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "The connectivity is not defined in the MESH object ")) ;
2216 // Nodal connectivity for classic geometric types
2217 if ( _ptrMesh->existConnectivity(MED_NODAL,entity) )
2220 int numberOfTypes = _ptrMesh->getNumberOfTypes (entity) ;
2221 const medGeometryElement * types = _ptrMesh->getTypes (entity) ;
2223 for (int i=0; i<numberOfTypes; i++)
2226 int numberOfElements = _ptrMesh->getNumberOfElements (entity,types[i]);
2227 const int * connectivity = _ptrMesh->getConnectivity (MED_EN::MED_FULL_INTERLACE,
2228 MED_NODAL, entity, types[i]); // ?? et SI MED_NODAL n'existe pas, recalcul auto ??
2230 // Pour l'instant la class utilise le multi.....
2232 // if (entity==MED_EN::MED_CELL)
2233 // if ( (types[i]/ 100) < _ptrMesh->_spaceDimension)
2235 int numberOfNodes = types[i]%100 ;
2236 int * connectivityArray = new int[numberOfElements*(numberOfNodes+multi)];
2238 // version originale sans prise en compte des numéros optionnels
2240 for (int j=0 ; j<numberOfElements; j++)
2242 for (int k=0; k<numberOfNodes; k++)
2243 connectivityArray[j*(numberOfNodes+multi)+k]=connectivity[j*numberOfNodes+k] ;
2245 if (multi>0) connectivityArray[j*(numberOfNodes+multi)+numberOfNodes]=0;
2248 //////////////////////////////////////////////////////////////////////////////////////
2249 /// Modification pour prise en compte de la numérotation optionnelle des noeuds ///
2250 //////////////////////////////////////////////////////////////////////////////////////
2252 /// Dénumérote les sommets des mailles pour leur rendre leurs numéros optionnels
2253 /// Le traitement est identique à la version originelle s'il n'y a pas de numérotation optionnelle
2255 // if (_ptrMesh->_arePresentOptionnalNodesNumbers==1)
2257 // const int * nodesNumbers = _ptrMesh->_coordinate->getNodesNumbers();
2258 // for (int j=0 ; j<numberOfElements; j++)
2260 // for (int k=0; k<numberOfNodes; k++) connectivityArray[j*(numberOfNodes+multi)+k]=nodesNumbers[connectivity[j*numberOfNodes+k]-1] ;
2261 // if (multi>0) connectivityArray[j*(numberOfNodes+multi)+numberOfNodes]=0;
2266 // for (int j=0 ; j<numberOfElements; j++)
2268 // for (int k=0; k<numberOfNodes; k++) connectivityArray[j*(numberOfNodes+multi)+k]=connectivity[j*numberOfNodes+k] ;
2269 // if (multi>0) connectivityArray[j*(numberOfNodes+multi)+numberOfNodes]=0;
2273 //////////////////////////////////////////////////////////////////////////////////////
2275 // err = MEDconnEcr( _medIdt, const_cast <char *> ( _meshName.c_str()), _ptrMesh->_spaceDimension,
2276 // connectivityArray, MED_FR::MED_FULL_INTERLACE , numberOfElements,
2277 // MED_FR::MED_LECTURE_ECRITURE,
2278 // (MED_FR::med_entite_maillage ) entity,
2279 // (MED_FR::med_geometrie_element) types[i], MED_FR::MED_NOD );
2281 // err = MEDconnEcr(_medIdt, const_cast <char *> ( _meshName.c_str()),
2282 // _ptrMesh->_spaceDimension, connectivityArray,
2283 // MED_FR::MED_FULL_INTERLACE , numberOfElements,
2284 // (MED_FR::med_entite_maillage ) entity,
2285 // (MED_FR::med_geometrie_element) types[i],
2286 // med_2_2::MED_NOD);
2288 err = MEDconnEcr(_medIdt, const_cast <char *> ( _meshName.c_str()),
2289 _ptrMesh->_spaceDimension, connectivityArray,
2290 med_2_2::MED_FULL_INTERLACE , numberOfElements,
2291 (med_2_2::med_entite_maillage ) MED_CELL,
2292 (med_2_2::med_geometrie_element) types[i],
2295 delete[] connectivityArray ;
2297 if (err<0) // ETENDRE LES EXPLICATIONS
2298 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write connectivities of mesh |" << _meshName.c_str() << "| in file |" << _fileName
2299 << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and"
2307 if (_ptrMesh->existPolygonsConnectivity(MED_NODAL,entity))
2309 err = MEDpolygoneConnEcr(_medIdt,
2310 const_cast <char *> (_meshName.c_str()),
2311 const_cast <med_int*> (_ptrMesh->getPolygonsConnectivityIndex(MED_NODAL,entity)),
2312 _ptrMesh->getNumberOfPolygons()+1,
2313 const_cast <med_int*> (_ptrMesh->getPolygonsConnectivity(MED_NODAL,entity)),
2314 (med_2_2::med_entite_maillage) entity,
2318 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write polygons nodal connectivities of mesh |" << _meshName.c_str() << "| in file |" << _fileName
2319 << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and"
2324 // Polyhedron writing
2325 if (_ptrMesh->existPolyhedronConnectivity(MED_NODAL,entity))
2327 err = MEDpolyedreConnEcr(_medIdt,
2328 const_cast <char *> (_meshName.c_str()),
2329 const_cast <med_int*> (_ptrMesh->getPolyhedronIndex(MED_NODAL)),
2330 _ptrMesh->getNumberOfPolyhedron()+1,
2331 const_cast <med_int*> (_ptrMesh->getPolyhedronFacesIndex()),
2332 _ptrMesh->getNumberOfPolyhedronFaces()+1,
2333 const_cast <med_int*> (_ptrMesh->getPolyhedronConnectivity(MED_NODAL)),
2337 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write polyhedron nodal connectivities of mesh |" << _meshName.c_str() << "| in file |" << _fileName
2338 << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and"
2343 // Descending connectivity for classic geometric types
2344 if ( _ptrMesh->existConnectivity(MED_DESCENDING,entity) )
2347 int numberOfTypes = _ptrMesh->getNumberOfTypes (entity) ;
2348 const medGeometryElement * types = _ptrMesh->getTypes (entity) ;
2350 for (int i=0; i<numberOfTypes; i++)
2353 int numberOfElements = _ptrMesh->getNumberOfElements (entity,types[i]);
2354 const int * connectivity = _ptrMesh->getConnectivity(MED_EN::MED_FULL_INTERLACE, MED_DESCENDING, entity, types[i]);
2356 // Pour l'instant la class utilise le multi.....
2357 // err = MED_FR::MEDconnEcr( _medIdt,
2358 // const_cast <char *> ( _meshName.c_str()),
2359 // _ptrMesh->_spaceDimension,
2360 // const_cast <int *> (connectivity),
2361 // MED_FR::MED_FULL_INTERLACE,
2362 // numberOfElements,
2363 // MED_FR::MED_LECTURE_ECRITURE,
2364 // (MED_FR::med_entite_maillage ) entity,
2365 // (MED_FR::med_geometrie_element) types[i],
2366 // MED_FR::MED_DESC );
2368 err = med_2_2::MEDconnEcr(_medIdt,
2369 const_cast <char *> ( _meshName.c_str()),
2370 _ptrMesh->_spaceDimension,
2371 const_cast <int *> (connectivity),
2372 med_2_2::MED_FULL_INTERLACE,
2374 (med_2_2::med_entite_maillage ) entity,
2375 (med_2_2::med_geometrie_element) types[i],
2376 med_2_2::MED_DESC );
2378 if (err<0) // ETENDRE LES EXPLICATIONS
2379 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write connectivities of mesh |" << _meshName.c_str() << "| in file |" << _fileName
2380 << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and"
2388 if (_ptrMesh->existPolygonsConnectivity(MED_DESCENDING,entity))
2390 err = MEDpolygoneConnEcr(_medIdt,
2391 const_cast <char *> (_meshName.c_str()),
2392 const_cast <med_int*> (_ptrMesh->getPolygonsConnectivityIndex(MED_DESCENDING,entity)),
2393 _ptrMesh->getNumberOfPolygons()+1,
2394 const_cast <med_int*> (_ptrMesh->getPolygonsConnectivity(MED_DESCENDING,entity)),
2395 (med_2_2::med_entite_maillage) entity,
2399 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write polygons descending connectivities of mesh |" << _meshName.c_str() << "| in file |" << _fileName
2400 << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and"
2405 // Polyhedron writing
2406 if (_ptrMesh->existPolyhedronConnectivity(MED_DESCENDING,entity))
2408 med_int NumberOfFaces = _ptrMesh->getPolyhedronIndex(MED_DESCENDING)[_ptrMesh->getNumberOfPolyhedron()]-1;
2409 vector<med_int> FacesGeometricTypes(NumberOfFaces,MED_POLYGON); // by default all polyhedron faces are polygons
2411 err = MEDpolyedreConnEcr(_medIdt,
2412 const_cast <char *> (_meshName.c_str()),
2413 const_cast <med_int*> (_ptrMesh->getPolyhedronIndex(MED_DESCENDING)),
2414 _ptrMesh->getNumberOfPolyhedron()+1,
2415 &FacesGeometricTypes[0],
2417 const_cast <med_int*> (_ptrMesh->getPolyhedronConnectivity(MED_DESCENDING)),
2421 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write polyhedron descending connectivities of mesh |" << _meshName.c_str() << "| in file |" << _fileName
2422 << "| with dimension |" << _ptrMesh->_spaceDimension <<"| and"
2431 int MED_MESH_WRONLY_DRIVER22::writeFamilyNumbers() const {
2433 const char * LOC="int MED_MESH_WRONLY_DRIVER22::writeFamilyNumbers() const : ";
2436 med_2_2::med_err err;
2438 // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArrayNodeFamily DOIT ETRE ENLEVER DE LA CLASSE MESH
2440 { // Node related block
2442 // We build the array from the families list objects :
2443 int NumberOfNodes = _ptrMesh->getNumberOfNodes() ;
2444 int * MEDArrayNodeFamily = new int[NumberOfNodes] ;
2445 // family 0 by default
2446 for (int i=0; i<NumberOfNodes; i++)
2447 MEDArrayNodeFamily[i]=0;
2448 //vector<FAMILY*> myFamilies = _ptrMesh->getFamilies(MED_NODE);
2449 vector<FAMILY*> * myFamilies = &_ptrMesh->_familyNode;
2450 int NumberOfNodesFamilies = myFamilies->size() ;
2451 //bool ToDestroy = false;
2452 if (0 == NumberOfNodesFamilies) {
2453 //ToDestroy = true ;
2454 vector<GROUP*> myGroups = _ptrMesh->getGroups(MED_NODE);
2455 int NumberOfGroups = myGroups.size() ;
2456 // build families from groups
2457 for (int i=0; i<NumberOfGroups; i++) {
2458 SUPPORT * mySupport = myGroups[i] ;
2459 FAMILY* myFamily = new FAMILY(*mySupport);
2460 myFamily->setIdentifier(i+1);
2461 myFamilies->push_back(myFamily);
2463 NumberOfNodesFamilies=myFamilies->size() ;
2465 for (int i=0 ; i<NumberOfNodesFamilies; i++) {
2467 //SCRUTE(myFamilies[i]->getName());
2468 int FamilyIdentifier = (*myFamilies)[i]->getIdentifier() ;
2469 int TotalNumber = (*myFamilies)[i]->getNumberOfElements(MED_ALL_ELEMENTS) ;
2470 if ((*myFamilies)[i]->isOnAllElements())
2471 for (int j=0; j<TotalNumber; j++)
2472 MEDArrayNodeFamily[j]=FamilyIdentifier;
2474 const int * Number = (*myFamilies)[i]->getNumber(MED_ALL_ELEMENTS) ;
2475 for (int j=0; j<TotalNumber; j++)
2476 MEDArrayNodeFamily[Number[j]-1]=FamilyIdentifier ;
2480 for(int j=0; j<NumberOfNodes; j++) {
2481 SCRUTE(MEDArrayNodeFamily[j]);
2484 // if ( !_ptrMesh->getIsAGrid() )
2486 err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
2487 MEDArrayNodeFamily, NumberOfNodes, med_2_2::MED_NOEUD,
2488 (med_2_2::med_geometrie_element) MED_NONE);
2491 // err = MEDfamGridEcr(_medIdt,
2492 // const_cast <char *> (_ptrMesh->_name.c_str()),
2493 // MEDArrayNodeFamily,
2495 // MED_FR::MED_LECTURE_ECRITURE,
2496 // MED_FR::MED_NOEUD);
2498 if ( err != MED_VALID)
2499 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write node family for the |"<< NumberOfNodes
2500 << "| nodes in mesh |"
2501 << _ptrMesh->_name.c_str() << "|" ));
2502 delete[] MEDArrayNodeFamily;
2503 //if (true == ToDestroy)
2504 // for (int i=0; i<NumberOfNodesFamilies; i++)
2505 // delete myFamilies[i];
2508 { // CELLS RELATED BLOCK
2509 medEntityMesh entity=MED_EN::MED_CELL;
2510 // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArray____Family DOIT ETRE ENLEVER DE LA CLASSE MESH
2511 if ( ( _ptrMesh->existConnectivity(MED_NODAL,entity) )|( _ptrMesh->existConnectivity(MED_DESCENDING,entity) ) ) {
2513 int numberOfTypes = _ptrMesh->getNumberOfTypes (entity) ;
2514 const medGeometryElement * types = _ptrMesh->getTypes (entity) ;
2516 // We build the array from the families list objects :
2517 int NumberOfElements = _ptrMesh->getNumberOfElements(entity, MED_ALL_ELEMENTS);
2518 int * MEDArrayFamily = new int[NumberOfElements] ;
2519 // family 0 by default
2520 for (int i=0; i<NumberOfElements; i++)
2521 MEDArrayFamily[i]=0;
2522 //vector<FAMILY*> myFamilies = _ptrMesh->getFamilies(entity);
2523 vector<FAMILY*> * myFamilies = &_ptrMesh->_familyCell ;
2524 int NumberOfFamilies = myFamilies->size() ;
2525 //bool ToDestroy = false;
2526 if (0 == NumberOfFamilies) {
2527 //ToDestroy = true ;
2528 vector<GROUP*> myGroups = _ptrMesh->getGroups(entity);
2529 int NumberOfGroups = myGroups.size() ;
2530 // build families from groups
2531 for (int i=0; i<NumberOfGroups; i++) {
2532 SCRUTE( myGroups[i]->getName() );
2533 SUPPORT * mySupport = myGroups[i] ;
2534 FAMILY* myFamily = new FAMILY(*mySupport);
2535 myFamily->setIdentifier(-i-1);
2536 myFamilies->push_back(myFamily);
2538 NumberOfFamilies=myFamilies->size() ;
2540 for (int i=0 ; i<NumberOfFamilies; i++) {
2541 int FamilyIdentifier = (*myFamilies)[i]->getIdentifier() ;
2542 int TotalNumber = (*myFamilies)[i]->getNumberOfElements(MED_ALL_ELEMENTS) ;
2543 if ((*myFamilies)[i]->isOnAllElements())
2544 for (int ii=0; ii<TotalNumber; ii++)
2545 MEDArrayFamily[ii]=FamilyIdentifier;
2547 const int * Number = (*myFamilies)[i]->getNumber(MED_ALL_ELEMENTS) ;
2548 for (int ii=0; ii<TotalNumber; ii++)
2549 MEDArrayFamily[Number[ii]-1]=FamilyIdentifier ;
2553 const int * typeCount = _ptrMesh->getGlobalNumberingIndex(entity) ;
2554 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000)
2555 int lgth=NumberOfElements;
2556 med_2_2::med_int *temp=new med_2_2::med_int[lgth];
2557 for(int i2=0;i2<lgth;i2++)
2558 temp[i2]=(med_2_2::med_int) (MEDArrayFamily[i2]);
2560 for (int i=0; i<numberOfTypes; i++) {
2561 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000)
2562 err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
2563 temp+typeCount[i]-1,typeCount[i+1]-typeCount[i],
2565 (med_2_2::med_entite_maillage) entity,
2566 (med_2_2::med_geometrie_element) types[i]
2569 err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
2570 (MEDArrayFamily+typeCount[i]-1),
2571 (typeCount[i+1]-typeCount[i]),
2572 (med_2_2::med_entite_maillage) entity,
2573 (med_2_2::med_geometrie_element) types[i]);
2576 if ( err != MED_VALID)
2577 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write family for the |"<< _ptrMesh->getNumberOfElements(entity, types[i])
2578 << "| cells of geometric type |" << geoNames[types[i]] <<"|in mesh |"
2579 << _ptrMesh->_name.c_str() << "|" ));
2581 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000)
2584 delete[] MEDArrayFamily ;
2585 //if (true == ToDestroy) {
2586 // int NumberOfFamilies = myFamilies->size();
2587 // for (int i=0; i<NumberOfFamilies; i++)
2588 // delete myFamilies[i];
2593 { // FACE RELATED BLOCK
2594 medEntityMesh entity=MED_EN::MED_FACE;
2595 // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArray____Family DOIT ETRE ENLEVER DE LA CLASSE MESH
2596 if ( ( _ptrMesh->existConnectivity(MED_NODAL,entity) )|( _ptrMesh->existConnectivity(MED_DESCENDING,entity) ) ) {
2598 int numberOfTypes = _ptrMesh->getNumberOfTypes (entity) ;
2599 const medGeometryElement * types = _ptrMesh->getTypes (entity) ;
2600 SCRUTE(numberOfTypes);
2602 int numberOfElements = _ptrMesh->getNumberOfElements(entity, MED_ALL_ELEMENTS) ;
2603 int * familyArray = new int[numberOfElements] ;
2604 for (int i=0;i<numberOfElements;i++)
2607 int numberOfFamilies = _ptrMesh->getNumberOfFamilies(entity) ;
2608 //vector<FAMILY*> myFamilies = _ptrMesh->getFamilies(entity) ;
2609 vector<FAMILY*> * myFamilies = &_ptrMesh->_familyFace ;
2610 //bool ToDestroy = false;
2611 if (0 == numberOfFamilies) {
2612 //ToDestroy = true ;
2613 vector<GROUP*> myGroups = _ptrMesh->getGroups(entity);
2614 int NumberOfGroups = myGroups.size() ;
2615 // build families from groups
2616 for (int i=0; i<NumberOfGroups; i++) {
2617 SCRUTE( myGroups[i]->getName() );
2618 SUPPORT * mySupport = myGroups[i] ;
2619 FAMILY* myFamily = new FAMILY(*mySupport);
2620 myFamily->setIdentifier(-i-1000);
2621 myFamilies->push_back(myFamily);
2623 numberOfFamilies=myFamilies->size() ;
2625 for (int i=0;i<numberOfFamilies;i++) {
2626 int familyNumber = (*myFamilies)[i]->getIdentifier() ;
2627 int numberOfFamilyElements = (*myFamilies)[i]->getNumberOfElements(MED_ALL_ELEMENTS) ;
2628 if ((*myFamilies)[i]->isOnAllElements())
2629 for (int ii=0; ii<numberOfFamilyElements; ii++)
2630 familyArray[ii]=familyNumber;
2632 const int * myFamilyElements = (*myFamilies)[i]->getNumber(MED_ALL_ELEMENTS) ;
2633 for (int ii=0;ii<numberOfFamilyElements;ii++)
2634 familyArray[myFamilyElements[ii]-1]=familyNumber;
2638 const int * typeCount = _ptrMesh->getGlobalNumberingIndex(entity) ;
2639 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000)
2640 int lgth=numberOfElements;
2641 med_2_2::med_int *temp=new med_2_2::med_int[lgth];
2642 for(int i2=0;i2<lgth;i2++)
2643 temp[i2]=(med_2_2::med_int) (familyArray[i2]);
2645 for (int i=0; i<numberOfTypes; i++) {
2646 int typeNumberOfElements = typeCount[i+1] - typeCount[i] ;
2648 err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
2649 familyArray+typeCount[i]-1, typeNumberOfElements,
2650 (med_2_2::med_entite_maillage) entity,
2651 (med_2_2::med_geometrie_element) types[i]);
2653 if ( err != MED_VALID)
2654 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write family for the |"<< _ptrMesh->getNumberOfElements(entity, types[i])
2655 << "| faces of geometric type |" << geoNames[types[i]] <<"|in mesh |"
2656 << _ptrMesh->_name.c_str() << "|" ));
2658 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000)
2661 delete[] familyArray ;
2662 //if (true == ToDestroy) {
2663 // int NumberOfFamilies = myFamilies->size();
2664 // for (int i=0; i<NumberOfFamilies; i++)
2665 // delete myFamilies[i];
2670 { // EDGE RELATED BLOCK
2671 //medEntityMesh entity=MED_EN::MED_FACE;
2672 medEntityMesh entity=MED_EN::MED_EDGE;
2673 // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArray____Family DOIT ETRE ENLEVER DE LA CLASSE MESH
2674 if ( ( _ptrMesh->existConnectivity(MED_NODAL,entity) )|( _ptrMesh->existConnectivity(MED_DESCENDING,entity) ) ) {
2676 int numberOfTypes = _ptrMesh->getNumberOfTypes (entity) ;
2677 const medGeometryElement * types = _ptrMesh->getTypes (entity) ;
2679 int numberOfElements = _ptrMesh->getNumberOfElements(entity, MED_ALL_ELEMENTS) ;
2680 int * familyArray = new int[numberOfElements] ;
2681 for (int i=0;i<numberOfElements;i++)
2684 int numberOfFamilies = _ptrMesh->getNumberOfFamilies(entity) ;
2685 //vector<FAMILY*> myFamilies = _ptrMesh->getFamilies(entity) ;
2686 vector<FAMILY*> * myFamilies = &_ptrMesh->_familyEdge ;
2687 //bool ToDestroy = false;
2688 if (0 == numberOfFamilies) {
2689 //ToDestroy = true ;
2690 vector<GROUP*> myGroups = _ptrMesh->getGroups(entity);
2691 int NumberOfGroups = myGroups.size() ;
2692 // build families from groups
2693 for (int i=0; i<NumberOfGroups; i++) {
2694 SCRUTE( myGroups[i]->getName() );
2695 SUPPORT * mySupport = myGroups[i] ;
2696 FAMILY* myFamily = new FAMILY(*mySupport);
2697 myFamily->setIdentifier(-i-2000);
2698 myFamilies->push_back(myFamily);
2700 numberOfFamilies=myFamilies->size() ;
2702 for (int i=0;i<numberOfFamilies;i++) {
2703 int familyNumber = (*myFamilies)[i]->getIdentifier() ;
2704 int numberOfFamilyElements = (*myFamilies)[i]->getNumberOfElements(MED_ALL_ELEMENTS) ;
2705 if ((*myFamilies)[i]->isOnAllElements())
2706 for (int ii=0; ii<numberOfFamilyElements; ii++)
2707 familyArray[ii]=familyNumber;
2709 const int * myFamilyElements = (*myFamilies)[i]->getNumber(MED_ALL_ELEMENTS) ;
2710 for (int ii=0;ii<numberOfFamilyElements;ii++)
2711 familyArray[myFamilyElements[ii]-1]=familyNumber;
2715 const int * typeCount = _ptrMesh->getGlobalNumberingIndex(entity) ;
2716 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000)
2717 int lgth=numberOfElements;
2718 med_2_2::med_int *temp=new med_2_2::med_int[lgth];
2719 for(int i2=0;i2<lgth;i2++)
2720 temp[i2]=(med_2_2::med_int) (familyArray[i2]);
2722 for (int i=0; i<numberOfTypes; i++) {
2723 int typeNumberOfElements = typeCount[i+1] - typeCount[i] ;
2725 err = MEDfamEcr(_medIdt, const_cast <char *> ( _meshName.c_str() ),
2726 familyArray+typeCount[i]-1, typeNumberOfElements,
2727 (med_2_2::med_entite_maillage) entity,
2728 (med_2_2::med_geometrie_element) types[i]);
2730 if ( err != MED_VALID)
2731 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write family for the |"<< _ptrMesh->getNumberOfElements(entity, types[i])
2732 << "| edges of geometric type |" << geoNames[types[i]] <<"|in mesh |"
2733 << _ptrMesh->_name.c_str() << "|" ));
2735 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000)
2738 delete[] familyArray ;
2739 //if (true == ToDestroy) {
2740 // int NumberOfFamilies = myFamilies->size();
2741 // for (int i=0; i<NumberOfFamilies; i++)
2742 // delete myFamilies[i];
2751 int MED_MESH_WRONLY_DRIVER22::writeFamilies(vector<FAMILY*> & families ) const
2754 const char * LOC="int MED_MESH_WRONLY_DRIVER22::writeFamilies(vector<FAMILY*> families) const : ";
2757 med_2_2::med_err err;
2759 MESSAGE(LOC<<" families.size() :"<<families.size());
2761 for (unsigned int i=0; i< families.size(); i++) {
2763 int numberOfAttributes = families[i]->getNumberOfAttributes ();
2764 string attributesDescriptions = "";
2766 // Recompose the attributes descriptions arg for MED
2767 for (int j=0; j < numberOfAttributes; j++) {
2769 string attributeDescription = families[i]->getAttributeDescription(j+1);
2771 if ( attributeDescription.size() > MED_TAILLE_DESC )
2772 throw MEDEXCEPTION( LOCALIZED(STRING(LOC) << "The size of the attribute description n° |" << j+1 << "| of the family |" << families[i]->getName()
2773 << "| with identifier |" << families[i]->getIdentifier() << "| is |"
2774 << attributeDescription.size() <<"| and is more than |" << MED_TAILLE_DESC << "|")) ;
2776 attributesDescriptions += attributeDescription;
2780 int numberOfGroups = families[i]->getNumberOfGroups();
2781 string groupsNames(numberOfGroups*MED_TAILLE_LNOM,'\0') ;
2782 // Recompose the groups names arg for MED
2783 for (int j=0; j < numberOfGroups; j++) {
2785 string groupName = families[i]->getGroupName(j+1);
2787 if ( groupName.size() > MED_TAILLE_LNOM )
2788 throw MEDEXCEPTION( LOCALIZED(STRING(LOC) << "The size of the group name n° |" << j+1 << "| of the family |" << families[i]->getName()
2789 << "| with identifier |" << families[i]->getIdentifier() << "| is |"
2790 << groupName.size() <<"| and is more than |" << MED_TAILLE_LNOM << "|")) ;
2793 int length = min(MED_TAILLE_LNOM,(int)groupName.size());
2794 groupsNames.replace(j*MED_TAILLE_LNOM,length, groupName,0,length);
2798 // test if the family already exists (HDF trick waiting a MED evolution to be replaced)
2800 string dataGroupFam;
2801 if (families[i]->getEntity() == MED_NODE)
2802 dataGroupFam = "/ENS_MAA/"+_meshName+"/FAS/NOEUD/"+families[i]->getName()+"/";
2804 dataGroupFam = "/ENS_MAA/"+_meshName+"/FAS/ELEME/"+families[i]->getName()+"/";
2806 SCRUTE("|"<<dataGroupFam<<"|");
2807 err = med_2_2::_MEDdatagroupOuvrir(_medIdt,const_cast <char *> (dataGroupFam.c_str()) ) ;
2808 if ( err < MED_VALID ) {
2811 MESSAGE(LOC<<"families[i]->getName().c_str() : "<<families[i]->getName().c_str());
2812 MESSAGE(LOC<<"_meshName.c_str() : "<<_meshName.c_str());
2813 MESSAGE(LOC<<"families[i]->getIdentifier() : "<<families[i]->getIdentifier());
2814 MESSAGE(LOC<<"numberOfAttributes : "<<numberOfAttributes);
2816 //MESSAGE(LOC<<"families[i]->getAttributesIdentifiers() : "<<families[i]->getAttributesIdentifiers()[0]);
2817 //MESSAGE(LOC<<"families[i]->getAttributesValues() : "<<families[i]->getAttributesValues()[0]);
2818 MESSAGE(LOC<<"attributesDescriptions.c_str() : "<<attributesDescriptions.c_str());
2819 MESSAGE(LOC<<"numberOfGroups : "<<numberOfGroups);
2820 MESSAGE(LOC<<"groupsNames.c_str() : "<<groupsNames.c_str());
2821 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000)
2822 int lgth=families[i]->getNumberOfAttributes();
2823 med_2_2::med_int * AttributesIdentifier2 = new med_2_2::med_int[lgth] ;
2824 med_2_2::med_int * AttributesValues2 = new med_2_2::med_int[lgth] ;
2825 for(med_2_2::med_int i2=0;i2<lgth;i2++)
2827 AttributesIdentifier2[i2]=(med_2_2::med_int)(families[i]->getAttributesIdentifiers()[i2]);
2828 AttributesValues2[i2]=(med_2_2::med_int)(families[i]->getAttributesValues()[i2]);
2830 err = med_2_2::MEDfamCr( _medIdt,
2831 const_cast <char *> ( _meshName.c_str() ),
2832 const_cast <char *> ( families[i]->getName().c_str() ),
2833 families[i]->getIdentifier(),
2834 AttributesIdentifier2,
2836 const_cast <char *> (attributesDescriptions.c_str()),
2838 const_cast <char *> (groupsNames.c_str()),
2840 delete [] AttributesIdentifier2;
2841 delete [] AttributesValues2;
2843 err = med_2_2::MEDfamCr( _medIdt,
2844 const_cast <char *> ( _meshName.c_str() ),
2845 const_cast <char *> ( families[i]->getName().c_str() ),
2846 families[i]->getIdentifier(),
2847 (med_2_2::med_int*)families[i]->getAttributesIdentifiers(),
2848 (med_2_2::med_int*)families[i]->getAttributesValues(),
2849 const_cast <char *> (attributesDescriptions.c_str()),
2851 const_cast <char *> (groupsNames.c_str()),
2855 if ( err != MED_VALID)
2856 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't create family |" << families[i]->getName()
2857 << "| with identifier |" << families[i]->getIdentifier() << "| groups names |"
2858 << groupsNames <<"| and attributes descriptions |" << attributesDescriptions << "|")) ;
2861 med_2_2::_MEDdatagroupFermer(_medIdt);
2872 // A FAIRE POUR LES NOEUDS ET LES ELEMENTS ret = MEDfamEcr(
2876 /*--------------------- RDWR PART -------------------------------*/
2878 MED_MESH_RDWR_DRIVER22::MED_MESH_RDWR_DRIVER22()
2882 MED_MESH_RDWR_DRIVER22::MED_MESH_RDWR_DRIVER22(const string & fileName,
2884 MED_MESH_DRIVER(fileName,ptrMesh,MED_RDWR),
2885 IMED_MESH_RDONLY_DRIVER(fileName,ptrMesh),
2886 IMED_MESH_WRONLY_DRIVER(fileName,ptrMesh),
2887 IMED_MESH_RDWR_DRIVER(fileName,ptrMesh),
2888 MED_MESH_DRIVER22(fileName,ptrMesh,MED_RDWR),
2889 MED_MESH_RDONLY_DRIVER22(fileName,ptrMesh),
2890 MED_MESH_WRONLY_DRIVER22(fileName,ptrMesh)
2892 MESSAGE("MED_MESH_RDWR_DRIVER22::MED_MESH_RDWR_DRIVER22(const string & fileName, MESH * ptrMesh) has been created");
2895 MED_MESH_RDWR_DRIVER22::MED_MESH_RDWR_DRIVER22(const MED_MESH_RDWR_DRIVER22 & driver):
2896 MED_MESH_DRIVER(driver),
2897 IMED_MESH_RDONLY_DRIVER(driver),
2898 IMED_MESH_WRONLY_DRIVER(driver),
2899 IMED_MESH_RDWR_DRIVER(driver),
2900 MED_MESH_DRIVER22(driver),
2901 MED_MESH_RDONLY_DRIVER22(driver),
2902 MED_MESH_WRONLY_DRIVER22(driver)
2906 MED_MESH_RDWR_DRIVER22::~MED_MESH_RDWR_DRIVER22() {
2907 //MESSAGE("MED_MESH_RDWR_DRIVER22::MED_MESH_RDWR_DRIVER22(const string & fileName, MESH * ptrMesh) has been destroyed");
2910 GENDRIVER * MED_MESH_RDWR_DRIVER22::copy(void) const
2912 return new MED_MESH_RDWR_DRIVER22(*this);
2915 void MED_MESH_RDWR_DRIVER22::write(void) const
2917 MED_MESH_WRONLY_DRIVER22::write();
2919 void MED_MESH_RDWR_DRIVER22::read (void)
2921 MED_MESH_RDONLY_DRIVER22::read();