public static Bitmap DoubleToBitmapSimple(IRI.Msh.Algebra.Matrix data)
        {
            Bitmap result = new Bitmap(data.NumberOfColumns, data.NumberOfRows);

            for (int i = 0; i < data.NumberOfRows; i++)
            {
                for (int j = 0; j < data.NumberOfColumns; j++)
                {
                    if (data[i, j] > 256)
                    {
                        result.SetPixel(j, i, Color.FromArgb(255, 255, 255));
                    }

                    else if (data[i, j] < 0)
                    {
                        result.SetPixel(j, i, Color.FromArgb(0, 0, 0));
                    }

                    else
                    {
                        result.SetPixel(j, i, Color.FromArgb((int)data[i, j], (int)data[i, j], (int)data[i, j]));
                    }
                }
            }

            return(result);
        }
        public static Bitmap DoubleToBitmapLinear(IRI.Msh.Algebra.Matrix data)
        {
            Bitmap result = new Bitmap(data.NumberOfColumns, data.NumberOfRows);

            double Max = IRI.Msh.Statistics.Statistics.GetMax(data);

            double Min = IRI.Msh.Statistics.Statistics.GetMin(data);

            for (int i = 0; i < data.NumberOfRows; i++)
            {
                for (int j = 0; j < data.NumberOfColumns; j++)
                {
                    if (data[i, j].Equals(double.NaN))
                    {
                        result.SetPixel(j, i, Color.Red);

                        continue;
                    }
                    int tempValue = (int)((data[i, j] - Min) * 255 / (Math.Abs(Max - Min)));

                    result.SetPixel(j, i, Color.FromArgb(tempValue, tempValue, tempValue));
                }
            }

            return(result);
        }
        public void SaveAsGRD(string path, IRI.Msh.Algebra.Matrix values, double lowerLeftX, double lowerLeftY, double cellSize, double noDataValue)
        {
            System.IO.StreamWriter writer = new System.IO.StreamWriter(path);

            int numberOfColumns = values.NumberOfColumns;

            int numberOfRows = values.NumberOfRows;

            writer.WriteLine(string.Format("ncols         {0}", numberOfColumns));

            writer.WriteLine(string.Format("nrows         {0}", numberOfRows));

            writer.WriteLine(string.Format("xllcorner     {0}", lowerLeftX));

            writer.WriteLine(string.Format("yllcorner     {0}", lowerLeftY));

            writer.WriteLine(string.Format("cellsize      {0}", cellSize));

            writer.WriteLine(string.Format("NODATA_value {0}", noDataValue));

            for (int i = 0; i < numberOfRows; i++)
            {
                for (int j = 0; j < numberOfColumns; j++)
                {
                    writer.Write(string.Format("{0} ", values[i, j]));
                }

                writer.WriteLine();
            }

            writer.Close();
        }
        private void ReadToMatrix()
        {
            System.IO.StreamReader reader = new System.IO.StreamReader(this.Path);

            Values = new IRI.Msh.Algebra.Matrix(this.NumberOfRows, this.NumberOfColumns);

            for (int i = 0; i < 6; i++)
            {
                reader.ReadLine();
            }

            for (int i = 0; i < NumberOfRows; i++)
            {
                string line = reader.ReadLine();

                string[] lineValues = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);

                if (lineValues.Length != this.NumberOfColumns)
                {
                    throw new Exception("File was corrupted");
                }

                for (int j = 0; j < NumberOfColumns; j++)
                {
                    double tempValue = double.Parse(lineValues[j]);

                    if (tempValue == this.NoDataValue)
                    {
                        Values[i, j] = double.NaN;
                    }
                    else
                    {
                        Values[i, j] = tempValue;
                    }
                }
            }

            reader.Close();
        }