Exemplo n.º 1
0
/* $Procedure SPKPVN ( S/P Kernel, position and velocity in native frame ) */
/* Subroutine */ int spkpvn_(integer *handle, doublereal *descr, doublereal *
	et, integer *ref, doublereal *state, integer *center)
{
    integer type__;
    extern /* Subroutine */ int chkin_(char *, ftnlen), dafus_(doublereal *, 
	    integer *, integer *, doublereal *, integer *), spke01_(
	    doublereal *, doublereal *, doublereal *), spke02_(doublereal *, 
	    doublereal *, doublereal *), spke03_(doublereal *, doublereal *, 
	    doublereal *), spke10_(doublereal *, doublereal *, doublereal *), 
	    spke05_(doublereal *, doublereal *, doublereal *), spke12_(
	    doublereal *, doublereal *, doublereal *), spke13_(doublereal *, 
	    doublereal *, doublereal *), spke08_(doublereal *, doublereal *, 
	    doublereal *), spke09_(doublereal *, doublereal *, doublereal *), 
	    spke14_(doublereal *, doublereal *, doublereal *), spke15_(
	    doublereal *, doublereal *, doublereal *), spke17_(doublereal *, 
	    doublereal *, doublereal *), spke18_(doublereal *, doublereal *, 
	    doublereal *), spkr01_(integer *, doublereal *, doublereal *, 
	    doublereal *), spkr02_(integer *, doublereal *, doublereal *, 
	    doublereal *), spkr03_(integer *, doublereal *, doublereal *, 
	    doublereal *), spkr05_(integer *, doublereal *, doublereal *, 
	    doublereal *), spkr10_(integer *, doublereal *, doublereal *, 
	    doublereal *), spkr12_(integer *, doublereal *, doublereal *, 
	    doublereal *), spkr08_(integer *, doublereal *, doublereal *, 
	    doublereal *), spkr09_(integer *, doublereal *, doublereal *, 
	    doublereal *), spkr13_(integer *, doublereal *, doublereal *, 
	    doublereal *), spkr14_(integer *, doublereal *, doublereal *, 
	    doublereal *), spkr15_(integer *, doublereal *, doublereal *, 
	    doublereal *), spkr17_(integer *, doublereal *, doublereal *, 
	    doublereal *), spkr18_(integer *, doublereal *, doublereal *, 
	    doublereal *), spkr19_(integer *, doublereal *, doublereal *, 
	    doublereal *), spke19_(doublereal *, doublereal *, doublereal *), 
	    spkr20_(integer *, doublereal *, doublereal *, doublereal *), 
	    spke20_(doublereal *, doublereal *, doublereal *), spkr21_(
	    integer *, doublereal *, doublereal *, doublereal *), spke21_(
	    doublereal *, doublereal *, doublereal *);
    doublereal dc[2];
    integer ic[6];
    extern logical failed_(void);
    doublereal record[198];
    extern /* Subroutine */ int sgfcon_(integer *, doublereal *, integer *, 
	    integer *, doublereal *), sigerr_(char *, ftnlen), chkout_(char *,
	     ftnlen);
    integer recsiz;
    extern /* Subroutine */ int setmsg_(char *, ftnlen), errint_(char *, 
	    integer *, ftnlen);
    extern logical return_(void);

/* $ Abstract */

/*     Return the state (position and velocity) of a target body */
/*     relative to some center of motion. */

/* $ 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 */

/*     SPK */

/* $ Keywords */

/*     EPHEMERIS */

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

/*     Declare SPK data record size.  This record is declared in */
/*     SPKPVN and is passed to SPK reader (SPKRxx) and evaluator */
/*     (SPKExx) routines. */

/* $ 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 */

/*     SPK */

/* $ Keywords */

/*     SPK */

/* $ Restrictions */

/*     1) If new SPK types are added, it may be necessary to */
/*        increase the size of this record.  The header of SPKPVN */
/*        should be updated as well to show the record size */
/*        requirement for each data type. */

/* $ Author_and_Institution */

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

/* $ Literature_References */

/*     None. */

/* $ Version */

/* -    SPICELIB Version 2.0.0, 05-OCT-2012 (NJB) */

/*        Updated to support increase of maximum degree to 27 for types */
/*        2, 3, 8, 9, 12, 13, 18, and 19. See SPKPVN for a list */
/*        of record size requirements as a function of data type. */

/* -    SPICELIB Version 1.0.0, 16-AUG-2002 (NJB) */

/* -& */

/*     End include file spkrec.inc */

/* $ Brief_I/O */

/*     Variable  I/O  Description */
/*     --------  ---  -------------------------------------------------- */
/*     HANDLE     I   File handle. */
/*     DESCR      I   Segment descriptor. */
/*     ET         I   Target epoch. */
/*     REF        O   Target reference frame. */
/*     STATE      O   Position, velocity. */
/*     CENTER     O   Center of state. */
/*     MAXREC     P   Maximum length of records returned by SPKRnn. */

/* $ Detailed_Input */

/*     HANDLE, */
/*     DESCR       are the file handle assigned to a SPK file, and the */
/*                 descriptor for a segment within the file. Together */
/*                 they determine the ephemeris data from which the */
/*                 state of the body is to be computed. */

/*     ET          is the epoch (ephemeris time) at which the state */
/*                 is to be computed. */

/* $ Detailed_Output */

/*     REF         is the id-code of the reference frame to */
/*                 which the vectors returned by the routine belong. */

/*     STATE       contains the position and velocity, at epoch ET, */
/*                 for whatever body is covered by the specified segment. */
/*                 STATE has six elements:  the first three contain the */
/*                 body's position; the last three contain the body's */
/*                 velocity.  These vectors are rotated into the */
/*                 specified  reference frame, the origin of */
/*                 which is located at the center of motion for the */
/*                 body (see CENTER, below).  Units are always km and */
/*                 km/sec. */

/*     CENTER      is the integer ID code of the center of motion for */
/*                 the state. */

/* $ Parameters */

/*     MAXREC      is the maximum length of a record returned by any of */
/*                 data type-specific routines SPKRnn, which are called */
/*                 by SPKPVN (see Particulars). */

/* $ Exceptions */

/*     1) If the segment type is not supported by the current */
/*        version of SPKPVN, the error 'SPICE(SPKTYPENOTSUPP)' */
/*        is signaled. */


/* $ Files */

/*     See argument HANDLE. */

/* $ Particulars */

/*     SPKPVN is the most basic of the SPK readers, the reader upon */
/*     which SPKPV and SPKGEO, etc. are built. It should not normally */
/*     be called directly except in cases where some optimization is */
/*     required. (That is, where the calling program has prior knowledge */
/*     of the center-barycenter shifts to be performed, or a non-standard */
/*     method of determining the files and segments to be used when */
/*     computing states.) */

/*     This is the only reader which makes distinctions between the */
/*     various segment types in the SPK format. The complete list */
/*     of types currently supported is shown below. */

/*        Type   Description */
/*        ----   ----------------------- */
/*           1   Difference Lines */
/*           2   Chebyshev (P) */
/*           3   Chebyshev (P,V) */
/*           5   Two body propagation between discrete states */
/*           8   Lagrange interpolation, equally spaced discrete states */
/*           9   Lagrange interpolation, unequally spaced discrete states */
/*          12   Hermite interpolation, equally spaced discrete states */
/*          13   Hermite interpolation, unequally spaced discrete states */
/*          14   Chebyshev Unequally spaced */
/*          15   Precessing Ellipse */
/*          17   Equinoctial Elements */
/*          18   ESOC/DDID Hermite/Lagrange Interpolation */
/*          19   ESOC/DDID Piecewise Interpolation */
/*          20   Chebyshev (V) */
/*          21   Extended Modified Difference Array */

/*     SPKPVN is the only reader that needs to be changed in order to */
/*     add a new segment type to the SPK format.  If a new data type is */
/*     added, the following steps should be taken: */

/*     1) Write two new routines, SPKRnn and SPKEnn, to read and */
/*        evaluate, respectively, a record from a data type nn segment. */

/*     2) Insert a new case into the body of SPKPVN to accommodate the */
/*        new type. */

/*     3) If necessary, adjust the parameter MAXREC, above, so that it */
/*        is large enough to encompass the maximum size of a record */
/*        returned by SPKRnn and passed to SPKEnn. */

/*        The maximum record lengths for each data type currently */
/*        supported are as follows: */

/*                  Data type       Maximum record length */
/*                  ---------       --------------------- */
/*                      1                    71 */
/*                      2                    87 */
/*                      3                   171 */
/*                      5                    15 */
/*                      8                   171 */
/*                      9                   197 */
/*                     12                    87 */
/*                     13                    99 */
/*                     14                 Variable */
/*                     15                    16 */
/*                     17                    12 */
/*                     18                   198 */
/*                     19                   198 */
/*                     20                   159 */
/*                     21                   112 */

/* $ Examples */

/*     In the following code fragment, an entire SPK file is searched */
/*     for segments containing a particular epoch. For each one found, */
/*     the body, center, segment identifier, and range at the epoch */
/*     are printed out. */

/*        CALL DAFOPR ( 'TEST.SPK', HANDLE ) */
/*        CALL DAFBFS (             HANDLE ) */

/*        CALL DAFFNA ( FOUND  ) */

/*        DO WHILE ( FOUND ) */
/*           CALL DAFGS ( DESCR ) */
/*           CALL DAFUS ( DESCR, 2, 6, DC, IC ) */

/*           IF ( DC(1) .LE. ET  .AND.  ET .LE. DC(2) ) THEN */
/*              CALL SPKPVN ( HANDLE, DESCR, ET, REF, STATE, CENTER ) */
/*              CALL DAFGN  ( IDENT ) */
/*              CALL FRMNAM ( REF, FRAME ) */
/*              WRITE (*,*) */
/*              WRITE (*,*) 'Body   = ', IC(1) */
/*              WRITE (*,*) 'Center = ', CENTER, */
/*              WRITE (*,*) 'ID     = ', IDENT */
/*              WRITE (*,*) 'Frame  = ', FRAME */
/*              WRITE (*,*) 'Range  = ', VNORM ( STATE ) */
/*           END IF */

/*           CALL DAFFNA ( FOUND ) */
/*        END DO */

/* $ Restrictions */

/*     None. */

/* $ Literature_References */

/*     None. */

/* $ Author_and_Institution */

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

/* $ Version */

/* -    SPICELIB Version 4.0.0,  23-DEC-2013 (NJB) */

/*        Added support for types 19, 20 and 21. Added header */
/*        comments giving description for types 18, 19, */
/*        and 21. Removed header reference to type 4. */

/* -    SPICELIB Version 3.0.0,  16-AUG-2002 (NJB) */

/*        Added support for type 18.  This routine now uses the */
/*        include file spkrec.inc to declare the record size. */

/*        Corrected header comments giving record sizes for types */
/*        8, 9, 12, 13. */

/* -    SPICELIB Version 2.0.0,  06-NOV-1999 (NJB) */

/*        Added support for types 12 and 13. */

/* -    SPICELIB Version 1.1.0,  7-JAN-1997 (WLT) */

/*        Added support for type 17. */

/* -    SPICELIB Version 1.0.0, 19-SEP-1995 (WLT) */


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

/*     position and velocity from ephemeris */
/*     spk file position and velocity */

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

/* -    SPICELIB Version 1.1.0,  7-JAN-1997 (WLT) */

/*        Added support for type 17. */


/* -& */

/*     SPICELIB functions */


/*     Some local space is needed in which to return records, and */
/*     into which to unpack the segment descriptor. */


/*     Local Parameters */


/*     Standard SPICE error handling. */

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

/*     Unpacking the segment descriptor will tell us the center, */
/*     reference frame, and data type for this segment. */

    dafus_(descr, &c__2, &c__6, dc, ic);
    *center = ic[1];
    *ref = ic[2];
    type__ = ic[3];

/*     Each data type has a pair of routines to read and evaluate */
/*     records for that data type. These routines are the only ones */
/*     that actually look inside the segments. */

/*     By the time we have more than 100 data types, we should be */
/*     allowed to use longer variable names. */

    if (type__ == 1) {
	spkr01_(handle, descr, et, record);
	spke01_(et, record, state);
    } else if (type__ == 2) {
	spkr02_(handle, descr, et, record);
	spke02_(et, record, state);
    } else if (type__ == 3) {
	spkr03_(handle, descr, et, record);
	spke03_(et, record, state);

/*     Type 04 is not officially part of the library. */

/*     ELSE IF ( TYPE .EQ. 04 ) THEN */
/*         CALL SPKR04 ( HANDLE, DESCR, ET, RECORD         ) */
/*         CALL SPKE04 (                ET, RECORD, STATE  ) */
    } else if (type__ == 5) {
	spkr05_(handle, descr, et, record);
	spke05_(et, record, state);
    } else if (type__ == 8) {
	spkr08_(handle, descr, et, record);
	spke08_(et, record, state);
    } else if (type__ == 9) {
	spkr09_(handle, descr, et, record);
	spke09_(et, record, state);
    } else if (type__ == 10) {
	spkr10_(handle, descr, et, record);
	spke10_(et, record, state);
    } else if (type__ == 12) {
	spkr12_(handle, descr, et, record);
	spke12_(et, record, state);
    } else if (type__ == 13) {
	spkr13_(handle, descr, et, record);
	spke13_(et, record, state);
    } else if (type__ == 14) {

/*        Fetch the number of Chebyshev coefficients, compute the record */
/*        size needed, and signal an error if there is not enough storage */
/*        in RECORD. The number of coefficients is the first constant */
/*        value in the generic segment. */

	sgfcon_(handle, descr, &c__1, &c__1, record);
	if (failed_()) {
	    chkout_("SPKPVN", (ftnlen)6);
	    return 0;
	}
	recsiz = (integer) record[0] * 6 + 3;
	if (recsiz > 198) {
	    setmsg_("Storage for # double precision numbers is needed for an"
		    " SPK data record and only # locations were available. Up"
		    "date the parameter MAXREC in the subroutine SPKPVN and n"
		    "otify the NAIF group of this problem.", (ftnlen)204);
	    errint_("#", &recsiz, (ftnlen)1);
	    errint_("#", &c__198, (ftnlen)1);
	    sigerr_("SPICE(SPKRECTOOLARGE)", (ftnlen)21);
	    chkout_("SPKPVN", (ftnlen)6);
	    return 0;
	}
	spkr14_(handle, descr, et, record);
	spke14_(et, record, state);
    } else if (type__ == 15) {
	spkr15_(handle, descr, et, record);
	spke15_(et, record, state);
    } else if (type__ == 17) {
	spkr17_(handle, descr, et, record);
	spke17_(et, record, state);
    } else if (type__ == 18) {
	spkr18_(handle, descr, et, record);
	spke18_(et, record, state);
    } else if (type__ == 19) {
	spkr19_(handle, descr, et, record);
	spke19_(et, record, state);
    } else if (type__ == 20) {
	spkr20_(handle, descr, et, record);
	spke20_(et, record, state);
    } else if (type__ == 21) {
	spkr21_(handle, descr, et, record);
	spke21_(et, record, state);
    } else {
	setmsg_("SPK type # is not supported in your version of the SPICE li"
		"brary.  You will need to upgrade your version of the library"
		" to make use of ephemerides that contain this SPK data type. "
		, (ftnlen)180);
	errint_("#", &type__, (ftnlen)1);
	sigerr_("SPICE(SPKTYPENOTSUPP)", (ftnlen)21);
	chkout_("SPKPVN", (ftnlen)6);
	return 0;
    }
    chkout_("SPKPVN", (ftnlen)6);
    return 0;
} /* spkpvn_ */
Exemplo n.º 2
0
/* $Procedure      PCKR03 ( Read PCK record from segment, type 03 ) */
/* Subroutine */ int pckr03_(integer *handle, doublereal *descr, doublereal *
	et, doublereal *record)
{
    integer ends, indx;
    extern /* Subroutine */ int chkin_(char *, ftnlen);
    logical found;
    doublereal value;
    extern /* Subroutine */ int errdp_(char *, doublereal *, ftnlen), sgfcon_(
	    integer *, doublereal *, integer *, integer *, doublereal *), 
	    sigerr_(char *, ftnlen), chkout_(char *, ftnlen), sgfpkt_(integer 
	    *, doublereal *, integer *, integer *, doublereal *, integer *), 
	    sgfrvi_(integer *, doublereal *, doublereal *, doublereal *, 
	    integer *, logical *), setmsg_(char *, ftnlen);
    extern logical return_(void);

/* $ Abstract */

/*     Read a single PCK data record from a segment of type 03. */

/* $ 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 */

/*     PCK */

/* $ Keywords */

/*     PCK */

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

/*     Variable  I/O  Description */
/*     --------  ---  -------------------------------------------------- */
/*     HANDLE     I   File handle for a PCK file. */
/*     DESCR      I   Descriptor for a type 03 PCK segment. */
/*     ET         I   Target epoch for orientation information. */
/*     RECORD     O   Data record associated with epoch ET. */

/* $ Detailed_Input */

/*     HANDLE      is the file handle for a type 03 PCK segment. */

/*     DESCR       is the segment descriptor for a type 03 PCK segment. */

/*     ET          is a target epoch, for which a data record from */
/*                 the specified segment is required. */

/* $ Detailed_Output */

/*     RECORD      is the record from the specified segment which, */
/*                 when evaluated at epoch ET, will give the RA, DEC, */
/*                 W and body fixed angular rates for the body associated */
/*                 with the segment. */

/* $ Parameters */

/*     None. */

/* $ Exceptions */

/*     1) It is assumed that the descriptor and handle supplied are */
/*        for a properly constructed type 03 segment. No checks are */
/*        performed to ensure this. */

/*     2) If the input ET value is not within the range specified */
/*        in the segment descriptor, the error SPICE(TIMEOUTOFBOUNDS) */
/*        is signalled. */

/*     3) All other errors are diagnosed by routines in the call tree */
/*        of this routine. */

/* $ Files */

/*     See argument HANDLE. */

/* $ Particulars */

/*     This subroutine reads a type 03 PCK record from the segment */
/*     specified by HANDLE and DESCR. The record read will contain */
/*     sufficient information to to compute RA, DEC, W and body fixed */
/*     angular rates for the body associated with the segment for epoch */
/*     ET. */

/*     See the PCK Required Reading file for a description of the */
/*     structure of a type 03 PCK segment. */

/* $ Examples */

/*     The data returned by the PCKRnn routine is in its rawest form, */
/*     taken directly from the segment.  As such, it will be meaningless */
/*     to a user unless he/she understands the structure of the data type */
/*     completely.  Given that understanding, however, the PCKRnn */
/*     routines might be used to "dump" and check segment data for a */
/*     particular epoch. */


/*     C */
/*     C     Get a segment applicable to a specified body and epoch. */
/*     C */
/*           CALL PCKSFS ( BODY, ET, HANDLE, DESCR, IDENT, FOUND ) */

/*     C */
/*     C     Look at parts of the descriptor. */
/*     C */
/*           CALL DAFUS ( DESCR, 2, 6, DCD, ICD ) */
/*           CENTER = ICD( 2 ) */
/*           REF    = ICD( 3 ) */
/*           TYPE   = ICD( 4 ) */

/*           IF ( TYPE .EQ. 03 ) THEN */
/*              CALL PCKR03 ( HANDLE, DESCR, ET, RECORD ) */
/*                  . */
/*                  .  Look at the RECORD data. */
/*                  . */
/*           END IF */

/* $ Restrictions */

/*     1) It is assumed that the descriptor and handle supplied are */
/*        for a properly constructed type 03 segment.  No checks are */
/*        performed to ensure this. */

/* $ Literature_References */

/*     None. */

/* $ Author_and_Institution */

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

/* $ Version */

/* -    SPICELIB Version 1.0.0, 20-SEP-1995 (KRG) */

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

/*     read record from type_03 pck segment */

/* -& */

/*     SPICELIB functions */


/*     Local Parameters */

/*     The number of constant values stored with a type 03 segment */
/*     segment. */


/*     The beginning location in the output record for the non-constant */
/*     segment data. */


/*     Local Variables */


/*     Standard SPICE error handling. */

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

/*     Check the request time against the time bounds in the segment */
/*     descriptor. In order to get the right data back from the generic */
/*     segment calls below, we need to be sure that the desired epoch */
/*     falls within the bounds of the segment, as specified by the */
/*     descriptor. The first two elements of the descriptor are the start */
/*     time for the segment and the stop time for the segment, */
/*     respectively. */

    if (*et < descr[0] || *et > descr[1]) {
	setmsg_("Request time # is outside of descriptor bounds # : #.", (
		ftnlen)53);
	errdp_("#", et, (ftnlen)1);
	errdp_("#", descr, (ftnlen)1);
	errdp_("#", &descr[1], (ftnlen)1);
	sigerr_("SPICE(TIMEOUTOFBOUNDS)", (ftnlen)22);
	chkout_("PCKR03", (ftnlen)6);
	return 0;
    }

/*     Fetch the constants and store them in the first part of */
/*     the output RECORD. */

    sgfcon_(handle, descr, &c__1, &c__1, record);

/*     Locate the time in the file less than or equal to the input ET. */

    sgfrvi_(handle, descr, et, &value, &indx, &found);

/*     Fetch the data record. */

    sgfpkt_(handle, descr, &indx, &indx, &record[1], &ends);
    chkout_("PCKR03", (ftnlen)6);
    return 0;
} /* pckr03_ */
Exemplo n.º 3
0
/* $Procedure PCKMAT ( PCK, get transformation matrix at time ) */
/* Subroutine */ int pckmat_(integer *body, doublereal *et, integer *ref, 
	doublereal *tsipm, logical *found)
{
    integer type__;
    extern /* Subroutine */ int pcke02_(doublereal *, doublereal *, 
	    doublereal *), pcke03_(doublereal *, doublereal *, doublereal *), 
	    pcke20_(doublereal *, doublereal *, doublereal *), chkin_(char *, 
	    ftnlen);
    doublereal descr[5];
    extern /* Subroutine */ int pckr02_(integer *, doublereal *, doublereal *,
	     doublereal *), dafus_(doublereal *, integer *, integer *, 
	    doublereal *, integer *);
    char ident[40];
    extern /* Subroutine */ int pckr03_(integer *, doublereal *, doublereal *,
	     doublereal *), pckr20_(integer *, doublereal *, doublereal *, 
	    doublereal *), eul2xf_(doublereal *, integer *, integer *, 
	    integer *, doublereal *);
    extern logical failed_(void);
    integer handle;
    doublereal eulang[6], record[130];
    extern /* Subroutine */ int sgfcon_(integer *, doublereal *, integer *, 
	    integer *, doublereal *);
    doublereal estate[6];
    extern /* Subroutine */ int pcksfs_(integer *, doublereal *, integer *, 
	    doublereal *, char *, logical *, ftnlen), sigerr_(char *, ftnlen),
	     chkout_(char *, ftnlen);
    integer recsiz;
    extern /* Subroutine */ int setmsg_(char *, ftnlen), errint_(char *, 
	    integer *, ftnlen);
    extern logical return_(void);
    doublereal dcd[2];
    integer icd[5];

/* $ Abstract */

/*      Given a body and epoch, return the name of an inertial */
/*      reference frame and the 6 x 6 state transformation matrix */
/*      from that frame to the body fixed frame. */

/* $ 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 */

/*     NAIF_IDS */
/*     ROTATION */
/*     TIME */
/*     PCK */

/* $ Keywords */

/*     TRANSFORMATION */
/*     ROTATION */

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

/*     VARIABLE  I/O  DESCRIPTION */
/*     --------  ---  -------------------------------------------------- */
/*     BODY       I   ID code of some body. */
/*     ET         I   Epoch of transformation. */
/*     REF        O   Integer code for inertial reference frame. */
/*     TSIPM      O   Transformation from Inertial to PM for BODY at ET. */
/*     FOUND      O   True if data for BODY and ET are found. */

/* $ Detailed_Input */

/*     BODY        is the integer ID code of the body for which the */
/*                 state transformation matrix is requested. Bodies */
/*                 are numbered according to the standard NAIF */
/*                 numbering scheme.  The numbering scheme is */
/*                 explained in the NAIF_IDS required reading file. */

/*     ET          is the epoch at which the state transformation */
/*                 matrix is requested. */

/* $ Detailed_Output */

/*     REF         is the integer code for the inertial reference frame */
/*                 of the state transformation matrix TSIPM. (See the */
/*                 routine CHGIRF for a full list of inertial reference */
/*                 frame names.) */

/*     TSIPM       is a 6x6 transformation matrix. It is used to */
/*                 transform states from inertial coordinates to body */
/*                 fixed (also called equator and prime meridian --- PM) */
/*                 coordinates. */

/*                 Given a state S in the inertial reference frame */
/*                 specified by REF, the corresponding state in the body */
/*                 fixed reference frame is given by the matrix vector */
/*                 product: */

/*                    TSIPM * S */

/*                 See the PCK required reading for further details */
/*                 concerning PCK reference frames. */

/*                 NOTE: The inverse of TSIPM is NOT its transpose. The */
/*                 matrix, TSIPM, has the structure shown below: */

/*                             -            - */
/*                            |       :      | */
/*                            |   R   :  0   | */
/*                            | ......:......| */
/*                            |       :      | */
/*                            | dR_dt :  R   | */
/*                            |       :      | */
/*                             -            - */

/*                 where R is a time varying rotation matrix and dR_dt */
/*                 is its derivative.  The inverse of this matrix is: */

/*                             -              - */
/*                            |     T  :       | */
/*                            |    R   :  0    | */
/*                            | .......:.......| */
/*                            |        :       | */
/*                            |      T :   T   | */
/*                            | dR_dt  :  R    | */
/*                            |        :       | */
/*                             -              - */

/*                 The SPICE routine INVSTM is available for producing */
/*                 this inverse. */

/*      FOUND      if the data allowing the computation of a state */
/*                 transformation matrix for the requested time and body */
/*                 are found in a binary PCK file, FOUND will have the */
/*                 value .TRUE., otherwise it will have the value */
/*                 .FALSE.. */

/* $ Parameters */

/*     None. */

/* $ Exceptions */

/*     1)  If the size of the type 20 PCK record to be  retrieved is too */
/*         large to fit into RECORD, the error SPICE(PCKRECTOOLARGE) */
/*         will be signaled. */

/*     2)  Any error that occurs while reading PCK data will be */
/*         diagnosed by a routine in the call tree of this routine. */

/*     3)  If the requested transformation matrix cannot be computed */
/*         using data from loaded binary PCK files, FOUND is returned */
/*         with the value .FALSE.. This is not a SPICE error. */

/* $ Files */

/*     This routine computes transformation matrices using data */
/*     provided by a loaded binary PCK kernel. */

/* $ Particulars */

/*     The matrix for transforming an inertial state into a body fixed */
/*     states is the 6x6 matrix shown below as a block structured */
/*     matrix. */

/*                 -            - */
/*                |       :      | */
/*                | TIPM  :  0   | */
/*                | ......:......| */
/*                |       :      | */
/*                | DTIPM : TIPM | */
/*                |       :      | */
/*                 -            - */

/*     If a binary PCK file record can be found for the time and body */
/*     requested, it will be used. The most recently loaded binary PCK */
/*     file has first priority, followed by previously loaded binary PCK */
/*     files in backward time order. If no binary PCK file has been */
/*     loaded, the text P_constants kernel file is used. */


/* $ Examples */

/*     Here we load a binary PCK files and use PCKEUL to get the */
/*     Euler angles. */

/*     C */
/*     C  Load binary PCK file. */
/*     C */
/*        CALL PCKLOF ('example.pck', HANDLE) */

/*     C  Call routine to get transformation matrix. */

/*        CALL PCKMAT ( BODY, ET, REF, TIPM, FOUND ) */

/* $ Restrictions */

/*      None. */

/* $ Literature_References */

/*      None. */

/* $ Author_and_Institution */

/*      K. S. Zukor     (JPL) */
/*      K. R. Gehringer (JPL) */
/*      N. J. Bachman   (JPL) */

/* $ Version */

/* -     SPICELIB Version 3.0.0, 03-JAN-2014 (NJB) (EDW) */

/*         Minor edits to Procedure; clean trailing whitespace. */
/*         Removed unneeded Revisions section. */

/*         Updated to support type 20. Changed long error message */
/*         for the case of RECORD having insufficient room: the */
/*         user is no longer advised to modify the record size. */

/* -     SPICELIB Version 2.0.0, 22-MAR-1995 (KRG) (KSZ) */

/*         Added PCK type 03. Added a new exception. Made some minor */
/*         comment changes. */

/* -     SPICELIB Version 1.0.0, 21-MAR-1995 (KSZ) */

/*         Replaces PCKEUL and returns the transformation */
/*         matrix rather than the Euler angles. */

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

/*     get state transformation matrix from binary PCK file */

/* -& */

/*     SPICELIB functions */


/*     Local Parameters */

/*     ND and NI values for a PCK file. */


/*     Index for the reference frame code in the integer summary. */


/*     Length of the descriptor for a PCK file. */


/*     Index for the data type code in the integer summary. */


/*     Maximum size allowed for a record in a segment of a binary PCK */
/*     file. */


/*     Number of components in a state vector. */


/*     Local Variables */


/*     Standard SPICE Error handling. */

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

/*     Get a segment applicable to a specified body and epoch. */

    pcksfs_(body, et, &handle, descr, ident, found, (ftnlen)40);
    if (failed_()) {
	*found = FALSE_;
	chkout_("PCKMAT", (ftnlen)6);
	return 0;
    }
    if (*found) {

/*        Look at parts of the descriptor. */

	dafus_(descr, &c__2, &c__5, dcd, icd);
	type__ = icd[2];
	*ref = icd[1];
	if (type__ == 2) {

/*           Read in Chebyshev coefficients from segment. */

	    pckr02_(&handle, descr, et, record);

/*           Call evaluation routine to get Euler angles */
/*           phi, delta, w. */

	    pcke02_(et, record, eulang);
	    if (failed_()) {
		*found = FALSE_;
		chkout_("PCKMAT", (ftnlen)6);
		return 0;
	    }

/*           From the PCK type two file the Euler angles are */
/*           retrieved in a particular order.  The routine to */
/*           get the TSIPM matrix from expects them in another */
/*           order.  Here we change from EULANG to ESTATE, which */
/*           has this proper order. */

	    estate[0] = eulang[2];
	    estate[1] = eulang[1];
	    estate[2] = eulang[0];
	    estate[3] = eulang[5];
	    estate[4] = eulang[4];
	    estate[5] = eulang[3];

/*           Call routine which takes Euler angles to transformation */
/*           matrix. */

	    eul2xf_(estate, &c__3, &c__1, &c__3, tsipm);
	    if (failed_()) {
		*found = FALSE_;
		chkout_("PCKMAT", (ftnlen)6);
		return 0;
	    }
	} else if (type__ == 3) {

/*           Fetch the number of Chebyshev coefficients, compute the */
/*           record size needed, and signal an error if there is not */
/*           enough storage in RECORD. The number of coefficients is the */
/*           first constant value in the generic segment. */

	    sgfcon_(&handle, descr, &c__1, &c__1, record);
	    if (failed_()) {
		*found = FALSE_;
		chkout_("PCKMAT", (ftnlen)6);
		return 0;
	    }
	    recsiz = (integer) record[0] * 6 + 2;
	    if (recsiz > 130) {
		setmsg_("Storage for # double precision numbers is needed fo"
			"r a PCK data record and only # locations were availa"
			"ble. Notify the NAIF group of this problem.", (ftnlen)
			146);
		errint_("#", &recsiz, (ftnlen)1);
		errint_("#", &c__130, (ftnlen)1);
		sigerr_("SPICE(PCKKRECTOOLARGE)", (ftnlen)22);
		chkout_("PCKMAT", (ftnlen)6);
		return 0;
	    }
	    pckr03_(&handle, descr, et, record);
	    pcke03_(et, record, tsipm);
	    if (failed_()) {
		*found = FALSE_;
		chkout_("PCKMAT", (ftnlen)6);
		return 0;
	    }
	} else if (type__ == 20) {

/*           Read in Chebyshev coefficients from segment. */

	    pckr20_(&handle, descr, et, record);

/*           Call evaluation routine to get Euler angles */
/*           phi, delta, w. */

	    pcke20_(et, record, eulang);
	    if (failed_()) {
		*found = FALSE_;
		chkout_("PCKMAT", (ftnlen)6);
		return 0;
	    }

/*           From the PCK type 20 file the Euler angles are */
/*           retrieved in a particular order. The routine to */
/*           get the TSIPM matrix from expects them in another */
/*           order. Here we change from EULANG to ESTATE, which */
/*           has this proper order. */

	    estate[0] = eulang[2];
	    estate[1] = eulang[1];
	    estate[2] = eulang[0];
	    estate[3] = eulang[5];
	    estate[4] = eulang[4];
	    estate[5] = eulang[3];

/*           Call routine which takes Euler angles to transformation */
/*           matrix. */

	    eul2xf_(estate, &c__3, &c__1, &c__3, tsipm);
	    if (failed_()) {
		*found = FALSE_;
		chkout_("PCKMAT", (ftnlen)6);
		return 0;
	    }
	} else {

/*           If data matching the requested body and time was not */
/*           found, FOUND is false. */

	    *found = FALSE_;
	}
    }
    chkout_("PCKMAT", (ftnlen)6);
    return 0;
} /* pckmat_ */
Exemplo n.º 4
0
/* $Procedure      SPKS10 ( S/P Kernel, subset, type 10 ) */
/* Subroutine */ int spks10_(integer *srchan, doublereal *srcdsc, integer *
	dsthan, doublereal *dstdsc, char *dstsid, ftnlen dstsid_len)
{
    /* System generated locals */
    integer i__1, i__2;

    /* Local variables */
    char time[40];
    integer i__;
    extern /* Subroutine */ int etcal_(doublereal *, char *, ftnlen), chkin_(
	    char *, ftnlen), dafus_(doublereal *, integer *, integer *, 
	    doublereal *, integer *), errch_(char *, char *, ftnlen, ftnlen);
    doublereal dtemp[2];
    logical found;
    integer itemp[6];
    doublereal myref;
    extern /* Subroutine */ int sgwes_(integer *);
    integer dummy;
    extern logical failed_(void);
    integer begidx;
    doublereal begtim, packet[14];
    integer endidx, nepoch;
    doublereal endtim;
    extern /* Subroutine */ int sgfcon_(integer *, doublereal *, integer *, 
	    integer *, doublereal *), sgbwfs_(integer *, doublereal *, char *,
	     integer *, doublereal *, integer *, integer *, ftnlen), chkout_(
	    char *, ftnlen), sigerr_(char *, ftnlen), sgfrvi_(integer *, 
	    doublereal *, doublereal *, doublereal *, integer *, logical *), 
	    setmsg_(char *, ftnlen), sgmeta_(integer *, doublereal *, integer 
	    *, integer *), sgfpkt_(integer *, doublereal *, integer *, 
	    integer *, doublereal *, integer *), sgfref_(integer *, 
	    doublereal *, integer *, integer *, doublereal *);
    doublereal consts[8];
    extern /* Subroutine */ int sgwfpk_(integer *, integer *, doublereal *, 
	    integer *, doublereal *);
    extern logical return_(void);

/* $ Abstract */

/*     Extract a subset of the data in a type 10 SPK segment into a new */
/*     type 10 segment. */

/* $ 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 */

/*     SPK */

/* $ Keywords */

/*     EPHEMERIS */

/* $ Declarations */

/* $ Abstract */

/*     Parameter declarations for the generic segments subroutines. */

/* $ 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 */

/*      DAF Required Reading */

/* $ Keywords */

/*       GENERIC SEGMENTS */

/* $ Particulars */

/*     This include file contains the parameters used by the generic */
/*     segments subroutines, SGxxxx. A generic segment is a */
/*     generalization of a DAF array which places a particular structure */
/*     on the data contained in the array, as described below. */

/*     This file defines the mnemonics that are used for the index types */
/*     allowed in generic segments as well as mnemonics for the meta data */
/*     items which are used to describe a generic segment. */

/*     A DAF generic segment contains several logical data partitions: */

/*        1) A partition for constant values to be associated with each */
/*           data packet in the segment. */

/*        2) A partition for the data packets. */

/*        3) A partition for reference values. */

/*        4) A partition for a packet directory, if the segment contains */
/*           variable sized packets. */

/*        5) A partition for a reference value directory. */

/*        6) A reserved partition that is not currently used. This */
/*           partition is only for the use of the NAIF group at the Jet */
/*           Propulsion Laboratory (JPL). */

/*        7) A partition for the meta data which describes the locations */
/*           and sizes of other partitions as well as providing some */
/*           additional descriptive information about the generic */
/*           segment. */

/*                 +============================+ */
/*                 |         Constants          | */
/*                 +============================+ */
/*                 |          Packet 1          | */
/*                 |----------------------------| */
/*                 |          Packet 2          | */
/*                 |----------------------------| */
/*                 |              .             | */
/*                 |              .             | */
/*                 |              .             | */
/*                 |----------------------------| */
/*                 |          Packet N          | */
/*                 +============================+ */
/*                 |      Reference Values      | */
/*                 +============================+ */
/*                 |      Packet Directory      | */
/*                 +============================+ */
/*                 |    Reference  Directory    | */
/*                 +============================+ */
/*                 |       Reserved  Area       | */
/*                 +============================+ */
/*                 |     Segment Meta Data      | */
/*                 +----------------------------+ */

/*     Only the placement of the meta data at the end of a generic */
/*     segment is required. The other data partitions may occur in any */
/*     order in the generic segment because the meta data will contain */
/*     pointers to their appropriate locations within the generic */
/*     segment. */

/*     The meta data for a generic segment should only be obtained */
/*     through use of the subroutine SGMETA. The meta data should not be */
/*     written through any mechanism other than the ending of a generic */
/*     segment begun by SGBWFS or SGBWVS using SGWES. */

/* $ Restrictions */

/*     1) If new reference index types are added, the new type(s) should */
/*        be defined to be the consecutive integer(s) after the last */
/*        defined reference index type used. In this way a value for */
/*        the maximum allowed index type may be maintained. This value */
/*        must also be updated if new reference index types are added. */

/*     2) If new meta data items are needed, mnemonics for them must be */
/*        added to the end of the current list of mnemonics and before */
/*        the NMETA mnemonic. In this way compatibility with files having */
/*        a different, but smaller, number of meta data items may be */
/*        maintained. See the description and example below. */

/* $ Author_and_Institution */

/*     N.J. Bachman      (JPL) */
/*     K.R. Gehringer    (JPL) */
/*     W.L. Taber        (JPL) */
/*     F.S. Turner       (JPL) */

/* $ Literature_References */

/*     Generic Segments Required Reading. */
/*     DAF Required Reading. */

/* $ Version */

/* -    SPICELIB Version 1.1.1, 28-JAN-2004 (NJB) */

/*        Header update: equations for comptutations of packet indices */
/*        for the cases of index types 0 and 1 were corrected. */

/* -    SPICELIB Version 1.1.0, 25-09-98 (FST) */

/*        Added parameter MNMETA, the minimum number of meta data items */
/*        that must be present in a generic DAF segment. */

/* -    SPICELIB Version 1.0.0, 04-03-95 (KRG) (WLT) */

/* -& */

/*     Mnemonics for the type of reference value index. */

/*     Two forms of indexing are provided: */

/*        1) An implicit form of indexing based on using two values, a */
/*           starting value, which will have an index of 1, and a step */
/*           size between reference values, which are used to compute an */
/*           index and a reference value associated with a specified key */
/*           value. See the descriptions of the implicit types below for */
/*           the particular formula used in each case. */

/*        2) An explicit form of indexing based on a reference value for */
/*           each data packet. */


/*     Reference Index Type 0 */
/*     ---------------------- */

/*     Implied index. The index and reference value of a data packet */
/*     associated with a specified key value are computed from the two */
/*     generic segment reference values using the formula below. The two */
/*     generic segment reference values, REF(1) and REF(2), represent, */
/*     respectively, a starting value and a step size between reference */
/*     values. The index of the data packet associated with a key value */
/*     of VALUE is given by: */

/*                          /    VALUE - REF(1)    \ */
/*        INDEX = 1  +  INT | -------------------- | */
/*                          \        REF(2)        / */

/*     and the reference value associated with VALUE is given by: */

/*        REFVAL = REF(1) + DBLE (INDEX-1) * REF(2) */


/*     Reference Index Type 1 */
/*     ---------------------- */

/*     Implied index. The index and reference value of a data packet */
/*     associated with a specified key value are computed from the two */
/*     generic segment reference values using the formula below. The two */
/*     generic segment reference values, REF(1) and REF(2), represent, */
/*     respectively, a starting value and a step size between reference */
/*     values. The index of the data packet associated with a key value */
/*     of VALUE is given by: */

/*                          /          VALUE - REF(1)    \ */
/*        INDEX = 1  +  INT | 0.5 + -------------------- | */
/*                          \              REF(2)        / */


/*     and the reference value associated with VALUE is given by: */

/*        REFVAL = REF(1) + DBLE (INDEX-1) * REF(2) */

/*     We get the larger index in the event that VALUE is halfway between */
/*     X(I) and X(I+1), where X(I) = BUFFER(1) + DBLE (I-1) * REFDAT(2). */


/*     Reference Index Type 2 */
/*     ---------------------- */

/*     Explicit index. In this case the number of packets must equal the */
/*     number of reference values. The index of the packet associated */
/*     with a key value of VALUE is the index of the last reference item */
/*     that is strictly less than VALUE. The reference values must be in */
/*     ascending order, REF(I) < REF(I+1). */


/*     Reference Index Type 3 */
/*     ---------------------- */

/*     Explicit index. In this case the number of packets must equal the */
/*     number of reference values. The index of the packet associated */
/*     with a key value of VALUE is the index of the last reference item */
/*     that is less than or equal to VALUE. The reference values must be */
/*     in ascending order, REF(I) < REF(I+1). */


/*     Reference Index Type 4 */
/*     ---------------------- */

/*     Explicit index. In this case the number of packets must equal the */
/*     number of reference values. The index of the packet associated */
/*     with a key value of VALUE is the index of the reference item */
/*     that is closest to the value of VALUE. In the event of a "tie" */
/*     the larger index is selected. The reference values must be in */
/*     ascending order, REF(I) < REF(I+1). */


/*     These parameters define the valid range for the index types. An */
/*     index type code, MYTYPE, for a generic segment must satisfy the */
/*     relation MNIDXT <= MYTYPE <= MXIDXT. */


/*     The following meta data items will appear in all generic segments. */
/*     Other meta data items may be added if a need arises. */

/*       1)  CONBAS  Base Address of the constants in a generic segment. */

/*       2)  NCON    Number of constants in a generic segment. */

/*       3)  RDRBAS  Base Address of the reference directory for a */
/*                   generic segment. */

/*       4)  NRDR    Number of items in the reference directory of a */
/*                   generic segment. */

/*       5)  RDRTYP  Type of the reference directory 0, 1, 2 ... for a */
/*                   generic segment. */

/*       6)  REFBAS  Base Address of the reference items for a generic */
/*                   segment. */

/*       7)  NREF    Number of reference items in a generic segment. */

/*       8)  PDRBAS  Base Address of the Packet Directory for a generic */
/*                   segment. */

/*       9)  NPDR    Number of items in the Packet Directory of a generic */
/*                   segment. */

/*      10)  PDRTYP  Type of the packet directory 0, 1, ... for a generic */
/*                   segment. */

/*      11)  PKTBAS  Base Address of the Packets for a generic segment. */

/*      12)  NPKT    Number of Packets in a generic segment. */

/*      13)  RSVBAS  Base Address of the Reserved Area in a generic */
/*                   segment. */

/*      14)  NRSV    Number of items in the reserved area of a generic */
/*                   segment. */

/*      15)  PKTSZ   Size of the packets for a segment with fixed width */
/*                   data packets or the size of the largest packet for a */
/*                   segment with variable width data packets. */

/*      16)  PKTOFF  Offset of the packet data from the start of a packet */
/*                   record. Each data packet is placed into a packet */
/*                   record which may have some bookkeeping information */
/*                   prepended to the data for use by the generic */
/*                   segments software. */

/*      17)  NMETA   Number of meta data items in a generic segment. */

/*     Meta Data Item  1 */
/*     ----------------- */


/*     Meta Data Item  2 */
/*     ----------------- */


/*     Meta Data Item  3 */
/*     ----------------- */


/*     Meta Data Item  4 */
/*     ----------------- */


/*     Meta Data Item  5 */
/*     ----------------- */


/*     Meta Data Item  6 */
/*     ----------------- */


/*     Meta Data Item  7 */
/*     ----------------- */


/*     Meta Data Item  8 */
/*     ----------------- */


/*     Meta Data Item  9 */
/*     ----------------- */


/*     Meta Data Item 10 */
/*     ----------------- */


/*     Meta Data Item 11 */
/*     ----------------- */


/*     Meta Data Item 12 */
/*     ----------------- */


/*     Meta Data Item 13 */
/*     ----------------- */


/*     Meta Data Item 14 */
/*     ----------------- */


/*     Meta Data Item 15 */
/*     ----------------- */


/*     Meta Data Item 16 */
/*     ----------------- */


/*     If new meta data items are to be added to this list, they should */
/*     be added above this comment block as described below. */

/*        INTEGER               NEW1 */
/*        PARAMETER           ( NEW1   = PKTOFF + 1 ) */

/*        INTEGER               NEW2 */
/*        PARAMETER           ( NEW2   = NEW1   + 1 ) */

/*        INTEGER               NEWEST */
/*        PARAMETER           ( NEWEST = NEW2   + 1 ) */

/*     and then the value of NMETA must be changed as well to be: */

/*        INTEGER               NMETA */
/*        PARAMETER           ( NMETA  = NEWEST + 1 ) */

/*     Meta Data Item 17 */
/*     ----------------- */


/*     Maximum number of meta data items. This is always set equal to */
/*     NMETA. */


/*     Minimum number of meta data items that must be present in a DAF */
/*     generic segment.  This number is to remain fixed even if more */
/*     meta data items are added for compatibility with old DAF files. */

/* $ Brief_I/O */

/*     Variable  I/O  Description */
/*     --------  ---  -------------------------------------------------- */
/*     SRCHAN     I   Handle of the SPK file with the source segment. */
/*     SRCDSC     I   Descriptor for the source segment. */
/*     DSTHAN     I   Handle of the SPK file for the destination segment. */
/*     DSTDSC     I   Descriptor for the destination segment. */
/*     DSTSID     I   Segment identifier for the new segment. */

/* $ Detailed_Input */

/*     SRCHAN   The handle of the SPK file containing the source segment. */

/*     SRCDSC   The SPK descriptor for the source segment. */

/*     DSTHAN   The handle of the SPK file containing the new segment. */

/*     DSTDSC   The SPK descriptor for the destination segment. It */
/*              contains the desired start and stop times for the */
/*              requested subset. */

/*     DSTSID   The segment identifier for the destination segment. */

/* $ Detailed_Output */

/*     None. */

/* $ Parameters */

/*     None. */

/* $ Exceptions */

/*     None. */

/* $ Files */

/*     See arguments SRCHAN, DSTHAN. */

/* $ Particulars */

/*     This subroutine copies a subset of the data form one SPK segment */
/*     to another. */

/*     The exact structure of a segment of SPK type 10 is detailed in */
/*     the SPK Required Reading. Please see this document for details. */

/* $ Examples */

/*     None. */

/* $ Restrictions */

/*     1) We assume that the source descriptor actually describes a */
/*        segment in the source SPK file containing the time coverage */
/*        that is desired for the subsetting operation. */

/* $ Literature_References */

/*     None. */

/* $ Author_and_Institution */

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

/* $ Version */

/* -    SPICELIB Version 1.0.0, 30-JUN-1997 (KRG) */

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

/*     subset type_10 spk segment */

/* -& */

/*     SPICELIB functions */


/*     Local Parameters */


/*     DAF ND and NI values for SPK files. */


/*     The number of geophysical constants: */


/*     The number of elements per two-line set: */


/*     Local Variables */


/*     Standard SPICE error handling. */

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

/*     First, unpack the destination segment descriptor and set some */
/*     local variables. */

    dafus_(dstdsc, &c__2, &c__6, dtemp, itemp);
    begtim = dtemp[0];
    endtim = dtemp[1];

/*     Get the constants for the input segment and send them to the */
/*     output segment by beginning a fixed packet size segment. */

    sgfcon_(srchan, srcdsc, &c__1, &c__8, consts);
    sgbwfs_(dsthan, dstdsc, dstsid, &c__8, consts, &c__14, &c__4, dstsid_len);
    if (failed_()) {
	chkout_("SPKS10", (ftnlen)6);
	return 0;
    }

/*     Get the beginning and ending indices for the packets we need for */
/*     the destination segment.  Note we need to get the preceding */
/*     and succeeding packets (if there are any) corresponding to the */
/*     start and end times of the output segments */

    sgfrvi_(srchan, srcdsc, &begtim, &myref, &begidx, &found);
    if (! found) {
	etcal_(&begtim, time, (ftnlen)40);
	setmsg_("An error has occurred while attempting to subset the a type"
		" 10 SPK segment. The error occurred while attempting to loca"
		"te a packet for the epoch #.  There does not appear to be su"
		"ch a packet. ", (ftnlen)192);
	errch_("#", time, (ftnlen)1, (ftnlen)40);
	sigerr_("SPICE(CANNOTGETPACKET)", (ftnlen)22);
	chkout_("SPKS10", (ftnlen)6);
	return 0;
    }
    if (myref > begtim) {
/* Computing MAX */
	i__1 = 1, i__2 = begidx - 1;
	begidx = max(i__1,i__2);
    }
    sgfrvi_(srchan, srcdsc, &endtim, &myref, &endidx, &found);
    if (! found) {
	etcal_(&endtim, time, (ftnlen)40);
	setmsg_("An error has occurred while attempting to subset the a type"
		" 10 SPK segment. The error occurred while attempting to loca"
		"te a packet for the epoch #.  There does not appear to be su"
		"ch a packet. ", (ftnlen)192);
	errch_("#", time, (ftnlen)1, (ftnlen)40);
	sigerr_("SPICE(CANNOTGETPACKET)", (ftnlen)22);
	chkout_("SPKS10", (ftnlen)6);
	return 0;
    }

/*     Get the total number of epochs. */

    sgmeta_(srchan, srcdsc, &c__7, &nepoch);
    if (myref < endtim) {
/* Computing MIN */
	i__1 = nepoch, i__2 = endidx + 1;
	endidx = min(i__1,i__2);
    }

/*     Now we get the data one record at a time from the source segment */
/*     and write it out to the destination segment. */

    i__1 = endidx;
    for (i__ = begidx; i__ <= i__1; ++i__) {
	sgfpkt_(srchan, srcdsc, &i__, &i__, packet, &dummy);
	sgfref_(srchan, srcdsc, &i__, &i__, &myref);
	sgwfpk_(dsthan, &c__1, packet, &c__1, &myref);
    }

/*     Now all we need to do is end the segment. */

    sgwes_(dsthan);
    chkout_("SPKS10", (ftnlen)6);
    return 0;
} /* spks10_ */
Exemplo n.º 5
0
Arquivo: spkr10.c Projeto: Dbelsa/coft
/* $Procedure SPKR10 ( SPK, read record from SPK type 10 segment ) */
/* Subroutine */ int spkr10_(integer *handle, doublereal *descr, doublereal *
	et, doublereal *record)
{
    /* System generated locals */
    integer i__1;

    /* Local variables */
    static integer ends[2], indx, from, i__;
    extern /* Subroutine */ int chkin_(char *, ftnlen), moved_(doublereal *, 
	    integer *, doublereal *);
    static logical found;
    static doublereal value;
    static integer to, nepoch, getelm;
    extern /* Subroutine */ int sgfcon_(integer *, doublereal *, integer *, 
	    integer *, doublereal *), sgmeta_(integer *, doublereal *, 
	    integer *, integer *), chkout_(char *, ftnlen), sgfpkt_(integer *,
	     doublereal *, integer *, integer *, doublereal *, integer *), 
	    sgfrvi_(integer *, doublereal *, doublereal *, doublereal *, 
	    integer *, logical *);
    static integer putelm;
    extern logical return_(void);
    static integer set1, set2;

/* $ Abstract */

/*     Read a single SPK data record from a segment of type 10 */
/*     (NORAD two line element sets). */

/* $ 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 */

/*     SPK */

/* $ Keywords */

/*     EPHEMERIS */

/* $ Declarations */

/* $ Abstract */

/*     Parameter declarations for the generic segments subroutines. */

/* $ 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 */

/*      DAF Required Reading */

/* $ Keywords */

/*       GENERIC SEGMENTS */

/* $ Particulars */

/*     This include file contains the parameters used by the generic */
/*     segments subroutines, SGxxxx. A generic segment is a */
/*     generalization of a DAF array which places a particular structure */
/*     on the data contained in the array, as described below. */

/*     This file defines the mnemonics that are used for the index types */
/*     allowed in generic segments as well as mnemonics for the meta data */
/*     items which are used to describe a generic segment. */

/*     A DAF generic segment contains several logical data partitions: */

/*        1) A partition for constant values to be associated with each */
/*           data packet in the segment. */

/*        2) A partition for the data packets. */

/*        3) A partition for reference values. */

/*        4) A partition for a packet directory, if the segment contains */
/*           variable sized packets. */

/*        5) A partition for a reference value directory. */

/*        6) A reserved partition that is not currently used. This */
/*           partition is only for the use of the NAIF group at the Jet */
/*           Propulsion Laboratory (JPL). */

/*        7) A partition for the meta data which describes the locations */
/*           and sizes of other partitions as well as providing some */
/*           additional descriptive information about the generic */
/*           segment. */

/*                 +============================+ */
/*                 |         Constants          | */
/*                 +============================+ */
/*                 |          Packet 1          | */
/*                 |----------------------------| */
/*                 |          Packet 2          | */
/*                 |----------------------------| */
/*                 |              .             | */
/*                 |              .             | */
/*                 |              .             | */
/*                 |----------------------------| */
/*                 |          Packet N          | */
/*                 +============================+ */
/*                 |      Reference Values      | */
/*                 +============================+ */
/*                 |      Packet Directory      | */
/*                 +============================+ */
/*                 |    Reference  Directory    | */
/*                 +============================+ */
/*                 |       Reserved  Area       | */
/*                 +============================+ */
/*                 |     Segment Meta Data      | */
/*                 +----------------------------+ */

/*     Only the placement of the meta data at the end of a generic */
/*     segment is required. The other data partitions may occur in any */
/*     order in the generic segment because the meta data will contain */
/*     pointers to their appropriate locations within the generic */
/*     segment. */

/*     The meta data for a generic segment should only be obtained */
/*     through use of the subroutine SGMETA. The meta data should not be */
/*     written through any mechanism other than the ending of a generic */
/*     segment begun by SGBWFS or SGBWVS using SGWES. */

/* $ Restrictions */

/*     1) If new reference index types are added, the new type(s) should */
/*        be defined to be the consecutive integer(s) after the last */
/*        defined reference index type used. In this way a value for */
/*        the maximum allowed index type may be maintained. This value */
/*        must also be updated if new reference index types are added. */

/*     2) If new meta data items are needed, mnemonics for them must be */
/*        added to the end of the current list of mnemonics and before */
/*        the NMETA mnemonic. In this way compatibility with files having */
/*        a different, but smaller, number of meta data items may be */
/*        maintained. See the description and example below. */

/* $ Author_and_Institution */

/*     N.J. Bachman      (JPL) */
/*     K.R. Gehringer    (JPL) */
/*     W.L. Taber        (JPL) */
/*     F.S. Turner       (JPL) */

/* $ Literature_References */

/*     Generic Segments Required Reading. */
/*     DAF Required Reading. */

/* $ Version */

/* -    SPICELIB Version 1.1.1, 28-JAN-2004 (NJB) */

/*        Header update: equations for comptutations of packet indices */
/*        for the cases of index types 0 and 1 were corrected. */

/* -    SPICELIB Version 1.1.0, 25-09-98 (FST) */

/*        Added parameter MNMETA, the minimum number of meta data items */
/*        that must be present in a generic DAF segment. */

/* -    SPICELIB Version 1.0.0, 04-03-95 (KRG) (WLT) */

/* -& */

/*     Mnemonics for the type of reference value index. */

/*     Two forms of indexing are provided: */

/*        1) An implicit form of indexing based on using two values, a */
/*           starting value, which will have an index of 1, and a step */
/*           size between reference values, which are used to compute an */
/*           index and a reference value associated with a specified key */
/*           value. See the descriptions of the implicit types below for */
/*           the particular formula used in each case. */

/*        2) An explicit form of indexing based on a reference value for */
/*           each data packet. */


/*     Reference Index Type 0 */
/*     ---------------------- */

/*     Implied index. The index and reference value of a data packet */
/*     associated with a specified key value are computed from the two */
/*     generic segment reference values using the formula below. The two */
/*     generic segment reference values, REF(1) and REF(2), represent, */
/*     respectively, a starting value and a step size between reference */
/*     values. The index of the data packet associated with a key value */
/*     of VALUE is given by: */

/*                          /    VALUE - REF(1)    \ */
/*        INDEX = 1  +  INT | -------------------- | */
/*                          \        REF(2)        / */

/*     and the reference value associated with VALUE is given by: */

/*        REFVAL = REF(1) + DBLE (INDEX-1) * REF(2) */


/*     Reference Index Type 1 */
/*     ---------------------- */

/*     Implied index. The index and reference value of a data packet */
/*     associated with a specified key value are computed from the two */
/*     generic segment reference values using the formula below. The two */
/*     generic segment reference values, REF(1) and REF(2), represent, */
/*     respectively, a starting value and a step size between reference */
/*     values. The index of the data packet associated with a key value */
/*     of VALUE is given by: */

/*                          /          VALUE - REF(1)    \ */
/*        INDEX = 1  +  INT | 0.5 + -------------------- | */
/*                          \              REF(2)        / */


/*     and the reference value associated with VALUE is given by: */

/*        REFVAL = REF(1) + DBLE (INDEX-1) * REF(2) */

/*     We get the larger index in the event that VALUE is halfway between */
/*     X(I) and X(I+1), where X(I) = BUFFER(1) + DBLE (I-1) * REFDAT(2). */


/*     Reference Index Type 2 */
/*     ---------------------- */

/*     Explicit index. In this case the number of packets must equal the */
/*     number of reference values. The index of the packet associated */
/*     with a key value of VALUE is the index of the last reference item */
/*     that is strictly less than VALUE. The reference values must be in */
/*     ascending order, REF(I) < REF(I+1). */


/*     Reference Index Type 3 */
/*     ---------------------- */

/*     Explicit index. In this case the number of packets must equal the */
/*     number of reference values. The index of the packet associated */
/*     with a key value of VALUE is the index of the last reference item */
/*     that is less than or equal to VALUE. The reference values must be */
/*     in ascending order, REF(I) < REF(I+1). */


/*     Reference Index Type 4 */
/*     ---------------------- */

/*     Explicit index. In this case the number of packets must equal the */
/*     number of reference values. The index of the packet associated */
/*     with a key value of VALUE is the index of the reference item */
/*     that is closest to the value of VALUE. In the event of a "tie" */
/*     the larger index is selected. The reference values must be in */
/*     ascending order, REF(I) < REF(I+1). */


/*     These parameters define the valid range for the index types. An */
/*     index type code, MYTYPE, for a generic segment must satisfy the */
/*     relation MNIDXT <= MYTYPE <= MXIDXT. */


/*     The following meta data items will appear in all generic segments. */
/*     Other meta data items may be added if a need arises. */

/*       1)  CONBAS  Base Address of the constants in a generic segment. */

/*       2)  NCON    Number of constants in a generic segment. */

/*       3)  RDRBAS  Base Address of the reference directory for a */
/*                   generic segment. */

/*       4)  NRDR    Number of items in the reference directory of a */
/*                   generic segment. */

/*       5)  RDRTYP  Type of the reference directory 0, 1, 2 ... for a */
/*                   generic segment. */

/*       6)  REFBAS  Base Address of the reference items for a generic */
/*                   segment. */

/*       7)  NREF    Number of reference items in a generic segment. */

/*       8)  PDRBAS  Base Address of the Packet Directory for a generic */
/*                   segment. */

/*       9)  NPDR    Number of items in the Packet Directory of a generic */
/*                   segment. */

/*      10)  PDRTYP  Type of the packet directory 0, 1, ... for a generic */
/*                   segment. */

/*      11)  PKTBAS  Base Address of the Packets for a generic segment. */

/*      12)  NPKT    Number of Packets in a generic segment. */

/*      13)  RSVBAS  Base Address of the Reserved Area in a generic */
/*                   segment. */

/*      14)  NRSV    Number of items in the reserved area of a generic */
/*                   segment. */

/*      15)  PKTSZ   Size of the packets for a segment with fixed width */
/*                   data packets or the size of the largest packet for a */
/*                   segment with variable width data packets. */

/*      16)  PKTOFF  Offset of the packet data from the start of a packet */
/*                   record. Each data packet is placed into a packet */
/*                   record which may have some bookkeeping information */
/*                   prepended to the data for use by the generic */
/*                   segments software. */

/*      17)  NMETA   Number of meta data items in a generic segment. */

/*     Meta Data Item  1 */
/*     ----------------- */


/*     Meta Data Item  2 */
/*     ----------------- */


/*     Meta Data Item  3 */
/*     ----------------- */


/*     Meta Data Item  4 */
/*     ----------------- */


/*     Meta Data Item  5 */
/*     ----------------- */


/*     Meta Data Item  6 */
/*     ----------------- */


/*     Meta Data Item  7 */
/*     ----------------- */


/*     Meta Data Item  8 */
/*     ----------------- */


/*     Meta Data Item  9 */
/*     ----------------- */


/*     Meta Data Item 10 */
/*     ----------------- */


/*     Meta Data Item 11 */
/*     ----------------- */


/*     Meta Data Item 12 */
/*     ----------------- */


/*     Meta Data Item 13 */
/*     ----------------- */


/*     Meta Data Item 14 */
/*     ----------------- */


/*     Meta Data Item 15 */
/*     ----------------- */


/*     Meta Data Item 16 */
/*     ----------------- */


/*     If new meta data items are to be added to this list, they should */
/*     be added above this comment block as described below. */

/*        INTEGER               NEW1 */
/*        PARAMETER           ( NEW1   = PKTOFF + 1 ) */

/*        INTEGER               NEW2 */
/*        PARAMETER           ( NEW2   = NEW1   + 1 ) */

/*        INTEGER               NEWEST */
/*        PARAMETER           ( NEWEST = NEW2   + 1 ) */

/*     and then the value of NMETA must be changed as well to be: */

/*        INTEGER               NMETA */
/*        PARAMETER           ( NMETA  = NEWEST + 1 ) */

/*     Meta Data Item 17 */
/*     ----------------- */


/*     Maximum number of meta data items. This is always set equal to */
/*     NMETA. */


/*     Minimum number of meta data items that must be present in a DAF */
/*     generic segment.  This number is to remain fixed even if more */
/*     meta data items are added for compatibility with old DAF files. */

/* $ Brief_I/O */

/*     Variable  I/O  Description */
/*     --------  ---  -------------------------------------------------- */
/*     HANDLE     I   File handle. */
/*     DESCR      I   Segment descriptor. */
/*     ET         I   Target epoch. */
/*     RECORD     O   Data record. */

/* $ Detailed_Input */

/*     HANDLE, */
/*     DESCR       are the file handle and segment descriptor for */
/*                 a SPK segment of type 10. */

/*     ET          is a target epoch, for which a data record from */
/*                 a specific segment is required. */

/* $ Detailed_Output */

/*     RECORD      is the record from the specified segment which, */
/*                 when evaluated at epoch ET, will give the state */
/*                 (position and velocity) of some body, relative */
/*                 to some center, in some inertial reference frame. */

/* $ Parameters */

/*     None. */

/* $ Exceptions */

/*     1) It is assumed that the descriptor and handle supplied are */
/*        for a properly constructed type 10 segment.  No checks are */
/*        performed to ensure this. */

/*     2) All errors are diagnosed by routines in the call tree */
/*        of this routine. */

/* $ Files */

/*     See argument HANDLE. */

/* $ Particulars */

/*     See the SPK Required Reading file for a description of the */
/*     structure of a data type 10 segment. */

/* $ Examples */

/*     The data returned by the SPKRnn routine is in its rawest form, */
/*     taken directly from the segment.  As such, it will be meaningless */
/*     to a user unless he/she understands the structure of the data type */
/*     completely.  Given that understanding, however, the SPKRxx */
/*     routines might be used to "dump" and check segment data for a */
/*     particular epoch. */


/*     C */
/*     C     Get a segment applicable to a specified body and epoch. */
/*     C */
/*           CALL SPKSFS ( BODY, ET, HANDLE, DESCR, IDENT, FOUND ) */

/*     C */
/*     C     Look at parts of the descriptor. */
/*     C */
/*           CALL DAFUS ( DESCR, 2, 6, DCD, ICD ) */
/*           CENTER = ICD( 2 ) */
/*           REF    = ICD( 3 ) */
/*           TYPE   = ICD( 4 ) */

/*           IF ( TYPE .EQ. 1 ) THEN */
/*              CALL SPKR10 ( HANDLE, DESCR, ET, RECORD ) */
/*                  . */
/*                  .  Look at the RECORD data. */
/*                  . */
/*           END IF */

/* $ Restrictions */

/*     None. */

/* $ Literature_References */

/*     NAIF Document 168.0, "S- and P- Kernel (SPK) Specification and */
/*     User's Guide" */

/* $ Author_and_Institution */

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

/* $ Version */

/* -    SPICELIB Version 1.1.0, 09-MAR-2009 (EDW) */

/*        Remove declaration of unused varaible DOINT. */

/* -    SPICELIB Version 1.0.0, 05-JAN-1994 (WLT) */

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

/*     read record from type_10 spk segment */

/* -& */

/*     SPICELIB functions */


/*     Local variables */


/*     We have 2 nutation/obliquity terms and their rates giving us */
/*     four angle components for each packet. */


/*     BEGEL1 is the location in the record where the first */
/*     two-line element set will begin. */


/*     BEGEL2 is the location in the record where the second */
/*     two-line element set will begin. */


/*     ENSET1 and ENSET2 are the locations in the record where the */
/*     last element of set 1 and set 2 will be located. */


/*     Standard SPICE error handling. */

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

/*     Fetch the constants and store them in the first part of */
/*     the output RECORD. */

    sgfcon_(handle, descr, &c__1, &c__8, record);

/*     Locate the time in the file closest to the input ET. */

    sgfrvi_(handle, descr, et, &value, &indx, &found);

/*     Determine which pair of element sets to choose so that */
/*     they will bracket ET. */

    if (*et <= value) {
/* Computing MAX */
	i__1 = indx - 1;
	from = max(i__1,1);
	to = indx;
    } else {
	sgmeta_(handle, descr, &c__7, &nepoch);
	from = indx;
/* Computing MIN */
	i__1 = indx + 1;
	to = min(i__1,nepoch);
    }

/*     Fetch the element sets */

    sgfpkt_(handle, descr, &from, &to, &record[8], ends);

/*     If the size of the packets is not 14, this is an old style */
/*     two-line element set without nutation information.  We simply */
/*     set all of the angles to zero. */

    if (ends[0] == 10) {

/*        First shift the elements to their proper locations in RECORD */
/*        so there will be room to fill in the zeros. */

	putelm = 32;
	getelm = 28;
	while(getelm > 18) {
	    record[putelm - 1] = record[getelm - 1];
	    --putelm;
	    --getelm;
	}
	set1 = 19;
	set2 = 33;
	for (i__ = 1; i__ <= 4; ++i__) {
	    record[set1 - 1] = 0.;
	    record[set2 - 1] = 0.;
	    ++set1;
	    ++set2;
	}
    }

/*     If we only got one element set, ET  was either before the */
/*     first one in the segment or after the last one in the */
/*     segment.  We simply copy the one fetched a second time so */
/*     that the record is properly constructed. */

    if (from == to) {
	moved_(&record[8], &c__14, &record[22]);
    }
    chkout_("SPKR10", (ftnlen)6);
    return 0;
} /* spkr10_ */