Salome HOME
Doc fix and enhancement.
[tools/medcoupling.git] / src / MEDLoader / SauvMedConvertor.cxx
index 67e28ed1165844545a95d48adb5124509c965e04..f1542f90cfdc51b2cd94096297575db31bc4b5e1 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2015  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 #endif
 
 #ifdef HAS_XDR
+#include <rpc/types.h>
 #include <rpc/xdr.h>
 #endif
 
 using namespace SauvUtilities;
-using namespace ParaMEDMEM;
+using namespace MEDCoupling;
 
 namespace
 {
@@ -209,7 +210,7 @@ namespace
    */
   struct TCellByIDCompare
   {
-    bool operator () (const Cell* i1, const Cell* i2)
+    bool operator () (const Cell* i1, const Cell* i2) const
     {
       return i1->_number < i2->_number;
     }
@@ -2372,17 +2373,17 @@ Group* IntermediateMED::addNewGroup(std::vector<SauvUtilities::Group*>* groupsTo
 
 //================================================================================
 /*!
- * \brief Makes ParaMEDMEM::MEDFileData from self
+ * \brief Makes MEDCoupling::MEDFileData from self
  */
 //================================================================================
 
-ParaMEDMEM::MEDFileData* IntermediateMED::convertInMEDFileDS()
+MEDCoupling::MEDFileData* IntermediateMED::convertInMEDFileDS()
 {
-  MEDCouplingAutoRefCountObjectPtr< MEDFileUMesh >  mesh   = makeMEDFileMesh();
-  MEDCouplingAutoRefCountObjectPtr< MEDFileFields > fields = makeMEDFileFields(mesh);
+  MCAuto< MEDFileUMesh >  mesh   = makeMEDFileMesh();
+  MCAuto< MEDFileFields > fields = makeMEDFileFields(mesh);
 
-  MEDCouplingAutoRefCountObjectPtr< MEDFileMeshes > meshes = MEDFileMeshes::New();
-  MEDCouplingAutoRefCountObjectPtr< MEDFileData >  medData = MEDFileData::New();
+  MCAuto< MEDFileMeshes > meshes = MEDFileMeshes::New();
+  MCAuto< MEDFileData >  medData = MEDFileData::New();
   meshes->pushMesh( mesh );
   medData->setMeshes( meshes );
   if ( fields ) medData->setFields( fields );
@@ -2392,11 +2393,11 @@ ParaMEDMEM::MEDFileData* IntermediateMED::convertInMEDFileDS()
 
 //================================================================================
 /*!
- * \brief Creates ParaMEDMEM::MEDFileUMesh from its data
+ * \brief Creates MEDCoupling::MEDFileUMesh from its data
  */
 //================================================================================
 
-ParaMEDMEM::MEDFileUMesh* IntermediateMED::makeMEDFileMesh()
+MEDCoupling::MEDFileUMesh* IntermediateMED::makeMEDFileMesh()
 {
   // check if all needed piles are present
   checkDataAvailability();
@@ -3091,7 +3092,7 @@ void IntermediateMED::numberElements()
  */
 //================================================================================
 
-ParaMEDMEM::DataArrayDouble * IntermediateMED::getCoords()
+MEDCoupling::DataArrayDouble * IntermediateMED::getCoords()
 {
   DataArrayDouble* coordArray = DataArrayDouble::New();
   coordArray->alloc( _nbNodes, _spaceDim );
@@ -3117,8 +3118,8 @@ ParaMEDMEM::DataArrayDouble * IntermediateMED::getCoords()
  */
 //================================================================================
 
-void IntermediateMED::setConnectivity( ParaMEDMEM::MEDFileUMesh*    mesh,
-                                       ParaMEDMEM::DataArrayDouble* coords )
+void IntermediateMED::setConnectivity( MEDCoupling::MEDFileUMesh*    mesh,
+                                       MEDCoupling::DataArrayDouble* coords )
 {
   int meshDim = 0;
 
@@ -3183,7 +3184,7 @@ void IntermediateMED::setConnectivity( ParaMEDMEM::MEDFileUMesh*    mesh,
  */
 //================================================================================
 
-void IntermediateMED::setGroups( ParaMEDMEM::MEDFileUMesh* mesh )
+void IntermediateMED::setGroups( MEDCoupling::MEDFileUMesh* mesh )
 {
   bool isMeshNameSet = false;
   const int meshDim = mesh->getMeshDimension();
@@ -3192,7 +3193,7 @@ void IntermediateMED::setGroups( ParaMEDMEM::MEDFileUMesh* mesh )
       const int meshDimRelToMaxExt = ( dim == 0 ? 1 : dim - meshDim );
 
       std::vector<const DataArrayInt *> medGroups;
-      std::vector<MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > refGroups;
+      std::vector<MCAuto<DataArrayInt> > refGroups;
       for ( size_t i = 0; i < _groups.size(); ++i )
         {
           Group& grp = _groups[i];
@@ -3265,10 +3266,13 @@ void IntermediateMED::setGroups( ParaMEDMEM::MEDFileUMesh* mesh )
           // Issue 0021311. Use case: a gibi group has references (recorded in pile 1)
           // and several names (pile 27) refer (pile 10) to this group.
           // We create a copy of this group per each named reference
+          std::set<std::string> uniqueNames;
+          uniqueNames.insert( grp._name );
           for ( unsigned iRef = 0 ; iRef < grp._refNames.size(); ++iRef )
-            if ( !grp._refNames[ iRef ].empty() )
+            if ( !grp._refNames[ iRef ].empty() &&
+                 uniqueNames.insert( grp._refNames[ iRef ]).second ) // for name uniqueness (23155)
               {
-                refGroups.push_back( grp._medGroup->deepCpy() );
+                refGroups.push_back( grp._medGroup->deepCopy() );
                 refGroups.back()->setName( grp._refNames[ iRef ].c_str() );
                 medGroups.push_back( refGroups.back() );
               }
@@ -3319,7 +3323,7 @@ bool IntermediateMED::isOnAll( const Group* grp, int & dimRel ) const
  */
 //================================================================================
 
-ParaMEDMEM::MEDFileFields * IntermediateMED::makeMEDFileFields(ParaMEDMEM::MEDFileUMesh* mesh)
+MEDCoupling::MEDFileFields * IntermediateMED::makeMEDFileFields(MEDCoupling::MEDFileUMesh* mesh)
 {
   if ( _nodeFields.empty() && _cellFields.empty() ) return 0;
 
@@ -3345,8 +3349,8 @@ ParaMEDMEM::MEDFileFields * IntermediateMED::makeMEDFileFields(ParaMEDMEM::MEDFi
 //================================================================================
 
 void IntermediateMED::setFields( SauvUtilities::DoubleField* fld,
-                                 ParaMEDMEM::MEDFileFields*  medFields,
-                                 ParaMEDMEM::MEDFileUMesh*   mesh,
+                                 MEDCoupling::MEDFileFields*  medFields,
+                                 MEDCoupling::MEDFileUMesh*   mesh,
                                  const TID                   castemID,
                                  std::set< std::string >&    usedFieldNames)
 {
@@ -3405,9 +3409,9 @@ void IntermediateMED::setFields( SauvUtilities::DoubleField* fld,
 //================================================================================
 
 void IntermediateMED::setTS( SauvUtilities::DoubleField*  fld,
-                             ParaMEDMEM::DataArrayDouble* values,
-                             ParaMEDMEM::MEDFileFields*   medFields,
-                             ParaMEDMEM::MEDFileUMesh*    mesh,
+                             MEDCoupling::DataArrayDouble* values,
+                             MEDCoupling::MEDFileFields*   medFields,
+                             MEDCoupling::MEDFileUMesh*    mesh,
                              const int                    iSub)
 {
   // treat a field support
@@ -3429,25 +3433,25 @@ void IntermediateMED::setTS( SauvUtilities::DoubleField*  fld,
   // set the mesh
   if ( onAll )
     {
-      MEDCouplingAutoRefCountObjectPtr
+      MCAuto
         < MEDCouplingUMesh > dimMesh = mesh->getMeshAtLevel( dimRel );
       timeStamp->setMesh( dimMesh );
     }
-  else if ( timeStamp->getTypeOfField() == ParaMEDMEM::ON_NODES )
+  else if ( timeStamp->getTypeOfField() == MEDCoupling::ON_NODES )
     {
       DataArrayDouble * coo = mesh->getCoords();
-      MEDCouplingAutoRefCountObjectPtr
+      MCAuto
         <DataArrayDouble> subCoo = coo->selectByTupleId(support->_medGroup->begin(),
                                                         support->_medGroup->end());
-      MEDCouplingAutoRefCountObjectPtr< MEDCouplingUMesh > nodeSubMesh =
+      MCAuto< MEDCouplingUMesh > nodeSubMesh =
         MEDCouplingUMesh::Build0DMeshFromCoords( subCoo );
       timeStamp->setMesh( nodeSubMesh );
     }
   else
     {
-      MEDCouplingAutoRefCountObjectPtr
+      MCAuto
         < MEDCouplingUMesh > dimMesh = mesh->getMeshAtLevel( dimRel );
-      MEDCouplingAutoRefCountObjectPtr
+      MCAuto
         <MEDCouplingMesh> subMesh = dimMesh->buildPart(support->_medGroup->begin(),
                                                        support->_medGroup->end());
       timeStamp->setMesh( subMesh);
@@ -3458,7 +3462,7 @@ void IntermediateMED::setTS( SauvUtilities::DoubleField*  fld,
   timeStamp->setArray( values );
   values->decrRef();
   // set gauss points
-  if ( timeStamp->getTypeOfField() == ParaMEDMEM::ON_GAUSS_PT )
+  if ( timeStamp->getTypeOfField() == MEDCoupling::ON_GAUSS_PT )
     {
       TGaussDef gaussDef( fld->_sub[iSub]._support->_cellType,
                           fld->_sub[iSub].nbGauss() );
@@ -3481,7 +3485,7 @@ void IntermediateMED::setTS( SauvUtilities::DoubleField*  fld,
     timeStamp->setOrder( nbTS );
 
   // add the time-stamp
-  timeStamp->checkCoherency();
+  timeStamp->checkConsistencyLight();
   if ( onAll )
     fld->_curMedField->appendFieldNoProfileSBT( timeStamp );
   else
@@ -3655,7 +3659,7 @@ bool DoubleField::hasSameComponentsBySupport() const
  */
 //================================================================================
 
-ParaMEDMEM::TypeOfField DoubleField::getMedType( const int iSub ) const
+MEDCoupling::TypeOfField DoubleField::getMedType( const int iSub ) const
 {
   using namespace INTERP_KERNEL;
 
@@ -3677,7 +3681,7 @@ ParaMEDMEM::TypeOfField DoubleField::getMedType( const int iSub ) const
  */
 //================================================================================
 
-ParaMEDMEM::TypeOfTimeDiscretization DoubleField::getMedTimeDisc() const
+MEDCoupling::TypeOfTimeDiscretization DoubleField::getMedTimeDisc() const
 {
   return ONE_TIME;
   // NO_TIME = 4,