Skip to content

Commit

Permalink
More Cs
Browse files Browse the repository at this point in the history
  • Loading branch information
helgee committed May 17, 2018
1 parent a7478de commit cc91d89
Show file tree
Hide file tree
Showing 3 changed files with 217 additions and 21 deletions.
151 changes: 138 additions & 13 deletions src/c.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export
ckobj!,
ckgp,
ckgpav,
cklpf,
ckopn,
ckupf,
ckw01,
clight

Expand Down Expand Up @@ -134,6 +136,103 @@ function ckcov!(ck, idcode, needav, level, tol, timsys, cover)
cover
end

"""
ckgp(inst, sclkdp, tol, ref)
Get pointing (attitude) for a specified spacecraft clock time.
### Arguments ###
- `inst`: NAIF ID of instrument, spacecraft, or structure
- `sclkdp`: Encoded spacecraft clock time
- `tol`: Time tolerance
- `ref`: Reference frame
### Outputs ###
- `cmat`: C-matrix pointing data
- `clkout`: Output encoded spacecraft clock time
- `found`: `true` when requested pointing is available
### References ###
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/ckgp_c.html)
"""
function ckgp(inst, sclkdp, tol, ref)
cmat = Matrix{SpiceDouble}(3, 3)
clkout = Ref{SpiceDouble}(0.0)
found = Ref{SpiceBoolean}(0)
ccall((:ckgp_c, libcspice), Void,
(SpiceInt, SpiceDouble, SpiceDouble, Cstring,
Ptr{SpiceDouble}, Ref{SpiceDouble}, Ref{SpiceBoolean}),
inst, sclkdp, tol, ref, cmat, clkout, found)
handleerror()
# TODO: Revisit this API in Julia 1.0 and use `nothing`
cmat', clkout[], found[] == 1
end

"""
ckgpav(inst, sclkdp, tol, ref)
Get pointing (attitude) and angular velocity for a specified spacecraft clock time.
### Arguments ###
- `inst`: NAIF ID of instrument, spacecraft, or structure
- `sclkdp`: Encoded spacecraft clock time
- `tol`: Time tolerance
- `ref`: Reference frame
### Outputs ###
- `cmat`: C-matrix pointing data
- `av`: Angular velocity vector
- `clkout`: Output encoded spacecraft clock time
- `found`: `true` when requested pointing is available
### References ###
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/ckgpav_c.html)
"""
function ckgpav(inst, sclkdp, tol, ref)
cmat = Matrix{SpiceDouble}(3, 3)
av = Vector{SpiceDouble}(3)
clkout = Ref{SpiceDouble}(0.0)
found = Ref{SpiceBoolean}(0)
ccall((:ckgpav_c, libcspice), Void,
(SpiceInt, SpiceDouble, SpiceDouble, Cstring,
Ptr{SpiceDouble}, Ptr{SpiceDouble}, Ref{SpiceDouble}, Ref{SpiceBoolean}),
inst, sclkdp, tol, ref, cmat, av, clkout, found)
handleerror()
# TODO: Revisit this API in Julia 1.0 and use `nothing`
cmat', av, clkout[], found[] == 1
end

"""
cklpf(filename)
Load a CK pointing file for use by the CK readers. Return that file's handle, to be used by other CK
routines to refer to the file.
### Arguments ###
- `filename`: Name of the CK file to be loaded
### Output ###
Loaded file's handle
### References ###
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/cklpf_c.html)
"""
function cklpf(filename)
handle = Ref{SpiceInt}()
ccall((:cklpf_c, libcspice), Void, (Cstring, Ref{SpiceInt}), filename, handle)
handleerror()
handle[]
end

"""
ckobj(ck)
Expand Down Expand Up @@ -255,8 +354,46 @@ function ckcls(handle)
end

"""
ckupf(handle)
Unload a CK pointing file so that it will no longer be searched by the readers.
### Arguments ###
- `handle`: Handle of CK file to be unloaded
### References ###
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/ckupf_c.html)
"""
function ckupf(handle)
ccall((:ckupf_c, libcspice), Void, (SpiceInt,), handle)
end

"""
ckw01(handle, inst, ref, segid, sclkdp, quats, avvs=Matrix{SpiceDouble}(0,0);
begtim=sclkdp[1], endtim=sclkdp[end])
Add a type 1 segment to a C-kernel.
### Arguments ###
- `handle`: Handle of an open CK file
- `inst`: The NAIF instrument ID code
- `ref`: The reference frame of the segment
- `avflag`: True if the segment will contain angular velocity
- `segid`: Segment identifier
- `nrec`: Number of pointing records
- `sclkdp`: Encoded SCLK times
- `quats`: Quaternions representing instrument pointing
- `avvs`: Angular velocity vectors (optional)
- `begtim`: The beginning encoded SCLK of the segment (optional)
- `endtim`: The ending encoded SCLK of the segment (optional)
### References ###
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/ckw01_c.html)
"""
function ckw01(handle, inst, ref, segid, sclkdp, quats, avvs=Matrix(0,0);
function ckw01(handle, inst, ref, segid, sclkdp, quats, avvs=Matrix{SpiceDouble}(0,0);
begtim=sclkdp[1], endtim=sclkdp[end])
nrec = length(sclkdp)
avflag = length(avvs) > 0 ? 1 : 0
Expand All @@ -267,21 +404,9 @@ function ckw01(handle, inst, ref, segid, sclkdp, quats, avvs=Matrix(0,0);
handleerror()
end

"""
"""
function ckgp()
end

"""
"""
function ckgpav()
end

"""
clight()
### Output ###
Returns the speed of light in vacuo (km/sec).
"""
function clight()
Expand Down
73 changes: 71 additions & 2 deletions test/c.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
end

try
sclk = path(CASSINI, :cass_sclk)
ck = path(CASSINI, :cass_ck)
sclk = path(CASSINI, :sclk)
ck = path(CASSINI, :ck)
furnsh(sclk)
ckid = ckobj(ck)[1]
@test length(ckid) == 1
Expand All @@ -30,6 +30,75 @@
kclear()
end

try
ck = path(CASSINI, :ck)
furnsh(
ck,
path(CASSINI, :sclk),
path(CASSINI, :ik),
path(CASSINI, :fk),
path(CASSINI, :pck),
)
ckid = ckobj(ck)[1]
cover = ckcov(ck, ckid, false, "INTERVAL", 0.0, "SCLK")
cmat, clkout, found = ckgp(ckid, cover[1], 256, "J2000")
expected_cmat = [
0.5064665782997639365 -0.75794210739897316387 0.41111478554891744963
-0.42372128242505308071 0.19647683351734512858 0.88422685364733510927
-0.7509672961490383436 -0.6220294331642198804 -0.22164725216433822652
]
@test cmat expected_cmat
@test clkout == 267832537952.0
@test found
finally
kclear()
end

try
ck = path(CASSINI, :ck)
furnsh(
ck,
path(CASSINI, :sclk),
path(CASSINI, :ik),
path(CASSINI, :fk),
path(CASSINI, :pck),
)
ckid = ckobj(ck)[1]
cover = ckcov(ck, ckid, false, "INTERVAL", 0.0, "SCLK")
cmat, av, clkout, found = ckgpav(ckid, cover[1], 256, "J2000")
expected_cmat = [
0.5064665782997639365 -0.75794210739897316387 0.41111478554891744963
-0.42372128242505308071 0.19647683351734512858 0.88422685364733510927
-0.7509672961490383436 -0.6220294331642198804 -0.22164725216433822652
]
expected_av = [-0.00231258422150853885, -0.00190333614370416515, -0.00069657429072504716]
@test cmat expected_cmat
@test av expected_av
@test clkout == 267832537952.0
@test found
finally
kclear()
end

let CKLPF = tempfile()
try
ifname = "Test CK type 1 segment created by cklpf"
handle = ckopn(CKLPF, ifname, 10)
ckw01(handle, -77701, "J2000", "Test type 1 CK segment",
[1.1, 4.1], [1.0 1.0 1.0 1.0; 2.0 2.0 2.0 2.0],
[0.0 0.0 1.0; 0.0 0.0 2.0])
ckcls(handle)
kclear()
handle = cklpf(CKLPF)
ckupf(handle)
ckcls(handle)
@test isfile(CKLPF)
finally
kclear()
rm(CKLPF, force=true)
end
end

file = "test.ck"
try
handle = ckopn(file)
Expand Down
14 changes: 8 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ using SPICE
using RemoteFiles
using Base.Test

tempfile() = joinpath(tempdir(), randstring(6))

const BASE_URL = "https://raw.githubusercontent.com/AndrewAnnex/SpiceyPyTestKernels/master/"
const KERNEL_DIR = joinpath(@__DIR__, "kernels")

@RemoteFileSet CASSINI "Cassini Kernels" begin
cass_pck = @RemoteFile BASE_URL * "cpck05Mar2004.tpc" dir=KERNEL_DIR
pck = @RemoteFile BASE_URL * "cpck05Mar2004.tpc" dir=KERNEL_DIR
sat_spk = @RemoteFile BASE_URL * "130220AP_SE_13043_13073.bsp" dir=KERNEL_DIR
cass_tour_spk = @RemoteFile BASE_URL * "130212AP_SK_13043_13058.bsp" dir=KERNEL_DIR
cass_fk = @RemoteFile BASE_URL * "cas_v40.tf" dir=KERNEL_DIR
cass_ck = @RemoteFile BASE_URL * "13056_13057ra.bc" dir=KERNEL_DIR
cass_sclk = @RemoteFile BASE_URL * "cas00167.tsc" dir=KERNEL_DIR
cass_ik = @RemoteFile BASE_URL * "cas_iss_v10.ti" dir=KERNEL_DIR
tour_spk = @RemoteFile BASE_URL * "130212AP_SK_13043_13058.bsp" dir=KERNEL_DIR
fk = @RemoteFile BASE_URL * "cas_v40.tf" dir=KERNEL_DIR
ck = @RemoteFile BASE_URL * "13056_13057ra.bc" dir=KERNEL_DIR
sclk = @RemoteFile BASE_URL * "cas00167.tsc" dir=KERNEL_DIR
ik = @RemoteFile BASE_URL * "cas_iss_v10.ti" dir=KERNEL_DIR
end

@RemoteFileSet EXTRA "Extra Kernels" begin
Expand Down

0 comments on commit cc91d89

Please sign in to comment.