Skip to content

Commit

Permalink
Cleanup a and b
Browse files Browse the repository at this point in the history
  • Loading branch information
helgee committed Mar 3, 2019
1 parent 8cb4438 commit 2149d04
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 82 deletions.
1 change: 1 addition & 0 deletions src/a.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Rotation matrix corresponding to `axis` and `angle`
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/axisar_c.html)
"""
function axisar(axis, angle)
length(axis) != 3 && throw(ArgumentError("`axis` must have three elements."))
r = Matrix{Float64}(undef, 3,3)
ccall((:axisar_c, libcspice), Cvoid, (Ref{SpiceDouble}, SpiceDouble, Ref{SpiceDouble}), axis, angle, r)
permutedims(r)
Expand Down
41 changes: 21 additions & 20 deletions src/b.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function badkpv(caller, name, comp, size, divby, typ)
(Cstring, Cstring, Cstring, SpiceInt, SpiceInt, SpiceChar),
caller, name, comp, size, divby, first(typ))
handleerror()
res == 1
Bool(res)
end

"""
Expand All @@ -94,7 +94,8 @@ Return a SPICE set containing the frame IDs of all built-in frames of a specifie
"""
function bltfrm(frmcls)
idset = SpiceIntCell(256)
ccall((:bltfrm_c, libcspice), Cvoid, (SpiceInt, Ref{Cell{SpiceInt}}), frmcls, Ref(idset.cell))
ccall((:bltfrm_c, libcspice), Cvoid, (SpiceInt, Ref{Cell{SpiceInt}}), frmcls, idset.cell)
handleerror()
idset
end

Expand All @@ -109,7 +110,7 @@ Translate the SPICE integer code of a body into a common name for that body.
### Output ###
- `name`: A common name for the body identified by code
A common name for the body identified by code or `nothing` if none was found.
### References ###
Expand All @@ -119,9 +120,9 @@ function bodc2n(code)
len = 36
name = Array{UInt8}(undef, len)
found = Ref{SpiceBoolean}()
ccall((:bodc2n_c, libcspice), Cvoid, (SpiceInt, SpiceInt, Ref{UInt8}, Ref{SpiceBoolean}),
code, 36, name, found)
found[] == 0 && throw(SpiceError("No body with code $code found."))
ccall((:bodc2n_c, libcspice), Cvoid, (SpiceInt, SpiceInt, Ref{SpiceChar}, Ref{SpiceBoolean}),
code, len, name, found)
Bool(found[]) || return nothing
chararray_to_string(name)
end

Expand All @@ -137,7 +138,7 @@ the string representation of the body ID value.
### Output ###
- `name`: String corresponding to `code`
Returns a string corresponding to `code`
### References ###
Expand All @@ -146,8 +147,8 @@ the string representation of the body ID value.
function bodc2s(code)
len = 36
name = Array{UInt8}(undef, len)
ccall((:bodc2s_c, libcspice), Cvoid, (SpiceInt, SpiceInt, Ref{UInt8}),
code, 36, name)
ccall((:bodc2s_c, libcspice), Cvoid, (SpiceInt, SpiceInt, Ref{SpiceChar}),
code, len, name)
chararray_to_string(name)
end

Expand All @@ -168,6 +169,7 @@ Define a body name/ID code pair for later translation via [`bodn2c`](@ref) or [`
function boddef(name, code)
length(name) > 35 && throw(SpiceError("The maximum allowed length for a name is 35 characters."))
ccall((:boddef_c, libcspice), Cvoid, (Cstring, SpiceInt), name, code)
handleerror()
end

"""
Expand All @@ -182,15 +184,14 @@ Determine whether values exist for some item for any body in the kernel pool.
### Output ###
- `found`: `true` if the item is in the kernel pool and `false` if it is not.
Returns `true` if the item is in the kernel pool and `false` if it is not.
### References ###
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/bodfnd_c.html)
"""
function bodfnd(body, item)
res = ccall((:bodfnd_c, libcspice), SpiceBoolean, (SpiceInt, Cstring), body, item)
res == 1
Bool(ccall((:bodfnd_c, libcspice), SpiceBoolean, (SpiceInt, Cstring), body, item))
end

"""
Expand All @@ -204,7 +205,7 @@ Translate the name of a body or object to the corresponding SPICE integer ID cod
### Output ###
- `code`: SPICE integer ID code for the named body
Return the SPICE integer ID code for the named body or `nothing` if none was found.
### References ###
Expand All @@ -215,7 +216,7 @@ function bodn2c(name)
found = Ref{SpiceBoolean}()
ccall((:bodn2c_c, libcspice), Cvoid, (Cstring, Ref{SpiceInt}, Ref{SpiceBoolean}),
name, code, found)
found[] == 0 && throw(SpiceError("No body with name '$name' found."))
Bool(found[]) || return nothing
Int(code[])
end

Expand All @@ -230,7 +231,7 @@ Translate a string containing a body name or ID code to an integer code.
### Output ###
- `code`: Integer ID code corresponding to `name`
Retunrs the integer ID code corresponding to `name` or `nothing` if none as found.
### References ###
Expand All @@ -241,7 +242,7 @@ function bods2c(name)
found = Ref{SpiceBoolean}()
ccall((:bods2c_c, libcspice), Cvoid, (Cstring, Ref{SpiceInt}, Ref{SpiceBoolean}),
name, code, found)
found[] == 0 && throw(SpiceError("Neither a body with name '$name' found nor is it an integer."))
Bool(found[]) || return nothing
Int(code[])
end

Expand All @@ -255,17 +256,17 @@ is specified by an integer ID code.
- `bodyid`: Body ID code
- `item`: Item for which values are desired. ("RADII", "NUT_PREC_ANGLES", etc.)
- `maxn`: Maximum number of values that may be returned (default: 100)
### Output ###
- `values`: Values
Returns the requested values.
### References ###
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/bodvcd_c.html)
"""
function bodvcd(bodyid, item)
maxn = 100
function bodvcd(bodyid, item, maxn=100)
values = Array{SpiceDouble}(undef, maxn)
dim = Ref{SpiceInt}()
ccall((:bodvcd_c, libcspice), Cvoid, (SpiceInt, Cstring, SpiceInt, Ref{SpiceInt}, Ref{SpiceDouble}),
Expand All @@ -283,7 +284,7 @@ Fetch from the kernel pool the double precision values of an item associated wit
- `bodynm`: Body name
- `item`: Item for which values are desired. ("RADII", "NUT_PREC_ANGLES", etc.)
- `maxn`: Maximum number of values that may be returned.
- `maxn`: Maximum number of values that may be returned (default: 100)
### Output ###
Expand Down
2 changes: 1 addition & 1 deletion src/d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1843,7 +1843,7 @@ surface defined by a type 2 DSK plate model.
- `handle`: Handle of DSK kernel containing plate model
- `dladsc`: DLA descriptor of plate model segment
- `vertex`: Ray's vertex in the body fixed frame
- `vertex`: Ray vertex in the body fixed frame
- `raydir`: Ray direction in the body fixed frame
### Output ###
Expand Down
5 changes: 3 additions & 2 deletions test/a.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@testset "A" begin
axis = [0.0, 0.0, 1.0]
output = axisar(axis, pi/2)
output = axisar(axis, π/2)
expected = [0.0 -1.0 0.0; 1.0 0.0 0.0; 0.0 0.0 1.0]
@test output expected
end
@test_throws ArgumentError axisar(axis[1:2], π/2)
end
141 changes: 83 additions & 58 deletions test/b.jl
Original file line number Diff line number Diff line change
@@ -1,63 +1,88 @@
@testset "B" begin
@test b1900() == 2415020.31352
@test b1950() == 2433282.42345905

furnsh(path(CORE, :pck))
@test badkpv("SPICE.jl", "BODY399_RADII", "=", 3, 1, "N") == false
@test_throws SpiceError badkpv("SPICE.jl", "BODY399_RADII", "=", 3, 1, "C")
unload(path(CORE, :pck))

idset = bltfrm(-1)
@test length(idset) >= 126

@test bodc2n(399) == "EARTH"
@test_throws SpiceError bodc2n(typemax(Cint))

@test bodc2s(399) == "EARTH"
@test bodc2s(typemax(Cint)) == string(typemax(Cint))

boddef("Spaceball One", 999999)
@test bodc2n(999999) == "Spaceball One"

furnsh(path(CORE, :pck))
@test bodfnd(399, "RADII") == true
@test bodfnd(999999, "RADII") == false
unload(path(CORE, :pck))

@test bodn2c("EARTH") == 399
@test_throws SpiceError bodn2c("Norbert")

@test bods2c("EARTH") == 399
@test bods2c("888888") == 888888
@test_throws SpiceError bodn2c("Norbert")

furnsh(path(CORE, :pck))
@test bodvcd(399, "RADII") == [6378.1366, 6378.1366, 6356.7519]
@test bodvcd(399, "RADII") == [6378.1366, 6378.1366, 6356.7519]
@test_throws SpiceError bodvcd(399, "Norbert")
@test_throws SpiceError bodvcd(999999, "RADII")
unload(path(CORE, :pck))

furnsh(path(CORE, :pck))
@test bodvrd("EARTH", "RADII") == [6378.1366, 6378.1366, 6356.7519]
@test bodvrd("EARTH", "RADII") == [6378.1366, 6378.1366, 6356.7519]
@test_throws SpiceError bodvrd("EARTH", "Norbert")
@test_throws SpiceError bodvrd("Norbert", "RADII")
unload(path(CORE, :pck))

@test SPICE._brcktd(4.0, 1.0, 3.0) == clamp(4.0, 1.0, 3.0)
@test SPICE._brckti(4, 1, 3) == clamp(4, 1, 3)
let arr = ["FEYNMAN", "BOHR", "EINSTEIN", "NEWTON", "GALILEO"],
ord=sortperm(arr)
@testset "b1900" begin
@test b1900() == 2415020.31352
end
@testset "b1900" begin
@test b1950() == 2433282.42345905
end
@testset "badkpv" begin
try
furnsh(path(CORE, :pck))
@test !badkpv("SPICE.jl", "BODY399_RADII", "=", 3, 1, "N")
@test_throws SpiceError badkpv("SPICE.jl", "BODY399_RADII", "=", 3, 1, "C")
finally
kclear()
end
end
@testset "bltfrm" begin
idset = bltfrm(-1)
@test length(idset) >= 126
end
@testset "bodc2n" begin
@test bodc2n(399) == "EARTH"
@test bodc2n(typemax(Cint)) === nothing
end
@testset "bodc2s" begin
@test bodc2s(399) == "EARTH"
@test bodc2s(typemax(Cint)) == string(typemax(Cint))
end
@testset "boddef" begin
boddef("Spaceball One", 999999)
@test bodc2n(999999) == "Spaceball One"
end
@testset "bodfnd" begin
try
furnsh(path(CORE, :pck))
@test bodfnd(399, "RADII") == true
@test bodfnd(999999, "RADII") == false
finally
kclear()
end
end
@testset "bodn2c" begin
@test bodn2c("EARTH") == 399
@test bodn2c("Norbert") === nothing
end
@testset "bods2c" begin
@test bods2c("EARTH") == 399
@test bods2c("888888") == 888888
@test bodn2c("Norbert") === nothing
end
@testset "bodvcd" begin
try
furnsh(path(CORE, :pck))
@test bodvcd(399, "RADII") == [6378.1366, 6378.1366, 6356.7519]
@test bodvcd(399, "RADII") == [6378.1366, 6378.1366, 6356.7519]
@test_throws SpiceError bodvcd(399, "Norbert")
@test_throws SpiceError bodvcd(999999, "RADII")
finally
kclear()
end
end
@testset "bodvrd" begin
try
furnsh(path(CORE, :pck))
@test bodvrd("EARTH", "RADII") == [6378.1366, 6378.1366, 6356.7519]
@test bodvrd("EARTH", "RADII") == [6378.1366, 6378.1366, 6356.7519]
@test_throws SpiceError bodvrd("EARTH", "Norbert")
@test_throws SpiceError bodvrd("Norbert", "RADII")
finally
kclear()
end
end
@testset "brcktd/brckti" begin
@test SPICE._brcktd(4.0, 1.0, 3.0) == clamp(4.0, 1.0, 3.0)
@test SPICE._brckti(4, 1, 3) == clamp(4, 1, 3)
arr = ["FEYNMAN", "BOHR", "EINSTEIN", "NEWTON", "GALILEO"]
ord = sortperm(arr)
for name in arr
@test SPICE._bschoc(name, arr, ord) ==
findfirst(arr .== name)
@test SPICE._bsrchc(name, sort(arr)) ==
findfirst(sort(arr) .== name)
@test SPICE._bschoc(name, arr, ord) == findfirst(arr .== name)
@test SPICE._bsrchc(name, sort(arr)) == findfirst(sort(arr) .== name)
end
end
@test SPICE._bschoi(1, [3, 1, 2], [2, 3, 1]) == findfirst([3, 1, 2] .== 1)
@test SPICE._bsrchd(3.0, [1.0, 2.0, 3.0]) ==
findfirst([1.0, 2.0, 3.0] .== 3.0)
@test SPICE._bsrchi(3, [1, 2, 3]) == findfirst([1, 2, 3] .== 3)
@testset "bschoi/bsrchd/bsrchi" begin
@test SPICE._bschoi(1, [3, 1, 2], [2, 3, 1]) == findfirst([3, 1, 2] .== 1)
@test SPICE._bsrchd(3.0, [1.0, 2.0, 3.0]) == findfirst([1.0, 2.0, 3.0] .== 3.0)
@test SPICE._bsrchi(3, [1, 2, 3]) == findfirst([1, 2, 3] .== 3)
end
end
1 change: 0 additions & 1 deletion test/e.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
try
furnsh(path(CORE, :lsk), path(CORE, :pck), path(CORE, :spk))
et = str2et("2007 FEB 3 00:00:00.000")
# umbral
trgepc, obspos, trmpts = edterm("UMBRAL", "SUN", "MOON", et, "IAU_MOON", "EARTH", 3, abcorr="LT+S")
expected_trgepc = 223732863.86351674795
expected_obspos = [394721.1024056578753516078,
Expand Down

0 comments on commit 2149d04

Please sign in to comment.