File: tst_zchunks3.c

package info (click to toggle)
netcdf-parallel 1%3A4.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 113,164 kB
  • sloc: ansic: 267,893; sh: 12,869; cpp: 5,822; yacc: 2,613; makefile: 1,813; lex: 1,216; xml: 173; awk: 2
file content (78 lines) | stat: -rw-r--r-- 2,331 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
/* This is part of the netCDF package. Copyright 2018 University
   Corporation for Atmospheric Research/Unidata.  See COPYRIGHT file for
   conditions of use. See www.unidata.ucar.edu for more info.

   Create a chunkable test file for nccopy to test chunking.
*/

#include "ut_includes.h"
#include "test_nczarr_utils.h"

#undef DEBUG

static int ret = NC_NOERR;
#define FILE_NAME "tmp_chunks3.nc"

#define VAR_RANK 7
#define IVAR_NAME "ivar"
#define FVAR_NAME "fvar"
#define NVALS 45360		/* 7 * 4 * 2 * 3 * 5 * 6 * 9 */

/* Make trackable ERR macro replacement */
static int lerr(int stat, const char* file, int lineno) {
    fflush(stdout); /* Make sure our stdout is synced with stderr. */
    err++;
    fprintf(stderr, "Sorry! Unexpected result(%d), %s, line: %d\n",ret,file,lineno);
    fflush(stderr);                                             \
    return 2;                                                   \
}
#define LERR lerr(ret,__FILE__,__LINE__)

static const char *dim_names[VAR_RANK] = {"dim0", "dim1", "dim2", "dim3", "dim4", "dim5", "dim6"};
static const size_t dim_lens[VAR_RANK] = {7, 4, 2, 3, 5, 6, 9};

int
main(int argc, char** argv)
{
    /* file metadata */
    int mode = NC_CLOBBER|NC_NETCDF4;
    int ncid;
    int ivarid, fvarid;
    int ivar_dims[VAR_RANK];
    int fvar_dims[VAR_RANK];
    int ivar_data[NVALS];
    float fvar_data[NVALS];
    int r, i;
    char* file_name = FILE_NAME;

    printf("*** Creating chunkable test file %s...\n", file_name);

    if ((ret=nc_create(FILE_NAME, mode, &ncid))) LERR;
    for(r = 0; r < VAR_RANK; r++) {
	if ((ret=nc_def_dim(ncid, dim_names[r], dim_lens[r], &ivar_dims[r]))) LERR;
	fvar_dims[VAR_RANK - 1 - r] = ivar_dims[r];
    }
    if ((ret=nc_def_var(ncid, IVAR_NAME, NC_INT, VAR_RANK, ivar_dims, &ivarid))) LERR;

    /* fvar is unchanged */
    if ((ret=nc_def_var(ncid, FVAR_NAME, NC_FLOAT, VAR_RANK, fvar_dims, &fvarid))) LERR;
    if ((ret=nc_enddef (ncid))) LERR;

    /* Fill in the data */
    for(i=0; i < NVALS; i++) {
	ivar_data[i] = i;
    }
    if ((ret=nc_put_var(ncid, ivarid, ivar_data))) LERR;

    /* fvar is unchanged */
    for(i=0; i < NVALS; i++) {
        fvar_data[i] = NVALS - i;
    }
    if ((ret=nc_put_var(ncid, fvarid, fvar_data))) LERR;

    if ((ret=nc_close(ncid))) LERR;

    SUMMARIZE_ERR;
    FINAL_RESULTS;

}