예제 #1
0
void JplApproximateEphemeris::VLoad()
{
   // make_unique not supported in c++11
   g_ephemerisDatabase = std::unique_ptr<JplApproximateEphemerisIO>(new JplApproximateEphemerisIO(GetDataFilename()));
   try
   {
      g_ephemerisDatabase->Initialize();
   }
   catch (std::exception ex)
   {
      OTL_FATAL() << "Exception caught while trying to load ephemeris datafile " <<
         Bracket(GetDataFilename()) << ": " << Bracket(ex.what());
   } 
}
예제 #2
0
PhysicalProperties JplApproximateEphemeris::VGetPhysicalProperties(const std::string& name)
{
   try
   {
      return GetPlanetPhysicalProperties(name);
   }
   catch (std::exception ex)
   {
      OTL_ERROR() << "Exception caught while trying to retrieve physical properties for "
         << Bracket(name) << ": " << Bracket(ex.what());
   }

   return PhysicalProperties();
}
예제 #3
0
OrbitalElements JplApproximateEphemeris::VGetOrbitalElements(const std::string& name, const Epoch& epoch)
{
   try
   {
      return g_ephemerisDatabase->GetOrbitalElements(name, epoch);
   }
   catch (std::exception ex)
   {
      OTL_ERROR() << "Exception caught while trying to retrieve state vector for " << Bracket(name) <<
         " at epoch " << Bracket(epoch) << ": " << Bracket(ex.what());
   }

   return OrbitalElements(); 
}
예제 #4
0
LagrangianPropagator::LagrangeCoefficients LagrangianPropagator::CalculateLagrangeCoefficients(double r0, double seconds, double sqrtMu, const UniversalVariableResult& result)
{
   // Unpack the inputs
   const double& x = result.x;
   const double& r = result.r;
   const double& psi = result.psi;
   const double& c2 = result.stumpff.c2;
   const double& c3 = result.stumpff.c3;

   // Create aliases for Lagrange coefficients
   LagrangeCoefficients coeff;
   double& f = coeff.f;
   double& g = coeff.g;
   double& fDot = coeff.fDot;
   double& gDot = coeff.gDot;

   f = 1.0 - SQR(x) / r0 * c2;
   fDot = sqrtMu / r / r0 * x * (psi * c3 - 1.0);
   g = seconds - pow(x, 3.0) / sqrtMu * c3;
   gDot = 1.0 - SQR(x) / r * c2;

   double sanityCheck = std::abs((f * gDot - fDot * g) - 1.0);
   OTL_WARN_IF(sanityCheck > MATH_TOLERANCE, "Sanity check failed for " << Bracket(sanityCheck) << " == " << Bracket(MATH_TOLERANCE));

   return coeff;
}
예제 #5
0
int main() {

    bool isBalanced = true;
    int errorPos = 0;

    std::string text;
    getline(std::cin, text);

    std::stack <Bracket> opening_brackets_stack;
    for (int position = 0; position < text.length(); ++position) {
        char next = text[position];

        if (next == '(' || next == '[' || next == '{') {
            // Process opening bracket, write your code here
            Bracket b = Bracket(next, position);
            opening_brackets_stack.push(b);
        }

        if (next == ')' || next == ']' || next == '}') {
            // Process closing bracket, write your code here
           if( opening_brackets_stack.empty() == false )
           {
            Bracket b = opening_brackets_stack.top();
            if ( b.Matchc(next) == false  ) {
              isBalanced = false;
              errorPos = position;
              break;
            } else
                opening_brackets_stack.pop();
           } else 
             { 
               isBalanced = false;
               errorPos = position;
               break;
             }
        }
    }
    
    if(opening_brackets_stack.empty() == false && isBalanced == true) 
    {
      isBalanced = false;
      errorPos = opening_brackets_stack.top().position;
    }

    // Printing answer, write your code here
    if ( isBalanced ) 
    	std::cout << "Success" << "\n";
    else 
        std::cout << errorPos+1 << "\n";
    
    return 0;
}
예제 #6
0
Epoch MpcorbEphemeris::GetReferenceEpoch(const std::string& name)
{
   if (IsValidName(name))
   {
      UpdateReference(name);
      return m_referenceEpoch;
   }
   else
   {
      OTL_ERROR() << "Name " << Bracket(name) << " not found";
   }
   return Epoch();
}
예제 #7
0
OrbitalElements MpcorbEphemeris::GetReferenceOrbitalElements(const std::string& name)
{
   if (IsValidName(name))
   {
      UpdateReference(name);
      return m_referenceOrbitalElements;
   }
   else
   {
      OTL_ERROR() << "Name " << Bracket(name) << " not found";
   }
   return OrbitalElements();
}
예제 #8
0
PhysicalProperties MpcorbEphemeris::VGetPhysicalProperties(const std::string& name)
{
   try
   {
      return g_ephemerisDatabase->GetPhysicalProperties(name);
   }
   catch (std::exception ex)
   {
      OTL_ERROR() << "Exception caught while retrieving physical properties for " << Bracket(name);
   }

   return PhysicalProperties();
}
예제 #9
0
TString MillePedeTrees::ParSi(const TString &tree, UInt_t iParam) const
{
  TString index(Form("%sparSize*%d", tree.Data(), iParam));
  if (iParam > 1) {
    UInt_t aParNum = 1;
    UInt_t reducer = 0;
    while (aParNum < iParam) {
      reducer += aParNum;
      ++aParNum;
    }
    index += Form("-%d", reducer);
  }

  return Sqrt((tree + "Cov") += Bracket(index));
}
예제 #10
0
////////////////////////////////////////////////////////////
// Vallado, preferred method but nearly identical performance-wise as Curtis
LagrangianPropagator::UniversalVariableResult
LagrangianPropagator::CalculateUniversalVariable(double r0, double v0, double rdotv, double seconds, double mu)
{
   // Create aliases for results
   UniversalVariableResult results;
   double& x = results.x;
   double& r = results.r;
   double& psi = results.psi;
   double& c2 = results.stumpff.c2;
   double& c3 = results.stumpff.c3;
   auto& stumpff = results.stumpff;

   // Compute frequently used variables
   double sqrtMu = sqrt(mu);
   double alpha = 2.0 / r0 - SQR(v0) / mu; // Reciprocal of semi-major axis

   // Compute the initial guess depending on orbit type
   x = CalculateUniversableVariableInitialGuess(r0, v0, rdotv, alpha, seconds, mu);

   // Solve using Newton-Raphson iteration
   int iter = 0;
   const int MAX_ITERATIONS = 100;
   double xPrev, error = MATH_INFINITY;
   while (error >= MATH_TOLERANCE && iter++ < MAX_ITERATIONS)
   {
      xPrev = x;
      double xSquared = SQR(x);
      psi = xSquared * alpha;
      stumpff = CalculateStumpffParameters(psi);
      r = xSquared * c2 + (rdotv / sqrtMu) * x * (1.0 - psi * c3) + r0 * (1.0 - psi * c2);
      x += (sqrtMu * seconds - pow(x, 3.0) * c3 - rdotv / sqrtMu * xSquared * c2 - r0 * x * (1.0 - psi * c3)) / r;
      error = fabs(x - xPrev);
   }
   OTL_WARN_IF(iter == MAX_ITERATIONS, "Max iterations << " << Bracket(MAX_ITERATIONS) << " reached before error " << Bracket(error) << " within tolerance " << Bracket(MATH_TOLERANCE));

   return results;
}
예제 #11
0
string Postfix::Record(const string& infstring)const
{

	if (!infstring.length())
		throw
		exception("String is empty");
	Bracket(infstring);
	int tmp1 = Line(infstring);
	if (tmp1)
		throw
		exception("You have entered incorrect string");
	map <char, int> operations;
	operations['*'] = 3;
	operations['/'] = 3;
	operations['+'] = 2;
	operations['-'] = 2;
	operations['('] = 1;
	Stack<char> result;
	Stack<char> operationsstack;
	char temp;
	for (int i = 0; i < infstring.length(); i++)
	{
		if (infstring[i] == ' ')
			continue;
		temp = infstring[i];
		if (operations.count(temp))
		{
			if ((!operationsstack.IsEmpty()) && (operations[temp] <= operations[operationsstack.GetKey()]) && (temp != '('))
				while ((!operationsstack.IsEmpty()) && (operations[temp] <= operations[operationsstack.GetKey()]))
					result.Push(operationsstack.Pop());
			operationsstack.Push(temp);
			continue;
		}
		if (((temp >= 'a') && (temp <= 'z')) || ((temp >= 'A') && (temp <= 'Z')))
		{
			result.Push(temp);
			continue;
		}
		if (temp == ')')
		{
			char t = '0';
			while ((!operationsstack.IsEmpty()) && (t != '('))
			{
				t = operationsstack.Pop();
				result.Push(t);
			}
			if (t == '(')
				result.Pop();
			continue;
		}
		throw 
			exception("You have entered anavailable symbol");
	}
	while (!operationsstack.IsEmpty())
		result.Push(operationsstack.Pop());
	if (result.IsEmpty())
		throw 
			exception("You haven't entered any expression");
	string resultstring = "";
	while (!result.IsEmpty())
		operationsstack.Push(result.Pop());
	while (!operationsstack.IsEmpty())
		resultstring += operationsstack.Pop();
	return resultstring;
}
예제 #12
0
TString MillePedeTrees::ParSi(UInt_t iParam) const
{
  return (MpT() += "Sigma") += Bracket(iParam);
}
예제 #13
0
TString MillePedeTrees::Diff(UInt_t iParam) const
{
  return (MpT() += "DiffBefore") += Bracket(iParam);
}
예제 #14
0
TString MillePedeTrees::Cor(UInt_t iParam) const
{
  return (MpT() += "GlobalCor") += Bracket(iParam);
}
예제 #15
0
TString MillePedeTrees::Valid(UInt_t iParam) const
{
  return (MpT() += "IsValid") += Bracket(iParam);
}