Skip to content

Commit

Permalink
add in place compute methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
bgodard committed Feb 10, 2019
1 parent f3d740c commit 641d0f1
Show file tree
Hide file tree
Showing 3 changed files with 235 additions and 16 deletions.
121 changes: 115 additions & 6 deletions src/compute.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,63 @@ function compute(eph::Ephem,jd0::Float64,time::Float64,
target::Integer,center::Integer)
@_checkPointer eph.data "Ephemeris is not properly initialized!"
result = Array{Float64,1}(undef,6)
stat = unsafe_compute!(result,eph,jd0,time,target,center)
@_checkStatus stat "Unable to compute ephemeris"
return result
end

"""
unsafe_compute!(eph,jd0,time,target,center)
In place version of the compute function. Does not perform any checks!
Compute position and velocity of target with respect to center at epoch
jd0+time. This method does not support the NAIF numbering scheme.
To get the best precision for the interpolation, the time is splitted in two
floating-point numbers. The argument jd0 should be an integer and time should
be a fraction of the day. But you may call this function with time=0 and jd0,
the desired time, if you don't take care about precision.
This method does not support the NAIF body identification scheme.
Output units are:
* AU and AU/day for position and velocity
* rad and rad/day for librations
* second and unitless for time ephemeris and time ephemeris rate
# Arguments
- `result`: container for result. It is not checked if it is sufficiently large enough!
- `jd0::Float64`: jd0+time must be equal to the Julian Day for the time coordinate corresponding to the ephemeris (usually TDB or TCB)
- `time::Float64`: jd0+time must be equal to the Julian Day for the time coordinate corresponding to the ephemeris (usually TDB or TCB)
- `target::Integer`: The body or reference point whose coordinates are required.
- `center::Integer`: The origin of the coordinate system.
The possible values for target and center are :
* 1 : Mercury Barycenter
* 2 : Venus Barycenter
* 3 : Earth
* 4 : Mars Barycenter
* 5 : Jupiter Barycenter
* 6 : Saturn Barycenter
* 7 : Uranus Barycenter
* 8 : Neptune Barycenter
* 9 : Pluto Barycenter
* 10 : Moon
* 11 : Sun
* 12 : Solar Sytem barycenter
* 13 : Earth-moon barycenter
* 14 : Nutation angles
* 15 : Librations
* 16 : TT-TDB
* 17 : TCG-TCB
* asteroid number + 2000000 : asteroid
"""
function unsafe_compute!(result,eph::Ephem,jd0::Float64,time::Float64,
target::Integer,center::Integer)
stat = ccall((:calceph_compute, libcalceph), Cint,
(Ptr{Cvoid},Cdouble,Cdouble,Cint,Cint,Ref{Cdouble}),
eph.data,jd0,time,target,center,result)
@_checkStatus stat "Unable to compute ephemeris"
return result
return stat
end

"""
Expand All @@ -75,11 +127,37 @@ function compute(eph::Ephem,jd0::Float64,time::Float64,
target::Integer,center::Integer,unit::Integer)
@_checkPointer eph.data "Ephemeris is not properly initialized!"
result = Array{Float64,1}(undef,6)
stat = unsafe_compute!(result,eph,jd0,time,target,center,unit)
@_checkStatus stat "Unable to compute ephemeris"
return result
end

"""
unsafe_compute!(result,eph,jd0,time,target,center,unit)
In place version of the compute function. Does not perform any checks!
Compute position and velocity of target with respect to center
at epoch jd0+time.
To get the best precision for the interpolation, the time is splitted in two
floating-point numbers. The argument jd0 should be an integer and time should
be a fraction of the day. But you may call this function with time=0 and jd0,
the desired time, if you don't take care about precision.
# Arguments
- `result`: container for result. It is not checked if it is sufficiently large enough!
- `jd0::Float64`: jd0+time must be equal to the Julian Day for the time coordinate corresponding to the ephemeris (usually TDB or TCB)
- `time::Float64`: jd0+time must be equal to the Julian Day for the time coordinate corresponding to the ephemeris (usually TDB or TCB)
- `target::Integer`: The body or reference point whose coordinates are required. The numbering system depends on the parameter unit.
- `center::Integer`: The origin of the coordinate system. The numbering system depends on the parameter unit.
- `unit::Integer` : The units of the result. This integer is a sum of some unit constants (unit*) and/or the constant useNaifId. If the unit contains useNaifId, the NAIF identification numbering system is used for the target and the center. If the unit does not contain useNaifId, the old number system is used for the target and the center.
"""
function unsafe_compute!(result,eph::Ephem,jd0::Float64,time::Float64,
target::Integer,center::Integer,unit::Integer)
stat = ccall((:calceph_compute_unit, libcalceph), Cint,
(Ptr{Cvoid},Cdouble,Cdouble,Cint,Cint,Cint,Ref{Cdouble}),
eph.data,jd0,time,target,center,unit,result)
@_checkStatus stat "Unable to compute ephemeris"
return result
return stat
end

"""
Expand Down Expand Up @@ -110,9 +188,40 @@ function compute(eph::Ephem,jd0::Float64,time::Float64,
@_checkPointer eph.data "Ephemeris is not properly initialized!"
@_checkOrder order
result = Array{Float64,1}(undef,3+3order)
stat = unsafe_compute!(result,eph,jd0,time,target,center,unit,order)
@_checkStatus stat "Unable to compute ephemeris"
return result
end

"""
unsafe_compute!(result,eph,jd0,time,target,center,unit,order)
In place version of the compute function. Does not perform any checks!
Compute position and derivatives up to order of target with respect to center
at epoch jd0+time.
To get the best precision for the interpolation, the time is splitted in two
floating-point numbers. The argument jd0 should be an integer and time should
be a fraction of the day. But you may call this function with time=0 and jd0,
the desired time, if you don't take care about precision.
# Arguments
- `result`: container for result. It is not checked if it is sufficiently large enough!
- `jd0::Float64`: jd0+time must be equal to the Julian Day for the time coordinate corresponding to the ephemeris (usually TDB or TCB)
- `time::Float64`: jd0+time must be equal to the Julian Day for the time coordinate corresponding to the ephemeris (usually TDB or TCB)
- `target::Integer`: The body or reference point whose coordinates are required. The numbering system depends on the parameter unit.
- `center::Integer`: The origin of the coordinate system. The numbering system depends on the parameter unit.
- `unit::Integer` : The units of the result. This integer is a sum of some unit constants (unit*) and/or the constant useNaifId. If the unit contains useNaifId, the NAIF identification numbering system is used for the target and the center. If the unit does not contain useNaifId, the old number system is used for the target and the center.
- `order::Integer` : The order of derivatives
* 0: only the position is computed.
* 1: only the position and velocity are computed.
* 2: only the position, velocity and acceleration are computed.
* 3: the position, velocity and acceleration and jerk are computed.
"""
function unsafe_compute!(result,eph::Ephem,jd0::Float64,time::Float64,
target::Integer,center::Integer,unit::Integer,order::Integer)
stat = ccall((:calceph_compute_order, libcalceph), Cint,
(Ptr{Cvoid},Cdouble,Cdouble,Cint,Cint,Cint,Cint,Ref{Cdouble}),
eph.data,jd0,time,target,center,unit,order,result)
@_checkStatus stat "Unable to compute ephemeris"
return result
return stat
end
67 changes: 61 additions & 6 deletions src/orient.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Compute Euler angles and first derivative for the orientation of target at
epoch jd0+time.
To get the best precision for the interpolation, the time is splitted in two
To get the best precision for the interpolation, the time is split in two
floating-point numbers. The argument jd0 should be an integer and time should
be a fraction of the day. But you may call this function with time=0 and jd0,
the desired time, if you don't take care about precision.
Expand All @@ -19,19 +19,44 @@ function orient(eph::Ephem,jd0::Float64,time::Float64,
target::Integer,unit::Integer)
@_checkPointer eph.data "Ephemeris is not properly initialized!"
result = Array{Float64,1}(undef,6)
stat = unsafe_orient!(result,eph,jd0,time,target,unit)
@_checkStatus stat "Unable to compute ephemeris"
return result
end

"""
unsafe_orient!(result,eph,jd0,time,target,unit)
In place version of the orient function. Does not perform any checks!
Compute Euler angles and first derivative for the orientation of target
at epoch jd0+time.
To get the best precision for the interpolation, the time is split in two
floating-point numbers. The argument jd0 should be an integer and time should
be a fraction of the day. But you may call this function with time=0 and jd0,
the desired time, if you don't take care about precision.
# Arguments
- `result`: container for result. It is not checked if it is sufficiently large enough!
- `jd0::Float64`: jd0+time must be equal to the Julian Day for the time coordinate corresponding to the ephemeris (usually TDB or TCB)
- `time::Float64`: jd0+time must be equal to the Julian Day for the time coordinate corresponding to the ephemeris (usually TDB or TCB)
- `target::Integer`: The body whose orientation is required. The numbering system depends on the parameter unit.
- `unit::Integer` : The units of the result. This integer is a sum of some unit constants (unit*) and/or the constant useNaifId. If the unit contains useNaifId, the NAIF identification numbering system is used for the target and the center. If the unit does not contain useNaifId, the old number system is used for the target and the center (see the list in the documentation of function compute). If the unit contains outputNutationAngles, the nutation angles are computed rather than the Euler angles.
"""
function unsafe_orient!(result,eph::Ephem,jd0::Float64,time::Float64,
target::Integer,unit::Integer)
stat = ccall((:calceph_orient_unit, libcalceph), Cint,
(Ptr{Cvoid},Cdouble,Cdouble,Cint,Cint,Ref{Cdouble}),
eph.data,jd0,time,target,unit,result)
@_checkStatus stat "Unable to compute ephemeris"
return result
return stat
end

"""
orient(eph,jd0,time,target,unit,order)
Compute Euler angles and derivatives up to order for the orientation of target
at epoch jd0+time.
To get the best precision for the interpolation, the time is splitted in two
To get the best precision for the interpolation, the time is split in two
floating-point numbers. The argument jd0 should be an integer and time should
be a fraction of the day. But you may call this function with time=0 and jd0,
the desired time, if you don't take care about precision.
Expand All @@ -53,9 +78,39 @@ function orient(eph::Ephem,jd0::Float64,time::Float64,
@_checkPointer eph.data "Ephemeris is not properly initialized!"
@_checkOrder order
result = Array{Float64,1}(undef,3+3order)
stat = unsafe_orient!(result,eph,jd0,time,target,unit,order)
@_checkStatus stat "Unable to compute ephemeris"
return result
end

"""
unsafe_orient!(result,eph,jd0,time,target,unit,order)
In place version of the orient function. Does not perform any checks!
Compute Euler angles and derivatives up to order for the orientation of target
at epoch jd0+time.
To get the best precision for the interpolation, the time is split in two
floating-point numbers. The argument jd0 should be an integer and time should
be a fraction of the day. But you may call this function with time=0 and jd0,
the desired time, if you don't take care about precision.
# Arguments
- `result`: container for result. It is not checked if it is sufficiently large enough!
- `jd0::Float64`: jd0+time must be equal to the Julian Day for the time coordinate corresponding to the ephemeris (usually TDB or TCB)
- `time::Float64`: jd0+time must be equal to the Julian Day for the time coordinate corresponding to the ephemeris (usually TDB or TCB)
- `target::Integer`: The body whose orientation is required. The numbering system depends on the parameter unit.
- `unit::Integer` : The units of the result. This integer is a sum of some unit constants (unit*) and/or the constant useNaifId. If the unit contains useNaifId, the NAIF identification numbering system is used for the target and the center. If the unit does not contain useNaifId, the old number system is used for the target and the center (see the list in the documentation of function compute). If the unit contains outputNutationAngles, the nutation angles are computed rather than the Euler angles.
- `order::Integer` : The order of derivatives
* 0: only the angles are computed.
* 1: only the angles and 1st derivatives are computed.
* 2: only the angles, the 1st derivatives and 2nd derivatives are computed.
* 3: the angles, the 1st derivatives, 2nd derivatives and 3rd derivatives are computed.
"""
function unsafe_orient!(result,eph::Ephem,jd0::Float64,time::Float64,
target::Integer,unit::Integer,order::Integer)
stat = ccall((:calceph_orient_order, libcalceph), Cint,
(Ptr{Cvoid},Cdouble,Cdouble,Cint,Cint,Cint,Ref{Cdouble}),
eph.data,jd0,time,target,unit,order,result)
@_checkStatus stat "Unable to compute ephemeris"
return result
return stat
end
63 changes: 59 additions & 4 deletions src/rotAngMom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,36 @@ function rotAngMom(eph::Ephem,jd0::Float64,time::Float64,
target::Integer,unit::Integer)
@_checkPointer eph.data "Ephemeris is not properly initialized!"
result = Array{Float64,1}(undef,6)
stat = unsafe_rotAngMom!(result,eph,jd0,time,target,unit)
@_checkStatus stat "Unable to compute ephemeris"
return result
end

"""
unsafe_rotAngMom!(result,eph,jd0,time,target,unit)
In place version of the rotAngMom function. Does not perform any checks!
Compute angular momentum due to rotation and first derivative of target at
epoch jd0+time.
To get the best precision for the interpolation, the time is splitted in two
floating-point numbers. The argument jd0 should be an integer and time should
be a fraction of the day. But you may call this function with time=0 and jd0,
the desired time, if you don't take care about precision.
# Arguments
- `result`: container for result. It is not checked if it is sufficiently large enough!
- `jd0::Float64`: jd0+time must be equal to the Julian Day for the time coordinate corresponding to the ephemeris (usually TDB or TCB)
- `time::Float64`: jd0+time must be equal to the Julian Day for the time coordinate corresponding to the ephemeris (usually TDB or TCB)
- `target::Integer`: The body whose angular momentum is required. The numbering system depends on the parameter unit.
- `unit::Integer` : The units of the result. This integer is a sum of some unit constants (unit*) and/or the constant useNaifId. If the unit contains useNaifId, the NAIF identification numbering system is used for the target and the center. If the unit does not contain useNaifId, the old number system is used for the target and the center (see the list in the documentation of function compute). The angles are expressed in radians if unit contains unitRad.
"""
function unsafe_rotAngMom!(result,eph::Ephem,jd0::Float64,time::Float64,
target::Integer,unit::Integer)
stat = ccall((:calceph_rotangmom_unit, libcalceph), Cint,
(Ptr{Cvoid},Cdouble,Cdouble,Cint,Cint,Ref{Cdouble}),
eph.data,jd0,time,target,unit,result)
@_checkStatus stat "Unable to compute ephemeris"
return result
return stat
end

"""
Expand Down Expand Up @@ -53,9 +78,39 @@ function rotAngMom(eph::Ephem,jd0::Float64,time::Float64,
@_checkPointer eph.data "Ephemeris is not properly initialized!"
@_checkOrder order
result = Array{Float64,1}(undef,3+3order)
stat = unsafe_rotAngMom!(result,eph,jd0,time,target,unit,order)
@_checkStatus stat "Unable to compute ephemeris"
return result
end

"""
unsafe_rotAngMom!(result,eph,jd0,time,target,unit,order)
In place version of the rotAngMom function. Does not perform any checks!
Compute angular momentum due to rotation and derivatives up to order of target
at epoch jd0+time.
To get the best precision for the interpolation, the time is splitted in two
floating-point numbers. The argument jd0 should be an integer and time should
be a fraction of the day. But you may call this function with time=0 and jd0,
the desired time, if you don't take care about precision.
# Arguments
- `result`: container for result. It is not checked if it is sufficiently large enough!
- `jd0::Float64`: jd0+time must be equal to the Julian Day for the time coordinate corresponding to the ephemeris (usually TDB or TCB)
- `time::Float64`: jd0+time must be equal to the Julian Day for the time coordinate corresponding to the ephemeris (usually TDB or TCB)
- `target::Integer`: The body whose angular momentum is required. The numbering system depends on the parameter unit.
- `unit::Integer` : The units of the result. This integer is a sum of some unit constants (unit*) and/or the constant useNaifId. If the unit contains useNaifId, the NAIF identification numbering system is used for the target and the center. If the unit does not contain useNaifId, the old number system is used for the target and the center (see the list in the documentation of function compute).
- `order::Integer` : The order of derivatives
* 0: only the angles are computed.
* 1: only the angles and 1st derivatives are computed.
* 2: only the angles, the 1st derivatives and 2nd derivatives are computed.
* 3: the angles, the 1st derivatives, 2nd derivatives and 3rd derivatives are computed.
"""
function unsafe_rotAngMom!(result,eph::Ephem,jd0::Float64,time::Float64,
target::Integer,unit::Integer,order::Integer)
stat = ccall((:calceph_rotangmom_order, libcalceph), Cint,
(Ptr{Cvoid},Cdouble,Cdouble,Cint,Cint,Cint,Ref{Cdouble}),
eph.data,jd0,time,target,unit,order,result)
@_checkStatus stat "Unable to compute ephemeris"
return result
return stat
end

0 comments on commit 641d0f1

Please sign in to comment.