File: tst_byterange.c

package info (click to toggle)
netcdf-parallel 1%3A4.7.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 105,352 kB
  • sloc: ansic: 229,114; sh: 11,180; yacc: 2,561; makefile: 1,390; lex: 1,173; xml: 173; awk: 2
file content (90 lines) | stat: -rw-r--r-- 2,026 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
/*********************************************************************
 *   Copyright 1996-2018, UCAR/Unidata
 *   See COPYRIGHT file for copying and redistribution conditions.
 *********************************************************************/

#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifdef HAVE_TIME_H
#include <time.h>
#endif
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_UNISTD_H
#include "unistd.h"
#endif
#ifdef _WIN32
#include <io.h>
#endif

#include "netcdf.h"

/*
https://github.com/Unidata/netcdf-c/issues/1251
*/

struct TESTURLS {
    int format; /* instance of NC_FORMATX_XXX */
    const char* url;
} testurls[] = {
{NC_FORMAT_CLASSIC,"http://remotetest.unidata.ucar.edu/thredds/fileServer/testdata/2004050300_eta_211.nc#bytes"},
#ifdef USE_NETCDF4
{NC_FORMAT_NETCDF4,"http://noaa-goes16.s3.amazonaws.com/ABI-L1b-RadC/2017/059/03/OR_ABI-L1b-RadC-M3C13_G16_s20170590337505_e20170590340289_c20170590340316.nc#mode=bytes"},
#endif
{0,NULL}
};

static int lineno = 0;

static int
fail(int ret)
{
    if(ret != NC_NOERR) {
        fprintf(stderr,"*** Fail: line: %d: (%d) %s\n", lineno, ret, nc_strerror(ret));
        fflush(stderr);
    }
    return ret;
}

static int
dotest(struct TESTURLS* test)
{
    int ret = NC_NOERR;
    int ncid;
    int format = -1;

    fprintf(stderr,"Test: url=%s\n",test->url);
    /* First, try to open the url */
    if((ret = nc_open(test->url,0,&ncid))) return fail(ret);

    /* Verify format */
    if((ret = nc_inq_format(ncid,&format))) return fail(ret);
    if(format != test->format) {
	printf("%s: format mismatch: expected %d received %d\n",__FILE__,test->format,format);
	return fail(NC_EINVAL);
    }

    if((ret = nc_close(ncid))) return fail(ret);

    return ret;
}

int
main()
{
    int ret = NC_NOERR;
    struct TESTURLS* test = NULL;

    for(test=testurls;test->format;test++) {
	if((ret=dotest(test))) goto done;
    }

done:
    return ret;
}