Skip to content

Commit 88bdbd6

Browse files
committed
Refactoring
1 parent 5490b24 commit 88bdbd6

File tree

3 files changed

+22
-27
lines changed

3 files changed

+22
-27
lines changed

src/grib_accessor_class_g2grid.cc

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,13 @@ static int value_count(grib_accessor* a, long* count)
148148
static int unpack_double(grib_accessor* a, double* val, size_t* len)
149149
{
150150
grib_accessor_g2grid* self = (grib_accessor_g2grid*)a;
151-
grib_handle* hand = grib_handle_of_accessor(a);
152-
int ret = 0;
151+
grib_handle* hand = grib_handle_of_accessor(a);
152+
int ret = GRIB_SUCCESS;
153153

154154
long basic_angle = 0;
155155
long sub_division = 0;
156-
int n = 0;
156+
int n = 0;
157157
long v[6];
158-
int i;
159158

160159
if (*len < 6) {
161160
ret = GRIB_ARRAY_TOO_SMALL;
@@ -199,7 +198,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
199198
if ((ret = grib_get_long_internal(hand, self->j_increment, &v[n++])) != GRIB_SUCCESS)
200199
return ret;
201200
}
202-
for (i = 0; i < n; i++)
201+
for (int i = 0; i < n; i++)
203202
if (v[i] == GRIB_MISSING_LONG)
204203
val[i] = GRIB_MISSING_DOUBLE;
205204
else
@@ -282,15 +281,14 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
282281
{
283282
grib_accessor_g2grid* self = (grib_accessor_g2grid*)a;
284283
grib_handle* hand = grib_handle_of_accessor(a);
285-
int ret;
284+
int ret = GRIB_SUCCESS;
286285
long v[6];
287286
int n;
288287
long basic_angle;
289288
long sub_division;
290289

291290
if (*len < 6) {
292-
ret = GRIB_ARRAY_TOO_SMALL;
293-
return ret;
291+
return GRIB_ARRAY_TOO_SMALL;
294292
}
295293

296294
/* printf("pack_double %g %g %g %g %g %g\n",val[0],val[1],val[2],val[3],val[4],val[5]);*/

src/grib_accessor_class_latitudes.cc

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,16 @@ static int get_distinct(grib_accessor* a, double** val, long* len);
114114

115115
static int compare_doubles(const void* a, const void* b, int ascending)
116116
{
117-
/* ascending is a boolean: 0 or 1 */
117+
// ascending is a boolean: 0 or 1
118118
double* arg1 = (double*)a;
119119
double* arg2 = (double*)b;
120120
if (ascending) {
121121
if (*arg1 < *arg2)
122-
return -1; /*Smaller values come before larger ones*/
122+
return -1; // Smaller values come before larger ones
123123
}
124124
else {
125125
if (*arg1 > *arg2)
126-
return -1; /*Larger values come before smaller ones*/
126+
return -1; // Larger values come before smaller ones
127127
}
128128
if (*arg1 == *arg2)
129129
return 0;
@@ -155,7 +155,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
155155
{
156156
grib_context* c = a->context;
157157
grib_accessor_latitudes* self = (grib_accessor_latitudes*)a;
158-
int ret = 0;
158+
int ret = GRIB_SUCCESS;
159159
double* v = val;
160160
double dummyLon = 0;
161161
size_t size = 0;
@@ -167,7 +167,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
167167
if (ret) return ret;
168168
size = count;
169169
if (*len < size) {
170-
/* self->lats are computed in value_count so must free */
170+
// self->lats are computed in value_count so must free
171171
if (self->lats) {
172172
grib_context_free(c, self->lats);
173173
self->lats = NULL;
@@ -176,7 +176,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
176176
}
177177
self->save = 0;
178178

179-
/* self->lats are computed in value_count*/
179+
// self->lats are computed in value_count
180180
if (self->lats) {
181181
int i;
182182
*len = self->size;
@@ -211,7 +211,7 @@ static int value_count(grib_accessor* a, long* len)
211211
grib_handle* h = grib_handle_of_accessor(a);
212212
grib_context* c = a->context;
213213
double* val = NULL;
214-
int ret;
214+
int ret = GRIB_SUCCESS;
215215
size_t size;
216216

217217
*len = 0;
@@ -251,9 +251,9 @@ static int get_distinct(grib_accessor* a, double** val, long* len)
251251
double* v = NULL;
252252
double* v1 = NULL;
253253
double dummyLon = 0;
254-
int ret = 0;
254+
int ret = GRIB_SUCCESS;
255255
int i;
256-
long jScansPositively = 0; /* default: north to south */
256+
long jScansPositively = 0; // default: north to south
257257
size_t size = *len;
258258
grib_context* c = a->context;
259259

@@ -276,14 +276,14 @@ static int get_distinct(grib_accessor* a, double** val, long* len)
276276
grib_iterator_delete(iter);
277277
v = *val;
278278

279-
/* See which direction the latitudes are to be scanned */
279+
// See which direction the latitudes are to be scanned
280280
if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), "jScansPositively", &jScansPositively)))
281281
return ret;
282282
if (jScansPositively) {
283-
qsort(v, *len, sizeof(double), &compare_doubles_ascending); /*South to North*/
283+
qsort(v, *len, sizeof(double), &compare_doubles_ascending); //South to North
284284
}
285285
else {
286-
qsort(v, *len, sizeof(double), &compare_doubles_descending); /*North to South*/
286+
qsort(v, *len, sizeof(double), &compare_doubles_descending); //North to South
287287
}
288288

289289
v1 = (double*)grib_context_malloc_clear(c, size * sizeof(double));
@@ -292,14 +292,14 @@ static int get_distinct(grib_accessor* a, double** val, long* len)
292292
return GRIB_OUT_OF_MEMORY;
293293
}
294294

295-
/* Construct a unique set of lats by filtering out duplicates */
295+
// Construct a unique set of lats by filtering out duplicates
296296
prev = v[0];
297297
v1[0] = prev;
298298
count = 1;
299299
for (i = 1; i < *len; i++) {
300300
if (v[i] != prev) {
301301
prev = v[i];
302-
v1[count] = prev; /* Value different from previous so store it */
302+
v1[count] = prev; // Value different from previous so store it
303303
count++;
304304
}
305305
}

src/grib_expression_class_binop.cc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ static int evaluate_long(grib_expression* g, grib_handle* h, long* lres)
8383
{
8484
long v1 = 0;
8585
long v2 = 0;
86-
int ret;
8786
grib_expression_binop* e = (grib_expression_binop*)g;
8887

8988
// #if DEBUGGING
@@ -100,7 +99,7 @@ static int evaluate_long(grib_expression* g, grib_handle* h, long* lres)
10099
// printf("\n");
101100
// }
102101

103-
ret = grib_expression_evaluate_long(h, e->left, &v1);
102+
int ret = grib_expression_evaluate_long(h, e->left, &v1);
104103
if (ret != GRIB_SUCCESS)
105104
return ret;
106105

@@ -116,8 +115,6 @@ static int evaluate_double(grib_expression* g, grib_handle* h, double* dres)
116115
{
117116
double v1 = 0.0;
118117
double v2 = 0.0;
119-
int ret;
120-
121118
grib_expression_binop* e = (grib_expression_binop*)g;
122119

123120
// #if DEBUGGING
@@ -134,7 +131,7 @@ static int evaluate_double(grib_expression* g, grib_handle* h, double* dres)
134131
// printf("\n");
135132
// }
136133

137-
ret = grib_expression_evaluate_double(h, e->left, &v1);
134+
int ret = grib_expression_evaluate_double(h, e->left, &v1);
138135
if (ret != GRIB_SUCCESS)
139136
return ret;
140137

0 commit comments

Comments
 (0)