Skip to content

Commit

Permalink
Finish p
Browse files Browse the repository at this point in the history
  • Loading branch information
helgee committed Feb 8, 2019
1 parent 3cabc49 commit 3269156
Show file tree
Hide file tree
Showing 7 changed files with 1,991 additions and 185 deletions.
4 changes: 2 additions & 2 deletions src/SPICE.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ function array_to_cmatrix(array::Vector{Vector{Int}}; n=0)
end

function cmatrix_to_array(matrix)
[matrix[:, i] for i in 1:size(matrix, 2)]
arr = [matrix[:, i] for i in 1:size(matrix, 2)]
end

function cmatrix_to_array(matrix::Matrix{SpiceInt})
[Int.(matrix[:, i]) for i in 1:size(matrix, 2)]
arr = [Int.(matrix[:, i]) for i in 1:size(matrix, 2)]
end

include("cells.jl")
Expand Down
42 changes: 42 additions & 0 deletions src/g.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export
gcpool,
gdpool,
georec,
getfov,
gfpa,
gfpa!,
gipool
Expand Down Expand Up @@ -101,6 +102,47 @@ function georec(lon, lat, alt, re, f)
rectan
end

"""
getfov(instid, room=10, shapelen=128, framelen=128)
Return the field-of-view (FOV) parameters for a specified instrument.
The instrument is specified by its NAIF ID code.
### Arguments ###
- `instid `: NAIF ID of an instrument
- `room `: Maximum number of vectors that can be returned (default: 10)
- `shapelen`: Space available in the string `shape` (default: 128)
- `framelen`: Space available in the string `frame` (default: 128)
### Output ###
Returns a tuple consisting of
- `shape `: Instrument FOV shape
- `frame `: Name of the frame in which FOV vectors are defined
- `bsight`: Boresight vector
- `bounds`: FOV boundary vectors
### References ###
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/getfov_c.html)
"""
function getfov(instid, room=10, shapelen=128, framelen=128)
shape = Array{UInt8}(undef, shapelen)
frame = Array{UInt8}(undef, framelen)
bsight = Array{SpiceDouble}(undef, 3)
n = Ref{SpiceInt}()
bounds = Array{SpiceDouble}(undef, 3, room)
ccall((:getfov_c, libcspice), Cvoid,
(SpiceInt, SpiceInt, SpiceInt, SpiceInt,
Ptr{UInt8}, Ptr{UInt8}, Ptr{SpiceDouble}, Ref{SpiceInt}, Ptr{SpiceDouble}),
instid, room, shapelen, framelen, shape, frame, bsight, n, bounds)
handleerror()
arr_bounds = cmatrix_to_array(bounds)
unsafe_string(pointer(shape)), unsafe_string(pointer(frame)), bsight, arr_bounds[1:n[]]
end

"""
gfpa!(cnfine, result, target, illmn, abcorr, obsrvr, relate, refval, adjust, step, nintvls)
Expand Down
35 changes: 33 additions & 2 deletions src/p.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export
prsdp,
prsint,
psv2pl,
pxform
pxform,
pxfrm2

"""
pckcov!(cover, pck, idcode)
Expand Down Expand Up @@ -701,6 +702,36 @@ function pxform(from, to, et)
(Cstring, Cstring, SpiceDouble, Ptr{SpiceDouble}),
from, to, et, rot)
handleerror()
rot
permutedims(rot)
end

"""
pxfrm2(from, to, etfrom, etto)
Return the 3x3 matrix that transforms position vectors from one specified frame at a
specified epoch to another specified frame at another specified epoch.
### Arguments ###
- `from`: Name of the frame to transform from
- `to`: Name of the frame to transform to
- `etfrom`: Evaluation time of `from` frame
- `etto`: Evaluation time of `to` frame
### Output ###
Returns a position transformation matrix from frame `from` to frame `to`.
### References ###
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/pxfrm2_c.html)
"""
function pxfrm2(from, to, etfrom, etto)
rot = Array{SpiceDouble}(undef, 3, 3)
ccall((:pxfrm2_c, libcspice), Cvoid,
(Cstring, Cstring, SpiceDouble, SpiceDouble, Ptr{SpiceDouble}),
from, to, etfrom, etto, rot)
handleerror()
permutedims(rot)
end

156 changes: 116 additions & 40 deletions src/s.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export
scard,
scard!,
sincpt,
spd,
spkcls,
spkcpo,
Expand All @@ -11,6 +12,7 @@ export
str2et,
subpnt,
subslr,
surfpt,
swpool,
sxform

Expand Down Expand Up @@ -39,11 +41,63 @@ end

@deprecate scard scard!

"""
sincpt(method, target, et, fixref, abcorr, obsrvr, dref, dvec)
Given an observer and a direction vector defining a ray, compute the surface intercept
of the ray on a target body at a specified epoch, optionally corrected for light time
and stellar aberration.
The surface of the target body may be represented by a triaxial ellipsoid or by
topographic data provided by DSK files.
### Arguments ###
- `method`: Computation method
- `target`: Name of target body
- `et`: Epoch in TDB seconds past J2000 TDB
- `fixref`: Body-fixed, body-centered target body frame
- `abcorr`: Aberration correction flag
- `obsrvr`: Name of observing body
- `dref`: Reference frame of ray's direction vector
- `dvec`: Ray's direction vector
### Output ###
Returns a tuple consisting of the following data or `nothing` if no intercept was found.
- `spoint`: Surface intercept point on the target body
- `trgepc`: Intercept epoch
- `srfvec`: Vector from observer to intercept point
### References ###
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/sincpt_c.html)
"""
function sincpt(method, target, et, fixref, abcorr, obsrvr, dref, dvec)
length(dvec) != 3 && throw(ArgumentError("Length of `dvec` must be 3."))

spoint = Array{SpiceDouble}(undef, 3)
trgepc = Ref{SpiceDouble}()
srfvec = Array{SpiceDouble}(undef, 3)
found = Ref{SpiceBoolean}()

ccall((:sincpt_c, libcspice), Cvoid,
(Cstring, Cstring, SpiceDouble, Cstring, Cstring, Cstring, Cstring, Ptr{SpiceDouble},
Ptr{SpiceDouble}, Ref{SpiceDouble}, Ptr{SpiceDouble}, Ref{SpiceInt}),
method, target, et, fixref, abcorr, obsrvr, dref, dvec, spoint, trgepc, srfvec, found)

handleerror()
Bool(found[]) || return nothing

spoint, trgepc[], srfvec
end

function str2et(string)
et = Ref{SpiceDouble}(0)
ccall((:str2et_c, libcspice), Cvoid, (Cstring, Ref{SpiceDouble}), string, et)
handleerror()
return et[]
et[]
end

"""
Expand Down Expand Up @@ -135,84 +189,106 @@ end


"""
subpnt(method, target, et, fixref, obsrvr, abcorr)
subslr(method, target, et, fixref, obsrvr, abcorr)
Compute the rectangular coordinates of the sub-observer point on
a target body at a specified epoch, optionally corrected for
light time and stellar aberration.
Compute the rectangular coordinates of the sub-solar point on
a target body at a specified epoch, optionally corrected for
light time and stellar aberration.
### Arguments ###
- `method`: Computation method.
- `target`: Name of target body.
- `et`: Epoch in ephemeris seconds past J2000 TDB.
- `fixref`: Body-fixed, body-centered target body frame.
- `obsrvr`: Name of observing body.
- `method`: Computation method.
- `target`: Name of target body.
- `et`: Epoch in ephemeris seconds past J2000 TDB.
- `fixref`: Body-fixed, body-centered target body frame.
- `obsrvr`: Name of observing body.
- `abcorr`: Aberration correction.
### Output ###
- `spoint`: Sub-solar point on the target body.
- `trgepc`: Sub-solar point epoch.
- `spoint`: Sub-solar point on the target body.
- `trgepc`: Sub-solar point epoch.
- `srfvec`: Vector from observer to sub-solar point.
Returns `cell` with its cardinality set to `card`.
### References ###
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/subpnt_c.html)
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/subslr_c.html)
"""
function subpnt(method, target, et, fixref, obsrvr; abcorr="NONE")
function subslr(method, target, et, fixref, obsrvr; abcorr="NONE")
spoint = Array{SpiceDouble}(undef, 3)
trgepc = Ref{SpiceDouble}(0)
trgepc = Ref{SpiceDouble}()
srfvec = Array{SpiceDouble}(undef, 3)
ccall((:subpnt_c, libcspice), Cvoid,
(Cstring, Cstring, SpiceDouble, Cstring, Cstring, Cstring, Ptr{SpiceDouble}, Ref{SpiceDouble}, Ptr{SpiceDouble}),
method, target, et, fixref, abcorr, obsrvr, spoint, trgepc, srfvec)
ccall((:subslr_c, libcspice), Cvoid,
(Cstring, Cstring, SpiceDouble, Cstring, Cstring, Cstring,
Ptr{SpiceDouble}, Ref{SpiceDouble}, Ptr{SpiceDouble}),
method, target, et, fixref, abcorr, obsrvr, spoint, trgepc, srfvec)
handleerror()
spoint, trgepc[], srfvec
end


"""
subslr(method, target, et, fixref, obsrvr, abcorr)
subpnt(method, target, et, fixref, obsrvr, abcorr)
Compute the rectangular coordinates of the sub-solar point on
a target body at a specified epoch, optionally corrected for
Compute the rectangular coordinates of the sub-observer point on
a target body at a specified epoch, optionally corrected for
light time and stellar aberration.
### Arguments ###
- `method`: Computation method.
- `target`: Name of target body.
- `et`: Epoch in ephemeris seconds past J2000 TDB.
- `fixref`: Body-fixed, body-centered target body frame.
- `obsrvr`: Name of observing body.
- `abcorr`: Aberration correction.
- `method`: Computation method.
- `target`: Name of target body.
- `et`: Epoch in ephemeris seconds past J2000 TDB.
- `fixref`: Body-fixed, body-centered target body frame.
- `obsrvr`: Name of observing body.
- `abcorr`: Aberration correction.
### Output ###
- `spoint`: Sub-solar point on the target body.
- `trgepc`: Sub-solar point epoch.
- `spoint`: Sub-solar point on the target body.
- `trgepc`: Sub-solar point epoch.
- `srfvec`: Vector from observer to sub-solar point.
Returns `cell` with its cardinality set to `card`.
### References ###
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/subslr_c.html)
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/subpnt_c.html)
"""
function subslr(method::AbstractString, target::AbstractString, et::Float64, fixref::AbstractString, obsrvr::AbstractString; abcorr::AbstractString="NONE")
function subpnt(method, target, et, fixref, obsrvr; abcorr="NONE")
spoint = Array{SpiceDouble}(undef, 3)
trgepc = Ref{SpiceDouble}(0)
trgepc = Ref{SpiceDouble}()
srfvec = Array{SpiceDouble}(undef, 3)
ccall((:subslr_c, libcspice), Cvoid, (Cstring, Cstring, SpiceDouble, Cstring, Cstring, Cstring, Ptr{SpiceDouble}, Ref{SpiceDouble}, Ptr{SpiceDouble}), method, target, et, fixref, abcorr, obsrvr, spoint, trgepc, srfvec)
ccall((:subpnt_c, libcspice), Cvoid,
(Cstring, Cstring, SpiceDouble, Cstring, Cstring, Cstring,
Ptr{SpiceDouble}, Ref{SpiceDouble}, Ptr{SpiceDouble}),
method, target, et, fixref, abcorr, obsrvr, spoint, trgepc, srfvec)
handleerror()
return spoint, trgepc[], srfvec
spoint, trgepc[], srfvec
end

"""
positn I Position of the observer in body-fixed frame.
u I Vector from the observer in some direction.
a I Length of the ellipsoid semi-axis along the x-axis.
b I Length of the ellipsoid semi-axis along the y-axis.
c I Length of the ellipsoid semi-axis along the z-axis.
point O Point on the ellipsoid pointed to by u.
found O Flag indicating if u points at the ellipsoid.
"""
function surfpt(positn, u, a, b, c)
length(positn) != 3 && throw(ArgumentError("Length of `positn` must be 3."))
length(u) != 3 && throw(ArgumentError("Length of `u` must be 3."))
point = Array{SpiceDouble}(undef, 3)
found = Ref{SpiceBoolean}()
ccall((:surfpt_c, libcspice), Cvoid,
(Ptr{SpiceDouble}, Ptr{SpiceDouble}, SpiceDouble, SpiceDouble, SpiceDouble,
Ptr{SpiceDouble}, Ref{SpiceBoolean}),
positn, u, a, b, c, point, found)
handleerror()
!Bool(found[]) && return nothing


point
end

"""
swpool(agent, names)
Expand All @@ -229,9 +305,9 @@ Add a name to the list of agents to notify whenever a member of a list of kernel
- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/swpool_c.html)
"""
function swpool(agent, names)
_names, m, n = chararray(names)
names, m, n = chararray(names)
ccall((:swpool_c, libcspice), Cvoid, (Cstring, SpiceInt, SpiceInt, Ptr{SpiceChar}),
agent, m, n, _names)
agent, m, n, names)
handleerror()
nothing
end
Expand Down
Loading

0 comments on commit 3269156

Please sign in to comment.