File: odc_header.cc

package info (click to toggle)
odc 1.6.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,140 kB
  • sloc: cpp: 21,984; f90: 3,707; sh: 966; ansic: 477; python: 389; makefile: 33
file content (77 lines) | stat: -rw-r--r-- 2,214 bytes parent folder | download
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
/**
 * To build this program, please make sure to reference linked libraries:
 *
 *     g++ -std=c++11 -leckit -lodccore -o odc-cpp-header odc_header.cc
 */

#include <iostream>

#include "eckit/runtime/Main.h"

#include "odc/api/Odb.h"

void usage() {
    std::cerr << "Usage:\n    odc-cpp-header <odb2 file 1> [<odb2 file 2> ...]" << std::endl << std::endl;
}

using namespace eckit;
using namespace odc::api;

int main(int argc, char** argv) {
    if (argc < 2) {
        usage();
        return 1;
    }

    // Initialise API
    Main::initialise(argc, argv);

    int argi;

    // Iterate over all supplied path arguments
    for (argi = 1; argi < argc; argi++) {
        char* path = argv[argi];

        bool aggregated = false;

        // Open supplied path in non-aggregated mode
        Reader reader(path, aggregated);

        std::cout << "File: " << path << std::endl;

        Frame frame;
        int i = 0;

        // Iterate over all frames in the stream, without decoding them
        while ((frame = reader.next())) {
            std::cout << "  Frame: " << ++i << ", Row count: " << frame.rowCount()
                      << ", Column count: " << frame.columnCount() << std::endl;

            for (const auto& property : frame.properties()) {
                std::cout << "  Property: " << property.first << " => " << property.second << std::endl;
            }

            int j = 0;

            // Iterate over frame columns
            for (const auto& column : frame.columnInfo()) {
                std::cout << "    Column: " << ++j << ", Name: " << column.name
                          << ", Type: " << columnTypeName(column.type) << ", Size: " << column.decodedSize << std::endl;

                // Process bitfields only
                if (column.type == BITFIELD) {
                    int k = 0;

                    for (auto const& bf : column.bitfield) {
                        std::cout << "      Bitfield: " << ++k << ", Name: " << bf.name << ", Offset: " << bf.offset
                                  << ", Nbits: " << bf.size << std::endl;
                    }
                }
            }

            std::cout << std::endl;
        }
    }

    return 0;
}