Loading...
Searching...
No Matches
g2c_compare.c
Go to the documentation of this file.
#include <ctype.h>
#include <grib2.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int
main(int argc, char **argv)
{
char *path[2];
int verbose = 0;
int index;
int g2cid0, g2cid1;
int c;
int p = 0;
int ret;
opterr = 0;
/* Parse command line arguments. */
while ((c = getopt(argc, argv, "v")) != -1)
{
switch (c)
{
case 'v':
verbose = 1;
break;
case '?':
if (isprint(optopt))
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
else
fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
return 1;
default:
return G2C_ERROR;
}
}
/* Get names of input and output files. */
for (index = optind; index < argc; index++)
{
if (!(path[p] = malloc(sizeof(char) * strlen(argv[index]) + 1)))
return G2C_ENOMEM;
strcpy(path[p], argv[index]);
if (++p == 2)
break;
}
/* Yammer on and on. */
if (verbose)
printf("g2c_compare %s comparing %s and %s.\n", G2C_VERSION, path[0], path[1]);
/* Open the two files. */
g2c_set_log_level(10);
if ((ret = g2c_open(path[0], G2C_NOWRITE, &g2cid0)))
return ret;
if ((ret = g2c_open(path[1], G2C_NOWRITE, &g2cid1)))
return ret;
/* Compare the files. */
if ((ret = g2c_compare(g2cid0, g2cid1)))
return ret;
/* Close the files. */
if ((ret = g2c_close(g2cid0)))
return ret;
if ((ret = g2c_close(g2cid1)))
return ret;
/* Clean up. */
free(path[0]);
free(path[1]);
return 0;
}
main
int main(int argc, char **argv)
Compare two GRIB2 files.
Definition g2c_compare.c:24
g2c_compare
int g2c_compare(int g2cid1, int g2cid2)
Compare the metadata of two open GRIB2 files.
Definition g2ccompare.c:28
g2c_open
int g2c_open(const char *path, int mode, int *g2cid)
Open an existing GRIB2 file.
Definition g2cfile.c:1201
g2c_close
int g2c_close(int g2cid)
Close a GRIB2 file, freeing resources.
Definition g2cfile.c:1367
grib2.h
Header file for NCEPLIBS-g2c library.
G2C_ENOMEM
#define G2C_ENOMEM
Out of memory.
Definition grib2.h:499
G2C_ERROR
#define G2C_ERROR
General error code, returned for some test errors.
Definition grib2.h:491
G2C_VERSION
#define G2C_VERSION
Current version of NCEPLIBS-g2c library.
Definition grib2.h:25
G2C_NOWRITE
#define G2C_NOWRITE
Set read-only access for g2c_open().
Definition grib2.h:275
g2c_set_log_level
int g2c_set_log_level(int new_level)
Use this to set the global log level.
Definition util.c:165