File: dump.c

package info (click to toggle)
netcdf-parallel 1%3A4.9.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 116,192 kB
  • sloc: ansic: 279,265; sh: 14,143; cpp: 5,971; yacc: 2,612; makefile: 2,075; lex: 1,218; javascript: 280; xml: 173; awk: 2
file content (96 lines) | stat: -rw-r--r-- 2,105 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*********************************************************************
 *   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

#if defined(_WIN32) && !defined(__MINGW32__)
#include "XGetopt.h"
#endif
    
#include "netcdf.h"
#include "netcdf_aux.h"
#include "ncbytes.h"
#include "ncpathmgr.h"

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;
    char* data0 = NULL;
    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);    
    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;
    NCD4_tagdump(len,data,swap,tag);
    nullfree(data0);
    nullfree(fname);
    nullfree(tag);
    return 0;
}