18 uint16_t &ncp, uint16_t &nbb, uint16_t &nrb,
19 uint16_t &nsp, uint16_t &ndc, uint16_t &nds,
20 uint16_t *btaps, uint16_t *rtaps,
itab *itable) {
24 short nagg[4] = {1,2,4,8};
30 for (
size_t i=0;
i<10;
i++) {
37 if (itable[
i].
dtype == 2) {
39 nds += itable[
i].lines / 8;
42 nsp += itable[
i].lines / 8;
63 short btap = apacket[
ioff+2]*256 + apacket[
ioff+3];
64 short rtap = apacket[
ioff]*256 + apacket[
ioff+1];
69 memcpy( &bagg, &apacket[
ioff+8],
sizeof(uint32_t));
70 memcpy( &ragg, &apacket[
ioff+4],
sizeof(uint32_t));
83 for (
int i=15;
i>=0;
i--) {
84 btaps[
i] = (btap & ken) / ken;
85 if (btaps[
i]) nbb += 32 / nagg[(bagg & kag) / lag];
86 rtaps[
i] = (rtap & ken) / ken;
87 if (rtaps[
i]) nrb += 32 / nagg[(ragg & kag) / lag];
107 memcpy( &sec58, &apacket[toff],
sizeof(uint32_t));
110 double dbl58 = (
double) sec58;
115 iday = sec58 / 86400;
116 int32_t
jd = iday + 2436205;
121 memcpy( &usec, &apacket[toff+4],
sizeof(uint32_t));
125 uint32_t isec = sec58 % 86400;
126 stime = isec + ((
double) usec) * 1e-6;
134 uint32_t &npkts, int32_t &spnum,
135 int32_t &ancind, vector<int32_t> &tlmind,
136 uint8_t &seqerr, int32_t &endfile) {
140 uint32_t apidmin = 636;
141 uint32_t apidmax = 745;
144 uint32_t maxpkts = 30000;
147 static uint32_t apida = 636;
150 static uint32_t apidt[8] = {711,712,713,715,716,717,721,723};
153 static uint32_t apidn[2] = {700,720};
156 uint32_t apid = (apacket[0] % 8) * 256 + apacket[1];
163 if ( endfile)
return 0;
167 memcpy( &ui32, &apacket[24], 4);
169 }
else if (apid == apidn[0] || apid == apidn[1]) {
171 memcpy( &ui32, &apacket[6], 4);
174 }
else if (std::find(std::begin(apidt), std::end(apidt), apid) != std::end(apidt)) {
176 memcpy( &ui32, &apacket[12], 4);
183 int32_t spnt = spnum;
184 uint8_t *packet = apacket;
186 len = apacket[4] * 256 + apacket[5] + 7;
193 while (spn <= spnum && spnt <= (spnum+1) && (npkts < maxpkts)) {
197 memcpy( &pbuffer[npkts][0], packet, len);
198 apid = (packet[0] % 8) * 256 + packet[1];
201 if (apid==apidn[0]) {
202 int pseq = (pbuffer[npkts][2] % 64)*256 + pbuffer[npkts][3];
203 if ( (prev_pseq>0) && ((pseq-prev_pseq) != 1 && (pseq-prev_pseq) != -16383)) {
210 if (apid == apida) ancind = npkts;
217 if (apid >= apidmin & apid <= apidmax &&
218 apid != apidn[0] && apid != apidn[1]) {
219 tlmind.push_back(npkts);
222 if (npkts == maxpkts) {
223 cout <<
"Maximum number of packets: " << maxpkts
224 <<
" exceeded." << endl;
231 if ( endfile)
return 0;
234 cout <<
"Packet size > " <<
PKTSIZE <<
" (" << len <<
")" << endl;
235 uint8_t *dummy_buf =
new uint8_t[len];
236 read_packet( tfileStream, dummy_buf, len, apid, endfile);
240 read_packet( tfileStream, packet, len, apid, endfile);
241 apid = (packet[0] % 8) * 256 + packet[1];
244 while (apid < apidmin || apid > apidmax) {
246 if ( endfile)
return 0;
249 cout <<
"Packet size > " <<
PKTSIZE <<
" (" << len <<
")" << endl;
250 uint8_t *dummy_buf =
new uint8_t[len];
251 read_packet( tfileStream, dummy_buf, len, apid, endfile);
255 read_packet( tfileStream, packet, len, apid, endfile);
256 apid = (packet[0] % 8) * 256 + packet[1];
262 memcpy( &ui32, &packet[24], 4);
264 }
else if (apid == apidn[0] || apid == apidn[1]) {
265 memcpy( &ui32, &packet[6], 4);
268 }
else if (std::find(std::begin(apidt), std::end(apidt), apid) != std::end(apidt)) {
269 memcpy( &ui32, &packet[12], 4);
299 for (
size_t i=0;
i<ilen;
i++)
300 if (apacket[
ioff+
i] != apacket0[
ioff+
i]) aggi++;
304 memcpy( &ui32, &apacket[24], 4);
305 int32_t spn =
SWAP_4( ui32);
306 uint16_t
ih = (uint16_t) floor(stime/3600);
307 uint16_t mn = (uint16_t) floor((stime -
ih*3600)/60);
308 uint16_t sec = (uint16_t) floor(stime -
ih*3600 - mn*60);
309 cout <<
"Spatial table change at: spin="<<spn<<
", "
310 <<
ih <<
":" << mn <<
":" << sec << endl;
321 for (
size_t i=0;
i<jlen;
i++)
322 if (apacket[joff+
i] != apacket0[joff+
i]) aggj++;
326 memcpy( &ui32, &apacket[24], 4);
327 int32_t spn =
SWAP_4( ui32);
328 uint16_t
ih = (uint16_t) floor(stime/3600);
329 uint16_t mn = (uint16_t) floor((stime -
ih*3600)/60);
330 uint16_t sec = (uint16_t) floor(stime -
ih*3600 - mn*60);
331 cout <<
"Spectral table change at: spin="<<spn<<
", "
332 <<
ih <<
":" << mn <<
":" << sec << endl;
341 uint32_t &len, uint32_t &apid, int32_t &endfile) {
343 if ( tfileStream->eof()) {
346 cout <<
"End of packet file" << endl;
352 if ( packet ==
NULL) {
353 tfileStream->read( (
char *) &phead, 6);
356 len = phead[4]*256 + phead[5] + 1 + 6;
357 apid = (phead[0] % 8)*256 + phead[1];
359 if ( tfileStream->tellg() == -1) endfile = 1;
360 tfileStream->seekg( -6, ios_base::cur);
363 tfileStream->read( (
char *) packet, len);
371 uint32_t npkts, uint16_t &smode) {
376 for (
size_t ipkt=0; ipkt<npkts; ipkt++) {
377 uint32_t apid = (pbuffer[ipkt][0] % 8) * 256 + pbuffer[ipkt][1];
381 uint8_t smeta = pbuffer[ipkt][12];
382 smode = (smeta % 64) / 16;