#include #include #include #include #include "sgdp4h.h" #include "satutl.h" #include "rftrace.h" #define LIM 80 #define D2R M_PI/180.0 #define R2D 180.0/M_PI #define XKMPER 6378.135 // Earth radius in km #define XKMPAU 149597879.691 // AU in km #define FLAT (1.0/298.257) #define C 299792.458 // Speed of light in km/s struct point { xyz_t obspos,obsvel; xyz_t grpos,grvel; }; struct site { int id; double lng,lat; float alt; char observer[64]; }; // Return x modulo y [0,y) double modulo(double x,double y) { x=fmod(x,y); if (x<0.0) x+=y; return x; } // Read a line of maximum length int lim from file FILE into string s int fgetline(FILE *file,char *s,int lim) { int c,i=0; while (--lim > 0 && (c=fgetc(file)) != EOF && c != '\n') s[i++] = c; // if (c == '\n') // s[i++] = c; s[i] = '\0'; return i; } // Greenwich Mean Sidereal Time double gmst(double mjd) { double t,gmst; t=(mjd-51544.5)/36525.0; gmst=modulo(280.46061837+360.98564736629*(mjd-51544.5)+t*t*(0.000387933-t/38710000),360.0); return gmst; } // Greenwich Mean Sidereal Time double dgmst(double mjd) { double t,dgmst; t=(mjd-51544.5)/36525.0; dgmst=360.98564736629+t*(0.000387933-t/38710000); return dgmst; } // Observer position void obspos_xyz(double mjd,double lng,double lat,float alt,xyz_t *pos,xyz_t *vel) { double ff,gc,gs,theta,s,dtheta; s=sin(lat*D2R); ff=sqrt(1.0-FLAT*(2.0-FLAT)*s*s); gc=1.0/ff+alt/XKMPER; gs=(1.0-FLAT)*(1.0-FLAT)/ff+alt/XKMPER; theta=gmst(mjd)+lng; dtheta=dgmst(mjd)*D2R/86400; pos->x=gc*cos(lat*D2R)*cos(theta*D2R)*XKMPER; pos->y=gc*cos(lat*D2R)*sin(theta*D2R)*XKMPER; pos->z=gs*sin(lat*D2R)*XKMPER; vel->x=-gc*cos(lat*D2R)*sin(theta*D2R)*XKMPER*dtheta; vel->y=gc*cos(lat*D2R)*cos(theta*D2R)*XKMPER*dtheta; vel->z=0.0; return; } // Get observing site struct site get_site(int site_id) { int i=0,status; char line[LIM]; FILE *file; int id; double lat,lng; float alt; char abbrev[3],observer[64]; struct site s; char *env,filename[LIM]; env=getenv("ST_DATADIR"); sprintf(filename,"%s/data/sites.txt",env); file=fopen(filename,"r"); if (file==NULL) { printf("File with site information not found!\n"); return; } while (fgets(line,LIM,file)!=NULL) { // Skip if (strstr(line,"#")!=NULL) continue; // Strip newline line[strlen(line)-1]='\0'; // Read data status=sscanf(line,"%4d %2s %lf %lf %f", &id,abbrev,&lat,&lng,&alt); strcpy(observer,line+38); // Change to km alt/=1000.0; // Copy site if (id==site_id) { s.lat=lat; s.lng=lng; s.alt=alt; s.id=id; strcpy(s.observer,observer); } } fclose(file); return s; } // Identify trace void identify_trace(char *tlefile,struct trace t,int satno) { int i,imode,flag=0,status; struct point *p; struct site s; double *v; orbit_t orb; xyz_t satpos,satvel; FILE *file; double dx,dy,dz,dvx,dvy,dvz,r,za; double sum1,sum2,beta,freq0,rms,mjd0; char nfd[32],nfdmin[32],text[16]; int satnomin; double rmsmin,freqmin; char *env,freqlist[LIM]; env=getenv("ST_DATADIR"); sprintf(freqlist,"%s/data/frequencies.txt",env); // Reloop stderr freopen("/tmp/stderr.txt","w",stderr); // Get site s=get_site(t.site); // Allocate p=(struct point *) malloc(sizeof(struct point)*t.n); v=(double *) malloc(sizeof(double)*t.n); // Get observer position for (i=0;i0.0) mjd2nfd(mjd0,nfd); else strcpy(nfd,"0000-00-00T00:00:00"); if (rms<1000) { printf("%05d: %s %8.3f MHz %8.3f kHz\n",orb.satno,nfd,1e-6*freq0,1e-3*rms); if (flag==0 || rms=fmin && freq0<=fmax) i++; } fclose(infile); *nsat=i; // Break out if (i==0) return t; // Valid MJDs for (i=0;ifmax) continue; // Allocate t[j].satno=satno; t[j].site=site_id; t[j].n=m; t[j].freq0=freq0; t[j].mjd=(double *) malloc(sizeof(double)*m); t[j].freq=(double *) malloc(sizeof(double)*m); t[j].za=(float *) malloc(sizeof(float)*m); sprintf(text," %d",satno); // Loop over TLEs file=fopen(tlefile,"r"); while (read_twoline(file,satno,&orb)==0) { // Initialize imode=init_sgdp4(&orb); if (imode==SGDP4_ERROR) printf("Error\n"); // Loop over points for (i=0,flag=0,tflag=0;i