1 |
/* |
2 |
* keystuff.c (linked from) ~rick/src/util |
3 |
* |
4 |
* library of miscellaneous utility functions for dealing with DRMS record keys |
5 |
* |
6 |
* append_keyval_to_primekeyval () |
7 |
* check_and_copy_key () |
8 |
* check_and_setkey_TYPE () |
9 |
* copy_prime_keys () |
10 |
* create_primekey_from_keylist () |
11 |
* drms_wcs_timestep () |
12 |
* propagate_keys () |
13 |
* |
14 |
* Bugs: |
15 |
* Commented out warnings of type mis-matches in check_and_copy_key |
16 |
* There is evidently a bug in append_keyval_to_primekeyval() in keystuff.c, |
17 |
* as the ingest_track module was generating a seg fault in |
18 |
* drms_setkey_string() with values of the PrimeKeyString like |
19 |
* 1987:000.0|22.5|-52.5|2002.03.30_00:44:30_TAI|1664|16.0|16.0|0.100000|0.000000|Postels|0.12500|0.00000|prog:mdi,level:lev1.5,series:fd_V_01h[80986-81014],sel:[53-36] |
20 |
* I was only able to work around this by changing the initial value of |
21 |
* buflen in append_keyval_to_primekeyval() from 128 to 256 |
22 |
* Many combinations of legitimate prefixes and unit strings for WCS time |
23 |
* descriptions are not yet supported |
24 |
* Consistency of floating-point key values in check_and_setkey_XXX is |
25 |
* only guaranteed to within the recommended format precision; this is |
26 |
* by design |
27 |
* check_and_setkey unimplemented for keys of type char and long long |
28 |
* |
29 |
* Revision history is at end of file |
30 |
*/ |
31 |
|
32 |
int check_and_set_key_short (DRMS_Record_t *new, const char *key, short val) { |
33 |
DRMS_Keyword_t *keywd; |
34 |
short vreq; |
35 |
int status; |
36 |
|
37 |
if (!(keywd = drms_keyword_lookup (new, key, 1))) return 0; |
38 |
if (keywd->info->recscope != 1) { |
39 |
/* it's not a constant, so don't worry, just set it */ |
40 |
drms_setkey_short (new, key, val); |
41 |
return 0; |
42 |
} |
43 |
vreq = drms_getkey_short (new, key, &status); |
44 |
if (status) { |
45 |
fprintf (stderr, "Error retrieving value for constant keyword %s\n", key); |
46 |
return 1; |
47 |
} |
48 |
if (vreq != val) { |
49 |
char format[256]; |
50 |
sprintf (format, |
51 |
"Error: parameter value %s for keyword %%s\n differs from required value %s\n", |
52 |
keywd->info->format, keywd->info->format); |
53 |
fprintf (stderr, format, val, key, vreq); |
54 |
return 1; |
55 |
} |
56 |
return 0; |
57 |
} |
58 |
|
59 |
int check_and_set_key_int (DRMS_Record_t *new, const char *key, int val) { |
60 |
DRMS_Keyword_t *keywd; |
61 |
int vreq; |
62 |
int status; |
63 |
|
64 |
if (!(keywd = drms_keyword_lookup (new, key, 1))) return 0; |
65 |
if (keywd->info->recscope != 1) { |
66 |
/* it's not a constant, so don't worry, just set it */ |
67 |
drms_setkey_int (new, key, val); |
68 |
return 0; |
69 |
} |
70 |
vreq = drms_getkey_int (new, key, &status); |
71 |
if (status) { |
72 |
fprintf (stderr, "Error retrieving value for constant keyword %s\n", key); |
73 |
return 1; |
74 |
} |
75 |
if (vreq != val) { |
76 |
char format[256]; |
77 |
sprintf (format, |
78 |
"Error: parameter value %s for keyword %%s\n differs from required value %s\n", |
79 |
keywd->info->format, keywd->info->format); |
80 |
fprintf (stderr, format, val, key, vreq); |
81 |
return 1; |
82 |
} |
83 |
return 0; |
84 |
} |
85 |
|
86 |
int check_and_set_key_float (DRMS_Record_t *new, const char *key, float val) { |
87 |
DRMS_Keyword_t *keywd; |
88 |
float vreq; |
89 |
int status; |
90 |
char sreq[128], sval[128]; |
91 |
|
92 |
if (!(keywd = drms_keyword_lookup (new, key, 1))) return 0; |
93 |
if (keywd->info->recscope != 1) { |
94 |
/* it's not a constant, so don't worry, just set it */ |
95 |
drms_setkey_float (new, key, val); |
96 |
return 0; |
97 |
} |
98 |
vreq = drms_getkey_float (new, key, &status); |
99 |
if (status) { |
100 |
fprintf (stderr, "Error retrieving value for constant keyword %s\n", key); |
101 |
return 1; |
102 |
} |
103 |
sprintf (sreq, keywd->info->format, vreq); |
104 |
sprintf (sval, keywd->info->format, val); |
105 |
if (strcmp (sreq, sval)) { |
106 |
char format[256]; |
107 |
sprintf (format, |
108 |
"Error: parameter value %s for keyword %%s\n differs from required value %s\n", |
109 |
keywd->info->format, keywd->info->format); |
110 |
fprintf (stderr, format, val, key, vreq); |
111 |
return 1; |
112 |
} |
113 |
return 0; |
114 |
} |
115 |
|
116 |
int check_and_set_key_double (DRMS_Record_t *new, const char *key, double val) { |
117 |
DRMS_Keyword_t *keywd; |
118 |
double vreq; |
119 |
int status; |
120 |
char sreq[128], sval[128]; |
121 |
|
122 |
if (!(keywd = drms_keyword_lookup (new, key, 1))) return 0; |
123 |
if (keywd->info->recscope != 1) { |
124 |
/* it's not a constant, so don't worry, just set it */ |
125 |
drms_setkey_double (new, key, val); |
126 |
return 0; |
127 |
} |
128 |
vreq = drms_getkey_double (new, key, &status); |
129 |
if (status) { |
130 |
fprintf (stderr, "Error retrieving value for constant keyword %s\n", key); |
131 |
return 1; |
132 |
} |
133 |
sprintf (sreq, keywd->info->format, vreq); |
134 |
sprintf (sval, keywd->info->format, val); |
135 |
if (strcmp (sreq, sval)) { |
136 |
char format[256]; |
137 |
sprintf (format, |
138 |
"Error: parameter value %s for keyword %%s\n differs from required value %s\n", |
139 |
keywd->info->format, keywd->info->format); |
140 |
fprintf (stderr, format, val, key, vreq); |
141 |
return 1; |
142 |
} |
143 |
return 0; |
144 |
} |
145 |
|
146 |
int check_and_set_key_str (DRMS_Record_t *new, const char *key, char *val) { |
147 |
DRMS_Keyword_t *keywd; |
148 |
char *vreq; |
149 |
int status; |
150 |
|
151 |
if (!(keywd = drms_keyword_lookup (new, key, 1))) return 0; |
152 |
if (keywd->info->recscope != 1) { |
153 |
/* it's not a constant, so don't worry, just set it */ |
154 |
drms_setkey_string (new, key, val); |
155 |
return 0; |
156 |
} |
157 |
vreq = drms_getkey_string (new, key, &status); |
158 |
if (status) { |
159 |
fprintf (stderr, "Error retrieving value for constant keyword %s\n", key); |
160 |
return 1; |
161 |
} |
162 |
if (strcmp (vreq, val)) { |
163 |
char format[256]; |
164 |
sprintf (format, |
165 |
"Error: parameter value \"%s\" for keyword %%s\n differs from required value \"%s\"\n", |
166 |
keywd->info->format, keywd->info->format); |
167 |
fprintf (stderr, format, val, key, vreq); |
168 |
return 1; |
169 |
} |
170 |
return 0; |
171 |
} |
172 |
|
173 |
int check_and_set_key_time (DRMS_Record_t *new, const char *key, TIME tval) { |
174 |
DRMS_Keyword_t *keywd; |
175 |
TIME treq; |
176 |
int status; |
177 |
char sreq[64], sval[64]; |
178 |
|
179 |
if (!(keywd = drms_keyword_lookup (new, key, 1))) return 0; |
180 |
if (keywd->info->recscope != 1) { |
181 |
/* it's not a constant, so don't worry, just set it */ |
182 |
drms_setkey_time (new, key, tval); |
183 |
return 0; |
184 |
} |
185 |
treq = drms_getkey_time (new, key, &status); |
186 |
if (status) { |
187 |
fprintf (stderr, "Error retrieving value for constant keyword %s\n", key); |
188 |
return 1; |
189 |
} |
190 |
sprint_time (sreq, treq, keywd->info->unit, atoi (keywd->info->format)); |
191 |
sprint_time (sval, tval, keywd->info->unit, atoi (keywd->info->format)); |
192 |
if (strcmp (sval, sreq)) { |
193 |
fprintf (stderr, "Error: parameter value %s for keyword %s\n", sval, key); |
194 |
fprintf (stderr, " differs from required value %s\n", sreq); |
195 |
return 1; |
196 |
} |
197 |
return 0; |
198 |
} |
199 |
|
200 |
int check_and_copy_key (DRMS_Record_t *new, DRMS_Record_t *old, |
201 |
const char *key) { |
202 |
DRMS_Keyword_t *oldkey, *newkey, *pkey; |
203 |
DRMS_Type_t *type; |
204 |
DRMS_Type_Value_t *value; |
205 |
int n, status; |
206 |
|
207 |
if (!(oldkey = drms_keyword_lookup (old, key, 1))) return 0; |
208 |
if (newkey = drms_keyword_lookup (new, key, 0)) { |
209 |
/* is it a link? */ |
210 |
if (newkey->info->islink) { |
211 |
int pkeyct = old->seriesinfo->pidx_num; |
212 |
type = (DRMS_Type_t *)malloc (pkeyct * sizeof (DRMS_Type_t)); |
213 |
value = (DRMS_Type_Value_t *)malloc (pkeyct * sizeof (DRMS_Type_Value_t)); |
214 |
for (n = 0; n < pkeyct; n++) { |
215 |
pkey = old->seriesinfo->pidx_keywords[n]; |
216 |
value[n] = drms_getkey (old, pkey->info->name, &type[n], NULL); |
217 |
} |
218 |
/* types and values refer to the prime keys specifying record old */ |
219 |
drms_setlink_dynamic (new, newkey->info->linkname, type, value); |
220 |
free (type); |
221 |
free (value); |
222 |
return 0; |
223 |
} |
224 |
} else { |
225 |
return 0; |
226 |
} |
227 |
/* check that key types agree (this could be relaxed) */ |
228 |
if (oldkey->info->type != newkey->info->type) { |
229 |
/* |
230 |
fprintf (stderr, "Warning: type for keyword %s differs in input and output\n", |
231 |
key); |
232 |
*/ |
233 |
; |
234 |
/* |
235 |
return 1; |
236 |
*/ |
237 |
} |
238 |
if (newkey->info->recscope != 1) { |
239 |
/* it's not a constant, so don't worry, just copy it */ |
240 |
/* but what if it is a link? */ |
241 |
drms_copykey (new, old, key); |
242 |
return 0; |
243 |
} |
244 |
switch (newkey->info->type) { |
245 |
/* |
246 |
case DRMS_TYPE_CHAR: |
247 |
return check_and_set_key_char (new, key, |
248 |
drms_getkey_char (old, key, &status)); |
249 |
*/ |
250 |
case DRMS_TYPE_SHORT: |
251 |
return check_and_set_key_short (new, key, |
252 |
drms_getkey_short (old, key, &status)); |
253 |
case DRMS_TYPE_INT: |
254 |
return check_and_set_key_int (new, key, |
255 |
drms_getkey_int (old, key, &status)); |
256 |
/* |
257 |
case DRMS_TYPE_LONGLONG: |
258 |
return check_and_set_key_longlong (new, key, |
259 |
drms_getkey_longlong (old, key, &status)); |
260 |
*/ |
261 |
case DRMS_TYPE_FLOAT: |
262 |
return check_and_set_key_float (new, key, |
263 |
drms_getkey_float (old, key, &status)); |
264 |
case DRMS_TYPE_DOUBLE: |
265 |
return check_and_set_key_double (new, key, |
266 |
drms_getkey_double (old, key, &status)); |
267 |
case DRMS_TYPE_TIME: |
268 |
return check_and_set_key_time (new, key, |
269 |
drms_getkey_time (old, key, &status)); |
270 |
case DRMS_TYPE_STRING: |
271 |
return check_and_set_key_str (new, key, |
272 |
drms_getkey_string (old, key, &status)); |
273 |
default: |
274 |
fprintf (stderr, |
275 |
"Error in check_and_copy_key(): Unknown type %s for keyword %s\n", |
276 |
drms_type2str (newkey->info->type), key); |
277 |
return 1; |
278 |
} |
279 |
} |
280 |
|
281 |
/* |
282 |
* Parse a token separated list of character strings into an array of |
283 |
* character strings and return the number of such strings, plus the |
284 |
* array itself in the argument list |
285 |
* |
286 |
* Bugs: |
287 |
* There is no way of including the token in the parsed strings |
288 |
*/ |
289 |
int construct_stringlist (const char *request, char token, char ***stringlist) { |
290 |
int keyct = 1; |
291 |
int m, n; |
292 |
char *req, *req0 = strdup (request); |
293 |
char c; |
294 |
/* count the number of separators */ |
295 |
req = req0; |
296 |
while (c = *req) { |
297 |
if (c == token) { |
298 |
*req = '\0'; |
299 |
keyct++; |
300 |
} |
301 |
req++; |
302 |
} |
303 |
*stringlist = (char **)malloc (keyct * sizeof (char **)); |
304 |
req = req0; |
305 |
for (n = 0; n < keyct; n++) { |
306 |
(*stringlist)[n] = strdup (req); |
307 |
req += strlen (req) + 1; |
308 |
} |
309 |
for (n = 0; n < keyct; n++) { |
310 |
char *subs = (*stringlist)[n]; |
311 |
/* remove leading white space */ |
312 |
while (isspace (c = *subs)) subs++; |
313 |
(*stringlist)[n] = subs; |
314 |
/* remove trailing white space */ |
315 |
if (strlen (subs)) { |
316 |
subs += strlen (subs) - 1; |
317 |
while (isspace (c = *subs)) { |
318 |
*subs = '\0'; |
319 |
subs--; |
320 |
} |
321 |
} |
322 |
} |
323 |
/* remove empty strings from list */ |
324 |
for (n = 0; n < keyct; n++) { |
325 |
if (!strlen ((*stringlist)[n])) { |
326 |
for (m = n; m < keyct - 1; m++) |
327 |
(*stringlist)[m] = (*stringlist)[m + 1]; |
328 |
keyct--; |
329 |
} |
330 |
} |
331 |
free (req0); |
332 |
return keyct; |
333 |
} |
334 |
|
335 |
int copy_prime_keys (DRMS_Record_t *new, DRMS_Record_t *old) { |
336 |
/* |
337 |
* Copy the prime keys of new from old if possible |
338 |
* For slotted prime keys, it is copy the key value rather than its index |
339 |
*/ |
340 |
DRMS_Keyword_t *pkey; |
341 |
int n, kstat = 0; |
342 |
char *key, *pkeyindex; |
343 |
int pkeyct = new->seriesinfo->pidx_num; |
344 |
|
345 |
for (n = 0; n < pkeyct; n++) { |
346 |
pkey = new->seriesinfo->pidx_keywords[n]; |
347 |
key = strdup (pkey->info->name); |
348 |
|
349 |
if (pkeyindex = strstr (key, "_index")) *pkeyindex = '\0'; |
350 |
if (!drms_keyword_lookup (old, key, 1)) continue; |
351 |
kstat += check_and_copy_key (new, old, key); |
352 |
} |
353 |
return kstat; |
354 |
} |
355 |
|
356 |
void string_insert_escape_char (char **str, const char esc) { |
357 |
int i, n, ct = 0, len; |
358 |
|
359 |
len = strlen (*str); |
360 |
for (n = 0; n < len; n++) if ((*str)[n] == esc) ct++; |
361 |
if (ct) { |
362 |
*str = realloc (*str, 2*len); |
363 |
for (n = len; n < 2*len; n++) (*str)[n] = '\0'; |
364 |
} |
365 |
for (n = 0; n < len; n++) { |
366 |
if ((*str)[n] == esc) { |
367 |
for (i = len; i > n; i--) (*str)[i] = (*str)[i-1]; |
368 |
(*str)[n] = '\\'; |
369 |
len++; |
370 |
n++; |
371 |
} |
372 |
} |
373 |
} |
374 |
|
375 |
int append_keyval_to_primekeyval (char **pkey, DRMS_Record_t *rec, |
376 |
const char *key) { |
377 |
DRMS_Keyword_t *keywd; |
378 |
int size; |
379 |
static int curlen; |
380 |
char **buf; |
381 |
int buflen = 256; |
382 |
|
383 |
if (!*pkey) { |
384 |
*pkey = calloc (buflen, sizeof (char)); |
385 |
curlen = buflen; |
386 |
} |
387 |
size = strlen (*pkey); |
388 |
if (size) { |
389 |
/* after first key, append separator */ |
390 |
size++; |
391 |
if (size >= curlen) { |
392 |
char *tmp = calloc (curlen, sizeof (char)); |
393 |
strcpy (tmp, *pkey); |
394 |
curlen += buflen; |
395 |
*pkey = realloc (*pkey, curlen); |
396 |
bzero (*pkey, curlen); |
397 |
strcpy (*pkey, tmp); |
398 |
free (tmp); |
399 |
} |
400 |
strcat (*pkey, "|"); |
401 |
} |
402 |
if (!(keywd = drms_keyword_lookup (rec, key, 1))) { |
403 |
fprintf (stderr, "create_primekey_from_keylist(): %s not found\n", key); |
404 |
if (*pkey) free (*pkey); |
405 |
*pkey = NULL; |
406 |
return 1; |
407 |
} |
408 |
buf = malloc (sizeof (char **)); |
409 |
*buf = malloc (DRMS_DEFVAL_MAXLEN * sizeof (char *)); |
410 |
drms_keyword_snprintfval (keywd, *buf, DRMS_DEFVAL_MAXLEN); |
411 |
if (keywd->info->type == DRMS_TYPE_STRING || |
412 |
keywd->info->type == DRMS_TYPE_TIME) { |
413 |
string_insert_escape_char (buf, '|'); |
414 |
} |
415 |
size += strlen (*buf); |
416 |
if (size >= curlen) { |
417 |
curlen += buflen; |
418 |
*pkey = realloc (*pkey, curlen); |
419 |
} |
420 |
strncat (*pkey, *buf, strlen (*buf)); |
421 |
free (*buf); |
422 |
free (buf); |
423 |
return 0; |
424 |
} |
425 |
|
426 |
char *create_primekey_from_keylist (DRMS_Record_t *rec, char **keylist, |
427 |
int keyct) { |
428 |
char *pkey = NULL; |
429 |
int n; |
430 |
for (n = 0; n < keyct; n++) |
431 |
if (append_keyval_to_primekeyval (&pkey, rec, keylist[n])) break; |
432 |
|
433 |
return pkey; |
434 |
} |
435 |
|
436 |
int propagate_keys (DRMS_Record_t *to, DRMS_Record_t *from, char **keylist, |
437 |
int keyct) { |
438 |
int n, status = 0; |
439 |
for (n = 0; n < keyct; n++) |
440 |
status += check_and_copy_key (to, from, keylist[n]); |
441 |
return status; |
442 |
} |
443 |
|
444 |
char *iau_units_parse_unit (char *unit, double *scale) { |
445 |
char prefix = unit[0]; |
446 |
|
447 |
*scale = 1.0; |
448 |
switch (prefix) { |
449 |
case ('y'): |
450 |
if (strcmp (unit, "yr")) { |
451 |
*scale = 1.0e24; |
452 |
return &unit[1]; |
453 |
} else return unit; |
454 |
case ('z'): *scale = 1.0e21; return &unit[1]; |
455 |
case ('a'): |
456 |
if (strlen (unit) == 1) return unit; |
457 |
if (strcmp (unit, "arcmin") && strcmp (unit, "arcsec") && |
458 |
strcmp (unit, "adu")) { |
459 |
*scale = 1.0e18; |
460 |
return &unit[1]; |
461 |
} else return unit; |
462 |
case ('f'): *scale = 1.0e15; return &unit[1]; |
463 |
case ('p'): |
464 |
if (strcmp (unit, "pc") && strcmp (unit, "ph") && strcmp (unit, "photon") |
465 |
&& strcmp (unit, "pix") && strcmp (unit, "pixel") ) { |
466 |
*scale = 1.0e12; |
467 |
return &unit[1]; |
468 |
} else return unit; |
469 |
case ('n'): *scale = 1.0e9; return &unit[1]; |
470 |
case ('u'): *scale = 1.0e6; return &unit[1]; |
471 |
case ('m'): |
472 |
if (strlen (unit) == 1) return unit; |
473 |
if (strcmp (unit, "mol") && strcmp (unit, "mas") && strcmp (unit, "min") |
474 |
&& strcmp (unit, "mag")) { |
475 |
*scale = 1.0e3; |
476 |
return &unit[1]; |
477 |
} else return unit; |
478 |
case ('c'): |
479 |
if (strcmp (unit, "cd") && strcmp (unit, "count") && strcmp (unit, "ct") |
480 |
&& strcmp (unit, "chan")) { |
481 |
*scale = 1.0e2; |
482 |
return &unit[1]; |
483 |
} else return unit; |
484 |
case ('d'): |
485 |
if (strlen (unit) == 1) return unit; |
486 |
if (strcmp (unit, "deg")) { |
487 |
*scale = 1.0e1; |
488 |
return &unit[1]; |
489 |
} else return unit; |
490 |
case ('h'): |
491 |
if (strlen (unit) == 1) return unit; |
492 |
else { |
493 |
*scale = 1.0e-2; |
494 |
return &unit[1]; |
495 |
} |
496 |
case ('k'): |
497 |
if (strcmp (unit, "kg") && strcmp (unit, "count") && strcmp (unit, "ct") |
498 |
&& strcmp (unit, "chan")) { |
499 |
*scale = 1.0e-3; |
500 |
return &unit[1]; |
501 |
} else return unit; |
502 |
case ('M'): *scale = 1.0e-6; return &unit[1]; |
503 |
case ('G'): |
504 |
if (strlen (unit) == 1) return unit; |
505 |
else { |
506 |
*scale = 1.0e-9; |
507 |
return &unit[1]; |
508 |
} |
509 |
case ('T'): |
510 |
if (strlen (unit) == 1) return unit; |
511 |
else { |
512 |
*scale = 1.0e-12; |
513 |
return &unit[1]; |
514 |
} |
515 |
case ('P'): |
516 |
if (strcmp (unit, "PA")) { |
517 |
*scale = 1.0e-15; |
518 |
return &unit[1]; |
519 |
} else return unit; |
520 |
case ('E'): *scale = 1.0e-18; return &unit[1]; |
521 |
case ('Z'): *scale = 1.0e-21; return &unit[1]; |
522 |
case ('Y'): *scale = 1.0e-24; return &unit[1]; |
523 |
default: return unit; |
524 |
} |
525 |
} |
526 |
|
527 |
int drms_iau_units_scale (char *unit, double *scale) { |
528 |
if (!(strcmp (unit, "rad"))) *scale = 1.0; |
529 |
else return -1; |
530 |
return 0; |
531 |
} |
532 |
|
533 |
int drms_wcs_timestep (DRMS_Record_t *rec, int axis, double *tstep) { |
534 |
double dval; |
535 |
int status; |
536 |
char *sval; |
537 |
char delta[9], unit[9]; |
538 |
|
539 |
*tstep = 1.0 / 0.0; |
540 |
sprintf (delta, "CDELT%d", axis); |
541 |
sprintf (unit, "CUNIT%d", axis); |
542 |
dval = drms_getkey_double (rec, delta, &status); |
543 |
if (status || isnan (dval)) return 1; |
544 |
*tstep = dval; |
545 |
sval = drms_getkey_string (rec, unit, &status); |
546 |
|
547 |
if (status || !sval) { |
548 |
fprintf (stderr, "Warning: no keyword %s: \"s\" assumed\n", unit); |
549 |
return 0; |
550 |
} |
551 |
if (!strcmp (sval, "s")) return 0; |
552 |
if (!strcmp (sval, "min")) { |
553 |
*tstep *= 60.0; |
554 |
return 0; |
555 |
} |
556 |
if (!strcmp (sval, "h")) { |
557 |
*tstep *= 3600.0; |
558 |
return 0; |
559 |
} |
560 |
if (!strcmp (sval, "d")) { |
561 |
*tstep *= 86400.0; |
562 |
return 0; |
563 |
} |
564 |
if (!strcmp (sval, "a") || !strcmp (sval, "yr")) { |
565 |
*tstep *= 31557600.0; |
566 |
return 0; |
567 |
} |
568 |
|
569 |
if (!strcmp (sval, "ns")) { |
570 |
*tstep *= 1.0e-9; |
571 |
return 0; |
572 |
} |
573 |
if (!strcmp (sval, "us")) { |
574 |
*tstep *= 1.0e-6; |
575 |
return 0; |
576 |
} |
577 |
if (!strcmp (sval, "ms")) { |
578 |
*tstep *= 0.001; |
579 |
return 0; |
580 |
} |
581 |
if (!strcmp (sval, "cs")) { |
582 |
*tstep *= 0.01; |
583 |
return 0; |
584 |
} |
585 |
if (!strcmp (sval, "ds")) { |
586 |
*tstep *= 0.1; |
587 |
return 0; |
588 |
} |
589 |
if (!strcmp (sval, "das")) { |
590 |
*tstep *= 10.0; |
591 |
return 0; |
592 |
} |
593 |
if (!strcmp (sval, "hs")) { |
594 |
*tstep *= 100.0; |
595 |
return 0; |
596 |
} |
597 |
if (!strcmp (sval, "ks")) { |
598 |
*tstep *= 1000.0; |
599 |
return 0; |
600 |
} |
601 |
if (!strcmp (sval, "Ms")) { |
602 |
*tstep *= 1.0e6; |
603 |
return 0; |
604 |
} |
605 |
if (!strcmp (sval, "gs")) { |
606 |
*tstep *= 1.0e9; |
607 |
return 0; |
608 |
} |
609 |
|
610 |
if (!strcmp (sval, "nmin")) { |
611 |
*tstep *= 6.0e-8; |
612 |
return 0; |
613 |
} |
614 |
if (!strcmp (sval, "umin")) { |
615 |
*tstep *= 6.0e-5; |
616 |
return 0; |
617 |
} |
618 |
if (!strcmp (sval, "mmin")) { |
619 |
*tstep *= 0.06; |
620 |
return 0; |
621 |
} |
622 |
if (!strcmp (sval, "cmin")) { |
623 |
*tstep *= 0.6; |
624 |
return 0; |
625 |
} |
626 |
if (!strcmp (sval, "dmin")) { |
627 |
*tstep *= 6.0; |
628 |
return 0; |
629 |
} |
630 |
if (!strcmp (sval, "damin")) { |
631 |
*tstep *= 600.0; |
632 |
return 0; |
633 |
} |
634 |
if (!strcmp (sval, "hmin")) { |
635 |
*tstep *= 6000.0; |
636 |
return 0; |
637 |
} |
638 |
if (!strcmp (sval, "kmin")) { |
639 |
*tstep *= 60000.0; |
640 |
return 0; |
641 |
} |
642 |
if (!strcmp (sval, "Mmin")) { |
643 |
*tstep *= 6.0e7; |
644 |
return 0; |
645 |
} |
646 |
if (!strcmp (sval, "gmin")) { |
647 |
*tstep *= 6.0e10; |
648 |
return 0; |
649 |
} |
650 |
|
651 |
if (!strcmp (sval, "nh")) { |
652 |
*tstep *= 3.6e-6; |
653 |
return 0; |
654 |
} |
655 |
if (!strcmp (sval, "uh")) { |
656 |
*tstep *= 3.6e-3; |
657 |
return 0; |
658 |
} |
659 |
if (!strcmp (sval, "mh")) { |
660 |
*tstep *= 0.36; |
661 |
return 0; |
662 |
} |
663 |
if (!strcmp (sval, "ch")) { |
664 |
*tstep *= 3.6; |
665 |
return 0; |
666 |
} |
667 |
if (!strcmp (sval, "dh")) { |
668 |
*tstep *= 360.0; |
669 |
return 0; |
670 |
} |
671 |
if (!strcmp (sval, "dah")) { |
672 |
*tstep *= 3.6e4; |
673 |
return 0; |
674 |
} |
675 |
if (!strcmp (sval, "hh")) { |
676 |
*tstep *= 3.6e5; |
677 |
return 0; |
678 |
} |
679 |
if (!strcmp (sval, "kh")) { |
680 |
*tstep *= 3.6e6; |
681 |
return 0; |
682 |
} |
683 |
if (!strcmp (sval, "Mh")) { |
684 |
*tstep *= 3.6e9; |
685 |
return 0; |
686 |
} |
687 |
if (!strcmp (sval, "gh")) { |
688 |
*tstep *= 3.6e12; |
689 |
return 0; |
690 |
} |
691 |
|
692 |
if (!strcmp (sval, "nd")) { |
693 |
*tstep *= 8.64e-5; |
694 |
return 0; |
695 |
} |
696 |
if (!strcmp (sval, "ud")) { |
697 |
*tstep *= 8.64-2; |
698 |
return 0; |
699 |
} |
700 |
if (!strcmp (sval, "md")) { |
701 |
*tstep *= 86.4; |
702 |
return 0; |
703 |
} |
704 |
if (!strcmp (sval, "cd")) { |
705 |
*tstep *= 864.0; |
706 |
return 0; |
707 |
} |
708 |
if (!strcmp (sval, "dd")) { |
709 |
*tstep *= 8640.0; |
710 |
return 0; |
711 |
} |
712 |
if (!strcmp (sval, "dad")) { |
713 |
*tstep *= 8.64e5; |
714 |
return 0; |
715 |
} |
716 |
if (!strcmp (sval, "hd")) { |
717 |
*tstep *= 8.64e6; |
718 |
return 0; |
719 |
} |
720 |
if (!strcmp (sval, "kd")) { |
721 |
*tstep *= 8.64e7; |
722 |
return 0; |
723 |
} |
724 |
if (!strcmp (sval, "Md")) { |
725 |
*tstep *= 8.64e10; |
726 |
return 0; |
727 |
} |
728 |
if (!strcmp (sval, "gd")) { |
729 |
*tstep *= 8.64e13; |
730 |
return 0; |
731 |
} |
732 |
|
733 |
fprintf (stderr, "Error: %s type of %s unrecognized by drms_wcs_timestep()\n", |
734 |
unit, sval); |
735 |
return 1; |
736 |
} |
737 |
|
738 |
/* |
739 |
* Revision History (all mods by Rick Bogart unless otherwise noted) |
740 |
* |
741 |
* 09.04.27 or earlier created file |
742 |
* 09.05.16 added functions for creating prime key string |
743 |
* 09.11.06 added WCS parsing function |
744 |
* 09.11.09 modified check_and_set_key_* to only require matching |
745 |
* to precision of keyword format for float, double, & time |
746 |
* 09.12.02 fixed two icc11 compiler warnings and one error |
747 |
* 10.01.07 added support in check_and_copy_key for keywords that |
748 |
* are dynamic links (in which case checking is irrelevant) |
749 |
* 10.02.03 relaxed check in check_and_copy_key (too much) |
750 |
* 10.04.24 added copy_prime_keys() |
751 |
* 10.06.11 added construct_stringlist() (orig in drms_rebin) |
752 |
*/ |