Work on eckit_geo

This commit is contained in:
Pedro Maciel 2023-10-27 16:50:04 +01:00
parent 080461249d
commit 3faa17f88a
2 changed files with 159 additions and 141 deletions

View File

@ -4,15 +4,14 @@ AccessModifierOffset: -4
AlignAfterOpenBracket: Align AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: false AlignConsecutiveDeclarations: false
AlignConsecutiveMacros: true
AlignEscapedNewlines: Left AlignEscapedNewlines: Left
AlignOperands: true AlignOperands: true
AlignTrailingComments: true AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: true AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: true AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None AlwaysBreakAfterReturnType: None
@ -21,14 +20,14 @@ AlwaysBreakTemplateDeclarations: true
BinPackArguments: true BinPackArguments: true
BinPackParameters: true BinPackParameters: true
BraceWrapping: BraceWrapping:
AfterClass: true AfterClass: false
AfterControlStatement: false AfterControlStatement: false
AfterEnum: true AfterEnum: true
AfterFunction: true AfterFunction: false
AfterNamespace: true AfterNamespace: false
AfterObjCDeclaration: false AfterObjCDeclaration: false
AfterStruct: true AfterStruct: false
AfterUnion: true AfterUnion: false
BeforeCatch: true BeforeCatch: true
BeforeElse: true BeforeElse: true
IndentBraces: false IndentBraces: false
@ -43,13 +42,13 @@ BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: AfterColon BreakConstructorInitializers: AfterColon
BreakAfterJavaFieldAnnotations: false BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true BreakStringLiterals: true
ColumnLimit: 0 ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:' CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4 ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4 ContinuationIndentWidth: 4
Cpp11BracedListStyle: false Cpp11BracedListStyle: true
DerivePointerAlignment: false DerivePointerAlignment: false
DisableFormat: false DisableFormat: false
ExperimentalAutoDetectBinPacking: false ExperimentalAutoDetectBinPacking: false
@ -67,12 +66,11 @@ IncludeCategories:
Priority: 3 Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$' IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true IndentCaseLabels: true
IndentPPDirectives: BeforeHash IndentWidth: 4
IndentWidth: 4
IndentWrappedFunctionNames: false IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave JavaScriptQuotes: Leave
JavaScriptWrapImports: true JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: '' MacroBlockBegin: ''
MacroBlockEnd: '' MacroBlockEnd: ''
MaxEmptyLinesToKeep: 2 MaxEmptyLinesToKeep: 2
@ -89,7 +87,7 @@ PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200 PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left PointerAlignment: Left
ReflowComments: true ReflowComments: true
SortIncludes: false SortIncludes: true
SortUsingDeclarations: true SortUsingDeclarations: true
SpaceAfterCStyleCast: false SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true SpaceAfterTemplateKeyword: true

View File

@ -15,102 +15,105 @@ static grib_values* get_key_values(grib_runtime_options* options, grib_handle* h
grib_option grib_options[] = { grib_option grib_options[] = {
/* {id, args, help}, on, command_line, value */ /* {id, args, help}, on, command_line, value */
{ "S", 0, 0, 1, 0, 0 }, {"S", nullptr, nullptr, 1, 0, nullptr},
{ "M", 0, 0, 0, 1, 0 }, {"M", nullptr, nullptr, 0, 1, nullptr},
{ "m:", "missingValue", {"m:", "missingValue",
"\n\t\tThe missing value is given through this option." "\n\t\tThe missing value is given through this option."
"\n\t\tAny string is allowed and it is printed in place of the missing" "\n\t\tAny string is allowed and it is printed in place of the missing"
"\n\t\tvalues. Default is to skip the missing values.\n", "\n\t\tvalues. Default is to skip the missing values.\n",
0, 1, 0 }, 0, 1, nullptr},
{ "p:", 0, 0, 0, 1, 0 }, {"p:", nullptr, nullptr, 0, 1, nullptr},
{ "F:", "format", "\n\t\tC style format for data values. Default is \"%.10e\"\n", 0, 1, 0 }, {"F:", "format", "\n\t\tC style format for data values. Default is \"%.10e\"\n", 0, 1, nullptr},
{ "L:", "format", "\n\t\tC style format for latitudes/longitudes. Default is \"%9.3f%9.3f\"\n", 0, 1, 0 }, {"L:", "format", "\n\t\tC style format for latitudes/longitudes. Default is \"%9.3f%9.3f\"\n", 0, 1, nullptr},
{ "w:", 0, 0, 0, 1, 0 }, {"w:", nullptr, nullptr, 0, 1, nullptr},
{ "s:", 0, 0, 0, 1, 0 }, {"s:", nullptr, nullptr, 0, 1, nullptr},
{ "f", 0, 0, 0, 1, 0 }, {"f", nullptr, nullptr, 0, 1, nullptr},
{ "G", 0, 0, 0, 1, 0 }, {"G", nullptr, nullptr, 0, 1, nullptr},
{ "7", 0, 0, 0, 1, 0 }, {"7", nullptr, nullptr, 0, 1, nullptr},
{ "X:", 0, 0, 0, 1, 0 }, {"X:", nullptr, nullptr, 0, 1, nullptr},
{ "V", 0, 0, 0, 1, 0 } {"V", nullptr, nullptr, 0, 1, nullptr}};
};
const char* tool_description = const char* tool_description =
"Print a latitude, longitude, data values list.\n" "Print a latitude, longitude, data values list.\n"
"\tNote: Rotated grids are first unrotated"; "\tNote: Rotated grids are first unrotated";
const char* tool_name = "grib_get_data"; const char* tool_name = "grib_get_data_geo";
const char* tool_online_doc = "https://confluence.ecmwf.int/display/ECC/grib_get_data"; const char* tool_online_doc = "";
const char* tool_usage = "[options] grib_file grib_file ..."; const char* tool_usage = "[options] grib_file grib_file ...";
extern FILE* dump_file; extern FILE* dump_file;
int grib_options_count = sizeof(grib_options) / sizeof(grib_option); int grib_options_count = sizeof(grib_options) / sizeof(grib_option);
int main(int argc, char* argv[]) int main(int argc, char* argv[]) {
{
return grib_tool(argc, argv); return grib_tool(argc, argv);
} }
int grib_tool_before_getopt(grib_runtime_options* options) int grib_tool_before_getopt(grib_runtime_options* options) {
{
return 0; return 0;
} }
int grib_tool_init(grib_runtime_options* options) int grib_tool_init(grib_runtime_options* options) {
{
return 0; return 0;
} }
int grib_tool_new_filename_action(grib_runtime_options* options, const char* file) int grib_tool_new_filename_action(grib_runtime_options* options, const char* file) {
{
return 0; return 0;
} }
int grib_tool_new_file_action(grib_runtime_options* options, grib_tools_file* file) int grib_tool_new_file_action(grib_runtime_options* options, grib_tools_file* file) {
{
exit_if_input_is_directory(tool_name, file->name); exit_if_input_is_directory(tool_name, file->name);
return 0; return 0;
} }
int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h) int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h) {
{
int err = 0; int err = 0;
double missingValue = 9999; double missingValue = 9999;
int skip_missing = 1; int skip_missing = 1;
char* missing_string = NULL; char* missing_string = nullptr;
int i = 0; int i = 0;
grib_values* values = NULL; grib_values* values = nullptr;
grib_iterator* iter = NULL; grib_iterator* iter = nullptr;
char format_values[32] = {0,}; char format_values[32] = {
char format_latlons[32] = {0,}; 0,
};
char format_latlons[32] = {
0,
};
const char* default_format_values = "%.10e"; const char* default_format_values = "%.10e";
const char* default_format_latlons = "%9.3f%9.3f"; const char* default_format_latlons = "%9.3f%9.3f";
int print_keys = grib_options_on("p:"); int print_keys = grib_options_on("p:");
long numberOfPoints = 0; long numberOfPoints = 0;
long bitmapPresent = 0; long bitmapPresent = 0;
long* bitmap = NULL; /* bitmap array */ long* bitmap = nullptr; /* bitmap array */
size_t bmp_len = 0; size_t bmp_len = 0;
double *data_values = 0, *lats = 0, *lons = 0; double* data_values = nullptr;
int n = 0; double* lats = nullptr;
size_t size = 0, num_bytes = 0; double* lons = nullptr;
long hasMissingValues = 0; int n = 0;
size_t size = 0;
size_t num_bytes = 0;
long hasMissingValues = 0;
if (!options->skip) { if (options->skip == 0) {
if (options->set_values_count != 0) if (options->set_values_count != 0) {
err = grib_set_values(h, options->set_values, options->set_values_count); err = grib_set_values(h, options->set_values, options->set_values_count);
if (err != GRIB_SUCCESS && options->fail) }
if (err != GRIB_SUCCESS && (options->fail != 0)) {
exit(err); exit(err);
}
} }
if (grib_options_on("m:")) { if (grib_options_on("m:") != 0) {
/* User wants to see missing values */ /* User wants to see missing values */
char* theEnd = NULL; char* theEnd = nullptr;
double mval = 0; double mval = 0;
char* kmiss = grib_options_get_option("m:"); char* kmiss = grib_options_get_option("m:");
char* p = kmiss; char* p = kmiss;
skip_missing = 0; skip_missing = 0;
while (*p != ':' && *p != '\0') while (*p != ':' && *p != '\0') {
p++; p++;
}
if (*p == ':' && *(p + 1) != '\0') { if (*p == ':' && *(p + 1) != '\0') {
*p = '\0'; *p = '\0';
missing_string = strdup(p + 1); missing_string = strdup(p + 1);
@ -119,13 +122,14 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
missing_string = strdup(kmiss); missing_string = strdup(kmiss);
} }
mval = strtod(kmiss, &theEnd); mval = strtod(kmiss, &theEnd);
if (kmiss != theEnd && *theEnd == '\0') if (kmiss != theEnd && *theEnd == '\0') {
missingValue = mval; missingValue = mval;
}
grib_set_double(h, "missingValue", missingValue); grib_set_double(h, "missingValue", missingValue);
/*missing_string=grib_options_get_option("m:");*/ /*missing_string=grib_options_get_option("m:");*/
} }
if (grib_options_on("F:")) { if (grib_options_on("F:") != 0) {
const char* str = grib_options_get_option("F:"); const char* str = grib_options_get_option("F:");
snprintf(format_values, sizeof(format_values), "%s", str); snprintf(format_values, sizeof(format_values), "%s", str);
} }
@ -133,17 +137,19 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
snprintf(format_values, sizeof(format_values), "%s", default_format_values); snprintf(format_values, sizeof(format_values), "%s", default_format_values);
} }
if (grib_options_on("L:")) { if (grib_options_on("L:") != 0) {
/* Do a very basic sanity check */ /* Do a very basic sanity check */
const char* str = grib_options_get_option("L:"); const char* str = grib_options_get_option("L:");
if (string_count_char(str, '%') != 2) { if (string_count_char(str, '%') != 2) {
fprintf(stderr, "ERROR: Invalid lats/lons format option \"%s\".\n" fprintf(stderr,
"ERROR: Invalid lats/lons format option \"%s\".\n"
" The default is: \"%s\"." " The default is: \"%s\"."
" For higher precision, try: \"%%12.6f%%12.6f\"\n", " For higher precision, try: \"%%12.6f%%12.6f\"\n",
str, default_format_latlons); str, default_format_latlons);
exit(1); exit(1);
} }
snprintf(format_latlons, sizeof(format_latlons), "%s ", str); /* Add a final space to separate from data values */ snprintf(format_latlons, sizeof(format_latlons), "%s ",
str); /* Add a final space to separate from data values */
} }
else { else {
snprintf(format_latlons, sizeof(format_latlons), "%s ", default_format_latlons); snprintf(format_latlons, sizeof(format_latlons), "%s ", default_format_latlons);
@ -158,85 +164,97 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
num_bytes = (numberOfPoints + 1) * sizeof(double); num_bytes = (numberOfPoints + 1) * sizeof(double);
data_values = (double*)calloc(numberOfPoints + 1, sizeof(double)); data_values = (double*)calloc(numberOfPoints + 1, sizeof(double));
if (!data_values) { if (data_values == nullptr) {
fprintf(stderr, "ERROR: Failed to allocate %zu bytes for data values (number of points=%ld)\n", fprintf(stderr, "ERROR: Failed to allocate %zu bytes for data values (number of points=%ld)\n", num_bytes,
num_bytes, numberOfPoints); numberOfPoints);
exit(GRIB_OUT_OF_MEMORY); exit(GRIB_OUT_OF_MEMORY);
} }
if (iter) { if (iter != nullptr) {
double *lat = 0, *lon = 0, *val = 0; double* lat = nullptr;
lats = (double*)calloc(numberOfPoints + 1, sizeof(double)); double* lon = nullptr;
lons = (double*)calloc(numberOfPoints + 1, sizeof(double)); double* val = nullptr;
lat = lats; lats = (double*)calloc(numberOfPoints + 1, sizeof(double));
lon = lons; lons = (double*)calloc(numberOfPoints + 1, sizeof(double));
val = data_values; lat = lats;
while (grib_iterator_next(iter, lat++, lon++, val++)) {} lon = lons;
val = data_values;
while (grib_iterator_next(iter, lat++, lon++, val++) != 0) {
}
} }
else if (err == GRIB_NOT_IMPLEMENTED || err == GRIB_SUCCESS) { else if (err == GRIB_NOT_IMPLEMENTED || err == GRIB_SUCCESS) {
size = numberOfPoints; size = numberOfPoints;
err = grib_get_double_array(h, "values", data_values, &size); err = grib_get_double_array(h, "values", data_values, &size);
if (err) { if (err != 0) {
grib_context_log(h->context, GRIB_LOG_ERROR, "Cannot decode values: %s", grib_context_log(h->context, GRIB_LOG_ERROR, "Cannot decode values: %s", grib_get_error_message(err));
grib_get_error_message(err));
exit(1); exit(1);
} }
if (size != (size_t)numberOfPoints) { if (size != (size_t)numberOfPoints) {
fprintf(stderr, "ERROR: Wrong number of points %ld\n", numberOfPoints); fprintf(stderr, "ERROR: Wrong number of points %ld\n", numberOfPoints);
if (grib_options_on("f")) if (grib_options_on("f") != 0) {
exit(1); exit(1);
}
} }
} }
else { else {
grib_context_log(h->context, GRIB_LOG_ERROR, grib_context_log(h->context, GRIB_LOG_ERROR, "%s", grib_get_error_message(err));
"%s", grib_get_error_message(err));
exit(err); exit(err);
} }
/* Cater for GRIBs which have missing values but no bitmap */ /* Cater for GRIBs which have missing values but no bitmap */
/* See ECC-511 */ /* See ECC-511 */
GRIB_CHECK(grib_get_long(h, "missingValuesPresent", &hasMissingValues), 0); GRIB_CHECK(grib_get_long(h, "missingValuesPresent", &hasMissingValues), nullptr);
GRIB_CHECK(grib_get_long(h, "bitmapPresent", &bitmapPresent), 0); GRIB_CHECK(grib_get_long(h, "bitmapPresent", &bitmapPresent), nullptr);
if (bitmapPresent) { if (bitmapPresent != 0) {
GRIB_CHECK(grib_get_size(h, "bitmap", &bmp_len), 0); GRIB_CHECK(grib_get_size(h, "bitmap", &bmp_len), nullptr);
bitmap = (long*)malloc(bmp_len * sizeof(long)); bitmap = (long*)malloc(bmp_len * sizeof(long));
GRIB_CHECK(grib_get_long_array(h, "bitmap", bitmap, &bmp_len), 0); GRIB_CHECK(grib_get_long_array(h, "bitmap", bitmap, &bmp_len), nullptr);
} }
if (iter) if (iter != nullptr) {
fprintf(dump_file, "Latitude Longitude "); fprintf(dump_file, "Latitude Longitude ");
}
fprintf(dump_file, "Value"); fprintf(dump_file, "Value");
if (print_keys) if (print_keys != 0) {
for (i = 0; i < options->print_keys_count; i++) for (i = 0; i < options->print_keys_count; i++) {
fprintf(dump_file, " %s", options->print_keys[i].name); fprintf(dump_file, " %s", options->print_keys[i].name);
}
}
fprintf(dump_file, "\n"); fprintf(dump_file, "\n");
if (print_keys) if (print_keys != 0) {
values = get_key_values(options, h); values = get_key_values(options, h);
}
if (skip_missing == 0) { if (skip_missing == 0) {
/* Show missing values in data */ /* Show missing values in data */
for (i = 0; i < numberOfPoints; i++) { for (i = 0; i < numberOfPoints; i++) {
int is_missing_val = 0; int is_missing_val = 0;
if (hasMissingValues) { if (hasMissingValues != 0) {
if (bitmapPresent) if (bitmapPresent != 0) {
is_missing_val = (bitmap[i] == 0); is_missing_val = static_cast<int>(bitmap[i] == 0);
else }
is_missing_val = (data_values[i] == missingValue); else {
is_missing_val = static_cast<int>(data_values[i] == missingValue);
}
} }
if (iter) if (iter != nullptr) {
fprintf(dump_file, format_latlons, lats[i], lons[i]); fprintf(dump_file, format_latlons, lats[i], lons[i]);
}
if (is_missing_val) if (is_missing_val != 0) {
fprintf(dump_file, "%s", missing_string); fprintf(dump_file, "%s", missing_string);
else }
else {
fprintf(dump_file, format_values, data_values[i]); fprintf(dump_file, format_values, data_values[i]);
}
if (print_keys) if (print_keys != 0) {
print_key_values(values, options->print_keys_count); print_key_values(values, options->print_keys_count);
}
fprintf(dump_file, "\n"); fprintf(dump_file, "\n");
n++; n++;
} }
@ -245,32 +263,38 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
/* Skip the missing values in data */ /* Skip the missing values in data */
for (i = 0; i < numberOfPoints; i++) { for (i = 0; i < numberOfPoints; i++) {
int is_missing_val = 0; int is_missing_val = 0;
if (hasMissingValues) { if (hasMissingValues != 0) {
if (bitmapPresent) if (bitmapPresent != 0) {
is_missing_val = (bitmap[i] == 0); is_missing_val = static_cast<int>(bitmap[i] == 0);
else }
is_missing_val = (data_values[i] == missingValue); else {
is_missing_val = static_cast<int>(data_values[i] == missingValue);
}
} }
if (!is_missing_val) { if (is_missing_val == 0) {
if (iter) if (iter != nullptr) {
fprintf(dump_file, format_latlons, lats[i], lons[i]); fprintf(dump_file, format_latlons, lats[i], lons[i]);
}
fprintf(dump_file, format_values, data_values[i]); fprintf(dump_file, format_values, data_values[i]);
if (print_keys) if (print_keys != 0) {
print_key_values(values, options->print_keys_count); print_key_values(values, options->print_keys_count);
}
fprintf(dump_file, "\n"); fprintf(dump_file, "\n");
n++; n++;
} }
} }
} }
if (iter) if (iter != nullptr) {
grib_iterator_delete(iter); grib_iterator_delete(iter);
if (bitmap) }
if (bitmap != nullptr) {
free(bitmap); free(bitmap);
}
free(data_values); free(data_values);
free(missing_string); free(missing_string);
if (iter) { if (iter != nullptr) {
free(lats); free(lats);
free(lons); free(lons);
} }
@ -278,42 +302,39 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
return 0; return 0;
} }
int grib_tool_skip_handle(grib_runtime_options* options, grib_handle* h) int grib_tool_skip_handle(grib_runtime_options* options, grib_handle* h) {
{
grib_handle_delete(h); grib_handle_delete(h);
return 0; return 0;
} }
void grib_tool_print_key_values(grib_runtime_options* options, grib_handle* h) void grib_tool_print_key_values(grib_runtime_options* options, grib_handle* h) {
{
grib_print_key_values(options, h); grib_print_key_values(options, h);
} }
int grib_tool_finalise_action(grib_runtime_options* options) int grib_tool_finalise_action(grib_runtime_options* options) {
{
return 0; return 0;
} }
static void print_key_values(grib_values* values, int values_count) static void print_key_values(grib_values* values, int values_count) {
{
int i = 0; int i = 0;
for (i = 0; i < values_count; i++) { for (i = 0; i < values_count; i++) {
fprintf(dump_file, " %s", values[i].string_value); fprintf(dump_file, " %s", values[i].string_value);
} }
} }
static grib_values* get_key_values(grib_runtime_options* options, grib_handle* h) static grib_values* get_key_values(grib_runtime_options* options, grib_handle* h) {
{
int i = 0; int i = 0;
int ret = 0; int ret = 0;
char value[MAX_STRING_LEN] = {0,}; char value[MAX_STRING_LEN] = {
0,
};
const char* notfound = "not found"; const char* notfound = "not found";
for (i = 0; i < options->print_keys_count; i++) { for (i = 0; i < options->print_keys_count; i++) {
size_t len = MAX_STRING_LEN; size_t len = MAX_STRING_LEN;
ret = GRIB_SUCCESS; ret = GRIB_SUCCESS;
if (grib_is_missing(h, options->print_keys[i].name, &ret) && ret == GRIB_SUCCESS) { if ((grib_is_missing(h, options->print_keys[i].name, &ret) != 0) && ret == GRIB_SUCCESS) {
options->print_keys[i].type = GRIB_TYPE_MISSING; options->print_keys[i].type = GRIB_TYPE_MISSING;
snprintf(value, sizeof(value), "MISSING"); snprintf(value, sizeof(value), "MISSING");
} }
@ -327,13 +348,11 @@ static grib_values* get_key_values(grib_runtime_options* options, grib_handle* h
ret = grib_get_string(h, options->print_keys[i].name, value, &len); ret = grib_get_string(h, options->print_keys[i].name, value, &len);
break; break;
case GRIB_TYPE_DOUBLE: case GRIB_TYPE_DOUBLE:
ret = grib_get_double(h, options->print_keys[i].name, ret = grib_get_double(h, options->print_keys[i].name, &(options->print_keys[i].double_value));
&(options->print_keys[i].double_value));
snprintf(value, sizeof(value), "%g", options->print_keys[i].double_value); snprintf(value, sizeof(value), "%g", options->print_keys[i].double_value);
break; break;
case GRIB_TYPE_LONG: case GRIB_TYPE_LONG:
ret = grib_get_long(h, options->print_keys[i].name, ret = grib_get_long(h, options->print_keys[i].name, &(options->print_keys[i].long_value));
&(options->print_keys[i].long_value));
snprintf(value, sizeof(value), "%ld", (long)options->print_keys[i].long_value); snprintf(value, sizeof(value), "%ld", (long)options->print_keys[i].long_value);
break; break;
default: default:
@ -343,10 +362,12 @@ static grib_values* get_key_values(grib_runtime_options* options, grib_handle* h
} }
if (ret != GRIB_SUCCESS) { if (ret != GRIB_SUCCESS) {
if (options->fail) if (options->fail != 0) {
GRIB_CHECK_NOLINE(ret, options->print_keys[i].name); GRIB_CHECK_NOLINE(ret, options->print_keys[i].name);
if (ret == GRIB_NOT_FOUND) }
if (ret == GRIB_NOT_FOUND) {
strcpy(value, notfound); strcpy(value, notfound);
}
else { else {
fprintf(dump_file, "%s %s\n", grib_get_error_message(ret), options->print_keys[i].name); fprintf(dump_file, "%s %s\n", grib_get_error_message(ret), options->print_keys[i].name);
exit(ret); exit(ret);
@ -357,8 +378,7 @@ static grib_values* get_key_values(grib_runtime_options* options, grib_handle* h
return options->print_keys; return options->print_keys;
} }
int grib_no_handle_action(grib_runtime_options* options, int err) int grib_no_handle_action(grib_runtime_options* options, int err) {
{
fprintf(dump_file, "\t\t\"ERROR: unreadable message\"\n"); fprintf(dump_file, "\t\t\"ERROR: unreadable message\"\n");
return 0; return 0;
} }