diff options
author | Allen Byrne <byrn@hdfgroup.org> | 2017-08-23 21:12:40 (GMT) |
---|---|---|
committer | Allen Byrne <byrn@hdfgroup.org> | 2017-08-23 21:12:40 (GMT) |
commit | b82ba32275f7ed998aafa68a1cecaab3e80323da (patch) | |
tree | 2e27f8701a0f4223a6a43c85087a963bf372b2d5 /tools/src/h5repack | |
parent | 1b647b18fee735086616bf99e1879e47bab0c72e (diff) | |
download | hdf5-b82ba32275f7ed998aafa68a1cecaab3e80323da.zip hdf5-b82ba32275f7ed998aafa68a1cecaab3e80323da.tar.gz hdf5-b82ba32275f7ed998aafa68a1cecaab3e80323da.tar.bz2 |
HDFFV-10282 refactor out assert calls in tools
Diffstat (limited to 'tools/src/h5repack')
-rw-r--r-- | tools/src/h5repack/h5repack.c | 1 | ||||
-rw-r--r-- | tools/src/h5repack/h5repack_copy.c | 2 | ||||
-rw-r--r-- | tools/src/h5repack/h5repack_filters.c | 368 | ||||
-rw-r--r-- | tools/src/h5repack/h5repack_refs.c | 8 |
4 files changed, 163 insertions, 216 deletions
diff --git a/tools/src/h5repack/h5repack.c b/tools/src/h5repack/h5repack.c index 4860d9e..76ca117 100644 --- a/tools/src/h5repack/h5repack.c +++ b/tools/src/h5repack/h5repack.c @@ -262,7 +262,6 @@ hid_t copy_named_datatype(hid_t type_in, hid_t fidout, /* Check if this type is the one requested */ if (oinfo.addr == dt->addr_in) { - HDassert(!dt_ret); dt_ret = dt; } /* end if */ } /* end if */ diff --git a/tools/src/h5repack/h5repack_copy.c b/tools/src/h5repack/h5repack_copy.c index 946f5ad..501f084 100644 --- a/tools/src/h5repack/h5repack_copy.c +++ b/tools/src/h5repack/h5repack_copy.c @@ -782,7 +782,6 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, switch (travt->objs[i].type) { case H5TRAV_TYPE_UNKNOWN: - HDassert(0); break; /*------------------------------------------------------------------------- @@ -1486,7 +1485,6 @@ static int copy_user_block(const char *infile, const char *outfile, hsize_t size int infid = -1, outfid = -1; /* File descriptors */ /* User block must be any power of 2 equal to 512 or greater (512, 1024, 2048, etc.) */ - HDassert(size > 0); /* Open files */ if ((infid = HDopen(infile, O_RDONLY)) < 0) diff --git a/tools/src/h5repack/h5repack_filters.c b/tools/src/h5repack/h5repack_filters.c index 804727b..c48158c 100644 --- a/tools/src/h5repack/h5repack_filters.c +++ b/tools/src/h5repack/h5repack_filters.c @@ -32,37 +32,32 @@ * *------------------------------------------------------------------------- */ -static int -aux_find_obj(const char* name, /* object name from traverse list */ - pack_opt_t *options, /* repack options */ - pack_info_t *obj /*OUT*/) /* info about object to filter */ +static int aux_find_obj(const char* name, /* object name from traverse list */ + pack_opt_t *options, /* repack options */ + pack_info_t *obj /*OUT*/) /* info about object to filter */ { - char *pdest; - int result; - unsigned int i; - - for ( i=0; i<options->op_tbl->nelems; i++) - { - if (HDstrcmp(options->op_tbl->objs[i].path,name)==0) - { - *obj = options->op_tbl->objs[i]; - return (int)i; - } - - pdest = HDstrstr(name,options->op_tbl->objs[i].path); - result = (int)(pdest - name); - - /* found at position 1, meaning without '/' */ - if( pdest != NULL && result==1 ) - { - *obj = options->op_tbl->objs[i]; - return (int)i; - } - }/*i*/ - - return -1; -} + char *pdest; + int result; + unsigned int i; + + for (i = 0; i < options->op_tbl->nelems; i++) { + if (HDstrcmp(options->op_tbl->objs[i].path,name) == 0) { + *obj = options->op_tbl->objs[i]; + return (int) i; + } + pdest = HDstrstr(name, options->op_tbl->objs[i].path); + result = (int) (pdest - name); + + /* found at position 1, meaning without '/' */ + if (pdest != NULL && result == 1) { + *obj = options->op_tbl->objs[i]; + return (int) i; + } + }/*i*/ + + return -1; +} /*------------------------------------------------------------------------- * Function: aux_assign_obj @@ -74,35 +69,31 @@ aux_find_obj(const char* name, /* object name from traverse list */ * *------------------------------------------------------------------------- */ -static int -aux_assign_obj(const char* name, /* object name from traverse list */ - pack_opt_t *options, /* repack options */ - pack_info_t *obj /*OUT*/) /* info about object to filter */ +static int aux_assign_obj(const char* name, /* object name from traverse list */ + pack_opt_t *options, /* repack options */ + pack_info_t *obj /*OUT*/) /* info about object to filter */ { - int idx, i; + int idx, i; pack_info_t tmp; init_packobject(&tmp); - idx = aux_find_obj(name,options,&tmp); + idx = aux_find_obj(name, options, &tmp); /* name was on input */ - if (idx>=0) - { - + if (idx >= 0) { /* applying to all objects */ - if (options->all_layout) - { + if (options->all_layout) { /* assign the global layout info to the OBJ info */ - tmp.layout=options->layout_g; - switch (options->layout_g) - { + tmp.layout = options->layout_g; + switch (options->layout_g) { case H5D_CHUNKED: - tmp.chunk.rank=options->chunk_g.rank; - for ( i=0; i<tmp.chunk.rank; i++) - tmp.chunk.chunk_lengths[i]=options->chunk_g.chunk_lengths[i]; + tmp.chunk.rank = options->chunk_g.rank; + for (i = 0; i < tmp.chunk.rank; i++) + tmp.chunk.chunk_lengths[i] = + options->chunk_g.chunk_lengths[i]; break; case H5D_LAYOUT_ERROR: case H5D_COMPACT: @@ -114,15 +105,14 @@ aux_assign_obj(const char* name, /* object name from traverse list */ break; }/*switch*/ } - else - { + else { tmp.layout = options->op_tbl->objs[idx].layout; - switch (tmp.layout) - { + switch (tmp.layout) { case H5D_CHUNKED: tmp.chunk.rank = options->op_tbl->objs[idx].chunk.rank; - for ( i=0; i<tmp.chunk.rank; i++) - tmp.chunk.chunk_lengths[i]=options->op_tbl->objs[idx].chunk.chunk_lengths[i]; + for (i = 0; i < tmp.chunk.rank; i++) + tmp.chunk.chunk_lengths[i] = + options->op_tbl->objs[idx].chunk.chunk_lengths[i]; break; case H5D_LAYOUT_ERROR: case H5D_COMPACT: @@ -137,49 +127,37 @@ aux_assign_obj(const char* name, /* object name from traverse list */ } /* applying to all objects */ - if (options->all_filter) - { + if (options->all_filter) { /* assign the global filter */ - tmp.nfilters=1; - tmp.filter[0]=options->filter_g[0]; + tmp.nfilters = 1; + tmp.filter[0] = options->filter_g[0]; } /* if all */ - else - { - tmp.nfilters=options->op_tbl->objs[idx].nfilters; - for ( i=0; i<tmp.nfilters; i++) - { + else { + tmp.nfilters = options->op_tbl->objs[idx].nfilters; + for (i = 0; i < tmp.nfilters; i++) { tmp.filter[i] = options->op_tbl->objs[idx].filter[i]; } } - - } /* if idx */ - - /* no input name */ - - else - { - - if (options->all_filter) - { + else { + if (options->all_filter) { int k; /* assign the global filters */ - tmp.nfilters=options->n_filter_g; - for ( k = 0; k < options->n_filter_g; k++) - tmp.filter[k]=options->filter_g[k]; + tmp.nfilters = options->n_filter_g; + for (k = 0; k < options->n_filter_g; k++) + tmp.filter[k] = options->filter_g[k]; } - if (options->all_layout) - { + if (options->all_layout) { /* assign the global layout info to the OBJ info */ - tmp.layout=options->layout_g; - switch (options->layout_g) - { + tmp.layout = options->layout_g; + switch (options->layout_g) { case H5D_CHUNKED: - tmp.chunk.rank=options->chunk_g.rank; - for ( i=0; i<tmp.chunk.rank; i++) - tmp.chunk.chunk_lengths[i]=options->chunk_g.chunk_lengths[i]; + tmp.chunk.rank = options->chunk_g.rank; + for (i = 0; i < tmp.chunk.rank; i++) + tmp.chunk.chunk_lengths[i] = + options->chunk_g.chunk_lengths[i]; break; case H5D_LAYOUT_ERROR: case H5D_COMPACT: @@ -195,10 +173,8 @@ aux_assign_obj(const char* name, /* object name from traverse list */ *obj = tmp; return 1; - } - /*------------------------------------------------------------------------- * Function: apply_filters * @@ -215,74 +191,69 @@ aux_assign_obj(const char* name, /* object name from traverse list */ *------------------------------------------------------------------------- */ -int apply_filters(const char* name, /* object name from traverse list */ - int rank, /* rank of dataset */ - hsize_t *dims, /* dimensions of dataset */ - size_t msize, /* size of type */ - hid_t dcpl_id, /* dataset creation property list */ - pack_opt_t *options, /* repack options */ - int *has_filter) /* (OUT) object NAME has a filter */ - - +int apply_filters(const char* name, /* object name from traverse list */ + int rank, /* rank of dataset */ + hsize_t *dims, /* dimensions of dataset */ + size_t msize, /* size of type */ + hid_t dcpl_id, /* dataset creation property list */ + pack_opt_t *options, /* repack options */ + int *has_filter) /* (OUT) object NAME has a filter */ { - int nfilters; /* number of filters in DCPL */ - hsize_t chsize[64]; /* chunk size in elements */ + int nfilters; /* number of filters in DCPL */ + hsize_t chsize[64]; /* chunk size in elements */ H5D_layout_t layout; - int i; - pack_info_t obj; + int i; + pack_info_t obj; *has_filter = 0; - if (rank==0) /* scalar dataset, do not apply */ + if (rank == 0) /* scalar dataset, do not apply */ return 0; - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * initialize the assigment object *------------------------------------------------------------------------- */ init_packobject(&obj); - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * find options *------------------------------------------------------------------------- */ - if (aux_assign_obj(name,options,&obj)==0) + if (aux_assign_obj(name, options, &obj) == 0) return 0; /* get information about input filters */ - if ((nfilters = H5Pget_nfilters(dcpl_id))<0) + if ((nfilters = H5Pget_nfilters(dcpl_id)) < 0) return -1; - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * check if we have filters in the pipeline * we want to replace them with the input filters * only remove if we are inserting new ones *------------------------------------------------------------------------- */ - if (nfilters && obj.nfilters ) - { + if (nfilters && obj.nfilters) { *has_filter = 1; - if (H5Premove_filter(dcpl_id,H5Z_FILTER_ALL)<0) + if (H5Premove_filter(dcpl_id, H5Z_FILTER_ALL) < 0) return -1; } - /*------------------------------------------------------------------------- + /*------------------------------------------------------------------------- * check if there is an existent chunk * read it only if there is not a requested layout *------------------------------------------------------------------------- */ - if (obj.layout == -1 ) - { - if ((layout = H5Pget_layout(dcpl_id))<0) + if (obj.layout == -1) { + if ((layout = H5Pget_layout(dcpl_id)) < 0) return -1; - if (layout == H5D_CHUNKED) - { - if ((rank = H5Pget_chunk(dcpl_id,NELMTS(chsize),chsize/*out*/))<0) + if (layout == H5D_CHUNKED) { + if ((rank = H5Pget_chunk(dcpl_id, NELMTS(chsize), chsize/*out*/)) < 0) return -1; obj.layout = H5D_CHUNKED; obj.chunk.rank = rank; - for ( i = 0; i < rank; i++) + for (i = 0; i < rank; i++) obj.chunk.chunk_lengths[i] = chsize[i]; } } @@ -300,19 +271,15 @@ int apply_filters(const char* name, /* object name from traverse list */ *------------------------------------------------------------------------- */ - if (obj.nfilters) - { - - /*------------------------------------------------------------------------- - * filters require CHUNK layout; if we do not have one define a default - *------------------------------------------------------------------------- - */ - if (obj.layout==-1) - { - + if (obj.nfilters) { + /*------------------------------------------------------------------------- + * filters require CHUNK layout; if we do not have one define a default + *------------------------------------------------------------------------- + */ + if (obj.layout == -1) { /* stripmine info */ hsize_t sm_size[H5S_MAX_RANK]; /*stripmine size */ - hsize_t sm_nbytes; /*bytes per stripmine */ + hsize_t sm_nbytes; /*bytes per stripmine */ obj.chunk.rank = rank; @@ -321,138 +288,129 @@ int apply_filters(const char* name, /* object name from traverse list */ * a hyperslab whose size is manageable. */ - - sm_nbytes = msize; - for ( i = rank; i > 0; --i) - { + for (i = rank; i > 0; --i) { hsize_t size = H5TOOLS_BUFSIZE / sm_nbytes; - if ( size == 0) /* datum size > H5TOOLS_BUFSIZE */ + if (size == 0) /* datum size > H5TOOLS_BUFSIZE */ size = 1; sm_size[i - 1] = MIN(dims[i - 1], size); sm_nbytes *= sm_size[i - 1]; HDassert(sm_nbytes > 0); - } - for ( i = 0; i < rank; i++) - { + for (i = 0; i < rank; i++) { obj.chunk.chunk_lengths[i] = sm_size[i]; } - } - for ( i=0; i<obj.nfilters; i++) - { - switch (obj.filter[i].filtn) - { - + for (i = 0; i < obj.nfilters; i++) { + switch (obj.filter[i].filtn) { /*------------------------------------------------------------------------- - * H5Z_FILTER_NONE 0 , uncompress if compressed - *------------------------------------------------------------------------- - */ - case H5Z_FILTER_NONE: - break; - - /*------------------------------------------------------------------------- - * H5Z_FILTER_DEFLATE 1 , deflation like gzip + * H5Z_FILTER_NONE 0 , uncompress if compressed *------------------------------------------------------------------------- */ + case H5Z_FILTER_NONE: + break; + + /*------------------------------------------------------------------------- + * H5Z_FILTER_DEFLATE 1 , deflation like gzip + *------------------------------------------------------------------------- + */ case H5Z_FILTER_DEFLATE: { - unsigned aggression; /* the deflate level */ + unsigned aggression; /* the deflate level */ aggression = obj.filter[i].cd_values[0]; /* set up for deflated data */ - if(H5Pset_chunk(dcpl_id, obj.chunk.rank, obj.chunk.chunk_lengths)<0) + if (H5Pset_chunk(dcpl_id, obj.chunk.rank, obj.chunk.chunk_lengths) < 0) return -1; - if(H5Pset_deflate(dcpl_id,aggression)<0) + if (H5Pset_deflate(dcpl_id, aggression) < 0) return -1; } break; - /*------------------------------------------------------------------------- - * H5Z_FILTER_SZIP 4 , szip compression - *------------------------------------------------------------------------- - */ + /*------------------------------------------------------------------------- + * H5Z_FILTER_SZIP 4 , szip compression + *------------------------------------------------------------------------- + */ case H5Z_FILTER_SZIP: { - unsigned options_mask; - unsigned pixels_per_block; + unsigned options_mask; + unsigned pixels_per_block; - options_mask = obj.filter[i].cd_values[0]; + options_mask = obj.filter[i].cd_values[0]; pixels_per_block = obj.filter[i].cd_values[1]; /* set up for szip data */ - if(H5Pset_chunk(dcpl_id,obj.chunk.rank,obj.chunk.chunk_lengths)<0) + if (H5Pset_chunk(dcpl_id, obj.chunk.rank, obj.chunk.chunk_lengths) < 0) return -1; - if (H5Pset_szip(dcpl_id,options_mask,pixels_per_block)<0) + if (H5Pset_szip(dcpl_id, options_mask, pixels_per_block) < 0) return -1; - } break; - /*------------------------------------------------------------------------- - * H5Z_FILTER_SHUFFLE 2 , shuffle the data - *------------------------------------------------------------------------- - */ + /*------------------------------------------------------------------------- + * H5Z_FILTER_SHUFFLE 2 , shuffle the data + *------------------------------------------------------------------------- + */ case H5Z_FILTER_SHUFFLE: - if(H5Pset_chunk(dcpl_id, obj.chunk.rank, obj.chunk.chunk_lengths)<0) + if (H5Pset_chunk(dcpl_id, obj.chunk.rank, obj.chunk.chunk_lengths) < 0) return -1; - if (H5Pset_shuffle(dcpl_id)<0) + if (H5Pset_shuffle(dcpl_id) < 0) return -1; break; - /*------------------------------------------------------------------------- - * H5Z_FILTER_FLETCHER32 3 , fletcher32 checksum of EDC - *------------------------------------------------------------------------- - */ + /*------------------------------------------------------------------------- + * H5Z_FILTER_FLETCHER32 3 , fletcher32 checksum of EDC + *------------------------------------------------------------------------- + */ case H5Z_FILTER_FLETCHER32: - if(H5Pset_chunk(dcpl_id, obj.chunk.rank, obj.chunk.chunk_lengths)<0) + if (H5Pset_chunk(dcpl_id, obj.chunk.rank, obj.chunk.chunk_lengths) < 0) return -1; - if (H5Pset_fletcher32(dcpl_id)<0) + if (H5Pset_fletcher32(dcpl_id) < 0) return -1; break; - /*----------- ------------------------------------------------------------- - * H5Z_FILTER_NBIT , NBIT compression - *------------------------------------------------------------------------- - */ + /*----------- ------------------------------------------------------------- + * H5Z_FILTER_NBIT , NBIT compression + *------------------------------------------------------------------------- + */ case H5Z_FILTER_NBIT: - if(H5Pset_chunk(dcpl_id, obj.chunk.rank, obj.chunk.chunk_lengths)<0) + if (H5Pset_chunk(dcpl_id, obj.chunk.rank, obj.chunk.chunk_lengths) < 0) return -1; - if (H5Pset_nbit(dcpl_id)<0) + if (H5Pset_nbit(dcpl_id) < 0) return -1; break; - /*----------- ------------------------------------------------------------- - * H5Z_FILTER_SCALEOFFSET , scale+offset compression - *------------------------------------------------------------------------- - */ + /*----------- ------------------------------------------------------------- + * H5Z_FILTER_SCALEOFFSET , scale+offset compression + *------------------------------------------------------------------------- + */ case H5Z_FILTER_SCALEOFFSET: { H5Z_SO_scale_type_t scale_type; - int scale_factor; + int scale_factor; - scale_type = (H5Z_SO_scale_type_t)obj.filter[i].cd_values[0]; - scale_factor = (int)obj.filter[i].cd_values[1]; + scale_type = (H5Z_SO_scale_type_t) obj.filter[i].cd_values[0]; + scale_factor = (int) obj.filter[i].cd_values[1]; - if(H5Pset_chunk(dcpl_id, obj.chunk.rank, obj.chunk.chunk_lengths)<0) + if (H5Pset_chunk(dcpl_id, obj.chunk.rank, obj.chunk.chunk_lengths) < 0) return -1; - if (H5Pset_scaleoffset(dcpl_id,scale_type,scale_factor)<0) + if (H5Pset_scaleoffset(dcpl_id, scale_type, scale_factor) < 0) return -1; } break; default: - { - if (H5Pset_filter (dcpl_id, obj.filter[i].filtn, H5Z_FLAG_MANDATORY, obj.filter[i].cd_nelmts, obj.filter[i].cd_values)<0) - return -1; - if(H5Pset_chunk(dcpl_id, obj.chunk.rank, obj.chunk.chunk_lengths)<0) - return -1; - } + { + if (H5Pset_filter(dcpl_id, obj.filter[i].filtn, + H5Z_FLAG_MANDATORY, obj.filter[i].cd_nelmts, + obj.filter[i].cd_values) < 0) + return -1; + if (H5Pset_chunk(dcpl_id, obj.chunk.rank, obj.chunk.chunk_lengths) < 0) + return -1; + } break; } /* switch */ }/*i*/ - } /*obj.nfilters*/ @@ -461,31 +419,27 @@ int apply_filters(const char* name, /* object name from traverse list */ *------------------------------------------------------------------------- */ - if (obj.layout>=0) - { + if (obj.layout >= 0) { /* a layout was defined */ - if (H5Pset_layout(dcpl_id, obj.layout)<0) + if (H5Pset_layout(dcpl_id, obj.layout) < 0) return -1; - if (H5D_CHUNKED == obj.layout) - { - if(H5Pset_chunk(dcpl_id, obj.chunk.rank, obj.chunk.chunk_lengths)<0) + if (H5D_CHUNKED == obj.layout) { + if (H5Pset_chunk(dcpl_id, obj.chunk.rank, obj.chunk.chunk_lengths) < 0) return -1; } - else if (H5D_COMPACT == obj.layout) - { - if (H5Pset_alloc_time(dcpl_id, H5D_ALLOC_TIME_EARLY)<0) + else if (H5D_COMPACT == obj.layout) { + if (H5Pset_alloc_time(dcpl_id, H5D_ALLOC_TIME_EARLY) < 0) return -1; } /* remove filters for the H5D_CONTIGUOUS case */ - else if (H5D_CONTIGUOUS == obj.layout) - { - if (H5Premove_filter(dcpl_id,H5Z_FILTER_ALL)<0) + else if (H5D_CONTIGUOUS == obj.layout) { + if (H5Premove_filter(dcpl_id, H5Z_FILTER_ALL) < 0) return -1; } } - return 0; + return 0; } diff --git a/tools/src/h5repack/h5repack_refs.c b/tools/src/h5repack/h5repack_refs.c index 408142c..36038b5 100644 --- a/tools/src/h5repack/h5repack_refs.c +++ b/tools/src/h5repack/h5repack_refs.c @@ -189,8 +189,7 @@ int do_copy_refobjs(hid_t fidin, /* create the reference, -1 parameter for objects */ if(H5Rcreate(&refbuf[u], fidout, refname, H5R_OBJECT, (hid_t)-1) < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Rcreate failed"); - if(options->verbose) - { + if(options->verbose) { printf(FORMAT_OBJ,"dset",travt->objs[i].name ); printf("object <%s> object reference created to <%s>\n", travt->objs[i].name, @@ -278,8 +277,7 @@ int do_copy_refobjs(hid_t fidin, HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Rcreate failed"); if(H5Sclose(region_id) < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sclose failed"); - if(options->verbose) - { + if(options->verbose) { printf(FORMAT_OBJ,"dset",travt->objs[i].name ); printf("object <%s> region reference created to <%s>\n", travt->objs[i].name, @@ -320,8 +318,6 @@ int do_copy_refobjs(hid_t fidin, HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dopen2 failed"); } /* end else */ - HDassert(dset_out != FAIL); - /*------------------------------------------------------------------------- * copy referenced objects in attributes *------------------------------------------------------------------------- |