NCEPLIBS-g2c  1.8.0
g2c_degrib2.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 g2cid;
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_degrib2 %s summarizing %s into %s.\n", G2C_VERSION, path[0], path[1]);
68 
69  /* Open the GRIB2 file. */
70  if ((ret = g2c_open(path[0], G2C_NOWRITE, &g2cid)))
71  return ret;
72 
73  /* Write the degrib2 summary. */
74  if ((ret = g2c_degrib2(g2cid, path[1])))
75  return ret;
76 
77  /* Close the file. */
78  if ((ret = g2c_close(g2cid)))
79  return ret;
80 
81  /* Free memory. */
82  free(path[0]);
83  free(path[1]);
84 
85  return 0;
86 }
int main(int argc, char **argv)
Compare two GRIB2 files.
Definition: g2c_degrib2.c:24
int g2c_degrib2(int g2cid, const char *fileout)
Write a summary file like the degrib2 utility.
Definition: g2cdegrib2.c:637
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