summaryrefslogtreecommitdiffstats
path: root/tools/h5repack/h5repack_copy.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/h5repack/h5repack_copy.c')
-rw-r--r--tools/h5repack/h5repack_copy.c268
1 files changed, 134 insertions, 134 deletions
diff --git a/tools/h5repack/h5repack_copy.c b/tools/h5repack/h5repack_copy.c
index 05ea7fa..5b0520d 100644
--- a/tools/h5repack/h5repack_copy.c
+++ b/tools/h5repack/h5repack_copy.c
@@ -26,16 +26,16 @@
/*-------------------------------------------------------------------------
* Function: print_obj
*
- * Purpose: print name and filters of an object
+ * Purpose: print name and filters of an object
*
*-------------------------------------------------------------------------
*/
static void print_obj(hid_t dcpl_id, char *name)
{
- char str[255];
+ char str[255];
#if defined (PRINT_DEBUG )
- char temp[255];
-#endif
+ char temp[255];
+#endif
int nfilters; /* number of filters */
unsigned filt_flags; /* filter flags */
H5Z_filter_t filtn; /* filter identification number */
@@ -47,7 +47,7 @@ static void print_obj(hid_t dcpl_id, char *name)
strcpy(str,"\0");
/* get information about input filters */
- if ((nfilters = H5Pget_nfilters(dcpl_id))<0)
+ if ((nfilters = H5Pget_nfilters(dcpl_id))<0)
return;
for ( i=0; i<nfilters; i++)
@@ -55,20 +55,20 @@ static void print_obj(hid_t dcpl_id, char *name)
cd_nelmts = NELMTS(cd_values);
#ifdef H5_WANT_H5_V1_6_COMPAT
- filtn = H5Pget_filter(dcpl_id,
- (unsigned)i,
- &filt_flags,
+ filtn = H5Pget_filter(dcpl_id,
+ (unsigned)i,
+ &filt_flags,
&cd_nelmts,
- cd_values,
- sizeof(f_name),
+ cd_values,
+ sizeof(f_name),
f_name);
#else
- filtn = H5Pget_filter(dcpl_id,
- (unsigned)i,
- &filt_flags,
+ filtn = H5Pget_filter(dcpl_id,
+ (unsigned)i,
+ &filt_flags,
&cd_nelmts,
- cd_values,
- sizeof(f_name),
+ cd_values,
+ sizeof(f_name),
f_name,
NULL);
#endif /* H5_WANT_H5_V1_6_COMPAT */
@@ -83,7 +83,7 @@ static void print_obj(hid_t dcpl_id, char *name)
#if defined (PRINT_DEBUG)
{
- unsigned level=cd_values[0];
+ unsigned level=cd_values[0];
sprintf(temp,"(%d)",level);
strcat(str,temp);
}
@@ -96,12 +96,12 @@ static void print_obj(hid_t dcpl_id, char *name)
#if defined (PRINT_DEBUG)
{
unsigned options_mask=cd_values[0]; /* from dcpl, not filt*/
- unsigned ppb=cd_values[1];
+ unsigned ppb=cd_values[1];
sprintf(temp,"(%d,",ppb);
strcat(str,temp);
- if (options_mask & H5_SZIP_EC_OPTION_MASK)
+ if (options_mask & H5_SZIP_EC_OPTION_MASK)
strcpy(temp,"EC) ");
- else if (options_mask & H5_SZIP_NN_OPTION_MASK)
+ else if (options_mask & H5_SZIP_NN_OPTION_MASK)
strcpy(temp,"NN) ");
}
strcat(str,temp);
@@ -132,7 +132,7 @@ static void print_obj(hid_t dcpl_id, char *name)
/*-------------------------------------------------------------------------
* Function: copy_objects
*
- * Purpose: duplicate all HDF5 objects in the file
+ * Purpose: duplicate all HDF5 objects in the file
*
* Return: 0, ok, -1 no
*
@@ -143,16 +143,16 @@ static void print_obj(hid_t dcpl_id, char *name)
*-------------------------------------------------------------------------
*/
-int copy_objects(const char* fnamein,
+int copy_objects(const char* fnamein,
const char* fnameout,
pack_opt_t *options)
{
- hid_t fidin;
- hid_t fidout=(-1);
+ hid_t fidin;
+ hid_t fidout=(-1);
trav_table_t *travt=NULL;
/*-------------------------------------------------------------------------
- * open the files
+ * open the files
*-------------------------------------------------------------------------
*/
if ((fidin=H5Fopen(fnamein,H5F_ACC_RDONLY,H5P_DEFAULT))<0 ){
@@ -224,7 +224,7 @@ out:
/*-------------------------------------------------------------------------
* Function: do_copy_objects
*
- * Purpose: duplicate all HDF5 objects in the file
+ * Purpose: duplicate all HDF5 objects in the file
*
* Return: 0, ok, -1 no
*
@@ -237,21 +237,21 @@ out:
*-------------------------------------------------------------------------
*/
-int do_copy_objects(hid_t fidin,
- hid_t fidout,
+int do_copy_objects(hid_t fidin,
+ hid_t fidout,
trav_table_t *travt,
pack_opt_t *options) /* repack options */
{
- hid_t grp_in=(-1); /* group ID */
- 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 type_in=(-1); /* named type ID */
- hid_t type_out=(-1); /* named type ID */
- hid_t dcpl_id=(-1); /* dataset creation property list ID */
- hid_t dcpl_out=(-1); /* dataset creation property list ID */
- hid_t space_id=(-1); /* space ID */
- hid_t ftype_id=(-1); /* file data type ID */
+ hid_t grp_in=(-1); /* group ID */
+ 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 type_in=(-1); /* named type ID */
+ hid_t type_out=(-1); /* named type ID */
+ hid_t dcpl_id=(-1); /* dataset creation property list ID */
+ hid_t dcpl_out=(-1); /* dataset creation property list ID */
+ hid_t space_id=(-1); /* space ID */
+ hid_t ftype_id=(-1); /* file data type ID */
hid_t mtype_id=(-1); /* memory data type ID */
size_t msize; /* memory size of memory type */
void *buf=NULL; /* data buffer */
@@ -281,22 +281,22 @@ int do_copy_objects(hid_t fidin,
if (options->verbose)
printf(" %-10s %s\n", "group",travt->objs[i].name );
- if ((grp_out=H5Gcreate(fidout,travt->objs[i].name, 0))<0)
+ if ((grp_out=H5Gcreate(fidout,travt->objs[i].name, 0))<0)
goto error;
- if((grp_in = H5Gopen (fidin,travt->objs[i].name))<0)
+ if((grp_in = H5Gopen (fidin,travt->objs[i].name))<0)
goto error;
/*-------------------------------------------------------------------------
* copy attrs
*-------------------------------------------------------------------------
*/
- if (copy_attr(grp_in,grp_out,options)<0)
+ if (copy_attr(grp_in,grp_out,options)<0)
goto error;
-
- if (H5Gclose(grp_out)<0)
+
+ if (H5Gclose(grp_out)<0)
goto error;
- if (H5Gclose(grp_in)<0)
+ if (H5Gclose(grp_in)<0)
goto error;
@@ -308,15 +308,15 @@ int do_copy_objects(hid_t fidin,
*/
case H5G_DATASET:
- if ((dset_in=H5Dopen(fidin,travt->objs[i].name))<0)
+ if ((dset_in=H5Dopen(fidin,travt->objs[i].name))<0)
goto error;
- if ((space_id=H5Dget_space(dset_in))<0)
+ if ((space_id=H5Dget_space(dset_in))<0)
goto error;
- if ((ftype_id=H5Dget_type (dset_in))<0)
+ if ((ftype_id=H5Dget_type (dset_in))<0)
goto error;
- if ((dcpl_id=H5Dget_create_plist(dset_in))<0)
+ if ((dcpl_id=H5Dget_create_plist(dset_in))<0)
goto error;
- if ((dcpl_out = H5Pcopy (dcpl_id))<0)
+ if ((dcpl_out = H5Pcopy (dcpl_id))<0)
goto error;
if ( (rank=H5Sget_simple_extent_ndims(space_id))<0)
goto error;
@@ -324,12 +324,12 @@ int do_copy_objects(hid_t fidin,
if ( H5Sget_simple_extent_dims(space_id,dims,NULL)<0)
goto error;
nelmts=1;
- for (j=0; j<rank; j++)
+ for (j=0; j<rank; j++)
nelmts*=dims[j];
-
+
if (options->verbose)
print_obj(dcpl_id,travt->objs[i].name );
-
+
if ((mtype_id=h5tools_get_native_type(ftype_id))<0)
goto error;
@@ -340,7 +340,7 @@ int do_copy_objects(hid_t fidin,
* check for external files
*-------------------------------------------------------------------------
*/
- if ((next=H5Pget_external_count (dcpl_id))<0)
+ if ((next=H5Pget_external_count (dcpl_id))<0)
goto error;
if (next) {
@@ -348,8 +348,8 @@ int do_copy_objects(hid_t fidin,
}
/*-------------------------------------------------------------------------
- * check if the dataset creation property list has filters that
- * are not registered in the current configuration
+ * 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
*-------------------------------------------------------------------------
@@ -365,10 +365,10 @@ int do_copy_objects(hid_t fidin,
*/
if ( (H5T_REFERENCE!=H5Tget_class(mtype_id)))
{
-
+
/* get the storage size of the input dataset */
dsize_in=H5Dget_storage_size(dset_in);
-
+
/*-------------------------------------------------------------------------
* read to memory
*-------------------------------------------------------------------------
@@ -382,7 +382,7 @@ int do_copy_objects(hid_t fidin,
}
if (H5Dread(dset_in,mtype_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf)<0)
goto error;
-
+
/*-------------------------------------------------------------------------
* apply the filter
*-------------------------------------------------------------------------
@@ -391,7 +391,7 @@ int do_copy_objects(hid_t fidin,
goto error;
}/*nelmts*/
-
+
/*-------------------------------------------------------------------------
* create;
* disable error checking in case the dataset cannot be created with the
@@ -405,9 +405,9 @@ int do_copy_objects(hid_t fidin,
if (dset_out==FAIL)
{
- if ((dset_out=H5Dcreate(fidout,travt->objs[i].name,mtype_id,space_id,dcpl_id))<0)
+ if ((dset_out=H5Dcreate(fidout,travt->objs[i].name,mtype_id,space_id,dcpl_id))<0)
goto error;
-
+
if (options->verbose)
printf("Warning: Could not apply the filter to <%s>\n", travt->objs[i].name);
}
@@ -425,16 +425,16 @@ int do_copy_objects(hid_t fidin,
* copy attrs
*-------------------------------------------------------------------------
*/
- if (copy_attr(dset_in,dset_out,options)<0)
+ if (copy_attr(dset_in,dset_out,options)<0)
goto error;
/*close */
- if (H5Dclose(dset_out)<0)
+ if (H5Dclose(dset_out)<0)
goto error;
-
+
if (buf)
free(buf);
-
+
}/*H5T_STD_REF_OBJ*/
}/*can_read*/
@@ -443,19 +443,19 @@ int do_copy_objects(hid_t fidin,
* close
*-------------------------------------------------------------------------
*/
- if (H5Tclose(ftype_id)<0)
+ if (H5Tclose(ftype_id)<0)
goto error;
- if (H5Tclose(mtype_id)<0)
+ if (H5Tclose(mtype_id)<0)
goto error;
- if (H5Pclose(dcpl_id)<0)
+ if (H5Pclose(dcpl_id)<0)
goto error;
- if (H5Pclose(dcpl_out)<0)
+ if (H5Pclose(dcpl_out)<0)
goto error;
- if (H5Sclose(space_id)<0)
+ if (H5Sclose(space_id)<0)
goto error;
- if (H5Dclose(dset_in)<0)
+ if (H5Dclose(dset_in)<0)
goto error;
-
+
break;
/*-------------------------------------------------------------------------
@@ -464,25 +464,25 @@ int do_copy_objects(hid_t fidin,
*/
case H5G_TYPE:
- if ((type_in = H5Topen (fidin,travt->objs[i].name))<0)
+ if ((type_in = H5Topen (fidin,travt->objs[i].name))<0)
goto error;
- if ((type_out = H5Tcopy(type_in))<0)
+ if ((type_out = H5Tcopy(type_in))<0)
goto error;
- if ((H5Tcommit(fidout,travt->objs[i].name,type_out))<0)
+ if ((H5Tcommit(fidout,travt->objs[i].name,type_out))<0)
goto error;
/*-------------------------------------------------------------------------
* copy attrs
*-------------------------------------------------------------------------
*/
- if (copy_attr(type_in,type_out,options)<0)
+ if (copy_attr(type_in,type_out,options)<0)
goto error;
-
- if (H5Tclose(type_in)<0)
+
+ if (H5Tclose(type_in)<0)
goto error;
- if (H5Tclose(type_out)<0)
+ if (H5Tclose(type_out)<0)
goto error;
if (options->verbose)
@@ -500,12 +500,12 @@ int do_copy_objects(hid_t fidin,
{
H5G_stat_t statbuf;
char *targbuf=NULL;
-
+
if (H5Gget_objinfo(fidin,travt->objs[i].name,FALSE,&statbuf)<0)
goto error;
-
+
targbuf = malloc(statbuf.linklen);
-
+
if (H5Gget_linkval(fidin,travt->objs[i].name,statbuf.linklen,targbuf)<0)
goto error;
@@ -513,11 +513,11 @@ int do_copy_objects(hid_t fidin,
H5G_LINK_SOFT,
targbuf, /* current name of object */
travt->objs[i].name /* new name of object */
- )<0)
+ )<0)
goto error;
-
+
free(targbuf);
-
+
if (options->verbose)
printf(" %-10s %s\n","link",travt->objs[i].name );
@@ -530,31 +530,31 @@ int do_copy_objects(hid_t fidin,
break;
}
}
-
+
/*-------------------------------------------------------------------------
- * the root is a special case, we get an ID for the root group
+ * the root is a special case, we get an ID for the root group
* and copy its attributes using that ID
* it must be done last, because the attributes might contain references to
* objects in the object list
*-------------------------------------------------------------------------
*/
- if ((grp_out = H5Gopen(fidout,"/"))<0)
+ if ((grp_out = H5Gopen(fidout,"/"))<0)
goto error;
-
- if ((grp_in = H5Gopen(fidin,"/"))<0)
+
+ if ((grp_in = H5Gopen(fidin,"/"))<0)
goto error;
-
- if (copy_attr(grp_in,grp_out,options)<0)
+
+ if (copy_attr(grp_in,grp_out,options)<0)
goto error;
-
- if (H5Gclose(grp_out)<0)
+
+ if (H5Gclose(grp_out)<0)
goto error;
- if (H5Gclose(grp_in)<0)
+ if (H5Gclose(grp_in)<0)
goto error;
-
+
return 0;
-
+
error:
H5E_BEGIN_TRY {
H5Gclose(grp_in);
@@ -578,7 +578,7 @@ error:
/*-------------------------------------------------------------------------
* Function: copy_attr
*
- * Purpose: copy attributes located in LOC_IN, which is obtained either from
+ * Purpose: copy attributes located in LOC_IN, which is obtained either from
* loc_id = H5Gopen( fid, name);
* loc_id = H5Dopen( fid, name);
* loc_id = H5Topen( fid, name);
@@ -592,15 +592,15 @@ error:
*-------------------------------------------------------------------------
*/
-int copy_attr(hid_t loc_in,
- hid_t loc_out,
+int copy_attr(hid_t loc_in,
+ hid_t loc_out,
pack_opt_t *options
)
{
- hid_t attr_id=-1; /* attr ID */
- hid_t attr_out=-1; /* attr ID */
- hid_t space_id=-1; /* space ID */
- hid_t ftype_id=-1; /* file data type ID */
+ hid_t attr_id=-1; /* attr ID */
+ hid_t attr_out=-1; /* attr ID */
+ hid_t space_id=-1; /* space ID */
+ hid_t ftype_id=-1; /* file data type ID */
hid_t mtype_id=-1; /* memory data type ID */
size_t msize; /* memory size of type */
void *buf=NULL; /* data buffer */
@@ -611,44 +611,44 @@ int copy_attr(hid_t loc_in,
int n, j;
unsigned u;
- if ((n = H5Aget_num_attrs(loc_in))<0)
+ if ((n = H5Aget_num_attrs(loc_in))<0)
goto error;
-
+
for ( u = 0; u < (unsigned)n; u++)
{
- /* set data buffer to NULL each iteration
- we might not use it in the case of references
+ /* set data buffer to NULL each iteration
+ we might not use it in the case of references
*/
- buf=NULL;
+ buf=NULL;
/*-------------------------------------------------------------------------
* open
*-------------------------------------------------------------------------
*/
/* open attribute */
- if ((attr_id = H5Aopen_idx(loc_in, u))<0)
+ if ((attr_id = H5Aopen_idx(loc_in, u))<0)
goto error;
-
+
/* get name */
- if (H5Aget_name( attr_id, 255, name )<0)
+ if (H5Aget_name( attr_id, 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++)
+ for (j=0; j<rank; j++)
nelmts*=dims[j];
-
+
if ((mtype_id=h5tools_get_native_type(ftype_id))<0)
goto error;
@@ -657,20 +657,20 @@ int copy_attr(hid_t loc_in,
/*-------------------------------------------------------------------------
* 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
+ * 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 ( ! H5Tequal(mtype_id, H5T_STD_REF_OBJ))
+ if ( ! H5Tequal(mtype_id, H5T_STD_REF_OBJ))
{
-
-
+
+
/*-------------------------------------------------------------------------
* read to memory
*-------------------------------------------------------------------------
*/
-
+
buf=(void *) HDmalloc((unsigned)(nelmts*msize));
if ( buf==NULL){
printf( "cannot read into memory\n" );
@@ -678,32 +678,32 @@ int copy_attr(hid_t loc_in,
}
if (H5Aread(attr_id,mtype_id,buf)<0)
goto error;
-
+
/*-------------------------------------------------------------------------
- * copy
+ * copy
*-------------------------------------------------------------------------
*/
-
+
if ((attr_out=H5Acreate(loc_out,name,ftype_id,space_id,H5P_DEFAULT))<0)
goto error;
if(H5Awrite(attr_out,mtype_id,buf)<0)
goto error;
-
+
/*close*/
- if (H5Aclose(attr_out)<0)
+ if (H5Aclose(attr_out)<0)
goto error;
-
-
+
+
if (buf)
free(buf);
-
-
+
+
} /*H5T_STD_REF_OBJ*/
-
+
if (options->verbose)
printf(" %-13s %s\n", "attr", name);
-
+
/*-------------------------------------------------------------------------
* close
*-------------------------------------------------------------------------
@@ -715,7 +715,7 @@ int copy_attr(hid_t loc_in,
if (H5Aclose(attr_id)<0) goto error;
} /* u */
-
+
return 0;
error: