GRIB-813: grib_nearest_find does not work on successive calls for Lambert grid

This commit is contained in:
Shahram Najm 2015-08-11 14:00:45 +01:00
parent a42b1e0f80
commit 03bdf4f77c
2 changed files with 15 additions and 15 deletions

View File

@ -65,16 +65,18 @@ int main(int argc, char** argv)
mode=CODES_NEAREST_SAME_GRID | CODES_NEAREST_SAME_POINT;
count=1;
while ((h=codes_fieldset_next_handle(set,&err))!=NULL) {
CODES_CHECK(codes_get_long(h,"step",&step),0);
len=20;
CODES_CHECK(codes_get_string(h,"param",param,&len),0);
CODES_CHECK(codes_get_string(h,"shortName",param,&len),0);
printf("%d %ld %s ",count,step,param);
if (!nearest) nearest=codes_grib_nearest_new(h,&err);
CODES_CHECK(err,0);
CODES_CHECK(codes_grib_nearest_find(nearest,h,lat,lon,mode,lats,lons,values,distances,indexes,&size),0);
for (i=0;i<4;i++) printf("%d %.2f %.2f %g %g - ",
printf("\nIdx\tlat\tlon\tdist\tval\n");
for (i=0;i<4;i++) printf("%d\t%.2f\t%.2f\t%g\t%g\n",
(int)indexes[i],lats[i],lons[i],distances[i],values[i]);
printf("\n");

View File

@ -178,7 +178,8 @@ static int find(grib_nearest* nearest, grib_handle* h,
neighbours[i].m_index=0;
}
if (!nearest->h || (flags & GRIB_NEAREST_SAME_GRID)==0) {
/* GRIB_NEAREST_SAME_GRID not yet implemented */
{
double the_value = 0;
double min_dist = 1e10;
size_t the_index = 0;
@ -219,7 +220,7 @@ static int find(grib_nearest* nearest, grib_handle* h,
self->lats[ilat++]=lat;
self->lons[ilon++]=lon;
}
/* See between which 2 latitudes our point lies */
qsort(self->lats, nvalues, sizeof(double), &compare_doubles_ascending);
grib_binary_search(self->lats, self->lats_count-1, inlat, &idx_upper, &idx_lower);
@ -253,7 +254,7 @@ static int find(grib_nearest* nearest, grib_handle* h,
/* Sort the candidate neighbours in ascending order of distance */
/* The first 4 entries will now be the closest 4 neighbours */
qsort(neighbours, nvalues, sizeof(PointStore), &compare_points);
grib_iterator_delete(iter);
}
nearest->h=h;
@ -265,17 +266,14 @@ static int find(grib_nearest* nearest, grib_handle* h,
}
#endif
if (!self->distances || (flags & GRIB_NEAREST_SAME_POINT)==0
|| (flags & GRIB_NEAREST_SAME_GRID)==0) {
if (!self->distances) {
self->distances=(double*)grib_context_malloc( nearest->context,4*sizeof(double));
}
self->distances[0] = neighbours[0].m_dist;
self->distances[1] = neighbours[1].m_dist;
self->distances[2] = neighbours[2].m_dist;
self->distances[3] = neighbours[3].m_dist;
/* GRIB_NEAREST_SAME_XXX not yet implemented */
if (!self->distances) {
self->distances=(double*)grib_context_malloc( nearest->context,4*sizeof(double));
}
self->distances[0] = neighbours[0].m_dist;
self->distances[1] = neighbours[1].m_dist;
self->distances[2] = neighbours[2].m_dist;
self->distances[3] = neighbours[3].m_dist;
for(i=0; i <4; ++i)
{