File: tst_dimsizes.c

package info (click to toggle)
netcdf 1%3A4.4.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 96,828 kB
  • ctags: 15,369
  • sloc: ansic: 163,650; sh: 9,294; yacc: 2,457; makefile: 1,208; lex: 1,161; xml: 173; f90: 7; fortran: 6; awk: 2
file content (81 lines) | stat: -rw-r--r-- 2,998 bytes parent folder | download
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 <nc_tests.h>
#include "err_macros.h"
#include <stdio.h>
#include <stdlib.h>
#include <netcdf.h>

#define FILECLASSIC "tst_dimsize_classic.nc"
#define FILE64OFFSET "tst_dimsize_64offset.nc"
#define FILE64DATA "tst_dimsize_64data.nc"

#define DIMMAXCLASSIC (NC_MAX_INT - 3)
#define DIMMAX64OFFSET (NC_MAX_UINT - 3)
#define DIMMAX64DATA (NC_MAX_UINT64 - 3)

/*
Test that at least the meta-data works
for dimension sizes X modes.
NC_CLASSIC => NC_INT_MAX - 3
NC_64BIT_OFFSET => NC_UINT_MAX - 3
NC_64BIT_DATA => NC_UINT64_MAX - 3
Note that this will not test the last case when
|size_t| == 4.
Also, leave the files around so we can test with ncdump.
*/

int
main(int argc, char **argv)
{
    int ncid;
    size_t dimsize;
    int dimid;
    int stat = NC_NOERR;

    printf("\n*** Testing Max Dimension Sizes\n");

    printf("\n|size_t|=%lu\n",(unsigned long)sizeof(size_t));

    printf("\n*** Writing Max Dimension Size For NC_CLASSIC\n");
    if ((stat=nc_create(FILECLASSIC, NC_CLOBBER, &ncid))) ERRSTAT(stat);
    dimsize = DIMMAXCLASSIC;
    if ((stat=nc_def_dim(ncid, "testdim", dimsize, &dimid))) ERRSTAT(stat);
    if ((stat=nc_close(ncid))) ERRSTAT(stat);

    printf("\n*** Reading Max Dimension Size For NC_CLASSIC\n");
    if ((stat=nc_open(FILECLASSIC, NC_NOCLOBBER, &ncid))) ERRSTAT(stat);
    if ((stat=nc_inq_dimid(ncid, "testdim", &dimid))) ERRSTAT(stat);
    if ((stat=nc_inq_dimlen(ncid, dimid, &dimsize))) ERRSTAT(stat);
    if(dimsize != DIMMAXCLASSIC) ERR;
    if ((stat=nc_close(ncid))) ERRSTAT(stat);

    printf("\n*** Writing Max Dimension Size For NC_64BIT_OFFSET\n");
    if ((stat=nc_create(FILE64OFFSET, NC_CLOBBER | NC_64BIT_OFFSET, &ncid))) ERRSTAT(stat);
    dimsize = DIMMAX64OFFSET;
    if ((stat=nc_def_dim(ncid, "testdim", dimsize, &dimid))) ERRSTAT(stat);
    if ((stat=nc_close(ncid))) ERRSTAT(stat);

    printf("\n*** Reading Max Dimension Size For NC_64BIT_OFFSET\n");
    if ((stat=nc_open(FILE64OFFSET, NC_NOCLOBBER|NC_64BIT_OFFSET, &ncid))) ERRSTAT(stat);
    if ((stat=nc_inq_dimid(ncid, "testdim", &dimid))) ERRSTAT(stat);
    if ((stat=nc_inq_dimlen(ncid, dimid, &dimsize))) ERRSTAT(stat);
    if(dimsize != DIMMAX64OFFSET) ERR;
    if ((stat=nc_close(ncid))) ERRSTAT(stat);

    if(sizeof(size_t) == 8) {
        printf("\n*** Writing Max Dimension Size For NC_64BIT_DATA\n");
        if ((stat=nc_create(FILE64DATA, NC_CLOBBER | NC_64BIT_DATA, &ncid))) ERRSTAT(stat);
        dimsize = (size_t)DIMMAX64DATA;
        if ((stat=nc_def_dim(ncid, "testdim", dimsize, &dimid))) ERRSTAT(stat);
        if ((stat=nc_close(ncid))) ERRSTAT(stat);

	printf("\n*** Reading Max Dimension Size For NC_64BIT_DATA\n");
	if ((stat=nc_open(FILE64DATA, NC_NOCLOBBER|NC_64BIT_DATA, &ncid))) ERRSTAT(stat);
	if ((stat=nc_inq_dimid(ncid, "testdim", &dimid))) ERRSTAT(stat);
	if ((stat=nc_inq_dimlen(ncid, dimid, &dimsize))) ERRSTAT(stat);
	if(dimsize != DIMMAX64DATA) ERR;
	if ((stat=nc_close(ncid))) ERRSTAT(stat);
    }

    SUMMARIZE_ERR;
    FINAL_RESULTS;
}