wapp_convert.h
1 #ifndef _WAPP_CONVERT_H
2 #define _WAPP_CONVERT_H
3 
4 #include <string.h>
5 #include "machine_endian.h"
6 #include "wapp_headers.h"
7 
8 template<class DEST_HEADER, class ORIG_HEADER>
9 int wapp_hdr_convert_common(DEST_HEADER *dest, char *rawsrc);
10 
11 template<class DEST_HEADER, class ORIG_HEADER>
12 void wapp_hdr_convert_v5(DEST_HEADER *dest, char *rawsrc);
13 
14 template<class DEST_HEADER, class ORIG_HEADER>
15 void wapp_hdr_convert_v6(DEST_HEADER *dest, char *rawsrc);
16 
17 template<class DEST_HEADER, class ORIG_HEADER>
18 void wapp_hdr_convert_v7(DEST_HEADER *dest, char *rawsrc);
19 
20 template<class DEST_HEADER, class ORIG_HEADER>
21 void wapp_hdr_convert_v8(DEST_HEADER *dest, char *rawsrc);
22 
23 template<class DEST_HEADER, class ORIG_HEADER>
24 void wapp_hdr_convert_v9(DEST_HEADER *dest, char *rawsrc);
25 
26 template<class DEST_HEADER, class ORIG_HEADER>
27 void wapp_hdr_convert_iflo_lt9(DEST_HEADER *dest, char *rawsrc);
28 
29 template<class DEST_HEADER, class ORIG_HEADER>
30 void wapp_hdr_convert_iflo_v9(DEST_HEADER *dest, char *rawsrc);
31 
32 int wapp_hdr_convert(WAPP_HEADER *dest, char *rawsrc);
33 
34 // Convert wrapper func
35 int wapp_hdr_convert(WAPP_HEADER *dest, char *rawsrc) {
36  int ver = *(int32_t *)rawsrc;
37  int rv;
38  if (ver==2) {
39  rv = wapp_hdr_convert_common<WAPP_HEADER, WAPP_HEADER_v2>(dest,rawsrc);
40  return(rv);
41  } else if (ver==3) {
42  rv = wapp_hdr_convert_common<WAPP_HEADER, WAPP_HEADER_v3>(dest,rawsrc);
43  return(rv);
44  } else if (ver==4) {
45  rv = wapp_hdr_convert_common<WAPP_HEADER, WAPP_HEADER_v4>(dest,rawsrc);
46  return(rv);
47  } else if (ver==5) {
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);
50  return(rv);
51  } else if (ver==6) {
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);
56  return(rv);
57  } else if (ver==7) {
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);
63  return(rv);
64  } else if (ver==8) {
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);
71  return(rv);
72  } else if (ver==9) {
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);
80  return(rv);
81  //memcpy(dest,rawsrc,sizeof(WAPP_HEADER_v9));
82  //return(0);
83  } else {
84  return(-1);
85  }
86 }
87 
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))
91 #else
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, \
98  sizeof(src->p[0])); \
99  memcpy(dest->p, src->p, sizeof(src->p)); } while(0)
100 #endif
101 
102 // Convert common attributes
103 template<class DEST_HEADER, class ORIG_HEADER>
104 int wapp_hdr_convert_common (DEST_HEADER *dest, char *rawsrc)
105 {
106  ORIG_HEADER *src = (ORIG_HEADER *)rawsrc;
107  int orig_version = src->header_version;
108 
109  // We only handle versions starting at 2
110  if (orig_version<2) { return(-1); }
111 
112  // Zero out dest struct
113  memset(dest, 0, sizeof(DEST_HEADER));
114 
115  // Attributes common to all versions
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);
139  WAPP_SET_PARAM(sum);
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);
154 
155  return(orig_version);
156 }
157 
158 // Things introduced in version 5
159 template<class DEST_HEADER, class ORIG_HEADER>
160 void wapp_hdr_convert_v5(DEST_HEADER *dest, char *rawsrc)
161 {
162  ORIG_HEADER *src = (ORIG_HEADER *)rawsrc;
163 
164  // Versions 5 additions
165  WAPP_CPY_PARAM(hostname);
166 }
167 
168 // Version 6
169 template<class DEST_HEADER, class ORIG_HEADER>
170 void wapp_hdr_convert_v6(DEST_HEADER *dest, char *rawsrc)
171 {
172  ORIG_HEADER *src = (ORIG_HEADER *)rawsrc;
173 
174  // Version 6 additions
175  WAPP_SET_PARAM(fold_bits);
176 
177  // Some of the IFLO stuff
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);
184 
185 }
186 
187 // Convert iflo_flip from versions less than 9 to v9+
188 template<class DEST_HEADER, class ORIG_HEADER>
189 void wapp_hdr_convert_iflo_lt9(DEST_HEADER *dest, char *rawsrc)
190 {
191  ORIG_HEADER *src = (ORIG_HEADER *)rawsrc;
192 #if (MACHINE_LITTLE_ENDIAN==0)
193  ChangeEndian(src->iflo_flip);
194 #endif
195  dest->iflo_flip[0] = src->iflo_flip;
196  dest->iflo_flip[1] = src->iflo_flip;
197 }
198 
199 // Convert iflo_flip for versions v9+
200 template<class DEST_HEADER, class ORIG_HEADER>
201 void wapp_hdr_convert_iflo_v9(DEST_HEADER *dest, char *rawsrc)
202 {
203  ORIG_HEADER *src = (ORIG_HEADER *)rawsrc;
204  WAPP_CPY_PARAM(iflo_flip);
205 }
206 
207 // Version 7
208 template<class DEST_HEADER, class ORIG_HEADER>
209 void wapp_hdr_convert_v7(DEST_HEADER *dest, char *rawsrc)
210 {
211  ORIG_HEADER *src = (ORIG_HEADER *)rawsrc;
212  WAPP_SET_PARAM(isfolding);
213  WAPP_SET_PARAM(isalfa);
214 }
215 
216 // Version 8
217 template<class DEST_HEADER, class ORIG_HEADER>
218 void wapp_hdr_convert_v8(DEST_HEADER *dest, char *rawsrc)
219 {
220  ORIG_HEADER *src = (ORIG_HEADER *)rawsrc;
221 
222  // Version 8 additions
223  WAPP_CPY_PARAM(frontend);
224 
225  // TODO : all the alfa stuff?
226 
227 }
228 
229 // Version 9
230 template<class DEST_HEADER, class ORIG_HEADER>
231 void wapp_hdr_convert_v9(DEST_HEADER *dest, char *rawsrc)
232 {
233  ORIG_HEADER *src = (ORIG_HEADER *)rawsrc;
234 
235  // Version 9 additions
236  WAPP_SET_PARAM(isdual);
237 
238 }
239 
240 #endif
Angle get_declination() const
Get the DEC (J2000) at subint centre.
Definition: Pointing.C:103
Angle get_galactic_longitude() const
Get the Gal longitude at subint centre.
Definition: Pointing.C:114
Angle get_parallactic_angle() const
Get the Parallactic angle at subint centre.
Definition: Pointing.C:158
Angle get_galactic_latitude() const
Get the Gal latitude at subint centre.
Definition: Pointing.C:125
static bool verbose
static Archive * load(const std::string &name)
Factory returns a new instance loaded from filename.
Definition: Archive_load.C:28
static void set_verbosity(unsigned level)
Set the verbosity level (0 to 3)
Definition: Archive_verbose.C:19
Angle get_right_ascension() const
Get the RA (J2000) at subint centre.
Definition: Pointing.C:92
Angle get_position_angle() const
Get the Position angle of feed at subint centre.
Definition: Pointing.C:147
Angle get_telescope_zenith() const
Get the Telescope zenith angle at subint centre.
Definition: Pointing.C:180
Angle get_telescope_azimuth() const
Get the Telescope azimuth at subint centre.
Definition: Pointing.C:169
double get_local_sidereal_time() const
Get the LST (in seconds) at subint centre.
Definition: Pointing.C:72
Angle get_feed_angle() const
Get the Feed angle at subint centre.
Definition: Pointing.C:136
bool verbose
Definition: timer++.C:25
Telescope pointing parameters recorded during the observation.
Definition: Pointing.h:27

Generated using doxygen 1.8.17