Skip to content

Commit

Permalink
Complete h
Browse files Browse the repository at this point in the history
  • Loading branch information
helgee committed Feb 9, 2019
1 parent 0caaa85 commit 3fe69fa
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 9 deletions.
42 changes: 38 additions & 4 deletions src/h.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export halfpi, hx2dp
export halfpi, hrmint, hx2dp

function _halfpi()
ccall((:halfpi_c, libcspice), SpiceDouble, ())
Expand All @@ -14,12 +14,45 @@ halfpi

@deprecate halfpi() π/2

"""
hrmint(xvals, yvals, x)
Evaluate a Hermite interpolating polynomial at a specified abscissa value.
### Arguments ###
- `xvals`: Abscissa values
- `yvals`: Ordinate and derivative values
- `x`: Point at which to interpolate the polynomial
### Output ###
- `f`: Interpolated function value at `x`
- `df`: Interpolated function's derivative at `x`
### References ###
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/hrmint_c.html)
"""
function hrmint(xvals, yvals, x)
n = length(xvals)
length(yvals) != 2n && throw(ArgumentError("`yvals` must have double the length of `xvals`."))
work = Array{SpiceDouble}(undef, 4n)
f = Ref{SpiceDouble}()
df = Ref{SpiceDouble}()
ccall((:hrmint_c, libcspice), Cvoid,
(SpiceInt, Ptr{SpiceDouble}, Ptr{SpiceDouble}, SpiceDouble, Ptr{SpiceDouble},
Ref{SpiceDouble}, Ref{SpiceDouble}),
n, xvals, yvals, x, work, f, df)
handleerror()
f[], df[]
end

"""
hx2dp(str)
Convert a string representing a double precision number in a
base 16 "scientific notation" into its equivalent double
precision number.
Convert a string representing a double precision number in a base 16 "scientific notation"
into its equivalent double precision number.
### Arguments ###
Expand All @@ -30,6 +63,7 @@ precision number.
- `dp`: Double precision value to be returned
### References ###
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/hx2dp_c.html)
"""
function hx2dp(str)
Expand Down
23 changes: 18 additions & 5 deletions test/h.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
@testset "H" begin
@test hx2dp("2A^3") == 672.0
@test_throws SpiceError hx2dp("2A^3000")
@test_throws SpiceError hx2dp("-2A^3000")
@test_throws SpiceError hx2dp("foo")
@test SPICE._halfpi() π/2
@testset "hex2dp" begin
@test hx2dp("2A^3") == 672.0
@test_throws SpiceError hx2dp("2A^3000")
@test_throws SpiceError hx2dp("-2A^3000")
@test_throws SpiceError hx2dp("foo")
end
@testset "hrmint" begin
xvals = [-1.0, 0.0, 3.0, 5.0]
yvals = [6.0, 3.0, 5.0, 0.0, 2210.0, 5115.0, 78180.0, 109395.0]
answer, deriv = hrmint(xvals, yvals, 2)
@test answer 141.0
@test deriv 456.0
@test_throws ArgumentError hrmint(xvals, yvals[1:4], 2)
@test_throws SpiceError hrmint([0.0, 0.0], yvals[1:4], 2)
end
@testset "halfpi" begin
@test SPICE._halfpi() π/2
end
end

0 comments on commit 3fe69fa

Please sign in to comment.