summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorPedro Vicente Nunes <pvn@hdfgroup.org>2003-10-23 19:51:51 (GMT)
committerPedro Vicente Nunes <pvn@hdfgroup.org>2003-10-23 19:51:51 (GMT)
commitcf86beb9832c21db179fad5bb00f93bf413481cd (patch)
treec2f09c688ee1dc886e31c5bbef5249ea1af6dbf2 /tools
parentf4c4923193a14899b342e4ce37153b296ecd02db (diff)
downloadhdf5-cf86beb9832c21db179fad5bb00f93bf413481cd.zip
hdf5-cf86beb9832c21db179fad5bb00f93bf413481cd.tar.gz
hdf5-cf86beb9832c21db179fad5bb00f93bf413481cd.tar.bz2
[svn-r7717] Purpose:
new features of h5repack Description: added copy routine added parsing of command line arguments Platforms tested: linux, solaris, IRIX Misc. update:
Diffstat (limited to 'tools')
-rw-r--r--tools/h5repack/h5repack.c3
-rw-r--r--tools/h5repack/h5repack.h10
-rw-r--r--tools/h5repack/h5repack_list.c298
-rw-r--r--tools/h5repack/h5repack_list.h27
-rw-r--r--tools/h5repack/h5repack_main.c96
-rw-r--r--tools/h5repack/h5repack_opttable.c2
-rw-r--r--tools/h5repack/h5repack_parse.h21
-rw-r--r--tools/h5repack/test_h5repack_add.c2
-rw-r--r--tools/h5repack/test_h5repack_main.c4
9 files changed, 433 insertions, 30 deletions
diff --git a/tools/h5repack/h5repack.c b/tools/h5repack/h5repack.c
index af267ee..d88196c 100644
--- a/tools/h5repack/h5repack.c
+++ b/tools/h5repack/h5repack.c
@@ -59,6 +59,9 @@ int h5repack(char* infile,
if (options->verbose)
printf("Making file <%s>...\n",outfile);
+
+ if (copy_file(infile,outfile,options)<0)
+ return -1;
}
diff --git a/tools/h5repack/h5repack.h b/tools/h5repack/h5repack.h
index 29b04ac..17c2b52 100644
--- a/tools/h5repack/h5repack.h
+++ b/tools/h5repack/h5repack.h
@@ -105,12 +105,18 @@ int h5repack_addchunk(char* str, packoptions_t *options);
int h5repack_init (packoptions_t *options, int verbose);
int h5repack_end (packoptions_t *options);
-
-
#ifdef __cplusplus
}
#endif
+/*-------------------------------------------------------------------------
+ * private functions
+ *-------------------------------------------------------------------------
+ */
+
+
+void read_info(char *filename,packoptions_t *options);
+
#endif /* H5REPACK_H__ */
diff --git a/tools/h5repack/h5repack_list.c b/tools/h5repack/h5repack_list.c
index 21ec337e..138cb5b 100644
--- a/tools/h5repack/h5repack_list.c
+++ b/tools/h5repack/h5repack_list.c
@@ -16,9 +16,10 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
+#include "H5private.h"
#include "h5repack.h"
#include "h5repack_list.h"
-#include "h5diff.h"
+
/*-------------------------------------------------------------------------
@@ -121,3 +122,298 @@ int get_objlist(char* fname, packoptions_t *options)
return 0;
}
+
+
+
+/*-------------------------------------------------------------------------
+ * Function: copy_file
+ *
+ * Purpose: duplicate all HDF5 objects in the file
+ *
+ * Return: 0, ok, -1 no
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: October, 23, 2003
+ *
+ *-------------------------------------------------------------------------
+ */
+
+int copy_file(char* fnamein,
+ char* fnameout,
+ packoptions_t *options)
+{
+ hid_t fidin;
+ hid_t fidout;
+ int nobjects;
+ info_t *info=NULL;
+
+/*-------------------------------------------------------------------------
+ * 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>: No such file or directory\n", fnamein );
+ exit(1);
+ }
+ if ((fidout=H5Fcreate(fnameout,H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT))<0 ){
+ printf("h5repack: <%s>: Could not create file\n", fnameout );
+ exit(1);
+ }
+ /* enable error reporting */
+ } H5E_END_TRY;
+
+
+/*-------------------------------------------------------------------------
+ * get the number of objects in the file
+ *-------------------------------------------------------------------------
+ */
+
+ if ((nobjects = H5get_object_info(fidin, NULL ))<0) {
+ printf("h5repack: <%s>: Could not obtain object list\n", fnamein );
+ return -1;
+ }
+
+/*-------------------------------------------------------------------------
+ * get the list of objects in the file
+ *-------------------------------------------------------------------------
+ */
+
+ if ((info = (info_t*) malloc( nobjects * sizeof(info_t)))==NULL){
+ printf("h5repack: <%s>: Could not allocate object list\n", fnamein );
+ return -1;
+ }
+ if (H5get_object_info(fidin, info )<0) {
+ printf("h5repack: <%s>: Could not obtain object list\n", fnamein );
+ return -1;
+ }
+
+/*-------------------------------------------------------------------------
+ * do the copy
+ *-------------------------------------------------------------------------
+ */
+
+ do_copy_file(fidin,fidout,nobjects,info,options);
+
+
+
+
+/*-------------------------------------------------------------------------
+ * free
+ *-------------------------------------------------------------------------
+ */
+ H5Fclose(fidin);
+ H5Fclose(fidout);
+ info_free(info,nobjects);
+ return 0;
+
+}
+
+
+
+/*-------------------------------------------------------------------------
+ * Function: print_objlist
+ *
+ * Purpose: print list of objects in file
+ *
+ * Return: void
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: October 23, 2003
+ *
+ *-------------------------------------------------------------------------
+ */
+void print_objlist(char *filename,
+ int nobjects,
+ info_t *info )
+{
+ int i;
+
+ printf("File <%s>: # of entries = %d\n", filename, nobjects );
+ for ( i = 0; i < nobjects; i++)
+ {
+ switch ( info[i].type )
+ {
+ case H5G_GROUP:
+ printf("%s %20s\n", info[i].name, "group" );
+ break;
+ case H5G_DATASET:
+ printf("%s %20s\n", info[i].name, "dataset" );
+ break;
+ case H5G_TYPE:
+ printf("%s %20s\n", info[i].name, "datatype" );
+ break;
+ case H5G_LINK:
+ printf("%s %20s\n", info[i].name, "link" );
+ break;
+ default:
+ printf("%s %20s\n", info[i].name, "User defined object" );
+ break;
+ }
+ }
+
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: do_copy_file
+ *
+ * Purpose: duplicate all HDF5 objects in the file
+ *
+ * Return: 0, ok, -1 no
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: October, 23, 2003
+ *
+ *-------------------------------------------------------------------------
+ */
+
+int do_copy_file(hid_t fidin,
+ hid_t fidout,
+ int nobjects,
+ info_t *info,
+ packoptions_t *options)
+{
+ hid_t grp_id; /* group ID */
+ hid_t dset_in; /* read dataset ID */
+ hid_t dset_out; /* write dataset ID */
+ hid_t dcpl_id; /* dataset creation property list ID */
+ hid_t space_id; /* space ID */
+ hid_t ftype_id; /* file data type ID */
+ hid_t mtype_id; /* memory data type ID */
+ size_t msize; /* memory size of memory type */
+ void *buf=NULL; /* data buffer */
+ hsize_t nelmts; /* number of elements in dataaset */
+ int rank; /* rank of dataset */
+ hsize_t dims[32]; /* dimansions of dataset */
+ int i, j;
+
+ for ( i = 0; i < nobjects; i++)
+ {
+ switch ( info[i].type )
+ {
+/*-------------------------------------------------------------------------
+ * H5G_GROUP
+ *-------------------------------------------------------------------------
+ */
+ case H5G_GROUP:
+ if (options->verbose)
+ printf("%s %20s\n", info[i].name, "group" );
+
+ if ((grp_id=H5Gcreate(fidout, info[i].name, 0))<0)
+ goto error;
+ if (H5Gclose(grp_id)<0)
+ goto error;
+
+ break;
+
+/*-------------------------------------------------------------------------
+ * H5G_DATASET
+ *-------------------------------------------------------------------------
+ */
+ case H5G_DATASET:
+ if (options->verbose)
+ printf("%s %20s\n", info[i].name, "dataset" );
+
+ if ((dset_in=H5Dopen(fidin,info[i].name))<0)
+ goto error;
+ if ((space_id=H5Dget_space(dset_in))<0)
+ goto error;
+ if ((ftype_id=H5Dget_type (dset_in))<0)
+ goto error;
+ if ((dcpl_id=H5Dget_create_plist(dset_in))<0)
+ goto error;
+ if ( (rank=H5Sget_simple_extent_ndims(space_id))<0)
+ goto error;
+ if ( H5Sget_simple_extent_dims(space_id,dims,NULL)<0)
+ goto error;
+
+/*-------------------------------------------------------------------------
+ * read to memory
+ *-------------------------------------------------------------------------
+ */
+ nelmts=1;
+ for (j=0; j<rank; j++)
+ nelmts*=dims[j];
+ if ((mtype_id=H5Tget_native_type(ftype_id,H5T_DIR_DEFAULT))<0)
+ goto error;
+ if ((msize=H5Tget_size(mtype_id))<0)
+ goto error;
+ buf=(void *) HDmalloc((unsigned)(nelmts*msize));
+ if ( buf==NULL){
+ printf( "cannot read into memory\n" );
+ goto error;
+ }
+ if (H5Dread(dset_in,mtype_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf)<0)
+ goto error;
+
+/*-------------------------------------------------------------------------
+ * create/write dataset/close
+ *-------------------------------------------------------------------------
+ */
+ if ((dset_out=H5Dcreate(fidout,info[i].name,ftype_id,space_id,dcpl_id))<0)
+ goto error;
+ if (H5Dwrite(dset_out,mtype_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf)<0)
+ goto error;
+
+ if (H5Tclose(ftype_id)<0)
+ goto error;
+ if (H5Tclose(mtype_id)<0)
+ goto error;
+ if (H5Pclose(dcpl_id)<0)
+ goto error;
+ if (H5Sclose(space_id)<0)
+ goto error;
+ if (H5Dclose(dset_in)<0)
+ goto error;
+ if (H5Dclose(dset_out)<0)
+ goto error;
+
+
+ break;
+
+/*-------------------------------------------------------------------------
+ * H5G_TYPE
+ *-------------------------------------------------------------------------
+ */
+ case H5G_TYPE:
+ if (options->verbose)
+ printf("%s %20s\n", info[i].name, "datatype" );
+ break;
+
+ case H5G_LINK:
+ if (options->verbose)
+ printf("%s %20s\n", info[i].name, "link" );
+ break;
+
+ default:
+ if (options->verbose)
+ printf("%s %20s\n", info[i].name, "User defined object" );
+ break;
+ }
+ }
+
+ return 0;
+
+error:
+ H5E_BEGIN_TRY {
+ H5Gclose(grp_id);
+ H5Pclose(dcpl_id);
+ H5Sclose(space_id);
+ H5Dclose(dset_in);
+ H5Dclose(dset_out);
+ H5Tclose(ftype_id);
+ H5Tclose(mtype_id);
+ } H5E_END_TRY;
+ return -1;
+
+}
+
+
diff --git a/tools/h5repack/h5repack_list.h b/tools/h5repack/h5repack_list.h
index e11b7fe..36f1907 100644
--- a/tools/h5repack/h5repack_list.h
+++ b/tools/h5repack/h5repack_list.h
@@ -18,21 +18,34 @@
#define H5REPACK_LIST_H__
#include "h5repack.h"
+#include "h5trav.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+/*-------------------------------------------------------------------------
+ * private functions
+ *-------------------------------------------------------------------------
+ */
+int get_objlist(char* infname,
+ packoptions_t *options);
-int get_objlist(char* infname, packoptions_t *options);
+int copy_file(char* fnamein,
+ char* fnameout,
+ packoptions_t *options);
+
+void print_objlist(char *filename,
+ int nobjects,
+ info_t *info );
+
+int do_copy_file(hid_t fidin,
+ hid_t fidout,
+ int nobjects,
+ info_t *info,
+ packoptions_t *options);
-#ifdef __cplusplus
-}
-#endif
#endif /* H5REPACK_LIST_H__ */
diff --git a/tools/h5repack/h5repack_main.c b/tools/h5repack/h5repack_main.c
index b0415e4..2956adb 100644
--- a/tools/h5repack/h5repack_main.c
+++ b/tools/h5repack/h5repack_main.c
@@ -13,12 +13,106 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "h5repack.h"
+#include "h5repack_parse.h"
+#include <stdlib.h>
-int main (void)
+static void usage();
+
+
+/*
+Examples of use:
+-v -i file1.h5 -o file2.h5 -t "dataset:GZIP 6" -c "dataset:2x2"
+-v -i file1.h5 -o file2.h5 -t "GZIP 6"
+*/
+
+
+int main(int argc, char **argv)
{
+ char *infile = NULL;
+ char *outfile = NULL;
+ packoptions_t options; /*the global options */
+ int i;
+
+ /* initialize options */
+ h5repack_init (&options,0);
+
+ for ( i = 1; i < argc; i++)
+ {
+ if (strcmp(argv[i], "-i") == 0) {
+ infile = argv[++i];
+ }
+ else if (strcmp(argv[i], "-o") == 0) {
+ outfile = argv[++i];
+ }
+ else if (strcmp(argv[i], "-v") == 0) {
+ options.verbose = 1;
+ }
+ else if (strcmp(argv[i], "-t") == 0) {
+
+ /* add the -t option */
+ h5repack_addcomp(argv[i+1],&options);
+
+ /* jump to next */
+ ++i;
+ }
+ else if (strcmp(argv[i], "-c") == 0) {
+
+ /* parse the -c option */
+ h5repack_addchunk(argv[i+1],&options);
+
+ /* jump to next */
+ ++i;
+ }
+
+ else if (strcmp(argv[i], "-m") == 0) {
+
+ options.threshold = parse_number(argv[i+1]);
+ if (options.threshold==-1) {
+ printf("Error: Invalid treshold size <%s>\n",argv[i+1]);
+ exit(1);
+ }
+ ++i;
+ }
+
+ else if (strcmp(argv[i], "-f") == 0) {
+ read_info(argv[++i],&options);
+ }
+
+ else if (argv[i][0] == '-') {
+ usage();
+ }
+ }
+ if (infile == NULL || outfile == NULL)
+ usage();
+
+ /* pack it */
+ h5repack(infile,outfile,&options);
+
+ /* free tables */
+ h5repack_end(&options);
return 0;
}
+
+/*-------------------------------------------------------------------------
+ * Function: usage
+ *
+ * Purpose: print usage
+ *
+ * Return: void
+ *
+ *-------------------------------------------------------------------------
+ */
+
+static
+void usage()
+{
+
+ exit(1);
+}
+
+
+
diff --git a/tools/h5repack/h5repack_opttable.c b/tools/h5repack/h5repack_opttable.c
index ef78ecb..cd0e7a2 100644
--- a/tools/h5repack/h5repack_opttable.c
+++ b/tools/h5repack/h5repack_opttable.c
@@ -37,7 +37,7 @@ int options_table_init( options_table_t **tbl )
return -1;
}
- table->size = 3;
+ table->size = 30;
table->nelems = 0;
table->objs = (pack_info_t*) malloc(table->size * sizeof(pack_info_t));
if (table->objs==NULL) {
diff --git a/tools/h5repack/h5repack_parse.h b/tools/h5repack/h5repack_parse.h
index 264b4b7..a3c5715 100644
--- a/tools/h5repack/h5repack_parse.h
+++ b/tools/h5repack/h5repack_parse.h
@@ -20,26 +20,15 @@
#include "h5repack.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int parse_number(char *str);
-
-
-/* compression */
+/*-------------------------------------------------------------------------
+ * private functions
+ *-------------------------------------------------------------------------
+ */
+int parse_number(char *str);
obj_list_t* parse_comp(char *str, int *n_objs, comp_info_t *comp);
char* get_scomp(int code);
-
-/* chunking */
-
obj_list_t* parse_chunk(char *str, int *n_objs, hsize_t *chunk_lengths, int *chunk_rank);
-#ifdef __cplusplus
-}
-#endif
-
-
#endif /* H5REPACK_PARSE_H__ */
diff --git a/tools/h5repack/test_h5repack_add.c b/tools/h5repack/test_h5repack_add.c
index 5edab2b..b357220 100644
--- a/tools/h5repack/test_h5repack_add.c
+++ b/tools/h5repack/test_h5repack_add.c
@@ -177,7 +177,9 @@ int make_dsets()
TEST_ERROR;
nerrors += make_deflate(fid);
+#if 0
nerrors += make_szip(fid);
+#endif
/* close */
if(H5Fclose(fid)<0)
diff --git a/tools/h5repack/test_h5repack_main.c b/tools/h5repack/test_h5repack_main.c
index 1768609..9ec780a 100644
--- a/tools/h5repack/test_h5repack_main.c
+++ b/tools/h5repack/test_h5repack_main.c
@@ -53,9 +53,9 @@ test()
if (h5repack_init (&options, 0)<0)
TEST_ERROR;
- if (h5repack_addcomp("dset2:GZIP 9",&options)<0)
+ if (h5repack_addcomp("dset1:GZIP 9",&options)<0)
TEST_ERROR;
- if (h5repack_addchunk("dset2:5x4",&options)<0)
+ if (h5repack_addchunk("dset1:5x4",&options)<0)
TEST_ERROR;
if (h5repack(FILENAME,FILENAME_OUT,&options)<0)
TEST_ERROR;