1 /* 2 3 -Procedure spkw10_c (SPK - write a type 10 segment ) 4 5 -Abstract 6 7 Write an SPK type 10 segment to the DAF open and attached to 8 the input handle. 9 10 -Disclaimer 11 12 THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE 13 CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. 14 GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE 15 ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE 16 PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" 17 TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY 18 WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A 19 PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC 20 SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE 21 SOFTWARE AND RELATED MATERIALS, HOWEVER USED. 22 23 IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA 24 BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT 25 LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, 26 INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, 27 REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE 28 REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. 29 30 RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF 31 THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY 32 CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE 33 ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. 34 35 -Required_Reading 36 37 None. 38 39 -Keywords 40 41 SPK 42 43 */ 44 45 #include "SpiceUsr.h" 46 #include "SpiceZfc.h" 47 #include "SpiceZmc.h" 48 #undef spkw10_c 49 spkw10_c(SpiceInt handle,SpiceInt body,SpiceInt center,ConstSpiceChar * frame,SpiceDouble first,SpiceDouble last,ConstSpiceChar * segid,ConstSpiceDouble consts[8],SpiceInt n,ConstSpiceDouble elems[],ConstSpiceDouble epochs[])50 void spkw10_c ( SpiceInt handle, 51 SpiceInt body, 52 SpiceInt center, 53 ConstSpiceChar * frame, 54 SpiceDouble first, 55 SpiceDouble last, 56 ConstSpiceChar * segid, 57 ConstSpiceDouble consts [8], 58 SpiceInt n, 59 ConstSpiceDouble elems [], 60 ConstSpiceDouble epochs [] ) 61 62 /* 63 64 -Brief_I/O 65 66 VARIABLE I/O DESCRIPTION 67 -------- --- -------------------------------------------------- 68 handle I The handle of a DAF file open for writing. 69 body I The NAIF ID code for the body of the segment. 70 center I The center of motion for body. 71 frame I The reference frame for this segment. 72 first I The first epoch for which the segment is valid. 73 last I The last epoch for which the segment is valid. 74 segid I The string to use for segment identifier. 75 consts I The array of geophysical constants for the segment 76 n I The number of element/epoch pairs to be stored 77 elems I The collection of "two-line" element sets. 78 epochs I The epochs associated with the element sets. 79 80 -Detailed_Input 81 82 handle is the file handle of an SPK file that has been 83 opened for writing by spcopn, dafopn, or dafopw. 84 85 body is the NAIF ID for the body whose states are 86 to be recorded in an SPK file. 87 88 center is the NAIF ID for the center of motion associated 89 with body. 90 91 frame is the reference frame that states are referenced to, 92 for example "J2000". 93 94 first are the bounds on the ephemeris times, expressed as 95 last seconds past J2000, for which the states can be used 96 to interpolate a state for body. 97 98 segid is the segment identifier. An SPK segment identifier 99 may contain up to 40 characters. 100 101 consts are the geophysical constants needed for evaluation 102 of the two line elements sets. The order of these 103 constants must be: 104 105 consts[0] = J2 gravitational harmonic for earth 106 consts[1] = J3 gravitational harmonic for earth 107 consts[2] = J4 gravitational harmonic for earth 108 consts[3] = Square root of the GM for earth where GM 109 is expressed in earth radii cubed per 110 minutes squared 111 consts[4] = Equatorial radius of the earth in km 112 consts[5] = Low altitude bound for atmospheric 113 model in km 114 consts[6] = High altitude bound for atmospheric 115 model in km 116 consts[7] = Distance units/earth radius (normally 1) 117 118 n is the number of "two-line" element sets and epochs 119 to be stored in the segment. 120 121 elems contains a time-ordered array of two-line elements 122 as supplied in NORAD two-line element files. The 123 i'th set of elements (where i ranges from 1 to n) 124 should be stored as shown here: 125 126 base = (i-1)*10 127 128 elems ( base + 0 ) = NDT20 129 elems ( base + 1 ) = NDD60 130 elems ( base + 2 ) = BSTAR 131 elems ( base + 3 ) = INCL 132 elems ( base + 4 ) = NODE0 133 elems ( base + 5 ) = ECC 134 elems ( base + 6 ) = OMEGA 135 elems ( base + 7 ) = MO 136 elems ( base + 8 ) = NO 137 elems ( base + 9 ) = EPOCH 138 139 The meaning of these variables is defined by the 140 format of the two-line element files available from 141 NORAD. 142 143 epochs contains the epochs (ephemeris seconds past J2000) 144 corresponding to the elements in elems. The I'th 145 epoch must equal the epoch of the I'th element set 146 Epochs must form a strictly increasing sequence. 147 148 -Detailed_Output 149 150 None. The data input is stored in an SPK segment in the 151 DAF connected to the input handle. 152 153 -Parameters 154 155 None. 156 157 -Particulars 158 159 This routine writes a type 10 SPK segment to the DAF open 160 for writing that is attached to handle. A routine, GETELM, that 161 reads two-line element data from files distributed by 162 NORAD is available from NAIF. 163 164 -Examples 165 166 Suppose that you have collected the two-line element data 167 and geophysical constants as prescribed above. The following 168 code fragment demonstrates how you could go about creating 169 a type 10 SPK segment. 170 171 #include "SpiceUsr.h" 172 . 173 . 174 . 175 /. 176 Open a new SPK file using DAF and get a file handle. 177 ./ 178 body = <integer code for the body>; 179 center = <integer code for central body for the trajectory>; 180 frame = "J2000"; 181 segid = <string that gives the bodies name>; 182 183 fname = "SAMPLE.SPK"; 184 ifname = "SAMPLE SPK FILE FOR PRIVATE USE"; 185 ncomch = 0; 186 187 void spkopn_c ( fname, ifname, ncomch, &handle ); 188 189 /. 190 Add the type 10 data. 191 ./ 192 spkw10_c ( handle, body, center, frame, first, last, 193 segid, consts, n, elems, epochs ); 194 195 /. 196 Close the SPK properly. 197 ./ 198 spkcls_c ( handle ); 199 200 201 202 -Restrictions 203 204 None. 205 206 -Exceptions 207 208 1) Errors in the structure or content of the inputs must be 209 diagnosed by routines called by this one. 210 211 2) File access errors are diagnosed by routines in the 212 call tree of this routine. 213 214 3) If either the input frame or segment ID string pointer is null, 215 the error SPICE(NULLPOINTER) is signaled. 216 217 4) If either the input frame or segment ID string is empty, 218 the error SPICE(EMPTYSTRING) is signaled. 219 220 -Files 221 222 None. 223 224 -Author_and_Institution 225 226 N.J. Bachman (JPL) 227 W.L. Taber (JPL) 228 229 -Literature_References 230 231 None. 232 233 -Version 234 235 -CSPICE Version 1.0.1, 30-OCT-2006 (BVS) 236 237 Deleted "inertial" from the FRAME description in the Brief_I/O 238 section of the header. 239 240 -CSPICE Version 1.0.0, 29-JUN-1999 (NJB) (WLT) 241 242 -Index_Entries 243 244 write a type_10 spk segment 245 246 -& 247 */ 248 249 { /* Begin spkw10_c */ 250 251 252 253 /* 254 Participate in error tracing. 255 */ 256 chkin_c ( "spkw10_c" ); 257 258 259 /* 260 Check the input strings to make sure the pointers 261 are non-null and the string lengths are non-zero. 262 */ 263 CHKFSTR ( CHK_STANDARD, "spkw10_c", frame ); 264 CHKFSTR ( CHK_STANDARD, "spkw10_c", segid ); 265 266 267 /* 268 Write the segment. 269 */ 270 spkw10_ ( ( integer * ) &handle, 271 ( integer * ) &body, 272 ( integer * ) ¢er, 273 ( char * ) frame, 274 ( doublereal * ) &first, 275 ( doublereal * ) &last, 276 ( char * ) segid, 277 ( doublereal * ) consts, 278 ( integer * ) &n, 279 ( doublereal * ) elems, 280 ( doublereal * ) epochs, 281 ( ftnlen ) strlen(frame), 282 ( ftnlen ) strlen(segid) ); 283 284 285 chkout_c ( "spkw10_c" ); 286 287 } /* End spkw10_c */ 288