Salome HOME
Merge from V6_main 12/04/2013
[tools/medcoupling.git] / src / MEDLoader / SauvWriter.cxx
index b86f34dfa7489bedbf267c7f3530824ab2164737..88d17854d50b701112c1bf957f5d4de1b3df536e 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2013  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
@@ -404,7 +404,7 @@ void SauvWriter::fillFamilySubMeshes()
 
 //================================================================================
 /*!
- * \brief fill sub-mehses of groups
+ * \brief fill sub-meshes of groups
  */
 //================================================================================
 
@@ -418,22 +418,30 @@ void SauvWriter::fillGroupSubMeshes()
       const vector<string>& famNames = g2ff->second;
       if ( famNames.empty() ) continue;
       std::vector<SubMesh*> famSubMeshes( famNames.size() );
+      std::size_t k = 0;
       for ( size_t i = 0; i < famNames.size(); ++i )
         {
           int famID = _fileMesh->getFamilyId( famNames[i].c_str() );
           map< int, SubMesh* >::iterator i2f = _famIDs2Sub.find( famID );
-          if ( i2f == _famIDs2Sub.end() )
-            THROW_IK_EXCEPTION("SauvWriter::fillGroupSubMeshes(): unknown family ID: " << famID);
-          famSubMeshes[ i ] = i2f->second;
+          if ( i2f != _famIDs2Sub.end() )
+            {
+              famSubMeshes[ k ] = i2f->second;
+              ++k;
+            }
         }
+      // if a family exists but has no element, no submesh has been found for this family
+      // => we have to resize famSubMeshes with the number of submeshes stored
+      if (k != famNames.size())
+          famSubMeshes.resize(k);
       SubMesh* grpSubMesh = addSubMesh( groupName, famSubMeshes[0]->_dimRelExt );
       grpSubMesh->_subs.swap( famSubMeshes );
     }
 }
 
+
 //================================================================================
 /*!
- * \brief fill sub-mehses of profiles
+ * \brief fill sub-meshes of profiles
  */
 //================================================================================
 
@@ -572,7 +580,7 @@ void SauvWriter::write(const char* fileName)
   std::fstream fileStream;
   fileStream.open( fileName, ios::out);
   if
-#ifdef WNT
+#ifdef WIN32
     ( !fileStream || !fileStream.is_open() )
 #else
     ( !fileStream || !fileStream.rdbuf()->is_open() )
@@ -737,7 +745,7 @@ void SauvWriter::writeSubMeshes()
                       if ( toMedConn )
                         {
                           for ( unsigned j = 0; j < nbElemNodes; ++j )
-                            transformedConn[ j ] = cellConn[ toMedConn[ j ]];
+                            transformedConn[ toMedConn[ j ]] = cellConn[ j ];
                           cellConn.swap( transformedConn );
                         }
                       for ( unsigned j = 0; j < nbElemNodes; ++j, fcount++ )