Table of contents
CSPICE_SPKPVN returns, for a specified SPK segment and time, the state
(position and velocity) of the segment's target body relative to its
center of motion.
Given:
handle,
descr respectively, file handle assigned to a SPK file and
the descriptor for a segment within the file. Together
they determine the ephemeris data from which the state
of the body is to be computed.
[1,1] = size(handle); int32 = class(handle)
[5,1] = size(descr); double = class(descr)
et a scalar double precision time, in seconds past the
epoch J2000 TDB.
[1,1] = size(et); double = class(et)
the call:
[ref, state, center] = cspice_spkpvn( handle, descr, et)
returns:
ref the ID code of the reference frame relative to which the
state returned by the routine is expressed.
[1,1] = size(ref); int32 = class(ref)
state the array containing the position and velocity, at epoch
'et', for the body covered by the specified segment. 'state'
has six elements: the first three contain the body's
position; the last three contain the body's velocity. These
vectors are expressed into the specified reference frame.
Units are always km and km/sec.
[6,1] = size(state); double = class(state)
center the SPK ID code of the center of motion for the state.
[1,1] = size(center); int32 = class(center)
None.
Any numerical results shown for this example may differ between
platforms as the results depend on the SPICE kernels used as input
and the machine specific arithmetic implementation.
1) In the following example, an SPK file is searched for
a segment containing ephemeris data for the Jupiter system
barycenter at a particular epoch. Using this segment,
states of the Jupiter system barycenter relative to the
solar system barycenter are evaluated at a sequence of times.
This method of state computation minimizes the number of
segment searches required to obtain requested data, but
it bypasses the SPK subsystem's state chaining mechanism.
Use the meta-kernel shown below to load the required SPICE
kernels.
KPL/MK
File name: spkpvn_ex1.tm
This meta-kernel is intended to support operation of SPICE
example programs. The kernels shown here should not be
assumed to contain adequate or correct versions of data
required by SPICE-based user applications.
In order for an application to use this meta-kernel, the
kernels referenced here must be present in the user's
current working directory.
The names and contents of the kernels referenced
by this meta-kernel are as follows:
File name Contents
--------- --------
de421.bsp Planetary ephemeris
naif0010.tls Leapseconds
\begindata
KERNELS_TO_LOAD = ( 'de421.bsp',
'naif0010.tls' )
\begintext
End of meta-kernel
Example code begins here.
function spkpvn_ex1()
%
% Local constants
%
META = 'spkpvn_ex1.tm';
ND = 2;
NI = 6;
TIMFMT = 'YYYY MON DD HR:MN:SC.######::TDB TDB';
%
% Load meta-kernel.
%
cspice_furnsh( META )
%
% Convert starting time to seconds past J2000 TDB.
%
timstr = '2012 APR 27 00:00:00.000 TDB';
et0 = cspice_str2et(timstr);
%
% Find a loaded segment for the Jupiter barycenter
% that covers `et0'.
%
body = 5;
[handle, descr, segid, found] = cspice_spksfs( body, et0);
if ~found
cspice_kclear
txt = sprintf( 'No SPK segment found for body %d at time %s', ...
body, timstr );
error( txt )
end
%
% Unpack the descriptor of the current segment.
%
[dc, ic] = cspice_dafus( descr, ND, NI );
frname = cspice_frmnam( ic(3) );
fprintf( 'Body = %d\n', ic(1) )
fprintf( 'Center = %d\n', ic(2) )
fprintf( 'Frame = %s\n', frname)
fprintf( 'Data type = %d\n', ic(4) )
fprintf( 'Start ET = %f\n', dc(1) )
fprintf( 'Stop ET = %f\n', dc(2) )
fprintf( 'Segment ID = %s\n\n', segid )
%
% Evaluate states at 10-second steps, starting at `et0'
% and continuing for 20 seconds.
%
for i=1:3
et = et0 + ( 10. * (i-1) );
%
% Convert `et' to a string for display.
%
outstr = cspice_timout( et, TIMFMT );
%
% Attempt to compute a state only if the segment's
% coverage interval contains `et'.
%
if ( et <= dc(2) )
%
% This segment has data at `et'. Evaluate the
% state of the target relative to its center
% of motion.
%
[ref_id, state, center] = cspice_spkpvn( handle, descr, et );
%
% Display the time and state.
%
fprintf( '\n%s\n', outstr )
fprintf( 'Position X (km): %24.17f\n', state(1) )
fprintf( 'Position Y (km): %24.17f\n', state(2) )
fprintf( 'Position Z (km): %24.17f\n', state(3) )
fprintf( 'Velocity X (km): %24.17f\n', state(4) )
fprintf( 'Velocity X (km): %24.17f\n', state(5) )
fprintf( 'Velocity X (km): %24.17f\n', state(6) )
else
cspice_kclear
txt = sprintf( 'No data found for body %d at time %s', ...
body, outstr );
error( txt )
end
end
%
% It's always good form to unload kernels after use,
% particularly in Matlab due to data persistence.
%
cspice_kclear
When this program was executed on a Mac/Intel/Octave6.x/64-bit
platform, the output was:
Body = 5
Center = 0
Frame = J2000
Data type = 2
Start ET = -3169195200.000000
Stop ET = 1696852800.000000
Segment ID = DE-0421LE-0421
2012 APR 27 00:00:00.000000 TDB
Position X (km): 464528993.98216485977172852
Position Y (km): 541513126.15685200691223145
Position Z (km): 220785135.62462940812110901
Velocity X (km): -10.38685648307654930
Velocity X (km): 7.95324700713742416
Velocity X (km): 3.66185835431306517
2012 APR 27 00:00:10.000000 TDB
Position X (km): 464528890.11359262466430664
Position Y (km): 541513205.68931341171264648
Position Z (km): 220785172.24320945143699646
Velocity X (km): -10.38685796160419272
Velocity X (km): 7.95324528430304944
Velocity X (km): 3.66185765185608103
2012 APR 27 00:00:20.000000 TDB
Position X (km): 464528786.24500560760498047
Position Y (km): 541513285.22175765037536621
Position Z (km): 220785208.86178246140480042
Velocity X (km): -10.38685944013147910
Velocity X (km): 7.95324356146845002
Velocity X (km): 3.66185694939899253
This routine finds the highest-priority segment, in any loaded
SPK file, such that the segment provides data for the specified
body and epoch.
1) If the segment type is not supported by the current
version of cspice_spkpvn, the error SPICE(SPKTYPENOTSUPP)
is signaled by a routine in the call tree of this routine.
2) If any of the input arguments, `handle', `descr' or `et', is
undefined, an error is signaled by the Matlab error handling
system.
3) If any of the input arguments, `handle', `descr' or `et', is
not of the expected type, or it does not have the expected
dimensions and size, an error is signaled by the Mice
interface.
See argument `handle'.
None.
MICE.REQ
SPK.REQ
None.
J. Diaz del Rio (ODC Space)
E.D. Wright (JPL)
-Mice Version 1.1.0, 10-AUG-2021 (EDW) (JDR)
Edited -Examples section to comply with NAIF standard.
Added -Parameters, -Exceptions, -Files, -Restrictions,
-Literature_References and -Author_and_Institution sections.
Eliminated use of "lasterror" in rethrow.
Removed reference to the function's corresponding CSPICE header from
-Required_Reading section.
-Mice Version 1.0.0, 30-OCT-2012 (EDW)
select SPK file and segment
|