summaryrefslogtreecommitdiffstats
path: root/tools/h5repack/h5repack_copy.c
diff options
context:
space:
mode:
authorPedro Vicente Nunes <pvn@hdfgroup.org>2009-04-02 20:17:10 (GMT)
committerPedro Vicente Nunes <pvn@hdfgroup.org>2009-04-02 20:17:10 (GMT)
commit443e2e355acda5d49168108e89cc5468b49dd183 (patch)
treed562c05d64995cf3b87ac43ff76cc895789d19a9 /tools/h5repack/h5repack_copy.c
parent38cf2e201dc4e950d71da3219fc5c5bca0bae8c2 (diff)
downloadhdf5-443e2e355acda5d49168108e89cc5468b49dd183.zip
hdf5-443e2e355acda5d49168108e89cc5468b49dd183.tar.gz
hdf5-443e2e355acda5d49168108e89cc5468b49dd183.tar.bz2
[svn-r16656] #1402 (B1) h5repack does not preserve creation order indexing.
ISSUE : h5repack does not handle group creation order flags. ACTION: call H5P(g)(s)et_link_creation_order functions when handling groups, add new groups with these flags to the test generation program, and verify results in the test program. TEST: in the test program, function that compares property lists, added code to verify groups tested: windows, linux, solaris
Diffstat (limited to 'tools/h5repack/h5repack_copy.c')
-rw-r--r--tools/h5repack/h5repack_copy.c1383
1 files changed, 705 insertions, 678 deletions
diff --git a/tools/h5repack/h5repack_copy.c b/tools/h5repack/h5repack_copy.c
index 4e2e036..8ab5a35 100644
--- a/tools/h5repack/h5repack_copy.c
+++ b/tools/h5repack/h5repack_copy.c
@@ -1,17 +1,17 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * Copyright by The HDF Group. *
- * Copyright by the Board of Trustees of the University of Illinois. *
- * All rights reserved. *
- * *
- * This file is part of HDF5. The full HDF5 copyright notice, including *
- * terms governing use, modification, and redistribution, is contained in *
- * the files COPYING and Copyright.html. COPYING can be found at the root *
- * of the source code distribution tree; Copyright.html can be found at the *
- * root level of an installed copy of the electronic HDF5 document set and *
- * is linked from the top-level documents page. It can also be found at *
- * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
- * access to either file, you may request a copy from help@hdfgroup.org. *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+* Copyright by The HDF Group. *
+* Copyright by the Board of Trustees of the University of Illinois. *
+* All rights reserved. *
+* *
+* This file is part of HDF5. The full HDF5 copyright notice, including *
+* terms governing use, modification, and redistribution, is contained in *
+* the files COPYING and Copyright.html. COPYING can be found at the root *
+* of the source code distribution tree; Copyright.html can be found at the *
+* root level of an installed copy of the electronic HDF5 document set and *
+* is linked from the top-level documents page. It can also be found at *
+* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
+* access to either file, you may request a copy from help@hdfgroup.org. *
+* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include <stdlib.h>
#include <string.h>
@@ -25,15 +25,15 @@ extern char *progname;
/*-------------------------------------------------------------------------
- * macros
- *-------------------------------------------------------------------------
- */
+* macros
+*-------------------------------------------------------------------------
+*/
#define USERBLOCK_XFER_SIZE 512 /* size of buffer/# of bytes to xfer at a time when copying userblock */
/*-------------------------------------------------------------------------
- * local functions
- *-------------------------------------------------------------------------
- */
+* local functions
+*-------------------------------------------------------------------------
+*/
static void print_dataset_info(hid_t dcpl_id,char *objname,double per, int pr);
static int do_copy_objects(hid_t fidin,hid_t fidout,trav_table_t *travt,pack_opt_t *options);
static int copy_attr(hid_t loc_in,hid_t loc_out,pack_opt_t *options);
@@ -43,28 +43,28 @@ static void print_user_block(const char *filename, hid_t fid);
#endif
/*-------------------------------------------------------------------------
- * Function: copy_objects
- *
- * Purpose: duplicate all HDF5 objects in the file
- *
- * Return: 0, ok, -1 no
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: October, 23, 2003
- *
- * Modification:
- * Peter Cao, June 13, 2007
- * Add "-L, --latest" and other options to pack a file with the latest file format
- *
- * Peter Cao, September 25, 2007
- * Copy user block when repacking a file
- *
- * Pedro Vicente, August 20, 2008
- * Add a user block to file if requested
- *
- *-------------------------------------------------------------------------
- */
+* Function: copy_objects
+*
+* Purpose: duplicate all HDF5 objects in the file
+*
+* Return: 0, ok, -1 no
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: October, 23, 2003
+*
+* Modification:
+* Peter Cao, June 13, 2007
+* Add "-L, --latest" and other options to pack a file with the latest file format
+*
+* Peter Cao, September 25, 2007
+* Copy user block when repacking a file
+*
+* Pedro Vicente, August 20, 2008
+* Add a user block to file if requested
+*
+*-------------------------------------------------------------------------
+*/
int copy_objects(const char* fnamein,
const char* fnameout,
@@ -90,19 +90,19 @@ int copy_objects(const char* fnamein,
/* get user block size */
{
hid_t fcpl_in; /* file creation property list ID for input file */
-
+
if((fcpl_in = H5Fget_create_plist(fidin)) < 0)
{
error_msg(progname, "failed to retrieve file creation property list\n");
goto out;
}
-
+
if(H5Pget_userblock(fcpl_in, &ub_size) < 0)
{
error_msg(progname, "failed to retrieve userblock size\n");
goto out;
}
-
+
if(H5Pclose(fcpl_in) < 0)
{
error_msg(progname, "failed to close property list\n");
@@ -147,25 +147,27 @@ int copy_objects(const char* fnamein,
{
switch(i)
{
- case 0:
- mesg_type_flags[nindex] = H5O_SHMESG_SDSPACE_FLAG;
- break;
-
- case 1:
- mesg_type_flags[nindex] = H5O_SHMESG_DTYPE_FLAG;
- break;
-
- case 2:
- mesg_type_flags[nindex] = H5O_SHMESG_FILL_FLAG;
- break;
-
- case 3:
- mesg_type_flags[nindex] = H5O_SHMESG_PLINE_FLAG;
- break;
-
- case 4:
- mesg_type_flags[nindex] = H5O_SHMESG_ATTR_FLAG;
- break;
+ case 0:
+ mesg_type_flags[nindex] = H5O_SHMESG_SDSPACE_FLAG;
+ break;
+
+ case 1:
+ mesg_type_flags[nindex] = H5O_SHMESG_DTYPE_FLAG;
+ break;
+
+ case 2:
+ mesg_type_flags[nindex] = H5O_SHMESG_FILL_FLAG;
+ break;
+
+ case 3:
+ mesg_type_flags[nindex] = H5O_SHMESG_PLINE_FLAG;
+ break;
+
+ case 4:
+ mesg_type_flags[nindex] = H5O_SHMESG_ATTR_FLAG;
+ break;
+ default:
+ break;
} /* end switch */
min_mesg_sizes[nindex] = (unsigned)options->msg_size[i];
@@ -205,8 +207,8 @@ int copy_objects(const char* fnamein,
} /* end if */
} /* end if */
} /* end if */
-
-
+
+
#if defined (H5REPACK_DEBUG_USER_BLOCK)
@@ -230,30 +232,30 @@ int copy_objects(const char* fnamein,
error_msg(progname, "failed to set userblock size\n");
goto out;
}
-
+
}
-
+
else
{
-
+
/* create a file creation property list */
if((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0)
{
error_msg(progname, "fail to create a file creation property list\n");
goto out;
}
-
+
/* set user block size */
if(H5Pset_userblock(fcpl, options->ublock_size) < 0)
{
error_msg(progname, "failed to set userblock size\n");
goto out;
}
-
+
}
-
-
-
+
+
+
}
@@ -262,39 +264,39 @@ int copy_objects(const char* fnamein,
*-------------------------------------------------------------------------
*/
-
+
if ( options->alignment > 0 )
{
/* either use the FAPL already created or create a new one */
if (fapl != H5P_DEFAULT)
{
-
+
if (H5Pset_alignment(fapl, options->threshold, options->alignment) < 0)
{
error_msg(progname, "failed to set alignment\n");
goto out;
}
-
+
}
-
+
else
{
-
+
/* create a file access property list */
if ((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
{
error_msg(progname, "Could not create file access property list\n");
goto out;
}
-
+
if (H5Pset_alignment(fapl, options->threshold, options->alignment) < 0)
{
error_msg(progname, "failed to set alignment\n");
goto out;
}
-
+
}
-
+
}
@@ -303,18 +305,18 @@ int copy_objects(const char* fnamein,
*-------------------------------------------------------------------------
*/
-
+
if(options->verbose)
printf("Making file <%s>...\n",fnameout);
-
-
+
+
if((fidout = H5Fcreate(fnameout,H5F_ACC_TRUNC, fcpl, fapl)) < 0)
{
error_msg(progname, "<%s>: Could not create file\n", fnameout );
goto out;
}
-
+
/*-------------------------------------------------------------------------
* write a new user block if requested
*-------------------------------------------------------------------------
@@ -325,11 +327,11 @@ int copy_objects(const char* fnamein,
{
error_msg(progname, "Could not copy user block. Exiting...\n");
goto out;
-
+
}
}
- /*-------------------------------------------------------------------------
+ /*-------------------------------------------------------------------------
* get list of objects
*-------------------------------------------------------------------------
*/
@@ -375,7 +377,7 @@ int copy_objects(const char* fnamein,
H5Fclose(fidin);
H5Fclose(fidout);
-
+
/* free table */
trav_table_free(travt);
travt = NULL;
@@ -391,7 +393,7 @@ int copy_objects(const char* fnamein,
{
error_msg(progname, "Could not copy user block. Exiting...\n");
goto out;
-
+
}
}
@@ -417,74 +419,74 @@ out:
}
/*-------------------------------------------------------------------------
- * Function: do_copy_objects
- *
- * Purpose: duplicate all HDF5 objects in the file
- *
- * Return: 0, ok, -1 no
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: October, 23, 2003
- *
- * Modifications:
- *
- * July 2004: Introduced the extra EC or NN option for SZIP
- *
- * December 2004: Added a check for H5Dcreate; if the dataset cannot be created
- * with the requested filter, use the input one
- *
- * October 2006: Read/write using the file type by default.
- *
- * October 2006: Read by hyperslabs for big datasets.
- *
- * A threshold of H5TOOLS_MALLOCSIZE (128 MB) is the limit upon which I/O hyperslab is done
- * i.e., if the memory needed to read a dataset is greater than this limit,
- * then hyperslab I/O is done instead of one operation I/O
- * For each dataset, the memory needed is calculated according to
- *
- * memory needed = number of elements * size of each element
- *
- * if the memory needed is lower than H5TOOLS_MALLOCSIZE, then the following operations
- * are done
- *
- * H5Dread( input_dataset1 )
- * H5Dread( input_dataset2 )
- *
- * with all elements in the datasets selected. If the memory needed is greater than
- * H5TOOLS_MALLOCSIZE, then the following operations are done instead:
- *
- * a strip mine is defined for each dimension k (a strip mine is defined as a
- * hyperslab whose size is memory manageable) according to the formula
- *
- * (1) strip_mine_size[k ] = MIN(dimension[k ], H5TOOLS_BUFSIZE / size of memory type)
- *
- * where H5TOOLS_BUFSIZE is a constant currently defined as 1MB. This formula assures
- * that for small datasets (small relative to the H5TOOLS_BUFSIZE constant), the strip
- * mine size k is simply defined as its dimension k, but for larger datasets the
- * hyperslab size is still memory manageable.
- * a cycle is done until the number of elements in the dataset is reached. In each
- * iteration, two parameters are defined for the function H5Sselect_hyperslab,
- * the start and size of each hyperslab, according to
- *
- * (2) hyperslab_size [k] = MIN(dimension[k] - hyperslab_offset[k], strip_mine_size [k])
- *
- * where hyperslab_offset [k] is initially set to zero, and later incremented in
- * hyperslab_size[k] offsets. The reason for the operation
- *
- * dimension[k] - hyperslab_offset[k]
- *
- * in (2) is that, when using the strip mine size, it assures that the "remaining" part
- * of the dataset that does not fill an entire strip mine is processed.
- *
- * November 2006: Use H5Ocopy in the copy of objects. The logic for using
- * H5Ocopy or not is if a change of filters or layout is requested by the user
- * then use read/write else use H5Ocopy.
- *
- * May, 1, 2008: Add a printing of the compression ratio of old size / new size
- *
- *-------------------------------------------------------------------------
- */
+* Function: do_copy_objects
+*
+* Purpose: duplicate all HDF5 objects in the file
+*
+* Return: 0, ok, -1 no
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: October, 23, 2003
+*
+* Modifications:
+*
+* July 2004: Introduced the extra EC or NN option for SZIP
+*
+* December 2004: Added a check for H5Dcreate; if the dataset cannot be created
+* with the requested filter, use the input one
+*
+* October 2006: Read/write using the file type by default.
+*
+* October 2006: Read by hyperslabs for big datasets.
+*
+* A threshold of H5TOOLS_MALLOCSIZE (128 MB) is the limit upon which I/O hyperslab is done
+* i.e., if the memory needed to read a dataset is greater than this limit,
+* then hyperslab I/O is done instead of one operation I/O
+* For each dataset, the memory needed is calculated according to
+*
+* memory needed = number of elements * size of each element
+*
+* if the memory needed is lower than H5TOOLS_MALLOCSIZE, then the following operations
+* are done
+*
+* H5Dread( input_dataset1 )
+* H5Dread( input_dataset2 )
+*
+* with all elements in the datasets selected. If the memory needed is greater than
+* H5TOOLS_MALLOCSIZE, then the following operations are done instead:
+*
+* a strip mine is defined for each dimension k (a strip mine is defined as a
+* hyperslab whose size is memory manageable) according to the formula
+*
+* (1) strip_mine_size[k ] = MIN(dimension[k ], H5TOOLS_BUFSIZE / size of memory type)
+*
+* where H5TOOLS_BUFSIZE is a constant currently defined as 1MB. This formula assures
+* that for small datasets (small relative to the H5TOOLS_BUFSIZE constant), the strip
+* mine size k is simply defined as its dimension k, but for larger datasets the
+* hyperslab size is still memory manageable.
+* a cycle is done until the number of elements in the dataset is reached. In each
+* iteration, two parameters are defined for the function H5Sselect_hyperslab,
+* the start and size of each hyperslab, according to
+*
+* (2) hyperslab_size [k] = MIN(dimension[k] - hyperslab_offset[k], strip_mine_size [k])
+*
+* where hyperslab_offset [k] is initially set to zero, and later incremented in
+* hyperslab_size[k] offsets. The reason for the operation
+*
+* dimension[k] - hyperslab_offset[k]
+*
+* in (2) is that, when using the strip mine size, it assures that the "remaining" part
+* of the dataset that does not fill an entire strip mine is processed.
+*
+* November 2006: Use H5Ocopy in the copy of objects. The logic for using
+* H5Ocopy or not is if a change of filters or layout is requested by the user
+* then use read/write else use H5Ocopy.
+*
+* May, 1, 2008: Add a printing of the compression ratio of old size / new size
+*
+*-------------------------------------------------------------------------
+*/
int do_copy_objects(hid_t fidin,
hid_t fidout,
@@ -495,7 +497,8 @@ int do_copy_objects(hid_t fidin,
hid_t grp_out=-1; /* group ID */
hid_t dset_in=-1; /* read dataset ID */
hid_t dset_out=-1; /* write dataset ID */
- hid_t gcpl_id=-1; /* group creation property list */
+ hid_t gcpl_in=-1; /* group creation property list */
+ hid_t gcpl_out=-1; /* group creation property list */
hid_t type_in=-1; /* named type ID */
hid_t type_out=-1; /* named type ID */
hid_t dcpl_id=-1; /* dataset creation property list ID */
@@ -515,6 +518,7 @@ int do_copy_objects(hid_t fidin,
void *sm_buf=NULL; /* buffer for raw data */
int has_filter; /* current object has a filter */
int req_filter; /* there was a request for a filter */
+ unsigned crt_order_flags; /* group creation order flag */
unsigned i;
unsigned u;
int is_ref=0;
@@ -537,510 +541,532 @@ int do_copy_objects(hid_t fidin,
buf = NULL;
switch ( travt->objs[i].type )
{
+
+ case H5TRAV_TYPE_UNKNOWN:
+ assert(0);
+ break;
/*-------------------------------------------------------------------------
- * H5TRAV_TYPE_GROUP
- *-------------------------------------------------------------------------
- */
- case H5TRAV_TYPE_GROUP:
- if (options->verbose)
- printf(FORMAT_OBJ,"group",travt->objs[i].name );
+ * H5TRAV_TYPE_GROUP
+ *-------------------------------------------------------------------------
+ */
+ case H5TRAV_TYPE_GROUP:
- /*-------------------------------------------------------------------------
- * the root is a special case, we get an ID for the root group
- * and copy its attributes using that ID
- *-------------------------------------------------------------------------
- */
- if(HDstrcmp(travt->objs[i].name, "/") == 0)
- {
- if ((grp_out = H5Gopen2(fidout, "/", H5P_DEFAULT)) < 0)
- goto error;
- }
- else if (options->grp_compact>0 || options->grp_indexed>0)
- {
- /* Set up group creation property list */
- if((gcpl_id = H5Pcreate(H5P_GROUP_CREATE)) < 0)
- goto error;
+ if (options->verbose)
+ {
+ printf(FORMAT_OBJ,"group",travt->objs[i].name );
+ }
- if(H5Pset_link_phase_change(gcpl_id, (unsigned)options->grp_compact, (unsigned)options->grp_indexed) < 0)
- goto error;
+ /* open input group */
+ if ((grp_in = H5Gopen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0)
+ goto error;
- if((grp_out = H5Gcreate2(fidout, travt->objs[i].name, H5P_DEFAULT, gcpl_id, H5P_DEFAULT)) < 0)
- goto error;
- }
- else
- {
- if((grp_out = H5Gcreate2(fidout, travt->objs[i].name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- goto error;
- }
+ /* get input group creation property list */
+ if ((gcpl_in = H5Gget_create_plist(grp_in)) < 0)
+ goto error;
- if((grp_in = H5Gopen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0)
- goto error;
+ /* query and set the group creation properties */
+ if (H5Pget_link_creation_order(gcpl_in, &crt_order_flags) < 0)
+ goto error;
- /*-------------------------------------------------------------------------
- * copy attrs
- *-------------------------------------------------------------------------
- */
- if(copy_attr(grp_in,grp_out,options) < 0)
+ /* set up group creation property list */
+ if ((gcpl_out = H5Pcreate(H5P_GROUP_CREATE)) < 0)
+ goto error;
+
+ if (H5Pset_link_creation_order(gcpl_out, crt_order_flags) < 0)
+ goto error;
+
+
+ /*-------------------------------------------------------------------------
+ * the root is a special case, we get an ID for the root group
+ * and copy its attributes using that ID
+ *-------------------------------------------------------------------------
+ */
+ if(HDstrcmp(travt->objs[i].name, "/") == 0)
+ {
+ if ((grp_out = H5Gopen2(fidout, "/", H5P_DEFAULT)) < 0)
goto error;
+ }
- if(gcpl_id > 0) {
- if(H5Pclose(gcpl_id) < 0)
+ else
+ {
+
+ if (options->grp_compact>0 || options->grp_indexed>0)
+ {
+ if(H5Pset_link_phase_change(gcpl_out, (unsigned)options->grp_compact, (unsigned)options->grp_indexed) < 0)
goto error;
}
- if(H5Gclose(grp_out) < 0)
- goto error;
- if(H5Gclose(grp_in) < 0)
+
+ if((grp_out = H5Gcreate2(fidout, travt->objs[i].name, H5P_DEFAULT, gcpl_out, H5P_DEFAULT)) < 0)
goto error;
- break;
+ }
+
+ /*-------------------------------------------------------------------------
+ * copy attrs
+ *-------------------------------------------------------------------------
+ */
+ if(copy_attr(grp_in,grp_out,options) < 0)
+ goto error;
+
+
+ if(H5Pclose(gcpl_out) < 0)
+ goto error;
+ if(H5Pclose(gcpl_in) < 0)
+ goto error;
+ if(H5Gclose(grp_out) < 0)
+ goto error;
+ if(H5Gclose(grp_in) < 0)
+ goto error;
+
+ break;
/*-------------------------------------------------------------------------
- * H5TRAV_TYPE_DATASET
- *-------------------------------------------------------------------------
- */
- case H5TRAV_TYPE_DATASET:
+ * H5TRAV_TYPE_DATASET
+ *-------------------------------------------------------------------------
+ */
+ case H5TRAV_TYPE_DATASET:
+
+ has_filter = 0;
+ req_filter = 0;
- has_filter = 0;
- req_filter = 0;
+ /* check if global filters were requested */
+ if ( options->n_filter_g )
+ req_filter = 1;
- /* check if global filters were requested */
- if ( options->n_filter_g )
- req_filter = 1;
+ /* check if filters were requested for individual objects */
+ for( u = 0; u < options->op_tbl->nelems; u++)
+ {
+ int k;
- /* check if filters were requested for individual objects */
- for( u = 0; u < options->op_tbl->nelems; u++)
+ for( k = 0; k < options->op_tbl->objs[u].nfilters; k++)
{
- int k;
-
- for( k = 0; k < options->op_tbl->objs[u].nfilters; k++)
+ if ( options->op_tbl->objs[u].filter->filtn > 0 )
{
- if ( options->op_tbl->objs[u].filter->filtn > 0 )
- {
-
- req_filter = 1;
-
- }
-
+
+ req_filter = 1;
+
}
+
}
+ }
+
+ /* early detection of references */
+ if((dset_in = H5Dopen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0)
+ goto error;
+ if((ftype_id = H5Dget_type(dset_in)) < 0)
+ goto error;
+ if(H5T_REFERENCE == H5Tget_class(ftype_id))
+ is_ref = 1;
+ if(H5Tclose(ftype_id) < 0)
+ goto error;
+ if(H5Dclose(dset_in) < 0)
+ goto error;
+
+
+ /*-------------------------------------------------------------------------
+ * check if we should use H5Ocopy or not
+ * if there is a request for filters/layout, we read/write the object
+ * otherwise we do a copy using H5Ocopy
+ *-------------------------------------------------------------------------
+ */
+ if ( options->op_tbl->nelems ||
+ options->all_filter == 1 ||
+ options->all_layout == 1 ||
+ is_ref)
+ {
+
+ int j;
- /* early detection of references */
if((dset_in = H5Dopen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0)
goto error;
+ if((f_space_id = H5Dget_space(dset_in)) < 0)
+ goto error;
if((ftype_id = H5Dget_type(dset_in)) < 0)
goto error;
- if(H5T_REFERENCE == H5Tget_class(ftype_id))
- is_ref = 1;
- if(H5Tclose(ftype_id) < 0)
+ if((dcpl_id = H5Dget_create_plist(dset_in)) < 0)
goto error;
- if(H5Dclose(dset_in) < 0)
+ if((dcpl_out = H5Pcopy(dcpl_id)) < 0)
+ goto error;
+ if((rank = H5Sget_simple_extent_ndims(f_space_id)) < 0)
+ goto error;
+ HDmemset(dims, 0, sizeof dims);
+ if(H5Sget_simple_extent_dims(f_space_id, dims, NULL) < 0)
+ goto error;
+ nelmts = 1;
+ for ( j = 0; j < rank; j++)
+ {
+ nelmts *= dims[j];
+ }
+
+ if(options->use_native == 1)
+ wtype_id = h5tools_get_native_type(ftype_id);
+ else
+ wtype_id = H5Tcopy(ftype_id);
+
+ if((msize = H5Tget_size(wtype_id)) == 0)
goto error;
-
/*-------------------------------------------------------------------------
- * check if we should use H5Ocopy or not
- * if there is a request for filters/layout, we read/write the object
- * otherwise we do a copy using H5Ocopy
- *-------------------------------------------------------------------------
- */
- if ( options->op_tbl->nelems ||
- options->all_filter == 1 ||
- options->all_layout == 1 ||
- is_ref)
+ * check if the dataset creation property list has filters that
+ * are not registered in the current configuration
+ * 1) the external filters GZIP and SZIP might not be available
+ * 2) the internal filters might be turned off
+ *-------------------------------------------------------------------------
+ */
+ if (h5tools_canreadf((travt->objs[i].name),dcpl_id)==1)
{
-
- int j;
-
- if((dset_in = H5Dopen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0)
- goto error;
- if((f_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((dcpl_out = H5Pcopy(dcpl_id)) < 0)
- goto error;
- if((rank = H5Sget_simple_extent_ndims(f_space_id)) < 0)
- goto error;
- HDmemset(dims, 0, sizeof dims);
- if(H5Sget_simple_extent_dims(f_space_id, dims, NULL) < 0)
- goto error;
- nelmts = 1;
- for ( j = 0; j < rank; j++)
- {
- nelmts *= dims[j];
- }
+ apply_s=1;
+ apply_f=1;
- if(options->use_native == 1)
- wtype_id = h5tools_get_native_type(ftype_id);
- else
- wtype_id = H5Tcopy(ftype_id);
-
- if((msize = H5Tget_size(wtype_id)) == 0)
- goto error;
-
/*-------------------------------------------------------------------------
- * check if the dataset creation property list has filters that
- * are not registered in the current configuration
- * 1) the external filters GZIP and SZIP might not be available
- * 2) the internal filters might be turned off
- *-------------------------------------------------------------------------
- */
- if (h5tools_canreadf((travt->objs[i].name),dcpl_id)==1)
+ * references are a special case
+ * we cannot just copy the buffers, but instead we recreate the reference
+ * in a second traversal of the output file
+ *-------------------------------------------------------------------------
+ */
+ if (H5T_REFERENCE!=H5Tget_class(wtype_id))
{
- apply_s=1;
- apply_f=1;
+ /* get the storage size of the input dataset */
+ dsize_in=H5Dget_storage_size(dset_in);
+
+ /* check for datasets too small */
+ if (nelmts*msize < options->min_comp )
+ apply_s=0;
+
+ /* apply the filter */
+ if (apply_s)
+ {
+ if (apply_filters(travt->objs[i].name,
+ rank,
+ dims,
+ msize,
+ dcpl_out,
+ options,
+ &has_filter) < 0)
+ goto error;
+ }
/*-------------------------------------------------------------------------
- * references are a special case
- * we cannot just copy the buffers, but instead we recreate the reference
- * in a second traversal of the output file
+ * create the output dataset;
+ * disable error checking in case the dataset cannot be created with the
+ * modified dcpl; in that case use the original instead
*-------------------------------------------------------------------------
*/
- if (H5T_REFERENCE!=H5Tget_class(wtype_id))
+ H5E_BEGIN_TRY {
+ dset_out = H5Dcreate2(fidout, travt->objs[i].name, wtype_id, f_space_id, H5P_DEFAULT, dcpl_out, H5P_DEFAULT);
+ } H5E_END_TRY;
+
+ if(dset_out == FAIL)
{
- /* get the storage size of the input dataset */
- dsize_in=H5Dget_storage_size(dset_in);
+ if(options->verbose)
+ printf(" warning: could not create dataset <%s>. Applying original settings\n",
+ travt->objs[i].name);
- /* check for datasets too small */
- if (nelmts*msize < options->min_comp )
- apply_s=0;
+ if((dset_out = H5Dcreate2(fidout, travt->objs[i].name, wtype_id, f_space_id, H5P_DEFAULT, dcpl_id, H5P_DEFAULT)) < 0)
+ goto error;
+ apply_f = 0;
+ }
- /* apply the filter */
- if (apply_s)
- {
- if (apply_filters(travt->objs[i].name,
- rank,
- dims,
- msize,
- dcpl_out,
- options,
- &has_filter) < 0)
- goto error;
- }
+ /*-------------------------------------------------------------------------
+ * read/write
+ *-------------------------------------------------------------------------
+ */
+ if (nelmts)
+ {
+ size_t need = (size_t)(nelmts*msize); /* bytes needed */
+ if ( need < H5TOOLS_MALLOCSIZE )
+ buf = HDmalloc(need);
- /*-------------------------------------------------------------------------
- * create the output dataset;
- * disable error checking in case the dataset cannot be created with the
- * modified dcpl; in that case use the original instead
- *-------------------------------------------------------------------------
- */
- H5E_BEGIN_TRY {
- dset_out = H5Dcreate2(fidout, travt->objs[i].name, wtype_id, f_space_id, H5P_DEFAULT, dcpl_out, H5P_DEFAULT);
- } H5E_END_TRY;
-
- if(dset_out == FAIL)
+ if (buf != NULL )
{
- if(options->verbose)
- printf(" warning: could not create dataset <%s>. Applying original settings\n",
- travt->objs[i].name);
-
- if((dset_out = H5Dcreate2(fidout, travt->objs[i].name, wtype_id, f_space_id, H5P_DEFAULT, dcpl_id, H5P_DEFAULT)) < 0)
+ if (H5Dread(dset_in,wtype_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf) < 0)
goto error;
- apply_f = 0;
- }
+ if (H5Dwrite(dset_out,wtype_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf) < 0)
+ goto error;
+ }
- /*-------------------------------------------------------------------------
- * read/write
- *-------------------------------------------------------------------------
- */
- if (nelmts)
+ else /* possibly not enough memory, read/write by hyperslabs */
{
- size_t need = (size_t)(nelmts*msize); /* bytes needed */
- if ( need < H5TOOLS_MALLOCSIZE )
- buf = HDmalloc(need);
+ size_t p_type_nbytes = msize; /*size of memory type */
+ hsize_t p_nelmts = nelmts; /*total selected elmts */
+ hsize_t elmtno; /*counter */
+ int carry; /*counter carry value */
+ unsigned int vl_data = 0; /*contains VL datatypes */
+
+ /* stripmine info */
+ hsize_t sm_size[H5S_MAX_RANK]; /*stripmine size */
+ hsize_t sm_nbytes; /*bytes per stripmine */
+ hsize_t sm_nelmts; /*elements per stripmine*/
+ hid_t sm_space; /*stripmine data space */
+
+ /* hyperslab info */
+ hsize_t hs_offset[H5S_MAX_RANK];/*starting offset */
+ hsize_t hs_size[H5S_MAX_RANK]; /*size this pass */
+ hsize_t hs_nelmts; /*elements in request */
+ hsize_t zero[8]; /*vector of zeros */
+ int k;
+
+ /* check if we have VL data in the dataset's datatype */
+ if (H5Tdetect_class(wtype_id, H5T_VLEN) == TRUE)
+ vl_data = TRUE;
+
+ /*
+ * determine the strip mine size and allocate a buffer. The strip mine is
+ * a hyperslab whose size is manageable.
+ */
+ sm_nbytes = p_type_nbytes;
- if (buf != NULL )
+ for (k = rank; k > 0; --k)
{
- if (H5Dread(dset_in,wtype_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf) < 0)
- goto error;
- if (H5Dwrite(dset_out,wtype_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf) < 0)
- goto error;
- }
+ hsize_t size = H5TOOLS_BUFSIZE / sm_nbytes;
+ if ( size == 0) /* datum size > H5TOOLS_BUFSIZE */
+ size = 1;
+ sm_size[k - 1] = MIN(dims[k - 1], size);
+ sm_nbytes *= sm_size[k - 1];
+ assert(sm_nbytes > 0);
+ }
+ sm_buf = HDmalloc((size_t)sm_nbytes);
+
+ sm_nelmts = sm_nbytes / p_type_nbytes;
+ sm_space = H5Screate_simple(1, &sm_nelmts, NULL);
- else /* possibly not enough memory, read/write by hyperslabs */
+ /* the stripmine loop */
+ memset(hs_offset, 0, sizeof hs_offset);
+ memset(zero, 0, sizeof zero);
+
+ for (elmtno = 0; elmtno < p_nelmts; elmtno += hs_nelmts)
{
- size_t p_type_nbytes = msize; /*size of memory type */
- hsize_t p_nelmts = nelmts; /*total selected elmts */
- hsize_t elmtno; /*counter */
- int carry; /*counter carry value */
- unsigned int vl_data = 0; /*contains VL datatypes */
-
- /* stripmine info */
- hsize_t sm_size[H5S_MAX_RANK]; /*stripmine size */
- hsize_t sm_nbytes; /*bytes per stripmine */
- hsize_t sm_nelmts; /*elements per stripmine*/
- hid_t sm_space; /*stripmine data space */
-
- /* hyperslab info */
- hsize_t hs_offset[H5S_MAX_RANK];/*starting offset */
- hsize_t hs_size[H5S_MAX_RANK]; /*size this pass */
- hsize_t hs_nelmts; /*elements in request */
- hsize_t zero[8]; /*vector of zeros */
- int k;
-
- /* check if we have VL data in the dataset's datatype */
- if (H5Tdetect_class(wtype_id, H5T_VLEN) == TRUE)
- vl_data = TRUE;
-
- /*
- * determine the strip mine size and allocate a buffer. The strip mine is
- * a hyperslab whose size is manageable.
- */
- sm_nbytes = p_type_nbytes;
-
- for (k = rank; k > 0; --k)
- {
- hsize_t size = H5TOOLS_BUFSIZE / sm_nbytes;
- if ( size == 0) /* datum size > H5TOOLS_BUFSIZE */
- size = 1;
- sm_size[k - 1] = MIN(dims[k - 1], size);
- sm_nbytes *= sm_size[k - 1];
- assert(sm_nbytes > 0);
- }
- sm_buf = HDmalloc((size_t)sm_nbytes);
-
- sm_nelmts = sm_nbytes / p_type_nbytes;
- sm_space = H5Screate_simple(1, &sm_nelmts, NULL);
-
- /* the stripmine loop */
- memset(hs_offset, 0, sizeof hs_offset);
- memset(zero, 0, sizeof zero);
-
- for (elmtno = 0; elmtno < p_nelmts; elmtno += hs_nelmts)
+ /* calculate the hyperslab size */
+ if (rank > 0)
{
- /* calculate the hyperslab size */
- if (rank > 0)
+ for (k = 0, hs_nelmts = 1; k < rank; k++)
{
- for (k = 0, hs_nelmts = 1; k < rank; k++)
- {
- hs_size[k] = MIN(dims[k] - hs_offset[k], sm_size[k]);
- hs_nelmts *= hs_size[k];
- }
-
- if (H5Sselect_hyperslab(f_space_id, H5S_SELECT_SET, hs_offset, NULL, hs_size, NULL) < 0)
- goto error;
- if (H5Sselect_hyperslab(sm_space, H5S_SELECT_SET, zero, NULL, &hs_nelmts, NULL) < 0)
- goto error;
- }
- else
- {
- H5Sselect_all(f_space_id);
- H5Sselect_all(sm_space);
- hs_nelmts = 1;
- } /* rank */
+ hs_size[k] = MIN(dims[k] - hs_offset[k], sm_size[k]);
+ hs_nelmts *= hs_size[k];
+ }
- /* read/write */
- if (H5Dread(dset_in, wtype_id, sm_space, f_space_id, H5P_DEFAULT, sm_buf) < 0)
+ if (H5Sselect_hyperslab(f_space_id, H5S_SELECT_SET, hs_offset, NULL, hs_size, NULL) < 0)
goto error;
- if (H5Dwrite(dset_out, wtype_id, sm_space, f_space_id, H5P_DEFAULT, sm_buf) < 0)
+ if (H5Sselect_hyperslab(sm_space, H5S_SELECT_SET, zero, NULL, &hs_nelmts, NULL) < 0)
goto error;
+ }
+ else
+ {
+ H5Sselect_all(f_space_id);
+ H5Sselect_all(sm_space);
+ hs_nelmts = 1;
+ } /* rank */
+
+ /* read/write */
+ if (H5Dread(dset_in, wtype_id, sm_space, f_space_id, H5P_DEFAULT, sm_buf) < 0)
+ goto error;
+ if (H5Dwrite(dset_out, wtype_id, sm_space, f_space_id, H5P_DEFAULT, sm_buf) < 0)
+ goto error;
- /* reclaim any VL memory, if necessary */
- if(vl_data)
- H5Dvlen_reclaim(wtype_id, sm_space, H5P_DEFAULT, sm_buf);
+ /* reclaim any VL memory, if necessary */
+ if(vl_data)
+ H5Dvlen_reclaim(wtype_id, sm_space, H5P_DEFAULT, sm_buf);
- /* calculate the next hyperslab offset */
- for (k = rank, carry = 1; k > 0 && carry; --k)
- {
- hs_offset[k - 1] += hs_size[k - 1];
- if (hs_offset[k - 1] == dims[k - 1])
- hs_offset[k - 1] = 0;
- else
- carry = 0;
- } /* k */
- } /* elmtno */
-
- H5Sclose(sm_space);
- /* free */
- if (sm_buf!=NULL)
+ /* calculate the next hyperslab offset */
+ for (k = rank, carry = 1; k > 0 && carry; --k)
{
- HDfree(sm_buf);
- sm_buf=NULL;
- }
- } /* hyperslab read */
- }/*nelmts*/
-
- /*-------------------------------------------------------------------------
- * amount of compression used
- *-------------------------------------------------------------------------
- */
- if (options->verbose)
+ hs_offset[k - 1] += hs_size[k - 1];
+ if (hs_offset[k - 1] == dims[k - 1])
+ hs_offset[k - 1] = 0;
+ else
+ carry = 0;
+ } /* k */
+ } /* elmtno */
+
+ H5Sclose(sm_space);
+ /* free */
+ if (sm_buf!=NULL)
+ {
+ HDfree(sm_buf);
+ sm_buf=NULL;
+ }
+ } /* hyperslab read */
+ }/*nelmts*/
+
+ /*-------------------------------------------------------------------------
+ * amount of compression used
+ *-------------------------------------------------------------------------
+ */
+ if (options->verbose)
+ {
+ double ratio=0;
+
+ /* only print the compression ration if there was a filter request */
+ if (apply_s && apply_f && req_filter)
{
- double ratio=0;
+ hssize_t a, b;
- /* only print the compression ration if there was a filter request */
- if (apply_s && apply_f && req_filter)
- {
- hssize_t a, b;
+ /* get the storage size of the output dataset */
+ dsize_out=H5Dget_storage_size(dset_out);
- /* get the storage size of the output dataset */
- dsize_out=H5Dget_storage_size(dset_out);
+ /* compression ratio = uncompressed size / compressed size */
- /* compression ratio = uncompressed size / compressed size */
+ a = dsize_in; b = dsize_out;
+ if (b!=0)
+ ratio = (double) a / (double) b;
- a = dsize_in; b = dsize_out;
- if (b!=0)
- ratio = (double) a / (double) b;
-
- print_dataset_info(dcpl_out,travt->objs[i].name,ratio,1);
- }
- else
- print_dataset_info(dcpl_id,travt->objs[i].name,ratio,0);
+ print_dataset_info(dcpl_out,travt->objs[i].name,ratio,1);
+ }
+ else
+ print_dataset_info(dcpl_id,travt->objs[i].name,ratio,0);
- /* print a message that the filter was not applied
- (in case there was a filter)
- */
- if ( has_filter && apply_s == 0 )
- printf(" <warning: filter not applied to %s. dataset smaller than %d bytes>\n",
- travt->objs[i].name,
- (int)options->min_comp);
-
- if ( has_filter && apply_f == 0 )
- printf(" <warning: could not apply the filter to %s>\n",
- travt->objs[i].name);
-
- } /* verbose */
-
- /*-------------------------------------------------------------------------
- * copy attrs
- *-------------------------------------------------------------------------
- */
- if (copy_attr(dset_in,dset_out,options) < 0)
- goto error;
+ /* print a message that the filter was not applied
+ (in case there was a filter)
+ */
+ if ( has_filter && apply_s == 0 )
+ printf(" <warning: filter not applied to %s. dataset smaller than %d bytes>\n",
+ travt->objs[i].name,
+ (int)options->min_comp);
- /*close */
- if (H5Dclose(dset_out) < 0)
- goto error;
+ if ( has_filter && apply_f == 0 )
+ printf(" <warning: could not apply the filter to %s>\n",
+ travt->objs[i].name);
- }/*!H5T_REFERENCE*/
- }/*h5tools_canreadf*/
+ } /* verbose */
+ /*-------------------------------------------------------------------------
+ * copy attrs
+ *-------------------------------------------------------------------------
+ */
+ if (copy_attr(dset_in,dset_out,options) < 0)
+ goto error;
+
+ /*close */
+ if (H5Dclose(dset_out) < 0)
+ goto error;
+
+ }/*!H5T_REFERENCE*/
+ }/*h5tools_canreadf*/
- /*-------------------------------------------------------------------------
- * close
- *-------------------------------------------------------------------------
- */
- if (H5Tclose(ftype_id) < 0)
- goto error;
- if (H5Tclose(wtype_id) < 0)
- goto error;
- if (H5Pclose(dcpl_id) < 0)
- goto error;
- if (H5Pclose(dcpl_out) < 0)
- goto error;
- if (H5Sclose(f_space_id) < 0)
- goto error;
- if (H5Dclose(dset_in) < 0)
- goto error;
- }
/*-------------------------------------------------------------------------
- * we do not have request for filter/chunking use H5Ocopy instead
- *-------------------------------------------------------------------------
- */
- else
- {
- hid_t pid;
+ * close
+ *-------------------------------------------------------------------------
+ */
+ if (H5Tclose(ftype_id) < 0)
+ goto error;
+ if (H5Tclose(wtype_id) < 0)
+ goto error;
+ if (H5Pclose(dcpl_id) < 0)
+ goto error;
+ if (H5Pclose(dcpl_out) < 0)
+ goto error;
+ if (H5Sclose(f_space_id) < 0)
+ goto error;
+ if (H5Dclose(dset_in) < 0)
+ goto error;
- /* create property to pass copy options */
- if ( (pid = H5Pcreate(H5P_OBJECT_COPY)) < 0)
- goto error;
+ }
+ /*-------------------------------------------------------------------------
+ * we do not have request for filter/chunking use H5Ocopy instead
+ *-------------------------------------------------------------------------
+ */
+ else
+ {
+ hid_t pid;
- /* set options for object copy */
- if(H5Pset_copy_object(pid, H5O_COPY_WITHOUT_ATTR_FLAG) < 0)
- goto error;
+ /* create property to pass copy options */
+ if ( (pid = H5Pcreate(H5P_OBJECT_COPY)) < 0)
+ goto error;
- /*-------------------------------------------------------------------------
- * do the copy
- *-------------------------------------------------------------------------
- */
-
- if(H5Ocopy(fidin, /* Source file or group identifier */
- travt->objs[i].name, /* Name of the source object to be copied */
- fidout, /* Destination file or group identifier */
- travt->objs[i].name, /* Name of the destination object */
- pid, /* Properties which apply to the copy */
- H5P_DEFAULT) < 0) /* Properties which apply to the new hard link */
- goto error;
+ /* set options for object copy */
+ if(H5Pset_copy_object(pid, H5O_COPY_WITHOUT_ATTR_FLAG) < 0)
+ goto error;
- /* close property */
- if(H5Pclose(pid) < 0)
- goto error;
+ /*-------------------------------------------------------------------------
+ * do the copy
+ *-------------------------------------------------------------------------
+ */
+
+ if(H5Ocopy(fidin, /* Source file or group identifier */
+ travt->objs[i].name, /* Name of the source object to be copied */
+ fidout, /* Destination file or group identifier */
+ travt->objs[i].name, /* Name of the destination object */
+ pid, /* Properties which apply to the copy */
+ H5P_DEFAULT) < 0) /* Properties which apply to the new hard link */
+ goto error;
+ /* close property */
+ if(H5Pclose(pid) < 0)
+ goto error;
- /*-------------------------------------------------------------------------
- * copy attrs manually
- *-------------------------------------------------------------------------
- */
- if((dset_in = H5Dopen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0)
- goto error;
- if((dset_out = H5Dopen2(fidout, travt->objs[i].name, H5P_DEFAULT)) < 0)
- goto error;
- if(copy_attr(dset_in, dset_out, options) < 0)
- goto error;
- if(H5Dclose(dset_in) < 0)
- goto error;
- if(H5Dclose(dset_out) < 0)
- goto error;
+
+ /*-------------------------------------------------------------------------
+ * copy attrs manually
+ *-------------------------------------------------------------------------
+ */
+ if((dset_in = H5Dopen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0)
+ goto error;
+ if((dset_out = H5Dopen2(fidout, travt->objs[i].name, H5P_DEFAULT)) < 0)
+ goto error;
+ if(copy_attr(dset_in, dset_out, options) < 0)
+ goto error;
+ if(H5Dclose(dset_in) < 0)
+ goto error;
+ if(H5Dclose(dset_out) < 0)
+ goto error;
- if (options->verbose)
- printf(FORMAT_OBJ,"dset",travt->objs[i].name );
-
+ if (options->verbose)
+ printf(FORMAT_OBJ,"dset",travt->objs[i].name );
- } /* end do we have request for filter/chunking */
+ } /* end do we have request for filter/chunking */
- break;
+
+ break;
/*-------------------------------------------------------------------------
- * H5TRAV_TYPE_NAMED_DATATYPE
- *-------------------------------------------------------------------------
- */
- case H5TRAV_TYPE_NAMED_DATATYPE:
+ * H5TRAV_TYPE_NAMED_DATATYPE
+ *-------------------------------------------------------------------------
+ */
+ case H5TRAV_TYPE_NAMED_DATATYPE:
- if(options->verbose)
- printf(FORMAT_OBJ, "type", travt->objs[i].name);
+ if(options->verbose)
+ printf(FORMAT_OBJ, "type", travt->objs[i].name);
- if((type_in = H5Topen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0)
- goto error;
+ if((type_in = H5Topen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0)
+ goto error;
- if((type_out = H5Tcopy(type_in)) < 0)
- goto error;
+ if((type_out = H5Tcopy(type_in)) < 0)
+ goto error;
- if((H5Tcommit2(fidout, travt->objs[i].name, type_out, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- goto error;
+ if((H5Tcommit2(fidout, travt->objs[i].name, type_out, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto error;
- /*-------------------------------------------------------------------------
- * copy attrs
- *-------------------------------------------------------------------------
- */
- if(copy_attr(type_in, type_out, options) < 0)
- goto error;
+ /*-------------------------------------------------------------------------
+ * copy attrs
+ *-------------------------------------------------------------------------
+ */
+ if(copy_attr(type_in, type_out, options) < 0)
+ goto error;
- if(H5Tclose(type_in) < 0)
- goto error;
- if(H5Tclose(type_out) < 0)
- goto error;
+ if(H5Tclose(type_in) < 0)
+ goto error;
+ if(H5Tclose(type_out) < 0)
+ goto error;
-
- break;
+
+ break;
/*-------------------------------------------------------------------------
- * H5TRAV_TYPE_LINK
- * H5TRAV_TYPE_UDLINK
- *
- * Only handles external links; H5Lcopy will fail for other UD link types
- * since we don't have creation or copy callbacks for them.
- *-------------------------------------------------------------------------
- */
-
- case H5TRAV_TYPE_LINK:
- case H5TRAV_TYPE_UDLINK:
+ * H5TRAV_TYPE_LINK
+ * H5TRAV_TYPE_UDLINK
+ *
+ * Only handles external links; H5Lcopy will fail for other UD link types
+ * since we don't have creation or copy callbacks for them.
+ *-------------------------------------------------------------------------
+ */
+
+ case H5TRAV_TYPE_LINK:
+ case H5TRAV_TYPE_UDLINK:
{
if(options->verbose)
@@ -1055,8 +1081,8 @@ int do_copy_objects(hid_t fidin,
}
break;
- default:
- goto error;
+ default:
+ goto error;
} /* switch */
/* free */
@@ -1075,7 +1101,8 @@ error:
H5Gclose(grp_in);
H5Gclose(grp_out);
H5Pclose(dcpl_id);
- H5Pclose(gcpl_id);
+ H5Pclose(gcpl_in);
+ H5Pclose(gcpl_out);
H5Sclose(f_space_id);
H5Dclose(dset_in);
H5Dclose(dset_out);
@@ -1094,21 +1121,21 @@ error:
/*-------------------------------------------------------------------------
- * Function: copy_attr
- *
- * Purpose: copy attributes located in LOC_IN, which is obtained either from
- * loc_id = H5Gopen2( fid, name);
- * loc_id = H5Dopen2( fid, name);
- * loc_id = H5Topen2( fid, name);
- *
- * Return: 0, ok, -1 no
- *
- * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
- *
- * Date: October, 28, 2003
- *
- *-------------------------------------------------------------------------
- */
+* Function: copy_attr
+*
+* Purpose: copy attributes located in LOC_IN, which is obtained either from
+* loc_id = H5Gopen2( fid, name);
+* loc_id = H5Dopen2( fid, name);
+* loc_id = H5Topen2( fid, name);
+*
+* Return: 0, ok, -1 no
+*
+* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+*
+* Date: October, 28, 2003
+*
+*-------------------------------------------------------------------------
+*/
int copy_attr(hid_t loc_in,
hid_t loc_out,
@@ -1129,71 +1156,71 @@ int copy_attr(hid_t loc_in,
H5O_info_t oinfo; /* object info */
int j;
unsigned u;
-
+
if(H5Oget_info(loc_in, &oinfo) < 0)
goto error;
-
- /*-------------------------------------------------------------------------
+
+ /*-------------------------------------------------------------------------
* copy all attributes
*-------------------------------------------------------------------------
*/
-
+
for ( u = 0; u < (unsigned)oinfo.num_attrs; u++)
{
-
+
buf=NULL;
-
+
/* open attribute */
if((attr_id = H5Aopen_by_idx(loc_in, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)u, H5P_DEFAULT, H5P_DEFAULT)) < 0)
goto error;
-
+
/* get name */
if (H5Aget_name( attr_id, (size_t)255, name ) < 0)
goto error;
-
+
/* get the file datatype */
if ((ftype_id = H5Aget_type( attr_id )) < 0 )
goto error;
-
+
/* get the dataspace handle */
if ((space_id = H5Aget_space( attr_id )) < 0 )
goto error;
-
+
/* get dimensions */
if ( (rank = H5Sget_simple_extent_dims(space_id, dims, NULL)) < 0 )
goto error;
-
+
nelmts=1;
for (j=0; j<rank; j++)
nelmts*=dims[j];
-
+
if (options->use_native==1)
wtype_id = h5tools_get_native_type(ftype_id);
else
wtype_id = H5Tcopy(ftype_id);
-
+
if ((msize=H5Tget_size(wtype_id))==0)
goto error;
-
- /*-------------------------------------------------------------------------
+
+ /*-------------------------------------------------------------------------
* object references are a special case
* we cannot just copy the buffers, but instead we recreate the reference
* this is done on a second sweep of the file that just copies
* the referenced objects
*-------------------------------------------------------------------------
*/
-
+
if (H5T_REFERENCE==H5Tget_class(wtype_id))
{
;
}
else
{
- /*-------------------------------------------------------------------------
- * read to memory
- *-------------------------------------------------------------------------
- */
-
+ /*-------------------------------------------------------------------------
+ * read to memory
+ *-------------------------------------------------------------------------
+ */
+
buf = (void *)HDmalloc((size_t)(nelmts * msize));
if(buf == NULL) {
error_msg(progname, "cannot read into memory\n" );
@@ -1201,46 +1228,46 @@ int copy_attr(hid_t loc_in,
}
if(H5Aread(attr_id, wtype_id, buf) < 0)
goto error;
-
- /*-------------------------------------------------------------------------
+
+ /*-------------------------------------------------------------------------
* copy
*-------------------------------------------------------------------------
*/
-
+
if((attr_out = H5Acreate2(loc_out, name, ftype_id, space_id, H5P_DEFAULT, H5P_DEFAULT)) < 0)
goto error;
if(H5Awrite(attr_out, wtype_id, buf) < 0)
goto error;
-
+
/*close*/
if(H5Aclose(attr_out) < 0)
goto error;
-
-
+
+
if(buf)
free(buf);
-
+
} /*H5T_REFERENCE*/
-
-
+
+
if(options->verbose)
printf(FORMAT_OBJ_ATTR, "attr", name);
-
+
/*-------------------------------------------------------------------------
- * close
- *-------------------------------------------------------------------------
- */
-
+ * close
+ *-------------------------------------------------------------------------
+ */
+
if (H5Tclose(ftype_id) < 0) goto error;
if (H5Tclose(wtype_id) < 0) goto error;
if (H5Sclose(space_id) < 0) goto error;
if (H5Aclose(attr_id) < 0) goto error;
-
+
} /* u */
-
-
+
+
return 0;
-
+
error:
H5E_BEGIN_TRY {
H5Tclose(ftype_id);
@@ -1258,12 +1285,12 @@ error:
/*-------------------------------------------------------------------------
- * Function: print_dataset_info
- *
- * Purpose: print name, filters, percentage compression of a dataset
- *
- *-------------------------------------------------------------------------
- */
+* Function: print_dataset_info
+*
+* Purpose: print name, filters, percentage compression of a dataset
+*
+*-------------------------------------------------------------------------
+*/
static void print_dataset_info(hid_t dcpl_id,
char *objname,
double ratio,
@@ -1280,27 +1307,27 @@ static void print_dataset_info(hid_t dcpl_id,
size_t cd_nelmts; /* filter client number of values */
char f_objname[256]; /* filter objname */
int i;
-
-
+
+
strcpy(strfilter,"\0");
-
+
/* get information about input filters */
if((nfilters = H5Pget_nfilters(dcpl_id)) < 0)
return;
-
+
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_objname), f_objname, NULL);
-
+
switch(filtn) {
default:
break;
-
+
case H5Z_FILTER_DEFLATE:
strcat(strfilter,"GZIP ");
-
+
#if defined (PRINT_DEBUG)
{
unsigned level=cd_values[0];
@@ -1309,10 +1336,10 @@ static void print_dataset_info(hid_t dcpl_id,
}
#endif
break;
-
+
case H5Z_FILTER_SZIP:
strcat(strfilter,"SZIP ");
-
+
#if defined (PRINT_DEBUG)
{
unsigned options_mask=cd_values[0]; /* from dcpl, not filt*/
@@ -1325,29 +1352,29 @@ static void print_dataset_info(hid_t dcpl_id,
strcpy(temp,"NN) ");
}
strcat(strfilter,temp);
-
+
#endif
-
+
break;
-
+
case H5Z_FILTER_SHUFFLE:
strcat(strfilter,"SHUF ");
break;
-
+
case H5Z_FILTER_FLETCHER32:
strcat(strfilter,"FLET ");
break;
-
+
case H5Z_FILTER_NBIT:
strcat(strfilter,"NBIT ");
break;
-
+
case H5Z_FILTER_SCALEOFFSET:
strcat(strfilter,"SCALEOFFSET ");
break;
} /* switch */
}/*i*/
-
+
if(!pr)
printf(FORMAT_OBJ,"dset",objname );
else
@@ -1362,18 +1389,18 @@ static void print_dataset_info(hid_t dcpl_id,
}
/*-------------------------------------------------------------------------
- * Function: copy_user_block
- *
- * Purpose: copy user block from one file to another
- *
- * Return: 0, ok, -1 no
- *
- * Programmer: Peter Cao
- *
- * Date: October, 25, 2007
- *
- *-------------------------------------------------------------------------
- */
+* Function: copy_user_block
+*
+* Purpose: copy user block from one file to another
+*
+* Return: 0, ok, -1 no
+*
+* Programmer: Peter Cao
+*
+* Date: October, 25, 2007
+*
+*-------------------------------------------------------------------------
+*/
static int
copy_user_block(const char *infile, const char *outfile, hsize_t size)
{
@@ -1448,18 +1475,18 @@ done:
/*-------------------------------------------------------------------------
- * Function: print_user_block
- *
- * Purpose: print user block
- *
- * Return: 0, ok, -1 no
- *
- * Programmer: Pedro Vicente
- *
- * Date: August, 20, 2008
- *
- *-------------------------------------------------------------------------
- */
+* Function: print_user_block
+*
+* Purpose: print user block
+*
+* Return: 0, ok, -1 no
+*
+* Programmer: Pedro Vicente
+*
+* Date: August, 20, 2008
+*
+*-------------------------------------------------------------------------
+*/
#if defined (H5REPACK_DEBUG_USER_BLOCK)
static
void print_user_block(const char *filename, hid_t fid)
@@ -1476,25 +1503,25 @@ void print_user_block(const char *filename, hid_t fid)
error_msg(progname, "failed to retrieve file creation property list\n");
goto done;
}
-
+
if(H5Pget_userblock(fcpl, &ub_size) < 0)
{
error_msg(progname, "failed to retrieve userblock size\n");
goto done;
}
-
+
if(H5Pclose(fcpl) < 0)
{
error_msg(progname, "failed to close property list\n");
goto done;
}
-
+
/* open file */
if((fh = HDopen(filename, O_RDONLY, 0)) < 0)
{
goto done;
}
-
+
size = ub_size;
/* read file */
@@ -1522,7 +1549,7 @@ void print_user_block(const char *filename, hid_t fid)
goto done;
}
-
+
/* update size of userblock left to transfer */
size -= nread;
}
@@ -1530,7 +1557,7 @@ void print_user_block(const char *filename, hid_t fid)
done:
if(fh > 0)
HDclose(fh);
-
+
return;
}