File: tst_put_vars_two_unlim_dim.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 (79 lines) | stat: -rw-r--r-- 2,145 bytes parent folder | download | duplicates (4)
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
/*! \file

Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014,
2015, 2016, 2017, 2018
University Corporation for Atmospheric Research/Unidata.

See \ref copyright file for more info.

*/

/*
 * Test contributed in support of netCDF issue
 * https://github.com/Unidata/netcdf-c/issues/160
 */

#include <config.h>
#include "netcdf.h"

#include <stdio.h>

int main(int argc, char* argv[])
{
    int ret;
    int ncid;
    int dim1id, dim2id;
    int var1id, var2id;
    size_t start = 0;
    size_t count = 5;
    double vals[] = { 1.0, 2.0, 3.0, 4.0, 5.0 };

    if ((ret = nc_create("tst_put_vars_two_unlim_dim.nc", NC_NETCDF4 | NC_CLOBBER, &ncid))) {
        printf("nc_create(...): error code = %d\n", ret);
        return -1;
    }

    if ((ret = nc_def_dim(ncid, "dim1", NC_UNLIMITED, &dim1id))) {
        printf("nc_def_dim(...\"dim1\"...): error code = %d\n", ret);
        nc_close(ncid);
        return -1;
    }

    if ((ret = nc_def_dim(ncid, "dim2", NC_UNLIMITED, &dim2id))) {
        printf("nc_def_dim(...\"dim1\"...): error code = %d\n", ret);
        nc_close(ncid);
        return -1;
    }

    if ((ret = nc_def_var(ncid, "var1", NC_DOUBLE, 1, &dim1id, &var1id))) {
        printf("nc_def_var(...\"var1\"...): error code = %d\n", ret);
        nc_close(ncid);
        return -1;
    }

    if ((ret = nc_def_var(ncid, "var2", NC_DOUBLE, 1, &dim2id, &var2id))) {
        printf("nc_def_var(...\"var2\"...): error code = %d\n", ret);
        nc_close(ncid);
        return -1;
    }

    if ((ret = nc_put_vars_double(ncid, var1id, &start, &count, NULL, &vals[0])))  {
        printf("nc_put_var_double(...var1id...): error code = %d\n", ret);
        nc_close(ncid);
        return -1;
    }

    if ((ret = nc_put_vars_double(ncid, var2id, &start, &count, NULL, &vals[0])))  {
        printf("nc_put_var_double(...var2id...): error code = %d\n", ret);
        nc_close(ncid);
        return -1;
    }

    if ((ret = nc_close(ncid))) {
        printf("nc_close(...): error code = %d\n", ret);
        return -1;
    }

    return 0;
}