Esempio n. 1
0
/* $ Procedure TIMECN (Convert and round times) */
/* Subroutine */ int timecn_(doublereal *tconv, integer *ids, char *tout, 
	char *linet, ftnlen tout_len, ftnlen linet_len)
{
    /* Builtin functions */
    /* Subroutine */ int s_copy(char *, char *, ftnlen, ftnlen);
    integer s_cmp(char *, char *, ftnlen, ftnlen);

    /* Local variables */
    extern /* Subroutine */ int sct2e_(integer *, doublereal *, doublereal *),
	     dpfmt_(doublereal *, char *, char *, ftnlen, ftnlen), reset_(
	    void);
    extern logical failed_(void);
    extern /* Subroutine */ int scdecd_(integer *, doublereal *, char *, 
	    ftnlen);
    integer sc;
    logical ok;
    extern /* Subroutine */ int ckmeta_(integer *, char *, integer *, ftnlen),
	     erract_(char *, char *, ftnlen, ftnlen);
    doublereal ettime;
    extern /* Subroutine */ int fixuni_(void), errprt_(char *, char *, ftnlen,
	     ftnlen), timout_(doublereal *, char *, char *, ftnlen, ftnlen);

/* $ Abstract */

/*     This is internal subroutine for CKBRIEF program. It converts */
/*     time between encoded SCLK, SCLK string, ET, UTC or UTC/DOY. */

/* $ Disclaimer */

/*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
/*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
/*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
/*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
/*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
/*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
/*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
/*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
/*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
/*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */

/*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
/*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
/*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
/*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
/*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
/*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */

/*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
/*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
/*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
/*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */

/* $ Keywords */

/*     SUMMARY */
/*     C KERNEL */

/* $ Declarations */
/* $ Disclaimer */

/*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
/*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
/*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
/*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
/*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
/*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
/*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
/*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
/*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
/*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */

/*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
/*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
/*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
/*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
/*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
/*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */

/*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
/*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
/*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
/*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */

/* $ Author_and_Institution */

/*     Y.K. Zaiko     (BERC) */
/*     B.V. Semenov   (NAIF) */

/* $ Version */

/* -    Toolkit Version 6.1.0, 27-JUN-2014 (BVS) */

/*        BUG FIX: changed logic to make a combination of -a and an ID */
/*        specified on the command line work in all cases. */

/* -    CKBRIEF Version 6.0.0, 2014-04-28 (BVS) (NJB) */

/*        Modified to treat all files as a single file (-a). */

/*        Changed SCLKD display format to include 6 decimal */
/*        places. */

/*        Increased MAXBOD to 1,000,000 (from 100,000) and CMDSIZ to */
/*        50,000 (from 25,000). */

/*        Added support for CK type 6. */

/* -    CKBRIEF Version 5.0.0, 2009-02-11 (BVS) */

/*        Updated version. */

/* -    CKBRIEF Version 4.0.0, 2008-01-13 (BVS) */

/*        Increased MAXBOD to 100,000 (from 10,000). */

/*        Increased CMDSIZ to 25,000 (from 4,000). */

/*        Updated version string and changed its format to */
/*        '#.#.#, Month DD, YYYY' (from '#.#.#, YYYY-MM-DD'). */

/* -    CKBRIEF Version 3.2.0, 2006-11-02 (BVS) */

/*        Updated version string. */

/* -    CKBRIEF Version 3.1.0, 2005-11-08 (BVS) */

/*        Updated version string. */

/* -    CKBRIEF Version 2.0.0, 2001-05-16 (BVS) */

/*        Increased MAXBOD to 10000 (from 4000). Set LRGWIN to be */
/*        MAXBOD*2 (was MAXBOD). Changed version string. */

/* -    CKBRIEF Version 1.1.2, 2001-04-09 (BVS) */

/*        Changed version parameter. */

/* -    CKBRIEF Version 1.0.0 beta, 1999-02-17 (YKZ)(BVS) */

/*        Initial release. */

/* -& */

/*     The Version is stored as a string. */


/*     The maximum number of segments or interpolation intervals */
/*     that can be summarized is stored in the parameter MAXBOD. */
/*     This is THE LIMIT that should be increased if window */
/*     routines called by CKBRIEF fail. */


/*     The largest expected window -- must be twice the size of */
/*     MAXBOD for consistency. */


/*     The longest command line that can be accommodated is */
/*     given by CMDSIZ. */


/*     MAXUSE is the maximum number of objects that can be explicitly */
/*     specified on the command line for ckbrief summaries. */


/*     Generic line size for all modules. */


/*     Time type keys. */


/*     Output time format pictures. */

/* $ Brief_I/O */

/*     Variable  I/O  Description */
/*     --------  ---  -------------------------------------------------- */
/*     TCONV      I   Encoded SCLK time */
/*     IDS        I   NAIF ID code of object */
/*     TOUT       I   Form of time representation on output */
/*     LINET      O   Text presentation of time */

/* $ Detailed Input */

/*     TCONV          Encoded SCLK time to be converted, rounded */
/*                    and decoded to character string */

/*     IDS            Integer NAIF ID code found in summary from which */
/*                    TCONV was obtained. */

/*     TOUT           Key specifying time presentation on output: */
/*                    SCLK string, encoded SCLK, ET, UTC or DOY UTC. */

/* $ Detailed Output */

/*     LINET          Character string which contains time converted */
/*                    to requested representation or NOTIME flag if */
/*                    conversion was not possible. */

/* $ Parameters */

/*     None. */

/* $ Files */

/*     None. */

/* $ Exceptions */

/*     Error free. */

/* $ Particulars */

/*     None. */

/* $ Examples */

/*     None. */

/* $ Restrictions */

/*     None. */

/* $ Author_and_Institution */

/*     Y.K. Zaiko      (BERC) */
/*     B.V. Semenov    (NAIF) */

/* $ Literature_References */

/*     None. */

/* $ Version */

/* -    CKBRIEF Beta Version 1.0.0, 17-FEB-1999 (YKZ)(BVS) */

/* -& */

/*     SPICELIB functions */


/*     Local variables */


/*     Reset output time string. */

    s_copy(linet, " ", linet_len, (ftnlen)1);

/*     It is necessary to use real spacecraft ID in SCLK<->ET */
/*     conversion routines. CKMETA is providing it. */

    ckmeta_(ids, "SCLK", &sc, (ftnlen)4);

/*     TIMECN is the special routine to be used in CKBRIEF */
/*     utility to convert times in accordance to user request. If user */
/*     haven't provided ancillary files to perform this conversion, the */
/*     program shouldn't stop. To achieve this we'll forbid TIMECN to */
/*     be aborted by SPICELIB standard error processing if it can't */
/*     convert times. On the exit from TIMECN, SPICE error handling */
/*     is restored to its original state. */

    erract_("SET", "RETURN", (ftnlen)3, (ftnlen)6);
    errprt_("SET", "NONE", (ftnlen)3, (ftnlen)4);

/*     We do appropriate conversion depending on the requested output */
/*     time representation. If SCLK for the s/c of interest and(!) */
/*     LSK file weren't loaded, conversions to string SCLK, ET, UTC */
/*     and UTC/DOY are not possible. The output time set to NOTIME */
/*     flag. */

    if (s_cmp(tout, "TICKS", tout_len, (ftnlen)5) == 0) {

/*        DP SLCKs should be simply converted to string. */

	dpfmt_(tconv, "xxxxxxxxxxxxxx.xxxxxx", linet, (ftnlen)21, linet_len);
    } else if (s_cmp(tout, "SCLK", tout_len, (ftnlen)4) == 0) {

/*        SCLK string is computed from DP SCLK if it's possible. */

	scdecd_(&sc, tconv, linet, linet_len);
	if (failed_()) {
	    s_copy(linet, "NEED LSK AND SCLK FILES", linet_len, (ftnlen)23);
	}
    } else if (s_cmp(tout, "ET", tout_len, (ftnlen)2) == 0) {

/*        Calendar ET is computed by converting DP SCLK to ET seconds */
/*        and converting them further to ET calendar string */

	sct2e_(&sc, tconv, &ettime);
	if (! failed_()) {
	    timout_(&ettime, "YYYY-MON-DD HR:MN:SC.### ::TDB", linet, (ftnlen)
		    30, linet_len);
	    if (failed_()) {
		s_copy(linet, "NEED LSK AND SCLK FILES", linet_len, (ftnlen)
			23);
	    }
	} else {
	    s_copy(linet, "NEED LSK AND SCLK FILES", linet_len, (ftnlen)23);
	}
    } else if (s_cmp(tout, "UTC", tout_len, (ftnlen)3) == 0) {

/*        UTC time is computed by converting DP SCLK to ET seconds, */
/*        which after that converted to UTC string. */

	sct2e_(&sc, tconv, &ettime);
	if (! failed_()) {
	    timout_(&ettime, "YYYY-MON-DD HR:MN:SC.###", linet, (ftnlen)24, 
		    linet_len);
	    if (failed_()) {
		s_copy(linet, "NEED LSK AND SCLK FILES", linet_len, (ftnlen)
			23);
	    }
	} else {
	    s_copy(linet, "NEED LSK AND SCLK FILES", linet_len, (ftnlen)23);
	}
    } else if (s_cmp(tout, "UTC/DOY", tout_len, (ftnlen)7) == 0) {

/*        UTCDOY time is computed by converting DP SCLK to ET seconds, */
/*        which after that converted to UTC string. */

	sct2e_(&sc, tconv, &ettime);
	if (! failed_()) {
	    timout_(&ettime, "YYYY-DOY // HR:MN:SC.###", linet, (ftnlen)24, 
		    linet_len);
	    if (failed_()) {
		s_copy(linet, "NEED LSK AND SCLK FILES", linet_len, (ftnlen)
			23);
	    }
	} else {
	    s_copy(linet, "NEED LSK AND SCLK FILES", linet_len, (ftnlen)23);
	}
    }
    ok = ! failed_();

/*     Now we can reset SPICE error handling mechanism back to its */
/*     original state. */

    reset_();
    erract_("SET", "ABORT", (ftnlen)3, (ftnlen)5);
    errprt_("SET", "DEFAULT", (ftnlen)3, (ftnlen)7);

/*     There is a bug in UNITIM (trace: SCT2E --> SCTE01 --> UNITIM) */
/*     that has to be temporarily fixed before UNITIM officially fixed */
/*     in N0049 delivery. Call to a specially written routine FIXUNI */
/*     does that. */

    if (! ok) {
	fixuni_();
    }
    return 0;
} /* timecn_ */
Esempio n. 2
0
/* $Procedure      CKWSS ( CK write segment summary ) */
/* Subroutine */ int ckwss_(integer *unit, char *segid, integer *segins, 
	integer *segfrm, integer *segtyp, integer *segrts, doublereal *segbtm,
	 doublereal *segetm, ftnlen segid_len)
{
    /* Initialized data */

    static char cktyp[80*6] = "Discrete Pointing                            "
	    "                                   " "Continuous Pointing: Const"
	    "ant Angular Velocity                                  " "Continu"
	    "ous Pointing: Linear Interpolation                              "
	    "         " "Continuous Pointing: Chebyshev, Variable Interval Le"
	    "ngth                        " "Continuous Pointing: MEX/Rosetta "
	    "Polynomial Interpolation                       " "Continuous Poi"
	    "nting: ESOC/DDID Piecewise Interpolation                        "
	    "  ";
    static char pvstat[40*2] = "Pointing Only                           " 
	    "Pointing and Angular Velocity           ";

    /* System generated locals */
    integer i__1;

    /* Builtin functions */
    /* Subroutine */ int s_copy(char *, char *, ftnlen, ftnlen);
    integer s_cmp(char *, char *, ftnlen, ftnlen), s_rnge(char *, integer, 
	    char *, integer);

    /* Local variables */
    static integer sclk;
    extern /* Subroutine */ int sct2e_(integer *, doublereal *, doublereal *);
    static doublereal beget;
    static char frame[32];
    extern /* Subroutine */ int chkin_(char *, ftnlen);
    static doublereal endet;
    extern /* Subroutine */ int repmc_(char *, char *, char *, char *, ftnlen,
	     ftnlen, ftnlen, ftnlen);
    static char lines[80*11];
    static logical found;
    extern /* Subroutine */ int repmi_(char *, char *, integer *, char *, 
	    ftnlen, ftnlen, ftnlen), bodc2n_(integer *, char *, logical *, 
	    ftnlen), et2utc_(doublereal *, char *, integer *, char *, ftnlen, 
	    ftnlen);
    extern logical failed_(void);
    extern /* Subroutine */ int scdecd_(integer *, doublereal *, char *, 
	    ftnlen), ckmeta_(integer *, char *, integer *, ftnlen);
    static char begtim[32], endtim[32], spname[32];
    extern /* Subroutine */ int frmnam_(integer *, char *, ftnlen), chkout_(
	    char *, ftnlen);
    static integer spcrft;
    extern /* Subroutine */ int writla_(integer *, char *, integer *, ftnlen);
    static char typdsc[80];
    extern logical return_(void);

/* $ Abstract */

/*     Write a segment summary for a CK segment to a Fortran logical */
/*     unit. */

/* $ Disclaimer */

/*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
/*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
/*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
/*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
/*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
/*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
/*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
/*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
/*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
/*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */

/*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
/*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
/*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
/*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
/*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
/*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */

/*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
/*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
/*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
/*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */

/* $ Required_Reading */

/*      None. */

/* $ Keywords */

/*     None. */

/* $ Declarations */
/* $ Brief_I/O */

/*     Variable  I/O  Description */
/*     --------  ---  -------------------------------------------------- */
/*      UNIT      I   The logical unit to use for writing the summary. */
/*      SEGID     I   Segment ID for a segment in a CK file. */
/*      SEGINS    I   ID for the instrument having data in a CK segment. */
/*      SEGFRM    I   Reference frame for a segment in a CK file. */
/*      SEGTYP    I   Data type for a segment in a CK file. */
/*      SEGRTS    I   Flag for velocity info in a CK segment. */
/*      SEGBTM    I   Begin time (SCLK) for a segment in a CK file. */
/*      SEGETM    I   End time (SCLK) for a segment in a CK file. */

/* $ Detailed_Input */

/*      UNIT     The Fortran logical unit on which the segment summary */
/*               is to be written. */

/*      SEGID    Segment ID for the current segment in a CK file. */

/*      SEGINS   NAIF integer ID code for the instrument having data */
/*               in the current segment in a CK file. */

/*      SEGFRM   Inertial reference frame for the current segment in a */
/*               CK file. This is the NAIF integer code for the inertial */
/*               reference frame. */

/*      SEGTYP   Data type for the current segment in a CK file. This */
/*               is an integer code which specifies the type of the data */
/*               in the current segment. */

/*      SEGRTS   Integer flag which indicates whether the segment */
/*               contains angular velocity data in addition to pointing */
/*               data, SEGRTS .EQ. 1, or just pointing data, SEGRTS .EQ. */
/*               0. */

/*      SEGBTM   The beginning encoded SCLK time for the data in the */
/*               current segment in a CK file. */

/*      SEGETM   The ending encoded SCLK time for the data in the */
/*               current segment in a CK file. */

/* $ Detailed_Output */

/*     None. */

/* $ Parameters */

/*     None. */

/* $ Exceptions */

/*     1) If an error occurs while writing to the logical unit, the error */
/*        SPICE(FILEWRITEFAILED) will be signalled. */

/*     2) If an error occurs in a routine called by this routine, this */
/*        routine will check out and return. Presumably an appropriate */
/*        error message will already have been set. */

/* $ Files */

/*     None. */

/* $ Particulars */

/*     This routine will format and display a CK segment summary in a */
/*     human compatible fashion. */

/* $ Examples */

/*     None. */

/* $ Restrictions */

/*     1) This routine performs time conversions using SCDECD, and */
/*        therefore requires that a SPICE SCLK kernel file be */
/*        loaded into the SPICELIB kernel pool before it is called. */

/*     2) This routine performs time conversions using ET2UTC, and */
/*        therefore requires that a SPICE leapseconds kernel file be */
/*        loaded into the SPICELIB kernel pool before it is called. */

/* $ Literature_References */

/*     None. */

/* $ Author_and_Institution */

/*     K.R. Gehringer (JPL) */

/* $ Version */

/* -    SPACIT Version 4.0.0,  08-MAR-2014 (NJB) */

/*        The routine was updated to handle CK type 6. */

/* -    SPACIT Version 3.0.0,  28-AUG-2002 (NJB) */

/*        The routine was updated to handle CK types 4 and 5. */

/* -    Beta Version 2.1.0,  7-FEB-1997 (WLT) */

/*        The routine was modified to use CKMETA to obtain the */
/*        spacecraft and spacecraft clock associated with a */
/*        a segment.  This replaces the old method of just dividing */
/*        by 1000. */

/* -    Beta Version 2.0.0, 24-JAN-1996 (KRG) */

/*        There have been several undocumented revisions of this */
/*        subroutine to improve its display formats and fix display bugs. */
/*        We are starting a new trend here, with the documentation of the */
/*        changes to this version. Hopefully we will continue to do so. */

/*        The changes to this version are: */

/*           Calling a new subroutien to get reference frame names, to */
/*           support the non-inertial frames software. */

/*           Fixing some display inconsistencies when body, or frame */
/*           names are not found. */

/* -    Beta Version 1.0.0, 25-FEB-1993 (KRG) */

/* -& */
/* $ Index_Entries */

/*      format and write a ck segment summary */

/* -& */

/*     SPICELIB functions */


/*     Local parameters */

/*     Set the value for the maximum output display width. */


/*     Set the maximum length for the inertial reference frame name. */


/*     Set the maximum length for a body name. */


/*     Set the precision for fractions of seconds used for UTC times */
/*     when converted from ET times. */


/*     Set the length of a time string, UTC or SCLK. */


/*     Set the maximum length of a CK data type description. */


/*     Set a value for the length of the pointing only/pointing and */
/*     angular velocity messages. */


/*     Set the maximum number of CK data types. */


/*     Set up some mnemonics for accessing the correct labels. */


/*     Set the number of output lines. */


/*     Local variables */


/*     Initial Values */


/*     Standard SPICE error handling. */

    if (return_()) {
	return 0;
    } else {
	chkin_("CKWSS", (ftnlen)5);
    }

/*     Set up the line labels. */

    s_copy(lines, "   Segment ID     : #", (ftnlen)80, (ftnlen)21);
    s_copy(lines + 160, "   Spacecraft     : Body #", (ftnlen)80, (ftnlen)26);
    s_copy(lines + 80, "   Instrument Code: #", (ftnlen)80, (ftnlen)21);
    s_copy(lines + 560, "   UTC Start Time : #", (ftnlen)80, (ftnlen)21);
    s_copy(lines + 640, "   UTC Stop Time  : #", (ftnlen)80, (ftnlen)21);
    s_copy(lines + 720, "   SCLK Start Time: #", (ftnlen)80, (ftnlen)21);
    s_copy(lines + 800, "   SCLK Stop Time : #", (ftnlen)80, (ftnlen)21);
    s_copy(lines + 240, "   Reference Frame: Frame #", (ftnlen)80, (ftnlen)27)
	    ;
    s_copy(lines + 320, "   CK Data Type   : Type #", (ftnlen)80, (ftnlen)26);
    s_copy(lines + 400, "      Description : #", (ftnlen)80, (ftnlen)21);
    s_copy(lines + 480, "   Available Data : #", (ftnlen)80, (ftnlen)21);

/*     Format the segment ID. */

    repmc_(lines, "#", segid, lines, (ftnlen)80, (ftnlen)1, segid_len, (
	    ftnlen)80);

/*     Get the spacecraft ID code from the instrument ID code by dividing */
/*     by 1000. */

    ckmeta_(segins, "SPK", &spcrft, (ftnlen)3);
    ckmeta_(segins, "SCLK", &sclk, (ftnlen)4);

/*     Format the spacecraft name and its name if we found it. */

    bodc2n_(&spcrft, spname, &found, (ftnlen)32);
    if (found) {
	repmc_(lines + 160, "#", "#, #", lines + 160, (ftnlen)80, (ftnlen)1, (
		ftnlen)4, (ftnlen)80);
	repmi_(lines + 160, "#", &spcrft, lines + 160, (ftnlen)80, (ftnlen)1, 
		(ftnlen)80);
	repmc_(lines + 160, "#", spname, lines + 160, (ftnlen)80, (ftnlen)1, (
		ftnlen)32, (ftnlen)80);
    } else {
	repmi_(lines + 160, "#", &spcrft, lines + 160, (ftnlen)80, (ftnlen)1, 
		(ftnlen)80);
    }

/*     Format the instrument name if we found it. */

    repmi_(lines + 80, "#", segins, lines + 80, (ftnlen)80, (ftnlen)1, (
	    ftnlen)80);

/*     Convert the segment start and stop times from encoded SCLK */
/*     to SCLK time strings that are human readable. */

    scdecd_(&sclk, segbtm, begtim, (ftnlen)32);
    scdecd_(&sclk, segetm, endtim, (ftnlen)32);
    if (failed_()) {
	chkout_("CKWSS", (ftnlen)5);
	return 0;
    }

/*     Format the UTC AND SCLK times. */

    repmc_(lines + 720, "#", begtim, lines + 720, (ftnlen)80, (ftnlen)1, (
	    ftnlen)32, (ftnlen)80);
    repmc_(lines + 800, "#", endtim, lines + 800, (ftnlen)80, (ftnlen)1, (
	    ftnlen)32, (ftnlen)80);

/*     Convert the segment start and stop times from encoded SCLK to ET */
/*     so that we can convert them to UTC. */

    sct2e_(&sclk, segbtm, &beget);
    sct2e_(&sclk, segetm, &endet);
    if (failed_()) {
	chkout_("CKWSS", (ftnlen)5);
	return 0;
    }

/*     Convert the segment start and stop times from ET to UTC for */
/*     human readability. */

    et2utc_(&beget, "C", &c__3, begtim, (ftnlen)1, (ftnlen)32);
    et2utc_(&endet, "C", &c__3, endtim, (ftnlen)1, (ftnlen)32);
    if (failed_()) {
	chkout_("CKWSS", (ftnlen)5);
	return 0;
    }

/*     Format the UTC times. */

    repmc_(lines + 560, "#", begtim, lines + 560, (ftnlen)80, (ftnlen)1, (
	    ftnlen)32, (ftnlen)80);
    repmc_(lines + 640, "#", endtim, lines + 640, (ftnlen)80, (ftnlen)1, (
	    ftnlen)32, (ftnlen)80);

/*     Format the inertial reference frame and its name if we found it. */

    frmnam_(segfrm, frame, (ftnlen)32);
    if (s_cmp(frame, " ", (ftnlen)32, (ftnlen)1) != 0) {
	repmc_(lines + 240, "#", "#, #", lines + 240, (ftnlen)80, (ftnlen)1, (
		ftnlen)4, (ftnlen)80);
	repmi_(lines + 240, "#", segfrm, lines + 240, (ftnlen)80, (ftnlen)1, (
		ftnlen)80);
	repmc_(lines + 240, "#", frame, lines + 240, (ftnlen)80, (ftnlen)1, (
		ftnlen)32, (ftnlen)80);
    } else {
	repmi_(lines + 240, "#", segfrm, lines + 240, (ftnlen)80, (ftnlen)1, (
		ftnlen)80);
    }

/*     Format the CK segment type and a description if we have one. */

    if (*segtyp > 6 || *segtyp < 1) {
	s_copy(typdsc, "No description for this type. Do you need a new tool"
		"kit?", (ftnlen)80, (ftnlen)56);
    } else {
	s_copy(typdsc, cktyp + ((i__1 = *segtyp - 1) < 6 && 0 <= i__1 ? i__1 :
		 s_rnge("cktyp", i__1, "ckwss_", (ftnlen)424)) * 80, (ftnlen)
		80, (ftnlen)80);
    }
    repmi_(lines + 320, "#", segtyp, lines + 320, (ftnlen)80, (ftnlen)1, (
	    ftnlen)80);
    repmc_(lines + 400, "#", typdsc, lines + 400, (ftnlen)80, (ftnlen)1, (
	    ftnlen)80, (ftnlen)80);

/*     Format the pointing / pointing and angular velocity status */

    repmc_(lines + 480, "#", pvstat + ((i__1 = *segrts) < 2 && 0 <= i__1 ? 
	    i__1 : s_rnge("pvstat", i__1, "ckwss_", (ftnlen)432)) * 40, lines 
	    + 480, (ftnlen)80, (ftnlen)1, (ftnlen)40, (ftnlen)80);

/*     Display the summary. */

    writla_(&c__11, lines, unit, (ftnlen)80);

/*     We were either successful or not on the previous write. In either */
/*     event, we want to check out and return to the caller, so there is */
/*     no need to check FAILED() here. */

    chkout_("CKWSS", (ftnlen)5);
    return 0;
} /* ckwss_ */
Esempio n. 3
0
/* $Procedure      CKCOV ( CK coverage ) */
/* Subroutine */ int ckcov_(char *ck, integer *idcode, logical *needav, char *
	level, doublereal *tol, char *timsys, doublereal *cover, ftnlen 
	ck_len, ftnlen level_len, ftnlen timsys_len)
{
    /* System generated locals */
    integer i__1;
    doublereal d__1;

    /* Builtin functions */
    integer s_cmp(char *, char *, ftnlen, ftnlen), s_rnge(char *, integer, 
	    char *, integer);

    /* Local variables */
    char arch[80];
    logical avok;
    extern /* Subroutine */ int sct2e_(integer *, doublereal *, doublereal *);
    integer i__;
    extern /* Subroutine */ int dafgs_(doublereal *);
    integer clkid;
    extern /* Subroutine */ int chkin_(char *, ftnlen);
    doublereal descr[5];
    extern /* Subroutine */ int dafus_(doublereal *, integer *, integer *, 
	    doublereal *, integer *), errch_(char *, char *, ftnlen, ftnlen);
    doublereal dctol[2];
    logical istdb, found;
    extern /* Subroutine */ int errdp_(char *, doublereal *, ftnlen);
    integer dtype;
    extern logical eqstr_(char *, char *, ftnlen, ftnlen);
    doublereal dc[2];
    integer ic[6];
    extern /* Subroutine */ int daffna_(logical *);
    extern logical failed_(void);
    extern /* Subroutine */ int dafbfs_(integer *);
    doublereal et;
    integer handle, segbeg;
    extern /* Subroutine */ int dafcls_(integer *), ckmeta_(integer *, char *,
	     integer *, ftnlen);
    integer segend;
    extern /* Subroutine */ int getfat_(char *, char *, char *, ftnlen, 
	    ftnlen, ftnlen), dafopr_(char *, integer *, ftnlen), sigerr_(char 
	    *, ftnlen);
    logical seglvl;
    extern /* Subroutine */ int chkout_(char *, ftnlen), setmsg_(char *, 
	    ftnlen), wninsd_(doublereal *, doublereal *, doublereal *), 
	    errint_(char *, integer *, ftnlen);
    char kertyp[80];
    extern logical return_(void);
    extern /* Subroutine */ int zzckcv01_(integer *, integer *, integer *, 
	    integer *, doublereal *, char *, doublereal *, ftnlen), zzckcv02_(
	    integer *, integer *, integer *, integer *, doublereal *, char *, 
	    doublereal *, ftnlen), zzckcv03_(integer *, integer *, integer *, 
	    integer *, doublereal *, char *, doublereal *, ftnlen), zzckcv04_(
	    integer *, integer *, integer *, integer *, doublereal *, char *, 
	    doublereal *, ftnlen), zzckcv05_(integer *, integer *, integer *, 
	    integer *, doublereal *, doublereal *, char *, doublereal *, 
	    ftnlen);

/* $ Abstract */

/*     Find the coverage window for a specified object in a specified CK */
/*     file. */

/* $ Disclaimer */

/*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
/*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
/*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
/*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
/*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
/*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
/*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
/*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
/*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
/*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */

/*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
/*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
/*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
/*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
/*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
/*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */

/*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
/*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
/*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
/*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */

/* $ Required_Reading */

/*     CELLS */
/*     DAF */
/*     CK */
/*     TIME */
/*     WINDOWS */

/* $ Keywords */

/*     POINTING */
/*     TIME */
/*     UTILITY */

/* $ Declarations */
/* $ Brief_I/O */

/*     Variable  I/O  Description */
/*     --------  ---  -------------------------------------------------- */
/*     CK         I   Name of CK file. */
/*     IDCODE     I   ID code of object. */
/*     NEEDAV     I   Flag indicating whether angular velocity is needed. */
/*     LEVEL      I   Coverage level:  'SEGMENT' OR 'INTERVAL'. */
/*     TOL        I   Tolerance in ticks. */
/*     TIMSYS     I   Time system used to represent coverage. */
/*     COVER     I/O  Window giving coverage for IDCODE. */

/* $ Detailed_Input */

/*     CK             is the name of a C-kernel. */

/*     IDCODE         is the integer ID code of an object, normally */
/*                    a spacecraft structure or instrument, for which */
/*                    pointing data are expected to exist in the */
/*                    specified CK file. */

/*     NEEDAV         is a logical variable indicating whether only */
/*                    segments having angular velocity are to be */
/*                    considered when determining coverage.  When */
/*                    NEEDAV is .TRUE., segments without angular */
/*                    velocity don't contribute to the coverage */
/*                    window; when NEEDAV is .FALSE., all segments for */
/*                    IDCODE may contribute to the coverage window. */


/*     LEVEL          is the level (granularity) at which the coverage */
/*                    is examined.  Allowed values and corresponding */
/*                    meanings are: */

/*                       'SEGMENT'    The output coverage window */
/*                                    contains intervals defined by the */
/*                                    start and stop times of segments */
/*                                    for the object designated by */
/*                                    IDCODE. */

/*                       'INTERVAL'   The output coverage window */
/*                                    contains interpolation intervals */
/*                                    of segments for the object */
/*                                    designated by IDCODE.  For type 1 */
/*                                    segments, which don't have */
/*                                    interpolation intervals, each */
/*                                    epoch associated with a pointing */
/*                                    instance is treated as a singleton */
/*                                    interval; these intervals are */
/*                                    added to the coverage window. */

/*                                    All interpolation intervals are */
/*                                    considered to lie within the */
/*                                    segment bounds for the purpose of */
/*                                    this summary:  if an interpolation */
/*                                    interval extends beyond the */
/*                                    segment coverage interval, only */
/*                                    its intersection with the segment */
/*                                    coverage interval is considered to */
/*                                    contribute to the total coverage. */


/*     TOL            is a tolerance value expressed in ticks of the */
/*                    spacecraft clock associated with IDCODE.  Before */
/*                    each interval is inserted into the coverage */
/*                    window, the interval is intersected with the */
/*                    segment coverage interval, then if the */
/*                    intersection is non-empty, it is expanded by TOL: */
/*                    the left endpoint of the intersection interval is */
/*                    reduced by TOL and the right endpoint is increased */
/*                    by TOL. Adjusted interval endpoints, when */
/*                    expressed as encoded SCLK, never are less than */
/*                    zero ticks.  Any intervals that overlap as a */
/*                    result of the expansion are merged. */

/*                    The coverage window returned when TOL > 0 */
/*                    indicates the coverage provided by the file to the */
/*                    CK readers CKGPAV and CKGP when that value of TOL */
/*                    is passed to them as an input. */


/*     TIMSYS         is a string indicating the time system used */
/*                    in the output coverage window.  TIMSYS may */
/*                    have the values: */

/*                        'SCLK'    Elements of COVER are expressed in */
/*                                  encoded SCLK ("ticks"), where the */
/*                                  clock is associated with the object */
/*                                  designated by IDCODE. */

/*                        'TDB'     Elements of COVER are expressed as */
/*                                  seconds past J2000 TDB. */


/*     COVER          is an initialized SPICELIB window data structure. */
/*                    COVER optionally may contain coverage data on */
/*                    input; on output, the data already present in */
/*                    COVER will be combined with coverage found for the */
/*                    object designated by IDCODE in the file CK. */

/*                    If COVER contains no data on input, its size and */
/*                    cardinality still must be initialized. */

/* $ Detailed_Output */

/*     COVER          is a SPICELIB window data structure which */
/*                    represents the merged coverage for IDCODE. When */
/*                    the coverage level is 'INTERVAL', this is the set */
/*                    of time intervals for which data for IDCODE are */
/*                    present in the file CK, merged with the set of */
/*                    time intervals present in COVER on input.  The */
/*                    merged coverage is represented as the union of one */
/*                    or more disjoint time intervals.  The window COVER */
/*                    contains the pairs of endpoints of these */
/*                    intervals. */

/*                    When the coverage level is 'SEGMENT', COVER is */
/*                    computed in a manner similar to that described */
/*                    above, but the coverage intervals used in the */
/*                    computation are those of segments rather than */
/*                    interpolation intervals within segments. */

/*                    When TOL is > 0, the intervals comprising the */
/*                    coverage window for IDCODE are expanded by TOL and */
/*                    any intervals overlapping as a result are merged. */
/*                    The resulting window is returned in COVER.  The */
/*                    expanded window in no case extends beyond the */
/*                    segment bounds in either direction by more than */
/*                    TOL. */

/*                    The interval endpoints contained in COVER are */
/*                    encoded spacecraft clock times if TIMSYS is */
/*                    'SCLK'; otherwise the times are converted from */
/*                    encoded spacecraft clock to seconds past J2000 */
/*                    TDB. */

/*                    See the Examples section below for a complete */
/*                    example program showing how to retrieve the */
/*                    endpoints from COVER. */

/* $ Parameters */

/*     None. */

/* $ Exceptions */

/*     1)  If the input file has transfer format, the error */
/*         SPICE(INVALIDFORMAT) is signaled. */

/*     2)  If the input file is not a transfer file but has architecture */
/*         other than DAF, the error SPICE(BADARCHTYPE) is signaled. */

/*     3)  If the input file is a binary DAF file of type other than */
/*         CK, the error SPICE(BADFILETYPE) is signaled. */

/*     4)  If the CK file cannot be opened or read, the error will */
/*         be diagnosed by routines called by this routine. The output */
/*         window will not be modified. */

/*     5)  If the size of the output WINDOW argument COVER is */
/*         insufficient to contain the actual number of intervals in the */
/*         coverage window for IDCODE, the error will be diagnosed by */
/*         routines called by this routine. */

/*     6)  If TOL is negative, the error SPICE(VALUEOUTOFRANGE) is */
/*         signaled. */

/*     7)  If LEVEL is not recognized, the error SPICE(INVALIDOPTION) */
/*         is signaled. */

/*     8)  If TIMSYS is not recognized, the error SPICE(NOTSUPPORTED) */
/*         is signaled. */

/*     9)  If a time conversion error occurs, the error will be */
/*         diagnosed by a routine in the call tree of this routine. */

/*     10) If the output time system is TDB, the CK subsystem must be */
/*         able to map IDCODE to the ID code of the associated */
/*         spacecraft clock.  If this mapping cannot be performed, the */
/*         error will be diagnosed by a routine in the call tree of this */
/*         routine. */

/* $ Files */

/*     This routine reads a C-kernel. */

/*     If the output time system is 'TDB', then a leapseconds kernel */
/*     and an SCLK kernel for the spacecraft clock associated with */
/*     IDCODE must be loaded before this routine is called. */

/*     If the ID code of the clock associated with IDCODE is not */
/*     equal to */

/*        IDCODE / 1000 */

/*     then the kernel variable */

/*        CK_<IDCODE>_SCLK */

/*     must be present in the kernel pool to identify the clock */
/*     associated with IDCODE.  This variable must contain the ID code */
/*     to be used for conversion between SCLK and TDB. Normally this */
/*     variable is provided in a text kernel loaded via FURNSH. */

/* $ Particulars */

/*     This routine provides an API via which applications can determine */
/*     the coverage a specified CK file provides for a specified */
/*     object. */

/* $ Examples */

/*     1)  Display the interval-level coverage for each object in a */
/*         specified CK file. Use tolerance of zero ticks. Do not */
/*         request angular velocity. Express the results in the TDB time */
/*         system. */

/*         Find the set of objects in the file. Loop over the contents */
/*         of the ID code set:  find the coverage for each item in the */
/*         set and display the coverage. */


/*              PROGRAM CKCVR */
/*              IMPLICIT NONE */

/*        C */
/*        C     SPICELIB functions */
/*        C */
/*              INTEGER               WNCARD */
/*              INTEGER               CARDI */
/*        C */
/*        C     Local parameters */
/*        C */
/*        C */
/*        C     Declare the coverage window.  Make enough room */
/*        C     for MAXIV intervals. */
/*        C */
/*              INTEGER               FILSIZ */
/*              PARAMETER           ( FILSIZ = 255 ) */

/*              INTEGER               LBCELL */
/*              PARAMETER           ( LBCELL = -5 ) */

/*              INTEGER               MAXIV */
/*              PARAMETER           ( MAXIV  = 100000 ) */

/*              INTEGER               WINSIZ */
/*              PARAMETER           ( WINSIZ = 2 * MAXIV ) */

/*              INTEGER               TIMLEN */
/*              PARAMETER           ( TIMLEN = 50 ) */

/*              INTEGER               MAXOBJ */
/*              PARAMETER           ( MAXOBJ = 1000 ) */

/*        C */
/*        C     Local variables */
/*        C */
/*              CHARACTER*(FILSIZ)    CK */
/*              CHARACTER*(FILSIZ)    LSK */
/*              CHARACTER*(FILSIZ)    SCLK */
/*              CHARACTER*(TIMLEN)    TIMSTR */

/*              DOUBLE PRECISION      B */
/*              DOUBLE PRECISION      COVER ( LBCELL : WINSIZ ) */
/*              DOUBLE PRECISION      E */

/*              INTEGER               I */
/*              INTEGER               IDS   ( LBCELL : MAXOBJ ) */
/*              INTEGER               J */
/*              INTEGER               NIV */

/*        C */
/*        C     Load a leapseconds kernel and SCLK kernel for output */
/*        C     time conversion.  Note that we assume a single spacecraft */
/*        C     clock is associated with all of the objects in the CK. */
/*        C */
/*              CALL PROMPT ( 'Name of leapseconds kernel > ', LSK  ) */
/*              CALL FURNSH ( LSK ) */

/*              CALL PROMPT ( 'Name of SCLK kernel        > ', SCLK ) */
/*              CALL FURNSH ( SCLK ) */

/*        C */
/*        C     Get name of CK file. */
/*        C */
/*              CALL PROMPT ( 'Name of CK file            > ', CK ) */

/*        C */
/*        C     Initialize the set IDS. */
/*        C */
/*              CALL SSIZEI ( MAXOBJ, IDS ) */

/*        C */
/*        C     Initialize the window COVER. */
/*        C */
/*              CALL SSIZED ( WINSIZ, COVER ) */

/*        C */
/*        C     Find the set of objects in the CK file. */
/*        C */
/*              CALL CKOBJ ( CK, IDS ) */

/*        C */
/*        C     We want to display the coverage for each object.  Loop */
/*        C     over the contents of the ID code set, find the coverage */
/*        C     for each item in the set, and display the coverage. */
/*        C */
/*              DO I = 1, CARDI( IDS ) */
/*        C */
/*        C        Find the coverage window for the current */
/*        C        object. Empty the coverage window each time */
/*        C        so we don't include data for the previous object. */
/*        C */
/*                 CALL SCARDD ( 0,   COVER ) */
/*                 CALL CKCOV  ( CK,          IDS(I),  .FALSE., */
/*             .                 'INTERVAL',  0.D0,    'TDB',    COVER ) */

/*        C */
/*        C        Get the number of intervals in the coverage */
/*        C        window. */
/*        C */
/*                 NIV = WNCARD( COVER ) */

/*        C */
/*        C        Display a simple banner. */
/*        C */
/*                 WRITE (*,*) '========================================' */
/*                 WRITE (*,*) 'Coverage for object ', IDS(I) */

/*        C */
/*        C        Convert the coverage interval start and stop */
/*        C        times to TDB calendar strings. */
/*        C */
/*                 DO J = 1, NIV */
/*        C */
/*        C           Get the endpoints of the Jth interval. */
/*        C */
/*                    CALL WNFETD ( COVER, J, B, E ) */
/*        C */
/*        C           Convert the endpoints to TDB calendar */
/*        C           format time strings and display them. */
/*        C */
/*                    CALL TIMOUT ( B, */
/*             .                    'YYYY MON DD HR:MN:SC.###### ' // */
/*             .                    '(TDB) ::TDB', */
/*             .                    TIMSTR                           ) */
/*                    WRITE (*,*) ' ' */
/*                    WRITE (*,*) 'Interval: ', J */
/*                    WRITE (*,*) 'Start:    ', TIMSTR */

/*                    CALL TIMOUT ( E, */
/*             .                    'YYYY MON DD HR:MN:SC.###### ' // */
/*             .                    '(TDB) ::TDB', */
/*             .                    TIMSTR                          ) */
/*                    WRITE (*,*) 'Stop:     ', TIMSTR */
/*                    WRITE (*,*) ' ' */

/*                 END DO */

/*                 WRITE (*,*) '========================================' */

/*              END DO */

/*              END */


/*     2)  Find the segment-level coverage for the object designated by */
/*         IDCODE provided by the set of CK files loaded via a */
/*         metakernel. (The metakernel must also specify leapseconds and */
/*         SCLK kernels.)  Use tolerance of zero ticks. Do not request */
/*         angular velocity. Express the results in the TDB time system. */

/*              PROGRAM CKMET */
/*              IMPLICIT NONE */
/*        C */
/*        C     SPICELIB functions */
/*        C */
/*              INTEGER               WNCARD */

/*        C */
/*        C     Local parameters */
/*        C */
/*              INTEGER               LBCELL */
/*              PARAMETER           ( LBCELL = -5 ) */

/*              INTEGER               FILSIZ */
/*              PARAMETER           ( FILSIZ = 255 ) */

/*              INTEGER               LNSIZE */
/*              PARAMETER           ( LNSIZE = 80 ) */

/*              INTEGER               MAXCOV */
/*              PARAMETER           ( MAXCOV = 100000 ) */

/*              INTEGER               TIMLEN */
/*              PARAMETER           ( TIMLEN = 50 ) */

/*        C */
/*        C     Local variables */
/*        C */
/*              CHARACTER*(FILSIZ)    FILE */
/*              CHARACTER*(LNSIZE)    IDCH */
/*              CHARACTER*(FILSIZ)    META */
/*              CHARACTER*(FILSIZ)    SOURCE */
/*              CHARACTER*(TIMLEN)    TIMSTR */
/*              CHARACTER*(LNSIZE)    TYPE */

/*              DOUBLE PRECISION      B */
/*              DOUBLE PRECISION      COVER  ( LBCELL : 2*MAXCOV ) */
/*              DOUBLE PRECISION      E */

/*              INTEGER               COUNT */
/*              INTEGER               HANDLE */
/*              INTEGER               I */
/*              INTEGER               IDCODE */
/*              INTEGER               NIV */

/*              LOGICAL               FOUND */

/*        C */
/*        C     Prompt for the metakernel name; load the metakernel. */
/*        C     The metakernel lists the CK files whose coverage */
/*        C     for IDCODE we'd like to determine.  The metakernel */
/*        C     must also specify a leapseconds kernel and an SCLK */
/*        C     kernel for the clock associated with IDCODE. */
/*        C */
/*              CALL PROMPT ( 'Enter name of metakernel > ', META ) */

/*              CALL FURNSH ( META ) */

/*        C */
/*        C     Get the ID code of interest. */
/*        C */
/*              CALL PROMPT ( 'Enter ID code            > ', IDCH ) */

/*              CALL PRSINT ( IDCH,  IDCODE ) */

/*        C */
/*        C     Initialize the coverage window. */
/*        C */
/*              CALL SSIZED ( MAXCOV, COVER ) */

/*        C */
/*        C     Find out how many kernels are loaded.  Loop over the */
/*        C     kernels:  for each loaded CK file, add its coverage */
/*        C     for IDCODE, if any, to the coverage window. */
/*        C */
/*              CALL KTOTAL ( 'CK', COUNT ) */

/*              DO I = 1, COUNT */

/*                 CALL KDATA ( I,       'CK',    FILE,  TYPE, */
/*             .                SOURCE,  HANDLE,  FOUND       ) */

/*                 CALL CKCOV  (  FILE,       IDCODE,  .FALSE., */
/*             .                  'SEGMENT',  0.0,     'TDB',    COVER ) */

/*              END DO */

/*        C */
/*        C     Display results. */
/*        C */
/*        C     Get the number of intervals in the coverage */
/*        C     window. */
/*        C */
/*              NIV = WNCARD( COVER ) */

/*        C */
/*        C     Display a simple banner. */
/*        C */
/*              WRITE (*,*) ' ' */
/*              WRITE (*,*) 'Coverage for object ', IDCODE */

/*        C */
/*        C     Convert the coverage interval start and stop */
/*        C     times to TDB calendar strings. */
/*        C */
/*              DO I = 1, NIV */
/*        C */
/*        C        Get the endpoints of the Ith interval. */
/*        C */
/*                 CALL WNFETD ( COVER, I, B, E ) */
/*        C */
/*        C        Convert the endpoints to TDB calendar */
/*        C        format time strings and display them. */
/*        C */
/*                 CALL TIMOUT ( B, */
/*             .                 'YYYY MON DD HR:MN:SC.###### ' // */
/*             .                 '(TDB) ::TDB', */
/*             .                 TIMSTR                           ) */
/*                 WRITE (*,*) ' ' */
/*                 WRITE (*,*) 'Interval: ', I */
/*                 WRITE (*,*) 'Start:    ', TIMSTR */

/*                 CALL TIMOUT ( E, */
/*             .                 'YYYY MON DD HR:MN:SC.###### ' // */
/*             .                 '(TDB) ::TDB', */
/*             .                 TIMSTR                           ) */
/*                 WRITE (*,*) 'Stop:     ', TIMSTR */
/*                 WRITE (*,*) ' ' */

/*              END DO */

/*              END */


/* $ Restrictions */

/*     1) When this routine is used to accumulate coverage for IDCODE */
/*        provided by multiple CK files, the inputs NEEDAV, LEVEL, TOL, */
/*        and TIMSYS  must have the same values for all files in order */
/*        for the result to be meaningful. */

/* $ Literature_References */

/*     None. */

/* $ Author_and_Institution */

/*     N.J. Bachman   (JPL) */

/* $ Version */

/* -    SPICELIB Version 1.0.1, 30-NOV-2007 (NJB) */

/*        Corrected bug in first program in header Examples section: */
/*        program now empties the coverage window prior to collecting */
/*        data for the current object. Updated examples to use WNCARD */
/*        rather than CARDD. */

/* -    SPICELIB Version 1.0.0, 07-JAN-2005 (NJB) */

/* -& */
/* $ Index_Entries */

/*     get coverage window for ck object */

/* -& */

/*     SPICELIB functions */


/*     Local parameters */


/*     Local variables */


/*     Standard SPICE error handling. */

    if (return_()) {
	return 0;
    }
    chkin_("CKCOV", (ftnlen)5);

/*     Check tolerance value. */

    if (*tol < 0.) {
	setmsg_("Tolerance must be non-negative; actual value was #.", (
		ftnlen)51);
	errdp_("#", tol, (ftnlen)1);
	sigerr_("SPICE(VALUEOUTOFRANGE)", (ftnlen)22);
	chkout_("CKCOV", (ftnlen)5);
	return 0;
    }

/*     Use a logical flag to indicate whether this is a segment-level */
/*     coverage description. */

    seglvl = eqstr_(level, "SEGMENT", level_len, (ftnlen)7);

/*     Check coverage level keyword. */

    if (! (seglvl || eqstr_(level, "INTERVAL", level_len, (ftnlen)8))) {
	setmsg_("Allowed values of LEVEL are # and #; actual value was #.", (
		ftnlen)56);
	errch_("#", "SEGMENT", (ftnlen)1, (ftnlen)7);
	errch_("#", "INTERVAL", (ftnlen)1, (ftnlen)8);
	errch_("#", level, (ftnlen)1, level_len);
	sigerr_("SPICE(INVALIDOPTION)", (ftnlen)20);
	chkout_("CKCOV", (ftnlen)5);
	return 0;
    }

/*     See whether GETFAT thinks we've got a CK file. */

    getfat_(ck, arch, kertyp, ck_len, (ftnlen)80, (ftnlen)80);
    if (s_cmp(arch, "XFR", (ftnlen)80, (ftnlen)3) == 0) {
	setmsg_("Input file # has architecture #. The file must be a binary "
		"CK file to be readable by this routine.  If the input file i"
		"s an CK file in transfer format, run TOBIN on the file to co"
		"nvert it to binary format.", (ftnlen)205);
	errch_("#", ck, (ftnlen)1, ck_len);
	errch_("#", arch, (ftnlen)1, (ftnlen)80);
	sigerr_("SPICE(INVALIDFORMAT)", (ftnlen)20);
	chkout_("CKCOV", (ftnlen)5);
	return 0;
    } else if (s_cmp(arch, "DAF", (ftnlen)80, (ftnlen)3) != 0) {
	setmsg_("Input file # has architecture #. The file must be a binary "
		"CK file to be readable by this routine.  Binary CK files hav"
		"e DAF architecture.  If you expected the file to be a binary"
		" CK file, the problem may be due to the file being an old no"
		"n-native file lacking binary file format information. It's a"
		"lso possible the file has been corrupted.", (ftnlen)340);
	errch_("#", ck, (ftnlen)1, ck_len);
	errch_("#", arch, (ftnlen)1, (ftnlen)80);
	sigerr_("SPICE(INVALIDARCHTYPE)", (ftnlen)22);
	chkout_("CKCOV", (ftnlen)5);
	return 0;
    } else if (s_cmp(kertyp, "CK", (ftnlen)80, (ftnlen)2) != 0) {
	setmsg_("Input file # has file type #. The file must be a binary CK "
		"file to be readable by this routine. If you expected the fil"
		"e to be a binary CK file, the problem may be due to the file"
		" being an old non-native file lacking binary file format inf"
		"ormation. It's also possible the file has been corrupted.", (
		ftnlen)296);
	errch_("#", ck, (ftnlen)1, ck_len);
	errch_("#", kertyp, (ftnlen)1, (ftnlen)80);
	sigerr_("SPICE(INVALIDFILETYPE)", (ftnlen)22);
	chkout_("CKCOV", (ftnlen)5);
	return 0;
    }

/*     Set a logical flag indicating whether the time systm is SCLK. */

    istdb = eqstr_(timsys, "TDB", timsys_len, (ftnlen)3);

/*     Check time system. */

    if (! istdb) {
	if (! eqstr_(timsys, "SCLK", timsys_len, (ftnlen)4)) {
	    setmsg_("Time system spec TIMSYS was #; allowed values are SCLK "
		    "and TDB.", (ftnlen)63);
	    errch_("#", timsys, (ftnlen)1, timsys_len);
	    sigerr_("SPICE(NOTSUPPORTED)", (ftnlen)19);
	    chkout_("CKCOV", (ftnlen)5);
	    return 0;
	}
    }

/*     If the output time system is TDB, find the clock ID associated */
/*     with IDCODE. */

    if (istdb) {
	ckmeta_(idcode, "SCLK", &clkid, (ftnlen)4);
	if (failed_()) {
	    chkout_("CKCOV", (ftnlen)5);
	    return 0;
	}
    }

/*     Open the file for reading. */

    dafopr_(ck, &handle, ck_len);
    if (failed_()) {
	chkout_("CKCOV", (ftnlen)5);
	return 0;
    }

/*     We will examine each segment descriptor in the file, and */
/*     we'll update our coverage bounds according to the data found */
/*     in these descriptors. */

/*     If TOL > 0, we'll apply TOL after we've found the coverage */
/*     for the zero-tolerance case. */

/*     If the time system is TDB, we'll convert the times to TDB */
/*     at the end of this routine. */

/*     Start a forward search. */

    dafbfs_(&handle);

/*     Find the next DAF array. */

    daffna_(&found);
    while(found) {

/*        Note:  we check FAILED() at the bottom of this loop; this */
/*        routine returns if FAILED() returns .TRUE. at that point. */

/*        Fetch and unpack the segment descriptor. */

	dafgs_(descr);
	dafus_(descr, &c__2, &c__6, dc, ic);

/*        Let AVOK indicate whether the segment satisfies the */
/*        angular velocity restriction. */

	avok = ic[3] == 1 || ! (*needav);
	if (ic[0] == *idcode && avok) {

/*           This segment is for the body of interest.  If angular */
/*           velocity is needed, this segment has it. */

	    if (seglvl) {

/*              This is a segment-level summary. */

/*              Insert the coverage bounds into the coverage window. */
/*              Adjust the interval using the tolerance. */

/* Computing MAX */
		d__1 = dc[0] - *tol;
		dctol[0] = max(d__1,0.);
		dctol[1] = dc[1] + *tol;

/*              Convert the time to TDB if necessary. */

		if (istdb) {

/*                 Convert the time bounds to TDB before inserting */
/*                 into the window. */

		    for (i__ = 1; i__ <= 2; ++i__) {
			sct2e_(&clkid, &dctol[(i__1 = i__ - 1) < 2 && 0 <= 
				i__1 ? i__1 : s_rnge("dctol", i__1, "ckcov_", 
				(ftnlen)868)], &et);
			dctol[(i__1 = i__ - 1) < 2 && 0 <= i__1 ? i__1 : 
				s_rnge("dctol", i__1, "ckcov_", (ftnlen)869)] 
				= et;
		    }
		}
		if (dctol[0] <= dctol[1]) {
		    wninsd_(dctol, &dctol[1], cover);
		}
	    } else {

/*              We're looking for an interval-level coverage window. */
/*              This information must be retrieved in a */
/*              data-type-dependent fashion.  The coverage routines */
/*              we'll call will, if necessary, adjust intervals by TOL */
/*              and convert interval times to TDB. */

		dtype = ic[2];
		segbeg = ic[4];
		segend = ic[5];
		if (dtype == 1) {
		    zzckcv01_(&handle, &segbeg, &segend, &clkid, tol, timsys, 
			    cover, timsys_len);
		} else if (dtype == 2) {
		    zzckcv02_(&handle, &segbeg, &segend, &clkid, tol, timsys, 
			    cover, timsys_len);
		} else if (dtype == 3) {
		    zzckcv03_(&handle, &segbeg, &segend, &clkid, tol, timsys, 
			    cover, timsys_len);
		} else if (dtype == 4) {
		    zzckcv04_(&handle, &segbeg, &segend, &clkid, tol, timsys, 
			    cover, timsys_len);
		} else if (dtype == 5) {

/*                 Note:  this calling sequence is exceptional; the */
/*                 segment bounds are an input. */

		    zzckcv05_(&handle, &segbeg, &segend, &clkid, dc, tol, 
			    timsys, cover, timsys_len);
		} else {
		    setmsg_("Supported CK data types are 1, 2, 3, 4, 5.  Dat"
			    "a type of segment: #. This problem may indicate "
			    "that you need to update your SPICE Toolkit.", (
			    ftnlen)138);
		    errint_("#", &dtype, (ftnlen)1);
		    sigerr_("SPICE(NOTSUPPORTED)", (ftnlen)19);
		    chkout_("CKCOV", (ftnlen)5);
		    return 0;
		}
	    }
	}
	daffna_(&found);
	if (failed_()) {
	    chkout_("CKCOV", (ftnlen)5);
	    return 0;
	}
    }

/*     COVER now represents the coverage of the entire file at the */
/*     granularity indicated by LEVEL, combined with the coverage */
/*     contained in COVER on input. */

/*     Release the file. */

    dafcls_(&handle);
    chkout_("CKCOV", (ftnlen)5);
    return 0;
} /* ckcov_ */
Esempio n. 4
0
/* $Procedure      CKGP ( C-kernel, get pointing ) */
/* Subroutine */ int ckgp_(integer *inst, doublereal *sclkdp, doublereal *tol,
	 char *ref, doublereal *cmat, doublereal *clkout, logical *found, 
	ftnlen ref_len)
{
    logical pfnd, sfnd;
    integer sclk;
    extern /* Subroutine */ int sct2e_(integer *, doublereal *, doublereal *);
    integer type1, type2;
    char segid[40];
    extern /* Subroutine */ int chkin_(char *, ftnlen);
    doublereal descr[5];
    extern /* Subroutine */ int dafus_(doublereal *, integer *, integer *, 
	    doublereal *, integer *), ckbss_(integer *, doublereal *, 
	    doublereal *, logical *), ckpfs_(integer *, doublereal *, 
	    doublereal *, doublereal *, logical *, doublereal *, doublereal *,
	     doublereal *, logical *), moved_(doublereal *, integer *, 
	    doublereal *), cksns_(integer *, doublereal *, char *, logical *, 
	    ftnlen);
    logical gotit;
    extern logical failed_(void);
    doublereal av[3], et;
    integer handle;
    extern /* Subroutine */ int refchg_(integer *, integer *, doublereal *, 
	    doublereal *);
    logical needav;
    extern /* Subroutine */ int ckmeta_(integer *, char *, integer *, ftnlen);
    integer refseg, center;
    extern /* Subroutine */ int namfrm_(char *, integer *, ftnlen), frinfo_(
	    integer *, integer *, integer *, integer *, logical *);
    integer refreq, typeid;
    extern /* Subroutine */ int chkout_(char *, ftnlen);
    doublereal tmpmat[9]	/* was [3][3] */;
    extern logical return_(void);
    doublereal dcd[2];
    integer icd[6];
    extern /* Subroutine */ int mxm_(doublereal *, doublereal *, doublereal *)
	    ;
    doublereal rot[9]	/* was [3][3] */;

/* $ Abstract */

/*     Get pointing (attitude) for a specified spacecraft clock time. */

/* $ Disclaimer */

/*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
/*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
/*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
/*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
/*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
/*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
/*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
/*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
/*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
/*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */

/*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
/*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
/*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
/*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
/*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
/*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */

/*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
/*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
/*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
/*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */

/* $ Required_Reading */

/*     CK */
/*     SCLK */

/* $ Keywords */

/*     POINTING */

/* $ Declarations */
/* $ Abstract */

/*     The parameters below form an enumerated list of the recognized */
/*     frame types.  They are: INERTL, PCK, CK, TK, DYN.  The meanings */
/*     are outlined below. */

/* $ Disclaimer */

/*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
/*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
/*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
/*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
/*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
/*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
/*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
/*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
/*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
/*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */

/*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
/*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
/*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
/*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
/*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
/*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */

/*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
/*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
/*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
/*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */

/* $ Parameters */

/*     INERTL      an inertial frame that is listed in the routine */
/*                 CHGIRF and that requires no external file to */
/*                 compute the transformation from or to any other */
/*                 inertial frame. */

/*     PCK         is a frame that is specified relative to some */
/*                 INERTL frame and that has an IAU model that */
/*                 may be retrieved from the PCK system via a call */
/*                 to the routine TISBOD. */

/*     CK          is a frame defined by a C-kernel. */

/*     TK          is a "text kernel" frame.  These frames are offset */
/*                 from their associated "relative" frames by a */
/*                 constant rotation. */

/*     DYN         is a "dynamic" frame.  These currently are */
/*                 parameterized, built-in frames where the full frame */
/*                 definition depends on parameters supplied via a */
/*                 frame kernel. */

/* $ Author_and_Institution */

/*     N.J. Bachman    (JPL) */
/*     W.L. Taber      (JPL) */

/* $ Literature_References */

/*     None. */

/* $ Version */

/* -    SPICELIB Version 3.0.0, 28-MAY-2004 (NJB) */

/*       The parameter DYN was added to support the dynamic frame class. */

/* -    SPICELIB Version 2.0.0, 12-DEC-1996 (WLT) */

/*        Various unused frames types were removed and the */
/*        frame time TK was added. */

/* -    SPICELIB Version 1.0.0, 10-DEC-1995 (WLT) */

/* -& */
/* $ Brief_I/O */

/*     Variable  I/O  Description */
/*     --------  ---  -------------------------------------------------- */
/*     INST       I   NAIF ID of instrument, spacecraft, or structure. */
/*     SCLKDP     I   Encoded spacecraft clock time. */
/*     TOL        I   Time tolerance. */
/*     REF        I   Reference frame. */
/*     CMAT       O   C-matrix pointing data. */
/*     CLKOUT     O   Output encoded spacecraft clock time. */
/*     FOUND      O   True when requested pointing is available. */

/* $ Detailed_Input */

/*     INST       is the NAIF integer ID for the instrument, spacecraft, */
/*                or other structure for which pointing is requested. */
/*                For brevity we will refer to this object as the */
/*                "instrument," and the frame fixed to this object as */
/*                the "instrument frame" or "instrument-fixed" frame. */

/*     SCLKDP     is the encoded spacecraft clock time for which */
/*                pointing is requested. */

/*                The SPICELIB routines SCENCD and SCE2C respectively */
/*                convert spacecraft clock strings and ephemeris time to */
/*                encoded spacecraft clock.  The inverse conversions are */
/*                performed by SCDECD and SCT2E. */

/*     TOL        is a time tolerance in ticks, the units of encoded */
/*                spacecraft clock time. */

/*                The SPICELIB routine SCTIKS converts a spacecraft */
/*                clock tolerance duration from its character string */
/*                representation to ticks.  SCFMT performs the inverse */
/*                conversion. */

/*                The C-matrix returned by CKGP is the one whose time */
/*                tag is closest to SCLKDP and within TOL units of */
/*                SCLKDP.  (More in Particulars, below.) */

/*                In general, because using a non-zero tolerance */
/*                affects selection of the segment from which the */
/*                data is obtained, users are strongly discouraged */
/*                from using a non-zero tolerance when reading CKs */
/*                with continuous data. Using a non-zero tolerance */
/*                should be reserved exclusively to reading CKs with */
/*                discrete data because in practice obtaining data */
/*                from such CKs using a zero tolerance is often not */
/*                possible due to time round off. */

/*     REF        is the desired reference frame for the returned */
/*                pointing.  The returned C-matrix CMAT gives the */
/*                orientation of the instrument designated by INST */
/*                relative to the frame designated by REF.  When a */
/*                vector specified relative to frame REF is left- */
/*                multiplied by CMAT, the vector is rotated to the */
/*                frame associated with INST.  See the discussion of */
/*                CMAT below for details. */

/*                Consult the SPICE document "Frames" for a discussion */
/*                of supported reference frames. */

/* $ Detailed_Output */

/*     CMAT       is a rotation matrix that transforms the components of */
/*                a vector expressed in the reference frame specified by */
/*                REF to components expressed in the frame tied to the */
/*                instrument, spacecraft, or other structure at time */
/*                CLKOUT (see below). */

/*                Thus, if a vector v has components x,y,z in the REF */
/*                reference frame, then v has components x',y',z' in the */
/*                instrument fixed frame at time CLKOUT: */

/*                     [ x' ]     [          ] [ x ] */
/*                     | y' |  =  |   CMAT   | | y | */
/*                     [ z' ]     [          ] [ z ] */

/*                If you know x', y', z', use the transpose of the */
/*                C-matrix to determine x, y, z as follows: */

/*                     [ x ]      [          ]T    [ x' ] */
/*                     | y |  =   |   CMAT   |     | y' | */
/*                     [ z ]      [          ]     [ z' ] */
/*                              (Transpose of CMAT) */


/*     CLKOUT     is the encoded spacecraft clock time associated with */
/*                the returned C-matrix. This value may differ from the */
/*                requested time, but never by more than the input */
/*                tolerance TOL. */

/*                The particulars section below describes the search */
/*                algorithm used by CKGP to satisfy a pointing */
/*                request.  This algorithm determines the pointing */
/*                instance (and therefore the associated time value) */
/*                that is returned. */

/*     FOUND      is true if a record was found to satisfy the pointing */
/*                request.  FOUND will be false otherwise. */

/* $ Parameters */

/*     None. */

/* $ Exceptions */

/*     1)  If a C-kernel file has not been loaded using FURNSH prior to */
/*         a call to this routine, an error is signaled by a routine in */
/*         the call tree of this routine. */

/*     2)  If TOL is negative, found is set to .FALSE. */

/*     3)  If REF is not a supported reference frame, an error is */
/*         signaled by a routine in the call tree of this routine and */
/*         FOUND is set to .FALSE. */

/* $ Files */

/*     CKGP searches through files loaded by FURNSH to locate a */
/*     segment that can satisfy the request for pointing for instrument */
/*     INST at time SCLKDP.  You must load a C-kernel file using FURNSH */
/*     prior to calling this routine. */

/* $ Particulars */

/*     How the tolerance argument is used */
/*     ================================== */


/*     Reading a type 1 CK segment (discrete pointing instances) */
/*     --------------------------------------------------------- */

/*     In the diagram below */

/*        - "0" is used to represent discrete pointing instances */
/*          (quaternions and associated time tags). */

/*        - "( )" are used to represent the end points of the time */
/*          interval covered by a segment in a CK file. */

/*        - SCLKDP is the time at which you requested pointing. */
/*          The location of SCLKDP relative to the time tags of the */
/*          pointing instances is indicated by the "+" sign. */

/*        - TOL is the time tolerance specified in the pointing */
/*          request.  The square brackets "[ ]" represent the */
/*          endpoints of the time interval */

/*             SCLKDP-TOL : SCLKDP+TOL */

/*        - The quaternions occurring in the segment need not be */
/*          evenly spaced in time. */


/*     Case 1:  pointing is available */
/*     ------------------------------ */

/*                              SCLKDP */
/*                                   \   TOL */
/*                                    | / */
/*                                    |/\ */
/*     Your request                [--+--] */
/*                                 .  .  . */
/*     Segment      (0-----0--0--0--0--0--0---0--0------------0--0--0--0) */
/*                                     ^ */
/*                                     | */
/*                         CKGP returns this instance. */


/*     Case 2:  pointing is not available */
/*     ---------------------------------- */

/*                                                   SCLKDP */
/*                                                      \   TOL */
/*                                                       | / */
/*                                                       |/\ */
/*     Your request                                   [--+--] */
/*                                                    .  .  . */
/*     Segment      (0-----0--0--0--0--0--0---0--0--0---------0--0--0--0) */


/*                         CKGP returns no pointing; the output */
/*                         FOUND flag is set to .FALSE. */



/*     Reading a type 2, 3, 4, or 5 CK segment (continuous pointing) */
/*     ------------------------------------------------------------- */

/*     In the diagrams below */

/*        - "==" is used to represent periods of continuous pointing. */

/*        - "--" is used to represent gaps in the pointing coverage. */

/*        - "( )" are used to represent the end points of the time */
/*          interval covered by a segment in a CK file. */

/*        - SCLKDP is the time at which you requested pointing. */
/*          The location of SCLKDP relative to the time tags of the */
/*          pointing instances is indicated by the "+" sign. */

/*        - TOL is the time tolerance specified in the pointing */
/*          request.  The square brackets "[ ]" represent the */
/*          endpoints of the time interval */

/*             SCLKDP-TOL : SCLKDP+TOL */

/*        - The quaternions occurring in the periods of continuous */
/*          pointing need not be evenly spaced in time. */


/*     Case 1:  pointing is available at the request time */
/*     -------------------------------------------------- */

/*                             SCLKDP */
/*                                   \   TOL */
/*                                    | / */
/*                                    |/\ */
/*     Your request                [--+--] */
/*                                 .  .  . */
/*                                 .  .  . */
/*                                 .  .  . */
/*     Segment            (==---===========---=======----------===--) */
/*                                    ^ */
/*                                    | */

/*                   The request time lies within an interval where */
/*                   continuous pointing is available. CKGP returns */
/*                   pointing at the requested epoch. */


/*     Case 2:  pointing is available "near" the request time */
/*     ------------------------------------------------------ */

/*                                    SCLKDP */
/*                                          \   TOL */
/*                                           | / */
/*                                           |/\ */
/*     Your request                       [--+--] */
/*                                        .  .  . */
/*     Segment            (==---===========----=======---------===--) */
/*                                             ^ */
/*                                             | */

/*                   The request time lies in a gap:  an interval where */
/*                   continuous pointing is *not* available.  CKGP */
/*                   returns pointing for the epoch closest to the */
/*                   request time SCLKDP. */


/*     Case 3:  pointing is not available */
/*     ---------------------------------- */

/*                                                 SCLKDP */
/*                                                       \   TOL */
/*                                                        | / */
/*                                                        |/\ */
/*     Your request                                    [--+--] */
/*                                                     .  .  . */
/*     Segment            (==---===========----=======---------===--) */

/*                         CKGP returns no pointing; the output */
/*                         FOUND flag is set to .FALSE. */



/*     Tolerance and segment priority */
/*     ============================== */

/*     CKGP searches through loaded C-kernels to satisfy a pointing */
/*     request. Last-loaded files are searched first. Individual files */
/*     are searched in backwards order, so that between competing */
/*     segments (segments containing data for the same object, for */
/*     overlapping time ranges), the one closest to the end of the file */
/*     has highest priority. */

/*     The search ends when a segment is found that can provide pointing */
/*     for the specified instrument at a time falling within the */
/*     specified tolerance on either side of the request time. Within */
/*     that segment, the instance closest to the input time is located */
/*     and returned. */

/*     The following four cases illustrate this search procedure. */
/*     Segments A and B are in the same file, with segment A located */
/*     further towards the end of the file than segment B. Both segments */
/*     A and B contain discrete pointing data, indicated by the number */
/*     0. */


/*     Case 1:  Pointing is available in the first segment searched. */
/*              Because segment A has the highest priority and can */
/*              satisfy the request, segment B is not searched. */


/*                                  SCLKDP */
/*                                        \  TOL */
/*                                         | / */
/*                                         |/\ */
/*     Your request                     [--+--] */
/*                                      .  .  . */
/*     Segment A          (0-----------------0--------0--0-----0) */
/*                                           ^ */
/*                                           | */
/*                                           | */
/*                               CKGP returns this instance */

/*     Segment B     (0--0--0--0--0--0--0--0--0--0--0--0--0--0--0--0--0) */



/*     Case 2:  Pointing is not available in the first segment searched. */
/*              Because segment A cannot satisfy the request, segment B */
/*              is searched. */


/*                             SCLKDP */
/*                                  \   TOL */
/*                                   | / */
/*                                   |/\ */
/*     Your request               [--+--] */
/*                                .  .  . */
/*     Segment A          (0-----------------0--------0--0-----0) */
/*                                .  .  . */
/*     Segment B     (0--0--0--0--0--0--0--0--0--0--0--0--0--0--0--0--0) */
/*                                   ^ */
/*                                   | */
/*                       CKGP returns this instance */


/*     Segments that contain continuous pointing data are searched in */
/*     the same manner as segments containing discrete pointing data. */
/*     For request times that fall within the bounds of continuous */
/*     intervals, CKGP will return pointing at the request time. When */
/*     the request time does not fall within an interval, then a time at */
/*     an endpoint of an interval may be returned if it is the closest */
/*     time in the segment to the user request time and is also within */
/*     the tolerance. */

/*     In the following examples, segment A is located further towards */
/*     the end of the file than segment C. Segment A contains discrete */
/*     pointing data and segment C contains continuous data, indicated */
/*     by the "=" character. */


/*     Case 3:  Pointing is not available in the first segment searched. */
/*              Because segment A cannot satisfy the request, segment C */
/*              is searched. */

/*                             SCLKDP */
/*                                   \  TOL */
/*                                    | / */
/*                                    |/\ */
/*     Your request                [--+--] */
/*                                 .  .  . */
/*                                 .  .  . */
/*     Segment A          (0-----------------0--------0--0-----0) */
/*                                 .  .  . */
/*                                 .  .  . */
/*     Segment C          (---=============-----====--------==--) */
/*                                    ^ */
/*                                    | */
/*                                    | */
/*                         CKGP returns this instance */


/*     In the next case, assume that the order of segments A and C in the */
/*     file is reversed:  A is now closer to the front, so data from */
/*     segment C are considered first. */


/*     Case 4:  Pointing is available in the first segment searched. */
/*              Because segment C has the highest priority and can */
/*              satisfy the request, segment A is not searched. */

/*                                             SCLKDP */
/*                                            / */
/*                                           |  TOL */
/*                                           | / */
/*                                           |/\ */
/*     Your request                       [--+--] */
/*                                        .  .  . */
/*                                        .  .  . */
/*     Segment C          (---=============-----====--------==--) */
/*                                             ^ */
/*                                             | */
/*                                CKGP returns this instance */

/*     Segment A          (0-----------------0--------0--0-----0) */
/*                                           ^ */
/*                                           | */
/*                                     "Best" answer */


/*     The next case illustrates an unfortunate side effect of using */
/*     a non-zero tolerance when reading multi-segment CKs with */
/*     continuous data. In all cases when the look-up interval */
/*     formed using tolerance overlaps a segment boundary and */
/*     the request time falls within the coverage of the lower */
/*     priority segment, the data at the end of the higher priority */
/*     segment will be picked instead of the data from the lower */
/*     priority segment. */


/*     Case 5:  Pointing is available in the first segment searched. */
/*              Because segment C has the highest priority and can */
/*              satisfy the request, segment A is not searched. */

/*                                             SCLKDP */
/*                                            / */
/*                                           |  TOL */
/*                                           | / */
/*                                           |/\ */
/*     Your request                       [--+--] */
/*                                        .  .  . */
/*                                        .  .  . */
/*     Segment C                                (===============) */
/*                                              ^ */
/*                                              | */
/*                                CKGP returns this instance */

/*     Segment A          (=====================) */
/*                                           ^ */
/*                                           | */
/*                                     "Best" answer */

/* $ Examples */

/*     Suppose you have two C-kernel files containing data for the */
/*     Voyager 2 narrow angle camera.  One file contains predict values, */
/*     and the other contains corrected pointing for a selected group */
/*     of images, that is, for a subset of images from the first file. */

/*     The following example program uses CKGP to get C-matrices for a */
/*     set of images whose SCLK counts (un-encoded character string */
/*     versions) are contained in the array SCLKCH. */

/*     If available, the program will get the corrected pointing values. */
/*     Otherwise, predict values will be used. */

/*     For each C-matrix, a unit  pointing vector is constructed */
/*     and printed. */


/*     C */
/*     C     Constants for this program. */
/*     C */
/*     C     -- The code for the Voyager 2 spacecraft clock is -32 */
/*     C */
/*     C     -- The code for the narrow angle camera on the Voyager 2 */
/*     C        spacecraft is -32001. */
/*     C */
/*     C    --  Spacecraft clock times for successive Voyager images */
/*     C        always differ by more than 0:0:400.  This is an */
/*     C        acceptable tolerance, and must be converted to "ticks" */
/*     C        (units of encoded SCLK) for input to CKGP. */
/*     C */
/*     C     -- The reference frame we want is FK4. */
/*     C */
/*     C     -- The narrow angle camera boresight defines the third */
/*     C        axis of the instrument-fixed coordinate system. */
/*     C        Therefore, the vector ( 0, 0, 1 ) represents */
/*     C        the boresight direction in the camera-fixed frame. */
/*     C */
/*           IMPLICIT NONE */

/*           INTEGER               FILEN */
/*           PARAMETER           ( FILEN  = 255 ) */

/*           INTEGER               NPICS */
/*           PARAMETER           ( NPICS  = 2 ) */

/*           INTEGER               TIMLEN */
/*           PARAMETER           ( TIMLEN = 30 ) */

/*           INTEGER               REFLEN */
/*           PARAMETER           ( REFLEN = 32 ) */

/*           CHARACTER*(TIMLEN)    CLKCH */
/*           CHARACTER*(FILEN)     CKPRED */
/*           CHARACTER*(FILEN)     CKCORR */
/*           CHARACTER*(REFLEN)    REF */
/*           CHARACTER*(FILEN)     SCLK */
/*           CHARACTER*(TIMLEN)    SCLKCH ( NPICS ) */
/*           CHARACTER*(TIMLEN)    TOLVGR */

/*           DOUBLE PRECISION      CLKOUT */
/*           DOUBLE PRECISION      CMAT   ( 3, 3 ) */
/*           DOUBLE PRECISION      SCLKDP */
/*           DOUBLE PRECISION      TOLTIK */
/*           DOUBLE PRECISION      VCFIX  ( 3 ) */
/*           DOUBLE PRECISION      VINERT ( 3 ) */

/*           INTEGER               SC */
/*           INTEGER               I */
/*           INTEGER               INST */

/*           LOGICAL               FOUND */

/*           CKPRED     = 'voyager2_predict.bc' */
/*           CKCORR     = 'voyager2_corrected.bc' */
/*           SCLK       = 'voyager2_sclk.tsc' */
/*           SC         = -32 */
/*           INST       = -32001 */
/*           SCLKCH(1)  = '4/08966:30:768' */
/*           SCLKCH(2)  = '4/08970:58:768' */
/*           TOLVGR     = '0:0:400' */
/*           REF        = 'FK4' */
/*           VCFIX( 1 ) =  0.D0 */
/*           VCFIX( 2 ) =  0.D0 */
/*           VCFIX( 3 ) =  1.D0 */

/*     C */
/*     C     Loading the files in this order ensures that the */
/*     C     corrected file will get searched first. */
/*     C */
/*           CALL FURNSH ( CKPRED ) */
/*           CALL FURNSH ( CKCORR ) */

/*     C */
/*     C     Need to load a Voyager 2 SCLK kernel to convert from */
/*     C     clock strings to ticks. */
/*     C */
/*           CALL FURNSH ( SCLK ) */

/*     C */
/*     C     Convert tolerance from VGR formatted character string */
/*     C     SCLK to ticks which are units of encoded SCLK. */
/*     C */
/*           CALL SCTIKS ( SC, TOLVGR, TOLTIK ) */


/*           DO I = 1, NPICS */
/*     C */
/*     C        CKGP requires encoded spacecraft clock. */
/*     C */
/*              CALL SCENCD ( SC, SCLKCH( I ), SCLKDP ) */

/*              CALL CKGP ( INST,   SCLKDP, TOLTIK, REF, CMAT, */
/*          .               CLKOUT, FOUND                      ) */

/*              IF ( FOUND ) THEN */

/*     C */
/*     C           Use the transpose of the C-matrix to transform the */
/*     C           boresight vector from camera-fixed to reference */
/*     C           coordinates. */
/*     C */
/*                 CALL MTXV   ( CMAT, VCFIX,  VINERT ) */
/*                 CALL SCDECD ( SC,   CLKOUT, CLKCH  ) */

/*                 WRITE (*,*) 'VGR 2 SCLK Time:         ', CLKCH */
/*                 WRITE (*,*) 'VGR 2 NA ISS boresight ' */
/*          .      //          'pointing vector: ',         VINERT */

/*              ELSE */

/*                 WRITE (*,*) 'Pointing not found for time ', SCLKCH(I) */

/*              END IF */

/*           END DO */

/*           END */


/* $ Restrictions */

/*     None. */

/* $ Literature_References */

/*     None. */

/* $ Author_and_Institution */

/*     C.H. Acton     (JPL) */
/*     N.J. Bachman   (JPL) */
/*     W.L. Taber     (JPL) */
/*     J.M. Lynch     (JPL) */
/*     B.V. Semenov   (JPL) */
/*     M.J. Spencer   (JPL) */
/*     R.E. Thurman   (JPL) */
/*     I.M. Underwood (JPL) */

/* $ Version */

/* -    SPICELIB Version 5.3.1, 09-JUN-2010 (BVS) */

/*        Header update: description of the tolerance and Particulars */
/*        section were expanded to address some problems arising from */
/*        using a non-zero tolerance. */

/* -    SPICELIB Version 5.3.0, 23-APR-2010 (NJB) */

/*        Bug fix: this routine now obtains the rotation */
/*        from the request frame to the applicable CK segment's */
/*        base frame via a call to REFCHG. Formerly the routine */
/*        used FRMCHG, which required that angular velocity data */
/*        be available for this transformation. */

/* -    SPICELIB Version 5.2.0, 25-AUG-2005 (NJB) */

/*        Updated to remove non-standard use of duplicate arguments */
/*        in MXM call. */

/* -    SPICELIB Version 5.1.2, 29-JAN-2004 (NJB) */

/*        Header update:  description of input argument REF was */
/*        expanded. */

/* -    SPICELIB Version 5.1.1, 27-JUL-2003 (CHA) (NJB) */

/*        Various header corrections were made. */

/* -    SPICELIB Version 3.2.0, 23-FEB-1999 (WLT) */

/*        The previous editions of this routine did not properly handle */
/*        the case when TOL was negative.  The routine now returns a */
/*        value of .FALSE. for FOUND as is advertised above. */

/* -    SPICELIB Version 3.1.0, 13-APR-1998 (WLT) */

/*        The call to CHKOUT in the case when FAILED returned the */
/*        value TRUE used to check out with the name 'CKGPAV'.  This */
/*        has been changed to a CKGP. */

/* -    SPICELIB Version 3.0.0, 19-SEP-1994 (WLT) */

/*        The routine was upgraded to support non-inertial frames. */

/* -    SPICELIB Version 2.0.1, 10-MAR-1992 (WLT) */

/*        Comment section for permuted index source lines was added */
/*        following the header. */

/* -    SPICELIB Version 2.0.0, 30-AUG-1991 (JML) */

/*        The Particulars section was updated to show how the */
/*        search algorithm processes segments with continuous */
/*        pointing data. */

/*        The example program now loads an SCLK kernel. */

/*        FAILED is checked after the call to IRFROT to handle the */
/*        case where the reference frame is invalid and the error */
/*        handling is not set to abort. */

/*        FAILED is checked in the DO WHILE loop to handle the case */
/*        where an error is detected by a SPICELIB routine inside the */
/*        loop and the error handling is not set to abort. */

/* -    SPICELIB Version 1.0.1, 02-NOV-1990 (JML) */

/*        The restriction that a C-kernel file must be loaded */
/*        was explicitly stated. */


/* -    SPICELIB Version 1.0.0, 07-SEP-1990 (RET) (IMU) */

/* -& */
/* $ Index_Entries */

/*     get ck pointing */

/* -& */
/* $ Revisions */

/* -    SPICELIB Version 5.2.0, 25-AUG-2005 (NJB) */

/*        Updated to remove non-standard use of duplicate arguments */
/*        in MXM call. */

/* -    SPICELIB Version 3.1.0, 20-DEC-1995 (WLT) */

/*        A call to FRINFO did not have enough arguments and */
/*        went undetected until Howard Taylor of ACT.  Many */
/*        thanks go out to Howard for tracking down this error. */

/* -    SPICELIB Version 3.0.0, 19-SEP-1994 (WLT) */

/*        The routine was upgraded to support non-inertial frames. */

/*        Calls to NAMIRF and IRFROT were replaced with calls to */
/*        NAMFRM and FRMCHG respectively. */


/* -    SPICELIB Version 1.0.2, 30-AUG-1991 (JML) */

/*        1) The Particulars section was updated to show how the */
/*           search algorithm processes segments with continuous */
/*           pointing data. */

/*        2) The example program now loads an SCLK kernel. */

/*        3) FAILED is checked after the call to IRFROT to handle the */
/*           case where the reference frame is invalid and the error */
/*           handling is not set to abort. */

/*        4) FAILED is checked in the DO WHILE loop to handle the case */
/*           where an error is detected by a SPICELIB routine inside the */
/*           loop and the error handling is not set to abort. */

/* -    SPICELIB Version 1.0.1, 02-NOV-1990 (JML) */

/*        1) The restriction that a C-kernel file must be loaded */
/*           was explicitly stated. */
/*        2) Minor changes were made to the wording of the header. */


/* -    Beta Version 1.1.0, 29-AUG-1990 (MJS) */

/*        The following changes were made as a result of the */
/*        NAIF CK Code and Documentation Review: */

/*        1) The variable SCLK was changed to SCLKDP. */
/*        2) The variable INSTR was changed to INST. */
/*        3) The variable IDENT was changed to SEGID. */
/*        4) The declarations for the parameters NDC, NIC, NC, and */
/*           IDLEN were moved from the "Declarations" section of the */
/*           header to the "Local parameters" section of the code below */
/*           the header. These parameters are not meant to modified by */
/*           users. */
/*        5) The header was updated to reflect the changes. */

/* -    Beta Version 1.0.0, 04-MAY-1990 (RET) (IMU) */

/* -& */

/*     SPICELIB functions */


/*     Local parameters */

/*        NDC        is the number of double precision components in an */
/*                   unpacked C-kernel segment descriptor. */

/*        NIC        is the number of integer components in an unpacked */
/*                   C-kernel segment descriptor. */

/*        NC         is the number of components in a packed C-kernel */
/*                   descriptor.  All DAF summaries have this formulaic */
/*                   relationship between the number of its integer and */
/*                   double precision components and the number of packed */
/*                   components. */

/*        IDLEN      is the length of the C-kernel segment identifier. */
/*                   All DAF names have this formulaic relationship */
/*                   between the number of summary components and */
/*                   the length of the name (You will notice that */
/*                   a name and a summary have the same length in bytes.) */


/*     Local variables */


/*     Standard SPICE error handling. */

    if (return_()) {
	return 0;
    } else {
	chkin_("CKGP", (ftnlen)4);
    }

/*     Don't need angular velocity data. */
/*     Assume the segment won't be found until it really is. */

    needav = FALSE_;
    *found = FALSE_;

/*     If the tolerance is less than zero, we go no further. */

    if (*tol < 0.) {
	chkout_("CKGP", (ftnlen)4);
	return 0;
    }

/*     Begin a search for this instrument and time, and get the first */
/*     applicable segment. */

    ckbss_(inst, sclkdp, tol, &needav);
    cksns_(&handle, descr, segid, &sfnd, (ftnlen)40);

/*     Keep trying candidate segments until a segment can produce a */
/*     pointing instance within the specified time tolerance of the */
/*     input time. */

/*     Check FAILED to prevent an infinite loop if an error is detected */
/*     by a SPICELIB routine and the error handling is not set to abort. */

    while(sfnd && ! failed_()) {
	ckpfs_(&handle, descr, sclkdp, tol, &needav, cmat, av, clkout, &pfnd);
	if (pfnd) {

/*           Found one. If the C-matrix doesn't already rotate from the */
/*           requested frame, convert it to one that does. */

	    dafus_(descr, &c__2, &c__6, dcd, icd);
	    refseg = icd[1];

/*           Look up the id code for the requested reference frame. */

	    namfrm_(ref, &refreq, ref_len);
	    if (refreq != refseg) {

/*              We may need to convert the output ticks CLKOUT to ET */
/*              so that we can get the needed state transformation */
/*              matrix.  This is the case if either of the frames */
/*              is non-inertial. */

		frinfo_(&refreq, &center, &type1, &typeid, &gotit);
		frinfo_(&refseg, &center, &type2, &typeid, &gotit);
		if (type1 == 1 && type2 == 1) {

/*                 Any old value of ET will do in this case.  We'll */
/*                 use zero. */

		    et = 0.;
		} else {

/*                 Look up the spacecraft clock id to use to convert */
/*                 the output CLKOUT to ET. */

		    ckmeta_(inst, "SCLK", &sclk, (ftnlen)4);
		    sct2e_(&sclk, clkout, &et);
		}

/*              Get the transformation from the requested frame to */
/*              the segment frame at ET. */

		refchg_(&refreq, &refseg, &et, rot);

/*              If REFCHG detects that the reference frame is invalid */
/*              then return from this routine with FOUND equal to false. */

		if (failed_()) {
		    chkout_("CKGP", (ftnlen)4);
		    return 0;
		}

/*              Transform the attitude information: convert CMAT so that */
/*              it maps from request frame to C-matrix frame. */

		mxm_(cmat, rot, tmpmat);
		moved_(tmpmat, &c__9, cmat);
	    }
	    *found = TRUE_;
	    chkout_("CKGP", (ftnlen)4);
	    return 0;
	}
	cksns_(&handle, descr, segid, &sfnd, (ftnlen)40);
    }
Esempio n. 5
0
File: ckfrot.c Progetto: Dbelsa/coft
/* $Procedure      CKFROT ( C-kernel, find rotation ) */
/* Subroutine */ int ckfrot_(integer *inst, doublereal *et, doublereal *
	rotate, integer *ref, logical *found)
{
    logical have, pfnd, sfnd;
    doublereal time;
    extern /* Subroutine */ int sce2c_(integer *, doublereal *, doublereal *);
    char segid[40];
    extern /* Subroutine */ int chkin_(char *, ftnlen);
    doublereal descr[5];
    extern /* Subroutine */ int dafus_(doublereal *, integer *, integer *, 
	    doublereal *, integer *), ckbss_(integer *, doublereal *, 
	    doublereal *, logical *), ckpfs_(integer *, doublereal *, 
	    doublereal *, doublereal *, logical *, doublereal *, doublereal *,
	     doublereal *, logical *), cksns_(integer *, doublereal *, char *,
	     logical *, ftnlen), xpose_(doublereal *, doublereal *);
    extern logical failed_(void);
    doublereal av[3];
    integer handle;
    extern /* Subroutine */ int ckhave_(logical *);
    logical needav;
    extern /* Subroutine */ int ckmeta_(integer *, char *, integer *, ftnlen);
    integer sclkid;
    extern /* Subroutine */ int chkout_(char *, ftnlen);
    doublereal clkout;
    extern logical return_(void), zzsclk_(integer *, integer *);
    doublereal dcd[2];
    integer icd[6];
    doublereal tol, rot[9]	/* was [3][3] */;

/* $ Abstract */

/*     Find the rotation from a C-kernel Id to the native */
/*     frame at the time requested. */

/* $ Disclaimer */

/*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
/*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
/*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
/*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
/*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
/*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
/*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
/*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
/*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
/*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */

/*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
/*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
/*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
/*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
/*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
/*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */

/*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
/*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
/*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
/*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */

/* $ Required_Reading */

/*     CK */

/* $ Keywords */

/*     POINTING */

/* $ Declarations */
/* $ Brief_I/O */

/*     Variable  I/O  Description */
/*     --------  ---  -------------------------------------------------- */
/*     INST       I   NAIF instrument ID. */
/*     ET         I   Epoch measured in seconds past J2000. */
/*     ROTATE     O   rotation from CK platform to frame REF. */
/*     REF        O   Reference frame. */
/*     FOUND      O   True when requested pointing is available. */

/* $ Detailed_Input */

/*     INST       is the unique NAIF integer ID for the spacecraft */
/*                instrument for which data is being requested. */

/*     ET         is the epoch for which the state rotation */
/*                is desired. ET should be given in seconds past the */
/*                epoch of J2000. */


/* $ Detailed_Output */

/*     ROTATE     is a rotation matrix that converts */
/*                positions relative to the input frame (given by INST) */
/*                to positions relative to the frame REF. */

/*                Thus, if a state S has components x,y,z,dx,dy,dz */
/*                in the frame of INST, frame, then S has components */
/*                x', y', z', dx', dy', dz' in frame REF. */

/*                     [  x' ]     [           ] [  x ] */
/*                     |  y' |  =  |   ROTATE  | |  y | */
/*                     [  z' ]     [           ] [  z ] */


/*     REF        is the id-code reference frame to which ROTATE will */
/*                transform states. */

/*     FOUND      is true if a record was found to satisfy the pointing */
/*                request.  FOUND will be false otherwise. */

/* $ Parameters */

/*     None. */

/* $ Exceptions */

/*     1)  If a C-kernel file is not loaded using CKLPF prior to calling */
/*         this routine, an error is signalled by a routine that this */
/*         routine calls. */


/* $ Files */

/*     CKFROT searches through files loaded by CKLPF to locate a segment */
/*     that can satisfy the request for position rotation */
/*     for instrument INST at time ET.  You must load a C-kernel */
/*     file using CKLPF before calling this routine. */

/* $ Particulars */

/*     CKFROT searches through files loaded by CKLPF to satisfy a */
/*     pointing request. Last-loaded files are searched first, and */
/*     individual files are searched in backwards order, giving */
/*     priority to segments that were added to a file later than the */
/*     others. CKFROT considers only those segments that contain */
/*     angular velocity data. */

/*     The search ends when a segment is found that can give pointing */
/*     for the specified instrument at the request time. */

/* $ Examples */

/*     None. */

/* $ Restrictions */

/*     A C-kernel file should have been loaded by CKLPF. */

/*     In addition it is helpful to load a CK-info file into the */
/*     Kernel pool.  This file should have the following variables */
/*     defined. */

/*       CK_<INST>_SCLK = SCLK idcode that yields SCLK mapping for INST. */
/*       CK_<INST>_SPK  = SPK idcode  that yields ephemeris for INST. */

/*     where <INST> is the integer string corresponding to INST. */

/* $ Literature_References */

/*     None. */

/* $ Author_and_Institution */

/*     W.L. Taber (JPL) */

/* $ Version */

/* -    SPICELIB Version 1.2.0, 17-FEB-2000 (WLT) */

/*        The routine now checks to make sure convert ET to TICKS */
/*        and that at least one C-kernel is loaded before trying */
/*        to look up the transformation.  Also the routine now calls */
/*        SCE2C instead of SCE2T. */

/* -    SPICELIB Version 1.0.0, 03-MAR-1999 (WLT) */

/* -& */
/* $ Index_Entries */

/*     get instrument frame rotation and reference frame */

/* -& */

/*     SPICELIB functions */


/*     Local parameters */

/*        NDC        is the number of double precision components in an */
/*                   unpacked C-kernel segment descriptor. */

/*        NIC        is the number of integer components in an unpacked */
/*                   C-kernel segment descriptor. */

/*        NC         is the number of components in a packed C-kernel */
/*                   descriptor.  All DAF summaries have this formulaic */
/*                   relationship between the number of its integer and */
/*                   double precision components and the number of packed */
/*                   components. */

/*        IDLEN      is the length of the C-kernel segment identifier. */
/*                   All DAF names have this formulaic relationship */
/*                   between the number of summary components and */
/*                   the length of the name (You will notice that */
/*                   a name and a summary have the same length in bytes.) */


/*     Local variables */


/*     Set FOUND to FALSE right now in case we end up */
/*     returning before doing any work. */

    *found = FALSE_;
    *ref = 0;

/*     Standard SPICE error handling. */

    if (return_()) {
	return 0;
    } else {
	chkin_("CKFROT", (ftnlen)6);
    }

/*     We don't need angular velocity data. */
/*     Assume the segment won't be found until it really is. */

    needav = FALSE_;
    tol = 0.;

/*     Begin a search for this instrument and time, and get the first */
/*     applicable segment. */

    ckhave_(&have);
    ckmeta_(inst, "SCLK", &sclkid, (ftnlen)4);
    if (! have) {
	chkout_("CKFROT", (ftnlen)6);
	return 0;
    } else if (! zzsclk_(inst, &sclkid)) {
	chkout_("CKFROT", (ftnlen)6);
	return 0;
    }
    sce2c_(&sclkid, et, &time);
    ckbss_(inst, &time, &tol, &needav);
    cksns_(&handle, descr, segid, &sfnd, (ftnlen)40);

/*     Keep trying candidate segments until a segment can produce a */
/*     pointing instance within the specified time tolerance of the */
/*     input time. */

/*     Check FAILED to prevent an infinite loop if an error is detected */
/*     by a SPICELIB routine and the error handling is not set to abort. */

    while(sfnd && ! failed_()) {
	ckpfs_(&handle, descr, &time, &tol, &needav, rot, av, &clkout, &pfnd);
	if (pfnd) {

/*           Found one. Fetch the ID code of the reference frame */
/*           from the descriptor. */

	    dafus_(descr, &c__2, &c__6, dcd, icd);
	    *ref = icd[1];
	    *found = TRUE_;

/*           We now have the rotation matrix from */
/*           REF to INS. We invert ROT to get the rotation */
/*           from INST to REF. */

	    xpose_(rot, rotate);
	    chkout_("CKFROT", (ftnlen)6);
	    return 0;
	}
	cksns_(&handle, descr, segid, &sfnd, (ftnlen)40);
    }
    chkout_("CKFROT", (ftnlen)6);
    return 0;
} /* ckfrot_ */