forked from SixByNine/sigproc
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdecimate_data.c
More file actions
68 lines (65 loc) · 1.89 KB
/
decimate_data.c
File metadata and controls
68 lines (65 loc) · 1.89 KB
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
#include "decimate.h"
void decimate_data(FILE *input, FILE *output) /*includefile*/
{
char string[80];
float *fblock,min,max,realtime,fsaved[2];
unsigned short *sblock;
unsigned char *cblock;
int nsaved=0,ns,nsblk,opened=0,nout;
nsblk=nchans*nifs*naddt;
fblock=(float *) malloc(nsblk*sizeof(float));
sblock=(unsigned short *) malloc(nsblk*sizeof(unsigned short));
cblock=(unsigned char *) malloc(nsblk*sizeof(unsigned short));
realtime=min=0.0;
max=(float) pow(2.0,(double)obits) -1.0;
/* main decimation loop */
while ((ns=read_block(input,nbits,fblock,nsblk))>0) {
add_channels(fblock,ns,naddc);
add_samples(fblock,nifs,nchans/naddc,naddt);
if (!opened) {
/* open up logfile */
open_log("decimate.monitor");
opened=1;
}
nout=ns/naddt/naddc;
switch (obits) {
case 32:
fwrite(fblock,sizeof(float),nout,output);
break;
case 16:
float2short(fblock,nout,min,max,sblock);
fwrite(sblock,sizeof(unsigned short),nout,output);
break;
case 8:
float2char(fblock,nout,min,max,cblock);
fwrite(cblock,sizeof(unsigned char),nout,output);
break;
case 4:
if (nout==1) {
/* must have at least two samples for four-bit packing save this one */
fsaved[nsaved]=fblock[0];
nsaved++;
if (nsaved==2) {
/* we have 2 saved! write out */
float2four(fsaved,nsaved,min,max,cblock);
fwrite(cblock,sizeof(unsigned char),1,output);
nsaved=0;
}
} else {
/* normal case */
float2four(fblock,nout,min,max,cblock);
fwrite(cblock,sizeof(unsigned char),nout/2,output);
}
break;
case 2:
float2two(fblock,nout,min,max,cblock);
fwrite(cblock,sizeof(unsigned char),nout/4,output);
break;
}
realtime+=(float) tsamp * (float) ns/(float) nchans/(float) nifs;
sprintf(string,"time:%.1fs",realtime);
update_log(string);
}
update_log("finished");
close_log();
}