// Method used to cache DataStream objects (new DataLogger)
    public YDataStream _findDataStream(YDataSet dataset, string def)
    {
      string key = dataset.get_functionId() + ":" + def;
      if (_dataStreams.ContainsKey(key))
        return (YDataStream)_dataStreams[key];

      YDataStream newDataStream = new YDataStream(this, dataset, YAPI._decodeWords(def));
      _dataStreams.Add(key, newDataStream);
      return newDataStream;
    }
    //--- (generated code: YDataStream implementation)


    public virtual int _initFromDataSet(YDataSet dataset, List<int> encoded)
    {
      int val = 0;
      int i = 0;
      int iRaw = 0;
      int iRef = 0;
      double fRaw = 0;
      double fRef = 0;
      double duration_float = 0;
      List<int> iCalib = new List<int>();

      // decode sequence header to extract data
      this._runNo = encoded[0] + (((encoded[1]) << (16)));
      this._utcStamp = encoded[2] + (((encoded[3]) << (16)));
      val = encoded[4];
      this._isAvg = (((val) & (0x100)) == 0);
      this._samplesPerHour = ((val) & (0xff));
      if (((val) & (0x100)) != 0)
      {
        this._samplesPerHour = this._samplesPerHour * 3600;
      }
      else
      {
        if (((val) & (0x200)) != 0)
        {
          this._samplesPerHour = this._samplesPerHour * 60;
        }
      }

      val = encoded[5];
      if (val > 32767)
      {
        val = val - 65536;
      }
      this._decimals = val;
      this._offset = val;
      this._scale = encoded[6];
      this._isScal = (this._scale != 0);

      val = encoded[7];
      this._isClosed = (val != 0xffff);
      if (val == 0xffff)
      {
        val = 0;
      }
      this._nRows = val;
      duration_float = this._nRows * 3600 / this._samplesPerHour;
      this._duration = (int)Math.Round(duration_float);
      // precompute decoding parameters
      this._decexp = 1.0;
      if (this._scale == 0)
      {
        i = 0;
        while (i < this._decimals)
        {
          this._decexp = this._decexp * 10.0;
          i = i + 1;
        }
      }
      iCalib = dataset.get_calibration();
      this._caltyp = iCalib[0];
      if (this._caltyp != 0)
      {
        this._calhdl = YAPI._getCalibrationHandler(this._caltyp);
        this._calpar.Clear();
        this._calraw.Clear();
        this._calref.Clear();
        i = 1;
        while (i + 1 < iCalib.Count)
        {
          iRaw = iCalib[i];
          iRef = iCalib[i + 1];
          this._calpar.Add(iRaw);
          this._calpar.Add(iRef);
          if (this._isScal)
          {
            fRaw = iRaw;
            fRaw = (fRaw - this._offset) / this._scale;
            fRef = iRef;
            fRef = (fRef - this._offset) / this._scale;
            this._calraw.Add(fRaw);
            this._calref.Add(fRef);
          }
          else
          {
            this._calraw.Add(YAPI._decimalToDouble(iRaw));
            this._calref.Add(YAPI._decimalToDouble(iRef));
          }
          i = i + 2;
        }
      }
      // preload column names for backward-compatibility
      this._functionId = dataset.get_functionId();
      if (this._isAvg)
      {
        this._columnNames.Clear();
        this._columnNames.Add("" + this._functionId + "_min");
        this._columnNames.Add("" + this._functionId + "_avg");
        this._columnNames.Add("" + this._functionId + "_max");
        this._nCols = 3;
      }
      else
      {
        this._columnNames.Clear();
        this._columnNames.Add(this._functionId);
        this._nCols = 1;
      }
      // decode min/avg/max values for the sequence
      if (this._nRows > 0)
      {
        this._minVal = this._decodeVal(encoded[8]);
        this._maxVal = this._decodeVal(encoded[9]);
        this._avgVal = this._decodeAvg(encoded[10] + (((encoded[11]) << (16))), this._nRows);
      }
      return 0;
    }