From 28e43d818f105e2b93caa1b39a0ea056d8f3393e Mon Sep 17 00:00:00 2001 From: Pedro Vicente Nunes Date: Thu, 4 Dec 2003 14:35:33 -0500 Subject: [svn-r7913] Purpose: code clean Description: separated the h5repack code in several modules Solution: Platforms tested: linux IRIX solaris Misc. update: --- MANIFEST | 7 +- tools/h5repack/Makefile.in | 6 +- tools/h5repack/h5repack.c | 65 +- tools/h5repack/h5repack.h | 108 ++- tools/h5repack/h5repack_copy.c | 516 +++++++++++++++ tools/h5repack/h5repack_list.c | 484 +------------- tools/h5repack/h5repack_list.h | 56 -- tools/h5repack/h5repack_main.c | 4 +- tools/h5repack/h5repack_opttable.c | 2 +- tools/h5repack/h5repack_opttable.h | 48 -- tools/h5repack/h5repack_parse.c | 2 +- tools/h5repack/h5repack_parse.h | 39 -- tools/h5repack/test_h5repack_add.c | 1235 ++++++++++++++++++++++++++++++++++- tools/h5repack/test_h5repack_add.h | 37 -- tools/h5repack/test_h5repack_main.c | 94 ++- tools/lib/h5diff.c | 18 +- tools/lib/h5diff_dset.c | 4 +- 17 files changed, 1964 insertions(+), 761 deletions(-) create mode 100644 tools/h5repack/h5repack_copy.c delete mode 100644 tools/h5repack/h5repack_list.h delete mode 100644 tools/h5repack/h5repack_opttable.h delete mode 100644 tools/h5repack/h5repack_parse.h delete mode 100644 tools/h5repack/test_h5repack_add.h diff --git a/MANIFEST b/MANIFEST index d186e47..8506c84 100644 --- a/MANIFEST +++ b/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 diff --git a/tools/h5repack/Makefile.in b/tools/h5repack/Makefile.in index 7ea6e23..617e4c6 100644 --- a/tools/h5repack/Makefile.in +++ b/tools/h5repack/Makefile.in @@ -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= diff --git a/tools/h5repack/h5repack.c b/tools/h5repack/h5repack.c index 2678b20..b989ab3 100644 --- a/tools/h5repack/h5repack.c +++ b/tools/h5repack/h5repack.c @@ -14,14 +14,14 @@ #include #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; } /*------------------------------------------------------------------------- diff --git a/tools/h5repack/h5repack.h b/tools/h5repack/h5repack.h index a1085da..bb0f8fc 100644 --- a/tools/h5repack/h5repack.h +++ b/tools/h5repack/h5repack.h @@ -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__ */ diff --git a/tools/h5repack/h5repack_copy.c b/tools/h5repack/h5repack_copy.c new file mode 100644 index 0000000..5c28b17 --- /dev/null +++ b/tools/h5repack/h5repack_copy.c @@ -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 +#include +#include +#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; jverbose) + 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; jverbose) + 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; +} diff --git a/tools/h5repack/h5repack_list.c b/tools/h5repack/h5repack_list.c index f1142f2..a285e3f 100644 --- a/tools/h5repack/h5repack_list.c +++ b/tools/h5repack/h5repack_list.c @@ -18,14 +18,13 @@ #include #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; jverbose) - 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; jverbose) - 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; -} diff --git a/tools/h5repack/h5repack_list.h b/tools/h5repack/h5repack_list.h deleted file mode 100644 index 29f16e6..0000000 --- a/tools/h5repack/h5repack_list.h +++ /dev/null @@ -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__ */ diff --git a/tools/h5repack/h5repack_main.c b/tools/h5repack/h5repack_main.c index 40f6f48..5a5bb78 100644 --- a/tools/h5repack/h5repack_main.c +++ b/tools/h5repack/h5repack_main.c @@ -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 +#include "h5repack.h" + static void usage(void); diff --git a/tools/h5repack/h5repack_opttable.c b/tools/h5repack/h5repack_opttable.c index f9d42b7..0dcebd4 100644 --- a/tools/h5repack/h5repack_opttable.c +++ b/tools/h5repack/h5repack_opttable.c @@ -14,7 +14,7 @@ #include -#include "h5repack_opttable.h" +#include "h5repack.h" diff --git a/tools/h5repack/h5repack_opttable.h b/tools/h5repack/h5repack_opttable.h deleted file mode 100644 index e9d0c9a..0000000 --- a/tools/h5repack/h5repack_opttable.h +++ /dev/null @@ -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__ */ diff --git a/tools/h5repack/h5repack_parse.c b/tools/h5repack/h5repack_parse.c index 5ac8bb8..f401e1c 100644 --- a/tools/h5repack/h5repack_parse.c +++ b/tools/h5repack/h5repack_parse.c @@ -16,7 +16,7 @@ #include #include #include -#include "h5repack_parse.h" +#include "h5repack.h" /*------------------------------------------------------------------------- diff --git a/tools/h5repack/h5repack_parse.h b/tools/h5repack/h5repack_parse.h deleted file mode 100644 index 83b5a28..0000000 --- a/tools/h5repack/h5repack_parse.h +++ /dev/null @@ -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__ */ diff --git a/tools/h5repack/test_h5repack_add.c b/tools/h5repack/test_h5repack_add.c index 95bb491..40a7af5 100644 --- a/tools/h5repack/test_h5repack_add.c +++ b/tools/h5repack/test_h5repack_add.c @@ -14,22 +14,20 @@ #include "hdf5.h" #include "h5test.h" -#include "test_h5repack_add.h" +#include "h5repack.h" /*------------------------------------------------------------------------- - * Function: make_deflate + * Function: make_deflate * - * Purpose: make a dataset using DEFLATE (GZIP) compression + * Purpose: make a dataset using DEFLATE (GZIP) compression in FID * - * Return: Success: zero - * Failure: 1 + * Return: Success: zero + * Failure: 1 * - * Programmer: Pedro Vicente + * Programmer: Pedro Vicente * September, 19, 2003 * - * Modifications: - * *------------------------------------------------------------------------- */ static int @@ -58,7 +56,7 @@ make_deflate(hid_t fid) TEST_ERROR; /* create the dataset */ - if((dsid = H5Dcreate (fid, "dset1", H5T_NATIVE_INT, sid, dcpl))<0) + if((dsid = H5Dcreate (fid, "dset_gzip", H5T_NATIVE_INT, sid, dcpl))<0) TEST_ERROR; /* write the data to the dataset */ @@ -80,18 +78,16 @@ error: } /*------------------------------------------------------------------------- - * Function: make_szip + * Function: make_szip * - * Purpose: make a dataset using SZIP compression + * Purpose: make a dataset using SZIP compression in FID * - * Return: Success: zero - * Failure: 1 + * Return: Success: zero + * Failure: 1 * - * Programmer: Pedro Vicente + * Programmer: Pedro Vicente * September, 19, 2003 * - * Modifications: - * *------------------------------------------------------------------------- */ static int @@ -128,7 +124,7 @@ make_szip(hid_t fid) TEST_ERROR; /* create the dataset */ - if((dsid = H5Dcreate (fid, "dset2", H5T_NATIVE_INT, sid, dcpl))<0) + if((dsid = H5Dcreate (fid, "dset_szip", H5T_NATIVE_INT, sid, dcpl))<0) TEST_ERROR; /* write the data to the dataset */ @@ -151,29 +147,38 @@ error: /*------------------------------------------------------------------------- - * Function: make_dsets + * Function: make_testfile * - * Purpose: make several datasets with DEFLATE and SZIP filters + * Purpose: make a test file with all types of HDF5 objects, + * datatypes and filters * - * Return: Success: zero - * Failure: 1 + * Return: Success: zero + * Failure: 1 * - * Programmer: Pedro Vicente + * Programmer: Pedro Vicente * September, 19, 2003 * - * Modifications: - * *------------------------------------------------------------------------- */ -int make_dsets(void) +int make_testfiles(void) { hid_t fid; /* file ID */ - int nerrors=0; + int nerrors=0; TESTING(" generating datasets"); - /* create a file */ - if((fid = H5Fcreate (FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT))<0) + /* create a file for the copy test */ + if((fid = H5Fcreate(FNAME1,H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT))<0) + TEST_ERROR; + + nerrors += make_all_objects(fid); + + /* close */ + if(H5Fclose(fid)<0) + TEST_ERROR; + + /* create a file for the filters test */ + if((fid = H5Fcreate(FNAME2,H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT))<0) TEST_ERROR; nerrors += make_deflate(fid); @@ -193,3 +198,1177 @@ error: return 1; } + + +/*------------------------------------------------------------------------- + * Function: write_attr_in + * + * Purpose: write attributes in LOC_ID (dataset, group, named datatype) + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: November 12, 2003 + * + *------------------------------------------------------------------------- + */ + + +void write_attr_in(hid_t loc_id, + const char* dset_name, /* for saving reference to dataset*/ + hid_t fid, /* for reference create */ + int make_diffs /* flag to modify data buffers */) +{ + /* Compound datatype */ + typedef struct s_t + { + char a; + double b; + } s_t; + + typedef enum + { + RED, + GREEN + } e_t; + + hid_t attr_id; + hid_t space_id; + hid_t type_id; + herr_t status; + int val, i, j, k, n; + float f; + + /* create 1D attributes with dimension [2], 2 elements */ + hsize_t dims[1]={2}; + char buf1[2][2]= {"ab","de"}; /* string */ + char buf2[2]= {1,2}; /* bitfield, opaque */ + s_t buf3[2]= {{1,2},{3,4}}; /* compound */ + hobj_ref_t buf4[2]; /* reference */ + e_t buf45[2]= {RED,RED}; /* enum */ + hvl_t buf5[2]; /* vlen */ + hsize_t dimarray[1]={3}; /* array dimension */ + int buf6[2][3]= {{1,2,3},{4,5,6}}; /* array */ + int buf7[2]= {1,2}; /* integer */ + float buf8[2]= {1,2}; /* float */ + + /* create 2D attributes with dimension [3][2], 6 elements */ + hsize_t dims2[2]={3,2}; + char buf12[6][2]= {"ab","cd","ef","gh","ij","kl"}; /* string */ + char buf22[3][2]= {{1,2},{3,4},{5,6}}; /* bitfield, opaque */ + s_t buf32[6]= {{1,2},{3,4},{5,6},{7,8},{9,10},{11,12}}; /* compound */ + hobj_ref_t buf42[3][2]; /* reference */ + e_t buf452[3][2]; /* enum */ + hvl_t buf52[3][2]; /* vlen */ + int buf62[6][3]= {{1,2,3},{4,5,6},{7,8,9},{10,11,12},{13,14,15},{16,17,18}}; /* array */ + int buf72[3][2]= {{1,2},{3,4},{5,6}}; /* integer */ + float buf82[3][2]= {{1,2},{3,4},{5,6}}; /* float */ + + /* create 3D attributes with dimension [4][3][2], 24 elements */ + hsize_t dims3[3]={4,3,2}; + char buf13[24][2]= {"ab","cd","ef","gh","ij","kl","mn","pq", + "rs","tu","vw","xz","AB","CD","EF","GH", + "IJ","KL","MN","PQ","RS","TU","VW","XZ"}; /* string */ + char buf23[4][3][2]; /* bitfield, opaque */ + s_t buf33[4][3][2]; /* compound */ + hobj_ref_t buf43[4][3][2]; /* reference */ + e_t buf453[4][3][2]; /* enum */ + hvl_t buf53[4][3][2]; /* vlen */ + int buf63[24][3]; /* array */ + int buf73[4][3][2]; /* integer */ + float buf83[4][3][2]; /* float */ + + +/*------------------------------------------------------------------------- + * 1D attributes + *------------------------------------------------------------------------- + */ + +/*------------------------------------------------------------------------- + * H5T_STRING + *------------------------------------------------------------------------- + */ + + if (make_diffs) + { + for (i=0; i<2; i++) + for (j=0; j<2; j++) + { + buf1[i][j]='z'; + } + } + /* + buf1[2][2]= {"ab","de"}; + $h5diff file7.h5 file6.h5 g1 g1 -v + Group: and + Attribute: and + position string of string of difference + ------------------------------------------------------------ +[ 0 ] a z +[ 0 ] b z +[ 1 ] d z +[ 1 ] e z + */ + type_id = H5Tcopy(H5T_C_S1); + status = H5Tset_size(type_id, 2); + write_attr(loc_id,1,dims,"string",type_id,buf1); + status = H5Tclose(type_id); + +/*------------------------------------------------------------------------- + * H5T_BITFIELD + *------------------------------------------------------------------------- + */ + + if (make_diffs) + { + for (i=0; i<2; i++) + buf2[i]=buf2[1]=0; + } + /* + buf2[2]= {1,2}; + $h5diff file7.h5 file6.h5 g1 g1 -v + Group: and + Attribute: and + position bitfield of bitfield of difference + position opaque of opaque of difference +------------------------------------------------------------ +[ 0 ] 1 0 1 +[ 1 ] 2 0 2 + */ + + type_id = H5Tcopy(H5T_STD_B8LE); + write_attr(loc_id,1,dims,"bitfield",type_id,buf2); + status = H5Tclose(type_id); + +/*------------------------------------------------------------------------- + * H5T_OPAQUE + *------------------------------------------------------------------------- + */ + + /* + buf2[2]= {1,2}; + $h5diff file7.h5 file6.h5 g1 g1 -v + Group: and + Attribute: and + position opaque of opaque of difference + position opaque of opaque of difference +------------------------------------------------------------ +[ 0 ] 1 0 1 +[ 1 ] 2 0 2 +*/ + + type_id = H5Tcreate(H5T_OPAQUE, 1); + status = H5Tset_tag(type_id, "1-byte opaque type"); /* must set this */ + write_attr(loc_id,1,dims,"opaque",type_id,buf2); + status = H5Tclose(type_id); + +/*------------------------------------------------------------------------- + * H5T_COMPOUND + *------------------------------------------------------------------------- + */ + + if (make_diffs) + { + for (i=0; i<2; i++) + { + buf3[i].a=0; buf3[i].b=0; + } + } + + /* + buf3[2]= {{1,2},{3,4}}; + $h5diff file7.h5 file6.h5 g1 g1 -v + Group: and + Attribute: and + position compound of compound of difference + ------------------------------------------------------------ + [ 0 ] 1 5 4 + [ 0 ] 2 5 3 + [ 1 ] 3 5 2 + [ 1 ] 4 5 1 + */ + + type_id = H5Tcreate (H5T_COMPOUND, sizeof(s_t)); + H5Tinsert(type_id, "a", HOFFSET(s_t, a), H5T_NATIVE_CHAR); + H5Tinsert(type_id, "b", HOFFSET(s_t, b), H5T_NATIVE_DOUBLE); + write_attr(loc_id,1,dims,"compound",type_id,buf3); + status = H5Tclose(type_id); + +/*------------------------------------------------------------------------- + * H5T_REFERENCE + *------------------------------------------------------------------------- + */ + /* Create references to dataset */ + if (dset_name) + { + status=H5Rcreate(&buf4[0],fid,dset_name,H5R_OBJECT,-1); + status=H5Rcreate(&buf4[1],fid,dset_name,H5R_OBJECT,-1); + write_attr(loc_id,1,dims,"reference",H5T_STD_REF_OBJ,buf4); + } + +/*------------------------------------------------------------------------- + * H5T_ENUM + *------------------------------------------------------------------------- + */ + if (make_diffs) + { + for (i=0; i<2; i++) + { + buf45[i]=GREEN; + } + } + /* + buf45[2]= {RED,RED}; + $h5diff file7.h5 file6.h5 g1 g1 -v + Group: and + Attribute: and + position enum of enum of difference +------------------------------------------------------------ +[ 0 ] RED GREEN +[ 1 ] RED GREEN + */ + type_id = H5Tcreate(H5T_ENUM, sizeof(e_t)); + H5Tenum_insert(type_id, "RED", (val = 0, &val)); + H5Tenum_insert(type_id, "GREEN", (val = 1, &val)); + write_attr(loc_id,1,dims,"enum",type_id,buf45); + status = H5Tclose(type_id); + +/*------------------------------------------------------------------------- + * H5T_VLEN + *------------------------------------------------------------------------- + */ + + /* Allocate and initialize VL dataset to write */ + + buf5[0].len = 1; + buf5[0].p = malloc( 1 * sizeof(int)); + ((int *)buf5[0].p)[0]=1; + buf5[1].len = 2; + buf5[1].p = malloc( 2 * sizeof(int)); + ((int *)buf5[1].p)[0]=2; + ((int *)buf5[1].p)[1]=3; + + if (make_diffs) + { + ((int *)buf5[0].p)[0]=0; + ((int *)buf5[1].p)[0]=0; + ((int *)buf5[1].p)[1]=0; + } + /* + $h5diff file7.h5 file6.h5 g1 g1 -v + Group: and + position vlen of vlen of difference +------------------------------------------------------------ +[ 0 ] 1 0 1 +[ 1 ] 2 0 2 +[ 1 ] 3 0 3 + */ + + space_id = H5Screate_simple(1,dims,NULL); + type_id = H5Tvlen_create(H5T_NATIVE_INT); + attr_id = H5Acreate(loc_id,"vlen",type_id,space_id,H5P_DEFAULT); + status = H5Awrite(attr_id,type_id,buf5); + assert(status>=0); + status = H5Dvlen_reclaim(type_id,space_id,H5P_DEFAULT,buf5); + assert(status>=0); + status = H5Aclose(attr_id); + status = H5Tclose(type_id); + status = H5Sclose(space_id); + +/*------------------------------------------------------------------------- + * H5T_ARRAY + *------------------------------------------------------------------------- + */ + + if (make_diffs) + { + for (i=0; i<2; i++) + for (j=0; j<3; j++) + { + buf6[i][j]=0; + } + } + /* + buf6[2][3]= {{1,2,3},{4,5,6}}; + $h5diff file7.h5 file6.h5 g1 g1 -v + Group: and + Attribute: and +position array of array of difference +------------------------------------------------------------ +[ 0 ] 1 0 1 +[ 0 ] 2 0 2 +[ 0 ] 3 0 3 +[ 1 ] 4 0 4 +[ 1 ] 5 0 5 +[ 1 ] 6 0 6 + */ + type_id = H5Tarray_create(H5T_NATIVE_INT,1,dimarray,NULL); + write_attr(loc_id,1,dims,"array",type_id,buf6); + status = H5Tclose(type_id); + +/*------------------------------------------------------------------------- + * H5T_INTEGER and H5T_FLOAT + *------------------------------------------------------------------------- + */ + + if (make_diffs) + { + for (i=0; i<2; i++) + { + buf7[i]=0; + buf8[i]=0; + } + } + /* + buf7[2]= {1,2}; + buf8[2]= {1,2}; + $h5diff file7.h5 file6.h5 g1 g1 -v + Group: and + position integer of integer of difference + ------------------------------------------------------------ + [ 0 ] 1 0 1 + [ 1 ] 2 0 2 + position float of float of difference + ------------------------------------------------------------ + [ 0 ] 1 0 1 + [ 1 ] 2 0 2 + */ + write_attr(loc_id,1,dims,"integer",H5T_NATIVE_INT,buf7); + write_attr(loc_id,1,dims,"float",H5T_NATIVE_FLOAT,buf8); + + +/*------------------------------------------------------------------------- + * 2D attributes + *------------------------------------------------------------------------- + */ + +/*------------------------------------------------------------------------- + * H5T_STRING + *------------------------------------------------------------------------- + */ + if (make_diffs) + { + memset(buf12, 'z', sizeof buf12); + } + + /* + buf12[6][2]= {"ab","cd","ef","gh","ij","kl"}; + $h5diff file7.h5 file6.h5 g1 g1 -v + Attribute: and + position string2D of string2D of difference + ------------------------------------------------------------ +[ 0 0 ] a z +[ 0 0 ] b z +[ 0 1 ] c z +[ 0 1 ] d z +[ 1 0 ] e z +[ 1 0 ] f z +[ 1 1 ] g z +[ 1 1 ] h z +[ 2 0 ] i z +[ 2 0 ] j z +[ 2 1 ] k z +[ 2 1 ] l z + */ + + type_id = H5Tcopy(H5T_C_S1); + status = H5Tset_size(type_id, 2); + write_attr(loc_id,2,dims2,"string2D",type_id,buf12); + status = H5Tclose(type_id); + +/*------------------------------------------------------------------------- + * H5T_BITFIELD + *------------------------------------------------------------------------- + */ + + if (make_diffs) + { + memset(buf22,0,sizeof buf22); + } + + /* + buf22[3][2]= {{1,2},{3,4},{5,6}}; + $h5diff file7.h5 file6.h5 g1 g1 -v + Attribute: and + position bitfield2D of bitfield2D of difference +------------------------------------------------------------ +[ 0 0 ] 1 0 1 +[ 0 1 ] 2 0 2 +[ 1 0 ] 3 0 3 +[ 1 1 ] 4 0 4 +[ 2 0 ] 5 0 5 +[ 2 1 ] 6 0 6 + */ + + + type_id = H5Tcopy(H5T_STD_B8LE); + write_attr(loc_id,2,dims2,"bitfield2D",type_id,buf22); + status = H5Tclose(type_id); + +/*------------------------------------------------------------------------- + * H5T_OPAQUE + *------------------------------------------------------------------------- + */ + + /* + buf22[3][2]= {{1,2},{3,4},{5,6}}; + $h5diff file7.h5 file6.h5 g1 g1 -v + Attribute: and + position opaque2D of opaque2D of difference +------------------------------------------------------------ +[ 0 0 ] 1 0 1 +[ 0 1 ] 2 0 2 +[ 1 0 ] 3 0 3 +[ 1 1 ] 4 0 4 +[ 2 0 ] 5 0 5 +[ 2 1 ] 6 0 6 + */ + type_id = H5Tcreate(H5T_OPAQUE, 1); + status = H5Tset_tag(type_id, "1-byte opaque type"); /* must set this */ + write_attr(loc_id,2,dims2,"opaque2D",type_id,buf22); + status = H5Tclose(type_id); + +/*------------------------------------------------------------------------- + * H5T_COMPOUND + *------------------------------------------------------------------------- + */ + if (make_diffs) + { + memset(buf32,0,sizeof buf32); + } + + /* + buf32[6]= {{1,2},{3,4},{5,6},{7,8},{9,10},{11,12}}; + $h5diff file7.h5 file6.h5 g1 g1 -v + Attribute: and + position opaque2D of opaque2D of difference +------------------------------------------------------------ +[ 0 0 ] 1 0 1 +[ 0 1 ] 2 0 2 +[ 1 0 ] 3 0 3 +[ 1 1 ] 4 0 4 +[ 2 0 ] 5 0 5 +[ 2 1 ] 6 0 6 + */ + + + type_id = H5Tcreate (H5T_COMPOUND, sizeof(s_t)); + H5Tinsert(type_id, "a", HOFFSET(s_t, a), H5T_NATIVE_CHAR); + H5Tinsert(type_id, "b", HOFFSET(s_t, b), H5T_NATIVE_DOUBLE); + write_attr(loc_id,2,dims2,"compound2D",type_id,buf32); + status = H5Tclose(type_id); + +/*------------------------------------------------------------------------- + * H5T_REFERENCE + *------------------------------------------------------------------------- + */ + /* Create references to dataset */ + if (dset_name) + { + for (i = 0; i < 3; i++) { + for (j = 0; j < 2; j++) { + status=H5Rcreate(&buf42[i][j],fid,dset_name,H5R_OBJECT,-1); + } + } + write_attr(loc_id,2,dims2,"reference2D",H5T_STD_REF_OBJ,buf42); + } + +/*------------------------------------------------------------------------- + * H5T_ENUM + *------------------------------------------------------------------------- + */ + for (i=0; i<3; i++) + for (j=0; j<2; j++) + { + if (make_diffs) buf452[i][j]=GREEN; else buf452[i][j]=RED; + } + +/* +Attribute: and +position enum2D of enum2D of difference +------------------------------------------------------------ +[ 0 0 ] RED GREEN +[ 0 1 ] RED GREEN +[ 1 0 ] RED GREEN +[ 1 1 ] RED GREEN +[ 2 0 ] RED GREEN +[ 2 1 ] RED GREEN +*/ + + type_id = H5Tcreate(H5T_ENUM, sizeof(e_t)); + H5Tenum_insert(type_id, "RED", (val = 0, &val)); + H5Tenum_insert(type_id, "GREEN", (val = 1, &val)); + write_attr(loc_id,2,dims2,"enum2D",type_id,buf452); + status = H5Tclose(type_id); + +/*------------------------------------------------------------------------- + * H5T_VLEN + *------------------------------------------------------------------------- + */ + + /* Allocate and initialize VL dataset to write */ + n=0; + for (i = 0; i < 3; i++) { + for (j = 0; j < 2; j++) { + int l; + buf52[i][j].p = malloc((i + 1) * sizeof(int)); + buf52[i][j].len = i + 1; + for (l = 0; l < i + 1; l++) + if (make_diffs)((int *)buf52[i][j].p)[l] = 0; + else ((int *)buf52[i][j].p)[l] = n++; + } + } + + /* + position vlen2D of vlen2D of difference +------------------------------------------------------------ +[ 0 1 ] 1 0 1 +[ 1 0 ] 2 0 2 +[ 1 0 ] 3 0 3 +[ 1 1 ] 4 0 4 +[ 1 1 ] 5 0 5 +[ 2 0 ] 6 0 6 +[ 2 0 ] 7 0 7 +[ 2 0 ] 8 0 8 +[ 2 1 ] 9 0 9 +[ 2 1 ] 10 0 10 +[ 2 1 ] 11 0 11 +*/ + + space_id = H5Screate_simple(2,dims2,NULL); + type_id = H5Tvlen_create(H5T_NATIVE_INT); + attr_id = H5Acreate(loc_id,"vlen2D",type_id,space_id,H5P_DEFAULT); + status = H5Awrite(attr_id,type_id,buf52); + assert(status>=0); + status = H5Dvlen_reclaim(type_id,space_id,H5P_DEFAULT,buf52); + assert(status>=0); + status = H5Aclose(attr_id); + status = H5Tclose(type_id); + status = H5Sclose(space_id); + +/*------------------------------------------------------------------------- + * H5T_ARRAY + *------------------------------------------------------------------------- + */ + + if (make_diffs) + { + memset(buf62,0,sizeof buf62); + } + /* + buf62[6][3]= {{1,2,3},{4,5,6},{7,8,9},{10,11,12},{13,14,15},{16,17,18}}; + $h5diff file7.h5 file6.h5 g1 g1 -v + Group: and +Attribute: and +position array2D of array2D of difference +------------------------------------------------------------ +[ 0 0 ] 1 0 1 +[ 0 0 ] 2 0 2 +[ 0 0 ] 3 0 3 +[ 0 1 ] 4 0 4 +[ 0 1 ] 5 0 5 +[ 0 1 ] 6 0 6 +[ 1 0 ] 7 0 7 +[ 1 0 ] 8 0 8 +[ 1 0 ] 9 0 9 +[ 1 1 ] 10 0 10 +[ 1 1 ] 11 0 11 +[ 1 1 ] 12 0 12 +[ 2 0 ] 13 0 13 +[ 2 0 ] 14 0 14 +[ 2 0 ] 15 0 15 +[ 2 1 ] 16 0 16 +[ 2 1 ] 17 0 17 +[ 2 1 ] 18 0 18 + */ + type_id = H5Tarray_create(H5T_NATIVE_INT,1,dimarray,NULL); + write_attr(loc_id,2,dims2,"array2D",type_id,buf62); + status = H5Tclose(type_id); + +/*------------------------------------------------------------------------- + * H5T_INTEGER and H5T_FLOAT + *------------------------------------------------------------------------- + */ + + if (make_diffs) + { + memset(buf72,0,sizeof buf72); + memset(buf82,0,sizeof buf82); + } +/* +Attribute: and +position integer2D of integer2D of difference +------------------------------------------------------------ +[ 0 0 ] 1 0 1 +[ 0 1 ] 2 0 2 +[ 1 0 ] 3 0 3 +[ 1 1 ] 4 0 4 +[ 2 0 ] 5 0 5 +[ 2 1 ] 6 0 6 +6 differences found +Attribute: and +position float2D of float2D of difference +------------------------------------------------------------ +[ 0 0 ] 1 0 1 +[ 0 1 ] 2 0 2 +[ 1 0 ] 3 0 3 +[ 1 1 ] 4 0 4 +[ 2 0 ] 5 0 5 +[ 2 1 ] 6 0 6 +*/ + + write_attr(loc_id,2,dims2,"integer2D",H5T_NATIVE_INT,buf72); + write_attr(loc_id,2,dims2,"float2D",H5T_NATIVE_FLOAT,buf82); + + +/*------------------------------------------------------------------------- + * 3D attributes + *------------------------------------------------------------------------- + */ + +/*------------------------------------------------------------------------- + * H5T_STRING + *------------------------------------------------------------------------- + */ + + if (make_diffs) + { + memset(buf13,'z',sizeof buf13); + } + + /* + buf13[24][2]= {"ab","cd","ef","gh","ij","kl","mn","pq", + "rs","tu","vw","xz","AB","CD","EF","GH", + "IJ","KL","MN","PQ","RS","TU","VW","XZ"}; + +Attribute: and +position string3D of string3D of difference +------------------------------------------------------------ +[ 0 0 0 ] a z +[ 0 0 0 ] b z +[ 0 0 1 ] c z +[ 0 0 1 ] d z +[ 0 1 0 ] e z +[ 0 1 0 ] f z +[ 0 1 1 ] g z +[ 0 1 1 ] h z +[ 0 2 0 ] i z +[ 0 2 0 ] j z +[ 0 2 1 ] k z +[ 0 2 1 ] l z +[ 1 0 0 ] m z +[ 1 0 0 ] n z +[ 1 0 1 ] p z +[ 1 0 1 ] q z +[ 1 1 0 ] r z +[ 1 1 0 ] s z +[ 1 1 1 ] t z +[ 1 1 1 ] u z +[ 1 2 0 ] v z +[ 1 2 0 ] w z +[ 1 2 1 ] x z +[ 2 0 0 ] A z +[ 2 0 0 ] B z +[ 2 0 1 ] C z +[ 2 0 1 ] D z +[ 2 1 0 ] E z +[ 2 1 0 ] F z +[ 2 1 1 ] G z +[ 2 1 1 ] H z +[ 2 2 0 ] I z +[ 2 2 0 ] J z +[ 2 2 1 ] K z +[ 2 2 1 ] L z +[ 3 0 0 ] M z +[ 3 0 0 ] N z +[ 3 0 1 ] P z +[ 3 0 1 ] Q z +[ 3 1 0 ] R z +[ 3 1 0 ] S z +[ 3 1 1 ] T z +[ 3 1 1 ] U z +[ 3 2 0 ] V z +[ 3 2 0 ] W z +[ 3 2 1 ] X z +[ 3 2 1 ] Z z + */ + + type_id = H5Tcopy(H5T_C_S1); + status = H5Tset_size(type_id, 2); + write_attr(loc_id,3,dims3,"string3D",type_id,buf13); + status = H5Tclose(type_id); + +/*------------------------------------------------------------------------- + * H5T_BITFIELD + *------------------------------------------------------------------------- + */ + + n=1; + for (i = 0; i < 4; i++) { + for (j = 0; j < 3; j++) { + for (k = 0; k < 2; k++) { + if (make_diffs) buf23[i][j][k]=0; + else buf23[i][j][k]=n++; + } + } + } + +/* +position bitfield3D of bitfield3D of difference +------------------------------------------------------------ +[ 0 0 0 ] 1 0 1 +[ 0 0 1 ] 2 0 2 +[ 0 1 0 ] 3 0 3 +[ 0 1 1 ] 4 0 4 +[ 0 2 0 ] 5 0 5 +[ 0 2 1 ] 6 0 6 +[ 1 0 0 ] 7 0 7 +[ 1 0 1 ] 8 0 8 +[ 1 1 0 ] 9 0 9 +[ 1 1 1 ] 10 0 10 +[ 1 2 0 ] 11 0 11 +[ 1 2 1 ] 12 0 12 +[ 2 0 0 ] 13 0 13 +[ 2 0 1 ] 14 0 14 +[ 2 1 0 ] 15 0 15 +[ 2 1 1 ] 16 0 16 +[ 2 2 0 ] 17 0 17 +[ 2 2 1 ] 18 0 18 +[ 3 0 0 ] 19 0 19 +[ 3 0 1 ] 20 0 20 +[ 3 1 0 ] 21 0 21 +[ 3 1 1 ] 22 0 22 +[ 3 2 0 ] 23 0 23 +[ 3 2 1 ] 24 0 24 +*/ + + type_id = H5Tcopy(H5T_STD_B8LE); + write_attr(loc_id,3,dims3,"bitfield3D",type_id,buf23); + status = H5Tclose(type_id); + +/*------------------------------------------------------------------------- + * H5T_OPAQUE + *------------------------------------------------------------------------- + */ + type_id = H5Tcreate(H5T_OPAQUE, 1); + status = H5Tset_tag(type_id, "1-byte opaque type"); /* must set this */ + write_attr(loc_id,3,dims3,"opaque3D",type_id,buf23); + status = H5Tclose(type_id); + +/*------------------------------------------------------------------------- + * H5T_COMPOUND + *------------------------------------------------------------------------- + */ + + n=1; + for (i = 0; i < 4; i++) { + for (j = 0; j < 3; j++) { + for (k = 0; k < 2; k++) { + if (make_diffs) { + buf33[i][j][k].a=0; + buf33[i][j][k].b=0; + } + else { + buf33[i][j][k].a=n++; + buf33[i][j][k].b=n++; + } + } + } + } +/*position compound3D of compound3D of difference +------------------------------------------------------------ +[ 0 0 0 ] 1 0 1 +[ 0 0 0 ] 2 0 2 +[ 0 0 1 ] 3 0 3 +[ 0 0 1 ] 4 0 4 +[ 0 1 0 ] 5 0 5 +[ 0 1 0 ] 6 0 6 +[ 0 1 1 ] 7 0 7 +[ 0 1 1 ] 8 0 8 +[ 0 2 0 ] 9 0 9 +[ 0 2 0 ] 10 0 10 +[ 0 2 1 ] 11 0 11 +[ 0 2 1 ] 12 0 12 +[ 1 0 0 ] 13 0 13 +[ 1 0 0 ] 14 0 14 +[ 1 0 1 ] 15 0 15 +[ 1 0 1 ] 16 0 16 +[ 1 1 0 ] 17 0 17 +[ 1 1 0 ] 18 0 18 +[ 1 1 1 ] 19 0 19 +[ 1 1 1 ] 20 0 20 +[ 1 2 0 ] 21 0 21 +[ 1 2 0 ] 22 0 22 +[ 1 2 1 ] 23 0 23 +[ 1 2 1 ] 24 0 24 +[ 2 0 0 ] 25 0 25 +[ 2 0 0 ] 26 0 26 +[ 2 0 1 ] 27 0 27 +[ 2 0 1 ] 28 0 28 +[ 2 1 0 ] 29 0 29 +[ 2 1 0 ] 30 0 30 +[ 2 1 1 ] 31 0 31 +[ 2 1 1 ] 32 0 32 +[ 2 2 0 ] 33 0 33 +[ 2 2 0 ] 34 0 34 +[ 2 2 1 ] 35 0 35 +[ 2 2 1 ] 36 0 36 +[ 3 0 0 ] 37 0 37 +[ 3 0 0 ] 38 0 38 +[ 3 0 1 ] 39 0 39 +[ 3 0 1 ] 40 0 40 +[ 3 1 0 ] 41 0 41 +[ 3 1 0 ] 42 0 42 +[ 3 1 1 ] 43 0 43 +[ 3 1 1 ] 44 0 44 +[ 3 2 0 ] 45 0 45 +[ 3 2 0 ] 46 0 46 +[ 3 2 1 ] 47 0 47 +[ 3 2 1 ] 48 0 48 +*/ + + + + type_id = H5Tcreate (H5T_COMPOUND, sizeof(s_t)); + H5Tinsert(type_id, "a", HOFFSET(s_t, a), H5T_NATIVE_CHAR); + H5Tinsert(type_id, "b", HOFFSET(s_t, b), H5T_NATIVE_DOUBLE); + write_attr(loc_id,3,dims3,"compound3D",type_id,buf33); + status = H5Tclose(type_id); + +/*------------------------------------------------------------------------- + * H5T_REFERENCE + *------------------------------------------------------------------------- + */ + /* Create references to dataset */ + if (dset_name) + { + for (i = 0; i < 4; i++) { + for (j = 0; j < 3; j++) { + for (k = 0; k < 2; k++) + status=H5Rcreate(&buf43[i][j][k],fid,dset_name,H5R_OBJECT,-1); + } + } + write_attr(loc_id,3,dims3,"reference3D",H5T_STD_REF_OBJ,buf43); + } + +/*------------------------------------------------------------------------- + * H5T_ENUM + *------------------------------------------------------------------------- + */ + + for (i = 0; i < 4; i++) { + for (j = 0; j < 3; j++) { + for (k = 0; k < 2; k++) { + if (make_diffs) buf453[i][j][k]=RED; else buf453[i][j][k]=GREEN; + } + } + } + +/* +position enum3D of enum3D of difference +------------------------------------------------------------ +[ 0 0 0 ] GREEN RED +[ 0 0 1 ] GREEN RED +[ 0 1 0 ] GREEN RED +[ 0 1 1 ] GREEN RED +[ 0 2 0 ] GREEN RED +[ 0 2 1 ] GREEN RED +[ 1 0 0 ] GREEN RED +[ 1 0 1 ] GREEN RED +[ 1 1 0 ] GREEN RED +[ 1 1 1 ] GREEN RED +[ 1 2 0 ] GREEN RED +[ 1 2 1 ] GREEN RED +[ 2 0 0 ] GREEN RED +[ 2 0 1 ] GREEN RED +[ 2 1 0 ] GREEN RED +[ 2 1 1 ] GREEN RED +[ 2 2 0 ] GREEN RED +[ 2 2 1 ] GREEN RED +[ 3 0 0 ] GREEN RED +[ 3 0 1 ] GREEN RED +[ 3 1 0 ] GREEN RED +[ 3 1 1 ] GREEN RED +[ 3 2 0 ] GREEN RED +[ 3 2 1 ] GREEN RED +*/ + + + type_id = H5Tcreate(H5T_ENUM, sizeof(e_t)); + H5Tenum_insert(type_id, "RED", (val = 0, &val)); + H5Tenum_insert(type_id, "GREEN", (val = 1, &val)); + write_attr(loc_id,3,dims3,"enum3D",type_id,buf453); + status = H5Tclose(type_id); + +/*------------------------------------------------------------------------- + * H5T_VLEN + *------------------------------------------------------------------------- + */ + + /* Allocate and initialize VL dataset to write */ + n=0; + for (i = 0; i < 4; i++) { + for (j = 0; j < 3; j++) { + for (k = 0; k < 2; k++) { + int l; + buf53[i][j][k].p = malloc((i + 1) * sizeof(int)); + buf53[i][j][k].len = i + 1; + for (l = 0; l < i + 1; l++) + if (make_diffs)((int *)buf53[i][j][k].p)[l] = 0; + else ((int *)buf53[i][j][k].p)[l] = n++; + } + } + } +/* +position vlen3D of vlen3D of difference +------------------------------------------------------------ +[ 0 0 1 ] 1 0 1 +[ 0 1 0 ] 2 0 2 +[ 0 1 1 ] 3 0 3 +[ 0 2 0 ] 4 0 4 +[ 0 2 1 ] 5 0 5 +[ 1 0 0 ] 6 0 6 +[ 1 0 0 ] 7 0 7 +[ 1 0 1 ] 8 0 8 +[ 1 0 1 ] 9 0 9 +[ 1 1 0 ] 10 0 10 +etc +*/ + space_id = H5Screate_simple(3,dims3,NULL); + type_id = H5Tvlen_create(H5T_NATIVE_INT); + attr_id = H5Acreate(loc_id,"vlen3D",type_id,space_id,H5P_DEFAULT); + status = H5Awrite(attr_id,type_id,buf53); + assert(status>=0); + status = H5Dvlen_reclaim(type_id,space_id,H5P_DEFAULT,buf53); + assert(status>=0); + status = H5Aclose(attr_id); + status = H5Tclose(type_id); + status = H5Sclose(space_id); + +/*------------------------------------------------------------------------- + * H5T_ARRAY + *------------------------------------------------------------------------- + */ + n=1; + for (i = 0; i < 24; i++) { + for (j = 0; j < (int)dimarray[0]; j++) { + if (make_diffs) buf63[i][j]=0; + else buf63[i][j]=n++; + } + } + /* + position array3D of array3D of difference +------------------------------------------------------------ +[ 0 0 0 ] 1 0 1 +[ 0 0 0 ] 2 0 2 +[ 0 0 0 ] 3 0 3 +[ 0 0 1 ] 4 0 4 +[ 0 0 1 ] 5 0 5 +[ 0 0 1 ] 6 0 6 +[ 0 1 0 ] 7 0 7 +etc +*/ + + type_id = H5Tarray_create(H5T_NATIVE_INT,1,dimarray,NULL); + write_attr(loc_id,3,dims3,"array3D",type_id,buf63); + status = H5Tclose(type_id); + +/*------------------------------------------------------------------------- + * H5T_INTEGER and H5T_FLOAT + *------------------------------------------------------------------------- + */ + n=1; f=1; + for (i = 0; i < 4; i++) { + for (j = 0; j < 3; j++) { + for (k = 0; k < 2; k++) { + if (make_diffs) { + buf73[i][j][k]=0; + buf83[i][j][k]=0; + } + else { + buf73[i][j][k]=n++; + buf83[i][j][k]=f++; + } + } + } + } + + /* + position integer3D of integer3D of difference +------------------------------------------------------------ +[ 0 0 0 ] 1 0 1 +[ 0 0 1 ] 2 0 2 +[ 0 1 0 ] 3 0 3 +[ 0 1 1 ] 4 0 4 +[ 0 2 0 ] 5 0 5 +[ 0 2 1 ] 6 0 6 +[ 1 0 0 ] 7 0 7 +[ 1 0 1 ] 8 0 8 +[ 1 1 0 ] 9 0 9 +[ 1 1 1 ] 10 0 10 +etc +*/ + write_attr(loc_id,3,dims3,"integer3D",H5T_NATIVE_INT,buf73); + write_attr(loc_id,3,dims3,"float3D",H5T_NATIVE_FLOAT,buf83); +} + + + +/*------------------------------------------------------------------------- + * Check all HDF5 classes + * H5T_INTEGER, H5T_FLOAT + * H5T_TIME, H5T_STRING, H5T_BITFIELD, H5T_OPAQUE, H5T_COMPOUND, H5T_REFERENCE, + * H5T_ENUM, H5T_VLEN, H5T_ARRAY + *------------------------------------------------------------------------- + */ + + +int make_attr(hid_t fid) +{ + hid_t dset_id; + hid_t group_id; + hid_t root_id; + hid_t space_id; + hsize_t dims[1]={2}; + + /* Create a 1D dataset */ + space_id = H5Screate_simple(1,dims,NULL); + dset_id = H5Dcreate(fid,"dset_ref",H5T_NATIVE_INT,space_id,H5P_DEFAULT); + H5Sclose(space_id); + + /* Create groups */ + group_id = H5Gcreate(fid,"g1",0); + root_id = H5Gopen(fid, "/"); + +/*------------------------------------------------------------------------- + * write a series of attributes on the dataset, group, and root group + *------------------------------------------------------------------------- + */ + + write_attr_in(dset_id,"dset_ref",fid,0); + write_attr_in(group_id,"dset_ref",fid,0); + write_attr_in(root_id,"dset_ref",fid,0); + + + /* Close */ + H5Dclose(dset_id); + H5Gclose(group_id); + H5Gclose(root_id); + + return 0; +} + + +/*------------------------------------------------------------------------- + * Function: make_all_objects + * + * Purpose: make a test file with all types of HDF5 objects, datatypes + * + * Return: Success: zero + * Failure: 1 + * + * Programmer: Pedro Vicente + * September, 19, 2003 + * + *------------------------------------------------------------------------- + */ +int make_all_objects(hid_t fid) +{ + + + /* create attributes */ + if((make_attr(fid))<0) + TEST_ERROR; + + return 0; + +error: + return 1; +} + + + +/*------------------------------------------------------------------------- + * Function: write_attr + * + * Purpose: utility function to write an attribute in LOC_ID + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: November 12, 2003 + * + *------------------------------------------------------------------------- + */ + + +int write_attr(hid_t loc_id, + int rank, + hsize_t *dims, + const char *attr_name, + hid_t type_id, + void *buf) +{ + hid_t attr_id; + hid_t space_id; + herr_t status; + + /* Create a buf space */ + space_id = H5Screate_simple(rank,dims,NULL); + + /* Create the attribute */ + attr_id = H5Acreate(loc_id,attr_name,type_id,space_id,H5P_DEFAULT); + + /* Write the buf */ + if ( buf ) + status = H5Awrite(attr_id,type_id,buf); + + /* Close */ + status = H5Aclose(attr_id); + status = H5Sclose(space_id); + return status; +} + +/*------------------------------------------------------------------------- + * Function: write_dset + * + * Purpose: utility function to create and write a dataset in LOC_ID + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: November 12, 2003 + * + *------------------------------------------------------------------------- + */ + + +int write_dset( hid_t loc_id, + int rank, + hsize_t *dims, + const char *dset_name, + hid_t type_id, + void *buf ) +{ + hid_t dset_id; + hid_t space_id; + herr_t status; + + /* Create a buf space */ + space_id = H5Screate_simple(rank,dims,NULL); + + /* Create a dataset */ + dset_id = H5Dcreate(loc_id,dset_name,type_id,space_id,H5P_DEFAULT); + + /* Write the buf */ + if ( buf ) + status = H5Dwrite(dset_id,type_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf); + + /* Close */ + status = H5Dclose(dset_id); + status = H5Sclose(space_id); + + return status; + +} + + + + diff --git a/tools/h5repack/test_h5repack_add.h b/tools/h5repack/test_h5repack_add.h deleted file mode 100644 index 4d84ad7..0000000 --- a/tools/h5repack/test_h5repack_add.h +++ /dev/null @@ -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__ */ diff --git a/tools/h5repack/test_h5repack_main.c b/tools/h5repack/test_h5repack_main.c index 7978da5..5bfed95 100644 --- a/tools/h5repack/test_h5repack_main.c +++ b/tools/h5repack/test_h5repack_main.c @@ -16,22 +16,66 @@ #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 + * + * Return: Success: zero + * Failure: 1 + * + * Programmer: Pedro Vicente + * September, 19, 2003 + * + *------------------------------------------------------------------------- + */ +static int +test_copy(void) +{ + pack_opt_t pack_options; + diff_opt_t diff_options; + memset(&diff_options, 0, sizeof (diff_opt_t)); + + TESTING(" copy with no filters"); + + if (h5repack_init (&pack_options, 0)<0) + TEST_ERROR; + if (h5repack(FNAME1,FNAME1OUT,&pack_options)<0) + TEST_ERROR; + if (h5repack_end (&pack_options)<0) + TEST_ERROR; + if (h5diff(FNAME1,FNAME1OUT,NULL,NULL,&diff_options) == 1) + TEST_ERROR; + + PASSED(); + return 0; + +error: + return 1; + +} + + + +/*------------------------------------------------------------------------- + * Function: test_filter_deflate + * + * Purpose: + * + * 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 * - * Return: Success: zero - * Failure: 1 + * Return: Success: zero + * Failure: 1 * - * Programmer: Pedro Vicente + * Programmer: Pedro Vicente * September, 19, 2003 * * Modifications: @@ -39,7 +83,7 @@ *------------------------------------------------------------------------- */ static int -test(void) +test_filter_deflate(void) { pack_opt_t pack_options; diff_opt_t diff_options; @@ -49,15 +93,15 @@ test(void) if (h5repack_init (&pack_options, 0)<0) TEST_ERROR; - if (h5repack_addcomp("dset1:GZIP 9",&pack_options)<0) + if (h5repack_addcomp("dset_gzip:GZIP 9",&pack_options)<0) TEST_ERROR; - if (h5repack_addchunk("dset1:5x4",&pack_options)<0) + if (h5repack_addchunk("dset_gzip:5x4",&pack_options)<0) TEST_ERROR; - if (h5repack(FILENAME,FILENAME_OUT,&pack_options)<0) + if (h5repack(FNAME2,FNAME2OUT,&pack_options)<0) TEST_ERROR; if (h5repack_end (&pack_options)<0) TEST_ERROR; - if (h5diff(FILENAME,FILENAME,NULL,NULL,&diff_options) == 1) + if (h5diff(FNAME2,FNAME2OUT,NULL,NULL,&diff_options) == 1) TEST_ERROR; PASSED(); @@ -69,15 +113,18 @@ error: } + + + /*------------------------------------------------------------------------- - * Function: main + * Function: main * - * Purpose: Executes h5repack tests + * Purpose: Executes h5repack tests * - * Return: Success: zero - * Failure: non-zero + * Return: Success: zero + * Failure: non-zero * - * Programmer: Pedro Vicente + * Programmer: Pedro Vicente * 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 */ diff --git a/tools/lib/h5diff.c b/tools/lib/h5diff.c index 9c9d8aa..1a5e1f3 100644 --- a/tools/lib/h5diff.c +++ b/tools/lib/h5diff.c @@ -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; diff --git a/tools/lib/h5diff_dset.c b/tools/lib/h5diff_dset.c index 9088c3a..767db68 100644 --- a/tools/lib/h5diff_dset.c +++ b/tools/lib/h5diff_dset.c @@ -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 -- cgit v0.12