ECC-1614: Cleanup

This commit is contained in:
Shahram Najm 2023-06-18 11:49:12 +01:00 committed by shahramn
parent 190c663586
commit 57e0ce018d
1 changed files with 5 additions and 10 deletions

View File

@ -30,8 +30,6 @@ static int count_messages_slow(FILE* in, int message_type, unsigned long* count)
wmo_read_proc wmo_read = NULL; wmo_read_proc wmo_read = NULL;
grib_context* c = grib_context_get_default(); grib_context* c = grib_context_get_default();
if (!in) return 1;
if (message_type == CODES_GRIB) if (message_type == CODES_GRIB)
wmo_read = wmo_read_grib_from_file_malloc; wmo_read = wmo_read_grib_from_file_malloc;
else if (message_type == CODES_BUFR) else if (message_type == CODES_BUFR)
@ -72,17 +70,14 @@ static int count_messages_slow(FILE* in, int message_type, unsigned long* count)
return err; return err;
} }
// This version does not store the message contents. Much faster // This version does not store the message contents (no malloc). Much faster
static int count_messages_fast(FILE* in, int message_type, unsigned long* count) static int count_messages_fast(FILE* in, int message_type, unsigned long* count)
{ {
size_t size = 0;
int err = GRIB_SUCCESS; int err = GRIB_SUCCESS;
typedef int (*wmo_read_proc)(FILE* , void* , size_t*); typedef int (*wmo_read_proc)(FILE* , void* , size_t*);
wmo_read_proc wmo_read = NULL; wmo_read_proc wmo_read = NULL;
unsigned char buff1[1000] = {0,}; unsigned char buffer[1000] = {0,};
size = sizeof(buff1); size_t size = sizeof(buffer);
if (!in) return 1;
if (message_type == CODES_GRIB) if (message_type == CODES_GRIB)
wmo_read = wmo_read_grib_from_file_fast; wmo_read = wmo_read_grib_from_file_fast;
@ -94,14 +89,14 @@ static int count_messages_fast(FILE* in, int message_type, unsigned long* count)
wmo_read = wmo_read_any_from_file_fast; wmo_read = wmo_read_any_from_file_fast;
if (fail_on_error) { if (fail_on_error) {
while ((err = wmo_read(in, buff1, &size)) == GRIB_SUCCESS) { while ((err = wmo_read(in, buffer, &size)) == GRIB_SUCCESS) {
(*count)++; (*count)++;
} }
} }
else { else {
int done = 0; int done = 0;
while (!done) { while (!done) {
err = wmo_read(in, buff1, &size); err = wmo_read(in, buffer, &size);
if (err) { if (err) {
if (err == GRIB_END_OF_FILE || err == GRIB_PREMATURE_END_OF_FILE) { if (err == GRIB_END_OF_FILE || err == GRIB_PREMATURE_END_OF_FILE) {
done = 1; // reached the end done = 1; // reached the end