From 2149d042bf6f07cfee30f98730e00365082d22ab Mon Sep 17 00:00:00 2001 From: Helge Eichhorn Date: Sun, 3 Mar 2019 09:56:54 +0100 Subject: [PATCH] Cleanup a and b --- src/a.jl | 1 + src/b.jl | 41 ++++++++-------- src/d.jl | 2 +- test/a.jl | 5 +- test/b.jl | 141 ++++++++++++++++++++++++++++++++---------------------- test/e.jl | 1 - 6 files changed, 109 insertions(+), 82 deletions(-) diff --git a/src/a.jl b/src/a.jl index cfc5af5..6b28e89 100644 --- a/src/a.jl +++ b/src/a.jl @@ -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) diff --git a/src/b.jl b/src/b.jl index 64f2d31..c9c303c 100644 --- a/src/b.jl +++ b/src/b.jl @@ -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 """ @@ -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 @@ -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 ### @@ -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 @@ -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 ### @@ -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 @@ -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 """ @@ -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 """ @@ -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 ### @@ -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 @@ -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 ### @@ -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 @@ -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}), @@ -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 ### diff --git a/src/d.jl b/src/d.jl index b36dfef..b4cbfa8 100644 --- a/src/d.jl +++ b/src/d.jl @@ -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 ### diff --git a/test/a.jl b/test/a.jl index 98307d4..2ef829a 100644 --- a/test/a.jl +++ b/test/a.jl @@ -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 \ No newline at end of file + @test_throws ArgumentError axisar(axis[1:2], π/2) +end diff --git a/test/b.jl b/test/b.jl index 7795aa7..9818206 100644 --- a/test/b.jl +++ b/test/b.jl @@ -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 diff --git a/test/e.jl b/test/e.jl index 03cdbb4..804f6de 100644 --- a/test/e.jl +++ b/test/e.jl @@ -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,