1 #ifndef _WAPP_CONVERT_H
2 #define _WAPP_CONVERT_H
5 #include "machine_endian.h"
6 #include "wapp_headers.h"
8 template<
class DEST_HEADER,
class ORIG_HEADER>
9 int wapp_hdr_convert_common(DEST_HEADER *dest,
char *rawsrc);
11 template<
class DEST_HEADER,
class ORIG_HEADER>
12 void wapp_hdr_convert_v5(DEST_HEADER *dest,
char *rawsrc);
14 template<
class DEST_HEADER,
class ORIG_HEADER>
15 void wapp_hdr_convert_v6(DEST_HEADER *dest,
char *rawsrc);
17 template<
class DEST_HEADER,
class ORIG_HEADER>
18 void wapp_hdr_convert_v7(DEST_HEADER *dest,
char *rawsrc);
20 template<
class DEST_HEADER,
class ORIG_HEADER>
21 void wapp_hdr_convert_v8(DEST_HEADER *dest,
char *rawsrc);
23 template<
class DEST_HEADER,
class ORIG_HEADER>
24 void wapp_hdr_convert_v9(DEST_HEADER *dest,
char *rawsrc);
26 template<
class DEST_HEADER,
class ORIG_HEADER>
27 void wapp_hdr_convert_iflo_lt9(DEST_HEADER *dest,
char *rawsrc);
29 template<
class DEST_HEADER,
class ORIG_HEADER>
30 void wapp_hdr_convert_iflo_v9(DEST_HEADER *dest,
char *rawsrc);
32 int wapp_hdr_convert(WAPP_HEADER *dest,
char *rawsrc);
35 int wapp_hdr_convert(WAPP_HEADER *dest,
char *rawsrc) {
36 int ver = *(int32_t *)rawsrc;
39 rv = wapp_hdr_convert_common<WAPP_HEADER, WAPP_HEADER_v2>(dest,rawsrc);
42 rv = wapp_hdr_convert_common<WAPP_HEADER, WAPP_HEADER_v3>(dest,rawsrc);
45 rv = wapp_hdr_convert_common<WAPP_HEADER, WAPP_HEADER_v4>(dest,rawsrc);
48 rv = wapp_hdr_convert_common<WAPP_HEADER, WAPP_HEADER_v5>(dest,rawsrc);
49 wapp_hdr_convert_v5<WAPP_HEADER, WAPP_HEADER_v5>(dest,rawsrc);
52 rv = wapp_hdr_convert_common<WAPP_HEADER, WAPP_HEADER_v6>(dest,rawsrc);
53 wapp_hdr_convert_v5<WAPP_HEADER, WAPP_HEADER_v6>(dest,rawsrc);
54 wapp_hdr_convert_v6<WAPP_HEADER, WAPP_HEADER_v6>(dest,rawsrc);
55 wapp_hdr_convert_iflo_lt9<WAPP_HEADER, WAPP_HEADER_v6>(dest,rawsrc);
58 rv = wapp_hdr_convert_common<WAPP_HEADER, WAPP_HEADER_v7>(dest,rawsrc);
59 wapp_hdr_convert_v5<WAPP_HEADER, WAPP_HEADER_v7>(dest,rawsrc);
60 wapp_hdr_convert_v6<WAPP_HEADER, WAPP_HEADER_v7>(dest,rawsrc);
61 wapp_hdr_convert_iflo_lt9<WAPP_HEADER, WAPP_HEADER_v7>(dest,rawsrc);
62 wapp_hdr_convert_v7<WAPP_HEADER, WAPP_HEADER_v7>(dest,rawsrc);
65 rv = wapp_hdr_convert_common<WAPP_HEADER, WAPP_HEADER_v8>(dest,rawsrc);
66 wapp_hdr_convert_v5<WAPP_HEADER, WAPP_HEADER_v8>(dest,rawsrc);
67 wapp_hdr_convert_v6<WAPP_HEADER, WAPP_HEADER_v8>(dest,rawsrc);
68 wapp_hdr_convert_iflo_lt9<WAPP_HEADER, WAPP_HEADER_v8>(dest,rawsrc);
69 wapp_hdr_convert_v7<WAPP_HEADER, WAPP_HEADER_v8>(dest,rawsrc);
70 wapp_hdr_convert_v8<WAPP_HEADER, WAPP_HEADER_v8>(dest,rawsrc);
73 rv = wapp_hdr_convert_common<WAPP_HEADER, WAPP_HEADER_v9>(dest,rawsrc);
74 wapp_hdr_convert_v5<WAPP_HEADER, WAPP_HEADER_v9>(dest,rawsrc);
75 wapp_hdr_convert_v6<WAPP_HEADER, WAPP_HEADER_v9>(dest,rawsrc);
76 wapp_hdr_convert_iflo_v9<WAPP_HEADER, WAPP_HEADER_v9>(dest,rawsrc);
77 wapp_hdr_convert_v7<WAPP_HEADER, WAPP_HEADER_v9>(dest,rawsrc);
78 wapp_hdr_convert_v8<WAPP_HEADER, WAPP_HEADER_v9>(dest,rawsrc);
79 wapp_hdr_convert_v9<WAPP_HEADER, WAPP_HEADER_v9>(dest,rawsrc);
88 #if MACHINE_LITTLE_ENDIAN
89 # define WAPP_SET_PARAM(p) dest->p = src->p
90 # define WAPP_CPY_PARAM(p) memcpy(dest->p, src->p, sizeof(src->p))
92 # define WAPP_SET_PARAM(p) do {\
93 if (sizeof(src->p)>1) ChangeEndian(src->p); \
94 dest->p = src->p; } while (0)
95 # define WAPP_CPY_PARAM(p) do {\
96 if (sizeof(src->p[0])>1) \
97 array_changeEndian(sizeof(src->p)/sizeof(src->p[0]), src->p, \
99 memcpy(dest->p, src->p, sizeof(src->p)); } while(0)
103 template<
class DEST_HEADER,
class ORIG_HEADER>
104 int wapp_hdr_convert_common (DEST_HEADER *dest,
char *rawsrc)
106 ORIG_HEADER *src = (ORIG_HEADER *)rawsrc;
107 int orig_version = src->header_version;
110 if (orig_version<2) {
return(-1); }
113 memset(dest, 0,
sizeof(DEST_HEADER));
116 WAPP_SET_PARAM(header_version);
117 WAPP_SET_PARAM(header_size);
118 WAPP_CPY_PARAM(obs_type);
119 WAPP_SET_PARAM(src_ra);
120 WAPP_SET_PARAM(src_dec);
121 WAPP_SET_PARAM(start_az);
122 WAPP_SET_PARAM(start_za);
123 WAPP_SET_PARAM(start_ast);
124 WAPP_SET_PARAM(start_lst);
125 WAPP_SET_PARAM(cent_freq);
126 WAPP_SET_PARAM(obs_time);
127 WAPP_SET_PARAM(samp_time);
128 WAPP_SET_PARAM(wapp_time);
129 WAPP_SET_PARAM(bandwidth);
130 WAPP_SET_PARAM(num_lags);
131 WAPP_SET_PARAM(scan_number);
132 WAPP_CPY_PARAM(src_name);
133 WAPP_CPY_PARAM(obs_date);
134 WAPP_CPY_PARAM(start_time);
135 WAPP_CPY_PARAM(project_id);
136 WAPP_CPY_PARAM(observers);
137 WAPP_SET_PARAM(nifs);
138 WAPP_SET_PARAM(level);
140 WAPP_SET_PARAM(freqinversion);
141 WAPP_SET_PARAM(timeoff);
142 WAPP_SET_PARAM(lagformat);
143 WAPP_SET_PARAM(lagtrunc);
144 WAPP_SET_PARAM(firstchannel);
145 WAPP_SET_PARAM(nbins);
146 WAPP_SET_PARAM(dumptime);
147 WAPP_CPY_PARAM(power_analog);
148 WAPP_SET_PARAM(psr_dm);
149 WAPP_CPY_PARAM(rphase);
150 WAPP_CPY_PARAM(psr_f0);
151 WAPP_CPY_PARAM(poly_tmid);
152 WAPP_CPY_PARAM(coeff);
153 WAPP_CPY_PARAM(num_coeffs);
155 return(orig_version);
159 template<
class DEST_HEADER,
class ORIG_HEADER>
160 void wapp_hdr_convert_v5(DEST_HEADER *dest,
char *rawsrc)
162 ORIG_HEADER *src = (ORIG_HEADER *)rawsrc;
165 WAPP_CPY_PARAM(hostname);
169 template<
class DEST_HEADER,
class ORIG_HEADER>
170 void wapp_hdr_convert_v6(DEST_HEADER *dest,
char *rawsrc)
172 ORIG_HEADER *src = (ORIG_HEADER *)rawsrc;
175 WAPP_SET_PARAM(fold_bits);
178 WAPP_SET_PARAM(syn1);
179 WAPP_CPY_PARAM(synfrq);
180 WAPP_SET_PARAM(ifnum);
181 WAPP_SET_PARAM(phbsig);
182 WAPP_SET_PARAM(hybrid);
183 WAPP_SET_PARAM(phblo);
188 template<
class DEST_HEADER,
class ORIG_HEADER>
189 void wapp_hdr_convert_iflo_lt9(DEST_HEADER *dest,
char *rawsrc)
191 ORIG_HEADER *src = (ORIG_HEADER *)rawsrc;
192 #if (MACHINE_LITTLE_ENDIAN==0)
193 ChangeEndian(src->iflo_flip);
195 dest->iflo_flip[0] = src->iflo_flip;
196 dest->iflo_flip[1] = src->iflo_flip;
200 template<
class DEST_HEADER,
class ORIG_HEADER>
201 void wapp_hdr_convert_iflo_v9(DEST_HEADER *dest,
char *rawsrc)
203 ORIG_HEADER *src = (ORIG_HEADER *)rawsrc;
204 WAPP_CPY_PARAM(iflo_flip);
208 template<
class DEST_HEADER,
class ORIG_HEADER>
209 void wapp_hdr_convert_v7(DEST_HEADER *dest,
char *rawsrc)
211 ORIG_HEADER *src = (ORIG_HEADER *)rawsrc;
212 WAPP_SET_PARAM(isfolding);
213 WAPP_SET_PARAM(isalfa);
217 template<
class DEST_HEADER,
class ORIG_HEADER>
218 void wapp_hdr_convert_v8(DEST_HEADER *dest,
char *rawsrc)
220 ORIG_HEADER *src = (ORIG_HEADER *)rawsrc;
223 WAPP_CPY_PARAM(frontend);
230 template<
class DEST_HEADER,
class ORIG_HEADER>
231 void wapp_hdr_convert_v9(DEST_HEADER *dest,
char *rawsrc)
233 ORIG_HEADER *src = (ORIG_HEADER *)rawsrc;
236 WAPP_SET_PARAM(isdual);