#include "elastro.h" /* //avoids a string in the form 000:00:00 which //contains degrees:arcminutes:arcseconds //mode == 0:converts it to the complete number of arcseconds, //mode == 1:converts it to a number of hours //mode == 2:converts it to a number of degrees //which are returned as double //if an error it returns value -1 */ double StrDegreesToDouble( char * str, int mode ) { double d,m,s,v; char *p1,*p2,*p3; int ct; strcpy(&il_tmptext[0],(const char *)str); ct = 0; p1 = &il_tmptext[0]; while( (p1[0] == 0x20) && (ct < 3)){ p1++;ct++; } p2 = NULL; p3 = NULL; p2 = strchr(p1,':'); if(p2 != NULL){ p2[0] = 0; p2++; ct = 0; while((p2[0] == 0x20) && (ct < 2 )){ p2++;ct++; } if( (p2[0] >= '0') && (p2[0] <= '9') ){ p3 = strchr(p2,':'); if(p3 != NULL){ p3[0] = 0; p3++; ct = 0; while((p3[0] == 0x20) && (ct < 2 )){ p3++;ct++; } if( (p3[0] < '0') || (p3[0] > '9') ){ p3 = NULL; } } } else { p2 = NULL; } } d = 0; m=0; s=0; v = 0; if(p1 != NULL){ if( (d = strtod((const char *)p1,NULL)) < 0){ return(-1); } } if(p2 != NULL){ if( (m = strtod((const char *)p2,NULL)) < 0){ return(-1); } } if(p3 != NULL){ if( (s = strtod((const char *)p3,NULL)) < 0){ return(-1); } } if(mode == 0){ if(d != 0){ d = d * 3600; } if(m != 0){ m = m * 60; } v = d + m + s; return(v); } if(mode == 1){ if(m != 0){ m = m / 60; } if(s != 0){ s = s / 3600; } v = d + m + s; return(v); } if(mode == 2){ if(m != 0){ m = m / 60; } if(s != 0){ s = s / 3600; } v = d + m + s; return(v); } return(v); } /* //avoids a double which //contains a number of arcseconds //converts it to a string of the form 000:00:00 //which are returned as pointer //if an error it returns NULL //if flag hours is set to 1, it will not be convertert //to a string representating degrees, instead hours:minutes:seconds */ char * DoubleToStrDegrees( double arc, int hours ) { double d,t,m,s,v; v = arc; if( hours ) { v = arc / 15.0; } d = v / 3600; d = makeAbsoluteDouble( d ); t = d * 3600; v = v - t; m = v / 60; m = makeAbsoluteDouble( m ); t = m * 60; s = v - t; s = makeAbsoluteDouble(s); if(m < 0 ){ m = m * -1; } if(s < 0 ){ s = s * -1; } sprintf(&il_tmptext[0],"%03.f:%02.f:%02.f\0", d, m, s); return( &il_tmptext[0] ); } /* //avoids a string like 00:00:00 containing ra-koodinates, and also for declination //converts it to azimuth/altitude,koordinates wich are stored to the struct AZALT //( this can be convertet later with DoubleToStrDegrees. //ra must be given as hours //ddc must be given as degrees //utcadjust must be the Difference between LocalTime and GMT in seconds */ void StrRADecToStrAZAlt( char * ra, char * dec, long utcadjust, double latitude, double longitude, struct AZALT * azalt ) { double rah,decd,stt; //convert ra to rah ( hours ) //convert dec to decd ( degrees ) rah = StrDegreesToDouble( ra , 1 ); decd = StrDegreesToDouble( dec, 2 ); stt = cCurrentStarTime( longitude , latitude, 0, 0, utcadjust ); cAzAlt( latitude, rah, decd, stt, azalt ); } /* //avoids a string like 000:00:00 containing az-koodinates, and also for altitude //converts it to rectaszension/declination ,koordinates wich are stored to the struct RADEC //( this can be convertet later with DoubleToStrDegrees //az must be given as degrees //alt must be given as degrees //utcadjust must be the Difference between LocalTime and GMT in seconds */ void StrAZAltToStrRADec( char * az, char * alt, long utcadjust, double latitude, double longitude, struct RADEC *radec ) { double azd,altd,stt; azd = StrDegreesToDouble( az , 2 ); altd = StrDegreesToDouble( alt, 2 ); stt = cCurrentStarTime( longitude , latitude, 0, 0, utcadjust ); cRaDec( latitude, azd, altd, stt, radec ); }