forked from lacker/seticore
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstampls.cpp
More file actions
76 lines (67 loc) · 2.37 KB
/
Copy pathstampls.cpp
File metadata and controls
76 lines (67 loc) · 2.37 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
69
70
71
72
73
74
75
76
#include <capnp/message.h>
#include <capnp/serialize.h>
#include <errno.h>
#include <fcntl.h>
#include <fmt/core.h>
#include <iostream>
#include "stamp.capnp.h"
#include <time.h>
#include <unistd.h>
#include "util.h"
using namespace std;
/*
Displays information about a stamp file.
Usage:
stampls <filename>
*/
int main(int argc, char* argv[]) {
if (argc != 2) {
cerr << "usage: stampls <filename>\n";
exit(1);
}
string filename(argv[1]);
int fd = open(filename.c_str(), O_RDONLY);
if (fd < 0) {
int err = errno;
cerr << "could not open " << filename << " for reading. errno = "
<< err << endl;
exit(1);
}
int count = 0;
kj::FdInputStream fd_stream(fd);
kj::BufferedInputStreamWrapper buffered_stream(fd_stream);
while (buffered_stream.tryGetReadBuffer() != nullptr) {
capnp::InputStreamMessageReader message(buffered_stream);
Stamp::Reader stamp = message.getRoot<Stamp>();
cout << "stamp " << count << ":\n";
cout << "version: " << stamp.getSeticoreVersion().cStr() << endl;
cout << "source: " << stamp.getSourceName().cStr() << endl;
cout << "obsid: " << stamp.getObsid().cStr() << endl;
cout << "ra: " << stamp.getRa() << endl;
cout << "dec: " << stamp.getDec() << endl;
cout << "fch1: " << stamp.getFch1() << endl;
cout << "foff: " << stamp.getFoff() << endl;
double tstart = stamp.getTstart();
long num_seconds = (long) tstart;
double remainder = tstart - num_seconds;
long microseconds = floor(remainder * 1000000);
time_t time = num_seconds;
int n = 100;
char date_string[n];
strftime(date_string, n, "%F %T", gmtime(&time));
cout << "tstart: " << date_string << fmt::format(".{:06d}", microseconds) << endl;
cout << "tsamp: " << stamp.getTsamp() << endl;
cout << "telescope: " << stamp.getTelescopeId() << endl;
cout << "timesteps: " << stamp.getNumTimesteps() << endl;
cout << "channels: " << stamp.getNumChannels() << endl;
cout << "polarizations: " << stamp.getNumPolarizations() << endl;
cout << "antennas: " << stamp.getNumAntennas() << endl;
cout << "coarse channel: " << stamp.getCoarseChannel() << endl;
cout << "fft size: " << stamp.getFftSize() << endl;
cout << "start channel: " << stamp.getStartChannel() << endl;
cout << endl;
++count;
}
close(fd);
cout << pluralize(count, "stamp") << " in the file\n";
}