Modified spice2xyzv tool to allow numeric IDs instead of strings. This helps
with objects that don't have an official SPICE name.sensor-dev
parent
2a201628a8
commit
d3e5fe64d4
|
@ -1,6 +1,6 @@
|
|||
// spice2xyzv.cpp
|
||||
//
|
||||
// Copyright (C) 2008, Chris Laurel <claurel@shatters.net>
|
||||
// Copyright (C) 2008-2009, Chris Laurel <claurel@gmail.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
|
@ -14,6 +14,7 @@
|
|||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <cmath>
|
||||
#include <ctime>
|
||||
|
@ -256,6 +257,33 @@ StateVector getStateVector(SpiceInt targetID,
|
|||
}
|
||||
|
||||
|
||||
// Convert a body name to a NAIF ID. Return true if the ID was
|
||||
// found, and false otherwise.
|
||||
bool bodyNameToId(const std::string& name, SpiceInt* naifId)
|
||||
{
|
||||
SpiceBoolean found = SPICEFALSE;
|
||||
|
||||
bodn2c_c(name.c_str(), naifId, &found);
|
||||
if (found)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check to see whether the string is actually a numeric ID
|
||||
istringstream str(name, istringstream::in);
|
||||
int id = 0;
|
||||
str >> id;
|
||||
if (str.eof())
|
||||
{
|
||||
*naifId = id;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool convertSpkToXyzv(const Configuration& config,
|
||||
ostream& out)
|
||||
|
@ -275,18 +303,15 @@ bool convertSpkToXyzv(const Configuration& config,
|
|||
str2et_c(config.startDate.c_str(), &startET);
|
||||
str2et_c(config.endDate.c_str(), &endET);
|
||||
|
||||
SpiceBoolean found = SPICEFALSE;
|
||||
SpiceInt observerID = 0;
|
||||
SpiceInt targetID = 0;
|
||||
bodn2c_c(config.observerName.c_str(), &observerID, &found);
|
||||
if (!found)
|
||||
if (!bodyNameToId(config.observerName, &observerID))
|
||||
{
|
||||
cerr << "Observer object " << config.observerName << " not found. Aborting.\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
bodn2c_c(config.targetName.c_str(), &targetID, &found);
|
||||
if (!found)
|
||||
if (!bodyNameToId(config.targetName, &targetID))
|
||||
{
|
||||
cerr << "Target object " << config.targetName << " not found. Aborting.\n";
|
||||
return false;
|
||||
|
@ -343,13 +368,10 @@ void writeCommentHeader(const Configuration& config,
|
|||
{
|
||||
SpiceInt observerID = 0;
|
||||
SpiceInt targetID = 0;
|
||||
SpiceBoolean found = SPICEFALSE;
|
||||
|
||||
bodn2c_c(config.observerName.c_str(), &observerID, &found);
|
||||
if (!found)
|
||||
if (!bodyNameToId(config.observerName, &observerID))
|
||||
return;
|
||||
bodn2c_c(config.targetName.c_str(), &targetID, &found);
|
||||
if (!found)
|
||||
if (!bodyNameToId(config.targetName, &targetID))
|
||||
return;
|
||||
|
||||
out << "# Celestia xyzv file generated by spice2xyzv\n";
|
||||
|
|
Loading…
Reference in New Issue