summaryrefslogtreecommitdiffstats
path: root/tools/h5repack
diff options
context:
space:
mode:
Diffstat (limited to 'tools/h5repack')
-rw-r--r--tools/h5repack/h5repack.c36
-rw-r--r--tools/h5repack/h5repack.h3
-rw-r--r--tools/h5repack/h5repack_copy.c84
-rw-r--r--tools/h5repack/h5repack_filters.c14
-rw-r--r--tools/h5repack/h5repack_list.c9
-rw-r--r--tools/h5repack/h5repack_main.c6
-rw-r--r--tools/h5repack/h5repack_opttable.c72
-rw-r--r--tools/h5repack/h5repack_parse.c1
8 files changed, 161 insertions, 64 deletions
diff --git a/tools/h5repack/h5repack.c b/tools/h5repack/h5repack.c
index cfd9363..7ba5a6c 100644
--- a/tools/h5repack/h5repack.c
+++ b/tools/h5repack/h5repack.c
@@ -55,7 +55,7 @@ static void aux_initglb_filter(pack_opt_t *options)
*
* Return: 0, ok, -1, fail
*
- * Programmer: pvn@ncsa.uiuc.edu
+ * Programmer: pvn@ncsa.uiuc.edu
*
* Date: September, 22, 2003
*
@@ -68,7 +68,7 @@ int h5repack(const char* infile,
/* check input */
if (check_options(options)<0)
return -1;
-
+
/* check for objects in input that are in the file */
if (check_objects(infile,options)<0)
return -1;
@@ -76,6 +76,7 @@ int h5repack(const char* infile,
/* copy the objects */
if (copy_objects(infile,outfile,options)<0)
return -1;
+
return 0;
}
@@ -223,7 +224,7 @@ int h5repack_addlayout(const char* str,
*
* Return: void, return -1 on error
*
- * Programmer: pvn@ncsa.uiuc.edu
+ * Programmer: pvn@ncsa.uiuc.edu
*
* Date: September, 22, 2003
*
@@ -242,7 +243,6 @@ static int check_options(pack_opt_t *options)
*/
if (options->verbose)
{
- printf("\n");
printf("Objects to modify layout are...\n");
if (options->all_layout==1) {
printf(" Apply layout to all\n ");
@@ -290,20 +290,22 @@ static int check_options(pack_opt_t *options)
if (options->verbose)
{
- printf("Objects to filter are...\n");
+ printf("Objects to apply filter are...\n");
if (options->all_filter==1)
{
H5Z_filter_t filtn=options->filter_g.filtn;
switch (filtn)
{
case H5Z_FILTER_NONE:
- printf(" Uncompress all %s\n",get_sfilter(filtn));
+ printf(" Uncompress all\n");
break;
- case H5Z_FILTER_SZIP:
- printf(" Compress all with %s compression\n",get_sfilter(filtn));
+ case H5Z_FILTER_SHUFFLE:
+ case H5Z_FILTER_FLETCHER32:
+ printf(" All with %s\n",get_sfilter(filtn));
break;
+ case H5Z_FILTER_SZIP:
case H5Z_FILTER_DEFLATE:
- printf("\tCompress all with %s compression, parameter %d\n",
+ printf(" All with %s, parameter %d\n",
get_sfilter(filtn),
options->filter_g.cd_values[0]);
break;
@@ -320,21 +322,22 @@ static int check_options(pack_opt_t *options)
{
if (options->verbose)
{
- printf(" <%s> with %s filter%s",
+ printf(" <%s> with %s filter\n",
name,
- get_sfilter(pack.filter[j].filtn),
- (i==options->op_tbl->nelems-1)? "" : "\n");
+ get_sfilter(pack.filter[j].filtn));
}
has_cp=1;
-
+
+#if defined (CHECK_SZIP)
+
/*check for invalid combination of options */
switch (pack.filter[j].filtn)
{
default:
break;
case H5Z_FILTER_SZIP:
-
+
szip_pixels_per_block=pack.filter[j].cd_values[0];
/* check szip parameters */
@@ -363,6 +366,9 @@ static int check_options(pack_opt_t *options)
break;
} /* switch */
+
+#endif
+
} /* j */
} /* i */
@@ -381,7 +387,7 @@ static int check_options(pack_opt_t *options)
*
* Return: void, exit on error
*
- * Programmer: pvn@ncsa.uiuc.edu
+ * Programmer: pvn@ncsa.uiuc.edu
*
* Date: September, 22, 2003
*
diff --git a/tools/h5repack/h5repack.h b/tools/h5repack/h5repack.h
index eb05316..3a3a7c0 100644
--- a/tools/h5repack/h5repack.h
+++ b/tools/h5repack/h5repack.h
@@ -21,6 +21,9 @@
#include "h5diff.h"
#include "h5tools.h"
+#define CHECK_SZIP
+
+
#define H5FOPENERROR "unable to open file"
#define PFORMAT "%-7s %-7s %-7s\n" /*chunk info, compression info, name*/
diff --git a/tools/h5repack/h5repack_copy.c b/tools/h5repack/h5repack_copy.c
index e352b97..870f3c7 100644
--- a/tools/h5repack/h5repack_copy.c
+++ b/tools/h5repack/h5repack_copy.c
@@ -26,7 +26,7 @@
*
* Return: 0, ok, -1 no
*
- * Programmer: pvn@ncsa.uiuc.edu
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
*
* Date: October, 23, 2003
*
@@ -45,27 +45,18 @@ int copy_objects(const char* fnamein,
* open the files
*-------------------------------------------------------------------------
*/
-
- /* disable error reporting */
- H5E_BEGIN_TRY {
-
- /* Open the files */
if ((fidin=H5Fopen(fnamein,H5F_ACC_RDONLY,H5P_DEFAULT))<0 ){
printf("h5repack: <%s>: %s\n", fnamein, H5FOPENERROR );
- exit(1);
+ goto out;
}
if ((fidout=H5Fcreate(fnameout,H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT))<0 ){
printf("h5repack: <%s>: Could not create file\n", fnameout );
- exit(1);
+ goto out;
}
- /* enable error reporting */
- } H5E_END_TRY;
-
if (options->verbose)
printf("Making file <%s>...\n",fnameout);
-
/* init table */
trav_table_init(&travt);
@@ -111,15 +102,56 @@ int copy_objects(const char* fnamein,
out:
H5E_BEGIN_TRY {
- H5Fclose(fidin);
- H5Fclose(fidout);
- trav_table_free(travt);
+ H5Fclose(fidin);
+ H5Fclose(fidout);
} H5E_END_TRY;
+ if (travt)
+ trav_table_free(travt);
return -1;
}
+/*-------------------------------------------------------------------------
+ * Function: print_obj
+ *
+ * Purpose: print name and filters of an object
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+void print_obj(pack_info_t *obj, char *name)
+{
+ char str[26]; /*5x5+1*/
+ int i;
+
+ strcpy(str,"\0");
+
+ for ( i=0; i<obj->nfilters; i++)
+ {
+ switch (obj->filter[i].filtn)
+ {
+ default:
+ break;
+ case H5Z_FILTER_DEFLATE:
+ strcat(str,"GZIP ");
+ break;
+ case H5Z_FILTER_SZIP:
+ strcat(str,"SZIP ");
+ break;
+ case H5Z_FILTER_SHUFFLE:
+ strcat(str,"SHUF ");
+ break;
+ case H5Z_FILTER_FLETCHER32:
+ strcat(str,"FLET ");
+ break;
+ } /* switch */
+ }/*i*/
+
+ printf(" %-10s %s %s\n", "dataset",str,name );
+
+}
/*-------------------------------------------------------------------------
@@ -129,7 +161,7 @@ out:
*
* Return: 0, ok, -1 no
*
- * Programmer: pvn@ncsa.uiuc.edu
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
*
* Date: October, 23, 2003
*
@@ -162,6 +194,7 @@ int do_copy_objects(hid_t fidin,
hsize_t dsize_out; /* output dataset size after filter */
#endif /* LATER */
int i, j;
+ int wrote=0;
/*-------------------------------------------------------------------------
* copy the suppplied object list
@@ -208,9 +241,6 @@ int do_copy_objects(hid_t fidin,
*-------------------------------------------------------------------------
*/
case H5G_DATASET:
- if (options->verbose)
- printf(" %-10s %s\n", "dataset",travt->objs[i].name );
-
if ((dset_in=H5Dopen(fidin,travt->objs[i].name))<0)
goto error;
if ((space_id=H5Dget_space(dset_in))<0)
@@ -311,12 +341,11 @@ int do_copy_objects(hid_t fidin,
*/
if ((dset_out=H5Dcreate(fidout,travt->objs[i].name,mtype_id,space_id,dcpl_id))<0)
goto error;
-
if (dsize_in && nelmts) {
if (H5Dwrite(dset_out,mtype_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf)<0)
goto error;
+ wrote=1;
}
-
/*-------------------------------------------------------------------------
* copy attrs
*-------------------------------------------------------------------------
@@ -339,6 +368,11 @@ int do_copy_objects(hid_t fidin,
if (buf)
free(buf);
+
+ if (options->verbose && wrote)
+ print_obj(&obj,travt->objs[i].name );
+
+
}/*H5T_STD_REF_OBJ*/
}/*can_read*/
@@ -488,7 +522,7 @@ error:
*
* Return: 0, ok, -1 no
*
- * Programmer: pvn@ncsa.uiuc.edu
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
*
* Date: October, 28, 2003
*
@@ -565,6 +599,8 @@ int copy_attr(hid_t loc_in,
*/
if ( ! H5Tequal(mtype_id, H5T_STD_REF_OBJ))
{
+
+
/*-------------------------------------------------------------------------
* read to memory
*-------------------------------------------------------------------------
@@ -592,6 +628,7 @@ int copy_attr(hid_t loc_in,
if (H5Aclose(attr_out)<0)
goto error;
+
if (buf)
free(buf);
@@ -629,3 +666,6 @@ error:
return -1;
}
+
+
+
diff --git a/tools/h5repack/h5repack_filters.c b/tools/h5repack/h5repack_filters.c
index 56ab189..61ef4a7 100644
--- a/tools/h5repack/h5repack_filters.c
+++ b/tools/h5repack/h5repack_filters.c
@@ -42,7 +42,7 @@ static void aux_objinsert_filter(pack_info_t *obj,
*
* Return: 0 not found, 1 found
*
- * Programmer: pvn@ncsa.uiuc.edu
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
*
* Date: December 19, 2003
*
@@ -104,7 +104,7 @@ int filter_this(const char* name, /* object name from traverse list */
*
* Return: 0 success, -1 an error occured
*
- * Programmer: pvn@ncsa.uiuc.edu
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
*
* Date: December 19, 2003
*
@@ -206,6 +206,8 @@ int apply_filters(const char* name, /* object name from traverse list */
*/
case H5Z_FILTER_SZIP:
szip_pixels_per_block=obj->filter[i].cd_values[0];
+
+#if defined (CHECK_SZIP)
/* check szip parameters */
if (check_szip(type_id,
obj->chunk.rank,
@@ -214,17 +216,24 @@ int apply_filters(const char* name, /* object name from traverse list */
&szip_pixels_per_block,
options)==1)
{
+#endif
+
/* set up for szip data */
if(H5Pset_chunk(dcpl_id,obj->chunk.rank,obj->chunk.chunk_lengths)<0)
return -1;
if (H5Pset_szip(dcpl_id, szip_options_mask, szip_pixels_per_block)<0)
return -1;
+
+#if defined (CHECK_SZIP)
}
else
{
if (options->verbose)
printf("Warning: SZIP filter cannot be applied to <%s>\n",name);
}
+#endif
+
+
break;
/*-------------------------------------------------------------------------
@@ -260,6 +269,7 @@ out:
}
+
/*-------------------------------------------------------------------------
* Function: print_filters
*
diff --git a/tools/h5repack/h5repack_list.c b/tools/h5repack/h5repack_list.c
index 8c8acee..d3a84e1 100644
--- a/tools/h5repack/h5repack_list.c
+++ b/tools/h5repack/h5repack_list.c
@@ -28,7 +28,7 @@
*
* Return: 0, ok, -1 no
*
- * Programmer: pvn@ncsa.uiuc.edu
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
*
* Date: September, 23, 2003
*
@@ -77,7 +77,6 @@ int check_objects(const char* fname,
if (options->verbose)
{
- printf("\n");
printf("Opening file <%s>. Searching for objects to modify...\n",fname);
}
@@ -90,8 +89,8 @@ int check_objects(const char* fname,
/* the input object names are present in the file and are valid */
if (h5trav_getindext(name,travt)<0)
{
- printf("\nError: Could not find <%s> in file <%s>. Exiting...\n",
- name,fname);
+ printf("%sError: Could not find <%s> in file <%s>. Exiting...\n",
+ (options->verbose?"\n":""),name,fname);
goto out;
}
if (options->verbose)
@@ -120,7 +119,7 @@ out:
*
* Return: void
*
- * Programmer: pvn@ncsa.uiuc.edu
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
*
* Date: October 23, 2003
*
diff --git a/tools/h5repack/h5repack_main.c b/tools/h5repack/h5repack_main.c
index cc3f6ea..810d30f 100644
--- a/tools/h5repack/h5repack_main.c
+++ b/tools/h5repack/h5repack_main.c
@@ -45,7 +45,8 @@ int main(int argc, char **argv)
else if (strcmp(argv[i], "-f") == 0) {
/* add the -f filter option */
- h5repack_addfilter(argv[i+1],&options);
+ if (h5repack_addfilter(argv[i+1],&options)<0)
+ exit(1);
/* jump to next */
++i;
@@ -53,7 +54,8 @@ int main(int argc, char **argv)
else if (strcmp(argv[i], "-l") == 0) {
/* parse the -l layout option */
- h5repack_addlayout(argv[i+1],&options);
+ if (h5repack_addlayout(argv[i+1],&options)<0)
+ exit(1);
/* jump to next */
++i;
diff --git a/tools/h5repack/h5repack_opttable.c b/tools/h5repack/h5repack_opttable.c
index 45dfac5..71cf1a8 100644
--- a/tools/h5repack/h5repack_opttable.c
+++ b/tools/h5repack/h5repack_opttable.c
@@ -72,6 +72,30 @@ static void aux_tblinsert_filter(pack_opttbl_t *table,
}
}
+/*-------------------------------------------------------------------------
+ * Function: aux_tblinsert_layout
+ *
+ * Purpose: auxiliary function, inserts the layout in object OBJS[ I ]
+ *
+ * Return: void
+ *
+ *-------------------------------------------------------------------------
+ */
+
+static void aux_tblinsert_layout(pack_opttbl_t *table,
+ int I,
+ pack_info_t *pack)
+{
+ int k;
+
+ table->objs[I].layout = pack->layout;
+ if (H5D_CHUNKED==pack->layout) {
+ table->objs[I].chunk.rank = pack->chunk.rank;
+ for (k = 0; k < pack->chunk.rank; k++)
+ table->objs[I].chunk.chunk_lengths[k] = pack->chunk.chunk_lengths[k];
+ }
+}
+
/*-------------------------------------------------------------------------
* Function: aux_inctable
@@ -189,7 +213,7 @@ int options_add_layout( obj_list_t *obj_list,
pack_info_t *pack,
pack_opttbl_t *table )
{
- int i, j, k, I, added=0, found=0;
+ int i, j, I, added=0, found=0;
/* increase the size of the collection by N_OBJS if necessary */
if (table->nelems+n_objs >= table->size)
@@ -219,12 +243,7 @@ int options_add_layout( obj_list_t *obj_list,
/* insert the layout info */
else
{
- table->objs[i].layout = pack->layout;
- if (H5D_CHUNKED==pack->layout) {
- table->objs[i].chunk.rank = pack->chunk.rank;
- for (k = 0; k < pack->chunk.rank; k++)
- table->objs[i].chunk.chunk_lengths[k] = pack->chunk.chunk_lengths[k];
- }
+ aux_tblinsert_layout(table,i,pack);
found=1;
break;
}
@@ -237,12 +256,20 @@ int options_add_layout( obj_list_t *obj_list,
I = table->nelems + added;
added++;
strcpy(table->objs[I].path,obj_list[j].obj);
- table->objs[I].layout = pack->layout;
- if (H5D_CHUNKED==pack->layout) {
- table->objs[I].chunk.rank = pack->chunk.rank;
- for (k = 0; k < pack->chunk.rank; k++)
- table->objs[I].chunk.chunk_lengths[k] = pack->chunk.chunk_lengths[k];
+ aux_tblinsert_layout(table,I,pack);
}
+ /* cases where we have an already inserted name but there is a new name also
+ example:
+ -f dset1:GZIP=1 -l dset1,dset2:CHUNK=20x20
+ dset1 is already inserted, but dset2 must also be
+ */
+ else if (found==1 && strcmp(obj_list[j].obj,table->objs[i].path)!=0)
+ {
+ /* keep the grow in a temp var */
+ I = table->nelems + added;
+ added++;
+ strcpy(table->objs[I].path,obj_list[j].obj);
+ aux_tblinsert_layout(table,I,pack);
}
} /* j */
}
@@ -256,12 +283,8 @@ int options_add_layout( obj_list_t *obj_list,
I = table->nelems + added;
added++;
strcpy(table->objs[I].path,obj_list[j].obj);
- table->objs[I].layout = pack->layout;
- if (H5D_CHUNKED==pack->layout) {
- table->objs[I].chunk.rank = pack->chunk.rank;
- for (k = 0; k < pack->chunk.rank; k++)
- table->objs[I].chunk.chunk_lengths[k] = pack->chunk.chunk_lengths[k];
- }
+ aux_tblinsert_layout(table,I,pack);
+
}
}
@@ -324,6 +347,19 @@ int options_add_filter(obj_list_t *obj_list,
strcpy(table->objs[I].path,obj_list[j].obj);
aux_tblinsert_filter(table,I,filt);
}
+ /* cases where we have an already inserted name but there is a new name also
+ example:
+ -l dset1:CHUNK=20x20 -f dset1,dset2:GZIP=1
+ dset1 is already inserted, but dset2 must also be
+ */
+ else if (found==1 && strcmp(obj_list[j].obj,table->objs[i].path)!=0)
+ {
+ /* keep the grow in a temp var */
+ I = table->nelems + added;
+ added++;
+ strcpy(table->objs[I].path,obj_list[j].obj);
+ aux_tblinsert_filter(table,I,filt);
+ }
} /* j */
}
diff --git a/tools/h5repack/h5repack_parse.c b/tools/h5repack/h5repack_parse.c
index 9efeeb3..96f7bce 100644
--- a/tools/h5repack/h5repack_parse.c
+++ b/tools/h5repack/h5repack_parse.c
@@ -385,6 +385,7 @@ obj_list_t* parse_layout(const char *str,
pack->layout=H5D_CHUNKED;
else {
printf("Parse layout error: Not a valid layout in <%s>\n",str);
+ exit(1);
}
}
else