1 /* scencd.f -- translated by f2c (version 19980913).
2 You must link the resulting object file with the libraries:
3 -lf2c -lm (in that order)
4 */
5
6 #include "f2c.h"
7
8 /* Table of constant values */
9
10 static integer c__1 = 1;
11 static integer c__9999 = 9999;
12
13 /* $Procedure SCENCD ( Encode spacecraft clock ) */
scencd_(integer * sc,char * sclkch,doublereal * sclkdp,ftnlen sclkch_len)14 /* Subroutine */ int scencd_(integer *sc, char *sclkch, doublereal *sclkdp,
15 ftnlen sclkch_len)
16 {
17 /* System generated locals */
18 integer i__1, i__2, i__3, i__4, i__5;
19 doublereal d__1;
20
21 /* Builtin functions */
22 double d_nint(doublereal *);
23 integer s_rnge(char *, integer, char *, integer), s_cmp(char *, char *,
24 ftnlen, ftnlen);
25
26 /* Local variables */
27 extern integer cpos_(char *, char *, integer *, ftnlen, ftnlen);
28 integer part, i__;
29 extern /* Subroutine */ int chkin_(char *, ftnlen), errch_(char *, char *,
30 ftnlen, ftnlen);
31 doublereal ticks;
32 integer pnter;
33 char error[25];
34 doublereal pstop[9999];
35 extern logical failed_(void);
36 extern /* Subroutine */ int sigerr_(char *, ftnlen), scpart_(integer *,
37 integer *, doublereal *, doublereal *), chkout_(char *, ftnlen),
38 nparsi_(char *, integer *, char *, integer *, ftnlen, ftnlen),
39 sctiks_(integer *, char *, doublereal *, ftnlen), setmsg_(char *,
40 ftnlen), errint_(char *, integer *, ftnlen);
41 integer nparts;
42 doublereal pstart[9999];
43 extern logical return_(void);
44 doublereal ptotls[9999];
45 integer pos;
46
47 /* $ Abstract */
48
49 /* Encode character representation of spacecraft clock time into a */
50 /* double precision number. */
51
52 /* $ Disclaimer */
53
54 /* THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
55 /* CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
56 /* GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
57 /* ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
58 /* PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
59 /* TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
60 /* WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
61 /* PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
62 /* SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
63 /* SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
64
65 /* IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
66 /* BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
67 /* LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
68 /* INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
69 /* REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
70 /* REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
71
72 /* RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
73 /* THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
74 /* CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
75 /* ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
76
77 /* $ Required_Reading */
78
79 /* SCLK */
80
81 /* $ Keywords */
82
83 /* CONVERSION */
84 /* TIME */
85
86 /* $ Declarations */
87 /* $ Abstract */
88
89 /* Include file sclk.inc */
90
91 /* SPICE private file intended solely for the support of SPICE */
92 /* routines. Users should not include this file directly due */
93 /* to the volatile nature of this file */
94
95 /* The parameters below define sizes and limits used by */
96 /* the SCLK system. */
97
98 /* $ Disclaimer */
99
100 /* THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
101 /* CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
102 /* GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
103 /* ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
104 /* PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
105 /* TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
106 /* WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
107 /* PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
108 /* SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
109 /* SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
110
111 /* IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
112 /* BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
113 /* LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
114 /* INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
115 /* REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
116 /* REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
117
118 /* RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
119 /* THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
120 /* CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
121 /* ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
122
123 /* $ Parameters */
124
125 /* See the declaration section below. */
126
127 /* $ Author_and_Institution */
128
129 /* N.J. Bachman (JPL) */
130
131 /* $ Literature_References */
132
133 /* None. */
134
135 /* $ Version */
136
137 /* - SPICELIB Version 2.0.0, 24-MAY-2010 (NJB) */
138
139 /* Increased value of maximum coefficient record count */
140 /* parameter MXCOEF from 10K to 50K. */
141
142 /* - SPICELIB Version 1.0.0, 11-FEB-2008 (NJB) */
143
144 /* -& */
145
146 /* Number of supported SCLK field delimiters: */
147
148
149 /* Supported SCLK string field delimiters: */
150
151
152 /* Maximum number of partitions: */
153
154
155 /* Partition string length. */
156
157 /* Since the maximum number of partitions is given by MXPART is */
158 /* 9999, PRTSTR needs at most 4 characters for the partition number */
159 /* and one character for the slash. */
160
161
162 /* Maximum number of coefficient records: */
163
164
165 /* Maximum number of fields in an SCLK string: */
166
167
168 /* Length of strings used to represent D.P. */
169 /* numbers: */
170
171
172 /* Maximum number of supported parallel time systems: */
173
174
175 /* End of include file sclk.inc */
176
177 /* $ Brief_I/O */
178
179 /* Variable I/O Description */
180 /* -------- --- -------------------------------------------------- */
181 /* SC I NAIF spacecraft identification code. */
182 /* SCLKCH I Character representation of a spacecraft clock. */
183 /* SCLKDP O Encoded representation of the clock count. */
184 /* MXPART P Maximum number of spacecraft clock partitions. */
185
186 /* $ Detailed_Input */
187
188 /* SC is the standard NAIF ID of the spacecraft whose clock's */
189 /* time is being encoded. */
190
191 /* SCLKCH is the character representation of some spacecraft's */
192 /* clock count. */
193
194 /* SCLKCH will have the following general format: */
195
196 /* 'pp/sclk_string', or just */
197 /* 'sclk_string' */
198
199 /* 'pp' is an integer greater than or equal to one */
200 /* and is called the partition number. */
201
202 /* Each mission is divided into some number of partitions. */
203 /* A new partition starts when the spacecraft clock */
204 /* resets, either to zero, or to some other */
205 /* value. Thus, the first partition for any mission */
206 /* starts with launch, and ends with the first clock */
207 /* reset. The second partition starts immediately when */
208 /* the first stopped, and so on. */
209
210 /* In order to be completely unambiguous about a */
211 /* particular time, you need to specify a partition number */
212 /* along with the standard clock string. */
213
214 /* Information about when partitions occur for different */
215 /* missions is contained in a spacecraft clock kernel */
216 /* file, which needs to be loaded into the kernel pool, */
217 /* using the routines CLPOOL and FURNSH. */
218
219 /* The routine SCPART is used to read the partition */
220 /* start and stop times, in encoded units of SCLK (called */
221 /* "ticks" -- see SCLKDP below) from the kernel file. */
222
223 /* If the partition number is included, it must be */
224 /* separated from the rest of the string by a '/'. */
225 /* Any number of spaces may separate the partition number, */
226 /* the '/', and the rest of the clock string. */
227
228
229 /* If the partition number is omitted, a default partition */
230 /* will be assumed. The default partition is the lowest- */
231 /* numbered partition that contains the given clock time. */
232 /* If the clock time does not fall in any of the */
233 /* partition boundaries then an error is signaled. */
234
235
236 /* 'sclk_string' is a spacecraft specific clock string. */
237 /* Using Galileo as an example, the full format is */
238
239 /* wwwwwwww:xx:y:z */
240
241 /* where z is a mod-8 counter (values 0-7) which */
242 /* increments approximately once every 8 1/3 ms., y is a */
243 /* mod-10 counter (values 0-9) which increments once */
244 /* every time z turns over, i.e., approximately once every */
245 /* 66 2/3 ms., xx is a mod-91 (values 0-90) counter */
246 /* which increments once every time y turns over, i.e., */
247 /* once every 2/3 seconds. wwwwwwww is the Real-Time Image */
248 /* Count (RIM), which increments once every time xx turns */
249 /* over, i.e., once every 60 2/3 seconds. The roll-over */
250 /* expression for the RIM is 16777215, which corresponds */
251 /* to approximately 32 years. */
252
253 /* wwwwwwww, xx, y, and z are referred to interchangeably */
254 /* as the fields or components of the spacecraft clock. */
255 /* SCLK components may be separated by any of these */
256 /* five characters: ' ' ':' ',' '-' '.' */
257 /* Any number of spaces can separate the components and */
258 /* the delimiters. The presence of the RIM component */
259 /* is required. Successive components may be omitted, and */
260 /* in such cases are assumed to represent zero values. */
261
262 /* Values for the individual components may exceed the */
263 /* maximum expected values. For instance, '0:0:0:9' is */
264 /* an acceptable Galileo clock string, and will convert */
265 /* to the same number of ticks as '0:0:1:1'. */
266
267 /* Consecutive delimiters containing no intervening digits */
268 /* are treated as if they delimit zero components. */
269
270 /* Trailing zeros should always be included to match the */
271 /* length of the counter. For example, a Galileo clock */
272 /* count of '25684.90' should not be represented as */
273 /* '25684.9'. */
274
275 /* Some spacecraft clock components have offset, or */
276 /* starting, values different from zero. For example, */
277 /* with an offset value of 1, a mod 20 counter would */
278 /* cycle from 1 to 20 instead of from 0 to 19. */
279
280 /* See the SCLK required reading for a detailed */
281 /* description of the Voyager and Mars Observer clock */
282 /* formats. */
283
284
285 /* $ Detailed_Output */
286
287 /* SCLKDP is the double precision encoding of SCLKCH. */
288
289 /* The encoding is such that order and proximity will be */
290 /* preserved. That is, if t1, t2, and t3 are spacecraft */
291 /* clock times, and t1*, t2*, and t3* are their encodings, */
292 /* then if */
293
294 /* t1 < t2 < t3, and */
295
296 /* t2 is closer to t1 than to t3, you will have the result */
297 /* that */
298
299 /* t1* < t2* < t3*, and */
300
301 /* t2* is closer to t1* than to t3*. */
302
303 /* The units of encoded SCLK are "ticks since the start of */
304 /* the mission", where a "tick" is defined to be the */
305 /* shortest time increment expressible by a particular */
306 /* spacecraft's clock. */
307
308 /* Each clock string without partition number represents */
309 /* a certain number of ticks, but you need to include */
310 /* partition information to determine the relative */
311 /* position of that time in relation to the start of the */
312 /* mission. */
313
314 /* Since the end time of one partition is coincident */
315 /* with the begin time of the next, there are two */
316 /* different representations for this instant, and they */
317 /* will both yield the same encoding. */
318
319 /* For example, if partition 1 has an end time of t1, and */
320 /* partition 2 has a begin time of t2, then if we did */
321
322 /* CALL SCENCD ( '1/t1', SC, X ) and */
323 /* CALL SCENCD ( '2/t2', SC, Y ), then */
324
325 /* X = Y. */
326
327 /* The individual routines TIKSnn, where nn is the */
328 /* clock type code, contain more detailed information */
329 /* on the conversion process. */
330
331 /* $ Parameters */
332
333 /* MXPART is the maximum number of spacecraft clock partitions */
334 /* expected in the kernel file for any one spacecraft. */
335 /* See the INCLUDE file sclk.inc for this parameter's */
336 /* value. */
337
338 /* $ Exceptions */
339
340 /* 1) If the number of partitions in the kernel file for spacecraft */
341 /* SC exceeds the parameter MXPART, the error */
342 /* 'SPICE(TOOMANYPARTS)' is signaled. */
343
344
345 /* If a partition number is included in the SCLK string, the */
346 /* following exceptions may occur: */
347
348 /* 2) If the partition number cannot be parsed as an integer, the */
349 /* error 'SPICE(BADPARTNUMBER)' is signaled. */
350
351 /* 3) If the partition number is not in the range of the number of */
352 /* partitions found in the kernel pool, the error */
353 /* 'SPICE(BADPARTNUMBER)' is signaled. */
354
355 /* 4) If the clock count does not fall in the boundaries of the */
356 /* specified partition, the error 'SPICE(NOTINPART)' is */
357 /* signaled. */
358
359
360 /* If a partition number is not included in the SCLK string, the */
361 /* following exception may occur. */
362
363 /* 5) If the clock count does not fall in the boundaries of any */
364 /* partition found in the kernel pool, the error */
365 /* 'SPICE(NOPARTITION)' is signaled. */
366
367 /* The following error is signaled by a routine called by SCENCD */
368
369 /* 6) If any of the extracted clock components cannot be parsed as */
370 /* integers, or the string has too many components, or the value */
371 /* of one of the components is less than the offset value, then */
372 /* the error SPICE(INVALIDSCLKSTRING) is signaled. */
373
374 /* $ Files */
375
376 /* A kernel file containing spacecraft clock partition information */
377 /* for the desired spacecraft must be loaded, using the routines */
378 /* CLPOOL and FURNSH, before calling this routine. */
379
380 /* $ Particulars */
381
382 /* In general, it is difficult to compare spacecraft clock counts */
383 /* numerically since there are too many clock components for a */
384 /* single comparison. This routine provides a method of assigning a */
385 /* single double precision number to a spacecraft's clock count, */
386 /* given one of its character representations. */
387
388 /* The routine SCDECD performs the inverse operation to SCENCD, */
389 /* converting an encoded double precision number to character format. */
390
391 /* To convert the string to ticks since the start of the mission, */
392 /* SCENCD */
393
394 /* 1) Converts the non-partition portion of the string to */
395 /* ticks, using the routine SCTIKS. */
396
397 /* 2) Determines the partition number for the clock time, */
398 /* either by getting it directly from the input string, or */
399 /* determining the default partition if none was specified. */
400
401 /* 3) Includes partition start and stop times, which are also */
402 /* measured in ticks, to compute the number of ticks */
403 /* since the beginning of the mission of the clock time. */
404
405 /* $ Examples */
406
407 /* Double precision encodings of spacecraft clock counts are used to */
408 /* tag pointing data in the C-kernel. */
409
410 /* In the following example, pointing for a sequence of images from */
411 /* the Voyager 2 narrow angle camera is requested from the C-kernel */
412 /* using an array of character spacecraft clock counts as input. */
413 /* The clock counts attached to the output are then decoded to */
414 /* character and compared with the input strings. */
415
416 /* CHARACTER*(25) SCLKIN ( 4 ) */
417 /* CHARACTER*(25) SCLKOUT */
418 /* CHARACTER*(25) CLKTOL */
419
420 /* DOUBLE PRECISION TIMEIN */
421 /* DOUBLE PRECISION TIMOUT */
422 /* DOUBLE PRECISION CMAT ( 3, 3 ) */
423
424 /* INTEGER NPICS */
425 /* INTEGER SC */
426
427 /* DATA NPICS / 4 / */
428
429 /* DATA SCLKIN / '2 / 20538:39:768', */
430 /* . '2 / 20543:21:768', */
431 /* . '2 / 20550:37', */
432 /* . '2 / 20561:59' / */
433
434 /* DATA CLKTOL / ' 0:01:000' / */
435
436 /* C */
437 /* C The instrument we want pointing for is the Voyager 2 */
438 /* C narrow angle camera. The reference frame we want is */
439 /* C J2000. The spacecraft is Voyager 2. */
440 /* C */
441 /* INST = -32001 */
442 /* REF = 'J2000' */
443 /* SC = -32 */
444
445 /* C */
446 /* C Load the appropriate files. We need */
447 /* C */
448 /* C 1) CK file containing pointing data. */
449 /* C 2) Spacecraft clock kernel file, for SCENCD and SCDECD. */
450 /* C */
451 /* CALL CKLPF ( 'VGR2NA.CK' ) */
452 /* CALL CLPOOL */
453 /* CALL FURNSH ( 'SCLK.KER' ) */
454
455 /* C */
456 /* C Convert the tolerance string to ticks. */
457 /* C */
458 /* CALL SCTIKS ( SC, CLKTOL, TOL ) */
459
460 /* DO I = 1, NPICS */
461
462 /* CALL SCENCD ( SC, SCLKIN( I ), TIMEIN ) */
463
464 /* CALL CKGP ( INST, TIMEIN, TOL, REF, CMAT, TIMOUT, */
465 /* . FOUND ) */
466
467 /* CALL SCDECD ( SC, TIMOUT, SCLKOUT ) */
468
469 /* WRITE (*,*) */
470 /* WRITE (*,*) 'Input s/c clock count: ', SCLKIN( I ) */
471 /* WRITE (*,*) 'Output s/c clock count: ', SCLKOUT */
472 /* WRITE (*,*) 'Output C-Matrix: ', CMAT */
473 /* WRITE (*,*) */
474
475 /* END DO */
476
477 /* The output from such a program might look like: */
478
479
480 /* Input s/c clock count: 2 / 20538:39:768 */
481 /* Output s/c clock count: 2/20538:39:768 */
482 /* Output C-Matrix: 'first C-matrix' */
483
484 /* Input s/c clock count: 2 / 20543:21:768 */
485 /* Output s/c clock count: 2/20543:22:768 */
486 /* Output C-Matrix: 'second C-matrix' */
487
488 /* Input s/c clock count: 2 / 20550:37 */
489 /* Output s/c clock count: 2/20550:36:768 */
490 /* Output C-Matrix: 'third C-matrix' */
491
492 /* Input s/c clock count: 2 / 20561:59 */
493 /* Output s/c clock count: 2/20561:58:768 */
494 /* Output C-Matrix: 'fourth C-matrix' */
495
496 /* $ Restrictions */
497
498 /* None. */
499
500 /* $ Literature_References */
501
502 /* None. */
503
504 /* $ Author_and_Institution */
505
506 /* N.J. Bachman (JPL) */
507 /* J.M. Lynch (JPL) */
508 /* R.E. Thurman (JPL) */
509
510 /* $ Version */
511
512 /* - SPICELIB Version 1.2.0, 28-FEB-2014 (BVS) */
513
514 /* Added FAILED checks to prevent passing uninitialized values to */
515 /* ANINT, which can causing numeric exceptions on some */
516 /* environments. */
517
518 /* - SPICELIB Version 1.1.0, 05-FEB-2008 (NJB) */
519
520 /* The values of the parameter MXPART is now */
521 /* provided by the INCLUDE file sclk.inc. */
522
523 /* - SPICELIB Version 1.0.2, 22-AUG-2006 (EDW) */
524
525 /* Replaced references to LDPOOL with references */
526 /* to FURNSH. */
527
528 /* - SPICELIB Version 1.0.1, 10-MAR-1992 (WLT) */
529
530 /* Comment section for permuted index source lines was added */
531 /* following the header. */
532
533 /* - SPICELIB Version 1.0.0, 03-SEP-1990 (JML) (RET) */
534
535 /* -& */
536 /* $ Index_Entries */
537
538 /* encode spacecraft_clock */
539
540 /* -& */
541
542 /* SPICELIB functions */
543
544
545 /* Local variables */
546
547
548 /* Standard SPICE error handling. */
549
550 if (return_()) {
551 return 0;
552 } else {
553 chkin_("SCENCD", (ftnlen)6);
554 }
555
556 /* Convert the non-partition portion of the clock string to ticks. */
557
558 pos = cpos_(sclkch, "/", &c__1, sclkch_len, (ftnlen)1);
559 i__1 = pos;
560 sctiks_(sc, sclkch + i__1, &ticks, sclkch_len - i__1);
561 if (failed_()) {
562 chkout_("SCENCD", (ftnlen)6);
563 return 0;
564 }
565 ticks = d_nint(&ticks);
566
567 /* Read the partition start and stop times (in ticks) for this */
568 /* mission. Error if there are too many of them. */
569
570 scpart_(sc, &nparts, pstart, pstop);
571 if (failed_()) {
572 chkout_("SCENCD", (ftnlen)6);
573 return 0;
574 }
575 if (nparts > 9999) {
576 setmsg_("The number of partitions, #, for spacecraft # exceeds the v"
577 "alue for parameter MXPART, #.", (ftnlen)88);
578 errint_("#", &nparts, (ftnlen)1);
579 errint_("#", sc, (ftnlen)1);
580 errint_("#", &c__9999, (ftnlen)1);
581 sigerr_("SPICE(TOOMANYPARTS)", (ftnlen)19);
582 chkout_("SCENCD", (ftnlen)6);
583 return 0;
584 }
585
586 /* PSTART and PSTOP represent integers but are read from the */
587 /* kernel pool as double precision numbers. Make them whole */
588 /* numbers so that logical tests may be performed with them. */
589
590 i__1 = nparts;
591 for (i__ = 1; i__ <= i__1; ++i__) {
592 pstop[(i__2 = i__ - 1) < 9999 && 0 <= i__2 ? i__2 : s_rnge("pstop",
593 i__2, "scencd_", (ftnlen)500)] = d_nint(&pstop[(i__3 = i__ -
594 1) < 9999 && 0 <= i__3 ? i__3 : s_rnge("pstop", i__3, "scenc"
595 "d_", (ftnlen)500)]);
596 pstart[(i__2 = i__ - 1) < 9999 && 0 <= i__2 ? i__2 : s_rnge("pstart",
597 i__2, "scencd_", (ftnlen)501)] = d_nint(&pstart[(i__3 = i__ -
598 1) < 9999 && 0 <= i__3 ? i__3 : s_rnge("pstart", i__3, "scen"
599 "cd_", (ftnlen)501)]);
600 }
601 /* For each partition, compute the total number of ticks in that */
602 /* partition plus all preceding partitions. */
603
604 d__1 = pstop[0] - pstart[0];
605 ptotls[0] = d_nint(&d__1);
606 i__1 = nparts;
607 for (i__ = 2; i__ <= i__1; ++i__) {
608 d__1 = ptotls[(i__3 = i__ - 2) < 9999 && 0 <= i__3 ? i__3 : s_rnge(
609 "ptotls", i__3, "scencd_", (ftnlen)512)] + pstop[(i__4 = i__
610 - 1) < 9999 && 0 <= i__4 ? i__4 : s_rnge("pstop", i__4, "sce"
611 "ncd_", (ftnlen)512)] - pstart[(i__5 = i__ - 1) < 9999 && 0 <=
612 i__5 ? i__5 : s_rnge("pstart", i__5, "scencd_", (ftnlen)512)];
613 ptotls[(i__2 = i__ - 1) < 9999 && 0 <= i__2 ? i__2 : s_rnge("ptotls",
614 i__2, "scencd_", (ftnlen)512)] = d_nint(&d__1);
615 }
616
617 /* Determine the partition number for the input clock string: */
618
619 /* If it was included in the string make sure it's valid for */
620 /* this mission. */
621
622 /* Error if */
623
624 /* 1) The partition number can't be parsed. */
625 /* 2) The partition number is not in the range 1 to the number */
626 /* of partitions. */
627 /* 3) The clock count does not fall in the boundaries of the */
628 /* specified partition. */
629
630 /* If it wasn't included, determine the default partition for */
631 /* this clock count. */
632
633 /* Error if */
634
635 /* 1) The clock count does not fall in the boundaries of any */
636 /* of the partitions. */
637
638
639 if (pos == 1) {
640 setmsg_("Unable to parse the partition number from SCLK string #.", (
641 ftnlen)56);
642 errch_("#", sclkch, (ftnlen)1, sclkch_len);
643 sigerr_("SPICE(BADPARTNUMBER)", (ftnlen)20);
644 chkout_("SCENCD", (ftnlen)6);
645 return 0;
646 }
647 if (pos > 1) {
648 part = 0;
649 nparsi_(sclkch, &part, error, &pnter, pos - 1, (ftnlen)25);
650 if (s_cmp(error, " ", (ftnlen)25, (ftnlen)1) != 0) {
651 setmsg_("Unable to parse the partition number from SCLK string #."
652 , (ftnlen)56);
653 errch_("#", sclkch, (ftnlen)1, sclkch_len);
654 sigerr_("SPICE(BADPARTNUMBER)", (ftnlen)20);
655 chkout_("SCENCD", (ftnlen)6);
656 return 0;
657 } else if (part <= 0 || part > nparts) {
658 setmsg_("Partition number # taken from SCLK string # is not in a"
659 "cceptable range 1 to #.", (ftnlen)78);
660 errint_("#", &part, (ftnlen)1);
661 errch_("#", sclkch, (ftnlen)1, sclkch_len);
662 errint_("#", &nparts, (ftnlen)1);
663 sigerr_("SPICE(BADPARTNUMBER)", (ftnlen)20);
664 chkout_("SCENCD", (ftnlen)6);
665 return 0;
666 } else if (ticks < pstart[(i__1 = part - 1) < 9999 && 0 <= i__1 ?
667 i__1 : s_rnge("pstart", i__1, "scencd_", (ftnlen)575)] ||
668 ticks > pstop[(i__2 = part - 1) < 9999 && 0 <= i__2 ? i__2 :
669 s_rnge("pstop", i__2, "scencd_", (ftnlen)575)]) {
670 setmsg_("SCLK count # does not fall in the boundaries of partiti"
671 "on number #.", (ftnlen)67);
672 errch_("#", sclkch, (ftnlen)1, sclkch_len);
673 errint_("#", &part, (ftnlen)1);
674 sigerr_("SPICE(NOTINPART)", (ftnlen)16);
675 chkout_("SCENCD", (ftnlen)6);
676 return 0;
677 }
678 } else {
679 part = 1;
680 while(part <= nparts && (ticks < pstart[(i__1 = part - 1) < 9999 && 0
681 <= i__1 ? i__1 : s_rnge("pstart", i__1, "scencd_", (ftnlen)
682 592)] || ticks > pstop[(i__2 = part - 1) < 9999 && 0 <= i__2 ?
683 i__2 : s_rnge("pstop", i__2, "scencd_", (ftnlen)592)])) {
684 ++part;
685 }
686 if (part > nparts) {
687 setmsg_("SCLK count # does not fall in the boundaries of any of "
688 "the partitions for spacecraft #.", (ftnlen)87);
689 errch_("#", sclkch, (ftnlen)1, sclkch_len);
690 errint_("#", sc, (ftnlen)1);
691 sigerr_("SPICE(NOPARTITION)", (ftnlen)18);
692 chkout_("SCENCD", (ftnlen)6);
693 return 0;
694 }
695 }
696
697 /* Now we have a valid partition number, and the number of ticks for */
698 /* the clock string. To convert to ticks since the start of the */
699 /* mission, add in the total number of ticks in preceding partitions */
700 /* and subtract off the starting ticks value for this partition. */
701
702 if (part > 1) {
703 *sclkdp = ticks - pstart[(i__1 = part - 1) < 9999 && 0 <= i__1 ? i__1
704 : s_rnge("pstart", i__1, "scencd_", (ftnlen)622)] + ptotls[(
705 i__2 = part - 2) < 9999 && 0 <= i__2 ? i__2 : s_rnge("ptotls",
706 i__2, "scencd_", (ftnlen)622)];
707 } else {
708 *sclkdp = ticks - pstart[(i__1 = part - 1) < 9999 && 0 <= i__1 ? i__1
709 : s_rnge("pstart", i__1, "scencd_", (ftnlen)624)];
710 }
711 chkout_("SCENCD", (ftnlen)6);
712 return 0;
713 } /* scencd_ */
714
715