eccodes/tools/codes_info.c

166 lines
5.6 KiB
C
Raw 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);
2017-09-01 16:52:05 +00:00
exit(1);
}
2015-01-16 16:35:11 +00:00
2020-01-22 13:10:59 +00:00
#define INFO_PRINT_ALL 0
#define INFO_PRINT_VERSION (1 << 0)
#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
grib_context_log(context, GRIB_LOG_DEBUG, "Git SHA1=%s", grib_get_git_sha1());
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_AEC=%d", aec);
grib_context_log(context, GRIB_LOG_DEBUG, "HAVE_ECCODES_THREADS=%d", GRIB_PTHREADS);
grib_context_log(context, GRIB_LOG_DEBUG, "HAVE_ECCODES_OMP_THREADS=%d", GRIB_OMP_THREADS);
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",
2020-01-22 13:10:59 +00:00
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");
}
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 {
2020-02-07 13:20:44 +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;
}