mirror of https://github.com/ecmwf/eccodes.git
Allow sample file specification with extension
This commit is contained in:
parent
a2cb76c7ec
commit
aa7e202083
|
@ -55,7 +55,10 @@ static grib_handle* try_template(grib_context* c, const char* dir, const char* n
|
|||
grib_handle* g = NULL;
|
||||
int err = 0;
|
||||
|
||||
sprintf(path, "%s/%s.tmpl", dir, name);
|
||||
if (string_ends_with(name, ".tmpl"))
|
||||
sprintf(path, "%s/%s", dir, name);
|
||||
else
|
||||
sprintf(path, "%s/%s.tmpl", dir, name);
|
||||
|
||||
if (c->debug) {
|
||||
fprintf(stderr, "ECCODES DEBUG try_template path='%s'\n", path);
|
||||
|
@ -83,7 +86,10 @@ static grib_handle* try_bufr_template(grib_context* c, const char* dir, const ch
|
|||
grib_handle* g = NULL;
|
||||
int err = 0;
|
||||
|
||||
sprintf(path, "%s/%s.tmpl", dir, name);
|
||||
if (string_ends_with(name, ".tmpl"))
|
||||
sprintf(path, "%s/%s", dir, name);
|
||||
else
|
||||
sprintf(path, "%s/%s.tmpl", dir, name);
|
||||
|
||||
if (c->debug) {
|
||||
fprintf(stderr, "ECCODES DEBUG try_template path='%s'\n", path);
|
||||
|
@ -108,8 +114,10 @@ static grib_handle* try_bufr_template(grib_context* c, const char* dir, const ch
|
|||
static char* try_template_path(grib_context* c, const char* dir, const char* name)
|
||||
{
|
||||
char path[2048];
|
||||
|
||||
sprintf(path, "%s/%s.tmpl", dir, name);
|
||||
if (string_ends_with(name, ".tmpl"))
|
||||
sprintf(path, "%s/%s", dir, name);
|
||||
else
|
||||
sprintf(path, "%s/%s.tmpl", dir, name);
|
||||
|
||||
if (codes_access(path, F_OK) == 0) {
|
||||
return grib_context_strdup(c, path);
|
||||
|
|
|
@ -31,7 +31,7 @@ int main(int argc, char* argv[])
|
|||
double zval[ILCHAM];
|
||||
int m, n, k;
|
||||
|
||||
GRIB_CHECK(((h = grib_handle_new_from_samples(NULL, "sh_ml_grib2")) == NULL), 0);
|
||||
GRIB_CHECK(((h = grib_handle_new_from_samples(NULL, "sh_ml_grib2.tmpl")) == NULL), 0);
|
||||
|
||||
/* Meteo-France settings */
|
||||
GRIB_CHECK(grib_set_long(h, "centre", 85), 0);
|
||||
|
|
|
@ -58,10 +58,6 @@ int main(int argc, char* argv[])
|
|||
}
|
||||
|
||||
if (resource_type == SAMPLE) {
|
||||
char* t = strstr(resource_path, ".tmpl");
|
||||
if (t) {
|
||||
*t = '\0'; /* get rid of sample file extension (if there) */
|
||||
}
|
||||
full_path = grib_external_template_path(c, resource_path);
|
||||
}
|
||||
else if (resource_type == DEFINITION) {
|
||||
|
@ -101,7 +97,7 @@ int main(int argc, char* argv[])
|
|||
|
||||
grib_context_free(c, full_path);
|
||||
|
||||
printf("Resource written out to file '%s'.\n", out_file);
|
||||
printf("Resource exported to file '%s'.\n", out_file);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue