summaryrefslogtreecommitdiffstats
path: root/tools/lib/h5tools.c
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2020-07-22 20:03:22 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2020-07-22 20:03:22 (GMT)
commit099c7242fbdf698cbb13339bfc71f38b8f363dfe (patch)
tree1ed51040cf41c16f2c55db79133ca86dfa0d3052 /tools/lib/h5tools.c
parent0ee5d676210291f784ce273ee34b1a7d383ec694 (diff)
downloadhdf5-099c7242fbdf698cbb13339bfc71f38b8f363dfe.zip
hdf5-099c7242fbdf698cbb13339bfc71f38b8f363dfe.tar.gz
hdf5-099c7242fbdf698cbb13339bfc71f38b8f363dfe.tar.bz2
Merge from dev of tools changes
Diffstat (limited to 'tools/lib/h5tools.c')
-rw-r--r--tools/lib/h5tools.c587
1 files changed, 410 insertions, 177 deletions
diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c
index 877f081..bbd30ac 100644
--- a/tools/lib/h5tools.c
+++ b/tools/lib/h5tools.c
@@ -29,59 +29,67 @@ int H5tools_INDENT_g = 0;
/* global variables */
-hid_t H5tools_ERR_STACK_g = 0;
+H5E_auto2_t lib_func;
+H5E_auto2_t tools_func;
+void *lib_edata;
+void *tools_edata;
+
+hid_t H5tools_ERR_STACK_g = H5I_INVALID_HID;
hid_t H5tools_ERR_CLS_g = H5I_INVALID_HID;
hid_t H5E_tools_g = H5I_INVALID_HID;
hid_t H5E_tools_min_id_g = H5I_INVALID_HID;
hid_t H5E_tools_min_info_id_g = H5I_INVALID_HID;
hid_t H5E_tools_min_dbg_id_g = H5I_INVALID_HID;
-int compound_data;
+
FILE *rawattrstream = NULL; /* should initialize to stdout but gcc moans about it */
FILE *rawdatastream = NULL; /* should initialize to stdout but gcc moans about it */
FILE *rawinstream = NULL; /* should initialize to stdin but gcc moans about it */
FILE *rawoutstream = NULL; /* should initialize to stdout but gcc moans about it */
FILE *rawerrorstream = NULL; /* should initialize to stderr but gcc moans about it */
+
int bin_output; /* binary output */
int bin_form = 0; /* binary form, default NATIVE */
int region_output; /* region output */
int oid_output; /* oid output */
int data_output; /* data output */
int attr_data_output; /* attribute data output */
+int compound_data;
+
unsigned packed_bits_num; /* number of packed bits to display */
unsigned packed_data_offset; /* offset of packed bits to display */
unsigned packed_data_length; /* length of packed bits to display */
unsigned long long packed_data_mask; /* mask in which packed bits to display */
+
int enable_error_stack = 0; /* re-enable error stack; disable=0 enable=1 */
/* sort parameters */
-H5_index_t sort_by = H5_INDEX_NAME; /*sort_by [creation_order | name] */
-H5_iter_order_t sort_order = H5_ITER_INC; /*sort_order [ascending | descending] */
+H5_index_t sort_by = H5_INDEX_NAME; /* sort_by [creation_order | name] */
+H5_iter_order_t sort_order = H5_ITER_INC; /* sort_order [ascending | descending] */
/* module-scoped variables */
static int h5tools_init_g; /* if h5tools lib has been initialized */
-/* Names of VFDs */
-static const char *drivernames[]={
+/* Names of VFDs. These names are always available so that
+ * the tools can emit special messages when a VFD is asked
+ * for by name but is not compiled into the library or is
+ * somehow otherwise not enabled.
+ *
+ */
+const char *drivernames[] = {
"sec2",
+ "direct",
+ "log",
+ "windows",
+ "stdio",
+ "core",
"family",
"split",
"multi",
-#ifdef H5_HAVE_PARALLEL
"mpio",
-#endif /* H5_HAVE_PARALLEL */
+ "ros3",
+ "hdfs",
};
-/* This enum should match the entries in the above drivers_list since they
- * are indexes into the drivers_list array. */
-typedef enum {
- SEC2_IDX = 0
- ,FAMILY_IDX
- ,SPLIT_IDX
- ,MULTI_IDX
-#ifdef H5_HAVE_PARALLEL
- ,MPIO_IDX
-#endif /* H5_HAVE_PARALLEL */
-} driver_idx;
#define NUM_DRIVERS (sizeof(drivernames) / sizeof(drivernames[0]))
/*-------------------------------------------------------------------------
@@ -97,6 +105,10 @@ typedef enum {
void
h5tools_init(void)
{
+ /* Disable error reporting */
+ H5Eget_auto2(H5E_DEFAULT, &lib_func, &lib_edata);
+ H5Eset_auto2(H5E_DEFAULT, NULL, NULL);
+
if (!h5tools_init_g) {
H5TOOLS_INIT_ERROR();
@@ -115,6 +127,29 @@ h5tools_init(void)
h5tools_init_g++;
}
+
+ /* Disable tools error reporting */
+ H5Eget_auto2(H5tools_ERR_STACK_g, &tools_func, &tools_edata);
+ H5Eset_auto2(H5tools_ERR_STACK_g, NULL, NULL);
+}
+
+/*-------------------------------------------------------------------------
+ * Function: h5tools_error_report
+ *
+ * Purpose: Enable error stack reporting after command line is parsed.
+ *
+ * Return: None
+ *-------------------------------------------------------------------------
+ */
+void
+h5tools_error_report(void)
+{
+ if (h5tools_init_g) {
+ if (enable_error_stack > 0) {
+ H5Eset_auto2(H5E_DEFAULT, lib_func, lib_edata);
+ H5Eset_auto2(H5tools_ERR_STACK_g, tools_func, tools_edata);
+ }
+ }
}
/*-------------------------------------------------------------------------
@@ -131,16 +166,14 @@ h5tools_init(void)
void
h5tools_close(void)
{
- H5E_auto2_t tools_func;
- void *tools_edata;
if (h5tools_init_g) {
/* special case where only data is output to stdout */
- if((rawoutstream == NULL) && rawdatastream && (rawdatastream == stdout))
+ if ((rawoutstream == NULL) && rawdatastream && (rawdatastream == stdout))
HDfprintf(rawdatastream, "\n");
- H5Eget_auto2(H5tools_ERR_STACK_g, &tools_func, &tools_edata);
- if(tools_func!=NULL)
+ if (tools_func)
H5Eprint2(H5tools_ERR_STACK_g, rawerrorstream);
+
if (rawattrstream && rawattrstream != stdout) {
if (fclose(rawattrstream))
perror("closing rawattrstream");
@@ -175,6 +208,10 @@ h5tools_close(void)
/* Clean up the reference path table, if it's been used */
term_ref_path_table();
+ /* Restore error stacks from init */
+ H5Eset_auto2(H5tools_ERR_STACK_g, tools_func, tools_edata);
+ H5Eset_auto2(H5E_DEFAULT, lib_func, lib_edata);
+
H5TOOLS_CLOSE_ERROR();
/* Shut down the library */
@@ -425,189 +462,337 @@ h5tools_set_error_file(const char *fname, int is_bin)
}
/*-------------------------------------------------------------------------
- * Function: h5tools_get_fapl
+ * Function: h5tools_set_fapl_vfd
*
- * Purpose: Get a FAPL for a given VFL driver name.
+ * Purpose: Given a VFL driver name, sets the appropriate driver on the
+ * specified FAPL.
*
* Return: positive - succeeded
* negative - failed
*-------------------------------------------------------------------------
*/
-static hid_t
-h5tools_get_fapl(hid_t fapl, const char *driver, unsigned *drivernum)
+static herr_t
+h5tools_set_fapl_vfd(hid_t fapl_id, h5tools_vfd_info_t *vfd_info)
{
- hid_t new_fapl = H5I_INVALID_HID; /* Copy of file access property list passed in, or new property list */
herr_t ret_value = SUCCEED;
- /* Make a copy of the FAPL, for the file open call to use, eventually */
- if (fapl == H5P_DEFAULT) {
- if ((new_fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
- H5TOOLS_GOTO_ERROR(FAIL, "H5Pcreate failed");
- } /* end if */
- else {
- if ((new_fapl = H5Pcopy(fapl)) < 0)
- H5TOOLS_GOTO_ERROR(FAIL, "H5Pcopy failed");
- } /* end else */
-
- /* Determine which driver the user wants to open the file with. Try
- * that driver. If it can't open it, then fail. */
- if (!HDstrcmp(driver, drivernames[SEC2_IDX])) {
- /* SEC2 driver */
- if (H5Pset_fapl_sec2(new_fapl) < 0)
+ /* Determine which driver the user wants to open the file with */
+ if (!HDstrcmp(vfd_info->name, drivernames[SEC2_VFD_IDX])) {
+ /* SEC2 Driver */
+ if (H5Pset_fapl_sec2(fapl_id) < 0)
H5TOOLS_GOTO_ERROR(FAIL, "H5Pset_fapl_sec2 failed");
+ }
+ else if (!HDstrcmp(vfd_info->name, drivernames[DIRECT_VFD_IDX])) {
+#ifdef H5_HAVE_DIRECT
+ /* Direct Driver */
+ if (H5Pset_fapl_direct(fapl_id, 1024, 4096, 8 * 4096) < 0)
+ H5TOOLS_GOTO_ERROR(FAIL, "H5Pset_fapl_direct failed");
+#else
+ H5TOOLS_GOTO_ERROR(FAIL, "Direct VFD is not enabled");
+#endif
+ }
+ else if (!HDstrcmp(vfd_info->name, drivernames[LOG_VFD_IDX])) {
+ unsigned long long log_flags = H5FD_LOG_LOC_IO | H5FD_LOG_ALLOC;
- if (drivernum)
- *drivernum = SEC2_IDX;
+ /* Log Driver */
+ if (H5Pset_fapl_log(fapl_id, NULL, log_flags, (size_t) 0) < 0)
+ H5TOOLS_GOTO_ERROR(FAIL, "H5Pset_fapl_log failed");
+ }
+ else if (!HDstrcmp(vfd_info->name, drivernames[WINDOWS_VFD_IDX])) {
+#ifdef H5_HAVE_WINDOWS
+ /* There is no Windows VFD - use SEC2 */
+ if (H5Pset_fapl_sec2(fapl_id) < 0)
+ H5TOOLS_GOTO_ERROR(FAIL, "H5Pset_fapl_sec2 failed");
+#else
+ H5TOOLS_GOTO_ERROR(FAIL, "Windows VFD is not enabled");
+#endif
+ }
+ else if (!HDstrcmp(vfd_info->name, drivernames[STDIO_VFD_IDX])) {
+ /* Stdio Driver */
+ if (H5Pset_fapl_stdio(fapl_id) < 0)
+ H5TOOLS_GOTO_ERROR(FAIL, "H5Pset_fapl_stdio failed");
+ }
+ else if (!HDstrcmp(vfd_info->name, drivernames[CORE_VFD_IDX])) {
+ /* Core Driver */
+ if (H5Pset_fapl_core(fapl_id, (size_t) H5_MB, TRUE) < 0)
+ H5TOOLS_GOTO_ERROR(FAIL, "H5Pset_fapl_core failed");
}
- else if (!HDstrcmp(driver, drivernames[FAMILY_IDX])) {
+ else if (!HDstrcmp(vfd_info->name, drivernames[FAMILY_VFD_IDX])) {
/* FAMILY Driver */
-
/* Set member size to be 0 to indicate the current first member size
* is the member size.
*/
- if (H5Pset_fapl_family(new_fapl, (hsize_t) 0, H5P_DEFAULT) < 0)
+ if (H5Pset_fapl_family(fapl_id, (hsize_t) 0, H5P_DEFAULT) < 0)
H5TOOLS_GOTO_ERROR(FAIL, "H5Pset_fapl_family failed");
-
- if (drivernum)
- *drivernum = FAMILY_IDX;
}
- else if (!HDstrcmp(driver, drivernames[SPLIT_IDX])) {
+ else if (!HDstrcmp(vfd_info->name, drivernames[SPLIT_VFD_IDX])) {
/* SPLIT Driver */
- if (H5Pset_fapl_split(new_fapl, "-m.h5", H5P_DEFAULT, "-r.h5", H5P_DEFAULT) < 0)
+ if (H5Pset_fapl_split(fapl_id, "-m.h5", H5P_DEFAULT, "-r.h5", H5P_DEFAULT) < 0)
H5TOOLS_GOTO_ERROR(FAIL, "H5Pset_fapl_split failed");
-
- if (drivernum)
- *drivernum = SPLIT_IDX;
}
- else if (!HDstrcmp(driver, drivernames[MULTI_IDX])) {
+ else if (!HDstrcmp(vfd_info->name, drivernames[MULTI_VFD_IDX])) {
/* MULTI Driver */
- if (H5Pset_fapl_multi(new_fapl, NULL, NULL, NULL, NULL, TRUE) < 0)
+ if (H5Pset_fapl_multi(fapl_id, NULL, NULL, NULL, NULL, TRUE) < 0)
H5TOOLS_GOTO_ERROR(FAIL, "H5Pset_fapl_multi failed");
-
- if(drivernum)
- *drivernum = MULTI_IDX;
}
+ else if (!HDstrcmp(vfd_info->name, drivernames[MPIO_VFD_IDX])) {
#ifdef H5_HAVE_PARALLEL
- else if(!HDstrcmp(driver, drivernames[MPIO_IDX])) {
int mpi_initialized, mpi_finalized;
/* MPI-I/O Driver */
+
/* check if MPI is available. */
MPI_Initialized(&mpi_initialized);
MPI_Finalized(&mpi_finalized);
- if(mpi_initialized && !mpi_finalized) {
- if(H5Pset_fapl_mpio(new_fapl, MPI_COMM_WORLD, MPI_INFO_NULL) < 0)
+ if (mpi_initialized && !mpi_finalized) {
+ if (H5Pset_fapl_mpio(fapl_id, MPI_COMM_WORLD, MPI_INFO_NULL) < 0)
H5TOOLS_GOTO_ERROR(FAIL, "H5Pset_fapl_mpio failed");
- if(drivernum)
- *drivernum = MPIO_IDX;
- } /* end if */
- }
+ }
+#else
+ H5TOOLS_GOTO_ERROR(FAIL, "MPI-I/O VFD is not enabled");
#endif /* H5_HAVE_PARALLEL */
+ }
+ else if (!HDstrcmp(vfd_info->name, drivernames[ROS3_VFD_IDX])) {
+#ifdef H5_HAVE_ROS3_VFD
+ if (!vfd_info->info)
+ H5TOOLS_GOTO_ERROR(FAIL, "Read-only S3 VFD info is invalid");
+ if (H5Pset_fapl_ros3(fapl_id, (H5FD_ros3_fapl_t *)vfd_info->info) < 0)
+ H5TOOLS_GOTO_ERROR(FAIL, "H5Pset_fapl_ros3() failed");
+#else
+ H5TOOLS_GOTO_ERROR(FAIL, "Read-only S3 VFD is not enabled");
+#endif
+ }
+ else if (!HDstrcmp(vfd_info->name, drivernames[HDFS_VFD_IDX])) {
+#ifdef H5_HAVE_LIBHDFS
+ if (!vfd_info->info)
+ H5TOOLS_GOTO_ERROR(FAIL, "HDFS VFD info is invalid");
+ if (H5Pset_fapl_hdfs(fapl_id, (H5FD_hdfs_fapl_t *)vfd_info->info) < 0)
+ H5TOOLS_GOTO_ERROR(FAIL, "H5Pset_fapl_hdfs() failed");
+#else
+ H5TOOLS_GOTO_ERROR(FAIL, "The HDFS VFD is not enabled");
+#endif
+ }
else
- ret_value = -1;
+ H5TOOLS_GOTO_ERROR(FAIL, "invalid VFD name");
done:
- if((new_fapl != H5P_DEFAULT) && (ret_value < 0)) {
- H5Pclose(new_fapl);
- new_fapl = H5I_INVALID_HID;
+ return ret_value;
+}
+
+/*-------------------------------------------------------------------------
+ * Function: h5tools_get_fapl
+ *
+ * Purpose: Copies an input fapl and then sets a VFD on it.
+ *
+ * The returned fapl must be closed by the caller.
+ *
+ * Return: positive - succeeded
+ * negative - failed
+ *-------------------------------------------------------------------------
+ */
+hid_t
+h5tools_get_fapl(hid_t prev_fapl_id, h5tools_vfd_info_t *vfd_info)
+{
+ hid_t new_fapl_id = H5I_INVALID_HID;
+ hid_t ret_value = H5I_INVALID_HID;
+
+ if (prev_fapl_id < 0)
+ H5TOOLS_GOTO_ERROR(FAIL, "invalid FAPL");
+
+ /* Make a copy of the FAPL or create one if H5P_DEFAULT is specified. */
+ if (H5P_DEFAULT == prev_fapl_id) {
+ if ((new_fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0)
+ H5TOOLS_GOTO_ERROR(H5I_INVALID_HID, "H5Pcreate failed");
+ }
+ else {
+ if ((new_fapl_id = H5Pcopy(prev_fapl_id)) < 0)
+ H5TOOLS_GOTO_ERROR(H5I_INVALID_HID, "H5Pcopy failed");
+ }
+
+ /* Set non-default virtual file driver, if requested */
+ if (vfd_info)
+ if (h5tools_set_fapl_vfd(new_fapl_id, vfd_info) < 0)
+ H5TOOLS_GOTO_ERROR(H5I_INVALID_HID, "failed to set VFD on FAPL");
+
+ ret_value = new_fapl_id;
+
+done:
+ if ((new_fapl_id >= 0) && (ret_value < 0)) {
+ H5Pclose(new_fapl_id);
+ new_fapl_id = H5I_INVALID_HID;
+ }
+
+ return ret_value;
+}
+
+/*-------------------------------------------------------------------------
+ * Function: h5tools_get_vfd_name
+ *
+ * Purpose: Given a FAPL, retrieves the name of the VFL driver set on it
+ * if using a native-terminal VOL connector. If a
+ * non-native-terminal VOL connector is set on the FAPL, the
+ * first byte of the returned driver name will be set to the null
+ * terminator.
+ *
+ * Return: SUCCEED/FAIL
+ *-------------------------------------------------------------------------
+ */
+herr_t
+h5tools_get_vfd_name(hid_t fapl_id, char *drivername, size_t drivername_size)
+{
+ hid_t fapl_vol_id = H5I_INVALID_HID;
+ herr_t ret_value = SUCCEED;
+
+ if (fapl_id < 0)
+ H5TOOLS_GOTO_ERROR(FAIL, "invalid FAPL");
+ if (!drivername)
+ H5TOOLS_GOTO_ERROR(FAIL, "drivername is NULL");
+ if (drivername && !drivername_size)
+ H5TOOLS_GOTO_ERROR(FAIL, "drivername_size must be non-zero");
+
+ /* Initialize the driver name */
+ drivername[0] = '\0';
+
+ if (fapl_id == H5P_DEFAULT)
+ fapl_id = H5P_FILE_ACCESS_DEFAULT;
+
+ if (fapl_id >= 0) {
+ const char *driver_name;
+ hid_t driver_id;
+
+ if ((driver_id = H5Pget_driver(fapl_id)) < 0)
+ H5TOOLS_GOTO_ERROR(FAIL, "failed to retrieve VFL driver ID from FAPL");
+
+ if (driver_id == H5FD_SEC2)
+ driver_name = drivernames[SEC2_VFD_IDX];
+#ifdef H5_HAVE_DIRECT
+ else if (driver_id == H5FD_DIRECT)
+ driver_name = drivernames[DIRECT_VFD_IDX];
+#endif
+ else if (driver_id == H5FD_LOG)
+ driver_name = drivernames[LOG_VFD_IDX];
+#ifdef H5_HAVE_WINDOWS
+ else if (driver_id == H5FD_WINDOWS)
+ driver_name = drivernames[WINDOWS_VFD_IDX];
+#endif
+ else if (driver_id == H5FD_STDIO)
+ driver_name = drivernames[STDIO_VFD_IDX];
+ else if (driver_id == H5FD_CORE)
+ driver_name = drivernames[CORE_VFD_IDX];
+ else if (driver_id == H5FD_FAMILY)
+ driver_name = drivernames[FAMILY_VFD_IDX];
+ else if (driver_id == H5FD_MULTI)
+ driver_name = drivernames[MULTI_VFD_IDX];
+#ifdef H5_HAVE_PARALLEL
+ else if (driver_id == H5FD_MPIO)
+ driver_name = drivernames[MPIO_VFD_IDX];
+#endif
+#ifdef H5_HAVE_ROS3_VFD
+ else if (driver_id == H5FD_ROS3)
+ driver_name = drivernames[ROS3_VFD_IDX];
+#endif
+#ifdef H5_HAVE_LIBHDFS
+ else if (driver_id == H5FD_HDFS)
+ driver_name = drivernames[HDFS_VFD_IDX];
+#endif
+ else
+ driver_name = "unknown";
+
+ HDstrncpy(drivername, driver_name, drivername_size);
+ drivername[drivername_size - 1] = '\0';
}
- return(new_fapl);
+done:
+
+ return ret_value;
}
/*-------------------------------------------------------------------------
* Function: h5tools_fopen
*
- * Purpose: Loop through the various types of VFL drivers trying to open FNAME.
- * If the HDF5 library is version 1.2 or less, then we have only the SEC2
- * driver to try out. If the HDF5 library is greater than version 1.2,
- * then we have the FAMILY, SPLIT, and MULTI drivers to play with.
+ * Purpose: Opens file FNAME using the specified flags and FAPL.
*
- * If DRIVER is non-NULL, then it will try to open the file with that
- * driver first. We assume that the user knows what they are doing so, if
- * we fail, then we won't try other file drivers.
+ * The 'use_specific_driver' parameter is used to control the
+ * VFD connector that this routine uses to open the file
+ * with. If 'use_specific_driver' is set to TRUE, this routine
+ * assumes that the caller has already set a specific VFD
+ * connector on the given FAPL and will attempt to directly use
+ * the FAPL for opening the file. We assume that the caller knows
+ * what they are doing; if the file is unable to be opened using
+ * that FAPL, this routine will return H5I_INVALID_HID.
+ *
+ * However, if 'use_specific_driver' is set to FALSE, this
+ * routine assumes that the caller HAS NOT set a specific VFD
+ * connector on the given FAPL and will instead loop through
+ * the various available VFL drivers and VOL connectors trying to
+ * open FNAME.
+ *
+ * The list of available VFL drivers is as follows:
+ * - If the HDF5 library is version 1.2 or less, then we have
+ * only the SEC2 driver to try out.
+ * - If the HDF5 library is greater than version 1.2, then we
+ * have the FAMILY, SPLIT, and MULTI drivers to play with.
*
* Return:
- * On success, returns a file id for the opened file. If DRIVERNAME is
+ * On success, returns a file ID for the opened file. If DRIVERNAME is
* non-null then the first DRIVERNAME_SIZE-1 characters of the driver
* name are copied into the DRIVERNAME array and null terminated.
*
- * Otherwise, the function returns FAIL. If DRIVERNAME is non-null then
- * the first byte is set to the null terminator.
+ * On failure, the function returns H5I_INVALID_HID and DRIVERNAME
+ * will not be set.
*-------------------------------------------------------------------------
*/
hid_t
-h5tools_fopen(const char *fname, unsigned flags, hid_t fapl, const char *driver,
+h5tools_fopen(const char *fname, unsigned flags, hid_t fapl_id, hbool_t use_specific_driver,
char *drivername, size_t drivername_size)
{
- unsigned drivernum;
- hid_t fid = FAIL;
- hid_t my_fapl = H5P_DEFAULT;
-
- if (driver && *driver) {
- /* Get the correct FAPL for the given driver */
- if ((my_fapl = h5tools_get_fapl(fapl, driver, &drivernum)) < 0)
- goto done;
-
- /* allow error stack display if enable-error-stack has optional arg number */
- if (enable_error_stack > 1) {
- fid = H5Fopen(fname, flags, my_fapl);
- }
- else {
- H5E_BEGIN_TRY {
- fid = H5Fopen(fname, flags, my_fapl);
- } H5E_END_TRY;
- }
+ hid_t fid = H5I_INVALID_HID;
+ hid_t tmp_fapl_id = H5I_INVALID_HID;
+ hid_t used_fapl_id = H5I_INVALID_HID;
+ hid_t ret_value = H5I_INVALID_HID;
- if (fid == FAIL)
- goto done;
+ /*
+ * First try to open the file using just the given FAPL.
+ */
+ /* Allow error stack display if --enable-error-stack has optional arg number */
+ if (enable_error_stack > 1) {
+ fid = H5Fopen(fname, flags, fapl_id);
}
else {
- /* Try to open the file using each of the drivers */
- for (drivernum = 0; drivernum < NUM_DRIVERS; drivernum++) {
- /* Get the correct FAPL for the given driver */
- if((my_fapl = h5tools_get_fapl(fapl, drivernames[drivernum], NULL)) < 0)
- goto done;
-
- /* allow error stack display if enable-error-stack has optional arg number */
- if (enable_error_stack > 1) {
- fid = H5Fopen(fname, flags, my_fapl);
- }
- else {
- H5E_BEGIN_TRY {
- fid = H5Fopen(fname, flags, my_fapl);
- } H5E_END_TRY;
- }
-
- if (fid != FAIL)
- break;
- else {
- /* Close the FAPL */
- H5Pclose(my_fapl);
- my_fapl = H5P_DEFAULT;
- } /* end else */
- }
+ H5E_BEGIN_TRY {
+ fid = H5Fopen(fname, flags, fapl_id);
+ } H5E_END_TRY;
}
- /* Save the driver name */
- if (drivername && drivername_size) {
- if (fid != FAIL) {
- HDstrncpy(drivername, drivernames[drivernum], drivername_size);
- drivername[drivername_size - 1] = '\0';
- }
- else {
- /*no file opened*/
- drivername[0] = '\0';
- }
+ /* If we succeeded in opening the file, we're done. */
+ if (fid >= 0) {
+ used_fapl_id = fapl_id;
+ H5TOOLS_GOTO_DONE(fid);
}
+ /*
+ * If we failed to open the file and the caller specified 'use_specific_driver'
+ * as TRUE, we should return failure now since the file couldn't be opened with
+ * the VFL driver that was set on the FAPL by the caller.
+ */
+ if (fid < 0 && use_specific_driver)
+ H5TOOLS_GOTO_ERROR(H5I_INVALID_HID, "failed to open file using specified FAPL");
+
+ /* File was unable to be opened at all */
+ ret_value = H5I_INVALID_HID;
+
done:
- if(my_fapl != H5P_DEFAULT)
- H5Pclose(my_fapl);
+ /* Save the driver name */
+ if (drivername && drivername_size && ret_value >= 0)
+ if (used_fapl_id >= 0 && h5tools_get_vfd_name(used_fapl_id, drivername, drivername_size) < 0)
+ H5TOOLS_ERROR(H5I_INVALID_HID, "failed to retrieve name of VFD used to open file");
+
+ if (tmp_fapl_id >= 0)
+ H5Pclose(tmp_fapl_id);
- return fid;
+ return ret_value;
}
/*-------------------------------------------------------------------------
@@ -733,8 +918,8 @@ done:
*-------------------------------------------------------------------------
*/
void
-h5tools_simple_prefix(FILE *stream, const h5tool_format_t *info,
- h5tools_context_t *ctx, hsize_t elmtno, int secnum)
+h5tools_simple_prefix(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx,
+ hsize_t elmtno, int secnum)
{
h5tools_str_t prefix;
h5tools_str_t str; /*temporary for indentation */
@@ -762,7 +947,7 @@ h5tools_simple_prefix(FILE *stream, const h5tool_format_t *info,
H5TOOLS_DEBUG("after CR elmtno=%ld, ctx->ndims=%d", elmtno, ctx->ndims);
/* Calculate new prefix */
- h5tools_str_prefix(&prefix, info, elmtno, ctx->ndims, ctx);
+ h5tools_str_prefix(&prefix, info, elmtno, ctx);
H5TOOLS_DEBUG("prefix=%s - str=%s", prefix.s, str.s);
/* Write new prefix to output */
@@ -829,8 +1014,8 @@ h5tools_simple_prefix(FILE *stream, const h5tool_format_t *info,
*-------------------------------------------------------------------------
*/
void
-h5tools_region_simple_prefix(FILE *stream, const h5tool_format_t *info,
- h5tools_context_t *ctx, hsize_t elmtno, hsize_t *ptdata, int secnum)
+h5tools_region_simple_prefix(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx,
+ hsize_t elmtno, hsize_t *ptdata, int secnum)
{
h5tools_str_t prefix;
h5tools_str_t str; /*temporary for indentation */
@@ -854,7 +1039,7 @@ h5tools_region_simple_prefix(FILE *stream, const h5tool_format_t *info,
}
/* Calculate new prefix */
- h5tools_str_region_prefix(&prefix, info, elmtno, ptdata, ctx->ndims, ctx->p_max_idx, ctx);
+ h5tools_str_region_prefix(&prefix, info, elmtno, ptdata, ctx);
/* Write new prefix to output */
if (ctx->indent_level > 0)
@@ -927,9 +1112,8 @@ h5tools_region_simple_prefix(FILE *stream, const h5tool_format_t *info,
*-------------------------------------------------------------------------
*/
hbool_t
-h5tools_render_element(FILE *stream, const h5tool_format_t *info,
- h5tools_context_t *ctx, h5tools_str_t *buffer, hsize_t *curr_pos,
- size_t ncols, hsize_t local_elmt_counter, hsize_t elmt_counter)
+h5tools_render_element(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx,
+ h5tools_str_t *buffer, hsize_t *curr_pos, size_t ncols, hsize_t local_elmt_counter, hsize_t elmt_counter)
{
hbool_t dimension_break = TRUE;
char *s = NULL;
@@ -1098,9 +1282,8 @@ h5tools_render_element(FILE *stream, const h5tool_format_t *info,
*-------------------------------------------------------------------------
*/
hbool_t
-h5tools_render_region_element(FILE *stream, const h5tool_format_t *info,
- h5tools_context_t *ctx, h5tools_str_t *buffer, hsize_t *curr_pos,
- size_t ncols, hsize_t *ptdata, hsize_t local_elmt_counter, hsize_t elmt_counter)
+h5tools_render_region_element(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx,
+ h5tools_str_t *buffer, hsize_t *curr_pos, size_t ncols, hsize_t *ptdata, hsize_t local_elmt_counter, hsize_t elmt_counter)
{
hbool_t dimension_break = TRUE;
char *s = NULL;
@@ -1117,8 +1300,10 @@ h5tools_render_region_element(FILE *stream, const h5tool_format_t *info,
* If the element would split on multiple lines if printed at our
* current location...
*/
- if (info->line_multi_new == 1 && (ctx->cur_column + h5tools_count_ncols(s) +
- HDstrlen(OPT(info->elmt_suf2, " ")) + HDstrlen(OPT(info->line_suf, ""))) > ncols) {
+ if (info->line_multi_new == 1 &&
+ (ctx->cur_column + h5tools_count_ncols(s) +
+ HDstrlen(OPT(info->elmt_suf2, " ")) +
+ HDstrlen(OPT(info->line_suf, ""))) > ncols) {
if (ctx->prev_multiline) {
/*
* ... and the previous element also occupied more than one
@@ -1127,7 +1312,8 @@ h5tools_render_region_element(FILE *stream, const h5tool_format_t *info,
ctx->need_prefix = TRUE;
}
else if ((ctx->prev_prefix_len + h5tools_count_ncols(s) +
- HDstrlen(OPT(info->elmt_suf2, " ")) + HDstrlen(OPT(info->line_suf, ""))) <= ncols) {
+ HDstrlen(OPT(info->elmt_suf2, " ")) +
+ HDstrlen(OPT(info->line_suf, ""))) <= ncols) {
/*
* ...but *could* fit on one line otherwise, then we
* should end the current line and start this element on its
@@ -1158,7 +1344,9 @@ h5tools_render_region_element(FILE *stream, const h5tool_format_t *info,
* beginning of the line.
*/
if (info->line_multi_new == 1 && ctx->prev_multiline &&
- (ctx->cur_column + h5tools_count_ncols(s) + HDstrlen(OPT(info->elmt_suf2, " ")) + HDstrlen(OPT(info->line_suf, ""))) > ncols)
+ (ctx->cur_column + h5tools_count_ncols(s) +
+ HDstrlen(OPT(info->elmt_suf2, " ")) +
+ HDstrlen(OPT(info->line_suf, ""))) > ncols)
ctx->need_prefix = TRUE;
/*
@@ -1186,7 +1374,9 @@ h5tools_render_region_element(FILE *stream, const h5tool_format_t *info,
* this check to happen for the first line
*/
if ((!info->skip_first || local_elmt_counter) &&
- (ctx->cur_column + HDstrlen(section) + HDstrlen(OPT(info->elmt_suf2, " ")) + HDstrlen(OPT(info->line_suf, ""))) > ncols)
+ (ctx->cur_column + HDstrlen(section) +
+ HDstrlen(OPT(info->elmt_suf2, " ")) +
+ HDstrlen(OPT(info->line_suf, ""))) > ncols)
ctx->need_prefix = 1;
/*
@@ -1232,27 +1422,65 @@ h5tools_render_region_element(FILE *stream, const h5tool_format_t *info,
*-------------------------------------------------------------------------
*/
void
-init_acc_pos(h5tools_context_t *ctx, hsize_t *dims)
+init_acc_pos(unsigned ndims, hsize_t *dims, hsize_t *acc, hsize_t *pos, hsize_t *p_min_idx)
{
int i;
unsigned j;
H5TOOLS_START_DEBUG("");
- if(ctx->ndims > 0) {
- ctx->acc[ctx->ndims - 1] = 1;
- for (i = ((int)ctx->ndims - 2); i >= 0; i--) {
- ctx->acc[i] = ctx->acc[i + 1] * dims[i + 1];
- H5TOOLS_DEBUG("ctx->acc[%d]=%ld", i, ctx->acc[i]);
+ for (i = 0; (unsigned)i < ndims; i++)
+ p_min_idx[i] = 0;
+
+ if(ndims > 0) {
+ acc[ndims - 1] = 1;
+ for (i = ((int)ndims - 2); i >= 0; i--) {
+ acc[i] = acc[i + 1] * dims[i + 1];
+ H5TOOLS_DEBUG("acc[%d]=%ld", i, acc[i]);
}
- for (j = 0; j < ctx->ndims; j++)
- ctx->pos[j] = 0;
+ for (j = 0; j < ndims; j++)
+ pos[j] = 0;
}
H5TOOLS_ENDDEBUG("");
}
/*-------------------------------------------------------------------------
+ * Function: calc_acc_pos
+ *
+ * Purpose: Calculate the number of elements represented by a unit change
+ * in a certain index position.
+ *
+ * Return: void
+ *-------------------------------------------------------------------------
+ */
+hsize_t
+calc_acc_pos(unsigned ndims, hsize_t elmtno, hsize_t *acc, hsize_t *pos)
+{
+ int i;
+ hsize_t curr_pos = elmtno;
+
+ H5TOOLS_START_DEBUG("");
+
+ if(ndims > 0) {
+ for(i = 0; i < (size_t) ndims; i++) {
+ if(curr_pos > 0) {
+ H5TOOLS_DEBUG("curr_pos=%ld - ctx->acc[%d]=%ld", curr_pos, i, acc[i]);
+ pos[i] = curr_pos / acc[i];
+ curr_pos -= acc[i] * pos[i];
+ }
+ else
+ pos[i] = 0;
+ H5TOOLS_DEBUG("curr_pos=%ld - pos[%d]=%ld - acc[%d]=%ld", curr_pos, i, pos[i], i, acc[i]);
+ }
+ }
+
+ H5TOOLS_ENDDEBUG("");
+
+ return curr_pos;
+}
+
+/*-------------------------------------------------------------------------
* Function: render_bin_output
*
* Purpose: Write one element of memory buffer to a binary file stream
@@ -1437,19 +1665,24 @@ render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t
for (block_index = 0; block_index < block_nelmts; block_index++) {
mem = ((unsigned char*)_mem) + block_index * size;
- region_id = H5Rdereference2(container, H5P_DEFAULT, H5R_DATASET_REGION, mem);
- if (region_id >= 0) {
- region_space = H5Rget_region(container, H5R_DATASET_REGION, mem);
- if (region_space >= 0) {
- region_type = H5Sget_select_type(region_space);
- if(region_type == H5S_SEL_POINTS)
- render_bin_output_region_points(region_space, region_id, stream, container);
- else
- render_bin_output_region_blocks(region_space, region_id, stream, container);
+ if((region_id = H5Rdereference2(container, H5P_DEFAULT, H5R_DATASET_REGION, mem)) < 0)
+ H5TOOLS_INFO("H5Ropen_object H5T_STD_REF failed");
+ else {
+ if((region_space = H5Rget_region(container, H5R_DATASET_REGION, mem)) >= 0) {
+ if (!h5tools_is_zero(mem, H5R_DSET_REG_REF_BUF_SIZE)) {
+ region_type = H5Sget_select_type(region_space);
+ if(region_type == H5S_SEL_POINTS)
+ render_bin_output_region_points(region_space, region_id, stream, container);
+ else
+ render_bin_output_region_blocks(region_space, region_id, stream, container);
+ }
+ else {
+ H5TOOLS_INFO("H5Ropen_object H5T_STD_REF NULL");
+ }
H5Sclose(region_space);
} /* end if (region_space >= 0) */
H5Dclose(region_id);
- } /* end if (region_id >= 0) */
+ }
}
} /* end if (region_output... */
}