1 /* sctiks.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 /* $Procedure      SCTIKS ( Convert spacecraft clock string to ticks. ) */
sctiks_(integer * sc,char * clkstr,doublereal * ticks,ftnlen clkstr_len)9 /* Subroutine */ int sctiks_(integer *sc, char *clkstr, doublereal *ticks,
10 	ftnlen clkstr_len)
11 {
12     integer type__;
13     extern /* Subroutine */ int chkin_(char *, ftnlen), sctk01_(integer *,
14 	    char *, doublereal *, ftnlen), sigerr_(char *, ftnlen), chkout_(
15 	    char *, ftnlen), setmsg_(char *, ftnlen), errint_(char *, integer
16 	    *, ftnlen);
17     extern integer sctype_(integer *);
18     extern logical return_(void);
19 
20 /* $ Abstract */
21 
22 /*     Convert a spacecraft clock format string to number of "ticks". */
23 
24 /* $ Disclaimer */
25 
26 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
27 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
28 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
29 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
30 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
31 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
32 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
33 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
34 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
35 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
36 
37 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
38 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
39 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
40 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
41 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
42 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
43 
44 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
45 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
46 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
47 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
48 
49 /* $ Required_Reading */
50 
51 /*     SCLK */
52 
53 /* $ Keywords */
54 
55 /*     CONVERSION */
56 /*     TIME */
57 
58 /* $ Declarations */
59 
60 /* $ Brief_I/O */
61 
62 /*     Variable  I/O  Description */
63 /*     --------  ---  -------------------------------------------------- */
64 /*     SC         I   NAIF spacecraft identification code. */
65 /*     CLKSTR     I   Character representation of a spacecraft clock. */
66 /*     TICKS      O   Number of ticks represented by the clock string. */
67 
68 /* $ Detailed_Input */
69 
70 /*     SC         is the NAIF ID number for the spacecraft whose clock */
71 /*                string is being converted. */
72 
73 /*     CLKSTR     is a character string representing a spacecraft clock */
74 /*                time, WITHOUT PARTITION NUMBER. */
75 
76 /*                Using Galileo as an example, the full format is */
77 
78 /*                               wwwwwwww:xx:y:z */
79 
80 /*                where z is a mod-8 counter (values 0-7) which */
81 /*                increments approximately once every 8 1/3 ms., y is a */
82 /*                mod-10 counter (values 0-9) which increments once */
83 /*                every time z turns over, i.e., approximately once every */
84 /*                66 2/3 ms., xx is a mod-91 (values 0-90) counter */
85 /*                which increments once every time y turns over, i.e., */
86 /*                once every 2/3 seconds. wwwwwwww is the Real-Time Image */
87 /*                Count (RIM), which increments once every time xx turns */
88 /*                over, i.e., once every 60 2/3 seconds. The roll-over */
89 /*                expression for the RIM is 16777215, which corresponds */
90 /*                to approximately 32 years. */
91 
92 /*                wwwwwwww, xx, y, and z are referred to interchangeably */
93 /*                as the fields or components of the spacecraft clock. */
94 /*                SCLK components may be separated by any of the */
95 /*                following characters: ' '  '.'  ':'  ','  '-' */
96 /*                Any number of spaces may separate the components and */
97 /*                the delimiters. The presence of the RIM component */
98 /*                is required. Successive components may be omitted, and */
99 /*                in such cases are assumed to represent zero values. */
100 
101 /*                Values for the individual components may exceed the */
102 /*                maximum expected values. For instance, '0:0:0:9' is */
103 /*                an acceptable Galileo clock string, and will convert */
104 /*                to the same number of ticks as '0:0:1:1'. */
105 
106 /*                Consecutive delimiters containing no intervening digits */
107 /*                are treated as if they delimit zero components. */
108 
109 /*                Trailing zeros should always be included to match the */
110 /*                length of the counter.  For example, a Galileo clock */
111 /*                count of '25684.90' should not be represented as */
112 /*                '25684.9'. */
113 
114 /*                Some spacecraft clock components have offset, or */
115 /*                starting, values different from zero.  For example, */
116 /*                with an offset value of 1, a mod 20 counter would */
117 /*                cycle from 1 to 20 instead of from 0 to 19. */
118 
119 /*                See the SCLK required reading for a detailed */
120 /*                description of the Voyager and Mars Observer clock */
121 /*                formats. */
122 
123 
124 /* $ Detailed_Output */
125 
126 /*     TICKS      is the number of ticks represented by the spacecraft */
127 /*                clock string. A tick is defined to be the smallest */
128 /*                time increment expressible by the spacecraft clock. */
129 
130 /*                An analogy may be drawn between a spacecraft clock */
131 /*                and a standard wall clock, measuring hours, minutes */
132 /*                and seconds. The number of ticks represented by the */
133 /*                wall clock string */
134 /*                                     hh:mm:ss */
135 
136 /*                would be the number of seconds represented by that */
137 /*                time. */
138 
139 /*                For example: */
140 
141 /*                         00:00:10  would convert to 10 */
142 /*                         00:01:00  would convert to 60 */
143 /*                         00:10:00  would convert to 600 */
144 /*                         01:00:00  would convert to 3600 */
145 /*                         01:01:00  would convert to 3660 */
146 
147 /*                See the Examples section below for examples for */
148 /*                actual spacecraft clocks. */
149 
150 /* $ Parameters */
151 
152 /*     None. */
153 
154 /* $ Exceptions */
155 
156 /*     1)  If the spacecraft clock type is not supported then the */
157 /*         error SPICE(NOTSUPPORTED) is signalled. */
158 
159 /*     2)  If any of the extracted clock components cannot be parsed as */
160 /*         integers, or the string has too many components, or the value */
161 /*         of one of the components is less than the offset value, then */
162 /*         the error is diagnosed by routines called by this routine. */
163 
164 /*     3)  Invalid spacecraft ID's are not diagnosed. */
165 
166 /* $ Files */
167 
168 /*     None. */
169 
170 /* $ Particulars */
171 
172 /*     Each spacecraft is assigned a clock type code in the kernel file. */
173 /*     SCTIKS calls the function SCTYPE to determine this value. If the */
174 /*     clock type is supported by SPICELIB, then the routine TIKSnn is */
175 /*     called to handle the actual conversion from clock format to number */
176 /*     of ticks. The nn in TIKSnn refers to the spacecraft clock type */
177 /*     code. Different spacecraft have distict clock formats but can */
178 /*     still be of the same clock type. */
179 
180 /*     The TIKSnn routines are entry points to the routines SCLKnn, which */
181 /*     also contain the ticks-to-clock format conversion routines FMTnn. */
182 /*     FMTnn is called by the subroutine SCFMT, which performs the */
183 /*     inverse operation to SCTIKS. */
184 
185 /*     Note the important difference between SCENCD and SCTIKS. SCENCD */
186 /*     converts a clock string to the number of ticks it represents */
187 /*     since the beginning of the mission, and so uses partition */
188 /*     information. SCTIKS just converts to absolute ticks. */
189 
190 /* $ Examples */
191 
192 /*     SCTIKS is used as part of the process of encoding spacecraft clock */
193 /*     by SCENCD, though SCTIKS does not process any partition informa- */
194 /*     tion. */
195 
196 /*     Another use of SCTIKS, however, is to convert a clock measurement */
197 /*     to ticks for use as a tolerance for the CK reader CKGP. */
198 
199 
200 /*     C */
201 /*     C      Get the pointing from a CK file of the VGR 1 narrow angle */
202 /*     C      image corresponding to a particular SCLK count. */
203 /*     C */
204 /*     C      Load the CK file and the kernel file containing SCLK */
205 /*     C      partition information for SCENCD. */
206 /*     C */
207 /*            CALL CKLPF  ( 'VGR1NA.CK', HANDLE ) */
208 /*            CALL FURNSH ( 'SCLK.KER' ) */
209 
210 /*     C */
211 /*     C      Get the right ID numbers. */
212 /*     C */
213 /*            SC    = -31 */
214 /*            INSTR = -31001 */
215 
216 /*     C */
217 /*     C      The SCLK string includes a partition number. Pictures are */
218 /*     C      never shuttered at intervals smaller than 1 MOD60 count */
219 /*     C      from each other. So use 1 MOD60 count as the time */
220 /*     C      tolerance. */
221 /*     C */
222 /*            CLKSTR = '1/20556:14:768' */
223 /*            TOLSTR = '      0:01:000' */
224 
225 /*     C */
226 /*     C      Encode the clock string and the tolerance. */
227 /*     C */
228 /*            CALL SCENCD ( SC, CLKSTR, SCLK ) */
229 /*            CALL SCTIKS ( SC, TOLSTR, TOL  ) */
230 
231 /*     C */
232 /*     C      Get the pointing from the C-kernel. */
233 /*     C */
234 /*            CALL CKGP ( INSTR, SCLK, TOL, REF, CMAT, CLKOUT, FOUND ) */
235 
236 
237 
238 /*      Below are some examples illustrating various clock string inputs */
239 /*      and the resulting outputs for the Galileo spacecraft. See the */
240 /*      SCLK required reading for a detailed description of the Galileo */
241 /*      clock format. */
242 
243 /*         CLKSTR                TICKS */
244 /*         ----------------      -------------------- */
245 /*         '0:0:0:1'             1 */
246 /*         '0:0:1'               8 */
247 /*         '0:1'                 80 */
248 /*         '1'                   7280 */
249 /*         '1 0 0 0'             7280 */
250 /*         '1,0,0,0'             7280 */
251 /*         '1:90'                14480 */
252 /*         '1:9'                 8000 */
253 /*         '1:09'                8000 */
254 /*         '0-0-10'              80   |--  Third component is supposed */
255 /*         '0-1-0'               80   |    to be a mod-10 count. */
256 /*         '0/1/0'               Error: '/' is not an accepted delimiter. */
257 /*         '1: 00 : 0 : 1'       7281 */
258 /*         '1:::1'               7281 */
259 /*         '1.1.1.1.1'           Error: Too many components */
260 /*         '1.1.1.1.'            Error: The last delimiter signals that */
261 /*                                      a fifth component will follow. */
262 
263 
264 /*         The following examples are for the Voyager 2 spacecraft. Note */
265 /*         that the last component of the Voyager clock has an offset */
266 /*         value of 1. */
267 
268 /*         CLKSTR                TICKS */
269 /*         ----------------      -------------------- */
270 /*          '0.0.001'              0 */
271 /*          '0:0:002'              1 */
272 /*          '0:01'                 800 */
273 /*          '1'                    48000 */
274 /*          '1.0'                  48000 */
275 /*          '1.0.0'                Error: The 3rd component is never 0. */
276 /*          '0.0:100'              99 */
277 /*          '0-60-1'               48000 */
278 /*          '1-1-1'                48800 */
279 /*          '1-1-2'                48801 */
280 
281 
282 /* $ Restrictions */
283 
284 /*     None. */
285 
286 /* $ Literature_References */
287 
288 /*     None. */
289 
290 /* $ Author_and_Institution */
291 
292 /*     J.M. Lynch     (JPL) */
293 /*     R.E. Thurman   (JPL) */
294 
295 /* $ Version */
296 
297 /* -    SPICELIB Version 1.0.2, 22-AUG-2006 (EDW) */
298 
299 /*        Replaced references to LDPOOL with references */
300 /*        to FURNSH. */
301 
302 /* -    SPICELIB Version 1.0.1, 10-MAR-1992 (WLT) */
303 
304 /*        Comment section for permuted index source lines was added */
305 /*        following the header. */
306 
307 /* -    SPICELIB Version 1.0.0, 06-SEP-1990 (JML) (RET) */
308 
309 /* -& */
310 /* $ Index_Entries */
311 
312 /*     convert spacecraft_clock string to ticks */
313 
314 /* -& */
315 
316 /*     SPICELIB functions */
317 
318 
319 /*     Local variables */
320 
321 
322 /*     Standard SPICE error handling. */
323 
324     if (return_()) {
325 	return 0;
326     } else {
327 	chkin_("SCTIKS", (ftnlen)6);
328     }
329 
330 /*     If the spacecraft clock type is supported by NAIF then */
331 /*     call TIKSnn to perform the conversion. */
332 
333     type__ = sctype_(sc);
334     if (type__ == 1) {
335 	sctk01_(sc, clkstr, ticks, clkstr_len);
336     } else {
337 	setmsg_("Clock type # is not supported.", (ftnlen)30);
338 	errint_("#", &type__, (ftnlen)1);
339 	sigerr_("SPICE(NOTSUPPORTED)", (ftnlen)19);
340 	chkout_("SCTIKS", (ftnlen)6);
341 	return 0;
342     }
343     chkout_("SCTIKS", (ftnlen)6);
344     return 0;
345 } /* sctiks_ */
346 
347