From 74392761006218438429acc82716a376a62c4558 Mon Sep 17 00:00:00 2001 From: Cees Bassa Date: Mon, 24 Mar 2014 16:41:38 +0100 Subject: [PATCH] Identification added --- rfplot.c | 268 +++++++++++++++++++++++++++++++++++++++++++----------- rftrace.c | 160 ++++++++++++++++++++++++++++---- rftrace.h | 3 +- 3 files changed, 361 insertions(+), 70 deletions(-) diff --git a/rfplot.c b/rfplot.c index 3d9d024..be12735 100644 --- a/rfplot.c +++ b/rfplot.c @@ -9,48 +9,18 @@ #include "rftrace.h" #define LIM 128 +#define NMAX 64 + +struct select { + int flag,n; + float x[NMAX],y[NMAX],w; +}; void dec2sex(double x,char *s,int f,int len); void time_axis(double *mjd,int n,float xmin,float xmax,float ymin,float ymax); void usage(void); - -void plot_traces(struct trace *t,int nsat) -{ - int i,j,flag,textflag; - char text[8]; - - // Loop over objects - for (i=0;i0 && t[i].za[j-1]>90.0 && t[i].za[j]<=90.0) - cpgtext((float) j,(float) t[i].freq[j],text); - - // Plot line - if (flag==0) { - cpgmove((float) j,(float) t[i].freq[j]); - flag=1; - } else { - cpgdraw((float) j,(float) t[i].freq[j]); - } - - // Below horizon - if (t[i].za[j]>90.0) - flag=0; - else - flag=1; - } - } - - return; -} +void plot_traces(struct trace *t,int nsat); +struct trace locate_trace(struct spectrogram s,struct select sel); int main(int argc,char *argv[]) { @@ -61,12 +31,12 @@ int main(int argc,char *argv[]) float cool_g[]={0.0,0.0,0.0,1.0,1.0,1.0,0.6,0.0,1.0}; float cool_b[]={0.0,0.3,0.8,1.0,0.3,0.0,0.0,0.0,1.0}; float xmin,xmax,ymin,ymax,zmin,zmax=8.0; - int i,j,k,flag=0; + int i,j,k,flag=0,isel=0; int redraw=1,mode=0,posn=0,click=0; float dt,zzmax,s1,s2; int ix=0,iy=0,isub=0; int i0,j0,i1,j1,jmax; - float width=500; + float width=1500; float x,y,x0,y0; char c; char path[128],xlabel[64],ylabel[64]; @@ -77,8 +47,9 @@ int main(int argc,char *argv[]) int arg=0,nsub=3600,nbin=1; double f0=0.0,df0=0.0; int foverlay=1; - struct trace *t; - int nsat; + struct trace *t,tf; + int nsat,satno; + struct select sel; // Read arguments if (argc>1) { @@ -130,11 +101,9 @@ int main(int argc,char *argv[]) s=read_spectrogram(path,isub,nsub,f0,df0,nbin); printf("Read spectrogram\n%d channels, %d subints\nFrequency: %g MHz\nBandwidth: %g MHz\n",s.nchan,s.nsub,s.freq*1e-6,s.samp_rate*1e-6); - fmin=(s.freq-0.5*s.samp_rate)*1e-6; - fmax=(s.freq+0.5*s.samp_rate)*1e-6; // Compute traces - t=compute_trace(s.mjd,s.nsub,4171,fmin,fmax,&nsat); + t=compute_trace(s.mjd,s.nsub,4171,s.freq*1e-6,s.samp_rate*1e-6,&nsat); printf("Traces for %d objects\n",nsat); cpgopen("/xs"); @@ -147,7 +116,15 @@ int main(int argc,char *argv[]) ymin=0.0; ymax=(float) s.nchan; zmin=0.0; + + // Set trace + tf.n=0; + // Set selection + isel=0; + sel.n=0; + sel.w=50.0; + // Forever loop for (;;) { if (redraw==1) { @@ -193,6 +170,30 @@ int main(int argc,char *argv[]) cpgswin(xmin,xmax,ymin,ymax); + // Plot selection + if (sel.n>0) { + cpgsci(7); + // Plot points + for (i=0;i0) { + free(tf.mjd); + free(tf.freq); + free(tf.za); + } + for (i=0;i0 && t[i].za[j-1]>90.0 && t[i].za[j]<=90.0) + cpgtext((float) j,(float) t[i].freq[j],text); + + // Plot line + if (flag==0) { + cpgmove((float) j,(float) t[i].freq[j]); + flag=1; + } else { + cpgdraw((float) j,(float) t[i].freq[j]); + } + + // Below horizon + if (t[i].za[j]>90.0) + flag=0; + else + flag=1; + } + } + + return; +} + +// Locate trace +struct trace locate_trace(struct spectrogram s,struct select sel) +{ + int i,j,k,l,sn; + int i0,i1,j0,j1,jmax; + double f; + float x,y,s1,s2,z,za,zs,zm,sigma; + struct trace t; + FILE *file; + + // Set up trace + t.satno=99999; + t.n=(int) ceil(sel.x[sel.n-1]-sel.x[0]); + t.mjd=(double *) malloc(sizeof(double)*t.n); + t.freq=(double *) malloc(sizeof(double)*t.n); + t.za=(float *) malloc(sizeof(float)*t.n); + + // Open file + file=fopen("out.dat","w"); + + // Loop over selected regions + for (k=0,l=0;kzm) { + zm=z; + jmax=j; + } + } + za=s1/(float) sn; + zs=sqrt(s2/(float) sn-za*za); + sigma=(zm-za)/zs; + + // Store + if (sigma>5.0 && s.mjd[i]>1.0) { + f=s.freq-0.5*s.samp_rate+(double) jmax*s.samp_rate/(double) s.nchan; + fprintf(file,"%lf %lf %f 4171\n",s.mjd[i],f,sigma); + cpgpt1((float) i,(float) jmax,17); + t.mjd[l]=s.mjd[i]; + t.freq[l]=f; + t.za[l]=0.0; + l++; + } + } + } + t.n=l; + + // Close file + fclose(file); + + return t; +} diff --git a/rftrace.c b/rftrace.c index d9aaf59..4c8f849 100644 --- a/rftrace.c +++ b/rftrace.c @@ -1,8 +1,10 @@ #include #include #include +#include #include "sgdp4h.h" #include "satutl.h" +#include "rftrace.h" #define LIM 80 #define D2R M_PI/180.0 @@ -21,12 +23,6 @@ struct site { float alt; char observer[64]; }; -struct trace { - int satno,n; - double *mjd; - double *freq; - float *za; -}; // Return x modulo y [0,y) double modulo(double x,double y) @@ -149,19 +145,141 @@ struct site get_site(int site_id) return s; } -// Compute trace -struct trace *compute_trace(double *mjd,int n,int site_id,float fmin,float fmax,int *nsat) +// Identify trace +void identify_trace(struct trace t,int satno) { - int i,j,imode,flag,satno,tflag; + int i,imode,flag=0; + 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; + + // 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