Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SpiceQL
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
aflab
astrogeology
SpiceQL
Commits
9b0e649f
Unverified
Commit
9b0e649f
authored
1 year ago
by
Christine Kim
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Write comment & replaced std::optional (#33)
parent
b9c95a9e
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
SpiceQL/include/io.h
+22
-20
22 additions, 20 deletions
SpiceQL/include/io.h
SpiceQL/src/io.cpp
+66
-22
66 additions, 22 deletions
SpiceQL/src/io.cpp
with
88 additions
and
42 deletions
SpiceQL/include/io.h
+
22
−
20
View file @
9b0e649f
...
@@ -35,7 +35,7 @@ namespace SpiceQL {
...
@@ -35,7 +35,7 @@ namespace SpiceQL {
* @param centerOfMotion Naif body code of an object which is the center of motion for
* @param centerOfMotion Naif body code of an object which is the center of motion for
* bodyCode
* bodyCode
* @param referenceFrame Naif name of the reference system relative to which the state is
* @param referenceFrame Naif name of the reference system relative to which the state is
* @param
i
d SPK segment identifier (max size 40)
* @param
segmentI
d SPK segment identifier (max size 40)
* @param degree Degree of the Hermite polynomials used to interpolate the states
* @param degree Degree of the Hermite polynomials used to interpolate the states
* @param stateVelocities Time ordered vector of state velocities dX, dY, dZ
* @param stateVelocities Time ordered vector of state velocities dX, dY, dZ
* @param segmentComment The comment string for the new segment
* @param segmentComment The comment string for the new segment
...
@@ -45,20 +45,20 @@ namespace SpiceQL {
...
@@ -45,20 +45,20 @@ namespace SpiceQL {
int
bodyCode
,
int
bodyCode
,
int
centerOfMotion
,
int
centerOfMotion
,
std
::
string
referenceFrame
,
std
::
string
referenceFrame
,
std
::
string
i
d
,
int
degree
,
std
::
string
segmentI
d
,
int
degree
,
std
::
optional
<
std
::
vector
<
std
::
vector
<
double
>>
>
stateVelocities
,
std
::
vector
<
std
::
vector
<
double
>>
stateVelocities
=
{}
,
std
::
optional
<
std
::
string
>
segmentComment
);
std
::
string
segmentComment
=
""
);
//! @cond Doxygen_Suppress
//! @cond Doxygen_Suppress
std
::
vector
<
double
>
stateTimes
;
std
::
vector
<
double
>
stateTimes
;
int
bodyCode
;
int
bodyCode
;
int
centerOfMotion
;
int
centerOfMotion
;
std
::
string
referenceFrame
;
std
::
string
referenceFrame
;
std
::
string
i
d
;
std
::
string
segmentI
d
;
int
polyDegree
;
int
polyDegree
;
std
::
vector
<
std
::
vector
<
double
>>
statePositions
;
std
::
vector
<
std
::
vector
<
double
>>
statePositions
;
std
::
optional
<
std
::
vector
<
std
::
vector
<
double
>>
>
stateVelocities
;
std
::
vector
<
std
::
vector
<
double
>>
stateVelocities
;
std
::
optional
<
std
::
string
>
comment
;
std
::
string
comment
;
//! @endcond
//! @endcond
};
};
...
@@ -82,23 +82,23 @@ namespace SpiceQL {
...
@@ -82,23 +82,23 @@ namespace SpiceQL {
* @param times times for the CK segment in ascending order
* @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 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 referenceFrame Naif name of the reference system relative to which the state is
* @param
i
d SPK segment identifier (max size 40)
* @param
segmentI
d SPK segment identifier (max size 40)
* @param ang
l
ularVelocities Time ordered vector of state velocities dX, dY, dZ
* @param angularVelocities Time ordered vector of state velocities dX, dY, dZ
* @param comment The comment string for the new segment
* @param comment The comment string for the new segment
*/
*/
CkSegment
(
std
::
vector
<
std
::
vector
<
double
>>
quats
,
std
::
vector
<
double
>
times
,
int
bodyCode
,
CkSegment
(
std
::
vector
<
std
::
vector
<
double
>>
quats
,
std
::
vector
<
double
>
times
,
int
bodyCode
,
std
::
string
referenceFrame
,
std
::
string
i
d
,
std
::
string
referenceFrame
,
std
::
string
segmentI
d
,
std
::
optional
<
std
::
vector
<
std
::
vector
<
double
>>
>
ang
l
ularVelocities
=
std
::
nullopt
,
std
::
vector
<
std
::
vector
<
double
>>
angularVelocities
=
{}
,
std
::
optional
<
std
::
string
>
comment
=
std
::
nullopt
);
std
::
string
comment
=
""
);
//! @cond Doxygen_Suppress
//! @cond Doxygen_Suppress
std
::
vector
<
double
>
times
;
std
::
vector
<
double
>
times
;
std
::
vector
<
std
::
vector
<
double
>>
quats
;
std
::
vector
<
std
::
vector
<
double
>>
quats
;
int
bodyCode
;
int
bodyCode
;
std
::
string
referenceFrame
;
std
::
string
referenceFrame
;
std
::
string
i
d
;
std
::
string
segmentI
d
;
std
::
optional
<
std
::
vector
<
std
::
vector
<
double
>>
>
angularVelocities
=
std
::
nullopt
;
std
::
vector
<
std
::
vector
<
double
>>
angularVelocities
;
std
::
optional
<
std
::
string
>
comment
=
std
::
nullopt
;
std
::
string
comment
;
//! @endcond
//! @endcond
};
};
...
@@ -146,8 +146,8 @@ namespace SpiceQL {
...
@@ -146,8 +146,8 @@ namespace SpiceQL {
std
::
string
referenceFrame
,
std
::
string
referenceFrame
,
std
::
string
segmentId
,
std
::
string
segmentId
,
int
polyDegree
,
int
polyDegree
,
std
::
optional
<
std
::
vector
<
std
::
vector
<
double
>>
>
stateVelocities
=
std
::
nullopt
,
std
::
vector
<
std
::
vector
<
double
>>
stateVelocities
=
{}
,
std
::
optional
<
std
::
string
>
segmentComment
=
std
::
nullopt
);
std
::
string
segmentComment
=
""
);
/**
/**
...
@@ -174,8 +174,8 @@ namespace SpiceQL {
...
@@ -174,8 +174,8 @@ namespace SpiceQL {
std
::
string
segmentId
,
std
::
string
segmentId
,
std
::
string
sclk
,
std
::
string
sclk
,
std
::
string
lsk
,
std
::
string
lsk
,
std
::
optional
<
std
::
vector
<
std
::
vector
<
double
>>
>
angularVelocity
=
std
::
nullopt
,
std
::
vector
<
std
::
vector
<
double
>>
angularVelocity
=
{}
,
std
::
optional
<
std
::
string
>
comment
=
std
::
nullopt
);
std
::
string
comment
=
""
);
/**
/**
...
@@ -193,6 +193,8 @@ namespace SpiceQL {
...
@@ -193,6 +193,8 @@ namespace SpiceQL {
std
::
string
lsk
,
std
::
string
lsk
,
std
::
vector
<
CkSegment
>
segments
);
std
::
vector
<
CkSegment
>
segments
);
void
writeComment
(
std
::
string
fileName
,
std
::
string
comment
);
/**
/**
* @brief Write json key value pairs into a NAIF text kernel
* @brief Write json key value pairs into a NAIF text kernel
...
@@ -202,6 +204,6 @@ namespace SpiceQL {
...
@@ -202,6 +204,6 @@ namespace SpiceQL {
* @param comment the comment to add to the top of the kernel
* @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
* @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
=
""
);
}
}
This diff is collapsed.
Click to expand it.
SpiceQL/src/io.cpp
+
66
−
22
View file @
9b0e649f
...
@@ -20,15 +20,15 @@ namespace SpiceQL {
...
@@ -20,15 +20,15 @@ namespace SpiceQL {
int
bodyCode
,
int
bodyCode
,
int
centerOfMotion
,
int
centerOfMotion
,
string
referenceFrame
,
string
referenceFrame
,
string
i
d
,
int
degree
,
string
segmentI
d
,
int
degree
,
optional
<
vector
<
vector
<
double
>>
>
stateVelocities
,
vector
<
vector
<
double
>>
stateVelocities
,
optional
<
string
>
comment
)
{
string
comment
)
{
this
->
comment
=
comment
;
this
->
comment
=
comment
;
this
->
bodyCode
=
bodyCode
;
this
->
bodyCode
=
bodyCode
;
this
->
centerOfMotion
=
centerOfMotion
;
this
->
centerOfMotion
=
centerOfMotion
;
this
->
referenceFrame
=
referenceFrame
;
this
->
referenceFrame
=
referenceFrame
;
this
->
id
=
i
d
;
this
->
segmentId
=
segmentI
d
;
this
->
polyDegree
=
degree
;
this
->
polyDegree
=
degree
;
this
->
statePositions
=
statePositions
;
this
->
statePositions
=
statePositions
;
this
->
stateVelocities
=
stateVelocities
;
this
->
stateVelocities
=
stateVelocities
;
...
@@ -61,14 +61,15 @@ namespace SpiceQL {
...
@@ -61,14 +61,15 @@ namespace SpiceQL {
int
bodyCode
,
int
bodyCode
,
string
referenceFrame
,
string
referenceFrame
,
string
segmentId
,
string
segmentId
,
optional
<
vector
<
vector
<
double
>>
>
ang
l
ularVelocities
,
vector
<
vector
<
double
>>
angularVelocities
,
optional
<
string
>
comment
)
{
string
comment
)
{
this
->
comment
=
comment
;
this
->
quats
=
quats
;
this
->
times
=
times
;
this
->
bodyCode
=
bodyCode
;
this
->
bodyCode
=
bodyCode
;
this
->
referenceFrame
=
referenceFrame
;
this
->
referenceFrame
=
referenceFrame
;
this
->
i
d
=
segmentId
;
this
->
segmentI
d
=
segmentId
;
this
->
angularVelocities
=
ang
l
ularVelocities
;
this
->
angularVelocities
=
angularVelocities
;
this
->
comment
=
comment
;
this
->
comment
=
comment
;
}
}
...
@@ -81,8 +82,8 @@ namespace SpiceQL {
...
@@ -81,8 +82,8 @@ namespace SpiceQL {
string
segmentId
,
string
segmentId
,
string
sclk
,
string
sclk
,
string
lsk
,
string
lsk
,
optional
<
vector
<
vector
<
double
>>
>
angularVelocities
,
vector
<
vector
<
double
>>
angularVelocities
,
optional
<
string
>
comment
)
{
string
comment
)
{
SpiceInt
handle
;
SpiceInt
handle
;
...
@@ -98,24 +99,32 @@ namespace SpiceQL {
...
@@ -98,24 +99,32 @@ namespace SpiceQL {
et
=
sclkdp
;
et
=
sclkdp
;
}
}
checkNaifErrors
();
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
();
checkNaifErrors
();
ckw03_c
(
handle
,
ckw03_c
(
handle
,
times
.
at
(
0
),
times
.
at
(
0
),
times
.
at
(
times
.
size
()
-
1
),
times
.
at
(
times
.
size
()
-
1
),
bodyCode
,
bodyCode
,
referenceFrame
.
c_str
(),
referenceFrame
.
c_str
(),
(
bool
)
angularVelocities
,
!
angularVelocities
.
empty
()
,
segmentId
.
c_str
(),
segmentId
.
c_str
(),
times
.
size
(),
times
.
size
(),
times
.
data
(),
times
.
data
(),
quats
.
data
(),
quats
.
data
(),
(
angularVelocities
)
?
angularVelocities
->
data
()
:
nullptr
,
(
!
angularVelocities
.
empty
()
)
?
angularVelocities
.
data
()
:
nullptr
,
times
.
size
(),
times
.
size
(),
times
.
data
());
times
.
data
());
checkNaifErrors
();
checkNaifErrors
();
ckcls_c
(
handle
);
ckcls_c
(
handle
);
checkNaifErrors
();
checkNaifErrors
();
writeComment
(
path
,
comment
);
}
}
...
@@ -127,12 +136,12 @@ namespace SpiceQL {
...
@@ -127,12 +136,12 @@ namespace SpiceQL {
string
referenceFrame
,
string
referenceFrame
,
string
segmentId
,
string
segmentId
,
int
polyDegree
,
int
polyDegree
,
optional
<
vector
<
vector
<
double
>>
>
stateVelocities
,
vector
<
vector
<
double
>>
stateVelocities
,
optional
<
string
>
segmentComment
)
{
string
segmentComment
)
{
vector
<
vector
<
double
>>
states
;
vector
<
vector
<
double
>>
states
;
if
(
!
stateVelocities
)
{
if
(
stateVelocities
.
empty
()
)
{
// init a 0 velocity array
// init a 0 velocity array
vector
<
vector
<
double
>>
velocities
;
vector
<
vector
<
double
>>
velocities
;
for
(
int
i
=
0
;
i
<
statePositions
.
size
();
i
++
)
{
for
(
int
i
=
0
;
i
<
statePositions
.
size
();
i
++
)
{
...
@@ -141,7 +150,7 @@ namespace SpiceQL {
...
@@ -141,7 +150,7 @@ namespace SpiceQL {
stateVelocities
=
velocities
;
stateVelocities
=
velocities
;
}
}
states
=
concatStates
(
statePositions
,
*
stateVelocities
);
states
=
concatStates
(
statePositions
,
stateVelocities
);
SpiceInt
handle
;
SpiceInt
handle
;
checkNaifErrors
();
checkNaifErrors
();
...
@@ -163,6 +172,9 @@ namespace SpiceQL {
...
@@ -163,6 +172,9 @@ namespace SpiceQL {
spkcls_c
(
handle
);
spkcls_c
(
handle
);
checkNaifErrors
();
checkNaifErrors
();
// Write comment to header
writeComment
(
fileName
,
segmentComment
);
return
;
return
;
}
}
...
@@ -183,7 +195,7 @@ namespace SpiceQL {
...
@@ -183,7 +195,7 @@ namespace SpiceQL {
segments
[
0
].
bodyCode
,
segments
[
0
].
bodyCode
,
segments
[
0
].
centerOfMotion
,
segments
[
0
].
centerOfMotion
,
segments
[
0
].
referenceFrame
,
segments
[
0
].
referenceFrame
,
segments
[
0
].
i
d
,
segments
[
0
].
segmentI
d
,
segments
[
0
].
polyDegree
,
segments
[
0
].
polyDegree
,
segments
[
0
].
stateVelocities
,
segments
[
0
].
stateVelocities
,
segments
[
0
].
comment
);
segments
[
0
].
comment
);
...
@@ -206,7 +218,7 @@ namespace SpiceQL {
...
@@ -206,7 +218,7 @@ namespace SpiceQL {
segments
[
0
].
times
,
segments
[
0
].
times
,
segments
[
0
].
bodyCode
,
segments
[
0
].
bodyCode
,
segments
[
0
].
referenceFrame
,
segments
[
0
].
referenceFrame
,
segments
[
0
].
i
d
,
segments
[
0
].
segmentI
d
,
sclk
,
sclk
,
lsk
,
lsk
,
segments
[
0
].
angularVelocities
,
segments
[
0
].
angularVelocities
,
...
@@ -214,8 +226,40 @@ namespace SpiceQL {
...
@@ -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.
* @brief Return an adjusted string such that it multi-lined if longer than some max length.
...
@@ -286,7 +330,7 @@ namespace SpiceQL {
...
@@ -286,7 +330,7 @@ namespace SpiceQL {
textKernel
<<
"KPL/"
+
toUpper
(
type
)
<<
endl
<<
endl
;
textKernel
<<
"KPL/"
+
toUpper
(
type
)
<<
endl
<<
endl
;
textKernel
<<
"
\\
begintext"
<<
endl
<<
endl
;
textKernel
<<
"
\\
begintext"
<<
endl
<<
endl
;
textKernel
<<
comment
.
value_or
(
""
)
<<
endl
<<
endl
;
textKernel
<<
comment
<<
endl
<<
endl
;
textKernel
<<
"
\\
begindata"
<<
endl
<<
endl
;
textKernel
<<
"
\\
begindata"
<<
endl
<<
endl
;
for
(
auto
it
=
keywords
.
begin
();
it
!=
keywords
.
end
();
it
++
)
{
for
(
auto
it
=
keywords
.
begin
();
it
!=
keywords
.
end
();
it
++
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment