//----------------------------------------
void CBratAlgorithmGeosVelAtp::SetParamValues(CVectorBratAlgorithmParam& args)
{
    CheckInputParams(args);

    // Set latitude
    m_lat = args.at(CBratAlgorithmGeosVelAtp::m_LAT_PARAM_INDEX).GetValueAsDouble();
    // Set longitude
    m_lon = args.at(CBratAlgorithmGeosVelAtp::m_LON_PARAM_INDEX).GetValueAsDouble();
    // Set variable
    m_varValue = args.at(CBratAlgorithmGeosVelAtp::m_VAR_PARAM_INDEX).GetValueAsDouble();
}
//----------------------------------------
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;
  }

}
//----------------------------------------
void CBratAlgoFilterLanczos::CheckInputParams(CVectorBratAlgorithmParam& args) 
{
  CBratAlgorithmBase::CheckInputParams(args);

  for (uint32_t indexParam = 0 ; indexParam < CBratAlgoFilterLanczos::m_INPUT_PARAMS ; indexParam++)
  {
    if (indexParam == CBratAlgoFilterLanczos::m_VAR_PARAM_INDEX)
    {
      CheckInputTypeParams(indexParam, m_expectedTypes, args);
      continue;
    }
    CheckInputTypeParams(indexParam, this->GetInputParamFormat(indexParam), args);
  }

  CBratAlgorithmParam* algoParam = &(args.at(CBratAlgoFilterLanczos::m_VAR_PARAM_INDEX));
  if (algoParam->GetTypeVal() == CBratAlgorithmParam::T_VECTOR_DOUBLE)
  {
    m_varValueArray = algoParam->GetValueAsVectDouble();
  }

}
Exemple #4
0
	void CreateAlgorithmParamVector( CVectorBratAlgorithmParam &brat_args, char **args, size_t argcount )
	{
		// Filling the std::vector with the algorithm parameters
		for ( size_t i = 0; i < argcount; ++i )
		{
			CBratAlgorithmParam value;
			CBratAlgorithmParam::bratAlgoParamTypeVal ParamTypeVal = GetInputParamFormat( (uint32_t)i );

			switch ( ParamTypeVal )
			{
				//case CBratAlgorithmParam::T_UNDEF: break;
				case CBratAlgorithmParam::T_INT:    value.SetValue( s2n<int32_t>( args[ i ] ) ); break;
				case CBratAlgorithmParam::T_LONG:   value.SetValue( s2n<int64_t>( args[ i ] ) ); break;
				case CBratAlgorithmParam::T_FLOAT:  value.SetValue( s2n<float>( args[ i ] ) ); break;
				case CBratAlgorithmParam::T_DOUBLE: value.SetValue( s2n<double>( args[ i ] ) ); break;
				case CBratAlgorithmParam::T_CHAR:   value.SetValue( static_cast<unsigned char>( s2n<unsigned>( args[ i ] ) ) ); break;
				case CBratAlgorithmParam::T_STRING: value.SetValue( std::string( args[ i ] ) ); break;
					//case CBratAlgorithmParam::T_VECTOR_DOUBLE:  break;
				default:
					throw e_invalid_parameter_type;
			}
			brat_args.Insert( value );
		}
	}
//----------------------------------------
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);
  }

}
//----------------------------------------
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);
  }

}