This function writes in sequential mode a type 9 segment (discrete states of the positions and velocities, Lagrange interpolation with unequal timesteps) to the SPK file associated to the ephemeris descriptor eph.

The states array must be of size record_count*6 and have the following structure :

X coord 1st record

Y coord 1st record

Z coord 1st record

dX 1st record

dY 1st record

dZ 1st record

...

...

...

...

...

...

X coord (record_count)th record

Y coord (record_count)th record

Z coord (record_count)th record

dX (record_count)th record

dY (record_count)th record

dZ (record_count)th record

The epochs array must be of size record_count and contain the epochs (in Julian date TDB) corresponding to each state vector, it has the following structure :

Epoch of the 1st record

...

Epoch of the (record_count)th record

The following example creates a new ephemeris file ephemeris.bsp with segment of type 9 for the heliocentric coordinates of Venus.

USE, INTRINSIC :: ISO_C_BINDING
use calceph
TYPE(C_PTR) :: weph
INTEGER len_timespan
REAL(8) :: jd_start, jd_end, jd
INTEGER frame, record_count, interpolation_degree, k, ret
REAL(8), dimension(600) :: pos_vel !  size = 600 = record_count * 6 components
REAL(8), dimension(100) :: epochs !  size = 100 = record_count states

len_timespan = 32 ! days
frame = 1 ! ICRF
record_count = 100
interpolation_degree = 7
jd_start = 2460000
jd_end = jd_start+record_count*len_timespan

weph = writeph_spk_create("ephemeris.bsp"//C_NULL_CHAR, "planet_2"//C_NULL_CHAR,0)
if (C_ASSOCIATED(weph)) then

     do k=0, record_count-1
          ! ... fill the array pos_vel with the positions and velocities at the date epochs[k]  ...
          ! epochs(...)  = ....
          ! pos_vel(...) = ...
     enddo
     ret = writeph_spk9_seq_write(weph, NAIFID_VENUS, NAIFID_SUN, frame, jd_start, 0.0, jd_end, 0.0,
                    len_timespan, pos_vel, epochs,  record_count, interpolation_degree, "seg_planet"//C_NULL_CHAR)

     call writeph_close(weph)
endif