Skip to content

Commit

Permalink
Clean and complete s to x
Browse files Browse the repository at this point in the history
  • Loading branch information
helgee committed Mar 5, 2019
1 parent 760e653 commit 999fce6
Show file tree
Hide file tree
Showing 12 changed files with 210 additions and 115 deletions.
115 changes: 53 additions & 62 deletions src/s.jl

Large diffs are not rendered by default.

78 changes: 73 additions & 5 deletions src/t.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export
term_pl02,
termpt,
timdef,
timout,
tipbod,
Expand All @@ -12,6 +14,72 @@ export
twovec,
tyear

"""
Find terminator points on a target body. The caller specifies
half-planes, bounded by the illumination source center-target center
vector, in which to search for terminator points.
The terminator can be either umbral or penumbral. The umbral
terminator is the boundary of the region on the target surface
where no light from the source is visible. The penumbral
terminator is the boundary of the region on the target surface
where none of the light from the source is blocked by the target
itself.
The surface of the target body may be represented either by a
triaxial ellipsoid or by topographic data.
### Arguments ###
- `method`: Computation method
- `ilusrc`: Illumination source
- `target`: Name of target body
- `et `: Epoch in ephemeris seconds past J2000 TDB
- `fixref`: Body-fixed, body-centered target body frame
- `abcorr`: Aberration correction
- `corloc`: Aberration correction locus
- `obsrvr`: Name of observing body
- `refvec`: Reference vector for cutting half-planes
- `rolstp`: Roll angular step for cutting half-planes
- `ncuts `: Number of cutting planes
- `schstp`: Angular step size for searching
- `soltol`: Solution convergence tolerance
- `maxn `: Maximum number of entries in output arrays
### Output ###
- `npts `: Counts of terminator points corresponding to cuts
- `points`: Terminator points
- `epochs`: Times associated with terminator points
- `trmvcs`: Terminator vectors emanating from the observer
### References ###
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/termpt_c.html)
"""
function termpt(method, ilusrc, target, et, fixref, abcorr, corloc, obsrvr, refvec, rolstp,
ncuts, schstp, soltol, maxn)
@checkdims 3 refvec
npts = zeros(SpiceInt, maxn)
points = Array{SpiceDouble}(undef, 3, maxn)
epochs = Array{SpiceDouble}(undef, maxn)
trmvcs = Array{SpiceDouble}(undef, 3, maxn)

ccall((:termpt_c, libcspice), Cvoid,
(Cstring, Cstring, Cstring, SpiceDouble, Cstring, Cstring, Cstring, Cstring,
Ref{SpiceDouble}, SpiceDouble, SpiceInt, SpiceDouble, SpiceDouble, SpiceInt,
Ref{SpiceInt}, Ref{SpiceDouble}, Ref{SpiceDouble}, Ref{SpiceDouble}),
method, ilusrc, target, et, fixref, abcorr, corloc, obsrvr, refvec, rolstp,
ncuts, schstp, soltol, maxn, npts, points, epochs, trmvcs)
handleerror()
valid_points = npts .>= 1
npts[valid_points], cmatrix_to_array(points)[valid_points],
epochs, cmatrix_to_array(trmvcs)[valid_points]
end

@deprecate term_pl02 termpt

"""
timdef(action, item, value="")
Expand Down Expand Up @@ -56,7 +124,7 @@ function timdef(action, item, value="")
val = fill(UInt8(0), lenout)
val[1:length(value)] .= collect(value)
ccall((:timdef_c, libcspice), Cvoid,
(Cstring, Cstring, SpiceInt, Ref{UInt8}),
(Cstring, Cstring, SpiceInt, Ref{SpiceChar}),
string(action), string(item), lenout, val)
handleerror()
chararray_to_string(val)
Expand Down Expand Up @@ -86,7 +154,7 @@ Returns a string representation of the input epoch.
function timout(et, pictur, lenout=128)
string = Array{UInt8}(undef, lenout)
ccall((:timout_c, libcspice), Cvoid,
(Cdouble, Cstring, Cint, Ref{UInt8}),
(Cdouble, Cstring, SpiceInt, Ref{SpiceChar}),
et, pictur, lenout, string)
handleerror()
chararray_to_string(string)
Expand Down Expand Up @@ -296,8 +364,7 @@ Returns output rotation matrix.
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/twovec_c.html)
"""
function twovec(axdef, indexa, plndef, indexp)
length(axdef) != 3 && throw(ArgumentError("`axdef` must be an iterable with three elements."))
length(plndef) != 3 && throw(ArgumentError("`plndef` must be an iterable with three elements."))
@checkdims 3 axdef plndef
mout = Array{SpiceDouble}(undef, 3, 3)
ccall((:twovec_c, libcspice), Cvoid,
(Ref{SpiceDouble}, SpiceInt, Ref{SpiceDouble}, SpiceInt, Ref{SpiceDouble}),
Expand All @@ -316,5 +383,6 @@ Returns the number of seconds per tropical year.
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/tyear_c.html)
"""
function tyear()
ccall((:tyear_c, libcspice), Cdouble, ())
ccall((:tyear_c, libcspice), SpiceDouble, ())
end

15 changes: 8 additions & 7 deletions src/u.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export ucase,

function _ucase(in)
n = length(in) + 1
out = Array{UInt8}(undef, n)
out = Array{SpiceChar}(undef, n)
ccall((:ucase_c, libcspice), Cvoid, (Cstring, SpiceInt, Ref{UInt8}),
in, n, out)
chararray_to_string(out)
Expand Down Expand Up @@ -68,12 +68,12 @@ Returns the approximate derivative of `udfunc` at `x`.
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/uddf_c.html)
"""
function uddf(udfunc, x, dx)
function _udfunc(et::SpiceDouble, value::Ref{SpiceDouble})
value = unsafe_wrap(Array, value, 1)
value[1] = udfunc(et)
function _udfunc(et::SpiceDouble, value::Ptr{SpiceDouble})
value_ = GC.@preserve value unsafe_wrap(Array{SpiceDouble}, value, 1)
value_[1] = udfunc(et)
nothing
end
func = @cfunction($_udfunc, Cvoid, (SpiceDouble, Ref{SpiceDouble}))
func = @cfunction($_udfunc, Cvoid, (SpiceDouble, Ptr{SpiceDouble}))
deriv = Ref{SpiceDouble}()
ccall((:uddf_c, libcspice), Cvoid,
(Ref{Cvoid}, SpiceDouble, SpiceDouble, Ref{SpiceDouble}),
Expand Down Expand Up @@ -213,15 +213,15 @@ unormg
Convert an input time from Calendar or Julian Date format, UTC, to ephemeris
seconds past J2000.
### Arguments ###
- `utcstr`: Input time string, UTC
### Output ###
Returns the equivalent of utcstr, expressed in ephemeris seconds past J2000.
### References ###
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/utc2et_c.html)
Expand All @@ -233,3 +233,4 @@ function utc2et(utcstr)
handleerror()
et[]
end

10 changes: 10 additions & 0 deletions src/v.jl
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ Returns the component `a` orthogonal to `b`.
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vperp_c.html)
"""
function vperp(a, b)
@checkdims 3 a b
p = Array{SpiceDouble}(undef, 3)
ccall((:vperp_c, libcspice), Cvoid,
(Ref{SpiceDouble}, Ref{SpiceDouble}, Ref{SpiceDouble}),
Expand All @@ -429,6 +430,7 @@ Returns the vector resulting from the projection.
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vprjp_c.html)
"""
function vprjp(vin, plane)
@checkdims 3 vin
vout = Array{SpiceDouble}(undef, 3)
ccall((:vprjp_c, libcspice), Cvoid,
(Ref{SpiceDouble}, Ref{Plane}, Ref{SpiceDouble}),
Expand Down Expand Up @@ -458,6 +460,7 @@ Returns the inverse projection of `vin` or `nothing` if `vin` could not be calcu
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vprjpi_c.html)
"""
function vprjpi(vin, projpl, invpl)
@checkdims 3 vin
vout = Array{SpiceDouble}(undef, 3)
found = Ref{SpiceBoolean}()
ccall((:vprjpi_c, libcspice), Cvoid,
Expand Down Expand Up @@ -486,6 +489,7 @@ Returns the projection of `a` onto `b`.
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vproj_c.html)
"""
function vproj(a, b)
@checkdims 3 a b
p = Array{SpiceDouble}(undef, 3)
ccall((:vproj_c, libcspice), Cvoid,
(Ref{SpiceDouble}, Ref{SpiceDouble}, Ref{SpiceDouble}), a, b, p)
Expand All @@ -510,6 +514,7 @@ Returns the relative differences between `v1` and `v2`.
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vrel_c.html)
"""
function vrel(v1, v2)
@checkdims 3 v1 v2
ccall((:vrel_c, libcspice), SpiceDouble,
(Ref{SpiceDouble}, Ref{SpiceDouble}), v1, v2)
end
Expand All @@ -533,6 +538,7 @@ Returns the relative differences between `v1` and `v2`.
"""
function vrelg(v1, v2)
ndim = length(v1)
@checkdims ndim v2
ccall((:vrelg_c, libcspice), SpiceDouble,
(Ref{SpiceDouble}, Ref{SpiceDouble}, SpiceInt), v1, v2, ndim)
end
Expand All @@ -558,6 +564,7 @@ Result of rotating `v` about `axis` by `theta`.
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vrotv_c.html)
"""
function vrotv(v, axis, theta)
@checkdims 3 v
r = Array{SpiceDouble}(undef, 3)
ccall((:vrotv_c, libcspice), Cvoid,
(Ref{SpiceDouble}, Ref{SpiceDouble}, SpiceDouble, Ref{SpiceDouble}),
Expand Down Expand Up @@ -619,6 +626,7 @@ Returns the angle between `v1` and `v2` in radians.
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/vsep_c.html)
"""
function vsep(v1, v2)
@checkdims 3 v1 v2
ccall((:vsep_c, libcspice), SpiceDouble,
(Ref{SpiceDouble}, Ref{SpiceDouble}), v1, v2)
end
Expand All @@ -642,6 +650,7 @@ Returns the angle between `v1` and `v2` in radians.
"""
function vsepg(v1, v2)
ndim = length(v1)
@checkdims ndim v2
ccall((:vsepg_c, libcspice), SpiceDouble,
(Ref{SpiceDouble}, Ref{SpiceDouble}, SpiceInt), v1, v2, ndim)
end
Expand Down Expand Up @@ -765,3 +774,4 @@ end
vzerog

@deprecate vzerog(v1) iszero(v1)

7 changes: 4 additions & 3 deletions src/w.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Determine the complement of a double precision window with respect to a specifie
### Arguments ###
- `window`: Input window.
- `window`: Input window
- `left`: Left endpoint of the complement interval
- `right`: Right endpoint of the complement interval
Expand Down Expand Up @@ -428,7 +428,7 @@ Returns a tuple consisting of:
- `avg`: Average measure
- `stddev`: Standard deviation
- `shortest`: Location of shortest interval
- `longest`: Location of longest interval
- `longest`: Location of longest interval
### References ###
Expand Down Expand Up @@ -483,7 +483,7 @@ Form a valid double precision window from the contents of a window array.
### Arguments ###
- `window`: A (possibly uninitialized) `SpiceDoubleCell` containing endpoints of
(possibly unordered and non-disjoint) intervals.
(possibly unordered and non-disjoint) intervals.
### Output ###
Expand All @@ -502,3 +502,4 @@ function wnvald!(window)
end

@deprecate wnvald wnvald!

6 changes: 3 additions & 3 deletions src/x.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ that indicates whether these are a unique representation.
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/xf2eul_c.html)
"""
function xf2eul(xform, axisa, axisb, axisc)
size(xform) != (6, 6) && throw(ArgumentError("`xform` must be a 6x6 matrix."))
@checkdims 6 6 xform
eulang = Array{SpiceDouble}(undef, 6)
unique = Ref{SpiceBoolean}()
ccall((:xf2eul_c, libcspice), Cvoid,
Expand Down Expand Up @@ -59,7 +59,7 @@ associated with `xform`.
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/xf2rav_c.html)
"""
function xf2rav(xform)
size(xform) != (6, 6) && throw(ArgumentError("`xform` must be a 6x6 matrix."))
@checkdims 6 6 xform
rot = Array{SpiceDouble}(undef, 3, 3)
av = Array{SpiceDouble}(undef, 3)
ccall((:xf2rav_c, libcspice), Cvoid,
Expand Down Expand Up @@ -89,7 +89,7 @@ Returns the converted output state.
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/xfmsta_c.html)
"""
function xfmsta(input_state, input_coord_sys, output_coord_sys, body)
length(input_state) != 6 && throw(ArgumentError("Lenght of `input_state` must be 6."))
@checkdims 6 input_state
output_state = Array{SpiceDouble}(undef, 6)
ccall((:xfmsta_c, libcspice), Cvoid,
(Ref{SpiceDouble}, Cstring, Cstring, Cstring, Ref{SpiceDouble}),
Expand Down
2 changes: 1 addition & 1 deletion test/i.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ using LinearAlgebra: I, norm
path(CASSINI, :ik))
et = str2et("2013 FEB 25 11:50:00 UTC")
spoint, trgepc, srfvec = subpnt("NEAR POINT/ELLIPSOID", "ENCELADUS", et, "IAU_ENCELADUS",
"EARTH", abcorr="CN+S")
"CN+S", "EARTH")
trgepc2, srfvec2, phase, incid, emissn = illumg("ELLIPSOID", "ENCELADUS", "SUN", et,
"IAU_ENCELADUS", "CASSINI", spoint, abcorr="CN+S")

Expand Down
4 changes: 2 additions & 2 deletions test/s.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ using LinearAlgebra: I, norm, cross, normalize
et = str2et("2008 aug 11 00:00:00")
re, _, rp = bodvrd("MARS", "RADII", 3)
f = (re - rp) / re
methods = ["Intercept: ellipsoid", "Near point: ellipsoid"]
methods = ["INTERCEPT: ELLIPSOID", "NEAR POINT: ELLIPSOID"]
expecteds = [[349199089.604657,
349199089.64135259,
0.0,
Expand All @@ -1157,7 +1157,7 @@ using LinearAlgebra: I, norm, cross, normalize
25.729407227461937,
25.994934171391463]]
for (expected, method) in zip(expecteds, methods)
spoint, trgepc, srfvec = subpnt(method, "Mars", et, "IAU_MARS", "earth", abcorr="LT+S")
spoint, trgepc, srfvec = subpnt(method, "MARS", et, "IAU_MARS", "LT+S", "EARTH")
odist = norm(srfvec)
@test odist expected[2]
spglon, spglat, spgalt = recpgr("mars", spoint, re, f)
Expand Down
21 changes: 19 additions & 2 deletions test/t.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
import LinearAlgebra

@testset "T" begin
@testset "T" begin
@testset "termpt" begin
try
furnsh(path(CORE, :spk),
path(CORE, :pck),
path(CORE, :lsk),
path(EXTRA, :mars_spk),
path(EXTRA, :phobos_dsk))
et = str2et("1972 AUG 11 00:00:00")
points, epochs, tangts = termpt("UMBRAL/TANGENT/DSK/UNPRIORITIZED", "SUN",
"PHOBOS", et, "IAU_PHOBOS", "CN+S", "CENTER",
"MARS", [0.0, 0.0, 1.0], 2/3 * π, 3, 1.0e-4,
1.0e-7, 10000)
@test length(points) == 3
finally
kclear()
end
end
@testset "timdef" begin
try
furnsh(path(CORE, :lsk))
Expand Down Expand Up @@ -144,4 +161,4 @@ import LinearAlgebra
@testset "tyear" begin
@test tyear() == 3.15569259747e7
end
end
end
32 changes: 16 additions & 16 deletions test/u.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ import LinearAlgebra
v2 = randn(3)
@test SPICE._ucrss(v1, v2) LinearAlgebra.normalize(LinearAlgebra.cross(v1, v2))
end
#= @testset "uddf" begin =#
#= try =#
#= furnsh(path(CORE, :lsk), path(CORE, :spk)) =#
#= et = str2et("JAN 1 2009") =#
#= =#
#= function udfunc(et_in) =#
#= _, new_et = spkpos("MERCURY", et_in, "J2000", "LT+S", "MOON") =#
#= new_et =#
#= end =#
#= =#
#= deriv = uddf(udfunc, et, 1.0) =#
#= @test deriv ≈ -0.000135670940 atol=1e-10 =#
#= finally =#
#= kclear() =#
#= end =#
#= end =#
@testset "uddf" begin
try
furnsh(path(CORE, :lsk), path(CORE, :spk))
et = str2et("JAN 1 2009")

function udfunc(et_in)
_, new_et = spkpos("MERCURY", et_in, "J2000", "LT+S", "MOON")
new_et
end

deriv = uddf(udfunc, et, 1.0)
@test deriv -0.000135670940 atol=1e-10
finally
kclear()
end
end
@testset "union" begin
# SPICEINT_CELL
one = SpiceIntCell(8)
Expand Down
Loading

0 comments on commit 999fce6

Please sign in to comment.