16 extern int moved_(doublereal *arrfrm, integer *ndim, doublereal *arrto);
17 extern int qmini(
double *init,
double *
final,
double frac,
double *qintrp);
21 int ck3sdn(
double sdntol,
bool avflag,
int *nrec,
22 double *sclkdp,
double *quats,
double *avvs,
23 int nints,
double *starts,
double *dparr,
int *intarr) {
28 doublereal frac, dneg;
30 doublereal dpos, dist2;
38 doublereal dist2a, dist2b;
41 integer intcrf, ndropd, intcrl;
44 doublereal qlinpt[4], qintrp[4];
258 setmsg_c(
"The number of pointing records must be greater than zero. I"
260 errint_c(
"#", *nrec);
261 sigerr_c(
"SPICE(INVALIDNUMBEROFRECORDS)");
269 setmsg_c(
"The number of interval starts must be greater than zero. It"
271 errint_c(
"#", nints);
272 sigerr_c(
"SPICE(INVALIDNUMBEROFINTERVALS)");
281 setmsg_c(
"The number of interval starts, #, is not less than or equal"
282 " to the number of records, #.");
283 errint_c(
"#", nints);
284 errint_c(
"#", *nrec);
285 sigerr_c(
"SPICE(BUFFERSIZESMISMATCH)");
293 if(sclkdp[0] != starts[0]) {
294 setmsg_c(
"The first interval start time, #, is not the same as the fi"
295 "rst record time, #.");
296 errdp_c(
"#", *sclkdp);
297 errdp_c(
"#", *starts);
298 sigerr_c(
"SPICE(FIRSTRECORDMISMATCH)");
307 setmsg_c(
"The down sampling tolerance must be a non-negative number. "
309 errdp_c(
"#", sdntol);
310 sigerr_c(
"SPICE(BADDOWNSAMPLINGTOL)");
328 for(i__ = 1; i__ <= i__1; ++i__) {
351 i__2 = *nrec - intcrf + 1;
352 intnrf = bsrchd_c(starts[i__], i__2, &sclkdp[intcrf - 1]);
359 intnrf = intnrf + intcrf - 1;
372 setmsg_c(
"Cannot find pointing record with time that matches "
373 "the start time # (encoded SCLK ticks) of the interpo"
374 "lation interval number #.");
375 errdp_c(
"#", starts[i__]);
378 sigerr_c(
"SPICE(INTERVALSTARTNOTFOUND)");
391 skipit = intcrf == intcrl || intcrf == intcrl - 1;
398 while(! skipit && keepf < intcrl) {
403 keepl = (left + right) / 2;
408 vhatg_c(&quats[(keepf << 2) - 4], c__4, qkeepf);
409 vhatg_c(&quats[(keepl << 2) - 4], c__4, qkeepl);
415 vminug_c(qkeepl, c__4, qlneg);
416 dpos = vdistg_c(qkeepl, qkeepf, c__4);
417 dneg = vdistg_c(qlneg, qkeepf, c__4);
419 moved_(qlneg, (integer *) &c__4, qlinpt);
422 moved_(qkeepl, (integer *) &c__4, qlinpt);
431 while(j <= keepl - 1 && fitok) {
435 if(sclkdp[keepl - 1] - sclkdp[keepf - 1] != 0.) {
436 frac = (sclkdp[j - 1] - sclkdp[keepf - 1]) / (sclkdp[
437 keepl - 1] - sclkdp[keepf - 1]);
440 sigerr_c(
"SPICE(CK3SDNBUG)");
448 qmini(qkeepf, qlinpt, frac, qintrp);
453 dist2a = (quats[(j << 2) - 4] - qintrp[0]) * (quats[(j << 2)
454 - 4] - qintrp[0]) + (quats[(j << 2) - 3] - qintrp[1])
455 * (quats[(j << 2) - 3] - qintrp[1]) + (quats[(j << 2)
456 - 2] - qintrp[2]) * (quats[(j << 2) - 2] - qintrp[2])
457 + (quats[(j << 2) - 1] - qintrp[3]) * (quats[(j << 2)
459 dist2b = (quats[(j << 2) - 4] + qintrp[0]) * (quats[(j << 2)
460 - 4] + qintrp[0]) + (quats[(j << 2) - 3] + qintrp[1])
461 * (quats[(j << 2) - 3] + qintrp[1]) + (quats[(j << 2)
462 - 2] + qintrp[2]) * (quats[(j << 2) - 2] + qintrp[2])
463 + (quats[(j << 2) - 1] + qintrp[3]) * (quats[(j << 2)
465 dist2 = min(dist2a, dist2b);
472 angle = asin(sqrt(dist2) / 2.) * 4.;
476 fitok = fitok && abs(angle) <= sdntol;
495 for(j = keepf + 1; j <= i__2; ++j) {
496 sclkdp[j - 1] = dpmax_c();
546 orderd_c(sclkdp, *nrec, (SpiceInt *) intarr);
550 reordd_c(intarr, *nrec, sclkdp);
554 for(i__ = 0; i__ <= 3; ++i__) {
556 for(j = 1; j <= i__1; ++j) {
557 dparr[j - 1] = quats[i__ + (j << 2) - 4];
559 reordd_c(intarr, *nrec, dparr);
561 for(j = 1; j <= i__1; ++j) {
562 quats[i__ + (j << 2) - 4] = dparr[j - 1];
570 for(i__ = 1; i__ <= 3; ++i__) {
572 for(j = 1; j <= i__1; ++j) {
573 dparr[j - 1] = avvs[i__ + j * 3 - 4];
575 reordd_c(intarr, *nrec, dparr);
577 for(j = 1; j <= i__1; ++j) {
578 avvs[i__ + j * 3 - 4] = dparr[j - 1];