diff options
Diffstat (limited to 'tools/h5repack/h5repack_copy.c')
-rw-r--r-- | tools/h5repack/h5repack_copy.c | 530 |
1 files changed, 264 insertions, 266 deletions
diff --git a/tools/h5repack/h5repack_copy.c b/tools/h5repack/h5repack_copy.c index 1171ab8..9c01b7e 100644 --- a/tools/h5repack/h5repack_copy.c +++ b/tools/h5repack/h5repack_copy.c @@ -44,7 +44,7 @@ H5Ewalk2(H5E_DEFAULT, H5E_WALK_DOWNWARD, walk_error_callback, &_err_num); \ H5Eget_msg(_err_num, NULL, _msg, (size_t)80); \ error_msg("%s %s -- %s\n", #_fun, "failed", _msg); \ - goto error; \ + goto done; \ } \ } H5E_END_TRY; \ } @@ -98,7 +98,8 @@ static herr_t walk_error_callback(H5_ATTR_UNUSED unsigned n, const H5E_error2_t */ int copy_objects(const char* fnamein, const char* fnameout, pack_opt_t *options) { - hid_t fidin; + int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */ + hid_t fidin; hid_t fidout = -1; trav_table_t *travt = NULL; hsize_t ub_size = 0; /* size of user block */ @@ -112,8 +113,8 @@ int copy_objects(const char* fnamein, const char* fnameout, pack_opt_t *options) if ((fidin = h5tools_fopen(fnamein, H5F_ACC_RDONLY, H5P_DEFAULT, NULL, NULL, (size_t) 0)) < 0) { error_msg("<%s>: %s\n", fnamein, H5FOPENERROR); - goto out; - } + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); + } /* get user block size and file space strategy/threshold */ { @@ -121,32 +122,32 @@ int copy_objects(const char* fnamein, const char* fnameout, pack_opt_t *options) if ((fcpl_in = H5Fget_create_plist(fidin)) < 0) { error_msg("failed to retrieve file creation property list\n"); - goto out; - } + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); + } if (H5Pget_userblock(fcpl_in, &ub_size) < 0) { error_msg("failed to retrieve userblock size\n"); - goto out; - } + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); + } if (!options->fs_strategy) { if (H5Pget_file_space(fcpl_in, &options->fs_strategy, NULL) < 0) { error_msg("failed to retrieve file space strategy\n"); - goto out; - } + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); + } } if (!options->fs_threshold) { if (H5Pget_file_space(fcpl_in, NULL, &options->fs_threshold) < 0) { error_msg("failed to retrieve file space threshold\n"); - goto out; - } + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); + } } if (H5Pclose(fcpl_in) < 0) { error_msg("failed to close property list\n"); - goto out; - } + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); + } } /* Check if we need to create a non-default file creation property list */ @@ -154,14 +155,14 @@ int copy_objects(const char* fnamein, const char* fnameout, pack_opt_t *options) /* Create file creation property list */ if ((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0) { error_msg("fail to create a file creation property list\n"); - goto out; - } + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); + } if (ub_size > 0) { if (H5Pset_userblock(fcpl, ub_size) < 0) { error_msg("failed to set non-default userblock size\n"); - goto out; - } + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); + } } if (options->latest) { @@ -173,8 +174,8 @@ int copy_objects(const char* fnamein, const char* fnameout, pack_opt_t *options) (unsigned) options->grp_indexed) < 0) { error_msg( "fail to adjust group creation parameters for root group\n"); - goto out; - } + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); + } for (i = 0; i < 5; i++) { if (options->msg_size[i] > 0) { @@ -211,8 +212,8 @@ int copy_objects(const char* fnamein, const char* fnameout, pack_opt_t *options) if (H5Pset_shared_mesg_nindexes(fcpl, nindex) < 0) { error_msg( "fail to set the number of shared object header message indexes\n"); - goto out; - } + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); + } /* msg_size[0]=dataspace, 1=datatype, 2=file value, 3=filter pipleline, 4=attribute */ for (i = 0; i < (nindex - 1); i++) { @@ -220,22 +221,22 @@ int copy_objects(const char* fnamein, const char* fnameout, pack_opt_t *options) min_mesg_sizes[i]) < 0) { error_msg( "fail to configure the specified shared object header message index\n"); - goto out; - } /* end if */ + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); + } /* end if */ } /* end for */ } /* if (nindex>0) */ /* Create file access property list */ if ((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) { error_msg("Could not create file access property list\n"); - goto out; - } /* end if */ + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); + } /* end if */ if (H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) { error_msg( "Could not set property for using latest version of the format\n"); - goto out; - } /* end if */ + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); + } /* end if */ } /* end if */ } /* end if */ #if defined (H5REPACK_DEBUG_USER_BLOCK) @@ -252,101 +253,100 @@ int copy_objects(const char* fnamein, const char* fnameout, pack_opt_t *options) /* create a file creation property list */ if ((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0) { error_msg("fail to create a file creation property list\n"); - goto out; - } - } - - /* set user block size */ - if (H5Pset_userblock(fcpl, options->ublock_size) < 0) { - error_msg("failed to set userblock size\n"); - goto out; - } - } - - /*------------------------------------------------------------------------- - * set alignment options - *------------------------------------------------------------------------- - */ - if (options->alignment > 0) { - /* either use the FAPL already created or create a new one */ - if (fapl == H5P_DEFAULT) { - /* create a file access property list */ - if ((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) { - error_msg("Could not create file access property list\n"); - goto out; - } - } - - if (H5Pset_alignment(fapl, options->threshold, options->alignment) < 0) { - error_msg("failed to set alignment\n"); - goto out; - } - } - - /*------------------------------------------------------------------------- - * set metadata block size option - *------------------------------------------------------------------------- - */ - if (options->meta_block_size > 0) { - /* either use the FAPL already created or create a new one */ - if (fapl == H5P_DEFAULT) { - /* create a file access property list */ - if ((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) { - error_msg("Could not create file access property list\n"); - goto out; - } - } - - if (H5Pset_meta_block_size(fapl, options->meta_block_size) < 0) { - error_msg("failed to set metadata block size\n"); - goto out; - } - } - - /*------------------------------------------------------------------------- - * set free-space strategy options - *------------------------------------------------------------------------- - */ - - /* either use the FCPL already created or create a new one */ - if (fcpl == H5P_DEFAULT) { - /* create a file creation property list */ - if ((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0) { - error_msg("fail to create a file creation property list\n"); - goto out; - } - } - - /* set file space strategy and free space threshold */ - if (H5Pset_file_space(fcpl, options->fs_strategy, options->fs_threshold) < 0) { - error_msg("failed to set file space strategy & threshold \n"); - goto out; - } - - /*------------------------------------------------------------------------- - * create the output file - *------------------------------------------------------------------------- - */ - if (options->verbose) - printf("Making file <%s>...\n", fnameout); - - if ((fidout = H5Fcreate(fnameout, H5F_ACC_TRUNC, fcpl, fapl)) < 0) { - error_msg("<%s>: Could not create file\n", fnameout); - goto out; - } - - /*------------------------------------------------------------------------- - * write a new user block if requested - *------------------------------------------------------------------------- - */ - if (options->ublock_size > 0) { - if (copy_user_block(options->ublock_filename, fnameout, - options->ublock_size) < 0) { - error_msg("Could not copy user block. Exiting...\n"); - goto out; - - } - } + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); + } + } + + /* set user block size */ + if (H5Pset_userblock(fcpl, options->ublock_size) < 0) { + error_msg("failed to set userblock size\n"); + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); + } + } + + /*------------------------------------------------------------------------- + * set alignment options + *------------------------------------------------------------------------- + */ + if (options->alignment > 0) { + /* either use the FAPL already created or create a new one */ + if (fapl == H5P_DEFAULT) { + /* create a file access property list */ + if ((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) { + error_msg("Could not create file access property list\n"); + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); + } + } + + if (H5Pset_alignment(fapl, options->threshold, options->alignment) < 0) { + error_msg("failed to set alignment\n"); + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); + } + } + + /*------------------------------------------------------------------------- + * set metadata block size option + *------------------------------------------------------------------------- + */ + if (options->meta_block_size > 0) { + /* either use the FAPL already created or create a new one */ + if (fapl == H5P_DEFAULT) { + /* create a file access property list */ + if ((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) { + error_msg("Could not create file access property list\n"); + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); + } + } + + if (H5Pset_meta_block_size(fapl, options->meta_block_size) < 0) { + error_msg("failed to set metadata block size\n"); + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); + } + } + + /*------------------------------------------------------------------------- + * set free-space strategy options + *------------------------------------------------------------------------- + */ + + /* either use the FCPL already created or create a new one */ + if (fcpl == H5P_DEFAULT) { + /* create a file creation property list */ + if ((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0) { + error_msg("fail to create a file creation property list\n"); + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); + } + } + + /* set file space strategy and free space threshold */ + if (H5Pset_file_space(fcpl, options->fs_strategy, options->fs_threshold) < 0) { + error_msg("failed to set file space strategy & threshold \n"); + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); + } + + /*------------------------------------------------------------------------- + * create the output file + *------------------------------------------------------------------------- + */ + if (options->verbose) + printf("Making file <%s>...\n", fnameout); + + if ((fidout = H5Fcreate(fnameout, H5F_ACC_TRUNC, fcpl, fapl)) < 0) { + error_msg("<%s>: Could not create file\n", fnameout); + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); + } + + /*------------------------------------------------------------------------- + * write a new user block if requested + *------------------------------------------------------------------------- + */ + if (options->ublock_size > 0) { + if (copy_user_block(options->ublock_filename, fnameout, + options->ublock_size) < 0) { + error_msg("Could not copy user block. Exiting...\n"); + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); + } + } /*------------------------------------------------------------------------- * get list of objects @@ -358,7 +358,7 @@ int copy_objects(const char* fnamein, const char* fnameout, pack_opt_t *options) /* get the list of objects in the file */ if (h5trav_gettable(fidin, travt) < 0) - goto out; + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); /*------------------------------------------------------------------------- * do the copy @@ -366,8 +366,8 @@ int copy_objects(const char* fnamein, const char* fnameout, pack_opt_t *options) */ if (do_copy_objects(fidin, fidout, travt, options) < 0) { error_msg("<%s>: Could not copy data to: %s\n", fnamein, fnameout); - goto out; - } /* end if */ + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); + } /* end if */ /*------------------------------------------------------------------------- * do the copy of referenced objects @@ -377,8 +377,8 @@ int copy_objects(const char* fnamein, const char* fnameout, pack_opt_t *options) if (do_copy_refobjs(fidin, fidout, travt, options) < 0) { printf("h5repack: <%s>: Could not copy data to: %s\n", fnamein, fnameout); - goto out; - } + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); + } /*------------------------------------------------------------------------- * close @@ -406,7 +406,7 @@ int copy_objects(const char* fnamein, const char* fnameout, pack_opt_t *options) if (ub_size > 0 && options->ublock_size == 0) { if (copy_user_block(fnamein, fnameout, ub_size) < 0) { error_msg("Could not copy user block. Exiting...\n"); - goto out; + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); } } @@ -418,7 +418,7 @@ int copy_objects(const char* fnamein, const char* fnameout, pack_opt_t *options) *------------------------------------------------------------------------- */ -out: +done: H5E_BEGIN_TRY { H5Pclose(fapl); @@ -470,8 +470,9 @@ out: *-----------------------------------------*/ int Get_hyperslab(hid_t dcpl_id, int rank_dset, hsize_t dims_dset[], - size_t size_datum, hsize_t dims_hslab[], hsize_t * hslab_nbytes_p) { - int status = 0; + size_t size_datum, hsize_t dims_hslab[], hsize_t * hslab_nbytes_p) { + int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */ + int status = 0; int k; H5D_layout_t dset_layout; int rank_chunk; @@ -495,8 +496,8 @@ int Get_hyperslab(hid_t dcpl_id, int rank_dset, hsize_t dims_dset[], rank_chunk = H5Pget_chunk(dcpl_id, rank_dset, dims_chunk); if (rank_chunk < 0) { status = -1; - goto out; - } + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); + } for (k = rank_dset; k > 0; --k) size_chunk *= dims_chunk[k - 1]; @@ -560,8 +561,8 @@ int Get_hyperslab(hid_t dcpl_id, int rank_dset, hsize_t dims_dset[], if (hslab_nbytes <= 0) { status = -1; - goto out; - } + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); + } } } } @@ -586,15 +587,15 @@ int Get_hyperslab(hid_t dcpl_id, int rank_dset, hsize_t dims_dset[], if (hslab_nbytes <= 0) { status = -1; - goto out; - } + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); + } } } /* pass out the hyperslab size*/ *hslab_nbytes_p = hslab_nbytes; -out: +done: return status; } @@ -695,7 +696,8 @@ out: int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, pack_opt_t *options) /* repack options */ { - hid_t grp_in = -1; /* group ID */ + int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */ + hid_t grp_in = -1; /* group ID */ hid_t grp_out = -1; /* group ID */ hid_t dset_in = -1; /* read dataset ID */ hid_t dset_out = -1; /* write dataset ID */ @@ -765,22 +767,22 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, /* open input group */ if ((grp_in = H5Gopen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0) - goto error; + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Gopen2 failed"); /* get input group creation property list */ if ((gcpl_in = H5Gget_create_plist(grp_in)) < 0) - goto error; + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Gget_create_plist failed"); /* query and set the group creation properties */ if (H5Pget_link_creation_order(gcpl_in, &crt_order_flags) < 0) - goto error; + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pget_link_creation_order failed"); /* set up group creation property list */ if ((gcpl_out = H5Pcreate(H5P_GROUP_CREATE)) < 0) - goto error; + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pcreate failed"); if (H5Pset_link_creation_order(gcpl_out, crt_order_flags) < 0) - goto error; + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pset_link_creation_order failed"); /*------------------------------------------------------------------------- * the root is a special case, we get an ID for the root group @@ -789,20 +791,20 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, */ if (HDstrcmp(travt->objs[i].name, "/") == 0) { if ((grp_out = H5Gopen2(fidout, "/", H5P_DEFAULT)) < 0) - goto error; - } + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Gopen2 failed"); + } else { if (options->grp_compact > 0 || options->grp_indexed > 0) { if (H5Pset_link_phase_change(gcpl_out, (unsigned) options->grp_compact, (unsigned) options->grp_indexed) < 0) - goto error; - } + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pset_link_phase_change failed"); + } if ((grp_out = H5Gcreate2(fidout, travt->objs[i].name, H5P_DEFAULT, gcpl_out, H5P_DEFAULT)) < 0) - goto error; + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Gcreate2 failed"); } @@ -811,16 +813,16 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, *------------------------------------------------------------------------- */ if (copy_attr(grp_in, grp_out, &named_dt_head, travt, options) < 0) - goto error; + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "copy_attr failed"); - if (H5Pclose(gcpl_out) < 0) - goto error; - if (H5Pclose(gcpl_in) < 0) - goto error; - if (H5Gclose(grp_out) < 0) - goto error; - if (H5Gclose(grp_in) < 0) - goto error; + if (H5Pclose(gcpl_out) < 0) + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); + if (H5Pclose(gcpl_in) < 0) + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); + if (H5Gclose(grp_out) < 0) + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Gclose failed"); + if (H5Gclose(grp_in) < 0) + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Gclose failed"); break; @@ -864,24 +866,24 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, /* early detection of references */ if ((dset_in = H5Dopen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0) - goto error; - if ((ftype_id = H5Dget_type(dset_in)) < 0) - goto error; - if (H5T_REFERENCE == H5Tget_class(ftype_id)) + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Dopen2 failed"); + if ((ftype_id = H5Dget_type(dset_in)) < 0) + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Dget_type failed"); + if (H5T_REFERENCE == H5Tget_class(ftype_id)) is_ref = 1; /* Check if the datatype is committed */ if ((is_named = H5Tcommitted(ftype_id)) < 0) - goto error; - if (is_named) + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tcommitted failed"); + if (is_named) if ((wtype_id = copy_named_datatype(ftype_id, fidout, &named_dt_head, travt, options)) < 0) - goto error; + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "copy_named_datatype failed"); if (H5Tclose(ftype_id) < 0) - goto error; - if (H5Dclose(dset_in) < 0) - goto error; + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed"); + if (H5Dclose(dset_in) < 0) + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Dclose failed"); /*------------------------------------------------------------------------- * check if we should use H5Ocopy or not @@ -895,23 +897,23 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, int j; if ((dset_in = H5Dopen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0) - goto error; - if ((f_space_id = H5Dget_space(dset_in)) < 0) - goto error; - if ((ftype_id = H5Dget_type(dset_in)) < 0) - goto error; - if ((dcpl_in = H5Dget_create_plist(dset_in)) < 0) - goto error; - if ((dcpl_out = H5Pcopy(dcpl_in)) < 0) - goto error; - if ((rank = H5Sget_simple_extent_ndims(f_space_id)) < 0) - goto error; - HDmemset(dims, 0, sizeof dims); + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Dopen2 failed"); + if ((f_space_id = H5Dget_space(dset_in)) < 0) + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Dget_space failed"); + if ((ftype_id = H5Dget_type(dset_in)) < 0) + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Dget_type failed"); + if ((dcpl_in = H5Dget_create_plist(dset_in)) < 0) + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Dget_create_plist failed"); + if ((dcpl_out = H5Pcopy(dcpl_in)) < 0) + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pcopy failed"); + if ((rank = H5Sget_simple_extent_ndims(f_space_id)) < 0) + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed"); + HDmemset(dims, 0, sizeof dims); if (H5Sget_simple_extent_dims(f_space_id, dims, NULL) < 0) - goto error; + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed"); if (H5Dget_space_status(dset_in, &space_status) < 0) - goto error; + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Dget_space_status failed"); nelmts = 1; for (j = 0; j < rank; j++) @@ -926,7 +928,7 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, } /* end if */ if ((msize = H5Tget_size(wtype_id)) == 0) - goto error; + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tget_size failed"); /* size of current dset */ size_dset = nelmts * msize; @@ -965,8 +967,8 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, if (apply_s) { if (apply_filters(travt->objs[i].name, rank, dims, msize, dcpl_out, options, &has_filter) < 0) - goto error; - } + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "apply_filters failed"); + } /* only if layout change requested for entire file or * individual obj */ @@ -1009,16 +1011,14 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, * modified dcpl; in that case use the original instead *------------------------------------------------------------------------- */ - H5E_BEGIN_TRY - { - dset_out = H5Dcreate2(fidout, + dset_out = H5Dcreate2(fidout, travt->objs[i].name, wtype_id, f_space_id, H5P_DEFAULT, dcpl_out, H5P_DEFAULT); - }H5E_END_TRY; if (dset_out == FAIL) { - if (options->verbose) + HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Dcreate2 failed"); + if (options->verbose) printf( " warning: could not create dataset <%s>. Applying original settings\n", travt->objs[i].name); @@ -1026,8 +1026,8 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, if ((dset_out = H5Dcreate2(fidout, travt->objs[i].name, wtype_id, f_space_id, H5P_DEFAULT, dcpl_in, H5P_DEFAULT)) < 0) - goto error; - apply_f = 0; + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Dcreate2 failed"); + apply_f = 0; } /*------------------------------------------------------------------------- @@ -1053,8 +1053,8 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, if (TRUE == H5Tdetect_class(wtype_id, H5T_VLEN)) if (H5Dvlen_reclaim(wtype_id, f_space_id, H5P_DEFAULT, buf) < 0) - goto error; - } + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Dvlen_reclaim failed"); + } else { /* possibly not enough memory, read/write by hyperslabs */ size_t p_type_nbytes = msize; /*size of memory type */ hsize_t p_nelmts = nelmts; /*total elements */ @@ -1096,7 +1096,7 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, if (Get_hyperslab(dcpl_tmp, rank, dims, p_type_nbytes, hslab_dims, &hslab_nbytes) < 0) - goto error; + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "Get_hyperslab failed"); hslab_buf = HDmalloc((size_t)hslab_nbytes); @@ -1126,12 +1126,12 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, if (H5Sselect_hyperslab(f_space_id, H5S_SELECT_SET, hs_sel_offset, NULL, hs_sel_count, NULL) < 0) - goto error; - if (H5Sselect_hyperslab(hslab_space, + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sselect_hyperslab failed"); + if (H5Sselect_hyperslab(hslab_space, H5S_SELECT_SET, zero, NULL, &hs_select_nelmts, NULL) < 0) - goto error; - } + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sselect_hyperslab failed"); + } else { H5Sselect_all(f_space_id); H5Sselect_all(hslab_space); @@ -1219,10 +1219,10 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, */ if (copy_attr(dset_in, dset_out, &named_dt_head, travt, options) < 0) - goto error; - /*close */ + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "copy_attr failed"); + /*close */ if (H5Dclose(dset_out) < 0) - goto error; + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Dclose failed"); }/*!H5T_REFERENCE*/ }/*h5tools_canreadf*/ @@ -1232,17 +1232,17 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, *------------------------------------------------------------------------- */ if (H5Tclose(ftype_id) < 0) - goto error; - if (H5Tclose(wtype_id) < 0) - goto error; - if (H5Pclose(dcpl_in) < 0) - goto error; - if (H5Pclose(dcpl_out) < 0) - goto error; - if (H5Sclose(f_space_id) < 0) - goto error; - if (H5Dclose(dset_in) < 0) - goto error; + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed"); + if (H5Tclose(wtype_id) < 0) + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed"); + if (H5Pclose(dcpl_in) < 0) + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); + if (H5Pclose(dcpl_out) < 0) + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); + if (H5Sclose(f_space_id) < 0) + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed"); + if (H5Dclose(dset_in) < 0) + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Dclose failed"); } /*------------------------------------------------------------------------- @@ -1254,11 +1254,11 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, /* create property to pass copy options */ if ((pid = H5Pcreate(H5P_OBJECT_COPY)) < 0) - goto error; + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pcreate failed"); /* set options for object copy */ if (H5Pset_copy_object(pid, H5O_COPY_WITHOUT_ATTR_FLAG) < 0) - goto error; + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pset_copy_object failed"); /*------------------------------------------------------------------------- * do the copy @@ -1271,11 +1271,11 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, travt->objs[i].name, /* Name of the destination object */ pid, /* Properties which apply to the copy */ H5P_DEFAULT) < 0) /* Properties which apply to the new hard link */ - goto error; + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Ocopy failed"); /* close property */ if (H5Pclose(pid) < 0) - goto error; + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); /*------------------------------------------------------------------------- * copy attrs manually @@ -1283,17 +1283,15 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, */ if ((dset_in = H5Dopen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0) - goto error; - if ((dset_out = H5Dopen2(fidout, travt->objs[i].name, - H5P_DEFAULT)) < 0) - goto error; - if (copy_attr(dset_in, dset_out, &named_dt_head, travt, options) - < 0) - goto error; - if (H5Dclose(dset_in) < 0) - goto error; - if (H5Dclose(dset_out) < 0) - goto error; + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Dopen2 failed"); + if ((dset_out = H5Dopen2(fidout, travt->objs[i].name, H5P_DEFAULT)) < 0) + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Dopen2 failed"); + if (copy_attr(dset_in, dset_out, &named_dt_head, travt, options) < 0) + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "copy_attr failed"); + if (H5Dclose(dset_in) < 0) + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Dclose failed"); + if (H5Dclose(dset_out) < 0) + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Dclose failed"); if (options->verbose) printf(FORMAT_OBJ, "dset", travt->objs[i].name); @@ -1311,32 +1309,30 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, if (options->verbose) printf(FORMAT_OBJ, "type", travt->objs[i].name); - if ((type_in = H5Topen2(fidin, travt->objs[i].name, H5P_DEFAULT)) - < 0) - goto error; + if ((type_in = H5Topen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0) + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Topen2 failed"); /* Copy the datatype anonymously */ if ((type_out = copy_named_datatype(type_in, fidout, &named_dt_head, travt, options)) < 0) - goto error; + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "copy_named_datatype failed"); /* Link in to group structure */ if (H5Lcreate_hard(type_out, ".", fidout, travt->objs[i].name, H5P_DEFAULT, H5P_DEFAULT) < 0) - goto error; + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Lcreate_hard failed"); /*------------------------------------------------------------------------- * copy attrs *------------------------------------------------------------------------- */ - if (copy_attr(type_in, type_out, &named_dt_head, travt, options) - < 0) - goto error; + if (copy_attr(type_in, type_out, &named_dt_head, travt, options) < 0) + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "copy_attr failed"); if (H5Tclose(type_in) < 0) - goto error; - if (H5Tclose(type_out) < 0) - goto error; + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed"); + if (H5Tclose(type_out) < 0) + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed"); break; @@ -1356,8 +1352,8 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, printf(FORMAT_OBJ, "link", travt->objs[i].name); if (H5Lcopy(fidin, travt->objs[i].name, fidout, travt->objs[i].name, - H5P_DEFAULT, H5P_DEFAULT) < 0) - goto error; + H5P_DEFAULT, H5P_DEFAULT) < 0) + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Lcopy failed"); if (options->verbose) printf(FORMAT_OBJ, "link", travt->objs[i].name); @@ -1366,8 +1362,8 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, break; default: - goto error; - } /* switch */ + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "Object type not found"); + } /* switch */ /* free */ if (buf != NULL) { @@ -1382,7 +1378,7 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, return 0; -error: +done: H5E_BEGIN_TRY { H5Gclose(grp_in); @@ -1526,8 +1522,9 @@ static void print_dataset_info(hid_t dcpl_id, char *objname, double ratio, *------------------------------------------------------------------------- */ static int copy_user_block(const char *infile, const char *outfile, - hsize_t size) { - int infid = -1, outfid = -1; /* File descriptors */ + hsize_t size) { + int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */ + int infid = -1, outfid = -1; /* File descriptors */ int status = 0; /* Return value */ /* User block must be any power of 2 equal to 512 or greater (512, 1024, 2048, etc.) */ @@ -1536,12 +1533,12 @@ static int copy_user_block(const char *infile, const char *outfile, /* Open files */ if ((infid = HDopen(infile, O_RDONLY, 0)) < 0) { status = -1; - goto done; - } + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "HDopen failed"); + } if ((outfid = HDopen(outfile, O_WRONLY, 0644)) < 0) { status = -1; - goto done; - } + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "HDopen failed"); + } /* Copy the userblock from the input file to the output file */ while (size > 0) { @@ -1556,8 +1553,8 @@ static int copy_user_block(const char *infile, const char *outfile, nread = HDread(infid, rbuf, (size_t)size); if (nread < 0) { status = -1; - goto done; - } /* end if */ + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "HDread failed"); + } /* end if */ /* Write buffer to destination file */ /* (compensating for interrupted writes & checking for errors, etc.) */ @@ -1571,8 +1568,8 @@ static int copy_user_block(const char *infile, const char *outfile, } while (-1 == nwritten && EINTR == errno); if (-1 == nwritten) { /* error */ status = -1; - goto done; - } /* end if */ + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "HDwrite failed"); + } /* end if */ HDassert(nwritten > 0); HDassert(nwritten <= nbytes); @@ -1612,7 +1609,8 @@ done: static void print_user_block(const char *filename, hid_t fid) { - int fh; /* file handle */ + int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */ + int fh; /* file handle */ hsize_t ub_size; /* user block size */ hsize_t size; /* size read */ hid_t fcpl; /* file creation property list ID for HDF5 file */ @@ -1621,23 +1619,23 @@ void print_user_block(const char *filename, hid_t fid) /* get user block size */ if(( fcpl = H5Fget_create_plist(fid)) < 0) { error_msg("failed to retrieve file creation property list\n"); - goto done; - } + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Fget_create_plist failed"); + } if(H5Pget_userblock(fcpl, &ub_size) < 0) { error_msg("failed to retrieve userblock size\n"); - goto done; - } + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pget_userblock failed"); + } if(H5Pclose(fcpl) < 0) { error_msg("failed to close property list\n"); - goto done; - } + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); + } /* open file */ if((fh = HDopen(filename, O_RDONLY, 0)) < 0) { - goto done; - } + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "HDopen failed"); + } size = ub_size; @@ -1660,8 +1658,8 @@ void print_user_block(const char *filename, hid_t fid) printf("\n"); if(nread < 0) { - goto done; - } + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "nread < 0"); + } /* update size of userblock left to transfer */ size -= nread; |