mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-01-24 16:04:40 +08:00
more quantize testing
This commit is contained in:
parent
1a13b9ed09
commit
82caba1f12
@ -384,65 +384,86 @@ main(int argc, char **argv)
|
||||
SUMMARIZE_ERR;
|
||||
printf("\t**** testing quantization of one value...");
|
||||
{
|
||||
int ncid, dimid, 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 vars. */
|
||||
if (nc_create(FILE_NAME, mode, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM_NAME_1, DIM_LEN_1, &dimid)) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME_1, NC_FLOAT, NDIM1, &dimid, &varid1)) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME_2, NC_DOUBLE, NDIM1, &dimid, &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;
|
||||
|
||||
/* For classic mode, we must call enddef. */
|
||||
if (m)
|
||||
if (nc_enddef(ncid)) 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;
|
||||
|
||||
for (q = 0; q < NUM_QUANTIZE_MODES; q++)
|
||||
{
|
||||
float float_in;
|
||||
double double_in;
|
||||
union FU fin;
|
||||
/* union FU fout; */
|
||||
union DU dfin;
|
||||
/* union DU dfout; */
|
||||
printf("\t\t**** testing quantize algorithm %d...\n", quantize_mode[q]);
|
||||
int ncid, dimid, varid1, varid2;
|
||||
int quantize_mode_in, nsd_in;
|
||||
float float_data[DIM_LEN_1] = {1.1111111};
|
||||
double double_data[DIM_LEN_1] = {1.111111111111};
|
||||
|
||||
/* Open the file and check metadata. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq_varid(ncid,VAR_NAME_1,&varid1)) ERR;
|
||||
if (nc_inq_varid(ncid,VAR_NAME_2,&varid2)) ERR;
|
||||
if (nc_inq_var_quantize(ncid, varid1, &quantize_mode_in, &nsd_in)) ERR;
|
||||
if (quantize_mode_in != NC_QUANTIZE_BITGROOM || nsd_in != NSD_3) ERR;
|
||||
if (nc_inq_var_quantize(ncid, varid2, &quantize_mode_in, &nsd_in)) ERR;
|
||||
if (quantize_mode_in != NC_QUANTIZE_BITGROOM || nsd_in != NSD_3) ERR;
|
||||
/* Create a netcdf-4 file with two vars. */
|
||||
if (nc_create(FILE_NAME, mode, &ncid)) ERR;
|
||||
if (nc_def_dim(ncid, DIM_NAME_1, DIM_LEN_1, &dimid)) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME_1, NC_FLOAT, NDIM1, &dimid, &varid1)) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME_2, NC_DOUBLE, NDIM1, &dimid, &varid2)) 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%16llx double_data_in: %15g : 0x%llx\n", */
|
||||
/* double_data[0], dfout.u, double_data[0], dfin.u); */
|
||||
if (dfin.u != 0x3ff1c60000000000) ERR;
|
||||
/* Turn on quantize for both vars. */
|
||||
if (nc_def_var_quantize(ncid, varid1, quantize_mode[q], NSD_3)) ERR;
|
||||
if (nc_def_var_quantize(ncid, varid2, quantize_mode[q], NSD_3)) ERR;
|
||||
|
||||
/* Close the file again. */
|
||||
/* For classic mode, we must call enddef. */
|
||||
if (m)
|
||||
if (nc_enddef(ncid)) 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;
|
||||
union DU dfin;
|
||||
/* union FU fout; */
|
||||
/* union DU dfout; */
|
||||
|
||||
/* Open the file and check metadata. */
|
||||
if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR;
|
||||
if (nc_inq_varid(ncid,VAR_NAME_1,&varid1)) ERR;
|
||||
if (nc_inq_varid(ncid,VAR_NAME_2,&varid2)) ERR;
|
||||
if (nc_inq_var_quantize(ncid, varid1, &quantize_mode_in, &nsd_in)) ERR;
|
||||
if (quantize_mode_in != quantize_mode[q] || nsd_in != NSD_3) ERR;
|
||||
if (nc_inq_var_quantize(ncid, varid2, &quantize_mode_in, &nsd_in)) ERR;
|
||||
if (quantize_mode_in != quantize_mode[q] || nsd_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]; */
|
||||
/* dfout.d = double_data[0]; */
|
||||
fin.f = float_in;
|
||||
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); */
|
||||
/* printf ("\ndouble_data: %15g : 0x%16lx double_data_in: %15g : 0x%lx\n", */
|
||||
/* double_data[0], dfout.u, double_data[0], dfin.u); */
|
||||
|
||||
/* Check the results, slightly different for each quantize algorithm. */
|
||||
switch (quantize_mode[q])
|
||||
{
|
||||
case NC_QUANTIZE_BITGROOM:
|
||||
if (fin.u != 0x3f8e3000) ERR;
|
||||
if (dfin.u != 0x3ff1c60000000000) ERR;
|
||||
break;
|
||||
case NC_QUANTIZE_GRANULARBR:
|
||||
if (fin.u != 0x3f8e0000) ERR;
|
||||
if (dfin.u != 0x3ff1c00000000000) ERR;
|
||||
break;
|
||||
case NC_QUANTIZE_BITROUND:
|
||||
if (fin.u != 0x3f900000) ERR;
|
||||
if (dfin.u != 0x3ff2000000000000) ERR;
|
||||
break;
|
||||
default:
|
||||
ERR;
|
||||
}
|
||||
|
||||
/* Close the file again. */
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
}
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
|
Loading…
Reference in New Issue
Block a user