Index: trunk/Mars/mcore/Interpolator2D.h
===================================================================
--- trunk/Mars/mcore/Interpolator2D.h	(revision 17336)
+++ trunk/Mars/mcore/Interpolator2D.h	(revision 17338)
@@ -20,4 +20,5 @@
 #include <math.h>
 #include <vector>
+#include <fstream>
 
 class Interpolator2D
@@ -44,4 +45,5 @@
     {
         unsigned int i;
+        point(unsigned int _i, const vec &_v) : vec(_v), i(_i) { }
         point(unsigned int _i=0, double _x=0, double _y=0) : vec(_x, _y), i(_i) { }
     };
@@ -296,4 +298,38 @@
     // --------------------------------------------------------------------------
     //
+    //! helper function to read a grid from a simple file
+    //! (alternating x, y)
+    //!
+    //! @param filename
+    //!    filename of ascii file with data
+    //!
+    //! @returns
+    //!    a vector of point with the x and y values.
+    //!    in case of failure the vector is empty
+    //
+    static std::vector<Interpolator2D::vec> ReadGrid(const std::string &filename)
+    {
+        std::vector<Interpolator2D::vec> grid;
+
+        std::ifstream fin(filename);
+        if (!fin.is_open())
+            return std::vector<Interpolator2D::vec>();
+
+        while (1)
+        {
+            double x, y;
+            fin >> x;
+            fin >> y;
+            if (!fin)
+                break;
+
+            grid.emplace_back(x, y);
+        }
+
+        return fin.bad() ? std::vector<Interpolator2D::vec>() : grid;
+    }
+
+    // --------------------------------------------------------------------------
+    //
     //! Set a new input grid (the points at which values are known).
     //! Invalidates the output grid and the calculated weights.
@@ -309,5 +345,5 @@
     //!    y coordinates of data points
     //
-    void SetInputGrid(int n, double *x, double *y)
+    void SetInputGrid(unsigned int n, double *x, double *y)
     {
         circles.clear();
@@ -317,5 +353,5 @@
         inputGrid.clear();
         inputGrid.reserve(n);
-        for (int i=0; i<n; i++)
+        for (unsigned int i=0; i<n; i++)
             inputGrid.emplace_back(i, x[i], y[i]);
 
@@ -331,9 +367,35 @@
         inputGrid.clear();
         inputGrid.reserve(v.size());
-        for (std::size_t i=0; i<v.size(); i++)
-            inputGrid.emplace_back(i, v[i].x, v[i].y);
+        for (unsigned int i=0; i<v.size(); i++)
+            inputGrid.emplace_back(i, v[i]);
 
         CalculateGrid();
     }
+
+    /*
+    void SetInputGrid(const std::vector<Interpolator2D::point> &v)
+    {
+        circles.clear();
+        weights.clear();
+        outputGrid.clear();
+
+        inputGrid.clear();
+        inputGrid.reserve(v.size());
+        for (unsigned int i=0; i<v.size(); i++)
+            inputGrid.emplace_back(v[i], i);
+
+        CalculateGrid();
+    }*/
+
+    bool ReadInputGrid(const std::string &filename)
+    {
+        const auto grid = ReadGrid(filename);
+        if (grid.empty())
+            return false;
+
+        SetInputGrid(grid);
+        return true;
+    }
+
 
     // --------------------------------------------------------------------------
@@ -355,7 +417,7 @@
     //!    case of success
     //
-    bool SetOutputGrid(int n, double *x, double *y)
-    {
-        if (inputGrid.empty())
+    bool SetOutputGrid(std::size_t n, double *x, double *y)
+    {
+        if (inputGrid.empty() && n==0)
             return false;
 
@@ -364,5 +426,5 @@
         outputGrid.clear();
         outputGrid.reserve(n);
-        for (int i=0; i<n; i++)
+        for (std::size_t i=0; i<n; i++)
             outputGrid.emplace_back(i, x[i], y[i]);
 
@@ -370,7 +432,8 @@
     }
 
+    /*
     bool SetOutputGrid(const std::vector<std::pair<double,double>> &v)
     {
-        if (inputGrid.empty())
+        if (inputGrid.empty() || v.empty())
             return false;
 
@@ -383,5 +446,30 @@
 
         return CalculateWeights();
-    }
+    }*/
+
+    bool SetOutputGrid(const std::vector<Interpolator2D::vec> &v)
+    {
+        if (inputGrid.empty())
+            return false;
+
+        weights.clear();
+
+        outputGrid.clear();
+        outputGrid.reserve(v.size());
+        for (std::size_t i=0; i<v.size(); i++)
+            outputGrid.emplace_back(i, v[i]);
+
+        return CalculateWeights();
+    }
+
+    bool ReadOutputGrid(const std::string &filename)
+    {
+        const auto grid = ReadGrid(filename);
+        if (grid.empty())
+            return false;
+
+        return SetOutputGrid(grid);
+    }
+
 
     // --------------------------------------------------------------------------
