Skip to content

Commit c7684fe

Browse files
committed
grib_get_values with silent option
1 parent e2ae754 commit c7684fe

File tree

2 files changed

+32
-24
lines changed

2 files changed

+32
-24
lines changed

src/eccodes_prototypes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,7 @@ int grib_get_string_array(const grib_handle* h, const char* name, char** val, si
732732
int grib_get_long_array_internal(grib_handle* h, const char* name, long* val, size_t* length);
733733
int grib_get_long_array(const grib_handle* h, const char* name, long* val, size_t* length);
734734
int grib_set_values(grib_handle* h, grib_values* args, size_t count);
735+
int grib_set_values_silent(grib_handle* h, grib_values* args, size_t count, int silent);
735736
int grib_get_nearest_smaller_value(grib_handle* h, const char* name, double val, double* nearest);
736737
void grib_print_values(const char* title, const grib_values* values, FILE* out, int count);
737738
int grib_values_check(grib_handle* h, grib_values* values, int count);

src/grib_value.cc

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ GRIB_INLINE static int grib_inline_strcmp(const char* a, const char* b)
3131
return (*a == 0 && *b == 0) ? 0 : 1;
3232
}
3333

34-
/* Debug utility function to track GRIB packing/repacking issues */
34+
// Debug utility function to track GRIB packing/repacking issues
3535
template <typename T>
3636
static void print_debug_info__set_array(grib_handle* h, const char* func, const char* name, const T* val, size_t length)
3737
{
@@ -339,7 +339,7 @@ int grib_copy_namespace(grib_handle* dest, const char* name, grib_handle* src)
339339
}
340340
}
341341
if (err)
342-
error_code = *err; /* copy the error code before cleanup */
342+
error_code = *err; // copy the error code before cleanup
343343
grib_keys_iterator_delete(iter);
344344
key_err = first;
345345
while (key_err) {
@@ -407,9 +407,8 @@ int grib_set_string_internal(grib_handle* h, const char* name,
407407
return GRIB_NOT_FOUND;
408408
}
409409

410-
/* Return 1 if we dealt with specific packing type changes and nothing more needs doing.
411-
* Return 0 if further action is needed
412-
*/
410+
// Return 1 if we dealt with specific packing type changes and nothing more needs doing.
411+
// Return 0 if further action is needed
413412
static int preprocess_packingType_change(grib_handle* h, const char* keyname, const char* keyval)
414413
{
415414
int err = 0;
@@ -488,7 +487,7 @@ int grib_set_string(grib_handle* h, const char* name, const char* val, size_t* l
488487

489488
int processed = preprocess_packingType_change(h, name, val);
490489
if (processed)
491-
return GRIB_SUCCESS; /* Dealt with - no further action needed */
490+
return GRIB_SUCCESS; // Dealt with - no further action needed
492491

493492
a = grib_find_accessor(h, name);
494493

@@ -566,8 +565,8 @@ int grib_set_bytes(grib_handle* h, const char* name, const unsigned char* val, s
566565
grib_accessor* a = grib_find_accessor(h, name);
567566

568567
if (a) {
569-
/* if(a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) */
570-
/* return GRIB_READ_ONLY; */
568+
// if(a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY)
569+
// return GRIB_READ_ONLY;
571570

572571
ret = a->pack_bytes(val, length);
573572
if (ret == GRIB_SUCCESS) {
@@ -639,14 +638,14 @@ int grib_is_missing_double(grib_accessor* a, double x)
639638

640639
int grib_is_missing_string(grib_accessor* a, const unsigned char* x, size_t len)
641640
{
642-
/* For a string value to be missing, every character has to be */
643-
/* all 1's (i.e. 0xFF) */
644-
/* Note: An empty string is also classified as missing */
641+
// For a string value to be missing, every character has to be */
642+
// all 1's (i.e. 0xFF) */
643+
// Note: An empty string is also classified as missing */
645644
int ret;
646645
size_t i = 0;
647646

648647
if (len == 0)
649-
return 1; /* empty string */
648+
return 1; // empty string
650649
ret = 1;
651650
for (i = 0; i < len; i++) {
652651
if (x[i] != 0xFF) {
@@ -695,7 +694,7 @@ int grib_is_missing(const grib_handle* h, const char* name, int* err)
695694
return grib_accessor_is_missing(a, err);
696695
}
697696

698-
/* Return true if the given key exists (is defined) in our grib message */
697+
// Return true if the given key exists (is defined) in our grib message
699698
int grib_is_defined(const grib_handle* h, const char* name)
700699
{
701700
const grib_accessor* a = grib_find_accessor(h, name);
@@ -729,7 +728,7 @@ static int _grib_set_double_array_internal(grib_handle* h, grib_accessor* a,
729728
err = a->pack_double(val + *encoded_length, &len);
730729
*encoded_length += len;
731730
if (err == GRIB_SUCCESS) {
732-
/* See ECC-778 */
731+
// See ECC-778
733732
return grib_dependency_notify_change_h(h, a);
734733
}
735734
}
@@ -768,7 +767,7 @@ static int _grib_set_double_array(grib_handle* h, const char* name,
768767
err = GRIB_ARRAY_TOO_SMALL;
769768

770769
if (err == GRIB_SUCCESS)
771-
return grib_dependency_notify_change_h(h, a); /* See ECC-778 */
770+
return grib_dependency_notify_change_h(h, a); // See ECC-778
772771

773772
return err;
774773
}
@@ -792,7 +791,7 @@ int grib_set_double_array_internal(grib_handle* h, const char* name, const doubl
792791
if (ret != GRIB_SUCCESS)
793792
grib_context_log(h->context, GRIB_LOG_ERROR, "Unable to set double array '%s' (%s)",
794793
name, grib_get_error_message(ret));
795-
/*if (h->context->debug) fprintf(stderr,"ECCODES DEBUG grib_set_double_array_internal key=%s --DONE\n",name);*/
794+
//if (h->context->debug) fprintf(stderr,"ECCODES DEBUG grib_set_double_array_internal key=%s --DONE\n",name);
796795
return ret;
797796
}
798797

@@ -1784,6 +1783,12 @@ int grib_get_long_array(const grib_handle* h, const char* name, long* val, size_
17841783
// }
17851784

17861785
int grib_set_values(grib_handle* h, grib_values* args, size_t count)
1786+
{
1787+
// The default behaviour is to print any error messages (not silent)
1788+
return grib_set_values_silent(h, args, count, /*silent=*/0);
1789+
}
1790+
1791+
int grib_set_values_silent(grib_handle* h, grib_values* args, size_t count, int silent)
17871792
{
17881793
int i, error = 0;
17891794
int err = 0;
@@ -1839,13 +1844,13 @@ int grib_set_values(grib_handle* h, grib_values* args, size_t count)
18391844
break;
18401845

18411846
default:
1842-
grib_context_log(h->context, GRIB_LOG_ERROR, "grib_set_values[%d] %s invalid type %d", i, args[i].name, args[i].type);
1847+
if (!silent)
1848+
grib_context_log(h->context, GRIB_LOG_ERROR, "grib_set_values[%d] %s invalid type %d", i, args[i].name, args[i].type);
18431849
args[i].error = GRIB_INVALID_ARGUMENT;
18441850
break;
18451851
}
1846-
/*if (args[i].error != GRIB_SUCCESS)
1847-
grib_context_log(h->context,GRIB_LOG_ERROR,"Unable to set %s (%s)",
1848-
args[i].name,grib_get_error_message(args[i].error)); */
1852+
// if (args[i].error != GRIB_SUCCESS)
1853+
// grib_context_log(h->context,GRIB_LOG_ERROR,"Unable to set %s (%s)",args[i].name,grib_get_error_message(args[i].error));
18491854
}
18501855
}
18511856

@@ -1856,10 +1861,12 @@ int grib_set_values(grib_handle* h, grib_values* args, size_t count)
18561861

18571862
for (i = 0; i < count; i++) {
18581863
if (args[i].error != GRIB_SUCCESS) {
1859-
grib_context_log(h->context, GRIB_LOG_ERROR,
1860-
"grib_set_values[%d] %s (type=%s) failed: %s (message %d)",
1861-
i, args[i].name, grib_get_type_name(args[i].type),
1862-
grib_get_error_message(args[i].error), h->context->handle_file_count);
1864+
if (!silent) {
1865+
grib_context_log(h->context, GRIB_LOG_ERROR,
1866+
"grib_set_values[%d] %s (type=%s) failed: %s (message %d)",
1867+
i, args[i].name, grib_get_type_name(args[i].type),
1868+
grib_get_error_message(args[i].error), h->context->handle_file_count);
1869+
}
18631870
err = err == GRIB_SUCCESS ? args[i].error : err;
18641871
}
18651872
}

0 commit comments

Comments
 (0)