-
Notifications
You must be signed in to change notification settings - Fork 37
/
rfedit.c
128 lines (101 loc) · 2.69 KB
/
rfedit.c
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cpgplot.h>
#include <getopt.h>
#include "rfio.h"
#define LIM 128
void dec2sex(double x,char *s,int f,int len);
void usage(void)
{
printf("rfplot: plot RF observations\n\n");
printf("-p <path> Path to file prefix /a/b/c_??????.bin\n");
printf("-O <file> Output file name [test_000000.bin]\n");
printf("-s <start> Number of starting subintegration [0]\n");
printf("-l <length> Number of subintegrations to plot [3600]\n");
printf("-o <offset> Frequency offset to apply (Hz) [0.0]\n");
printf("-b <nbin> Number of subintegrations to bin [1]\n");
printf("-f <freq> Frequency to zoom into (Hz)\n");
printf("-w <bw> Bandwidth to zoom into (Hz)\n");
printf("-h This help\n");
return;
}
int main(int argc,char *argv[])
{
struct spectrogram s;
char path[128],outfile[128]="test";
int arg=0,nsub=3600,nbin=1,isub=0;
double f0=0.0,df0=0.0,foff=0.0;
// Read arguments
if (argc>1) {
while ((arg=getopt(argc,argv,"p:o:O:f:w:s:l:b:h"))!=-1) {
switch (arg) {
case 'p':
strcpy(path,optarg);
break;
case 'O':
strcpy(outfile,optarg);
break;
case 'o':
foff=(double) atof(optarg);
break;
case 's':
isub=atoi(optarg);
break;
case 'l':
nsub=atoi(optarg);
break;
case 'b':
nbin=atoi(optarg);
break;
case 'f':
f0=(double) atof(optarg);
break;
case 'w':
df0=(double) atof(optarg);
break;
case 'h':
usage();
break;
default:
usage();
return 0;
}
}
} else {
usage();
return 0;
}
// Read data
s=read_spectrogram(path,isub,nsub,f0,df0,nbin,foff);
// Write data
write_spectrogram(s,outfile);
// Free
// free(s.z);
// free(s.mjd);
// free(s.length);
return 0;
}
// Convert Decimal into Sexagesimal
void dec2sex(double x,char *s,int f,int len)
{
int i;
double sec,deg,min;
char sign;
char *form[]={"::",",,","hms"," "};
sign=(x<0 ? '-' : ' ');
x=3600.*fabs(x);
sec=fmod(x,60.);
x=(x-sec)/60.;
min=fmod(x,60.);
x=(x-min)/60.;
// deg=fmod(x,60.);
deg=x;
if (len==7) sprintf(s,"%c%02i%c%02i%c%07.4f%c",sign,(int) deg,form[f][0],(int) min,form[f][1],sec,form[f][2]);
if (len==6) sprintf(s,"%c%02i%c%02i%c%06.3f%c",sign,(int) deg,form[f][0],(int) min,form[f][1],sec,form[f][2]);
if (len==5) sprintf(s,"%c%02i%c%02i%c%05.2f%c",sign,(int) deg,form[f][0],(int) min,form[f][1],sec,form[f][2]);
if (len==4) sprintf(s,"%c%02i%c%02i%c%04.1f%c",sign,(int) deg,form[f][0],(int) min,form[f][1],sec,form[f][2]);
if (len==2) sprintf(s,"%c%02i%c%02i%c%02i%c",sign,(int) deg,form[f][0],(int) min,form[f][1],(int) floor(sec),form[f][2]);
return;
}