diff --git a/src/cells.jl b/src/cells.jl index 2a89dd1..ba2d213 100644 --- a/src/cells.jl +++ b/src/cells.jl @@ -8,6 +8,7 @@ dtype(::Type{SpiceDouble}) = 1 dtype(::Type{SpiceInt}) = 2 mutable struct Cell{T} + # Do not reorder these fields dtype::SpiceInt length::SpiceInt size::SpiceInt @@ -22,23 +23,57 @@ mutable struct Cell{T} end end -mutable struct SpiceCell{T, N} <: AbstractArray{T, N} - data::Array{T, N} - cell::Cell{T} +itertype(::Type{T}) where {T} = T +itertype(::Type{SpiceChar}) = String + +init_data(::Type{T}, size, _) where {T} = Array{T}(undef, CTRLSZ + size) +init_data(::Type{SpiceChar}, size, length) = fill(SpiceChar(0), (length, CTRLSZ + size)) + +len(::Type{T}, _) where {T} = 0 +len(::Type{SpiceChar}, length) = length += 1 + +dim(::Type{T}) where {T} = 1 +dim(::Type{SpiceChar}) = 2 + +data_ptr(::Type{SpiceChar}, data, length) = pointer(data, CTRLSZ * length + 1) +data_ptr(::Type{T}, data, _) where {T} = pointer(data, CTRLSZ + 1) + +mutable struct SpiceCell{S, T, N} <: AbstractArray{T, 1} + data::Array{S, N} + cell::Cell{S} + + function SpiceCell{T}(size::Integer, length::Integer=256) where T + length = len(T, length) + cell = Cell{T}(length, size) + data = init_data(T, size, length) + self = new{T, itertype(T), dim(T)}(data, cell) + base = pointer(self.data, 1) + data = pointer(self.data, CTRLSZ + 1) + self.cell.base = pointer(self.data, 1) + self.cell.data = data_ptr(T, self.data, length) + self + end end -const SpiceCharCell = SpiceCell{SpiceChar,2} -const SpiceDoubleCell = SpiceCell{SpiceDouble,1} -const SpiceIntCell = SpiceCell{SpiceInt,1} +const SpiceDoubleCell = SpiceCell{SpiceDouble} +const SpiceIntCell = SpiceCell{SpiceInt} +const SpiceCharCell = SpiceCell{SpiceChar} Base.IndexStyle(::SpiceCell) = IndexLinear() Base.firstindex(cell::SpiceCell) = 1 Base.lastindex(cell::SpiceCell) = cell.cell.card -function show(io::IO, cell::SpiceCell{T,1}) where T +""" + SpiceCharCell(size, length) + +Create a SpiceCharCell that can contain up to `size` strings with `length` characters. +""" +SpiceCharCell + +function show(io::IO, cell::SpiceCell{T}) where T print(io, "SpiceCell{$(T.name.name)}($(cell.cell.size))") end -function show(io::IO, cell::SpiceCell{T,2}) where T +function show(io::IO, cell::SpiceCharCell) print(io, "SpiceCell{$(T.name.name)}($(cell.cell.size),$(cell.cell.length))") end @@ -51,52 +86,15 @@ function check_ind(cell, inds) end end -function getindex(cell::SpiceCell{T}, ind) where T<:Real +function getindex(cell::SpiceCell, ind::Int) check_ind(cell, ind) - return cell.data[CTRLSZ .+ ind] + cell.data[CTRLSZ .+ ind] end function getindex(cell::SpiceCharCell, ind::Int) check_ind(cell, ind) str = cell.data[:, CTRLSZ .+ ind] - return String(str[1:findfirst(str .== 0)-1]) -end - -function getindex(cell::SpiceCharCell, ind) - check_ind(cell, ind) - str = cell.data[:, CTRLSZ .+ ind] - return vec(mapslices(x -> String(x[1:findfirst(x .== 0)-1]), str, dims=1)) -end - -function SpiceCell{SpiceChar}(size, length) - # We add an extra element for the null-byte terminator. - nlength = length + 1 - strc = Cell{SpiceChar}(nlength, size) - data = fill(UInt8(0), (nlength, CTRLSZ + size)) - self = SpiceCell(data, strc) - base = pointer(self.data, 1) - data = pointer(self.data, CTRLSZ * nlength + 1) - self.cell.base = base - self.cell.data = data - return self -end - -""" - SpiceCharCell(size, length) - -Create a SpiceCharCell that can contain up to `size` strings with `length` characters. -""" -SpiceCharCell(size::Int, length::Int) = SpiceCell{SpiceChar}(size, length) - -function SpiceCell{T}(size) where T<:Real - strc = Cell{T}(0, size) - data = Vector{T}(undef, CTRLSZ + size) - self = SpiceCell(data, strc) - base = pointer(self.data, 1) - data = pointer(self.data, CTRLSZ + 1) - self.cell.base = base - self.cell.data = data - return self + String(str[1:findfirst(str .== 0)-1]) end """ @@ -104,18 +102,18 @@ end Create a SpiceDoubleCell that can contain up to `size` elements. """ -SpiceDoubleCell(size) = SpiceCell{SpiceDouble}(size) +SpiceDoubleCell """ SpiceIntCell(size) Create a SpiceIntCell that can contain up to `size` elements. """ -SpiceIntCell(size) = SpiceCell{SpiceInt}(size) +SpiceIntCell for (t, f) in zip((SpiceInt, SpiceDouble), ("appndi_c", "appndd_c")) @eval begin - function appnd(item, cell::SpiceCell{$t}) + function appnd(item, cell::SpiceCell{$t, $t}) c = Ref(cell.cell) ccall(($f, libcspice), Cvoid, ($t, Ref{Cell{$t}}), item, cell.cell) handleerror() @@ -133,7 +131,7 @@ Append an `item` to the char/double/integer SpiceCell `cell`. [https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/appndd_c.html](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/appndd_c.html) [https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/appndi_c.html](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/appndi_c.html) """ -function appnd(item, cell::SpiceCell{SpiceChar}) +function appnd(item, cell::SpiceCharCell) ccall((:appndc_c, libcspice), Cvoid, (Cstring, Ref{Cell{SpiceChar}}), item, cell.cell) handleerror() return nothing @@ -156,21 +154,21 @@ append!(cell::SpiceCell, collection) = foreach(x -> appnd(x, cell), collection) """ card(cell) -Returns the cardinality (number of elements) of a SpiceCell `cell`. +Returns the cardinality (number of elements) of `cell`. """ card(cell::SpiceCell) = Int(cell.cell.card) """ length(cell) -Returns the cardinality (number of elements) of a SpiceCell `cell`. +Returns the cardinality (number of elements) of `cell`. """ length(cell::SpiceCell) = card(cell) """ size(cell) -Returns the cardinality (number of elements) of a SpiceCell `cell`. +Returns the cardinality (number of elements) of `cell`. """ size(cell::SpiceCell) = (card(cell),) @@ -179,8 +177,15 @@ size(cell::SpiceCell) = (card(cell),) Duplicate the SpiceCell `cell`. """ -function Base.copy(cell::SpiceCell{T, N}) where {T, N} +function Base.copy(cell::SpiceCell{T}) where {T} copy = SpiceCell{T}(cell.cell.size) ccall((:copy_c, libcspice), Cvoid, (Ref{Cell{T}}, Ref{Cell{T}}), cell.cell, copy.cell) copy end + +function Base.copy(cell::SpiceCharCell) + copy = SpiceCharCell(cell.cell.size, cell.cell.length) + ccall((:copy_c, libcspice), Cvoid, (Ref{Cell{SpiceChar}}, Ref{Cell{SpiceChar}}), cell.cell, copy.cell) + copy +end + diff --git a/src/e.jl b/src/e.jl index b361c44..d9dbd2c 100644 --- a/src/e.jl +++ b/src/e.jl @@ -1,9 +1,40 @@ -export +export + edlimb, et2utc, etcal, eul2m, edterm +""" + edlimb(a, b, c, viewpt) + +Find the limb of a triaxial ellipsoid, viewed from a specified point. + +### Arguments ### + +- `a`: Length of ellipsoid semi-axis lying on the x-axis +- `b`: Length of ellipsoid semi-axis lying on the y-axis +- `c`: Length of ellipsoid semi-axis lying on the z-axis +- `viewpt`: Location of viewing point + +### Output ### + +Returns the limb of the ellipsoid as seen from the viewing point. + +### References ### + +- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/edlimb_c.html) +""" +function edlimb(a, b, c, viewpt) + length(viewpt) != 3 && throw(ArgumentError("Length of `viewpt` must be 3.")) + limb = Ellipse() + ccall((:edlimb_c, libcspice), Cvoid, + (SpiceDouble, SpiceDouble, SpiceDouble, Ptr{SpiceDouble}, Ref{Ellipse}), + a, b, c, viewpt, limb) + handleerror() + limb +end + """ et2utc(et, format, prec) @@ -23,8 +54,7 @@ to Calendar, Day-of-Year, or Julian Date format, UTC. ### Output ### -Returns an output time string equivalent to the input -epoch, in the specified format. +Returns an output time string equivalent to the input epoch, in the specified format. ### References ### @@ -128,5 +158,5 @@ function edterm(trmtyp, source, target, et, fixref, obsrvr, npts; abcorr="NONE") (Cstring, Cstring, Cstring, SpiceDouble, Cstring, Cstring, Cstring, SpiceInt, Ref{SpiceDouble}, Ptr{SpiceDouble}, Ptr{SpiceDouble}), trmtyp, source, target, et, fixref, abcorr, obsrvr, npts, trgepc, obspos, trmpts) handleerror() - trgepc[], obspos, trmpts + trgepc[], obspos, trmpts end diff --git a/src/i.jl b/src/i.jl index 170a7d2..2436768 100644 --- a/src/i.jl +++ b/src/i.jl @@ -1,88 +1,378 @@ -export +export + ident, + illum, + illum_pl02, + illum_plid_pl02, + illumf, + illumg, ilumin, - illumg + inedpl, + inelpl, + inrypl, + insrtc!, + insrtc, + insrtd!, + insrtd, + insrti!, + insrti, + inter + +function _ident() + matrix = Array{SpiceDouble}(undef, 3, 3) + ccall((:ident_c, libcspice), Cvoid, (Ptr{SpiceDouble},), matrix) + matrix +end + +@deprecate ident() Array{Float64}(LinearAlgebra.I, 3, 3) """ - ilumin(method, target, et, fixref, obsrvr, spoint, abcorr) + illumf(method, target, ilusrc, et, fixref, abcorr, obsrvr, spoint) + +Compute the illumination angles - phase, incidence, and emission - at a specified point on a +target body. Return logical flags indicating whether the surface point is visible from the +observer's position and whether the surface point is illuminated. -Find the illumination angles (phase, solar incidence, and emission) at a specified surface point of a target body. +The target body's surface is represented using topographic data provided by DSK files, or by a +reference ellipsoid. + +The illumination source is a specified ephemeris object. ### 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 +- `ilusrc`: Name of illumination source +- `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 +- `spoint`: Body-fixed coordinates of a target surface point + +### Output ### + +- `trgepc`: Target surface point epoch +- `srfvec`: Vector from observer to target surface point +- `phase`: Phase angle at the surface point +- `incdnc`: Source incidence angle at the surface point +- `emissn`: Emission angle at the surface point +- `visibl`: Visibility flag (`true` if visible) +- `lit`: Illumination flag (`true` if illuminated) + +### References ### + +- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/illumf_c.html) +""" +function illumf(method, target, ilusrc, et, fixref, abcorr, obsrvr, spoint) + length(spoint) != 3 && throw(ArgumentError("Length of `spoint` must be 3.")) + trgepc = Ref{SpiceDouble}() + srfvec = Array{SpiceDouble}(undef, 3) + phase = Ref{SpiceDouble}() + incdnc = Ref{SpiceDouble}() + emissn = Ref{SpiceDouble}() + visibl = Ref{SpiceBoolean}() + lit = Ref{SpiceBoolean}() + ccall((:illumf_c, libcspice), Cvoid, + (Cstring, Cstring, Cstring, SpiceDouble, Cstring, Cstring, Cstring, Ptr{SpiceDouble}, + Ref{SpiceDouble}, Ptr{SpiceDouble}, Ref{SpiceDouble}, Ref{SpiceDouble}, + Ref{SpiceDouble}, Ref{SpiceBoolean}, Ref{SpiceBoolean}), + method, target, ilusrc, et, fixref, abcorr, obsrvr, spoint, trgepc, srfvec, phase, incdnc, + emissn, visibl, lit) + handleerror() + trgepc[], srfvec, phase[], incdnc[], emissn[], Bool(visibl[]), Bool(lit[]) +end + +""" + illumg(method, target, ilusrc, et, fixref, obsrvr, spoint, abcorr) + +Find the illumination angles (phase, incidence, and emission) at a specified surface point of a +target body. + +The surface of the target body may be represented by a triaxial ellipsoid or by topographic data +provided by DSK files. + +The illumination source is a specified ephemeris object. + +### Arguments ### + +- `method`: Computation method. +- `target`: Name of target body. +- `ilusrc`: Name of illumination source. +- `et`: Epoch in ephemeris seconds past J2000 TDB. +- `fixref`: Body-fixed, body-centered target body frame. +- `obsrvr`: Name of observing body. - `spoint`: Body-fixed coordinates of a target surface point. - `abcorr`: Aberration correction. ### Output ### -- `trgepc`: Sub-solar point epoch. +- `trgepc`: Sub-solar point epoch. - `srfvec`: Vector from observer to sub-solar point. -- `phase`: Phase angle at the surface point. -- `incdnc`: Solar incidence angle at the surface point. -- `emissn`: Emission angle at the surface point. +- `phase`: Phase angle at the surface point. +- `incdnc`: Solar incidence angle at the surface point. +- `emissn`: Emission angle at the surface point. ### References ### -- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/ilumin_c.html +- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/illumg_c.html """ -function ilumin(method, target, et, fixref, obsrvr, spoint; abcorr="NONE") +function illumg(method, target, ilusrc, et, fixref, obsrvr, spoint; abcorr="NONE") trgepc = Ref{SpiceDouble}(0) srfvec = Array{SpiceDouble}(undef, 3) phase = Ref{SpiceDouble}(0) incdnc = Ref{SpiceDouble}(0) emissn = Ref{SpiceDouble}(0) - ccall((:ilumin_c, libcspice), Cvoid, - (Cstring, Cstring, SpiceDouble, Cstring, Cstring, Cstring, Ptr{SpiceDouble}, Ref{SpiceDouble}, Ptr{SpiceDouble}, Ref{SpiceDouble}, Ref{SpiceDouble}, Ref{SpiceDouble}), - method, target, et, fixref, abcorr, obsrvr, spoint, trgepc, srfvec, phase, incdnc, emissn) + ccall((:illumg_c, libcspice), Cvoid, + (Cstring, Cstring, Cstring, SpiceDouble, Cstring, Cstring, Cstring, Ptr{SpiceDouble}, + Ref{SpiceDouble}, Ptr{SpiceDouble}, Ref{SpiceDouble}, Ref{SpiceDouble}, + Ref{SpiceDouble}), + method, target, ilusrc, et, fixref, abcorr, obsrvr, spoint, trgepc, srfvec, phase, + incdnc, emissn) handleerror() trgepc[], srfvec, phase[], incdnc[], emissn[] end +@deprecate illum illumin +@deprecate illum_pl02 illumin +@deprecate illum_plid_pl02 illumin + """ - illumg(method, target, ilusrc, et, fixref, obsrvr, spoint, abcorr) + ilumin(method, target, et, fixref, obsrvr, spoint, abcorr) -Find the illumination angles (phase, incidence, and emission) at a specified surface point of a target body. - -The surface of the target body may be represented by a triaxial ellipsoid or by topographic data provided by DSK files. - -The illumination source is a specified ephemeris object. +Find the illumination angles (phase, solar incidence, and emission) at a specified surface point +of a target body. ### Arguments ### -- `method`: Computation method. -- `target`: Name of target body. -- `ilusrc`: Name of illumination source. -- `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. - `spoint`: Body-fixed coordinates of a target surface point. - `abcorr`: Aberration correction. ### Output ### -- `trgepc`: Sub-solar point epoch. +- `trgepc`: Sub-solar point epoch. - `srfvec`: Vector from observer to sub-solar point. -- `phase`: Phase angle at the surface point. -- `incdnc`: Solar incidence angle at the surface point. -- `emissn`: Emission angle at the surface point. +- `phase`: Phase angle at the surface point. +- `incdnc`: Solar incidence angle at the surface point. +- `emissn`: Emission angle at the surface point. ### References ### -- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/illumg_c.html +- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/ilumin_c.html """ -function illumg(method, target, ilusrc, et, fixref, obsrvr, spoint; abcorr="NONE") +function ilumin(method, target, et, fixref, obsrvr, spoint; abcorr="NONE") trgepc = Ref{SpiceDouble}(0) srfvec = Array{SpiceDouble}(undef, 3) phase = Ref{SpiceDouble}(0) incdnc = Ref{SpiceDouble}(0) emissn = Ref{SpiceDouble}(0) - ccall((:illumg_c, libcspice), Cvoid, - (Cstring, Cstring, Cstring, SpiceDouble, Cstring, Cstring, Cstring, Ptr{SpiceDouble}, Ref{SpiceDouble}, Ptr{SpiceDouble}, Ref{SpiceDouble}, Ref{SpiceDouble}, Ref{SpiceDouble}), - method, target, ilusrc, et, fixref, abcorr, obsrvr, spoint, trgepc, srfvec, phase, incdnc, emissn) + ccall((:ilumin_c, libcspice), Cvoid, + (Cstring, Cstring, SpiceDouble, Cstring, Cstring, Cstring, Ptr{SpiceDouble}, + Ref{SpiceDouble}, Ptr{SpiceDouble}, Ref{SpiceDouble}, Ref{SpiceDouble}, + Ref{SpiceDouble}), + method, target, et, fixref, abcorr, obsrvr, spoint, trgepc, srfvec, phase, incdnc, emissn) handleerror() trgepc[], srfvec, phase[], incdnc[], emissn[] end + +""" + inedpl(a, b, c, plane) + +Find the intersection of a triaxial ellipsoid and a plane. + +### Arguments ### + +- `a`: Length of ellipsoid semi-axis lying on the x-axis +- `b`: Length of ellipsoid semi-axis lying on the y-axis +- `c`: Length of ellipsoid semi-axis lying on the z-axis +- `plane`: Plane that intersects ellipsoid + +### Output ### + +- `ellipse`: Intersection ellipse + +Returns `nothing` if no ellipse could be found. + +### References ### + +- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/XXX_c.html) +""" +function inedpl(a, b, c, plane) + ellipse = Ellipse() + found = Ref{SpiceBoolean}() + ccall((:inedpl_c, libcspice), Cvoid, + (SpiceDouble, SpiceDouble, SpiceDouble, Ref{Plane}, Ref{Ellipse}, Ref{SpiceBoolean}), + a, b, c, plane, ellipse, found) + handleerror() + !Bool(found[]) && return nothing + ellipse +end + +""" + inelpl(ellips, plane) + +Find the intersection of an ellipse and a plane. + +### Arguments ### + +- `ellips`: An ellipse +- `plane`: A plane + +### Output ### + +- `nxpts`: Number of intersection points of ellipse and plane +- `xpt1`, `xpt2`: Intersection points + +### References ### + +- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/inelpl_c.html) +""" +function inelpl(ellips, plane) + nxpts = Ref{SpiceInt}() + xpt1 = Array{SpiceDouble}(undef, 3) + xpt2 = Array{SpiceDouble}(undef, 3) + ccall((:inelpl_c, libcspice), Cvoid, + (Ref{Ellipse}, Ref{Plane}, Ref{SpiceInt}, Ptr{SpiceDouble}, Ptr{SpiceDouble}), + ellips, plane, nxpts, xpt1, xpt2) + handleerror() + nxpts[], xpt1, xpt2 +end + +""" + inrypl(vertex, dir, plane) + +Find the intersection of a ray and a plane. + +### Arguments ### + +- `vertex`, `dir`: Vertex and direction vector of ray +- `plane`: A plane + +### Output ### + +- `nxpts`: Number of intersection points of ray and plane +- `xpt1`, `xpt2`: Intersection points + +### References ### + +- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/inrypl_c.html) +""" +function inrypl(vertex, dir, plane) + length(vertex) != 3 && throw(ArgumentError("Length of `vertex` must be 3.")) + length(dir) != 3 && throw(ArgumentError("Length of `dir` must be 3.")) + nxpts = Ref{SpiceInt}() + xpt = Array{SpiceDouble}(undef, 3) + ccall((:inrypl_c, libcspice), Cvoid, + (Ptr{SpiceDouble}, Ptr{SpiceDouble}, Ref{Plane}, Ref{SpiceInt}, Ptr{SpiceDouble}), + vertex, dir, plane, nxpts, xpt) + handleerror() + nxpts[], xpt +end + +""" + insrtc!(set, item) + +Insert an item into a character set. + +### Arguments ### + +- `set`: Insertion set +- `item`: Item to be inserted + +### Output ### + +Returns the updated set. + +### References ### + +- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/insrtc_c.html) +""" +function insrtc!(set, item) + ccall((:insrtc_c, libcspice), Cvoid, (Cstring, Ref{Cell{SpiceChar}}), item, set.cell) + set +end + +@deprecate insrtc insrtc! + +""" + insrtd!(set, item) + +Insert an item into a double set. + +### Arguments ### + +- `set`: Insertion set +- `item`: Item to be inserted + +### Output ### + +Returns the updated set. + +### References ### + +- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/insrtd_c.html) +""" +function insrtd!(set, item) + ccall((:insrtd_c, libcspice), Cvoid, (SpiceDouble, Ref{Cell{SpiceDouble}}), item, set.cell) + set +end + +@deprecate insrtd insrtd! + +""" + insrti!(set, item) + +Insert an item into a character set. + +### Arguments ### + +- `set`: Insertion set +- `item`: Item to be inserted + +### Output ### + +Returns the updated set. + +### References ### + +- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/insrti_c.html) +""" +function insrti!(set, item) + ccall((:insrti_c, libcspice), Cvoid, (SpiceInt, Ref{Cell{SpiceInt}}), item, set.cell) + set +end + +@deprecate insrti insrti! + +""" + inter(a, b) + +Intersect two sets of any data type to form a third set. + +### Arguments ### + +- `a`: First input set +- `b`: Second input set + +### Output ### + +Returns intersection of a and b. + +### References ### + +- [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/inter_c.html) +""" +function inter(a::T, b::T) where {T <: SpiceCell{S}} where S + n = card(a) + card(b) + l = max(a.cell.length, b.cell.length) + out = SpiceCell{S}(n, l) + ccall((:inter_c, libcspice), Cvoid, + (Ref{Cell{S}}, Ref{Cell{S}}, Ref{Cell{S}}), + a.cell, b.cell, out.cell) + handleerror() + out +end + diff --git a/src/u.jl b/src/u.jl index 8650468..d8563b3 100644 --- a/src/u.jl +++ b/src/u.jl @@ -93,14 +93,13 @@ Compute the union of two sets of any data type to form a third set. ### Output ### -Returns a cell containing the union of a and b. +Returns a cell containing the union of `a` and `b`. ### References ### - [NAIF Documentation](https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/union_c.html) """ -function Base.union(a::T, b::T) where { - T <: SpiceCell{S}} where S +function Base.union(a::T, b::T) where {T <: SpiceCell{S}} where S size = max(a.cell.size, b.cell.size) if S <: SpiceChar length = max(a.cell.length, b.cell.length) diff --git a/test/e.jl b/test/e.jl index e6b83b7..f93b525 100644 --- a/test/e.jl +++ b/test/e.jl @@ -1,101 +1,74 @@ @testset "E" begin - @testset "et2utc" begin - try - furnsh(path(CORE, :lsk)) - let et = -527644192.5403653 - output = et2utc(et, :J, 6) - @test output == "JD 2445438.006415" - end - finally - kclear() - end - end - @testset "etcal" begin - et = 0.0 - cal = etcal(et) - @test cal == "2000 JAN 01 12:00:00.000" + @testset "edlimb" begin + viewpt = [2.0, 0.0, 0.0] + limb = edlimb(sqrt(2), 2.0 * sqrt(2), sqrt(2), viewpt) + expected_sminor = [0.0, 0.0, -1.0] + expected_smajor = [0.0, 2.0, 0.0] + expected_center = [1.0, 0.0, 0.0] + @test center(limb) ≈ expected_center + @test semi_major(limb) ≈ expected_smajor + @test semi_minor(limb) ≈ expected_sminor + @test_throws ArgumentError edlimb(sqrt(2), 2.0 * sqrt(2), sqrt(2), viewpt[1:2]) + @test_throws SpiceError edlimb(sqrt(2), 2.0 * sqrt(2), -sqrt(2), viewpt) end - @testset "eul2m" begin - act = eul2m(3, 2, 1, 3, 2, 1) - @test size(act) == (3, 3) - exp = [0.411982245665683 -0.6812427202564033 0.6051272472413688; - 0.05872664492762098 -0.642872836134547 -0.7637183366502791; - 0.9092974268256817 0.35017548837401463 -0.2248450953661529] - @testset for i in eachindex(act, exp) - @test act[i] ≈ exp[i] - end - end - @testset "edterm" begin try - furnsh( - path(CORE, :lsk), - path(CORE, :pck), - path(CORE, :spk), - ) + 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, 27265.11780063395417528227, -19069.08478859506431035697] + expected_obspos = [394721.1024056578753516078, + 27265.11780063395417528227, + -19069.08478859506431035697] + expected_trmpts0 = [-1.53978381936825627463e+02, + -1.73056331949840728157e+03, + 1.22893325627419600088e-01] + expected_trmpts1 = [ 87.37506200891714058798, + 864.40670594653545322217, + 1504.56817899807947469526] + expected_trmpts2 = [ 42.21324376177891224415, + 868.21134635239388899208, + -1504.3223923468244720425] + expected_trmpts = [ -1.53978381936825627463e+02, + -1.73056331949840728157e+03, + 1.22893325627419600088e-01, + 87.37506200891714058798, + 864.40670594653545322217, + 1504.56817899807947469526, + 42.21324376177891224415, + 868.21134635239388899208, + -1504.3223923468244720425] - expected_trmpts0 = [ - -1.53978381936825627463e+02, - -1.73056331949840728157e+03, - 1.22893325627419600088e-01, - ] - expected_trmpts1 = [ - 87.37506200891714058798, - 864.40670594653545322217, - 1504.56817899807947469526, - ] - expected_trmpts2 = [ - 42.21324376177891224415, - 868.21134635239388899208, - -1504.3223923468244720425, - ] - expected_trmpts = [ - -1.53978381936825627463e+02, - -1.73056331949840728157e+03, - 1.22893325627419600088e-01, - 87.37506200891714058798, - 864.40670594653545322217, - 1504.56817899807947469526, - 42.21324376177891224415, - 868.21134635239388899208, - -1504.3223923468244720425, - ] @test trgepc ≈ expected_trgepc @test obspos[1] ≈ expected_obspos[1] @test obspos[2] ≈ expected_obspos[2] @test obspos[3] ≈ expected_obspos[3] - + @testset for i in eachindex(trmpts, expected_trmpts) @test obspos[1] ≈ expected_obspos[1] @test trmpts[i] ≈ expected_trmpts[i] end iluet0, srfvec0, phase0, solar0, emissn0 = ilumin("Ellipsoid", "MOON", et, "IAU_MOON", - "EARTH", trmpts[:,1], abcorr="LT+S") + "EARTH", trmpts[:,1], abcorr="LT+S") @test rad2deg(solar0) ≈ 90.269765819 iluet1, srfvec1, phase1, solar1, emissn1 = ilumin("Ellipsoid", "MOON", et, "IAU_MOON", - "EARTH", trmpts[:,2], abcorr="LT+S") + "EARTH", trmpts[:,2], abcorr="LT+S") @test rad2deg(solar1) ≈ 90.269765706 iluet2, srfvec2, phase2, solar2, emissn2 = ilumin("Ellipsoid", "MOON", et, "IAU_MOON", - "EARTH", trmpts[:,3], abcorr="LT+S") + "EARTH", trmpts[:,3], abcorr="LT+S") @test rad2deg(solar2) ≈ 90.269765730 - #penumbral + # penumbral trgepc, obspos, trmpts = edterm("PENUMBRAL", "SUN", "MOON", et, "IAU_MOON", "EARTH", 3, abcorr="LT+S") - expected_trmpts = [ - 1.54019056755619715204e+02, - 1.73055969989532059117e+03, - -1.23508409498995316844e-01, - -87.33436047798454637814, - -864.41003834758112134296, - -1504.56862757530461749411, - -42.17254722919552278881, - -868.21467833235510624945, - 1504.32161075630597224517, - ] + expected_trmpts = [1.54019056755619715204e+02, + 1.73055969989532059117e+03, + -1.23508409498995316844e-01, + -87.33436047798454637814, + -864.41003834758112134296, + -1504.56862757530461749411, + -42.17254722919552278881, + -868.21467833235510624945, + 1504.32161075630597224517] @test trgepc ≈ expected_trgepc @test obspos[1] ≈ expected_obspos[1] @test obspos[2] ≈ expected_obspos[2] @@ -104,16 +77,886 @@ @test trmpts[i] ≈ expected_trmpts[i] end iluet0, srfvec0, phase0, solar0, emissn0 = ilumin("Ellipsoid", "MOON", et, "IAU_MOON", - "EARTH", trmpts[:,1], abcorr="LT+S") + "EARTH", trmpts[:,1], abcorr="LT+S") @test rad2deg(solar0) ≈ 89.730234406 iluet1, srfvec1, phase1, solar1, emissn1 = ilumin("Ellipsoid", "MOON", et, "IAU_MOON", - "EARTH", trmpts[:,2], abcorr="LT+S") + "EARTH", trmpts[:,2], abcorr="LT+S") @test rad2deg(solar1) ≈ 89.730234298 iluet2, srfvec2, phase2, solar2, emissn2 = ilumin("Ellipsoid", "MOON", et, "IAU_MOON", - "EARTH", trmpts[:,3], abcorr="LT+S") + "EARTH", trmpts[:,3], abcorr="LT+S") @test rad2deg(solar2) ≈ 89.730234322 finally kclear() end end +#= @testset "ekacec" begin =# +#= kclear() =# +#= ekpath = os.path.join(cwd, "example_ekacec.ek") =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= handle = ekopn(ekpath, ekpath, 0) =# +#= segno = ekbseg(handle, "test_table_ekacec", ["c1"], ["DATATYPE = CHARACTER*(*), NULLS_OK = TRUE"]) =# +#= recno = ekappr(handle, segno) =# +#= ekacec(handle, segno, recno, "c1", 2, ["1.0", "2.0"], False) =# +#= ekcls(handle) =# +#= kclear() =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= @test not exists(ekpath) =# +#= =# +#= =# +#= @testset "ekaced" begin =# +#= kclear() =# +#= ekpath = os.path.join(cwd, "example_ekaced.ek") =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= handle = ekopn(ekpath, ekpath, 0) =# +#= segno = ekbseg(handle, "test_table_ekaced", ["c1"], ["DATATYPE = DOUBLE PRECISION, NULLS_OK = TRUE"]) =# +#= recno = ekappr(handle, segno) =# +#= ekaced(handle, segno, recno, "c1", 2, [1.0, 2.0], False) =# +#= ekcls(handle) =# +#= kclear() =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= @test not exists(ekpath) =# +#= =# +#= =# +#= @testset "ekmany" begin =# +#= kclear() =# +#= ekpath = os.path.join(cwd, "example_ekmany.ek") =# +#= tablename = "test_table_ekmany" =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= # Create new EK and new segment with table =# +#= handle = ekopn(ekpath, ekpath, 0) =# +#= decls = ["DATATYPE = CHARACTER*(10), NULLS_OK = FALSE, SIZE = VARIABLE", =# +#= "DATATYPE = DOUBLE PRECISION, NULLS_OK = FALSE, SIZE = VARIABLE", =# +#= "DATATYPE = INTEGER, NULLS_OK = FALSE, SIZE = VARIABLE"] =# +#= segno = ekbseg(handle, tablename, ['c1', 'd1', 'i1'], decls) =# +#= # Insert records: 1, 2, and 3 entries at rows 0, 1, 2, respectively =# +#= c_data = [['100'], ['101', '101'], ['102', '102', '102']] =# +#= d_data = [[100.0], [101.0, 101.0], [102.0, 102.0, 102.0]] =# +#= i_data = [[100], [101, 101], [102, 102, 102]] =# +#= for r in range(0, 3): =# +#= ekinsr(handle, segno, r) =# +#= ekacec(handle, segno, r, "c1", len(c_data[r]), c_data[r], False) =# +#= ekaced(handle, segno, r, "d1", len(d_data[r]), d_data[r], False) =# +#= ekacei(handle, segno, r, "i1", len(i_data[r]), i_data[r], False) =# +#= # Try record insertion beyond the next available, verify the exception =# +#= with pytest.raises(stypes.SpiceyError): =# +#= ekinsr(handle, segno, 4) =# +#= # Close EK, then reopen for reading =# +#= ekcls(handle) =# +#= kclear() =# +#= # =# +#= # Start of part two =# +#= # =# +#= handle = eklef(ekpath) =# +#= @test handle is not None =# +#= # Test query using ekpsel =# +#= query = "SELECT c1, d1, i1 from {}".format(tablename) =# +#= n, xbegs, xends, xtypes, xclass, tabs, cols, err, errmsg = ekpsel(query, 99, 99, 99) =# +#= @test n == 3 =# +#= @test stypes.SpiceEKDataType.SPICE_CHR == xtypes[0] =# +#= @test stypes.SpiceEKDataType.SPICE_DP == xtypes[1] =# +#= @test stypes.SpiceEKDataType.SPICE_INT == xtypes[2] =# +#= @test ([stypes.SpiceEKExprClass.SPICE_EK_EXP_COL]*3) == list(xclass) =# +#= @test (["TEST_TABLE_EKMANY"]*3) == tabs =# +#= @test "C1 D1 I1".split() == cols =# +#= @test not err =# +#= @test "" == errmsg =# +#= # Run query to retrieve the row count =# +#= nmrows, error, errmsg = ekfind(query, 99) =# +#= @test nmrows == 3 =# +#= @test not error =# +#= @test '' == errmsg =# +#= # test fail case for eknelt =# +#= with pytest.raises(stypes.SpiceyError): =# +#= eknelt(0, nmrows+1) =# +#= # Validate the content of each field, including exceptions when =# +#= # Loop over rows, test .ekgc/.ekgd/.ekgi =# +#= for r in range(nmrows): =# +#= # get number of elements in this row =# +#= n_elm = eknelt(0, r) =# +#= @test n_elm == r + 1 =# +#= for e in range(0, n_elm): =# +#= # get row int data =# +#= i_datum, i_null = ekgi(2, r, e) =# +#= @test not i_null =# +#= @test i_datum == i_data[r][e] =# +#= # get row double data =# +#= d_datum, d_null = ekgd(1, r, e) =# +#= @test not d_null =# +#= @test d_datum == d_data[r][e] =# +#= # get row char data =# +#= c_datum, c_null = ekgc(0, r, e) =# +#= @test not c_null =# +#= @test c_datum == c_data[r][e] =# +#= # Loop over rows, test .ekrcec/.ekrced/.ekrcei =# +#= for r in range(nmrows): =# +#= # get row int data =# +#= ni_vals, ri_data, i_null = ekrcei(handle, segno, r, "i1") =# +#= @test not i_null =# +#= @test ni_vals == r + 1 =# +#= npt.@test_array_equal(ri_data, i_data[r]) =# +#= # get row double data =# +#= nd_vals, rd_data, d_null = ekrced(handle, segno, r, "d1") =# +#= @test not d_null =# +#= @test nd_vals == r + 1 =# +#= npt.@test_array_equal(rd_data, d_data[r]) =# +#= # get row char data =# +#= nc_vals, rc_data, c_null = ekrcec(handle, segno, r, "c1", 11) =# +#= @test not c_null =# +#= @test nc_vals == r + 1 =# +#= @test rc_data == c_data[r] =# +#= # test out of bounds =# +#= with pytest.raises(stypes.SpiceyError): =# +#= ekrcei(handle, segno, 3, "i1") =# +#= with pytest.raises(stypes.SpiceyError): =# +#= ekrced(handle, segno, 3, "d1") =# +#= #with pytest.raises(stypes.SpiceyError): TODO: FIX =# +#= # ekrcec(handle, segno, 4, "c1", 4) # this causes a SIGSEGV =# +#= # =# +#= # Part 3 =# +#= # =# +#= # Close file, re-open for writing =# +#= ekuef(handle) =# +#= handle = ekopw(ekpath) =# +#= # Loop over rows, update values using .ekucec/.ekuced/.ekucei =# +#= c_data = [['200'], ['201', '201'], ['202', '202', '202']] =# +#= d_data = [[200.0], [201.0, 201.0], [202.0, 202.0, 202.0]] =# +#= i_data = [[200], [201, 201], [202, 202, 202]] =# +#= for r in range(0, 3): =# +#= ekucec(handle, segno, r, "c1", len(c_data[r]), c_data[r], False) =# +#= ekuced(handle, segno, r, "d1", len(d_data[r]), d_data[r], False) =# +#= ekucei(handle, segno, r, "i1", len(i_data[r]), i_data[r], False) =# +#= # Test invalid updates =# +#= with pytest.raises(stypes.SpiceyError): =# +#= ekucec(handle, segno, 3, "c1", 1, ['300'], False) =# +#= with pytest.raises(stypes.SpiceyError): =# +#= ekuced(handle, segno, 3, "d1", 1, [300.0], False) =# +#= with pytest.raises(stypes.SpiceyError): =# +#= ekucei(handle, segno, 3, "i1", 1, [300], False) =# +#= # Loop over rows, use .ekrcec/.ekrced/.ekrcei to test updates =# +#= for r in range(nmrows): =# +#= # get row int data =# +#= ni_vals, ri_data, i_null = ekrcei(handle, segno, r, "i1") =# +#= @test not i_null =# +#= @test ni_vals == r + 1 =# +#= npt.@test_array_equal(ri_data, i_data[r]) =# +#= # get row double data =# +#= nd_vals, rd_data, d_null = ekrced(handle, segno, r, "d1") =# +#= @test not d_null =# +#= @test nd_vals == r + 1 =# +#= npt.@test_array_equal(rd_data, d_data[r]) =# +#= # get row char data =# +#= nc_vals, rc_data, c_null = ekrcec(handle, segno, r, "c1", 11) =# +#= @test not c_null =# +#= @test nc_vals == r + 1 =# +#= @test rc_data == c_data[r] =# +#= # Cleanup =# +#= ekcls(handle) =# +#= @test not failed() =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= =# +#= =# +#= @testset "ekaclc" begin =# +#= kclear() =# +#= ekpath = os.path.join(cwd, "example_ekaclc.ek") =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= handle = ekopn(ekpath, ekpath, 0) =# +#= segno, rcptrs = ekifld(handle, "test_table_ekaclc", 1, 2, 200, ["c1"], 200, =# +#= ["DATATYPE = CHARACTER*(*), INDEXED = TRUE"]) =# +#= ekaclc(handle, segno, "c1", 10, ["1.0", "2.0"], [4, 4], [False, False], rcptrs, [0, 0]) =# +#= ekffld(handle, segno, rcptrs) =# +#= ekcls(handle) =# +#= kclear() =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= @test not exists(ekpath) =# +#= =# +#= =# +#= @testset "ekacld" begin =# +#= kclear() =# +#= ekpath = os.path.join(cwd, "example_ekacld.ek") =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= handle = ekopn(ekpath, ekpath, 0) =# +#= segno, rcptrs = ekifld(handle, "test_table_ekacld", 1, 2, 200, ["c1"], 200, =# +#= ["DATATYPE = DOUBLE PRECISION, NULLS_OK = FALSE"]) =# +#= ekacld(handle, segno, "c1", [1.0, 2.0], [1, 1], [False, False], rcptrs, [0, 0]) =# +#= ekffld(handle, segno, rcptrs) =# +#= ekcls(handle) =# +#= kclear() =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= @test not exists(ekpath) =# +#= =# +#= =# +#= @testset "ekacli" begin =# +#= kclear() =# +#= ekpath = os.path.join(cwd, "example_ekacli.ek") =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= handle = ekopn(ekpath, ekpath, 0) =# +#= segno, rcptrs = ekifld(handle, "test_table_ekacli", 1, 2, 200, ["c1"], 200, =# +#= ["DATATYPE = INTEGER, NULLS_OK = TRUE"]) =# +#= ekacli(handle, segno, "c1", [1, 2], [1, 1], [False, False], rcptrs, [0, 0]) =# +#= ekffld(handle, segno, rcptrs) =# +#= ekcls(handle) =# +#= kclear() =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= @test not exists(ekpath) =# +#= =# +#= =# +#= @testset "ekacli_stress" begin =# +#= for i in range(10): =# +#= test_ekacli() =# +#= =# +#= =# +#= @testset "ekappr" begin =# +#= kclear() =# +#= ekpath = os.path.join(cwd, "example_ekappr.ek") =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= handle = ekopn(ekpath, ekpath, 0) =# +#= segno = ekbseg(handle, "test_table_ekappr", ["c1"], ["DATATYPE = INTEGER, NULLS_OK = TRUE"]) =# +#= recno = ekappr(handle, segno) =# +#= ekacei(handle, segno, recno, "c1", 2, [1, 2], False) =# +#= ekcls(handle) =# +#= kclear() =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= @test not exists(ekpath) =# +#= =# +#= =# +#= @testset "ekbseg" begin =# +#= ekpath = os.path.join(cwd, "example_ekbseg.ek") =# +#= kclear() =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= handle = ekopn(ekpath, "Test EK", 100) =# +#= cnames = ['INT_COL_1'] =# +#= cdecls = ["DATATYPE=INTEGER, INDEXED=TRUE, NULLS_OK=TRUE"] =# +#= segno = ekbseg(handle, "SCALAR_DATA", cnames, cdecls) =# +#= recno = ekappr(handle, segno) =# +#= @test recno != -1 =# +#= ordids = [x for x in range(5)] =# +#= ekacei(handle, segno, recno, 'INT_COL_1', 5, ordids, False) =# +#= ekcls(handle) =# +#= kclear() =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= @test not exists(ekpath) =# +#= =# +#= =# +#= @testset "ekbseg_stress" begin =# +#= for i in range(10): =# +#= test_ekbseg() =# +#= =# +#= =# +#= @testset "ekccnt" begin =# +#= kclear() =# +#= ekpath = os.path.join(cwd, "example_ekccnt.ek") =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= handle = ekopn(ekpath, ekpath, 0) =# +#= segno = ekbseg(handle, "TEST_TABLE_EKCCNT", ["c1"], ["DATATYPE = INTEGER, NULLS_OK = TRUE"]) =# +#= recno = ekappr(handle, segno) =# +#= ekacei(handle, segno, recno, "c1", 2, [1, 2], False) =# +#= ekcls(handle) =# +#= kclear() =# +#= furnsh(ekpath) =# +#= @test ekntab() == 1 =# +#= @test ektnam(0, 100) == "TEST_TABLE_EKCCNT" =# +#= @test ekccnt("TEST_TABLE_EKCCNT") == 1 =# +#= kclear() =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= @test not exists(ekpath) =# +#= =# +#= =# +#= @testset "ekcii" begin =# +#= kclear() =# +#= ekpath = os.path.join(cwd, "example_ekcii.ek") =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= handle = ekopn(ekpath, ekpath, 0) =# +#= segno = ekbseg(handle, "TEST_TABLE_EKCII", ["c1"], ["DATATYPE = INTEGER, NULLS_OK = TRUE"]) =# +#= recno = ekappr(handle, segno) =# +#= ekacei(handle, segno, recno, "c1", 2, [1, 2], False) =# +#= ekcls(handle) =# +#= kclear() =# +#= furnsh(ekpath) =# +#= @test ekntab() == 1 =# +#= @test ektnam(0, 100) == "TEST_TABLE_EKCII" =# +#= @test ekccnt("TEST_TABLE_EKCII") == 1 =# +#= column, attdsc = ekcii("TEST_TABLE_EKCII", 0, 30) =# +#= kclear() =# +#= @test column == "C1" =# +#= @test attdsc.cclass == 1 =# +#= @test attdsc.dtype == 2 =# +#= @test attdsc.size == 1 =# +#= @test attdsc.strlen == 1 =# +#= @test not attdsc.indexd =# +#= @test attdsc.nullok # this used to be false, although clearly it should be true given the call to ekbseg =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= @test not exists(ekpath) =# +#= =# +#= =# +#= @testset "ekcls" begin =# +#= kclear() # same as ekopn test =# +#= ekpath = os.path.join(cwd, "example_ekcls.ek") =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= handle = ekopn(ekpath, ekpath, 80) =# +#= ekcls(handle) =# +#= @test exists(ekpath) =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= kclear() =# +#= =# +#= =# +#= @testset "ekdelr" begin =# +#= kclear() =# +#= ekpath = os.path.join(cwd, "example_ekdelr.ek") =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= handle = ekopn(ekpath, ekpath, 0) =# +#= segno, rcptrs = ekifld(handle, "test_table_ekdelr", 1, 10, 200, ["c1"], 200, =# +#= ["DATATYPE = INTEGER, NULLS_OK = TRUE"]) =# +#= ekacli(handle, segno, "c1", [1, 2], [1], [False, False], rcptrs, [1]) =# +#= ekffld(handle, segno, rcptrs) =# +#= ekdelr(handle, segno, 2) =# +#= ekcls(handle) =# +#= kclear() =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= @test not exists(ekpath) =# +#= =# +#= =# +#= @testset "ekdelr_stress" begin =# +#= for i in range(10): =# +#= test_ekdelr() =# +#= =# +#= =# +#= @testset "ekffld" begin =# +#= # same as test_ekacli =# +#= kclear() =# +#= ekpath = os.path.join(cwd, "example_ekffld.ek") =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= handle = ekopn(ekpath, ekpath, 0) =# +#= segno, rcptrs = ekifld(handle, "test_table_ekffld", 1, 10, 200, ["c1"], 200, =# +#= ["DATATYPE = INTEGER, NULLS_OK = TRUE"]) =# +#= ekacli(handle, segno, "c1", [1, 2], [1], [False, False], rcptrs, [1]) =# +#= ekffld(handle, segno, rcptrs) =# +#= ekcls(handle) =# +#= kclear() =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= @test not exists(ekpath) =# +#= =# +#= =# +#= @testset "ekffld_stress" begin =# +#= for i in range(10): =# +#= test_ekffld() =# +#= =# +#= =# +#= @testset "ekfind" begin =# +#= kclear() =# +#= ekpath = os.path.join(cwd, "example_ekfind.ek") =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= handle = ekopn(ekpath, ekpath, 0) =# +#= segno, rcptrs = ekifld(handle, "test_table_ekfind", 1, 2, 200, ["cc1"], 200, =# +#= ["DATATYPE = INTEGER, NULLS_OK = TRUE"]) =# +#= ekacli(handle, segno, "cc1", [1, 2], [1, 1], [False, False], rcptrs, [0, 0]) =# +#= ekffld(handle, segno, rcptrs) =# +#= ekcls(handle) =# +#= kclear() =# +#= furnsh(ekpath) =# +#= nmrows, error, errmsg = ekfind("SELECT CC1 FROM TEST_TABLE_EKFIND WHERE CC1 > 0", 100) =# +#= @test nmrows != 0 # should be 2 but I am not concerned about correctness in this case =# +#= @test not error =# +#= kclear() =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= @test not exists(ekpath) =# +#= =# +#= =# +#= @testset "ekfind_stess" begin =# +#= for i in range(10): =# +#= test_ekfind() =# +#= =# +#= =# +#= @testset "ekgc" begin =# +#= kclear() =# +#= ekpath = os.path.join(cwd, "example_ekgc.ek") =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= handle = ekopn(ekpath, ekpath, 0) =# +#= segno, rcptrs = ekifld(handle, "test_table_ekgc", 1, 2, 200, ["c1"], 200, =# +#= ["DATATYPE = CHARACTER*(*), INDEXED = TRUE"]) =# +#= ekaclc(handle, segno, "c1", 10, ["1.0", "2.0"], [4, 4], [False, False], rcptrs, [0, 0]) =# +#= ekffld(handle, segno, rcptrs) =# +#= ekcls(handle) =# +#= kclear() =# +#= furnsh(ekpath) =# +#= nmrows, error, errmsg = ekfind("SELECT C1 FROM TEST_TABLE_EKGC", 100) =# +#= @test not error =# +#= c, null = ekgc(0, 0, 0, 4) =# +#= @test not null =# +#= @test c == "1.0" =# +#= c, null = ekgc(0, 1, 0, 4) =# +#= @test not null =# +#= # @test c == "2.0" this fails, c is an empty string despite found being true. =# +#= kclear() =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= @test not exists(ekpath) =# +#= =# +#= =# +#= @testset "ekgd" begin =# +#= kclear() =# +#= ekpath = os.path.join(cwd, "example_ekgd.ek") =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= handle = ekopn(ekpath, ekpath, 0) =# +#= segno, rcptrs = ekifld(handle, "test_table_ekgd", 1, 2, 200, ["c1"], 200, =# +#= ["DATATYPE = DOUBLE PRECISION, NULLS_OK = TRUE"]) =# +#= ekacld(handle, segno, "c1", [1.0, 2.0], [1, 1], [False, False], rcptrs, [0, 0]) =# +#= ekffld(handle, segno, rcptrs) =# +#= ekcls(handle) =# +#= kclear() =# +#= furnsh(ekpath) =# +#= nmrows, error, errmsg = ekfind("SELECT C1 FROM TEST_TABLE_EKGD", 100) =# +#= @test not error =# +#= d, null = ekgd(0, 0, 0) =# +#= @test not null =# +#= @test d == 1.0 =# +#= d, null = ekgd(0, 1, 0) =# +#= @test not null =# +#= @test d == 2.0 =# +#= kclear() =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= @test not exists(ekpath) =# +#= =# +#= =# +#= @testset "ekgi" begin =# +#= kclear() =# +#= ekpath = os.path.join(cwd, "example_ekgi.ek") =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= handle = ekopn(ekpath, ekpath, 0) =# +#= segno, rcptrs = ekifld(handle, "test_table_ekgi", 1, 2, 200, ["c1"], 200, =# +#= ["DATATYPE = INTEGER, NULLS_OK = FALSE"]) =# +#= ekacli(handle, segno, "c1", [1, 2], [1, 1], [False, False], rcptrs, [0, 0]) =# +#= ekffld(handle, segno, rcptrs) =# +#= ekcls(handle) =# +#= kclear() =# +#= furnsh(ekpath) =# +#= nmrows, error, errmsg = ekfind("SELECT C1 FROM TEST_TABLE_EKGI", 100) =# +#= @test not error =# +#= i, null = ekgi(0, 0, 0) =# +#= @test not null =# +#= @test i == 1 =# +#= i, null = ekgi(0, 1, 0) =# +#= @test not null =# +#= @test i == 2 =# +#= kclear() =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= @test not exists(ekpath) =# +#= =# +#= =# +#= @testset "ekifld" begin =# +#= # Same as test_ekacli =# +#= kclear() =# +#= ekpath = os.path.join(cwd, "example_ekifld.ek") =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= handle = ekopn(ekpath, ekpath, 0) =# +#= segno, rcptrs = ekifld(handle, "test_table_ekifld", 1, 2, 200, ["c1"], 200, =# +#= ["DATATYPE = INTEGER, NULLS_OK = TRUE"]) =# +#= ekacli(handle, segno, "c1", [1, 2], [1, 1], [False, False], rcptrs, [0, 0]) =# +#= ekffld(handle, segno, rcptrs) =# +#= ekcls(handle) =# +#= kclear() =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= @test not exists(ekpath) =# +#= =# +#= =# +#= @testset "eklef" begin =# +#= kclear() =# +#= ekpath = os.path.join(cwd, "example_eklef.ek") =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= handle = ekopn(ekpath, ekpath, 0) =# +#= segno = ekbseg(handle, "test_table_eklef", ["c1"], ["DATATYPE = INTEGER, NULLS_OK = TRUE"]) =# +#= recno = ekappr(handle, segno) =# +#= ekacei(handle, segno, recno, "c1", 2, [1, 2], False) =# +#= ekcls(handle) =# +#= kclear() =# +#= handle = eklef(ekpath) =# +#= @test handle is not None =# +#= ekuef(handle) =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= =# +#= =# +#= @testset "eknseg" begin =# +#= kclear() =# +#= ekpath = os.path.join(cwd, "example_eknseg.ek") =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= handle = ekopn(ekpath, ekpath, 0) =# +#= segno = ekbseg(handle, "TEST_TABLE_EKNSEG", ["c1"], ["DATATYPE = INTEGER, NULLS_OK = TRUE"]) =# +#= recno = ekappr(handle, segno) =# +#= ekacei(handle, segno, recno, "c1", 2, [1, 2], False) =# +#= ekcls(handle) =# +#= kclear() =# +#= handle = ekopr(ekpath) =# +#= @test eknseg(handle) == 1 =# +#= ekcls(handle) =# +#= kclear() =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= @test not exists(ekpath) =# +#= =# +#= =# +#= @testset "ekntab" begin =# +#= @test ekntab() == 0 =# +#= =# +#= =# +#= @testset "ekopn" begin =# +#= kclear() =# +#= ekpath = os.path.join(cwd, "example_ek.ek") =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= handle = ekopn(ekpath, ekpath, 80) =# +#= ekcls(handle) =# +#= kclear() =# +#= @test exists(ekpath) =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= =# +#= =# +#= @testset "ekopr" begin =# +#= kclear() =# +#= ekpath = os.path.join(cwd, "example_ekopr.ek") =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= handle = ekopn(ekpath, ekpath, 80) =# +#= ekcls(handle) =# +#= @test exists(ekpath) =# +#= testhandle = ekopr(ekpath) =# +#= @test testhandle is not None =# +#= ekcls(testhandle) =# +#= kclear() =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= =# +#= =# +#= @testset "ekops" begin =# +#= kclear() =# +#= handle = ekops() =# +#= @test handle is not None =# +#= ekcls(handle) =# +#= kclear() =# +#= =# +#= =# +#= @testset "ekopw" begin =# +#= kclear() =# +#= ekpath = os.path.join(cwd, "example_ekopw.ek") =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= handle = ekopn(ekpath, ekpath, 80) =# +#= ekcls(handle) =# +#= @test exists(ekpath) =# +#= testhandle = ekopw(ekpath) =# +#= @test testhandle is not None =# +#= ekcls(testhandle) =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= kclear() =# +#= =# +#= =# +#= @testset "ekssum" begin =# +#= kclear() =# +#= ekpath = os.path.join(cwd, "example_ekssum.ek") =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= handle = ekopn(ekpath, ekpath, 0) =# +#= segno, rcptrs = ekifld(handle, "test_table_ekssum", 1, 2, 200, ["c1"], 200, =# +#= ["DATATYPE = INTEGER, NULLS_OK = TRUE"]) =# +#= ekacli(handle, segno, "c1", [1, 2], [1, 1], [False, False], rcptrs, [0, 0]) =# +#= ekffld(handle, segno, rcptrs) =# +#= segsum = ekssum(handle, segno) =# +#= @test segsum.ncols == 1 =# +#= @test segsum.nrows == 2 =# +#= @test segsum.cnames == ["C1"] =# +#= @test segsum.tabnam == "TEST_TABLE_EKSSUM" =# +#= c1descr = segsum.cdescrs[0] =# +#= @test c1descr.dtype == 2 =# +#= @test c1descr.indexd is False =# +#= # @test c1descr.null == True, for some reason this is actually false, SpikeEKAttDsc may not be working correctly =# +#= ekcls(handle) =# +#= kclear() =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= @test not exists(ekpath) =# +#= =# +#= =# +#= @testset "ektnam" begin =# +#= kclear() =# +#= ekpath = os.path.join(cwd, "example_ektnam.ek") =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= handle = ekopn(ekpath, ekpath, 0) =# +#= segno = ekbseg(handle, "TEST_TABLE_EKTNAM", ["c1"], ["DATATYPE = INTEGER, NULLS_OK = TRUE"]) =# +#= recno = ekappr(handle, segno) =# +#= ekacei(handle, segno, recno, "c1", 2, [1, 2], False) =# +#= ekcls(handle) =# +#= kclear() =# +#= furnsh(ekpath) =# +#= @test ekntab() == 1 =# +#= @test ektnam(0, 100) == "TEST_TABLE_EKTNAM" =# +#= @test ekccnt("TEST_TABLE_EKTNAM") == 1 =# +#= kclear() =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= @test not exists(ekpath) =# +#= =# +#= =# +#= @testset "ekucec" begin =# +#= @test 1 =# +#= =# +#= =# +#= @testset "ekuced" begin =# +#= @test 1 =# +#= =# +#= =# +#= @testset "ekucei" begin =# +#= @test 1 =# +#= =# +#= =# +#= @testset "ekuef" begin =# +#= kclear() =# +#= ekpath = os.path.join(cwd, "example_ekuef.ek") =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= handle = ekopn(ekpath, ekpath, 80) =# +#= ekcls(handle) =# +#= kclear() =# +#= @test exists(ekpath) =# +#= testhandle = ekopr(ekpath) =# +#= @test testhandle is not None =# +#= ekuef(testhandle) =# +#= ekcls(testhandle) =# +#= kclear() =# +#= if exists(ekpath): =# +#= os.remove(ekpath) # pragma: no cover =# +#= =# +#= =# +#= @testset "el2cgv" begin =# +#= vec1 = [1.0, 1.0, 1.0] =# +#= vec2 = [1.0, -1.0, 1.0] =# +#= center = [1.0, 1.0, 1.0] =# +#= smajor, sminor = saelgv(vec1, vec2) =# +#= ellipse = cgv2el(center, smajor, sminor) =# +#= outCenter, outSmajor, outSminor = el2cgv(ellipse) =# +#= expectedCenter = [1.0, 1.0, 1.0] =# +#= expectedSmajor = [sqrt(2.0), 0.0, sqrt(2.0)] =# +#= expectedSminor = [0.0, sqrt(2.0), 0.0] =# +#= npt.@test_array_almost_equal(outCenter, expectedCenter) =# +#= npt.@test_array_almost_equal(outSmajor, expectedSmajor) =# +#= npt.@test_array_almost_equal(outSminor, expectedSminor) =# +#= =# +#= =# +#= @testset "elemc" begin =# +#= testCellOne = cell_char(10, 10) =# +#= insrtc("one", testCellOne) =# +#= insrtc("two", testCellOne) =# +#= insrtc("three", testCellOne) =# +#= @test elemc("one", testCellOne) =# +#= @test elemc("two", testCellOne) =# +#= @test elemc("three", testCellOne) =# +#= @test not elemc("not", testCellOne) =# +#= @test not elemc("there", testCellOne) =# +#= =# +#= =# +#= @testset "elemd" begin =# +#= testCellOne = cell_double(8) =# +#= insrtd(1.0, testCellOne) =# +#= insrtd(2.0, testCellOne) =# +#= insrtd(3.0, testCellOne) =# +#= @test elemd(1.0, testCellOne) =# +#= @test elemd(2.0, testCellOne) =# +#= @test elemd(3.0, testCellOne) =# +#= @test not elemd(4.0, testCellOne) =# +#= @test not elemd(-1.0, testCellOne) =# +#= =# +#= =# +#= @testset "elemi" begin =# +#= testCellOne = cell_int(8) =# +#= insrti(1, testCellOne) =# +#= insrti(2, testCellOne) =# +#= insrti(3, testCellOne) =# +#= @test elemi(1, testCellOne) =# +#= @test elemi(2, testCellOne) =# +#= @test elemi(3, testCellOne) =# +#= @test not elemi(4, testCellOne) =# +#= @test not elemi(-1, testCellOne) =# +#= =# +#= =# +#= @testset "eqncpv" begin =# +#= p = 10000.0 =# +#= gm = 398600.436 =# +#= ecc = 0.1 =# +#= a = p / (1.0 - ecc) =# +#= n = sqrt(gm / a) / a =# +#= argp = 30. * rpd() =# +#= node = 15. * rpd() =# +#= inc = 10. * rpd() =# +#= m0 = 45. * rpd() =# +#= t0 = -100000000.0 =# +#= eqel = [a, ecc * sin(argp + node), ecc * cos(argp + node), m0 + argp + node, =# +#= tan(inc / 2.0) * sin(node), tan(inc / 2.0) * cos(node), 0.0, n, 0.0] =# +#= state = eqncpv(t0 - 9750.0, t0, eqel, halfpi() * -1, halfpi()) =# +#= expected = [-10732.167433285387, 3902.505790600528, 1154.4516152766892, =# +#= -2.540766899262123, -5.15226920298345, -0.7615758062877463] =# +#= npt.@test_array_almost_equal(expected, state, decimal=5) =# +#= =# +#= =# +#= @testset "eqstr" begin =# +#= @test eqstr("A short string ", "ashortstring") =# +#= @test eqstr("Embedded blanks", "Em be dd ed bl an ks") =# +#= @test eqstr("One word left out", "WORD LEFT OUT") is False =# +#= =# +#= =# +#= @testset "erract" begin =# +#= @test erract("GET", 10, "") == "RETURN" =# +#= @test erract("GET", 10) == "RETURN" =# +#= =# +#= =# +#= @testset "errch" begin =# +#= setmsg("test errch value: #") =# +#= errch("#", "some error") =# +#= sigerr("some error") =# +#= message = getmsg("LONG", 2000) =# +#= @test message == "test errch value: some error" =# +#= reset() =# +#= =# +#= =# +#= @testset "errdev" begin =# +#= @test errdev("GET", 10, "Screen") == "NULL" =# +#= =# +#= =# +#= @testset "errdp" begin =# +#= setmsg("test errdp value: #") =# +#= errdp("#", 42.1) =# +#= sigerr("some error") =# +#= message = getmsg("LONG", 2000) =# +#= @test message == "test errdp value: 4.2100000000000E+01" =# +#= reset() =# +#= =# +#= =# +#= @testset "errint" begin =# +#= setmsg("test errint value: #") =# +#= errint("#", 42) =# +#= sigerr("some error") =# +#= message = getmsg("LONG", 2000) =# +#= @test message == "test errint value: 42" =# +#= reset() =# +#= =# +#= =# +#= @testset "errprt" begin =# +#= @test errprt("GET", 40, "ALL") == "NULL" =# +#= =# +#= =# +#= @testset "esrchc" begin =# +#= array = ["This", "is", "a", "test"] =# +#= @test esrchc("This", array) == 0 =# +#= @test esrchc("is", array) == 1 =# +#= @test esrchc("a", array) == 2 =# +#= @test esrchc("test", array) == 3 =# +#= @test esrchc("fail", array) == -1 =# +#= =# +#= =# +#= @testset "et2lst" begin =# +#= kclear() =# +#= furnsh(CoreKernels.testMetaKernel) =# +#= et = str2et("2004 may 17 16:30:00") =# +#= hr, mn, sc, time, ampm = et2lst(et, 399, 281.49521300000004 * rpd(), "planetocentric", 51, 51) =# +#= @test hr == 11 =# +#= @test mn == 19 =# +#= @test sc == 22 =# +#= @test time == "11:19:22" =# +#= @test ampm == '11:19:22 A.M.' =# +#= kclear() =# +#= =# +#= =# + @testset "et2utc" begin + try + furnsh(path(CORE, :lsk)) + et = -527644192.5403653 + output = et2utc(et, :J, 6) + @test output == "JD 2445438.006415" + @test_throws SpiceError et2utc(et, :NORBERT, 6) + finally + kclear() + end + end + @testset "etcal" begin + et = 0.0 + cal = etcal(et) + @test cal == "2000 JAN 01 12:00:00.000" + end + @testset "eul2m" begin + act = eul2m(3, 2, 1, 3, 2, 1) + @test size(act) == (3, 3) + exp = [0.411982245665683 -0.6812427202564033 0.6051272472413688; + 0.05872664492762098 -0.642872836134547 -0.7637183366502791; + 0.9092974268256817 0.35017548837401463 -0.2248450953661529] + @testset for i in eachindex(act, exp) + @test act[i] ≈ exp[i] + end + end +#= @testset "eul2xf" begin =# +#= kclear() =# +#= furnsh(CoreKernels.testMetaKernel) =# +#= et = str2et("Jan 1, 2009") =# +#= expected = sxform('IAU_EARTH', 'J2000', et) =# +#= eul = [1.571803284049681, 0.0008750002978301174, 2.9555269829740034, =# +#= 3.5458495690569166e-12, 3.080552365717176e-12, -7.292115373266558e-05] =# +#= out = eul2xf(eul, 3, 1, 3) =# +#= npt.@test_array_almost_equal(out, expected) =# +#= kclear() =# +#= =# +#= =# +#= @testset "exists" begin =# +#= @test exists(CoreKernels.testMetaKernel) =# +#= =# +#= =# +#= @testset "expool" begin =# +#= kclear() =# +#= textbuf = ['DELTET/K = 1.657D-3', 'DELTET/EB = 1.671D-2'] =# +#= lmpool(textbuf) =# +#= @test expool('DELTET/K') =# +#= @test expool('DELTET/EB') =# +#= kclear() =# +#= =# +#= =# +#= @testset "expoolstress" begin =# +#= # this is to show that the bug in lmpool is fixed (lenvals needs +=1) =# +#= for i in range(500): =# +#= test_expool() =# end + diff --git a/test/i.jl b/test/i.jl index 84895f7..b009a9f 100644 --- a/test/i.jl +++ b/test/i.jl @@ -1,67 +1,97 @@ -@testset "I" begin +using LinearAlgebra: I, norm + +@testset "I" begin + @testset "ident" begin + @test SPICE._ident() == Array{Float64}(I, 3, 3) + end @testset "ilumin" begin try - furnsh( - path(CORE, :lsk), - path(CORE, :pck), - path(CORE, :spk), - ) + furnsh(path(CORE, :lsk), path(CORE, :pck), path(CORE, :spk)) et = str2et("2007 FEB 3 00:00:00.000") trgepc, obspos, trmpts = edterm("UMBRAL", "SUN", "MOON", et, "IAU_MOON", "EARTH", 3, abcorr="LT+S") expected_trgepc = 223732863.86351672 - expected_obspos = [ - 394721.1024056578753516078, - 27265.11780063395417528227, - -19069.08478859506431035697, - ] - expected_trmpts = [ - -1.53978381936825627463e+02, - -1.73056331949840728157e+03, - 1.22893325627419600088e-01, - 87.37506200891714058798, - 864.40670594653545322217, - 1504.56817899807947469526, - 42.213243378688254, - 868.21134651980412, - -1504.3223922609538, - ] + expected_obspos = [394721.1024056578753516078, + 27265.11780063395417528227, + -19069.08478859506431035697] + expected_trmpts = [-1.53978381936825627463e+02, + -1.73056331949840728157e+03, + 1.22893325627419600088e-01, + 87.37506200891714058798, + 864.40670594653545322217, + 1504.56817899807947469526, + 42.213243378688254, + 868.21134651980412, + -1504.3223922609538] @test trgepc ≈ expected_trgepc @test obspos ≈ expected_obspos for i in eachindex(trmpts, expected_trmpts) @test trmpts[i] ≈ expected_trmpts[i] end iluet0, srfvec0, phase0, solar0, emissn0 = ilumin("Ellipsoid", "MOON", et, "IAU_MOON", - "EARTH", trmpts[:,1], abcorr="LT+S") + "EARTH", trmpts[:,1], abcorr="LT+S") @test rad2deg(solar0) ≈ 90.269765819 iluet1, srfvec1, phase1, solar1, emissn1 = ilumin("Ellipsoid", "MOON", et, "IAU_MOON", - "EARTH", trmpts[:,2], abcorr="LT+S") + "EARTH", trmpts[:,2], abcorr="LT+S") @test rad2deg(solar1) ≈ 90.269765706 iluet2, srfvec2, phase2, solar2, emissn2 = ilumin("Ellipsoid", "MOON", et, "IAU_MOON", - "EARTH", trmpts[:,3], abcorr="LT+S") + "EARTH", trmpts[:,3], abcorr="LT+S") @test rad2deg(solar2) ≈ 90.269765730 finally kclear() end end - + @testset "illumf" begin + try + furnsh(path(CORE, :lsk), + path(CORE, :pck), + path(CORE, :spk), + path(CASSINI, :pck), + path(CASSINI, :sat_spk), + path(CASSINI, :tour_spk), + path(CASSINI, :fk), + path(CASSINI, :ck), + path(CASSINI, :sclk), + path(CASSINI, :ik)) + et = str2et("2013 FEB 25 11:50:00 UTC") + camid = bodn2c("CASSINI_ISS_NAC") + shape, obsref, bsight, bounds = getfov(camid, 4) + # run sincpt on boresight vector + spoint, etemit, srfvec = sincpt("ELLIPSOID", "ENCELADUS", et, "IAU_ENCELADUS", "CN+S", + "CASSINI", obsref, bsight) + trgepc2, srfvec2, phase, incid, emissn, visible, lit = illumf("ELLIPSOID", "ENCELADUS", + "SUN", et, "IAU_ENCELADUS", + "CN+S", "CASSINI", spoint) + @test rad2deg(phase) ≈ 161.82854377660345 + @test rad2deg(incid) ≈ 134.92108561449996 + @test rad2deg(emissn) ≈ 63.23618556218115 + @test !lit # Incidence angle is greater than 90deg + @test visible # Emission angle is less than 90deg + @test_throws SpiceError illumf("ELLIPSOID", "norbert", "SUN", et, "IAU_ENCELADUS", "CN+S", + "CASSINI", spoint) + @test_throws ArgumentError illumf("ELLIPSOID", "ENCELADUS", "SUN", et, "IAU_ENCELADUS", "CN+S", + "CASSINI", spoint[1:2]) + finally + kclear() + end + end @testset "illumg" begin try - furnsh( - path(CORE, :lsk), - path(CORE, :pck), - path(CORE, :spk), - path(CASSINI, :pck), - path(CASSINI, :sat_spk), - path(CASSINI, :tour_spk), - path(CASSINI, :fk), - path(CASSINI, :ck), - path(CASSINI, :sclk), - path(CASSINI, :ik) - ) + furnsh(path(CORE, :lsk), + path(CORE, :pck), + path(CORE, :spk), + path(CASSINI, :pck), + path(CASSINI, :sat_spk), + path(CASSINI, :tour_spk), + path(CASSINI, :fk), + path(CASSINI, :ck), + path(CASSINI, :sclk), + 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") - trgepc2, srfvec2, phase, incid, emissn = illumg("Ellipsoid", "Enceladus", "Sun", et, "IAU_ENCELADUS", "CASSINI", spoint, abcorr="CN+S") - + spoint, trgepc, srfvec = subpnt("NEAR POINT/ELLIPSOID", "ENCELADUS", et, "IAU_ENCELADUS", + "EARTH", abcorr="CN+S") + trgepc2, srfvec2, phase, incid, emissn = illumg("ELLIPSOID", "ENCELADUS", "SUN", et, + "IAU_ENCELADUS", "CASSINI", spoint, abcorr="CN+S") + @test rad2deg(phase) ≈ 161.859925246638 @test rad2deg(incid) ≈ 18.47670084384343 @test rad2deg(emissn) ≈ 143.6546170649875 @@ -69,5 +99,180 @@ kclear() end end -end + @testset "inedpl" begin + try + furnsh(path(CORE, :lsk), path(CORE, :pck), path(CORE, :spk)) + time = "Oct 31 2002, 12:55:00 PST" + et = str2et(time) + state, ltime = spkezr("EARTH", et, "J2000", "SUN", abcorr="LT+S") + pos = state[1:3] + radii = bodvrd("EARTH", "RADII", 3) + pos = [pos[1] / radii[1]^2.0, + pos[2] / radii[2]^2.0, + pos[3] / radii[3]^2.0] + plane = nvc2pl(pos, 1.0) + term = inedpl(radii[1], radii[2], radii[3], plane) + expected_center = [0.21512031, 0.15544527, 0.067391641] + expected_smajor = [-3.73561164720596843836e+03, 5.16970328302375583007e+03, + 1.35988201424391742850e-11] + expected_sminor = [-1276.33357469839393161237, -922.27470443423590040766, + 6159.97371233560443215538] + @test center(term) ≈ expected_center atol=1e-6 + @test semi_major(term) ≈ expected_smajor + @test semi_minor(term) ≈ expected_sminor + @test norm(semi_major(term)) ≈ 6378.1365 rtol=1e-4 + @test norm(semi_minor(term)) ≈ 6358.0558 rtol=1e-4 + @test_throws SpiceError inedpl(-radii[1], radii[2], radii[3], plane) + finally + kclear() + end + end + @testset "inelpl" begin + try + furnsh(path(CORE, :pck)) + radii = bodvrd("SATURN", "RADII", 3) + vertex = [100.0 * radii[1], 0.0, radii[1] * 100.0] + limb = edlimb(radii..., vertex) + normal = [0.0, 0.0, 1.0] + point = [0.0, 0.0, 0.0] + plane = nvp2pl(normal, point) + nxpts, xpt1, xpt2 = inelpl(limb, plane) + expected_xpt1 = [602.68000, 60264.9865, 0.0] + expected_xpt2 = [602.68000, -60264.9865, 0.0] + @test nxpts == 2.0 + @test expected_xpt1 ≈ xpt1 + @test expected_xpt2 ≈ xpt2 + finally + kclear() + end + end + @testset "inrypl" begin + try + furnsh(path(CORE, :pck)) + radii = bodvrd("SATURN", "RADII", 3) + vertex = [3.0 * radii[1], 0.0, radii[3] * 0.5] + dire = [0.0, cos(deg2rad(30.0)), -1.0 * sin(deg2rad(30.0))] + normal = [0.0, 0.0, 1.0] + point = [0.0, 0.0, 0.0] + plane = nvp2pl(normal, point) + nxpts, xpt = inrypl(vertex, dire, plane) + expected_xpt = [180804.0, 47080.6050513, 0.0] + @test nxpts == 1 + @test xpt ≈ expected_xpt + finally + kclear() + end + end + @testset "insrtc" begin + cell = SpiceCharCell(10, 10) + clist = ["aaa", "bbb", "ccc", "bbb"] + for c in clist + insrtc!(cell, c) + end + @test collect(cell) == ["aaa", "bbb", "ccc"] + end + @testset "insrtd" begin + cell = SpiceDoubleCell(8) + dlist = [0.5, 2.0, 30.0, 0.01, 30.0] + for d in dlist + insrtd!(cell, d) + end + @test collect(cell) == [0.01, 0.5, 2.0, 30.0] + end + @testset "insrti" begin + cell = SpiceIntCell(8) + ilist = [1, 2, 30, 1, 30] + for i in ilist + insrti!(cell, i) + end + @test collect(cell) == [1, 2, 30] + end + @testset "inter" begin + i1 = SpiceIntCell(8) + i2 = SpiceIntCell(8) + insrti!(i1, 1) + insrti!(i1, 2) + insrti!(i2, 1) + insrti!(i2, 3) + out = inter(i1, i2) + @test out == [1] + + d1 = SpiceDoubleCell(8) + d2 = SpiceDoubleCell(8) + insrtd!(d1, 1.0) + insrtd!(d1, 2.0) + insrtd!(d2, 1.0) + insrtd!(d2, 3.0) + out = inter(d1, d2) + @test out == [1.0] + + c1 = SpiceCharCell(8, 8) + c2 = SpiceCharCell(8, 8) + insrtc!(c1, "1") + insrtc!(c1, "2") + insrtc!(c2, "1") + insrtc!(c2, "3") + out = inter(c1, c2) + @test out == ["1"] + end + + + #= @testset "intmax" begin =# + #= @test intmax() >= 2147483647 or intmax() >= 32768 =# + #= =# + #= =# + #= @testset "intmin" begin =# + #= @test intmin() <= -2147483648 or intmin() <= -32768 =# + #= =# + #= =# + #= @testset "invert" begin =# + #= m1 = array([[0.0, -1.0, 0.0], [0.5, 0.0, 0.0], [0.0, 0.0, 1.0]]) =# + #= expected = array([[0.0, 2.0, 0.0], [-1.0, 0.0, 0.0], [0.0, 0.0, 1.0]]) =# + #= mout = invert(m1) =# + #= @test array_equal(expected, mout) =# + #= =# + #= =# + #= @testset "invort" begin =# + #= # I think this is valid... =# + #= m = ident() =# + #= mit = invort(m) =# + #= npt.@test_array_almost_equal(m, mit) =# + #= =# + #= =# + #= @testset "isordv" begin =# + #= @test isordv([0, 1], 2) =# + #= @test isordv([0, 1, 2], 3) =# + #= @test isordv([0, 1, 2, 3], 4) =# + #= @test isordv([1, 1, 1], 3) is False =# + #= =# + #= =# + #= @testset "isrchc" begin =# + #= array = ["1", "0", "4", "2"] =# + #= @test isrchc("4", 4, 3, array) == 2 =# + #= @test isrchc("2", 4, 3, array) == 3 =# + #= @test isrchc("3", 4, 3, array) == -1 =# + #= =# + #= =# + #= @testset "isrchd" begin =# + #= array = [1.0, 0.0, 4.0, 2.0] =# + #= @test isrchd(4.0, 4, array) == 2 =# + #= @test isrchd(2.0, 4, array) == 3 =# + #= @test isrchd(3.0, 4, array) == -1 =# + #= =# + #= =# + #= @testset "isrchi" begin =# + #= array = [1, 0, 4, 2] =# + #= @test isrchi(4, 4, array) == 2 =# + #= @test isrchi(2, 4, array) == 3 =# + #= @test isrchi(3, 4, array) == -1 =# + #= =# + #= =# + #= @testset "isrot" begin =# + #= @test isrot(ident(), 0.0001, 0.0001) =# + #= =# + #= =# + #= @testset "iswhsp" begin =# + #= @test iswhsp(" ") =# + #= @test iswhsp("spice") is False =# + end