From 30834ad7b96059834bb13e88ba4a9438bbb0d93c Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Tue, 27 Dec 2022 15:10:14 +0000 Subject: [PATCH] Cleanup --- ...accessor_class_bufr_extract_area_subsets.c | 72 +++++++----------- ...ssor_class_bufr_extract_datetime_subsets.c | 75 +++++++------------ 2 files changed, 51 insertions(+), 96 deletions(-) diff --git a/src/grib_accessor_class_bufr_extract_area_subsets.c b/src/grib_accessor_class_bufr_extract_area_subsets.c index 14d74cafd..b7ef42e7b 100644 --- a/src/grib_accessor_class_bufr_extract_area_subsets.c +++ b/src/grib_accessor_class_bufr_extract_area_subsets.c @@ -182,6 +182,7 @@ static void fill_in(double a[], long length) for (i = 1; i < length; ++i) a[i] = a[0]; } + static int select_area(grib_accessor* a) { int ret = 0; @@ -190,39 +191,33 @@ static int select_area(grib_accessor* a) grib_handle* h = grib_handle_of_accessor(a); grib_context* c = h->context; - double* lat = 0; - double* lon = 0; + double* lat = NULL; + double* lon = NULL; size_t n; double lonWest, lonEast, latNorth, latSouth; long numberOfSubsets, i, latRank, lonRank; - grib_iarray* subsets; - long* subsets_ar = 0; + grib_iarray* subsets = NULL; size_t nsubsets = 0; char latstr[32] = {0,}; char lonstr[32] = {0,}; ret = grib_get_long(h, "compressedData", &compressed); - if (ret) - return ret; + if (ret) return ret; ret = grib_get_long(h, self->numberOfSubsets, &numberOfSubsets); - if (ret) - return ret; + if (ret) return ret; subsets = grib_iarray_new(c, numberOfSubsets, 10); ret = grib_set_long(h, "unpack", 1); - if (ret) - return ret; + if (ret) return ret; if (compressed) { ret = grib_get_long(h, self->extractAreaLongitudeRank, &lonRank); - if (ret) - return ret; + if (ret) return ret; snprintf(lonstr, sizeof(lonstr), "#%ld#longitude", lonRank); ret = grib_get_long(h, self->extractAreaLatitudeRank, &latRank); - if (ret) - return ret; + if (ret) return ret; snprintf(latstr, sizeof(latstr), "#%ld#latitude", latRank); } @@ -231,8 +226,7 @@ static int select_area(grib_accessor* a) lat = (double*)grib_context_malloc_clear(c, sizeof(double) * numberOfSubsets); if (compressed) { ret = grib_get_double_array(h, latstr, lat, &n); - if (ret) - return ret; + if (ret) return ret; if (!(n == 1 || n == numberOfSubsets)) { /* n can be 1 if all latitudes are the same */ return GRIB_INTERNAL_ERROR; @@ -246,13 +240,10 @@ static int select_area(grib_accessor* a) for (i = 0; i < numberOfSubsets; ++i) { snprintf(latstr, sizeof(latstr), "#%ld#latitude", i + 1); ret = grib_get_size(h, latstr, &values_len); - if (ret) - return ret; - if (values_len > 1) - return GRIB_NOT_IMPLEMENTED; + if (ret) return ret; + if (values_len > 1) return GRIB_NOT_IMPLEMENTED; ret = grib_get_double(h, latstr, &(lat[i])); - if (ret) - return ret; + if (ret) return ret; } } @@ -261,8 +252,7 @@ static int select_area(grib_accessor* a) lon = (double*)grib_context_malloc_clear(c, sizeof(double) * numberOfSubsets); if (compressed) { ret = grib_get_double_array(h, lonstr, lon, &n); - if (ret) - return ret; + if (ret) return ret; if (!(n == 1 || n == numberOfSubsets)) { /* n can be 1 if all longitudes are the same */ return GRIB_INTERNAL_ERROR; @@ -276,28 +266,21 @@ static int select_area(grib_accessor* a) for (i = 0; i < numberOfSubsets; ++i) { snprintf(lonstr, sizeof(lonstr), "#%ld#longitude", i + 1); ret = grib_get_size(h, lonstr, &values_len); - if (ret) - return ret; - if (values_len > 1) - return GRIB_NOT_IMPLEMENTED; + if (ret) return ret; + if (values_len > 1) return GRIB_NOT_IMPLEMENTED; ret = grib_get_double(h, lonstr, &(lon[i])); - if (ret) - return ret; + if (ret) return ret; } } ret = grib_get_double(h, self->extractAreaWestLongitude, &lonWest); - if (ret) - return ret; + if (ret) return ret; ret = grib_get_double(h, self->extractAreaEastLongitude, &lonEast); - if (ret) - return ret; + if (ret) return ret; ret = grib_get_double(h, self->extractAreaNorthLatitude, &latNorth); - if (ret) - return ret; + if (ret) return ret; ret = grib_get_double(h, self->extractAreaSouthLatitude, &latSouth); - if (ret) - return ret; + if (ret) return ret; for (i = 0; i < numberOfSubsets; i++) { /* printf("++++++ lat: %g <= %g <= %g lon: %g <= %g <= %g \n",latSouth,lat[i],latNorth,lonWest,lon[i],lonEast); */ @@ -309,25 +292,22 @@ static int select_area(grib_accessor* a) nsubsets = grib_iarray_used_size(subsets); ret = grib_set_long(h, self->extractedAreaNumberOfSubsets, nsubsets); - if (ret) - return ret; + if (ret) return ret; if (nsubsets != 0) { - subsets_ar = grib_iarray_get_array(subsets); + long* subsets_ar = grib_iarray_get_array(subsets); ret = grib_set_long_array(h, self->extractSubsetList, subsets_ar, nsubsets); grib_context_free(c, subsets_ar); - if (ret) - return ret; + if (ret) return ret; ret = grib_set_long(h, self->doExtractSubsets, 1); - if (ret) - return ret; + if (ret) return ret; } grib_context_free(c, lat); grib_context_free(c, lon); grib_iarray_delete(subsets); - subsets = 0; + subsets = NULL; return ret; } diff --git a/src/grib_accessor_class_bufr_extract_datetime_subsets.c b/src/grib_accessor_class_bufr_extract_datetime_subsets.c index 83f8de43a..297030ac3 100644 --- a/src/grib_accessor_class_bufr_extract_datetime_subsets.c +++ b/src/grib_accessor_class_bufr_extract_datetime_subsets.c @@ -253,75 +253,61 @@ static int select_datetime(grib_accessor* a) char secondstr[32] = "second"; ret = grib_get_long(h, "compressedData", &compressed); - if (ret) - return ret; + if (ret) return ret; ret = grib_get_long(h, self->numberOfSubsets, &numberOfSubsets); - if (ret) - return ret; + if (ret) return ret; subsets = grib_iarray_new(c, numberOfSubsets, 10); ret = grib_set_long(h, "unpack", 1); - if (ret) - return ret; + if (ret) return ret; if (compressed) { ret = grib_get_long(h, "extractDateTimeYearRank", &yearRank); - if (ret) - return ret; + if (ret) return ret; snprintf(yearstr, sizeof(yearstr), "#%ld#year", yearRank); ret = grib_get_long(h, "extractDateTimeMonthRank", &monthRank); - if (ret) - return ret; + if (ret) return ret; snprintf(monthstr, sizeof(monthstr), "#%ld#month", monthRank); ret = grib_get_long(h, "extractDateTimeDayRank", &dayRank); - if (ret) - return ret; + if (ret) return ret; snprintf(daystr, sizeof(daystr), "#%ld#day", dayRank); ret = grib_get_long(h, "extractDateTimeHourRank", &hourRank); - if (ret) - return ret; + if (ret) return ret; snprintf(hourstr, sizeof(hourstr), "#%ld#hour", hourRank); ret = grib_get_long(h, "extractDateTimeMinuteRank", &minuteRank); - if (ret) - return ret; + if (ret) return ret; snprintf(minutestr, sizeof(minutestr), "#%ld#minute", minuteRank); ret = grib_get_long(h, "extractDateTimeSecondRank", &secondRank); - if (ret) - return ret; + if (ret) return ret; snprintf(secondstr, sizeof(secondstr), "#%ld#second", secondRank); } /* YEAR */ ret = build_long_array(c, h, compressed, &year, yearstr, numberOfSubsets, 0); - if (ret) - return ret; + if (ret) return ret; /* MONTH */ ret = build_long_array(c, h, compressed, &month, monthstr, numberOfSubsets, 0); - if (ret) - return ret; + if (ret) return ret; /* DAY */ ret = build_long_array(c, h, compressed, &day, daystr, numberOfSubsets, 0); - if (ret) - return ret; + if (ret) return ret; /* HOUR */ ret = build_long_array(c, h, compressed, &hour, hourstr, numberOfSubsets, 0); - if (ret) - return ret; + if (ret) return ret; /* MINUTE: Special treatment if error => set all entries to zero */ ret = build_long_array(c, h, compressed, &minute, minutestr, numberOfSubsets, 1); - if (ret) - return ret; + if (ret) return ret; /* SECOND: Double array */ n = numberOfSubsets; @@ -365,17 +351,13 @@ static int select_datetime(grib_accessor* a) } ret = grib_get_long(h, "extractDateTimeYearStart", &yearStart); - if (ret) - return ret; + if (ret) return ret; ret = grib_get_long(h, "extractDateTimeMonthStart", &monthStart); - if (ret) - return ret; + if (ret) return ret; ret = grib_get_long(h, "extractDateTimeDayStart", &dayStart); - if (ret) - return ret; + if (ret) return ret; ret = grib_get_long(h, "extractDateTimeHourStart", &hourStart); - if (ret) - return ret; + if (ret) return ret; ret = grib_get_long(h, "extractDateTimeMinuteStart", &minuteStart); if (ret) minuteStart = 0; @@ -393,17 +375,13 @@ static int select_datetime(grib_accessor* a) } ret = grib_get_long(h, "extractDateTimeYearEnd", &yearEnd); - if (ret) - return ret; + if (ret) return ret; ret = grib_get_long(h, "extractDateTimeMonthEnd", &monthEnd); - if (ret) - return ret; + if (ret) return ret; ret = grib_get_long(h, "extractDateTimeDayEnd", &dayEnd); - if (ret) - return ret; + if (ret) return ret; ret = grib_get_long(h, "extractDateTimeHourEnd", &hourEnd); - if (ret) - return ret; + if (ret) return ret; ret = grib_get_long(h, "extractDateTimeMinuteEnd", &minuteEnd); if (ret) minuteEnd = 0; @@ -453,19 +431,16 @@ static int select_datetime(grib_accessor* a) nsubsets = grib_iarray_used_size(subsets); ret = grib_set_long(h, "extractedDateTimeNumberOfSubsets", nsubsets); - if (ret) - return ret; + if (ret) return ret; if (nsubsets != 0) { long* subsets_ar = grib_iarray_get_array(subsets); ret = grib_set_long_array(h, self->extractSubsetList, subsets_ar, nsubsets); grib_context_free(c, subsets_ar); - if (ret) - return ret; + if (ret) return ret; ret = grib_set_long(h, self->doExtractSubsets, 1); - if (ret) - return ret; + if (ret) return ret; } cleanup: