summaryrefslogtreecommitdiffstats
path: root/tools/h5dump.c
diff options
context:
space:
mode:
authorAlbert Cheng <acheng@hdfgroup.org>2000-09-30 17:27:18 (GMT)
committerAlbert Cheng <acheng@hdfgroup.org>2000-09-30 17:27:18 (GMT)
commit375e1d4d7745f7115631901e5a34fdf6755c3658 (patch)
tree0744e2db99b2b21d101403b1a3215d5aa7346c4d /tools/h5dump.c
parent5e8a177dd825a0b955d8f91b88b18860771311fe (diff)
downloadhdf5-375e1d4d7745f7115631901e5a34fdf6755c3658.zip
hdf5-375e1d4d7745f7115631901e5a34fdf6755c3658.tar.gz
hdf5-375e1d4d7745f7115631901e5a34fdf6755c3658.tar.bz2
[svn-r2626] Purpose:
New Feature Description: Add -o option to h5dumper. It displays the raw data of datasets to a separate output file. Add a feature to h5tools library that it uses the FILE *rawdatastream as the stream for the display of datasets raw data. Solution: Define an "extern FILE *rawdatastream" in h5tools.h and declare it in h5tools.c. This way, it would work even if an application does not explicitely declare it. Tried to initialized it to stdout as FILE *rawdatastream = stdout; but Linux gcc rejected it though all other platforms+compilers accepted it fine. For now, put in a kludge to set it right before it is used. Need a safer way to initialize it. Platforms tested: arabica, eirene, modi4 -64.
Diffstat (limited to 'tools/h5dump.c')
-rw-r--r--tools/h5dump.c52
1 files changed, 51 insertions, 1 deletions
diff --git a/tools/h5dump.c b/tools/h5dump.c
index c87a74f..886737b 100644
--- a/tools/h5dump.c
+++ b/tools/h5dump.c
@@ -223,7 +223,8 @@ h5dump [-h] [-bb] [-header] [-v] [-V] [-a <names>] [-d <names>] [-g <names>]\n\
-a <names> Display the specified attribute(s).\n\
-d <names> Display the specified dataset(s).\n\
-g <names> Display the specified group(s) and all the members.\n\
- -l <names> Displays the value(s) of the specified soft link(s).\n\
+ -l <names> Display the value(s) of the specified soft link(s).\n\
+ -o <fname> Display the raw data of datasets to a separate Output file <fname>.\n\
-t <names> Display the specified named data type(s).\n\
-w <number> Display the information with the specified maximum number of columns.\n\
\n\
@@ -1315,6 +1316,34 @@ 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.
+ *
+ * Return: 0 -- succeeded
+ * negative -- failed
+ *
+ * Programmer: Albert Cheng, 2000/09/30
+ *
+ * Modifications:
+ *
+ *-----------------------------------------------------------------------
+ */
+int
+set_output_file(char *fname)
+{
+ FILE *f; /* temporary holding place for the stream pointer */
+ /* so that rawdatastream is changed only when succeeded */
+
+ if (f = fopen(fname, "w")){
+ rawdatastream = f;
+ return 0;
+ }else
+ return -1;
+}
+
+/*-------------------------------------------------------------------------
* Function: main
*
* Purpose: HDF5 dumper
@@ -1325,6 +1354,8 @@ dump_data(hid_t obj_id, int obj_data)
* Programmer: Ruey-Hsia Li
*
* Modifications:
+ * Albert Cheng, 2000/09/30
+ * Add the -o option--output file for datasets raw data
*
*-----------------------------------------------------------------------*/
int
@@ -1379,6 +1410,20 @@ main(int argc, char *argv[])
* since curr_arg starts at 1
*/
newwidth = curr_arg;
+ } else if (!strcmp(argv[curr_arg], "-o")) {
+ /* a separate output file for dataset raw data */
+ if (argc == curr_arg){
+ /* missing <fname> */
+ usage();
+ free(opts);
+ exit(1);
+ }
+ if (set_output_file(argv[curr_arg+1]) < 0){
+ /* failed to set output file */
+ usage();
+ free(opts);
+ exit(1);
+ }
} else if (!strcmp(argv[curr_arg], "-xml")) {
dump_header_format = &xmlformat;
} else if (strcmp(argv[curr_arg],"-a") &&
@@ -1698,6 +1743,11 @@ done:
if (H5Fclose(fid) < 0)
d_status = 1;
+ if (rawdatastream != stdout)
+ if (fclose(rawdatastream))
+ perror("fclose");
+
+
free(group_table->objs);
free(dset_table->objs);
free(type_table->objs);