summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlbert Cheng <acheng@hdfgroup.org>2000-11-02 04:59:51 (GMT)
committerAlbert Cheng <acheng@hdfgroup.org>2000-11-02 04:59:51 (GMT)
commit48b4b454816677b3b79d03bb4d4dc7b1eef90e30 (patch)
tree5335b3f7ab3b8c2d8beb914cc4cd7030c6065696
parent180a47a037320fc8fcf48cf3114e1f548d019659 (diff)
downloadhdf5-48b4b454816677b3b79d03bb4d4dc7b1eef90e30.zip
hdf5-48b4b454816677b3b79d03bb4d4dc7b1eef90e30.tar.gz
hdf5-48b4b454816677b3b79d03bb4d4dc7b1eef90e30.tar.bz2
[svn-r2790] Purpose:
new feature Description: h5tools.c: Created h5tools_init() and h5tools_close() for the initialization of the h5tools library and closing of it. With this, the rawdatastream and other internal structures can be initialized properly. h5tools.h: added prototypes for h5tools_init and h5tools_close. h5dump.c: h5ls.c: Added the calls for h5tools_init() and h5tools_close(). Platforms tested: IRIX64 -64 parallel and Linux
-rw-r--r--tools/h5dump.c22
-rw-r--r--tools/h5ls.c4
-rw-r--r--tools/h5tools.c61
-rw-r--r--tools/h5tools.h2
4 files changed, 74 insertions, 15 deletions
diff --git a/tools/h5dump.c b/tools/h5dump.c
index 882cc85..6272ca4 100644
--- a/tools/h5dump.c
+++ b/tools/h5dump.c
@@ -215,7 +215,7 @@ usage(void)
Usage of HDF5 Dumper:\n\
\n\
h5dump [-h] [-bb] [-header] [-v] [-V] [-a <names>] [-d <names>] [-g <names>]\n\
- [-l <names>] [-t <names>] [-w <number>] <file>\n\
+ [-l <names>] [-o <fname>] [-t <names>] [-w <number>] <file>\n\
\n\
-h Print information on this command and exit.\n\
-bb Display the conent of the boot block. [Default: don't display]\n\
@@ -1295,10 +1295,10 @@ dump_data(hid_t obj_id, int obj_data)
* Function: set_output_file
*
* Purpose: Open fname as the output file for dataset raw data.
- * Set rawdatastream as its file stream.
+ * Set rawdatastream as its file stream.
*
* Return: 0 -- succeeded
- * negative -- failed
+ * negative -- failed
*
* Programmer: Albert Cheng, 2000/09/30
*
@@ -1359,6 +1359,9 @@ main(int argc, char *argv[])
H5Eget_auto(&func, &edata);
H5Eset_auto(NULL, NULL);
+ /* Initialize h5tools lib */
+ h5tools_init();
+
opts = malloc((argc / 2) * sizeof(int));
opts[0] = -1;
@@ -1712,23 +1715,20 @@ main(int argc, char *argv[])
end_obj(dump_header_format->fileend, dump_header_format->fileblockend);
done:
- H5Eset_auto(func, edata);
- free(opts);
-
if (H5Fclose(fid) < 0)
d_status = 1;
- if (rawdatastream && rawdatastream != stdout)
- if (fclose(rawdatastream))
- perror("fclose");
-
-
free(group_table->objs);
free(dset_table->objs);
free(type_table->objs);
free(prefix);
free(info->prefix);
free(info);
+ free(opts);
+
+ h5tools_close();
+ H5Eset_auto(func, edata);
+
return d_status;
}
diff --git a/tools/h5ls.c b/tools/h5ls.c
index e6fc2f0..f7af540 100644
--- a/tools/h5ls.c
+++ b/tools/h5ls.c
@@ -1923,6 +1923,9 @@ main (int argc, char *argv[])
static char root_name[] = "/";
char drivername[50];
+ /* Initialize h5tools lib */
+ h5tools_init();
+
/* Build display table */
DISPATCH(H5G_DATASET, "Dataset", H5Dopen, H5Dclose,
dataset_list1, dataset_list2);
@@ -2154,6 +2157,7 @@ main (int argc, char *argv[])
}
H5Fclose(file);
}
+ h5tools_close();
return 0;
}
diff --git a/tools/h5tools.c b/tools/h5tools.c
index 52851ca..78a8258 100644
--- a/tools/h5tools.c
+++ b/tools/h5tools.c
@@ -26,6 +26,8 @@ int compound_data;
int nCols = 80;
FILE *rawdatastream; /* should initialize to stdout but gcc moans about it */
+static int h5tools_init_g = 0; /* if h5tools lib has been initialized */
+
int print_data(hid_t oid, hid_t _p_type, int obj_data);
/*
@@ -107,6 +109,61 @@ extern char *get_objectname(table_t*, int);
static int h5dump_vlen_dset(FILE *, const h5dump_t *, hid_t, hid_t, int);
/*-------------------------------------------------------------------------
+ * Function: h5tools_init
+ *
+ * Purpose: Initialize the H5 Tools library.
+ * This should be called before any other h5tools function is
+ * called. Effect of any h5tools function called before this
+ * has been called is undetermined.
+ *
+ * Return: None
+ *
+ * Programmer: Albert Cheng, 2000-10-31
+ *
+ * Modifications:
+ *-------------------------------------------------------------------------
+ */
+void
+h5tools_init(void)
+{
+ if (!h5tools_init_g){
+ if (!rawdatastream)
+ rawdatastream = stdout;
+ h5tools_init_g++;
+ }
+}
+
+/*-------------------------------------------------------------------------
+ * Function: h5tools_close
+ *
+ * Purpose: Close the H5 Tools library by closing or releasing resources
+ * such as files opened by the library.
+ * This should be called after all other h5tools functions have
+ * been called. Effect of any h5tools function called after this
+ * has been called is undetermined.
+ *
+ * Return: None
+ *
+ * Programmer: Albert Cheng, 2000-10-31
+ *
+ * Modifications:
+ *-------------------------------------------------------------------------
+ */
+void
+h5tools_close(void)
+{
+ if (h5tools_init_g){
+ if (rawdatastream && rawdatastream != stdout){
+ if (fclose(rawdatastream))
+ perror("closing rawdatastream");
+ else
+ rawdatastream = NULL;
+ }
+ h5tools_init_g = 0;
+ }
+}
+
+/*-------------------------------------------------------------------------
* Function: h5dump_str_close
*
* Purpose: Closes a string by releasing it's memory and setting the size
@@ -1814,10 +1871,6 @@ h5dump_dset(FILE *stream, const h5dump_t *info, hid_t dset, hid_t _p_type,
f_space = H5Dget_space(dset);
/* Print the data */
- /* a kludge because gcc does not accept the initialization with sdtout */
- if (!rawdatastream)
- rawdatastream = stdout;
-
if (H5Sis_simple(f_space) > 0) {
/* Probably a compound datatype or something... */
if (H5Tget_class(p_type) == H5T_VLEN) {
diff --git a/tools/h5tools.h b/tools/h5tools.h
index ffd7221..c34547b 100644
--- a/tools/h5tools.h
+++ b/tools/h5tools.h
@@ -436,4 +436,6 @@ extern FILE *rawdatastream; /* output stream for raw data */
/* Definitions of useful routines */
void print_version(const char *program_name);
+void h5tools_init(void);
+void h5tools_close(void);