File: tst_chunk_hdf4.c

package info (click to toggle)
netcdf 1:4.7.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 104,952 kB
  • sloc: ansic: 228,683; sh: 10,980; yacc: 2,561; makefile: 1,319; lex: 1,173; xml: 173; awk: 2
file content (102 lines) | stat: -rw-r--r-- 2,595 bytes parent folder | download | duplicates (3)
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
91
92
93
94
95
96
97
98
99
100
101
102
/* This is part of the netCDF package.  Copyright 2005-2011,
   University Corporation for Atmospheric Research/Unidata. See
   COPYRIGHT file for conditions of use.

   Test that NetCDF-4 can read HDF4 files.
   
   Dennis Heimbigner, Ward Fisher, Ed Hartnett
*/
#include <config.h>
#include <nc_tests.h>
#include "err_macros.h"
#include <mfhdf.h>

#define CHUNKEDFILE "ref_chunked.hdf4"
#define CHUNKEDVAR "LandWater"

#define CONTIGFILE "ref_contiguous.hdf4"
#define CONTIGVAR "pres"

#define LAT_LEN 3
#define LON_LEN 2
#define DIMS_2 2

static size_t EXPECTED_CHUNKSIZES[2] = {1,1200};

int
main(int argc, char **argv)
{
   int ncid;
   int varid;
   int rank;
   int d;
   int storage;
   size_t chunksizes[NC_MAX_VAR_DIMS];

   printf("\n*** Testing HDF4/NetCDF-4 chunking API: chunked...");
   {

      /* Open with netCDF */
      if (nc_open(CHUNKEDFILE, NC_NOWRITE, &ncid)) ERR;

      /* Get a variable id */
      if(nc_inq_varid(ncid,CHUNKEDVAR,&varid)) ERR;

      /* get rank */
      if(nc_inq_varndims(ncid,varid,&rank)) ERR;

      /* get chunk info */
      memset(chunksizes,0,sizeof(chunksizes));
      if(nc_inq_var_chunking(ncid,varid,&storage,chunksizes)) ERR;

      if(storage == NC_CONTIGUOUS) {
         fprintf(stderr,"nc_inq_var_chunking did not return CHUNKED\n");
         ERR;
      }

      for(d=0;d<rank;d++) {
         if(EXPECTED_CHUNKSIZES[d] != chunksizes[d]) {
            fprintf(stderr,"chunk size mismatch: [%d] %ld :: %ld\n",d,chunksizes[d],EXPECTED_CHUNKSIZES[d]);
            ERR;
         }
      }
      if (nc_close(ncid)) ERR;
   }
   SUMMARIZE_ERR;

   printf("*** Testing HDF4/NetCDF-4 chunking API: contiguous...");
   {
      /* Open with netCDF */
      if (nc_open(CONTIGFILE, NC_NOWRITE, &ncid)) ERR;

      /* Get a variable id */
      if(nc_inq_varid(ncid,CONTIGVAR,&varid)) ERR;

      /* get rank */
      if(nc_inq_varndims(ncid,varid,&rank)) ERR;

      /* get chunk info */
      memset(chunksizes,0,sizeof(chunksizes));
      if(nc_inq_var_chunking(ncid,varid,&storage,chunksizes)) ERR;

      if(storage != NC_CONTIGUOUS) {
         fprintf(stderr,"nc_inq_var_chunking did not return CONTIGUOUS\n");
         ERR;
      }

      if (nc_close(ncid)) ERR;
   }
   SUMMARIZE_ERR;
   printf("*** Testing HDF4/NetCDF-4 chunking API: contiguous...");
   {
      /* Open with netCDF */
      if (nc_open(CONTIGFILE, 0, &ncid)) ERR;

      if (nc_inq_varid(ncid, CONTIGVAR, &varid)) ERR;
      if (nc_def_var_deflate(ncid, varid, 0, 1, 4) != NC_ENOTNC4) ERR;

      if (nc_close(ncid)) ERR;
   }
   SUMMARIZE_ERR;
   FINAL_RESULTS;
}