eccodes/tests/codes_set_samples_path.cc

58 lines
1.8 KiB
C++
Raw Permalink Normal View History

2022-07-12 15:03:19 +00:00
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_api_internal.h"
2024-08-19 11:15:22 +00:00
#include "eccodes.h"
2022-07-12 15:03:19 +00:00
/* Windows always has a colon in pathnames e.g. C:\temp\file. So instead we use semi-colons as delimiter */
/* in order to have multiple definitions/samples directories */
#ifdef ECCODES_ON_WINDOWS
#define ECC_PATH_DELIMITER_CHAR ';'
#else
#define ECC_PATH_DELIMITER_CHAR ':'
#endif
int main(int argc, char** argv)
{
grib_handle* h = NULL;
char full_path[2048] = {0,};
const char* sample_name = NULL;
const char* new_dir = NULL;
grib_context* c = NULL;
long paramId = 0;
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(argc == 3);
2022-07-12 15:03:19 +00:00
sample_name = argv[1];
new_dir = argv[2]; /* The directory containing the given sample */
2024-08-19 11:15:22 +00:00
codes_context_set_debug(c, -1);
2022-07-12 15:03:19 +00:00
printf("Initial samples path = %s\n", grib_samples_path(c));
/* Should fail - default samples path does not include ifs_samples dirs */
h = grib_handle_new_from_samples(c, sample_name);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(!h);
2022-07-12 15:03:19 +00:00
snprintf(full_path, 2048, "%s%c%s", new_dir, ECC_PATH_DELIMITER_CHAR, grib_samples_path(c));
2022-07-12 15:03:19 +00:00
printf("Change samples_path to: %s\n", full_path);
2024-08-19 11:15:22 +00:00
codes_context_set_samples_path(c, full_path);
codes_context_set_debug(c, 0);
2022-07-12 15:03:19 +00:00
h = grib_handle_new_from_samples(c, sample_name);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(h);
2022-07-12 15:03:19 +00:00
GRIB_CHECK(grib_get_long(h, "paramId", &paramId), NULL);
2024-12-20 12:58:07 +00:00
ECCODES_ASSERT(paramId == 130);
2022-07-12 15:03:19 +00:00
grib_handle_delete(h);
printf("Success\n");
return 0;
}