Salome HOME
Merge from V6_main 12/04/2013
[tools/medcoupling.git] / src / MEDLoader / SauvMedConvertor.cxx
index 800c84ab1619836b72e8e53183b193209c4249c3..f4af715ff6ed43e5489eacf2deee1c8ea832311f 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
 #include <cstring>
 #include <fcntl.h>
 
-#ifdef WNT
+#ifdef WIN32
 #include <io.h>
 #endif
 
-#ifndef WNT
+#ifndef WIN32
 #define HAS_XDR
 #include <unistd.h>
 #endif
@@ -259,7 +259,8 @@ unsigned SauvUtilities::getDimension( INTERP_KERNEL::NormalizedCellType type )
 
 //================================================================================
 /*!
- * \brief Returns interlace array to transform a quadratic GIBI element to a MED one
+ * \brief Returns interlace array to transform a quadratic GIBI element to a MED one.
+ *        i-th array item gives node index in GIBI connectivity for i-th MED node
  */
 //================================================================================
 
@@ -267,7 +268,7 @@ const int * SauvUtilities::getGibi2MedQuadraticInterlace( INTERP_KERNEL::Normali
 {
   static vector<const int*> conn;
   static const int hexa20 [] = {0,6,4,2, 12,18,16,14, 7,5,3,1, 19,17,15,13, 8,11,10,9};
-  static const int penta15[] = {0,2,4, 9,11,13, 1,3,5, 10,12,14, 6,7,3};
+  static const int penta15[] = {0,2,4, 9,11,13, 1,3,5, 10,12,14, 6,8,7};
   static const int pyra13 [] = {0,2,4,6, 12, 1,3,5,7, 8,9,10,11};
   static const int tetra10[] = {0,2,4, 9, 1,3,5, 6,7,8};
   static const int quad8  [] = {0,2,4,6, 1,3,5,7};
@@ -474,7 +475,7 @@ bool ASCIIReader::isASCII() const
 
 bool ASCIIReader::open()
 {
-#ifdef WNT
+#ifdef WIN32
   _file = ::_open (_fileName.c_str(), _O_RDONLY|_O_BINARY);
 #else
   _file = ::open (_fileName.c_str(), O_RDONLY);
@@ -772,9 +773,9 @@ double ASCIIReader::getDouble() const
   //  7.70000000000000-100  7.70000000000000+100  7.70000000000000+100
   //0123456789012345678901234567890123456789012345678901234567890123456789
   const size_t posE = 18;
-  if ( _curPos[posE] != 'E' && _curPos[posE] != 'e' )
+  std::string aStr (_curPos);
+  if ( aStr.find('E') < 0 && aStr.find('e') < 0 )
     {
-      std::string aStr (_curPos);
       if ( aStr.size() < posE+1 )
         THROW_IK_EXCEPTION("No more doubles (line #" << lineNb() << ")");
       aStr.insert( posE, "E", 1 );
@@ -1117,8 +1118,7 @@ ParaMEDMEM::MEDFileData* IntermediateMED::convertInMEDFileDS()
   medData->setMeshes( meshes );
   if ( fields ) medData->setFields( fields );
 
-  medData->incrRef();
-  return medData;
+  return medData.retn();
 }
 
 //================================================================================
@@ -1577,9 +1577,16 @@ void IntermediateMED::orientFaces3D()
                               if ( lfIt2 != linkFacesMap.end() )
                                 {
                                   list<const Cell*> & ff = lfIt2->second;
-                                  ff.erase( find( ff.begin(), ff.end(), badFace ));
-                                  if ( ff.empty() )
-                                    linkFacesMap.erase( lfIt2 );
+                                  list<const Cell*>::iterator lfIt3 = find( ff.begin(), ff.end(), badFace );
+                                  // check if badFace has been found,
+                                  // else we can't erase it
+                                  // case of degenerated face in edge
+                                  if (lfIt3 != ff.end())
+                                    {
+                                      ff.erase( lfIt3 );
+                                      if ( ff.empty() )
+                                        linkFacesMap.erase( lfIt2 );
+                                    }
                                 }
                             }
                           badFace->_reverse = true; // reverse
@@ -2376,7 +2383,7 @@ int DoubleField::setValues( double * valPtr, const int iSub, const int elemShift
     THROW_IK_EXCEPTION("SauvMedConvertor.cxx: support size mismatches field size");
   // compute nb values in previous subs
   int valsShift = 0;
-  for ( int iS = iSub-1, shift = elemShift; shift > 0; )
+  for ( int iS = iSub-1, shift = elemShift; shift > 0; --iS)
   {
     int nbE = _sub[iS]._support->size();
     shift -= nbE;