h5repack.h

00001 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00002  * Copyright by The HDF Group.                                               *
00003  * Copyright by the Board of Trustees of the University of Illinois.         *
00004  * All rights reserved.                                                      *
00005  *                                                                           *
00006  * This file is part of HDF5.  The full HDF5 copyright notice, including     *
00007  * terms governing use, modification, and redistribution, is contained in    *
00008  * the files COPYING and Copyright.html.  COPYING can be found at the root   *
00009  * of the source code distribution tree; Copyright.html can be found at the  *
00010  * root level of an installed copy of the electronic HDF5 document set and   *
00011  * is linked from the top-level documents page.  It can also be found at     *
00012  * http://hdfgroup.org/HDF5/doc/Copyright.html.  If you do not have          *
00013  * access to either file, you may request a copy from help@hdfgroup.org.     *
00014  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00015 
00016 
00017 #ifndef H5REPACK_H__
00018 #define H5REPACK_H__
00019 
00020 #include "hdf5.h"
00021 #include "h5trav.h"
00022 
00023 #define H5FOPENERROR "unable to open file"
00024 #define PFORMAT  "%-7s %-7s %-7s\n"   /* chunk info, compression info, name*/
00025 #define PFORMAT1 "%-7s %-7s %-7s"     /* chunk info, compression info, name*/
00026 #define MAX_NC_NAME 256               /* max length of a name */
00027 #define MAX_VAR_DIMS 32               /* max per variable dimensions */
00028 #define FORMAT_OBJ      " %-27s %s\n"   /* obj type, name */
00029 #define FORMAT_OBJ_ATTR "  %-27s %s\n"  /* obj type, name */
00030 
00031 /*-------------------------------------------------------------------------
00032  * data structures for command line options
00033  *-------------------------------------------------------------------------
00034  */
00035 
00036 /* a list of names */
00037 typedef struct {
00038  char obj[MAX_NC_NAME];
00039 } obj_list_t;
00040 
00041 /*
00042  the type of filter and additional parameter
00043  type can be one of the filters
00044  H5Z_FILTER_NONE        0,  uncompress if compressed
00045  H5Z_FILTER_DEFLATE     1 , deflation like gzip
00046  H5Z_FILTER_SHUFFLE     2 , shuffle the data
00047  H5Z_FILTER_FLETCHER32  3 , letcher32 checksum of EDC
00048  H5Z_FILTER_SZIP        4 , szip compression
00049  H5Z_FILTER_NBIT        5 , nbit compression
00050  H5Z_FILTER_SCALEOFFSET 6 , scaleoffset compression
00051 */
00052 
00053 #define CD_VALUES 20
00054 
00055 typedef struct {
00056  H5Z_filter_t filtn;                           /* filter identification number */
00057  unsigned     cd_values[CD_VALUES];            /* filter client data values */
00058  size_t       cd_nelmts;                       /* filter client number of values */
00059 } filter_info_t;
00060 
00061 /* chunk lengths along each dimension and rank */
00062 typedef struct {
00063  hsize_t chunk_lengths[MAX_VAR_DIMS];
00064  int     rank;
00065 } chunk_info_t;
00066 
00067 /* we currently define a maximum value for the filters array,
00068    that corresponds to the current library filters */
00069 #define H5_REPACK_MAX_NFILTERS 6
00070 
00071 /* information for one object, contains PATH, CHUNK info and FILTER info */
00072 typedef struct {
00073  char          path[MAX_NC_NAME];               /* name of object */
00074  filter_info_t filter[H5_REPACK_MAX_NFILTERS];  /* filter array */
00075  int           nfilters;                        /* current number of filters */
00076  H5D_layout_t  layout;                          /* layout information */
00077  chunk_info_t  chunk;                           /* chunk information */
00078  hid_t         refobj_id;                       /* object ID, references */
00079 } pack_info_t;
00080 
00081 /* store a table of all objects */
00082 typedef struct {
00083  unsigned int size;
00084  unsigned int nelems;
00085  pack_info_t  *objs;
00086 } pack_opttbl_t;
00087 
00088 
00089 /*-------------------------------------------------------------------------
00090  * command line options
00091  *-------------------------------------------------------------------------
00092  */
00093 
00094 /* all the above, ready to go to the hrepack call */
00095 typedef struct {
00096  pack_opttbl_t   *op_tbl;     /*table with all -c and -f options */
00097  int             all_layout;  /*apply the layout to all objects */
00098  int             all_filter;  /*apply the filter to all objects */
00099  filter_info_t   filter_g[H5_REPACK_MAX_NFILTERS];    /*global filter array for the ALL case */
00100  int             n_filter_g;  /*number of global filters */
00101  chunk_info_t    chunk_g;     /*global chunk INFO for the ALL case */
00102  H5D_layout_t    layout_g;    /*global layout information for the ALL case */
00103  int             verbose;     /*verbose mode */
00104  hsize_t         min_comp;    /*minimum size to compress, in bytes */
00105  int             use_native;  /*use a native type in write */
00106  int             latest;      /*pack file with the latest file format */
00107  int             grp_compact; /* Set the maximum number of links to store as header messages in the group */
00108  int             grp_indexed; /* Set the minimum number of links to store in the indexed format */
00109  int             msg_size[8]; /* Minimum size of shared messages: dataspace,
00110                                  datatype, fill value, filter pipleline, attribute */
00111  const char      *ublock_filename; /* user block file name */
00112  hsize_t         ublock_size;      /* user block size */
00113  hsize_t         threshold;        /* alignment threshold for H5Pset_alignment */
00114  hsize_t         alignment ;       /* alignment for H5Pset_alignment */
00115 } pack_opt_t;
00116 
00117 
00118 
00119 /*-------------------------------------------------------------------------
00120  * public functions
00121  *-------------------------------------------------------------------------
00122  */
00123 
00124 #ifdef __cplusplus
00125 extern "C" {
00126 #endif
00127 
00128 int h5repack           (const char* infile, const char* outfile, pack_opt_t *options);
00129 int h5repack_addfilter (const char* str, pack_opt_t *options);
00130 int h5repack_addlayout (const char* str, pack_opt_t *options);
00131 int h5repack_init      (pack_opt_t *options, int verbose);
00132 int h5repack_end       (pack_opt_t *options);
00133 int h5repack_verify    (const char *fname,pack_opt_t *options);
00134 int h5repack_cmp_pl   (const char *fname1,
00135                         const char *fname2);
00136 
00137 
00138 #ifdef __cplusplus
00139 }
00140 #endif
00141 
00142 
00143 
00144 /*-------------------------------------------------------------------------
00145  * private functions
00146  *-------------------------------------------------------------------------
00147  */
00148 
00149 
00150 /*-------------------------------------------------------------------------
00151  * copy module
00152  *-------------------------------------------------------------------------
00153  */
00154 
00155 int copy_objects   (const char* fnamein,
00156                     const char* fnameout,
00157                     pack_opt_t *options);
00158 
00159 int do_copy_refobjs(hid_t fidin,
00160                     hid_t fidout,
00161                     trav_table_t *travt,
00162                     pack_opt_t *options);
00163 
00164 /*-------------------------------------------------------------------------
00165  * filters and verify module
00166  *-------------------------------------------------------------------------
00167  */
00168 void init_packobject(pack_info_t *obj);
00169 
00170 
00171 /*-------------------------------------------------------------------------
00172  * filters and copy module
00173  *-------------------------------------------------------------------------
00174  */
00175 
00176 int apply_filters(const char* name,    /* object name from traverse list */
00177                   int rank,            /* rank of dataset */
00178                   hsize_t *dims,       /* dimensions of dataset */
00179                   size_t msize,        /* size of type */
00180                   hid_t dcpl_id,       /* dataset creation property list */
00181                   pack_opt_t *options, /* repack options */
00182                   int *has_filter);    /* (OUT) object NAME has a filter */
00183 
00184 
00185 /*-------------------------------------------------------------------------
00186  * options table
00187  *-------------------------------------------------------------------------
00188  */
00189 int          options_table_init( pack_opttbl_t **tbl );
00190 int          options_table_free( pack_opttbl_t *table );
00191 int          options_add_layout( obj_list_t *obj_list,
00192                                  int n_objs,
00193                                  pack_info_t *pack,
00194                                  pack_opttbl_t *table );
00195 int          options_add_filter ( obj_list_t *obj_list,
00196                                  int n_objs,
00197                                  filter_info_t filt,
00198                                  pack_opttbl_t *table );
00199 pack_info_t* options_get_object( const char *path,
00200                                  pack_opttbl_t *table);
00201 
00202 /*-------------------------------------------------------------------------
00203  * parse functions
00204  *-------------------------------------------------------------------------
00205  */
00206 
00207 obj_list_t* parse_filter(const char *str,
00208                          int *n_objs,
00209                          filter_info_t *filt,
00210                          pack_opt_t *options,
00211                          int *is_glb);
00212 
00213 obj_list_t* parse_layout(const char *str,
00214                          int *n_objs,
00215                          pack_info_t *pack,    /* info about object */
00216                          pack_opt_t *options);
00217 
00218 
00219 
00220 
00221 #endif  /* H5REPACK_H__ */
00222