testing of quantize with scalars

This commit is contained in:
Edward Hartnett 2021-08-29 22:25:57 -06:00
parent 229e101569
commit f5e2926f02

View File

@ -200,6 +200,70 @@ main(int argc, char **argv)
}
}
SUMMARIZE_ERR;
printf("**** testing quantization of scalars...");
{
int ncid, varid1, varid2;
int quantize_mode_in, nsd_in;
float float_data[DIM_LEN_1] = {1.1111111};
double double_data[DIM_LEN_1] = {1.111111111111};
/* Create a netcdf-4 file with two scalar vars. */
if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLOBBER, &ncid)) ERR;
if (nc_def_var(ncid, VAR_NAME_1, NC_FLOAT, 0, NULL, &varid1)) ERR;
if (nc_def_var(ncid, VAR_NAME_2, NC_DOUBLE, 0, NULL, &varid2)) ERR;
/* Turn on quantize for both vars. */
if (nc_def_var_quantize(ncid, varid1, NC_QUANTIZE_BITGROOM, NSD_3)) ERR;
if (nc_def_var_quantize(ncid, varid2, NC_QUANTIZE_BITGROOM, NSD_3)) ERR;
/* Write some data. */
if (nc_put_var_float(ncid, varid1, float_data)) ERR;
if (nc_put_var_double(ncid, varid2, double_data)) ERR;
/* Close the file. */
if (nc_close(ncid)) ERR;
{
float float_in;
double double_in;
union FU fin;
int nsd_att_in;
/* union FU fout; */
union DU dfin;
/* union DU dfout; */
/* Open the file and check metadata. */
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
if (nc_inq_var_quantize(ncid, 0, &quantize_mode_in, &nsd_in)) ERR;
if (quantize_mode_in != NC_QUANTIZE_BITGROOM || nsd_in != NSD_3) ERR;
if (nc_inq_var_quantize(ncid, 1, &quantize_mode_in, &nsd_in)) ERR;
if (quantize_mode_in != NC_QUANTIZE_BITGROOM || nsd_in != NSD_3) ERR;
/* Each var now has an attribute describing the quantize settings. */
if (nc_get_att_int(ncid, 0, NC_QUANTIZE_ATT_NAME, &nsd_att_in)) ERR;
if (nsd_att_in != NSD_3) ERR;
if (nc_get_att_int(ncid, 1, NC_QUANTIZE_ATT_NAME, &nsd_att_in)) ERR;
if (nsd_att_in != NSD_3) ERR;
/* Check the data. */
if (nc_get_var(ncid, varid1, &float_in)) ERR;
if (nc_get_var(ncid, varid2, &double_in)) ERR;
/* fout.f = float_data[0]; */
fin.f = float_in;
/* dfout.d = double_data[0]; */
dfin.d = double_in;
/* printf ("\nfloat_data: %10f : 0x%x float_data_in: %10f : 0x%x\n", */
/* float_data[0], fout.u, float_data[0], fin.u); */
if (fin.u != 0x3f8e3000) ERR;
/* printf ("\ndouble_data: %15g : 0x%16lx double_data_in: %15g : 0x%lx\n", */
/* double_data[0], dfout.u, double_data[0], dfin.u); */
if (dfin.u != 0x3ff1c60000000000) ERR;
/* Close the file again. */
if (nc_close(ncid)) ERR;
}
}
SUMMARIZE_ERR;
printf("**** testing quantization of one value...");
{
int ncid, dimid, varid1, varid2;
@ -230,7 +294,7 @@ main(int argc, char **argv)
union FU fin;
/* union FU fout; */
union DU dfin;
/* union DU dfout; */
/* union DU dfout; */
/* Open the file and check metadata. */
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;