Formatting

This commit is contained in:
shahramn 2024-07-13 13:10:08 +01:00
parent b8f157f105
commit 56a7dc39a1
7 changed files with 146 additions and 119 deletions

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -13,11 +12,12 @@
#include "step.h"
#include "step_utilities.h"
grib_accessor_class_optimal_step_units_t _grib_accessor_class_optimal_step_units{"optimal_step_units"};
grib_accessor_class_optimal_step_units_t _grib_accessor_class_optimal_step_units{ "optimal_step_units" };
grib_accessor_class* grib_accessor_class_optimal_step_units = &_grib_accessor_class_optimal_step_units;
void grib_accessor_class_optimal_step_units_t::init(grib_accessor* a, const long l, grib_arguments* c){
void grib_accessor_class_optimal_step_units_t::init(grib_accessor* a, const long l, grib_arguments* c)
{
grib_accessor_class_gen_t::init(a, l, c);
grib_accessor_optimal_step_units_t* self = (grib_accessor_optimal_step_units_t*)a;
grib_handle* hand = grib_handle_of_accessor(a);
@ -27,72 +27,78 @@ void grib_accessor_class_optimal_step_units_t::init(grib_accessor* a, const long
self->forecast_time_unit = grib_arguments_get_name(hand, c, n++);
self->time_range_value = grib_arguments_get_name(hand, c, n++);
self->time_range_unit = grib_arguments_get_name(hand, c, n++);
a->length = 0;
self->overwriteStepUnits = eccodes::Unit{eccodes::Unit::Value::MISSING}.value<long>();
a->length = 0;
self->overwriteStepUnits = eccodes::Unit{ eccodes::Unit::Value::MISSING }.value<long>();
}
void grib_accessor_class_optimal_step_units_t::dump(grib_accessor* a, grib_dumper* dumper){
void grib_accessor_class_optimal_step_units_t::dump(grib_accessor* a, grib_dumper* dumper)
{
grib_dump_string(dumper, a, NULL);
}
size_t grib_accessor_class_optimal_step_units_t::string_length(grib_accessor* a){
size_t grib_accessor_class_optimal_step_units_t::string_length(grib_accessor* a)
{
return 255;
}
int grib_accessor_class_optimal_step_units_t::pack_expression(grib_accessor* a, grib_expression* e){
const char* cval = NULL;
int ret = 0;
long lval = 0;
size_t len = 1;
grib_handle* hand = grib_handle_of_accessor(a);
int grib_accessor_class_optimal_step_units_t::pack_expression(grib_accessor* a, grib_expression* e)
{
const char* cval = NULL;
int ret = 0;
long lval = 0;
size_t len = 1;
grib_handle* hand = grib_handle_of_accessor(a);
const char* cclass_name = a->cclass->name;
if (strcmp(e->cclass->name, "long") == 0) {
grib_expression_evaluate_long(hand, e, &lval); /* TODO: check return value */
ret = a->pack_long(&lval, &len); }
grib_expression_evaluate_long(hand, e, &lval); // TODO: check return value
ret = a->pack_long(&lval, &len);
}
else {
char tmp[1024];
len = sizeof(tmp);
cval = grib_expression_evaluate_string(hand, e, tmp, &len, &ret);
if (ret != GRIB_SUCCESS) {
grib_context_log(a->context, GRIB_LOG_ERROR,
"%s.%s: Unable to evaluate string %s to be set in %s",
cclass_name, __func__, grib_expression_get_name(e), a->name);
"%s.%s: Unable to evaluate string %s to be set in %s",
cclass_name, __func__, grib_expression_get_name(e), a->name);
return ret;
}
len = strlen(cval) + 1;
//if (hand->context->debug)
// printf("ECCODES DEBUG grib_accessor_class_codetable::pack_expression %s %s\n", a->name, cval);
ret = a->pack_string(cval, &len); }
// if (hand->context->debug)
// printf("ECCODES DEBUG grib_accessor_class_codetable::pack_expression %s %s\n", a->name, cval);
ret = a->pack_string(cval, &len);
}
return ret;
}
int grib_accessor_class_optimal_step_units_t::pack_long(grib_accessor* a, const long* val, size_t* len){
int grib_accessor_class_optimal_step_units_t::pack_long(grib_accessor* a, const long* val, size_t* len)
{
grib_handle* h = grib_handle_of_accessor(a);
grib_accessor_optimal_step_units_t* self = (grib_accessor_optimal_step_units_t*)a;
long start_step = 0;
long start_step = 0;
long start_step_unit = 0;
long end_step = 0;
long end_step_unit = 0;
long end_step = 0;
long end_step_unit = 0;
int ret;
auto supported_units = eccodes::Unit::list_supported_units();
try {
eccodes::Unit unit{*val}; // throws if not supported
eccodes::Unit unit{ *val }; // throws if not supported
auto iter = std::find(supported_units.begin(), supported_units.end(), unit);
if (iter == supported_units.end()) {
throw std::runtime_error{"eccodes::Unit not supported"};
throw std::runtime_error{ "eccodes::Unit not supported" };
}
}
catch (std::exception& e) {
std::string supported_units_str;
for (auto& u : supported_units)
supported_units_str += eccodes::Unit{u}.value<std::string>() + ",";
supported_units_str += eccodes::Unit{ u }.value<std::string>() + ",";
supported_units_str.pop_back();
std::string msg = std::string{"Invalid unit: "} + std::to_string(*val) + " (" + e.what() + ")" +
". Available units are: " + supported_units_str;
std::string msg = std::string{ "Invalid unit: " } + std::to_string(*val) + " (" + e.what() + ")" +
". Available units are: " + supported_units_str;
grib_context_log(a->context, GRIB_LOG_ERROR, "%s", msg.c_str());
return GRIB_INVALID_ARGUMENT;
}
@ -115,9 +121,9 @@ int grib_accessor_class_optimal_step_units_t::pack_long(grib_accessor* a, const
return ret;
try {
eccodes::Step start{start_step, start_step_unit};
eccodes::Step start{ start_step, start_step_unit };
start.set_unit(*val);
eccodes::Step end{end_step, end_step_unit};
eccodes::Step end{ end_step, end_step_unit };
end.set_unit(*val);
if ((ret = grib_set_long_internal(h, "startStepUnit", start.unit().value<long>())) != GRIB_SUCCESS)
@ -130,7 +136,7 @@ int grib_accessor_class_optimal_step_units_t::pack_long(grib_accessor* a, const
return ret;
}
catch (std::exception& e) {
std::string msg = std::string{"Failed to convert steps to: "} + std::to_string(*val) + " (" + e.what() + ")";
std::string msg = std::string{ "Failed to convert steps to: " } + std::to_string(*val) + " (" + e.what() + ")";
grib_context_log(a->context, GRIB_LOG_ERROR, "%s", msg.c_str());
return GRIB_INTERNAL_ERROR;
}
@ -144,17 +150,17 @@ int grib_accessor_class_optimal_step_units_t::unpack_long(grib_accessor* a, long
grib_handle* h = grib_handle_of_accessor(a);
try {
if (eccodes::Unit{self->overwriteStepUnits} != eccodes::Unit{eccodes::Unit::Value::MISSING}) {
if (eccodes::Unit{ self->overwriteStepUnits } != eccodes::Unit{ eccodes::Unit::Value::MISSING }) {
*val = self->overwriteStepUnits;
return GRIB_SUCCESS;
}
auto forecast_time_opt = get_step(h, self->forecast_time_value, self->forecast_time_unit);
auto time_range_opt = get_step(h, self->time_range_value, self->time_range_unit);
auto time_range_opt = get_step(h, self->time_range_value, self->time_range_unit);
if (forecast_time_opt && time_range_opt) {
auto [step_a, step_b] = find_common_units(forecast_time_opt.value().optimize_unit(),
(forecast_time_opt.value() + time_range_opt.value()).optimize_unit());
(forecast_time_opt.value() + time_range_opt.value()).optimize_unit());
*val = step_a.unit().value<long>();
}
else if (forecast_time_opt && !time_range_opt) {
@ -164,7 +170,7 @@ int grib_accessor_class_optimal_step_units_t::unpack_long(grib_accessor* a, long
*val = time_range_opt.value().optimize_unit().unit().value<long>();
}
else if (!forecast_time_opt && !time_range_opt) {
*val = eccodes::Unit{eccodes::Unit::Value::HOUR}.value<long>();
*val = eccodes::Unit{ eccodes::Unit::Value::HOUR }.value<long>();
}
}
catch (std::exception& e) {
@ -175,16 +181,17 @@ int grib_accessor_class_optimal_step_units_t::unpack_long(grib_accessor* a, long
return GRIB_SUCCESS;
}
int grib_accessor_class_optimal_step_units_t::pack_string(grib_accessor* a, const char* val, size_t* len){
int grib_accessor_class_optimal_step_units_t::pack_string(grib_accessor* a, const char* val, size_t* len)
{
try {
long unit = eccodes::Unit{val}.value<long>();
long unit = eccodes::Unit{ val }.value<long>();
pack_long(a, &unit, len);
}
catch (std::exception& e) {
auto supported_units = eccodes::Unit::list_supported_units();
std::string supported_units_str;
for (auto& u : supported_units)
supported_units_str += eccodes::Unit{u}.value<std::string>() + ",";
supported_units_str += eccodes::Unit{ u }.value<std::string>() + ",";
supported_units_str.pop_back();
std::string msg = "Invalid unit: " + std::string(val) + " (" + e.what() + ")" + ". Available units are: " + supported_units_str;
@ -195,22 +202,25 @@ int grib_accessor_class_optimal_step_units_t::pack_string(grib_accessor* a, cons
return GRIB_SUCCESS;
}
int grib_accessor_class_optimal_step_units_t::unpack_string(grib_accessor* a, char* val, size_t* len){
int ret = 0;
long unit = 0;
int grib_accessor_class_optimal_step_units_t::unpack_string(grib_accessor* a, char* val, size_t* len)
{
int ret = 0;
long unit = 0;
size_t unit_len = 0;
if ((ret = unpack_long(a, &unit, &unit_len)) != GRIB_SUCCESS)
return ret;
*len = snprintf(val, *len, "%s", eccodes::Unit{unit}.value<std::string>().c_str());
*len = snprintf(val, *len, "%s", eccodes::Unit{ unit }.value<std::string>().c_str());
return GRIB_SUCCESS;
}
// Step units are never missing
// If the user does not specify a step unit, we default to hours
int grib_accessor_class_optimal_step_units_t::is_missing(grib_accessor* a){
int grib_accessor_class_optimal_step_units_t::is_missing(grib_accessor* a)
{
return 0;
}
int grib_accessor_class_optimal_step_units_t::get_native_type(grib_accessor* a){
int grib_accessor_class_optimal_step_units_t::get_native_type(grib_accessor* a)
{
return GRIB_TYPE_LONG;
}

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -11,13 +10,14 @@
#include "grib_accessor_class_packing_type.h"
grib_accessor_class_packing_type_t _grib_accessor_class_packing_type{"packing_type"};
grib_accessor_class_packing_type_t _grib_accessor_class_packing_type{ "packing_type" };
grib_accessor_class* grib_accessor_class_packing_type = &_grib_accessor_class_packing_type;
void grib_accessor_class_packing_type_t::init(grib_accessor* a, const long l, grib_arguments* args){
void grib_accessor_class_packing_type_t::init(grib_accessor* a, const long l, grib_arguments* args)
{
grib_accessor_class_gen_t::init(a, l, args);
int n = 0;
int n = 0;
grib_accessor_packing_type_t* self = (grib_accessor_packing_type_t*)a;
self->values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
self->packing_type = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
@ -25,21 +25,25 @@ void grib_accessor_class_packing_type_t::init(grib_accessor* a, const long l, gr
a->length = 0;
}
size_t grib_accessor_class_packing_type_t::string_length(grib_accessor* a){
size_t grib_accessor_class_packing_type_t::string_length(grib_accessor* a)
{
return 1024;
}
int grib_accessor_class_packing_type_t::get_native_type(grib_accessor* a){
int grib_accessor_class_packing_type_t::get_native_type(grib_accessor* a)
{
return GRIB_TYPE_STRING;
}
int grib_accessor_class_packing_type_t::pack_string(grib_accessor*a, const char* sval, size_t* len){
int grib_accessor_class_packing_type_t::pack_string(grib_accessor* a, const char* sval, size_t* len)
{
grib_accessor_packing_type_t* self = (grib_accessor_packing_type_t*)a;
grib_handle* h = grib_handle_of_accessor(a);
double* values = NULL;
grib_handle* h = grib_handle_of_accessor(a);
double* values = NULL;
grib_context* c = a->context;
size_t size = 0;
int err = 0;
size_t size = 0;
int err = 0;
if ((err = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS)
return err;
@ -66,9 +70,10 @@ int grib_accessor_class_packing_type_t::pack_string(grib_accessor*a, const char*
return GRIB_SUCCESS;
}
int grib_accessor_class_packing_type_t::unpack_string(grib_accessor* a, char* val, size_t* len){
int grib_accessor_class_packing_type_t::unpack_string(grib_accessor* a, char* val, size_t* len)
{
grib_accessor_packing_type_t* self = (grib_accessor_packing_type_t*)a;
grib_handle* h = grib_handle_of_accessor(a);
grib_handle* h = grib_handle_of_accessor(a);
return grib_get_string(h, self->packing_type, val, len);
}

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -12,7 +11,7 @@
#include "grib_accessor_class_second_order_bits_per_value.h"
#include "grib_scaling.h"
grib_accessor_class_second_order_bits_per_value_t _grib_accessor_class_second_order_bits_per_value{"second_order_bits_per_value"};
grib_accessor_class_second_order_bits_per_value_t _grib_accessor_class_second_order_bits_per_value{ "second_order_bits_per_value" };
grib_accessor_class* grib_accessor_class_second_order_bits_per_value = &_grib_accessor_class_second_order_bits_per_value;
@ -35,10 +34,11 @@ static const size_t nbits[64] = {
0x1000000000000000, 0x2000000000000000, 0x4000000000000000, 0x8000000000000000
};
static int number_of_bits(size_t x, long* result){
static int number_of_bits(size_t x, long* result)
{
const size_t* n = nbits;
const int count = sizeof(nbits) / sizeof(nbits[0]);
*result = 0;
*result = 0;
while (x >= *n) {
n++;
(*result)++;
@ -49,27 +49,30 @@ static int number_of_bits(size_t x, long* result){
return GRIB_SUCCESS;
}
void grib_accessor_class_second_order_bits_per_value_t::init(grib_accessor* a, const long l, grib_arguments* c){
void grib_accessor_class_second_order_bits_per_value_t::init(grib_accessor* a, const long l, grib_arguments* c)
{
grib_accessor_class_long_t::init(a, l, c);
int n = 0;
int n = 0;
grib_accessor_second_order_bits_per_value_t* self = (grib_accessor_second_order_bits_per_value_t*)a;
self->values = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++);
self->binaryScaleFactor = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++);
self->decimalScaleFactor = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++);
self->bitsPerValue = 0;
self->values = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++);
self->binaryScaleFactor = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++);
self->decimalScaleFactor = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++);
self->bitsPerValue = 0;
a->length = 0;
}
int grib_accessor_class_second_order_bits_per_value_t::pack_long(grib_accessor* a, const long* val, size_t* len){
int grib_accessor_class_second_order_bits_per_value_t::pack_long(grib_accessor* a, const long* val, size_t* len)
{
grib_accessor_second_order_bits_per_value_t* self = (grib_accessor_second_order_bits_per_value_t*)a;
self->bitsPerValue = (long)*val;
*len = 1;
self->bitsPerValue = (long)*val;
*len = 1;
return 0;
return GRIB_SUCCESS;
}
int grib_accessor_class_second_order_bits_per_value_t::unpack_long(grib_accessor* a, long* val, size_t* len){
int grib_accessor_class_second_order_bits_per_value_t::unpack_long(grib_accessor* a, long* val, size_t* len)
{
int ret = GRIB_SUCCESS;
size_t size = 0;
size_t i;

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -11,30 +10,33 @@
#include "grib_accessor_class_select_step_template.h"
grib_accessor_class_select_step_template_t _grib_accessor_class_select_step_template{"select_step_template"};
grib_accessor_class_select_step_template_t _grib_accessor_class_select_step_template{ "select_step_template" };
grib_accessor_class* grib_accessor_class_select_step_template = &_grib_accessor_class_select_step_template;
void grib_accessor_class_select_step_template_t::init(grib_accessor* a, const long l, grib_arguments* c){
void grib_accessor_class_select_step_template_t::init(grib_accessor* a, const long l, grib_arguments* c)
{
grib_accessor_class_unsigned_t::init(a, l, c);
grib_accessor_select_step_template_t* self = (grib_accessor_select_step_template_t*)a;
grib_handle* hand = grib_handle_of_accessor(a);
int n = 0;
self->productDefinitionTemplateNumber = grib_arguments_get_name(hand, c, n++);
self->instant = grib_arguments_get_long(hand, c, n++);
self->instant = grib_arguments_get_long(hand, c, n++);
}
int grib_accessor_class_select_step_template_t::unpack_long(grib_accessor* a, long* val, size_t* len){
int grib_accessor_class_select_step_template_t::unpack_long(grib_accessor* a, long* val, size_t* len)
{
*val = 1;
return GRIB_SUCCESS;
}
int grib_accessor_class_select_step_template_t::pack_long(grib_accessor* a, const long* val, size_t* len){
int grib_accessor_class_select_step_template_t::pack_long(grib_accessor* a, const long* val, size_t* len)
{
grib_accessor_select_step_template_t* self = (grib_accessor_select_step_template_t*)a;
grib_handle* hand = grib_handle_of_accessor(a);
long productDefinitionTemplateNumber = 0;
long productDefinitionTemplateNumberNew = 0;
grib_handle* hand = grib_handle_of_accessor(a);
long productDefinitionTemplateNumber = 0;
long productDefinitionTemplateNumberNew = 0;
grib_get_long(hand, self->productDefinitionTemplateNumber, &productDefinitionTemplateNumber);
@ -64,28 +66,28 @@ int grib_accessor_class_select_step_template_t::pack_long(grib_accessor* a, cons
case 14:
productDefinitionTemplateNumberNew = 4;
break;
case 42: // DET chemical
case 42: // DET chemical
productDefinitionTemplateNumberNew = 40;
break;
case 43: // ENS chemical
case 43: // ENS chemical
productDefinitionTemplateNumberNew = 41;
break;
case 46: // DET aerosol
productDefinitionTemplateNumberNew = 48; // 44 is deprecated
case 46: // DET aerosol
productDefinitionTemplateNumberNew = 48; // 44 is deprecated
break;
case 47: // ENS aerosol
case 47: // ENS aerosol
productDefinitionTemplateNumberNew = 45;
break;
case 67: // DET chemical distrib func
case 67: // DET chemical distrib func
productDefinitionTemplateNumberNew = 57;
break;
case 68: // ENS chemical distrib func
case 68: // ENS chemical distrib func
productDefinitionTemplateNumberNew = 58;
break;
case 72: // DET post-processing
case 72: // DET post-processing
productDefinitionTemplateNumberNew = 70;
break;
case 73: // ENS post-processing */
case 73: // ENS post-processing */
productDefinitionTemplateNumberNew = 71;
break;
case 0:
@ -128,25 +130,25 @@ int grib_accessor_class_select_step_template_t::pack_long(grib_accessor* a, cons
case 6:
productDefinitionTemplateNumberNew = 10;
break;
case 40: // DET chemical
case 40: // DET chemical
productDefinitionTemplateNumberNew = 42;
break;
case 41: // ENS chemical
case 41: // ENS chemical
productDefinitionTemplateNumberNew = 43;
break;
case 45: // ENS aerosol
productDefinitionTemplateNumberNew = 85; // 47 is deprecated
case 45: // ENS aerosol
productDefinitionTemplateNumberNew = 85; // 47 is deprecated
break;
case 57: // DET chemical distrib func
case 57: // DET chemical distrib func
productDefinitionTemplateNumberNew = 67;
break;
case 58: // ENS chemical distrib func
case 58: // ENS chemical distrib func
productDefinitionTemplateNumberNew = 68;
break;
case 70: // DET post-processing
case 70: // DET post-processing
productDefinitionTemplateNumberNew = 72;
break;
case 71: // ENS post-processing
case 71: // ENS post-processing
productDefinitionTemplateNumberNew = 73;
break;
case 7:
@ -172,7 +174,8 @@ int grib_accessor_class_select_step_template_t::pack_long(grib_accessor* a, cons
return GRIB_SUCCESS;
}
int grib_accessor_class_select_step_template_t::value_count(grib_accessor* a, long* c){
int grib_accessor_class_select_step_template_t::value_count(grib_accessor* a, long* c)
{
*c = 1;
return 0;
}

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -12,11 +11,12 @@
#include "grib_accessor_class_simple_packing_error.h"
#include "grib_scaling.h"
grib_accessor_class_simple_packing_error_t _grib_accessor_class_simple_packing_error{"simple_packing_error"};
grib_accessor_class_simple_packing_error_t _grib_accessor_class_simple_packing_error{ "simple_packing_error" };
grib_accessor_class* grib_accessor_class_simple_packing_error = &_grib_accessor_class_simple_packing_error;
void grib_accessor_class_simple_packing_error_t::init(grib_accessor* a, const long l, grib_arguments* c){
void grib_accessor_class_simple_packing_error_t::init(grib_accessor* a, const long l, grib_arguments* c)
{
grib_accessor_class_double_t::init(a, l, c);
grib_accessor_simple_packing_error_t* self = (grib_accessor_simple_packing_error_t*)a;
int n = 0;
@ -32,7 +32,8 @@ void grib_accessor_class_simple_packing_error_t::init(grib_accessor* a, const lo
a->length = 0;
}
int grib_accessor_class_simple_packing_error_t::unpack_double(grib_accessor* a, double* val, size_t* len){
int grib_accessor_class_simple_packing_error_t::unpack_double(grib_accessor* a, double* val, size_t* len)
{
grib_accessor_simple_packing_error_t* self = (grib_accessor_simple_packing_error_t*)a;
int ret = 0;
@ -40,7 +41,7 @@ int grib_accessor_class_simple_packing_error_t::unpack_double(grib_accessor* a,
long bitsPerValue = 0;
long decimalScaleFactor = 0;
double referenceValue = 0;
grib_handle* h = grib_handle_of_accessor(a);
grib_handle* h = grib_handle_of_accessor(a);
if ((ret = grib_get_long_internal(h, self->binaryScaleFactor, &binaryScaleFactor)) != GRIB_SUCCESS)
return ret;

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -11,14 +10,15 @@
#include "grib_accessor_class_spectral_truncation.h"
grib_accessor_class_spectral_truncation_t _grib_accessor_class_spectral_truncation{"spectral_truncation"};
grib_accessor_class_spectral_truncation_t _grib_accessor_class_spectral_truncation{ "spectral_truncation" };
grib_accessor_class* grib_accessor_class_spectral_truncation = &_grib_accessor_class_spectral_truncation;
void grib_accessor_class_spectral_truncation_t::init(grib_accessor* a, const long l, grib_arguments* c){
void grib_accessor_class_spectral_truncation_t::init(grib_accessor* a, const long l, grib_arguments* c)
{
grib_accessor_class_long_t::init(a, l, c);
grib_accessor_spectral_truncation_t* self = (grib_accessor_spectral_truncation_t*)a;
int n = 0;
int n = 0;
self->J = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++);
self->K = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++);
@ -28,9 +28,10 @@ void grib_accessor_class_spectral_truncation_t::init(grib_accessor* a, const lon
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
}
int grib_accessor_class_spectral_truncation_t::unpack_long(grib_accessor* a, long* val, size_t* len){
int grib_accessor_class_spectral_truncation_t::unpack_long(grib_accessor* a, long* val, size_t* len)
{
grib_accessor_spectral_truncation_t* self = (grib_accessor_spectral_truncation_t*)a;
int ret = 0;
int ret = GRIB_SUCCESS;
long J, K, M, T, Tc;

View File

@ -1,4 +1,3 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -11,18 +10,20 @@
#include "grib_accessor_class_sprintf.h"
grib_accessor_class_sprintf_t _grib_accessor_class_sprintf{"sprintf"};
grib_accessor_class_sprintf_t _grib_accessor_class_sprintf{ "sprintf" };
grib_accessor_class* grib_accessor_class_sprintf = &_grib_accessor_class_sprintf;
void grib_accessor_class_sprintf_t::init(grib_accessor* a, const long l, grib_arguments* c){
void grib_accessor_class_sprintf_t::init(grib_accessor* a, const long l, grib_arguments* c)
{
grib_accessor_class_ascii_t::init(a, l, c);
grib_accessor_sprintf_t* self = (grib_accessor_sprintf_t*)a;
self->args = c;
self->args = c;
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
}
int grib_accessor_class_sprintf_t::unpack_string(grib_accessor* a, char* val, size_t* len){
int grib_accessor_class_sprintf_t::unpack_string(grib_accessor* a, char* val, size_t* len)
{
grib_accessor_sprintf_t* self = (grib_accessor_sprintf_t*)a;
char result[1024];
char tempBuffer[2048];
@ -61,7 +62,8 @@ int grib_accessor_class_sprintf_t::unpack_string(grib_accessor* a, char* val, si
if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), tempname, &ires)) != GRIB_SUCCESS)
return ret;
/* Bug GRIB-56: Check to see if the key is missing */
is_missing = grib_is_missing(grib_handle_of_accessor(a), tempname, &ret); if (ret != GRIB_SUCCESS)
is_missing = grib_is_missing(grib_handle_of_accessor(a), tempname, &ret);
if (ret != GRIB_SUCCESS)
return ret;
if (is_missing) {
snprintf(tempBuffer, sizeof(tempBuffer), "%sMISSING", result);
@ -117,11 +119,13 @@ int grib_accessor_class_sprintf_t::unpack_string(grib_accessor* a, char* val, si
return GRIB_SUCCESS;
}
int grib_accessor_class_sprintf_t::value_count(grib_accessor* a, long* count){
int grib_accessor_class_sprintf_t::value_count(grib_accessor* a, long* count)
{
*count = 1;
return 0;
}
size_t grib_accessor_class_sprintf_t::string_length(grib_accessor* a){
size_t grib_accessor_class_sprintf_t::string_length(grib_accessor* a)
{
return 1024;
}