eccodes/tools/codes_info.c

126 lines
4.2 KiB
C
Raw Normal View History

2015-01-16 16:35:11 +00:00
/*
2018-01-02 11:31:02 +00:00
* Copyright 2005-2018 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"
2017-09-01 16:52:05 +00:00
static void usage_and_exit(const char* progname) {
printf("\nUsage: %s [-v] [-d] [-s]\n",progname);
exit(1);
}
2015-01-16 16:35:11 +00:00
#define INFO_PRINT_ALL 0
#define INFO_PRINT_VERSION (1<<0)
#define INFO_PRINT_DEFINITION_PATH (1<<1)
2015-01-16 16:35:11 +00:00
#define INFO_PRINT_SAMPLES_PATH (1<<2)
int main( int argc,char* argv[])
{
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;
2015-01-16 16:35:11 +00:00
while (1) {
int c = getopt (argc, argv, "vds");
2015-01-16 16:35:11 +00:00
if (c == -1)
break;
switch (c) {
case 'v':
print_flags|=INFO_PRINT_VERSION;
break;
case 'd':
print_flags|=INFO_PRINT_DEFINITION_PATH;
break;
case 's':
2015-01-16 16:35:11 +00:00
print_flags|=INFO_PRINT_SAMPLES_PATH;
break;
default:
2017-09-01 16:52:05 +00:00
usage_and_exit(argv[0]);
2015-01-16 16:35:11 +00:00
}
}
nfiles=argc-optind;
2017-09-01 16:52:05 +00:00
if (nfiles != 0) usage_and_exit(argv[0]);
2015-01-16 16:35:11 +00:00
if (print_flags == INFO_PRINT_ALL) {
2018-04-20 15:48:06 +00:00
grib_context* context = grib_context_get_default();
2015-01-16 16:35:11 +00:00
printf("\n");
printf("%s Version %d.%d.%d",
grib_get_package_name(), major,minor,revision);
2015-03-10 18:20:46 +00:00
/* if (ECCODES_MAJOR_VERSION < 1) printf(" PRE-RELEASE"); */
2015-01-16 16:35:11 +00:00
printf("\n");
printf("\n");
2018-04-20 15:48:06 +00:00
if(context->debug) {
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
if ((path=getenv("ECCODES_DEFINITION_PATH")) != NULL) {
2015-01-16 16:35:11 +00:00
printf("Definition files path from environment variable");
printf(" ECCODES_DEFINITION_PATH=%s\n",path);
} else if ((path=getenv("GRIB_DEFINITION_PATH")) != NULL) {
printf("Definition files path from environment variable");
printf(" GRIB_DEFINITION_PATH=%s\n",path);
printf("(This is for backward compatibility. "
"It is recommended you use ECCODES_DEFINITION_PATH instead!)\n");
2015-01-16 16:35:11 +00:00
} else {
printf("Default definition files path is used: %s\n",ECCODES_DEFINITION_PATH);
printf("Definition files path can be changed setting ECCODES_DEFINITION_PATH environment variable\n");
2015-01-16 16:35:11 +00:00
}
printf("\n");
if ((path=getenv("ECCODES_SAMPLES_PATH")) != NULL) {
2015-01-16 16:35:11 +00:00
printf("SAMPLES path from environment variable");
printf(" ECCODES_SAMPLES_PATH=%s\n",path);
} else if ((path=getenv("GRIB_SAMPLES_PATH")) != NULL) {
printf("SAMPLES path from environment variable");
printf(" GRIB_SAMPLES_PATH=%s\n",path);
printf("(This is for backward compatibility. "
"It is recommended you use ECCODES_SAMPLES_PATH instead!)\n");
2015-01-16 16:35:11 +00:00
} else {
printf("Default SAMPLES path is used: %s\n",ECCODES_SAMPLES_PATH);
printf("SAMPLES path can be changed 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)
printf("%d.%d.%d ",major,minor,revision);
if (print_flags & INFO_PRINT_DEFINITION_PATH) {
if ((path=codes_getenv("ECCODES_DEFINITION_PATH")) != NULL) {
2015-01-16 16:35:11 +00:00
printf("%s",path);
} else {
printf("%s",ECCODES_DEFINITION_PATH);
2015-01-16 16:35:11 +00:00
}
}
if (print_flags & INFO_PRINT_SAMPLES_PATH) {
if ((path=codes_getenv("ECCODES_SAMPLES_PATH")) != NULL) {
2015-01-16 16:35:11 +00:00
printf("%s",path);
} else {
printf("%s",ECCODES_SAMPLES_PATH);
2015-01-16 16:35:11 +00:00
}
}
return 0;
}