eccodes/tools/codes_info.cc

178 lines
6.2 KiB
C++
Raw Permalink Normal View History

2015-01-16 16:35:11 +00:00
/*
2020-01-28 14:32:34 +00:00
* (C) Copyright 2005- ECMWF.
2015-01-16 16:35:11 +00:00
*
* 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_tools.h"
2020-01-22 13:10:59 +00:00
extern char* optarg;
extern int optind;
#ifdef ECCODES_ON_WINDOWS
#include "wingetopt.h"
#endif
2020-01-22 13:10:59 +00:00
static void usage_and_exit(const char* progname)
{
printf("\nUsage: %s [-v] [-d] [-s]\n", progname);
printf("\t-v\tPrint only the version of ecCodes\n");
printf("\t-d\tPrint only the definitions path\n");
printf("\t-s\tPrint only the samples path\n");
2017-09-01 16:52:05 +00:00
exit(1);
}
2015-01-16 16:35:11 +00:00
#define INFO_PRINT_ALL 0
#define INFO_PRINT_VERSION (1 << 0)
2020-01-22 13:10:59 +00:00
#define INFO_PRINT_DEFINITION_PATH (1 << 1)
#define INFO_PRINT_SAMPLES_PATH (1 << 2)
2015-01-16 16:35:11 +00:00
2020-12-22 17:45:35 +00:00
static void print_debug_info(grib_context* context)
{
int memfs = 0, aec = 0;
#ifdef HAVE_MEMFS
memfs = 1;
#endif
#ifdef HAVE_AEC
aec = 1;
#endif
const char* git_branch = grib_get_git_branch();
const char* git_sha1 = grib_get_git_sha1();
if (strlen(git_branch) > 0)
grib_context_log(context, GRIB_LOG_DEBUG, "Git branch: %s", git_branch);
if (strlen(git_sha1) > 0)
grib_context_log(context, GRIB_LOG_DEBUG, "Git SHA1: %s", git_sha1);
grib_context_log(context, GRIB_LOG_DEBUG, "Build date: %s", codes_get_build_date());
2021-11-24 14:24:29 +00:00
grib_context_log(context, GRIB_LOG_DEBUG, "Features:");
grib_context_log(context, GRIB_LOG_DEBUG, " HAVE_AEC=%d", aec);
grib_context_log(context, GRIB_LOG_DEBUG, " HAVE_JPEG=%d", HAVE_JPEG);
grib_context_log(context, GRIB_LOG_DEBUG, " HAVE_LIBJASPER=%d", HAVE_LIBJASPER);
grib_context_log(context, GRIB_LOG_DEBUG, " HAVE_LIBOPENJPEG=%d", HAVE_JPEG);
grib_context_log(context, GRIB_LOG_DEBUG, " HAVE_LIBPNG=%d", HAVE_LIBPNG);
grib_context_log(context, GRIB_LOG_DEBUG, " HAVE_ECCODES_THREADS=%d", GRIB_PTHREADS);
#ifdef GRIB_OMP_THREADS
grib_context_log(context, GRIB_LOG_DEBUG, " HAVE_ECCODES_OMP_THREADS=%d", GRIB_OMP_THREADS);
#endif
grib_context_log(context, GRIB_LOG_DEBUG, " HAVE_MEMFS=%d", memfs);
}
2020-01-22 13:10:59 +00:00
int main(int argc, char* argv[])
2015-01-16 16:35:11 +00:00
{
2020-01-22 13:10:59 +00:00
char* path = NULL;
int nfiles = 0;
unsigned long print_flags = 0;
int major = ECCODES_MAJOR_VERSION;
int minor = ECCODES_MINOR_VERSION;
int revision = ECCODES_REVISION_VERSION;
grib_context* context = grib_context_get_default();
2015-01-16 16:35:11 +00:00
while (1) {
2020-01-22 13:10:59 +00:00
int c = getopt(argc, argv, "vds");
2015-01-16 16:35:11 +00:00
if (c == -1)
break;
switch (c) {
2020-01-22 13:10:59 +00:00
case 'v':
print_flags |= INFO_PRINT_VERSION;
break;
case 'd':
print_flags |= INFO_PRINT_DEFINITION_PATH;
break;
case 's':
print_flags |= INFO_PRINT_SAMPLES_PATH;
break;
default:
usage_and_exit(argv[0]);
2015-01-16 16:35:11 +00:00
}
}
2020-01-22 13:10:59 +00:00
nfiles = argc - optind;
if (nfiles != 0)
usage_and_exit(argv[0]);
2015-01-16 16:35:11 +00:00
2020-01-22 13:10:59 +00:00
if (print_flags == INFO_PRINT_ALL) {
print_debug_info(context);
2015-01-16 16:35:11 +00:00
printf("\n");
printf("%s Version %d.%d.%d", grib_get_package_name(), major, minor, revision);
2019-03-27 12:33:27 +00:00
2020-01-22 13:10:59 +00:00
if (ECCODES_MAJOR_VERSION < 1)
printf(" PRE-RELEASE");
2019-03-27 12:33:27 +00:00
2015-01-16 16:35:11 +00:00
printf("\n");
printf("\n");
2020-01-22 13:10:59 +00:00
if ((path = getenv("ECCODES_DEFINITION_PATH")) != NULL) {
2015-01-16 16:35:11 +00:00
printf("Definition files path from environment variable");
2020-01-22 13:10:59 +00:00
printf(" ECCODES_DEFINITION_PATH=%s\n", path);
printf("Full definition files path=%s\n", context->grib_definition_files_path);
2020-01-22 13:10:59 +00:00
}
else if ((path = getenv("GRIB_DEFINITION_PATH")) != NULL) {
printf("Definition files path from environment variable");
2020-01-22 13:10:59 +00:00
printf(" GRIB_DEFINITION_PATH=%s\n", path);
printf(
"(This is for backward compatibility. "
"It is recommended you use ECCODES_DEFINITION_PATH instead!)\n");
printf("Full definition files path=%s\n", context->grib_definition_files_path);
2020-01-22 13:10:59 +00:00
}
else {
printf("Default definition files path is used: %s\n", context->grib_definition_files_path);
printf("Definition files path can be changed by setting the ECCODES_DEFINITION_PATH environment variable.\n");
}
2021-02-07 22:06:42 +00:00
if ((path = getenv("ECCODES_EXTRA_DEFINITION_PATH")) != NULL) {
printf("Environment variable ECCODES_EXTRA_DEFINITION_PATH=%s\n", path);
2015-01-16 16:35:11 +00:00
}
printf("\n");
2020-01-22 13:10:59 +00:00
if ((path = getenv("ECCODES_SAMPLES_PATH")) != NULL) {
2015-01-16 16:35:11 +00:00
printf("SAMPLES path from environment variable");
2020-01-22 13:10:59 +00:00
printf(" ECCODES_SAMPLES_PATH=%s\n", path);
}
else if ((path = getenv("GRIB_SAMPLES_PATH")) != NULL) {
printf("SAMPLES path from environment variable");
2020-01-22 13:10:59 +00:00
printf(" GRIB_SAMPLES_PATH=%s\n", path);
printf(
"(This is for backward compatibility. "
"It is recommended you use ECCODES_SAMPLES_PATH instead!)\n");
}
else {
2024-02-26 13:21:23 +00:00
printf("Default samples path is used: %s\n", context->grib_samples_path);
printf("Samples path can be changed by setting the ECCODES_SAMPLES_PATH environment variable.\n");
}
if ((path = getenv("ECCODES_EXTRA_SAMPLES_PATH")) != NULL) {
printf("Environment variable ECCODES_EXTRA_SAMPLES_PATH=%s\n", path);
2015-01-16 16:35:11 +00:00
}
printf("\n");
return 0;
}
if (print_flags & INFO_PRINT_VERSION)
printf("%d.%d.%d", major, minor, revision);
2015-01-16 16:35:11 +00:00
if (print_flags & INFO_PRINT_DEFINITION_PATH) {
2020-01-22 13:10:59 +00:00
if ((path = codes_getenv("ECCODES_DEFINITION_PATH")) != NULL) {
printf("%s", path);
}
else {
printf("%s", context->grib_definition_files_path);
2015-01-16 16:35:11 +00:00
}
}
if (print_flags & INFO_PRINT_SAMPLES_PATH) {
2020-01-22 13:10:59 +00:00
if ((path = codes_getenv("ECCODES_SAMPLES_PATH")) != NULL) {
printf("%s", path);
}
else {
2020-02-07 13:20:44 +00:00
printf("%s", context->grib_samples_path);
2015-01-16 16:35:11 +00:00
}
}
return 0;
}