Added helper functions

This commit is contained in:
Shahram Najm 2015-07-27 13:27:03 +01:00
parent e1d7323fb9
commit 281815dd12
4 changed files with 30 additions and 33 deletions

View File

@ -1349,6 +1349,8 @@ int is_productDefinitionTemplateNumber_EPS(long productDefinitionTemplateNumber)
int is_productDefinitionTemplateNumber_Chemical(long productDefinitionTemplateNumber);
int is_productDefinitionTemplateNumber_Aerosol(long productDefinitionTemplateNumber);
int is_index_file(const char *filename);
char get_dir_separator_char();
const char* extract_filename(const char* filepath);
/* compile.c */
void grib_compile_flags(grib_compiler *c, long flags);

View File

@ -330,7 +330,8 @@ static grib_trie* init_list(const char* name) {
return 0;
}
static void print_values(grib_context* c,const grib_util_grid_spec* spec,const double* data_values,size_t data_values_count,const grib_values *values,int count) {
static void print_values(grib_context* c,const grib_util_grid_spec* spec, const double* data_values,size_t data_values_count,const grib_values *values,int count)
{
int i;
printf("GRIB_API DEBUG grib_util grib_set_values: setting %d values \n",count);
@ -365,9 +366,6 @@ static void print_values(grib_context* c,const grib_util_grid_spec* spec,const d
}
}
#define ISECTION_2 3000
#define ISECTION_4 512
grib_handle* grib_util_set_spec(grib_handle* h,
const grib_util_grid_spec *spec,
const grib_util_packing_spec *packing_spec,
@ -1033,7 +1031,6 @@ grib_handle* grib_util_set_spec(grib_handle* h,
return NULL;
}
int grib_moments(grib_handle* h,double east,double north,double west,double south,int order,double* moments,long *count) {
grib_iterator* iter=NULL;
int ret=0,i,j,l;
@ -1317,3 +1314,23 @@ int is_index_file(const char* filename)
return ret;
}
char get_dir_separator_char()
{
#ifdef ECCODES_ON_WINDOWS
# define DIR_SEPARATOR_CHAR '\\'
#else
# define DIR_SEPARATOR_CHAR '/'
#endif
return DIR_SEPARATOR_CHAR;
}
/* Return the component after final slash */
/* "/tmp/x" -> "x" */
/* "/tmp/" -> "" */
const char* extract_filename(const char* filepath)
{
char* s = strrchr(filepath, get_dir_separator_char());
if (!s) return filepath;
else return s + 1;
}

View File

@ -10,19 +10,6 @@
#include "grib_tools.h"
#ifdef ECCODES_ON_WINDOWS
# define DIR_SEPARATOR_CHAR '\\'
#else
# define DIR_SEPARATOR_CHAR '/'
#endif
static const char* basename(const char* path)
{
char* s = strrchr(path, DIR_SEPARATOR_CHAR);
if (!s) return path;
else return s + 1;
}
GRIB_INLINE static int grib_inline_strcmp(const char* a,const char* b)
{
if (*a != *b) return 1;
@ -342,7 +329,9 @@ int grib_tool_init(grib_runtime_options* options)
char bufr[2048] = {0,};
/* options->infile_extra->name is the 1st file */
sprintf(bufr, "%s%c%s",
infile->name, DIR_SEPARATOR_CHAR, basename(options->infile_extra->name));
infile->name,
get_dir_separator_char(),
extract_filename(options->infile_extra->name));
infile->name = strdup(bufr);
}
}

View File

@ -10,19 +10,6 @@
#include "grib_tools.h"
#ifdef ECCODES_ON_WINDOWS
# define DIR_SEPARATOR_CHAR '\\'
#else
# define DIR_SEPARATOR_CHAR '/'
#endif
static const char* basename(const char* path)
{
char* s = strrchr(path, DIR_SEPARATOR_CHAR);
if (!s) return path;
else return s + 1;
}
GRIB_INLINE static int grib_inline_strcmp(const char* a,const char* b)
{
if (*a != *b) return 1;
@ -308,7 +295,9 @@ int grib_tool_init(grib_runtime_options* options)
char bufr[2048] = {0,};
/* options->infile_extra->name is the 1st file */
sprintf(bufr, "%s%c%s",
infile->name, DIR_SEPARATOR_CHAR, basename(options->infile_extra->name));
infile->name,
get_dir_separator_char(),
extract_filename(options->infile_extra->name));
infile->name = strdup(bufr);
}
}