NCEPLIBS-g2c  1.8.0
g2c_compare.c
Go to the documentation of this file.
1 
5 #include <ctype.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <unistd.h>
9 #include <grib2.h>
10 
23 int
24 main(int argc, char **argv)
25 {
26  char *path[2];
27  int verbose = 0;
28  int index;
29  int g2cid0, g2cid1;
30  int c;
31  int p = 0;
32  int ret;
33 
34  opterr = 0;
35 
36  /* Parse command line arguments. */
37  while ((c = getopt(argc, argv, "v")) != -1)
38  {
39  switch (c)
40  {
41  case 'v':
42  verbose = 1;
43  break;
44  case '?':
45  if (isprint(optopt))
46  fprintf(stderr, "Unknown option `-%c'.\n", optopt);
47  else
48  fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
49  return 1;
50  default:
51  return G2C_ERROR;
52  }
53  }
54 
55  /* Get names of input and output files. */
56  for (index = optind; index < argc; index++)
57  {
58  if (!(path[p] = malloc(sizeof(char) * strlen(argv[index]) + 1)))
59  return G2C_ENOMEM;
60  strcpy(path[p], argv[index]);
61  if (++p == 2)
62  break;
63  }
64 
65  /* Yammer on and on. */
66  if (verbose)
67  printf("g2c_compare %s comparing %s and %s.\n", G2C_VERSION, path[0], path[1]);
68 
69  /* Open the two files. */
71  if ((ret = g2c_open(path[0], G2C_NOWRITE, &g2cid0)))
72  return ret;
73  if ((ret = g2c_open(path[0], G2C_NOWRITE, &g2cid1)))
74  return ret;
75 
76  /* Compare the files. */
77  if ((ret = g2c_compare(g2cid0, g2cid1)))
78  return ret;
79 
80  /* Close the files. */
81  if ((ret = g2c_close(g2cid0)))
82  return ret;
83  if ((ret = g2c_close(g2cid1)))
84  return ret;
85 
86  /* Clean up. */
87  free(path[0]);
88  free(path[1]);
89 
90  return 0;
91 }
int main(int argc, char **argv)
Compare two GRIB2 files.
Definition: g2c_compare.c:24
int g2c_compare(int g2cid1, int g2cid2)
Compare the metadata of two open GRIB2 files.
Definition: g2ccompare.c:28
int g2c_open(const char *path, int mode, int *g2cid)
Open an existing GRIB2 file.
Definition: g2cfile.c:1193
int g2c_close(int g2cid)
Close a GRIB2 file, freeing resources.
Definition: g2cfile.c:1357
Header file for NCEPLIBS-g2c library.
#define G2C_ENOMEM
Out of memory.
Definition: grib2.h:500
#define G2C_ERROR
General error code, returned for some test errors.
Definition: grib2.h:492
#define G2C_VERSION
Current version of NCEPLIBS-g2c library.
Definition: grib2.h:26
#define G2C_NOWRITE
Set read-only access for g2c_open().
Definition: grib2.h:291
int g2c_set_log_level(int new_level)
Use this to set the global log level.
Definition: util.c:124