Finding significant points

pull/10/head
Cees Bassa 2018-04-10 13:22:45 +02:00
parent 3d237f8022
commit 59a1c74404
3 changed files with 40 additions and 17 deletions

View File

@ -106,7 +106,7 @@ int main(int argc,char *argv[])
int i,j,k,l,j0,j1,m=2,n;
struct spectrogram s;
char path[128];
int isub=0,nsub=60;
int isub=0,nsub=0;
char *env;
int site_id=0;
float avg,std;
@ -171,21 +171,40 @@ int main(int argc,char *argv[])
return 0;
}
// Read data
s=read_spectrogram(path,isub,nsub,f0,df0,1,0.0);
if (nsub==0) {
// Read data
for (i=isub;;i++) {
s=read_spectrogram(path,i,nsub,f0,df0,1,0.0);
// Exit on emtpy file
if (s.nsub==0)
return 0;
// Exit on emtpy file
if (s.nsub==0)
break;
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);
// Filter
filter(s,site_id,sigma,filename);
}
} else {
// Read data
s=read_spectrogram(path,isub,nsub,f0,df0,1,0.0);
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);
// Exit on emtpy file
if (s.nsub==0)
return 0;
// Filter
filter(s,site_id,sigma,filename);
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);
// Filter
filter(s,site_id,sigma,filename);
}
// Free
free(s.z);
free(s.mjd);
// free(s.zavg);
// free(s.zstd);
// free(s.length);
return 0;
}

14
rfio.c
View File

@ -33,12 +33,11 @@ struct spectrogram read_spectrogram(char *prefix,int isub,int nsub,double f0,dou
// Read header
status=fread(header,sizeof(char),256,file);
if (strstr(header,"NBITS 8")==NULL) {
status=sscanf(header,"HEADER\nUTC_START %s\nFREQ %lf Hz\nBW %lf Hz\nLENGTH %f s\nNCHAN %d\n",s.nfd0,&s.freq,&s.samp_rate,&length,&nch);
status=sscanf(header,"HEADER\nUTC_START %s\nFREQ %lf Hz\nBW %lf Hz\nLENGTH %f s\nNCHAN %d\nNSUB %d\n",s.nfd0,&s.freq,&s.samp_rate,&length,&nch,&msub);
} else {
status=sscanf(header,"HEADER\nUTC_START %s\nFREQ %lf Hz\nBW %lf Hz\nLENGTH %f s\nNCHAN %d\nNSUB %d\nNBITS 8\nMEAN %f\nRMS %f",s.nfd0,&s.freq,&s.samp_rate,&length,&nch,&dummy,&zavg,&zstd);
nbits=8;
}
s.freq+=foff;
// Close file
@ -63,9 +62,13 @@ struct spectrogram read_spectrogram(char *prefix,int isub,int nsub,double f0,dou
j1=s.nchan;
}
// Read whole file if not specified
if (nsub==0 && msub>0)
nsub=msub;
// Number of subints
s.nsub=nsub/nbin;
// Allocate
s.z=(float *) malloc(sizeof(float)*s.nchan*s.nsub);
s.zavg=(float *) malloc(sizeof(float)*s.nsub);
@ -90,7 +93,8 @@ struct spectrogram read_spectrogram(char *prefix,int isub,int nsub,double f0,dou
file=fopen(filename,"r");
if (file==NULL) {
printf("%s does not exist\n",filename);
break;
s.nsub=0;
break;
}
printf("opened %s\n",filename);
@ -102,7 +106,7 @@ struct spectrogram read_spectrogram(char *prefix,int isub,int nsub,double f0,dou
if (status==0)
break;
if (nbits==-32)
status=sscanf(header,"HEADER\nUTC_START %s\nFREQ %lf Hz\nBW %lf Hz\nLENGTH %f s\nNCHAN %d\n",nfd,&freq,&samp_rate,&length,&nchan);
status=sscanf(header,"HEADER\nUTC_START %s\nFREQ %lf Hz\nBW %lf Hz\nLENGTH %f s\nNCHAN %d\nNSUB %d\n",nfd,&freq,&samp_rate,&length,&nchan,&msub);
else if (nbits==8)
status=sscanf(header,"HEADER\nUTC_START %s\nFREQ %lf Hz\nBW %lf Hz\nLENGTH %f s\nNCHAN %d\nNSUB %d\nNBITS 8\nMEAN %f\nRMS %f",nfd,&freq,&samp_rate,&length,&nchan,&dummy,&zavg,&zstd);

View File

@ -878,7 +878,7 @@ void plot_traces(struct trace *t,int nsat,float fcen)
// Plot label for rising sources
if (j>0 && t[i].za[j-1]>90.0 && t[i].za[j]<=90.0)
cpgtext((float) j,(float) t[i].freq[j]-fcen,text);
// Plot line
if (flag==0) {
cpgmove((float) j,t[i].freq[j]-fcen);
@ -1165,7 +1165,7 @@ void filter(struct spectrogram s,int site_id)
else
mask[j]=0;
}
/*
// Find maximum when points are adjacent
for (j=0;j<s.nchan-1;j++) {
if (mask[j]==1 && mask[j+1]==1) {
@ -1179,7 +1179,7 @@ void filter(struct spectrogram s,int site_id)
mask[j]=0;
}
}
*/
// Mark points
for (j=0;j<s.nchan;j++) {
if (mask[j]==1) {