Back to index

salome-med  6.5.0
MEDMEM_MedMeshDriver.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "MEDMEM_MedMeshDriver.hxx"
00024 #include "MEDMEM_GenDriver.hxx"
00025 #include "MEDMEM_DriversDef.hxx"
00026 
00027 #include "MEDMEM_Family.hxx"
00028 #include "MEDMEM_Group.hxx"
00029 #include "MEDMEM_Coordinate.hxx"
00030 #include "MEDMEM_Connectivity.hxx"
00031 #include "MEDMEM_Mesh.hxx"
00032 #include "MEDMEM_CellModel.hxx"
00033 #include "MEDMEM_Grid.hxx"
00034 #include "MEDMEM_MedVersion.hxx"
00035 
00036 using namespace std;
00037 using namespace MED_EN;
00038 using namespace MEDMEM;
00039 
00040 namespace med_2_3 {
00041   extern "C" {
00042     extern med_idt _MEDdatagroupOuvrir(med_idt pid, char *nom);
00043     extern med_err _MEDdatagroupFermer(med_idt id);
00044   }
00045 }
00046 
00047 // Every memory allocation made in the MedDriver members function are desallocated in the Mesh destructor
00048 
00049 MED_MESH_DRIVER::MED_MESH_DRIVER():
00050   GENDRIVER(MED_DRIVER),
00051   _ptrMesh(( GMESH *)MED_NULL),
00052   _meshName(""),
00053   _medIdt(MED_INVALID)
00054 {
00055 }
00056 
00057 MED_MESH_DRIVER::MED_MESH_DRIVER(const std::string &    fileName,
00058                                  GMESH *                ptrMesh,
00059                                  MED_EN::med_mode_acces accessMode): 
00060   GENDRIVER(fileName, accessMode, MED_DRIVER),
00061   _ptrMesh(ptrMesh), 
00062   _meshName(""),
00063   _medIdt(MED_INVALID)
00064 {
00065 }
00066 
00067 MED_MESH_DRIVER::MED_MESH_DRIVER(const MED_MESH_DRIVER & driver): 
00068   GENDRIVER(driver),
00069   _ptrMesh(driver._ptrMesh),
00070   _meshName(driver._meshName),
00071   _medIdt(driver._medIdt)
00072 {
00073 
00074 }
00075 
00076 MED_MESH_DRIVER::~MED_MESH_DRIVER()
00077 {
00078   MESSAGE_MED("MED_MESH_DRIVER::~MED_MESH_DRIVER()has been destroyed");
00079 }
00080 
00081 void MED_MESH_DRIVER::setMeshName(const string & meshName) 
00082 { 
00083   _meshName = meshName; 
00084 }
00085 
00086 string  MED_MESH_DRIVER::getMeshName() const 
00087 { 
00088   return _meshName; 
00089 }
00090 
00091 void MED_MESH_DRIVER::open()
00092 {
00093 const char * LOC = "MED_MESH_DRIVER::open()";
00094   BEGIN_OF_MED(LOC);
00095 
00096   int accessMode = getMedAccessMode( _accessMode );
00097   MESSAGE_MED(LOC<<" : _fileName.c_str : "<< _fileName.c_str()<<",mode : "<< accessMode);
00098   _medIdt = med_2_3::MEDfileOpen(_fileName.c_str(),(med_2_3::med_access_mode) accessMode);
00099   MESSAGE_MED(LOC<<" _medIdt : "<< _medIdt );
00100   if (_medIdt > 0)
00101     _status = MED_OPENED;
00102   else {
00103     _medIdt = MED_INVALID;
00104     _status = MED_CLOSED;
00105     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Could not open file "<<_fileName<<" in mode "<<_accessMode));
00106   }
00107 
00108   END_OF_MED(LOC);
00109 }
00110 
00111 void MED_MESH_DRIVER::close()
00112 {
00113   const char * LOC = "MED_MESH_DRIVER::close() ";
00114   BEGIN_OF_MED(LOC);
00115   int err = 0;
00116   if ( _status == MED_OPENED) {
00117 
00118     err = med_2_3::MEDfileClose(_medIdt);
00119     // san -- MED5873 : Calling H5close() here leads to failure of SALOMEDS::StudyManager_i::_SaveAs()
00120     // method during study saving process. MEDfermer() seems sufficient for closing a file.
00121     //H5close(); // If we call H5close() all the files are closed.
00122     if (err)
00123       throw MEDEXCEPTION( LOCALIZED(STRING(LOC)<<" Error when closing file ! " << err));
00124 
00125     MESSAGE_MED(LOC <<": _medIdt= " << _medIdt );
00126     MESSAGE_MED(LOC<<": MEDfermer : err    = " << err );
00127     _status = MED_CLOSED;
00128     _medIdt = MED_INVALID;
00129   }
00130   END_OF_MED(LOC);
00131 }
00132 
00133 //A FAIRE UTILISER LES MAPS...
00134 const med_2_3::med_geometry_type  MED_MESH_DRIVER::all_cell_type[MED_N_CELL_GEO_FIXED_CON]=
00135   { MED_POINT1,MED_SEG2,MED_SEG3,MED_SEG4,MED_TRIA3,MED_QUAD4,MED_TRIA6,MED_TRIA7,MED_QUAD8,MED_QUAD9,
00136     MED_TETRA4,MED_PYRA5,MED_PENTA6,MED_HEXA8,MED_TETRA10,MED_OCTA12,MED_PYRA13,
00137     MED_PENTA15, MED_HEXA20,MED_HEXA27};
00138 
00139 const char * const MED_MESH_DRIVER::all_cell_type_tab [MED_N_CELL_GEO_FIXED_CON]=
00140   { "MED_POINT1","MED_SEG2","MED_SEG3","MEDMEM_SEG4","MED_TRIA3","MED_QUAD4","MED_TRIA6","MEDMEM_TRIA7","MED_QUAD8","MEDMEM_QUAD9",
00141     "MED_TETRA4","MED_PYRA5","MED_PENTA6","MED_HEXA8","MED_TETRA10","MEDMEM_OCTA12","MED_PYRA13",
00142     "MED_PENTA15","MED_HEXA20","MEDMEM_HEXA27"};
00143 
00144 
00145 //---------------------------------- RDONLY PART -------------------------------------------------------------
00146 
00147 MED_MESH_RDONLY_DRIVER::MED_MESH_RDONLY_DRIVER():MED_MESH_DRIVER(),_computeFaces(true)
00148 {
00149   this->GENDRIVER::_accessMode = MED_EN::RDONLY;
00150 }
00151 
00152 MED_MESH_RDONLY_DRIVER::MED_MESH_RDONLY_DRIVER(const string & fileName,
00153                                                GMESH *        ptrMesh):
00154   MED_MESH_DRIVER(fileName,ptrMesh,RDONLY),
00155   _computeFaces(true)
00156 {
00157   MESSAGE_MED("MED_MESH_RDONLY_DRIVER::MED_MESH_RDONLY_DRIVER(const string & fileName, MESH * ptrMesh) has been created");
00158 }
00159 
00160 MED_MESH_RDONLY_DRIVER::MED_MESH_RDONLY_DRIVER(const MED_MESH_RDONLY_DRIVER & driver):
00161   MED_MESH_DRIVER(driver),
00162   _computeFaces(driver._computeFaces)
00163 {
00164 }
00165 
00166 MED_MESH_RDONLY_DRIVER::~MED_MESH_RDONLY_DRIVER()
00167 {
00168   //MESSAGE_MED("MED_MESH_RDONLY_DRIVER::~MED_MESH_RDONLY_DRIVER() has been destroyed");
00169 }
00170 
00171 GENDRIVER * MED_MESH_RDONLY_DRIVER::copy(void) const
00172 {
00173   return new MED_MESH_RDONLY_DRIVER(*this);
00174 }
00175 
00176 void MED_MESH_RDONLY_DRIVER::merge ( const GENDRIVER& driver )
00177 {
00178   MED_MESH_DRIVER::merge( driver );
00179 
00180   const MED_MESH_RDONLY_DRIVER* other =
00181     dynamic_cast< const MED_MESH_RDONLY_DRIVER* >( &driver );
00182   if ( other ) {
00183     _computeFaces = other->_computeFaces;
00184   }
00185 }
00186 
00187 void MED_MESH_RDONLY_DRIVER::write( void ) const
00188 {
00189   throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER::write : Can't write with a RDONLY driver !");
00190 }
00191 
00192 void MED_MESH_RDONLY_DRIVER::read(void)
00193 {
00194   const char * LOC = "MED_MESH_RDONLY_DRIVER::read() : ";
00195   BEGIN_OF_MED(LOC);
00196   if (_status != MED_OPENED)
00197     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "The _idt of file " << _fileName
00198                                  << " is : " << _medIdt << " (the file is not opened)."));
00199 
00200   if ( ( _meshName.empty() ) && ( _ptrMesh->_name.empty() ) )
00201     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)
00202                                  <<" neither <meshName> is set in driver nor in object MESH."));
00203 
00204   // If _meshName is not set in driver, try to use _ptrMesh->_name
00205   if ( ( _meshName.empty() ) && ( !_ptrMesh->_name.empty() ) )
00206     _meshName = _ptrMesh->_name;
00207 
00208   if ( _meshName.size() > MED_NAME_SIZE )
00209     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)
00210                                  <<" <meshName> size in object driver MESH is > MED_TAILLE_NOM ."));
00211 
00212   _ptrMesh->_name = _meshName;
00213 
00214   // 0020058: Check version of med, which was used to save the file.
00215   // 0020058: An assertion happens in MEDcoordLire(), if this version
00216   // 0020058: is higher than the currently used version of med product.
00217   med_2_3::med_int aMajor, aMinor, aRelease;
00218   med_2_3::med_int aMajorCurr=3, aMinorCurr=1, aReleaseCurr=0;
00219 
00220   med_err aRet = med_2_3::MEDfileNumVersionRd(_medIdt, &aMajor, &aMinor, &aRelease);
00221 
00222   int aVersionHex     = (aMajor << 16 | aMinor << 8 | aRelease);
00223   int aVersionHexCurr = (aMajorCurr << 16 | aMinorCurr << 8 | aReleaseCurr);
00224 
00225   if (aRet != 0 || aVersionHex > aVersionHexCurr) {
00226     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << " cannot read file " << _fileName
00227                                  << " of version (" << aMajor << "." << aMinor << "." << aRelease
00228                                  << ") higher than the currently used version of med ("
00229                                  << aMajorCurr << "." << aMinorCurr << "." << aReleaseCurr << ")."));
00230   }
00231   // 0020058: end of version check
00232 
00233   SCRUTE_MED(_ptrMesh->getIsAGrid());
00234 
00235   int numberOfMeshes = med_2_3::MEDnMesh(_medIdt);
00236   if ( numberOfMeshes < 1 )
00237     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << " no meshes at all in file " << _fileName));
00238 
00239   // check mesh nature, unstructured or not (PAL14113)
00240   // and set space dimension
00241   {
00242     int naxis=med_2_3::MEDmeshnAxisByName(_medIdt,_meshName.c_str());
00243     if ( naxis < 0 )
00244       throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << " no mesh |" << _meshName
00245                                    << "| in file " << _fileName));
00246     if ( naxis == 0 )
00247       throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Mesh |" << _meshName
00248                                    << "| has invalid space dimension 0."));
00249 
00250     med_2_3::med_int spaceDimension,meshDimension;
00251     med_2_3::med_mesh_type meshType;
00252     char commentp3[MED_COMMENT_SIZE+1];
00253     char dtunittp3[MED_LNAME_SIZE+1];
00254     med_2_3::med_sorting_type sttp3;
00255     int nstep;
00256     med_2_3::med_axis_type axtypp3;
00257     naxis = std::max(3, naxis); // safe enough?
00258     char *t1pp3=new char[naxis*MED_SNAME_SIZE+1];
00259     char *t2pp3=new char[naxis*MED_SNAME_SIZE+1];
00260     med_2_3::MEDmeshInfoByName(_medIdt,_meshName.c_str(),&spaceDimension,&meshDimension,&meshType,commentp3,dtunittp3,&sttp3,&nstep,&axtypp3,t1pp3,t2pp3);
00261     delete [] t1pp3;
00262     delete [] t2pp3;
00263 
00264     if ((meshType == med_2_3::MED_STRUCTURED_MESH ) != _ptrMesh->getIsAGrid())
00265       {
00266         if ( _ptrMesh->getIsAGrid() )
00267           throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Mesh type mismatch. "
00268                                        "Class MESH must be used for an unstructured mesh"));
00269         else
00270           throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Mesh type mismatch. "
00271                                        "Class GRID must be used for a structured mesh"));
00272       }
00273     if ( meshDimension > spaceDimension )
00274       spaceDimension = meshDimension;
00275 
00276     if ( spaceDimension < 1 )
00277       throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "The space dimension |" << spaceDimension
00278                                    << "| seems to be incorrect for the mesh : |" << _meshName << "|"));
00279     _ptrMesh->_spaceDimension = spaceDimension;
00280     
00281   }
00282 
00283   if (_ptrMesh->getIsAGrid())
00284   {
00285     getGRID();
00286     {
00287       if (getFAMILY() != MED_VALID)
00288         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getFAMILY when the mesh is a grid"));
00289       buildAllGroups(_ptrMesh->_groupNode, _ptrMesh->_familyNode);
00290     }
00291     END_OF_MED(LOC);
00292     return;
00293   }
00294 
00295   if (getCOORDINATE() != MED_VALID)
00296     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getCOORDINATE"  ));
00297 
00298   if (getCONNECTIVITY() != MED_VALID)
00299     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getCOONECTIVITY"));
00300 
00301   if (getFAMILY() != MED_VALID)
00302     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERREUR in getFAMILY"      ));
00303 
00304   if (_computeFaces)
00305     updateFamily();
00306 
00307   // we build all groups
00308   // on node
00309   buildAllGroups(_ptrMesh->_groupNode,_ptrMesh->_familyNode);
00310   // on cell
00311   buildAllGroups(_ptrMesh->_groupCell,_ptrMesh->_familyCell);
00312 
00313   if (_ptrMesh->getMeshDimension() == 3)
00314     // on face
00315     buildAllGroups(_ptrMesh->_groupFace,_ptrMesh->_familyFace);
00316 //   else if (_ptrMesh->getMeshDimension() == 2) -- PAL13414
00317   if (_ptrMesh->getMeshDimension() > 1)
00318     // on edge
00319     buildAllGroups(_ptrMesh->_groupEdge,_ptrMesh->_familyEdge);
00320 
00321   _ptrMesh->_name = healName( _ptrMesh->_name );
00322 
00323   END_OF_MED(LOC);
00324 }
00325 
00326 //=======================================================================
00327 //function : getGRID
00328 //purpose  :
00329 //=======================================================================
00330 
00331 void MED_MESH_RDONLY_DRIVER::getGRID()
00332 {
00333   const char * LOC = "MED_MESH_RDONLY_DRIVER::getGRID() : ";
00334   BEGIN_OF_MED(LOC);
00335 
00336   if (_status!=MED_OPENED)
00337     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "med file is not opened"));
00338 
00339   GRID * ptrGrid = (GRID *) _ptrMesh;
00340 
00341   SCRUTE_MED(ptrGrid);
00342 
00343   int err, i;
00344 
00345   int numberOfMeshesInFile = med_2_3::MEDnMesh(_medIdt);
00346 
00347   if (numberOfMeshesInFile == MED_INVALID)
00348     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Problem in File where the mesh " << _meshName << " is supposed to be stored"));
00349   int MeshDimension;
00350   int SpaceDimensionRead;
00351   string tmp_nom_coord (MED_SNAME_SIZE*(_ptrMesh->_spaceDimension)+1,' ');
00352   string tmp_unit_coord(MED_SNAME_SIZE*(_ptrMesh->_spaceDimension)+1,' ');
00353   char * tmp_nom = (const_cast <char *> ( tmp_nom_coord.c_str())  );
00354   char * tmp_unit= (const_cast <char *> ( tmp_unit_coord.c_str()) );
00355   med_2_3::med_axis_type rep;
00356   med_2_3::med_int dtp3,itp3;
00357   med_2_3::med_float ttpp3;
00358   for (int index = 0; index < numberOfMeshesInFile; index++)
00359     {
00360       char meshName[MED_NAME_SIZE+1]="";
00361       char meshDescription[MED_COMMENT_SIZE+1]="";
00362       med_2_3::med_int meshDim;
00363       med_2_3::med_mesh_type meshType;
00364       med_2_3::med_int spaceDimp3;
00365       char dtunittp3[MED_LNAME_SIZE+1];
00366       med_2_3::med_sorting_type stypp3;
00367       med_2_3::med_int nstepp3;
00368       int naxis=med_2_3::MEDmeshnAxis(_medIdt,(index+1));
00369       char *axisnamep3=new char[naxis*MED_SNAME_SIZE+1];
00370       char *axisunitp3=new char[naxis*MED_SNAME_SIZE+1];
00371       med_2_3::med_axis_type axtpp3;
00372       err = med_2_3::MEDmeshInfo(_medIdt,(index+1),meshName, &spaceDimp3, &meshDim,&meshType, meshDescription, dtunittp3,&stypp3,&nstepp3,&axtpp3,axisnamep3,axisunitp3);
00373       MESSAGE_MED(LOC<<": Mesh n°"<< (index+1) <<" nammed "<< meshName << " with the description " << meshDescription << " is structured");
00374       if (_meshName == string(meshName))
00375         {
00376           _ptrMesh->_description = meshDescription;
00377           _ptrMesh->_name = meshName;
00378           MeshDimension=meshDim;
00379           SpaceDimensionRead=spaceDimp3;
00380           rep=axtpp3;
00381           strncpy(tmp_nom,axisnamep3,naxis*_ptrMesh->_spaceDimension+1);
00382           strncpy(tmp_unit,axisunitp3,naxis*_ptrMesh->_spaceDimension+1);
00383           med_2_3::MEDmeshComputationStepInfo(_medIdt,meshName,1,&dtp3,&itp3,&ttpp3);
00384         }
00385       delete [] axisnamep3;
00386       delete [] axisunitp3;
00387     }
00388 
00389   MED_EN::med_grid_type gridType = ptrGrid->getGridType();
00390   if ( ptrGrid->_is_default_gridType )
00391   {
00392     med_2_3::med_grid_type type;
00393     MEDmeshGridTypeRd(_medIdt,_ptrMesh->_name.c_str(),&type);
00394     gridType = ptrGrid->_gridType = (MED_EN::med_grid_type) type;
00395     ptrGrid->_is_default_gridType = false;
00396   }
00397 
00398   MESSAGE_MED(LOC<<": Mesh processed is nammed "<< _ptrMesh->_name << " with the description " << _ptrMesh->_description << " is structured with the type " << gridType);
00399 
00400 
00401   if (MeshDimension == MED_INVALID)
00402     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "The mesh dimension |" <<
00403                                  MeshDimension << "| seems to be incorrect " <<
00404                                  "for the mesh : |" << _meshName << "|"));
00405 
00406   // Read or get the dimension of the space for the mesh <_meshName>
00407   int SpaceDimension = MeshDimension;
00408 
00409   if (SpaceDimensionRead != MED_INVALID) SpaceDimension = SpaceDimensionRead;
00410 
00411   _ptrMesh->_spaceDimension = SpaceDimension;
00412 
00413 
00414   // Read Array length
00415   int * ArrayLen[] = { & ptrGrid->_iArrayLength,
00416                        & ptrGrid->_jArrayLength,
00417                        & ptrGrid->_kArrayLength  };
00418 
00419   MESSAGE_MED(LOC << "The mesh is a " << _ptrMesh->getMeshDimension() << "D mesh on a " << _ptrMesh->_spaceDimension << "D space");
00420 
00421   int NumberOfNodes;
00422 
00423   //  if (gridType == MED_EN::MED_GRILLE_STANDARD)
00424   if (gridType == MED_EN::MED_BODY_FITTED)
00425     {
00426       med_2_3::med_int * structure = new med_2_3::med_int[MeshDimension];
00427 
00428       err = med_2_3::MEDmeshGridStructRd(_medIdt,_ptrMesh->_name.c_str(),dtp3,itp3,structure);
00429 
00430       if (err != MED_VALID)
00431         throw MEDEXCEPTION(STRING(LOC) <<"Error in reading the structure of grid : |" << _meshName << "|" );
00432 
00433       NumberOfNodes = 1;
00434 
00435       for (int idim = 0; idim < MeshDimension; idim++)
00436         {
00437           MESSAGE_MED(LOC<<"structure dim " << idim << " " << structure[idim]);
00438 
00439           ArrayLen [idim][0] = structure[idim];
00440           NumberOfNodes = NumberOfNodes*structure[idim];
00441         }
00442 
00443       delete [] structure;
00444 
00445       if ( NumberOfNodes == MED_INVALID )
00446         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"The number of nodes |" <<
00447                                      NumberOfNodes <<
00448                                      "| seems to be incorrect "
00449                                      << "for the mesh : |" <<
00450                                      _meshName << "|" ));
00451 
00452       // create coordinates and its structure
00453       ptrGrid->_coordinate = new COORDINATE(SpaceDimension,NumberOfNodes,
00454                                             MED_EN::MED_FULL_INTERLACE);
00455 
00456       err = med_2_3::MEDmeshNodeCoordinateRd(_medIdt,_ptrMesh->_name.c_str(),dtp3,itp3,med_2_3::MED_FULL_INTERLACE,const_cast<double *>(ptrGrid->_coordinate->_coordinate.get(MED_EN::MED_FULL_INTERLACE)));
00457 
00458       if (err != MED_VALID)
00459         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't read coordinates of the |" <<
00460                                      NumberOfNodes << "| nodes for the mesh : |" <<
00461                                      _meshName << "| of space dimension |" <<
00462                                      SpaceDimension << "| with units names |" <<
00463                                      tmp_nom << "| and units |" <<
00464                                      tmp_unit << " |"));
00465 
00466     }
00467   else if ((gridType == MED_EN::MED_CARTESIAN) ||
00468            (gridType == MED_EN::MED_POLAR))
00469     {
00470       NumberOfNodes = 1;
00471 
00472       double * Array[] = { (double*) 0, (double*) 0, (double*) 0 };
00473 
00474       for (int idim = 0; idim < _ptrMesh->getMeshDimension(); ++idim)
00475         {
00476           med_2_3::med_data_type table;
00477           if (idim == 0) table = med_2_3::MED_COORDINATE_AXIS1;
00478           else if (idim == 1) table = med_2_3::MED_COORDINATE_AXIS2;
00479           else if (idim == 2) table = med_2_3::MED_COORDINATE_AXIS3;
00480           
00481           med_2_3::med_bool chgtpp3,trsfpp3;
00482           int length = med_2_3::MEDmeshnEntity(_medIdt,_ptrMesh->_name.c_str(),dtp3,itp3,med_2_3::MED_NODE,MED_NONE,table,med_2_3::MED_NO_CMODE,&chgtpp3,&trsfpp3);
00483 
00484           if ( length <= MED_VALID )
00485             throw MEDEXCEPTION(STRING(LOC) <<"The number of nodes |" << length <<
00486                                "| seems to be incorrect "
00487                                << "for the mesh : |" << _meshName << "|" );
00488 
00489           ArrayLen [idim][0] = length;
00490           NumberOfNodes *= length;
00491 
00492           Array [idim] = new double [ length ];
00493 
00494           err = med_2_3::MEDmeshGridIndexCoordinateRd(_medIdt,_ptrMesh->_name.c_str(),dtp3,itp3,idim+1,Array [idim]);
00495 
00496           if (err != MED_VALID)
00497             throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Error in reading coordinates indices " <<
00498                                          idim << "of the grid : |" <<
00499                                          _meshName << "|" ));
00500         }
00501 
00502       ptrGrid->_iArray = Array[0];
00503       ptrGrid->_jArray = Array[1];
00504       ptrGrid->_kArray = Array[2];
00505 
00506       // create coordinates
00507       ptrGrid->_coordinate = new COORDINATE(SpaceDimension,NumberOfNodes,
00508                                             MED_EN::MED_FULL_INTERLACE);
00509 
00510       if (gridType == MED_EN::MED_CARTESIAN)
00511         rep = med_2_3::MED_CARTESIAN;
00512       else if (gridType == MED_EN::MED_POLAR)
00513         {
00514           if (SpaceDimension == 2) rep = med_2_3::MED_CYLINDRICAL;
00515           else if (SpaceDimension == 3) rep = med_2_3::MED_SPHERICAL;
00516         }
00517     }
00518   else
00519     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<" bad grid type : " << gridType));
00520 
00521   // set coordinate names
00522 
00523   for (i=0; i<_ptrMesh->_spaceDimension; ++i )
00524   {
00525     string myStringName(tmp_nom_coord,i*MED_SNAME_SIZE,MED_SNAME_SIZE);
00526     string myStringUnit(tmp_unit_coord,i*MED_SNAME_SIZE,MED_SNAME_SIZE);
00527     // suppress space at the end
00528     int j;
00529     for(j=MED_SNAME_SIZE-1;j>=0;j--)
00530       if (myStringName[j] != ' ') break;
00531     ptrGrid->_coordinate->_coordinateName[i]=string(myStringName,0,j+1);
00532     for(j=MED_SNAME_SIZE-1;j>=0;j--)
00533       if (myStringUnit[j] != ' ') break;
00534     ptrGrid->_coordinate->_coordinateUnit[i]=string(myStringUnit,0,j+1);
00535   }
00536 
00537   string coordinateSystem = "UNDEFINED";
00538 
00539   if( rep == med_2_3::MED_CARTESIAN) coordinateSystem = "CARTESIAN";
00540   else if ( rep == med_2_3::MED_CYLINDRICAL) coordinateSystem = "CYLINDRICAL";
00541   else if ( rep == med_2_3::MED_SPHERICAL) coordinateSystem = "SPHERICAL";
00542 
00543   ptrGrid->_coordinate->setCoordinatesSystem(coordinateSystem);
00544 
00545   END_OF_MED(LOC);
00546 }
00547 
00548 //=======================================================================
00549 //function : getCOORDINATE
00550 // A FAIRE : RENVOYER DU VOID
00551 //=======================================================================
00552 int  MED_MESH_RDONLY_DRIVER::getCOORDINATE()
00553 {
00554   const char * LOC = "MED_MESH_RDONLY_DRIVER::getCOORDINATE() : ";
00555 
00556   BEGIN_OF_MED(LOC);
00557 
00558   if (_status==MED_OPENED)
00559   {
00560     int err;
00561     int MeshDimension;
00562     int SpaceDimensionRead;
00563     med_2_3::med_mesh_type meshTypepp3;
00564     char meshDescription[MED_COMMENT_SIZE+1]="";
00565     char dtunit[MED_LNAME_SIZE+1];
00566     med_2_3::med_sorting_type sortTypepp3;
00567     int nstepp3;
00568     med_2_3::med_axis_type axtypepp3;
00569     //
00570     string tmp_nom_coord (MED_SNAME_SIZE*_ptrMesh->_spaceDimension+1,'\0');
00571     string tmp_unit_coord(MED_SNAME_SIZE*_ptrMesh->_spaceDimension+1,'\0');
00572     char * tmp_nom = (const_cast <char *> ( tmp_nom_coord.c_str())  );
00573     char * tmp_unit= (const_cast <char *> ( tmp_unit_coord.c_str()) );
00574     //
00575     err=med_2_3::MEDmeshInfoByName(_medIdt,_meshName.c_str(),
00576                                    &SpaceDimensionRead,&MeshDimension,
00577                                    &meshTypepp3,meshDescription,
00578                                    dtunit,&sortTypepp3,&nstepp3,
00579                                    &axtypepp3,tmp_nom,tmp_unit);
00580     int dtp3,itp3;
00581     med_2_3::med_float ttpp3;
00582     med_2_3::MEDmeshComputationStepInfo(_medIdt,_meshName.c_str(),1,&dtp3,&itp3,&ttpp3);
00583 
00584     MESH* ptrMesh = dynamic_cast<MESH*>(_ptrMesh);
00585 
00586     // Read the number of nodes used in the mesh <_meshName>
00587     // to be able to create a COORDINATE object
00588     med_2_3::med_bool chgtpp3,trsfpp3;
00589     int NumberOfNodes = med_2_3::MEDmeshnEntity(_medIdt,_meshName.c_str(),
00590                                                 dtp3,itp3,med_2_3::MED_NODE,MED_NONE,
00591                                                 med_2_3::MED_COORDINATE,
00592                                                 med_2_3::MED_NO_CMODE,
00593                                                 &chgtpp3,&trsfpp3);
00594     if ( NumberOfNodes <= MED_VALID )
00595       throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"The number of nodes |" << NumberOfNodes
00596                                    << "| seems to be incorrect for the mesh : |" << _meshName << "|" ));
00597     ptrMesh->_numberOfNodes = NumberOfNodes;
00598 
00599     // create a COORDINATE object
00600     if (ptrMesh->_coordinate)
00601       delete ptrMesh->_coordinate;
00602     ptrMesh->_coordinate = new COORDINATE(ptrMesh->_spaceDimension, NumberOfNodes, MED_EN::MED_FULL_INTERLACE);
00603 
00604     med_2_3::med_axis_type rep=axtypepp3; // ATTENTION ---> DOIT ETRE INTEGRE DS MESH EF: FAIT NON?
00605 
00606     err=MEDmeshNodeCoordinateRd(_medIdt,_ptrMesh->_name.c_str(),dtp3,itp3,med_2_3::MED_FULL_INTERLACE,const_cast<double *>(ptrMesh->_coordinate->_coordinate.get(MED_EN::MED_FULL_INTERLACE)));
00607 
00608     if (err != MED_VALID)
00609       throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't read coordinates of the |" << NumberOfNodes
00610                                    << "| nodes for the mesh : |" << _meshName
00611                                    << "| of space dimension |" << ptrMesh->_spaceDimension
00612                                    << "| with units names |"   << tmp_nom
00613                                    << "| and units |"          << tmp_unit
00614                                    << " |"));
00615 
00616     for (int i=0;i<_ptrMesh->_spaceDimension;i++) {
00617       string myStringName(tmp_nom_coord,i*MED_SNAME_SIZE,MED_SNAME_SIZE);
00618       string myStringUnit(tmp_unit_coord,i*MED_SNAME_SIZE,MED_SNAME_SIZE);
00619       // suppress space at the end
00620       int j;
00621       for(j=MED_SNAME_SIZE-1;j>=0;j--)
00622         if (myStringName[j] != ' ') break;
00623       ptrMesh->_coordinate->_coordinateName[i]=string(myStringName,0,j+1);
00624       for(j=MED_SNAME_SIZE-1;j>=0;j--)
00625         if (myStringUnit[j] != ' ') break;
00626       ptrMesh->_coordinate->_coordinateUnit[i]=string(myStringUnit,0,j+1);
00627     }
00628 
00629     // Pourquoi le stocker sous forme de chaîne ?
00630     switch (rep)
00631     {
00632     case med_2_3::MED_CARTESIAN :
00633       {
00634         ptrMesh->_coordinate->_coordinateSystem = "CARTESIAN";
00635         break;
00636       }
00637     case med_2_3::MED_CYLINDRICAL :
00638       {
00639         ptrMesh->_coordinate->_coordinateSystem = "CYLINDRICAL";
00640         break;
00641       }
00642     case med_2_3::MED_SPHERICAL  :
00643       {
00644         ptrMesh->_coordinate->_coordinateSystem = "SPHERICAL";
00645         break;
00646       }
00647     default :
00648       {
00649         ptrMesh->_coordinate->_coordinateSystem = "UNDEFINED"; // ?Erreur ?
00650         break;
00651       }
00652     }
00653 
00654     // Read the unused optional node Names
00655     if(MEDmeshnEntity(_medIdt,_ptrMesh->_name.c_str(),dtp3,itp3,med_2_3::MED_NODE,MED_NONE,med_2_3::MED_NAME,med_2_3::MED_NO_CMODE,&chgtpp3,&trsfpp3)>0)
00656       MESSAGE_MED(LOC<<"MED_MESH_RDONLY_DRIVER::getNoeuds() : WARNING : Nodes have names but we do not read them !");
00657 
00658     // ??? Read the unused optional node Numbers ???
00659     med_2_3::med_int * tmp_node_number = new med_2_3::med_int[NumberOfNodes];
00660     if(MEDmeshnEntity(_medIdt,_ptrMesh->_name.c_str(),dtp3,itp3,med_2_3::MED_NODE,MED_NONE,med_2_3::MED_NUMBER,med_2_3::MED_NO_CMODE,&chgtpp3,&trsfpp3)>0)
00661       {
00662         err=MEDmeshEntityNumberRd(_medIdt,_ptrMesh->_name.c_str(),dtp3,itp3,med_2_3::MED_NODE,MED_NONE,tmp_node_number);
00663 
00664         MESSAGE_MED(LOC<<"MED_MESH_RDONLY_DRIVER::getNoeuds() : Nodes have numbers, we DO TAKE care of them !");
00665         ptrMesh->_coordinate->_nodeNumber.set(NumberOfNodes);
00666 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
00667         for(med_2_3::med_int i2=0;i2<NumberOfNodes;i2++)
00668           ptrMesh->_coordinate->_nodeNumber[i2]=(int)(tmp_node_number[i2]);
00669 #else
00670         memcpy((int*)ptrMesh->_coordinate->_nodeNumber,tmp_node_number,sizeof(int)*NumberOfNodes);
00671 #endif
00672 
00678 
00679       //        ptrMesh->_arePresentOptionnalNodesNumbers=1;
00680       //        for (int canonicNumber=1;canonicNumber<=NumberOfNodes;canonicNumber++) ptrMesh->_optionnalToCanonicNodesNumbers[tmp_node_number[canonicNumber-1]]=canonicNumber;
00681       // ICI RETOUR A LA NORMALE::: AUCUNE PRISE EN COMPTE D'UN NUMEROTATION OPTIONNEL
00682       ptrMesh->_arePresentOptionnalNodesNumbers=0;
00683     }
00684     else ptrMesh->_arePresentOptionnalNodesNumbers=0;
00685 
00687 
00688     delete[] tmp_node_number;
00689 
00690     END_OF_MED(LOC);
00691     return MED_VALID;
00692   }
00693   return MED_ERROR;
00694 }
00695 
00696 
00697 int MED_MESH_RDONLY_DRIVER::getCONNECTIVITY()
00698 {
00699   const char * LOC = "MED_MESH_RDONLY_DRIVER::getCONNECTIVITY : ";
00700   BEGIN_OF_MED(LOC);
00701 
00702   if (_status==MED_OPENED)
00703     {
00704 
00705       int err = 0;
00706       // read MED_CELL connectivity
00707       CONNECTIVITY * Connectivity     = new CONNECTIVITY(MED_CELL);
00708       Connectivity->_numberOfNodes    = _ptrMesh->getNumberOfNodes();   // EF : Pourquoi cet attribut est-il dans MESH et non dans COORDINATE ?
00709 
00710       // Try to read nodal connectivity of the cells <Connectivity->_nodal>
00711       // then try to read descending connectivity    <Connectivity->_descending>
00712       // if neither nodal nor descending connectivity exists
00713       // throw an exception.
00714       err = getNodalConnectivity(Connectivity);
00715       if (err!=MED_VALID)
00716         {
00717           Connectivity->_typeConnectivity = MED_DESCENDING;
00718           err = getDescendingConnectivity(Connectivity);
00719         }
00720       else
00721         getDescendingConnectivity(Connectivity); // we read it if there is one
00722 
00723       if (err!=MED_VALID)
00724         {
00725           delete Connectivity;
00726           throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "We could not read " <<
00727                                        "any Connectivity"));
00728         }
00729 
00730       // commented since _ptrMesh->getMeshDimension() is based on connectivity
00731       // which is not yet set
00732 //       if (Connectivity->_entityDimension != _ptrMesh->getMeshDimension())
00733 //         MESSAGE_MED(LOC << "Small mesh dimension problem on the med file mounted in memory : diim stored " << _ptrMesh->getMeshDimension() << " dim computed using the connectivity " << Connectivity->_entityDimension);
00734 
00735       // At this point Connectivity->_typeConnectivity is either NODAL or DESCENDING
00736       // If both connectivities are found Connectivity->_typeConnectivity is NODAL
00737       // If space dimension is 3
00738       // try to read the nodal connectivity of the faces <ConnectivityFace->_nodal> then
00739       // try to read the descending connectivity <ConnectivityFace->_descending>
00740       // if there is no descending connectivity and the CELLS are
00741       // defined in descending mode then throw an exception
00742 
00743       // PROVISOIRE : if we have some face or edge in MED_MAILLE, we don't read more. There could not be have face or edge !!!!
00744 
00745       if(Connectivity->_constituent==NULL) {
00746 
00747       if (Connectivity->_entityDimension == 3) {
00748         MESSAGE_MED(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE DES FACES..." );
00749         CONNECTIVITY * ConnectivityFace = new CONNECTIVITY(MED_EN::MED_FACE);
00750         ConnectivityFace->_numberOfNodes    = _ptrMesh->getNumberOfNodes();
00751         ConnectivityFace->_typeConnectivity = Connectivity->_typeConnectivity; // NODAL or DESCENDING
00752         SCRUTE_MED(ConnectivityFace->_typeConnectivity);
00753         if (Connectivity->_typeConnectivity == MED_DESCENDING) {
00754           MESSAGE_MED(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE DESCENDANTE DES FACES" );
00755           err = getDescendingConnectivity(ConnectivityFace);
00756           if (err!=MED_VALID)
00757             throw MEDEXCEPTION ( LOCALIZED(STRING(LOC) << "No FACE in descending connectivity"));
00758           getNodalConnectivity(ConnectivityFace); // if any !
00759         } else {
00760           MESSAGE_MED(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE NODALE DES FACES" );
00761           err = getNodalConnectivity(ConnectivityFace);
00762           if (err!=MED_VALID) { // or error ????? we are in NODAL mode.
00763             err = getDescendingConnectivity(ConnectivityFace);
00764           } else
00765             getDescendingConnectivity(ConnectivityFace); // if any !
00766         }
00767         if (err!=MED_VALID) {
00768           delete ConnectivityFace;
00769           MESSAGE_MED(LOC<<"No FACE defined.");
00770         } else {
00771           MESSAGE_MED(LOC<<" SAUVEGARDE DE LA CONNECTIVITE DES FACES DANS L'OBJET CONNECTIVITY" );
00772           delete Connectivity->_constituent;
00773           Connectivity->_constituent=ConnectivityFace;
00774         }
00775       }
00776 
00777       // read MED_EDGE connectivity
00778       if (Connectivity->_entityDimension > 1) { // we are in 3 or 2D
00779         MESSAGE_MED(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE DES ARRETES...." );
00780         CONNECTIVITY * ConnectivityEdge = new CONNECTIVITY(MED_EDGE);
00781         ConnectivityEdge->_numberOfNodes    = _ptrMesh->getNumberOfNodes();
00782         ConnectivityEdge->_typeConnectivity = Connectivity->_typeConnectivity;
00783         if (Connectivity->_typeConnectivity == MED_DESCENDING) {
00784           MESSAGE_MED(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE DESCENDANTE DES ARRETES" );
00785           err = getDescendingConnectivity(ConnectivityEdge);
00786           if (err!=MED_VALID)
00787             throw MEDEXCEPTION ( LOCALIZED(STRING(LOC) << "No EDGE in descending connectivity"));
00788           getNodalConnectivity(ConnectivityEdge); // if any !
00789         } else {
00790           MESSAGE_MED(LOC<<" ESSAI DE LECTURE DE LA CONNECTIVITE NODALE DES ARRETES" );
00791           err = getNodalConnectivity(ConnectivityEdge);
00792           if (err!=MED_VALID) { // or error ????? we are in NODAL mode.
00793             err = getDescendingConnectivity(ConnectivityEdge);
00794           } else
00795             getDescendingConnectivity(ConnectivityEdge); // if any !
00796         }
00797         if (err!=MED_VALID) {
00798           delete ConnectivityEdge;
00799           MESSAGE_MED(LOC<<"No EDGE defined.");
00800         } else {
00801           if (Connectivity->_entityDimension == 3)
00802             if (Connectivity->_constituent != NULL)
00803               Connectivity->_constituent->_constituent=ConnectivityEdge;
00804             else
00805               throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<< "EDGE defined but there are no FACE !"));
00806           else { // IN 2D
00807             MESSAGE_MED(LOC<<" SAUVEGARDE DE LA CONNECTIVITE DES ARETES DANS L'OBJET CONNECTIVITY" );
00808             Connectivity->_constituent=ConnectivityEdge;
00809           }
00810         }
00811       }
00812       }
00813       MESH* ptrMesh = dynamic_cast<MESH*>(_ptrMesh);
00814       if (ptrMesh->_connectivity)
00815         delete ptrMesh->_connectivity;
00816       ptrMesh->_connectivity  = Connectivity;
00817 
00818 
00819       END_OF_MED(LOC);
00820       return MED_VALID;
00821     }
00822   return MED_ERROR;
00823 }
00824 
00825 int MED_MESH_RDONLY_DRIVER::getNodalConnectivity(CONNECTIVITY * Connectivity)
00826 {
00827   const char * LOC = "MED_MESH_RDONLY_DRIVER::getNodalConnectivity : ";
00828   BEGIN_OF_MED(LOC);
00829   med_2_3::med_bool chgtp3,trfp3;
00830   if (_status==MED_OPENED)
00831     {
00832       int dtp3,itp3;
00833       med_2_3::med_float ttpp3;
00834       med_2_3::MEDmeshComputationStepInfo(_medIdt,_meshName.c_str(),1,&dtp3,&itp3,&ttpp3);
00835       // Get the type of entity to work on (previously set in the Connectivity Object)
00836       med_2_3::med_entity_type Entity = (med_2_3::med_entity_type) Connectivity->getEntity();
00837 
00838       // Get the number of cells of each type & store it in <tmp_cells_count>.
00839       vector<int> tmp_cells_count;
00840       vector<CELLMODEL> tmp_cell_models; // models of present types
00841       int i;
00842       const list<MED_EN::medGeometryElement>& all_cell_type = meshEntities[ Connectivity->getEntity() ];
00843       list<MED_EN::medGeometryElement>::const_iterator type_iter;
00844       for ( type_iter = all_cell_type.begin(); type_iter != all_cell_type.end(); ++type_iter )
00845         {
00846           int nb_cells;
00847           if ( med_2_3::med_geometry_type(*type_iter) != MED_POLYGON &&
00848                med_2_3::med_geometry_type(*type_iter) != MED_POLYHEDRON )
00849             nb_cells=med_2_3::MEDmeshnEntity(_medIdt,_ptrMesh->_name.c_str(),
00850                                              dtp3,itp3,
00851                                              med_2_3::MED_CELL,
00852                                              med_2_3::med_geometry_type(*type_iter),
00853                                              med_2_3::MED_CONNECTIVITY,med_2_3::MED_NODAL,
00854                                              &chgtp3,&trfp3);
00855           else if ( med_2_3::med_geometry_type(*type_iter) == MED_POLYGON )
00856             nb_cells=med_2_3::MEDmeshnEntity(_medIdt,_ptrMesh->_name.c_str(),
00857                                              dtp3,itp3,
00858                                              med_2_3::MED_CELL,
00859                                              MED_POLYGON,
00860                                              med_2_3::MED_INDEX_NODE,
00861                                              med_2_3::MED_NODAL,
00862                                              &chgtp3,&trfp3) - 1;
00863           else
00864             nb_cells=med_2_3::MEDmeshnEntity(_medIdt,_ptrMesh->_name.c_str(),
00865                                              dtp3,itp3,
00866                                              med_2_3::MED_CELL,
00867                                              MED_POLYHEDRON,
00868                                              med_2_3::MED_INDEX_FACE,
00869                                              med_2_3::MED_NODAL,
00870                                              &chgtp3,&trfp3)-1;
00871           /*med_2_3::MED_CONN,Entity,
00872             med_2_3::med_geometry_type(*type_iter),med_2_3::MED_NOD);*/
00873 
00874           // Get the greatest dimension of the cells : Connectivity->_entityDimension
00875           // We suppose there is no cells used as faces in MED 2.2.x , this is forbidden !!!
00876           // In version prior to 2.2.x, it is possible
00877           if (nb_cells>0)
00878             {
00879               tmp_cells_count.push_back(nb_cells);
00880               tmp_cell_models.push_back( CELLMODEL_Map::retrieveCellModel( *type_iter ));
00881               Connectivity->_entityDimension=tmp_cell_models.back().getDimension();
00882               Connectivity->_numberOfTypes++;
00883             }
00884         }
00885 
00886       if (Connectivity->_numberOfTypes > 0)
00887         {
00888           // if MED version < 2.2.x, we read only entity with
00889         // dimention = Connectivity->_entityDimension. Lesser dimension are face or edge !
00890 
00891         med_2_3::med_int major, minor, release;
00892 
00893         if ( med_2_3::MEDfileNumVersionRd(_medIdt, &major, &minor, &release) != 0 )
00894           // error : we suppose we have not a good med file !
00895           return MED_ERROR;
00896 
00897         // we get MED version number
00898         // If MED version is < 2.2 then the cells which dimension
00899         // is lesser than the main dimension ( Connectivity->_entityDimension )
00900         // are either faces or edges
00901 
00902         vector<int> tmpEdgeCount, tmpFaceCount;
00903         vector<MED_EN::medGeometryElement> edgeTypes, faceTypes;
00904         if (Entity==med_2_3::MED_CELL)
00905         {
00906           Connectivity->_numberOfTypes=0;
00907 
00908           for ( i=0;i<int(tmp_cell_models.size());i++)
00909           {
00910             int dimension = tmp_cell_models[i].getDimension();
00911             if (Connectivity->_entityDimension == dimension)
00912               Connectivity->_numberOfTypes++;
00913             if (Connectivity->_entityDimension > dimension)
00914             {
00915               if (dimension == 2 )
00916               {
00917                 faceTypes.push_back( tmp_cell_models[i].getType() );
00918                 tmpFaceCount.push_back( tmp_cells_count[i] );
00919                 tmp_cells_count[i] = 0;
00920               }
00921               else if (dimension == 1 )
00922                 {
00923                   edgeTypes.push_back( tmp_cell_models[i].getType() );
00924                   tmpEdgeCount.push_back( tmp_cells_count[i] );
00925                   tmp_cells_count[i] = 0;
00926                 }
00927               else if (dimension == 0 )
00928                 {
00929                   tmp_cells_count[i] = 0;
00930                 }
00931             }
00932           }
00933         }
00934 
00935         // Retrieve connectivity size of poly elements
00936         med_2_3::med_int polygonConnSize, polyhedraFacesIndexSize, polyhedraConnSize;
00937         int polyhedraConnSizeWithFaceSeparators;
00938         if ( tmp_cell_models.back().getType() == MED_EN::MED_POLYGON ||
00939              (!faceTypes.empty() && faceTypes.back() == MED_EN::MED_POLYGON ))
00940           {
00941             polygonConnSize = med_2_3::MEDmeshnEntity(_medIdt,_ptrMesh->_name.c_str(),
00942                                                       dtp3,itp3,
00943                                                       med_2_3::MED_CELL,
00944                                                       MED_POLYGON,
00945                                                       med_2_3::MED_CONNECTIVITY,
00946                                                       med_2_3::MED_NODAL,
00947                                                       &chgtp3,&trfp3);
00948           }
00949         if ( tmp_cell_models.back().getType() == MED_EN::MED_POLYHEDRA )
00950           {
00951             polyhedraFacesIndexSize=MEDmeshnEntity(_medIdt,_ptrMesh->_name.c_str(),
00952                                                    dtp3,itp3,
00953                                                    med_2_3::MED_CELL,
00954                                                    MED_POLYHEDRON,
00955                                                    med_2_3::MED_INDEX_NODE,
00956                                                    med_2_3::MED_NODAL,
00957                                                    &chgtp3,&trfp3);
00958             polyhedraConnSize=MEDmeshnEntity(_medIdt,_ptrMesh->_name.c_str(),
00959                                              dtp3,itp3,
00960                                              med_2_3::MED_CELL,
00961                                              MED_POLYHEDRON,
00962                                              med_2_3::MED_CONNECTIVITY,
00963                                              med_2_3::MED_NODAL,
00964                                              &chgtp3,&trfp3);
00965 
00966             int nbPolyherda = tmp_cells_count.back();
00967             int nbFaces     = polyhedraFacesIndexSize - 1;
00968             // connectivity of each but last face of each polyhedron ends with -1
00969             polyhedraConnSizeWithFaceSeparators = polyhedraConnSize + nbFaces - nbPolyherda;
00970           }
00971 
00972         // bloc to read CELL :
00973         {
00974           // Prepare an array of indexes on the different cell types to create a MEDSKYLINEARRAY
00975           // We use <tmp_cells_count> to calculate <Connectivity->_count> then we release it
00976           Connectivity->_geometricTypes = new MED_EN::medGeometryElement [Connectivity->_numberOfTypes]; // Double emploi pour des raisons pratiques
00977           Connectivity->_type           = new CELLMODEL                  [Connectivity->_numberOfTypes]; //
00978           if(Connectivity->_count) delete [] Connectivity->_count;
00979           Connectivity->_count          = new int                        [Connectivity->_numberOfTypes+1];
00980           Connectivity->_count[0]       = 1;
00981 
00982           int size = 0;
00983           int typeNumber=1;
00984           vector<int> connSizeByType;
00985           for ( i=0; i < (int)tmp_cells_count.size(); i++)
00986           { // no point1 cell type (?)
00987             if ( !tmp_cells_count[i] ) continue; // faces or edges
00988 
00989             Connectivity->_count[typeNumber]=Connectivity->_count[typeNumber-1]+tmp_cells_count[i];
00990 
00991             Connectivity->_type[typeNumber-1] = tmp_cell_models[i];
00992 
00993             Connectivity->_geometricTypes[typeNumber-1] = tmp_cell_models[i].getType();
00994 
00995             // probleme avec les mailles de dimension < a dimension du maillage :
00996             // Il faut oter le zero a la lecture est le remettre a l'ecriture : ce n'est pas fait !!!!!
00997             // On interdit ce cas pour l'instant !!!
00998 
00999             switch (tmp_cell_models[i].getType() )
01000             {
01001             case MED_EN::MED_POLYGON:
01002               connSizeByType.push_back( polygonConnSize ); break;
01003             case MED_EN::MED_POLYHEDRA:
01004               connSizeByType.push_back( polyhedraConnSizeWithFaceSeparators ); break;
01005             default:
01006               connSizeByType.push_back
01007                 (tmp_cells_count[i] * tmp_cell_models[i].getNumberOfNodes() );
01008             }
01009             size += connSizeByType.back();
01010             typeNumber++;
01011             MESSAGE_MED(LOC << Connectivity->_count[typeNumber-1]-1 << " cells of type "
01012                         << tmp_cell_models[i].getName() );
01013           }
01014 
01015           // Creation of the MEDSKYLINEARRAY
01016           PointerOf <int> NodalValue(size);
01017           PointerOf <int> NodalIndex(Connectivity->_count[Connectivity->_numberOfTypes]);
01018           NodalIndex[0]=1;
01019 
01020           // Fill the MEDSKYLINEARRAY by reading the MED file.
01021           int j=0;
01022           for ( i=0;i<Connectivity->_numberOfTypes;i++)
01023           {
01024             int tmp_numberOfCells = Connectivity->_count[i+1]-Connectivity->_count[i];
01025             PointerOf< med_2_3::med_int > tmp_ConnectivityArray( connSizeByType[i] );
01026 
01027             med_2_3::med_err err2;
01028             switch ( Connectivity->_geometricTypes[i] )
01029             {
01030             case MED_EN::MED_POLYGON:
01031               {
01032                 PointerOf <med_2_3::med_int> PolygonsConnIndex( tmp_numberOfCells+1 );
01033                 err2=med_2_3::MEDmeshPolygonRd(_medIdt,_ptrMesh->_name.c_str(),
01034                                                dtp3,itp3,
01035                                                med_2_3::MED_CELL,
01036                                                med_2_3::MED_NODAL,
01037                                                PolygonsConnIndex,
01038                                                tmp_ConnectivityArray);
01039                 if (err2 != MED_VALID)
01040                 {
01041                   MESSAGE_MED(LOC<<": MEDpolygoneConnLire returns "<<err2);
01042                   return MED_ERROR;
01043                 }
01044                 int* polyindex = (int*)NodalIndex + Connectivity->_count[i] - 1;
01045                 int delta = polyindex[0] - PolygonsConnIndex[0];
01046                 for ( j=0; j<=tmp_numberOfCells; j++)
01047                   polyindex[j]= delta + PolygonsConnIndex[ j ];
01048                 break;
01049               }
01050             case MED_EN::MED_POLYHEDRA:
01051               {
01052                 PointerOf< med_2_3::med_int> FacesIndex( polyhedraFacesIndexSize );
01053                 PointerOf< med_2_3::med_int> PolyhedronIndex( tmp_numberOfCells+1 );
01054                 err2=med_2_3::MEDmeshPolyhedronRd(_medIdt,_ptrMesh->_name.c_str(),
01055                                                   dtp3,itp3,
01056                                                   med_2_3::MED_CELL,
01057                                                   med_2_3::MED_NODAL,
01058                                                   PolyhedronIndex,
01059                                                   FacesIndex,
01060                                                   tmp_ConnectivityArray);
01061                 if (err2 != MED_VALID)
01062                 {
01063                   MESSAGE_MED(LOC<<": MEDpolyedreConnLire returns "<<err2);
01064                   return MED_ERROR;
01065                 }
01066                 // insert face separators
01067                 int* polyindex = NodalIndex + Connectivity->_count[i] - 1;
01068                 int k = NodalIndex[ Connectivity->_count[i]-1 ] - 1;
01069                 for ( j=0; j<tmp_numberOfCells; j++)
01070                 {
01071                   int k0 = k;
01072                   for ( int iface = PolyhedronIndex[j]; iface < PolyhedronIndex[j+1]; ++iface)
01073                   {
01074                     for ( int inode = FacesIndex[iface-1]; inode < FacesIndex[iface]; ++inode)
01075                       NodalValue[k++] = tmp_ConnectivityArray[inode-1];
01076                     if ( iface+1 < PolyhedronIndex[j+1] )
01077                       NodalValue[k++] = -1;
01078                   }
01079                   polyindex[j+1] = polyindex[j] + k - k0;
01080                 }
01081                 continue; // no need to copy tmp_ConnectivityArray - already done
01082                 //break;
01083               }
01084             default:
01085               med_2_3::med_bool withname=med_2_3::MED_FALSE,withnumber=med_2_3::MED_FALSE,withfam=med_2_3::MED_FALSE;
01086               int curNbOfElemp3=med_2_3::MEDmeshnEntity(_medIdt,_ptrMesh->_name.c_str(),
01087                                                         dtp3,itp3,
01088                                                         med_2_3::MED_CELL,
01089                                                         med_2_3::med_geometry_type(Connectivity->_geometricTypes[i]),
01090                                                         med_2_3::MED_CONNECTIVITY,
01091                                                         med_2_3::MED_NODAL,
01092                                                         &chgtp3,&trfp3);
01093               char *nomsp3=new char[MED_SNAME_SIZE*curNbOfElemp3+1];
01094               int *globArrp3=new int[curNbOfElemp3];
01095               int *famp3=new int[curNbOfElemp3];
01096               err2=med_2_3::MEDmeshElementRd(_medIdt,_ptrMesh->_name.c_str(),
01097                                              dtp3,itp3,
01098                                              med_2_3::MED_CELL,
01099                                              med_2_3::med_geometry_type(Connectivity->_geometricTypes[i]),
01100                                              med_2_3::MED_NODAL,
01101                                              med_2_3::MED_FULL_INTERLACE,
01102                                              tmp_ConnectivityArray,
01103                                              &withname,nomsp3,&withnumber,
01104                                              globArrp3,&withfam,famp3);
01105               delete [] nomsp3;
01106               delete [] globArrp3;
01107               delete [] famp3;
01108               if ( err2 != MED_VALID)
01109               {
01110                 MESSAGE_MED(LOC<<": MEDconnLire returns "<<err2);
01111                 return MED_ERROR;
01112               }
01113               int NumberOfNodeByCell = Connectivity->_type[i].getNumberOfNodes();
01114               // initialise index
01115               for ( j=Connectivity->_count[i]; j<Connectivity->_count[i+1];j++)
01116                 NodalIndex[j]=NodalIndex[j-1]+NumberOfNodeByCell;
01117             }
01118 
01119             // version originale sans prise en compte des numeros optionnels
01120             //
01121             int * ConnectivityArray = NodalValue + NodalIndex[Connectivity->_count[i]-1]-1;
01122             for ( j=0; j<connSizeByType[i]; j++)
01123               ConnectivityArray[j] = tmp_ConnectivityArray[j];
01124 
01126             // Modification pour prise en compte de la numerotation optionnelle des noeuds ///
01128             //
01129             // Renumerote le tableau temporaire tmp_ConnectivityArray
01130             // en utilisant _optionnalToCanonicNodesNumbers
01131             // Le traitement est identique a la version originelle
01132             // s'il n'y a pas de numerotation optionnelle
01133             //
01134             //if (_ptrMesh->_arePresentOptionnalNodesNumbers==1)
01135             //{
01136             //  for ( j=0; j<tmp_numberOfCells; j++) for (int k=0; k<NumberOfNodeByCell; k++)
01137             //    ConnectivityArray[j*NumberOfNodeByCell+k] = _ptrMesh->
01138             //      _optionnalToCanonicNodesNumbers[tmp_ConnectivityArray[j*(NumberOfNodeByCell+multi)+k]];
01139             //}
01140             //else
01141             //{
01142             //  for ( j=0; j<tmp_numberOfCells; j++) for (int k=0; k<NumberOfNodeByCell; k++)
01143             //    ConnectivityArray[j*NumberOfNodeByCell+k] =
01144             //      tmp_ConnectivityArray[j*(NumberOfNodeByCell+multi)+k];
01145             //}
01147 
01148           }
01149 
01150           Connectivity->_nodal = new MEDSKYLINEARRAY(Connectivity->_count[Connectivity->_numberOfTypes]-1,
01151                                                      size,
01152                                                      NodalIndex,
01153                                                      NodalValue);
01154 
01155         } // end of bloc to read CELL
01156 
01157         // Get Face if any
01158         // ===============
01159         if (!faceTypes.empty())
01160         {
01161           // Create a CONNECTIVITY constituent to put in the top level CONNECTIVITY recursive class
01162           CONNECTIVITY * constituent = new CONNECTIVITY(faceTypes.size(),MED_EN::MED_FACE);
01163           constituent->_numberOfNodes = _ptrMesh->getNumberOfNodes();
01164           constituent->_entityDimension = 2;
01165           constituent->_count[0]=1;
01166 
01167           // In order to create the MEDSKYLINEARRAY of the constituent object we need :
01168           // 1:
01169           // To initialize the _count array of the constituent object
01170           // (containning cumulated face count by geometric type)
01171           // _count[0]=1 and _count[_numberOfTypes] give the size of NodalIndex
01172           // 2:
01173           // To calculate the total number of face nodes whatever the geometric type is.
01174           // The result is the size of the array containning all the nodes : NodalValue
01175           // 3 :
01176           // To calculate the starting indexes of the different face types in NodalValue,
01177           // this is the NodalIndex array.
01178 
01179           int size = 0;
01180           vector<int> connSizeByType;
01181           for ( i=0; i < (int)faceTypes.size(); i++)
01182           {
01183             constituent->_count[i+1] = constituent->_count[i] + tmpFaceCount[i];
01184             constituent->_type[i] = CELLMODEL_Map::retrieveCellModel( faceTypes[i] );
01185             constituent->_geometricTypes[i] = faceTypes[i];
01186 
01187             if ( faceTypes[i] == MED_EN::MED_POLYGON )
01188               connSizeByType.push_back( polygonConnSize );
01189             else
01190               connSizeByType.push_back( tmpFaceCount[i] * constituent->_type[i].getNumberOfNodes());
01191             size += connSizeByType.back();
01192           }
01193 
01194           // Creation of the MEDSKYLINEARRAY
01195           PointerOf<int> NodalValue (size);
01196           PointerOf<int> NodalIndex (constituent->_count[constituent->_numberOfTypes]);
01197           NodalIndex[0]=1;
01198 
01199           // Fill the MEDSKYLINEARRAY by reading the MED file.
01200           for ( i=0; i<constituent->_numberOfTypes; i++)
01201           {
01202               int NumberOfNodeByFace = constituent->_type[i].getNumberOfNodes();
01203 
01204               // Il faut ajouter 1 pour le zero a la lecture !!!
01205             // ATTENTION UNIQUEMENT POUR MED < 2.2.x
01206             PointerOf< med_2_3::med_int> tmp_constituentArray;
01207 
01208             MESSAGE_MED(LOC << "Med file version used here " << major << " " << minor << " " << release);
01209 
01210             if ((major == 2) && (minor <= 1))
01211               tmp_constituentArray.set( connSizeByType[i] + tmpFaceCount[i] );
01212             else if ((major == 2) && (minor >= 2))
01213             {
01214               tmp_constituentArray.set( connSizeByType[i] );
01215               MESSAGE_MED(LOC<<": WE ARE USING MED2.2 so there is no +1 for calculating the size of  tmp_constituentArray !");
01216             }
01217             else
01218               tmp_constituentArray.set( connSizeByType[i] );
01219 
01220             if ( constituent->_geometricTypes[i] == MED_EN::MED_POLYGON )
01221             {
01222               PointerOf< med_2_3::med_int> PolygonsConnIndex( tmpFaceCount[i]+1 );
01223               int err2 = med_2_3::MEDmeshPolygonRd(_medIdt,_ptrMesh->_name.c_str(),
01224                                                    dtp3,itp3,
01225                                                    med_2_3::MED_CELL,
01226                                                    med_2_3::MED_NODAL,
01227                                                    PolygonsConnIndex,
01228                                                    tmp_constituentArray);
01229 
01230               if (err2 != MED_VALID)
01231               {
01232                 MESSAGE_MED(LOC<<": MEDpolygoneConnLire returns "<<err2);
01233                 delete constituent;
01234                 return MED_ERROR;
01235               }
01236               int* polyindex = (int*)NodalIndex + constituent->_count[i] - 1;
01237               int delta = polyindex[0] - PolygonsConnIndex[0];
01238               for ( int j=0; j<=tmpFaceCount[i]; j++)
01239                 polyindex[j]= delta + PolygonsConnIndex[ j ];
01240             }
01241             else
01242             {
01243               med_2_3::med_geometry_type med_type =
01244                 (med_2_3::med_geometry_type) constituent->_type[i].getType();
01245 
01246               
01247               med_2_3::med_bool withname=med_2_3::MED_FALSE,withnumber=med_2_3::MED_FALSE,withfam=med_2_3::MED_FALSE;
01248               int curNbOfElemp3=med_2_3::MEDmeshnEntity(_medIdt,_ptrMesh->_name.c_str(),
01249                                                         dtp3,itp3,
01250                                                         med_2_3::MED_CELL,med_type,
01251                                                         med_2_3::MED_CONNECTIVITY,
01252                                                         med_2_3::MED_NODAL,
01253                                                         &chgtp3,&trfp3);
01254               char *nomsp3=new char[MED_SNAME_SIZE*curNbOfElemp3+1];
01255               int *globArrp3=new int[curNbOfElemp3];
01256               int *famp3=new int[curNbOfElemp3];
01257               int err=med_2_3::MEDmeshElementRd(_medIdt,_ptrMesh->_name.c_str(),
01258                                                 dtp3,itp3,
01259                                                 med_2_3::MED_CELL,med_type,
01260                                                 med_2_3::MED_NODAL,
01261                                                 med_2_3::MED_FULL_INTERLACE,
01262                                                 tmp_constituentArray,
01263                                                 &withname,nomsp3,&withnumber,
01264                                                 globArrp3,&withfam,famp3);
01265               delete [] nomsp3;
01266               delete [] globArrp3;
01267               delete [] famp3;
01268               
01269               if ( err != MED_VALID)
01270               {
01271                 MESSAGE_MED(LOC<<": MEDconnLire returns "<<err);
01272                 delete constituent;
01273                 return MED_ERROR;
01274               }
01275               // initialise NodalIndex
01276               for (int j=constituent->_count[i]; j<constituent->_count[i+1];j++)
01277                 NodalIndex[j]=NodalIndex[j-1]+NumberOfNodeByFace;
01278             }
01279 
01280             int tmp_numberOfFaces = constituent->_count[i+1]-constituent->_count[i];
01281 
01282             int * constituentArray = NodalValue + NodalIndex[constituent->_count[i]-1]-1;
01283 
01284             MESSAGE_MED(LOC << "Med file version used here " << major << " " << minor << " " << release);
01285             if ((major == 2) && (minor <= 1))
01286               for (int j=0; j<tmp_numberOfFaces; j++)
01287                 for (int k=0; k<NumberOfNodeByFace; k++)
01288                   constituentArray[j*NumberOfNodeByFace+k]=tmp_constituentArray[j*(NumberOfNodeByFace+1)+k];
01289             else if (((major == 2) && (minor >= 2)) || (major > 2))
01290               for ( int j = 0; j < connSizeByType[i]; ++j )
01291                 constituentArray[j]=tmp_constituentArray[j];
01292           }
01293 
01294           constituent->_nodal = new MEDSKYLINEARRAY(constituent->_count[constituent->_numberOfTypes]-1,
01295                                                     size,
01296                                                     NodalIndex,
01297                                                     NodalValue);
01298           Connectivity->_constituent = constituent;
01299         }
01300 
01301         // get Edge if any
01302         // ===============
01303         if ( !edgeTypes.empty() )
01304         {
01305           CONNECTIVITY * constituent = new CONNECTIVITY(tmpEdgeCount.size() ,MED_EDGE);
01306           constituent->_numberOfNodes = _ptrMesh->getNumberOfNodes();
01307           constituent->_entityDimension = 1;
01308           constituent->_count[0]=1;
01309 
01310           int size = 0;
01311           for ( i=0; i<(int)edgeTypes.size(); i++)
01312           {
01313             constituent->_count[i+1]=constituent->_count[i]+tmpEdgeCount[i];
01314             constituent->_type[i]=CELLMODEL_Map::retrieveCellModel( edgeTypes[i] );
01315             constituent->_geometricTypes[i] = edgeTypes[i];
01316 
01317             size+=tmpEdgeCount[i]*constituent->_type[i].getNumberOfNodes();
01318           }
01319 
01320           // Creation of the MEDSKYLINEARRAY
01321           PointerOf< int > NodalValue( size );
01322           PointerOf< int > NodalIndex( constituent->_count[constituent->_numberOfTypes] );
01323           NodalIndex[0]=1;
01324 
01325           // Fill the MEDSKYLINEARRAY by reading the MED file.
01326           for ( i=0; i<constituent->_numberOfTypes; i++)
01327           {
01328             med_2_3::med_geometry_type med_type =
01329               (med_2_3::med_geometry_type) constituent->_type[i].getType();
01330             int NumberOfNodeByEdge = constituent->_type[i].getNumberOfNodes();
01331 
01332             // initialise index
01333             for (int j=constituent->_count[i]; j<constituent->_count[i+1];j++)
01334               NodalIndex[j]=NodalIndex[j-1]+NumberOfNodeByEdge;
01335 
01336             int tmp_numberOfEdges = constituent->_count[i+1]-constituent->_count[i];
01337             // Il faut ajouter 1 pour le zero a la lecture !!!
01338 
01339             // ATTENTION UNIQUEMENT POUR MED < 2.2.x
01340             med_2_3::med_int * tmp_constituentArray = NULL;
01341 
01342             MESSAGE_MED(LOC << "Med file version used here " << major << " " << minor << " " << release);
01343 
01344             if ((major == 2) && (minor <= 1))
01345               tmp_constituentArray = new med_2_3::med_int[(NumberOfNodeByEdge+1)*tmp_numberOfEdges];
01346             else if ((major == 2 && minor >= 2) || ( major > 2 ))
01347             {
01348               tmp_constituentArray = new med_2_3::med_int[NumberOfNodeByEdge*tmp_numberOfEdges];
01349               MESSAGE_MED(LOC<<": WE ARE USING MED2.2 so there is no +1 for calculating the size of  tmp_constituentArray !");
01350             }
01351 
01352 
01353             med_2_3::med_bool withname=med_2_3::MED_FALSE,withnumber=med_2_3::MED_FALSE,withfam=med_2_3::MED_FALSE;
01354             int curNbOfElemp3=med_2_3::MEDmeshnEntity(_medIdt,_ptrMesh->_name.c_str(),
01355                                                       dtp3,itp3,
01356                                                       med_2_3::MED_CELL,
01357                                                       med_type,
01358                                                       med_2_3::MED_CONNECTIVITY,
01359                                                       med_2_3::MED_NODAL,
01360                                                       &chgtp3,&trfp3);
01361             char *nomsp3  =new char[MED_SNAME_SIZE*curNbOfElemp3+1];
01362             int *globArrp3=new int[curNbOfElemp3];
01363             int *famp3    =new int[curNbOfElemp3];
01364             int err=med_2_3::MEDmeshElementRd(_medIdt,_ptrMesh->_name.c_str(),
01365                                               dtp3,itp3,
01366                                               med_2_3::MED_CELL,
01367                                               med_type,
01368                                               med_2_3::MED_NODAL,
01369                                               med_2_3::MED_FULL_INTERLACE,
01370                                               tmp_constituentArray,
01371                                               &withname,nomsp3,&withnumber,
01372                                               globArrp3,&withfam,famp3);
01373             delete [] nomsp3;
01374             delete [] globArrp3;
01375             delete [] famp3;
01376 
01377             if ( err != MED_VALID)
01378             {
01379               MESSAGE_MED(LOC<<": MEDconnLire returns "<<err);
01380               delete constituent;
01381               delete[] tmp_constituentArray;
01382               return MED_ERROR;
01383             }
01384 
01385             int * constituentArray = NodalValue + NodalIndex[constituent->_count[i]-1]-1;
01386 
01387             // version originale sans prise en compte des numéros optionnels
01388             //
01389             int multi = 0; // quand est-ce que multi vaut 1 ?? en MED-fichier < 2.2 ??
01390             MESSAGE_MED(LOC << "Med file version used here " << major << " " << minor << " " << release);
01391 
01392             if ((major == 2) && (minor <= 1))
01393               for (int j=0; j<tmp_numberOfEdges; j++)
01394                 for (int k=0; k<NumberOfNodeByEdge; k++)
01395                   constituentArray[j*NumberOfNodeByEdge+k] =
01396                     tmp_constituentArray[j*(NumberOfNodeByEdge+multi)+k];
01397             else if ((major == 2 && minor >= 2) || (major > 2))
01398               for (int j=0; j<tmp_numberOfEdges; j++)
01399                 for (int k=0; k<NumberOfNodeByEdge; k++)
01400                   constituentArray[j*NumberOfNodeByEdge+k] = tmp_constituentArray[j*(NumberOfNodeByEdge)+k];
01401 
01410             //
01411             //if (_ptrMesh->_arePresentOptionnalNodesNumbers)
01412             //{
01413             //  for (int j=0; j<tmp_numberOfEdges; j++) for (int k=0; k<NumberOfNodeByEdge; k++)
01414             //    constituentArray[j*NumberOfNodeByEdge+k] = _ptrMesh->
01415             //      _optionnalToCanonicNodesNumbers[tmp_constituentArray[j*(NumberOfNodeByEdge+1)+k]];
01416             //}
01417             //else
01418             //{
01419             //  for (int j=0; j<tmp_numberOfEdges; j++) for (int k=0; k<NumberOfNodeByEdge; k++)
01420             //    constituentArray[j*NumberOfNodeByEdge+k]=tmp_constituentArray[j*(NumberOfNodeByEdge+1)+k];
01421             //}
01423 
01424             delete[] tmp_constituentArray;
01425           }
01426 
01427           constituent->_nodal = new MEDSKYLINEARRAY(constituent->_count[constituent->_numberOfTypes]-1,
01428                                                     size,
01429                                                     NodalIndex,
01430                                                     NodalValue);
01431 
01432           if (Connectivity->_entityDimension == 3)
01433           {
01434             if (Connectivity->_constituent==NULL)
01435               throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Edges are defined but there are no Faces !"));
01436             Connectivity->_constituent->_constituent = constituent;
01437           } else
01438             Connectivity->_constituent = constituent;
01439         }
01440 
01441       }
01442 
01443       // If there is no nodal connectivity, we return MED_ERROR !
01444       if (Connectivity->_numberOfTypes == 0)
01445         return MED_ERROR;
01446       else
01447         return MED_VALID;
01448     }
01449   return MED_ERROR;
01450 }
01451 
01452 int  MED_MESH_RDONLY_DRIVER::getFAMILY()
01453 {
01454   const char * LOC = "MED_MESH_RDONLY_DRIVER::getFAMILY() : ";
01455   BEGIN_OF_MED(LOC);
01456 
01457   if (_status==MED_OPENED)
01458   {
01459     int err = 0;
01460 
01461     int * MEDArrayNodeFamily = NULL;
01462     int ** MEDArrayCellFamily = NULL;
01463     int ** MEDArrayFaceFamily = NULL;
01464     int ** MEDArrayEdgeFamily = NULL;
01465 
01466     // NODE :
01467     MEDArrayNodeFamily = new int[_ptrMesh->getNumberOfNodes()];
01468 
01469     err = getNodesFamiliesNumber(MEDArrayNodeFamily);
01470     // error only if (_status!=MED_OPENED), other case exeception !
01471     // CELL
01472 
01473     MESSAGE_MED(LOC << "error returned from getNodesFamiliesNumber " << err);
01474 
01475     MEDArrayCellFamily = new int* [_ptrMesh->getNumberOfTypes(MED_CELL)];
01476     // ET SI IL N'Y A PAS DE CELLS ?
01477 
01478     const medGeometryElement * myTypes = _ptrMesh->getTypes(MED_CELL);
01479     for (int i=0;i<_ptrMesh->getNumberOfTypes(MED_CELL);i++)
01480       MEDArrayCellFamily[i] = new
01481         int[_ptrMesh->getNumberOfElements(MED_CELL,myTypes[i])];
01482 
01483     err = getCellsFamiliesNumber(MEDArrayCellFamily,MED_CELL);
01484     MESSAGE_MED(LOC << "error returned from getCellsFamiliesNumber for Cells " << err);
01485 
01486     if (_ptrMesh->getNumberOfElements( MED_EN::MED_FACE, MED_EN::MED_ALL_ELEMENTS ))
01487     {
01488       // FACE
01489       MEDArrayFaceFamily = new int* [_ptrMesh->getNumberOfTypes(MED_FACE)];
01490 
01491       myTypes = _ptrMesh->getTypes(MED_FACE);
01492       for (int i=0;i<_ptrMesh->getNumberOfTypes(MED_FACE);i++)
01493         MEDArrayFaceFamily[i] = new int[ _ptrMesh->getNumberOfElements( MED_FACE,myTypes[i])];
01494 
01495       err = getCellsFamiliesNumber(MEDArrayFaceFamily,MED_FACE);
01496       MESSAGE_MED(LOC << "error returned from getCellsFamiliesNumber for Faces " << err);
01497     }
01498     if (_ptrMesh->getNumberOfElements( MED_EN::MED_EDGE, MED_EN::MED_ALL_ELEMENTS))
01499     {
01500       // EDGE in 3D or 2D
01501       MEDArrayEdgeFamily = new int* [_ptrMesh->getNumberOfTypes(MED_EDGE)];
01502 
01503       const medGeometryElement *myTypes2 = _ptrMesh->getTypes(MED_EDGE);
01504       for (int i=0;i<_ptrMesh->getNumberOfTypes(MED_EDGE);i++)
01505         MEDArrayEdgeFamily[i] = new
01506           int[_ptrMesh->getNumberOfElements(MED_EDGE,myTypes2[i])];
01507 
01508       err = getCellsFamiliesNumber(MEDArrayEdgeFamily,MED_EDGE);
01509 
01510       MESSAGE_MED(LOC << "error returned from getCellsFamiliesNumber for Edges " << err);
01511     }
01512 
01513     int NumberOfFamilies = med_2_3::MEDnFamily(_medIdt,_meshName.c_str());
01514 
01515     if ( NumberOfFamilies < 1 ) // at least family 0 must exist
01516       throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"There is no FAMILY, FAMILY 0 must exists" ));
01517 
01518     SCRUTE_MED(NumberOfFamilies);
01519 
01520     vector<FAMILY*> &NodeFamilyVector = _ptrMesh->_familyNode;
01521     vector<FAMILY*> &CellFamilyVector = _ptrMesh->_familyCell;
01522     vector<FAMILY*> &FaceFamilyVector = _ptrMesh->_familyFace;
01523     vector<FAMILY*> &EdgeFamilyVector = _ptrMesh->_familyEdge;
01524 
01525     int numberOfNodesFamilies = 0;
01526     int numberOfCellsFamilies = 0;
01527     int numberOfFacesFamilies = 0;
01528     int numberOfEdgesFamilies = 0;
01529 
01530 
01531     for (int i=0;i<NumberOfFamilies;i++)
01532     {
01533 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
01534       med_2_3::med_int tmp_NumberOfAttributes = med_2_3::MEDnFamily23Attribute(_medIdt,_meshName.c_str(),i+1);
01535       med_2_3::med_int NumberOfAttributes = tmp_NumberOfAttributes;
01536 #else
01537       int NumberOfAttributes = med_2_3::MEDnFamily23Attribute(_medIdt,_meshName.c_str(),(i+1));
01538 #endif
01539 
01540       if (NumberOfAttributes < 0)
01541         throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER::getFAMILY() : NumberOfAttributes" );
01542 
01543 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
01544       med_2_3::med_int tmp_NumberOfGroups = med_2_3::MEDnFamilyGroup(_medIdt,_meshName.c_str(),i+1);
01545       int NumberOfGroups = tmp_NumberOfGroups;
01546 #else
01547       int NumberOfGroups = med_2_3::MEDnFamilyGroup(_medIdt,_meshName.c_str(),i+1);
01548 #endif
01549 
01550       if (NumberOfGroups < 0)
01551         throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER::getFAMILY() : NumberOfGroups" );
01552 
01553       int FamilyIdentifier;
01554       string FamilyName(MED_NAME_SIZE,'\0');
01555       // 0020071: Crash of V4_1_4rc2 (of testMedMemGeneral.py)
01556       // Pb with Mistrat_import22.med: it's zero family has non-empty AttributesIdentifier's and
01557       // AttributesValues' but MEDnAttribut() returns 0 (0 is hardcoded for zero family).
01558       // So we allocate nothing but MEDfamInfo() reads file contents so overwritting
01559       // stranger's memory. Stupid solution: allocate more than MEDnAttribut()
01560       const int iSafe = 10;
01561       int *  AttributesIdentifier = new int[NumberOfAttributes+iSafe];
01562       int *  AttributesValues     = new int[NumberOfAttributes+iSafe];
01563       string AttributesDescription(MED_COMMENT_SIZE*(NumberOfAttributes+iSafe),' ');
01564       string GroupsNames(MED_LNAME_SIZE*NumberOfGroups+1,'\0');
01565 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
01566       med_2_3::med_int tmp_FamilyIdentifier;
01567       med_2_3::med_int *  tmp_AttributesIdentifier = new med_2_3::med_int[NumberOfAttributes+iSafe];
01568       med_2_3::med_int *  tmp_AttributesValues     = new med_2_3::med_int[NumberOfAttributes+iSafe];
01569 
01570       err=med_2_3::MEDfamily23Info(_medIdt,_meshName.c_str(),i+1,const_cast <char *>(FamilyName.c_str()),
01571                                    tmp_AttributesIdentifier,tmp_AttributesValues,const_cast <char *>(AttributesDescription.c_str()),&tmp_FamilyIdentifier,const_cast <char *>(GroupsNames.c_str()));
01572 
01573       FamilyIdentifier = tmp_FamilyIdentifier;
01574       int ii;
01575       for ( ii = 0; ii < NumberOfAttributes; ii++ ) {
01576         AttributesIdentifier[ii] = tmp_AttributesIdentifier[ii];
01577         AttributesValues[ii] = tmp_AttributesValues[ii];
01578       }
01579       NumberOfAttributes = tmp_NumberOfAttributes;
01580       NumberOfGroups = tmp_NumberOfGroups;
01581       delete [] tmp_AttributesIdentifier;
01582       delete [] tmp_AttributesValues;
01583 #else
01584       err = med_2_3::MEDfamily23Info(_medIdt,_meshName.c_str(),i+1,const_cast <char *>(FamilyName.c_str()),
01585                                      AttributesIdentifier,AttributesValues,const_cast <char *>(AttributesDescription.c_str()),&FamilyIdentifier,const_cast <char *>(GroupsNames.c_str()));
01586 #endif
01587 
01588 
01589       SCRUTE_MED(GroupsNames);
01590       SCRUTE_MED(FamilyName);
01591       SCRUTE_MED(err);
01592       SCRUTE_MED(i);
01593 
01594       if (err != MED_VALID)
01595         throw MEDEXCEPTION("MED_MESH_RDONLY_DRIVER::getFAMILY() : ERROR when get FAMILY informations" );
01596 
01597       if (FamilyIdentifier != 0 )
01598       {
01599         FAMILY * Family = new FAMILY(_ptrMesh,FamilyIdentifier,FamilyName,
01600                                      NumberOfAttributes,
01601                                      AttributesIdentifier,
01602                                      AttributesValues,
01603                                      AttributesDescription,
01604                                      NumberOfGroups,GroupsNames,
01605                                      MEDArrayNodeFamily,
01606                                      MEDArrayCellFamily,
01607                                      MEDArrayFaceFamily,
01608                                      MEDArrayEdgeFamily);
01609 
01610         // All good ?
01611         // if nothing found, delete Family
01612 
01617         if (Family->getNumberOfTypes() == 0)
01618         {
01619           MESSAGE_MED(LOC<<"Nothing found for family "<<FamilyName<<
01620                       " : skip");
01621           Family->removeReference();
01622         }
01623         else
01624           switch (Family->getEntity())
01625           {
01626           case MED_EN::MED_NODE :
01627             _ptrMesh->removeReference();
01628             NodeFamilyVector.push_back(Family);
01629             numberOfNodesFamilies++;
01630             break;
01631           case MED_EN::MED_CELL :
01632             _ptrMesh->removeReference();
01633             CellFamilyVector.push_back(Family);
01634             numberOfCellsFamilies++;
01635             break;
01636           case MED_EN::MED_FACE :
01637             _ptrMesh->removeReference();
01638             FaceFamilyVector.push_back(Family);
01639             numberOfFacesFamilies++;
01640             break;
01641           case MED_EN::MED_EDGE :
01642             _ptrMesh->removeReference();
01643             EdgeFamilyVector.push_back(Family);
01644             numberOfEdgesFamilies++;
01645             break;
01646           }
01647       }
01648 
01649       delete [] AttributesIdentifier;
01650       delete [] AttributesValues;
01651     }
01652 
01653     if (MEDArrayNodeFamily != NULL)
01654       delete[] MEDArrayNodeFamily;
01655 
01656     if (MEDArrayCellFamily != NULL)
01657     {
01658       for (int i=0; i<_ptrMesh->getNumberOfTypes(MED_CELL); i++)
01659         delete[] MEDArrayCellFamily[i];
01660       delete[] MEDArrayCellFamily;
01661     }
01662 
01663     if (MEDArrayFaceFamily != NULL)
01664     {
01665       for (int i=0; i<_ptrMesh->getNumberOfTypes(MED_FACE); i++)
01666         delete[] MEDArrayFaceFamily[i];
01667       delete[] MEDArrayFaceFamily;
01668     }
01669 
01670     if (MEDArrayEdgeFamily != NULL)
01671     {
01672       for (int i=0; i<_ptrMesh->getNumberOfTypes(MED_EDGE); i++)
01673         delete[] MEDArrayEdgeFamily[i];
01674       delete[] MEDArrayEdgeFamily;
01675     }
01676 
01677     END_OF_MED(LOC);
01678     return MED_VALID;
01679   }
01680 
01681   return MED_ERROR;
01682 }
01683 
01684 int  MED_MESH_RDONLY_DRIVER::getNodesFamiliesNumber(int * MEDArrayNodeFamily)
01685 {
01686   const char * LOC = "MED_MESH_RDONLY_DRIVER::getNodesFamiliesNumber() : ";
01687 
01688   BEGIN_OF_MED(LOC);
01689 
01690   if (_status==MED_OPENED)
01691     {
01692 
01693       int dtp3,itp3;
01694       med_2_3::med_float ttpp3;
01695       med_2_3::MEDmeshComputationStepInfo(_medIdt,_ptrMesh->_name.c_str(),1,&dtp3,&itp3,&ttpp3);
01696       int err = 0;
01697 
01698 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
01699       med_2_3::med_int * tmp_MEDArrayNodeFamily = new med_2_3::med_int[_ptrMesh->getNumberOfNodes()];
01700       err=med_2_3::MEDmeshEntityFamilyNumberRd(_medIdt,_ptrMesh->_name.c_str(),dtp3,itp3,med_2_3::MED_NODE,MED_NONE,tmp_MEDArrayNodeFamily);
01701       int i;
01702       for ( i = 0; i < _ptrMesh->getNumberOfNodes(); i++ )
01703         MEDArrayNodeFamily[i] = tmp_MEDArrayNodeFamily[i];
01704       delete [] tmp_MEDArrayNodeFamily;
01705 #else
01706       err=med_2_3::MEDmeshEntityFamilyNumberRd(_medIdt,_ptrMesh->_name.c_str(),dtp3,itp3,med_2_3::MED_NODE,MED_NONE,MEDArrayNodeFamily);
01707 #endif
01708 
01709       if ( err != MED_VALID)
01710         {
01711           std::fill(MEDArrayNodeFamily,MEDArrayNodeFamily+_ptrMesh->getNumberOfNodes(),0);
01712           //throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "There is no family for the |"<< _ptrMesh->getNumberOfNodes() << "| nodes in mesh |" << _ptrMesh->_name.c_str() << "|"));
01713         }
01714 
01715       END_OF_MED(LOC);
01716       return MED_VALID;
01717     }
01718 
01719   return MED_ERROR;
01720 }
01721 
01722 int  MED_MESH_RDONLY_DRIVER::getCellsFamiliesNumber(int **MEDArrayFamily,
01723                                                     MED_EN::medEntityMesh entity)
01724 {
01725   const char * LOC = "MED_MESH_RDONLY_DRIVER::getCellsFamiliesNumber ";
01726 
01727   BEGIN_OF_MED(LOC);
01728 
01729   if (_status==MED_OPENED)
01730   {
01731     int dtp3,itp3;
01732     med_2_3::med_float ttpp3;
01733     med_2_3::MEDmeshComputationStepInfo(_medIdt,_ptrMesh->_name.c_str(),1,&dtp3,&itp3,&ttpp3);
01734     int i, err = 0;
01735     const MED_EN::medGeometryElement *types=_ptrMesh->getTypes(entity);
01736     for (i=0;i<_ptrMesh->getNumberOfTypes(entity);i++)
01737     {
01738 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
01739       int NumberOfCell=_ptrMesh->getNumberOfElements(entity,types[i]);
01740       med_2_3::med_int * tmp_MEDArrayFamily = new med_2_3::med_int[NumberOfCell];
01741       err=med_2_3::MEDmeshEntityFamilyNumberRd(_medIdt,_ptrMesh->_name.c_str(),dtp3,itp3,(med_2_3::med_entity_type) entity,(med_2_3::med_geometry_type)types[i],tmp_MEDArrayFamily);
01742       if (err != MED_VALID
01743           && !_ptrMesh->getIsAGrid()) // it's normal for a grid (PAL14113)
01744       {
01745         err=med_2_3::MEDmeshEntityFamilyNumberRd(_medIdt,_ptrMesh->_name.c_str(),dtp3,itp3,med_2_3::MED_CELL,(med_2_3::med_geometry_type)types[i],tmp_MEDArrayFamily);
01746         if (err != MED_VALID )
01747           {
01748             std::fill(tmp_MEDArrayFamily,tmp_MEDArrayFamily+NumberOfCell,0);
01749             //throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Family not found for entity "<<entity<<" and geometric type "<<types[i]));
01750           }
01751       }
01752       if (err == MED_VALID) {
01753         int ii;
01754         for ( ii = 0; ii < NumberOfCell; ii++ )
01755           MEDArrayFamily[i][ii] = tmp_MEDArrayFamily[ii];
01756       }
01757       delete [] tmp_MEDArrayFamily;
01758 #else
01759       err=med_2_3::MEDmeshEntityFamilyNumberRd(_medIdt,_ptrMesh->_name.c_str(),dtp3,itp3,(med_2_3::med_entity_type) entity,(med_2_3::med_geometry_type)types[i],MEDArrayFamily[i]);
01760 
01761       if (err != MED_VALID
01762           && !_ptrMesh->getIsAGrid() ) // it's normal for a grid (PAL14113)
01763       {
01764         err=med_2_3::MEDmeshEntityFamilyNumberRd(_medIdt,_ptrMesh->_name.c_str(),dtp3,itp3,med_2_3::MED_CELL,(med_2_3::med_geometry_type)types[i],MEDArrayFamily[i]);
01765 
01766         if (err != MED_VALID)
01767           {
01768             int NumberOfCell=_ptrMesh->getNumberOfElements(entity,types[i]);
01769             std::fill(MEDArrayFamily[i],MEDArrayFamily[i]+NumberOfCell,0);
01770             //throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<" Family not found for entity "<<entity<<" and geometric type "<<types[i]));
01771           }
01772       }
01773 #endif
01774     }
01775     return err ? MED_INVALID : MED_VALID;
01776   }
01777   return MED_ERROR;
01778 }
01779 
01780 int MED_MESH_RDONLY_DRIVER::getDescendingConnectivity(CONNECTIVITY * Connectivity) 
01781 {
01782   if (_status==MED_OPENED)
01783     {
01784       MESSAGE_MED("MED_MESH_RDONLY_DRIVER::getDescendingConnectivity : "<<"call on the object " << Connectivity);
01785       MESSAGE_MED("MED_MESH_RDONLY_DRIVER::getDescendingConnectivity : "<<"Not yet implemented !");
01786     }
01787   return MED_ERROR;
01788 }
01789 
01790 void MED_MESH_RDONLY_DRIVER::buildAllGroups(vector<GROUP*> & Groups, vector<FAMILY*> & Families) 
01791 {
01792   const char* LOC = "MED_MESH_RDONLY_DRIVER::buildAllGroups ";
01793   BEGIN_OF_MED(LOC);
01794 
01795   int numberOfFamilies = Families.size() ;
01796   map< string,list<FAMILY*> > groupsNames ;
01797   for(int i=0; i<numberOfFamilies; i++) {
01798     FAMILY * myFamily = Families[i] ;
01799     int numberOfGroups_ = myFamily->getNumberOfGroups();
01800     for (int j=0; j<numberOfGroups_; j++) {
01801       groupsNames[myFamily->getGroupName(j+1)].push_back(myFamily);
01802     }
01803   }
01804   int numberOfGroups = groupsNames.size() ;
01805   SCRUTE_MED(numberOfGroups);
01806   Groups.resize(numberOfGroups);
01807   map< string,list<FAMILY*> >::const_iterator currentGroup ;
01808   int it = 0 ;
01809   for(currentGroup=groupsNames.begin();currentGroup!=groupsNames.end();currentGroup++) {
01810     GROUP * myGroup = new GROUP(healName((*currentGroup).first),(*currentGroup).second) ;
01811     _ptrMesh->removeReference();
01812     Groups[it]=myGroup;
01813     it++;
01814   }
01815 
01816   END_OF_MED(LOC);
01817 }
01818 
01819 void MED_MESH_RDONLY_DRIVER::updateFamily()
01820 {
01821   const char* LOC = "MED_MESH_RDONLY_DRIVER::updateFamily() ";
01822   BEGIN_OF_MED(LOC);
01823 
01824   // we need to update family on constituent if we have constituent, but no 
01825   // descending connectivity, so, we must calculate all constituent and
01826   // numbering correctly family !
01827   if ( !_ptrMesh->getIsAGrid() )
01828   {
01829     MESH* mesh = (MESH*) _ptrMesh;
01830     mesh->_connectivity->updateFamily(_ptrMesh->_familyFace) ; // in 2d, do nothing
01831     mesh->_connectivity->updateFamily(_ptrMesh->_familyEdge) ; // in 3d, do nothing
01832   }
01833   END_OF_MED(LOC);
01834 }
01835 
01836 /*--------------------- WRONLY PART -------------------------------*/
01837 
01838 MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER():MED_MESH_DRIVER()
01839 {
01840   this->GENDRIVER::_accessMode = MED_EN::WRONLY;
01841 }
01842 
01843 MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER(const string &         fileName,
01844                                                GMESH *                ptrMesh,
01845                                                MED_EN::med_mode_acces access):
01846   MED_MESH_DRIVER(fileName,ptrMesh,access)
01847 {
01848   MESSAGE_MED("MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER(const string & fileName, MESH * ptrMesh) has been created");
01849 }
01850 
01851 MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER(const MED_MESH_WRONLY_DRIVER & driver):
01852   MED_MESH_DRIVER(driver)
01853 {
01854 }
01855 
01856 MED_MESH_WRONLY_DRIVER::~MED_MESH_WRONLY_DRIVER()
01857 {
01858   //MESSAGE_MED("MED_MESH_WRONLY_DRIVER::MED_MESH_WRONLY_DRIVER(const string & fileName, MESH * ptrMesh) has been destroyed");
01859 }
01860 
01861 GENDRIVER * MED_MESH_WRONLY_DRIVER::copy(void) const
01862 {
01863   return new MED_MESH_WRONLY_DRIVER(*this);
01864 }
01865 
01866 void MED_MESH_WRONLY_DRIVER::read (void)
01867 {
01868   throw MEDEXCEPTION("MED_MESH_WRONLY_DRIVER::read : Can't read with a WRONLY driver !");
01869 }
01870 
01871 void MED_MESH_WRONLY_DRIVER::write(void) const
01872 {
01873 
01874   if (_ptrMesh==NULL || _ptrMesh->getNumberOfNodes() < 1 )
01875     throw MEDEXCEPTION("Error trying to write an empty mesh");
01876 
01877   const char * LOC = "void MED_MESH_WRONLY_DRIVER::write(void) const : ";
01878   BEGIN_OF_MED(LOC);
01879 
01880   // we must first create mesh !!
01881   MESSAGE_MED(LOC << "MeshName : |" << _meshName << "| FileName : |"<<_fileName<<"| MedIdt : | "<< _medIdt << "|");
01882 
01883   if (_status!=MED_OPENED)
01884     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "File "<<_fileName<<" is not open. Open it before write !"));
01885 
01886 
01887   string fieldName;
01888   if ( ( _meshName.empty() ) && ( _ptrMesh->_name.empty() )    )
01889     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)
01890                                  <<" neither <meshName> is set in driver nor in object MESH."));
01891 
01892   // If _meshName is not set in driver, try to use _ptrmesh->_meshName
01893   if ( ( _meshName.empty() ) && ( !_ptrMesh->_name.empty() )    )
01894     _meshName = healName(_ptrMesh->_name );
01895 
01896   if ( _meshName.size() > MED_NAME_SIZE )
01897     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)
01898                                  <<" <meshName> size in object driver MESH is > MED_NAME_SIZE ."));
01899 
01900 
01901   if (_ptrMesh->getIsAGrid())
01902   {
01903     if ( writeGRID() != MED_VALID )
01904       throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeGRID()"  ));
01905   }
01906   else
01907   {
01908     if (writeCoordinates()!=MED_VALID)
01909       throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeCoordinates()"  ));
01910 
01911     if (writeConnectivities(MED_EN::MED_CELL)!=MED_VALID)
01912       throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeConnectivities(MED_CELL)"  ));
01913     if (writeConnectivities(MED_EN::MED_FACE)!=MED_VALID)
01914       throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeConnectivities(MED_FACE)"  ));
01915     if (writeConnectivities(MED_EN::MED_EDGE)!=MED_VALID)
01916       throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeConnectivities(MED_EDGE)"  ));
01917   }
01918 
01919   if (writeFamilyNumbers() !=MED_VALID)
01920     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilyNumbers()"  ));
01921 
01922 
01923   // well we must first write zero family :
01924   if (_status==MED_OPENED) {
01925     int err;
01926     // test if the family already exists (HDF trick waiting a MED evolution to be replaced)
01927     string dataGroupFam = "/ENS_MAA/"+_meshName+"/FAS/FAMILLE_ZERO/";
01928     MESSAGE_MED("|"<<dataGroupFam<<"|");
01929     err =med_2_3::_MEDdatagroupOuvrir(_medIdt,const_cast <char *> (dataGroupFam.c_str()) );
01930     if ( err < MED_VALID ) {
01931       SCRUTE_MED(err);
01932 
01933       char familyName[MED_NAME_SIZE+1];
01934       strcpy(familyName,"FAMILLE_ZERO");
01935       err = med_2_3::MEDfamilyCr(_medIdt,_meshName.c_str(),familyName,0,0,0);
01936 
01937       SCRUTE_MED(familyName);
01938 
01939       if ( err != MED_VALID)
01940         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't create family |FAMILLE_ZERO| with identifier |0| groups names || and  attributes descriptions ||"));
01941     }
01942     else
01943       med_2_3::_MEDdatagroupFermer(_medIdt);
01944 
01945   }
01946 
01947   MESSAGE_MED(LOC<<"writeFamilies(_ptrMesh->_familyNode)");
01948   if (writeFamilies(_ptrMesh->_familyNode) !=MED_VALID)
01949     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilies(_ptrMesh->_familyNode)"  ));
01950 
01951   MESSAGE_MED(LOC<<"writeFamilies(_ptrMesh->_familyCell)");
01952   if (writeFamilies(_ptrMesh->_familyCell) !=MED_VALID)
01953     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilies(_ptrMesh->_familyCell)"  ));
01954 
01955   MESSAGE_MED(LOC<<"writeFamilies(_ptrMesh->_familyFace)");
01956   if (writeFamilies(_ptrMesh->_familyFace) !=MED_VALID)
01957     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilies(_ptrMesh->_familyFace)"  ));
01958 
01959   MESSAGE_MED(LOC<<"writeFamilies(_ptrMesh->_familyEdge)");
01960   if (writeFamilies(_ptrMesh->_familyEdge) !=MED_VALID)
01961     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "ERROR in writeFamilies(_ptrMesh->_familyEdge)"  ));
01962 
01963   END_OF_MED(LOC);
01964 }
01965 
01966 //=======================================================================
01967 //function : writeGRID
01968 //purpose  :
01969 //=======================================================================
01970 
01971 int MED_MESH_WRONLY_DRIVER::writeGRID() const
01972 {
01973   const char * LOC = "MED_MESH_WRONLY_DRIVER::writeGRID() : ";
01974   BEGIN_OF_MED(LOC);
01975 
01976   if (_status!=MED_OPENED)
01977   {
01978     MESSAGE_MED (LOC<<" Not open !!!");
01979     return MED_ERROR;
01980   }
01981   GRID * ptrGrid = (GRID*) _ptrMesh;
01982 
01983   med_2_3::med_err err = MED_ERROR;
01984   med_2_3::med_axis_type rep;
01985   string tmp_name(_ptrMesh->_spaceDimension*MED_SNAME_SIZE,' ');
01986   string tmp_unit(_ptrMesh->_spaceDimension*MED_SNAME_SIZE,' ');
01987 
01988   // Test if the mesh <_meshName> already exists
01989   // If it doesn't exists create it
01990   // If it already exists verify if its space and mesh dimensions are the same
01991   // as <_ptrMesh->_spaceDimension>, <_ptrMesh->getMeshDimension()> respectively
01992   // rem : <_meshName> is the driver meshName not <ptrMesh->_meshName>
01993 
01994   med_2_3::med_int dtpp3,itpp3;
01995   med_2_3::med_float ttpp3;
01996   err=med_2_3::MEDmeshComputationStepInfo(_medIdt,_meshName.c_str(),1,&dtpp3,&itpp3,&ttpp3);
01997 
01998   int spaceDimension=-1;
01999   int meshDimension=-1;
02000   if(!err)
02001     {
02002       med_2_3::med_mesh_type ttmp3;
02003       char commentp3[MED_COMMENT_SIZE+1];
02004       char dtunittp3[MED_LNAME_SIZE+1];
02005       med_2_3::med_sorting_type sttp3;
02006       int nstep;
02007       med_2_3::med_axis_type axtypp3;
02008       int naxis=std::max( 3, med_2_3::MEDmeshnAxisByName(_medIdt,_meshName.c_str()));
02009       char *t1pp3=new char[naxis*MED_SNAME_SIZE+1];
02010       char *t2pp3=new char[naxis*MED_SNAME_SIZE+1];
02011       med_2_3::MEDmeshInfoByName(_medIdt,_meshName.c_str(),&spaceDimension,&meshDimension,&ttmp3,commentp3,dtunittp3,&sttp3,&nstep,&axtypp3,t1pp3,t2pp3);
02012       delete [] t1pp3;
02013       delete [] t2pp3;
02014     }
02015   // Recompose the <_spaceDimension> strings in 1 string
02016   int lengthString;
02017   string valueString;
02018   for (int i=0;i<_ptrMesh->_spaceDimension;i++) {
02019     SCRUTE_MED(i);
02020     valueString = ptrGrid->_coordinate->_coordinateName[i];
02021     lengthString = (MED_SNAME_SIZE<valueString.size())?MED_SNAME_SIZE:valueString.size();
02022     tmp_name.replace(i*MED_SNAME_SIZE,i*MED_SNAME_SIZE+lengthString,valueString,0,lengthString);
02023     valueString = ptrGrid->_coordinate->_coordinateUnit[i];
02024     lengthString = (MED_SNAME_SIZE<valueString.size())?MED_SNAME_SIZE:valueString.size();
02025     tmp_unit.replace(i*MED_SNAME_SIZE,i*MED_SNAME_SIZE+lengthString,valueString,0,lengthString);
02026   }
02027 
02028   if (err) // create a mesh in the file
02029     {
02030       // Pourquoi le stocker sous forme de chaîne ?
02031       const string & coordinateSystem = ptrGrid->_coordinate->_coordinateSystem;
02032       if      (coordinateSystem  == "CARTESIAN")
02033         rep = med_2_3::MED_CARTESIAN;
02034       else if ( coordinateSystem == "CYLINDRICAL")
02035         rep = med_2_3::MED_CYLINDRICAL;
02036       else if ( coordinateSystem == "SPHERICAL" )
02037         rep = med_2_3::MED_SPHERICAL;
02038       else
02039         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Grid |" << _meshName.c_str() <<
02040                                      "| doesn't have a valid coordinate system : |"
02041                                      << ptrGrid->_coordinate->_coordinateSystem
02042                                      << "|" ));
02043 
02044       _ptrMesh->_description.resize(MED_COMMENT_SIZE+1,'\0');
02045       char dtunitp3[MED_LNAME_SIZE+1];
02046       std::fill(dtunitp3,dtunitp3+MED_LNAME_SIZE+1,'\0');
02047 
02048       err = med_2_3::MEDmeshCr(_medIdt,_meshName.c_str(),
02049                                _ptrMesh->getSpaceDimension(),
02050                                _ptrMesh->getMeshDimension(),
02051                                med_2_3::MED_STRUCTURED_MESH,
02052                                _ptrMesh->_description.c_str(),
02053                                dtunitp3,med_2_3::MED_SORT_DTIT,
02054                                rep,
02055                                const_cast <char *> (tmp_name.c_str()),
02056                                const_cast <char *> (tmp_unit.c_str()));
02057 
02058       if (err != MED_VALID)
02059         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Unable to create Grid"));
02060       else
02061         MESSAGE_MED(LOC<<"Grid "<<_meshName<<" created in file "<<_fileName<<" !");
02062 
02063       err = med_2_3::MEDmeshGridTypeWr(_medIdt,_meshName.c_str(),
02064                                        (med_2_3::med_grid_type)ptrGrid->getGridType());
02065       if (err != MED_VALID)
02066         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Error in MEDmeshGridTypeWr()"));
02067 
02068       meshDimension =  _ptrMesh->getMeshDimension();
02069     }
02070   else if ((spaceDimension != _ptrMesh->_spaceDimension)  &&
02071            (meshDimension != _ptrMesh->getMeshDimension()))
02072     {
02073       throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Grid |" << _meshName.c_str() <<
02074                                    "| already exists in file |" << _fileName <<
02075                                    "| with space dimension |" << spaceDimension <<
02076                                    "| and mesh dimension |" << meshDimension <<
02077                                    "| but the space dimension and the mesh dimension of "
02078                                    "the mesh we want to write are respectively |"
02079                                    << _ptrMesh->_spaceDimension <<"|" <<
02080                                    _ptrMesh->getMeshDimension() <<"|" ));
02081     }
02082 
02083   MED_EN::med_grid_type gridType = ptrGrid->getGridType();
02084 
02085   if (err != MED_VALID)
02086     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Unable to write the type of the Grid"));
02087 
02088 
02089   med_2_3::med_int ArrayLen[] = { (med_2_3::med_int) ptrGrid->_iArrayLength,
02090                                   (med_2_3::med_int) ptrGrid->_jArrayLength,
02091                                   (med_2_3::med_int) ptrGrid->_kArrayLength  };
02092 
02093   // Write node coordinates for MED_BODY_FITTED grid
02094   if (gridType == MED_EN::MED_BODY_FITTED)
02095     {
02096       // Write Coordinates and families
02097 
02098       err = med_2_3::MEDmeshNodeCoordinateWr(_medIdt,_meshName.c_str(),
02099                                              MED_NO_DT,MED_NO_IT,MED_NO_DT,
02100                                              med_2_3::MED_FULL_INTERLACE,
02101                                              ptrGrid->getNumberOfNodes(),
02102                                              ptrGrid->_coordinate->_coordinate.get(MED_EN::MED_FULL_INTERLACE));
02103 
02104       if (err != MED_VALID)
02105         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write coordinates of the grid |" << _meshName.c_str() << "| in file |" << _fileName
02106                                      << "| with dimension |"  << _ptrMesh->_spaceDimension <<"| and"
02107                                      << " with units names |"  << tmp_name
02108                                      << "| and units |"       << tmp_unit
02109                                      << " |"));
02110 
02111       med_2_3::med_int* structure = new med_2_3::med_int [meshDimension];
02112 
02113       for (int idim = 0; idim < meshDimension; ++idim)
02114         structure[idim] = ArrayLen [idim];
02115 
02116 
02117       err = med_2_3::MEDmeshGridStructWr(_medIdt,_meshName.c_str(),
02118                                          MED_NO_DT,MED_NO_IT,MED_NO_DT,
02119                                          structure);
02120 
02121       if (err != MED_VALID)
02122         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"error in writing the structure of the grid |" << _meshName.c_str()));
02123 
02124       delete [] structure;
02125     }
02126   else if ((gridType == MED_EN::MED_CARTESIAN) ||
02127            (gridType == MED_EN::MED_POLAR))
02128     {
02129       // Write Arrays of Cartesian or Polar Grid
02130 
02131       double * Array[] = { ptrGrid->_iArray,
02132                            ptrGrid->_jArray,
02133                            ptrGrid->_kArray };
02134 
02135       for (int idim = 0; idim < _ptrMesh->getMeshDimension(); ++idim)
02136         {
02137           string str_name = string (tmp_name,idim*MED_SNAME_SIZE,
02138                                     MED_SNAME_SIZE);
02139           string str_unit = string (tmp_unit,idim*MED_SNAME_SIZE,
02140                                     MED_SNAME_SIZE);
02141 
02142           err = med_2_3::MEDmeshGridIndexCoordinateWr(_medIdt,_meshName.c_str(),
02143                                                       MED_NO_DT,MED_NO_IT,MED_NO_DT,
02144                                                       idim+1,
02145                                                       ArrayLen[idim],
02146                                                       Array[idim]);
02147 
02148           if (err != MED_VALID)
02149             throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<
02150                                          "Can't write grid coordinates for " <<
02151                                          idim << "-th dimention"));
02152         }
02153   } // end Write  Cartesian or Polar Grid
02154 
02155   END_OF_MED(LOC);
02156   return MED_VALID;
02157 }
02158 
02159 //=======================================================================
02160 //function : writeCoordinates
02161 //purpose  :
02162 //=======================================================================
02163 
02164 int MED_MESH_WRONLY_DRIVER::writeCoordinates() const {
02165 
02166   const char * LOC = "int MED_MESH_WRONLY_DRIVER::writeCoordinates() const : ";
02167   BEGIN_OF_MED(LOC);
02168 
02169   MESH * ptrMesh = (MESH*) _ptrMesh;
02170 
02171   med_2_3::med_err err = MED_ERROR;
02172   med_2_3::med_axis_type rep;
02173   string tmp_name(ptrMesh->_spaceDimension*MED_SNAME_SIZE+1,' ');
02174   string tmp_unit(ptrMesh->_spaceDimension*MED_SNAME_SIZE+1,' ');
02175 
02176   // Recompose the <_spaceDimension> strings in 1 string
02177   int lengthString;
02178   string valueString;
02179   for (int i=0;i<ptrMesh->_spaceDimension;i++) {
02180     valueString = ptrMesh->_coordinate->_coordinateName[i];
02181     lengthString = (MED_SNAME_SIZE<valueString.size())?MED_SNAME_SIZE:valueString.size();
02182     tmp_name.replace(i*MED_SNAME_SIZE,i*MED_SNAME_SIZE+lengthString,valueString,0,lengthString);
02183     valueString = ptrMesh->_coordinate->_coordinateUnit[i];
02184     lengthString = (MED_SNAME_SIZE<valueString.size())?MED_SNAME_SIZE:valueString.size();
02185     tmp_unit.replace(i*MED_SNAME_SIZE,i*MED_SNAME_SIZE+lengthString,valueString,0,lengthString);
02186   }
02187   // Pourquoi le stocker sous forme de chaîne ?
02188   const string & coordinateSystem = ptrMesh->_coordinate->_coordinateSystem;
02189   if      (coordinateSystem  == "CARTESIAN")
02190     rep = med_2_3::MED_CARTESIAN;
02191   else if ( coordinateSystem == "CYLINDRICAL")
02192     rep = med_2_3::MED_CYLINDRICAL;
02193   else if ( coordinateSystem == "SPHERICAL" )
02194     rep = med_2_3::MED_SPHERICAL;
02195   else
02196     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Mesh |" << _meshName.c_str() << "| doesn't have a valid coordinate system : |"
02197                                  << ptrMesh->_coordinate->_coordinateSystem
02198                                  << "|" ));
02199   // Test if the mesh <_meshName> already exists
02200   // If it doesn't exists create it
02201   // If it already exists verify if its space and mesh dimensions are the same
02202   // as <ptrMesh->_spaceDimension>, <ptrMesh->getMeshDimension()> respectively
02203   // rem : <_meshName> is the driver meshName not <ptrMesh->_meshName>
02204 
02205   med_2_3::med_int dtpp3,itpp3;
02206   med_2_3::med_float ttpp3;
02207   err=med_2_3::MEDmeshComputationStepInfo(_medIdt,_meshName.c_str(),1,&dtpp3,&itpp3,&ttpp3);
02208   int spaceDimension=-1;
02209   int meshDimension=-1;
02210   if(!err)
02211     {
02212       med_2_3::med_mesh_type ttmp3;
02213       char commentp3[MED_COMMENT_SIZE+1];
02214       char dtunittp3[MED_LNAME_SIZE+1];
02215       med_2_3::med_sorting_type sttp3;
02216       int nstep;
02217       med_2_3::med_axis_type axtypp3;
02218       int naxis=med_2_3::MEDmeshnAxisByName(_medIdt,_meshName.c_str());
02219       if ( naxis > 0 )
02220         {
02221           char *t1pp3=new char[naxis*MED_SNAME_SIZE+1];
02222           char *t2pp3=new char[naxis*MED_SNAME_SIZE+1];
02223           med_2_3::MEDmeshInfoByName(_medIdt,_meshName.c_str(),&spaceDimension,&meshDimension,&ttmp3,commentp3,dtunittp3,&sttp3,&nstep,&axtypp3,t1pp3,t2pp3);
02224           delete [] t1pp3;
02225           delete [] t2pp3;
02226         }
02227       else
02228         {
02229           err = MED_INVALID;
02230         }
02231     }
02232   SCRUTE_MED(spaceDimension);
02233   SCRUTE_MED(meshDimension);
02234   SCRUTE_MED(ptrMesh->_spaceDimension);
02235   SCRUTE_MED(ptrMesh->getMeshDimension());
02236 
02237   if (err)
02238     {
02239       _ptrMesh->_description.resize(MED_COMMENT_SIZE+1,'\0');
02240       char dtunitp3[MED_LNAME_SIZE+1];
02241       std::fill(dtunitp3,dtunitp3+MED_LNAME_SIZE+1,'\0');
02242 
02243       err = med_2_3::MEDmeshCr(_medIdt,_meshName.c_str(),
02244                                _ptrMesh->getSpaceDimension(),
02245                                _ptrMesh->getMeshDimension(),
02246                                med_2_3::MED_UNSTRUCTURED_MESH,
02247                                _ptrMesh->_description.c_str(),
02248                                dtunitp3,
02249                                med_2_3::MED_SORT_DTIT,
02250                                rep,
02251                                const_cast <char *> (tmp_name.c_str()),
02252                                const_cast <char *> (tmp_unit.c_str()));
02253 
02254       if (err < MED_VALID)
02255         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Unable to create Mesh : |" << _meshName << "|"));
02256       else
02257         MESSAGE_MED(LOC<<"Mesh "<<_meshName<<" created in file "<<_fileName<<" !");
02258     }
02259   else if ((spaceDimension != ptrMesh->_spaceDimension)  &&
02260            (meshDimension != ptrMesh->getMeshDimension()))
02261     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Mesh |" << _meshName.c_str() <<
02262                                  "| already exists in file |" << _fileName <<
02263                                  "| with space dimension |" << spaceDimension <<
02264                                  "| and mesh dimension |" << meshDimension <<
02265                                  "| but the space dimension and the mesh dimension of the mesh we want to write are respectively |"
02266                                  << ptrMesh->_spaceDimension <<"|" <<
02267                                  ptrMesh->getMeshDimension() << "|"));
02268   
02269   err=med_2_3::MEDmeshNodeCoordinateWr(_medIdt,_meshName.c_str(),MED_NO_DT,MED_NO_IT,MED_NO_DT,med_2_3::MED_FULL_INTERLACE,ptrMesh->getNumberOfNodes(),
02270                                        const_cast <double *> ( ptrMesh->_coordinate->_coordinate.get(MED_EN::MED_FULL_INTERLACE)));
02271 
02272   if (err<0)
02273     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write coordinates of mesh |" << _meshName.c_str() << "| in file |" << _fileName
02274                                  << "| with dimension |"  << ptrMesh->_spaceDimension <<"| and"
02275                                  << " with units names |"  << tmp_name
02276                                  << "| and units |"       << tmp_unit
02277                                  << " |"));
02278 
02279 
02286 
02287 
02288       if (ptrMesh->_arePresentOptionnalNodesNumbers==1) {
02289 
02290 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
02291         const int * NodesNumbers = ptrMesh->_coordinate->getNodesNumbers();
02292         med_2_3::med_int * tmp_NodesNumbers = new med_2_3::med_int[ptrMesh->getNumberOfNodes()];
02293         int ii;
02294         for ( ii = 0; ii < ptrMesh->getNumberOfNodes(); ii++ )
02295            tmp_NodesNumbers[ii] = NodesNumbers[ii];
02296         err=med_2_3::MEDmeshEntityNumberWr(_medIdt,_meshName.c_str(),MED_NO_DT,MED_NO_IT,med_2_3::MED_NODE,MED_NONE,ptrMesh->getNumberOfNodes(),
02297                                            tmp_NodesNumbers);
02298         delete [] tmp_NodesNumbers;
02299 #else
02300         err=med_2_3::MEDmeshEntityNumberWr(_medIdt,_meshName.c_str(),MED_NO_DT,MED_NO_IT,med_2_3::MED_NODE,MED_NONE,ptrMesh->getNumberOfNodes(),
02301                                            const_cast<med_int *>(ptrMesh->_coordinate->getNodesNumbers()));
02302 #endif
02303 
02304         if (err != MED_VALID)
02305           throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write optionnal numbers of mesh |" <<
02306                                        _meshName.c_str() << "| in file |" <<
02307                                        _fileName  << " |"));
02308       }
02310 
02311   END_OF_MED(LOC);
02312 
02313   return MED_VALID;
02314 }
02315 
02316 
02317 
02318 
02319 int MED_MESH_WRONLY_DRIVER::writeConnectivities(medEntityMesh entity) const
02320 {
02321   const char * LOC="int MED_MESH_WRONLY_DRIVER::writeConnectivities() const : ";
02322   BEGIN_OF_MED(LOC);
02323 
02324   med_2_3::med_err err;
02325 
02326   MESH * ptrMesh = (MESH*) _ptrMesh;
02327 
02328   if ( ptrMesh->_connectivity == (CONNECTIVITY *) NULL )
02329     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "The connectivity is not defined in the MESH object "));
02330 
02331 
02332   if ( ptrMesh->existConnectivity(MED_NODAL,entity) )
02333     {
02334       int numberOfTypes = ptrMesh->getNumberOfTypes(entity);
02335       const medGeometryElement * types = ptrMesh->getTypes(entity);
02336       const int * index = ptrMesh->getConnectivityIndex(MED_NODAL, entity);
02337 
02338       for (int i=0; i<numberOfTypes; i++)
02339         {
02340           int numberOfElements = ptrMesh->getNumberOfElements(entity,types[i]);
02341           const int * connectivity = ptrMesh->getConnectivity(MED_NODAL, entity, types[i]);
02342           int size = ptrMesh->getConnectivityLength(MED_NODAL, entity, types[i]);
02343 
02344           switch ( types[i] )
02345             {
02346             case MED_EN::MED_POLYGON:
02347               {
02348                 int nbStdCells = ptrMesh->getGlobalNumberingIndex(entity)[i]-1;
02349                 vector< med_2_3::med_int > connectivityArray( connectivity, connectivity + size );
02350                 vector< med_2_3::med_int > tmp_Index( numberOfElements+1 );
02351                 for ( unsigned j = 0; j < tmp_Index.size(); ++ j )
02352                   tmp_Index[j] = index[ nbStdCells + j ] - index[ nbStdCells ] + 1;
02353                 err=med_2_3::MEDmeshPolygonWr(_medIdt,_meshName.c_str(),
02354                                               MED_NO_DT,MED_NO_IT,MED_NO_DT,
02355                                               med_2_3::MED_CELL,
02356                                               med_2_3::MED_NODAL,
02357                                               numberOfElements+1,
02358                                               &tmp_Index[0],
02359                                               &connectivityArray[0]);
02360 
02361                 if (err<0)
02362                   throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write polygons nodal connectivities of mesh |"
02363                                                <<  _meshName.c_str() << "| in file |" << _fileName
02364                                                << "| with dimension |"  << ptrMesh->_spaceDimension <<"| and"
02365                                                ));
02366                 break;
02367               }
02368             case MED_EN::MED_POLYHEDRA:
02369               {
02370                 vector< med_2_3::med_int > PolyhedronIndex, PolyhedronFacesIndex, PolyhedronConnectivity;
02371                 PolyhedronIndex.push_back(1);
02372                 PolyhedronFacesIndex.push_back(1);
02373                 connectivity = ptrMesh->getConnectivity(MED_NODAL, entity, MED_ALL_ELEMENTS);
02374                 int nbStdCells = ptrMesh->getGlobalNumberingIndex(entity)[i]-1;
02375                 for ( int j = nbStdCells; j < nbStdCells+numberOfElements; ++j )
02376                   {
02377                     for ( int k = index[j]; k < index[j+1]; ++k )
02378                       if ( connectivity[k-1] == -1 )
02379                         PolyhedronFacesIndex.push_back( PolyhedronConnectivity.size()+1 );
02380                       else
02381                         PolyhedronConnectivity.push_back( connectivity[k-1] );
02382                     PolyhedronIndex.push_back( PolyhedronFacesIndex.size()+1 );
02383                     PolyhedronFacesIndex.push_back( PolyhedronConnectivity.size()+1 );
02384                   }
02385                 err=med_2_3::MEDmeshPolyhedronWr(_medIdt,_meshName.c_str(),
02386                                                  MED_NO_DT,MED_NO_IT,MED_NO_DT,
02387                                                  med_2_3::MED_CELL,
02388                                                  med_2_3::MED_NODAL,
02389                                                  PolyhedronIndex.size(),
02390                                                  &PolyhedronIndex[0],
02391                                                  PolyhedronFacesIndex.size(),
02392                                                  &PolyhedronFacesIndex[0],
02393                                                  &PolyhedronConnectivity[0]);
02394                 if (err<0)
02395                   throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write polyhedron nodal connectivities of mesh |"
02396                                                << _meshName.c_str() << "| in file |" << _fileName
02397                                                << "| with dimension |"  << ptrMesh->_spaceDimension <<"| and"
02398                                                ));
02399                 break;
02400               }
02401             default:
02402 
02403               vector< med_2_3::med_int > connectivityArray( connectivity, connectivity + size );
02404               err=med_2_3::MEDmeshElementConnectivityWr(_medIdt,_meshName.c_str(),MED_NO_DT,MED_NO_IT,MED_NO_DT,med_2_3::MED_CELL,(med_2_3::med_geometry_type)types[i],
02405                                                         med_2_3::MED_NODAL,med_2_3::MED_FULL_INTERLACE,numberOfElements,&connectivityArray[0]);
02406 
02407               if (err<0) // ETENDRE LES EXPLICATIONS
02408                 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write connectivities of mesh |"
02409                                              << _meshName.c_str() << "| in file |" << _fileName
02410                                              << "| with dimension |"  << ptrMesh->_spaceDimension <<"| and"));
02411             }
02412         }
02413     }
02414 
02415 
02416   // Descending connectivity for classic geometric types
02417   if ( ptrMesh->existConnectivity(MED_DESCENDING,entity) )
02418     {
02419       int numberOfTypes                = ptrMesh->getNumberOfTypes (entity);
02420       const medGeometryElement * types = ptrMesh->getTypes         (entity);
02421 
02422       for (int i=0; i<numberOfTypes; i++)
02423         {
02424           int    numberOfElements = ptrMesh->getNumberOfElements (entity,types[i]);
02425           const int * connectivity = ptrMesh->getConnectivity(MED_DESCENDING, entity, types[i]);
02426 
02427 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
02428           int lgth = ptrMesh->getConnectivityLength(MED_DESCENDING, entity, types[i]);
02429           vector< med_2_3::med_int > tmp_Connectivity( connectivity, connectivity + lgth );
02430           err=med_2_3::MEDmeshElementConnectivityWr(_medIdt,_meshName.c_str(),
02431                                                     MED_NO_DT,MED_NO_IT,MED_NO_DT,
02432                                                     med_2_3::MED_CELL,
02433                                                     (med_2_3::med_geometry_type)types[i],
02434                                                     med_2_3::MED_DESCENDING,
02435                                                     med_2_3::MED_FULL_INTERLACE,
02436                                                     numberOfElements,
02437                                                     &tmp_Connectivity[0]);
02438 #else
02439           err=med_2_3::MEDmeshElementConnectivityWr(_medIdt,_meshName.c_str(),
02440                                                     MED_NO_DT,MED_NO_IT,MED_NO_DT,
02441                                                     med_2_3::MED_CELL,
02442                                                     (med_2_3::med_geometry_type)types[i],
02443                                                     med_2_3::MED_DESCENDING,
02444                                                     med_2_3::MED_FULL_INTERLACE,
02445                                                     numberOfElements,
02446                                                     const_cast<int *>(connectivity));
02447 #endif
02448 
02449           if (err<0) // ETENDRE LES EXPLICATIONS
02450             throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<"Can't write connectivities of mesh |"
02451                                          << _meshName.c_str() << "| in file |" << _fileName
02452                                          << "| with dimension |"  << ptrMesh->_spaceDimension <<"| and"
02453                                          ));
02454 
02455         }
02456     }
02457 
02458   END_OF_MED(LOC);
02459   return MED_VALID;
02460 }
02461 
02475 void MED_MESH_WRONLY_DRIVER::groupFamilyConverter(const vector <GROUP*>& myGroups, vector <FAMILY*>& myFamilies ) const
02476 {
02477 
02478   const char* LOC = "MED_MESH_WRONLY_DRIVER::groupFamilyConverter";
02479   BEGIN_OF_MED(LOC);
02480   if (myGroups.empty()) return;
02481 
02482 //      if (!myFamilies.empty())
02483 //      throw MEDEXCEPTION(LOCALIZED("Family vector must be empty on call "
02484 //      << "to groupFamilyConverter"));
02485 //
02486  //mapping elements to all the groups containing it
02487   std::multimap <int,int> elem2groups;
02488   for (int igroup=0; igroup< (int)myGroups.size(); igroup++)
02489   {
02490     const int*Number = myGroups[igroup]->getNumber(MED_ALL_ELEMENTS);
02491     for (int ielem = 0; ielem< myGroups[igroup]->getNumberOfElements(MED_ALL_ELEMENTS); ielem++)
02492     {
02493       elem2groups.insert(make_pair(Number[ielem], igroup));
02494     }
02495   }
02496 
02497   //creating a set of signatures for the groups intersections
02498   std::multimap<vector<int>,int> signatures;
02499 
02500   typedef multimap<int,int>::iterator MI;
02501   MI iter=elem2groups.begin();
02502 
02503   while (iter!=elem2groups.end())
02504   {
02505     vector<int> sign (1, iter -> second );
02506     int key = iter -> first;
02507     iter ++;
02508     while (iter!=elem2groups.end()&&iter-> first == key)
02509     {
02510       sign.push_back(iter -> second);
02511       iter++;
02512     }
02513     signatures.insert(make_pair(sign,key));
02514   }
02515 
02516   elem2groups.clear();
02517 
02518   //creating the families from the signatures mapping
02519   //each signature will correspond to a new family
02520   std::multimap<vector<int>,int>::const_iterator iter_signatures = signatures.begin();
02521 
02522   //retrieving the entity type (all the groups have the same)
02523   // node families are numbered above 0
02524   // cell families are numbered from  -1 to -MAX_NB_GROUPS
02525   // face falimies are numbered from -MAX_NB_GROUPS-1 to -2*MAX_NB_GROUPS
02526   // edge families are numbered from -2*MAX_NB_GROUPS to -3*MAX_NB_GROUPS
02527   // MAX_NB_GROUPS is defined in MEDMEM_define.hxx
02528 
02529   medEntityMesh entity = myGroups[0]->getEntity();
02530   MESH* mesh=(MESH*)myGroups[0]->getMesh();
02531 
02532   int ifamily;
02533   switch (entity)
02534   {
02535   case MED_NODE:
02536     ifamily=1;
02537     break;
02538   case MED_CELL:
02539     ifamily=-MAX_NB_GROUP;
02540     break;
02541   case MED_FACE:
02542     ifamily=-2*MAX_NB_GROUP;
02543     break;
02544   case MED_EDGE:
02545     ifamily=-3*MAX_NB_GROUP;
02546     break;
02547   }
02548 
02549   //browsing signatures to build all the families
02550   //each signature corresponds to a new family
02551 
02552   while (iter_signatures!= signatures.end())
02553   {
02554     const vector<int>& key= iter_signatures->first;
02555     int size = signatures.count(key);
02556 
02557     list<int> numbers;
02558 
02559     for (int i=0; i< size; i++)
02560     {
02561       numbers.push_back(iter_signatures->second);
02562       iter_signatures++;
02563     }
02564 
02565     //TODO : see if build SupportOnElementFromElementList could not be built from another container
02566 
02567     // for nodes, the family is built directly from the node list
02568     // for elements, it is built from the buildSupportOnElementsFromElementList
02569     //               which allocates a support
02570     FAMILY* myFamily;
02571     if (entity!=MED_NODE)
02572     {
02573       SUPPORT* support;
02574       support=mesh->buildSupportOnElementsFromElementList(numbers, entity);
02575       myFamily=new FAMILY(*support);
02576       support->removeReference();
02577     }
02578     else
02579     {
02580       myFamily= new FAMILY();
02581       myFamily->setMesh(mesh);
02582       myFamily->fillFromNodeList(numbers);
02583     }
02584 
02585 
02586     // the identifier and the groups are set
02587     myFamily->setIdentifier(ifamily);
02588     myFamily->setNumberOfGroups(key.size());
02589     char family_name[MED_NAME_SIZE];
02590 
02591     //if the family has one group to which only one family
02592     //is associated, the name of the family underlying the group
02593     //is given back to the family
02594     if (key.size()==1 && myGroups[key[0]]->getNumberOfFamilies()==0)
02595     {
02596       vector<FAMILY*> families;
02597       families.push_back(myFamily);
02598       myGroups[key[0]]->setFamilies(families);
02599       //it is necessary to use strncpy because group and family
02600       //have different name sizes
02601       strncpy(family_name,myGroups[key[0]]->getName().c_str(),MED_NAME_SIZE);
02602       family_name[MED_NAME_SIZE-1]='\0';
02603     }
02604     else
02605       sprintf(family_name,"family%d",ifamily);
02606 
02607     myFamily->setName( healName( family_name ));
02608 
02609     string* groupnames=new string[key.size()];
02610 
02611     for (int igroup=0; igroup<(int)key.size(); igroup++)
02612     {
02613       groupnames[igroup]=myGroups[key[igroup]]->getName();
02614     }
02615 
02616     myFamily->setGroupsNames(groupnames,true);
02617     if(myFamily->getMesh()==_ptrMesh)
02618       _ptrMesh->removeReference();
02619     myFamilies.push_back(myFamily);
02620     ifamily++;
02621   }
02622 
02623   //adding empty families corresponding to empty groups
02624   for (size_t i=0; i<myGroups.size(); i++)
02625   {
02626     if (myGroups[i]->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)==0)
02627     {
02628       FAMILY* myFamily=new FAMILY(*(myGroups[i]));
02629       char family_name[MED_NAME_SIZE];
02630       //it is necessary to use strncpy because group and family
02631       //have different name sizes
02632       strncpy(family_name,myGroups[i]->getName().c_str(),MED_NAME_SIZE);
02633       family_name[MED_NAME_SIZE-1]='\0';
02634       myFamily->setName( healName( family_name ));
02635       myFamily->setIdentifier(ifamily);
02636       ifamily++;
02637       vector<string> groupnames;
02638       groupnames.push_back(myGroups[i]->getName());
02639       myFamily->setNumberOfGroups(1);
02640       myFamily->setGroupsNames(&groupnames[0]);
02641       if(myFamily->getMesh()==_ptrMesh)
02642         _ptrMesh->removeReference();
02643       myFamilies.push_back(myFamily);
02644     }
02645   }
02646   END_OF_MED(LOC);
02647 }
02648 
02649 int MED_MESH_WRONLY_DRIVER::writeFamilyNumbers() const {
02650 
02651   const char * LOC="int MED_MESH_WRONLY_DRIVER::writeFamilyNumbers() const : ";
02652   BEGIN_OF_MED(LOC);
02653 
02654   med_2_3::med_err err;
02655 
02656   // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArrayNodeFamily DOIT ETRE ENLEVER DE LA CLASSE MESH
02657 
02658   { // Node related block
02659 
02660     // We build the array from the families list objects :
02661     int NumberOfNodes = _ptrMesh->getNumberOfNodes();
02662     med_2_3::med_int * MEDArrayNodeFamily = new med_2_3::med_int[NumberOfNodes];
02663     // family 0 by default
02664     for (int i=0; i<NumberOfNodes; i++)
02665       MEDArrayNodeFamily[i]=0;
02666     vector<FAMILY*> * myFamilies = &_ptrMesh->_familyNode;
02667     int NumberOfNodesFamilies = myFamilies->size();
02668     if (0 == NumberOfNodesFamilies) {
02669       vector<GROUP*> myGroups = _ptrMesh->getGroups(MED_NODE);
02670 
02671       groupFamilyConverter(myGroups,*myFamilies);
02672 
02673       NumberOfNodesFamilies=myFamilies->size();
02674     }
02675     for (int i=0; i<NumberOfNodesFamilies; i++) {
02676       int FamilyIdentifier = (*myFamilies)[i]->getIdentifier();
02677       int TotalNumber = (*myFamilies)[i]->getNumberOfElements(MED_ALL_ELEMENTS);
02678       const int * Number = (*myFamilies)[i]->getNumber(MED_ALL_ELEMENTS);
02679       for (int j=0; j<TotalNumber; j++)
02680         MEDArrayNodeFamily[Number[j]-1]=FamilyIdentifier;
02681     }
02682     err=med_2_3::MEDmeshEntityFamilyNumberWr(_medIdt,_meshName.c_str(),MED_NO_DT,MED_NO_IT,med_2_3::MED_NODE,MED_NONE,NumberOfNodes,MEDArrayNodeFamily);
02683 
02684 
02685     if ( err != MED_VALID)
02686       throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write node family for the |"<< NumberOfNodes
02687                                    << "| nodes in mesh |"
02688                                    << _ptrMesh->_name.c_str() << "|" ));
02689     delete[] MEDArrayNodeFamily;
02690   }
02691 
02692   { // CELLS RELATED BLOCK
02693     medEntityMesh entity=MED_EN::MED_CELL;
02694     // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArray____Family DOIT ETRE ENLEVER DE LA CLASSE MESH
02695     if ((_ptrMesh->getIsAGrid()) || // PAL18712, GRID::existConnectivity() calls GRID::fillConnectivity() but it is not needed for writing GRID
02696         (((MESH*)_ptrMesh)->existConnectivity(MED_NODAL,entity)) ||
02697         (((MESH*)_ptrMesh)->existConnectivity(MED_DESCENDING,entity)))
02698     {
02699       int numberOfTypes                 = _ptrMesh->getNumberOfTypes(entity);
02700       const medGeometryElement  * types = _ptrMesh->getTypes(entity);
02701 
02702       // We build the array from the families list objects :
02703       int NumberOfElements = _ptrMesh->getNumberOfElements(entity, MED_ALL_ELEMENTS);
02704       int * MEDArrayFamily = new int[NumberOfElements];
02705       // family 0 by default
02706       for (int i=0; i<NumberOfElements; i++)
02707         MEDArrayFamily[i]=0;
02708       vector<FAMILY*> * myFamilies = &_ptrMesh->_familyCell;
02709       int NumberOfFamilies = myFamilies->size();
02710       if (0 == NumberOfFamilies) {
02711         vector<GROUP*> myGroups = _ptrMesh->getGroups(entity);
02712         groupFamilyConverter(myGroups,*myFamilies);
02713         NumberOfFamilies=myFamilies->size();
02714       }
02715       for (int i=0; i<NumberOfFamilies; i++) {
02716         int FamilyIdentifier = (*myFamilies)[i]->getIdentifier();
02717         int TotalNumber = (*myFamilies)[i]->getNumberOfElements(MED_ALL_ELEMENTS);
02718         const int * Number = (*myFamilies)[i]->getNumber(MED_ALL_ELEMENTS);
02719         for (int ii=0; ii<TotalNumber; ii++)
02720           MEDArrayFamily[Number[ii]-1]=FamilyIdentifier;
02721       }
02722 
02723       int offset=0;
02724 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
02725       vector < med_2_3::med_int > temp( MEDArrayFamily, MEDArrayFamily + NumberOfElements );
02726 #endif
02727       for (int i=0; i<numberOfTypes; i++)
02728       {
02729         int typeNumberOfElements=_ptrMesh->getNumberOfElements(entity,types[i]);
02730 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
02731         err=med_2_3::MEDmeshEntityFamilyNumberWr(_medIdt,_meshName.c_str(),MED_NO_DT,MED_NO_IT,med_2_3::MED_CELL,(med_2_3::med_geometry_type) types[i],typeNumberOfElements,&temp[0]+offset);
02732 #else
02733         err=med_2_3::MEDmeshEntityFamilyNumberWr(_medIdt,_meshName.c_str(),MED_NO_DT,MED_NO_IT,med_2_3::MED_CELL,(med_2_3::med_geometry_type) types[i],typeNumberOfElements,MEDArrayFamily+offset);
02734 #endif
02735         MESSAGE_MED("OK "<<i);
02736         if ( err != MED_VALID)
02737           throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't write family for the |"<< typeNumberOfElements
02738                                        << "| cells of geometric type |" << geoNames[types[i]] <<"|in mesh |"
02739                                        << _ptrMesh->_name.c_str() << "|" ));
02740         offset+=typeNumberOfElements;
02741       }
02742       delete[] MEDArrayFamily;
02743     }
02744   }
02745 
02746   if (!_ptrMesh->getIsAGrid() || _ptrMesh->getMeshDimension() == 3 ) // for grid - only in 3D mesh
02747 
02748   { // FACE RELATED BLOCK
02749     medEntityMesh entity=MED_EN::MED_FACE;
02750     // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArray____Family DOIT ETRE ENLEVER DE LA CLASSE MESH
02751     if ((_ptrMesh->getIsAGrid()) || // PAL18712, GRID::existConnectivity() calls GRID::fillConnectivity() but it is not needed for writing GRID
02752         (((MESH*)_ptrMesh)->existConnectivity(MED_NODAL,entity)) ||
02753         (((MESH*)_ptrMesh)->existConnectivity(MED_DESCENDING,entity)))
02754     {
02755       int numberOfTypes                 = _ptrMesh->getNumberOfTypes(entity);
02756       const medGeometryElement  * types = _ptrMesh->getTypes(entity);
02757       SCRUTE_MED(numberOfTypes);
02758 
02759       int numberOfElements = _ptrMesh->getNumberOfElements(entity, MED_ALL_ELEMENTS);
02760       int * familyArray = new int[numberOfElements];
02761       for (int i=0;i<numberOfElements;i++)
02762         familyArray[i]=0;
02763 
02764       int numberOfFamilies = _ptrMesh->getNumberOfFamilies(entity);
02765       vector<FAMILY*> * myFamilies = &_ptrMesh->_familyFace;
02766       if (0 == numberOfFamilies) {
02767         vector<GROUP*> myGroups = _ptrMesh->getGroups(entity);
02768 
02769         groupFamilyConverter(myGroups,*myFamilies);
02770 
02771         numberOfFamilies=myFamilies->size();
02772       }
02773       for (int i=0;i<numberOfFamilies;i++) {
02774         int familyNumber = (*myFamilies)[i]->getIdentifier();
02775         int numberOfFamilyElements = (*myFamilies)[i]->getNumberOfElements(MED_ALL_ELEMENTS);
02776         const int * myFamilyElements = (*myFamilies)[i]->getNumber(MED_ALL_ELEMENTS);
02777         for (int ii=0;ii<numberOfFamilyElements;ii++)
02778           familyArray[myFamilyElements[ii]-1]=familyNumber;
02779       }
02780 
02781       for (int i=0;i<numberOfElements;i++)
02782         SCRUTE_MED(familyArray[i]);
02783 
02784 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
02785       vector< med_2_3::med_int > temp( familyArray, familyArray + numberOfElements);
02786 #endif
02787       int offset=0;
02788       for (int i=0; i<numberOfTypes; i++)
02789       {
02790         int typeNumberOfElements = _ptrMesh->getNumberOfElements(entity,types[i]);
02791 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
02792         err=med_2_3::MEDmeshEntityFamilyNumberWr(_medIdt,_meshName.c_str(),MED_NO_DT,MED_NO_IT,med_2_3::MED_CELL,(med_2_3::med_geometry_type) types[i],typeNumberOfElements,&temp[0]+offset);
02793 #else
02794         err=med_2_3::MEDmeshEntityFamilyNumberWr(_medIdt,_meshName.c_str(),MED_NO_DT,MED_NO_IT,med_2_3::MED_CELL,(med_2_3::med_geometry_type) types[i],typeNumberOfElements,familyArray+offset);
02795 #endif
02796         if ( err != MED_VALID)
02797           {
02798             if ( _ptrMesh->getIsAGrid() )
02799               {
02800                 if ( numberOfFamilies > 0 )
02801                   throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<
02802                                                "Groups and families of FACEs in the structured "
02803                                                "mesh are not supported by med file" ));
02804               }
02805             else
02806               {
02807                 throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<
02808                                              "Can't write family for the |"<< typeNumberOfElements
02809                                              << "| faces of geometric type |" << geoNames[types[i]]
02810                                              << "| in mesh |" << _meshName << "|" ));
02811               }
02812           }
02813         offset+=typeNumberOfElements;
02814       }
02815       delete[] familyArray;
02816     }
02817   }
02818 
02819   if (!_ptrMesh->getIsAGrid() || _ptrMesh->getMeshDimension() > 1 ) // for grid - only in 3D and 2D mesh
02820 
02821   { // EDGE RELATED BLOCK
02822     medEntityMesh entity=MED_EN::MED_EDGE;
02823     // SOLUTION TEMPORAIRE CAR _ptrMesh->_MEDArray____Family DOIT ETRE ENLEVER DE LA CLASSE MESH
02824     if  ((_ptrMesh->getIsAGrid()) || // PAL18712, GRID::existConnectivity() calls GRID::fillConnectivity() but it is not needed for writing GRID
02825          (((MESH*)_ptrMesh)->existConnectivity(MED_NODAL,entity) ) ||
02826          (((MESH*)_ptrMesh)->existConnectivity(MED_DESCENDING,entity) ) ) {
02827 
02828       int numberOfTypes           = _ptrMesh->getNumberOfTypes (entity);
02829       const medGeometryElement  * types = _ptrMesh->getTypes         (entity);
02830 
02831       int numberOfElements = _ptrMesh->getNumberOfElements(entity, MED_ALL_ELEMENTS);
02832       int * familyArray = new int[numberOfElements];
02833       for (int i=0;i<numberOfElements;i++)
02834         familyArray[i]=0;
02835 
02836       int numberOfFamilies = _ptrMesh->getNumberOfFamilies(entity);
02837       vector<FAMILY*> * myFamilies = &_ptrMesh->_familyEdge;
02838       if (0 == numberOfFamilies) {
02839         vector<GROUP*> myGroups = _ptrMesh->getGroups(entity);
02840 
02841         groupFamilyConverter(myGroups,*myFamilies);
02842 
02843         numberOfFamilies=myFamilies->size();
02844 
02845       }
02846 
02847       for (int i=0;i<numberOfFamilies;i++) {
02848         int familyNumber = (*myFamilies)[i]->getIdentifier();
02849         int numberOfFamilyElements = (*myFamilies)[i]->getNumberOfElements(MED_ALL_ELEMENTS);
02850         const int * myFamilyElements = (*myFamilies)[i]->getNumber(MED_ALL_ELEMENTS);
02851         for (int ii=0;ii<numberOfFamilyElements;ii++)
02852           familyArray[myFamilyElements[ii]-1]=familyNumber;
02853       }
02854 
02855 
02856       for (int i=0;i<numberOfElements;i++)
02857         SCRUTE_MED(familyArray[i]);
02858 
02859 
02860       int typeCount = 0;
02861 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
02862       vector< med_2_3::med_int > temp (familyArray, familyArray+numberOfElements );
02863 #endif
02864 
02865       for (int i=0; i<numberOfTypes; i++)
02866         {
02867           int typeNumberOfElements = _ptrMesh->getNumberOfElements(entity, types[i]);
02868 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
02869           err=med_2_3::MEDmeshEntityFamilyNumberWr(_medIdt,_meshName.c_str(),MED_NO_DT,MED_NO_IT,med_2_3::MED_CELL,(med_2_3::med_geometry_type) types[i],typeNumberOfElements,&temp[0]+typeCount);
02870 #else
02871           err=med_2_3::MEDmeshEntityFamilyNumberWr(_medIdt,_meshName.c_str(),MED_NO_DT,MED_NO_IT,med_2_3::MED_CELL,(med_2_3::med_geometry_type) types[i],typeNumberOfElements,familyArray+typeCount);
02872 #endif
02873           if ( err != MED_VALID)
02874             {
02875               if ( _ptrMesh->getIsAGrid() )
02876                 {
02877                   if ( numberOfFamilies > 0 )
02878                     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<
02879                                                  "Groups and families of EDGEs in the structured "
02880                                                  " mesh are not supported by med file" ));
02881                 }
02882               else
02883                 {
02884                   throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<  "Can't write family for the |"
02885                                                << _ptrMesh->getNumberOfElements(entity, types[i])
02886                                                << "| edges of geometric type |"
02887                                                << geoNames[types[i]] <<"|in mesh |"
02888                                                << _ptrMesh->_name.c_str() << "|" ));
02889                 }
02890             }
02891           typeCount += typeNumberOfElements;
02892         }
02893       delete[] familyArray;
02894     }
02895   }
02896 
02897   END_OF_MED(LOC);
02898   return MED_VALID;
02899 }
02900 
02901 int MED_MESH_WRONLY_DRIVER::writeFamilies(vector<FAMILY*> & families ) const
02902 {
02903 
02904   const char * LOC="int MED_MESH_WRONLY_DRIVER::writeFamilies(vector<FAMILY*> families) const : ";
02905   BEGIN_OF_MED(LOC);
02906 
02907   med_2_3::med_err err;
02908 
02909   MESSAGE_MED(LOC<<" families.size() :"<<families.size());
02910 
02911   for (unsigned int i=0; i< families.size(); i++) {
02912 
02913     int      numberOfAttributes = families[i]->getNumberOfAttributes ();
02914     string   attributesDescriptions (numberOfAttributes*MED_COMMENT_SIZE,'\0');
02915 
02916     // Recompose the attributes descriptions arg for MED
02917     for (int j=0; j < numberOfAttributes; j++)
02918     {
02919       string attributeDescription = families[i]->getAttributeDescription(j+1);
02920 
02921       if ( attributeDescription.size() > MED_COMMENT_SIZE )
02922         throw MEDEXCEPTION( LOCALIZED(STRING(LOC) << "The size of the attribute description n° |"
02923                                       << j+1 << "| of the family |" << families[i]->getName()
02924                                       << "| with identifier |" << families[i]->getIdentifier()
02925                                       << "| is |" << attributeDescription.size()
02926                                       <<"| and is more than |" <<  MED_COMMENT_SIZE << "|"));
02927 
02928       int length = min(MED_COMMENT_SIZE,(int)attributeDescription.size());
02929       attributesDescriptions.replace(j*MED_COMMENT_SIZE,length, attributeDescription,0,length);
02930     }
02931 
02932 
02933     int      numberOfGroups  = families[i]->getNumberOfGroups();
02934     string   groupsNames(numberOfGroups*MED_LNAME_SIZE,'\0');
02935 
02936     // Recompose the groups names arg for MED
02937     for (int j=0; j < numberOfGroups; j++)
02938     {
02939       string groupName = families[i]->getGroupName(j+1);
02940 
02941       if ( groupName.size() > MED_LNAME_SIZE )
02942         throw MEDEXCEPTION( LOCALIZED(STRING(LOC) << "The size of the group name  n° |"
02943                                       << j+1 << "| of the family |" << families[i]->getName()
02944                                       << "| with identifier |" << families[i]->getIdentifier()
02945                                       << "| is |" << groupName.size()
02946                                       <<"| and is more than |" << MED_LNAME_SIZE  << "|"));
02947 
02948       int length = min(MED_LNAME_SIZE,(int)groupName.size());
02949       groupsNames.replace(j*MED_LNAME_SIZE,length, groupName,0,length);
02950     }
02951 
02952     // test if the family already exists (HDF trick waiting a MED evolution to be replaced)
02953 
02954     string dataGroupFam;
02955     if (families[i]->getEntity() == MED_NODE)
02956       dataGroupFam = "/ENS_MAA/"+_meshName+"/FAS/NOEUD/"+families[i]->getName()+"/";
02957     else
02958       dataGroupFam = "/ENS_MAA/"+_meshName+"/FAS/ELEME/"+families[i]->getName()+"/";
02959 
02960     SCRUTE_MED("|"<<dataGroupFam<<"|");
02961     err = med_2_3::_MEDdatagroupOuvrir(_medIdt,const_cast <char *> (dataGroupFam.c_str()) );
02962     if ( err < MED_VALID ) {
02963       SCRUTE_MED(err);
02964       if ( families[i]->getName().size() > MED_NAME_SIZE )
02965         throw MEDEXCEPTION
02966           ( LOCALIZED(STRING(LOC) << "The size of the name of the family |" << i+1
02967                       << "| |" << families[i]->getName()
02968                       << "| with identifier |" << families[i]->getIdentifier()  << "| is |"
02969                       <<  families[i]->getName().size()  <<"| and is more than |"
02970                       << MED_NAME_SIZE << "|"));
02971 
02972       MESSAGE_MED(LOC<<"families[i]->getName().c_str() : "<<families[i]->getName().c_str());
02973       MESSAGE_MED(LOC<<"_meshName.c_str() : "<<_meshName.c_str());
02974       MESSAGE_MED(LOC<<"families[i]->getIdentifier() : "<<families[i]->getIdentifier());
02975       MESSAGE_MED(LOC<<"numberOfAttributes : "<<numberOfAttributes);
02976 
02977       MESSAGE_MED(LOC<<"attributesDescriptions.c_str() : "<<attributesDescriptions.c_str());
02978       MESSAGE_MED(LOC<<"numberOfGroups : "<<numberOfGroups);
02979       MESSAGE_MED(LOC<<"groupsNames.c_str() : "<<groupsNames.c_str());
02980 #if defined(IRIX64) || defined(OSF1) || defined(VPP5000) || defined(PCLINUX64)
02981       int lgth=families[i]->getNumberOfAttributes();
02982       med_2_3::med_int *  AttributesIdentifier2 = new med_2_3::med_int[lgth];
02983       med_2_3::med_int *  AttributesValues2     = new med_2_3::med_int[lgth];
02984       for(med_2_3::med_int i2=0;i2<lgth;i2++)
02985         {
02986           AttributesIdentifier2[i2]=(med_2_3::med_int)(families[i]->getAttributesIdentifiers()[i2]);
02987           AttributesValues2[i2]=(med_2_3::med_int)(families[i]->getAttributesValues()[i2]);
02988         }
02989       err = med_2_3::MEDfamilyCr(_medIdt,_meshName.c_str(),healName(families[i]->getName()).c_str(),
02990                                  families[i]->getIdentifier(),numberOfGroups,groupsNames.c_str());
02991       /*err = med_2_3::MEDfamCr( _medIdt,
02992                               const_cast <char *> ( _meshName.c_str() ),
02993                               const_cast <char *> ( healName(families[i]->getName()).c_str() ),
02994                               families[i]->getIdentifier(),
02995                               AttributesIdentifier2,
02996                               AttributesValues2,
02997                               const_cast <char *> (attributesDescriptions.c_str()),
02998                               numberOfAttributes,
02999                               const_cast <char *> (groupsNames.c_str()),
03000                               numberOfGroups);*/
03001       delete [] AttributesIdentifier2;
03002       delete [] AttributesValues2;
03003 #else
03004       err = med_2_3::MEDfamilyCr(_medIdt,_meshName.c_str(),healName(families[i]->getName()).c_str(),
03005                                  families[i]->getIdentifier(),numberOfGroups,groupsNames.c_str());
03006       /*const_cast <char *> ( healName(families[i]->getName()).c_str() ),
03007         families[i]->getIdentifier(),
03008         (med_2_3::med_int*)families[i]->getAttributesIdentifiers(),
03009         (med_2_3::med_int*)families[i]->getAttributesValues(),
03010         const_cast <char *> (attributesDescriptions.c_str()),
03011         numberOfAttributes,
03012         const_cast <char *> (groupsNames.c_str()),
03013         numberOfGroups); -------- attributes for MED3 ...*/
03014 #endif
03015       SCRUTE_MED(err);
03016       if (err != MED_VALID)
03017         throw MEDEXCEPTION(LOCALIZED(STRING(LOC) << "Can't create family |" << families[i]->getName()
03018                                      << "| with identifier |" << families[i]->getIdentifier()
03019                                      << "| groups names |" << groupsNames
03020                                      << "| and  attributes descriptions |" << attributesDescriptions << "|"));
03021     }
03022     else
03023       med_2_3::_MEDdatagroupFermer(_medIdt);
03024 
03025   }
03026 
03027   END_OF_MED(LOC);
03028 
03029   return MED_VALID;
03030 }
03031 
03032 
03033 
03034 
03035 /*--------------------- RDWR PART -------------------------------*/
03036 
03037 MED_MESH_RDWR_DRIVER::MED_MESH_RDWR_DRIVER()
03038 {
03039   this->GENDRIVER::_accessMode = MED_EN::RDWR;
03040 }
03041 
03042 MED_MESH_RDWR_DRIVER::MED_MESH_RDWR_DRIVER(const string & fileName,
03043                                            GMESH *        ptrMesh):
03044   MED_MESH_DRIVER(fileName,ptrMesh,RDWR),
03045   MED_MESH_RDONLY_DRIVER(fileName,ptrMesh),
03046   MED_MESH_WRONLY_DRIVER(fileName,ptrMesh)
03047 {
03048   MESSAGE_MED("MED_MESH_RDWR_DRIVER::MED_MESH_RDWR_DRIVER(const string & fileName, MESH * ptrMesh) has been created");
03049 }
03050 
03051 MED_MESH_RDWR_DRIVER::MED_MESH_RDWR_DRIVER(const MED_MESH_RDWR_DRIVER & driver):
03052   MED_MESH_DRIVER(driver),
03053   MED_MESH_RDONLY_DRIVER(driver),
03054   MED_MESH_WRONLY_DRIVER(driver)
03055 {
03056 }
03057 
03058 MED_MESH_RDWR_DRIVER::~MED_MESH_RDWR_DRIVER()
03059 {
03060   //MESSAGE_MED("MED_MESH_RDWR_DRIVER::MED_MESH_RDWR_DRIVER(const string & fileName, MESH * ptrMesh) has been destroyed");
03061 }
03062 
03063 GENDRIVER * MED_MESH_RDWR_DRIVER::copy(void) const
03064 {
03065   return new MED_MESH_RDWR_DRIVER(*this);
03066 }
03067 
03068 void MED_MESH_RDWR_DRIVER::write(void) const
03069 {
03070   MED_MESH_WRONLY_DRIVER::write();
03071 }
03072 void MED_MESH_RDWR_DRIVER::read (void)
03073 {
03074   MED_MESH_RDONLY_DRIVER::read();
03075 }