internal TopOfCell(IXYZDataSet CellBottom, IXYDataSet TopoGraphy)
    {
      _data = new Matrix3d(CellBottom.Data[0].RowCount, CellBottom.Data[0].ColumnCount, CellBottom.Data.LayerCount);

      for (int i = 0; i < _data.LayerCount - 1; i++)
      {
        _data[i] = CellBottom.Data[i + 1];
      }

      _data[_data.LayerCount - 1] = TopoGraphy.Data;
    }
Exemple #2
0
    /// <summary>
    /// Returns a Matrix3D with the data for the TimeStep, Item
    /// TimeStep counts from 0, Item from 1.
    /// </summary>
    /// <param name="TimeStep"></param>
    /// <param name="Item"></param>
    /// <returns></returns>
    public Matrix3d GetData(int TimeStep, int Item)
    {
      Dictionary<int, CacheEntry> _timeValues;
      CacheEntry cen;

      lock (LockThis)
      {
        if (!_bufferData.TryGetValue(Item, out _timeValues))
        {
          _timeValues = new Dictionary<int, CacheEntry>();
          _bufferData.Add(Item, _timeValues);
        }
        if (!_timeValues.TryGetValue(TimeStep, out cen))
        {
          var dfsdata = ReadItemTimeStep(TimeStep, Item);
          Matrix3d _data = new Matrix3d(_numberOfRows, _numberOfColumns, _numberOfLayers);

          int m = 0;
          for (int k = 0; k < NumberOfLayers; k++)
          {
            var _jagged = _data[k];
            for (int i = 0; i < NumberOfRows; i++)
              for (int j = 0; j < NumberOfColumns; j++)
              {
                _jagged[i, j] = dfsdata[m];
                m++;
              }
            _data[k] = _jagged; ;
          }

          cen = new CacheEntry(AbsoluteFileName, Item, TimeStep, _data);
          _timeValues.Add(TimeStep, cen);
          CheckBuffer();
        }
        else
          AccessList.Remove(cen);

        AccessList.AddLast(cen);
      }
      return cen.Data3d;
    }
Exemple #3
0
 internal CacheEntry(string FileName, int Item, int TimeStep, Matrix3d Data)
     : this(FileName, Item, TimeStep)
 {
     this.Data3d = Data;
 }
Exemple #4
0
    /// <summary>
    /// NOTE: Cannot write data to a cell with a delete value in .dfs3-files written by MikeShe because it uses file compression
    /// </summary>
    /// <param name="TimeStep"></param>
    /// <param name="Item"></param>
    /// <param name="Data"></param>
    public void SetData(int TimeStep, int Item, Matrix3d Data)
    {
      lock (LockThis)
      {

        float[] fdata = new float[Data[0].ColumnCount * Data[0].RowCount * Data.LayerCount];
        int m = 0;
        for (int k = 0; k < Data.LayerCount; k++)
          for (int i = 0; i < Data[0].RowCount; i++)
            for (int j = 0; j < Data[0].ColumnCount; j++)
            {
              fdata[m] = (float)Data[k][i, j];
              m++;
            }
        WriteItemTimeStep(TimeStep, Item, fdata);

        //Now add to buffer
        Dictionary<int, CacheEntry> _timeValues;
        CacheEntry cen;

        if (!_bufferData.TryGetValue(Item, out _timeValues))
        {
          _timeValues = new Dictionary<int, CacheEntry>();
          _bufferData.Add(Item, _timeValues);
        }
        if (!_timeValues.TryGetValue(TimeStep, out cen))
        {
          cen = new CacheEntry(AbsoluteFileName, Item, TimeStep, Data);
          _timeValues.Add(TimeStep, cen);
          CheckBuffer();
        }
        else
          AccessList.Remove(cen);

        AccessList.AddLast(cen);
      }
    }
Exemple #5
0
    public void CreateFile()
    {
      DFS3 df = new DFS3("test.dfs3", 1);
      df.NumberOfColumns = 5;
      df.NumberOfRows = 7;
      df.NumberOfLayers = 3;
      df.XOrigin = 9000;
      df.YOrigin = 6000;
      df.Orientation = 1;
      df.GridSize = 15;
      df.TimeOfFirstTimestep = DateTime.Now;
      df.TimeStep = TimeSpan.FromHours(2);

      df.FirstItem.Name = "SGS Kriged dyn. corr.precip";
      df.FirstItem.EumItem = eumItem.eumIPrecipitationRate;
      df.FirstItem.EumUnit = eumUnit.eumUmillimeterPerDay;


      Matrix3d m3 = new Matrix3d(df.NumberOfRows, df.NumberOfColumns, df.NumberOfLayers);

      m3[0] = new DenseMatrix(df.NumberOfRows, df.NumberOfColumns);
      m3[1] = new DenseMatrix(df.NumberOfRows, df.NumberOfColumns, 3);
      m3[2] = new DenseMatrix(df.NumberOfRows, df.NumberOfColumns, 2);

      m3[3, 4,0] = 25;


      df.SetData(0,1,m3);
      m3[3, 4, 0] = 24;
      m3[3, 4, 1] = 100;
      m3[3, 4, 2] = 110;
      df.SetData(1,1,m3);
      df.Dispose();

      df = new DFS3("test.dfs3");

      Assert.AreEqual(eumItem.eumIPrecipitationRate, df.FirstItem.EumItem);

      Matrix m2 = df.GetData(0, 1)[0];
      Assert.AreEqual(25, m2[3, 4]);

    }