Rename template to sample

This commit is contained in:
shahramn 2024-03-01 23:34:10 +00:00
parent 4112313874
commit e24fdb90f1
3 changed files with 23 additions and 22 deletions

View File

@ -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);
/* grib_templates.cc*/
grib_handle* codes_external_template(grib_context* c, ProductKind product_kind, const char* name);
char* get_external_template_path(grib_context* c, const char* name);
grib_handle* codes_external_sample(grib_context* c, ProductKind product_kind, const char* name);
char* get_external_sample_path(grib_context* c, const char* name);
/* grib_dependency.cc*/
grib_handle* grib_handle_of_accessor(const grib_accessor* a);

View File

@ -10,7 +10,6 @@
/***************************************************************************
* Jean Baptiste Filippi - 01.11.2005 *
* Enrico Fucile *
***************************************************************************/
#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);
}
g = codes_external_template(c, PRODUCT_ANY, name);
g = codes_external_sample(c, PRODUCT_ANY, name);
if (!g) {
grib_context_log(c, GRIB_LOG_ERROR,
"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);
}
g = codes_external_template(c, PRODUCT_GRIB, name);
g = codes_external_sample(c, PRODUCT_GRIB, name);
if (!g)
grib_context_log(c, GRIB_LOG_ERROR,
"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);
}
g = codes_external_template(c, PRODUCT_BUFR, name);
g = codes_external_sample(c, PRODUCT_BUFR, name);
if (!g) {
grib_context_log(c, GRIB_LOG_ERROR,
"Unable to load BUFR sample file '%s.tmpl'\n"

View File

@ -35,15 +35,15 @@
// 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
#define ECC_PATH_DELIMITER_CHAR ';'
#else
#define ECC_PATH_DELIMITER_CHAR ':'
#endif
/* 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)
// if product_kind is PRODUCT_ANY, the type of sample file is determined at runtime
static grib_handle* try_product_sample(grib_context* c, ProductKind product_kind, const char* dir, const char* name)
{
char path[1024];
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);
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");
if (!f) {
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)
{
/* Determine the product kind from sample file */
// Determine the product kind from sample file
char* mesg = NULL;
size_t size = 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) {
g = codes_bufr_handle_new_from_file(c, f, &err);
} 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);
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;
}
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];
if (string_ends_with(name, ".tmpl"))
snprintf(path, sizeof(path), "%s/%s", dir, name);
else
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 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;
char buffer[1024];
@ -130,21 +132,21 @@ grib_handle* codes_external_template(grib_context* c, ProductKind product_kind,
while (*base) {
if (*base == ECC_PATH_DELIMITER_CHAR) {
*p = 0;
g = try_product_template(c, product_kind, buffer, name);
g = try_product_sample(c, product_kind, buffer, name);
if (g)
return g;
p = buffer;
base++; /*advance past delimiter*/
base++; //advance past delimiter
}
*p++ = *base++;
}
*p = 0;
g = try_product_template(c, product_kind, buffer, name);
g = try_product_sample(c, product_kind, buffer, name);
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;
char buffer[1024];
@ -157,7 +159,7 @@ char* get_external_template_path(grib_context* c, const char* name)
while (*base) {
if (*base == ECC_PATH_DELIMITER_CHAR) {
*p = 0;
g = try_template_path(c, buffer, name);
g = try_sample_path(c, buffer, name);
if (g)
return g;
p = buffer;
@ -167,5 +169,5 @@ char* get_external_template_path(grib_context* c, const char* name)
}
*p = 0;
return g = try_template_path(c, buffer, name);
return g = try_sample_path(c, buffer, name);
}