Skip to content

Commit e5cff6a

Browse files
committed
Merge remote-tracking branch 'origin/develop' into feature/ECC-1766-EERIE
2 parents 8f366f2 + 9ce9b1f commit e5cff6a

26 files changed

+176
-102
lines changed

examples/C/grib_clone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ int main(int argc, char* argv[])
6868
CODES_CHECK(codes_get_message(clone_handle, &buffer, &size), 0);
6969
/* write the buffer to a file */
7070
if (fwrite(buffer, 1, size, out) != size) {
71-
perror(argv[1]);
71+
perror(argv[2]);
7272
return 1;
7373
}
7474
codes_handle_delete(clone_handle);

examples/C/grib_precision.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ int main(int argc, char** argv)
116116

117117
/* write the buffer in a file*/
118118
if (fwrite(buffer, 1, size, out) != size) {
119-
perror(argv[1]);
119+
perror(outfile);
120120
exit(1);
121121
}
122122

examples/C/grib_set_keys.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ int main(int argc, char** argv)
7878

7979
/* write the buffer in a file*/
8080
if (fwrite(buffer, 1, size, out) != size) {
81-
perror(argv[1]);
81+
perror(outfile);
8282
exit(1);
8383
}
8484

examples/C/grib_set_missing.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ int main(int argc, char** argv)
7777

7878
/* write the buffer in a file*/
7979
if (fwrite(buffer, 1, size, out) != size) {
80-
perror(argv[1]);
80+
perror(outfile);
8181
exit(1);
8282
}
8383

examples/C/grib_set_pv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ int main(int argc, char** argv)
7878

7979
/* write the buffer in a file*/
8080
if (fwrite(buffer, 1, size, out) != size) {
81-
perror(argv[1]);
81+
perror(outfile);
8282
exit(1);
8383
}
8484

src/eccodes_prototypes.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,6 @@ grib_handle* grib_fieldset_retrieve(grib_fieldset* set, int i, int* err);
918918

919919
/* grib_filepool.cc*/
920920
void grib_file_pool_clean(void);
921-
grib_file* grib_file_pool_get_files(void);
922921
grib_file* grib_file_open(const char* filename, const char* mode, int* err);
923922
void grib_file_pool_delete_file(grib_file* file);
924923
void grib_file_close(const char* filename, int force, int* err);

src/grib_accessor_class_bit.cc

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,22 +106,20 @@ grib_accessor_class* grib_accessor_class_bit = &_grib_accessor_class_bit;
106106
static void init(grib_accessor* a, const long len, grib_arguments* arg)
107107
{
108108
grib_accessor_bit* self = (grib_accessor_bit*)a;
109-
a->length = 0;
110-
self->owner = grib_arguments_get_name(grib_handle_of_accessor(a), arg, 0);
111-
self->bit_index = grib_arguments_get_long(grib_handle_of_accessor(a), arg, 1);
109+
a->length = 0;
110+
self->owner = grib_arguments_get_name(grib_handle_of_accessor(a), arg, 0);
111+
self->bit_index = grib_arguments_get_long(grib_handle_of_accessor(a), arg, 1);
112112
}
113113

114-
115114
static int unpack_long(grib_accessor* a, long* val, size_t* len)
116115
{
117116
grib_accessor_bit* self = (grib_accessor_bit*)a;
118-
int ret = 0;
119-
117+
int ret = 0;
120118
long data = 0;
121119

122120
if (*len < 1) {
123-
grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_bit : unpack_long : Wrong size for %s it contains %d values ", a->name, 1);
124-
*len = 0;
121+
grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_bit: unpack_long: Wrong size for %s, it contains %d values ", a->name, 1);
122+
*len = 1;
125123
return GRIB_ARRAY_TOO_SMALL;
126124
}
127125

@@ -142,23 +140,22 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len)
142140
static int pack_long(grib_accessor* a, const long* val, size_t* len)
143141
{
144142
grib_accessor_bit* self = (grib_accessor_bit*)a;
145-
grib_accessor* owner = NULL;
146-
unsigned char* mdata = 0;
143+
147144
if (*len < 1) {
148-
grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_bit : pack_long : At least one value to pack for %s", a->name);
149-
*len = 0;
145+
grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_bit: pack_long: At least one value to pack for %s", a->name);
146+
*len = 1;
150147
return GRIB_ARRAY_TOO_SMALL;
151148
}
152149

153-
owner = grib_find_accessor(grib_handle_of_accessor(a), self->owner);
154-
150+
grib_accessor* owner = grib_find_accessor(grib_handle_of_accessor(a), self->owner);
155151
if (!owner) {
156-
grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_bit : Cannot get the owner %s for computing the bit value of %s ", self->owner, a->name);
152+
grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_bit: Cannot get the owner %s for computing the bit value of %s",
153+
self->owner, a->name);
157154
*len = 0;
158155
return GRIB_NOT_FOUND;
159156
}
160157

161-
mdata = grib_handle_of_accessor(a)->buffer->data;
158+
unsigned char* mdata = grib_handle_of_accessor(a)->buffer->data;
162159
mdata += grib_byte_offset(owner);
163160

164161
/* Note: In the definitions, flagbit numbers go from 7 to 0 (the bit_index), while WMO convention is from 1 to 8 */

src/grib_accessor_class_bitmap.cc

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ static void compute_size(grib_accessor* a)
161161
static void init(grib_accessor* a, const long len, grib_arguments* arg)
162162
{
163163
grib_accessor_bitmap* self = (grib_accessor_bitmap*)a;
164-
grib_handle* hand = grib_handle_of_accessor(a);
165-
int n = 0;
164+
grib_handle* hand = grib_handle_of_accessor(a);
165+
int n = 0;
166166

167167
self->tableReference = grib_arguments_get_name(hand, arg, n++);
168168
self->missing_value = grib_arguments_get_name(hand, arg, n++);
@@ -190,23 +190,21 @@ static void dump(grib_accessor* a, grib_dumper* dumper)
190190

191191
static int unpack_long(grib_accessor* a, long* val, size_t* len)
192192
{
193-
long pos = a->offset * 8;
194-
long tlen = 0;
195-
long i = 0;
196-
int err = 0;
193+
long pos = a->offset * 8;
194+
long tlen = 0;
197195
const grib_handle* hand = grib_handle_of_accessor(a);
198196

199-
err = grib_value_count(a, &tlen);
197+
int err = grib_value_count(a, &tlen);
200198
if (err)
201199
return err;
202200

203201
if (*len < tlen) {
204202
grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %ld values", a->name, tlen);
205-
*len = 0;
203+
*len = tlen;
206204
return GRIB_ARRAY_TOO_SMALL;
207205
}
208206

209-
for (i = 0; i < tlen; i++) {
207+
for (long i = 0; i < tlen; i++) {
210208
val[i] = (long)grib_decode_unsigned_long(hand->buffer->data, &pos, 1);
211209
}
212210
*len = tlen;
@@ -219,21 +217,19 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
219217
static_assert(std::is_floating_point<T>::value, "Requires floating points numbers");
220218
long pos = a->offset * 8;
221219
long tlen;
222-
long i;
223-
int err = 0;
224220
grib_handle* hand = grib_handle_of_accessor(a);
225221

226-
err = grib_value_count(a, &tlen);
222+
int err = grib_value_count(a, &tlen);
227223
if (err)
228224
return err;
229225

230226
if (*len < tlen) {
231227
grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %ld values", a->name, tlen);
232-
*len = 0;
228+
*len = tlen;
233229
return GRIB_ARRAY_TOO_SMALL;
234230
}
235231

236-
for (i = 0; i < tlen; i++) {
232+
for (long i = 0; i < tlen; i++) {
237233
val[i] = (T)grib_decode_unsigned_long(hand->buffer->data, &pos, 1);
238234
}
239235
*len = tlen;
@@ -261,8 +257,7 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val)
261257
}
262258
static int unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array)
263259
{
264-
size_t i = 0;
265-
for (i=0; i<len; ++i) {
260+
for (size_t i=0; i<len; ++i) {
266261
unpack_double_element(a, index_array[i], val_array + i);
267262
}
268263
return GRIB_SUCCESS;
@@ -280,7 +275,6 @@ static size_t string_length(grib_accessor* a)
280275

281276
static int unpack_string(grib_accessor* a, char* val, size_t* len)
282277
{
283-
long i = 0;
284278
grib_handle* hand = grib_handle_of_accessor(a);
285279
const size_t l = a->length;
286280

@@ -293,7 +287,7 @@ static int unpack_string(grib_accessor* a, char* val, size_t* len)
293287
return GRIB_BUFFER_TOO_SMALL;
294288
}
295289

296-
for (i = 0; i < a->length; i++) {
290+
for (long i = 0; i < a->length; i++) {
297291
val[i] = hand->buffer->data[a->offset + i];
298292
}
299293

src/grib_accessor_class_codetable.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -908,9 +908,9 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len)
908908
}
909909

910910
if (*len < rlen) {
911-
grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size (%lu) for %s, it contains %ld values",
911+
grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size (%zu) for %s, it contains %ld values",
912912
*len, a->name, rlen);
913-
*len = 0;
913+
*len = rlen;
914914
return GRIB_ARRAY_TOO_SMALL;
915915
}
916916

src/grib_accessor_class_spd.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len)
167167

168168
if (*len < rlen) {
169169
grib_context_log(a->context, GRIB_LOG_ERROR,
170-
"Wrong size (%ld) for %s it contains %ld values", *len, a->name, rlen);
171-
*len = 0;
170+
"Wrong size (%zu) for %s, it contains %ld values", *len, a->name, rlen);
171+
*len = rlen;
172172
return GRIB_ARRAY_TOO_SMALL;
173173
}
174174

src/grib_accessor_class_unexpanded_descriptors.cc

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
CLASS = accessor
1717
SUPER = grib_accessor_class_long
1818
IMPLEMENTS = unpack_long;pack_long
19-
IMPLEMENTS = init;dump
19+
IMPLEMENTS = init
2020
IMPLEMENTS = next_offset
2121
IMPLEMENTS = value_count
2222
IMPLEMENTS = byte_offset
@@ -43,7 +43,6 @@ static int unpack_long(grib_accessor*, long* val, size_t* len);
4343
static long byte_offset(grib_accessor*);
4444
static long next_offset(grib_accessor*);
4545
static int value_count(grib_accessor*, long*);
46-
static void dump(grib_accessor*, grib_dumper*);
4746
static void init(grib_accessor*, const long, grib_arguments*);
4847
static void update_size(grib_accessor*, size_t);
4948

@@ -68,7 +67,7 @@ static grib_accessor_class _grib_accessor_class_unexpanded_descriptors = {
6867
&init, /* init */
6968
0, /* post_init */
7069
0, /* destroy */
71-
&dump, /* dump */
70+
0, /* dump */
7271
&next_offset, /* next_offset */
7372
0, /* get length of string */
7473
&value_count, /* get number of values */
@@ -122,11 +121,6 @@ static void init(grib_accessor* a, const long len, grib_arguments* args)
122121
a->length = 0;
123122
}
124123

125-
static void dump(grib_accessor* a, grib_dumper* dumper)
126-
{
127-
grib_dump_long(dumper, a, NULL);
128-
}
129-
130124
static int unpack_long(grib_accessor* a, long* val, size_t* len)
131125
{
132126
grib_accessor_unexpanded_descriptors* self = (grib_accessor_unexpanded_descriptors*)a;

src/grib_accessor_class_unsigned_bits.cc

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
CLASS = accessor
1717
SUPER = grib_accessor_class_long
1818
IMPLEMENTS = unpack_long;pack_long
19-
IMPLEMENTS = init;dump
19+
IMPLEMENTS = init
2020
IMPLEMENTS = next_offset
2121
IMPLEMENTS = byte_count
2222
IMPLEMENTS = value_count
@@ -45,7 +45,6 @@ static long byte_count(grib_accessor*);
4545
static long byte_offset(grib_accessor*);
4646
static long next_offset(grib_accessor*);
4747
static int value_count(grib_accessor*, long*);
48-
static void dump(grib_accessor*, grib_dumper*);
4948
static void init(grib_accessor*, const long, grib_arguments*);
5049
static void update_size(grib_accessor*, size_t);
5150

@@ -70,7 +69,7 @@ static grib_accessor_class _grib_accessor_class_unsigned_bits = {
7069
&init, /* init */
7170
0, /* post_init */
7271
0, /* destroy */
73-
&dump, /* dump */
72+
0, /* dump */
7473
&next_offset, /* next_offset */
7574
0, /* get length of string */
7675
&value_count, /* get number of values */
@@ -149,11 +148,6 @@ static void init(grib_accessor* a, const long len, grib_arguments* args)
149148
a->length = compute_byte_count(a);
150149
}
151150

152-
static void dump(grib_accessor* a, grib_dumper* dumper)
153-
{
154-
grib_dump_long(dumper, a, NULL);
155-
}
156-
157151
static int unpack_long(grib_accessor* a, long* val, size_t* len)
158152
{
159153
grib_accessor_unsigned_bits* self = (grib_accessor_unsigned_bits*)a;
@@ -169,7 +163,7 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len)
169163
if (*len < rlen) {
170164
grib_context_log(a->context, GRIB_LOG_ERROR,
171165
"Wrong size (%ld) for %s, it contains %ld values", *len, a->name, rlen);
172-
*len = 0;
166+
*len = rlen;
173167
return GRIB_ARRAY_TOO_SMALL;
174168
}
175169

src/grib_accessor_class_variable.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
208208
const double dval = *val;
209209

210210
if (*len != 1) {
211-
grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %d values", a->name, 1);
211+
grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains 1 value", a->name);
212212
*len = 1;
213213
return GRIB_ARRAY_TOO_SMALL;
214214
}
@@ -233,7 +233,7 @@ static int pack_float(grib_accessor* a, const float* val, size_t* len)
233233
const double fval = *val;
234234

235235
if (*len != 1) {
236-
grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %d values", a->name, 1);
236+
grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains 1 value", a->name);
237237
*len = 1;
238238
return GRIB_ARRAY_TOO_SMALL;
239239
}
@@ -252,7 +252,7 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len)
252252
grib_accessor_variable* self = (grib_accessor_variable*)a;
253253

254254
if (*len != 1) {
255-
grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s it contains %d values ", a->name, 1);
255+
grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s it contains 1 value", a->name);
256256
*len = 1;
257257
return GRIB_ARRAY_TOO_SMALL;
258258
}

src/grib_filepool.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ void grib_file_pool_clean()
132132
// return grib_write_file(fh, file->next);
133133
// }
134134

135-
grib_file* grib_file_pool_get_files()
136-
{
137-
return file_pool.first;
138-
}
135+
// grib_file* grib_file_pool_get_files()
136+
// {
137+
// return file_pool.first;
138+
// }
139139

140140
// int grib_file_pool_read(grib_context* c, FILE* fh)
141141
// {

src/grib_util.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,6 +1723,7 @@ static void set_value(grib_values* value, char* str, int equal)
17231723
}
17241724
break;
17251725
case GRIB_TYPE_LONG:
1726+
errno = 0; // must clear errno before calling strtol
17261727
value->long_value = strtol(buf, &p, 10);
17271728
if (*p != 0)
17281729
value->has_value = 1;
@@ -1746,11 +1747,11 @@ static void set_value(grib_values* value, char* str, int equal)
17461747
}
17471748
break;
17481749
case GRIB_TYPE_UNDEFINED:
1750+
errno = 0; // must clear errno before calling strtol
17491751
value->long_value = strtol(buf, &p, 10);
17501752
if (*p == 0) {
17511753
// check the conversion from string to long
1752-
if ((errno == ERANGE && (value->long_value == LONG_MAX || value->long_value == LONG_MIN)) ||
1753-
(errno != 0 && value->long_value == 0)) {
1754+
if (errno == ERANGE && (value->long_value == LONG_MAX || value->long_value == LONG_MIN)) {
17541755
fprintf(stderr, "ECCODES WARNING : Setting %s=%s causes overflow/underflow\n", value->name, buf);
17551756
fprintf(stderr, "ECCODES WARNING : Value adjusted to %ld\n", value->long_value);
17561757
//perror("strtol");

0 commit comments

Comments
 (0)