Skip to content

Commit

Permalink
Add m
Browse files Browse the repository at this point in the history
  • Loading branch information
helgee committed Dec 5, 2018
1 parent 7a7f145 commit 49edb58
Show file tree
Hide file tree
Showing 13 changed files with 531 additions and 44 deletions.
10 changes: 4 additions & 6 deletions src/SPICE.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#= __precompile__() =#

module SPICE

export SpiceException
export SpiceError

deps = abspath(joinpath(splitdir(@__FILE__)[1], "..", "deps", "deps.jl"))
if isfile(deps)
Expand All @@ -18,11 +16,11 @@ function __init__()
ccall((:errprt_c, libcspice), Cvoid, (Cstring, Cint, Cstring), "SET", 0, "NONE")
end

struct SpiceException <: Exception
struct SpiceError <: Exception
msg::String
end

Base.show(io::IO, ex::SpiceException) = print(io, ex.msg)
Base.show(io::IO, ex::SpiceError) = print(io, ex.msg)

function handleerror()
failed = ccall((:failed_c, libcspice), Bool, ())
Expand All @@ -33,7 +31,7 @@ function handleerror()
message = unsafe_string(pointer(msg))
# Reset error status and throw Julia error
ccall((:reset_c, libcspice), Cvoid, ())
throw(SpiceException(message))
throw(SpiceError(message))
end
end

Expand Down
8 changes: 4 additions & 4 deletions src/b.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function bodc2n(code)
found = Ref{SpiceBoolean}()
ccall((:bodc2n_c, libcspice), Cvoid, (SpiceInt, SpiceInt, Ptr{UInt8}, Ref{SpiceBoolean}),
code, 36, name, found)
found[] == 0 && throw(SpiceException("No body with code $code found."))
found[] == 0 && throw(SpiceError("No body with code $code found."))
unsafe_string(pointer(name))
end

Expand Down Expand Up @@ -166,7 +166,7 @@ Define a body name/ID code pair for later translation via [`bodn2c`](@ref) or [`
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/boddef_c.html)
"""
function boddef(name, code)
length(name) > 35 && throw(SpiceException("The maximum allowed length for a name is 35 characters."))
length(name) > 35 && throw(SpiceError("The maximum allowed length for a name is 35 characters."))
ccall((:boddef_c, libcspice), Cvoid, (Cstring, SpiceInt), name, code)
end

Expand Down Expand Up @@ -215,7 +215,7 @@ function bodn2c(name)
found = Ref{SpiceBoolean}()
ccall((:bodn2c_c, libcspice), Cvoid, (Cstring, Ref{SpiceInt}, Ref{SpiceBoolean}),
name, code, found)
found[] == 0 && throw(SpiceException("No body with name '$name' found."))
found[] == 0 && throw(SpiceError("No body with name '$name' found."))
Int(code[])
end

Expand All @@ -241,7 +241,7 @@ function bods2c(name)
found = Ref{SpiceBoolean}()
ccall((:bods2c_c, libcspice), Cvoid, (Cstring, Ref{SpiceInt}, Ref{SpiceBoolean}),
name, code, found)
found[] == 0 && throw(SpiceException("Neither a body with name '$name' found nor is it an integer."))
found[] == 0 && throw(SpiceError("Neither a body with name '$name' found nor is it an integer."))
Int(code[])
end

Expand Down
4 changes: 2 additions & 2 deletions src/c.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function ccifrm(frclss, clssid)
frclss, clssid, lenout, frcode, frname, center, found,
)
handleerror()
found[] == 0 && throw(SpiceException("No frame with class $frclss and class ID $clssid found."))
found[] == 0 && throw(SpiceError("No frame with class $frclss and class ID $clssid found."))
frcode[], unsafe_string(pointer(frname)), center[]
end

Expand Down Expand Up @@ -315,7 +315,7 @@ function cidfrm(cent)
found = Ref{SpiceBoolean}()
ccall((:cidfrm_c, libcspice), Cvoid, (SpiceInt, SpiceInt, Ref{SpiceInt}, Ptr{UInt8}, Ref{SpiceBoolean}),
cent, lenout, frcode, frname, found)
found[] == 0 && throw(SpiceException("No frame associated with body $cent found."))
found[] == 0 && throw(SpiceError("No frame associated with body $cent found."))
frcode[], unsafe_string(pointer(frname))
end

Expand Down
2 changes: 1 addition & 1 deletion src/h.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ function hx2dp(str)
(Cstring, SpiceInt, Ref{SpiceDouble}, Ref{SpiceBoolean}, Ptr{UInt8}),
str, 46, dp, error, errmsg
)
error[] == 1 && throw(SpiceException(unsafe_string(pointer(errmsg))))
error[] == 1 && throw(SpiceError(unsafe_string(pointer(errmsg))))
dp[]
end
Loading

0 comments on commit 49edb58

Please sign in to comment.