2020-05-31 07:36:25 +08:00
|
|
|
/*********************************************************************
|
|
|
|
* Copyright 2018, UCAR/Unidata
|
|
|
|
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
|
|
|
|
* $Header: /upc/share/CVS/netcdf-3/ncgen3/main.c,v 1.20 2010/03/31 18:18:40 dmh Exp $
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#include <string.h>
|
|
|
|
#ifdef HAVE_GETOPT_H
|
|
|
|
#include <getopt.h>
|
|
|
|
#endif
|
|
|
|
|
2021-05-27 04:27:27 +08:00
|
|
|
#if defined(_WIN32) && !defined(__MINGW32__)
|
2020-05-31 07:36:25 +08:00
|
|
|
#include "XGetopt.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "netcdf.h"
|
2021-01-29 11:11:01 +08:00
|
|
|
#include "netcdf_aux.h"
|
2020-05-31 07:36:25 +08:00
|
|
|
#include "ncbytes.h"
|
2020-10-14 09:12:15 +08:00
|
|
|
#include "ncpathmgr.h"
|
2020-05-31 07:36:25 +08:00
|
|
|
|
|
|
|
extern void NCD4_dumpbytes(size_t size, const void* data0, int swap);
|
|
|
|
extern void NCD4_tagdump(size_t size, const void* data0, int swap, const char* tag);
|
|
|
|
|
|
|
|
static char* progname = NULL;
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
|
|
|
fprintf(stderr,"Usage: %s [ -O ][ -f infile | file ]",progname);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
char* fname = NULL;
|
|
|
|
char* tag = NULL;
|
|
|
|
size_t offset = 0;
|
|
|
|
size_t len = 0;
|
2023-01-19 10:47:29 +08:00
|
|
|
char* data0 = NULL;
|
2020-05-31 07:36:25 +08:00
|
|
|
char* data = NULL;
|
|
|
|
int swap = 0;
|
|
|
|
|
|
|
|
progname = strdup(argv[0]);
|
|
|
|
|
|
|
|
while ((c = getopt(argc, argv, "SO:f:t:")) != EOF) {
|
|
|
|
switch(c) {
|
|
|
|
case 'f':
|
|
|
|
fname = strdup(optarg);
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
tag = strdup(optarg);
|
|
|
|
break;
|
|
|
|
case 'S':
|
|
|
|
swap = 1;
|
|
|
|
break;
|
|
|
|
case 'O':
|
|
|
|
offset = atol(optarg);
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if(fname == NULL) {
|
|
|
|
if (argc > 1) {
|
|
|
|
fprintf(stderr,"%s: only one input file argument permitted",progname);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
fname = strdup(argv[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(tag == NULL) tag = strdup(progname);
|
2023-01-19 10:47:29 +08:00
|
|
|
if(ncaux_readfile(fname,&len,(void**)&data0)) usage();
|
|
|
|
if(offset >= len) {
|
|
|
|
fprintf(stderr,"Offset too large: file length = %u\n",(unsigned)len);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
data = data0 + offset;
|
2020-05-31 07:36:25 +08:00
|
|
|
NCD4_tagdump(len,data,swap,tag);
|
2023-01-19 10:47:29 +08:00
|
|
|
nullfree(data0);
|
|
|
|
nullfree(fname);
|
|
|
|
nullfree(tag);
|
2020-05-31 07:36:25 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|