mirror of
https://github.com/HDFGroup/hdf5.git
synced 2025-03-31 17:10:47 +08:00
[svn-r7913] Purpose:
code clean Description: separated the h5repack code in several modules Solution: Platforms tested: linux IRIX solaris Misc. update:
This commit is contained in:
parent
967a04fdec
commit
28e43d818f
7
MANIFEST
7
MANIFEST
@ -1125,18 +1125,15 @@
|
||||
./tools/h5repack/Dependencies
|
||||
./tools/h5repack/Makefile.in
|
||||
./tools/h5repack/h5repack.sh
|
||||
./tools/h5repack/h5repack.h
|
||||
./tools/h5repack/h5repack.c
|
||||
./tools/h5repack/h5repack_list.c
|
||||
./tools/h5repack/h5repack_copy.c
|
||||
./tools/h5repack/h5repack_main.c
|
||||
./tools/h5repack/h5repack_opttable.c
|
||||
./tools/h5repack/h5repack_parse.c
|
||||
./tools/h5repack/h5repack.h
|
||||
./tools/h5repack/h5repack_list.h
|
||||
./tools/h5repack/h5repack_opttable.h
|
||||
./tools/h5repack/h5repack_parse.h
|
||||
./tools/h5repack/test_h5repack_add.c
|
||||
./tools/h5repack/test_h5repack_main.c
|
||||
./tools/h5repack/test_h5repack_add.h
|
||||
|
||||
|
||||
./tools/h5ls/Dependencies
|
||||
|
@ -50,10 +50,10 @@ MOSTLYCLEAN=*.h5
|
||||
|
||||
## Source and object files for programs...
|
||||
##
|
||||
PROG_SRC=h5repack.c h5repack_list.c h5repack_main.c h5repack_opttable.c h5repack_parse.c test_h5repack_add.c test_h5repack_main.c
|
||||
PROG_SRC=h5repack.c h5repack_copy.c h5repack_list.c h5repack_main.c h5repack_opttable.c h5repack_parse.c test_h5repack_add.c test_h5repack_main.c
|
||||
PROG_OBJ=$(PROG_SRC:.c=.lo)
|
||||
OBJS=h5repack.lo h5repack_list.lo h5repack_main.lo h5repack_opttable.lo h5repack_parse.lo
|
||||
TEST_OBJS=h5repack.lo h5repack_list.lo h5repack_opttable.lo h5repack_parse.lo test_h5repack_add.lo test_h5repack_main.lo
|
||||
OBJS=h5repack.lo h5repack_copy.lo h5repack_list.lo h5repack_main.lo h5repack_opttable.lo h5repack_parse.lo
|
||||
TEST_OBJS=h5repack.lo h5repack_copy.lo h5repack_list.lo h5repack_opttable.lo h5repack_parse.lo test_h5repack_add.lo test_h5repack_main.lo
|
||||
|
||||
PRIVATE_HDR=
|
||||
|
||||
|
@ -14,14 +14,14 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "h5repack.h"
|
||||
#include "h5repack_opttable.h"
|
||||
#include "h5repack_parse.h"
|
||||
#include "h5repack_list.h"
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* File: h5repack.c
|
||||
* Purpose: Public API functions
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
|
||||
static void print_options(pack_opt_t *options);
|
||||
static int check_options(pack_opt_t *options);
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Function: h5repack
|
||||
@ -46,25 +46,18 @@ int h5repack(const char* infile,
|
||||
const char* outfile,
|
||||
pack_opt_t *options)
|
||||
{
|
||||
options->trip=0;
|
||||
|
||||
/* also checks input */
|
||||
print_options(options);
|
||||
|
||||
/* first check for objects in input that are in the file */
|
||||
if (get_objlist(infile,options)==0)
|
||||
{
|
||||
/* the real deal now */
|
||||
options->trip=1;
|
||||
|
||||
if (options->verbose)
|
||||
printf("Making file <%s>...\n",outfile);
|
||||
|
||||
if (copy_file(infile,outfile,options)<0)
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
||||
/* 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;
|
||||
|
||||
/* copy the file */
|
||||
if (copy_file(infile,outfile,options)<0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -108,7 +101,7 @@ int h5repack_end (pack_opt_t *options)
|
||||
* Purpose: add a compression -t option to table
|
||||
* Example: -t "*:GZIP 6" , STR = "*:GZIP 6"
|
||||
*
|
||||
* Return: 0, ok, exit, fail
|
||||
* Return: 0, ok, -1, fail
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -123,7 +116,7 @@ int h5repack_addcomp(const char* str,
|
||||
|
||||
if (options->all_comp==1){
|
||||
printf("Error: Invalid compression input: '*' is present with other objects <%s>\n",str);
|
||||
exit(1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* parse the -t option */
|
||||
@ -147,7 +140,7 @@ int h5repack_addcomp(const char* str,
|
||||
printf("\nError: '*' cannot be with other objects, <%s>. Exiting...\n",str);
|
||||
free(obj_list);
|
||||
options_table_free(options->op_tbl);
|
||||
exit(1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (options->all_comp==0)
|
||||
@ -182,7 +175,7 @@ int h5repack_addchunk(const char* str,
|
||||
|
||||
if (options->all_chunk==1){
|
||||
printf("Error: Invalid chunking input: '*' is present with other objects <%s>\n",str);
|
||||
exit(1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* parse the -c option */
|
||||
@ -208,7 +201,7 @@ int h5repack_addchunk(const char* str,
|
||||
printf("\nError: '*' cannot be with other objects, <%s>. Exiting...\n",str);
|
||||
free(obj_list);
|
||||
options_table_free(options->op_tbl);
|
||||
exit(1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (options->all_chunk==0)
|
||||
@ -220,11 +213,11 @@ int h5repack_addchunk(const char* str,
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Function: print_options
|
||||
* Function: check_options
|
||||
*
|
||||
* Purpose: print options, checks for invalid options
|
||||
*
|
||||
* Return: void, exit on error
|
||||
* Return: void, return -1 on error
|
||||
*
|
||||
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
|
||||
*
|
||||
@ -232,8 +225,7 @@ int h5repack_addchunk(const char* str,
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
static
|
||||
void print_options(pack_opt_t *options)
|
||||
static int check_options(pack_opt_t *options)
|
||||
{
|
||||
int i, k, j, has_cp=0, has_ck=0;
|
||||
|
||||
@ -277,7 +269,7 @@ void print_options(pack_opt_t *options)
|
||||
|
||||
if (options->all_chunk==1 && has_ck){
|
||||
printf("Error: Invalid chunking input: '*' is present with other objects\n");
|
||||
exit(1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
@ -327,8 +319,9 @@ void print_options(pack_opt_t *options)
|
||||
|
||||
if (options->all_comp==1 && has_cp){
|
||||
printf("Error: Invalid compression input: * is present with other objects\n");
|
||||
exit(1);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
|
@ -17,6 +17,8 @@
|
||||
#define H5REPACK_H__
|
||||
|
||||
#include "hdf5.h"
|
||||
#include "h5trav.h"
|
||||
|
||||
|
||||
#define PFORMAT "%-7s %-7s %-7s\n" /*chunk info, compression info, name*/
|
||||
#define PFORMAT1 "%-7s %-7s %-7s" /*chunk info, compression info, name*/
|
||||
@ -85,7 +87,6 @@ typedef struct {
|
||||
comp_info_t comp_g; /*global compress INFO for the ALL case */
|
||||
chunk_info_t chunk_g; /*global chunk INFO for the ALL case */
|
||||
int verbose; /*verbose mode */
|
||||
int trip; /*which cycle are we in */
|
||||
int threshold; /*minimum size to compress, in bytes */
|
||||
|
||||
} pack_opt_t;
|
||||
@ -111,14 +112,119 @@ int h5repack_end (pack_opt_t *options);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* private functions
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
int check_objects(const char* fname,
|
||||
pack_opt_t *options);
|
||||
|
||||
int copy_file(const char* fnamein,
|
||||
const char* fnameout,
|
||||
pack_opt_t *options);
|
||||
|
||||
void print_objlist(const char *filename,
|
||||
int nobjects,
|
||||
trav_info_t *info );
|
||||
|
||||
int do_copy_file(hid_t fidin,
|
||||
hid_t fidout,
|
||||
int nobjects,
|
||||
trav_info_t *info,
|
||||
pack_opt_t *options);
|
||||
|
||||
int copy_attr(hid_t loc_in,
|
||||
hid_t loc_out,
|
||||
pack_opt_t *options
|
||||
);
|
||||
|
||||
|
||||
void read_info(const char *filename,pack_opt_t *options);
|
||||
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* options table
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
int options_table_init( pack_opttbl_t **tbl );
|
||||
int options_table_free( pack_opttbl_t *table );
|
||||
int options_add_chunk ( obj_list_t *obj_list,
|
||||
int n_objs,
|
||||
hsize_t *chunk_lengths,
|
||||
int chunk_rank,
|
||||
pack_opttbl_t *table );
|
||||
int options_add_comp ( obj_list_t *obj_list,
|
||||
int n_objs,
|
||||
comp_info_t comp,
|
||||
pack_opttbl_t *table );
|
||||
pack_info_t* options_get_object( const char *path,
|
||||
pack_opttbl_t *table);
|
||||
|
||||
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* parse functions
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
obj_list_t* parse_comp (const char *str,
|
||||
int *n_objs,
|
||||
comp_info_t *comp);
|
||||
obj_list_t* parse_chunk (const char *str,
|
||||
int *n_objs,
|
||||
hsize_t *chunk_lengths,
|
||||
int *chunk_rank);
|
||||
const char* get_scomp (int code);
|
||||
int parse_number(char *str);
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* tests
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#define FNAME1 "testcopy.h5"
|
||||
#define FNAME1OUT "testcopyout.h5"
|
||||
#define FNAME2 "testfilters.h5"
|
||||
#define FNAME2OUT "testfiltersout.h5"
|
||||
|
||||
|
||||
|
||||
#define FNAME1 "testcopy.h5"
|
||||
#define FNAME1OUT "testcopyout.h5"
|
||||
#define FNAME2 "testfilters.h5"
|
||||
#define FNAME2OUT "testfiltersout.h5"
|
||||
|
||||
|
||||
int make_testfiles(void);
|
||||
|
||||
int make_all_objects(hid_t fid);
|
||||
|
||||
int make_attr(hid_t fid);
|
||||
|
||||
int write_dset( hid_t loc_id,
|
||||
int rank,
|
||||
hsize_t *dims,
|
||||
const char *dset_name,
|
||||
hid_t type_id,
|
||||
void *buf );
|
||||
|
||||
int write_attr(hid_t loc_id,
|
||||
int rank,
|
||||
hsize_t *dims,
|
||||
const char *attr_name,
|
||||
hid_t type_id,
|
||||
void *buf);
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* H5REPACK_H__ */
|
||||
|
516
tools/h5repack/h5repack_copy.c
Normal file
516
tools/h5repack/h5repack_copy.c
Normal file
@ -0,0 +1,516 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* 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://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have *
|
||||
* access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "H5private.h"
|
||||
#include "h5repack.h"
|
||||
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* 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(const char* fnamein,
|
||||
const char* fnameout,
|
||||
pack_opt_t *options)
|
||||
{
|
||||
hid_t fidin;
|
||||
hid_t fidout;
|
||||
int nobjects;
|
||||
trav_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;
|
||||
|
||||
|
||||
if (options->verbose)
|
||||
printf("Making file <%s>...\n",fnameout);
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* get the number of objects in the file
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
if ((nobjects = h5trav_getinfo(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 = (trav_info_t*) malloc( nobjects * sizeof(trav_info_t)))==NULL){
|
||||
printf("h5repack: <%s>: Could not allocate object list\n", fnamein );
|
||||
return -1;
|
||||
}
|
||||
if (h5trav_getinfo(fidin, info )<0) {
|
||||
printf("h5repack: <%s>: Could not obtain object list\n", fnamein );
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* do the copy
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
if(do_copy_file(fidin,fidout,nobjects,info,options)<0) {
|
||||
printf("h5repack: <%s>: Could not copy data to: %s\n", fnamein, fnameout);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* free
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
H5Fclose(fidin);
|
||||
H5Fclose(fidout);
|
||||
h5trav_freeinfo(info,nobjects);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* 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,
|
||||
trav_info_t *info,
|
||||
pack_opt_t *options)
|
||||
{
|
||||
hid_t grp_in; /* group ID */
|
||||
hid_t grp_out; /* group ID */
|
||||
hid_t dset_in; /* read dataset ID */
|
||||
hid_t dset_out; /* write dataset ID */
|
||||
hid_t type_in; /* named type ID */
|
||||
hid_t type_out; /* named type 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 dataset */
|
||||
int rank; /* rank of dataset */
|
||||
hsize_t dims[H5S_MAX_RANK];/* dimensions of dataset */
|
||||
int i, j;
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* copy the suppplied object list
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
for ( i = 0; i < nobjects; i++)
|
||||
{
|
||||
switch ( info[i].type )
|
||||
{
|
||||
/*-------------------------------------------------------------------------
|
||||
* H5G_GROUP
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
case H5G_GROUP:
|
||||
if (options->verbose)
|
||||
printf(" %-10s %s\n", "group",info[i].name );
|
||||
|
||||
if ((grp_out=H5Gcreate(fidout, info[i].name, 0))<0)
|
||||
goto error;
|
||||
|
||||
if((grp_in = H5Gopen (fidin, info[i].name))<0)
|
||||
goto error;
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* copy attrs
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
if (copy_attr(grp_in,grp_out,options)<0)
|
||||
goto error;
|
||||
|
||||
if (H5Gclose(grp_out)<0)
|
||||
goto error;
|
||||
if (H5Gclose(grp_in)<0)
|
||||
goto error;
|
||||
|
||||
break;
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* H5G_DATASET
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
case H5G_DATASET:
|
||||
if (options->verbose)
|
||||
printf(" %-10s %s\n", "dataset",info[i].name );
|
||||
|
||||
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;
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* copy attrs
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
if (copy_attr(dset_in,dset_out,options)<0)
|
||||
goto error;
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* close
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
if (buf)
|
||||
free(buf);
|
||||
|
||||
break;
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* H5G_TYPE
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
case H5G_TYPE:
|
||||
|
||||
if ((type_in = H5Topen (fidin, info[i].name))<0)
|
||||
goto error;
|
||||
|
||||
if ((type_out = H5Tcopy(type_in))<0)
|
||||
goto error;
|
||||
|
||||
if ((H5Tcommit(fidout, info[i].name, type_out))<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 (options->verbose)
|
||||
printf(" %-10s %s\n", "datatype",info[i].name );
|
||||
|
||||
break;
|
||||
|
||||
case H5G_LINK:
|
||||
|
||||
{
|
||||
|
||||
H5G_stat_t statbuf;
|
||||
char *targbuf=NULL;
|
||||
|
||||
if (H5Gget_objinfo(fidin,info[i].name,FALSE,&statbuf)<0)
|
||||
goto error;
|
||||
|
||||
targbuf = malloc(statbuf.linklen);
|
||||
|
||||
if (H5Gget_linkval(fidin,info[i].name,statbuf.linklen,targbuf)<0)
|
||||
goto error;
|
||||
|
||||
if (H5Glink(fidout,
|
||||
H5G_LINK_SOFT,
|
||||
targbuf, /* current name of object */
|
||||
info[i].name /* new name of object */
|
||||
)<0)
|
||||
goto error;
|
||||
|
||||
free(targbuf);
|
||||
|
||||
if (options->verbose)
|
||||
printf(" %-10s %s\n", "link",info[i].name );
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (options->verbose)
|
||||
printf(" %-10s %s\n", "User defined object", info[i].name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* 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)
|
||||
goto error;
|
||||
|
||||
if ((grp_in = H5Gopen(fidin,"/"))<0)
|
||||
goto error;
|
||||
|
||||
if (copy_attr(grp_in,grp_out,options)<0)
|
||||
goto error;
|
||||
|
||||
if (H5Gclose(grp_out)<0)
|
||||
goto error;
|
||||
if (H5Gclose(grp_in)<0)
|
||||
goto error;
|
||||
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
H5E_BEGIN_TRY {
|
||||
H5Gclose(grp_in);
|
||||
H5Gclose(grp_out);
|
||||
H5Pclose(dcpl_id);
|
||||
H5Sclose(space_id);
|
||||
H5Dclose(dset_in);
|
||||
H5Dclose(dset_out);
|
||||
H5Tclose(ftype_id);
|
||||
H5Tclose(mtype_id);
|
||||
H5Tclose(type_in);
|
||||
H5Tclose(type_out);
|
||||
if (buf)
|
||||
free(buf);
|
||||
} H5E_END_TRY;
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Function: copy_attr
|
||||
*
|
||||
* 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);
|
||||
*
|
||||
* 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,
|
||||
pack_opt_t *options
|
||||
)
|
||||
{
|
||||
hid_t attr_id; /* attr ID */
|
||||
hid_t attr_out; /* attr 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 dataset */
|
||||
int rank; /* rank of dataset */
|
||||
hsize_t dims[H5S_MAX_RANK];/* dimensions of dataset */
|
||||
char name[255];
|
||||
int n, j;
|
||||
unsigned u;
|
||||
|
||||
if ((n = H5Aget_num_attrs(loc_in))<0)
|
||||
goto error;
|
||||
|
||||
for ( u = 0; u < (unsigned)n; u++)
|
||||
{
|
||||
/*-------------------------------------------------------------------------
|
||||
* open
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
/* open attribute */
|
||||
if ((attr_id = H5Aopen_idx(loc_in, u))<0)
|
||||
goto error;
|
||||
|
||||
/* get name */
|
||||
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;
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* 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 (H5Aread(attr_id,mtype_id,buf)<0)
|
||||
goto error;
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* 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;
|
||||
|
||||
if (options->verbose)
|
||||
printf(" %-13s %s\n", "attr", name);
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* close
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
if (H5Tclose(ftype_id)<0) goto error;
|
||||
if (H5Tclose(mtype_id)<0) goto error;
|
||||
if (H5Sclose(space_id)<0) goto error;
|
||||
if (H5Aclose(attr_id)<0) goto error;
|
||||
if (H5Aclose(attr_out)<0) goto error;
|
||||
if (buf)
|
||||
free(buf);
|
||||
} /* u */
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
H5E_BEGIN_TRY {
|
||||
H5Tclose(ftype_id);
|
||||
H5Tclose(mtype_id);
|
||||
H5Sclose(space_id);
|
||||
H5Aclose(attr_id);
|
||||
H5Aclose(attr_out);
|
||||
if (buf)
|
||||
free(buf);
|
||||
} H5E_END_TRY;
|
||||
return -1;
|
||||
}
|
@ -18,14 +18,13 @@
|
||||
#include <stdio.h>
|
||||
#include "H5private.h"
|
||||
#include "h5repack.h"
|
||||
#include "h5repack_list.h"
|
||||
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Function: get_objlist
|
||||
* Function: check_objects
|
||||
*
|
||||
* Purpose: locate all HDF5 objects in the file
|
||||
* Purpose: locate all HDF5 objects in the file and compare with user
|
||||
* supplied list
|
||||
*
|
||||
* Return: 0, ok, -1 no
|
||||
*
|
||||
@ -35,10 +34,8 @@
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
int get_objlist(const char* fname,
|
||||
pack_opt_t *options)
|
||||
int check_objects(const char* fname,
|
||||
pack_opt_t *options)
|
||||
{
|
||||
hid_t fid;
|
||||
int nobjects, i;
|
||||
@ -111,9 +108,6 @@ int get_objlist(const char* fname,
|
||||
if (options->verbose)
|
||||
printf("...Found\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* free
|
||||
*-------------------------------------------------------------------------
|
||||
@ -121,100 +115,6 @@ int get_objlist(const char* fname,
|
||||
H5Fclose(fid);
|
||||
h5trav_freeinfo(info,nobjects);
|
||||
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(const char* fnamein,
|
||||
const char* fnameout,
|
||||
pack_opt_t *options)
|
||||
{
|
||||
hid_t fidin;
|
||||
hid_t fidout;
|
||||
int nobjects;
|
||||
trav_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 = h5trav_getinfo(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 = (trav_info_t*) malloc( nobjects * sizeof(trav_info_t)))==NULL){
|
||||
printf("h5repack: <%s>: Could not allocate object list\n", fnamein );
|
||||
return -1;
|
||||
}
|
||||
if (h5trav_getinfo(fidin, info )<0) {
|
||||
printf("h5repack: <%s>: Could not obtain object list\n", fnamein );
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* do the copy
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
if(do_copy_file(fidin,fidout,nobjects,info,options)<0) {
|
||||
printf("h5repack: <%s>: Could not copy data to: %s\n", fnamein, fnameout);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* free
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
H5Fclose(fidin);
|
||||
H5Fclose(fidout);
|
||||
h5trav_freeinfo(info,nobjects);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -263,377 +163,3 @@ void print_objlist(const char *filename,
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* 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,
|
||||
trav_info_t *info,
|
||||
pack_opt_t *options)
|
||||
{
|
||||
hid_t grp_in; /* group ID */
|
||||
hid_t grp_out; /* group ID */
|
||||
hid_t dset_in; /* read dataset ID */
|
||||
hid_t dset_out; /* write dataset ID */
|
||||
hid_t type_in; /* named type ID */
|
||||
hid_t type_out; /* named type 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 dataset */
|
||||
int rank; /* rank of dataset */
|
||||
hsize_t dims[H5S_MAX_RANK];/* dimensions of dataset */
|
||||
int i, j;
|
||||
|
||||
for ( i = 0; i < nobjects; i++)
|
||||
{
|
||||
switch ( info[i].type )
|
||||
{
|
||||
/*-------------------------------------------------------------------------
|
||||
* H5G_GROUP
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
case H5G_GROUP:
|
||||
if (options->verbose)
|
||||
printf(" %-10s %s\n", "group",info[i].name );
|
||||
|
||||
if ((grp_out=H5Gcreate(fidout, info[i].name, 0))<0)
|
||||
goto error;
|
||||
|
||||
if((grp_in = H5Gopen (fidin, info[i].name))<0)
|
||||
goto error;
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* copy attrs
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
copy_attr(grp_in,
|
||||
grp_out,
|
||||
options);
|
||||
|
||||
if (H5Gclose(grp_out)<0)
|
||||
goto error;
|
||||
if (H5Gclose(grp_in)<0)
|
||||
goto error;
|
||||
|
||||
break;
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* H5G_DATASET
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
case H5G_DATASET:
|
||||
if (options->verbose)
|
||||
printf(" %-10s %s\n", "dataset",info[i].name );
|
||||
|
||||
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;
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* copy attrs
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
copy_attr(dset_in,
|
||||
dset_out,
|
||||
options);
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* close
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
if (buf)
|
||||
free(buf);
|
||||
|
||||
break;
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* H5G_TYPE
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
case H5G_TYPE:
|
||||
|
||||
if ((type_in = H5Topen (fidin, info[i].name))<0)
|
||||
goto error;
|
||||
|
||||
if ((type_out = H5Tcopy(type_in))<0)
|
||||
goto error;
|
||||
|
||||
if ((H5Tcommit(fidout, info[i].name, type_out))<0)
|
||||
goto error;
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* copy attrs
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
copy_attr(type_in,
|
||||
type_out,
|
||||
options);
|
||||
|
||||
if (H5Tclose(type_in)<0)
|
||||
goto error;
|
||||
if (H5Tclose(type_out)<0)
|
||||
goto error;
|
||||
|
||||
if (options->verbose)
|
||||
printf(" %-10s %s\n", "datatype",info[i].name );
|
||||
|
||||
break;
|
||||
|
||||
case H5G_LINK:
|
||||
|
||||
{
|
||||
|
||||
H5G_stat_t statbuf;
|
||||
char *targbuf=NULL;
|
||||
|
||||
if (H5Gget_objinfo(fidin,info[i].name,FALSE,&statbuf)<0)
|
||||
goto error;
|
||||
|
||||
targbuf = malloc(statbuf.linklen);
|
||||
|
||||
if (H5Gget_linkval(fidin,info[i].name,statbuf.linklen,targbuf)<0)
|
||||
goto error;
|
||||
|
||||
if (H5Glink(fidout,
|
||||
H5G_LINK_SOFT,
|
||||
targbuf, /* current name of object */
|
||||
info[i].name /* new name of object */
|
||||
)<0)
|
||||
goto error;
|
||||
|
||||
free(targbuf);
|
||||
|
||||
if (options->verbose)
|
||||
printf(" %-10s %s\n", "link",info[i].name );
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (options->verbose)
|
||||
printf(" %-10s %s\n", "User defined object", info[i].name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
H5E_BEGIN_TRY {
|
||||
H5Gclose(grp_in);
|
||||
H5Gclose(grp_out);
|
||||
H5Pclose(dcpl_id);
|
||||
H5Sclose(space_id);
|
||||
H5Dclose(dset_in);
|
||||
H5Dclose(dset_out);
|
||||
H5Tclose(ftype_id);
|
||||
H5Tclose(mtype_id);
|
||||
H5Tclose(type_in);
|
||||
H5Tclose(type_out);
|
||||
if (buf)
|
||||
free(buf);
|
||||
} H5E_END_TRY;
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Function: copy_attr
|
||||
*
|
||||
* 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);
|
||||
*
|
||||
* 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,
|
||||
pack_opt_t *options
|
||||
)
|
||||
{
|
||||
hid_t attr_id; /* attr ID */
|
||||
hid_t attr_out; /* attr 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 dataset */
|
||||
int rank; /* rank of dataset */
|
||||
hsize_t dims[H5S_MAX_RANK];/* dimensions of dataset */
|
||||
char name[255];
|
||||
int n, j;
|
||||
unsigned u;
|
||||
|
||||
if ((n = H5Aget_num_attrs(loc_in))<0)
|
||||
goto error;
|
||||
|
||||
for ( u = 0; u < (unsigned)n; u++)
|
||||
{
|
||||
/*-------------------------------------------------------------------------
|
||||
* open
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
/* open attribute */
|
||||
if ((attr_id = H5Aopen_idx(loc_in, u))<0)
|
||||
goto error;
|
||||
|
||||
/* get name */
|
||||
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;
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* 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 (H5Aread(attr_id,mtype_id,buf)<0)
|
||||
goto error;
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* 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;
|
||||
|
||||
if (options->verbose)
|
||||
printf(" %-13s %s\n", "attr", name);
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* close
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
if (H5Tclose(ftype_id)<0) goto error;
|
||||
if (H5Tclose(mtype_id)<0) goto error;
|
||||
if (H5Sclose(space_id)<0) goto error;
|
||||
if (H5Aclose(attr_id)<0) goto error;
|
||||
if (H5Aclose(attr_out)<0) goto error;
|
||||
if (buf)
|
||||
free(buf);
|
||||
} /* u */
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
H5E_BEGIN_TRY {
|
||||
H5Tclose(ftype_id);
|
||||
H5Tclose(mtype_id);
|
||||
H5Sclose(space_id);
|
||||
H5Aclose(attr_id);
|
||||
H5Aclose(attr_out);
|
||||
if (buf)
|
||||
free(buf);
|
||||
} H5E_END_TRY;
|
||||
return -1;
|
||||
}
|
||||
|
@ -1,56 +0,0 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* 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://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have *
|
||||
* access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
|
||||
|
||||
#ifndef H5REPACK_LIST_H__
|
||||
#define H5REPACK_LIST_H__
|
||||
|
||||
#include "h5repack.h"
|
||||
#include "h5trav.h"
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* private functions
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
int get_objlist(const char* infname,
|
||||
pack_opt_t *options);
|
||||
|
||||
int copy_file(const char* fnamein,
|
||||
const char* fnameout,
|
||||
pack_opt_t *options);
|
||||
|
||||
void print_objlist(const char *filename,
|
||||
int nobjects,
|
||||
trav_info_t *info );
|
||||
|
||||
int do_copy_file(hid_t fidin,
|
||||
hid_t fidout,
|
||||
int nobjects,
|
||||
trav_info_t *info,
|
||||
pack_opt_t *options);
|
||||
|
||||
int copy_attr(hid_t loc_in,
|
||||
hid_t loc_out,
|
||||
pack_opt_t *options
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* H5REPACK_LIST_H__ */
|
@ -12,9 +12,9 @@
|
||||
* access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#include "h5repack.h"
|
||||
#include "h5repack_parse.h"
|
||||
#include <stdlib.h>
|
||||
#include "h5repack.h"
|
||||
|
||||
|
||||
|
||||
static void usage(void);
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "h5repack_opttable.h"
|
||||
#include "h5repack.h"
|
||||
|
||||
|
||||
|
||||
|
@ -1,48 +0,0 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* 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://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have *
|
||||
* access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
|
||||
#ifndef H5REPACK_OPTTABLE_H__
|
||||
#define H5REPACK_OPTTABLE_H__
|
||||
|
||||
|
||||
#include "h5repack.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
int options_table_init( pack_opttbl_t **tbl );
|
||||
int options_table_free( pack_opttbl_t *table );
|
||||
int options_add_chunk ( obj_list_t *obj_list,
|
||||
int n_objs,
|
||||
hsize_t *chunk_lengths,
|
||||
int chunk_rank,
|
||||
pack_opttbl_t *table );
|
||||
int options_add_comp ( obj_list_t *obj_list,
|
||||
int n_objs,
|
||||
comp_info_t comp,
|
||||
pack_opttbl_t *table );
|
||||
pack_info_t* options_get_object( const char *path,
|
||||
pack_opttbl_t *table);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* H5REPACK_OPTTABLE_H__ */
|
@ -16,7 +16,7 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include "h5repack_parse.h"
|
||||
#include "h5repack.h"
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
|
@ -1,39 +0,0 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* 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://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have *
|
||||
* access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
|
||||
#ifndef H5REPACK_PARSE_H__
|
||||
#define H5REPACK_PARSE_H__
|
||||
|
||||
|
||||
#include "h5repack.h"
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* private functions
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
obj_list_t* parse_comp (const char *str,
|
||||
int *n_objs,
|
||||
comp_info_t *comp);
|
||||
obj_list_t* parse_chunk (const char *str,
|
||||
int *n_objs,
|
||||
hsize_t *chunk_lengths,
|
||||
int *chunk_rank);
|
||||
const char* get_scomp (int code);
|
||||
int parse_number(char *str);
|
||||
|
||||
|
||||
#endif /* H5REPACK_PARSE_H__ */
|
File diff suppressed because it is too large
Load Diff
@ -1,37 +0,0 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* 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://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have *
|
||||
* access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
|
||||
|
||||
#ifndef H5REPACK_ADD_H__
|
||||
#define H5REPACK_ADD_H__
|
||||
|
||||
|
||||
#define FILENAME "h5repacktst.h5"
|
||||
#define FILENAME_OUT "h5repacktstout.h5"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int make_dsets(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* H5REPACK_ADD_H__ */
|
@ -16,48 +16,40 @@
|
||||
#include "h5test.h"
|
||||
#include "h5repack.h"
|
||||
#include "h5diff.h"
|
||||
#include "test_h5repack_add.h"
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Function: test
|
||||
* Function: test_copy
|
||||
*
|
||||
* Purpose:
|
||||
* Purpose:
|
||||
*
|
||||
* 1) compress/chunk FILENAME with some compression/chunking options
|
||||
* 1) make a copy with no filters
|
||||
* 2) use the h5diff utility to compare the input and output file;
|
||||
* it returns RET==0 if the objects have the same data
|
||||
* 3) use API functions to verify the compression/chunking input on the otput file
|
||||
*
|
||||
* Return: Success: zero
|
||||
* Failure: 1
|
||||
* Return: Success: zero
|
||||
* Failure: 1
|
||||
*
|
||||
* Programmer: Pedro Vicente <pvn@ncsa.uiuc.edu>
|
||||
* Programmer: Pedro Vicente <pvn@ncsa.uiuc.edu>
|
||||
* September, 19, 2003
|
||||
*
|
||||
* Modifications:
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
static int
|
||||
test(void)
|
||||
test_copy(void)
|
||||
{
|
||||
pack_opt_t pack_options;
|
||||
diff_opt_t diff_options;
|
||||
memset(&diff_options, 0, sizeof (diff_opt_t));
|
||||
|
||||
TESTING(" deflate filter");
|
||||
TESTING(" copy with no filters");
|
||||
|
||||
if (h5repack_init (&pack_options, 0)<0)
|
||||
TEST_ERROR;
|
||||
if (h5repack_addcomp("dset1:GZIP 9",&pack_options)<0)
|
||||
TEST_ERROR;
|
||||
if (h5repack_addchunk("dset1:5x4",&pack_options)<0)
|
||||
TEST_ERROR;
|
||||
if (h5repack(FILENAME,FILENAME_OUT,&pack_options)<0)
|
||||
if (h5repack(FNAME1,FNAME1OUT,&pack_options)<0)
|
||||
TEST_ERROR;
|
||||
if (h5repack_end (&pack_options)<0)
|
||||
TEST_ERROR;
|
||||
if (h5diff(FILENAME,FILENAME,NULL,NULL,&diff_options) == 1)
|
||||
if (h5diff(FNAME1,FNAME1OUT,NULL,NULL,&diff_options) == 1)
|
||||
TEST_ERROR;
|
||||
|
||||
PASSED();
|
||||
@ -69,15 +61,70 @@ error:
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Function: main
|
||||
* Function: test_filter_deflate
|
||||
*
|
||||
* Purpose: Executes h5repack tests
|
||||
* Purpose:
|
||||
*
|
||||
* Return: Success: zero
|
||||
* Failure: non-zero
|
||||
* 1) compress/chunk FILENAME with teh DEFLATE filter
|
||||
* 2) use the h5diff utility to compare the input and output file;
|
||||
* it returns RET==0 if the objects have the same data
|
||||
* 3) use API functions to verify the compression/chunking input on the otput file
|
||||
*
|
||||
* Programmer: Pedro Vicente <pvn@ncsa.uiuc.edu>
|
||||
* Return: Success: zero
|
||||
* Failure: 1
|
||||
*
|
||||
* Programmer: Pedro Vicente <pvn@ncsa.uiuc.edu>
|
||||
* September, 19, 2003
|
||||
*
|
||||
* Modifications:
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
static int
|
||||
test_filter_deflate(void)
|
||||
{
|
||||
pack_opt_t pack_options;
|
||||
diff_opt_t diff_options;
|
||||
memset(&diff_options, 0, sizeof (diff_opt_t));
|
||||
|
||||
TESTING(" deflate filter");
|
||||
|
||||
if (h5repack_init (&pack_options, 0)<0)
|
||||
TEST_ERROR;
|
||||
if (h5repack_addcomp("dset_gzip:GZIP 9",&pack_options)<0)
|
||||
TEST_ERROR;
|
||||
if (h5repack_addchunk("dset_gzip:5x4",&pack_options)<0)
|
||||
TEST_ERROR;
|
||||
if (h5repack(FNAME2,FNAME2OUT,&pack_options)<0)
|
||||
TEST_ERROR;
|
||||
if (h5repack_end (&pack_options)<0)
|
||||
TEST_ERROR;
|
||||
if (h5diff(FNAME2,FNAME2OUT,NULL,NULL,&diff_options) == 1)
|
||||
TEST_ERROR;
|
||||
|
||||
PASSED();
|
||||
return 0;
|
||||
|
||||
error:
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Function: main
|
||||
*
|
||||
* Purpose: Executes h5repack tests
|
||||
*
|
||||
* Return: Success: zero
|
||||
* Failure: non-zero
|
||||
*
|
||||
* Programmer: Pedro Vicente <pvn@ncsa.uiuc.edu>
|
||||
* September, 19, 2003
|
||||
*
|
||||
* Modifications:
|
||||
@ -87,12 +134,19 @@ error:
|
||||
|
||||
int main (void)
|
||||
{
|
||||
int nerrors=0;
|
||||
int nerrors=0;
|
||||
|
||||
/* run tests */
|
||||
puts("Testing h5repack:");
|
||||
nerrors += make_dsets();
|
||||
nerrors += test();
|
||||
|
||||
/* make the test files */
|
||||
nerrors += make_testfiles();
|
||||
|
||||
/* test a copy with no filters */
|
||||
nerrors += test_copy();
|
||||
|
||||
/* test a copy with the deflate filter */
|
||||
nerrors += test_filter_deflate();
|
||||
|
||||
|
||||
/* check for errors */
|
||||
|
@ -417,8 +417,13 @@ int diff( hid_t file1_id,
|
||||
/* if H5Tequal is > 0 then the datatypes refer to the same datatype */
|
||||
nfound = (ret>0) ? 0 : 1;
|
||||
|
||||
/* compare attributes */
|
||||
nfound=diff_attr(type1_id,type2_id,path1,path2,options);
|
||||
/*-------------------------------------------------------------------------
|
||||
* compare attributes
|
||||
* the if condition refers to cases when the dataset is a referenced object
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
if (path1)
|
||||
nfound=diff_attr(type1_id,type2_id,path1,path2,options);
|
||||
|
||||
if ( H5Tclose(type1_id)<0)
|
||||
goto out;
|
||||
@ -445,8 +450,13 @@ int diff( hid_t file1_id,
|
||||
/* if "path1" != "path2" then the groups are "different" */
|
||||
nfound = (ret!=0) ? 1 : 0;
|
||||
|
||||
/* compare attributes */
|
||||
nfound=diff_attr(grp1_id,grp2_id,path1,path2,options);
|
||||
/*-------------------------------------------------------------------------
|
||||
* compare attributes
|
||||
* the if condition refers to cases when the dataset is a referenced object
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
if (path1)
|
||||
nfound=diff_attr(grp1_id,grp2_id,path1,path2,options);
|
||||
|
||||
if ( H5Gclose(grp1_id)<0)
|
||||
goto out;
|
||||
|
@ -347,10 +347,12 @@ int diff_datasetid( hid_t dset1_id,
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* compare attributes
|
||||
* the if condition refers to cases when the dataset is a referenced object
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
nfound=diff_attr(dset1_id,dset2_id,obj1_name,obj2_name,options);
|
||||
if (obj1_name)
|
||||
nfound=diff_attr(dset1_id,dset2_id,obj1_name,obj2_name,options);
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* close
|
||||
|
Loading…
x
Reference in New Issue
Block a user