mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-01-30 16:10:44 +08:00
more testing of quantize
This commit is contained in:
parent
8142189892
commit
31dfc1ce15
@ -950,103 +950,134 @@ main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
/* /\* printf("\t**** testing more quantization values with custom fill values..."); *\/ */
|
||||
/* /\* { *\/ */
|
||||
/* /\* #define CUSTOM_FILL_FLOAT 99.99999 *\/ */
|
||||
/* /\* #define CUSTOM_FILL_DOUBLE -99999.99999 *\/ */
|
||||
/* /\* for (q = 0; q < NUM_QUANTIZE_MODES; q++) *\/ */
|
||||
/* /\* { *\/ */
|
||||
/* /\* int ncid, dimid, varid1, varid2; *\/ */
|
||||
/* /\* int quantize_mode_in, nsd_in; *\/ */
|
||||
/* /\* float float_data[DIM_LEN_5] = {1.11111111, CUSTOM_FILL_FLOAT, 9.99999999, 12345.67, CUSTOM_FILL_FLOAT}; *\/ */
|
||||
/* /\* double double_data[DIM_LEN_5] = {1.1111111, CUSTOM_FILL_DOUBLE, 9.999999999, 1234567890.12345, CUSTOM_FILL_DOUBLE}; *\/ */
|
||||
/* /\* float custom_fill_float = CUSTOM_FILL_FLOAT; *\/ */
|
||||
/* /\* double custom_fill_double = CUSTOM_FILL_DOUBLE; *\/ */
|
||||
/* /\* int x; *\/ */
|
||||
printf("\t**** testing more quantization values with custom fill values...");
|
||||
{
|
||||
#define CUSTOM_FILL_FLOAT 99.99999
|
||||
#define CUSTOM_FILL_DOUBLE -99999.99999
|
||||
for (q = 0; q < NUM_QUANTIZE_MODES; q++)
|
||||
{
|
||||
int ncid, dimid, varid1, varid2;
|
||||
int quantize_mode_in, nsd_in;
|
||||
float float_data[DIM_LEN_5] = {1.11111111, CUSTOM_FILL_FLOAT, 9.99999999, 12345.67, CUSTOM_FILL_FLOAT};
|
||||
double double_data[DIM_LEN_5] = {1.1111111, CUSTOM_FILL_DOUBLE, 9.999999999, 1234567890.12345, CUSTOM_FILL_DOUBLE};
|
||||
float custom_fill_float = CUSTOM_FILL_FLOAT;
|
||||
double custom_fill_double = CUSTOM_FILL_DOUBLE;
|
||||
int x;
|
||||
|
||||
/* /\* printf("\t\t**** testing quantize algorithm %d...\n", quantize_mode[q]); *\/ */
|
||||
printf("\t\t**** testing quantize algorithm %d...\n", quantize_mode[q]);
|
||||
|
||||
/* /\* /\\* 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_5, &dimid)) ERR; *\/ */
|
||||
/* /\* if (nc_def_var(ncid, VAR_NAME_1, NC_FLOAT, NDIM1, &dimid, &varid1)) ERR; *\/ */
|
||||
/* /\* if (nc_put_att_float(ncid, varid1, _FillValue, NC_FLOAT, 1, &custom_fill_float)) ERR; *\/ */
|
||||
/* /\* if (nc_def_var(ncid, VAR_NAME_2, NC_DOUBLE, NDIM1, &dimid, &varid2)) ERR; *\/ */
|
||||
/* /\* if (nc_put_att_double(ncid, varid2, _FillValue, NC_DOUBLE, 1, &custom_fill_double)) 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_5, &dimid)) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME_1, NC_FLOAT, NDIM1, &dimid, &varid1)) ERR;
|
||||
if (nc_put_att_float(ncid, varid1, _FillValue, NC_FLOAT, 1, &custom_fill_float)) ERR;
|
||||
if (nc_def_var(ncid, VAR_NAME_2, NC_DOUBLE, NDIM1, &dimid, &varid2)) ERR;
|
||||
if (nc_put_att_double(ncid, varid2, _FillValue, NC_DOUBLE, 1, &custom_fill_double)) 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; *\/ */
|
||||
/* 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;
|
||||
|
||||
/* /\* /\\* For classic mode, we must call enddef. *\\/ *\/ */
|
||||
/* /\* if (m) *\/ */
|
||||
/* /\* if (nc_enddef(ncid)) 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; *\/ */
|
||||
/* 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; *\/ */
|
||||
/* Close the file. */
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* /\* { *\/ */
|
||||
/* /\* float float_in[DIM_LEN_5]; *\/ */
|
||||
/* /\* double double_in[DIM_LEN_5]; *\/ */
|
||||
/* /\* union FU { *\/ */
|
||||
/* /\* float f; *\/ */
|
||||
/* /\* uint32_t u; *\/ */
|
||||
/* /\* }; *\/ */
|
||||
{
|
||||
float float_in[DIM_LEN_5];
|
||||
double double_in[DIM_LEN_5];
|
||||
union FU {
|
||||
float f;
|
||||
uint32_t u;
|
||||
};
|
||||
|
||||
/* /\* union FU fin; *\/ */
|
||||
/* /\* /\\* union FU fout; *\\/ *\/ */
|
||||
/* /\* union FU xpect[DIM_LEN_5]; *\/ */
|
||||
/* /\* union DU dfin; *\/ */
|
||||
/* /\* /\\* union DU dfout; *\\/ *\/ */
|
||||
/* /\* union DU double_xpect[DIM_LEN_5]; *\/ */
|
||||
/* /\* xpect[0].u = 0x3f8e3000; *\/ */
|
||||
/* /\* xpect[1].u = 0x42c7ffff; *\/ */
|
||||
/* /\* xpect[2].u = 0x41200000; *\/ */
|
||||
/* /\* xpect[3].u = 0x4640efff; *\/ */
|
||||
/* /\* xpect[4].u = 0x42c7ffff; *\/ */
|
||||
/* /\* double_xpect[0].u = 0x3ff1c60000000000; *\/ */
|
||||
/* /\* double_xpect[1].u = 0xc0f869fffff583a5; *\/ */
|
||||
/* /\* double_xpect[2].u = 0x4023fe0000000000; *\/ */
|
||||
/* /\* double_xpect[3].u = 0x41d265ffffffffff; *\/ */
|
||||
/* /\* double_xpect[4].u = 0xc0f869fffff583a5; *\/ */
|
||||
union FU fin;
|
||||
/* union FU fout; */
|
||||
union FU xpect[NUM_QUANTIZE_MODES][DIM_LEN_5];
|
||||
union DU dfin;
|
||||
/* union DU dfout; */
|
||||
union DU double_xpect[NUM_QUANTIZE_MODES][DIM_LEN_5];
|
||||
switch (quantize_mode[q])
|
||||
{
|
||||
case NC_QUANTIZE_BITGROOM:
|
||||
xpect[0][0].u = 0x3f8e3000;
|
||||
xpect[0][1].u = 0x42c7ffff;
|
||||
xpect[0][2].u = 0x41200000;
|
||||
xpect[0][3].u = 0x4640efff;
|
||||
xpect[0][4].u = 0x42c7ffff;
|
||||
double_xpect[0][0].u = 0x3ff1c60000000000;
|
||||
double_xpect[0][1].u = 0xc0f869fffff583a5;
|
||||
double_xpect[0][2].u = 0x4023fe0000000000;
|
||||
double_xpect[0][3].u = 0x41d265ffffffffff;
|
||||
double_xpect[0][4].u = 0xc0f869fffff583a5;
|
||||
break;
|
||||
case NC_QUANTIZE_GRANULARBR:
|
||||
xpect[1][0].u = 0x3f8e0000;
|
||||
xpect[1][1].u = 0x7cf00000;
|
||||
xpect[1][2].u = 0x41200000;
|
||||
xpect[1][3].u = 0x46410000;
|
||||
xpect[1][4].u = 0x7cf00000;
|
||||
double_xpect[1][0].u = 0x3ff1c00000000000;
|
||||
double_xpect[1][1].u = 0x479e000000000000;
|
||||
double_xpect[1][2].u = 0x4024000000000000;
|
||||
double_xpect[1][3].u = 0x41d2600000000000;
|
||||
double_xpect[1][4].u = 0x479e000000000000;
|
||||
break;
|
||||
case NC_QUANTIZE_BITROUND:
|
||||
xpect[2][0].u = 0x3f900000;
|
||||
xpect[2][1].u = 0x7cf00000;
|
||||
xpect[2][2].u = 0x41200000;
|
||||
xpect[2][3].u = 0x46400000;
|
||||
xpect[2][4].u = 0x7cf00000;
|
||||
double_xpect[2][0].u = 0x3ff2000000000000;
|
||||
double_xpect[2][1].u = 0x479e000000000000;
|
||||
double_xpect[2][2].u = 0x4024000000000000;
|
||||
double_xpect[2][3].u = 0x41d2000000000000;
|
||||
double_xpect[2][4].u = 0x479e000000000000;
|
||||
break;
|
||||
default:
|
||||
ERR;
|
||||
}
|
||||
|
||||
/* /\* /\\* 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; *\/ */
|
||||
/* 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; *\/ */
|
||||
/* /\* /\\* printf("\n"); *\\/ *\/ */
|
||||
/* /\* for (x = 0; x < DIM_LEN_5; x++) *\/ */
|
||||
/* /\* { *\/ */
|
||||
/* /\* /\\* fout.f = float_data[x]; *\\/ *\/ */
|
||||
/* /\* fin.f = float_in[x]; *\/ */
|
||||
/* /\* /\\* printf ("float_data: %10f : 0x%x float_data_in: %10f : 0x%x\n", *\\/ *\/ */
|
||||
/* /\* /\\* float_data[x], fout.u, float_data[x], fin.u); *\\/ *\/ */
|
||||
/* /\* if (fin.u != xpect[x].u) ERR; *\/ */
|
||||
/* /\* /\\* dfout.d = double_data[x]; *\\/ *\/ */
|
||||
/* /\* dfin.d = double_in[x]; *\/ */
|
||||
/* /\* /\\* printf("double_data: %15g : 0x%16lx double_data_in: %15g : 0x%16lx\n", *\\/ *\/ */
|
||||
/* /\* /\\* double_data[x], dfout.u, double_data[x], dfin.u); *\\/ *\/ */
|
||||
/* /\* if (dfin.u != double_xpect[x].u) ERR; *\/ */
|
||||
/* /\* } *\/ */
|
||||
/* Check the data. */
|
||||
if (nc_get_var(ncid, varid1, float_in)) ERR;
|
||||
if (nc_get_var(ncid, varid2, double_in)) ERR;
|
||||
printf("\n");
|
||||
for (x = 0; x < DIM_LEN_5; x++)
|
||||
{
|
||||
fout.f = float_data[x];
|
||||
fin.f = float_in[x];
|
||||
printf ("float_data: %10f : 0x%x float_data_in: %10f : 0x%x\n",
|
||||
float_data[x], fout.u, float_data[x], fin.u);
|
||||
dfout.d = double_data[x];
|
||||
dfin.d = double_in[x];
|
||||
printf("double_data: %15g : 0x%16lx double_data_in: %15g : 0x%16lx\n",
|
||||
double_data[x], dfout.u, double_data[x], dfin.u);
|
||||
/* if (fin.u != xpect[q][x].u) ERR; */
|
||||
/* if (dfin.u != double_xpect[q][x].u) ERR; */
|
||||
}
|
||||
|
||||
/* /\* /\\* Close the file again. *\\/ *\/ */
|
||||
/* /\* if (nc_close(ncid)) ERR; *\/ */
|
||||
/* /\* } *\/ */
|
||||
/* /\* } *\/ */
|
||||
/* /\* } *\/ */
|
||||
/* /\* SUMMARIZE_ERR; *\/ */
|
||||
/* Close the file again. */
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
}
|
||||
}
|
||||
SUMMARIZE_ERR;
|
||||
/* /\* printf("\t*** Checking BitGroom values with type conversion between ints and floats..."); *\/ */
|
||||
/* /\* { *\/ */
|
||||
/* /\* for (q = 0; q < NUM_QUANTIZE_MODES; q++) *\/ */
|
||||
|
Loading…
Reference in New Issue
Block a user