summaryrefslogtreecommitdiffstats
path: root/tools/h5repack/h5repack_verify.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/h5repack/h5repack_verify.c')
-rw-r--r--tools/h5repack/h5repack_verify.c232
1 files changed, 211 insertions, 21 deletions
diff --git a/tools/h5repack/h5repack_verify.c b/tools/h5repack/h5repack_verify.c
index f50e018..7f4f636 100644
--- a/tools/h5repack/h5repack_verify.c
+++ b/tools/h5repack/h5repack_verify.c
@@ -20,6 +20,8 @@
extern char *progname;
static int has_filter(hid_t dcpl_id, H5Z_filter_t filtnin);
static int has_layout(hid_t dcpl_id,pack_info_t *obj);
+static int has_filters(hid_t dcpl_id, pack_opt_t *options);
+static int filtcmp( filter_info_t f1, filter_info_t f2);
@@ -46,9 +48,9 @@ int h5repack_verify(const char *fname,
hid_t dcpl_id = -1; /* dataset creation property list ID */
hid_t space_id = -1; /* space ID */
unsigned int i;
- int j;
- trav_table_t *travt = NULL;
- int have = 1;
+ int j;
+ trav_table_t *travt = NULL;
+ int ok = 1;
/* open the file */
if((fid = H5Fopen(fname, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0 )
@@ -77,7 +79,7 @@ int h5repack_verify(const char *fname,
for(j = 0; j < obj->nfilters; j++)
{
if(has_filter(dcpl_id, obj->filter[j].filtn) == 0)
- have = 0;
+ ok = 0;
}
@@ -87,11 +89,11 @@ int h5repack_verify(const char *fname,
*-------------------------------------------------------------------------
*/
if((obj->layout != -1) && (has_layout(dcpl_id, obj) == 0))
- have = 0;
+ ok = 0;
- /*-------------------------------------------------------------------------
- * close
- *-------------------------------------------------------------------------
+ /*-------------------------------------------------------------------------
+ * close
+ *-------------------------------------------------------------------------
*/
if(H5Pclose(dcpl_id) < 0)
goto error;
@@ -142,13 +144,8 @@ int h5repack_verify(const char *fname,
*/
if(options->all_filter == 1)
{
- int k;
-
- for (k = 0; k < options->n_filter_g; k++ )
- {
- if (has_filter(dcpl_id, options->filter_g[k].filtn) == 0)
- have = 0;
- }
+ if (has_filters(dcpl_id, options) == 0)
+ ok = 0;
}
/*-------------------------------------------------------------------------
@@ -162,7 +159,7 @@ int h5repack_verify(const char *fname,
pack.layout = options->layout_g;
pack.chunk = options->chunk_g;
if(has_layout(dcpl_id, &pack) == 0)
- have = 0;
+ ok = 0;
}
@@ -192,7 +189,7 @@ int h5repack_verify(const char *fname,
if (H5Fclose(fid) < 0)
return -1;
- return have;
+ return ok;
error:
H5E_BEGIN_TRY {
@@ -320,10 +317,6 @@ int has_layout(hid_t dcpl_id,
return 1;
}
-
-
-
-
/*-------------------------------------------------------------------------
* Function: h5repack_cmpdcpl
*
@@ -471,3 +464,200 @@ error:
return -1;
}
+
+
+/*-------------------------------------------------------------------------
+ * Function: has_filters
+ *
+ * Purpose: verify if all requested filters are present in the
+ * property list DCPL_ID
+ *
+ * Return: 1 has, 0 does not, -1 error
+ *
+ * Programmer: Pedro Vicente, pvn@hdfgroup.org
+ *
+ * Date: December 3, 2007
+ *
+ *-------------------------------------------------------------------------
+ */
+
+static int has_filters(hid_t dcpl_id, pack_opt_t *options)
+{
+ unsigned nfilters_dcpl; /* number of filters in DCPL*/
+ unsigned nfilters_opt; /* number of filters in OPTIONS*/
+ unsigned filt_flags; /* filter flags */
+ H5Z_filter_t filtn; /* filter identification number */
+ unsigned cd_values[20]; /* filter client data values */
+ size_t cd_nelmts; /* filter client number of values */
+ char f_name[256]; /* filter name */
+ int have = 0; /* flag, filter is present */
+ unsigned i, j; /* index */
+ filter_info_t filter_dcpl[H5_REPACK_MAX_NFILTERS]; /* filter array in the DCPL*/
+ filter_info_t filter_opt[H5_REPACK_MAX_NFILTERS]; /* filter array in options */
+
+ /* get information about filters */
+ if((nfilters_dcpl = H5Pget_nfilters(dcpl_id)) < 0)
+ return -1;
+
+ /* if we do not have filters and the requested filter is NONE, return 1 */
+ if(!nfilters_dcpl &&
+ options->n_filter_g==1 &&
+ options->filter_g[0].filtn == H5Z_FILTER_NONE )
+ return 1;
+
+ /*-------------------------------------------------------------------------
+ * build a list with DCPL filters
+ *-------------------------------------------------------------------------
+ */
+
+ for( i = 0; i < nfilters_dcpl; i++)
+ {
+ cd_nelmts = NELMTS(cd_values);
+ filtn = H5Pget_filter2(dcpl_id, i, &filt_flags, &cd_nelmts,
+ cd_values, sizeof(f_name), f_name, NULL);
+
+ filter_dcpl[i].filtn = filtn;
+ filter_dcpl[i].cd_nelmts = cd_nelmts;
+ for( j = 0; j < cd_nelmts; j++)
+ {
+ filter_dcpl[i].cd_values[j] = cd_values[j];
+
+ }
+
+ }
+
+ /*-------------------------------------------------------------------------
+ * build a list with options filters
+ *-------------------------------------------------------------------------
+ */
+
+ nfilters_opt = options->n_filter_g;
+
+ for( i = 0; i < nfilters_opt; i++)
+ {
+
+ filter_opt[i].filtn = options->filter_g[i].filtn;
+ filter_opt[i].cd_nelmts = options->filter_g[i].cd_nelmts;
+ for( j = 0; j < options->filter_g[i].cd_nelmts; j++)
+ {
+ filter_opt[i].cd_values[j] = options->filter_g[i].cd_values[j];
+
+ }
+
+ }
+
+ /*-------------------------------------------------------------------------
+ * match the 2 lists
+ *-------------------------------------------------------------------------
+ */
+
+
+ if (nfilters_dcpl != nfilters_opt)
+ return 0;
+
+ for( i = 0; i < nfilters_opt; i++)
+ {
+
+ /* criteria is filter compare, returns same as strcmp */
+ if ( filtcmp( filter_dcpl[i], filter_opt[i] ) != 0 )
+ return 0;
+
+
+ }
+
+
+
+ return 1;
+}
+
+
+
+/*-------------------------------------------------------------------------
+ * Function: filtcmp
+ *
+ * Purpose: compare 2 filters
+ *
+ * Return: same as strcmp:
+ * < 0 F1 "less" than F2
+ * 0 F1 identical to F2
+ * > 0 F1 "greater" than F2
+ *
+ * Programmer: Pedro Vicente, pvn@hdfgroup.org
+ *
+ * Date: December 3, 2007
+ *
+ *-------------------------------------------------------------------------
+ */
+static int filtcmp( filter_info_t f1 /*DCPL*/, filter_info_t f2 /*OPT*/)
+{
+ unsigned i;
+
+ /*-------------------------------------------------------------------------
+ * compare cd_nelmts and cd_values
+ *-------------------------------------------------------------------------
+ */
+
+ if ( f1.filtn == 4 ) /* SZIP special case */
+ {
+
+ if ( f1.cd_nelmts != 4 && f2.cd_nelmts != 2 )
+ return -1;
+
+ if ( f2.cd_values[0] != f1.cd_values[2] &&
+ f2.cd_values[1] != f1.cd_values[1] )
+ return -1;
+
+ }
+
+ else if ( f1.filtn == 2 ) /* SHUFFLE returns 1 cd_nelmts */
+ {
+
+ if ( f1.cd_nelmts != 1 && f2.cd_nelmts != 0 )
+ return -1;
+
+ }
+
+ else
+
+ {
+
+ if ( f1.cd_nelmts != f2.cd_nelmts )
+ return -1;
+
+ /* consider different filter values as "less" */
+ for( i = 0; i < f1.cd_nelmts; i++)
+ {
+ if (f1.cd_values[i] != f2.cd_values[i])
+ {
+ return -1;
+ }
+
+ }
+
+ }
+
+ /*-------------------------------------------------------------------------
+ * compare the filter type
+ *-------------------------------------------------------------------------
+ */
+
+
+ if (f1.filtn == f2.filtn)
+ {
+ return 0;
+ }
+ else if (f1.filtn < f2.filtn)
+ {
+ return -1;
+ }
+ else if (f1.filtn > f2.filtn)
+ {
+ return 1;
+ }
+
+ assert(0);
+ return -1;
+
+}
+
+