mirror of https://github.com/ecmwf/eccodes.git
ECC-1115: fix value count
This commit is contained in:
parent
8114b9a6b3
commit
8aea24d72a
|
@ -16,7 +16,7 @@
|
||||||
CLASS = accessor
|
CLASS = accessor
|
||||||
SUPER = grib_accessor_class_gen
|
SUPER = grib_accessor_class_gen
|
||||||
IMPLEMENTS = get_native_type;init
|
IMPLEMENTS = get_native_type;init
|
||||||
IMPLEMENTS = unpack_string;value_count
|
IMPLEMENTS = unpack_string
|
||||||
MEMBERS = const char* grid_type
|
MEMBERS = const char* grid_type
|
||||||
END_CLASS_DEF
|
END_CLASS_DEF
|
||||||
|
|
||||||
|
@ -34,7 +34,6 @@ or edit "accessor.class" and rerun ./make_class.pl
|
||||||
|
|
||||||
static int get_native_type(grib_accessor*);
|
static int get_native_type(grib_accessor*);
|
||||||
static int unpack_string(grib_accessor*, char*, size_t* len);
|
static int unpack_string(grib_accessor*, char*, size_t* len);
|
||||||
static int value_count(grib_accessor*, long*);
|
|
||||||
static void init(grib_accessor*, const long, grib_arguments*);
|
static void init(grib_accessor*, const long, grib_arguments*);
|
||||||
static void init_class(grib_accessor_class*);
|
static void init_class(grib_accessor_class*);
|
||||||
|
|
||||||
|
@ -60,7 +59,7 @@ static grib_accessor_class _grib_accessor_class_proj_string = {
|
||||||
0, /* describes himself */
|
0, /* describes himself */
|
||||||
0, /* get length of section */
|
0, /* get length of section */
|
||||||
0, /* get length of string */
|
0, /* get length of string */
|
||||||
&value_count, /* get number of values */
|
0, /* get number of values */
|
||||||
0, /* get number of bytes */
|
0, /* get number of bytes */
|
||||||
0, /* get offset to bytes */
|
0, /* get offset to bytes */
|
||||||
&get_native_type, /* get native type */
|
&get_native_type, /* get native type */
|
||||||
|
@ -100,6 +99,7 @@ static void init_class(grib_accessor_class* c)
|
||||||
c->dump = (*(c->super))->dump;
|
c->dump = (*(c->super))->dump;
|
||||||
c->next_offset = (*(c->super))->next_offset;
|
c->next_offset = (*(c->super))->next_offset;
|
||||||
c->string_length = (*(c->super))->string_length;
|
c->string_length = (*(c->super))->string_length;
|
||||||
|
c->value_count = (*(c->super))->value_count;
|
||||||
c->byte_count = (*(c->super))->byte_count;
|
c->byte_count = (*(c->super))->byte_count;
|
||||||
c->byte_offset = (*(c->super))->byte_offset;
|
c->byte_offset = (*(c->super))->byte_offset;
|
||||||
c->sub_section = (*(c->super))->sub_section;
|
c->sub_section = (*(c->super))->sub_section;
|
||||||
|
@ -132,11 +132,11 @@ static void init_class(grib_accessor_class* c)
|
||||||
|
|
||||||
static void init(grib_accessor* a, const long len, grib_arguments* arg)
|
static void init(grib_accessor* a, const long len, grib_arguments* arg)
|
||||||
{
|
{
|
||||||
grib_accessor_proj_string* self = (grib_accessor_proj_string*)a;
|
grib_accessor_proj_string* self = (grib_accessor_proj_string*)a;
|
||||||
grib_handle* h = grib_handle_of_accessor(a);
|
grib_handle* h = grib_handle_of_accessor(a);
|
||||||
|
|
||||||
self->grid_type = grib_arguments_get_name(h, arg, 0);
|
self->grid_type = grib_arguments_get_name(h, arg, 0);
|
||||||
a->length = 0;
|
a->length = 0;
|
||||||
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
|
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
|
||||||
a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC;
|
a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC;
|
||||||
}
|
}
|
||||||
|
@ -149,19 +149,20 @@ static int get_native_type(grib_accessor* a)
|
||||||
static int unpack_string(grib_accessor* a, char* v, size_t* len)
|
static int unpack_string(grib_accessor* a, char* v, size_t* len)
|
||||||
{
|
{
|
||||||
grib_accessor_proj_string* self = (grib_accessor_proj_string*)a;
|
grib_accessor_proj_string* self = (grib_accessor_proj_string*)a;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
size_t size = 64;
|
size_t size = 64;
|
||||||
char grid_type[512] = {0,};
|
char grid_type[512] = {0,};
|
||||||
grib_handle* h = grib_handle_of_accessor(a);
|
grib_handle* h = grib_handle_of_accessor(a);
|
||||||
double earthMajorAxisInMetres = 0, earthMinorAxisInMetres = 0, radius = 0;
|
double earthMajorAxisInMetres = 0, earthMinorAxisInMetres = 0, radius = 0;
|
||||||
|
|
||||||
err = grib_get_string(h, self->grid_type, grid_type, &size);
|
err = grib_get_string(h, self->grid_type, grid_type, &size);
|
||||||
if (err) return err;
|
if (err) return err;
|
||||||
|
|
||||||
if (grib_is_earth_oblate(h)) {
|
if (grib_is_earth_oblate(h)) {
|
||||||
if ((err = grib_get_double_internal(h, "earthMinorAxisInMetres", &earthMinorAxisInMetres)) != GRIB_SUCCESS) return err;
|
if ((err = grib_get_double_internal(h, "earthMinorAxisInMetres", &earthMinorAxisInMetres)) != GRIB_SUCCESS) return err;
|
||||||
if ((err = grib_get_double_internal(h, "earthMajorAxisInMetres", &earthMajorAxisInMetres)) != GRIB_SUCCESS) return err;
|
if ((err = grib_get_double_internal(h, "earthMajorAxisInMetres", &earthMajorAxisInMetres)) != GRIB_SUCCESS) return err;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if ((err = grib_get_double_internal(h, "radius", &radius)) != GRIB_SUCCESS) return err;
|
if ((err = grib_get_double_internal(h, "radius", &radius)) != GRIB_SUCCESS) return err;
|
||||||
earthMinorAxisInMetres = earthMajorAxisInMetres = radius;
|
earthMinorAxisInMetres = earthMajorAxisInMetres = radius;
|
||||||
}
|
}
|
||||||
|
@ -170,13 +171,13 @@ static int unpack_string(grib_accessor* a, char* v, size_t* len)
|
||||||
double LaDInDegrees = 0;
|
double LaDInDegrees = 0;
|
||||||
if ((err = grib_get_double_internal(h, "LaDInDegrees", &LaDInDegrees)) != GRIB_SUCCESS)
|
if ((err = grib_get_double_internal(h, "LaDInDegrees", &LaDInDegrees)) != GRIB_SUCCESS)
|
||||||
return err;
|
return err;
|
||||||
sprintf(v,"+proj=merc +lat_ts=%lf +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +a=%lf +b=%lf",
|
sprintf(v, "+proj=merc +lat_ts=%lf +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +a=%lf +b=%lf",
|
||||||
LaDInDegrees, earthMajorAxisInMetres, earthMinorAxisInMetres);
|
LaDInDegrees, earthMajorAxisInMetres, earthMinorAxisInMetres);
|
||||||
}
|
}
|
||||||
else if (strcmp(grid_type, "polar_stereographic") == 0) {
|
else if (strcmp(grid_type, "polar_stereographic") == 0) {
|
||||||
double centralLongitude, centralLatitude;
|
double centralLongitude, centralLatitude;
|
||||||
long projectionCentreFlag = 0;
|
long projectionCentreFlag = 0;
|
||||||
int has_northPole = 0;
|
int has_northPole = 0;
|
||||||
if ((err = grib_get_double_internal(h, "orientationOfTheGridInDegrees", ¢ralLongitude)) != GRIB_SUCCESS)
|
if ((err = grib_get_double_internal(h, "orientationOfTheGridInDegrees", ¢ralLongitude)) != GRIB_SUCCESS)
|
||||||
return err;
|
return err;
|
||||||
if ((err = grib_get_double_internal(h, "LaDInDegrees", ¢ralLatitude)) != GRIB_SUCCESS)
|
if ((err = grib_get_double_internal(h, "LaDInDegrees", ¢ralLatitude)) != GRIB_SUCCESS)
|
||||||
|
@ -184,7 +185,7 @@ static int unpack_string(grib_accessor* a, char* v, size_t* len)
|
||||||
if ((err = grib_get_long_internal(h, "projectionCentreFlag", &projectionCentreFlag)) != GRIB_SUCCESS)
|
if ((err = grib_get_long_internal(h, "projectionCentreFlag", &projectionCentreFlag)) != GRIB_SUCCESS)
|
||||||
return err;
|
return err;
|
||||||
has_northPole = ((projectionCentreFlag & 128) == 0);
|
has_northPole = ((projectionCentreFlag & 128) == 0);
|
||||||
sprintf(v,"+proj=stere +lat_ts=%lf +lat_0=%s +lon_0=%lf +k_0=1 +x_0=0 +y_0=0 +a=%lf +b=%lf",
|
sprintf(v, "+proj=stere +lat_ts=%lf +lat_0=%s +lon_0=%lf +k_0=1 +x_0=0 +y_0=0 +a=%lf +b=%lf",
|
||||||
centralLatitude, has_northPole ? "90" : "-90", centralLongitude, earthMajorAxisInMetres, earthMinorAxisInMetres);
|
centralLatitude, has_northPole ? "90" : "-90", centralLongitude, earthMajorAxisInMetres, earthMinorAxisInMetres);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -192,13 +193,7 @@ static int unpack_string(grib_accessor* a, char* v, size_t* len)
|
||||||
*len = 0;
|
*len = 0;
|
||||||
return GRIB_NOT_IMPLEMENTED;
|
return GRIB_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
*len = strlen(v)+1;
|
*len = strlen(v) + 1;
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int value_count(grib_accessor* a, long* count)
|
|
||||||
{
|
|
||||||
*count = 16;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue