File: ref_ctest_small_3.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 (81 lines) | stat: -rw-r--r-- 2,010 bytes parent folder | download | duplicates (6)
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
#include <stdio.h>
#include <stdlib.h>
#include <netcdf.h>


void
check_err(const int stat, const int line, const char *file) {
    if (stat != NC_NOERR) {
        (void)fprintf(stderr,"line %d of %s: %s\n", line, file, nc_strerror(stat));
        fflush(stderr);
        exit(1);
    }
}

int
main() {/* create ref_tst_small.nc */

    int  stat;  /* return status */
    int  ncid;  /* netCDF id */

    /* dimension ids */
    int Time_dim;
    int DateStrLen_dim;

    /* dimension lengths */
    size_t Time_len = NC_UNLIMITED;
    size_t DateStrLen_len = 19;

    /* variable ids */
    int Times_id;

    /* rank (number of dimensions) for each variable */
#   define RANK_Times 2

    /* variable shapes */
    int Times_dims[RANK_Times];

    /* enter define mode */
    stat = nc_create("ref_tst_small.nc", NC_CLOBBER, &ncid);
    check_err(stat,__LINE__,__FILE__);

    /* define dimensions */
    stat = nc_def_dim(ncid, "Time", Time_len, &Time_dim);
    check_err(stat,__LINE__,__FILE__);
    stat = nc_def_dim(ncid, "DateStrLen", DateStrLen_len, &DateStrLen_dim);
    check_err(stat,__LINE__,__FILE__);

    /* define variables */

    Times_dims[0] = Time_dim;
    Times_dims[1] = DateStrLen_dim;
    stat = nc_def_var(ncid, "Times", NC_CHAR, RANK_Times, Times_dims, &Times_id);
    check_err(stat,__LINE__,__FILE__);

    /* assign global attributes */

    {
    stat = nc_put_att_text(ncid, NC_GLOBAL, "TITLE", 31, " OUTPUT FROM WRF V2.0.3.1 MODEL");
    check_err(stat,__LINE__,__FILE__);
    }


    /* leave define mode */
    stat = nc_enddef (ncid);
    check_err(stat,__LINE__,__FILE__);

    /* assign variable data */

    {
    char* Times_data = "2005-04-11_12:00:002005-04-11_13:00:00" ;
    size_t Times_startset[2] = {0, 0} ;
    size_t Times_countset[2] = {2, 19};
    stat = nc_put_vara(ncid, Times_id, Times_startset, Times_countset, Times_data);
    check_err(stat,__LINE__,__FILE__);
    }


    stat = nc_close(ncid);
    check_err(stat,__LINE__,__FILE__);
    return 0;
}