CALCEPH - C language
  • Introduction
  • Installation
  • Library interface
  • Reading/Evaluation functions
  • Time conversion functions
  • Instrument functions
  • Error functions
  • Miscellaneous functions
  • Writing functions
    • Thread notes
    • Usage
    • SPK Functions
      • writeph_spk_create
        • writeph_spk_create()
      • writeph_spk_open
        • writeph_spk_open()
      • writeph_close
        • writeph_close()
      • writeph_dump
        • writeph_dump()
      • writeph_restore
        • writeph_restore()
      • writeph_comment
        • writeph_comment()
      • writeph_spk2_seq_write
        • writeph_spk2_seq_write()
      • writeph_spk2_par_reserve
        • writeph_spk2_par_reserve()
      • writeph_spk2_par_write
        • writeph_spk2_par_write()
      • writeph_spk3_seq_write
        • writeph_spk3_seq_write()
      • writeph_spk3_par_reserve
        • writeph_spk3_par_reserve()
      • writeph_spk3_par_write
        • writeph_spk3_par_write()
      • writeph_spk8_seq_write
        • writeph_spk8_seq_write()
      • writeph_spk8_par_reserve
        • writeph_spk8_par_reserve()
      • writeph_spk8_par_write
        • writeph_spk8_par_write()
      • writeph_spk9_seq_write
        • writeph_spk9_seq_write()
      • writeph_spk9_par_reserve
        • writeph_spk9_par_reserve()
      • writeph_spk9_par_write
        • writeph_spk9_par_write()
      • writeph_spk12_seq_write
        • writeph_spk12_seq_write()
      • writeph_spk12_par_reserve
        • writeph_spk12_par_reserve()
      • writeph_spk12_par_write
        • writeph_spk12_par_write()
      • writeph_spk13_seq_write
        • writeph_spk13_seq_write()
      • writeph_spk13_par_reserve
        • writeph_spk13_par_reserve()
      • writeph_spk13_par_write
        • writeph_spk13_par_write()
      • writeph_spk14_begin
        • writeph_spk14_begin()
      • writeph_spk14_add
        • writeph_spk14_add()
      • writeph_spk14_end
        • writeph_spk14_end()
      • writeph_spk102_seq_write
        • writeph_spk102_seq_write()
      • writeph_spk102_par_reserve
        • writeph_spk102_par_reserve()
      • writeph_spk102_par_write
        • writeph_spk102_par_write()
      • writeph_spk103_seq_write
        • writeph_spk103_seq_write()
      • writeph_spk103_par_reserve
        • writeph_spk103_par_reserve()
      • writeph_spk103_par_write
        • writeph_spk103_par_write()
    • PCK Functions
  • Single file access functions
  • NAIF identification numbers
  • Frame numbers
  • Release notes
  • Reporting bugs
  • CALCEPH Library Copying conditions
CALCEPH - C language
  • Writing functions
  • writeph_spk_create

writeph_spk_create

t_writephbin *writeph_spk_create(const char *filename, const char *ifname, int flags)
Parameters:
  • filename -- pathname of the file

  • ifname -- internal filename (max 60 characters)

  • flags -- reserved for future extensions (must be zero)

Returns:

ephemeris descriptor. This value is NULL if an error occurs, otherwise non-NULL value.

This function creates for writing a new SPK file whose pathname is the string pointed to by filename, and returns an ephemeris descriptor associated to it. If a file with the same name already exists, it is overwritten.

The function writeph_close() must be called to free memory allocated by this function.

The following example creates a new ephemeris file ephemeris.bsp

t_writephbin *weph;

weph = writeph_spk_create("ephemeris.bsp","asteroid_1");
if (weph)
{

  /* ... compute and write to weph ... */
  writeph_close(weph);
}

writeph_spk_open

t_writephbin *writeph_spk_open(const char *filename)
Parameters:
  • filename -- pathname of the file

Returns:

ephemeris descriptor. This value is NULL if an error occurs, otherwise non-NULL value.

This function opens an existing SPK ephemeris file in order to append ephemeris data to it, whose pathname is the string pointed to by filename, and returns an ephemeris descriptor associated to it. If the file doesn't exist, or if it isn't a SPK file, the function fails and returns NULL. This file must be compliant to the format specified by the 'SPICE' SPK ephemeris file.

The function writeph_close() must be called to flush data to the disk and to free memory allocated by this function.

The following example appends data to the ephemeris file ephemeris.bsp

t_writephbin *weph;
const char segid[] = "seg_asteroid_1";

weph = writeph_spk_open("ephemeris.bsp");
if (weph)
{
  /*
    ...  computation and writing to weph ...
  */
  writeph_close(weph);
}

writeph_close

int writeph_close(t_writephbin *eph)
Parameters:
  • eph -- ephemeris descriptor

Returns:

0 if an error occurs, otherwise non-zero value.

This function closes the file associated to the ephemeris descriptor eph, and frees all memory allocated by the functions open/create functions. After this call, the ephemeris descriptor eph is no longer valid.

The following example creates a new ephemeris file ephemeris.bsp

t_writephbin *weph;

weph = writeph_spk_create("ephemeris.bsp","asteroid_1");
if (weph)
{

  /* ... compute and write to weph ... */
  writeph_close(weph);
}

writeph_dump

int writeph_dump(t_writephbin *eph, const char *filename)
Parameters:
  • eph -- ephemeris descriptor

  • filename -- pathname of the file

Returns:

0 if an error occurs, otherwise non-zero value.

This function dumps the content of the ephemeris descriptor eph to a binary dump file whose pathname is the string pointed to by filename. The state of the ephemeris descriptor eph can be restored from this dump file using the function writeph_restore().

This function can be called to create a checkpoint restart if the creation of the file is very long.

The following example writes a first part to the ephemeris file ephemeris.bsp and continue from a restart checkpoint.

t_writephbin *weph;

weph = writeph_spk_create("ephemeris.bsp","asteroid_1");
if (weph)
{
  /*
    ...  computation and writing to weph ...
  */
  writeph_dump(weph, "checkpoint_ephemeris_bsp.dump")
   /*
     ... compute and write to weph ...
     ... may be an interruption here ...
  */
  writeph_close(weph);
}

/* may be an interruption here */

weph = writeph_spk_open("ephemeris.bsp");
if (weph)
{
  /* restart from the checkpoint */
  writeph_restore(weph, "checkpoint_ephemeris_bsp.dump");

  /*
   ... compute and write to weph ...
  */
  writeph_close(weph);
}

writeph_restore

int writeph_restore(t_writephbin *eph, const char *filename)
Parameters:
  • eph -- ephemeris descriptor

  • filename -- pathname of the file

Returns:

0 if an error occurs, otherwise non-zero value.

This function restores the content of the ephemeris descriptor eph from a binary dump file whose pathname is the string pointed to by filename. The dump file must have been created by the function writeph_dump().

This function can be called to restart from a checkpoint restart.

The following example writes a first part to the ephemeris file ephemeris.bsp and continue from a restart checkpoint.

t_writephbin *weph;

weph = writeph_spk_create("ephemeris.bsp","asteroid_1");
if (weph)
{
  /*
    ...  computation and writing to weph ...
  */
  writeph_dump(weph, "checkpoint_ephemeris_bsp.dump")
   /*
     ... compute and write to weph ...
     ... may be an interruption here ...
  */
  writeph_close(weph);
}

/* may be an interruption here */

weph = writeph_spk_open("ephemeris.bsp");
if (weph)
{
  /* restart from the checkpoint */
  writeph_restore(weph, "checkpoint_ephemeris_bsp.dump");

  /*
   ... compute and write to weph ...
  */
  writeph_close(weph);
}

writeph_comment

int writeph_comment(t_writephbin *eph, const char *comment)
Parameters:
  • eph -- ephemeris descriptor

  • comment -- comment to be written.

Returns:

0 if an error occurs, otherwise non-zero value.

This function writes a comment to the SPK file associated to the ephemeris descriptor eph. The comment is a null-terminated string of characters pointed to by comment. This function cannot be called after writing a segment to the SPK file (i.e. after calling any of the writeph_spkN_seq_write or writeph_spkN_par_reserve functions), otherwise it will fail.

The following example adds a comment to the new ephemeris file ephemeris.bsp

t_writephbin *weph;

weph = writeph_spk_create("ephemeris.bsp","asteroid_1");
if (weph)
{
  writeph_comment(weph, "Created by ...\nDate : ....\n");

  /* ... compute and write to weph ...
  */
  writeph_close(weph);
}

writeph_spk2_seq_write

int writeph_spk2_seq_write(t_writephbin *eph, int target, int center, int frame, double start_jd0_tdb, double start_frac_tdb, double end_jd0_tdb, double end_frac_tdb, double intlen_jd_tdb, const double *polynomials, int record_count, int deg, const char *segid)
Parameters:
  • eph -- ephemeris descriptor

  • target -- The body or reference point whose coordinates will be written (see NAIF identification numbers).

  • center -- The origin of the coordinate system (see NAIF identification numbers).

  • frame -- reference frame (see Frame numbers).

  • start_jd0_tdb -- starting Julian date integer part (TDB).

  • start_frac_tdb -- starting Julian date fraction part (TDB).

  • end_jd0_tdb -- stop Julian date integer part (TDB).

  • end_frac_tdb -- stop Julian date fraction part (TDB).

  • intlen_jd_tdb -- length of the interpolation interval (in days, TDB).

  • polynomials -- array of Chebyshev polynomial coefficients.

  • record_count -- number of records to be written.

  • deg -- degree of the Chebyshev polynomials.

  • segid -- segment identifier (must be unique within the file, max 40 characters).

Returns:

0 if an error occurs, otherwise non-zero value.

This function writes, in sequential mode, a type 2 segment (Chebyshev polynomials of Chebyshev polynomials of the positions only) to the SPK file associated to the ephemeris descriptor eph.

The polynomials array must be of size record_count*(deg+1)*3 and have the following structure :

X's 1st coef 1st record

...

X's (deg + 1)th coef 1st record

Y's 1st coef 1st record

...

Y's (deg + 1)th coef 1st record

Z's 1st coef 1st record

...

Z's (deg + 1)th coef 1st record

...

...

...

...

...

...

...

...

...

X's 1st coef (record_count)th record

...

X's (deg + 1)th coef (record_count)th record

Y's 1st coef (record_count)th record

...

Y's (deg + 1)th coef (record_count)th record

Z's 1st coef (record_count)th record

...

Z's (deg + 1)th coef (record_count)th record

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

t_writephbin *weph;
const char segid[] = "seg_planet";

weph = writeph_spk_create("ephemeris.bsp","planet_2");
if (weph)
{
      int len_timespan = 32; /* days */
      int frame = 1; /* ICRF */
      int record_count = 10;
      int degree = 12;
      double jd_start = 2460000;
      double jd_end = jd_start+record_count*len_timespan;
      double coefs[390];  /*  size = 10*13*3  = record_count * (degree+1) * 3 components */

      for (int k=0; k<record_count; k++)
      {

           double jd_startk = jd_start+k*len_timespan;
           double jd_endk = jd_start+(k+1)*len_timespan;


           /* ... fill the array coefs with the coefficients of the Chebychev polynomials ...
                coefs[..] =...
           */
      }
      writeph_spk2_seq_write(weph, NAIFID_VENUS, NAIFID_SUN, frame, jd_start, 0.0, jd_end, 0.0,
                             len_timespan, coefs, record_count, degree+1, segid);


      writeph_close(weph);
}

writeph_spk2_par_reserve

int writeph_spk2_par_reserve(t_writephbin *eph, int target_count, const int *targets, int center, int frame, double start_jd0_tdb, double start_frac_tdb, double end_jd0_tdb, double end_frac_tdb, const double *intlens_jd_tdb, const int *record_counts, int deg, const char *segids[])
Parameters:
  • eph -- ephemeris descriptor

  • target_count -- number of targets the reservation is done for.

  • targets -- array of bodies or reference points whose coordinates will be written (see NAIF identification numbers).

  • center -- The origin of the coordinate system (see NAIF identification numbers).

  • frame -- reference frame (see Frame numbers).

  • start_jd0_tdb -- starting Julian date integer part (TDB).

  • start_frac_tdb -- starting Julian date fraction part (TDB).

  • end_jd0_tdb -- stop Julian date integer part (TDB).

  • end_frac_tdb -- stop Julian date fraction part (TDB).

  • intlens_jd_tdb -- array containing the interpolation interval length for each target (in days, TDB).

  • record_counts -- array of number of records for each target.

  • deg -- degree of the Chebyshev polynomials.

  • segids -- array of segment identifiers (one per target, each must be unique within the file, max 40 characters).

Returns:

return a reservation identifier on success, 0 on failure.

This function is meant to enable the parallel writing (with multiple threads) of several type 2 segments (Chebyshev polynomials of the position only) in the time scale TDB to the SPK file associated to the ephemeris descriptor eph.

It reserves space in the file for target_count segments, each segment associated to a target in the targets array. Each target has its own interpolation interval length specified in the intlens_jd_tdb array, its own number of records specified in the record_counts array, and its own segment identifier specified in the segids array. All the targets share the same center, frame, start_..._tdb, end_..._tdb and deg parameters.

The array targets, intlens_jd_tdb, record_counts and segids must be of size target_count.

The reservation id returned by this function must be used in the function writeph_spk2_par_write() to write in the corresponding reserved space. In addition, the function writeph_spk2_par_write() will require a target_index, which is the index of the target in the targets array used in this function.

A call to writeph_spk2_par_reserve is always performed by a single thread and is followed by several calls to writeph_spk2_par_write() by one or several threads.

Warning

The data covers the same timespan from the date start_jd_tdb+start_frac_tdb to end_jd_tdb+end_frac_tdb for all targets, but each target may have a different number of polynomials. The time span record_counts*intlens_jd_tdb must be equal to the timespan defined from the date start_jd_tdb+start_frac_tdb to end_jd_tdb+end_frac_tdb. If the targets doesnot have the timespan, multiple reservations must be performed before the call to writing writeph_spk2_par_write().

The following example creates a new ephemeris file ephemeris.bsp with segment of type 2 for the heliocentric coordinates of Mercury and Venus using OpenMP.

t_writephbin *weph;

weph = writeph_spk_create("ephemeris.bsp","planet_2");
if (weph)
{
      int frame = 1; /* ICRF */
      int degree = 12;
      int target_count = 2;
      int targets[2] = { NAIFID_MERCURY, NAIFID_VENUS };
      int records_count[2] = { 10, 20 };
      int len_timespan[2] = { 32, 16 };
      const char segids[2] = { "seg_mercury",  "seg_venus" };
      double jd_start = 2460000;
      double jd_end = 2460000+32*10;
      int reservation;

      reservation = writeph_spk2_seq_reserve(weph, target_count, targets, NAIFID_SUN,
                             frame, jd_start, 0.0, jd_end, 0.0,
                             len_timespan, record_counts, degree+1, segids);

      #pragma omp parallel for
      for (int body = 0; body<target_count; body++)
      {
           #pragma omp parallel for
           for (int k=0; k<records_count[body]; k++)
           {
               double coefs[39];  /*  size = 13*3  = (degree+1) * 3 components */

               double jd_startk = jd_start+k*len_timespan[body];
               double jd_endk = jd_start+(k+1)*len_timespan[body];


               /* ... fill the array coefs with the coefficients of the Chebychev polynomials ...
                   coefs[..] =...
               */
               writeph_spk2_par_write(weph, reservation, body,  k, 1,  coefs);
           }
      }


      writeph_close(weph);
}

writeph_spk2_par_write

int writeph_spk2_par_write(t_writephbin *eph, int reservation, int target_index, int record_begin_index, int record_count, const double *polynomials)
Parameters:
  • eph -- ephemeris descriptor

  • reservation -- reservation identifier.

  • target_index -- index of the target body in the reservation.

  • record_begin_index -- index of the first record to be written in the target's segment.

  • record_count -- number of records to be written.

  • polynomials -- array of Chebyshev polynomial coefficients.

Returns:

0 if an error occurs, otherwise non-zero value.

This function writes, in parallel mode, the records of a type 2 segment (Chebyshev polynomials of the position only) in the time scale TDB to the SPK file associated to the ephemeris descriptor eph.

The reservation parameter must be the reservation id returned by the function writeph_spk2_par_reserve().

The target_index parameter is the index of the target in the targets array that was passed to the function writeph_spk2_par_reserve(), starting from 0.

The record_begin_index parameter is the index of the first record to be written in the target's segment, starting from 0.

The record_count parameter is the number of records to be written starting from the record_begin_index.

The polynomials array must have the following structure :

X's 1st coef 1st record

...

X's (deg + 1)th coef 1st record

Y's 1st coef 1st record

...

Y's (deg + 1)th coef 1st record

Z's 1st coef 1st record

...

Z's (deg + 1)th coef 1st record

...

...

...

...

...

...

...

...

...

X's 1st coef (record_count)th record

...

X's (deg + 1)th coef (record_count)th record

Y's 1st coef (record_count)th record

...

Y's (deg + 1)th coef (record_count)th record

Z's 1st coef (record_count)th record

...

Z's (deg + 1)th coef (record_count)th record

With the 1st record being the record at index record_begin_index, and the (record_count)th record being the record at index record_begin_index + record_count - 1.

Multiple threads can call this function at the same time, but with different values of target_index and/or record_begin_index. The behavior is undefined if multiple threads overlap the written data : e.g., two threads write to the same target target_index and a common record number.

writeph_spk3_seq_write

int writeph_spk3_seq_write(t_writephbin *eph, int target, int center, int frame, double start_jd0_tdb, double start_frac_tdb, double end_jd0_tdb, double end_frac_tdb, double intlen_jd_tdb, const double *polynomials, int record_count, int deg, const char *segid)
Parameters:
  • eph -- ephemeris descriptor

  • target -- The body or reference point whose coordinates will be written (see NAIF identification numbers).

  • center -- The origin of the coordinate system (see NAIF identification numbers).

  • frame -- reference frame (see Frame numbers).

  • start_jd0_tdb -- starting Julian date integer part (TDB).

  • start_frac_tdb -- starting Julian date fraction part (TDB).

  • end_jd0_tdb -- stop Julian date integer part (TDB).

  • end_frac_tdb -- stop Julian date fraction part (TDB).

  • intlen_jd_tdb -- length of the interpolation interval (in days, TDB).

  • polynomials -- array of Chebyshev polynomial coefficients.

  • record_count -- number of records to be written.

  • deg -- degree of the Chebyshev polynomials.

  • segid -- segment identifier (must be unique within the file, max 40 characters).

Returns:

0 if an error occurs, otherwise non-zero value.

This function writes, in sequential, mode a type 3 segment (Chebyshev polynomials of the position and velocity) in the time scale TDB to the SPK file associated to the ephemeris descriptor eph.

The polynomials array must be of size record_count*(deg+1)*6 and have the following structure :

X's 1st coef 1st record

...

X's (deg + 1)th coef 1st record

Y's 1st coef 1st record

...

Y's (deg + 1)th coef 1st record

Z's 1st coef 1st record

...

Z's (deg + 1)th coef 1st record

dX's 1st coef 1st record

...

dX's (deg + 1)th coef 1st record

dY's 1st coef 1st record

...

dY's (deg + 1)th coef 1st record

dZ's 1st coef 1st record

...

dZ's (deg + 1)th coef 1st record

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

X's 1st coef (record_count)th record

...

X's (deg + 1)th coef (record_count)th record

Y's 1st coef (record_count)th record

...

Y's (deg + 1)th coef (record_count)th record

Z's 1st coef (record_count)th record

...

Z's (deg + 1)th coef (record_count)th record

dX's 1st coef (record_count)th record

...

dX's (deg + 1)th coef (record_count)th record

dY's 1st coef (record_count)th record

...

dY's (deg + 1)th coef (record_count)th record

dZ's 1st coef (record_count)th record

...

dZ's (deg + 1)th coef (record_count)th record

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

t_writephbin *weph;
const char segid[] = "seg_planet";

weph = writeph_spk_create("ephemeris.bsp","planet_2");
if (weph)
{
      int len_timespan = 32; /* days */
      int frame = 1; /* ICRF */
      int record_count = 10;
      int degree = 12;
      double jd_start = 2460000;
      double jd_end = jd_start+record_count*len_timespan;
      double coefs[780];  /*  size = 10*13*6  = record_count * (degree+1) * 6 components */

      for (int k=0; k<record_count; k++)
      {

           double jd_startk = jd_start+k*len_timespan;
           double jd_endk = jd_start+(k+1)*len_timespan;


           /* ... fill the array coefs with the coefficients of the Chebychev polynomials ...
                coefs[..] =...
           */
      }
      writeph_spk3_seq_write(weph, NAIFID_VENUS, NAIFID_SUN, frame, jd_start, 0.0, jd_end, 0.0,
                             len_timespan, coefs, record_count, degree+1, segid);


      writeph_close(weph);
}

writeph_spk3_par_reserve

int writeph_spk3_par_reserve(t_writephbin *eph, int target_count, const int *targets, int center, int frame, double start_jd0_tdb, double start_frac_tdb, double end_jd0_tdb, double end_frac_tdb, const double *intlens_jd_tdb, const int *record_counts, int deg, const char *segids[])
Parameters:
  • eph -- ephemeris descriptor

  • target_count -- number of targets the reservation is done for.

  • targets -- array of bodies or reference points whose coordinates will be written (see NAIF identification numbers).

  • center -- The origin of the coordinate system (see NAIF identification numbers).

  • frame -- reference frame (see Frame numbers).

  • start_jd0_tdb -- starting Julian date integer part (TDB).

  • start_frac_tdb -- starting Julian date fraction part (TDB).

  • end_jd0_tdb -- stop Julian date integer part (TDB).

  • end_frac_tdb -- stop Julian date fraction part (TDB).

  • intlens_jd_tdb -- array containing the interpolation interval length for each target (in days, TDB).

  • record_counts -- array of number of records for each target.

  • deg -- degree of the Chebyshev polynomials.

  • segids -- array of segment identifiers (one per target, each must be unique within the file, max 40 characters).

Returns:

return a reservation identifier on success, 0 on failure.

This function is meant to enable the parallel writing (with multiple threads) of several type 3 segments (Chebyshev polynomials of the position and velocity) in the time scale TDB to the SPK file associated to the ephemeris descriptor eph.

It reserves space in the file for target_count segments, each segment associated to a target in the targets array. Each target has its own interpolation interval length specified in the intlens_jd_tdb array, its own number of records specified in the record_counts array, and its own segment identifier specified in the segids array. All the targets share the same center, frame, start_..._tdb, end_..._tdb and deg parameters.

The array targets, intlens_jd_tdb, record_counts and segids must be of size target_count.

The reservation id returned by this function must be used in the function writeph_spk3_par_write() to write in the corresponding reserved space. In addition, the function writeph_spk3_par_write() will require a target_index, which is the index of the target in the targets array used in this function.

A call to writeph_spk3_par_reserve is always performed by a single thread and is followed by several calls to writeph_spk3_par_write() by one or several threads.

Warning

The data covers the same timespan from the date start_jd_tdb+start_frac_tdb to end_jd_tdb+end_frac_tdb for all targets, but each target may have a different number of polynomials. The time span record_counts*intlens_jd_tdb must be equal to the timespan defined from the date start_jd_tdb+start_frac_tdb to end_jd_tdb+end_frac_tdb. If the targets doesnot have the timespan, multiple reservations must be performed before the call to writing writeph_spk3_par_write().

The following example creates a new ephemeris file ephemeris.bsp with segment of type 3 for the heliocentric coordinates of Mercury and Venus using OpenMP.

t_writephbin *weph;

weph = writeph_spk_create("ephemeris.bsp","planet_2");
if (weph)
{
      int frame = 1; /* ICRF */
      int degree = 12;
      int target_count = 2;
      int targets[2] = { NAIFID_MERCURY, NAIFID_VENUS };
      int records_count[2] = { 10, 20 };
      int len_timespan[2] = { 32, 16 };
      const char segids[2] = { "seg_mercury",  "seg_venus" };
      double jd_start = 2460000;
      double jd_end = 2460000+32*10;
      int reservation;

      reservation = writeph_spk3_seq_reserve(weph, target_count, targets, NAIFID_SUN,
                             frame, jd_start, 0.0, jd_end, 0.0,
                             len_timespan, record_counts, degree+1, segids);

      #pragma omp parallel for
      for (int body = 0; body<target_count; body++)
      {
           #pragma omp parallel for
           for (int k=0; k<records_count[body]; k++)
           {
               double coefs[78];  /*  size = 13*6  = (degree+1) * 6 components */

               double jd_startk = jd_start+k*len_timespan[body];
               double jd_endk = jd_start+(k+1)*len_timespan[body];


               /* ... fill the array coefs with the coefficients of the Chebychev polynomials ...
                   coefs[..] =...
               */
               writeph_spk3_par_write(weph, reservation, body,  k, 1,  coefs);
           }
      }


      writeph_close(weph);
}

writeph_spk3_par_write

int writeph_spk3_par_write(t_writephbin *eph, int reservation, int target_index, int record_begin_index, int record_count, const double *polynomials)
Parameters:
  • eph -- ephemeris descriptor

  • reservation -- reservation identifier.

  • target_index -- index of the target body in the reservation.

  • record_begin_index -- index of the first record to be written in the target's segment.

  • record_count -- number of records to be written.

  • polynomials -- array of Chebyshev polynomial coefficients.

Returns:

0 if an error occurs, otherwise non-zero value.

This function writes in parallel mode records of a type 3 segment (Chebyshev polynomials of the position and velocity) in the time scale TDB to the SPK file associated to the ephemeris descriptor eph.

The reservation parameter must be the reservation id returned by the function writeph_spk3_par_reserve().

The target_index parameter is the index of the target in the targets array that was passed to the function writeph_spk3_par_reserve(), starting from 0.

The record_begin_index parameter is the index of the first record to be written in the target's segment, starting from 0.

The record_count parameter is the number of records to be written starting from the record_begin_index.

The polynomials array must be of size record_count*(deg+1)*6 and have the following structure :

X's 1st coef 1st record

...

X's (deg + 1)th coef 1st record

Y's 1st coef 1st record

...

Y's (deg + 1)th coef 1st record

Z's 1st coef 1st record

...

Z's (deg + 1)th coef 1st record

dX's 1st coef 1st record

...

dX's (deg + 1)th coef 1st record

dY's 1st coef 1st record

...

dY's (deg + 1)th coef 1st record

dZ's 1st coef 1st record

...

dZ's (deg + 1)th coef 1st record

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

X's 1st coef (record_count)th record

...

X's (deg + 1)th coef (record_count)th record

Y's 1st coef (record_count)th record

...

Y's (deg + 1)th coef (record_count)th record

Z's 1st coef (record_count)th record

...

Z's (deg + 1)th coef (record_count)th record

dX's 1st coef (record_count)th record

...

dX's (deg + 1)th coef (record_count)th record

dY's 1st coef (record_count)th record

...

dY's (deg + 1)th coef (record_count)th record

dZ's 1st coef (record_count)th record

...

dZ's (deg + 1)th coef (record_count)th record

With the 1st record being the record at index record_begin_index, and the (record_count)th record being the record at index record_begin_index + record_count - 1.

Multiple threads can call this function at the same time, but with different values of target_index and/or record_begin_index. The behavior is undefined if multiple threads overlap the written data : e.g., two threads write to the same target target_index and a common record number.

writeph_spk8_seq_write

int writeph_spk8_seq_write(t_writephbin *eph, int target, int center, int frame, double start_jd0_tdb, double start_frac_tdb, double end_jd0_tdb, double end_frac_tdb, double intlen_jd_tdb, const double *polynomials, int record_count, int deg, const char *segid)
Parameters:
  • eph -- ephemeris descriptor

  • target -- The body or reference point whose coordinates will be written (see NAIF identification numbers).

  • center -- The origin of the coordinate system (see NAIF identification numbers).

  • frame -- reference frame (see Frame numbers).

  • start_jd0_tdb -- starting Julian date integer part (TDB).

  • start_frac_tdb -- starting Julian date fraction part (TDB).

  • end_jd0_tdb -- stop Julian date integer part (TDB).

  • end_frac_tdb -- stop Julian date fraction part (TDB).

  • intlen_jd_tdb -- length of the interpolation interval (in days, TDB).

  • states -- array of state vectors.

  • record_count -- number of records to be written.

  • deg -- degree of interpolation.

  • segid -- segment identifier (must be unique within the file, max 40 characters).

Returns:

0 if an error occurs, otherwise non-zero value.

This function writes in sequential mode a type 8 segment (discrete states of the positions and velocities, Lagrange interpolation with equal timesteps) in the time scale TDB 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 following example creates a new ephemeris file ephemeris.bsp with segment of type 8 for the heliocentric coordinates of Venus.

t_writephbin *weph;
const char segid[] = "seg_planet";

weph = writeph_spk_create("ephemeris.bsp","planet_2");
if (weph)
{
      int len_timespan = 32; /* days */
      int frame = 1; /* ICRF */
      int record_count = 100;
      int interpolation_degree = 7;
      double jd_start = 2460000;
      double jd_end = jd_start+record_count*len_timespan;
      double pos_vel[600];  /*  size = 100*6  = record_count* 6 components */

      for (int k=0; k<record_count; k++)
      {
           double jd = jd_start+k*len_timespan;

           /* ... fill the array pos_vel with the positions and velocities at the date jd ...
                pos_vel[..] =...
           */
      }
      writeph_spk8_seq_write(weph, NAIFID_VENUS, NAIFID_SUN, frame, jd_start, 0.0, jd_end, 0.0,
                             len_timespan, pos_vel, record_count, interpolation_degree, segid);


      writeph_close(weph);
}

writeph_spk8_par_reserve

int writeph_spk8_par_reserve(t_writephbin *eph, int target_count, const int *targets, int center, int frame, double start_jd0_tdb, double start_frac_tdb, double end_jd0_tdb, double end_frac_tdb, const double *intlens_jd_tdb, const int *record_counts, int deg, const char *segids[])
Parameters:
  • eph -- ephemeris descriptor

  • target_count -- number of targets the reservation is done for.

  • targets -- array of bodies or reference points whose coordinates will be written (see NAIF identification numbers).

  • center -- The origin of the coordinate system (see NAIF identification numbers).

  • frame -- reference frame (see Frame numbers).

  • start_jd0_tdb -- starting Julian date integer part (TDB).

  • start_frac_tdb -- starting Julian date fraction part (TDB).

  • end_jd0_tdb -- stop Julian date integer part (TDB).

  • end_frac_tdb -- stop Julian date fraction part (TDB).

  • intlens_jd_tdb -- array containing the interpolation interval length for each target (in days, TDB).

  • record_counts -- array of number of records for each target.

  • deg -- degree of interpolation.

  • segids -- array of segment identifiers (one per target, each must be unique within the file, max 40 characters).

Returns:

return a reservation identifier on success, 0 on failure.

This function is meant to enable the parallel writing (with multiple threads) of several type 8 segments (discrete states of the positions and velocities, Lagrange interpolation with equal timesteps) in the time scale TDB to the SPK file associated to the ephemeris descriptor eph.

It reserves space in the file for target_count segments, each segment associated to a target in the targets array. Each target has its own interpolation interval length specified in the intlens_jd_tdb array, its own number of records specified in the record_counts array, and its own segment identifier specified in the segids array. All the targets share the same center, frame, start_..._tdb, end_..._tdb and deg parameters.

The array targets, intlens_jd_tdb, record_counts and segids must be of size target_count.

The reservation id returned by this function must be used in the function writeph_spk8_par_write() to write in the corresponding reserved space. In addition, the function writeph_spk8_par_write() will require a target_index, which is the index of the target in the targets array used in this function.

A call to writeph_spk8_par_reserve is always performed by a single thread and is followed by several calls to writeph_spk8_par_write() by one or several threads.

Warning

The data covers the same timespan from the date start_jd_tdb+start_frac_tdb to end_jd_tdb+end_frac_tdb for all targets, but each target may have a different number of polynomials. The time span record_counts*intlens_jd_tdb must be equal to the timespan defined from the date start_jd_tdb+start_frac_tdb to end_jd_tdb+end_frac_tdb. If the targets doesnot have the timespan, multiple reservations must be performed before the call to writing writeph_spk8_par_write().

The following example creates a new ephemeris file ephemeris.bsp with segment of type 8 for the heliocentric coordinates of Mercury and Venus using OpenMP.

t_writephbin *weph;

weph = writeph_spk_create("ephemeris.bsp","planet_2");
if (weph)
{
      int frame = 1; /* ICRF */
      int target_count = 2;
      int targets[2] = { NAIFID_MERCURY, NAIFID_VENUS };
      int records_count[2] = { 10, 20 };
      int len_timespan[2] = { 32, 16 };
      const char segids[2] = { "seg_mercury",  "seg_venus" };
      double jd_start = 2460000;
      double jd_end = 2460000+32*10;
      int reservation;
      int interpolation_degree = 7;

      reservation = writeph_spk8_seq_reserve(weph, target_count, targets, NAIFID_SUN,
                             frame, jd_start, 0.0, jd_end, 0.0,
                             len_timespan, record_counts, interpolation_degree, segids);

      #pragma omp parallel for
      for (int body = 0; body<target_count; body++)
      {
           #pragma omp parallel for
           for (int k=0; k<records_count[body]; k++)
           {
               double pos_vel[6];  /*  size = 6 components */

               double jd = jd_start+k*len_timespan;

               /* ... fill the array pos_vel with the positions and velocities at the date jd ...
                pos_vel[..] =...
               */
               writeph_spk8_par_write(weph, reservation, body,  k, 1,  pos_vel);
           }
      }


      writeph_close(weph);
}

writeph_spk8_par_write

int writeph_spk8_par_write(t_writephbin *eph, int reservation, int target_index, int record_begin_index, int record_count, const double *states)
Parameters:
  • eph -- ephemeris descriptor

  • reservation -- reservation identifier.

  • target_index -- index of the target body in the reservation.

  • record_begin_index -- index of the first record to be written in the target's segment.

  • record_count -- number of records to be written.

  • states -- array of state vectors.

Returns:

0 if an error occurs, otherwise non-zero value.

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

The reservation parameter must be the reservation id returned by the function writeph_spk8_par_reserve().

The target_index parameter is the index of the target in the targets array that was passed to the function writeph_spk8_par_reserve(), starting from 0.

The record_begin_index parameter is the index of the first record to be written in the target's segment, starting from 0.

The record_count parameter is the number of records to be written starting from the record_begin_index.

The states array must 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

With the 1st record being the record at index record_begin_index, and the (record_count)th record being the record at index record_begin_index + record_count - 1.

Multiple threads can call this function at the same time, but with different values of target_index and/or record_begin_index. The behavior is undefined if multiple threads overlap the written data : e.g., two threads write to the same target target_index and a common record number.

writeph_spk9_seq_write

int writeph_spk9_seq_write(t_writephbin *eph, int target, int center, int frame, double start_jd0_tdb, double start_frac_tdb, double end_jd0_tdb, double end_frac_tdb, const double *states, const double *epochs, int record_count, int deg, const char *segid)
Parameters:
  • eph -- ephemeris descriptor

  • target -- The body or reference point whose coordinates will be written (see NAIF identification numbers).

  • center -- The origin of the coordinate system (see NAIF identification numbers).

  • frame -- reference frame (see Frame numbers).

  • start_jd0_tdb -- starting Julian date integer part (TDB).

  • start_frac_tdb -- starting Julian date fraction part (TDB).

  • end_jd0_tdb -- stop Julian date integer part (TDB).

  • end_frac_tdb -- stop Julian date fraction part (TDB).

  • states -- array of state vectors.

  • epochs -- array of epochs (in Julian date TCB) one per state vector.

  • record_count -- number of records to be written.

  • deg -- degree of interpolation.

  • segid -- segment identifier (must be unique within the file, max 40 characters).

Returns:

0 if an error occurs, otherwise non-zero value.

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.

t_writephbin *weph;
const char segid[] = "seg_planet";

weph = writeph_spk_create("ephemeris.bsp","planet_2", 0);
if (weph)
{
      int frame = 1; /* ICRF */
      int record_count = 100;
      int interpolation_degree = 7;
      double jd_start = 2460000;
      double jd_end = jd_start+record_count*len_timespan;
      double pos_vel[600];  /*  size = 100*6  = record_count* 6 components */
      double epochs[100];  /*  size = 100  = record_count components */

      for (int k=0; k<record_count; k++)
      {


           /* ... fill the array epochs and pos_vel with the positions and velocities ...
               epochs[k]   = ...
               pos_vel[..] = ...
           */
      }
      writeph_spk9_seq_write(weph, NAIFID_VENUS, NAIFID_SUN, frame, jd_start, 0.0, jd_end, 0.0,
                             pos_vel, epochs, record_count, interpolation_degree, segid);


      writeph_close(weph);
}

writeph_spk9_par_reserve

int writeph_spk9_par_reserve(t_writephbin *eph, int target_count, const int *targets, int center, int frame, double start_jd0_tdb, double start_frac_tdb, double end_jd0_tdb, double end_frac_tdb, const int *record_counts, int deg, const char *segids[])
Parameters:
  • eph -- ephemeris descriptor

  • target_count -- number of targets the reservation is done for.

  • targets -- array of bodies or reference points whose coordinates will be written (see NAIF identification numbers).

  • center -- The origin of the coordinate system (see NAIF identification numbers).

  • frame -- reference frame (see Frame numbers).

  • start_jd0_tdb -- starting Julian date integer part (TDB).

  • start_frac_tdb -- starting Julian date fraction part (TDB).

  • end_jd0_tdb -- stop Julian date integer part (TDB).

  • end_frac_tdb -- stop Julian date fraction part (TDB).

  • record_counts -- array of number of records for each target.

  • deg -- degree of interpolation.

  • segids -- array of segment identifiers (one per target, each must be unique within the file, max 40 characters).

Returns:

return a reservation identifier on success, 0 on failure.

This function is meant to enable the parallel writing (with multiple threads) of several type 9 segments (discrete states of the positions and velocities, Lagrange interpolation with unequal timesteps) to the SPK file associated to the ephemeris descriptor eph.

It reserves space in the file for target_count segments, each segment associated to a target in the targets array. Each target has its own number of records specified in the record_counts array, and its own segment identifier specified in the segids array. All the targets share the same center, frame, start_..._tdb, end_..._tdb and deg parameters.

The array targets, record_counts and segids must be of size target_count.

The reservation id returned by this function must be used in the function writeph_spk9_par_write() to write in the corresponding reserved space. In addition, the function writeph_spk9_par_write() will require a target_index, which is the index of the target in the targets array used in this function.

A call to writeph_spk9_par_reserve is always performed by a single thread and is followed by several calls to writeph_spk9_par_write() by one or several threads.

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

t_writephbin *weph;

weph = writeph_spk_create("ephemeris.bsp","planet_2", 0);
if (weph)
{
      int frame = 1; /* ICRF */
      int target_count = 2;
      int targets[2] = { NAIFID_MERCURY, NAIFID_VENUS };
      int records_count[2] = { 10, 20 };
      int len_timespan[2] = { 32, 16 };
      const char segids[2] = { "seg_mercury",  "seg_venus" };
      double jd_start = 2460000;
      double jd_end = 2460000+32*10;
      int reservation;
      int interpolation_degree = 7;

      reservation = writeph_spk9_seq_reserve(weph, target_count, targets, NAIFID_SUN,
                             frame, jd_start, 0.0, jd_end, 0.0,
                             len_timespan, record_counts, interpolation_degree, segids);

      #pragma omp parallel for
      for (int body = 0; body<target_count; body++)
      {
           #pragma omp parallel for
           for (int k=0; k<records_count[body]; k++)
           {
               double pos_vel[6]; /*  size = 6 components */
               double epochs[1];  /*  size =  1 time */

               epochs[0] = jd_start+k*len_timespan;

               /* ... fill the array pos_vel with the positions and velocities at the date jd ...
                pos_vel[..] =...
               */
               writeph_spk9_par_write(weph, reservation, body,  k, 1,  pos_vel, epochs);
           }
      }


      writeph_close(weph);
}

writeph_spk9_par_write

int writeph_spk9_par_write(t_writephbin *eph, int reservation, int target_index, int record_begin_index, int record_count, const double *states, const double *epochs)
Parameters:
  • eph -- ephemeris descriptor

  • reservation -- reservation identifier.

  • target_index -- index of the target body in the reservation.

  • record_begin_index -- index of the first record to be written in the target's segment.

  • record_count -- number of records to be written.

  • states -- array of state vectors.

  • epochs -- array of epochs (in Julian date TCB) one per state vector.

Returns:

0 if an error occurs, otherwise non-zero value.

This function writes in parallel mode records of 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 reservation parameter must be the reservation id returned by the function writeph_spk9_par_reserve().

The target_index parameter is the index of the target in the targets array that was passed to the function writeph_spk9_par_reserve(), starting from 0.

The record_begin_index parameter is the index of the first record to be written in the target's segment, starting from 0.

The record_count parameter is the number of records to be written starting from the record_begin_index.

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

Multiple threads can call this function at the same time, but with different values of target_index and/or record_begin_index. The behavior is undefined if multiple threads overlap the written data : e.g., two threads write to the same target target_index and a common record number.

writeph_spk12_seq_write

int writeph_spk12_seq_write(t_writephbin *eph, int target, int center, int frame, double start_jd0_tdb, double start_frac_tdb, double end_jd0_tdb, double end_frac_tdb, double intlen_jd_tdb, const double *states, int record_count, int deg, const char *segid)
Parameters:
  • eph -- ephemeris descriptor

  • target -- The body or reference point whose coordinates will be written (see NAIF identification numbers).

  • center -- The origin of the coordinate system (see NAIF identification numbers).

  • frame -- reference frame (see Frame numbers).

  • start_jd0_tdb -- starting Julian date integer part (TDB).

  • start_frac_tdb -- starting Julian date fraction part (TDB).

  • end_jd0_tdb -- stop Julian date integer part (TDB).

  • end_frac_tdb -- stop Julian date fraction part (TDB).

  • intlen_jd_tdb -- length of the interpolation interval (in days, TDB).

  • states -- array of state vectors.

  • record_count -- number of records to be written.

  • deg -- degree of interpolation.

  • segid -- segment identifier (must be unique within the file, max 40 characters).

Returns:

0 if an error occurs, otherwise non-zero value.

This function writes in sequential mode a type 12 segment (discrete states of the positions and velocities, Hermite interpolation with equal 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 following example creates a new ephemeris file ephemeris.bsp with segment of type 12 for the heliocentric coordinates of Venus.

t_writephbin *weph;
const char segid[] = "seg_planet";

weph = writeph_spk_create("ephemeris.bsp","planet_2", 0);
if (weph)
{
      int len_timespan = 32; /* days */
      int frame = 1; /* ICRF */
      int record_count = 100;
      int interpolation_degree = 7;
      double jd_start = 2460000;
      double jd_end = jd_start+record_count*len_timespan;
      double pos_vel[600];  /*  size = 100*6  = record_count* 6 components */

      for (int k=0; k<record_count; k++)
      {

           double jd = jd_start+k*len_timespan;

           /* ... fill the array pos_vel with the positions and velocities at the date jd ...
                pos_vel[..] =...
           */
      }
      writeph_spk12_seq_write(weph, NAIFID_VENUS, NAIFID_SUN, frame, jd_start, 0.0, jd_end, 0.0,
                             len_timespan, pos_vel, record_count, interpolation_degree, segid);


      writeph_close(weph);
}

writeph_spk12_par_reserve

int writeph_spk12_par_reserve(t_writephbin *eph, int target_count, const int *targets, int center, int frame, double start_jd0_tdb, double start_frac_tdb, double end_jd0_tdb, double end_frac_tdb, const double *intlens_jd_tdb, const int *record_counts, int deg, const char *segids[])
Parameters:
  • eph -- ephemeris descriptor

  • target_count -- number of targets the reservation is done for.

  • targets -- array of bodies or reference points whose coordinates will be written (see NAIF identification numbers).

  • center -- The origin of the coordinate system (see NAIF identification numbers).

  • frame -- reference frame (see Frame numbers).

  • start_jd0_tdb -- starting Julian date integer part (TDB).

  • start_frac_tdb -- starting Julian date fraction part (TDB).

  • end_jd0_tdb -- stop Julian date integer part (TDB).

  • end_frac_tdb -- stop Julian date fraction part (TDB).

  • intlens_jd_tdb -- array containing the interpolation interval length for each target (in days, TDB).

  • record_counts -- array of number of records for each target.

  • deg -- degree of interpolation.

  • segids -- array of segment identifiers (one per target, each must be unique within the file, max 40 characters).

Returns:

return a reservation identifier on success, 0 on failure.

This function is meant to enable the parallel writing (with multiple threads) of several type 12 segments (discrete states of the positions and velocities, Hermite interpolation with equal timesteps) to the SPK file associated to the ephemeris descriptor eph. This function is similar to writeph_spk2_par_reserve(), except that it reserves enough space for type 12 segments (state vectors with derivatives). In the same way writeph_spk2_par_reserve() is used with writeph_spk2_par_write(), this function must be used with writeph_spk12_par_write().

It reserves space in the file for target_count segments, each segment associated to a target in the targets array. Each target has its own interpolation interval length specified in the intlens_jd_tdb array, its own number of records specified in the record_counts array, and its own segment identifier specified in the segids array. All the targets share the same center, frame, start_..._tdb, end_..._tdb and deg parameters.

The array targets, intlens_jd_tdb, record_counts and segids must be of size target_count.

The reservation id returned by this function must be used in the function writeph_spk12_par_write() to write in the corresponding reserved space. In addition, the function writeph_spk12_par_write() will require a target_index, which is the index of the target in the targets array used in this function.

A call to writeph_spk12_par_reserve is always performed by a single thread and is followed by several calls to writeph_spk12_par_write() by one or several threads.

Warning

The data covers the same timespan from the date start_jd_tdb+start_frac_tdb to end_jd_tdb+end_frac_tdb for all targets, but each target may have a different number of polynomials. The time span record_counts*intlens_jd_tdb must be equal to the timespan defined from the date start_jd_tdb+start_frac_tdb to end_jd_tdb+end_frac_tdb. If the targets doesnot have the timespan, multiple reservations must be performed before the call to writing writeph_spk12_par_write().

The following example creates a new ephemeris file ephemeris.bsp with segment of type 12 for the heliocentric coordinates of Mercury and Venus using OpenMP.

t_writephbin *weph;

weph = writeph_spk_create("ephemeris.bsp","planet_2", 0);
if (weph)
{
      int frame = 1; /* ICRF */
      int target_count = 2;
      int targets[2] = { NAIFID_MERCURY, NAIFID_VENUS };
      int records_count[2] = { 10, 20 };
      int len_timespan[2] = { 32, 16 };
      const char segids[2] = { "seg_mercury",  "seg_venus" };
      double jd_start = 2460000;
      double jd_end = 2460000+32*10;
      int reservation;
      int interpolation_degree = 7;

      reservation = writeph_spk12_seq_reserve(weph, target_count, targets, NAIFID_SUN,
                             frame, jd_start, 0.0, jd_end, 0.0,
                             len_timespan, record_counts, interpolation_degree, segids);

      #pragma omp parallel for
      for (int body = 0; body<target_count; body++)
      {
           #pragma omp parallel for
           for (int k=0; k<records_count[body]; k++)
           {
               double pos_vel[6];  /*  size = 6 components */

               double jd = jd_start+k*len_timespan;

               /* ... fill the array pos_vel with the positions and velocities at the date jd ...
                pos_vel[..] =...
               */
               writeph_spk12_par_write(weph, reservation, body,  k, 1,  pos_vel);
           }
      }


      writeph_close(weph);
}

writeph_spk12_par_write

int writeph_spk12_par_write(t_writephbin *eph, int reservation, int target_index, int record_begin_index, int record_count, const double *states)
Parameters:
  • eph -- ephemeris descriptor

  • reservation -- reservation identifier.

  • target_index -- index of the target body in the reservation.

  • record_begin_index -- index of the first record to be written in the target's segment.

  • record_count -- number of records to be written.

  • states -- array of state vectors.

Returns:

0 if an error occurs, otherwise non-zero value.

This function writes in parallel mode records of a type 12 segment (discrete states of the positions and velocities, Hermite interpolation with equal timesteps) to the SPK file associated to the ephemeris descriptor eph.

The reservation parameter must be the reservation id returned by the function writeph_spk8_par_reserve().

The target_index parameter is the index of the target in the targets array that was passed to the function writeph_spk8_par_reserve(), starting from 0.

The record_begin_index parameter is the index of the first record to be written in the target's segment, starting from 0.

The record_count parameter is the number of records to be written starting from the record_begin_index.

The states array must 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

With the 1st record being the record at index record_begin_index, and the (record_count)th record being the record at index record_begin_index + record_count - 1.

Multiple threads can call this function at the same time, but with different values of target_index and/or record_begin_index. The behavior is undefined if multiple threads overlap the written data : e.g., two threads write to the same target target_index and a common record number.

writeph_spk13_seq_write

int writeph_spk13_seq_write(t_writephbin *eph, int target, int center, int frame, double start_jd0_tdb, double start_frac_tdb, double end_jd0_tdb, double end_frac_tdb, const double *states, int record_count, int deg, const char *segid)
Parameters:
  • eph -- ephemeris descriptor

  • target -- The body or reference point whose coordinates will be written (see NAIF identification numbers).

  • center -- The origin of the coordinate system (see NAIF identification numbers).

  • frame -- reference frame (see Frame numbers).

  • start_jd0_tdb -- starting Julian date integer part (TDB).

  • start_frac_tdb -- starting Julian date fraction part (TDB).

  • end_jd0_tdb -- stop Julian date integer part (TDB).

  • end_frac_tdb -- stop Julian date fraction part (TDB).

  • states -- array of state vectors.

  • record_count -- number of records to be written.

  • deg -- degree of interpolation.

  • segid -- segment identifier (must be unique within the file, max 40 characters).

Returns:

0 if an error occurs, otherwise non-zero value.

This function writes in sequential mode a type 13 segment (discrete states of the positions and velocities, Hermite 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.

t_writephbin *weph;
const char segid[] = "seg_planet";

weph = writeph_spk_create("ephemeris.bsp","planet_2", 0);
if (weph)
{
      int frame = 1; /* ICRF */
      int record_count = 100;
      int interpolation_degree = 7;
      double jd_start = 2460000;
      double jd_end = jd_start+1000;
      double pos_vel[600];  /*  size = 100*6  = record_count* 6 components */
      double epochs[100];  /*  size = 100  = record_count components */

      for (int k=0; k<record_count; k++)
      {



           /* ... fill the array epochs and pos_vel with the positions and velocities at the date epochs[k] ...
                epochs[k] = ....
                pos_vel[..] =...
           */
      }
      writeph_spk13_seq_write(weph, NAIFID_VENUS, NAIFID_SUN, frame, jd_start, 0.0, jd_end, 0.0,
                             pos_vel, epochs, record_count, interpolation_degree, segid);


      writeph_close(weph);
}

writeph_spk13_par_reserve

int writeph_spk13_par_reserve(t_writephbin *eph, int target_count, const int *targets, int center, int frame, double start_jd0_tdb, double start_frac_tdb, double end_jd0_tdb, double end_frac_tdb, const int *record_counts, int deg, const char *segids[])
Parameters:
  • eph -- ephemeris descriptor

  • target_count -- number of targets the reservation is done for.

  • targets -- array of bodies or reference points whose coordinates will be written (see NAIF identification numbers).

  • center -- The origin of the coordinate system (see NAIF identification numbers).

  • frame -- reference frame (see Frame numbers).

  • start_jd0_tdb -- starting Julian date integer part (TDB).

  • start_frac_tdb -- starting Julian date fraction part (TDB).

  • end_jd0_tdb -- stop Julian date integer part (TDB).

  • end_frac_tdb -- stop Julian date fraction part (TDB).

  • record_counts -- array of number of records for each target.

  • deg -- degree of interpolation.

  • segids -- array of segment identifiers (one per target, each must be unique within the file, max 40 characters).

Returns:

return a reservation identifier on success, 0 on failure.

This function is meant to enable the parallel writing (with multiple threads) of several type 13 segments (discrete states of the positions and velocities, Hermite interpolation with variable timesteps) to the SPK file associated to the ephemeris descriptor eph.

It reserves space in the file for target_count segments, each segment associated to a target in the targets array. Each target has its own number of records specified in the record_counts array, and its own segment identifier specified in the segids array. All the targets share the same center, frame, start_..._tdb, end_..._tdb and deg parameters.

The array targets, record_counts and segids must be of size target_count.

The reservation id returned by this function must be used in the function writeph_spk13_par_write() to write in the corresponding reserved space. In addition, the function writeph_spk13_par_write() will require a target_index, which is the index of the target in the targets array used in this function.

A call to writeph_spk13_par_reserve is always performed by a single thread and is followed by several calls to writeph_spk13_par_write() by one or several threads.

The following example creates a new ephemeris file ephemeris.bsp with segment of type 13 for the heliocentric coordinates of Mercury and Venus using OpenMP.

t_writephbin *weph;

weph = writeph_spk_create("ephemeris.bsp","planet_2", 0);
if (weph)
{
      int frame = 1; /* ICRF */
      int target_count = 2;
      int targets[2] = { NAIFID_MERCURY, NAIFID_VENUS };
      int records_count[2] = { 10, 20 };
      int len_timespan[2] = { 32, 16 };
      const char segids[2] = { "seg_mercury",  "seg_venus" };
      double jd_start = 2460000;
      double jd_end = 2460000+32*10;
      int reservation;
      int interpolation_degree = 7;

      reservation = writeph_spk13_seq_reserve(weph, target_count, targets, NAIFID_SUN,
                             frame, jd_start, 0.0, jd_end, 0.0,
                             len_timespan, record_counts, interpolation_degree, segids);

      #pragma omp parallel for
      for (int body = 0; body<target_count; body++)
      {
           #pragma omp parallel for
           for (int k=0; k<records_count[body]; k++)
           {
               double pos_vel[6]; /*  size = 6 components */
               double epochs[1];  /*  size =  1 time */

               epochs[0] = jd_start+k*len_timespan;

               /* ... fill the array pos_vel with the positions and velocities at the date jd ...
                pos_vel[..] =...
               */
               writeph_spk13_par_write(weph, reservation, body,  k, 1,  pos_vel, epochs);
           }
      }


      writeph_close(weph);
}

writeph_spk13_par_write

int writeph_spk13_par_write(t_writephbin *eph, int reservation, int target_index, int record_begin_index, int record_count, const double *states, const double *epochs)
Parameters:
  • eph -- ephemeris descriptor

  • reservation -- reservation identifier.

  • target_index -- index of the target body in the reservation.

  • record_begin_index -- index of the first record to be written in the target's segment.

  • record_count -- number of records to be written.

  • states -- array of state vectors.

  • epochs -- array of epochs (in Julian date TCB) one per state vector.

Returns:

0 if an error occurs, otherwise non-zero value.

This function writes in parallel mode records of a type 13 segment (discrete states of the positions and velocities, Hermite interpolation with variable timesteps) to the SPK file associated to the ephemeris descriptor eph.

The reservation parameter must be the reservation id returned by the function writeph_spk13_par_reserve().

The target_index parameter is the index of the target in the targets array that was passed to the function writeph_spk13_par_reserve(), starting from 0.

The record_begin_index parameter is the index of the first record to be written in the target's segment, starting from 0.

The record_count parameter is the number of records to be written starting from the record_begin_index.

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

Multiple threads can call this function at the same time, but with different values of target_index and/or record_begin_index. The behavior is undefined if multiple threads overlap the written data : e.g., two threads write to the same target target_index and a common record number.

writeph_spk14_begin

int writeph_spk14_begin(t_writephbin *eph, int target, int center, int frame, double start_jd0_tdb, double start_frac_tdb, double end_jd0_tdb, double end_frac_tdb, int deg, const char *segid)
Parameters:
  • eph -- ephemeris descriptor

  • target -- The body or reference point whose coordinates will be written (see NAIF identification numbers).

  • center -- The origin of the coordinate system (see NAIF identification numbers).

  • frame -- reference frame (see Frame numbers).

  • start_jd0_tdb -- starting Julian date integer part (TDB).

  • start_frac_tdb -- starting Julian date fraction part (TDB).

  • end_jd0_tdb -- stop Julian date integer part (TDB).

  • end_frac_tdb -- stop Julian date fraction part (TDB).

  • deg -- degree of the Chebyshev polynomials.

  • segid -- segment identifier (must be unique within the file, max 40 characters).

This function begins the sequential writting of a type 14 segment (Chebyshev polynomials of the positions and velocities, with variable timesteps) to the SPK file associated to the ephemeris descriptor eph. Once this function is called, no other segment can be written to the same file, and only writeph_spk14_add() can be used with eph, until writeph_spk14_end() is called.

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

t_writephbin *weph;
const char segid[] = "seg_planet";

weph = writeph_spk_create("ephemeris.bsp","planet_2", 0);
if (weph)
{
      int len_timespan = 32; /* days */
      int frame = 1; /* ICRF */
      int degree = 12;
      double jd_start = 2460000;
      double jd_end = 2460300;
      double coefs[80];  /*  size = 13*6+2  =  (degree+1) * 6+2 components */
      double epoch[1];   /*  size = 1  date only */

      writeph_spk14_begin(weph, NAIFID_VENUS, NAIFID_SUN, frame, jd_start, 0.0, jd_end, 0.0,
                          degree+1, segid);

      for (int k=0; k<100; k++)
      {

           /* ... fill the array coefs with the epochs and coefficients of the Chebychev polynomials ...
                epoch[k] = ...
                coefs[..] =...
           */
           /* write one record  only */
           writeph_spk14_add(weph, 1, coefs, epochs);
      }
      writeph_spk14_end(weph);


      writeph_close(weph);
}

writeph_spk14_add

int writeph_spk14_add(t_writephbin *eph, int record_count, const double *data, const double *epochs)
Parameters:
  • eph -- ephemeris descriptor

  • record_count -- number of records to be written.

  • data -- array data to be written.

  • epochs -- array of epochs (in Julian date TCB) one per state vector.

This function adds data to the segment that has been begun with writeph_spk14_begin.

The data array must be of size record_count*((deg+1)*6 + 2) and have the following structure :

MID 1st record

RADIUS 1st record

X's 1st coef 1st record

...

X's (deg + 1)th coef 1st record

Y's 1st coef 1st record

...

Y's (deg + 1)th coef 1st record

Z's 1st coef 1st record

...

Z's (deg + 1)th coef 1st record

dX's 1st coef 1st record

...

dX's (deg + 1)th coef 1st record

dY's 1st coef 1st record

...

dY's (deg + 1)th coef 1st record

dZ's 1st coef 1st record

...

dZ's (deg + 1)th coef 1st record

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

MID (record_count)th record

RADIUS (record_count)th record

X's 1st coef (record_count)th record

...

X's (deg + 1)th coef (record_count)th record

Y's 1st coef (record_count)th record

...

Y's (deg + 1)th coef (record_count)th record

Z's 1st coef (record_count)th record

...

Z's (deg + 1)th coef (record_count)th record

dX's 1st coef (record_count)th record

...

dX's (deg + 1)th coef (record_count)th record

dY's 1st coef (record_count)th record

...

dY's (deg + 1)th coef (record_count)th record

dZ's 1st coef (record_count)th record

...

dZ's (deg + 1)th coef (record_count)th record

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

Epoch of the 1st record

...

Epoch of the (record_count)th record

writeph_spk14_end

int writeph_spk14_end(t_writephbin *eph)
Parameters:
  • eph -- ephemeris descriptor

This function ends the sequential writting of the segment begun with writeph_spk14_begin, and finally stores it in the SPK file associated to the ephemeris descriptor eph. After this function has been called other segments can be written to this file again.

writeph_spk102_seq_write

int writeph_spk102_seq_write(t_writephbin *eph, int target, int center, int frame, double start_jd0_tcb, double start_frac_tcb, double end_jd0_tcb, double end_frac_tcb, double intlen_jd_tcb, const double *polynomials, int record_count, int deg, const char *segid)
Parameters:
  • eph -- ephemeris descriptor

  • target -- The body or reference point whose coordinates will be written (see NAIF identification numbers).

  • center -- The origin of the coordinate system (see NAIF identification numbers).

  • frame -- reference frame (see Frame numbers).

  • start_jd0_tcb -- starting Julian date integer part (TCB).

  • start_frac_tcb -- starting Julian date fraction part (TCB).

  • end_jd0_tcb -- stop Julian date integer part (TCB).

  • end_frac_tcb -- stop Julian date fraction part (TCB).

  • intlen_jd_tcb -- length of the interpolation interval (in days, TCB).

  • polynomials -- array of Chebyshev polynomial coefficients.

  • record_count -- number of records to be written.

  • deg -- degree of the Chebyshev polynomials.

  • segid -- segment identifier (must be unique within the file, max 40 characters).

Returns:

0 if an error occurs, otherwise non-zero value.

This function writes in sequential mode a type 102 segment (Chebyshev polynomials of the position only ) in the time scale TCB to the SPK file associated to the ephemeris descriptor eph.

The polynomials array must be of size record_count*(deg+1)*3 and have the following structure :

X's 1st coef 1st record

...

X's (deg + 1)th coef 1st record

Y's 1st coef 1st record

...

Y's (deg + 1)th coef 1st record

Z's 1st coef 1st record

...

Z's (deg + 1)th coef 1st record

...

...

...

...

...

...

...

...

...

X's 1st coef (record_count)th record

...

X's (deg + 1)th coef (record_count)th record

Y's 1st coef (record_count)th record

...

Y's (deg + 1)th coef (record_count)th record

Z's 1st coef (record_count)th record

...

Z's (deg + 1)th coef (record_count)th record

The following example creates a new ephemeris file ephemeris.bsp with segment of type 2 for the heliocentric coordinates of Venus, in the timescale TCB.

t_writephbin *weph;
const char segid[] = "seg_planet";

weph = writeph_spk_create("ephemeris.bsp","planet_2", 0);
if (weph)
{
      int len_timespan = 32; /* days */
      int frame = 1; /* ICRF */
      int record_count = 10;
      int degree = 12;
      double jd_start = 2460000;
      double jd_end = jd_start+record_count*len_timespan;
      double coefs[390];  /*  size = 10*13*3  = record_count * (degree+1) * 3 components */

      for (int k=0; k<record_count; k++)
      {

           double jd_startk = jd_start+k*len_timespan;
           double jd_endk = jd_start+(k+1)*len_timespan;


           /* ... fill the array coefs with the coefficients of the Chebychev polynomials ...
                coefs[..] =...
           */
      }
      writeph_spk102_seq_write(weph, NAIFID_VENUS, NAIFID_SUN, frame, jd_start, 0.0, jd_end, 0.0,
                             len_timespan, coefs, record_count, degree+1, segid);


      writeph_close(weph);
}

writeph_spk102_par_reserve

int writeph_spk102_par_reserve(t_writephbin *eph, int target_count, const int *targets, int center, int frame, double start_jd0_tcb, double start_frac_tcb, double end_jd0_tcb, double end_frac_tcb, const double *intlens_jd_tcb, const int *record_counts, int deg, const char *segids[])
Parameters:
  • eph -- ephemeris descriptor

  • target_count -- number of targets the reservation is done for.

  • targets -- array of bodies or reference points whose coordinates will be written (see NAIF identification numbers).

  • center -- The origin of the coordinate system (see NAIF identification numbers).

  • frame -- reference frame (see Frame numbers).

  • start_jd0_tcb -- starting Julian date integer part (TCB).

  • start_frac_tcb -- starting Julian date fraction part (TCB).

  • end_jd0_tcb -- stop Julian date integer part (TCB).

  • end_frac_tcb -- stop Julian date fraction part (TCB).

  • intlens_jd_tcb -- array containing the interpolation interval length for each target (in days, TCB).

  • record_counts -- array of number of records for each target.

  • deg -- degree of the Chebyshev polynomials.

  • segids -- array of segment identifiers (one per target, each must be unique within the file, max 40 characters).

Returns:

return a reservation identifier on success, 0 on failure.

This function is meant to enable the parallel writing (with multiple threads) of several type 102 segments (Chebyshev polynomials of the position only ) in the time scale TCB to the SPK file associated to the ephemeris descriptor eph. It reserves space in the file for target_count segments, each segment associated to a target in the targets array. Each target has its own interpolation interval length specified in the intlens_jd_tcb array, its own number of records specified in the record_counts array, and its own segment identifier specified in the segids array. All the targets share the same center, frame, start_..._tcb, end_..._tcb and deg parameters.

The array targets, intlens_jd_tcb, record_counts and segids must be of size target_count.

The reservation id returned by this function must be used in the function writeph_spk102_par_write() to write in the corresponding reserved space. In addition, the function writeph_spk102_par_write() will require a target_index, which is the index of the target in the targets array used in this function.

A call to writeph_spk102_par_reserve is always performed by a single thread and is followed by several calls to writeph_spk102_par_write() by one or several threads.

Warning

The data covers the same timespan from the date start_jd_tcb+start_frac_tcb to end_jd_tcb+end_frac_tcb for all targets, but each target may have a different number of polynomials. The time span record_counts*intlens_jd_tcb must be equal to the timespan defined from the date start_jd_tcb+start_frac_tcb to end_jd_tcb+end_frac_tcb. If the targets doesnot have the timespan, multiple reservations must be performed before the call to writing writeph_spk3_par_write().

The following example creates a new ephemeris file ephemeris.bsp with segment of type 102 for the heliocentric coordinates of Mercury and Venus, in the timescale TCB, using OpenMP.

t_writephbin *weph;

weph = writeph_spk_create("ephemeris.bsp","planet_2", 0);
if (weph)
{
      int frame = 1; /* ICRF */
      int degree = 12;
      int target_count = 2;
      int targets[2] = { NAIFID_MERCURY, NAIFID_VENUS };
      int records_count[2] = { 10, 20 };
      int len_timespan[2] = { 32, 16 };
      const char segids[2] = { "seg_mercury",  "seg_venus" };
      double jd_start = 2460000;
      double jd_end = 2460000+32*10;
      int reservation;

      reservation = writeph_spk102_seq_reserve(weph, target_count, targets, NAIFID_SUN,
                             frame, jd_start, 0.0, jd_end, 0.0,
                             len_timespan, record_counts, degree+1, segids);

      #pragma omp parallel for
      for (int body = 0; body<target_count; body++)
      {
           #pragma omp parallel for
           for (int k=0; k<records_count[body]; k++)
           {
               double coefs[39];  /*  size = 13*3  = (degree+1) * 3 components */

               double jd_startk = jd_start+k*len_timespan[body];
               double jd_endk = jd_start+(k+1)*len_timespan[body];


               /* ... fill the array coefs with the coefficients of the Chebychev polynomials ...
                   coefs[..] =...
               */
               ret = writeph_spk102_par_write(weph, reservation, body,  k, 1,  coefs);
           }
      }


      writeph_close(weph);
}

writeph_spk102_par_write

int writeph_spk102_par_write(t_writephbin *eph, int reservation, int target_index, int record_begin_index, int record_count, const double *polynomials)
Parameters:
  • eph -- ephemeris descriptor

  • reservation -- reservation identifier.

  • target_index -- index of the target body in the reservation.

  • record_begin_index -- index of the first record to be written in the target's segment.

  • record_count -- number of records to be written.

  • polynomials -- array of Chebyshev polynomial coefficients.

Returns:

0 if an error occurs, otherwise non-zero value.

This function writes in parallel mode records of a type 102 segment (Chebyshev polynomials of the position only ) in the time scale TCB to the SPK file associated to the ephemeris descriptor eph.

The reservation parameter must be the reservation id returned by the function writeph_spk2_par_reserve().

The target_index parameter is the index of the target in the targets array that was passed to the function writeph_spk2_par_reserve(), starting from 0.

The record_begin_index parameter is the index of the first record to be written in the target's segment, starting from 0.

The record_count parameter is the number of records to be written starting from the record_begin_index.

The polynomials array must have the following structure :

X's 1st coef 1st record

...

X's (deg + 1)th coef 1st record

Y's 1st coef 1st record

...

Y's (deg + 1)th coef 1st record

Z's 1st coef 1st record

...

Z's (deg + 1)th coef 1st record

...

...

...

...

...

...

...

...

...

X's 1st coef (record_count)th record

...

X's (deg + 1)th coef (record_count)th record

Y's 1st coef (record_count)th record

...

Y's (deg + 1)th coef (record_count)th record

Z's 1st coef (record_count)th record

...

Z's (deg + 1)th coef (record_count)th record

With the 1st record being the record at index record_begin_index, and the (record_count)th record being the record at index record_begin_index + record_count - 1.

Multiple threads can call this function at the same time, but with different values of target_index and/or record_begin_index. The behavior is undefined if multiple threads overlap the written data : e.g., two threads write to the same target target_index and a common record number.

writeph_spk103_seq_write

int writeph_spk103_seq_write(t_writephbin *eph, int target, int center, int frame, double start_jd0_tcb, double start_frac_tcb, double end_jd0_tcb, double end_frac_tcb, double intlen_jd_tcb, const double *polynomials, int record_count, int deg, const char *segid)
Parameters:
  • eph -- ephemeris descriptor

  • target -- The body or reference point whose coordinates will be written (see NAIF identification numbers).

  • center -- The origin of the coordinate system (see NAIF identification numbers).

  • frame -- reference frame (see Frame numbers).

  • start_jd0_tcb -- starting Julian date integer part (TCB).

  • start_frac_tcb -- starting Julian date fraction part (TCB).

  • end_jd0_tcb -- stop Julian date integer part (TCB).

  • end_frac_tcb -- stop Julian date fraction part (TCB).

  • intlen_jd_tcb -- length of the interpolation interval (in days, TCB).

  • polynomials -- array of Chebyshev polynomial coefficients.

  • record_count -- number of records to be written.

  • deg -- degree of the Chebyshev polynomials.

  • segid -- segment identifier (must be unique within the file, max 40 characters).

Returns:

0 if an error occurs, otherwise non-zero value.

This function writes in sequential mode a type 103 segment (Chebyshev polynomials of the position and velocity ) in the time scale TCB to the SPK file associated to the ephemeris descriptor eph.

The polynomials array must be of size record_count*(deg+1)*6 and have the following structure :

X's 1st coef 1st record

...

X's (deg + 1)th coef 1st record

Y's 1st coef 1st record

...

Y's (deg + 1)th coef 1st record

Z's 1st coef 1st record

...

Z's (deg + 1)th coef 1st record

dX's 1st coef 1st record

...

dX's (deg + 1)th coef 1st record

dY's 1st coef 1st record

...

dY's (deg + 1)th coef 1st record

dZ's 1st coef 1st record

...

dZ's (deg + 1)th coef 1st record

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

X's 1st coef (record_count)th record

...

X's (deg + 1)th coef (record_count)th record

Y's 1st coef (record_count)th record

...

Y's (deg + 1)th coef (record_count)th record

Z's 1st coef (record_count)th record

...

Z's (deg + 1)th coef (record_count)th record

dX's 1st coef (record_count)th record

...

dX's (deg + 1)th coef (record_count)th record

dY's 1st coef (record_count)th record

...

dY's (deg + 1)th coef (record_count)th record

dZ's 1st coef (record_count)th record

...

dZ's (deg + 1)th coef (record_count)th record

The following example creates a new ephemeris file ephemeris.bsp with segment of type 3 for the heliocentric coordinates of Venus, in the timescale TCB.

t_writephbin *weph;
const char segid[] = "seg_planet";

weph = writeph_spk_create("ephemeris.bsp","planet_2", 0);
if (weph)
{
      int len_timespan = 32; /* days */
      int frame = 1; /* ICRF */
      int record_count = 10;
      int degree = 12;
      double jd_start = 2460000;
      double jd_end = jd_start+record_count*len_timespan;
      double coefs[780];  /*  size = 10*13*6  = record_count * (degree+1) * 6 components */

      for (int k=0; k<record_count; k++)
      {

           double jd_startk = jd_start+k*len_timespan;
           double jd_endk = jd_start+(k+1)*len_timespan;


           /* ... fill the array coefs with the coefficients of the Chebychev polynomials ...
                coefs[..] =...
           */
      }
      writeph_spk103_seq_write(weph, NAIFID_VENUS, NAIFID_SUN, frame, jd_start, 0.0, jd_end, 0.0,
                             len_timespan, coefs, record_count, degree+1, segid);


      writeph_close(weph);
}

writeph_spk103_par_reserve

int writeph_spk103_par_reserve(t_writephbin *eph, int target_count, const int *targets, int center, int frame, double start_jd0_tcb, double start_frac_tcb, double end_jd0_tcb, double end_frac_tcb, const double *intlens_jd_tcb, const int *record_counts, int deg, const char *segids[])
Parameters:
  • eph -- ephemeris descriptor

  • target_count -- number of targets the reservation is done for.

  • targets -- array of bodies or reference points whose coordinates will be written (see NAIF identification numbers).

  • center -- The origin of the coordinate system (see NAIF identification numbers).

  • frame -- reference frame (see Frame numbers).

  • start_jd0_tcb -- starting Julian date integer part (TCB).

  • start_frac_tcb -- starting Julian date fraction part (TCB).

  • end_jd0_tcb -- stop Julian date integer part (TCB).

  • end_frac_tcb -- stop Julian date fraction part (TCB).

  • intlens_jd_tcb -- array containing the interpolation interval length for each target (in days, TCB).

  • record_counts -- array of number of records for each target.

  • deg -- degree of the Chebyshev polynomials.

  • segids -- array of segment identifiers (one per target, each must be unique within the file, max 40 characters).

Returns:

return a reservation identifier on success, 0 on failure.

This function is meant to enable the parallel writing (with multiple threads) of several type 103 segments (Chebyshev polynomials of the position and velocity ) in the time scale TCB to the SPK file associated to the ephemeris descriptor eph. It reserves space in the file for target_count segments, each segment associated to a target in the targets array. Each target has its own interpolation interval length specified in the intlens_jd_tcb array, its own number of records specified in the record_counts array, and its own segment identifier specified in the segids array. All the targets share the same center, frame, start_..._tcb, end_..._tcb and deg parameters.

The array targets, intlens_jd_tcb, record_counts and segids must be of size target_count.

The reservation id returned by this function must be used in the function writeph_spk103_par_write() to write in the corresponding reserved space. In addition, the function writeph_spk103_par_write() will require a target_index, which is the index of the target in the targets array used in this function.

A call to writeph_spk103_par_reserve is always performed by a single thread and is followed by several calls to writeph_spk103_par_write() by one or several threads.

Warning

The data covers the same timespan from the date start_jd_tcb+start_frac_tcb to end_jd_tcb+end_frac_tcb for all targets, but each target may have a different number of polynomials. The time span record_counts*intlens_jd_tcb must be equal to the timespan defined from the date start_jd_tcb+start_frac_tcb to end_jd_tcb+end_frac_tcb. If the targets doesnot have the timespan, multiple reservations must be performed before the call to writing writeph_spk103_par_write().

The following example creates a new ephemeris file ephemeris.bsp with segment of type 103 for the heliocentric coordinates of Mercury and Venus, in the timescale TCB, using OpenMP.

t_writephbin *weph;

weph = writeph_spk_create("ephemeris.bsp","planet_2", 0);
if (weph)
{
      int frame = 1; /* ICRF */
      int degree = 12;
      int target_count = 2;
      int targets[2] = { NAIFID_MERCURY, NAIFID_VENUS };
      int records_count[2] = { 10, 20 };
      int len_timespan[2] = { 32, 16 };
      const char segids[2] = { "seg_mercury",  "seg_venus" };
      double jd_start = 2460000;
      double jd_end = 2460000+32*10;
      int reservation;

      reservation = writeph_spk103_seq_reserve(weph, target_count, targets, NAIFID_SUN,
                             frame, jd_start, 0.0, jd_end, 0.0,
                             len_timespan, record_counts, degree+1, segids);

      #pragma omp parallel for
      for (int body = 0; body<target_count; body++)
      {
           #pragma omp parallel for
           for (int k=0; k<records_count[body]; k++)
           {
               double coefs[78];  /*  size = 13*6  = (degree+1) * 6 components */

               double jd_startk = jd_start+k*len_timespan[body];
               double jd_endk = jd_start+(k+1)*len_timespan[body];


               /* ... fill the array coefs with the coefficients of the Chebychev polynomials ...
                   coefs[..] =...
               */
               ret = writeph_spk103_par_write(weph, reservation, body,  k, 1,  coefs);
           }
      }


      writeph_close(weph);
}

writeph_spk103_par_write

int writeph_spk103_par_write(t_writephbin *eph, int reservation, int target_index, int record_begin_index, int record_count, const double *polynomials)
Parameters:
  • eph -- ephemeris descriptor

  • reservation -- reservation identifier.

  • target_index -- index of the target body in the reservation.

  • record_begin_index -- index of the first record to be written in the target's segment.

  • record_count -- number of records to be written.

  • polynomials -- array of Chebyshev polynomial coefficients.

Returns:

0 if an error occurs, otherwise non-zero value.

This function writes in parallel mode records of a type 103 segment (Chebyshev polynomials of the position and velocity ) in the time scale TCB to the SPK file associated to the ephemeris descriptor eph.

The reservation parameter must be the reservation id returned by the function writeph_spk3_par_reserve().

The target_index parameter is the index of the target in the targets array that was passed to the function writeph_spk3_par_reserve(), starting from 0.

The record_begin_index parameter is the index of the first record to be written in the target's segment, starting from 0.

The record_count parameter is the number of records to be written starting from the record_begin_index.

The polynomials array must have the following structure :

X's 1st coef 1st record

...

X's (deg + 1)th coef 1st record

Y's 1st coef 1st record

...

Y's (deg + 1)th coef 1st record

Z's 1st coef 1st record

...

Z's (deg + 1)th coef 1st record

dX's 1st coef 1st record

...

dX's (deg + 1)th coef 1st record

dY's 1st coef 1st record

...

dY's (deg + 1)th coef 1st record

dZ's 1st coef 1st record

...

dZ's (deg + 1)th coef 1st record

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

X's 1st coef (record_count)th record

...

X's (deg + 1)th coef (record_count)th record

Y's 1st coef (record_count)th record

...

Y's (deg + 1)th coef (record_count)th record

Z's 1st coef (record_count)th record

...

Z's (deg + 1)th coef (record_count)th record

dX's 1st coef (record_count)th record

...

dX's (deg + 1)th coef (record_count)th record

dY's 1st coef (record_count)th record

...

dY's (deg + 1)th coef (record_count)th record

dZ's 1st coef (record_count)th record

...

dZ's (deg + 1)th coef (record_count)th record

With the 1st record being the record at index record_begin_index, and the (record_count)th record being the record at index record_begin_index + record_count - 1.

Multiple threads can call this function at the same time, but with different values of target_index and/or record_begin_index. The behavior is undefined if multiple threads overlap the written data : e.g., two threads write to the same target target_index and a common record number.

Previous Next

© Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026, CNRS, Observatoire de Paris, Observatoire de la Côte d'Azur.