diff options
author | Allen Byrne <byrn@hdfgroup.org> | 2013-08-12 19:54:49 (GMT) |
---|---|---|
committer | Allen Byrne <byrn@hdfgroup.org> | 2013-08-12 19:54:49 (GMT) |
commit | a003143ded20bc0d3cc0da3b04170bf2a9602482 (patch) | |
tree | c71ec5b50a81aa721f6384eef5bc98c1e92655d5 /tools/lib/h5tools.c | |
parent | ca0bd915dbfac669f7fd962196846724d89982d2 (diff) | |
download | hdf5-a003143ded20bc0d3cc0da3b04170bf2a9602482.zip hdf5-a003143ded20bc0d3cc0da3b04170bf2a9602482.tar.gz hdf5-a003143ded20bc0d3cc0da3b04170bf2a9602482.tar.bz2 |
[svn-r23992] HDFFV-8490 and H5UNJAM file handling. Merge from trunk.
Tested: local linux
Diffstat (limited to 'tools/lib/h5tools.c')
-rw-r--r-- | tools/lib/h5tools.c | 267 |
1 files changed, 262 insertions, 5 deletions
diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c index 06471de..66f87a3 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,254 @@ 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) { + /* binary output */ + if (is_bin) { + if ((f = HDfopen(fname, "wb")) != NULL) { + rawattrstream = f; + retvalue = SUCCEED; + } + } + else { + 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 is_bin) +{ + 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) { + /* binary output */ + if (is_bin) { + if ((f = HDfopen(fname, "rb")) != NULL) { + rawinstream = f; + retvalue = SUCCEED; + } + } + else { + 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 is_bin) +{ + 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) { + /* binary output */ + if (is_bin) { + if ((f = HDfopen(fname, "wb")) != NULL) { + rawoutstream = f; + retvalue = SUCCEED; + } + } + else { + 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 is_bin) +{ + 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; + } + + /* First check if filename is string "NULL" */ + if (fname != NULL) { + /* binary output */ + if (is_bin) { + if ((f = HDfopen(fname, "wb")) != NULL) { + rawerrorstream = f; + retvalue = SUCCEED; + } + } + else { + if ((f = HDfopen(fname, "w")) != NULL) { + rawerrorstream = f; + retvalue = SUCCEED; + } + } + } + else { + rawerrorstream = NULL; + retvalue = SUCCEED; + } + + return retvalue; +} + +/*------------------------------------------------------------------------- * Audience: Private * Chapter: H5Tools Library * Purpose: Get a FAPL for a driver @@ -1468,7 +1725,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) |