1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
/* Return the right ascension in degrees from sexagesimal hours or decimal degrees */
double
str2ra (in)
const char *in; /* Character string of sexigesimal hours or decimal degrees */
{
double ra; /* Right ascension in degrees (returned) */
ra = str2dec (in);
if (strsrch (in,":"))
ra = ra * 15.0;
return (ra);
}
/* Return the declination in degrees from sexagesimal or decimal degrees */
double
str2dec (in)
const char *in; /* Character string of sexigesimal or decimal degrees */
{
double dec; /* Declination in degrees (returned) */
double deg, min, sec, sign;
char *value, *c1, *c2;
int lval;
char *dchar;
dec = 0.0;
/* Return 0.0 if string is null */
if (in == NULL)
return (dec);
/* Translate value from ASCII colon-delimited string to binary */
if (in[0]) {
value = (char *) in;
/* Remove leading spaces */
while (*value == ' ')
value++;
/* Save sign */
if (*value == '-') {
sign = -1.0;
value++;
}
else if (*value == '+') {
sign = 1.0;
value++;
}
else
sign = 1.0;
/* Remove trailing spaces */
lval = strlen (value);
while (value[lval-1] == ' ')
lval--;
if ((c1 = strsrch (value,":")) == NULL)
c1 = strnsrch (value," ",lval);
if (c1 != NULL) {
*c1 = 0;
deg = (double) atoi (value);
*c1 = ':';
value = c1 + 1;
if ((c2 = strsrch (value,":")) == NULL)
c2 = strsrch (value," ");
if (c2 != NULL) {
*c2 = 0;
min = (double) atoi (value);
*c2 = ':';
value = c2 + 1;
sec = atof (value);
}
else {
sec = 0.0;
if ((c1 = strsrch (value,".")) != NULL)
min = atof (value);
if (strlen (value) > 0)
min = (double) atoi (value);
}
dec = sign * (deg + (min / 60.0) + (sec / 3600.0));
}
else if (isnum (value) == 2) {
if ((dchar = strchr (value, 'D')))
*dchar = 'e';
if ((dchar = strchr (value, 'd')))
*dchar = 'e';
if ((dchar = strchr (value, 'E')))
*dchar = 'e';
dec = sign * atof (value);
}
else
dec = sign * (double) atoi (value);
}
return (dec);
}
|