2018-12-07 06:36:53 +08:00
|
|
|
/* This is part of the netCDF package. Copyright 2018 University
|
2010-09-01 06:41:00 +08:00
|
|
|
Corporation for Atmospheric Research/Unidata. See COPYRIGHT file for
|
|
|
|
conditions of use. See www.unidata.ucar.edu for more info.
|
|
|
|
|
|
|
|
Create a compressible test file for nccopy to compress.
|
|
|
|
|
2017-11-17 04:03:35 +08:00
|
|
|
Russ Rew, Ward Fisher, Dennis Heimbigner
|
2010-09-01 06:41:00 +08:00
|
|
|
*/
|
|
|
|
|
2017-03-09 08:01:10 +08:00
|
|
|
#include "config.h"
|
2010-09-01 06:41:00 +08:00
|
|
|
#include <nc_tests.h>
|
2016-10-22 01:17:39 +08:00
|
|
|
#include "err_macros.h"
|
2010-09-01 06:41:00 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <netcdf.h>
|
|
|
|
|
|
|
|
#define FILENAME "tst_inflated.nc"
|
2011-06-21 23:10:17 +08:00
|
|
|
#define FILENAME2 "tst_inflated4.nc"
|
2010-09-01 06:41:00 +08:00
|
|
|
#define DIM_NAME "dim1"
|
|
|
|
#define DIM1_LEN 10000
|
|
|
|
#define VAR1_RANK 1
|
|
|
|
#define VAR_NAME "var"
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv) { /* create a compressible file, for testing */
|
|
|
|
|
|
|
|
int ncid;
|
|
|
|
int dimid, varid;
|
|
|
|
int var1_dims[VAR1_RANK]; /* variable shapes */
|
|
|
|
int var1_data[DIM1_LEN]; /* data to write */
|
|
|
|
int i;
|
|
|
|
|
2011-06-24 01:15:01 +08:00
|
|
|
printf("*** Creating compressible test files %s, %s...", FILENAME, FILENAME2);
|
2010-09-01 06:41:00 +08:00
|
|
|
if (nc_create(FILENAME, NC_CLOBBER, &ncid)) ERR;
|
|
|
|
if (nc_def_dim(ncid, "dim1", DIM1_LEN, &dimid)) ERR;
|
|
|
|
var1_dims[0] = dimid;
|
|
|
|
if (nc_def_var(ncid, "var1", NC_INT, VAR1_RANK, var1_dims, &varid)) ERR;
|
|
|
|
if (nc_enddef (ncid)) ERR;
|
|
|
|
for(i=0; i < DIM1_LEN; i++) {
|
2021-08-17 00:06:45 +08:00
|
|
|
var1_data[i] = i / 3; /* Want integer division / truncation */
|
2010-09-01 06:41:00 +08:00
|
|
|
}
|
|
|
|
if (nc_put_var(ncid, varid, var1_data)) ERR;
|
|
|
|
if (nc_close(ncid)) ERR;
|
2011-06-21 23:10:17 +08:00
|
|
|
|
|
|
|
if (nc_create(FILENAME2, NC_CLOBBER|NC_NETCDF4, &ncid)) ERR;
|
|
|
|
if (nc_def_dim(ncid, "dim1", DIM1_LEN, &dimid)) ERR;
|
|
|
|
var1_dims[0] = dimid;
|
|
|
|
if (nc_def_var(ncid, "var1", NC_INT, VAR1_RANK, var1_dims, &varid)) ERR;
|
|
|
|
if (nc_enddef (ncid)) ERR;
|
|
|
|
for(i=0; i < DIM1_LEN; i++) {
|
2021-08-17 00:06:45 +08:00
|
|
|
var1_data[i] = i / 3; /* Want integer division / truncation */
|
2011-06-21 23:10:17 +08:00
|
|
|
}
|
|
|
|
if (nc_put_var(ncid, varid, var1_data)) ERR;
|
|
|
|
if (nc_close(ncid)) ERR;
|
|
|
|
|
2010-09-01 06:41:00 +08:00
|
|
|
SUMMARIZE_ERR;
|
|
|
|
FINAL_RESULTS;
|
|
|
|
}
|