eccodes/tools/codes_info.c

146 lines
4.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-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) {
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 (context->debug) {
2018-04-20 15:48:06 +00:00
grib_context_log(context, GRIB_LOG_DEBUG, "Git SHA1=%s", grib_get_git_sha1());
}
2015-01-29 15:49:23 +00:00
#if GRIB_PTHREADS
2018-04-20 15:48:06 +00:00
grib_context_log(context, GRIB_LOG_DEBUG, "POSIX threads enabled\n");
#elif GRIB_OMP_THREADS
grib_context_log(context, GRIB_LOG_DEBUG, "OMP threads enabled\n");
2016-06-21 13:36:35 +00:00
#endif
#ifdef HAVE_MEMFS
2018-04-20 15:48:06 +00:00
grib_context_log(context, GRIB_LOG_DEBUG, "MEMFS enabled");
2015-01-29 15:49:23 +00:00
#endif
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);
}
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");
}
else {
printf("Default definition files path is used: %s\n", context->grib_definition_files_path);
2018-12-28 12:00:18 +00:00
printf("Definition files path can be changed by setting ECCODES_DEFINITION_PATH environment variable\n");
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 {
printf("Default SAMPLES path is used: %s\n", ECCODES_SAMPLES_PATH);
2018-12-28 12:00:18 +00:00
printf("SAMPLES path can be changed by setting ECCODES_SAMPLES_PATH environment variable\n");
2015-01-16 16:35:11 +00:00
}
printf("\n");
return 0;
}
if (print_flags & INFO_PRINT_VERSION)
2020-01-22 13:10:59 +00:00
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 {
printf("%s", ECCODES_SAMPLES_PATH);
2015-01-16 16:35:11 +00:00
}
}
return 0;
}