Astro-Nova
view release on metacpan or search on metacpan
libnova-0.15.0/src/utility.c view on Meta::CPAN
*/
double ln_get_light_time (double dist)
{
return dist * 0.005775183;
}
/* local types and macros */
typedef int BOOL;
#define TRUE 1
#define FALSE 0
#define iswhite(c) ((c)== ' ' || (c)=='\t')
/*
[]------------------------------------------------------------------------[]
| trim() & strip() |
| |
| strips trailing whitespaces from buf. |
| |
[]------------------------------------------------------------------------[]
*/
static char *trim(char *x)
{
char *y;
if(!x)
return(x);
y = x + strlen(x)-1;
while (y >= x && isspace(*y))
*y-- = 0; /* skip white space */
return x;
}
/*
[]------------------------------------------------------------------------[]
| |
| skipwhite() |
| salta espacios en blanco |
| |
[]------------------------------------------------------------------------[]
*/
static void skipwhite(char **s)
{
while(iswhite(**s))
(*s)++;
}
/*! \fn double ln_get_dec_location(char * s)
* \param s Location string
* \return angle in degrees
*
* Obtains Latitude, Longitude, RA or Declination from a string.
*
* If the last char is N/S doesn't accept more than 90 degrees.
* If it is E/W doesn't accept more than 180 degrees.
* If they are hours don't accept more than 24:00
*
* Any position can be expressed as follows:
* (please use a 8 bits charset if you want
* to view the degrees separator char '0xba')
*
* 42.30.35,53
* 90º0'0,01 W
* 42º30'35.53 N
* 42º30'35.53S
* 42º30'N
* - 42.30.35.53
* 42:30:35.53 S
* + 42.30.35.53
* +42º30 35,53
* 23h36'45,0
*
*
* 42:30:35.53 S = -42º30'35.53"
* + 42 30.35.53 S the same previous position, the plus (+) sign is
* considered like an error, the last 'S' has precedence over the sign
*
* 90º0'0,01 N ERROR: +- 90º0'00.00" latitude limit
*
*/
double ln_get_dec_location(char *s)
{
char *ptr, *dec, *hh, *ame, *tok_ptr;
BOOL negative = FALSE;
char delim1[] = " :.,;DdHhMm'\n\t";
char delim2[] = " NSEWnsew\"\n\t";
int dghh = 0, minutes = 0;
double seconds = 0.0, pos;
short count;
enum _type{
HOURS, DEGREES, LAT, LONG
}type;
if (s == NULL || !*s)
return(-0.0);
count = strlen(s) + 1;
if ((ptr = (char *) alloca(count)) == NULL)
return (-0.0);
memcpy(ptr, s, count);
trim(ptr);
skipwhite(&ptr);
if (*ptr == '+' || *ptr == '-')
negative = (char) (*ptr++ == '-' ? TRUE : negative);
/* the last letter has precedence over the sign */
if (strpbrk(ptr,"SsWw") != NULL)
negative = TRUE;
skipwhite(&ptr);
if ((hh = strpbrk(ptr,"Hh")) != NULL && hh < ptr + 3) {
type = HOURS;
if (negative) /* if RA no negative numbers */
negative = FALSE;
} else if ((ame = strpbrk(ptr,"SsNn")) != NULL) {
type = LAT;
if (ame == ptr) /* the North/South found before data */
ptr++;
( run in 3.023 seconds using v1.01-cache-2.11-cpan-5837b0d9d2c )