mirror of https://github.com/ecmwf/eccodes.git
Rename template to sample
This commit is contained in:
parent
4112313874
commit
e24fdb90f1
|
@ -1101,8 +1101,8 @@ double grib_power(long s, long n);
|
||||||
long grib_get_binary_scale_fact(double max, double min, long bpval, int* error);
|
long grib_get_binary_scale_fact(double max, double min, long bpval, int* error);
|
||||||
|
|
||||||
/* grib_templates.cc*/
|
/* grib_templates.cc*/
|
||||||
grib_handle* codes_external_template(grib_context* c, ProductKind product_kind, const char* name);
|
grib_handle* codes_external_sample(grib_context* c, ProductKind product_kind, const char* name);
|
||||||
char* get_external_template_path(grib_context* c, const char* name);
|
char* get_external_sample_path(grib_context* c, const char* name);
|
||||||
|
|
||||||
/* grib_dependency.cc*/
|
/* grib_dependency.cc*/
|
||||||
grib_handle* grib_handle_of_accessor(const grib_accessor* a);
|
grib_handle* grib_handle_of_accessor(const grib_accessor* a);
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Jean Baptiste Filippi - 01.11.2005 *
|
* Jean Baptiste Filippi - 01.11.2005 *
|
||||||
* Enrico Fucile *
|
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
#include "grib_api_internal.h"
|
#include "grib_api_internal.h"
|
||||||
|
|
||||||
|
@ -228,7 +227,7 @@ grib_handle* codes_handle_new_from_samples(grib_context* c, const char* name)
|
||||||
fprintf(stderr, "ECCODES DEBUG codes_handle_new_from_samples '%s'\n", name);
|
fprintf(stderr, "ECCODES DEBUG codes_handle_new_from_samples '%s'\n", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
g = codes_external_template(c, PRODUCT_ANY, name);
|
g = codes_external_sample(c, PRODUCT_ANY, name);
|
||||||
if (!g) {
|
if (!g) {
|
||||||
grib_context_log(c, GRIB_LOG_ERROR,
|
grib_context_log(c, GRIB_LOG_ERROR,
|
||||||
"Unable to load sample file '%s.tmpl'\n"
|
"Unable to load sample file '%s.tmpl'\n"
|
||||||
|
@ -256,7 +255,7 @@ grib_handle* grib_handle_new_from_samples(grib_context* c, const char* name)
|
||||||
fprintf(stderr, "ECCODES DEBUG grib_handle_new_from_samples '%s'\n", name);
|
fprintf(stderr, "ECCODES DEBUG grib_handle_new_from_samples '%s'\n", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
g = codes_external_template(c, PRODUCT_GRIB, name);
|
g = codes_external_sample(c, PRODUCT_GRIB, name);
|
||||||
if (!g)
|
if (!g)
|
||||||
grib_context_log(c, GRIB_LOG_ERROR,
|
grib_context_log(c, GRIB_LOG_ERROR,
|
||||||
"Unable to load GRIB sample file '%s.tmpl'\n"
|
"Unable to load GRIB sample file '%s.tmpl'\n"
|
||||||
|
@ -279,7 +278,7 @@ grib_handle* codes_bufr_handle_new_from_samples(grib_context* c, const char* nam
|
||||||
fprintf(stderr, "ECCODES DEBUG bufr_handle_new_from_samples '%s'\n", name);
|
fprintf(stderr, "ECCODES DEBUG bufr_handle_new_from_samples '%s'\n", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
g = codes_external_template(c, PRODUCT_BUFR, name);
|
g = codes_external_sample(c, PRODUCT_BUFR, name);
|
||||||
if (!g) {
|
if (!g) {
|
||||||
grib_context_log(c, GRIB_LOG_ERROR,
|
grib_context_log(c, GRIB_LOG_ERROR,
|
||||||
"Unable to load BUFR sample file '%s.tmpl'\n"
|
"Unable to load BUFR sample file '%s.tmpl'\n"
|
||||||
|
|
|
@ -35,15 +35,15 @@
|
||||||
// return NULL;
|
// return NULL;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
/* Windows always has a colon in pathnames e.g. C:\temp\file. It uses semi-colons as delimiter */
|
// Windows always has a colon in pathnames e.g. C:\temp\file. It uses semi-colons as delimiter
|
||||||
#ifdef ECCODES_ON_WINDOWS
|
#ifdef ECCODES_ON_WINDOWS
|
||||||
#define ECC_PATH_DELIMITER_CHAR ';'
|
#define ECC_PATH_DELIMITER_CHAR ';'
|
||||||
#else
|
#else
|
||||||
#define ECC_PATH_DELIMITER_CHAR ':'
|
#define ECC_PATH_DELIMITER_CHAR ':'
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* if product_kind is PRODUCT_ANY, the type of sample file is determined at runtime */
|
// if product_kind is PRODUCT_ANY, the type of sample file is determined at runtime
|
||||||
static grib_handle* try_product_template(grib_context* c, ProductKind product_kind, const char* dir, const char* name)
|
static grib_handle* try_product_sample(grib_context* c, ProductKind product_kind, const char* dir, const char* name)
|
||||||
{
|
{
|
||||||
char path[1024];
|
char path[1024];
|
||||||
grib_handle* g = NULL;
|
grib_handle* g = NULL;
|
||||||
|
@ -55,10 +55,10 @@ static grib_handle* try_product_template(grib_context* c, ProductKind product_ki
|
||||||
snprintf(path, sizeof(path), "%s/%s.tmpl", dir, name);
|
snprintf(path, sizeof(path), "%s/%s.tmpl", dir, name);
|
||||||
|
|
||||||
if (c->debug) {
|
if (c->debug) {
|
||||||
fprintf(stderr, "ECCODES DEBUG try_product_template product=%s, path='%s'\n", codes_get_product_name(product_kind), path);
|
fprintf(stderr, "ECCODES DEBUG try_product_sample product=%s, path='%s'\n", codes_get_product_name(product_kind), path);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (codes_access(path, F_OK) == 0) { /* 0 means file exists */
|
if (codes_access(path, F_OK) == 0) { // 0 means file exists
|
||||||
FILE* f = codes_fopen(path, "r");
|
FILE* f = codes_fopen(path, "r");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
grib_context_log(c, GRIB_LOG_PERROR, "cannot open %s", path);
|
grib_context_log(c, GRIB_LOG_PERROR, "cannot open %s", path);
|
||||||
|
@ -66,7 +66,7 @@ static grib_handle* try_product_template(grib_context* c, ProductKind product_ki
|
||||||
}
|
}
|
||||||
if (product_kind == PRODUCT_ANY)
|
if (product_kind == PRODUCT_ANY)
|
||||||
{
|
{
|
||||||
/* Determine the product kind from sample file */
|
// Determine the product kind from sample file
|
||||||
char* mesg = NULL;
|
char* mesg = NULL;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
off_t offset = 0;
|
off_t offset = 0;
|
||||||
|
@ -89,7 +89,7 @@ static grib_handle* try_product_template(grib_context* c, ProductKind product_ki
|
||||||
if (product_kind == PRODUCT_BUFR) {
|
if (product_kind == PRODUCT_BUFR) {
|
||||||
g = codes_bufr_handle_new_from_file(c, f, &err);
|
g = codes_bufr_handle_new_from_file(c, f, &err);
|
||||||
} else {
|
} else {
|
||||||
/* Note: Pseudo GRIBs like DIAG and BUDG also come here */
|
// Note: Pseudo GRIBs like DIAG and BUDG also come here
|
||||||
DEBUG_ASSERT(product_kind == PRODUCT_GRIB);
|
DEBUG_ASSERT(product_kind == PRODUCT_GRIB);
|
||||||
g = grib_handle_new_from_file(c, f, &err);
|
g = grib_handle_new_from_file(c, f, &err);
|
||||||
}
|
}
|
||||||
|
@ -102,22 +102,24 @@ static grib_handle* try_product_template(grib_context* c, ProductKind product_ki
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char* try_template_path(grib_context* c, const char* dir, const char* name)
|
static char* try_sample_path(grib_context* c, const char* dir, const char* name)
|
||||||
{
|
{
|
||||||
|
// The ".tmpl" extension is historic. It should have been ".sample"
|
||||||
char path[2048];
|
char path[2048];
|
||||||
if (string_ends_with(name, ".tmpl"))
|
if (string_ends_with(name, ".tmpl"))
|
||||||
snprintf(path, sizeof(path), "%s/%s", dir, name);
|
snprintf(path, sizeof(path), "%s/%s", dir, name);
|
||||||
else
|
else
|
||||||
snprintf(path, sizeof(path), "%s/%s.tmpl", dir, name);
|
snprintf(path, sizeof(path), "%s/%s.tmpl", dir, name);
|
||||||
|
|
||||||
if (codes_access(path, F_OK) == 0) { /* 0 means file exists */
|
if (codes_access(path, F_OK) == 0) { // 0 means file exists
|
||||||
return grib_context_strdup(c, path);
|
return grib_context_strdup(c, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
grib_handle* codes_external_template(grib_context* c, ProductKind product_kind, const char* name)
|
// External here means on disk
|
||||||
|
grib_handle* codes_external_sample(grib_context* c, ProductKind product_kind, const char* name)
|
||||||
{
|
{
|
||||||
const char* base = c->grib_samples_path;
|
const char* base = c->grib_samples_path;
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
|
@ -130,21 +132,21 @@ grib_handle* codes_external_template(grib_context* c, ProductKind product_kind,
|
||||||
while (*base) {
|
while (*base) {
|
||||||
if (*base == ECC_PATH_DELIMITER_CHAR) {
|
if (*base == ECC_PATH_DELIMITER_CHAR) {
|
||||||
*p = 0;
|
*p = 0;
|
||||||
g = try_product_template(c, product_kind, buffer, name);
|
g = try_product_sample(c, product_kind, buffer, name);
|
||||||
if (g)
|
if (g)
|
||||||
return g;
|
return g;
|
||||||
p = buffer;
|
p = buffer;
|
||||||
base++; /*advance past delimiter*/
|
base++; //advance past delimiter
|
||||||
}
|
}
|
||||||
*p++ = *base++;
|
*p++ = *base++;
|
||||||
}
|
}
|
||||||
|
|
||||||
*p = 0;
|
*p = 0;
|
||||||
g = try_product_template(c, product_kind, buffer, name);
|
g = try_product_sample(c, product_kind, buffer, name);
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* get_external_template_path(grib_context* c, const char* name)
|
char* get_external_sample_path(grib_context* c, const char* name)
|
||||||
{
|
{
|
||||||
const char* base = c->grib_samples_path;
|
const char* base = c->grib_samples_path;
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
|
@ -157,7 +159,7 @@ char* get_external_template_path(grib_context* c, const char* name)
|
||||||
while (*base) {
|
while (*base) {
|
||||||
if (*base == ECC_PATH_DELIMITER_CHAR) {
|
if (*base == ECC_PATH_DELIMITER_CHAR) {
|
||||||
*p = 0;
|
*p = 0;
|
||||||
g = try_template_path(c, buffer, name);
|
g = try_sample_path(c, buffer, name);
|
||||||
if (g)
|
if (g)
|
||||||
return g;
|
return g;
|
||||||
p = buffer;
|
p = buffer;
|
||||||
|
@ -167,5 +169,5 @@ char* get_external_template_path(grib_context* c, const char* name)
|
||||||
}
|
}
|
||||||
|
|
||||||
*p = 0;
|
*p = 0;
|
||||||
return g = try_template_path(c, buffer, name);
|
return g = try_sample_path(c, buffer, name);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue