Back to index

salome-med  6.5.0
MEDLoader.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "MEDLoader.hxx"
00021 #include "MEDLoaderBase.hxx"
00022 #include "MEDFileUtilities.hxx"
00023 #include "CellModel.hxx"
00024 #include "MEDCouplingUMesh.hxx"
00025 #include "MEDCouplingMemArray.hxx"
00026 #include "MEDCouplingFieldDouble.hxx"
00027 #include "MEDCouplingGaussLocalization.hxx"
00028 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
00029 
00030 #include "InterpKernelAutoPtr.hxx"
00031 
00032 #include "med.h"
00033 
00034 #include <string>
00035 #include <limits>
00036 #include <cstring>
00037 #include <sstream>
00038 #include <fstream>
00039 #include <numeric>
00040 #include <iterator>
00041 #include <algorithm>
00042 
00043 med_geometry_type typmai[MED_N_CELL_FIXED_GEO] = { MED_POINT1,
00044                                                    MED_SEG2,
00045                                                    MED_SEG3,
00046                                                    MED_SEG4,
00047                                                    MED_TRIA3,
00048                                                    MED_QUAD4,
00049                                                    MED_TRIA6,
00050                                                    MED_TRIA7,
00051                                                    MED_QUAD8,
00052                                                    MED_QUAD9,
00053                                                    MED_TETRA4,
00054                                                    MED_PYRA5,
00055                                                    MED_PENTA6,
00056                                                    MED_HEXA8,
00057                                                    MED_OCTA12,
00058                                                    MED_TETRA10,
00059                                                    MED_PYRA13,
00060                                                    MED_PENTA15,
00061                                                    MED_HEXA20,
00062                                                    MED_HEXA27,
00063                                                    MED_POLYGON,
00064                                                    MED_POLYHEDRON };
00065 
00066 med_geometry_type typmainoeud[1] = { MED_NONE };
00067 
00068 INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO] = { INTERP_KERNEL::NORM_POINT1,
00069                                                                     INTERP_KERNEL::NORM_SEG2,
00070                                                                     INTERP_KERNEL::NORM_SEG3,
00071                                                                     INTERP_KERNEL::NORM_ERROR,//SEG4
00072                                                                     INTERP_KERNEL::NORM_TRI3,
00073                                                                     INTERP_KERNEL::NORM_QUAD4,
00074                                                                     INTERP_KERNEL::NORM_TRI6,
00075                                                                     INTERP_KERNEL::NORM_ERROR,//TRI7
00076                                                                     INTERP_KERNEL::NORM_QUAD8,
00077                                                                     INTERP_KERNEL::NORM_ERROR,//QUAD9
00078                                                                     INTERP_KERNEL::NORM_TETRA4,
00079                                                                     INTERP_KERNEL::NORM_PYRA5,
00080                                                                     INTERP_KERNEL::NORM_PENTA6,
00081                                                                     INTERP_KERNEL::NORM_HEXA8,
00082                                                                     INTERP_KERNEL::NORM_HEXGP12,
00083                                                                     INTERP_KERNEL::NORM_TETRA10,
00084                                                                     INTERP_KERNEL::NORM_PYRA13,
00085                                                                     INTERP_KERNEL::NORM_PENTA15,
00086                                                                     INTERP_KERNEL::NORM_HEXA20,
00087                                                                     INTERP_KERNEL::NORM_ERROR,//HEXA27
00088                                                                     INTERP_KERNEL::NORM_POLYGON,
00089                                                                     INTERP_KERNEL::NORM_POLYHED };
00090 
00091 med_geometry_type typmai3[34] = { MED_POINT1,//0
00092                                   MED_SEG2,//1
00093                                   MED_SEG3,//2
00094                                   MED_TRIA3,//3
00095                                   MED_QUAD4,//4
00096                                   MED_POLYGON,//5
00097                                   MED_TRIA6,//6
00098                                   MED_NONE,//7
00099                                   MED_QUAD8,//8
00100                                   MED_NONE,//9
00101                                   MED_NONE,//10
00102                                   MED_NONE,//11
00103                                   MED_NONE,//12
00104                                   MED_NONE,//13
00105                                   MED_TETRA4,//14
00106                                   MED_PYRA5,//15
00107                                   MED_PENTA6,//16
00108                                   MED_NONE,//17
00109                                   MED_HEXA8,//18
00110                                   MED_NONE,//19
00111                                   MED_TETRA10,//20
00112                                   MED_NONE,//21
00113                                   MED_OCTA12,//22
00114                                   MED_PYRA13,//23
00115                                   MED_NONE,//24
00116                                   MED_PENTA15,//25
00117                                   MED_NONE,//26
00118                                   MED_NONE,//27
00119                                   MED_NONE,//28
00120                                   MED_NONE,//29
00121                                   MED_HEXA20,//30
00122                                   MED_POLYHEDRON,//31
00123                                   MED_NONE,//32
00124                                   MED_NONE//33
00125 };
00126 
00127 double MEDLoader::_EPS_FOR_NODE_COMP=1.e-12;
00128 
00129 int MEDLoader::_COMP_FOR_CELL=0;
00130 
00131 int MEDLoader::_TOO_LONG_STR=0;
00132 
00133 using namespace ParaMEDMEM;
00134 
00136 
00137 namespace MEDLoaderNS
00138 {
00139   class FieldPerTypeCopier
00140   {
00141   public:
00142     FieldPerTypeCopier(double *ptr):_ptr(ptr) { }
00143     void operator()(const MEDLoader::MEDFieldDoublePerCellType& elt) { _ptr=std::copy(elt.getArray(),elt.getArray()+elt.getNbOfValues(),_ptr); }
00144   private:
00145     double *_ptr;
00146   };
00147  
00148   class ConnReaderML
00149   {
00150   public:
00151     ConnReaderML(const int *c, int val):_conn(c),_val(val) { }
00152     bool operator() (const int& pos) { return _conn[pos]!=_val; }
00153   private:
00154     const int *_conn;
00155     int _val;
00156   };
00157   
00158   std::vector<std::string> getMeshNamesFid(med_idt fid);
00159   void readFieldDoubleDataInMedFile(const char *fileName, const char *meshName, const char *fieldName,
00160                                     int iteration, int order, ParaMEDMEM::TypeOfField typeOfOutField,
00161                                     std::list<MEDLoader::MEDFieldDoublePerCellType>& field,
00162                                     double& time, std::vector<std::string>& infos);
00163   std::vector<int> getIdsFromFamilies(const char *fileName, const char *meshName, const std::vector<std::string>& fams);
00164   std::vector<int> getIdsFromGroups(const char *fileName, const char *meshName, const std::vector<std::string>& grps);
00165   med_int getIdFromMeshName(med_idt fid, const char *meshName, std::string& trueMeshName) throw(INTERP_KERNEL::Exception);
00166   void dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfElem, med_entity_type& whichEntity);
00167   int readUMeshDimFromFile(const char *fileName, const char *meshName, std::vector<int>& possibilities);
00168   void readUMeshDataInMedFile(med_idt fid, med_int meshId, DataArrayDouble *&coords, std::list<MEDLoader::MEDConnOfOneElemType>& conn, std::string& desc);
00169   int buildMEDSubConnectivityOfOneType(const std::vector<const DataArrayInt *>& conn, const std::vector<const DataArrayInt *>& connIndex, const std::vector<const DataArrayInt *>& families, INTERP_KERNEL::NormalizedCellType type,
00170                                        std::vector<int>& conn4MEDFile, std::vector<int>& connIndex4MEDFile, std::vector<int>& connIndexRk24MEDFile,
00171                                        std::vector<int>& fam4MEDFile, std::vector<int>& renumber);
00172   MEDCouplingUMesh *readUMeshFromFileLev1(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector<int>& ids,
00173                                           const std::vector<INTERP_KERNEL::NormalizedCellType>& typesToKeep, unsigned& meshDimExtract, int *&cellRenum) throw(INTERP_KERNEL::Exception);
00174   void tradMEDFileCoreFrmt2MEDCouplingUMesh(const std::list<MEDLoader::MEDConnOfOneElemType>& medConnFrmt,
00175                                             const std::vector<int>& familiesToKeep,
00176                                             DataArrayInt* &conn,
00177                                             DataArrayInt* &connIndex,
00178                                             int *&cellRenum);
00179   ParaMEDMEM::DataArrayDouble *buildArrayFromRawData(const std::list<MEDLoader::MEDFieldDoublePerCellType>& fieldPerType,
00180                                                      const std::vector<std::string>& infos);
00181   int buildMEDSubConnectivityOfOneTypesPolyg(const std::vector<const DataArrayInt *>& conn, const std::vector<const DataArrayInt *>& connIndex, const std::vector<const DataArrayInt *>& families,
00182                                              std::vector<int>& conn4MEDFile, std::vector<int>& connIndex4MEDFile, std::vector<int>& fam4MEDFile, std::vector<int>& renumber);
00183   int buildMEDSubConnectivityOfOneTypesPolyh(const std::vector<const DataArrayInt *>&conn, const std::vector<const DataArrayInt *>& connIndex, const std::vector<const DataArrayInt *>& families,
00184                                              std::vector<int>& conn4MEDFile, std::vector<int>& connIndex4MEDFile, std::vector<int>& connIndexRk24MEDFile,
00185                                              std::vector<int>& fam4MEDFile, std::vector<int>& renumber);
00186   int buildMEDSubConnectivityOfOneTypeStaticTypes(const std::vector<const DataArrayInt *>& conn, const std::vector<const DataArrayInt *>& connIndex, const std::vector<const DataArrayInt *>& families,
00187                                                   INTERP_KERNEL::NormalizedCellType type, std::vector<int>& conn4MEDFile, std::vector<int>& fam4MEDFile, std::vector<int>& renumber);
00188   ParaMEDMEM::MEDCouplingFieldDouble *readFieldDoubleLev1(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order,
00189                                                           ParaMEDMEM::TypeOfField typeOfOutField) throw(INTERP_KERNEL::Exception);
00190   ParaMEDMEM::MEDCouplingFieldDouble *readFieldDoubleLev2(const char *fileName, ParaMEDMEM::TypeOfField typeOfOutField, unsigned meshDim, const int *renumCell, const ParaMEDMEM::MEDCouplingUMesh *mesh,
00191                                                           const std::vector<std::string>& infos, const char *fieldName, int iteration, int order, double time,
00192                                                           std::list<MEDLoader::MEDFieldDoublePerCellType>& fieldPerCellType) throw(INTERP_KERNEL::Exception);
00193   med_idt appendFieldSimpleAtt(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, med_int& numdt, med_int& numo, med_float& dt);
00194   void appendFieldDirectly(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f);
00195   void appendNodeProfileField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *thisMeshNodeIds);
00196   void appendCellProfileField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *thisMeshCellIds);
00197   void appendNodeElementProfileField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *thisMeshCellIds);
00198   void prepareCellFieldDoubleForWriting(const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *cellIds, std::list<MEDLoader::MEDFieldDoublePerCellType>& split);
00199   void fillGaussDataOnField(const char *fileName, const std::list<MEDLoader::MEDFieldDoublePerCellType>& data, MEDCouplingFieldDouble *f);
00200   void writeUMeshesDirectly(const char *fileName, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& mesh, const std::vector<const DataArrayInt *>& families, bool forceFromScratch, bool &isRenumbering);
00201   void writeUMeshesPartitionDirectly(const char *fileName, const char *meshName, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool forceFromScratch);
00202   void writeFieldAndMeshDirectly(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool forceFromScratch);
00203   void writeFieldTryingToFitExistingMesh(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f);
00204 }
00205 
00207 
00211 void MEDLoader::setEpsilonForNodeComp(double val) throw(INTERP_KERNEL::Exception)
00212 {
00213   _EPS_FOR_NODE_COMP=val;
00214 }
00215 
00219 void MEDLoader::setCompPolicyForCell(int val) throw(INTERP_KERNEL::Exception)
00220 {
00221   _COMP_FOR_CELL=val;
00222 }
00223 
00228 void MEDLoader::setTooLongStrPolicy(int val) throw(INTERP_KERNEL::Exception)
00229 {
00230   _TOO_LONG_STR=val;
00231 }
00232 
00238 MEDLoader::MEDConnOfOneElemType::MEDConnOfOneElemType(INTERP_KERNEL::NormalizedCellType type, int *conn, int *index, int *fam, int lgth, int connLgth):_lgth(lgth),_fam(fam),
00239                                                                                                                                                        _conn(conn),_index(index),
00240                                                                                                                                                        _global(0),_conn_lgth(connLgth),
00241                                                                                                                                                        _type(type)
00242 {
00243 }
00244 
00245 void MEDLoader::MEDConnOfOneElemType::setGlobal(int *global)
00246 {
00247   if(_global!=global)
00248     {
00249       if(_global)
00250         delete [] _global;
00251       _global=global;
00252     }
00253 }
00254 
00255 void MEDLoader::MEDConnOfOneElemType::releaseArray()
00256 {
00257   delete [] _fam;
00258   delete [] _conn;
00259   delete [] _index;
00260   delete [] _global;
00261 }
00262 
00263 MEDLoader::MEDFieldDoublePerCellType::MEDFieldDoublePerCellType(INTERP_KERNEL::NormalizedCellType type, double *values, int ncomp, int ntuple,
00264                                                                 const int *cellIdPerType, const char *locName):_ntuple(ntuple),_ncomp(ncomp),_values(values),_type(type)
00265 {
00266   if(cellIdPerType)
00267     _cell_id_per_type.insert(_cell_id_per_type.end(),cellIdPerType,cellIdPerType+ntuple);
00268   if(locName)
00269     _loc_name=locName;
00270 }
00271 
00272 void MEDLoader::MEDFieldDoublePerCellType::releaseArray()
00273 {
00274   delete [] _values;
00275 }
00276 
00278 
00279 std::vector<std::string> MEDLoaderNS::getMeshNamesFid(med_idt fid)
00280 {
00281   med_mesh_type type_maillage;
00282   char maillage_description[MED_COMMENT_SIZE+1];
00283   char dtunit[MED_COMMENT_SIZE+1];
00284   med_int space_dim;
00285   med_int mesh_dim;
00286   char nommaa[MED_NAME_SIZE+1];
00287   med_axis_type axistype;
00288   med_sorting_type stype;
00289   med_int n=MEDnMesh(fid);
00290   std::vector<std::string> ret(n);
00291   for(int i=0;i<n;i++)
00292     {
00293       int naxis=MEDmeshnAxis(fid,i+1);
00294       INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
00295       INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
00296       int nstep;
00297       MEDmeshInfo(fid,i+1,nommaa,&space_dim,&mesh_dim,&type_maillage,maillage_description,dtunit,&stype,&nstep,&axistype,axisname,axisunit);
00298       std::string cur=MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa));
00299       ret[i]=cur;
00300     }
00301   return ret;
00302 }
00303 
00304 void MEDLoaderNS::fillGaussDataOnField(const char *fileName, const std::list<MEDLoader::MEDFieldDoublePerCellType>& data, MEDCouplingFieldDouble *f)
00305 {
00306   med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
00307   char locName[MED_NAME_SIZE+1];
00308   int nloc=MEDnLocalization(fid);
00309   med_geometry_type typeGeo;
00310   for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=data.begin();iter!=data.end();iter++)
00311     {
00312       const std::string& loc=(*iter).getLocName();
00313       int idLoc=1;
00314       int nbOfGaussPt=-1;
00315       med_int spaceDim;
00316       for(;idLoc<=nloc;idLoc++)
00317         {
00318           char geointerpname[MED_NAME_SIZE+1]="";
00319           char ipointstructmeshname[MED_NAME_SIZE+1]="";
00320           med_int nsectionmeshcell;
00321           med_geometry_type sectiongeotype;
00322           MEDlocalizationInfo(fid,idLoc,locName,&typeGeo,&spaceDim,&nbOfGaussPt, geointerpname, ipointstructmeshname, &nsectionmeshcell,
00323                               &sectiongeotype);
00324           if(loc==locName)
00325             break;
00326         }
00327       int dim=(int)INTERP_KERNEL::CellModel::GetCellModel((*iter).getType()).getDimension();
00328       int nbPtPerCell=(int)INTERP_KERNEL::CellModel::GetCellModel((*iter).getType()).getNumberOfNodes();
00329       std::vector<double> refcoo(nbPtPerCell*dim),gscoo(nbOfGaussPt*dim),w(nbOfGaussPt);
00330       MEDlocalizationRd(fid,(*iter).getLocName().c_str(),MED_FULL_INTERLACE,&refcoo[0],&gscoo[0],&w[0]);
00331       f->setGaussLocalizationOnType((*iter).getType(),refcoo,gscoo,w);
00332     }
00333   MEDfileClose(fid);
00334 }
00335 
00337 
00338 void MEDLoader::CheckFileForRead(const char *fileName) throw(INTERP_KERNEL::Exception)
00339 {
00340   MEDFileUtilities::CheckFileForRead(fileName);
00341 }
00342 
00343 std::vector<std::string> MEDLoader::GetMeshNames(const char *fileName) throw(INTERP_KERNEL::Exception)
00344 {
00345   CheckFileForRead(fileName);
00346   med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
00347   std::vector<std::string> ret=MEDLoaderNS::getMeshNamesFid(fid);
00348   MEDfileClose(fid);
00349   return ret;
00350 }
00351 
00352 std::vector< std::pair<std::string,std::string> > MEDLoader::GetComponentsNamesOfField(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
00353 {
00354   CheckFileForRead(fileName);
00355   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
00356   med_int nbFields=MEDnField(fid);
00357   std::vector<std::string> fields(nbFields);
00358   med_field_type typcha;
00359   for(int i=0;i<nbFields;i++)
00360     {
00361       med_int ncomp=MEDfieldnComponent(fid,i+1);
00362       INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
00363       INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
00364       INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
00365       med_int nbPdt;
00366       med_bool localmesh;
00367       INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
00368       INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
00369       MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
00370       std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE);
00371       std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
00372       if(curFieldName==fieldName)
00373         {
00374           std::vector< std::pair<std::string,std::string> > ret(ncomp);
00375           for(int j=0;j<ncomp;j++)
00376             ret[j]=std::pair<std::string,std::string>(MEDLoaderBase::buildStringFromFortran(((char *)comp)+j*MED_SNAME_SIZE,MED_SNAME_SIZE),
00377                                                       MEDLoaderBase::buildStringFromFortran(((char *)unit)+j*MED_SNAME_SIZE,MED_SNAME_SIZE));
00378           return ret;
00379         }
00380       fields[i]=curFieldName;
00381     }
00382   std::ostringstream oss; oss << "MEDLoader::GetComponentsNamesOfField : no such field \"" << fieldName << "\" in file \"" << fileName << "\" !" << std::endl;
00383   oss << "Possible field names are : " << std::endl;
00384   std::copy(fields.begin(),fields.end(),std::ostream_iterator<std::string>(oss," "));
00385   throw INTERP_KERNEL::Exception(oss.str().c_str());
00386 }
00387 
00396 std::vector< std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > > MEDLoader::GetUMeshGlobalInfo(const char *fileName, const char *meshName, int &meshDim, int& spaceDim, int& numberOfNodes) throw(INTERP_KERNEL::Exception)
00397 {
00398   CheckFileForRead(fileName);
00399   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
00400   std::set<int> poss;
00401   char nommaa[MED_NAME_SIZE+1];
00402   char maillage_description[MED_COMMENT_SIZE+1];
00403   med_mesh_type type_maillage;
00404   std::string trueMeshName;
00405   med_int meshId=MEDLoaderNS::getIdFromMeshName(fid,meshName,trueMeshName);
00406   INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
00407   med_sorting_type sortingType;
00408   med_int nstep;
00409   med_axis_type axisType;
00410   int naxis=MEDmeshnAxis(fid,meshId);
00411   INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
00412   INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
00413   MEDmeshInfo(fid,meshId,nommaa,&spaceDim,&meshDim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit); 
00414   if(type_maillage!=MED_UNSTRUCTURED_MESH)
00415     {
00416       std::ostringstream oss; oss << "MEDLoader::GetUMeshGlobalInfo : Mesh \""<< meshName << "\" in file \"" << fileName;
00417       oss << "\" exists but it is not an unstructured mesh ! This method is not relevant for mesh types that are not unstructured !";
00418       throw INTERP_KERNEL::Exception(oss.str().c_str());
00419     }
00420   // limitation
00421   if(nstep!=1)
00422     throw INTERP_KERNEL::Exception("MEDLoader::GetUMeshGlobalInfo : multisteps on mesh not managed !");
00423   med_int numdt,numit;
00424   med_float dt;
00425   MEDmeshComputationStepInfo(fid,nommaa,1,&numdt,&numit,&dt);
00426   // endlimitation
00427   std::vector<int> dims;
00428   std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > geoTypes;
00429   med_bool changement,transformation;
00430   for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
00431     {
00432       med_geometry_type curMedType=typmai[i];
00433       int curNbOfElemM=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation);
00434       if(curNbOfElemM>0)
00435         {
00436           INTERP_KERNEL::NormalizedCellType typp=typmai2[i];
00437           int mdimCell=INTERP_KERNEL::CellModel::GetCellModel(typp).getDimension();
00438           dims.push_back(mdimCell);
00439           geoTypes.push_back(std::pair<INTERP_KERNEL::NormalizedCellType,int>(typp,curNbOfElemM));
00440         }
00441     }
00442   int maxLev=*std::max_element(dims.begin(),dims.end());
00443   int lowLev=*std::min_element(dims.begin(),dims.end());
00444   int nbOfLevels=maxLev-lowLev+1;
00445   std::vector< std::vector< std::pair<INTERP_KERNEL::NormalizedCellType,int> > > ret(nbOfLevels);
00446   for(std::size_t i=0;i<dims.size();i++)
00447     {
00448       ret[maxLev-dims[i]].push_back(geoTypes[i]);
00449     }
00450   numberOfNodes=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation);
00451   return ret;
00452 }
00453 
00454 std::vector<std::string> MEDLoader::GetMeshNamesOnField(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception)
00455 {
00456   CheckFileForRead(fileName);
00457   std::vector<std::string> ret;
00458   //
00459   med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
00460   med_int nbFields=MEDnField(fid);
00461   //
00462   med_field_type typcha;
00463   INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
00464   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
00465   med_bool localmesh;
00466   //
00467   for(int i=0;i<nbFields;i++)
00468     {
00469       med_int ncomp=MEDfieldnComponent(fid,i+1);
00470       INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
00471       INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
00472       med_int nbPdt;
00473       INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
00474       MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
00475       std::string meshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE);
00476       std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
00477       if(curFieldName==fieldName)
00478         ret.push_back(meshName);
00479     }
00480   MEDfileClose(fid);
00481   return ret;
00482 }
00483 
00484 std::vector<std::string> MEDLoader::GetMeshFamiliesNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
00485 {
00486   CheckFileForRead(fileName);
00487   med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
00488   med_int nfam=MEDnFamily(fid,meshName);
00489   std::vector<std::string> ret(nfam);
00490   char nomfam[MED_NAME_SIZE+1];
00491   med_int numfam;
00492   for(int i=0;i<nfam;i++)
00493     {
00494       int ngro=MEDnFamilyGroup(fid,meshName,i+1);
00495       med_int natt=MEDnFamily23Attribute(fid,meshName,i+1);
00496       INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
00497       INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
00498       INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
00499       INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
00500       MEDfamily23Info(fid,meshName,i+1,nomfam,attide,attval,attdes,&numfam,gro);
00501       std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
00502       ret[i]=cur;
00503     }
00504   MEDfileClose(fid);
00505   return ret;
00506 }
00507 
00508 
00509 std::vector<std::string> MEDLoader::GetMeshFamiliesNamesOnGroup(const char *fileName, const char *meshName, const char *grpName) throw(INTERP_KERNEL::Exception)
00510 {
00511   CheckFileForRead(fileName);
00512   med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
00513   med_int nfam=MEDnFamily(fid,meshName);
00514   std::vector<std::string> ret;
00515   char nomfam[MED_NAME_SIZE+1];
00516   med_int numfam;
00517   for(int i=0;i<nfam;i++)
00518     {
00519       int ngro=MEDnFamilyGroup(fid,meshName,i+1);
00520       med_int natt=MEDnFamily23Attribute(fid,meshName,i+1);
00521       INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
00522       INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
00523       INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
00524       INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
00525       MEDfamily23Info(fid,meshName,i+1,nomfam,attide,attval,attdes,&numfam,gro);
00526       std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
00527       for(int j=0;j<ngro;j++)
00528         {
00529           std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
00530           if(cur2==grpName)
00531             ret.push_back(cur);
00532         }
00533     }
00534   MEDfileClose(fid);
00535   return ret;
00536 }
00537 
00538 std::vector<std::string> MEDLoader::GetMeshGroupsNamesOnFamily(const char *fileName, const char *meshName, const char *famName) throw(INTERP_KERNEL::Exception)
00539 {
00540   CheckFileForRead(fileName);
00541   med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
00542   med_int nfam=MEDnFamily(fid,meshName);
00543   std::vector<std::string> ret;
00544   char nomfam[MED_NAME_SIZE+1];
00545   med_int numfam;
00546   bool found=false;
00547   for(int i=0;i<nfam && !found;i++)
00548     {
00549       int ngro=MEDnFamilyGroup(fid,meshName,i+1);
00550       med_int natt=MEDnFamily23Attribute(fid,meshName,i+1);
00551       INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
00552       INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
00553       INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
00554       INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
00555       MEDfamily23Info(fid,meshName,i+1,nomfam,attide,attval,attdes,&numfam,gro);
00556       std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
00557       found=(cur==famName);
00558       if(found)
00559         for(int j=0;j<ngro;j++)
00560           {
00561             std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
00562             ret.push_back(cur2);
00563           }
00564     }
00565   MEDfileClose(fid);
00566   if(!found)
00567     {
00568       std::ostringstream oss;
00569       oss << "MEDLoader::GetMeshGroupsNamesOnFamily : no such family \"" << famName << "\" in file \"" << fileName << "\" in mesh \"" << meshName << "\" !";
00570       throw INTERP_KERNEL::Exception(oss.str().c_str());
00571     }
00572   return ret;
00573 }
00574 
00575   
00576 std::vector<std::string> MEDLoader::GetMeshGroupsNames(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
00577 {
00578   CheckFileForRead(fileName);
00579   med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
00580   med_int nfam=MEDnFamily(fid,meshName);
00581   std::vector<std::string> ret;
00582   char nomfam[MED_NAME_SIZE+1];
00583   med_int numfam;
00584   for(int i=0;i<nfam;i++)
00585     {
00586       int ngro=MEDnFamilyGroup(fid,meshName,i+1);
00587       med_int natt=MEDnFamily23Attribute(fid,meshName,i+1);
00588       INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
00589       INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
00590       INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
00591       INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
00592       MEDfamily23Info(fid,meshName,i+1,nomfam,attide,attval,attdes,&numfam,gro);
00593       for(int j=0;j<ngro;j++)
00594         {
00595           std::string cur=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
00596           if(std::find(ret.begin(),ret.end(),cur)==ret.end())
00597             ret.push_back(cur);
00598         }
00599     }
00600   MEDfileClose(fid);
00601   return ret;
00602 }
00603 std::vector<ParaMEDMEM::TypeOfField> MEDLoader::GetTypesOfField(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception)
00604 {
00605   CheckFileForRead(fileName);
00606   std::vector<ParaMEDMEM::TypeOfField> ret;
00607   med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
00608   med_int nbFields=MEDnField(fid);
00609   //
00610   med_field_type typcha;
00611   //med_int nbpdtnor=0,pflsize,*pflval,lnsize;
00612   med_int numdt=0,numo=0;
00613   med_float dt=0.0;
00614   char pflname[MED_NAME_SIZE+1]="";
00615   char locname[MED_NAME_SIZE+1]="";
00616   char *maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
00617   char *nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
00618   med_bool localmesh;
00619   //
00620   for(int i=0;i<nbFields;i++)
00621     {
00622       med_int ncomp=MEDfieldnComponent(fid,i+1);
00623       INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
00624       INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
00625       INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
00626       med_int nbPdt;
00627       MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
00628       std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
00629       std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
00630       if(curMeshName==meshName)
00631         {
00632           if(curFieldName==fieldName)
00633             {
00634               int profilesize,nbi;
00635               if(nbPdt>0)
00636                 {
00637                   bool found=false;
00638                   for(int ii=0;ii<nbPdt && !found;ii++)
00639                     {
00640                       MEDfieldComputingStepInfo(fid,nomcha,1,&numdt,&numo,&dt);
00641                       med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
00642                                                                 pflname,&profilesize,locname,&nbi);
00643                       if(nbOfVal>0)
00644                         {
00645                           ret.push_back(ON_NODES);
00646                           found=true;
00647                         }
00648                     }
00649                 }
00650               bool found=false;
00651               for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
00652                 {
00653                   if(nbPdt>0)
00654                     {
00655                       MEDfieldComputingStepInfo(fid,nomcha,1,&numdt,&numo,&dt);
00656                       med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
00657                                                                 pflname,&profilesize,locname,&nbi);
00658                       if(nbOfVal>0)
00659                         {
00660                           found=true;
00661                           ret.push_back(ON_CELLS);
00662                         }
00663                     }
00664                 }
00665             }
00666         }
00667     }
00668   delete [] maa_ass;
00669   delete [] nomcha;
00670   MEDfileClose(fid);
00671   return ret;
00672 }
00673 
00674 std::vector<std::string> MEDLoader::GetAllFieldNames(const char *fileName) throw(INTERP_KERNEL::Exception)
00675 {
00676   CheckFileForRead(fileName);
00677   std::vector<std::string> ret;
00678   med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
00679   med_int nbFields=MEDnField(fid);
00680   med_field_type typcha;
00681   for(int i=0;i<nbFields;i++)
00682     {
00683       med_int ncomp=MEDfieldnComponent(fid,i+1);
00684       INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
00685       INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
00686       INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
00687       INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
00688       INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
00689       med_int nbPdt;
00690       med_bool localmesh;
00691       MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
00692       ret.push_back(std::string(nomcha));
00693     }
00694   MEDfileClose(fid);
00695   return ret;
00696 }
00697 
00698 std::vector<std::string> MEDLoader::GetAllFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
00699 {
00700   CheckFileForRead(fileName);
00701   std::vector<std::string> ret;
00702   med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
00703   med_int nbFields=MEDnField(fid);
00704   //
00705   med_field_type typcha;
00706   char *maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
00707   char *nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
00708   //
00709   for(int i=0;i<nbFields;i++)
00710     {
00711       med_int ncomp=MEDfieldnComponent(fid,i+1);
00712       INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
00713       INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
00714       INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
00715       med_int nbPdt;
00716       med_bool localmesh;
00717       MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
00718       std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
00719       std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
00720       //
00721       if(curMeshName==meshName)
00722         ret.push_back(curFieldName);
00723     }
00724   delete [] maa_ass;
00725   delete [] nomcha;
00726   MEDfileClose(fid);
00727   return ret;
00728 }
00729 
00730 std::vector<std::string> MEDLoader::GetFieldNamesOnMesh(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
00731 {
00732   CheckFileForRead(fileName);
00733   switch(type)
00734     {
00735     case ON_CELLS:
00736       return GetCellFieldNamesOnMesh(fileName,meshName);
00737     case ON_NODES:
00738       return GetNodeFieldNamesOnMesh(fileName,meshName);
00739     default:
00740       throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
00741     } 
00742 }
00743 
00744 std::vector<std::string> MEDLoader::GetCellFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
00745 {
00746   CheckFileForRead(fileName);
00747   std::vector<std::string> ret;
00748   med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
00749   med_int nbFields=MEDnField(fid);
00750   //
00751   med_field_type typcha;
00752   //med_int nbpdtnor=0,pflsize,*pflval,lnsize;
00753   med_int numdt=0,numo=0;
00754   med_float dt=0.0;
00755   char pflname[MED_NAME_SIZE+1]="";
00756   char locname[MED_NAME_SIZE+1]="";
00757   INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
00758   INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
00759   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
00760   med_bool localmesh;
00761   med_int nbPdt;
00762   //
00763   for(int i=0;i<nbFields;i++)
00764     {
00765       med_int ncomp=MEDfieldnComponent(fid,i+1);
00766       INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
00767       INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
00768       MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
00769       std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
00770       std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
00771       int profilesize,nbi;
00772       if(curMeshName==meshName)
00773         {
00774           bool found=false;
00775           for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
00776             {
00777               if(nbPdt>0)
00778                 {
00779                   MEDfieldComputingStepInfo(fid,nomcha,1,&numdt,&numo,&dt);
00780                   med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
00781                                                             pflname,&profilesize,locname,&nbi);
00782                   if(nbOfVal>0)
00783                     {
00784                       found=true;
00785                       ret.push_back(curFieldName);
00786                     }
00787                 }
00788             }
00789         }
00790     }
00791   MEDfileClose(fid);
00792   return ret;
00793 }
00794 
00795 std::vector<std::string> MEDLoader::GetNodeFieldNamesOnMesh(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
00796 {
00797   CheckFileForRead(fileName);
00798   std::vector<std::string> ret;
00799   med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
00800   med_int nbFields=MEDnField(fid);
00801   char pflname[MED_NAME_SIZE+1]="";
00802   char locname[MED_NAME_SIZE+1]="";
00803   //
00804   med_field_type typcha;
00805   med_int numdt=0,numo=0;
00806   med_float dt=0.0;
00807   INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
00808   INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
00809   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
00810   med_bool localmesh;
00811   //
00812   for(int i=0;i<nbFields;i++)
00813     {
00814       med_int ncomp=MEDfieldnComponent(fid,i+1);
00815       INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
00816       INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
00817       med_int nbPdt;
00818       MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
00819       std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
00820       std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
00821       if(nbPdt>0)
00822         {
00823           int profilesize,nbi;
00824           MEDfieldComputingStepInfo(fid,nomcha,1,&numdt,&numo,&dt);
00825           med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
00826                                                     pflname,&profilesize,locname,&nbi);
00827           if(curMeshName==meshName && nbOfVal>0)
00828             {
00829               ret.push_back(curFieldName);
00830             }
00831         }
00832     }
00833   MEDfileClose(fid);
00834   return ret;
00835 }
00836 
00837 std::vector< std::pair< std::pair<int,int>, double> > MEDLoader::GetAllFieldIterations(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception)
00838 {
00839   CheckFileForRead(fileName);
00840   std::string meshNameCpp(meshName);
00841   std::vector< std::pair< std::pair<int,int>, double > > ret;
00842   med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
00843   med_int nbFields=MEDnField(fid);
00844   //
00845   med_field_type typcha;
00846   med_int numdt=0,numo=0;
00847   med_float dt=0.0;
00848   INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
00849   INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
00850   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
00851   med_bool localmesh;
00852   //
00853   for(int i=0;i<nbFields;i++)
00854     {
00855       med_int ncomp=MEDfieldnComponent(fid,i+1);
00856       INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
00857       INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
00858       med_int nbPdt;
00859       MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
00860       std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
00861       if(curFieldName==fieldName)
00862         {
00863           for(int k=0;k<nbPdt;k++)
00864             {
00865               MEDfieldComputingStepInfo(fid,nomcha,k+1,&numdt,&numo,&dt);
00866               ret.push_back(std::make_pair(std::make_pair(numdt,numo),dt));
00867             }
00868         }
00869     }
00870   MEDfileClose(fid);
00871   return ret;
00872 }
00873 
00874 double MEDLoader::GetTimeAttachedOnFieldIteration(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
00875 {
00876   CheckFileForRead(fileName);
00877   med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
00878   med_int nbFields=MEDnField(fid);
00879   //
00880   med_field_type typcha;
00881   med_int numdt=0,numo=0;
00882   med_float dt=0.0;
00883   med_bool local;
00884   INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
00885   INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
00886   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
00887   //
00888   bool found=false;
00889   bool found2=false;
00890   double ret=std::numeric_limits<double>::max();
00891   for(int i=0;i<nbFields && !found;i++)
00892     {
00893       med_int ncomp=MEDfieldnComponent(fid,i+1);
00894       INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
00895       INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
00896       med_int nbPdt;
00897       MEDfieldInfo(fid,i+1,nomcha,maa_ass,&local,&typcha,comp,unit,dt_unit,&nbPdt);
00898       std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
00899       if(curFieldName==fieldName)
00900         {
00901           found=true;
00902           for(int k=0;k<nbPdt;k++)
00903             {
00904               MEDfieldComputingStepInfo(fid,nomcha,k+1,&numdt,&numo,&dt);
00905               if(numdt==iteration && numo==order)
00906                 {
00907                   found2=true;
00908                   ret=dt;
00909                 }
00910             }
00911         }
00912     }
00913   MEDfileClose(fid);
00914   if(!found || !found2)
00915     {
00916       std::ostringstream oss;
00917       oss << "No such field with name \"" << fieldName << "\" and iteration,order=(" << iteration << "," << order << ") exists in file \"" << fileName << "\" !";
00918       throw INTERP_KERNEL::Exception(oss.str().c_str());
00919     }
00920   return ret;
00921 }
00922 
00923 std::vector< std::pair<int,int> > MEDLoader::GetFieldIterations(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception)
00924 {
00925   CheckFileForRead(fileName);
00926   switch(type)
00927     {
00928     case ON_CELLS:
00929       return GetCellFieldIterations(fileName,meshName,fieldName);
00930     case ON_NODES:
00931       return GetNodeFieldIterations(fileName,meshName,fieldName);
00932     default:
00933       throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES or ON_CELLS !");
00934     }
00935 }
00936 
00937 std::vector< std::pair<int,int> > MEDLoader::GetCellFieldIterations(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception)
00938 {
00939   CheckFileForRead(fileName);
00940   std::string meshNameCpp(meshName);
00941   std::vector< std::pair<int,int> > ret;
00942   med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
00943   med_int nbFields=MEDnField(fid);
00944   //
00945   med_field_type typcha;
00946   med_int numdt=0,numo=0;
00947   med_float dt=0.0;
00948   char pflname[MED_NAME_SIZE+1]="";
00949   char locname[MED_NAME_SIZE+1]="";
00950   INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
00951   INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
00952   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
00953   med_bool localmesh;
00954   //
00955   for(int i=0;i<nbFields;i++)
00956     {
00957       med_int ncomp=MEDfieldnComponent(fid,i+1);
00958       INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
00959       INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
00960       med_int nbPdt;
00961       MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
00962       std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
00963       if(curFieldName==fieldName)
00964         {
00965           bool found=false;
00966           for(int j=0;j<MED_N_CELL_FIXED_GEO && !found;j++)
00967             {
00968               for(int k=0;k<nbPdt;k++)
00969                 {
00970                   int profilesize,nbi;
00971                   MEDfieldComputingStepInfo(fid,nomcha,k+1,&numdt,&numo,&dt);
00972                   med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_CELL,typmai[j],1,MED_COMPACT_PFLMODE,
00973                                                             pflname,&profilesize,locname,&nbi);
00974                   std::string maa_ass_cpp(maa_ass);
00975                   if(meshNameCpp==maa_ass_cpp && nbOfVal>0)
00976                     {
00977                       found=true;
00978                       ret.push_back(std::make_pair(numdt,numo));
00979                     }
00980                 }
00981             }
00982         }
00983     }
00984   MEDfileClose(fid);
00985   return ret;
00986 }
00987 
00988 std::vector< std::pair<int,int> > MEDLoader::GetNodeFieldIterations(const char *fileName, const char *meshName, const char *fieldName) throw(INTERP_KERNEL::Exception)
00989 {
00990   CheckFileForRead(fileName);
00991   std::string meshNameCpp(meshName);
00992   std::vector< std::pair<int,int> > ret;
00993   med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
00994   med_int nbFields=MEDnField(fid);
00995   //
00996   med_field_type typcha;
00997   med_int numdt=0,numo=0;
00998   med_float dt=0.0;
00999   char pflname[MED_NAME_SIZE+1]="";
01000   char locname[MED_NAME_SIZE+1]="";
01001   INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
01002   INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
01003   INTERP_KERNEL::AutoPtr<char> nomcha=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
01004   med_bool localmesh;
01005   //
01006   for(int i=0;i<nbFields;i++)
01007     {
01008       med_int ncomp=MEDfieldnComponent(fid,i+1);
01009       INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
01010       INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
01011       med_int nbPdt;
01012       MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
01013       std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
01014       if(curFieldName==fieldName)
01015         {
01016           for(int k=0;k<nbPdt;k++)
01017             {
01018               int profilesize,nbi;
01019               MEDfieldComputingStepInfo(fid,nomcha,k+1,&numdt,&numo,&dt);
01020               med_int nbOfVal=MEDfieldnValueWithProfile(fid,nomcha,numdt,numo,MED_NODE,MED_NONE,1,MED_COMPACT_PFLMODE,
01021                                                         pflname,&profilesize,locname,&nbi);
01022                std::string maa_ass_cpp(maa_ass);
01023                if(meshNameCpp==maa_ass_cpp && nbOfVal>0)
01024                  {
01025                    ret.push_back(std::make_pair(numdt,numo));
01026                  }
01027             }
01028         }
01029     }
01030   MEDfileClose(fid);
01031   return ret;
01032 }
01033 
01039 void MEDLoaderNS::readFieldDoubleDataInMedFile(const char *fileName, const char *meshName, const char *fieldName, 
01040                                                int iteration, int order, ParaMEDMEM::TypeOfField typeOfOutField,
01041                                                std::list<MEDLoader::MEDFieldDoublePerCellType>& field,
01042                                                double& time, std::vector<std::string>& infos)
01043 {
01044   time=0.;
01045   MEDFileUtilities::CheckFileForRead(fileName);
01046   MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
01047   med_int nbFields=MEDnField(fid);
01048   //
01049   med_field_type typcha;
01050   char nomcha[MED_NAME_SIZE+1]="";
01051   char pflname [MED_NAME_SIZE+1]="";
01052   char locname [MED_NAME_SIZE+1]="";
01053   std::map<ParaMEDMEM::TypeOfField, med_entity_type> tabEnt;
01054   std::map<ParaMEDMEM::TypeOfField, med_geometry_type *> tabType;
01055   std::map<ParaMEDMEM::TypeOfField, int> tabTypeLgth;
01056   med_bool localmesh;
01057   bool found=false;
01058   tabEnt[ON_CELLS]=MED_CELL;
01059   tabType[ON_CELLS]=typmai;
01060   tabTypeLgth[ON_CELLS]=MED_N_CELL_FIXED_GEO;
01061   tabEnt[ON_NODES]=MED_NODE;
01062   tabType[ON_NODES]=typmainoeud;
01063   tabTypeLgth[ON_NODES]=1;
01064   tabEnt[ON_GAUSS_PT]=MED_CELL;
01065   tabType[ON_GAUSS_PT]=typmai;
01066   tabTypeLgth[ON_GAUSS_PT]=MED_N_CELL_FIXED_GEO;
01067   tabEnt[ON_GAUSS_NE]=MED_NODE_ELEMENT;
01068   tabType[ON_GAUSS_NE]=typmai;
01069   tabTypeLgth[ON_GAUSS_NE]=MED_N_CELL_FIXED_GEO;
01070   //
01071   for(int i=0;i<nbFields && !found;i++)
01072     {
01073       med_int ncomp=MEDfieldnComponent(fid,i+1);
01074       INTERP_KERNEL::AutoPtr<char> comp=new char[ncomp*MED_SNAME_SIZE+1];
01075       INTERP_KERNEL::AutoPtr<char> unit=new char[ncomp*MED_SNAME_SIZE+1];
01076       INTERP_KERNEL::AutoPtr<char> dt_unit=new char[MED_LNAME_SIZE+1];
01077       INTERP_KERNEL::AutoPtr<char> maa_ass=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
01078       med_int nbPdt;
01079       MEDfieldInfo(fid,i+1,nomcha,maa_ass,&localmesh,&typcha,comp,unit,dt_unit,&nbPdt);
01080       std::string curMeshName=MEDLoaderBase::buildStringFromFortran(maa_ass,MED_NAME_SIZE+1);
01081       std::string curFieldName=MEDLoaderBase::buildStringFromFortran(nomcha,MED_NAME_SIZE+1);
01082       found=(curFieldName==fieldName) && (curMeshName==meshName);
01083       if(found)
01084         {
01085           infos.resize(ncomp);
01086           for(int ii=0;ii<ncomp;ii++)
01087             infos[ii]=MEDLoaderBase::buildUnionUnit(comp+ii*MED_SNAME_SIZE,MED_SNAME_SIZE,unit+ii*MED_SNAME_SIZE,MED_SNAME_SIZE);
01088           bool found2=false;
01089           med_int numdt=0,numo=0;
01090           med_float dt=0.0;
01091           for(int k=0;k<nbPdt && !found2;k++)
01092             {
01093               MEDfieldComputingStepInfo(fid,fieldName,k+1,&numdt,&numo,&dt);
01094               found2=(numdt==iteration && numo==order);
01095               if(found2)
01096                 time=dt;
01097             }
01098           if(!found2)
01099             {
01100               std::ostringstream oss; oss << "FieldDouble in file \""<< fileName<< "\" with name \"" << fieldName << "\" on mesh \"" <<  meshName;
01101               oss << "\" does not have such time step : iteration=" << iteration << " order=" << order << std::endl;
01102               throw INTERP_KERNEL::Exception(oss.str().c_str());
01103             }
01104           for(int j=0;j<tabTypeLgth[typeOfOutField];j++)
01105             {
01106               if(nbPdt>0)
01107                 {
01108                   int profilesize,nbi;
01109                   int nval=MEDfieldnValueWithProfile(fid,fieldName,numdt,numo,tabEnt[typeOfOutField],tabType[typeOfOutField][j],1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi);
01110                   if(nval>0)
01111                     {
01112                       double *valr=new double[ncomp*nval*nbi];
01113                       MEDfieldValueWithProfileRd(fid,fieldName,iteration,order,tabEnt[typeOfOutField],tabType[typeOfOutField][j],MED_COMPACT_PFLMODE,
01114                                                  pflname,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,(unsigned char*)valr);
01115                       std::string tmp(locname);
01116                       if((locname[0]!='\0' && (typeOfOutField!=ON_GAUSS_PT))
01117                          || (locname[0]=='\0' && typeOfOutField==ON_GAUSS_PT))
01118                         {
01119                           delete [] valr;
01120                           continue;
01121                         }
01122                       INTERP_KERNEL::AutoPtr<int> pfl=0;
01123                       if(pflname[0]!='\0')
01124                         {
01125                           pfl=new int[nval];
01126                           MEDprofileRd(fid,pflname,pfl);
01127                         }
01128                       field.push_back(MEDLoader::MEDFieldDoublePerCellType(typmai2[j],valr,ncomp,nval*nbi,pfl,locname));
01129                     }
01130                 }
01131             }
01132         }
01133     }
01134   if(!found)
01135     {
01136       std::ostringstream oss; oss << "MEDLoaderNS::readFieldDoubleDataInMedFile : no such couple meshName=\"" << meshName << "\", fieldName=\"" << fieldName << "\" in file \"" << fileName << "\" !";
01137       throw INTERP_KERNEL::Exception(oss.str().c_str());
01138     }
01139 }
01140 
01141 std::vector<int> MEDLoaderNS::getIdsFromFamilies(const char *fileName, const char *meshName, const std::vector<std::string>& fams)
01142 {
01143   std::vector<int> ret;
01144   med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
01145   med_int nfam=MEDnFamily(fid,meshName);
01146   char nomfam[MED_NAME_SIZE+1];
01147   med_int numfam;
01148   for(int i=0;i<nfam;i++)
01149     {
01150       int ngro=MEDnFamilyGroup(fid,meshName,i+1);
01151       med_int natt=MEDnFamily23Attribute(fid,meshName,i+1);
01152       INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
01153       INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
01154       INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
01155       INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
01156       MEDfamily23Info(fid,meshName,i+1,nomfam,attide,attval,attdes,&numfam,gro);
01157       std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
01158       if(std::find(fams.begin(),fams.end(),cur)!=fams.end())
01159         ret.push_back(numfam);
01160     }
01161   MEDfileClose(fid);
01162   return ret;
01163 }
01164 
01165 std::vector<int> MEDLoaderNS::getIdsFromGroups(const char *fileName, const char *meshName, const std::vector<std::string>& grps)
01166 {
01167   std::vector<int> ret;
01168   med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
01169   med_int nfam=MEDnFamily(fid,meshName);
01170   char nomfam[MED_NAME_SIZE+1];
01171   med_int numfam;
01172   for(int i=0;i<nfam;i++)
01173     {
01174       int ngro=MEDnFamilyGroup(fid,meshName,i+1);
01175       med_int natt=MEDnFamily23Attribute(fid,meshName,i+1);
01176       INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
01177       INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
01178       INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
01179       INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
01180       MEDfamily23Info(fid,meshName,i+1,nomfam,attide,attval,attdes,&numfam,gro);
01181       std::string cur=MEDLoaderBase::buildStringFromFortran(nomfam,sizeof(nomfam));
01182       for(int j=0;j<ngro;j++)
01183         {
01184           std::string cur2=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
01185           if(std::find(grps.begin(),grps.end(),cur2)!=grps.end())
01186             {
01187               ret.push_back(numfam);
01188               break;
01189             }
01190         }
01191     }
01192   MEDfileClose(fid);
01193   return ret;
01194 }
01195 
01196 med_int MEDLoaderNS::getIdFromMeshName(med_idt fid, const char *meshName, std::string& trueMeshName) throw(INTERP_KERNEL::Exception)
01197 {
01198   if(meshName==0)
01199     {
01200       std::vector<std::string> meshes=getMeshNamesFid(fid);
01201       if(meshes.empty())
01202         throw INTERP_KERNEL::Exception("No mesh in file");
01203       trueMeshName=meshes[0];
01204       return 1;
01205     }
01206   std::string meshNameStr(meshName);
01207   std::vector<std::string> meshes=getMeshNamesFid(fid);
01208   if(meshes.empty())
01209     throw INTERP_KERNEL::Exception("No mesh in file");
01210   std::vector<std::string>::iterator iter=std::find(meshes.begin(),meshes.end(),meshNameStr);
01211   if(iter==meshes.end())
01212     {
01213       std::ostringstream os2;
01214       os2 << "MeshName '" << meshName << "' not in file : meshes available : ";
01215       std::copy(meshes.begin(),meshes.end(),std::ostream_iterator<std::string>(os2," "));
01216       throw INTERP_KERNEL::Exception(os2.str().c_str());
01217     }
01218   trueMeshName=meshName;
01219   return iter-meshes.begin()+1;
01220 }
01221 
01225 void MEDLoaderNS::dispatchElems(int nbOfElemCell, int nbOfElemFace, int& nbOfElem, med_entity_type& whichEntity)
01226 {
01227   if(nbOfElemCell>=nbOfElemFace)
01228     {
01229       whichEntity=MED_CELL;
01230       nbOfElem=nbOfElemCell;
01231     }
01232   else
01233     {
01234       whichEntity=MED_CELL;
01235       nbOfElem=nbOfElemFace;
01236     }
01237 }
01238 
01244 int MEDLoaderNS::readUMeshDimFromFile(const char *fileName, const char *meshName, std::vector<int>& possibilities)
01245 {
01246   possibilities.clear();
01247   med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
01248   int ret;
01249   std::set<int> poss;
01250   char nommaa[MED_NAME_SIZE+1];
01251   char maillage_description[MED_COMMENT_SIZE+1];
01252   med_mesh_type type_maillage;
01253   med_int Sdim,Mdim;
01254   std::string trueMeshName;
01255   med_int meshId=getIdFromMeshName(fid,meshName,trueMeshName);
01256   INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
01257   med_sorting_type sortingType;
01258   med_int nstep;
01259   med_axis_type axisType;
01260   int naxis=MEDmeshnAxis(fid,meshId);
01261   INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
01262   INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
01263   MEDmeshInfo(fid,meshId,nommaa,&Sdim,&Mdim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,axisname,axisunit);
01264   // limitation
01265   if(nstep!=1)
01266     {
01267       throw INTERP_KERNEL::Exception("multisteps on mesh not managed yet !");
01268     } 
01269   med_int numdt,numit;
01270   med_float dt;
01271   MEDmeshComputationStepInfo(fid,nommaa,1,&numdt,&numit,&dt);
01272   // endlimitation
01273   for(int i=0;i<MED_N_CELL_GEO_FIXED_CON;i++)
01274     {
01275       med_geometry_type curMedType=typmai[i];
01276       med_bool changement,transformation;
01277       int curNbOfElemM=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation);
01278       int curNbOfElemF=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation);//limitation
01279       int curNbOfElem;
01280       med_entity_type whichEntity;
01281       MEDLoaderNS::dispatchElems(curNbOfElemM,curNbOfElemF,curNbOfElem,whichEntity);
01282       if(curNbOfElem>0)
01283         {
01284           INTERP_KERNEL::NormalizedCellType type=typmai2[i];
01285           int curDim=(int)INTERP_KERNEL::CellModel::GetCellModel(type).getDimension();
01286           poss.insert(curDim);
01287         }
01288     }
01289   MEDfileClose(fid);
01290   if(!poss.empty())
01291     {
01292       ret=*poss.rbegin();
01293       for(std::set<int>::const_reverse_iterator it=poss.rbegin();it!=poss.rend();it++)
01294         possibilities.push_back(*it-ret);
01295     }
01296   else
01297     ret=-2;
01298   return ret;
01299 }
01300 
01301 void MEDLoaderNS::readUMeshDataInMedFile(med_idt fid, med_int meshId, DataArrayDouble *&coords, std::list<MEDLoader::MEDConnOfOneElemType>& conn, std::string& description)
01302 {
01303   char nommaa[MED_NAME_SIZE+1];
01304   char maillage_description[MED_COMMENT_SIZE+1];
01305   med_mesh_type type_maillage;
01306   med_int Mdim;
01307   med_int Sdim;
01308   INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
01309   med_sorting_type sortingType;
01310   med_int nstep;
01311   med_axis_type axisType;
01312   med_int numdt,numit;
01313   med_float dt;
01314   med_bool changement,transformation;
01315   // endlimitation
01316   Sdim=MEDmeshnAxis(fid,1);
01317   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(Sdim*MED_SNAME_SIZE);
01318   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(Sdim*MED_SNAME_SIZE);
01319   MEDmeshInfo(fid,meshId,nommaa,&Sdim,&Mdim,&type_maillage,maillage_description,dt_unit,&sortingType,&nstep,&axisType,comp,unit);
01320   description=MEDLoaderBase::buildStringFromFortran(maillage_description,sizeof(maillage_description));
01321   MEDmeshComputationStepInfo(fid,nommaa,1,&numdt,&numit,&dt);
01322   int spaceDim=std::max((int)Mdim,(int)Sdim);
01323   int nCoords=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation);
01324   // limitation
01325   if(nstep!=1)
01326     {
01327       throw INTERP_KERNEL::Exception("multisteps on mesh not managed yet !");
01328     }
01329   coords=DataArrayDouble::New();
01330   coords->alloc(nCoords,spaceDim);
01331   double *coordsPtr=coords->getPointer();
01332   MEDmeshNodeCoordinateRd(fid,nommaa,numdt,numit,MED_FULL_INTERLACE,coordsPtr);
01333   for(int i=0;i<spaceDim;i++)
01334     {
01335       std::string info=MEDLoaderBase::buildUnionUnit(comp+i*MED_SNAME_SIZE,MED_SNAME_SIZE,unit+i*MED_SNAME_SIZE,MED_SNAME_SIZE);
01336       coords->setInfoOnComponent(i,info.c_str());
01337     }
01338   for(int i=0;i<MED_N_CELL_GEO_FIXED_CON;i++)
01339     {
01340       med_geometry_type curMedType=typmai[i];
01341       med_entity_type whichEntity;
01342       int curNbOfElemM=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation);
01343       int curNbOfElemF=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,curMedType,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation);//limitation
01344       int curNbOfElem;
01345       MEDLoaderNS::dispatchElems(curNbOfElemM,curNbOfElemF,curNbOfElem,whichEntity);
01346       if(curNbOfElem>0)
01347         {
01348           int *connTab=new int[(curMedType%100)*curNbOfElem];
01349           int *fam=new int[curNbOfElem];
01350           MEDLoader::MEDConnOfOneElemType elem(typmai2[i],connTab,0,fam,curNbOfElem,-1);
01351           char *noms=new char[MED_SNAME_SIZE*curNbOfElem+1];
01352           med_bool withname=MED_FALSE,withnumber=MED_FALSE,withfam=MED_FALSE;
01353           int *globArr=new int[curNbOfElem];
01354           MEDmeshElementRd(fid,nommaa,numdt,numit,whichEntity,curMedType,MED_NODAL,MED_FULL_INTERLACE,connTab,&withname,noms,&withnumber,globArr,&withfam,fam);
01355           if(!withfam)
01356             std::fill(fam,fam+curNbOfElem,0);
01357           delete [] noms;
01358           //trying to read global numbering
01359           if(withnumber)
01360             elem.setGlobal(globArr);
01361           else
01362             delete [] globArr;
01363           //limitation manage withfam==false
01364           conn.push_back(elem);
01365         }
01366     }
01367   int curNbOfPolyElem;
01368   int curNbOfPolyElemM=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYGON,MED_INDEX_NODE,MED_NODAL,&changement,&transformation)-1;
01369   int curNbOfPolyElemF=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYGON,MED_INDEX_NODE,MED_NODAL,&changement,&transformation)-1;//limitation
01370   med_entity_type whichPolyEntity;
01371   MEDLoaderNS::dispatchElems(curNbOfPolyElemM,curNbOfPolyElemF,curNbOfPolyElem,whichPolyEntity);
01372   if(curNbOfPolyElem>0)
01373     {
01374       med_int arraySize=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYGON,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation);
01375       int *index=new int[curNbOfPolyElem+1];
01376       int *locConn=new int[arraySize];
01377       int *fam=new int[curNbOfPolyElem];
01378       int *globArr=new int[curNbOfPolyElem];
01379       MEDLoader::MEDConnOfOneElemType elem(INTERP_KERNEL::NORM_POLYGON,locConn,index,fam,curNbOfPolyElem,arraySize);
01380       MEDmeshPolygonRd(fid,nommaa,numdt,numit,MED_CELL,MED_NODAL,index,locConn);
01381       if(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYGON,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0)
01382         {
01383           if(MEDmeshEntityFamilyNumberRd(fid,nommaa,numdt,numit,MED_CELL,MED_POLYGON,fam)!=0)
01384             std::fill(fam,fam+curNbOfPolyElem,0);
01385         }
01386       else
01387         std::fill(fam,fam+curNbOfPolyElem,0);
01388       if(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYGON,MED_NUMBER,MED_NODAL,&changement,&transformation)>0)
01389         {
01390           if(MEDmeshEntityNumberRd(fid,nommaa,numdt,numit,whichPolyEntity,MED_POLYGON,globArr)==0)
01391             elem.setGlobal(globArr);
01392           else
01393             delete [] globArr;
01394         }
01395       else
01396         delete [] globArr;
01397       conn.push_back(elem);
01398     }
01399   curNbOfPolyElem=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYHEDRON,MED_INDEX_FACE,MED_NODAL,&changement,&transformation)-1;
01400   if(curNbOfPolyElem>0)
01401     {
01402       med_int indexFaceLgth,connFaceLgth;
01403       indexFaceLgth=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYHEDRON,MED_INDEX_NODE,MED_NODAL,&changement,&transformation);
01404       connFaceLgth=MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYHEDRON,MED_CONNECTIVITY,MED_NODAL,&changement,&transformation);
01405       INTERP_KERNEL::AutoPtr<int> index=new int[curNbOfPolyElem+1];
01406       INTERP_KERNEL::AutoPtr<int> indexFace=new int[indexFaceLgth];
01407       INTERP_KERNEL::AutoPtr<int> locConn=new int[connFaceLgth];
01408       int *fam=new int[curNbOfPolyElem];
01409       int *globArr=new int[curNbOfPolyElem];
01410       MEDmeshPolyhedronRd(fid,nommaa,numdt,numit,MED_CELL,MED_NODAL,index,indexFace,locConn);
01411       if(MEDmeshnEntity(fid,nommaa,numdt,numit,whichPolyEntity,MED_POLYHEDRON,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0)
01412         {
01413           if(MEDmeshEntityFamilyNumberRd(fid,nommaa,numdt,numit,whichPolyEntity,MED_POLYHEDRON,fam)!=0)
01414             std::fill(fam,fam+curNbOfPolyElem,0);
01415         }
01416       else
01417         std::fill(fam,fam+curNbOfPolyElem,0);
01418       int arraySize=connFaceLgth;
01419       for(int i=0;i<curNbOfPolyElem;i++)
01420         arraySize+=index[i+1]-index[i]-1;
01421       int *finalConn=new int[arraySize];
01422       int *finalIndex=new int[curNbOfPolyElem+1];
01423       finalIndex[0]=1;
01424       int *wFinalConn=finalConn;
01425       for(int i=0;i<curNbOfPolyElem;i++)
01426         {
01427           finalIndex[i+1]=finalIndex[i]+index[i+1]-index[i]-1+indexFace[index[i+1]-1]-indexFace[index[i]-1];
01428           wFinalConn=std::copy(locConn+indexFace[index[i]-1]-1,locConn+indexFace[index[i]]-1,wFinalConn);
01429           for(int j=index[i];j<index[i+1]-1;j++)
01430             {
01431               *wFinalConn++=0;
01432               wFinalConn=std::copy(locConn+indexFace[j]-1,locConn+indexFace[j+1]-1,wFinalConn);
01433             }
01434         }
01435       MEDLoader::MEDConnOfOneElemType elem(INTERP_KERNEL::NORM_POLYHED,finalConn,finalIndex,fam,curNbOfPolyElem,arraySize);
01436       if(MEDmeshnEntity(fid,nommaa,numdt,numit,MED_CELL,MED_POLYHEDRON,MED_NUMBER,MED_NODAL,&changement,&transformation)>0)
01437         {
01438           if(MEDmeshEntityNumberRd(fid,nommaa,numdt,numit,whichPolyEntity,MED_POLYHEDRON,globArr)==0)
01439             elem.setGlobal(globArr);
01440           else
01441             delete [] globArr;
01442         }
01443       else
01444         delete [] globArr;
01445       conn.push_back(elem);
01446     }
01447 }
01448 
01450 
01451 namespace MEDLoaderNS
01452 {
01453   template<class T>
01454   unsigned calculateHighestMeshDim(const std::list<T>& conn)
01455   {
01456     unsigned ret=0;
01457     for(typename std::list<T>::const_iterator iter=conn.begin();iter!=conn.end();iter++)
01458       {
01459         unsigned curDim=INTERP_KERNEL::CellModel::GetCellModel((*iter).getType()).getDimension();
01460         if(ret<curDim)
01461           ret=curDim;
01462       }
01463     return ret;
01464   }
01465   
01466   template<class T>
01467   void keepSpecifiedMeshDim(typename std::list<T>& conn, unsigned meshDim)
01468   {
01469     for(typename std::list<T>::iterator iter=conn.begin();iter!=conn.end();)
01470       {
01471         unsigned curDim=INTERP_KERNEL::CellModel::GetCellModel((*iter).getType()).getDimension();
01472         if(curDim!=meshDim)
01473           {
01474             (*iter).releaseArray();
01475             iter=conn.erase(iter);
01476           }
01477         else
01478           iter++;
01479       }
01480   }
01481   
01482   template<class T>
01483   void keepTypes(typename std::list<T>& conn, const std::vector<INTERP_KERNEL::NormalizedCellType>& typesToKeep)
01484   {
01485     if(!typesToKeep.empty())
01486       {
01487         for(typename std::list<T>::iterator iter=conn.begin();iter!=conn.end();)
01488           {
01489             INTERP_KERNEL::NormalizedCellType curType=(*iter).getType();
01490             if(std::find(typesToKeep.begin(),typesToKeep.end(),curType)==typesToKeep.end())
01491               {
01492                 (*iter).releaseArray();
01493                 iter=conn.erase(iter);
01494               }
01495             else
01496               iter++;
01497           }
01498       }
01499   }
01500 }
01501 
01502 class FieldPerTypeAccumulator
01503 {
01504 public:
01505   int operator()(int res, const MEDLoader::MEDFieldDoublePerCellType& elt) { return res+elt.getNbOfTuple(); }
01506 };
01507 
01508 ParaMEDMEM::DataArrayDouble *MEDLoaderNS::buildArrayFromRawData(const std::list<MEDLoader::MEDFieldDoublePerCellType>& fieldPerType,
01509                                                                 const std::vector<std::string>& infos)
01510 {
01511   ParaMEDMEM::DataArrayDouble *ret=ParaMEDMEM::DataArrayDouble::New();
01512   int totalNbOfTuple=std::accumulate(fieldPerType.begin(),fieldPerType.end(),0,FieldPerTypeAccumulator());
01513   int nbOfComp=(*fieldPerType.begin()).getNbComp();
01514   double *ptr=new double[nbOfComp*totalNbOfTuple];
01515   ret->useArray(ptr,true,ParaMEDMEM::CPP_DEALLOC,totalNbOfTuple,nbOfComp);
01516   std::for_each(fieldPerType.begin(),fieldPerType.end(),FieldPerTypeCopier(ptr));
01517   for(int i=0;i<nbOfComp;i++)
01518     ret->setInfoOnComponent(i,infos[i].c_str());
01519   return ret;
01520 }
01521 
01522 class PolyCounterForFams
01523 {
01524 public:
01525   PolyCounterForFams(int id, const int *index):_id(id),_index(index),_count(0),_sigma(0) { }
01526   void operator()(int val) { if(val==_id) _sigma+=_index[_count+1]-_index[_count]; _count++; }
01527   int getSigma() const { return _sigma; }
01528 private:
01529   int _id;
01530   const int *_index;
01531   int _count;
01532   int _sigma;
01533 };
01534 
01539 void MEDLoaderNS::tradMEDFileCoreFrmt2MEDCouplingUMesh(const std::list<MEDLoader::MEDConnOfOneElemType>& medConnFrmt,
01540                                                        const std::vector<int>& familiesToKeep,
01541                                                        DataArrayInt* &conn,
01542                                                        DataArrayInt* &connIndex,
01543                                                        int *&cellRenum)
01544 {
01545   bool keepAll=familiesToKeep.empty();
01546   if(medConnFrmt.empty())
01547     {
01548       conn=0;
01549       connIndex=0;
01550       cellRenum=0;
01551       return ;
01552     }
01553   std::list<MEDLoader::MEDConnOfOneElemType>::const_iterator iter=medConnFrmt.begin();
01554   int totalNbOfCells=0;
01555   int totalNbOfMedConn=0;
01556   bool renumber=true;
01557   cellRenum=0;
01558   for(;iter!=medConnFrmt.end();iter++)
01559     {
01560       if((*iter).getGlobal()==0)
01561         renumber=false;
01562       const INTERP_KERNEL::CellModel& cellMod=INTERP_KERNEL::CellModel::GetCellModel((*iter).getType());
01563       if(keepAll)
01564         totalNbOfCells+=(*iter).getLength();
01565       else
01566         for(std::vector<int>::const_iterator iter2=familiesToKeep.begin();iter2!=familiesToKeep.end();iter2++)
01567           totalNbOfCells+=std::count((*iter).getFam(),(*iter).getFam()+(*iter).getLength(),*iter2);
01568       if(!cellMod.isDynamic())
01569         if(keepAll)
01570           totalNbOfMedConn+=(*iter).getLength()*cellMod.getNumberOfNodes();
01571         else
01572           for(std::vector<int>::const_iterator iter2=familiesToKeep.begin();iter2!=familiesToKeep.end();iter2++)
01573             totalNbOfMedConn+=std::count((*iter).getFam(),(*iter).getFam()+(*iter).getLength(),*iter2)*cellMod.getNumberOfNodes();
01574       else
01575         if(keepAll)
01576           totalNbOfMedConn+=(*iter).getConnLength();
01577         else
01578           for(std::vector<int>::const_iterator iter2=familiesToKeep.begin();iter2!=familiesToKeep.end();iter2++)
01579             {
01580               PolyCounterForFams res=std::for_each((*iter).getFam(),(*iter).getFam()+(*iter).getLength(),PolyCounterForFams(*iter2,(*iter).getIndex()));
01581               totalNbOfMedConn+=res.getSigma();
01582             }
01583     }
01584   connIndex=DataArrayInt::New();
01585   conn=DataArrayInt::New();
01586   connIndex->alloc(totalNbOfCells+1,1);
01587   int *connIdxPtr=connIndex->getPointer();
01588   int connFillId=0;
01589   conn->alloc(totalNbOfMedConn+totalNbOfCells,1);
01590   int *connPtr=conn->getPointer();
01591   if(renumber)
01592     cellRenum=new int[totalNbOfCells];
01593   int *renumW=cellRenum;
01594   for(iter=medConnFrmt.begin();iter!=medConnFrmt.end();iter++)
01595     {
01596       INTERP_KERNEL::NormalizedCellType type=(*iter).getType();
01597       const int *sourceConn=(*iter).getArray();
01598       const int *sourceIndex=(*iter).getIndex();
01599       const int *globalNum=(*iter).getGlobal();
01600       const INTERP_KERNEL::CellModel& cellMod=INTERP_KERNEL::CellModel::GetCellModel(type);
01601       int nbOfCellsInCurType;
01602       int nbOfNodesIn1Cell=cellMod.getNumberOfNodes();
01603       nbOfCellsInCurType=(*iter).getLength();
01604       bool isDyn=cellMod.isDynamic();
01605       int *tmpConnPtr;
01606       for(int i=0;i<nbOfCellsInCurType;i++)
01607         {
01608           if(keepAll)
01609             {//duplication of next 3 lines needed.
01610               *connIdxPtr=connFillId;
01611               *connPtr++=type;
01612               if(renumber)
01613                 *renumW++=globalNum[i];
01614               if(!isDyn)
01615                 tmpConnPtr=std::transform(sourceConn,sourceConn+nbOfNodesIn1Cell,connPtr,std::bind2nd(std::minus<int>(),1));
01616               else
01617                 tmpConnPtr=std::transform(sourceConn,sourceConn+sourceIndex[i+1]-sourceIndex[i],connPtr,std::bind2nd(std::minus<int>(),1));
01618               connIdxPtr++;
01619               nbOfNodesIn1Cell=tmpConnPtr-connPtr;
01620               connFillId+=nbOfNodesIn1Cell+1;
01621               connPtr=tmpConnPtr;
01622             }
01623           else if(std::find(familiesToKeep.begin(),familiesToKeep.end(),(*iter).getFam()[i])!=familiesToKeep.end())
01624             {//duplication of next 3 lines needed.
01625               *connIdxPtr=connFillId;
01626               *connPtr++=type;
01627               if(renumber)
01628                 *renumW++=globalNum[i];
01629               if(!isDyn)
01630                 tmpConnPtr=std::transform(sourceConn,sourceConn+nbOfNodesIn1Cell,connPtr,std::bind2nd(std::minus<int>(),1));
01631               else//The duplication of code is motivated by the line underneath.
01632                 tmpConnPtr=std::transform((*iter).getArray()+sourceIndex[i]-1,(*iter).getArray()+sourceIndex[i+1]-1,connPtr,std::bind2nd(std::minus<int>(),1));
01633               connIdxPtr++;
01634               nbOfNodesIn1Cell=tmpConnPtr-connPtr;
01635               connFillId+=nbOfNodesIn1Cell+1;
01636               connPtr=tmpConnPtr;
01637             }
01638           sourceConn+=nbOfNodesIn1Cell;
01639         }
01640       *connIdxPtr=connFillId;
01641     }
01642 }
01643 
01644 namespace MEDLoaderNS
01645 {
01646   template<class T>
01647   void releaseMEDFileCoreFrmt(typename std::list<T>& medConnFrmt)
01648   {
01649     for(typename std::list<T>::iterator iter=medConnFrmt.begin();iter!=medConnFrmt.end();iter++)
01650       (*iter).releaseArray();
01651     medConnFrmt.clear();
01652   }
01653 }
01654 
01667 int MEDLoaderNS::buildMEDSubConnectivityOfOneTypeStaticTypes(const std::vector<const DataArrayInt *>& connV, const std::vector<const DataArrayInt *>& connVIndex, const std::vector<const DataArrayInt *>& familiesV,
01668                                                              INTERP_KERNEL::NormalizedCellType type, std::vector<int>& conn4MEDFile, std::vector<int>& fam4MEDFile, std::vector<int>& renumber)
01669 {
01670   int ret=0;
01671   int nbOfMeshes=connV.size();
01672   int renumOffset=0;
01673   for(int i=0;i<nbOfMeshes;i++)
01674     {
01675       const DataArrayInt *conn=connV[i];
01676       const DataArrayInt *connIndex=connVIndex[i];
01677       const DataArrayInt *families=familiesV[i];
01678       int nbOfElem=connIndex->getNbOfElems()-1;
01679       const int *connPtr=conn->getConstPointer();
01680       const int *connIdxPtr=connIndex->getConstPointer();
01681       const int *famPtr=0;
01682       if(families)
01683         famPtr=families->getConstPointer();
01684       for(int ii=0;ii<nbOfElem;ii++)
01685         {
01686           int delta=connIdxPtr[1]-connIdxPtr[0];
01687           if(*connPtr==type)
01688             {
01689               conn4MEDFile.insert(conn4MEDFile.end(),connPtr+1,connPtr+delta);
01690               if(families)
01691                 fam4MEDFile.push_back(famPtr[ii]);
01692               renumber.push_back(ii+1+renumOffset);
01693               ret++;
01694             }
01695           connIdxPtr++;
01696           connPtr+=delta;
01697         }
01698       renumOffset+=nbOfElem;
01699     }
01700   std::transform(conn4MEDFile.begin(),conn4MEDFile.end(),conn4MEDFile.begin(),std::bind2nd(std::plus<int>(),1));
01701   return ret;
01702 }
01703 
01704 int MEDLoaderNS::buildMEDSubConnectivityOfOneTypesPolyg(const std::vector<const DataArrayInt *>&connV, const std::vector<const DataArrayInt *>& connVIndex, const std::vector<const DataArrayInt *>& familiesV,
01705                                                         std::vector<int>& conn4MEDFile, std::vector<int>& connIndex4MEDFile, std::vector<int>& fam4MEDFile, std::vector<int>& renumber)
01706 {
01707   int ret=0;
01708   int nbOfMeshes=connV.size();
01709   connIndex4MEDFile.push_back(1);
01710   int renumOffset=0;
01711   for(int i=0;i<nbOfMeshes;i++)
01712     {
01713       const DataArrayInt *conn=connV[i];
01714       const DataArrayInt *connIndex=connVIndex[i];
01715       const DataArrayInt *families=familiesV[i];
01716       int nbOfElem=connIndex->getNbOfElems()-1;
01717       const int *connPtr=conn->getConstPointer();
01718       const int *connIdxPtr=connIndex->getConstPointer();
01719       const int *famPtr=0;
01720       if(families)
01721         famPtr=families->getConstPointer();
01722       for(int ii=0;ii<nbOfElem;ii++)
01723         {
01724           int delta=connIdxPtr[1]-connIdxPtr[0];
01725           if(*connPtr==INTERP_KERNEL::NORM_POLYGON)
01726             {
01727               conn4MEDFile.insert(conn4MEDFile.end(),connPtr+1,connPtr+delta);
01728               connIndex4MEDFile.push_back(connIndex4MEDFile.back()+delta-1);
01729               if(families)
01730                 fam4MEDFile.push_back(famPtr[ii]);
01731               renumber.push_back(ii+1+renumOffset);
01732               ret++;
01733             }
01734           connIdxPtr++;
01735           connPtr+=delta;
01736         }
01737       renumOffset+=nbOfElem;
01738     }
01739   std::transform(conn4MEDFile.begin(),conn4MEDFile.end(),conn4MEDFile.begin(),std::bind2nd(std::plus<int>(),1));
01740   return ret;
01741 }
01742   
01743 int MEDLoaderNS::buildMEDSubConnectivityOfOneTypesPolyh(const std::vector<const DataArrayInt *>& connV, const std::vector<const DataArrayInt *>& connVIndex, const std::vector<const DataArrayInt *>& familiesV,
01744                                                         std::vector<int>& conn4MEDFile, std::vector<int>& connIndex4MEDFile, std::vector<int>& connIndexRk24MEDFile,
01745                                                         std::vector<int>& fam4MEDFile, std::vector<int>& renumber)
01746 {
01747   int ret=0;
01748   int nbOfMeshes=connV.size();
01749   connIndexRk24MEDFile.push_back(1);
01750   connIndex4MEDFile.push_back(1);
01751   int renumOffset=0;
01752   for(int i=0;i<nbOfMeshes;i++)
01753     {
01754       const DataArrayInt *conn=connV[i];
01755       const DataArrayInt *connIndex=connVIndex[i];
01756       const DataArrayInt *families=familiesV[i];
01757       int nbOfElem=connIndex->getNbOfElems()-1;
01758       const int *connPtr=conn->getConstPointer();
01759       const int *connIdxPtr=connIndex->getConstPointer();
01760       const int *famPtr=0;
01761       if(families)
01762         famPtr=families->getConstPointer();
01763       for(int ii=0;ii<nbOfElem;ii++)
01764         {
01765           int delta=connIdxPtr[1]-connIdxPtr[0];
01766           if(*connPtr==INTERP_KERNEL::NORM_POLYHED)
01767             {
01768               int nbOfFacesOfPolyh=std::count(connPtr+1,connPtr+delta,-1)+1;
01769               const int *work=connPtr+1;
01770               while(work!=connPtr+delta)
01771                 {
01772                   const int *end=std::find(work,connPtr+delta,-1);
01773                   conn4MEDFile.insert(conn4MEDFile.end(),work,end);
01774                   connIndex4MEDFile.push_back(connIndex4MEDFile.back()+std::distance(work,end));
01775                   if(end==connPtr+delta)
01776                     work=connPtr+delta;
01777                   else
01778                     work=end+1;
01779                 }
01780               connIndexRk24MEDFile.push_back(connIndexRk24MEDFile.back()+nbOfFacesOfPolyh);
01781               if(families)
01782                 fam4MEDFile.push_back(famPtr[ii]);
01783               renumber.push_back(ii+1+renumOffset);
01784               ret++;
01785             }
01786           connIdxPtr++;
01787           connPtr+=delta;
01788         }
01789       renumOffset+=nbOfElem;
01790     }
01791   std::transform(conn4MEDFile.begin(),conn4MEDFile.end(),conn4MEDFile.begin(),std::bind2nd(std::plus<int>(),1));
01792   return ret;
01793 }
01794   
01807 int MEDLoaderNS::buildMEDSubConnectivityOfOneType(const std::vector<const DataArrayInt *>& conn, const std::vector<const DataArrayInt *>& connIndex, const std::vector<const DataArrayInt *>& families,
01808                                                   INTERP_KERNEL::NormalizedCellType type, std::vector<int>& conn4MEDFile,
01809                                                   std::vector<int>& connIndex4MEDFile, std::vector<int>& connIndexRk24MEDFile, std::vector<int>& fam4MEDFile, std::vector<int>& renumber)
01810 {
01811     
01812   const INTERP_KERNEL::CellModel& cellMod=INTERP_KERNEL::CellModel::GetCellModel(type);
01813   if(!cellMod.isDynamic())
01814     return buildMEDSubConnectivityOfOneTypeStaticTypes(conn,connIndex,families,type,conn4MEDFile,fam4MEDFile,renumber);
01815   else
01816     {
01817       if(type==INTERP_KERNEL::NORM_POLYGON)
01818         return buildMEDSubConnectivityOfOneTypesPolyg(conn,connIndex,families,conn4MEDFile,connIndex4MEDFile,fam4MEDFile,renumber);
01819       else
01820         return buildMEDSubConnectivityOfOneTypesPolyh(conn,connIndex,families,conn4MEDFile,connIndex4MEDFile,connIndexRk24MEDFile,fam4MEDFile,renumber);
01821     }
01822 }
01823   
01830 MEDCouplingUMesh *MEDLoaderNS::readUMeshFromFileLev1(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector<int>& ids,
01831                                                      const std::vector<INTERP_KERNEL::NormalizedCellType>& typesToKeep, unsigned& meshDimExtract, int *&cellRenum) throw(INTERP_KERNEL::Exception)
01832 {
01833   if(meshDimRelToMax>0)
01834     throw INTERP_KERNEL::Exception("meshDimRelToMax must be <=0 !");
01835   //Extraction data from MED file.
01836   med_idt fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
01837   std::string trueMeshName;
01838   med_int mid=getIdFromMeshName(fid,meshName,trueMeshName);
01839   DataArrayDouble *coords=0;
01840   std::list<MEDLoader::MEDConnOfOneElemType> conn;
01841   std::string descr;
01842   readUMeshDataInMedFile(fid,mid,coords,conn,descr);
01843   meshDimExtract=MEDLoaderNS::calculateHighestMeshDim<MEDLoader::MEDConnOfOneElemType>(conn);
01844   meshDimExtract=meshDimExtract+meshDimRelToMax;
01845   MEDLoaderNS::keepSpecifiedMeshDim<MEDLoader::MEDConnOfOneElemType>(conn,meshDimExtract);
01846   MEDLoaderNS::keepTypes<MEDLoader::MEDConnOfOneElemType>(conn,typesToKeep);
01847   MEDfileClose(fid);
01848   //Put data in returned data structure.
01849   MEDCouplingUMesh *ret=MEDCouplingUMesh::New();
01850   ret->setName(trueMeshName.c_str());
01851   ret->setDescription(descr.c_str());
01852   ret->setMeshDimension(meshDimExtract);
01853   //
01854   ret->setCoords(coords);
01855   coords->decrRef();
01856   //
01857   DataArrayInt *connArr,*connIndexArr;
01858   tradMEDFileCoreFrmt2MEDCouplingUMesh(conn,ids,connArr,connIndexArr,cellRenum);
01859   ret->setConnectivity(connArr,connIndexArr);
01860   //clean-up
01861   if(connArr)
01862     connArr->decrRef();
01863   if(connIndexArr)
01864     connIndexArr->decrRef();
01865   releaseMEDFileCoreFrmt<MEDLoader::MEDConnOfOneElemType>(conn);
01866   return ret;
01867 }
01868 
01869 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoaderNS::readFieldDoubleLev2(const char *fileName, ParaMEDMEM::TypeOfField typeOfOutField, unsigned meshDim, const int *cellRenum, const ParaMEDMEM::MEDCouplingUMesh *mesh,
01870                                                                      const std::vector<std::string>& infos, const char *fieldName, int iteration, int order, double time,
01871                                                                      std::list<MEDLoader::MEDFieldDoublePerCellType>& fieldPerCellType) throw(INTERP_KERNEL::Exception)
01872 {
01873   if(typeOfOutField==ON_CELLS || typeOfOutField==ON_GAUSS_PT || typeOfOutField==ON_GAUSS_NE)
01874     MEDLoaderNS::keepSpecifiedMeshDim<MEDLoader::MEDFieldDoublePerCellType>(fieldPerCellType,meshDim);
01875   if(fieldPerCellType.empty())
01876     {
01877       std::ostringstream oss; oss << "Error on reading file \"" << fileName << "\" meshName=\"" << mesh->getName();
01878       oss << std::endl << "FieldName=\"" << fieldName << "\" (iteration=" << iteration << ",order=" << order << ")" << std::endl;
01879       if(typeOfOutField==ON_CELLS || typeOfOutField==ON_GAUSS_PT || typeOfOutField==ON_GAUSS_NE)
01880         oss << "Request for cell field, maybe it is an ON_NODES field ?";
01881       else
01882         oss << "Request for a node field, maybe it is an ON_CELLS field ?";
01883       throw INTERP_KERNEL::Exception(oss.str().c_str());
01884     }
01885   //for profiles
01886   ParaMEDMEM::MEDCouplingUMesh *newMesh=0;
01887   std::string mName(mesh->getName());
01888   for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=fieldPerCellType.begin();iter!=fieldPerCellType.end();iter++)
01889     {
01890       const std::vector<int>& cellIds=(*iter).getCellIdPerType();
01891       if(!cellIds.empty())
01892         {
01893           std::vector<int> ci(cellIds.size());
01894           std::transform(cellIds.begin(),cellIds.end(),ci.begin(),std::bind2nd(std::plus<int>(),-1));
01895           ParaMEDMEM::MEDCouplingUMesh *mesh2=0;
01896           if(typeOfOutField==ON_CELLS)
01897             {
01898               if(newMesh)
01899                 mesh2=newMesh->keepSpecifiedCells((*iter).getType(),&ci[0],&ci[0]+ci.size());
01900               else
01901                 mesh2=mesh->keepSpecifiedCells((*iter).getType(),&ci[0],&ci[0]+ci.size());
01902             }
01903           else if(typeOfOutField==ON_NODES)
01904             {
01905               DataArrayInt *da=0,*da2=0;
01906               if(newMesh)
01907                 {
01908                   if((int)ci.size()!=newMesh->getNumberOfNodes())
01909                     {
01910                       da=newMesh->getCellIdsFullyIncludedInNodeIds(&ci[0],&ci[ci.size()]);
01911                       mesh2=dynamic_cast<MEDCouplingUMesh *>(newMesh->buildPartAndReduceNodes(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems(),da2));
01912                     }
01913                 }
01914               else
01915                 {
01916                   if((int)ci.size()!=mesh->getNumberOfNodes())
01917                     {
01918                       da=mesh->getCellIdsFullyIncludedInNodeIds(&ci[0],&ci[ci.size()]);
01919                       mesh2=dynamic_cast<MEDCouplingUMesh *>(mesh->buildPartAndReduceNodes(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems(),da2));
01920                       //
01921                       int nnodes=mesh2->getNumberOfNodes();
01922                       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=DataArrayInt::New();
01923                       const int *da2Ptr=da2->getConstPointer();
01924                       da3->alloc(nnodes,1);
01925                       int *da3Ptr=da3->getPointer();
01926                       for(int i=0;i<(int)ci.size();i++)
01927                         {
01928                           int val=da2Ptr[ci[i]];
01929                           if(val!=-1)
01930                             da3Ptr[val]=i;
01931                         }
01932                       mesh2->renumberNodes(da3->getConstPointer(),nnodes);
01933                     }
01934                   else
01935                     {
01936                       mesh2=mesh->clone(true);
01937                       da=DataArrayInt::New();
01938                       da->alloc((int)ci.size(),1);
01939                       std::copy(ci.begin(),ci.end(),da->getPointer());
01940                       da2=da->invertArrayO2N2N2O(ci.size());
01941                       mesh2->renumberNodes(da2->getConstPointer(),(int)ci.size());
01942                     }
01943                 }
01944               if(da)
01945                 da->decrRef();
01946               if(da2)
01947                 da2->decrRef();
01948             }
01949           if(newMesh)
01950             newMesh->decrRef();
01951           newMesh=mesh2;
01952         }
01953     }
01954   //
01955   ParaMEDMEM::MEDCouplingFieldDouble *ret=ParaMEDMEM::MEDCouplingFieldDouble::New(typeOfOutField,ONE_TIME);
01956   ret->setName(fieldName);
01957   ret->setTime(time,iteration,order);
01958   if(newMesh)
01959     {
01960       newMesh->setName(mName.c_str());//retrieving mesh name to avoid renaming due to mesh restriction in case of profile.
01961       ret->setMesh(newMesh);
01962       newMesh->decrRef();
01963     }
01964   else
01965     ret->setMesh(mesh);
01966   ParaMEDMEM::DataArrayDouble *arr=buildArrayFromRawData(fieldPerCellType,infos);
01967   ret->setArray(arr);
01968   arr->decrRef();
01969   //
01970   if(typeOfOutField==ON_GAUSS_PT)
01971     fillGaussDataOnField(fileName,fieldPerCellType,ret);
01972   if(cellRenum)
01973     ret->renumberCellsWithoutMesh(cellRenum,true);
01974   return ret;
01975 }
01976 
01977 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoaderNS::readFieldDoubleLev1(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order,
01978                                                                      ParaMEDMEM::TypeOfField typeOfOutField) throw(INTERP_KERNEL::Exception)
01979 {
01980   std::list<MEDLoader::MEDFieldDoublePerCellType> fieldPerCellType;
01981   double time;
01982   std::vector<std::string> infos;
01983   readFieldDoubleDataInMedFile(fileName,meshName,fieldName,iteration,order,typeOfOutField,fieldPerCellType,time,infos);
01984   std::vector<int> familiesToKeep;
01985   std::vector<INTERP_KERNEL::NormalizedCellType> typesToKeep;
01986   if(typeOfOutField==ON_CELLS || typeOfOutField==ON_GAUSS_PT || typeOfOutField==ON_GAUSS_NE)
01987     for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=fieldPerCellType.begin();iter!=fieldPerCellType.end();iter++)
01988       typesToKeep.push_back((*iter).getType());
01989   unsigned meshDim;
01990   int *cellRenum;
01991   if(fieldPerCellType.empty())
01992     {
01993       std::ostringstream oss; oss << "Error on reading file \"" << fileName << "\" meshName=\"" << meshName << "\" meshDimRelToMax=" << meshDimRelToMax;
01994       oss << std::endl << "FieldName=\"" << fieldName << "\" (iteration=" << iteration << ",order=" << order << ")" << std::endl;
01995       if(typeOfOutField==ON_CELLS || typeOfOutField==ON_GAUSS_PT || typeOfOutField==ON_GAUSS_NE)
01996         oss << "Request for cell field, maybe it is a node instead or by changing meshDimRelToMax ?";
01997       else
01998         oss << "Request for a node field, maybe it is a cell field instead ?";
01999       throw INTERP_KERNEL::Exception(oss.str().c_str());
02000       }
02001   MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingUMesh> mesh=readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim,cellRenum);
02002   ParaMEDMEM::MEDCouplingFieldDouble *ret=readFieldDoubleLev2(fileName,typeOfOutField,meshDim,cellRenum,mesh,infos,fieldName,iteration,order,time,fieldPerCellType);
02003   if(cellRenum)
02004     mesh->renumberCells(cellRenum,true);
02005   //clean-up
02006   delete [] cellRenum;
02007   releaseMEDFileCoreFrmt<MEDLoader::MEDFieldDoublePerCellType>(fieldPerCellType);
02008   return ret;
02009 }
02010 
02012 
02013 MEDCouplingUMesh *MEDLoader::ReadUMeshFromFile(const char *fileName, const char *meshName, int meshDimRelToMax) throw(INTERP_KERNEL::Exception)
02014 {
02015   CheckFileForRead(fileName);
02016   std::vector<int> familiesToKeep;
02017   std::vector<INTERP_KERNEL::NormalizedCellType> typesToKeep;
02018   unsigned meshDim;
02019   int *cellRenum;
02020   ParaMEDMEM::MEDCouplingUMesh *ret=MEDLoaderNS::readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim,cellRenum);
02021   if(cellRenum)
02022     {
02023       ret->renumberCells(cellRenum,true);
02024       delete [] cellRenum;
02025     }
02026   return ret;
02027 }
02028 
02029 ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFile(const char *fileName, int meshDimRelToMax) throw(INTERP_KERNEL::Exception)
02030 {
02031   CheckFileForRead(fileName);
02032   std::vector<int> familiesToKeep;
02033   std::vector<INTERP_KERNEL::NormalizedCellType> typesToKeep;
02034   unsigned meshDim;
02035   int *cellRenum;
02036   ParaMEDMEM::MEDCouplingUMesh *ret=MEDLoaderNS::readUMeshFromFileLev1(fileName,0,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim,cellRenum);
02037   if(cellRenum)
02038     {
02039       ret->renumberCells(cellRenum,true);
02040       delete [] cellRenum;
02041     }
02042   return ret;
02043 }
02044 
02045 int MEDLoader::ReadUMeshDimFromFile(const char *fileName, const char *meshName) throw(INTERP_KERNEL::Exception)
02046 {
02047   CheckFileForRead(fileName);
02048   std::vector<int> poss;
02049   return MEDLoaderNS::readUMeshDimFromFile(fileName,meshName,poss);
02050 }
02051 
02052 ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromFamilies(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector<std::string>& fams) throw(INTERP_KERNEL::Exception)
02053 {
02054   CheckFileForRead(fileName);
02055   std::vector<int> familiesToKeep=MEDLoaderNS::getIdsFromFamilies(fileName,meshName,fams);
02056   std::vector<INTERP_KERNEL::NormalizedCellType> typesToKeep;
02057   unsigned meshDim;
02058   int *cellRenum;
02059   ParaMEDMEM::MEDCouplingUMesh *ret=MEDLoaderNS::readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim,cellRenum);
02060   if(fams.size()==1)
02061     ret->setName(fams.back().c_str());
02062   if(cellRenum)
02063     {
02064       ret->renumberCells(cellRenum,true);
02065       delete [] cellRenum;
02066     }
02067   return ret;
02068 }
02069 
02070 ParaMEDMEM::MEDCouplingUMesh *MEDLoader::ReadUMeshFromGroups(const char *fileName, const char *meshName, int meshDimRelToMax, const std::vector<std::string>& grps) throw(INTERP_KERNEL::Exception)
02071 {
02072   CheckFileForRead(fileName);
02073   std::vector<int> familiesToKeep=MEDLoaderNS::getIdsFromGroups(fileName,meshName,grps);
02074   std::vector<INTERP_KERNEL::NormalizedCellType> typesToKeep;
02075   unsigned meshDim;
02076   int *cellRenum;
02077   ParaMEDMEM::MEDCouplingUMesh *ret=MEDLoaderNS::readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim,cellRenum);
02078   if(grps.size()==1)
02079     ret->setName(grps.back().c_str());
02080   if(cellRenum)
02081     {
02082       ret->renumberCells(cellRenum,true);
02083       delete [] cellRenum;
02084     }
02085   return ret;
02086 }
02087 
02088 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadField(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
02089 {
02090   CheckFileForRead(fileName);
02091   switch(type)
02092     {
02093     case ON_CELLS:
02094       return ReadFieldCell(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
02095     case ON_NODES:
02096       return ReadFieldNode(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
02097     case ON_GAUSS_PT:
02098       return ReadFieldGauss(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
02099     case ON_GAUSS_NE:
02100       return ReadFieldGaussNE(fileName,meshName,meshDimRelToMax,fieldName,iteration,order);
02101     default:
02102       throw INTERP_KERNEL::Exception("Type of field specified not managed ! manages are ON_NODES, ON_CELLS, ON_GAUSS_PT or ON_GAUSS_NE !");
02103     } 
02104 }
02105 
02106 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsOnSameMesh(ParaMEDMEM::TypeOfField type, const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName,
02107                                                                                   const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
02108 {
02109   if(its.empty())
02110     return std::vector<ParaMEDMEM::MEDCouplingFieldDouble *>();
02111   CheckFileForRead(fileName);
02112   std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> ret(its.size());
02113   if(its.empty())
02114     return ret;
02115   //Retrieving mesh of rank 0 and field on rank 0 too.
02116   std::list<MEDLoader::MEDFieldDoublePerCellType> fieldPerCellType;
02117   double time;
02118   std::vector<std::string> infos;
02119   MEDLoaderNS::readFieldDoubleDataInMedFile(fileName,meshName,fieldName,its[0].first,its[0].second,type,fieldPerCellType,time,infos);
02120   std::vector<int> familiesToKeep;
02121   std::vector<INTERP_KERNEL::NormalizedCellType> typesToKeep;
02122   if(type==ON_CELLS || type==ON_GAUSS_PT || type==ON_GAUSS_NE)
02123     for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=fieldPerCellType.begin();iter!=fieldPerCellType.end();iter++)
02124       typesToKeep.push_back((*iter).getType());
02125   unsigned meshDim;
02126   int *cellRenum;
02127   MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingUMesh> m1=MEDLoaderNS::readUMeshFromFileLev1(fileName,meshName,meshDimRelToMax,familiesToKeep,typesToKeep,meshDim,cellRenum);
02128   ret[0]=MEDLoaderNS::readFieldDoubleLev2(fileName,type,meshDim,cellRenum,m1,infos,fieldName,its[0].first,its[0].second,time,fieldPerCellType);
02129   if(cellRenum)
02130     m1->renumberCells(cellRenum,true);
02131   MEDLoaderNS::releaseMEDFileCoreFrmt<MEDLoader::MEDFieldDoublePerCellType>(fieldPerCellType);
02132   //
02133   for(int itId=1;itId<(int)its.size();itId++)
02134     {
02135       std::list<MEDLoader::MEDFieldDoublePerCellType> fieldPerCellType2;
02136       double timmee;
02137       std::vector<std::string> infoss;
02138       MEDLoaderNS::readFieldDoubleDataInMedFile(fileName,meshName,fieldName,its[itId].first,its[itId].second,type,fieldPerCellType2,timmee,infoss);
02139       ret[itId]=MEDLoaderNS::readFieldDoubleLev2(fileName,type,meshDim,cellRenum,m1,infoss,fieldName,its[itId].first,its[itId].second,timmee,fieldPerCellType2);
02140       //clean-up
02141       MEDLoaderNS::releaseMEDFileCoreFrmt<MEDLoader::MEDFieldDoublePerCellType>(fieldPerCellType2);
02142     }
02143   delete [] cellRenum;
02144   return ret;
02145 }
02146 
02147 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsCellOnSameMesh(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName,
02148                                                                                             const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
02149 {
02150   return ReadFieldsOnSameMesh(ON_CELLS,fileName,meshName,meshDimRelToMax,fieldName,its);
02151 }
02152 
02153 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsNodeOnSameMesh(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName,
02154                                                                                       const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
02155 {
02156   return ReadFieldsOnSameMesh(ON_NODES,fileName,meshName,meshDimRelToMax,fieldName,its);
02157 }
02158 
02159 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsGaussOnSameMesh(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName,
02160                                                                                        const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
02161 {
02162   return ReadFieldsOnSameMesh(ON_GAUSS_PT,fileName,meshName,meshDimRelToMax,fieldName,its);
02163 }
02164 
02165 std::vector<ParaMEDMEM::MEDCouplingFieldDouble *> MEDLoader::ReadFieldsGaussNEOnSameMesh(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName,
02166                                                                                          const std::vector<std::pair<int,int> >& its) throw(INTERP_KERNEL::Exception)
02167 {
02168   return ReadFieldsOnSameMesh(ON_GAUSS_NE,fileName,meshName,meshDimRelToMax,fieldName,its);
02169 }
02170 
02171 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldCell(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
02172 {
02173   return MEDLoaderNS::readFieldDoubleLev1(fileName,meshName,meshDimRelToMax,fieldName,iteration,order,ON_CELLS);
02174 }
02175 
02176 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldNode(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
02177 {
02178   return MEDLoaderNS::readFieldDoubleLev1(fileName,meshName,meshDimRelToMax,fieldName,iteration,order,ON_NODES);
02179 }
02180 
02181 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldGauss(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
02182 {
02183   return MEDLoaderNS::readFieldDoubleLev1(fileName,meshName,meshDimRelToMax,fieldName,iteration,order,ON_GAUSS_PT);
02184 }
02185 
02186 ParaMEDMEM::MEDCouplingFieldDouble *MEDLoader::ReadFieldGaussNE(const char *fileName, const char *meshName, int meshDimRelToMax, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception)
02187 {
02188   return MEDLoaderNS::readFieldDoubleLev1(fileName,meshName,meshDimRelToMax,fieldName,iteration,order,ON_GAUSS_NE);
02189 }
02190 
02195 void MEDLoaderNS::writeUMeshesDirectly(const char *fileName, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& mesh, const std::vector<const DataArrayInt *>& families, bool forceFromScratch, bool &isRenumbering)
02196 {
02197   med_idt fid=MEDfileOpen(fileName,forceFromScratch?MED_ACC_CREAT:MED_ACC_RDWR);
02198   std::string meshName(mesh[0]->getName());
02199   if(meshName=="")
02200     {
02201       MEDfileClose(fid);
02202       throw INTERP_KERNEL::Exception("MEDCouplingMesh must have a not null name !");
02203     }
02204   isRenumbering=false;
02205   bool isFamilies=true;
02206   std::vector<const DataArrayInt *> conn;
02207   std::vector<const DataArrayInt *> connIndex;
02208   std::set<INTERP_KERNEL::NormalizedCellType> allTypes;
02209   for(std::vector<const ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=mesh.begin();iter!=mesh.end();iter++)
02210     {
02211       isRenumbering|=!(*iter)->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_N_CELL_FIXED_GEO);
02212       isFamilies&=(families[std::distance(mesh.begin(),iter)]!=0);
02213       conn.push_back((*iter)->getNodalConnectivity());
02214       connIndex.push_back((*iter)->getNodalConnectivityIndex());
02215       const std::set<INTERP_KERNEL::NormalizedCellType>& curTypes=(*iter)->getAllTypes();
02216       allTypes.insert(curTypes.begin(),curTypes.end());
02217     }
02218   INTERP_KERNEL::AutoPtr<char> maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
02219   INTERP_KERNEL::AutoPtr<char> desc=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
02220   MEDLoaderBase::safeStrCpy(meshName.c_str(),MED_NAME_SIZE,maa,MEDLoader::_TOO_LONG_STR);
02221   MEDLoaderBase::safeStrCpy(mesh[0]->getDescription(),MED_COMMENT_SIZE,desc,MEDLoader::_TOO_LONG_STR);
02222   const int spaceDim=mesh[0]->getSpaceDimension();
02223   const int meshDim=mesh[0]->getMeshDimension();
02224   const DataArrayDouble *arr=mesh[0]->getCoords();
02225   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE);
02226   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE);
02227   for(int i=0;i<spaceDim;i++)
02228     {
02229       std::string info=arr->getInfoOnComponent(i);
02230       std::string c,u;
02231       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
02232       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE-1,comp+i*MED_SNAME_SIZE,MEDLoader::_TOO_LONG_STR);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
02233       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE-1,unit+i*MED_SNAME_SIZE,MEDLoader::_TOO_LONG_STR);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
02234     }
02235   MEDmeshCr(fid,maa,spaceDim,meshDim,MED_UNSTRUCTURED_MESH,desc,"",MED_SORT_DTIT,MED_CARTESIAN,comp,unit);
02236   for(std::vector<const ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=mesh.begin();iter!=mesh.end();iter++)
02237     {
02238       for(int i=0;i<MED_N_CELL_FIXED_GEO;i++)
02239         {
02240           med_geometry_type curMedType=typmai[i];
02241           INTERP_KERNEL::NormalizedCellType curType=typmai2[i];
02242           if(allTypes.find(curType)!=allTypes.end())
02243             {
02244               std::vector<int> medConn;
02245               std::vector<int> medConnIndex;
02246               std::vector<int> medConnIndex2;
02247               std::vector<int> fam;
02248               std::vector<int> renumber;
02249               int nbOfElt=MEDLoaderNS::buildMEDSubConnectivityOfOneType(conn,connIndex,families,curType,medConn,medConnIndex,medConnIndex2,fam,renumber);
02250               if(curMedType!=MED_POLYGON && curMedType!=MED_POLYHEDRON)
02251                 MEDmeshElementConnectivityWr(fid,maa,-1,-1,0.,MED_CELL,curMedType,MED_NODAL,MED_FULL_INTERLACE,nbOfElt,&medConn[0]);
02252               else
02253                 {
02254                   if(curMedType==MED_POLYGON)
02255                     MEDmeshPolygonWr(fid,maa,-1,-1,0.,MED_CELL,MED_NODAL,medConnIndex.size(),&medConnIndex[0],&medConn[0]);
02256                   if(curMedType==MED_POLYHEDRON)
02257                     {
02258                       MEDmeshPolyhedronWr(fid,maa,-1,-1,0.,MED_CELL,MED_NODAL,medConnIndex2.size(),&medConnIndex2[0],medConnIndex.size(),&medConnIndex[0],
02259                                          &medConn[0]);
02260                     }
02261                 }
02262               if(isFamilies)
02263                 MEDmeshEntityFamilyNumberWr(fid,maa,-1,-1,MED_CELL,curMedType,nbOfElt,&fam[0]);
02264               if(isRenumbering)
02265                 MEDmeshEntityNumberWr(fid,maa,-1,-1,MED_CELL,curMedType,nbOfElt,&renumber[0]);
02266             }
02267         }
02268     }
02269   char familyName[MED_NAME_SIZE+1];
02270   std::fill(familyName,familyName+MED_NAME_SIZE+1,'\0');
02271   const char DftFamilyName[]="DftFamily";
02272   std::copy(DftFamilyName,DftFamilyName+sizeof(DftFamilyName),familyName);
02273   MEDfamilyCr(fid,maa,familyName,0,0,0);
02274   
02275   MEDmeshNodeCoordinateWr(fid,maa,-1,-1,0.,MED_FULL_INTERLACE,mesh[0]->getNumberOfNodes(),arr->getConstPointer());
02276   MEDfileClose(fid);
02277 }
02278 
02283 void MEDLoaderNS::writeUMeshesPartitionDirectly(const char *fileName, const char *meshName, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool forceFromScratch)
02284 {
02285   std::string meshNameCpp(meshName);
02286   INTERP_KERNEL::AutoPtr<char> maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
02287   MEDLoaderBase::safeStrCpy(meshName,MED_NAME_SIZE,maa,MEDLoader::_TOO_LONG_STR);
02288   if(meshNameCpp=="")
02289     throw INTERP_KERNEL::Exception("writeUMeshesPartitionDirectly : Invalid meshName : Must be different from \"\" !");
02290   std::vector< DataArrayInt * > corr;
02291   MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=ParaMEDMEM::MEDCouplingUMesh::FuseUMeshesOnSameCoords(meshes,0,corr);
02292   m->setName(meshName);
02293   std::vector< std::vector<int> > fidsOfGroups;
02294   std::vector< const DataArrayInt * > corr2(corr.begin(),corr.end());
02295   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr2=DataArrayInt::MakePartition(corr2,m->getNumberOfCells(),fidsOfGroups);
02296   for(std::vector< DataArrayInt * >::iterator it=corr.begin();it!=corr.end();it++)
02297     (*it)->decrRef();
02298   bool isRenumbering;
02299   std::vector<const MEDCouplingUMesh *> mv(1); mv[0]=m;
02300   std::vector<const DataArrayInt *> famv(1); famv[0]=arr2;
02301   writeUMeshesDirectly(fileName,mv,famv,forceFromScratch,isRenumbering);
02302   // families creation
02303   std::set<int> familyIds;
02304   for(std::vector< std::vector<int> >::const_iterator it1=fidsOfGroups.begin();it1!=fidsOfGroups.end();it1++)
02305     for(std::vector<int>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
02306       familyIds.insert(*it2);
02307   std::vector< std::vector<int> > gidsOfFamilies(familyIds.size());
02308   int fid=0;
02309   for(std::set<int>::const_iterator it=familyIds.begin();it!=familyIds.end();it++,fid++)
02310     {
02311       int gid=0;
02312       for(std::vector< std::vector<int> >::const_iterator it1=fidsOfGroups.begin();it1!=fidsOfGroups.end();it1++,gid++)
02313         for(std::vector<int>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
02314           if(*it2==*it)
02315             gidsOfFamilies[fid].push_back(gid);
02316     }
02317   fid=0;
02318   med_idt fid2=MEDfileOpen(fileName,MED_ACC_RDWR);
02319   for(std::set<int>::const_iterator it=familyIds.begin();it!=familyIds.end();it++,fid++)
02320     {
02321       int ngro=gidsOfFamilies[fid].size();
02322       INTERP_KERNEL::AutoPtr<char> groName=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE*ngro);
02323       for(int i=0;i<ngro;i++)
02324         MEDLoaderBase::safeStrCpy2(meshes[gidsOfFamilies[fid][i]]->getName(),MED_LNAME_SIZE-1,groName+i*MED_LNAME_SIZE,MEDLoader::_TOO_LONG_STR);//MED_LNAME_SIZE-1 to avoid to write '\0' on next compo
02325       std::ostringstream oss; oss << "Family_" << *it;
02326       INTERP_KERNEL::AutoPtr<char> famName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
02327       MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_NAME_SIZE,famName,MEDLoader::_TOO_LONG_STR);
02328       MEDfamilyCr(fid2,maa,famName,*it,ngro,groName);
02329     }
02330   MEDfileClose(fid2);
02331 }
02332 
02337 void MEDLoaderNS::appendNodeProfileField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *thisMeshNodeIds)
02338 {
02339   med_int numdt,numo;
02340   med_float dt;
02341   INTERP_KERNEL::AutoPtr<char> nommaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
02342   MEDLoaderBase::safeStrCpy(f->getMesh()->getName(),MED_NAME_SIZE,nommaa,MEDLoader::_TOO_LONG_STR);
02343   med_idt fid=appendFieldSimpleAtt(fileName,f,numdt,numo,dt);
02344   int nbOfNodes=f->getMesh()->getNumberOfNodes();
02345   const double *pt=f->getArray()->getConstPointer();
02346   INTERP_KERNEL::AutoPtr<int> profile=new int[nbOfNodes];
02347   std::ostringstream oss; oss << "Pfln" << f->getName();
02348   INTERP_KERNEL::AutoPtr<char> profileName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
02349   MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_NAME_SIZE,profileName,MEDLoader::_TOO_LONG_STR);
02350   std::transform(thisMeshNodeIds,thisMeshNodeIds+nbOfNodes,(int *)profile,std::bind2nd(std::plus<int>(),1));
02351   MEDprofileWr(fid,profileName,nbOfNodes,profile);
02352   MEDfieldValueWithProfileWr(fid,f->getName(),numdt,numo,dt,MED_NODE,MED_NONE,MED_COMPACT_PFLMODE,profileName,MED_NO_LOCALIZATION,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nbOfNodes,(const unsigned char*)pt);
02353   MEDfileClose(fid);
02354 }
02355 
02360 void MEDLoaderNS::appendCellProfileField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *thisMeshCellIdsPerType)
02361 {
02362   med_int numdt,numo;
02363   med_float dt;
02364   int nbComp=f->getNumberOfComponents();
02365   med_idt fid=appendFieldSimpleAtt(fileName,f,numdt,numo,dt);
02366   std::list<MEDLoader::MEDFieldDoublePerCellType> split;
02367   prepareCellFieldDoubleForWriting(f,thisMeshCellIdsPerType,split);
02368   const double *pt=f->getArray()->getConstPointer();
02369   int number=0;
02370   for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=split.begin();iter!=split.end();iter++)
02371     {
02372       INTERP_KERNEL::AutoPtr<char> nommaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
02373       MEDLoaderBase::safeStrCpy(f->getMesh()->getName(),MED_NAME_SIZE,nommaa,MEDLoader::_TOO_LONG_STR);
02374       INTERP_KERNEL::AutoPtr<char> profileName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
02375       std::ostringstream oss; oss << "Pfl" << f->getName() << "_" << number++;
02376       MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_NAME_SIZE,profileName,MEDLoader::_TOO_LONG_STR);
02377       const std::vector<int>& ids=(*iter).getCellIdPerType();
02378       int *profile=new int [ids.size()];
02379       std::transform(ids.begin(),ids.end(),profile,std::bind2nd(std::plus<int>(),1));
02380       MEDprofileWr(fid,profileName,ids.size(),profile);
02381       delete [] profile;
02382       MEDfieldValueWithProfileWr(fid,f->getName(),numdt,numo,dt,MED_CELL,typmai3[(int)(*iter).getType()],MED_COMPACT_PFLMODE,profileName,
02383                                  MED_NO_LOCALIZATION,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,(*iter).getNbOfTuple(),(const unsigned char*)pt);
02384       pt+=(*iter).getNbOfTuple()*nbComp;
02385     }
02386   MEDfileClose(fid);
02387 }
02388 
02389 void MEDLoaderNS::appendNodeElementProfileField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *thisMeshCellIdsPerType)
02390 {
02391   med_int numdt,numo;
02392   med_float dt;
02393   int nbComp=f->getNumberOfComponents();
02394   med_idt fid=appendFieldSimpleAtt(fileName,f,numdt,numo,dt);
02395   std::list<MEDLoader::MEDFieldDoublePerCellType> split;
02396   prepareCellFieldDoubleForWriting(f,thisMeshCellIdsPerType,split);
02397   const double *pt=f->getArray()->getConstPointer();
02398   int number=0;
02399   for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=split.begin();iter!=split.end();iter++)
02400     {
02401       INTERP_KERNEL::AutoPtr<char> nommaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
02402       MEDLoaderBase::safeStrCpy(f->getMesh()->getName(),MED_NAME_SIZE,nommaa,MEDLoader::_TOO_LONG_STR);
02403       INTERP_KERNEL::AutoPtr<char> profileName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
02404       std::ostringstream oss; oss << "Pfl" << f->getName() << "_" << number++;
02405       MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_NAME_SIZE,profileName,MEDLoader::_TOO_LONG_STR);
02406       const std::vector<int>& ids=(*iter).getCellIdPerType();
02407       int *profile=new int [ids.size()];
02408       std::transform(ids.begin(),ids.end(),profile,std::bind2nd(std::plus<int>(),1));
02409       MEDprofileWr(fid,profileName,ids.size(),profile);
02410       delete [] profile;
02411       int nbPtPerCell=(int)INTERP_KERNEL::CellModel::GetCellModel((*iter).getType()).getNumberOfNodes();
02412       int nbOfEntity=f->getMesh()->getNumberOfCellsWithType((*iter).getType());
02413       int nbOfValues=nbPtPerCell*nbOfEntity;
02414       MEDfieldValueWithProfileWr(fid,f->getName(),numdt,numo,dt,MED_NODE_ELEMENT,typmai3[(int)(*iter).getType()],
02415                                  MED_COMPACT_PFLMODE,profileName,
02416                                  MED_NO_LOCALIZATION,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,
02417                                  nbOfEntity,(const unsigned char*)pt);
02418       pt+=nbOfValues*nbComp;
02419     }
02420   MEDfileClose(fid);
02421 }
02422 
02426 med_idt MEDLoaderNS::appendFieldSimpleAtt(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, med_int& numdt, med_int& numo, med_float& dt)
02427 {
02428   std::string fieldName(f->getName());
02429   if(fieldName.empty())
02430     throw INTERP_KERNEL::Exception("MEDLoaderNS::appendFieldSimpleAtt : Trying to store a field with no name ! MED file format requires a NON EMPTY field name !");
02431   med_idt fid=MEDfileOpen(fileName,MED_ACC_RDWR);
02432   int nbComp=f->getNumberOfComponents();
02433   INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
02434   INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(nbComp*MED_SNAME_SIZE);
02435   for(int i=0;i<nbComp;i++)
02436     {
02437       std::string info=f->getArray()->getInfoOnComponent(i);
02438       std::string c,u;
02439       MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
02440       MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE-1,comp+i*MED_SNAME_SIZE,MEDLoader::_TOO_LONG_STR);
02441       MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE-1,unit+i*MED_SNAME_SIZE,MEDLoader::_TOO_LONG_STR);
02442     }
02443   INTERP_KERNEL::AutoPtr<char> dt_unit=MEDLoaderBase::buildEmptyString(MED_SNAME_SIZE);
02444   INTERP_KERNEL::AutoPtr<char> maaname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
02445   INTERP_KERNEL::AutoPtr<char> fname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
02446   MEDLoaderBase::safeStrCpy(f->getName(),MED_NAME_SIZE,fname,MEDLoader::_TOO_LONG_STR);
02447   MEDLoaderBase::safeStrCpy(f->getMesh()->getName(),MED_NAME_SIZE,maaname,MEDLoader::_TOO_LONG_STR);
02448   MEDLoaderBase::safeStrCpy(f->getTimeUnit(),MED_SNAME_SIZE,dt_unit,MEDLoader::_TOO_LONG_STR);
02449   MEDfieldCr(fid,fname,MED_FLOAT64,nbComp,comp,unit,dt_unit,maaname);
02450   ParaMEDMEM::TypeOfTimeDiscretization td=f->getTimeDiscretization();
02451   if(td==ParaMEDMEM::NO_TIME)
02452     {
02453       numdt=MED_NO_DT; numo=MED_NO_IT; dt=0.0;
02454     }
02455   else if(td==ParaMEDMEM::ONE_TIME)
02456     {
02457       int tmp1,tmp2;
02458       double tmp0=f->getTime(tmp1,tmp2);
02459       numdt=(med_int)tmp1; numo=(med_int)tmp2;
02460       dt=(med_float)tmp0;
02461     }
02462   return fid;
02463 }
02464 
02465 void MEDLoaderNS::appendFieldDirectly(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f2)
02466 {
02467   med_int numdt,numo;
02468   med_float dt;
02469   //renumbering
02470   const ParaMEDMEM::MEDCouplingFieldDouble *f=f2;
02471   const MEDCouplingMesh *mesh=f->getMesh();
02472   const MEDCouplingUMesh *meshC=dynamic_cast<const MEDCouplingUMesh *>(mesh);
02473   if(!meshC)
02474     throw INTERP_KERNEL::Exception("Not implemented yet for not unstructured mesh !");
02475   bool renum=!meshC->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_N_CELL_FIXED_GEO);
02476   if(renum)
02477     {
02478       ParaMEDMEM::MEDCouplingFieldDouble *f3=f2->clone(true);
02479       MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=meshC->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_N_CELL_FIXED_GEO);
02480       f3->renumberCells(da->getConstPointer(),false);
02481       f=f3;
02482     }
02483   //end renumbering
02484   int nbComp=f->getNumberOfComponents();
02485   med_idt fid=appendFieldSimpleAtt(fileName,f,numdt,numo,dt);
02486   const double *pt=f->getArray()->getConstPointer();
02487   INTERP_KERNEL::AutoPtr<char> nommaa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
02488   MEDLoaderBase::safeStrCpy(f->getMesh()->getName(),MED_NAME_SIZE,nommaa,MEDLoader::_TOO_LONG_STR);
02489   switch(f->getTypeOfField())
02490     {
02491     case ParaMEDMEM::ON_CELLS:
02492       {
02493         std::list<MEDLoader::MEDFieldDoublePerCellType> split;
02494         prepareCellFieldDoubleForWriting(f,0,split);
02495         for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=split.begin();iter!=split.end();iter++)
02496           {
02497             MEDfieldValueWithProfileWr(fid,f->getName(),numdt,numo,dt,MED_CELL,typmai3[(int)(*iter).getType()],MED_COMPACT_PFLMODE,
02498                                        MED_ALLENTITIES_PROFILE,MED_NO_LOCALIZATION,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,(*iter).getNbOfTuple(),(const unsigned char*)pt);
02499             pt+=(*iter).getNbOfTuple()*nbComp;
02500           }
02501         break;
02502       }
02503     case ParaMEDMEM::ON_NODES:
02504       {
02505         int nbOfTuples=f->getArray()->getNumberOfTuples();
02506         MEDfieldValueWithProfileWr(fid,f->getName(),numdt,numo,dt,MED_NODE,MED_NONE,MED_COMPACT_PFLMODE,
02507                                    MED_ALLENTITIES_PROFILE,MED_NO_LOCALIZATION,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nbOfTuples,(const unsigned char*)pt);
02508         break;
02509       }
02510     case ParaMEDMEM::ON_GAUSS_PT:
02511       {
02512         std::list<MEDLoader::MEDFieldDoublePerCellType> split;
02513         prepareCellFieldDoubleForWriting(f,0,split);
02514         int idGp=0;
02515         for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=split.begin();iter!=split.end();iter++)
02516           {
02517             INTERP_KERNEL::AutoPtr<char> nomGauss=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
02518             std::ostringstream oss; oss << "GP_" << f->getName() << idGp++;
02519             MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_NAME_SIZE,nomGauss,MEDLoader::_TOO_LONG_STR);
02520             int id=f->getGaussLocalizationIdOfOneType((*iter).getType());
02521             const MEDCouplingGaussLocalization& gl=f->getGaussLocalization(id);
02522             MEDlocalizationWr(fid,nomGauss,typmai3[(int)(*iter).getType()],mesh->getMeshDimension(),&gl.getRefCoords()[0],MED_FULL_INTERLACE,
02523                               gl.getNumberOfGaussPt(),&gl.getGaussCoords()[0],&gl.getWeights()[0],MED_NO_INTERPOLATION, MED_NO_MESH_SUPPORT);
02524             int nbOfEntity=f->getMesh()->getNumberOfCellsWithType((*iter).getType());
02525             int nbOfValues=gl.getNumberOfGaussPt()*nbOfEntity;
02526             INTERP_KERNEL::AutoPtr<char> fieldname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
02527             MEDLoaderBase::safeStrCpy(f->getName(),MED_NAME_SIZE,fieldname,MEDLoader::_TOO_LONG_STR);
02528             MEDfieldValueWithProfileWr(fid,fieldname,numdt,numo,dt,MED_CELL,typmai3[(int)(*iter).getType()],MED_COMPACT_PFLMODE,
02529                                        MED_ALLENTITIES_PROFILE,nomGauss,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nbOfEntity,(const unsigned char*)pt);
02530             pt+=nbOfValues*nbComp;
02531           }
02532         break;
02533       }
02534     case ParaMEDMEM::ON_GAUSS_NE:
02535       {
02536         std::list<MEDLoader::MEDFieldDoublePerCellType> split;
02537         prepareCellFieldDoubleForWriting(f,0,split);
02538         for(std::list<MEDLoader::MEDFieldDoublePerCellType>::const_iterator iter=split.begin();iter!=split.end();iter++)
02539           {
02540             int nbPtPerCell=(int)INTERP_KERNEL::CellModel::GetCellModel((*iter).getType()).getNumberOfNodes();
02541             int nbOfEntity=f->getMesh()->getNumberOfCellsWithType((*iter).getType());
02542             int nbOfValues=nbPtPerCell*nbOfEntity;
02543             MEDfieldValueWithProfileWr(fid,f->getName(),numdt,numo,dt,MED_NODE_ELEMENT,typmai3[(int)(*iter).getType()],MED_COMPACT_PFLMODE,
02544                                        MED_ALLENTITIES_PROFILE,MED_NO_LOCALIZATION,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nbOfEntity,(const unsigned char*)pt);
02545             pt+=nbOfValues*nbComp;
02546           }
02547         break;
02548       }
02549     default:
02550       throw INTERP_KERNEL::Exception("Not managed this type of FIELD !");
02551     }
02552   MEDfileClose(fid);
02553   if(renum)
02554     f->decrRef();
02555 }
02556 
02561 void MEDLoaderNS::prepareCellFieldDoubleForWriting(const ParaMEDMEM::MEDCouplingFieldDouble *f, const int *cellIdsPerType, std::list<MEDLoader::MEDFieldDoublePerCellType>& split)
02562 {
02563   int nbComp=f->getNumberOfComponents();
02564   const MEDCouplingMesh *mesh=f->getMesh();
02565   const MEDCouplingUMesh *meshC=dynamic_cast<const MEDCouplingUMesh *>(mesh);
02566   if(!meshC)
02567     throw INTERP_KERNEL::Exception("Not implemented yet for not unstructured mesh !");
02568   if(!meshC->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_N_CELL_FIXED_GEO))
02569     throw INTERP_KERNEL::Exception("Unstructuded mesh has not consecutive cell types !");
02570   const int *connI=meshC->getNodalConnectivityIndex()->getConstPointer();
02571   const int *conn=meshC->getNodalConnectivity()->getConstPointer();
02572   int nbOfCells=meshC->getNumberOfCells();
02573   INTERP_KERNEL::NormalizedCellType curType;
02574   const int *wCellIdsPT=cellIdsPerType;
02575   for(const int *pt=connI;pt!=connI+nbOfCells;)
02576     {
02577       curType=(INTERP_KERNEL::NormalizedCellType)conn[*pt];
02578       const int *pt2=std::find_if(pt+1,connI+nbOfCells,ConnReaderML(conn,(int)curType));
02579       if(!cellIdsPerType)
02580         split.push_back(MEDLoader::MEDFieldDoublePerCellType(curType,0,nbComp,pt2-pt,0,0));
02581       else
02582         {
02583           split.push_back(MEDLoader::MEDFieldDoublePerCellType(curType,0,nbComp,pt2-pt,wCellIdsPT,0));
02584           wCellIdsPT+=std::distance(pt,pt2);
02585         }
02586       pt=pt2;
02587     }
02588 }
02589 
02590 void MEDLoaderNS::writeFieldAndMeshDirectly(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool forceFromScratch)
02591 {
02592   f->checkCoherency();
02593   std::string meshName(f->getMesh()->getName());
02594   if(meshName.empty())
02595     throw INTERP_KERNEL::Exception("Trying to write a mesh (f->getMesh()) with no name ! MED file format needs a not empty mesh name !");
02596   std::string fieldName(f->getName());
02597   if(fieldName.empty())
02598     throw INTERP_KERNEL::Exception("Trying to write a field with no name ! MED file format needs a not empty field name !");
02599   MEDCouplingUMesh *mesh=dynamic_cast<MEDCouplingUMesh *>(const_cast<MEDCouplingMesh *>(f->getMesh()));
02600   if(mesh)
02601     {
02602       bool isRenumbering;
02603       std::vector<const MEDCouplingUMesh *> meshV(1); meshV[0]=mesh;
02604       std::vector<const DataArrayInt *> famV(1); famV[0]=0;
02605       writeUMeshesDirectly(fileName,meshV,famV,forceFromScratch,isRenumbering);
02606       if(isRenumbering)
02607         {
02608           MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> f2=f->clone(true);
02609           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=mesh->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_N_CELL_FIXED_GEO);
02610           f2->renumberCells(da->getConstPointer(),false);
02611           appendFieldDirectly(fileName,f2);
02612         }
02613       else
02614         appendFieldDirectly(fileName,f);
02615       return ;
02616     }
02617   throw INTERP_KERNEL::Exception("The mesh underlying field is not unstructured ! Only unstructured mesh supported for writting now !");
02618 }
02619 
02626 void MEDLoaderNS::writeFieldTryingToFitExistingMesh(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f)
02627 {
02628   std::vector<int> poss;
02629   int mDimInFile=MEDLoaderNS::readUMeshDimFromFile(fileName,f->getMesh()->getName(),poss);
02630   int mdim=f->getMesh()->getMeshDimension();
02631   int f2=mdim-mDimInFile;
02632   if(std::find(poss.begin(),poss.end(),f2)==poss.end())
02633     {
02634       std::ostringstream oss; oss << "Trying to fit with the existing \"" << f->getMesh()->getName() << "mesh in file \"" << fileName;
02635       oss << "\" but meshdimension does not match !";
02636       throw INTERP_KERNEL::Exception(oss.str().c_str());
02637     }
02638   MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=MEDLoader::ReadUMeshFromFile(fileName,f->getMesh()->getName(),f2);
02639   MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m2=MEDCouplingUMesh::MergeUMeshes(m,(MEDCouplingUMesh *)f->getMesh());
02640   bool areNodesMerged;
02641   int newNbOfNodes;
02642   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=m2->mergeNodes(MEDLoader::_EPS_FOR_NODE_COMP,areNodesMerged,newNbOfNodes);
02643   if(!areNodesMerged || newNbOfNodes!=m->getNumberOfNodes())
02644     {
02645       std::ostringstream oss; oss << "Nodes in already written mesh \"" << f->getMesh()->getName() << "\" in file \"" << fileName << "\" does not fit coordinates of unstructured grid f->getMesh() !";
02646       throw INTERP_KERNEL::Exception(oss.str().c_str());
02647     }
02648   switch(f->getTypeOfField())
02649     {
02650     case ParaMEDMEM::ON_CELLS:
02651       {
02652         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=m2->zipConnectivityTraducer(MEDLoader::_COMP_FOR_CELL);
02653         if(m2->getNumberOfCells()!=m->getNumberOfCells())
02654           {
02655             std::ostringstream oss1; oss1 << "Cells in already written mesh \"" << f->getMesh()->getName() << "\" in file \"" << fileName << "\" does not fit connectivity of unstructured grid f->getMesh() !";
02656             throw INTERP_KERNEL::Exception(oss1.str().c_str());
02657           }
02658         da=m2->convertCellArrayPerGeoType(da2);
02659         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da->substr(m2->getNumberOfCells());
02660         da2=m2->convertCellArrayPerGeoType(da3);
02661         appendCellProfileField(fileName,f,da2->getConstPointer());
02662         break;
02663       }
02664     case ParaMEDMEM::ON_GAUSS_NE:
02665       {
02666         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da2=m2->zipConnectivityTraducer(MEDLoader::_COMP_FOR_CELL);
02667         if(m2->getNumberOfCells()!=m->getNumberOfCells())
02668           {
02669             std::ostringstream oss1; oss1 << "Cells in already written mesh \"" << f->getMesh()->getName() << "\" in file \"" << fileName << "\" does not fit connectivity of unstructured grid f->getMesh() !";
02670             throw INTERP_KERNEL::Exception(oss1.str().c_str());
02671           }
02672         da=m2->convertCellArrayPerGeoType(da2);
02673         MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da3=da->substr(m2->getNumberOfCells());
02674         da2=m2->convertCellArrayPerGeoType(da3);
02675         appendNodeElementProfileField(fileName,f,da2->getConstPointer());
02676         break;
02677       }
02678     case ParaMEDMEM::ON_NODES:
02679       {
02680         appendNodeProfileField(fileName,f,da->getConstPointer()+m->getNumberOfNodes());
02681         break;
02682       }
02683     default:
02684       {
02685         throw INTERP_KERNEL::Exception("Not implemented other profile fitting from already written mesh for fields than on NODES and on CELLS.");
02686       }
02687     }
02688 }
02689 
02690 void MEDLoader::WriteUMesh(const char *fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
02691 {
02692   std::string meshName(mesh->getName());
02693   if(meshName.empty())
02694     throw INTERP_KERNEL::Exception("Trying to write a unstructured mesh with no name ! MED file format needs a not empty mesh name !");
02695   int status=MEDLoaderBase::getStatusOfFile(fileName);
02696   bool isRenumbering;
02697   if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
02698     {
02699       std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
02700       throw INTERP_KERNEL::Exception(oss.str().c_str());
02701     }
02702   std::vector<const ParaMEDMEM::MEDCouplingUMesh *> meshV(1); meshV[0]=mesh;
02703   std::vector<const ParaMEDMEM::DataArrayInt *> famV(1); famV[0]=0;
02704   if(writeFromScratch)
02705     {
02706       MEDLoaderNS::writeUMeshesDirectly(fileName,meshV,famV,true,isRenumbering);
02707       return ;
02708     }
02709   if(status==MEDLoaderBase::NOT_EXIST)
02710     {
02711       MEDLoaderNS::writeUMeshesDirectly(fileName,meshV,famV,true,isRenumbering);
02712       return;
02713     }
02714   else
02715     {
02716       std::vector<std::string> meshNames=GetMeshNames(fileName);
02717       if(std::find(meshNames.begin(),meshNames.end(),meshName)==meshNames.end())
02718         MEDLoaderNS::writeUMeshesDirectly(fileName,meshV,famV,false,isRenumbering);
02719       else
02720         {
02721           std::ostringstream oss; oss << "File \'" << fileName << "\' already exists and has already a mesh called \"";
02722           oss << meshName << "\" !";
02723           throw INTERP_KERNEL::Exception(oss.str().c_str());
02724         }
02725     }
02726 }
02727 
02728 void MEDLoader::WriteUMeshDep(const char *fileName, const ParaMEDMEM::MEDCouplingUMesh *mesh, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
02729 {
02730   std::string meshName(mesh->getName());
02731   if(meshName.empty())
02732     throw INTERP_KERNEL::Exception("Trying to write a unstructured mesh with no name ! MED file format needs a not empty mesh name !");
02733   int status=MEDLoaderBase::getStatusOfFile(fileName);
02734   bool isRenumbering;
02735   if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
02736     {
02737       std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
02738       throw INTERP_KERNEL::Exception(oss.str().c_str());
02739     }
02740   std::vector<const ParaMEDMEM::MEDCouplingUMesh *> meshV(1); meshV[0]=mesh;
02741   std::vector<const ParaMEDMEM::DataArrayInt *> famV(1); famV[0]=0;
02742   if(writeFromScratch)
02743     {
02744       MEDLoaderNS::writeUMeshesDirectly(fileName,meshV,famV,true,isRenumbering);
02745       return ;
02746     }
02747   if(status==MEDLoaderBase::NOT_EXIST)
02748     {
02749       MEDLoaderNS::writeUMeshesDirectly(fileName,meshV,famV,true,isRenumbering);
02750       return;
02751     }
02752   else
02753     MEDLoaderNS::writeUMeshesDirectly(fileName,meshV,famV,false,isRenumbering);
02754 }
02755 
02756 void MEDLoader::WriteUMeshesPartition(const char *fileName, const char *meshNameC, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
02757 {
02758   std::string meshName(meshNameC);
02759   if(meshName.empty())
02760     throw INTERP_KERNEL::Exception("Trying to write a unstructured mesh with no name ! MED file format needs a not empty mesh name : change 2nd parameter !");
02761   int status=MEDLoaderBase::getStatusOfFile(fileName);
02762   if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
02763     {
02764       std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
02765       throw INTERP_KERNEL::Exception(oss.str().c_str());
02766     }
02767   if(meshes.empty())
02768     throw INTERP_KERNEL::Exception("List of meshes must be not empty !");
02769   const DataArrayDouble *coords=meshes.front()->getCoords();
02770   for(std::vector<const ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=meshes.begin();iter!=meshes.end();iter++)
02771     if(coords!=(*iter)->getCoords())
02772       throw INTERP_KERNEL::Exception("Meshes does not not share the same coordinates : try method MEDCouplingPointSet::tryToShareSameCoords !");
02773   std::set<std::string> tmp;
02774   for(std::vector<const ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=meshes.begin();iter!=meshes.end();iter++)
02775     {
02776       if(tmp.find((*iter)->getName())==tmp.end())
02777         tmp.insert((*iter)->getName());
02778       else
02779         throw INTERP_KERNEL::Exception("The names of meshes must be different each other !");
02780     }
02781   tmp.clear();
02782   if(writeFromScratch)
02783     {
02784       MEDLoaderNS::writeUMeshesPartitionDirectly(fileName,meshNameC,meshes,true);
02785       return ;
02786     }
02787   if(status==MEDLoaderBase::NOT_EXIST)
02788     {
02789       MEDLoaderNS::writeUMeshesPartitionDirectly(fileName,meshNameC,meshes,true);
02790       return;
02791     }
02792   else
02793     {
02794       std::vector<std::string> meshNames=GetMeshNames(fileName);
02795       if(std::find(meshNames.begin(),meshNames.end(),meshName)==meshNames.end())
02796         MEDLoaderNS::writeUMeshesPartitionDirectly(fileName,meshNameC,meshes,false);
02797       else
02798         {
02799           std::ostringstream oss; oss << "File \'" << fileName << "\' already exists and has already a mesh called \"";
02800           oss << meshName << "\" !";
02801           throw INTERP_KERNEL::Exception(oss.str().c_str());
02802         }
02803     }
02804 }
02805 
02806 void MEDLoader::WriteUMeshesPartitionDep(const char *fileName, const char *meshNameC, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
02807 {
02808   std::string meshName(meshNameC);
02809   if(meshName.empty())
02810     throw INTERP_KERNEL::Exception("Trying to write a unstructured mesh with no name ! MED file format needs a not empty mesh name : change 2nd parameter !");
02811   int status=MEDLoaderBase::getStatusOfFile(fileName);
02812   if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
02813     {
02814       std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
02815       throw INTERP_KERNEL::Exception(oss.str().c_str());
02816     }
02817   if(meshes.empty())
02818     throw INTERP_KERNEL::Exception("List of meshes must be not empty !");
02819   const DataArrayDouble *coords=meshes.front()->getCoords();
02820   for(std::vector<const ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=meshes.begin();iter!=meshes.end();iter++)
02821     if(coords!=(*iter)->getCoords())
02822       throw INTERP_KERNEL::Exception("Meshes does not not share the same coordinates : try method MEDCouplingPointSet::tryToShareSameCoords !");
02823   std::set<std::string> tmp;
02824   for(std::vector<const ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=meshes.begin();iter!=meshes.end();iter++)
02825     {
02826       if(tmp.find((*iter)->getName())==tmp.end())
02827         tmp.insert((*iter)->getName());
02828       else
02829         throw INTERP_KERNEL::Exception("The names of meshes must be different each other !");
02830     }
02831   tmp.clear();
02832   if(writeFromScratch)
02833     {
02834       MEDLoaderNS::writeUMeshesPartitionDirectly(fileName,meshNameC,meshes,true);
02835       return ;
02836     }
02837   if(status==MEDLoaderBase::NOT_EXIST)
02838     {
02839       MEDLoaderNS::writeUMeshesPartitionDirectly(fileName,meshNameC,meshes,true);
02840       return;
02841     }
02842   else
02843     {
02844       MEDLoaderNS::writeUMeshesPartitionDirectly(fileName,meshNameC,meshes,false);
02845     }
02846 }
02847 
02848 void MEDLoader::WriteUMeshes(const char *fileName, const std::vector<const ParaMEDMEM::MEDCouplingUMesh *>& meshes, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
02849 {
02850   int status=MEDLoaderBase::getStatusOfFile(fileName);
02851   if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
02852     {
02853       std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
02854       throw INTERP_KERNEL::Exception(oss.str().c_str());
02855     }
02856   if(meshes.empty())
02857     throw INTERP_KERNEL::Exception("List of meshes must be not empty !");
02858   std::string meshName(meshes[0]->getName());
02859   if(meshName.empty())
02860     throw INTERP_KERNEL::Exception("Trying to write a unstructured mesh with no name ! MED file format needs a not empty mesh name : change name of first element of 2nd parameter !");
02861   const DataArrayDouble *coords=meshes.front()->getCoords();
02862   for(std::vector<const ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=meshes.begin();iter!=meshes.end();iter++)
02863     if(coords!=(*iter)->getCoords())
02864       throw INTERP_KERNEL::Exception("Meshes does not not share the same coordinates : try method MEDCouplingPointSet::tryToShareSameCoords !");
02865   std::set<int> tmp;
02866   for(std::vector<const ParaMEDMEM::MEDCouplingUMesh *>::const_iterator iter=meshes.begin();iter!=meshes.end();iter++)
02867     {
02868       if(tmp.find((*iter)->getMeshDimension())==tmp.end())
02869         tmp.insert((*iter)->getMeshDimension());
02870       else
02871         throw INTERP_KERNEL::Exception("The mesh dimension of meshes must be different each other !");
02872     }
02873   tmp.clear();
02874   bool isRenumbering;
02875   std::vector<const DataArrayInt *> families(meshes.size());
02876   if(writeFromScratch)
02877     {
02878       MEDLoaderNS::writeUMeshesDirectly(fileName,meshes,families,true,isRenumbering);
02879       return ;
02880     }
02881   if(status==MEDLoaderBase::NOT_EXIST)
02882     {
02883       MEDLoaderNS::writeUMeshesDirectly(fileName,meshes,families,true,isRenumbering);
02884       return;
02885     }
02886   else
02887     {
02888       MEDLoaderNS::writeUMeshesDirectly(fileName,meshes,families,false,isRenumbering);
02889       return;
02890     }
02891 }
02892 
02893 void MEDLoader::WriteField(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
02894 {
02895   int status=MEDLoaderBase::getStatusOfFile(fileName);
02896   if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
02897     {
02898       std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
02899       throw INTERP_KERNEL::Exception(oss.str().c_str());
02900     }
02901   if(writeFromScratch)
02902     {
02903       MEDLoaderNS::writeFieldAndMeshDirectly(fileName,f,true);
02904      return ;
02905     }
02906   if(status==MEDLoaderBase::NOT_EXIST)
02907     {
02908      MEDLoaderNS::writeFieldAndMeshDirectly(fileName,f,true);
02909      return ;
02910     }
02911   else
02912     {
02913       std::vector<std::string> meshNames=GetMeshNames(fileName);
02914       std::string fileNameCpp(f->getMesh()->getName());
02915       if(std::find(meshNames.begin(),meshNames.end(),fileNameCpp)==meshNames.end())
02916         MEDLoaderNS::writeFieldAndMeshDirectly(fileName,f,false);
02917       else
02918         MEDLoaderNS::writeFieldTryingToFitExistingMesh(fileName,f);
02919     }
02920 }
02921 
02922 void MEDLoader::WriteFieldDep(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f, bool writeFromScratch) throw(INTERP_KERNEL::Exception)
02923 {
02924   int status=MEDLoaderBase::getStatusOfFile(fileName);
02925   if(status!=MEDLoaderBase::EXIST_RW && status!=MEDLoaderBase::NOT_EXIST)
02926     {
02927       std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions !";
02928       throw INTERP_KERNEL::Exception(oss.str().c_str());
02929     }
02930   if(writeFromScratch)
02931     {
02932       MEDLoaderNS::writeFieldAndMeshDirectly(fileName,f,true);
02933      return ;
02934     }
02935   if(status==MEDLoaderBase::NOT_EXIST)
02936     {
02937      MEDLoaderNS::writeFieldAndMeshDirectly(fileName,f,true);
02938      return ;
02939     }
02940   else
02941     MEDLoaderNS::writeFieldAndMeshDirectly(fileName,f,false);
02942 }
02943 
02944 void MEDLoader::WriteFieldUsingAlreadyWrittenMesh(const char *fileName, const ParaMEDMEM::MEDCouplingFieldDouble *f) throw(INTERP_KERNEL::Exception)
02945 {
02946   f->checkCoherency();
02947   int status=MEDLoaderBase::getStatusOfFile(fileName);
02948   if(status!=MEDLoaderBase::EXIST_RW)
02949     {
02950       std::ostringstream oss; oss << "File with name \'" << fileName << "\' has not valid permissions or not exists !";
02951       throw INTERP_KERNEL::Exception(oss.str().c_str());
02952     }
02953   MEDLoaderNS::appendFieldDirectly(fileName,f);
02954 }