Move is_index_file to grib_index.c

This commit is contained in:
Shahram Najm 2020-07-14 22:11:45 +01:00
parent 0bdf0a5acd
commit 3aac9157d5
3 changed files with 35 additions and 32 deletions

View File

@ -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);

View File

@ -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;
}

View File

@ -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;