1 /* enchar.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      ENCHAR ( Encode a character string ) */
enchar_0_(int n__,integer * number,char * string,ftnlen string_len)9 /* Subroutine */ int enchar_0_(int n__, integer *number, char *string, ftnlen
10 	string_len)
11 {
12     /* Builtin functions */
13     integer i_len(char *, ftnlen);
14 
15     /* Local variables */
16     integer base, i__;
17     extern /* Subroutine */ int chkin_(char *, ftnlen);
18     extern integer chbase_(void);
19     integer remain;
20     extern /* Subroutine */ int sigerr_(char *, ftnlen), chkout_(char *,
21 	    ftnlen);
22     extern logical return_(void);
23     integer num;
24 
25 /* $ Abstract */
26 
27 /*     Encode a nonnegative integer number into a character string */
28 /*     as the expansion of the number in base CHBASE (a function of */
29 /*     the size of the available character set). */
30 
31 /* $ Disclaimer */
32 
33 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
34 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
35 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
36 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
37 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
38 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
39 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
40 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
41 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
42 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
43 
44 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
45 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
46 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
47 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
48 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
49 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
50 
51 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
52 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
53 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
54 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
55 
56 /* $ Required_Reading */
57 
58 /*     None. */
59 
60 /* $ Keywords */
61 
62 /*     CELLS, CHARACTER */
63 
64 /* $ Declarations */
65 /* $ Brief_I/O */
66 
67 /*     VARIABLE  I/O  DESCRIPTION */
68 /*     --------  ---  -------------------------------------------------- */
69 /*     NUMBER     I   Number to be encoded. */
70 /*     STRING     O   Encoded string. */
71 /*     MINLEN     P   Minimum length of string. */
72 
73 /* $ Detailed_Input */
74 
75 /*     NUMBER      is an arbitrary nonnegative integer. */
76 
77 /* $ Detailed_Output */
78 
79 /*     STRING      is the character string implied by the ASCII */
80 /*                 interpretation of NUMBER when converted to its */
81 /*                 base CHBASE representation. */
82 
83 /*                 Let L be the declared length of STRING, and let */
84 /*                 NUMBER be given by */
85 
86 /*                                     0           1                 L-1 */
87 /*                    NUMBER = a CHBASE  + a CHBASE  + ... + a CHBASE */
88 /*                              1           2                 L */
89 
90 /*                 Then */
91 
92 /*                    STRING(i:i) = CHAR(a )   for i = 1, L */
93 /*                                        i */
94 
95 /*                 Note that, just as for any other "numbers", */
96 /*                 the "digits" in STRING are arranged from right */
97 /*                 to left in order of increasing significance. */
98 /*                 The string is, in effect, "padded with nulls" */
99 /*                 on the left. */
100 
101 /* $ Parameters */
102 
103 /*     MINLEN      is the minimum length of a string into which a */
104 /*                 number may be encoded. In order to avoid padding */
105 /*                 long strings with hundreds, possibly thousands */
106 /*                 of null characters, only the first MINLEN characters */
107 /*                 of the string are actually used. Note that this */
108 /*                 also allows the encoded number to be preserved */
109 /*                 during assignments, */
110 
111 /*                    STR1 = STR2 */
112 
113 /*                 so long as both strings are of length MINLEN or */
114 /*                 greater. */
115 
116 /* $ Exceptions */
117 
118 /*     1) If the length of the output string is less than MINLEN, */
119 /*        the error 'SPICE(INSUFFLEN)' is signalled. */
120 
121 /*     2) If the number to be encoded is negative, the error */
122 /*        'SPICE(OUTOFRANGE)' is signalled. */
123 
124 /*                                                         MINLEN */
125 /*     3) If the number to be encoded is larger than CHBASE       - 1, */
126 /*        the error 'SPICE(OUTOFRANGE)' is signalled. */
127 
128 /* $ Files */
129 
130 /*     None. */
131 
132 /* $ Particulars */
133 
134 /*     The value of CHBASE, which varies from machine to machine, is */
135 /*     returned by a constant function of the same name. */
136 
137 /* $ Examples */
138 
139 /*     See: SCARDC, SSIZEC. */
140 
141 /* $ Restrictions */
142 
143 /*     None. */
144 
145 /* $ Literature_References */
146 
147 /*     None. */
148 
149 /* $ Author_and_Institution */
150 
151 /*     W.L. Taber      (JPL) */
152 /*     I.M. Underwood  (JPL) */
153 /*     B.V. Semenov    (JPL) */
154 
155 /* $ Version */
156 
157 /* -    SPICELIB Version 1.0.2, 31-JAN-2008 (BVS) */
158 
159 /*        Changed header section title '$C Revision' to '$C Revisions'. */
160 
161 /* -    SPICELIB Version 1.0.1, 10-MAR-1992 (WLT) */
162 
163 /*        Comment section for permuted index source lines was added */
164 /*        following the header. */
165 
166 /* -    SPICELIB Version 1.0.0, 31-JAN-1990 (WLT) (IMU) */
167 
168 /* -& */
169 /* $ Index_Entries */
170 
171 /*     encode a character_string */
172 
173 /* -& */
174 /* $ Revisions */
175 
176 /* -    Beta Version 2.0.0, 13-JAN-1989 (IMU) */
177 
178 /*        Only the first MINLEN characters of the string are now */
179 /*        used to encode the value. Also, negative values are now */
180 /*        treated as errors. */
181 
182 /* -& */
183 
184 /*     SPICELIB functions */
185 
186 
187 /*     Local variables */
188 
189 
190 /*     Standard SPICE error handling. */
191 
192     switch(n__) {
193 	case 1: goto L_dechar;
194 	}
195 
196     if (return_()) {
197 	return 0;
198     } else if (i_len(string, string_len) < 5) {
199 	chkin_("ENCHAR", (ftnlen)6);
200 	sigerr_("SPICE(INSUFFLEN)", (ftnlen)16);
201 	chkout_("ENCHAR", (ftnlen)6);
202 	return 0;
203     } else if (*number < 0) {
204 	chkin_("ENCHAR", (ftnlen)6);
205 	sigerr_("SPICE(OUTOFRANGE)", (ftnlen)17);
206 	chkout_("ENCHAR", (ftnlen)6);
207 	return 0;
208     }
209 
210 /*     Generate the digits from right to left. */
211 
212     base = chbase_();
213     num = *number;
214     for (i__ = 5; i__ >= 1; --i__) {
215 	remain = num % base;
216 	*(unsigned char *)&string[i__ - 1] = (char) remain;
217 	num /= base;
218     }
219 
220 /*     More error handling. */
221 
222     if (num > 0) {
223 	chkin_("ENCHAR", (ftnlen)6);
224 	sigerr_("SPICE(OUTOFRANGE)", (ftnlen)17);
225 	chkout_("ENCHAR", (ftnlen)6);
226     }
227     return 0;
228 /* $Procedure      DECHAR ( Decode a character string ) */
229 
230 L_dechar:
231 /* $ Abstract */
232 
233 /*     Decode a character string encoded by ENCHAR. */
234 
235 /* $ Disclaimer */
236 
237 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
238 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
239 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
240 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
241 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
242 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
243 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
244 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
245 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
246 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
247 
248 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
249 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
250 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
251 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
252 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
253 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
254 
255 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
256 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
257 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
258 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
259 
260 /* $ Required_Reading */
261 
262 /*     None. */
263 
264 /* $ Keywords */
265 
266 /*     CHARACTER */
267 
268 /* $ Declarations */
269 
270 /*     CHARACTER*(*)      STRING */
271 /*     INTEGER            NUMBER */
272 
273 /* $ Brief_I/O */
274 
275 /*     VARIABLE  I/O  DESCRIPTION */
276 /*     --------  ---  -------------------------------------------------- */
277 /*     STRING     I   Encoded character string. */
278 /*     NUMBER     O   Decoded number. */
279 
280 /* $ Detailed_Input */
281 
282 /*     STRING      is a character string previously encoded by ENCHAR. */
283 /*                 This contains an integer in base CHBASE notation, */
284 /*                 where CHBASE is a function of the size of the */
285 /*                 available character set. See ENCHAR for details */
286 /*                 about the format of STRING. */
287 
288 /* $ Detailed_Output */
289 
290 /*     NUMBER      is the integer encoded in the input string. */
291 
292 /* $ Parameters */
293 
294 /*     None. */
295 
296 /* $ Exceptions */
297 
298 /*     1) If the length of the input string is less than MINLEN, */
299 /*        the error 'SPICE(INSUFFLEN)' is signalled. */
300 
301 /* $ Files */
302 
303 /*     None. */
304 
305 /* $ Particulars */
306 
307 /*     DECHAR is the inverse of ENCHAR. In the example below, */
308 
309 /*           CALL ENCHAR (      I, STRING ) */
310 /*           CALL DECHAR ( STRING,      J ) */
311 
312 /*           IF ( I .EQ. J ) THEN */
313 /*            . */
314 /*            . */
315 /*           END IF */
316 
317 /*     the logical test (I .EQ. J) is always true. */
318 
319 /* $ Examples */
320 
321 /*     See: CARDC, SIZEC. */
322 
323 /* $ Restrictions */
324 
325 /*     None. */
326 
327 /* $ Literature_References */
328 
329 /*     None. */
330 
331 /* $ Author_and_Institution */
332 
333 /*     W.L. Taber      (JPL) */
334 /*     I.M. Underwood  (JPL) */
335 /*     B.V. Semenov    (JPL) */
336 
337 /* $ Version */
338 
339 /* -    SPICELIB Version 1.0.2, 31-JAN-2008 (BVS) */
340 
341 /*        Changed header section title '$C Revision' to '$C Revisions'. */
342 
343 /* -    SPICELIB Version 1.0.1, 10-MAR-1992 (WLT) */
344 
345 /*        Comment section for permuted index source lines was added */
346 /*        following the header. */
347 
348 /* -    SPICELIB Version 1.0.0, 31-JAN-1990 (WLT) (IMU) */
349 
350 /* -& */
351 /* $ Index_Entries */
352 
353 /*     decode a character_string */
354 
355 /* -& */
356 /* $ Revisions */
357 
358 /* -    Beta Version 2.0.0, 13-JAN-1989 (IMU) */
359 
360 /*        Changed to reflect changes in ENCHAR. In particular, */
361 /*        it now checks the length of the input string. It is */
362 /*        also an entry point of ENCHAR, to make sure they always */
363 /*        have the same value of MINLEN. (Also, if CHBASE is */
364 /*        changed, ENCHAR and DECHAR will always be recompiled */
365 /*        simultaneously.) */
366 
367 /* -& */
368 
369 /*     Standard SPICE error handling. */
370 
371     if (return_()) {
372 	return 0;
373     } else if (i_len(string, string_len) < 5) {
374 	chkin_("DECHAR", (ftnlen)6);
375 	sigerr_("SPICE(INSUFFLEN)", (ftnlen)16);
376 	chkout_("DECHAR", (ftnlen)6);
377 	return 0;
378     }
379 
380 /*     Sum the products of the 'digits' and the corresponding powers */
381 /*     of NDCHAR, just like any other base conversion. */
382 
383     base = chbase_();
384     *number = 0;
385     for (i__ = 1; i__ <= 5; ++i__) {
386 	*number = base * *number + *(unsigned char *)&string[i__ - 1];
387     }
388     return 0;
389 } /* enchar_ */
390 
enchar_(integer * number,char * string,ftnlen string_len)391 /* Subroutine */ int enchar_(integer *number, char *string, ftnlen string_len)
392 {
393     return enchar_0_(0, number, string, string_len);
394     }
395 
dechar_(char * string,integer * number,ftnlen string_len)396 /* Subroutine */ int dechar_(char *string, integer *number, ftnlen string_len)
397 {
398     return enchar_0_(1, number, string, string_len);
399     }
400 
401