1 /*********************************************************************
2  *   Copyright 2016, UCAR/Unidata
3  *   See netcdf/COPYRIGHT file for copying and redistribution conditions.
4  *********************************************************************/
5 
6 /**
7 This provides a simple netcdf-4 metadata -> xml printer.
8 Primarily for use in debugging, but could be adapted to
9 create other tools.
10 */
11 
12 /**************************************************/
13 
14 #include "config.h"
15 #include <stdlib.h>
16 #include <stdio.h>
17 #include "netcdf.h"
18 #include "ncbytes.h"
19 
20 extern int NC4print(NCbytes* buf, int ncid);
21 
22 int
main(int argc,char ** argv)23 main(int argc, char** argv)
24 {
25     int i;
26     int ret = NC_NOERR;
27 
28     if(argc == 1) {
29 	fprintf(stderr,"usage: nc4printer <file> <file>...\n");
30 	exit(1);
31     }
32     for(i=1;i<argc;i++) {
33 	int ncid;
34 	char* filename;
35         NCbytes* buf;
36 
37 	filename = argv[i];
38 	buf = ncbytesnew();
39 
40 	if((ret = nc_open(filename,NC_NETCDF4,&ncid))) goto fail;
41 
42 	ret = NC4print(buf,ncid);
43 	ncbytesnull(buf);
44 	fprintf(stderr,"========== %s ==========\n",filename);
45 	fprintf(stderr,"%s\n",ncbytescontents(buf));
46 	ncbytesfree(buf);
47     }
48     exit(0);
49 
50 fail:
51     fprintf(stderr,"***Fail: (%d) %s\n",ret,nc_strerror(ret));
52     exit(1);
53 }
54