2
0
mirror of https://github.com/HDFGroup/hdf5.git synced 2025-03-25 17:00:45 +08:00

[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.
This commit is contained in:
Albert Cheng 2000-09-30 12:27:18 -05:00
parent 5e8a177dd8
commit 375e1d4d77
3 changed files with 57 additions and 2 deletions

@ -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\
@ -1314,6 +1315,34 @@ dump_data(hid_t obj_id, int obj_data)
indent -= COL;
}
/*-------------------------------------------------------------------------
* 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
*
@ -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);

@ -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;
}

@ -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*/