summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBill Wendling <wendling@ncsa.uiuc.edu>2003-04-30 22:37:06 (GMT)
committerBill Wendling <wendling@ncsa.uiuc.edu>2003-04-30 22:37:06 (GMT)
commita306b38d670cbc0f040debccf55209fe0739243e (patch)
tree6c392637116dca68fc2cd6e5f50b6961308df832
parent60754030c75ad737d5b09af1cdfba4b4e153effd (diff)
downloadhdf5-a306b38d670cbc0f040debccf55209fe0739243e.zip
hdf5-a306b38d670cbc0f040debccf55209fe0739243e.tar.gz
hdf5-a306b38d670cbc0f040debccf55209fe0739243e.tar.bz2
[svn-r6785] Purpose:
Feature Add Description: It's now possible to print out characters as actual characters instead of their decimal equivalent numbers. It's the same thing that h5ls does. The flag to do this is "--string" or "-r". Platforms tested: Verbena (Fortran & C++) Arabica (Fortran) Modi4 (Fortran & Parallel) Misc. update:
-rw-r--r--MANIFEST2
-rw-r--r--tools/h5dump/h5dump.c66
-rw-r--r--tools/h5dump/h5dumpgentest.c34
-rwxr-xr-xtools/h5dump/testh5dump.sh3
-rw-r--r--tools/testfiles/tchar.h5bin0 -> 2356 bytes
-rw-r--r--tools/testfiles/tchar1.ddl18
-rw-r--r--tools/testfiles/tnofilename.ddl1
7 files changed, 112 insertions, 12 deletions
diff --git a/MANIFEST b/MANIFEST
index 65fff41..c0a3dbe 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -1207,6 +1207,8 @@
./tools/testfiles/tattr.h5
./tools/testfiles/tbitfields-1.ddl
./tools/testfiles/tbitfields.h5
+./tools/testfiles/tchar.h5
+./tools/testfiles/tchar1.ddl
./tools/testfiles/tcomp-1.ddl
./tools/testfiles/tcomp-2.ddl
./tools/testfiles/tcomp-3.ddl
diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c
index 87ecb49..8f0e7e5 100644
--- a/tools/h5dump/h5dump.c
+++ b/tools/h5dump/h5dump.c
@@ -36,6 +36,7 @@ static int display_all = TRUE;
static int display_bb = FALSE;
static int display_oid = FALSE;
static int display_data = TRUE;
+static int display_char = FALSE; /*print 1-byte numbers as ASCII? */
static int usingdasho = FALSE;
/**
@@ -399,9 +400,9 @@ struct handler_t {
*/
#if 0
/* binary: not implemented yet */
-static const char *s_opts = "hbBHiVa:d:f:g:l:t:w:xD:o:s:S:c:k:";
+static const char *s_opts = "hbBHirVa:c:d:f:g:k:l:t:w:xD:o:s:S:";
#else
-static const char *s_opts = "hBHiVa:d:f:g:l:t:w:xD:o:s:S:c:k:";
+static const char *s_opts = "hBHirVa:c:d:f:g:k:l:t:w:xD:o:s:S:";
#endif /* 0 */
static struct long_options l_opts[] = {
{ "help", no_arg, 'h' },
@@ -493,8 +494,8 @@ static struct long_options l_opts[] = {
{ "sta", require_arg, 's' },
{ "stride", require_arg, 'S' },
{ "strid", require_arg, 'S' },
- { "stri", require_arg, 'S' },
- { "str", require_arg, 'S' },
+ { "string", no_arg, 'r' },
+ { "strin", no_arg, 'r' },
{ "width", require_arg, 'w' },
{ "widt", require_arg, 'w' },
{ "wid", require_arg, 'w' },
@@ -607,6 +608,7 @@ usage(const char *prog)
fprintf(stdout, " -B, --bootblock Print the content of the boot block\n");
fprintf(stdout, " -H, --header Print the header only; no data is displayed\n");
fprintf(stdout, " -i, --object-ids Print the object ids\n");
+ fprintf(stdout, " -r, --string Print 1-bytes integer datasets as ASCII\n");
fprintf(stdout, " -V, --version Print version number and exit\n");
fprintf(stdout, " -a P, --attribute=P Print the specified attribute\n");
fprintf(stdout, " -d P, --dataset=P Print the specified dataset\n");
@@ -1853,16 +1855,17 @@ dump_subsetting_header(struct subset_t *sset, int dims)
static void
dump_data(hid_t obj_id, int obj_data, struct subset_t *sset)
{
- h5dump_t *outputformat = &dataformat;
- int status = -1;
- void *buf;
- hid_t space, type, p_type;
- int ndims, i;
- hsize_t size[64], nelmts = 1, alloc_size;
- int depth;
- int stdindent = COL; /* should be 3 */
+ h5dump_t *outputformat = &dataformat;
+ int status = -1;
+ void *buf;
+ hid_t space, type, p_type;
+ int ndims, i;
+ hsize_t size[64], nelmts = 1, alloc_size;
+ int depth;
+ int stdindent = COL; /* should be 3 */
outputformat->line_ncols = nCols;
+
indent += COL;
/*
@@ -1889,7 +1892,39 @@ dump_data(hid_t obj_id, int obj_data, struct subset_t *sset)
/* Print all the values. */
if (obj_data == DATASET_DATA) {
+ hid_t f_type = H5Dget_type(obj_id);
+ char string_prefix[64];
+ h5dump_t string_dataformat;
+
+ if (display_char && H5Tget_size(f_type) == 1 && H5Tget_class(f_type) == H5T_INTEGER) {
+ /*
+ * Print 1-byte integer data as an ASCII character string
+ * instead of integers if the `-r' or `--string' command-line
+ * option was given.
+ *
+ * We don't want to modify the global dataformat, so make a
+ * copy of it instead.
+ */
+ string_dataformat = *outputformat;
+ string_dataformat.idx_fmt = " ";
+ string_dataformat.line_multi_new = 1;
+ string_dataformat.line_1st = " %s\"";
+ string_dataformat.line_pre = " %s";
+ string_dataformat.line_cont = " %s";
+ string_dataformat.str_repeat = 8;
+ string_dataformat.ascii = TRUE;
+ string_dataformat.elmt_suf1 = "";
+ string_dataformat.elmt_suf2 = "";
+ string_dataformat.line_indent = "";
+ strcpy(string_prefix, string_dataformat.line_pre);
+ strcat(string_prefix, "\"");
+ string_dataformat.line_pre = string_prefix;
+ string_dataformat.line_suf = "\"";
+ outputformat = &string_dataformat;
+ }
+
status = h5tools_dump_dset(stdout, outputformat, obj_id, -1, sset, depth);
+ H5Tclose(f_type);
} else {
/* need to call h5tools_dump_mem for the attribute data */
type = H5Aget_type(obj_id);
@@ -2460,6 +2495,9 @@ parse_start:
display_oid = TRUE;
last_was_dset = FALSE;
break;
+ case 'r':
+ display_char = TRUE;
+ break;
case 'V':
print_version(progname);
exit(EXIT_SUCCESS);
@@ -2740,6 +2778,10 @@ main(int argc, const char *argv[])
error_msg(progname, "option \"%s\" not available for XML\n",
"--object-ids");
exit(EXIT_FAILURE);
+ } else if (display_char == TRUE) {
+ error_msg(progname, "option \"%s\" not available for XML\n",
+ "--string");
+ exit(EXIT_FAILURE);
} else if (usingdasho) {
error_msg(progname, "option \"%s\" not available for XML\n",
"--output");
diff --git a/tools/h5dump/h5dumpgentest.c b/tools/h5dump/h5dumpgentest.c
index d220b8b..496a0f6 100644
--- a/tools/h5dump/h5dumpgentest.c
+++ b/tools/h5dump/h5dumpgentest.c
@@ -64,6 +64,7 @@
#define FILE36 "tmulti"
#define FILE37 "tlarge_objname.h5"
#define FILE38 "tvlstr.h5"
+#define FILE39 "tchar.h5"
#define LENSTR 50
#define LENSTR2 11
@@ -2891,6 +2892,38 @@ static void gent_vlstr(void)
H5Fclose(fid1);
}
+static void gent_char(void)
+{
+ const char *wdata =
+ "Four score and seven years ago our forefathers brought "
+ "forth on this continent a new nation, conceived in "
+ "liberty and dedicated to the proposition that all "
+ "men are created equal. Now we are engaged in a great "
+ "civil war, testing whether that nation or any nation "
+ "so conceived and so dedicated can long endure.";
+ hid_t fid1; /* HDF5 File IDs */
+ hid_t dataset; /* Dataset ID */
+ hid_t sid1; /* Dataspace ID */
+ hsize_t dims1[1];
+
+ dims1[0] = strlen(wdata);
+
+ /* Create file */
+ fid1 = H5Fcreate(FILE39, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ sid1 = H5Screate_simple(1, dims1, NULL);
+
+ /* Create a dataset */
+ dataset = H5Dcreate(fid1, "Dataset1", H5T_NATIVE_CHAR, sid1, H5P_DEFAULT);
+
+ /* Write some characters to it. */
+ H5Dwrite(dataset, H5T_NATIVE_CHAR, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata);
+
+ /* Close */
+ H5Dclose(dataset);
+ H5Sclose(sid1);
+ H5Fclose(fid1);
+}
+
int main(void)
{
gent_group();
@@ -2942,6 +2975,7 @@ int main(void)
gent_large_objname();
gent_vlstr();
+ gent_char();
return 0;
}
diff --git a/tools/h5dump/testh5dump.sh b/tools/h5dump/testh5dump.sh
index 12a71de..5bc98cf 100755
--- a/tools/h5dump/testh5dump.sh
+++ b/tools/h5dump/testh5dump.sh
@@ -176,6 +176,9 @@ TOOLTEST tall-5s.ddl -d "/g1/g1.1/dset1.1.2[0;2;10;]" tall.h5
TOOLTEST tdset-3s.ddl -d "/dset1[1,1;;;]" tdset.h5
TOOLTEST tdset2-1s.ddl -d "/dset1[;3,2;4,4;1,4]" tdset2.h5
+# test printing characters in ASCII instead of decimal
+TOOLTEST tchar1.ddl -r tchar.h5
+
# test failure handling
# Missing file name
TOOLTEST tnofilename.ddl
diff --git a/tools/testfiles/tchar.h5 b/tools/testfiles/tchar.h5
new file mode 100644
index 0000000..03bd6d5
--- /dev/null
+++ b/tools/testfiles/tchar.h5
Binary files differ
diff --git a/tools/testfiles/tchar1.ddl b/tools/testfiles/tchar1.ddl
new file mode 100644
index 0000000..29842c3
--- /dev/null
+++ b/tools/testfiles/tchar1.ddl
@@ -0,0 +1,18 @@
+#############################
+Expected output for 'h5dump -r tchar.h5'
+#############################
+HDF5 "tchar.h5" {
+GROUP "/" {
+ DATASET "Dataset1" {
+ DATATYPE H5T_STD_I8LE
+ DATASPACE SIMPLE { ( 308 ) / ( 308 ) }
+ DATA {
+ "Four score and seven years ago our forefathers brought forth on this "
+ "continent a new nation, conceived in liberty and dedicated to the pro"
+ "position that all men are created equal. Now we are engaged in a grea"
+ "t civil war, testing whether that nation or any nation so conceived a"
+ "nd so dedicated can long endure."
+ }
+ }
+}
+}
diff --git a/tools/testfiles/tnofilename.ddl b/tools/testfiles/tnofilename.ddl
index 213ff4c..8a72382 100644
--- a/tools/testfiles/tnofilename.ddl
+++ b/tools/testfiles/tnofilename.ddl
@@ -7,6 +7,7 @@ usage: h5dump [OPTIONS] file
-B, --bootblock Print the content of the boot block
-H, --header Print the header only; no data is displayed
-i, --object-ids Print the object ids
+ -r, --string Print 1-bytes integer datasets as ASCII
-V, --version Print version number and exit
-a P, --attribute=P Print the specified attribute
-d P, --dataset=P Print the specified dataset