Skip to content

Commit

Permalink
Add f
Browse files Browse the repository at this point in the history
  • Loading branch information
helgee committed Feb 9, 2019
1 parent d71fb40 commit 2aaca99
Show file tree
Hide file tree
Showing 2 changed files with 255 additions and 7 deletions.
181 changes: 180 additions & 1 deletion src/f.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,184 @@
export furnsh
export
fovray,
fovtrg,
frame,
frinfo,
frmnam,
ftncls,
furnsh

"""
fovray(inst, raydir, rframe, abcorr, observer, et)
Determine if a specified ray is within the field-of-view (FOV) of a specified instrument
at a given time.
### Arguments ###
- `inst`: Name or ID code string of the instrument
- `raydir`: Ray's direction vector
- `rframe`: Body-fixed, body-centered frame for target body
- `abcorr`: Aberration correction flag
- `observer`: Name or ID code string of the observer
- `et`: Time of the observation (seconds past J2000)
### Output ###
Returns `true` if the ray is visible.
### References ###
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/fovray_c.html)
"""
function fovray(inst, raydir, rframe, abcorr, observer, et)
length(raydir) != 3 && throw(ArgumentError("Length of `raydir` must be 3."))
visible = Ref{SpiceBoolean}()
ccall((:fovray_c, libcspice), Cvoid,
(Cstring, Ptr{SpiceDouble}, Cstring, Cstring, Cstring, Ref{SpiceDouble}, Ref{SpiceBoolean}),
inst, raydir, rframe, abcorr, observer, et, visible)
handleerror()
Bool(visible[])
end

"""
fovtrg(inst, target, tshape, tframe, abcorr, obsrvr, et)
Determine if a specified ephemeris object is within the field-of-view (FOV) of a specified
instrument at a given time.
### Arguments ###
- `inst`: Name or ID code string of the instrument.
- `target`: Name or ID code string of the target.
- `tshape`: Type of shape model used for the target.
- `tframe`: Body-fixed, body-centered frame for target body.
- `abcorr`: Aberration correction flag.
- `obsrvr`: Name or ID code string of the observer.
- `et`: Time of the observation (seconds past J2000).
### Output ###
Returns `true` if the object is visible.
### References ###
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/fovtrg_c.html)
"""
function fovtrg(inst, target, tshape, tframe, abcorr, obsrvr, et)
visible = Ref{SpiceBoolean}()
ccall((:fovtrg_c, libcspice), Cvoid,
(Cstring, Cstring, Cstring, Cstring, Cstring, Cstring, Ref{SpiceDouble}, Ref{SpiceBoolean}),
inst, target, tshape, tframe, abcorr, obsrvr, et, visible)
handleerror()
Bool(visible[])
end

"""
frame(x)
Given a vector `x`, this routine builds a right handed orthonormal frame `x`, `y`, `z`
where the output `x` is parallel to the input `x`.
### Arguments ###
- `x`: Input vector
### Output ###
- `x`: Unit vector parallel to `x` on output
- `y`: Unit vector in the plane orthogonal to `x`
- `z`: Unit vector given by `x × y`
### References ###
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/frame_c.html)
"""
function frame(x)
length(x) != 3 && throw(ArgumentError("Length of `x` must be 3."))
x = copy(x)
y = Array{SpiceDouble}(undef, 3)
z = Array{SpiceDouble}(undef, 3)
ccall((:frame_c, libcspice), Cvoid,
(Ptr{SpiceDouble}, Ptr{SpiceDouble}, Ptr{SpiceDouble}),
x, y, z)
x, y, z
end

"""
frinfo(frcode)
Retrieve the minimal attributes associated with a frame needed for converting transformations
to and from it.
### Arguments ###
- `frcode`: The id code for a reference frame
### Output ###
- `cent`: The center of the frame
- `frclss`: The class (type) of the frame
- `clssid`: The idcode for the frame within its class
Returns `nothing` if no frame with id `frcode` could be found.
### References ###
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/frinfo_c.html)
"""
function frinfo(frcode)
cent = Ref{SpiceInt}()
frclss = Ref{SpiceInt}()
clssid = Ref{SpiceInt}()
found = Ref{SpiceBoolean}()
ccall((:frinfo_c, libcspice), Cvoid,
(SpiceInt, Ref{SpiceInt}, Ref{SpiceInt}, Ref{SpiceInt}, Ref{SpiceBoolean}),
frcode, cent, frclss, clssid, found)

!Bool(found[]) && return nothing
cent[], frclss[], clssid[]
end

"""
frmnam(frcode)
Retrieve the name of a reference frame associated with an id code.
### Arguments ###
- `frcode`: The id code for a reference frame
### Output ###
Returns the name associated with the reference frame.
### References ###
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/frmnam_c.html)
"""
function frmnam(frcode)
lenout = 33
frname = Array{UInt8}(undef, lenout)
ccall((:frmnam_c, libcspice), Cvoid, (SpiceInt, SpiceInt, Ptr{UInt8}),
frcode, lenout, frname)
unsafe_string(pointer(frname))
end

@deprecate ftncls close

"""
furnsh(kernels...)
Load one or more SPICE kernels into a program.
### Arguments ###
- `kernels`: Path(s) of SPICE kernels to load
### References ###
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/furnsh_c.html)
"""
function furnsh(kernels...)
for kernel in kernels
ccall((:furnsh_c, libcspice), Cvoid, (Cstring,), kernel)
Expand Down
81 changes: 75 additions & 6 deletions test/f.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,76 @@
@testset "F" begin
# TODO: code doesnt work (problem with kernels), needs to be modified
kclear()
furnsh(path(CORE, :pck),path(CORE, :spk),path(CORE, :gm_pck),path(CORE, :lsk))
@test ktotal("ALL") == 4
kclear()
end
@testset "fovray" begin
try
furnsh(path(CORE, :lsk),
path(CORE, :pck),
path(CORE, :spk),
path(CASSINI, :pck),
path(CASSINI, :sat_spk),
path(CASSINI, :tour_spk),
path(CASSINI, :fk),
path(CASSINI, :ck),
path(CASSINI, :sclk),
path(CASSINI, :ik))
camid = bodn2c("CASSINI_ISS_NAC")
shape, frame, bsight, bounds = getfov(camid, 4)
et = str2et("2013 FEB 25 11:50:00 UTC")
visible = fovray("CASSINI_ISS_NAC", [0.0, 0.0, 1.0], frame, "S", "CASSINI", et)
@test visible
@test_throws ArgumentError fovray("CASSINI_ISS_NAC", [0.0, 0.0], frame, "S", "CASSINI", et)
@test_throws SpiceError fovray("norbert", [0.0, 0.0, 1.0], frame, "S", "CASSINI", et)
@test_throws SpiceError fovray("CASSINI_ISS_NAC", [0.0, 0.0, 1.0], frame, "S", "norbert", et)
@test_throws SpiceError fovray("CASSINI_ISS_NAC", [0.0, 0.0, 1.0], "norbert", "S", "CASSINI", et)
finally
kclear()
end
end
@testset "fovtrg" begin
try
furnsh(path(CORE, :lsk),
path(CORE, :pck),
path(CORE, :spk),
path(CASSINI, :pck),
path(CASSINI, :sat_spk),
path(CASSINI, :tour_spk),
path(CASSINI, :fk),
path(CASSINI, :ck),
path(CASSINI, :sclk),
path(CASSINI, :ik))
et = str2et("2013 FEB 25 11:50:00 UTC")
visible = fovtrg("CASSINI_ISS_NAC", "Enceladus", "Ellipsoid",
"IAU_ENCELADUS", "LT+S", "CASSINI", et)
@test visible
@test_throws SpiceError fovtrg("norbert", "Enceladus", "Ellipsoid",
"IAU_ENCELADUS", "LT+S", "CASSINI", et)
finally
kclear()
end
end
@testset "frame" begin
vec = [23.0, -3.0, 18.0]
x, y, z = frame(vec)
expected_x = [0.78338311, -0.10218041, 0.61308243]
expected_y = [0.61630826, 0.0000000, -0.78750500]
expected_z = [0.080467580, 0.99476588, 0.062974628]
@test expected_x x
@test expected_y y
@test expected_z z
end
@testset "frinfo" begin
@test frinfo(13000) == (399, 2, 3000)
@test frinfo(42) === nothing
end
@testset "frmnam" begin
@test frmnam(13000) == "ITRF93"
@test frmnam(13000) == "ITRF93"
@test isempty(frmnam(42))
end
@testset "furnsh" begin
try
furnsh(path(CORE, :pck),path(CORE, :spk),path(CORE, :gm_pck),path(CORE, :lsk))
@test ktotal("ALL") == 4
finally
kclear()
end
end
end

0 comments on commit 2aaca99

Please sign in to comment.