Skip to content

Commit fdb0888

Browse files
authored
Merge pull request #2 from ymaan4/write_plot_data
2 parents bdc05d5 + 09dd8be commit fdb0888

File tree

7 files changed

+76
-16
lines changed

7 files changed

+76
-16
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ periodic RFI from GMRT time-domain data. Over the time, rfiClean has evolved
66
to mitigate any spiky (in time or frequency) RFI as well, and from any SIGPROC
77
filterbank format data file. It is written primarily in C. For handling the
88
filterbank format I/O, rfiClean uses several modules from Duncan Lorimer's SIGPROC
9-
(https://sourceforge.net/p/sigproc/wiki/Home/; thank you Dunc) most of which are
10-
included here in the src/ext/ folder.
9+
(https://sourceforge.net/p/sigproc/wiki/Home/; thank you Dunc) which are included
10+
here in the src/ext/ folder (some of these codes are also modified suitably).
1111

1212
#### Dependencies:
1313
FFTW3
@@ -17,8 +17,12 @@ PGPLOT
1717

1818

1919
### Bash-script based parallel processing
20-
For faster processing, use the bash script in bin/ to use rfiClean on different parts of a single data file simultaneously and then combine the output products at the end --- parallel processing in a rather crude way.
20+
For faster processing, use the bash script in bin/ to use rfiClean on different parts of a single data file simultaneously and then combine the output products at the end --- parallel processing in a rather crude but efficient way.
2121

22+
### Diagnostic plot
23+
rfiClean produces a diagnostic plot showing which Fourier frequencies are
24+
mitigated from the data and how frequently. The plot data are also output
25+
in a file.
2226

2327

2428
Yogesh Maan <ymaan4[@]gmail.com>

include/header.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ double analog_power[2];
1515

1616
/* added frequency table for use with non-contiguous data */
1717
//double frequency_table[4096]; /* note limited number of channels */
18-
double frequency_table[8192]; /* note limited number of channels */
18+
double frequency_table[32768]; /* note limited number of channels */
1919
//double frequency_table[16384]; /* note limited number of channels */
2020
long int npuls; /* added for binary pulse profile format */

include/rficlean.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void bcast_header();
2727
void rficlean_data(FILE *input, FILE *output);
2828
float vmax(float *vec, int n);
2929
float vmin(float *vec, int n);
30-
void plot_data(char outdev[]);
30+
void plot_data(char outdev[], int wpout);
3131

3232
/* include these from sigproc-4.3 */
3333
void slaCldj ( int iy, int im, int id, double *djm, int *j );

src/ext/read_header.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ void get_string(FILE *inputfile, int *nbytes, char string[]) /* includefile */
1414
strcpy(string,"ERROR");
1515
fread(&nchar, sizeof(int), 1, inputfile);
1616
if (feof(inputfile)) exit(0);
17-
if (nchar>80 || nchar<1) return;
17+
if (nchar>80 || nchar<1){
18+
printf("\nnchar: %d ; more than allowed limit of 80.\n",nchar);
19+
*nbytes=sizeof(int);
20+
fread(string, 79, 1, inputfile);
21+
printf("Partial string: '%s'\n",string);
22+
return;
23+
}
1824
*nbytes=sizeof(int);
1925
fread(string, nchar, 1, inputfile);
2026
string[nchar]='\0';

src/plot_data.c

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,17 @@ float vmax(float *vec, int n)
2323
return (maxvalue);
2424
}
2525

26+
struct headrecord
27+
{
28+
long int bl,totalsamp;
29+
int nchn,numints;
30+
double sampt,fchan1,chanwidth,startmjd;
31+
};
2632

27-
28-
void plot_data(char outdev[])
33+
void plot_data(char outdev[], int wpout)
2934
{
30-
char plotdev[100];
31-
int i,j,k,npt, i1,i2,j1,j2;
35+
char plotdev[100], plotout[100]={ '\0' };
36+
int i,j,k,n, npt, i1,i2,j1,j2;
3237
long int ntot;
3338
float *xarr, *yarr, *fcstat;
3439
double *tmparr;
@@ -38,6 +43,7 @@ void plot_data(char outdev[])
3843
float tt, ft, th, fh; /* thin and fat thicknesses and heights */
3944
float lm, rm, tm, bm; /* LRTB margins */
4045
int ii, mincol, maxcol, numcol;
46+
struct headrecord head;
4147

4248
npt = maxhist*nsub;
4349
ntot = nchans*naddt;
@@ -48,8 +54,41 @@ void plot_data(char outdev[])
4854
//sprintf(plotdev, "%s/CPS", plotdev);
4955
strcpy(plotdev, outdev);
5056

57+
/*-----------------------------------------------------------*/
58+
/* write the plot data out, if asked for */
59+
if (wpout>0){
60+
n = strlen(outdev);
61+
//printf("\n %d %c %c %s\n",n,outdev[n-2],outdev[n-1],outdev);
62+
if(outdev[n-2]=='p' && outdev[n-1]=='s'){
63+
strncpy(plotout, outdev, n-2);
64+
strcat(plotout, "pdat");
65+
} else {
66+
strcpy(plotout,"abc.pdat");
67+
}
68+
printf ("\nPlot data will be written in: %s\n", plotout);
69+
70+
FILE *optr;
71+
optr = fopen(plotout,"wb");
72+
//fprintf(optr,"%ld %d %ld %f ",naddt,nchans,ntot,tsamp);
73+
//fprintf(optr,"%f %f %f ",fch1,foff,(fch1+nchans*foff));
74+
head.bl = naddt;
75+
head.totalsamp = totsamp;
76+
head.nchn = nchans;
77+
head.numints = nints;
78+
head.sampt = tsamp;
79+
head.fchan1 = fch1;
80+
head.chanwidth = foff;
81+
head.startmjd = tstart;
82+
fwrite(&head,sizeof(head),1,optr);
83+
fwrite(chanstat,sizeof(float),nchans,optr);
84+
fwrite(fftstat,sizeof(float),ntot,optr);
85+
fclose(optr);
86+
}
87+
/*-----------------------------------------------------------*/
88+
5189

5290
/* Open and prep the device */
91+
strcat(plotdev,"/CPS");
5392
cpgopen(plotdev);
5493
cpgpap(10.25, 8.5 / 11.0);
5594
cpgpage();
@@ -237,7 +276,7 @@ void plot_data(char outdev[])
237276
cpgswin(xl, xh, yl, yh);
238277
cpgbox("BCNLST", 0.0, 0, "BNST", 0.0, 0);
239278
//cpgbox("", 0.0, 0, "CST", 0.0, 0);
240-
cpgmtxt("B", 2.6, 0.5, 0.5, "Fluc. Frequency (Hz)");
279+
cpgmtxt("B", 2.6, 0.5, 0.5, "Fourier Frequency (Hz)");
241280
cpgmtxt("L", 2.1, 0.5, 0.5, "Radio Frequency (MHz)");
242281
/* Label */
243282
left = lm + 3.0 * ft + 4.0 * tt;
@@ -324,7 +363,7 @@ void plot_data(char outdev[])
324363
cpgbin(naddt/2, xarr, yarr, 1);
325364
//for (i=0;i<naddt/2;i++) printf("%f %f\n",xarr[i],yarr[i]);
326365
cpgbox("CMLST", 0.0, 0, "", 0.0, 0);
327-
cpgmtxt("T", 1.8, 0.5, 0.5, "Fluc. Frequency (Hz)");
366+
cpgmtxt("T", 1.8, 0.5, 0.5, "Fourier Frequency (Hz)");
328367
/*=======================================================*/
329368

330369
/*==== Chan-reject stats ==========================*/

src/rficlean.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,12 @@ void print_version(char *program, char *argument)
105105

106106
void main (int argc, char *argv[])
107107
{
108-
int i, nc, headersize, headerless=0,gm=0;
108+
int i, ibits, nc, headersize, headerless=0,gm=0;
109109
char string[80];
110110

111111
/* set up default global variables */
112112
obits=headerless=naddt=nsamp=0;
113+
ibits=0;
113114
fthresh = 6.0;
114115
forcefthresh = 1000.0;
115116
rthresh = 4.0;
@@ -159,6 +160,9 @@ void main (int argc, char *argv[])
159160
/* get and open file for output */
160161
strcpy(outfile,argv[++i]);
161162
output=fopen(outfile,"wb");
163+
} else if (strings_equal(argv[i],"-ibits")) {
164+
i++;
165+
ibits=atoi(argv[i]);
162166
} else if (strings_equal(argv[i],"-T")) {
163167
i++;
164168
nsamp=atoi(argv[i]);
@@ -246,6 +250,7 @@ void main (int argc, char *argv[])
246250
printf ("\n Reading the GMRT header & time-stamp file...\n");
247251
read_gmheader(gminfofile, gmhdrfile);
248252
if (naddt <= 1) naddt=4096;
253+
if (ibits > 0) nbits=ibits;
249254
if (obits == 0) obits=nbits;
250255
if( nsamp>0) tsamp = tsamp*nsamp ;
251256
if (!headerless) {
@@ -270,6 +275,8 @@ void main (int argc, char *argv[])
270275
case 2:
271276
nchans=1;
272277
break;
278+
case 6:
279+
break;
273280
default:
274281
error_message("ERROR: Input data to rficlean is not in filterbank format");
275282
break;
@@ -292,5 +299,6 @@ void main (int argc, char *argv[])
292299
/* finally clean and output the data */
293300
rficlean_data(input,output);
294301

302+
printf("\n");
295303
exit(0);
296304
}

src/rficlean_data.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void rficlean_data(FILE *input, FILE *output)
1919
float *fblock,min,max,hpower,realtime,fsaved[2], *ts0dm, atemp;
2020
unsigned short *sblock;
2121
unsigned char *cblock;
22-
int nsaved=0,opened=0;
22+
int nsaved=0,opened=0, wpout=10;
2323
long int ns,nsblk,nout,iter,i,j,k, jt1, jt2, iblock;
2424
long int itemp, isum, nsize, istart, ii, jj, kk, n0;
2525

@@ -34,7 +34,7 @@ void rficlean_data(FILE *input, FILE *output)
3434
nsub = 1;
3535
nsubchans = nchans/nsub ;
3636
strcpy(plotdevice, psfile);
37-
strcat(plotdevice,"/CPS");
37+
////strcat(plotdevice,"/CPS");
3838
nsize = naddt;
3939
if(nsize < nchans) nsize = nchans;
4040
nsize = 2*nsize;
@@ -244,9 +244,12 @@ void rficlean_data(FILE *input, FILE *output)
244244
printf (" Data rfiClean-ed and written out! \n\n");
245245
printf (" Now making diagnostic plots ... ");
246246

247-
plot_data(plotdevice);
247+
plot_data(plotdevice,wpout);
248248
printf (" Done! \n ");
249249

250+
fclose(input);
251+
fclose(output);
252+
250253
fftw_destroy_plan ( fplan );
251254
fftw_destroy_plan ( bplan );
252255
fftw_free ( in );

0 commit comments

Comments
 (0)