NetCDF  4.9.2
filter_example.c File Reference

Example program for write then read of a variable using bzip2 compression. More...

#include "config.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <hdf5.h>
#include "netcdf.h"
#include "netcdf_filter.h"
Include dependency graph for filter_example.c:

Go to the source code of this file.

Macros

#define BZIP2_ID   307
 
#define BZIP2_LEVEL   9
 
#define CHECK(x)   check(x,__LINE__)
 
#define CHUNKSIZE   4 /* Note: not the total size of the chunk, but size wrt a dim*/
 
#define DIMSIZE   4
 
#define ERRR
 
#define MAXERRS   8
 
#define NDIMS   4
 
#define TESTFILE   "bzip2.nc"
 

Functions

static int check (int err, int line)
 
static int compare (void)
 
static void init (int argc, char **argv)
 
int main (int argc, char **argv)
 
static int test_bzip2 (void)
 
static int verifychunks (void)
 

Variables

static size_t actualdims = NDIMS
 
static size_t actualproduct = 1
 
static float * array = NULL
 
static size_t chunkproduct = 1
 
static size_t chunks [NDIMS]
 
static size_t chunksize = CHUNKSIZE
 
static int dimids [NDIMS]
 
static size_t dims [NDIMS]
 
static size_t dimsize = DIMSIZE
 
static float * expected = NULL
 
static unsigned int filterid = 0
 
static int ncid
 
static int nerrs = 0
 
static unsigned int * params = NULL
 
static int varid
 

Detailed Description

Example program for write then read of a variable using bzip2 compression.

This is an example which creates a file with a variable that is compressed using bzip2. Then it reads that file and verifies that it returned the correct uncompressed data.

The meta-data (.cdl) for the created file is as follows:

netcdf bzip2 {
dimensions:
dim0 = 4 ;
dim1 = 4 ;
dim2 = 4 ;
dim3 = 4 ;
variables:
float var(dim0, dim1, dim2, dim3) ;
var:_Storage = "chunked" ;
var:_ChunkSizes = 4, 4, 4, 4 ;
var:_Filter = "307,9" ;
var:_NoFill = "true" ;
data:
var =
0, 1, 2, 3,
4, 5, 6, 7,
...
252, 253, 254, 255 ;
}

Definition in file filter_example.c.

Macro Definition Documentation

◆ ERRR

#define ERRR
Value:
do { \
fflush(stdout); /* Make sure our stdout is synced with stderr. */ \
fprintf(stderr, "Sorry! Unexpected result, %s, line: %d\n", \
__FILE__, __LINE__); \
nerrs++;\
} while (0)

Definition at line 91 of file filter_example.c.