-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathselect_final_beamcodes.c
158 lines (148 loc) · 4.61 KB
/
select_final_beamcodes.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include <errno.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <math.h>
#include <netdb.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/mman.h>
#include <sys/stat.h>
#ifdef __QNX__
#include <hw/pci.h>
#include <hw/inout.h>
#include <sys/neutrino.h>
#include <sys/mman.h>
#endif
#include "registers.h"
#define SWITCHES 0
#define ATTEN 1
#define READ 0
#define WRITE 1
#define ON 1
#define OFF 0
#define NEW_PMAT 1
#define read_lookup_table 1
#define CARDS 32
#define PHASECODES 8192
#define BEAMCODES 8192
#define MAX_FREQS 2000
#define MAX_ANGLES 100
int32_t sock=-1;
int32_t verbose=2;
char summaryfile_prefix[20]="beamcodes";
char beamfile_prefix[20]="beamcodes_cal";
char file_ext[20]=".dat";
char filename[120];
char dir[80];
FILE *beamcodefile=NULL;
FILE *beamtablefile=NULL;
FILE *summaryfile=NULL;
char radar_name[80];
struct timeval t0,t1,t2,t3;
unsigned long elapsed;
int32_t main(int32_t argc, char **argv)
{
double *pwr_mag[MAX_FREQS];
double freqs[MAX_FREQS];
double angles[MAX_ANGLES],std_angles[MAX_ANGLES];
int32_t lowest_pwr_mag_index[3]={-1,-1,-1}; // freq,card,phasecode
int32_t *best_phasecode[MAX_FREQS], *best_std_phasecode[MAX_FREQS];
int32_t *final_beamcodes[CARDS];
int32_t *final_attencodes[CARDS];
double *final_angles[CARDS];
double *final_freqs[CARDS];
int32_t a=0,i=0,c=0,b=0,rval=0,count=0;
int32_t num_freqs,num_angles,num_std_angles,num_beamcodes,num_cards;
int32_t std_angle_index_offset=0,angle_index_offset=192;
double df=0.0,angle,freq;
int32_t requested_phasecode=0, beamcode=0;
char radar_name[80];
int32_t temp, j;
float time;
for (c=0;c<CARDS;c++) {
final_beamcodes[c]=calloc(BEAMCODES,sizeof(int32_t));
final_attencodes[c]=calloc(BEAMCODES,sizeof(int32_t));
final_angles[c]=calloc(BEAMCODES,sizeof(double));
final_freqs[c]=calloc(BEAMCODES,sizeof(double));
for (b=0;b<BEAMCODES;b++) {
final_beamcodes[c][b]=-1;
final_attencodes[c][b]=-1;
final_angles[c][b]=-1;
final_freqs[c][b]=-1;
}
}
printf("\n\nEnter Radar Name: ");
fflush(stdin);
scanf("%s", &radar_name);
fflush(stdout);
fflush(stdin);
sprintf(dir,"/home/jspaleta/data/calibrations/%s/",radar_name);
if(read_lookup_table) {
sprintf(filename,"%s/beamcode_lookup_table_%s.dat",dir,radar_name);
beamtablefile=fopen(filename,"r+");
printf("%p %s\n",beamtablefile,filename);
if(beamtablefile!=NULL) {
printf("Reading from saved beamcode lookup table\n");
fread(&num_freqs,sizeof(int32_t),1,beamtablefile);
fread(&num_std_angles,sizeof(int32_t),1,beamtablefile);
fread(&num_angles,sizeof(int32_t),1,beamtablefile);
fread(&num_beamcodes,sizeof(int32_t),1,beamtablefile);
fread(&num_cards,sizeof(int32_t),1,beamtablefile);
fread(&std_angle_index_offset,sizeof(int32_t),1,beamtablefile);
fread(&angle_index_offset,sizeof(int32_t),1,beamtablefile);
fread(freqs,sizeof(double),num_freqs,beamtablefile);
fread(std_angles,sizeof(double),num_std_angles,beamtablefile);
fread(angles,sizeof(double),num_angles,beamtablefile);
printf("Counting saved codes in lookup table\n");
for (c=0;c<CARDS;c++) {
count=0;
rval=fread(final_beamcodes[c],sizeof(int32_t),num_beamcodes,beamtablefile);
rval=fread(final_attencodes[c],sizeof(int32_t),num_beamcodes,beamtablefile);
for (b=0;b<BEAMCODES;b++) {
if (final_beamcodes[c][b] >= 0 ) {
count++;
}
}
printf("Lookup Card: %d Count: %d\n",c,count);
}
fclose(beamtablefile);
beamtablefile=NULL;
} else {
fprintf(stderr,"Error writing beam lookup table file\n");
}
printf("Counting saved codes in lookup table\n");
for (c=0;c<CARDS;c++) {
count=0;
for (b=0;b<BEAMCODES;b++) {
if (final_beamcodes[c][b] >= 0 ) {
count++;
}
}
printf("Lookup Card: %d Count: %d\n",c,count);
}
}
/*
printf("\n\nEnter Beamcode: ");
fflush(stdin);
fflush(stdout);
scanf("%d", &b);
printf("Radar: <%s> Beamcode: %d \n",radar_name,b);
for(c=0;c<20;c++) {
if ( b < angle_index_offset )
printf(" Card: %d Angle: %lf PhaseCode: %d AttenCode: %d\n",c,std_angles[b],final_beamcodes[c][b],final_attencodes[c][b]);
}
fflush(stdout);
*/
}