Skip to content
Snippets Groups Projects
Unverified Commit 9b0e649f authored by Christine Kim's avatar Christine Kim Committed by GitHub
Browse files

Write comment & replaced std::optional (#33)

parent b9c95a9e
No related branches found
No related tags found
No related merge requests found
......@@ -35,7 +35,7 @@ namespace SpiceQL {
* @param centerOfMotion Naif body code of an object which is the center of motion for
* bodyCode
* @param referenceFrame Naif name of the reference system relative to which the state is
* @param id SPK segment identifier (max size 40)
* @param segmentId SPK segment identifier (max size 40)
* @param degree Degree of the Hermite polynomials used to interpolate the states
* @param stateVelocities Time ordered vector of state velocities dX, dY, dZ
* @param segmentComment The comment string for the new segment
......@@ -45,20 +45,20 @@ namespace SpiceQL {
int bodyCode,
int centerOfMotion,
std::string referenceFrame,
std::string id, int degree,
std::optional<std::vector<std::vector<double>>> stateVelocities,
std::optional<std::string> segmentComment);
std::string segmentId, int degree,
std::vector<std::vector<double>> stateVelocities = {},
std::string segmentComment = "");
//! @cond Doxygen_Suppress
std::vector<double> stateTimes;
int bodyCode;
int centerOfMotion;
std::string referenceFrame;
std::string id;
std::string segmentId;
int polyDegree;
std::vector<std::vector<double>> statePositions;
std::optional<std::vector<std::vector<double>>> stateVelocities;
std::optional<std::string> comment;
std::vector<std::vector<double>> stateVelocities;
std::string comment;
//! @endcond
};
......@@ -82,23 +82,23 @@ namespace SpiceQL {
* @param times times for the CK segment in ascending order
* @param bodyCode Naif body code of an object whose state is described by the segments
* @param referenceFrame Naif name of the reference system relative to which the state is
* @param id SPK segment identifier (max size 40)
* @param anglularVelocities Time ordered vector of state velocities dX, dY, dZ
* @param segmentId SPK segment identifier (max size 40)
* @param angularVelocities Time ordered vector of state velocities dX, dY, dZ
* @param comment The comment string for the new segment
*/
CkSegment(std::vector<std::vector<double>> quats, std::vector<double> times, int bodyCode,
std::string referenceFrame, std::string id,
std::optional<std::vector<std::vector<double>>> anglularVelocities = std::nullopt,
std::optional<std::string> comment = std::nullopt);
std::string referenceFrame, std::string segmentId,
std::vector<std::vector<double>> angularVelocities = {},
std::string comment = "");
//! @cond Doxygen_Suppress
std::vector<double> times;
std::vector<std::vector<double>> quats;
int bodyCode;
std::string referenceFrame;
std::string id;
std::optional<std::vector<std::vector<double>>> angularVelocities = std::nullopt;
std::optional<std::string> comment = std::nullopt;
std::string segmentId;
std::vector<std::vector<double>> angularVelocities;
std::string comment;
//! @endcond
};
......@@ -146,8 +146,8 @@ namespace SpiceQL {
std::string referenceFrame,
std::string segmentId,
int polyDegree,
std::optional<std::vector<std::vector<double>>> stateVelocities = std::nullopt,
std::optional<std::string> segmentComment = std::nullopt);
std::vector<std::vector<double>> stateVelocities = {},
std::string segmentComment = "");
/**
......@@ -174,8 +174,8 @@ namespace SpiceQL {
std::string segmentId,
std::string sclk,
std::string lsk,
std::optional<std::vector<std::vector<double>>> angularVelocity = std::nullopt,
std::optional<std::string> comment= std::nullopt);
std::vector<std::vector<double>> angularVelocity = {},
std::string comment = "");
/**
......@@ -193,6 +193,8 @@ namespace SpiceQL {
std::string lsk,
std::vector<CkSegment> segments);
void writeComment(std::string fileName,
std::string comment);
/**
* @brief Write json key value pairs into a NAIF text kernel
......@@ -202,6 +204,6 @@ namespace SpiceQL {
* @param comment the comment to add to the top of the kernel
* @param keywords json object containing key/value pairs to write to the text kernel
*/
void writeTextKernel(std::string fileName, std::string type, nlohmann::json &keywords, std::optional<std::string> comment = std::nullopt);
void writeTextKernel(std::string fileName, std::string type, nlohmann::json &keywords, std::string comment = "");
}
......@@ -20,15 +20,15 @@ namespace SpiceQL {
int bodyCode,
int centerOfMotion,
string referenceFrame,
string id, int degree,
optional<vector<vector<double>>> stateVelocities,
optional<string> comment) {
string segmentId, int degree,
vector<vector<double>> stateVelocities,
string comment) {
this->comment = comment;
this->bodyCode = bodyCode;
this->centerOfMotion = centerOfMotion;
this->referenceFrame = referenceFrame;
this->id = id;
this->segmentId = segmentId;
this->polyDegree = degree;
this->statePositions = statePositions;
this->stateVelocities = stateVelocities;
......@@ -61,14 +61,15 @@ namespace SpiceQL {
int bodyCode,
string referenceFrame,
string segmentId,
optional<vector<vector<double>>> anglularVelocities,
optional<string> comment) {
vector<vector<double>> angularVelocities,
string comment) {
this->comment = comment;
this->quats = quats;
this->times = times;
this->bodyCode = bodyCode;
this->referenceFrame = referenceFrame;
this->id = segmentId;
this->angularVelocities = anglularVelocities;
this->segmentId = segmentId;
this->angularVelocities = angularVelocities;
this->comment = comment;
}
......@@ -81,8 +82,8 @@ namespace SpiceQL {
string segmentId,
string sclk,
string lsk,
optional<vector<vector<double>>> angularVelocities,
optional<string> comment) {
vector<vector<double>> angularVelocities,
string comment) {
SpiceInt handle;
......@@ -98,24 +99,32 @@ namespace SpiceQL {
et = sclkdp;
}
checkNaifErrors();
ckopn_c(path.c_str(), "CK", comment.value_or("CK Kernel").size(), &handle);
if(comment.empty()) {
comment = "CK Kernel";
}
ckopn_c(path.c_str(), "CK", comment.size(), &handle);
checkNaifErrors();
ckw03_c (handle,
times.at(0),
times.at(times.size()-1),
bodyCode,
referenceFrame.c_str(),
(bool)angularVelocities,
!angularVelocities.empty(),
segmentId.c_str(),
times.size(),
times.data(),
quats.data(),
(angularVelocities) ? angularVelocities->data() : nullptr,
(!angularVelocities.empty()) ? angularVelocities.data() : nullptr,
times.size(),
times.data());
checkNaifErrors();
ckcls_c(handle);
checkNaifErrors();
writeComment(path, comment);
}
......@@ -127,12 +136,12 @@ namespace SpiceQL {
string referenceFrame,
string segmentId,
int polyDegree,
optional<vector<vector<double>>> stateVelocities,
optional<string> segmentComment) {
vector<vector<double>> stateVelocities,
string segmentComment) {
vector<vector<double>> states;
if (!stateVelocities) {
if (stateVelocities.empty()) {
// init a 0 velocity array
vector<vector<double>> velocities;
for (int i = 0; i < statePositions.size(); i++) {
......@@ -141,7 +150,7 @@ namespace SpiceQL {
stateVelocities = velocities;
}
states = concatStates(statePositions, *stateVelocities);
states = concatStates(statePositions, stateVelocities);
SpiceInt handle;
checkNaifErrors();
......@@ -163,6 +172,9 @@ namespace SpiceQL {
spkcls_c(handle);
checkNaifErrors();
// Write comment to header
writeComment(fileName, segmentComment);
return;
}
......@@ -183,7 +195,7 @@ namespace SpiceQL {
segments[0].bodyCode,
segments[0].centerOfMotion,
segments[0].referenceFrame,
segments[0].id,
segments[0].segmentId,
segments[0].polyDegree,
segments[0].stateVelocities,
segments[0].comment);
......@@ -206,7 +218,7 @@ namespace SpiceQL {
segments[0].times,
segments[0].bodyCode,
segments[0].referenceFrame,
segments[0].id,
segments[0].segmentId,
sclk,
lsk,
segments[0].angularVelocities,
......@@ -214,8 +226,40 @@ namespace SpiceQL {
}
void writeComment(string fileName, string comment) {
SpiceInt handle;
dafopw_c(fileName.c_str(), &handle);
checkNaifErrors();
// Trap errors so they are not fatal if the comment section fills up.
// Calling environments can decide how to handle it.
string commOut;
checkNaifErrors();
for ( int i = 0 ; i < comment.size() ; i++ ) {
if ( comment[i] == '\n' ) {
while ( commOut.size() < 2 ) { commOut.append(" "); }
dafac_c(handle, 1, commOut.size(), commOut.data());
checkNaifErrors();
commOut.clear();
}
else {
commOut.push_back(comment[i]);
}
}
// See if there is residual to write
if ( commOut.size() > 0 ) {
while ( commOut.size() < 2 ) { commOut.append(" "); }
dafac_c(handle, 1, commOut.size(), commOut.data());
checkNaifErrors();
}
// Close file handle
dafcls_c(handle);
}
void writeTextKernel(string fileName, string type, json &keywords, optional<string> comment) {
void writeTextKernel(string fileName, string type, json &keywords, string comment) {
/**
* @brief Return an adjusted string such that it multi-lined if longer than some max length.
......@@ -286,7 +330,7 @@ namespace SpiceQL {
textKernel << "KPL/" + toUpper(type) << endl << endl;
textKernel << "\\begintext" << endl << endl;
textKernel << comment.value_or("") << endl << endl;
textKernel << comment << endl << endl;
textKernel << "\\begindata" << endl << endl;
for(auto it = keywords.begin(); it != keywords.end(); it++) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment