diff --git a/src/grib_api_prototypes.h b/src/grib_api_prototypes.h index cc7b0578b..129df97dd 100644 --- a/src/grib_api_prototypes.h +++ b/src/grib_api_prototypes.h @@ -746,6 +746,9 @@ grib_handle* grib_handle_new_from_index(grib_index* index, int* err); grib_handle* codes_new_from_index(grib_index* index, int message_type, int* err); void grib_index_rewind(grib_index* index); int grib_index_search(grib_index* index, grib_index_key* keys); +int codes_index_set_product_kind(grib_index* index, ProductKind product_kind); +int codes_index_set_unpack_bufr(grib_index* index, int unpack); +int is_index_file(const char* filename); /* grib_accessor_class_number_of_points_gaussian.c */ @@ -1476,7 +1479,6 @@ int grib2_is_PDTN_ChemicalDistFunc(long productDefinitionTemplateNumber); int grib2_is_PDTN_Aerosol(long productDefinitionTemplateNumber); int grib2_is_PDTN_AerosolOptical(long productDefinitionTemplateNumber); int grib2_select_PDTN(int is_eps, int is_instant, int is_chemical, int is_chemical_distfn, int is_aerosol, int is_aerosol_optical); -int is_index_file(const char* filename); size_t sum_of_pl_array(const long* pl, size_t plsize); int grib_is_earth_oblate(grib_handle* h); int grib_util_grib_data_quality_check(grib_handle* h, double min_val, double max_val); diff --git a/src/grib_index.c b/src/grib_index.c index f3a16ca85..dfe523335 100644 --- a/src/grib_index.c +++ b/src/grib_index.c @@ -1980,3 +1980,35 @@ int codes_index_set_unpack_bufr(grib_index* index, int unpack) index->unpack_bufr = unpack; return GRIB_SUCCESS; } + +/* Return 1 if the file is an index file. 0 otherwise */ +int is_index_file(const char* filename) +{ + FILE* fh; + char buf[8] = {0,}; + const char* id_grib = "GRBIDX"; + const char* id_bufr = "BFRIDX"; + int ret = 0; + size_t size = 0; + + fh = fopen(filename, "r"); + if (!fh) + return 0; + + size = fread(buf, 1, 1, fh); + if (size != 1) { + fclose(fh); + return 0; + } + size = fread(buf, 6, 1, fh); + if (size != 1) { + fclose(fh); + return 0; + } + + ret = (strcmp(buf, id_grib)==0 || strcmp(buf, id_bufr)==0); + + fclose(fh); + + return ret; +} diff --git a/src/grib_util.c b/src/grib_util.c index 011b5cfb7..15e182d9c 100644 --- a/src/grib_util.c +++ b/src/grib_util.c @@ -2141,37 +2141,6 @@ int grib2_select_PDTN(int is_eps, int is_instant, } } -int is_index_file(const char* filename) -{ - FILE* fh; - char buf[8] = {0,}; - const char* id_grib = "GRBIDX"; - const char* id_bufr = "BFRIDX"; - int ret = 0; - size_t size = 0; - - fh = fopen(filename, "r"); - if (!fh) - return 0; - - size = fread(buf, 1, 1, fh); - if (size != 1) { - fclose(fh); - return 0; - } - size = fread(buf, 6, 1, fh); - if (size != 1) { - fclose(fh); - return 0; - } - - ret = (strcmp(buf, id_grib)==0 || strcmp(buf, id_bufr)==0); - - fclose(fh); - - return ret; -} - size_t sum_of_pl_array(const long* pl, size_t plsize) { long i, count = 0;