Example #1
0
//----------------------------------------
void CBratAlgoFilterKernel::SetParamValueExtrapolate(CVectorBratAlgorithmParam& args, uint32_t paramIndex)
{
  if (!isDefaultValue(m_extrapolate))
  {
    return;
  }

  int32_t valueInt32;

  // Set extrapolate flag (once)
  this->CheckConstantParam(paramIndex);

  valueInt32 = args.at(paramIndex).GetValueAsInt();
  if (valueInt32 < 0)
  {
    throw CAlgorithmException(CTools::Format("'%s' algorithm can't be applied because the '%s' parameter (%d) is not equal to 0 or 1. " 
                                              "You have to adjust the '%s'  parameter.", 
                                              this->GetName().c_str(), 
                                              this->GetParamName(paramIndex).c_str(),
                                              valueInt32, 
                                              this->GetParamName(paramIndex).c_str()),
                              this->GetName(), BRATHL_LOGIC_ERROR);
  }

  m_extrapolate = valueInt32;
  if (isDefaultValue(valueInt32))
  {
    m_extrapolate = 0;
  }

}
Example #2
0
//----------------------------------------
void CBratAlgoFilterLanczos::PrepareDataReading2DY()
{
  uint32_t halfWindowHeight = m_dataWindowHeight/2;

  m_countY = 0;
  m_countX = 0;
  m_addHeightBottom = 0;
  m_addHeightTop = 0;
  m_addWidthRight = 0;
  m_addWidthLeft = 0;
  m_gapWidth = 0;
  m_gapHeight = 0;

  if (CTools::IsEven(m_dataWindowWidth))
  {
    m_gapWidth = 1;
  }

  if (CTools::IsEven(m_dataWindowHeight))
  {
    m_gapHeight = 1;
  }


  // Set number of data to read for 2D fields
  m_field2DAsRef = NULL;

  CObMap::const_iterator itMap;
  for (itMap = m_fieldVarsCaller.begin(); itMap != m_fieldVarsCaller.end() ; itMap++)
  { 
    CFieldNetCdf* fieldCaller = CExternalFiles::GetFieldNetCdf(itMap->second);
    
    int32_t nbDims = fieldCaller->GetNbDims();
    if (nbDims != 2)
    {
      continue;
    }

    //fieldCaller->Dump(*CTrace::GetDumpContext());
  
    uint32_t indexX = fieldCaller->GetDimsIndexArray()[0];
    uint32_t indexY = fieldCaller->GetDimsIndexArray()[1];

    if (indexX == 1)
    {
      string msg = "qsdsqd";
    }

    uint32_t dimX = fieldCaller->GetDimAt(0);
    uint32_t dimY = fieldCaller->GetDimAt(1);

    if (m_dataWindowWidth > dimX)
    {
      throw CAlgorithmException(CTools::Format("'%s' algorithm can't be applied because the window width parameter (%d) is greater than the X-dimension value (%d) of the variable '%s' within the data file (%s). "
                                               "You have to decrease the window width parameter", 
                                                this->GetName().c_str(), m_dataWindowWidth, dimX, itMap->first.c_str(), m_currentFileName.c_str()),
                                this->GetName(), BRATHL_LOGIC_ERROR);
    }

    if (m_dataWindowHeight > dimY)
    {
      throw CAlgorithmException(CTools::Format("'%s' algorithm can't be applied because the window height parameter (%d) is greater than the Y-dimension value (%d) of the variable '%s' within the data file (%s). "
                                               "You have to decrease the window width parameter", 
                                                this->GetName().c_str(), m_dataWindowHeight, dimY, itMap->first.c_str(), m_currentFileName.c_str()),
                                this->GetName(), BRATHL_LOGIC_ERROR);
    }
    
    CFieldNetCdf* field = CExternalFiles::GetFieldNetCdf(m_fieldVars.Exists(fieldCaller->GetName()));
    if (field->GetDimsIndexArray() == NULL)
    {
      field->NewDimIndexArray();
    }

    if (m_field2DAsRef == NULL)
    {
      m_field2DAsRef = field;
    }


    m_addWidthRight = 0;
    m_addWidthLeft = 0;
    //int32_t minIndexX = 0;
    //m_countX = m_dataWindowWidth;
    int32_t minIndexX = indexX;
    m_countX = 1;


    int32_t minIndexY = 0;
    m_countY = m_dataWindowHeight;
    m_addHeightBottom = 0;
    m_addHeightTop = 0;

    if (indexY < halfWindowHeight) 
    {
      m_addHeightTop = (halfWindowHeight - indexY);
      m_countY -= m_addHeightTop;
    }
    else 
    {
      minIndexY = indexY - halfWindowHeight;
      if ((indexY + halfWindowHeight) >= dimY)
      {
        m_addHeightBottom = (halfWindowHeight + indexY + 1) - dimY;
        m_countY -= m_addHeightBottom;
      }
    }
    
    // Read data from Netcdf file
    field->GetDimsIndexArray()[0] = minIndexX;
    field->GetDimsCountArray()[0] = m_countX;
    
    field->GetDimsIndexArray()[1] = minIndexY;
    field->GetDimsCountArray()[1] = m_countY;
    
  }

  // Set number of data to read for 1D fields
  for (itMap = m_fieldVars.begin(); itMap != m_fieldVars.end() ; itMap++)
  { 
    CFieldNetCdf* field = CExternalFiles::GetFieldNetCdf(itMap->second);
    
    int32_t nbDims = field->GetNbDims();
    if (nbDims != 1)
    {
      continue;
    }

    if (field->GetDimsIndexArray() == NULL)
    {
      field->NewDimIndexArray();
    }

    CFieldNetCdf* fieldTemp = CExternalFiles::GetFieldNetCdf(m_fieldDependOnXDim.Exists(itMap->first), false);
    if (fieldTemp != NULL)
    {
      field->GetDimsIndexArray()[0] = m_field2DAsRef->GetDimsIndexArray()[0];
      field->GetDimsCountArray()[0] = m_field2DAsRef->GetDimsCountArray()[0];
      continue;
    }

    fieldTemp = CExternalFiles::GetFieldNetCdf(m_fieldDependOnYDim.Exists(itMap->first), false);
    if (fieldTemp != NULL)
    {
      field->GetDimsIndexArray()[0] = m_field2DAsRef->GetDimsIndexArray()[1];
      field->GetDimsCountArray()[0] = m_field2DAsRef->GetDimsCountArray()[1];
    }

  }


}
Example #3
0
//----------------------------------------
void CBratAlgoFilterLanczos::SetParamValues(CVectorBratAlgorithmParam& args)
{    
  CheckInputParams(args);

  // Set variable
  m_varValue = args.at(CBratAlgoFilterLanczos::m_VAR_PARAM_INDEX).GetValueAsDouble();

  int32_t valueInt32;

  // Set data window size (once)
  if (CTools::IsDefaultValue(m_dataWindowLength))
  {
    this->CheckConstantParam(CBratAlgoFilterLanczos::m_WINDOW_PARAM_INDEX);

    valueInt32 = args.at(CBratAlgoFilterLanczos::m_WINDOW_PARAM_INDEX).GetValueAsInt();
    if (valueInt32 <= 0)
    {
      throw CAlgorithmException(CTools::Format("'%s' algorithm can't be applied because the window size parameter (%d) is not greater than 0. " 
                                               "You have to adjust the '%s' parameter.", 
                                                this->GetName().c_str(), valueInt32, 
                                                this->GetParamName(CBratAlgoFilterLanczos::m_WINDOW_PARAM_INDEX).c_str()),
                                this->GetName(), BRATHL_LOGIC_ERROR);
    }

    m_dataWindowLength = valueInt32;
    if (CTools::IsDefaultValue(valueInt32))
    {
      m_dataWindowLength = 3;
    }
    if (CTools::IsEven(m_dataWindowLength))
    {
      throw CAlgorithmException(CTools::Format("'%s' algorithm can't be applied because the window size parameter (%d) is not an odd number." 
                                               "You have to adjust the '%s' parameter.", 
                                                this->GetName().c_str(), m_dataWindowLength,
                                                this->GetParamName(CBratAlgoFilterLanczos::m_WINDOW_PARAM_INDEX).c_str()),
                                this->GetName(), BRATHL_LOGIC_ERROR);

    }

    m_dataWindowWidth = m_dataWindowLength;
    m_dataWindowHeight = m_dataWindowLength;
  }

  // Set valid points limit (once)
  if (CTools::IsDefaultValue(m_validPts))
  {
    this->CheckConstantParam(CBratAlgoFilterLanczos::m_VALID_PARAM_INDEX);

    valueInt32 = args.at(CBratAlgoFilterLanczos::m_VALID_PARAM_INDEX).GetValueAsInt();
    if (valueInt32 <= 0)
    {
      throw CAlgorithmException(CTools::Format("'%s' algorithm can't be applied because the '%s' parameter (%d) is less than or equal to 0. " 
                                               "You have to adjust the '%s'  parameter.", 
                                                this->GetName().c_str(), 
                                                this->GetParamName(CBratAlgoFilterLanczos::m_VALID_PARAM_INDEX).c_str(),
                                                valueInt32, 
                                                this->GetParamName(CBratAlgoFilterLanczos::m_VALID_PARAM_INDEX).c_str()),
                                this->GetName(), BRATHL_LOGIC_ERROR);
    }

    m_validPts = valueInt32;
    if (CTools::IsDefaultValue(valueInt32))
    {
      m_validPts = GetDataWindowSize()/2;
    }

    if (GetDataWindowSize() < m_validPts)
    {
      throw CAlgorithmException(CTools::Format("'%s' algorithm can't be applied because the window size %d (%dx%d) is less than the minimum number of valid points parameter (%d). "
                                               "You have to adjust either the '%s' parameter or the '%s' parameter.", 
                                               this->GetName().c_str(), GetDataWindowSize(), m_dataWindowLength, m_dataWindowLength, m_validPts,
                                               this->GetParamName(CBratAlgoFilterLanczos::m_WINDOW_PARAM_INDEX).c_str(),
                                               this->GetParamName(CBratAlgoFilterLanczos::m_VALID_PARAM_INDEX).c_str()),
                                this->GetName(), BRATHL_LOGIC_ERROR);
    }
  }

  // Set cut-off period  (once)
  if (CTools::IsDefaultValue(m_cutOffPeriod))
  {
    this->CheckConstantParam(CBratAlgoFilterLanczos::m_CUTOFF_PERIOD_PARAM_INDEX);

    valueInt32 = args.at(CBratAlgoFilterLanczos::m_CUTOFF_PERIOD_PARAM_INDEX).GetValueAsInt();
    if (valueInt32 < 0)
    {
      throw CAlgorithmException(CTools::Format("'%s' algorithm can't be applied because the '%s' parameter (%d) is strictly less than 0. " 
                                               "You have to adjust the '%s'  parameter.", 
                                                this->GetName().c_str(), 
                                                this->GetParamName(CBratAlgoFilterLanczos::m_CUTOFF_PERIOD_PARAM_INDEX).c_str(),
                                                valueInt32, 
                                                this->GetParamName(CBratAlgoFilterLanczos::m_CUTOFF_PERIOD_PARAM_INDEX).c_str()),
                                this->GetName(), BRATHL_LOGIC_ERROR);
    }

    m_cutOffPeriod = valueInt32;
    if (CTools::IsDefaultValue(valueInt32))
    {
      this->GetParamDefValue(CBratAlgoFilterLanczos::m_CUTOFF_PERIOD_PARAM_INDEX, m_cutOffPeriod);
    }

    m_cutOffFrequency = 1.0/static_cast<double>(m_cutOffPeriod);

  }

  // Set extrapolate flag (once)
  if (CTools::IsDefaultValue(m_extrapolate))
  {
    SetParamValueExtrapolate(args, CBratAlgoFilterLanczos::m_EXTRAPOLATE_PARAM_INDEX);
  }

}
//----------------------------------------
double CBratAlgoFilterGaussian1D::Run(CVectorBratAlgorithmParam& args)
{
  int32_t iRecord = m_callerProduct->GetCurrentRecordNumber();

  if (iRecord == m_callerProductRecordPrev)
  {
    // Do nothing: data have been already computed
    return m_gaussian;
  }

  setDefaultValue(m_gaussian);
  
  OpenProductFile();

  // Gets the next record regarding to the current product record.
  // and save previous values.
  //this->GetNextData();

  // Get current parameter values (included expression value)
  SetParamValues(args);

  //// Set only the first value, others values will be stored in the 'SetNextValues'
  //if (m_rawDataWindow.size() <= 0)
  //{
  //  m_rawDataWindow.Insert(m_varValue);
  //}


  if (m_dataWindowLength > static_cast<uint32_t>(m_nProductRecords))
  {
    throw CAlgorithmException(CTools::Format("'%s' algorithm can't be applied because the window size parameter (%d) is greater than the number of data values (%d) within the data file (%s). "
                                             "You have to decrease the window size parameter", 
                                              this->GetName().c_str(), m_dataWindowLength, m_nProductRecords, m_currentFileName.c_str()),
                              this->GetName(), BRATHL_LOGIC_ERROR);
  }

  if (m_dataWindowLength < 1)
  {
    PrepareReturn();
    return m_gaussian;
  }

  if (m_dataWindowLength == 1)
  {
    m_gaussian = m_varValue;
    PrepareReturn();
    return m_varValue;
  }

  // If 'default value' and no extrapolation then returns
  if (isDefaultValue(m_varValue) && (m_extrapolate == 0))
  {
    PrepareReturn();
    return m_gaussian;
  }

  uint32_t shiftSymmetry = 1;
  
  PrepareDataValues1D(shiftSymmetry);

  ComputeGaussian();

  PrepareReturn();

  return m_gaussian;
}
Example #5
0
//----------------------------------------
void CBratAlgoFilterLoess2D::SetParamValues(CVectorBratAlgorithmParam& args)
{    
  CheckInputParams(args);

  // Set variable
  m_varValue = args.at(CBratAlgoFilterLoess2D::m_VAR_PARAM_INDEX).GetValueAsDouble();

  int32_t valueInt32;

  // Set data window width (once)
  if (isDefaultValue(m_dataWindowWidth))
  {
    this->CheckConstantParam(CBratAlgoFilterLoess2D::m_WINDOW_WIDTH_PARAM_INDEX);
    
    valueInt32 = args.at(CBratAlgoFilterLoess2D::m_WINDOW_WIDTH_PARAM_INDEX).GetValueAsInt();
    if (valueInt32 <= 0)
    {
      throw CAlgorithmException(CTools::Format("'%s' algorithm can't be applied because the window width parameter (%d) is not greater than 0. " 
                                               "You have to adjust the '%s' parameter.", 
                                                this->GetName().c_str(), valueInt32, 
                                                this->GetParamName(CBratAlgoFilterLoess2D::m_WINDOW_WIDTH_PARAM_INDEX).c_str()),
                                this->GetName(), BRATHL_LOGIC_ERROR);
    }

    m_dataWindowWidth = valueInt32;

    if (isDefaultValue(valueInt32))
    {
      m_dataWindowWidth = 3;
    }
    if (CTools::IsEven(m_dataWindowWidth))
    {
      throw CAlgorithmException(CTools::Format("'%s' algorithm can't be applied because the window width parameter (%d) is not an odd number." 
                                               "You have to adjust the '%s' parameter.", 
                                                this->GetName().c_str(), m_dataWindowWidth,
                                                this->GetParamName(CBratAlgoFilterLoess2D::m_WINDOW_WIDTH_PARAM_INDEX).c_str()),
                                this->GetName(), BRATHL_LOGIC_ERROR);

    }
  }

  // Set data window height (once)
  if (isDefaultValue(m_dataWindowHeight))
  {
    this->CheckConstantParam(CBratAlgoFilterLoess2D::m_WINDOW_HEIGHT_PARAM_INDEX);

    valueInt32 = args.at(CBratAlgoFilterLoess2D::m_WINDOW_HEIGHT_PARAM_INDEX).GetValueAsInt();
    if (valueInt32 <= 0)
    {
      throw CAlgorithmException(CTools::Format("'%s' algorithm can't be applied because the window height parameter (%d) is not greater than 0. " 
                                               "You have to adjust the '%s'  parameter.", 
                                                this->GetName().c_str(), valueInt32, 
                                                this->GetParamName(CBratAlgoFilterLoess2D::m_WINDOW_HEIGHT_PARAM_INDEX).c_str()),
                                this->GetName(), BRATHL_LOGIC_ERROR);
    }

    m_dataWindowHeight = valueInt32;

    if (isDefaultValue(valueInt32))
    {
      m_dataWindowHeight = 3;
    }

    if (CTools::IsEven(m_dataWindowHeight))
    {
      throw CAlgorithmException(CTools::Format("'%s' algorithm can't be applied because the window height parameter (%d) is not an odd number."
                                               "You have to adjust the '%s'  parameter.", 
                                                this->GetName().c_str(), m_dataWindowHeight,
                                                this->GetParamName(CBratAlgoFilterLoess2D::m_WINDOW_HEIGHT_PARAM_INDEX).c_str()),
                                this->GetName(), BRATHL_LOGIC_ERROR);

    }

  }

  // Set valid points limit (once)
  if (isDefaultValue(m_validPts))
  {
    this->CheckConstantParam(CBratAlgoFilterLoess2D::m_VALID_PARAM_INDEX);

    valueInt32 = args.at(CBratAlgoFilterLoess2D::m_VALID_PARAM_INDEX).GetValueAsInt();
    if (valueInt32 <= 0)
    {
      throw CAlgorithmException(CTools::Format("'%s' algorithm can't be applied because the '%s' parameter (%d) is less than or equal to 0. " 
                                               "You have to adjust the '%s'  parameter.", 
                                                this->GetName().c_str(), 
                                                this->GetParamName(CBratAlgoFilterLoess2D::m_VALID_PARAM_INDEX).c_str(),
                                                valueInt32, 
                                                this->GetParamName(CBratAlgoFilterLoess2D::m_VALID_PARAM_INDEX).c_str()),
                                this->GetName(), BRATHL_LOGIC_ERROR);
    }


    m_validPts = valueInt32;
    if (isDefaultValue(valueInt32))
    {
      m_validPts = GetDataWindowSize()/2;
    }

    if (GetDataWindowSize() < m_validPts)
    {
      throw CAlgorithmException(CTools::Format("'%s' algorithm can't be applied because the window size parameter (%dx%d=%d ) is less than the minimum number of valid points parameter (%d). " 
                                               "You have to adjust either the '%s' or '%s' parameters or the '%s' parameter.", 
                                                this->GetName().c_str(), m_dataWindowWidth, m_dataWindowHeight, GetDataWindowSize(), m_validPts,
                                                this->GetParamName(CBratAlgoFilterLoess2D::m_WINDOW_WIDTH_PARAM_INDEX).c_str(),
                                                this->GetParamName(CBratAlgoFilterLoess2D::m_WINDOW_HEIGHT_PARAM_INDEX).c_str(),
                                                this->GetParamName(CBratAlgoFilterLoess2D::m_VALID_PARAM_INDEX).c_str()),
                                this->GetName(), BRATHL_LOGIC_ERROR);
    }
  }

  // Set extrapolate flag (once)
  if (isDefaultValue(m_extrapolate))
  {
    SetParamValueExtrapolate(args, CBratAlgoFilterLoess2D::m_EXTRAPOLATE_PARAM_INDEX);
  }

}
Example #6
0
//----------------------------------------
double CBratAlgoFilterLoess2D::ComputeMean()
{
  throw CAlgorithmException(CTools::Format("'%s' algorithm can't be applied because input data are an array of values and not a single value. "
                                           "Perhaps, you are trying to reduce the two-dimensionals data to only one of its dimensions. " 
                                           "This use case is not implemented.", 
                                          this->GetName().c_str()),
                          this->GetName(), BRATHL_LOGIC_ERROR);

  // TODO
  //CDoubleArray varValueArrayTmp;

  //if (m_varValueArray == NULL)
  //{
  //  varValueArrayTmp.Insert(m_varValue);
  //  m_varValueArray = &varValueArrayTmp;
  //}

  //uint32_t iVarValue;
  //
  //setDefaultValue(m_median);
  //double countValue = 0.0;
  //double dummy = 0.0;

  //double medianTmp;
  //setDefaultValue(medianTmp);

  //SetField2DAsRef();

  //uint32_t xArraySize =  m_field2DAsRef->Get->size();
  //uint32_t yArraySize =  m_latArray->size();

  //if (m_varDimLonIndex == 0)
  //{
  //  for (iLon = 0 ; iLon < lonArraySize ; iLon++)
  //  {
  //    m_lon = m_lonArray->at(iLon);
  //    m_indexLon = this->GetLongitudeIndex(m_lon);

  //    for (iLat = 0 ; iLat < latArraySize ; iLat++)
  //    {
  //      m_lat = m_latArray->at(iLat);
  //      m_indexLat = this->GetLatitudeIndex(m_lat);

  //      iVarValue = (iLon * m_latArray->size()) + iLat;
  //      m_varValue = m_varValueArray->at(iVarValue);
  //      
  //      ComputeSingle();

	 //     CTools::DoIncrementalStats(m_velocity,
	 //                          countValue,
	 //                          velocityTmp,
	 //                          dummy,
	 //                          dummy,
	 //                          dummy);
  //    }
  //  }
  //}
  //else if (m_varDimLatIndex == 0)
  //{
  //  for (iLat = 0 ; iLat < latArraySize ; iLat++)
  //  {
  //    m_lat = m_latArray->at(iLat);
  //    m_indexLat = this->GetLatitudeIndex(m_lat);

  //    for (iLon = 0 ; iLon < lonArraySize ; iLon++)
  //    {
  //      m_lon = m_lonArray->at(iLon);
  //      m_indexLon = this->GetLongitudeIndex(m_lon);

  //      iVarValue = (iLat * m_lonArray->size()) + iLon;
  //      m_varValue = m_varValueArray->at(iVarValue);
  //      
  //      ComputeSingle();

	 //     CTools::DoIncrementalStats(m_velocity,
	 //                          countValue,
	 //                          velocityTmp,
	 //                          dummy,
	 //                          dummy,
	 //                          dummy);
  //    }
  //  }
  //}

  //m_median = medianTmp;

  return m_loess;
}
Example #7
0
//----------------------------------------
void CBratAlgoFilterKernel::PrepareDataValues1D(uint32_t shiftSymmetry)
{
  int32_t iRecord = m_callerProduct->GetCurrentRecordNumber();

  uint32_t gapHalfWindow = 1;
  uint32_t halfWindow =  m_dataWindowLength / 2;
  if (CTools::IsEven(m_dataWindowLength))
  {
    gapHalfWindow = 0;
  }

  // Is it the begin of the data file ?
  // read data (half window) and treat left edge
  int32_t iRecordTmp = iRecord - halfWindow;

  if ((m_rawDataWindow.size() < m_dataWindowLength) && (iRecordTmp <= 0))
  {
    // Need to read previous values ? 
    if (iRecord > 0)
    {
      // Read previous data and add a new element within the window
      for (int32_t i = 0 ; i < iRecord ; i++)
      {
        this->GetData1D(i);
      }

    }

    // Add current value (the centered value)
    this->InsertCurrentValueDataWindow1D();

    int32_t endRead = halfWindow + gapHalfWindow;
    // read next values;
    for (int32_t i = 1 ; i < endRead ; i++)
    {
      this->GetData1D(iRecord + i);
    }
    
    //while (m_rawDataWindow.size() < (halfWindow + gapHalfWindow))
    //{
    //  this->GetData1D(iRecord + m_gapFromCurrentRecord + 1);
    //  m_gapFromCurrentRecord++;
    //}
    //if (m_gapFromCurrentRecord > 0)
    //{
    //  m_gapFromCurrentRecord--;
    //}

    // Treating left edge
    // For all window filters there is some problem. 
    // That is edge treating. If you place window over first element, the left  part of the window will be empty.
    // Data should be extended symmetrically.
    uint32_t i = 0;
    while (m_rawDataWindow.size() < m_dataWindowLength)
    //for (uint32_t i = 0 ; i < halfWindow ; i++)
    {
      this->TreatLeftEdge1D(shiftSymmetry, i);
      i++;
      //m_rawDataWindow.InsertAt(m_rawDataWindow.begin(), *(m_rawDataWindow.begin() + shiftSymmetry + (i * 2)));
    }

  }
  else
  {   
    // At least a new record has been read from the caller

    // Get the current record of the product use in the algo.
    // and compare it with the current record of the caller's product
    int32_t currentAlgoRecord = m_product->GetCurrentRecordNumber();

    // Treating right edge
    // For all window filters there is some problem. 
    // That is edge treating. If you place window over last element, the right part of the window will be empty.
    // Data should be extended symmetrically.
    if (currentAlgoRecord >= m_nProductRecords - 1)
    {
      //std::cout << "THIS IS THE END OF FILE:" << std::endl;
      this->TreatRightEdge1D(shiftSymmetry, m_lastIndexDataToInsert);
      m_lastIndexDataToInsert++;
    }

    // Need to read previous values ? 
    if (currentAlgoRecord < iRecordTmp)
    {
      currentAlgoRecord = iRecordTmp;

      if (currentAlgoRecord < 0)
      {
        throw CAlgorithmException(CTools::Format("Algorithm %s - The current record of the product is negative (%d). This should never happened. "
                                    "\nThe current record of the caller is %d."
                                    "\nThere is something wrong in the Brat software."
                                    "\nPlease contact Brat Helpdesk", 
                                    this->GetName().c_str(), currentAlgoRecord, iRecord),
                                    this->GetName(), BRATHL_LOGIC_ERROR);
      }


      // Read previous data and add a new element within the window
      while (currentAlgoRecord < iRecord)
      {
        this->GetData1D(currentAlgoRecord);
        currentAlgoRecord++;
      }

      // Add current value (the centered value)
      this->InsertCurrentValueDataWindow1D();

      int32_t endRead =  iRecord + halfWindow + gapHalfWindow;
      
      // read next values;
      for (int32_t i = currentAlgoRecord + 1 ; i < endRead ; i++)
      {
        if (i >= m_nProductRecords)
        {
          // Treating right edge
          this->TreatRightEdge1D(shiftSymmetry, m_lastIndexDataToInsert);
          m_lastIndexDataToInsert++;
        }
        else
        {
         this->GetData1D(i);
        }
      }
    }
    else
    {
      // Read the next values
      // Add a new element within the window

      int32_t endRead =  iRecord + halfWindow + gapHalfWindow;

      for (int32_t i = currentAlgoRecord + 1 ; i < endRead ; i++)
      {
          this->GetData1D(i);
      }
    }

    // Remove elements that are not inside the window.
    while (m_rawDataWindow.size() > m_dataWindowLength)
    {
      this->RemoveFirstItemDataWindow1D();
    }
  
  }

}