Salome HOME
Add test for .mesh file format
[tools/medcoupling.git] / src / MEDLoader / SauvReader.cxx
index f530d1f2d1b7169e0981f3092796873e4024c96e..f2a64fffff631bf83bfb8ba4f378119f079f97da 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -24,7 +24,7 @@
 #include "SauvReader.hxx"
 
 #include "SauvMedConvertor.hxx"
-#include "MEDCouplingAutoRefCountObjectPtr.hxx"
+#include "MCAuto.hxx"
 #include "NormalizedUnstructuredMesh.hxx"
 #include "MEDCouplingRefCountObject.hxx"
 
 #include <sstream>
 #include <iostream>
 
-using namespace ParaMEDMEM;
+using namespace MEDCoupling;
 using namespace SauvUtilities;
 using namespace std;
 
 #define GIBI_EQUAL(var_str, stat_str) (strncmp (var_str, stat_str, strlen(stat_str)) == 0)
 
+namespace
+{
+  class Localizer
+  {
+    std::string _locale;
+  public:
+    Localizer()
+    {
+      _locale = setlocale(LC_NUMERIC, NULL);
+      setlocale(LC_NUMERIC, "C");
+    }
+    ~Localizer()
+    {
+      setlocale(LC_NUMERIC, _locale.c_str());
+    }
+  };
+}
+
 //================================================================================
 /*!
  * \brief Creates a reader of a given sauve file
@@ -48,7 +66,7 @@ SauvReader* SauvReader::New(const std::string& fileName)
 {
   if ( fileName.empty() ) THROW_IK_EXCEPTION("Invalid file name");
 
-  ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr< SauvUtilities::FileReader> parser;
+  MEDCoupling::MCAuto< SauvUtilities::FileReader> parser;
 
   // try to open as XRD
   parser = new XDRReader( fileName.c_str() );
@@ -112,8 +130,10 @@ std::string SauvReader::lineNb() const
  */
 //================================================================================
 
-ParaMEDMEM::MEDFileData * SauvReader::loadInMEDFileDS()
+MEDCoupling::MEDFileData * SauvReader::loadInMEDFileDS()
 {
+  Localizer loc; // localization, to read numbers in "C" locale
+
   SauvUtilities::IntermediateMED iMed; // intermadiate DS
   _iMed = &iMed;
 
@@ -139,6 +159,8 @@ ParaMEDMEM::MEDFileData * SauvReader::loadInMEDFileDS()
         readRecord4();
       else if (recordNumber == 7 )
         readRecord7();
+      else if (recordNumber == 8 )
+        readRecord8();
       else if (recordNumber == 5 )
         break; // stop reading
       else
@@ -146,7 +168,7 @@ ParaMEDMEM::MEDFileData * SauvReader::loadInMEDFileDS()
           THROW_IK_EXCEPTION("XDR : ENREGISTREMENT DE TYPE " << recordNumber << " not implemented!!!");
     }
 
-  ParaMEDMEM::MEDFileData* medFileData = iMed.convertInMEDFileDS();
+  MEDCoupling::MEDFileData* medFileData = iMed.convertInMEDFileDS();
 
   return medFileData;
 }
@@ -212,6 +234,38 @@ void SauvReader::readRecord7()
     }
 }
 
+//================================================================================
+/*!
+ * \brief Reads "ENREGISTREMENT DE TYPE 8"
+ */
+//================================================================================
+
+void SauvReader::readRecord8()
+{
+  // This record is useless (a constant table)
+  // => we skip it
+  int info;
+  int nbIntToSkip;
+  if ( !isASCII() )
+    {
+      getInt();
+      info = getInt();
+      int i = 0;
+      if (info == 3) {
+        // castem >= 18
+        // 1 more line
+        nbIntToSkip = 145;
+      }
+      else
+        nbIntToSkip = 141;
+
+      while (i <= nbIntToSkip) {
+        getInt();
+        i ++;
+      }
+    }
+}
+
 //================================================================================
 /*!
  * \brief Reads the pile number, nb of objects and nb named of objects
@@ -220,7 +274,7 @@ void SauvReader::readRecord7()
 
 int SauvReader::readPileNumber(int& nbNamedObjects, int& nbObjects)
 {
-  // FORMAT(' PILE NUMERO',I4,'NBRE ObjectS NOMMES',I8,'NBRE ObjectS',I8)
+  // FORMAT(' PILE NUMERO',I4,'NBRE OBJETS NOMMES',I8,'NBRE OBJETS',I8)
   int pileNumber;
   if ( !isASCII() )
     {
@@ -233,7 +287,7 @@ int SauvReader::readPileNumber(int& nbNamedObjects, int& nbObjects)
     {
       char* line;
       getNextLine(line);
-      const char *s1 = " PILE NUMERO", *s2 = "NBRE ObjectS NOMMES", *s3 = "NBRE ObjectS";
+      const char *s1 = " PILE NUMERO", *s2 = "NBRE OBJETS NOMMES", *s3 = "NBRE OBJETS";
       if ( ! GIBI_EQUAL( line, s1 ) )
         THROW_IK_EXCEPTION("Could not read the pile number " << lineNb() );
       line           = line + strlen(s1);
@@ -701,10 +755,10 @@ void SauvReader::setFieldSupport(const vector<SauvUtilities::Group*>& supports,
           while ( isSwapped )
             {
               isSwapped = false;
-              for ( size_t i = 1; i < groups.size(); ++i )
+              for ( std::size_t i = 1; i < groups.size(); ++i )
                 {
-                  int nbN1 = groups[i-1]->empty() ? 0 : groups[i-1]->_cells[0]->_nodes.size();
-                  int nbN2 = groups[i  ]->empty() ? 0 : groups[i  ]->_cells[0]->_nodes.size();
+                  std::size_t nbN1 = groups[i-1]->empty() ? 0 : groups[i-1]->_cells[0]->_nodes.size();
+                  std::size_t nbN2 = groups[i  ]->empty() ? 0 : groups[i  ]->_cells[0]->_nodes.size();
                   if ( nbN1 > nbN2 )
                     {
                       isSwapped = isModified = true;
@@ -1170,7 +1224,7 @@ void SauvReader::read_PILE_STRINGS (const int                 nbObjects,
       const int fixedLength = 71;
       while ((int)aWholeString.length() < stringLen)
         {
-          int remainLen = stringLen - aWholeString.length();
+          int remainLen = (int)(stringLen - aWholeString.length());
           int len;
           if ( remainLen > fixedLength )
             {
@@ -1192,7 +1246,7 @@ void SauvReader::read_PILE_STRINGS (const int                 nbObjects,
       while ((int)aWholeString.length() < stringLen)
         {
           getNextLine( line );
-          int remainLen = stringLen - aWholeString.length();
+          int remainLen = (int)(stringLen - aWholeString.length());
           if ( remainLen > fixedLength )
             {
               aWholeString += line + 1;