<commit_before>#ifndef DUNE_STUFF_FILE_IO_HH
#define DUNE_STUFF_FILE_IO_HH

#ifdef HAVE_CMAKE_CONFIG
 #include "cmake_config.h"
#else
 #include "config.h"
#endif // ifdef HAVE_CMAKE_CONFIG

#include <string>
#include <fstream>

#include <dune/grid/common/grid.hh>
#include <dune/stuff/common/string.hh>
#include <dune/fem/gridpart/common/gridpart.hh>
#include <dune/fem/io/file/vtkio.hh>
#include <dune/common/deprecated.hh>
#include <iostream>

namespace Dune {
namespace Stuff {
namespace Fem {

/** \todo FELIX needs to doc me **/
template< class DiscreteFunctionType>
int saveDiscreteFunction(const DiscreteFunctionType& discreteFunction,
                         const std::string gridType,
                         const int refineLevel,
                         const std::string dgfFilename,
                         const std::string saveToFilenamePrefix,
                         std::ostream& error) {
  int errorState(0);

  error.flush();

  if ( !( discreteFunction.write_ascii( saveToFilenamePrefix + std::string(".ddf") ) ) )
  {
    ++errorState;
    error << "Error in saveDiscreteFunction(): could not write to " << saveToFilenamePrefix + std::string(".ddf")
          << "!" << std::endl;
    return errorState;
  }

  // save dgf file with information
  std::ifstream readFile( dgfFilename.c_str() );
  if ( readFile.is_open() )
  {
    std::ofstream writeFile( std::string( saveToFilenamePrefix + std::string(".dgf") ).c_str() );
    if ( writeFile.is_open() )
    {
      // shift until "DGF"
      while ( !( readFile.eof() ) )
      {
        std::string line("");
        std::getline(readFile, line);
        if ( line.size() )
        {
          // remove lines with redundant information == "# ddf_"
          if ( !( (line[0] == '#') && (line[1] == ' ') && (line[2] == 'd') && (line[3] == 'd') && (line[4] == 'f')
                  && (line[5] == '_') ) )
          {
            writeFile << line << std::endl;
          }
          if ( (line[0] == 'D') && (line[1] == 'G') && (line[2] == 'F') )
          {
            break;
          }
        }
      }
      // insert informations
      writeFile << "# ddf_gridtype: " << gridType << std::endl;
      writeFile << "# ddf_refine_level: " << refineLevel << std::endl;
      // rest of dgf file
      while ( !( readFile.eof() ) )
      {
        std::string line("");
        std::getline(readFile, line);
        if ( line.size() )
        {
          // remove lines with redundant information == "# ddf_"
          if ( !( (line[0] == '#') && (line[1] == ' ') && (line[2] == 'd') && (line[3] == 'd') && (line[4] == 'f')
                  && (line[5] == '_') ) )
          {
            writeFile << line << std::endl;
          }
        }
      }
      writeFile.flush();
      writeFile.close();
      readFile.close();
    } else {
      ++errorState;
      error << "Error in saveDiscreteFunction(): could not write to " << saveToFilenamePrefix + std::string(".dgf")
            << "!" << std::endl;
      return errorState;
    }
  } else {
    ++errorState;
    error << "Error in saveDiscreteFunction(): could not open " << dgfFilename << "!" << std::endl;
    return errorState;
  }
  return errorState;
} // saveDiscreteFunction

/** \todo FELIX needs to doc me **/
template< class DiscreteFunctionType >
int loadDiscreteFunction(const std::string loadFromfilenamePrefix,
                         std::ostream& error) {
  int errorState(0);

  error.flush();

  std::string gridType("");
  int refineLevel(0);

  bool gridTypeRead(false);
  bool refineLevelRead(false);

  std::ifstream readFile( std::string( loadFromfilenamePrefix + std::string(".dgf") ).c_str() );
  if ( readFile.is_open() )
  {
    while ( !( readFile.eof() ) )
    {
      if ( !(gridTypeRead && refineLevelRead) )
      {
        std::string line("");
        std::getline(readFile, line);
        if ( line.size() )
        {
          if (line.substr(0, 6) == "# ddf_")
          {<commit_msg>[fem] deprecate ancient discretefunction r/w calls<commit_after>#ifndef DUNE_STUFF_FILE_IO_HH
#define DUNE_STUFF_FILE_IO_HH

#ifdef HAVE_CMAKE_CONFIG
 #include "cmake_config.h"
#else
 #include "config.h"
#endif // ifdef HAVE_CMAKE_CONFIG

#include <string>
#include <fstream>

#include <dune/grid/common/grid.hh>
#include <dune/stuff/common/string.hh>
#include <dune/fem/gridpart/common/gridpart.hh>
#include <dune/fem/io/file/vtkio.hh>
#include <dune/common/deprecated.hh>
#include <iostream>

namespace Dune {
namespace Stuff {
namespace Fem {

/** \todo FELIX needs to doc me **/
template< class DiscreteFunctionType>
int saveDiscreteFunction(const DiscreteFunctionType& discreteFunction,
                         const std::string gridType,
                         const int refineLevel,
                         const std::string dgfFilename,
                         const std::string saveToFilenamePrefix,
                         std::ostream& error) DUNE_DEPRECATED_MSG("To be removed by 2012's end")
{
  int errorState(0);

  error.flush();

  if ( !( discreteFunction.write_ascii( saveToFilenamePrefix + std::string(".ddf") ) ) )
  {
    ++errorState;
    error << "Error in saveDiscreteFunction(): could not write to " << saveToFilenamePrefix + std::string(".ddf")
          << "!" << std::endl;
    return errorState;
  }

  // save dgf file with information
  std::ifstream readFile( dgfFilename.c_str() );
  if ( readFile.is_open() )
  {
    std::ofstream writeFile( std::string( saveToFilenamePrefix + std::string(".dgf") ).c_str() );
    if ( writeFile.is_open() )
    {
      // shift until "DGF"
      while ( !( readFile.eof() ) )
      {
        std::string line("");
        std::getline(readFile, line);
        if ( line.size() )
        {
          // remove lines with redundant information == "# ddf_"
          if ( !( (line[0] == '#') && (line[1] == ' ') && (line[2] == 'd') && (line[3] == 'd') && (line[4] == 'f')
                  && (line[5] == '_') ) )
          {
            writeFile << line << std::endl;
          }
          if ( (line[0] == 'D') && (line[1] == 'G') && (line[2] == 'F') )
          {
            break;
          }
        }
      }
      // insert informations
      writeFile << "# ddf_gridtype: " << gridType << std::endl;
      writeFile << "# ddf_refine_level: " << refineLevel << std::endl;
      // rest of dgf file
      while ( !( readFile.eof() ) )
      {
        std::string line("");
        std::getline(readFile, line);
        if ( line.size() )
        {
          // remove lines with redundant information == "# ddf_"
          if ( !( (line[0] == '#') && (line[1] == ' ') && (line[2] == 'd') && (line[3] == 'd') && (line[4] == 'f')
                  && (line[5] == '_') ) )
          {
            writeFile << line << std::endl;
          }
        }
      }
      writeFile.flush();
      writeFile.close();
      readFile.close();
    } else {
      ++errorState;
      error << "Error in saveDiscreteFunction(): could not write to " << saveToFilenamePrefix + std::string(".dgf")
            << "!" << std::endl;
      return errorState;
    }
  } else {
    ++errorState;
    error << "Error in saveDiscreteFunction(): could not open " << dgfFilename << "!" << std::endl;
    return errorState;
  }
  return errorState;
} // saveDiscreteFunction

/** \todo FELIX needs to doc me **/
template< class DiscreteFunctionType >
int loadDiscreteFunction(const std::string loadFromfilenamePrefix,
                         std::ostream& error) DUNE_DEPRECATED_MSG("To be removed by 2012's end")
{
  int errorState(0);

  error.flush();

  std::string gridType("");
  int refineLevel(0);

  bool gridTypeRead(false);
  bool refineLevelRead(false);

  std::ifstream readFile( std::string( loadFromfilenamePrefix + std::string(".dgf") ).c_str() );
  if ( readFile.is_open() )
  {
    while ( !( readFile.eof() ) )
    {
      if ( !(gridTypeRead && refineLevelRead) )
      {
        std::string line("");
        std::getline(readFile, line);
        if ( line.size() )
        {
          if (line.substr(0, 6) == "# ddf_")
          {
{'fraction_non_alphanumeric': 0.16734794995664562, 'fraction_numerical': 0.005945745076179859, 'mean_word_length': 2.304952926729431, 'pattern_counts': {'":': 0, '<': 111, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7454480', 'n_tokens_mistral': 2643, 'n_tokens_neox': 2575, 'n_words': 545}