Refactoring

This commit is contained in:
Shahram Najm 2019-02-20 17:54:43 +00:00
parent 35db3145b8
commit 3f83ce74c3
2 changed files with 22 additions and 24 deletions

View File

@ -49,7 +49,7 @@ int grib_options_count=sizeof(grib_options)/sizeof(grib_option);
double lat=0;
double lon=0;
int mode=0;
grib_nearest* n=NULL;
grib_nearest* nearest=NULL;
int main(int argc, char *argv[])
{
@ -108,9 +108,8 @@ int grib_tool_init(grib_runtime_options* options)
}
if (options->latlon && options->latlon_mask) {
FILE* f=NULL;
grib_handle* hh;
f=fopen(options->latlon_mask,"r");
FILE* f=fopen(options->latlon_mask,"r");
if(!f) {
perror(options->latlon_mask);
exit(1);
@ -118,12 +117,12 @@ int grib_tool_init(grib_runtime_options* options)
hh=grib_handle_new_from_file(0,f,&ret);
fclose(f);
GRIB_CHECK_NOLINE(ret,0);
n=grib_nearest_new(hh,&ret);
nearest=grib_nearest_new(hh,&ret);
GRIB_CHECK_NOLINE(ret,0);
GRIB_CHECK_NOLINE(grib_nearest_find(n,hh,lat,lon,mode,
options->lats,options->lons,options->mask_values,options->distances,options->indexes,&size),0);
grib_nearest_delete(n);
n=NULL;
GRIB_CHECK_NOLINE(grib_nearest_find(nearest,hh,lat,lon,mode,
options->lats,options->lons,options->mask_values,options->distances,options->indexes,&size),0);
grib_nearest_delete(nearest);
nearest=NULL;
grib_handle_delete( hh);
options->latlon_idx=-1;
@ -181,9 +180,9 @@ int grib_tool_new_handle_action(grib_runtime_options* options,grib_handle* h)
int i;
double min;
err=0;
if (!n) n=grib_nearest_new(h,&err);
if (!nearest) nearest=grib_nearest_new(h,&err);
GRIB_CHECK_NOLINE(err,0);
GRIB_CHECK_NOLINE(grib_nearest_find(n,h,lat,lon,0,
GRIB_CHECK_NOLINE(grib_nearest_find(nearest,h,lat,lon,0,
options->lats,options->lons,options->values,
options->distances,options->indexes,&size),0);
min=options->distances[0];
@ -213,7 +212,7 @@ void grib_tool_print_key_values(grib_runtime_options* options,grib_handle* h)
int grib_tool_finalise_action(grib_runtime_options* options)
{
if (n) grib_nearest_delete(n);
if (nearest) grib_nearest_delete(nearest);
return 0;
}

View File

@ -54,7 +54,7 @@ double lon=0;
int mode=0;
static int json_latlon=0;
grib_nearest* n=NULL;
grib_nearest* nearest=NULL;
int main(int argc, char *argv[])
{
@ -122,12 +122,11 @@ int grib_tool_init(grib_runtime_options* options)
}
if (options->latlon && options->latlon_mask) {
FILE* f=NULL;
grib_handle* hh;
int idx=0, land_found=0;
double min_overall = 0.0;
int idx_overall = -1;
f=fopen(options->latlon_mask,"r");
FILE* f=fopen(options->latlon_mask,"r");
if(!f) {
perror(options->latlon_mask);
exit(1);
@ -135,13 +134,13 @@ int grib_tool_init(grib_runtime_options* options)
hh=grib_handle_new_from_file(0,f,&ret);
fclose(f);
GRIB_CHECK_NOLINE(ret,0);
n=grib_nearest_new(hh,&ret);
nearest=grib_nearest_new(hh,&ret);
GRIB_CHECK_NOLINE(ret,0);
GRIB_CHECK_NOLINE(grib_nearest_find(n,hh,lat,lon,mode,
GRIB_CHECK_NOLINE(grib_nearest_find(nearest,hh,lat,lon,mode,
options->lats,options->lons,options->mask_values,options->distances,options->indexes,&size),0);
grib_nearest_delete(n);
n=NULL;
grib_handle_delete( hh);
grib_nearest_delete(nearest);
nearest=NULL;
grib_handle_delete(hh);
options->latlon_idx=-1;
max=options->distances[0];
@ -263,7 +262,7 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
if (options->latlon) {
double min;
err=0;
if (!n) n=grib_nearest_new(h,&err);
if (!nearest) nearest=grib_nearest_new(h,&err);
if (err == GRIB_NOT_IMPLEMENTED) {
char grid_type[100];
size_t grid_type_len=100;
@ -278,9 +277,9 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
if (options->latlon_mask) {
nn_flag = mode; /* ECC-638 */
}
GRIB_CHECK_NOLINE(grib_nearest_find(n,h,lat,lon,nn_flag,
options->lats,options->lons,options->values,
options->distances,options->indexes,&size),0);
GRIB_CHECK_NOLINE(grib_nearest_find(nearest,h,lat,lon,nn_flag,
options->lats,options->lons,options->values,
options->distances,options->indexes,&size),0);
}
if (!options->latlon_mask) {
@ -383,7 +382,7 @@ int grib_tool_finalise_action(grib_runtime_options* options)
}
}
if (n) grib_nearest_delete(n);
if (nearest) grib_nearest_delete(nearest);
if (json_latlon) printf("\n]\n");
return 0;