summaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--tools/h5dump.c52
-rw-r--r--tools/h5tools.c6
-rw-r--r--tools/h5tools.h1
3 files changed, 57 insertions, 2 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);
diff --git a/tools/h5tools.c b/tools/h5tools.c
index d4ece5c..197fc2f 100644
--- a/tools/h5tools.c
+++ b/tools/h5tools.c
@@ -23,6 +23,7 @@
int indent = 0;
int compound_data=0;
int nCols = 80;
+FILE *rawdatastream = NULL; /* should be stdout but linux gcc moans about it*/
int print_data(hid_t oid, hid_t _p_type, int obj_data);
@@ -1734,7 +1735,10 @@ h5dump_dset(FILE *stream, const h5dump_t *info, hid_t dset, hid_t _p_type,
H5Sclose(f_space);
/* Print the data */
- status = h5dump_simple_dset(stream, info, dset, p_type, indentlevel);
+ /* a kludge because linux gcc does not accept the initialization with sdtout */
+ if (!rawdatastream)
+ rawdatastream=stdout;
+ status = h5dump_simple_dset(rawdatastream, info, dset, p_type, indentlevel);
if (p_type!=_p_type) H5Tclose(p_type);
return status;
}
diff --git a/tools/h5tools.h b/tools/h5tools.h
index 51256c4..ffda022 100644
--- a/tools/h5tools.h
+++ b/tools/h5tools.h
@@ -399,6 +399,7 @@ void init_prefix(char **temp, int);
extern int indent;
extern void indentation(int);
extern int nCols;
+extern FILE *rawdatastream; /* output stream for raw data */
/* taken from h5dump.h*/