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
|
/*****************************************/
/** Geostationary Satellite Locator **/
/** KD2BD Software **/
/** (c) 1992, 1999 **/
/*****************************************/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#ifndef PI
#define PI 3.141592653589793
#endif
double sgn(x)
double x;
{
double value=0.0;
if (x>0.0)
value=1.0;
if (x<0.0)
value=-1.0;
return value;
}
int main()
{
double l, g, dr, c, dc, ds, j, az, el, cd;
char qthfile[50], input[7];
FILE *fd;
sprintf(qthfile,"%s/.predict/predict.qth",getenv("HOME"));
/* Read user's lat and long from ~/.predict/predict.qth file */
fd=fopen(qthfile,"r");
if (fd!=NULL)
{
fscanf(fd,"%s",input);
fscanf(fd,"%lf",&l);
fscanf(fd,"%lf",&g);
fclose(fd);
}
else
{
printf("%c\n*** ERROR! \"%s\" not found! Program aborted!\n",7,qthfile);
exit(-1);
}
input[0]=0;
dr=PI/180.0;
l=l*dr;
g=g*dr;
printf("\nEnter Longitude of Satellite in Degrees West: ");
fgets(input,5,stdin);
while (input[0]!='\n')
{
sscanf(input,"%lf",&cd);
c=cd*dr;
dc=cos(l)*cos(c-g);
ds=sqrt(1.0-(dc*dc));
j=-sin(l)*dc/(cos(l)*ds);
if (fabs(j)>0.9999)
j=sgn(j)*0.9999;
az=90.0-atan(j/sqrt(1.0-j*j))/dr;
if (((c>g) && (c<(PI+g))) || ((c>(2.0*PI+g))))
az=360.0-az;
el=atan((42171.0*dc-6371.0)/(42171.0*ds))/dr;
printf("\nAzimuth : %6.2f degrees\n",az);
printf("Elevation : %6.2f degrees\n\n",el);
printf("\nEnter Longitude of Satellite in Degrees West: ");
fgets(input,5,stdin);
}
exit(0);
}
|