#include <wreport/bulletin.h>
namespace {
void read_bufr_raw(const Options& opts, const char* fname, RawHandler& handler)
{
FILE* in = fopen(fname, "rb");
if (in == NULL)
try {
std::string raw_data;
off_t offset;
handler.handle_raw_bufr(raw_data, fname, offset);
fclose(in);
} catch (...) {
fclose(in);
throw;
}
}
void read_crex_raw(const Options& opts, const char* fname, RawHandler& handler)
{
FILE* in = fopen(fname, "rt");
if (in == NULL)
try {
string raw_data;
off_t offset;
handler.handle_raw_crex(raw_data, fname, offset);
fclose(in);
} catch (...) {
fclose(in);
throw;
}
}
}
static bool read(FILE *in, std::string &buf, const char *fname=0, off_t *offset=0)
Read an encoded BUFR message from a stream.
static bool read(FILE *in, std::string &buf, const char *fname=0, off_t *offset=0)
Read an encoded BUFR message from a stream.
static std::unique_ptr< CrexBulletin > create()
To prevent breaking ABI if new members are added to bulletins, direct construction is discouraged in ...
static void throwf(const char *fmt,...) WREPORT_THROWF_ATTRS(1
Throw the exception, building the message printf-style.
The bulletin namespace contains bulletin implementation details, internals and utility functions.
Definition input.h:13
String functions.
Definition benchmark.h:13
Configuration variables to control configurable aspects of wreport's behaviour.
#include <wreport/bulletin.h>
#include <wreport/bulletin/dds-scanfeatures.h>
#include <cstring>
struct PrintContents : public BulletinFullHandler
{
FILE* out;
PrintContents(FILE* out=stderr) : out(out) {}
{
}
};
struct PrintTrace : public BulletinFullHandler
{
FILE* out;
PrintTrace(FILE* out=stderr) : out(out) {}
void handle_raw_bufr(const std::string& raw_data, const char* fname, long offset) override
{
try {
handle(*bulletin);
} catch (std::exception& e) {
fprintf(stderr, "%s:%ld:%s\n", fname, offset, e.what());
}
}
void handle(wreport::Bulletin& b) override {}
};
struct PrintStructure : public BulletinFullHandler
{
FILE* out;
PrintStructure(FILE* out=stderr) : out(out) {}
void handle(wreport::Bulletin& b) override
{
}
};
struct PrintDDS : public BulletinHeadHandler
{
FILE* out;
PrintDDS(FILE* out=stderr) : out(out) {}
void handle(wreport::Bulletin& b) override
{
}
};
struct PrintTables : public BulletinHeadHandler
{
FILE* out;
bool header_printed;
PrintTables(FILE* out=stderr) : out(out), header_printed(false) {}
void handle(wreport::Bulletin& b) override
{
if (const BufrBulletin* m = dynamic_cast<const BufrBulletin*>(&b))
{
if (!header_printed)
{
fprintf(out,
"%-*s\tOffset\tCentre\tSubc.\tMaster\tLocal\n", (
int)b.
fname.size(),
"Filename");
header_printed = true;
}
fprintf(out, "%s\t%zd\t%d\t%d\t%d\t%d\n",
m->originating_centre, m->originating_subcentre,
m->master_table_version_number, m->master_table_version_number_local);
}
else if (const CrexBulletin* m = dynamic_cast<const CrexBulletin*>(&b))
{
if (!header_printed)
{
fprintf(out, "Filename\tOffset\tMaster\tEdition\tTable\n");
header_printed = true;
}
fprintf(out, "%s\t%zd\t%d\t%d\t%d\n",
m->master_table_number, m->edition_number, m->master_table_version_number);
}
else
{
fprintf(out, "%s\t%zd\tunknown message type\n",
}
}
};
struct PrintFeatures : public BulletinHeadHandler
{
FILE* out;
PrintFeatures(FILE* out=stderr) : out(out) {}
void handle(wreport::Bulletin& b) override
{
scan.run();
bool first = true;
for (const auto& f: scan.features)
if (first)
{
fprintf(out, "%s", f.c_str());
first = false;
} else
fprintf(out, ",%s", f.c_str());
fprintf(out, "\n");
}
};
static std::unique_ptr< BufrBulletin > decode_verbose(const std::string &raw, FILE *out, const char *fname="(memory)", size_t offset=0)
Parse an encoded BUFR message, printing decoding information.
Storage for the decoded data of a BUFR or CREX message.
Definition bulletin.h:30
void print_structured(FILE *out) const
Dump the contents of this bulletin, in a more structured way.
std::vector< Varcode > datadesc
Parsed data descriptor section.
Definition bulletin.h:119
off_t offset
File offset of the start of the message.
Definition bulletin.h:48
Tables tables
Varcode and opcode tables used for encoding or decoding.
Definition bulletin.h:116
std::string fname
Input file name (optional).
Definition bulletin.h:39
void print_datadesc(FILE *out, unsigned indent=0) const
Pretty-print the data descriptor section.
void print(FILE *out) const
Dump the contents of this bulletin.
namespace {
struct PrintVars : public BulletinFullHandler
{
FILE* out;
const std::vector<wreport::Varcode>& codes;
PrintVars(const std::vector<wreport::Varcode>& codes, FILE* out=stdout)
: out(out), codes(codes) {}
{
for (size_t i = 0; i < subset.size(); ++i)
if (subset[i].code() == code)
return &subset[i];
return NULL;
}
void handle(wreport::Bulletin& b) override
{
for (
size_t sset = 0; sset < b.
subsets.size(); ++sset)
{
fprintf(out,
"%s:%zu:", b.
fname.c_str(), sset + 1);
for (size_t i = 0; i < codes.size(); ++i)
{
const Var* var = find_varcode(b.
subsets[sset], codes[i]);
if (var)
{
string formatted = var->
format();
fprintf(out, "\t%s", formatted.c_str());
}
}
putc('\n', out);
}
}
};
}
std::vector< Subset > subsets
Decoded variables.
Definition bulletin.h:122
A physical variable.
Definition var.h:25
std::string format(const char *ifundef="") const
Create a formatted string representation of the variable value.
uint16_t Varcode
Holds the WMO variable code of a variable.
Definition fwd.h:12