[svn-r14895] RFC display compression ratio in h5dump

Here's the current behavior of h5dump regarding the printing of the dataset creation property list

For example

./h5dump -H -p -d filters

HDF5 "tfilters.h5" {
DATASET "deflate" {
   DATATYPE  H5T_STD_I32LE
   DATASPACE  SIMPLE { ( 20, 10 ) / ( 20, 10 ) }
   STORAGE_LAYOUT {
      CHUNKED ( 10, 5 )
      SIZE 385 
    }
   FILTERS {
      COMPRESSION DEFLATE { LEVEL 9 }
   }
   FILLVALUE {
      FILL_TIME H5D_FILL_TIME_IFSET
      VALUE  0
   }
   ALLOCATION_TIME {
      H5D_ALLOC_TIME_INCR
   }
}
}


The proposed behavior is to add this information after SIZE

SIZE 385 (51.9%COMPRESSION)

That percentage is obtained trough

Per = (b-a) / a

Where a = theoretical size obtained by multiplying datum size times number of elements
b =  size obtained with H5Dget_storage_size

The final print would look like

HDF5 "tfilters.h5" {
DATASET "deflate" {
   DATATYPE  H5T_STD_I32LE
   DATASPACE  SIMPLE { ( 20, 10 ) / ( 20, 10 ) }
   STORAGE_LAYOUT {
      CHUNKED ( 10, 5 )
      SIZE 385 (51.9%COMPRESSION)
    }
   FILTERS {
      COMPRESSION DEFLATE { LEVEL 9 }
   }
   FILLVALUE {
      FILL_TIME H5D_FILL_TIME_IFSET
      VALUE  0
   }
   ALLOCATION_TIME {
      H5D_ALLOC_TIME_INCR
   }
}
}

tested: windows, linux, solaris
This commit is contained in:
Pedro Vicente Nunes
2008-04-29 14:15:53 -05:00
parent c954ba63a4
commit b2a2c17c44
6 changed files with 77 additions and 8 deletions

View File

@@ -2440,6 +2440,9 @@ static void dump_fill_value(hid_t dcpl,hid_t type_id, hid_t obj_id)
*
* Programmer: pvn
*
* Modifications: pvn, March 28, 2008
* Add a COMPRESSION ratio information for cases when filters are present
*
*-------------------------------------------------------------------------
*/
static void
@@ -2467,6 +2470,7 @@ dump_dcpl(hid_t dcpl_id,hid_t type_id, hid_t obj_id)
unsigned j;
storage_size=H5Dget_storage_size(obj_id);
nfilters = H5Pget_nfilters(dcpl_id);
ioffset=H5Dget_offset(obj_id);
next=H5Pget_external_count(dcpl_id);
strcpy(f_name,"\0");
@@ -2490,7 +2494,72 @@ dump_dcpl(hid_t dcpl_id,hid_t type_id, hid_t obj_id)
HDfprintf(stdout, ", %Hu", chsize[i]);
printf(" %s\n", dump_header_format->dataspacedimend);
indentation(indent + COL);
HDfprintf(stdout, "SIZE %Hu\n ", storage_size);
/* if there are filters, print a compression ratio */
if ( nfilters )
{
hid_t sid = H5Dget_space( obj_id );
hid_t tid = H5Dget_type( obj_id );
size_t datum_size = H5Tget_size( tid );
hsize_t dims[H5S_MAX_RANK];
int ndims = H5Sget_simple_extent_dims( sid, dims, NULL);
hsize_t nelmts = 1;
hsize_t size;
double per = 0;
hssize_t a, b;
int ok = 0;
/* only print the compression ratio for these filters */
for ( i = 0; i < nfilters; i++)
{
cd_nelmts = NELMTS(cd_values);
filtn = H5Pget_filter2(dcpl_id, (unsigned)i, &filt_flags, &cd_nelmts,
cd_values, sizeof(f_name), f_name, NULL);
switch (filtn)
{
case H5Z_FILTER_DEFLATE:
case H5Z_FILTER_SZIP:
case H5Z_FILTER_NBIT:
case H5Z_FILTER_SCALEOFFSET:
ok = 1;
break;
}
}
if (ndims && ok )
{
for (i = 0; i < ndims; i++)
{
nelmts *= dims[i];
}
size = nelmts * datum_size;
a = size; b = storage_size;
if (a!=0)
per = (double) (b-a)/a;
per = -per;
per *=100;
HDfprintf(stdout, "SIZE %Hu (%.1f%%COMPRESSION)\n ", storage_size, per);
}
else
HDfprintf(stdout, "SIZE %Hu\n ", storage_size);
H5Sclose(sid);
H5Tclose(tid);
}
else
{
HDfprintf(stdout, "SIZE %Hu\n ", storage_size);
}
/*end indent */
indent -= COL;
@@ -2559,11 +2628,11 @@ dump_dcpl(hid_t dcpl_id,hid_t type_id, hid_t obj_id)
printf("%s\n",END);
}
}
/*-------------------------------------------------------------------------
/*-------------------------------------------------------------------------
* FILTERS
*-------------------------------------------------------------------------
*/
nfilters = H5Pget_nfilters(dcpl_id);
indentation(indent + COL);
printf("%s %s\n", FILTERS, BEGIN);

View File

@@ -7,7 +7,7 @@ DATASET "all" {
DATASPACE SIMPLE { ( 20, 10 ) / ( 20, 10 ) }
STORAGE_LAYOUT {
CHUNKED ( 10, 5 )
SIZE 458
SIZE 458 (42.8%COMPRESSION)
}
FILTERS {
PREPROCESSING SHUFFLE

View File

@@ -7,7 +7,7 @@ DATASET "deflate" {
DATASPACE SIMPLE { ( 20, 10 ) / ( 20, 10 ) }
STORAGE_LAYOUT {
CHUNKED ( 10, 5 )
SIZE 385
SIZE 385 (51.9%COMPRESSION)
}
FILTERS {
COMPRESSION DEFLATE { LEVEL 9 }

View File

@@ -7,7 +7,7 @@ DATASET "nbit" {
DATASPACE SIMPLE { ( 20, 10 ) / ( 20, 10 ) }
STORAGE_LAYOUT {
CHUNKED ( 10, 5 )
SIZE 76
SIZE 76 (90.5%COMPRESSION)
}
FILTERS {
COMPRESSION NBIT

View File

@@ -7,7 +7,7 @@ DATASET "scaleoffset" {
DATASPACE SIMPLE { ( 20, 10 ) / ( 20, 10 ) }
STORAGE_LAYOUT {
CHUNKED ( 10, 5 )
SIZE 152
SIZE 152 (81.0%COMPRESSION)
}
FILTERS {
COMPRESSION SCALEOFFSET { MIN BITS 4 }

View File

@@ -7,7 +7,7 @@ DATASET "szip" {
DATASPACE SIMPLE { ( 20, 10 ) / ( 20, 10 ) }
STORAGE_LAYOUT {
CHUNKED ( 10, 5 )
SIZE 372
SIZE 372 (53.5%COMPRESSION)
}
FILTERS {
COMPRESSION SZIP {