<commit_before>/** 
 * @file gis.cpp
 * @brief WELL GIS storage
 * @author <NAME>
 * @version 
 * @date 2011-07-26
 */

#include <memory.h>
#include <iomanip>
#include <iostream>
#include <fstream>
#include <vector>

#include <boost/spirit/include/qi.hpp>
#include <boost/fusion/include/std_pair.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/filesystem.hpp>


#include "bs_kernel.h"
#include "gis.h"
#include "bs_misc.h"
#include "bs_serialize.h"

using namespace boost;

#ifdef BSPY_EXPORTING_PLUGIN

#include <boost/python.hpp>
using namespace boost::python;

#endif //BSPY_EXPORTING_PLUGIN


namespace blue_sky
{
  gis::gis (bs_type_ctor_param) 
    {
      sp_prop = BS_KERNEL.create_object ("prop");
      sp_table = BS_KERNEL.create_object ("table");
      if (!sp_prop || !sp_table)
        {
          bs_throw_exception ("Type (gis) isn't created");
        }
    }
  gis::gis (const gis& rhs) 
        : bs_refcounter ()
    {
      *this = rhs;
    }

  void split_str (std::string &s,
                  std::string &name,
                  std::string &units,
                  std::string &data,
                  std::string &description)
    {
      size_t colon_pos;
      size_t dot_pos; 
      size_t space_pos;

      colon_pos = s.find_last_of (':');
      description = s.substr (colon_pos + 1);
      s.erase (colon_pos);
      dot_pos = s.find ('.');
      if (dot_pos == s.npos) // dot not found
        {
          name = s;
          trim (name);
        }
      else
        {
          units = s.substr (dot_pos + 1);
          s.erase (dot_pos);
          name = s;
          trim (name);
          space_pos = units.find (' ');
          if (space_pos != units.npos)
            {
              data = units.substr (space_pos + 1);
              units.erase (space_pos);
              trim(data);
            }
          trim (units);
        }
    }
  template <class T>
  T str2T (std::string &s)
    {
      T f;
      trim (s);
      try
        {
          f = boost::lexical_cast<T>(s);
        }
      catch (boost::bad_lexical_cast &)
        {
          f = 0;
        }
      return f;
    }
  int 
  gis::read_ver_info (sp_prop_iface prop, std::string &s)
    {
      std::string description;
      std::string name;
      std::string units;
      std::string data;

      std::cout << "SEC VER:" << s << std::endl;

      split_str (s, name, units, data, description);
      if (name == "VERS")
        {
          //prop->add_property_f (0, name, description);
          prop->set_f (str2wstr (name), str2T<double>(data));
        }
      else
        {
          prop->add_property_s (L"", str2wstr (name), str2wstr(description));
          prop->set_s (str2wstr (name), str2wstr (data));
        }
      return 0;
    }

  int 
  gis::read_wel_info (sp_prop_iface prop, std::string &s, double ver)
    {
      std::string description;
      std::string name;
      std::string units;
      std::string data;

      std::cout << "SEC WELL:" << s << std::endl;

      split_str (s, name, units, data, description);
      if (name == "STRT"
          || name == "STOP"
          || name == "STEP"
          || name == "NULL")
        {
          prop->add_property_f (0, str2wstr (name), str2wstr(units));
          prop->set_f (str2wstr (name), str2T<double> (data));
        }
      else if (name == "LIC")
        {
          prop->add_property_i (0, str2wstr (name), str2wstr(description));
          prop->set_i (str2wstr (name), str2T<int> (data));
        }
      else
        {
          if (ver <= 1.2 && data == "")
            {
              prop->add_property_s (L"", str2wstr (name), L"");
              prop->set_s (str2wstr (name), str2wstr (description));
            }
          else if (data != "")
            {
              prop->add_property_s (L"", str2wstr (name), str2wstr(description));
              prop->set_s (str2wstr (name), str2wstr (data));
            }
        }
      return 0;
    }

  int 
  gis::read_par_info (sp_prop_iface prop, std::string &s, double ver)
    {
      std::string description;
      std::string name;
      std::string units;
      std::string data;

      std::cout << "SEC PAR:" << s << std::endl;
      if (s[0]='-')
        {
          return 0;
        }

      split_str (s, name, units, data, description);
      if (ver <= 1.2 && data == "")
        {
          prop->add_property_s (L"", str2wstr (name), L"");
          prop->set_s (str2wstr (name), str2wstr (description));
        }
      else if (data != "")
        {
          prop->add_property_s (L"", str2wstr (name), str2wstr(description));
          prop->set_s (str2wstr (name), str2wstr (data));
        }
      return 0;
    }

  int 
  gis::read_cur_info (sp_prop_iface prop, std::string &s, int n)
    {
      std::string description;
      std::string name;<commit_msg>common_types: fix typo - assignment instead of comaprison in if clause<commit_after>/** 
 * @file gis.cpp
 * @brief WELL GIS storage
 * @author <NAME>
 * @version 
 * @date 2011-07-26
 */

#include <memory.h>
#include <iomanip>
#include <iostream>
#include <fstream>
#include <vector>

#include <boost/spirit/include/qi.hpp>
#include <boost/fusion/include/std_pair.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/filesystem.hpp>


#include "bs_kernel.h"
#include "gis.h"
#include "bs_misc.h"
#include "bs_serialize.h"

using namespace boost;

#ifdef BSPY_EXPORTING_PLUGIN

#include <boost/python.hpp>
using namespace boost::python;

#endif //BSPY_EXPORTING_PLUGIN


namespace blue_sky
{
  gis::gis (bs_type_ctor_param) 
    {
      sp_prop = BS_KERNEL.create_object ("prop");
      sp_table = BS_KERNEL.create_object ("table");
      if (!sp_prop || !sp_table)
        {
          bs_throw_exception ("Type (gis) isn't created");
        }
    }
  gis::gis (const gis& rhs) 
        : bs_refcounter ()
    {
      *this = rhs;
    }

  void split_str (std::string &s,
                  std::string &name,
                  std::string &units,
                  std::string &data,
                  std::string &description)
    {
      size_t colon_pos;
      size_t dot_pos; 
      size_t space_pos;

      colon_pos = s.find_last_of (':');
      description = s.substr (colon_pos + 1);
      s.erase (colon_pos);
      dot_pos = s.find ('.');
      if (dot_pos == s.npos) // dot not found
        {
          name = s;
          trim (name);
        }
      else
        {
          units = s.substr (dot_pos + 1);
          s.erase (dot_pos);
          name = s;
          trim (name);
          space_pos = units.find (' ');
          if (space_pos != units.npos)
            {
              data = units.substr (space_pos + 1);
              units.erase (space_pos);
              trim(data);
            }
          trim (units);
        }
    }
  template <class T>
  T str2T (std::string &s)
    {
      T f;
      trim (s);
      try
        {
          f = boost::lexical_cast<T>(s);
        }
      catch (boost::bad_lexical_cast &)
        {
          f = 0;
        }
      return f;
    }
  int 
  gis::read_ver_info (sp_prop_iface prop, std::string &s)
    {
      std::string description;
      std::string name;
      std::string units;
      std::string data;

      std::cout << "SEC VER:" << s << std::endl;

      split_str (s, name, units, data, description);
      if (name == "VERS")
        {
          //prop->add_property_f (0, name, description);
          prop->set_f (str2wstr (name), str2T<double>(data));
        }
      else
        {
          prop->add_property_s (L"", str2wstr (name), str2wstr(description));
          prop->set_s (str2wstr (name), str2wstr (data));
        }
      return 0;
    }

  int 
  gis::read_wel_info (sp_prop_iface prop, std::string &s, double ver)
    {
      std::string description;
      std::string name;
      std::string units;
      std::string data;

      std::cout << "SEC WELL:" << s << std::endl;

      split_str (s, name, units, data, description);
      if (name == "STRT"
          || name == "STOP"
          || name == "STEP"
          || name == "NULL")
        {
          prop->add_property_f (0, str2wstr (name), str2wstr(units));
          prop->set_f (str2wstr (name), str2T<double> (data));
        }
      else if (name == "LIC")
        {
          prop->add_property_i (0, str2wstr (name), str2wstr(description));
          prop->set_i (str2wstr (name), str2T<int> (data));
        }
      else
        {
          if (ver <= 1.2 && data == "")
            {
              prop->add_property_s (L"", str2wstr (name), L"");
              prop->set_s (str2wstr (name), str2wstr (description));
            }
          else if (data != "")
            {
              prop->add_property_s (L"", str2wstr (name), str2wstr(description));
              prop->set_s (str2wstr (name), str2wstr (data));
            }
        }
      return 0;
    }

  int 
  gis::read_par_info (sp_prop_iface prop, std::string &s, double ver)
    {
      std::string description;
      std::string name;
      std::string units;
      std::string data;

      std::cout << "SEC PAR:" << s << std::endl;
      if (s[0] == '-')
        {
          return 0;
        }

      split_str (s, name, units, data, description);
      if (ver <= 1.2 && data == "")
        {
          prop->add_property_s (L"", str2wstr (name), L"");
          prop->set_s (str2wstr (name), str2wstr (description));
        }
      else if (data != "")
        {
          prop->add_property_s (L"", str2wstr (name), str2wstr(description));
          prop->set_s (str2wstr (name), str2wstr (data));
        }
      return 0;
    }

  int 
  gis::read_cur_info (sp_prop_iface prop, std::string &s, int n)
    {
      std::string description;
      std::string name;
{'fraction_non_alphanumeric': 0.14754264825345248, 'fraction_numerical': 0.010763606823720552, 'mean_word_length': 1.8498263888888888, 'pattern_counts': {'":': 0, '<': 77, '<?xml version=': 0, '>': 69, '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': '7426605', 'n_tokens_mistral': 3428, 'n_tokens_neox': 3339, 'n_words': 750}