summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2013-07-30 17:04:23 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2013-07-30 17:04:23 (GMT)
commitad7624ada3acaa03d1a588383250465f61e4838f (patch)
tree45ccc44553df4c00e6036f85a13c2738e643226f /tools
parentf26b04712eec8481b436050cc479fa7f57bb8a67 (diff)
downloadhdf5-ad7624ada3acaa03d1a588383250465f61e4838f.zip
hdf5-ad7624ada3acaa03d1a588383250465f61e4838f.tar.gz
hdf5-ad7624ada3acaa03d1a588383250465f61e4838f.tar.bz2
[svn-r23944] Move stream functions into tools lib.
Tested: local linux
Diffstat (limited to 'tools')
-rw-r--r--tools/h5dump/h5dump.c176
-rw-r--r--tools/lib/h5tools.c224
-rw-r--r--tools/lib/h5tools.h8
3 files changed, 230 insertions, 178 deletions
diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c
index 9b304bd..8e60bf7 100644
--- a/tools/h5dump/h5dump.c
+++ b/tools/h5dump/h5dump.c
@@ -481,172 +481,6 @@ table_list_free(void)
} /* end table_list_free() */
/*-------------------------------------------------------------------------
- * Function: set_data_output_file
- *
- * Purpose: Open fname as the output file for dataset raw data.
- * Set rawdatastream as its file stream.
- *
- * Return: 0 -- succeeded
- * negative -- failed
- *
- * Programmer: Albert Cheng, 2000/09/30
- *
- * Modifications:
- * pvn June, 1, 2006. Add a switch for binary output
- *
- *-------------------------------------------------------------------------
- */
-static int
-set_data_output_file(const char *fname, int is_bin)
-{
- int retvalue = FAIL;
- FILE *f; /* temporary holding place for the stream pointer
- * so that rawdatastream is changed only when succeeded */
-
- if (rawdatastream && rawdatastream != stdout) {
- if (HDfclose(rawdatastream))
- HDperror("closing rawdatastream");
- else
- rawdatastream = NULL;
- }
-
- /* First check if filename is string "NULL" */
- if (fname != NULL) {
- /* binary output */
- if (is_bin) {
- if ((f = HDfopen(fname, "wb")) != NULL) {
- rawdatastream = f;
- retvalue = SUCCEED;
- }
- }
- else {
- if ((f = HDfopen(fname, "w")) != NULL) {
- rawdatastream = f;
- retvalue = SUCCEED;
- }
- }
- }
- else {
- rawdatastream = NULL;
- retvalue = SUCCEED;
- }
-
- return retvalue;
-}
-
-/*-------------------------------------------------------------------------
- * Function: set_attr_output_file
- *
- * Purpose: Open fname as the output file for attribute raw data.
- * Set rawattrstream as its file stream.
- *
- * Return: 0 -- succeeded
- * negative -- failed
- *
- *-------------------------------------------------------------------------
- */
-static int
-set_attr_output_file(const char *fname, int is_bin)
-{
- int retvalue = FAIL;
- FILE *f; /* temporary holding place for the stream pointer
- * so that rawattrstream is changed only when succeeded */
-
- if (rawattrstream && rawattrstream != stdout) {
- if (HDfclose(rawattrstream))
- HDperror("closing rawattrstream");
- else
- rawattrstream = NULL;
- }
-
- /* First check if filename is string "NULL" */
- if (fname != NULL) {
- if ((f = HDfopen(fname, "w")) != NULL) {
- rawattrstream = f;
- retvalue = SUCCEED;
- }
- }
- else {
- rawattrstream = NULL;
- retvalue = SUCCEED;
- }
-
- return retvalue;
-}
-
-/*-------------------------------------------------------------------------
- * Function: set_output_file
- *
- * Purpose: Open fname as the output file for raw output.
- * Set rawoutstream as its file stream.
- *
- * Return: 0 -- succeeded
- * negative -- failed
- *
- *-------------------------------------------------------------------------
- */
-static int
-set_output_file(const char *fname)
-{
- int retvalue = FAIL;
- FILE *f; /* temporary holding place for the stream pointer
- * so that rawoutstream is changed only when succeeded */
-
- if (rawoutstream && rawoutstream != stdout) {
- if (HDfclose(rawoutstream))
- HDperror("closing rawoutstream");
- else
- rawoutstream = NULL;
- }
- /* First check if filename is string "NULL" */
- if (fname != NULL) {
- if ((f = HDfopen(fname, "w")) != NULL) {
- rawoutstream = f;
- retvalue = SUCCEED;
- }
- }
- else {
- rawoutstream = NULL;
- retvalue = SUCCEED;
- }
-
- return retvalue;
-}
-
-/*-------------------------------------------------------------------------
- * Function: set_error_file
- *
- * Purpose: Open fname as the error output file for dataset raw error.
- * Set rawerrorstream as its file stream.
- *
- * Return: 0 -- succeeded
- * negative -- failed
- *
- *-------------------------------------------------------------------------
- */
-static int
-set_error_file(const char *fname)
-{
- int retvalue = FAIL;
- FILE *f; /* temporary holding place for the stream pointer
- * so that rawerrorstream is changed only when succeeded */
-
- if (rawerrorstream && rawerrorstream != stderr) {
- if (HDfclose(rawerrorstream))
- HDperror("closing rawerrorstream");
- else
- rawerrorstream = NULL;
- }
-
- if ((f = HDfopen(fname, "w")) != NULL) {
- rawerrorstream = f;
- retvalue = SUCCEED;
- }
-
- return retvalue;
-}
-
-/*-------------------------------------------------------------------------
* Function: set_binary_form
*
* Purpose: set the binary form of output by translating from a string input
@@ -1186,7 +1020,7 @@ parse_start:
break;
case 'O':
- if (set_output_file(opt_arg) < 0) {
+ if (h5tools_set_output_file(opt_arg) < 0) {
usage(h5tools_getprogname());
goto error;
}
@@ -1194,20 +1028,20 @@ parse_start:
case 'o':
if ( bin_output ) {
- if (set_data_output_file(opt_arg, 1) < 0) {
+ if (h5tools_set_data_output_file(opt_arg, 1) < 0) {
usage(h5tools_getprogname());
goto error;
}
}
else {
if(display_attr_data && !display_data) {
- if (set_attr_output_file(opt_arg, 0) < 0) {
+ if (h5tools_set_attr_output_file(opt_arg, 0) < 0) {
usage(h5tools_getprogname());
goto error;
}
}
if(display_data || display_all) {
- if (set_data_output_file(opt_arg, 0) < 0) {
+ if (h5tools_set_data_output_file(opt_arg, 0) < 0) {
usage(h5tools_getprogname());
goto error;
}
@@ -1229,7 +1063,7 @@ parse_start:
}
bin_output = TRUE;
if (outfname!=NULL) {
- if (set_data_output_file(outfname, 1) < 0) {
+ if (h5tools_set_data_output_file(outfname, 1) < 0) {
/* failed to set output file */
usage(h5tools_getprogname());
goto error;
diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c
index 3e9c43e..2e48889 100644
--- a/tools/lib/h5tools.c
+++ b/tools/lib/h5tools.c
@@ -36,10 +36,11 @@ hid_t H5tools_ERR_CLS_g = -1;
hid_t H5E_tools_g = -1;
hid_t H5E_tools_min_id_g = -1;
int compound_data;
-FILE *rawattrstream; /* should initialize to stdout but gcc moans about it */
-FILE *rawdatastream; /* should initialize to stdout but gcc moans about it */
-FILE *rawoutstream; /* should initialize to stdout but gcc moans about it */
-FILE *rawerrorstream; /* should initialize to stderr but gcc moans about it */
+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; /* binary form */
int region_output; /* region output */
@@ -120,6 +121,8 @@ h5tools_init(void)
rawattrstream = stdout;
if (!rawdatastream)
rawdatastream = stdout;
+ if (!rawinstream)
+ rawinstream = stdin;
if (!rawoutstream)
rawoutstream = stdout;
if (!rawerrorstream)
@@ -172,6 +175,12 @@ h5tools_close(void)
else
rawdatastream = NULL;
}
+ if (rawinstream && rawinstream != stdin) {
+ if (fclose(rawinstream))
+ perror("closing rawinstream");
+ else
+ rawinstream = NULL;
+ }
if (rawoutstream && rawoutstream != stdout) {
if (fclose(rawoutstream))
perror("closing rawoutstream");
@@ -198,6 +207,211 @@ h5tools_close(void)
}
/*-------------------------------------------------------------------------
+ * Function: h5tools_set_data_output_file
+ *
+ * Purpose: Open fname as the output file for dataset raw data.
+ * Set rawdatastream as its file stream.
+ *
+ * Return: 0 -- succeeded
+ * negative -- failed
+ *
+ * Programmer: Albert Cheng, 2000/09/30
+ *
+ * Modifications:
+ * pvn June, 1, 2006. Add a switch for binary output
+ *
+ *-------------------------------------------------------------------------
+ */
+int
+h5tools_set_data_output_file(const char *fname, int is_bin)
+{
+ int retvalue = FAIL;
+ FILE *f; /* temporary holding place for the stream pointer
+ * so that rawdatastream is changed only when succeeded */
+
+ if (rawdatastream && rawdatastream != stdout) {
+ if (HDfclose(rawdatastream))
+ HDperror("closing rawdatastream");
+ else
+ rawdatastream = NULL;
+ }
+
+ /* First check if filename is string "NULL" */
+ if (fname != NULL) {
+ /* binary output */
+ if (is_bin) {
+ if ((f = HDfopen(fname, "wb")) != NULL) {
+ rawdatastream = f;
+ retvalue = SUCCEED;
+ }
+ }
+ else {
+ if ((f = HDfopen(fname, "w")) != NULL) {
+ rawdatastream = f;
+ retvalue = SUCCEED;
+ }
+ }
+ }
+ else {
+ rawdatastream = NULL;
+ retvalue = SUCCEED;
+ }
+
+ return retvalue;
+}
+
+/*-------------------------------------------------------------------------
+ * Function: h5tools_set_attr_output_file
+ *
+ * Purpose: Open fname as the output file for attribute raw data.
+ * Set rawattrstream as its file stream.
+ *
+ * Return: 0 -- succeeded
+ * negative -- failed
+ *
+ *-------------------------------------------------------------------------
+ */
+int
+h5tools_set_attr_output_file(const char *fname, int is_bin)
+{
+ int retvalue = FAIL;
+ FILE *f; /* temporary holding place for the stream pointer
+ * so that rawattrstream is changed only when succeeded */
+
+ if (rawattrstream && rawattrstream != stdout) {
+ if (HDfclose(rawattrstream))
+ HDperror("closing rawattrstream");
+ else
+ rawattrstream = NULL;
+ }
+
+ /* First check if filename is string "NULL" */
+ if (fname != NULL) {
+ if ((f = HDfopen(fname, "w")) != NULL) {
+ rawattrstream = f;
+ retvalue = SUCCEED;
+ }
+ }
+ else {
+ rawattrstream = NULL;
+ retvalue = SUCCEED;
+ }
+
+ return retvalue;
+}
+
+/*-------------------------------------------------------------------------
+ * Function: h5tools_set_input_file
+ *
+ * Purpose: Open fname as the input file for raw input.
+ * Set rawinstream as its file stream.
+ *
+ * Return: 0 -- succeeded
+ * negative -- failed
+ *
+ *-------------------------------------------------------------------------
+ */
+int
+h5tools_set_input_file(const char *fname)
+{
+ int retvalue = FAIL;
+ FILE *f; /* temporary holding place for the stream pointer
+ * so that rawinstream is changed only when succeeded */
+
+ if (rawinstream && rawinstream != stdin) {
+ if (HDfclose(rawinstream))
+ HDperror("closing rawinstream");
+ else
+ rawinstream = NULL;
+ }
+ /* First check if filename is string "NULL" */
+ if (fname != NULL) {
+ if ((f = HDfopen(fname, "r")) != NULL) {
+ rawinstream = f;
+ retvalue = SUCCEED;
+ }
+ }
+ else {
+ rawinstream = NULL;
+ retvalue = SUCCEED;
+ }
+
+ return retvalue;
+}
+
+/*-------------------------------------------------------------------------
+ * Function: h5tools_set_output_file
+ *
+ * Purpose: Open fname as the output file for raw output.
+ * Set rawoutstream as its file stream.
+ *
+ * Return: 0 -- succeeded
+ * negative -- failed
+ *
+ *-------------------------------------------------------------------------
+ */
+int
+h5tools_set_output_file(const char *fname)
+{
+ int retvalue = FAIL;
+ FILE *f; /* temporary holding place for the stream pointer
+ * so that rawoutstream is changed only when succeeded */
+
+ if (rawoutstream && rawoutstream != stdout) {
+ if (HDfclose(rawoutstream))
+ HDperror("closing rawoutstream");
+ else
+ rawoutstream = NULL;
+ }
+ /* First check if filename is string "NULL" */
+ if (fname != NULL) {
+ if ((f = HDfopen(fname, "w")) != NULL) {
+ rawoutstream = f;
+ retvalue = SUCCEED;
+ }
+ }
+ else {
+ rawoutstream = NULL;
+ retvalue = SUCCEED;
+ }
+
+ return retvalue;
+}
+
+/*-------------------------------------------------------------------------
+ * Function: h5tools_set_error_file
+ *
+ * Purpose: Open fname as the error output file for dataset raw error.
+ * Set rawerrorstream as its file stream.
+ *
+ * Return: 0 -- succeeded
+ * negative -- failed
+ *
+ *-------------------------------------------------------------------------
+ */
+int
+h5tools_set_error_file(const char *fname)
+{
+ int retvalue = FAIL;
+ FILE *f; /* temporary holding place for the stream pointer
+ * so that rawerrorstream is changed only when succeeded */
+
+ if (rawerrorstream && rawerrorstream != stderr) {
+ if (HDfclose(rawerrorstream))
+ HDperror("closing rawerrorstream");
+ else
+ rawerrorstream = NULL;
+ }
+
+ if ((f = HDfopen(fname, "w")) != NULL) {
+ rawerrorstream = f;
+ retvalue = SUCCEED;
+ }
+
+ return retvalue;
+}
+
+/*-------------------------------------------------------------------------
* Audience: Private
* Chapter: H5Tools Library
* Purpose: Get a FAPL for a driver
@@ -1468,7 +1682,7 @@ render_bin_output_region_blocks(hid_t region_space, hid_t region_id,
* hssize_t npoints is the number of points in the region
*-------------------------------------------------------------------------
*/
-static int
+int
render_bin_output_region_data_points(hid_t region_space, hid_t region_id,
FILE *stream, hid_t container,
int ndims, hid_t type_id, hssize_t npoints)
diff --git a/tools/lib/h5tools.h b/tools/lib/h5tools.h
index efadba4..5f834c5 100644
--- a/tools/lib/h5tools.h
+++ b/tools/lib/h5tools.h
@@ -532,6 +532,7 @@ H5TOOLS_DLLVAR int packed_data_length; /* lengtht of packed bits to display
H5TOOLS_DLLVAR unsigned long long packed_data_mask; /* mask in which packed bits to display */
H5TOOLS_DLLVAR FILE *rawattrstream; /* output stream for raw attribute data */
H5TOOLS_DLLVAR FILE *rawdatastream; /* output stream for raw data */
+H5TOOLS_DLLVAR FILE *rawinstream; /* input stream for raw input */
H5TOOLS_DLLVAR FILE *rawoutstream; /* output stream for raw output */
H5TOOLS_DLLVAR FILE *rawerrorstream; /* output stream for raw error */
H5TOOLS_DLLVAR int bin_output; /* binary output */
@@ -549,6 +550,11 @@ H5TOOLS_DLLVAR int attr_data_output; /* attribute data output */
/* Definitions of useful routines */
H5TOOLS_DLL void h5tools_init(void);
H5TOOLS_DLL void h5tools_close(void);
+H5TOOLS_DLL int h5tools_set_data_output_file(const char *fname, int is_bin);
+H5TOOLS_DLL int h5tools_set_attr_output_file(const char *fname, int is_bin);
+H5TOOLS_DLL int h5tools_set_input_file(const char *fname);
+H5TOOLS_DLL int h5tools_set_output_file(const char *fname);
+H5TOOLS_DLL int h5tools_set_error_file(const char *fname);
H5TOOLS_DLL hid_t h5tools_fopen(const char *fname, unsigned flags, hid_t fapl,
const char *driver, char *drivername, size_t drivername_len);
H5TOOLS_DLL hid_t h5tools_get_native_type(hid_t type);
@@ -568,8 +574,6 @@ H5TOOLS_DLL void h5tools_region_simple_prefix(FILE *stream, const h5tool_form
h5tools_context_t *ctx, hsize_t elmtno, hsize_t *ptdata, int secnum);
H5TOOLS_DLL int render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t nelmts);
-H5TOOLS_DLL int render_bin_output_region_data_blocks(hid_t region_id, FILE *stream,
- hid_t container, int ndims, hid_t type_id, hssize_t nblocks, hsize_t *ptdata);
H5TOOLS_DLL hbool_t render_bin_output_region_blocks(hid_t region_space, hid_t region_id,
FILE *stream, hid_t container);
H5TOOLS_DLL hbool_t render_bin_output_region_points(hid_t region_space, hid_t region_id,