From aa267768c13ab173e13c58bffe902468b67d6c24 Mon Sep 17 00:00:00 2001 From: Ruey-Hsia Li Date: Mon, 1 Feb 1999 03:46:29 -0500 Subject: [svn-r1038] Did some work on the output format for compound data and string. Also added test script for string. --- tools/h5dump.c | 75 ++--- tools/h5dump.h | 119 +------- tools/h5dumputil.c | 805 ++++++++++++++++++++++++++++++++-------------------- tools/testh5dump.sh | 3 + 4 files changed, 524 insertions(+), 478 deletions(-) diff --git a/tools/h5dump.c b/tools/h5dump.c index 043f70e..5105cfa 100644 --- a/tools/h5dump.c +++ b/tools/h5dump.c @@ -3,7 +3,6 @@ #include "H5private.h" int indent = 0; -int ischar=0; static int display_data = 1; static int status = 0; static int unamedtype = 0; /* shared data type with no name */ @@ -30,6 +29,9 @@ static void dump_dataset (hid_t, const char*); static void dump_data (hid_t, int); static void dump_named_datatype (hid_t , const char *); static int search_obj (table_t, unsigned long *); +void indentation(int); + +extern int print_data(hid_t, hid_t, int); /*------------------------------------------------------------------------- * Function: usage @@ -75,7 +77,7 @@ h5dump [-h] [-bb] [-header] [-a ] [-d ] [-g ]\n \ * Modifications: * *-----------------------------------------------------------------------*/ -static void indentation(int x) { +void indentation(int x) { while (x>0) { printf(" "); x--; } @@ -250,7 +252,7 @@ H5G_stat_t statbuf; H5Tclose(str_type); } indentation (indent+col); - printf("%s\n", END); + printf("%s", END); break; @@ -313,7 +315,8 @@ H5G_stat_t statbuf; ndims = H5Tget_member_dims(type, i, dims, perm); - indentation (indent+col); + if (H5Tget_class(mtype) != H5T_STRING) + indentation (indent+col); print_datatype(mtype); @@ -379,12 +382,17 @@ dump_datatype (hid_t type) { indent += col; indentation (indent); - if (H5Tget_class(type) == H5T_COMPOUND || - H5Tget_class(type) == H5T_STRING ) { + if (H5Tget_class(type) == H5T_COMPOUND) { printf ("%s %s\n", DATATYPE, BEGIN); print_datatype(type); indentation (indent); printf ("%s\n", END); + } else if (H5Tget_class(type) == H5T_STRING) { + printf ("%s %s\n", DATATYPE, BEGIN); + print_datatype(type); + printf("\n"); + indentation (indent); + printf ("%s\n", END); } else { printf ("%s %s ", DATATYPE, BEGIN); print_datatype(type); @@ -590,7 +598,6 @@ H5G_stat_t statbuf; printf("h5dump error: unable to open attribute.\n"); end_obj(); status = 1; - return FAIL; } switch (statbuf.type) { @@ -922,10 +929,7 @@ hid_t type, space; printf("DATA{ not yet implemented.}\n"); break; case H5T_STRING: - indent += col; - indentation (indent); - indent -= col; - printf("DATA{ not yet implemented.}\n"); + dump_data(did, DATASET_DATA); break; case H5T_BITFIELD: indent += col; @@ -1002,9 +1006,6 @@ int i; prefix = (char *) malloc(prefix_len * sizeof (char)); *prefix = '\0'; -/* - strcpy(prefix, ""); -*/ } @@ -1231,62 +1232,20 @@ int i; static void dump_data (hid_t obj_id, int obj_data) { - hid_t f_type ; - size_t size ; - h5dump_t info; - indent += col; indentation (indent); printf("%s %s\n", DATA, BEGIN); - if (obj_data == DATASET_DATA) - f_type = H5Dget_type(obj_id); - else - f_type = H5Aget_type(obj_id); - - size = H5Tget_size(f_type); - - /* Set to all default values and then override */ - memset(&info, 0, sizeof info); - info.idx_fmt = " (%s) "; - info.line_ncols = 70 - indent; - - /* - * If the dataset is a 1-byte integer type then format it as an ASCI - * character string instead of integers. - */ - if ((1==size && H5T_INTEGER==H5Tget_class(f_type)) || - (H5T_STRING == H5Tget_class(f_type))) { - info.elmt_suf1 = ""; - info.elmt_suf2 = ""; - info.idx_fmt = " (%s) \""; -/* - info.line_suf = "\""; -*/ - info.line_suf = ""; - ischar = 1; - } - - - /* - * Print all the values. - */ - - if (h5dump1(stdout, &info, obj_id, -1, obj_data)<0) { + /* Print all the values. */ + if (print_data(obj_id, -1, obj_data) < 0) { indentation(indent+col); printf("Unable to print data.\n"); status = 1; } - if (1==size && H5T_INTEGER==H5Tget_class(f_type)) - ischar = 0; - indentation(indent); printf("%s\n", END); indent -= col; - - H5Tclose(f_type); - } diff --git a/tools/h5dump.h b/tools/h5dump.h index 0a55508..5ebb1f0 100644 --- a/tools/h5dump.h +++ b/tools/h5dump.h @@ -37,125 +37,8 @@ #define begin_obj(obj,name) printf("%s \"%s\" %s\n", obj, name, BEGIN) #define end_obj() printf("%s\n", END); +#define ncols 80 #define col 3 -#endif - - -/* - * Copyright © 1998 NCSA - * All rights reserved. - * - * Programmer: Robb Matzke - * Thursday, July 23, 1998 - * - * Purpose: Support functions for the various tools. - */ -#ifndef _H5TOOLS_H -#define _H5TOOLS_H - - -/* - * Information about how to format output. - */ -typedef struct h5dump_t { - /* - * Fields associated with compound array members. - * - * pre: A string to print at the beginning of each array. The - * default value is the left square bracket `['. - * - * sep: A string to print between array values. The default - * value is a comma. - * - * suf: A strint to print at the end of each array. The default - * value is a right square bracket `]'. - */ - const char *arr_pre; - const char *arr_sep; - const char *arr_suf; - - /* - * Fields associated with compound data types. - * - * name: How the name of the struct member is printed in the - * values. By default the name is not printed, but a - * reasonable setting might be "%s=" which prints the name - * followed by an equal sign and then the value. - * - * sep: A string that separates one member from another. The - * default is a comma. - * - * pre: A string to print at the beginning of a compound type. - * The default is a left curly brace. - * - * suf: A string to print at the end of each compound type. The - * default is a right curly brace. - */ - const char *cmpd_name; - const char *cmpd_sep; - const char *cmpd_pre; - const char *cmpd_suf; - - /* - * Fields associated with the individual elements. - * - * fmt: A printf(3c) format to use to print the value string - * after it has been rendered. The default is "%s". - * - * suf1: This string is appended to elements which are followed by - * another element whether the following element is on the - * same line or the next line. The default is a comma. - * - * suf2: This string is appended (after `suf1') to elements which - * are followed on the same line by another element. The - * default is a single space. - */ - const char *elmt_fmt; - const char *elmt_suf1; - const char *elmt_suf2; - - /* - * Fields associated with the index values printed at the left edge of - * each line of output. - * - * n_fmt: Each index value is printed according to this printf(3c) - * format string which should include a format for a long - * integer. The default is "%lu". - * - * sep: Each integer in the index list will be separated from the - * others by this string, which defaults to a comma. - * - * fmt: After the index values are formated individually and - * separated from one another by some string, the entire - * resulting string will be formated according to this - * printf(3c) format which should include a format for a - * character string. The default is "%s". - */ - const char *idx_n_fmt; /*index number format */ - const char *idx_sep; /*separator between numbers */ - const char *idx_fmt; /*entire index format */ - - /* - * Fields associated with entire lines. - * - * ncols: Number of columns per line defaults to 80. - * - * suf: This character string will be appended to each line of - * output. It should not contain line feeds. The default - * is the empty string. - * - * sep: A character string to be printed after every line feed - * defaulting to the empty string. It should end with a - * line feed. - */ - int line_ncols; /*columns of output */ - const char *line_suf; /*string to append to each line */ - const char *line_sep; /*separates lines */ - -} h5dump_t; - - -int h5dump1(FILE *stream, const h5dump_t *info, hid_t dset, hid_t p_type, int); #endif diff --git a/tools/h5dumputil.c b/tools/h5dumputil.c index 4ae9012..d63c98f 100644 --- a/tools/h5dumputil.c +++ b/tools/h5dumputil.c @@ -1,14 +1,10 @@ /* - * Copyright © 1998 NCSA - * All rights reserved. * - * Programmer: Robb Matzke - * Thursday, July 23, 1998 + * Purpose: A library for displaying the values of a dataset or an attribute + * in a human readable format. * - * Purpose: A library for displaying the values of a dataset in a human - * readable format. + * Note: h5dumputil is a modification of h5tools.c */ -/* Note: h5dumputil is a modification of h5tools.c */ #include #include #include @@ -28,13 +24,14 @@ #define H5DUMP_BUFSIZE (1024) #endif -#define OPT(X,S) ((X)?(X):(S)) #define MIN(X,Y) ((X)<(Y)?(X):(Y)) #define NELMTS(X) (sizeof(X)/sizeof(*X)) #define ALIGN(A,Z) ((((A)+(Z)-1)/(Z))*(Z)) extern int indent; -extern int ischar; +extern void indentation(int); +int compound_data=0; +int print_data(hid_t , hid_t , int); /*------------------------------------------------------------------------- * Function: h5dump_sprint @@ -44,152 +41,489 @@ extern int ischar; * * Return: void * - * Programmer: Robb Matzke - * Thursday, July 23, 1998 - * * Modifications: * *------------------------------------------------------------------------- */ static void -h5dump_sprint(char *s/*out*/, const h5dump_t *info, hid_t type, void *vp) +h5dump_sprint(char *s/*out*/, hid_t type, void *vp) { - size_t i, n, offset, size, dims[4], nelmts; - char temp[1024], *name; - hid_t memb; - int nmembs, j, k, ndims; + size_t i, n; + char temp[1024]; + int j; + H5T_str_t str_pad; if (H5Tequal(type, H5T_NATIVE_DOUBLE)) { - sprintf(temp, "%g", *((double*)vp)); + sprintf(s, "%g", *((double*)vp)); } else if (H5Tequal(type, H5T_NATIVE_FLOAT)) { - sprintf(temp, "%g", *((float*)vp)); + sprintf(s, "%g", *((float*)vp)); } else if (H5Tequal(type, H5T_NATIVE_SHORT)) { - sprintf(temp, "%d", *((short*)vp)); + sprintf(s, "%d", *((short*)vp)); } else if (H5Tequal(type, H5T_NATIVE_USHORT)) { - sprintf(temp, "%u", *((unsigned short*)vp)); + sprintf(s, "%u", *((unsigned short*)vp)); } else if (H5Tequal(type, H5T_NATIVE_INT)) { - sprintf(temp, "%d", *((int*)vp)); + sprintf(s, "%d", *((int*)vp)); } else if (H5Tequal(type, H5T_NATIVE_UINT)) { - sprintf(temp, "%u", *((unsigned*)vp)); + sprintf(s, "%u", *((unsigned*)vp)); } else if (H5Tequal(type, H5T_NATIVE_LONG)) { - sprintf(temp, "%ld", *((long*)vp)); + sprintf(s, "%ld", *((long*)vp)); } else if (H5Tequal(type, H5T_NATIVE_ULONG)) { - sprintf(temp, "%lu", *((unsigned long*)vp)); - } else if (H5Tequal(type, H5T_NATIVE_SCHAR) || - H5Tequal(type, H5T_NATIVE_UCHAR)) { - switch (*((char*)vp)) { - case '"': - strcpy(temp, "\\\""); - break; - case '\\': - strcpy(temp, "\\\\"); - break; - case '\b': - strcpy(temp, "\\b"); - break; - case '\f': - strcpy(temp, "\\f"); - break; - case '\n': - strcpy(temp, "\\n"); - break; - case '\r': - strcpy(temp, "\\r"); - break; - case '\t': - strcpy(temp, "\\t"); - break; - default: - if (isprint(*((char*)vp))) sprintf(temp, "%c", *((char*)vp)); - else sprintf(temp, "\\%03o", *((unsigned char*)vp)); - break; - } - } else if (H5T_COMPOUND==H5Tget_class(type)) { - nmembs = H5Tget_nmembers(type); - strcpy(temp, OPT(info->cmpd_pre, "{")); - for (j=0; jcmpd_sep, ",")); - - /* The name */ - name = H5Tget_member_name(type, j); - sprintf(temp+strlen(temp), OPT(info->cmpd_name, ""), name); - free(name); - - /* The value */ - offset = H5Tget_member_offset(type, j); - memb = H5Tget_member_type(type, j); - size = H5Tget_size(memb); - ndims = H5Tget_member_dims(type, j, dims, NULL); - assert(ndims>=0 && ndims<=4); - for (k=0, nelmts=1; k1) strcat(temp, OPT(info->arr_pre, "[")); - for (i=0; iarr_sep, ",")); - h5dump_sprint(temp+strlen(temp), info, memb, - (char*)vp+offset+i*size); - } - if (nelmts>1) strcat(temp, OPT(info->arr_suf, "]")); - H5Tclose(memb); - } - strcat(temp, OPT(info->cmpd_suf, "}")); + sprintf(s, "%lu", *((unsigned long*)vp)); + } else if (H5Tequal(type, H5T_NATIVE_SCHAR)) { + sprintf(s, "%d", *((signed char*)vp)); + } else if (H5Tequal(type, H5T_NATIVE_UCHAR)) { + sprintf(s, "%u", *((unsigned char*)vp)); } else if (H5T_STRING==H5Tget_class(type)) { - for (i = 0; i < H5Tget_size(type); i++) - h5dump_sprint(s+i, info, H5T_NATIVE_SCHAR, (char*)vp+i); - goto done; + str_pad = H5Tget_strpad(type) ; + j = 0; + for (i = 0; i < H5Tget_size(type); i++) { + switch (*((char*)vp+i)) { + case '"': + strcpy(s+j, "\\\""); + j += strlen("\\\""); + break; + case '\\': + strcpy(s+j, "\\\\"); + j += strlen("\\\\"); + break; + case '\b': + strcpy(s+j, "\\b"); + j += strlen("\\b"); + break; + case '\f': + strcpy(s+j, "\\f"); + j += strlen("\\f"); + break; + case '\n': + strcpy(s+j, "\\n"); + j += strlen("\\n"); + break; + case '\r': + strcpy(s+j, "\\r"); + j += strlen("\\r"); + break; + case '\t': + strcpy(s+j, "\\t"); + j += strlen("\\t"); + break; + default: + if (isprint(*((char*)vp+i))){ + sprintf(s+j, "%c", *((char*)vp+i)); + j += strlen(s+j); + } else { + if (str_pad == H5T_STR_NULLTERM && + *((unsigned char*)vp+i) == '\0' ) { + sprintf(s+j, "%c", *((unsigned char*)vp+i)); + i = H5Tget_size(type); + } else { + sprintf(s+j, "\\%03o", *((unsigned char*)vp+i)); + j += strlen(s+j); + } + } + break; + } + } } else { strcpy(temp, "0x"); n = H5Tget_size(type); for (i=0; i ncols) indent = 0; + + for (i=0; i (ncols-indent-col)) { + /* first row of member */ + if (compound_data && (elmtno+i+1) == dim_n_size) + printf("%s\n", out_buf); + else { + indentation(indent+col); + printf("%s\n", out_buf); + } + strcpy(out_buf, p_buf); + if ((elmtno+i+1) % dim_n_size) + strcat(out_buf, ", "); + else { /* end of a row, flush out_buf */ + indentation(indent+col); + printf("%s", out_buf); + if ((elmtno+i+1) != p_nelmts) /* not last element */ + printf(",\n"); + else if (compound_data) { /* last element of member data*/ + if ((ncols-strlen(out_buf)-indent-col) < 2) { + /* 2 for space and ] */ + printf("\n"); + indentation(indent+col-3); + } + } else + printf("\n"); /* last row */ + *out_buf = '\0'; + } + } else { + strcat(out_buf, p_buf); + if ((elmtno+i+1) % dim_n_size) { + if ((ncols-strlen(out_buf)-indent-col-1) > 0) + strcat(out_buf, ", "); + else + strcat(out_buf, ","); + } else { /* end of a row */ + /* 1st row of member data */ + if (compound_data && (elmtno+i+1) == dim_n_size) + printf("%s", out_buf); + else { + indentation(indent+col); + printf("%s", out_buf); + } + + /* if it's the last element */ + if ((elmtno+i+1) != p_nelmts) + printf(",\n"); + else if (compound_data) { /* last row of member data*/ + /* 2 for space and ] */ + if ((ncols-strlen(out_buf)-indent-col) < 2) { + printf("\n"); + indentation(indent+col-3); + } + } else + printf("\n"); /* last row */ + *out_buf = '\0'; + } + } + } +} + + +/*------------------------------------------------------------------------- + * Function: display_string + * + * Purpose: Display string in ddl format + * + * Return: void + * + * Comment: concatenator operator : '//' + * separator between elements: ',' + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static void display_string +(hsize_t hs_nelmts, hid_t p_type, unsigned char *sm_buf, size_t p_type_nbytes, + hsize_t p_nelmts, hsize_t dim_n_size, hsize_t elmtno) { +hsize_t i, row_size=0; +int j, m, x, y, z, first_row=1; +int free_space, long_string = 0; +char p_buf[256], out_buf[ncols]; + + out_buf[0] = '\0'; + if ((indent+col) > ncols) indent = 0; + + for (i=0; i free_space) long_string = 1; + } else + /* 3 for double quotes and one comma */ + if (((int)strlen(p_buf) + 3) > free_space) long_string = 1; + + if (long_string) { + + if (free_space < 5) { /* 5 for double quotes, one space and two '/'s */ + /* flush out_buf */ + if (compound_data && first_row) { + printf("%s\n", out_buf); + first_row = 0; + } else { + indentation(indent+col); + printf("%s\n", out_buf); + } + out_buf[0] = '\0'; + x = 0 ; + } else { + x = free_space - 5; + if (compound_data && first_row) { + printf("%s\"", out_buf); + strncpy(out_buf, p_buf, x); + out_buf[x] = '\0'; + printf("%s\" //\n", out_buf); + first_row = 0; + } else { + indentation(indent+col); + printf("%s\"", out_buf); + strncpy(out_buf, p_buf, x); + out_buf[x] = '\0'; + printf("%s\" //\n", out_buf); + } + out_buf[0] = '\0'; + } + + y = ncols - indent -col - 5; + + m = (strlen(p_buf) - x)/y; + + z = (strlen(p_buf) - x) % y; + + + for (j = 0; j < m - 1 ; j++) { + indentation(indent+col); + strncpy(out_buf, p_buf+x+j*y, y); + out_buf[y] = '\0'; + printf("\"%s\" //\n", out_buf); + } + + if ((elmtno+i+1) == p_nelmts) { /* last element */ + if ((int)strlen(p_buf+x+j*y) > (ncols - indent - col -2)) { /* 2 for double quotes */ + indentation(indent+col); + strncpy(out_buf, p_buf+x+j*y, y); + out_buf[y] = '\0'; + printf("\"%s\" //\n", out_buf); + indentation(indent+col); + printf("\"%s\"", p_buf+x+m*y); + if (compound_data) { + if ((ncols-strlen(out_buf)-indent-col) < 2) { + printf("\n"); + indentation(indent+col-3); + } + } else + printf("\n"); + + } else { + indentation(indent+col); + printf("\"%s\"", p_buf+x+j*y); + if (compound_data) { + if ((ncols-strlen(out_buf)-indent-col) < 2) { + printf("\n"); + indentation(indent+col-3); + } + + } else + printf("\n"); + } + out_buf[0] = '\0'; + } else if ( row_size == dim_n_size) { + if ((int)strlen(p_buf+x+j*y) > (ncols - indent - col -3)) { /* 3 for 2 "'s and 1 , */ + indentation(indent+col); + strncpy(out_buf, p_buf+x+j*y, y); + out_buf[y] = '\0'; + printf("\"%s\" //\n", out_buf); + indentation(indent+col); + printf("\"%s\",\n", p_buf+x+m*y); + } else { + indentation(indent+col); + printf("\"%s\",\n", p_buf+x+j*y); + } + out_buf[0] = '\0'; + row_size = 0; + + } else { + if ((int)strlen(p_buf+x+j*y) > (ncols - indent - col -3)) { /* 3 for 2 "'s and 1 , */ + indentation(indent+col); + strncpy(out_buf, p_buf+x+j*y, y); + out_buf[y] = '\0'; + printf("\"%s\" //\n", out_buf); + strcpy(out_buf, "\""); + strcat(out_buf, p_buf+x+m*y); + strcat(out_buf, "\","); + if ((int)strlen(out_buf) < (ncols-indent-col)) strcat(out_buf, " "); + } else { + strcpy(out_buf, "\""); + strcat (out_buf, p_buf+x+j*y); + strcat(out_buf, "\","); + if ((int)strlen(out_buf) < (ncols-indent-col)) strcat(out_buf, " "); + } + } + long_string = 0; + + } else { + + /* flush out_buf if it's end of a row */ + if (row_size == dim_n_size) { + if (compound_data && (elmtno+i+1) == dim_n_size) { /* 1st row */ + printf("%s\"%s\"", out_buf, p_buf); + first_row = 0; + } else { + indentation(indent+col); + printf("%s\"%s\"", out_buf, p_buf); + } + + if ((elmtno+i+1) != p_nelmts) + printf(",\n"); + else if (compound_data) { + if ((ncols-strlen(out_buf)-strlen(p_buf)-indent-col) < 2) { + /* 2 for space and ] */ + printf("\n"); + indentation(indent+col-3); + } + } else + printf("\n"); + + out_buf[0] = '\0'; + row_size = 0; + } else { + strcat(out_buf, "\""); + strcat(out_buf, p_buf); + strcat(out_buf, "\","); + if ((int)strlen(out_buf) < (ncols-indent-col)) strcat(out_buf, " "); + } + + } } +} + + +/*------------------------------------------------------------------------- + * Function: display_compound_data + * + * Purpose: Display compound data in ddl format + * + * Return: void + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static void display_compound_data +(hsize_t hs_nelmts, hid_t p_type, unsigned char *sm_buf, size_t p_type_nbytes, + hsize_t p_nelmts, hsize_t elmtno) { +size_t offset, size, dims[4]; +hsize_t nelmts, dim_n_size=0; +hid_t memb; +int nmembs, i, j, k, ndims, perm[4]; + + if ((indent+col) > ncols) indent = 0; + + for (i=0; i<(int)hs_nelmts && (elmtno+i) < p_nelmts; i++) { + + nmembs = H5Tget_nmembers(p_type); - sprintf(s, OPT(info->elmt_fmt, "%s"), temp); -done: - ; + indentation(indent+col); + printf("{\n"); + + indent+= col; + for (j=0; j 0) dim_n_size = dims[ndims-1]; + else dim_n_size = 1; + for (k=0, nelmts=1; k 80) indent = 0; - for (j=0;jline_ncols>0) p_ncolumns = info->line_ncols; - /* The stripmine loop */ memset(hs_offset, 0, sizeof hs_offset); memset(zero, 0, sizeof zero); - if (ndims == 0) { /* scalar space */ - if (obj_type == DATASET_DATA) { - if (H5Dread(oid, p_type, sm_space, f_space, H5P_DEFAULT, sm_buf)<0) - return -1; - } else { - if (H5Aread(oid, p_type, sm_buf) < 0) return -1; - } + for (elmtno=0; elmtno (80-strlen(prefix))) { - printf("%s\"%s\" //\n", prefix, out_buf); - strcpy(out_buf, p_buf); - if ( j+1 == (int)p_type_nbytes ) - printf("%s\"%s\"\n", prefix, out_buf); - } else { - strcat(out_buf, p_buf); - if ( j+1 == (int)p_type_nbytes ) - printf("%s\"%s\"\n", prefix, out_buf); - } - } + /* Calculate the hyperslab size */ + if (ndims > 0) { + for (i=0, hs_nelmts=1; i<(hsize_t)ndims; i++) { + hs_size[i] = MIN(sm_size[i], p_max_idx[i]-hs_offset[i]); + hs_nelmts *= hs_size[i]; + } + H5Sselect_hyperslab(f_space, H5S_SELECT_SET, hs_offset, NULL, + hs_size, NULL); + H5Sselect_hyperslab(sm_space, H5S_SELECT_SET, zero, NULL, + &hs_nelmts, NULL); + dim_n_size = p_max_idx[ndims-1]; } else { - h5dump_sprint(p_buf, info, p_type, sm_buf); - printf("%s%s\n", prefix, p_buf); + H5Sselect_all(f_space); + H5Sselect_all(sm_space); + hs_nelmts = 1; + dim_n_size = 1; } - return 0 ; - } - -row_size = 0; - for (elmtno=0; elmtno (80-strlen(prefix))) { - printf("%s", prefix); - if (ischar) printf("\""); - printf("%s", out_buf); - if (ischar) printf("\" //"); - printf("\n"); - - strcpy(out_buf, p_buf); - if (row_size == (int)p_max_idx[ndims-1]) { - printf("%s", prefix); - if (ischar) printf("\""); - printf("%s", out_buf); - *out_buf = '\0'; - if (ischar) printf("\""); - if ((i+1) != hs_nelmts) { - if (ischar) printf(" //"); - else printf(","); - } - printf("\n"); - row_size = 0; - } else - if (!ischar) strcat(out_buf, ", "); - } else { - strcat(out_buf, p_buf); - if (row_size == (int)p_max_idx[ndims-1]) { - printf("%s", prefix); - if (ischar) printf("\""); - printf("%s", out_buf); - if (ischar) printf("\""); - if ((i+1) != hs_nelmts) { - if (ischar) printf(" //"); - else printf(","); - } - printf("\n"); - *out_buf = '\0'; - row_size = 0; - } else - if (!ischar) strcat(out_buf, ", "); - - } - } - + switch (H5Tget_class(p_type)) { + case H5T_INTEGER: + display_numeric_data (hs_nelmts, p_type, sm_buf, p_type_nbytes, + p_nelmts, dim_n_size, elmtno); + break; + + case H5T_FLOAT: + display_numeric_data (hs_nelmts, p_type, sm_buf, p_type_nbytes, + p_nelmts, dim_n_size, elmtno); + break; + + case H5T_TIME: + break; + + case H5T_STRING: + display_string (hs_nelmts, p_type, sm_buf, p_type_nbytes, + p_nelmts, dim_n_size, elmtno); + break; + + case H5T_BITFIELD: + break; + + case H5T_OPAQUE: + break; + + case H5T_COMPOUND: + compound_data = 1; + display_compound_data (hs_nelmts, p_type, sm_buf, p_type_nbytes, p_nelmts, elmtno); + compound_data = 0; + break; + + default: break; } -/* - for (i=0; ielmt_suf1, ",")); - } - - if ((p_column + - strlen(p_buf) + - strlen(OPT(info->elmt_suf2, " ")) + - strlen(OPT(info->line_suf, ""))) > p_ncolumns) { - need_prefix = 1; - } - if (need_prefix) { - - if (p_column) { - fputs(OPT(info->line_suf, ""), stream); - putc('\n', stream); - fputs(OPT(info->line_sep, ""), stream); - - } - for (j=0;jelmt_suf2, " "), stream); - p_column += strlen(OPT(info->elmt_suf2, " ")); - } - - fputs(p_buf, stream); - p_column += strlen(p_buf); - - } -*/ - - /* Calculate the next hyperslab offset */ -/* - for (i=ndims, carry=1; i>0 && carry; --i) { - hs_offset[i-1] += hs_size[i-1]; - if (hs_offset[i-1]==(hssize_t)p_max_idx[i-1]) { - hs_offset[i-1] = p_min_idx[i-1]; - } else { - carry = 0; - } - } -*/ } -/* - if (p_column) { - fputs(OPT(info->line_suf, ""), stream); - if (ischar) - putc('"',stream); - putc('\n', stream); - fputs(OPT(info->line_sep, ""), stream); - } -*/ H5Sclose(sm_space); H5Sclose(f_space); return 0; } - + /*------------------------------------------------------------------------- * Function: h5dump_fixtype * @@ -556,7 +767,6 @@ h5dump_fixtype(hid_t f_type) offset = ALIGN(offset, H5Tget_size(memb[i])) + nelmts * H5Tget_size(memb[i]); } -/* free name */ break; case H5T_TIME: @@ -606,45 +816,35 @@ h5dump_fixtype(hid_t f_type) return m_type; } - /*------------------------------------------------------------------------- - * Function: h5dump1 + * Function: print_data * - * Purpose: Print some values from a dataset DSET to the file STREAM - * after converting all types to P_TYPE (which should be a - * native type). If P_TYPE is a negative value then it will be - * computed from the dataset type using only native types. + * Purpose: Print some values from a dataset or an attribute to the + * file STREAM after converting all types to P_TYPE (which + * should be a native type). If P_TYPE is a negative value + * then it will be computed from the dataset/attribute type + * using only native types. * * Return: Success: 0 * * Failure: -1 * - * Programmer: Robb Matzke - * Thursday, July 23, 1998 - * * Modifications: * *------------------------------------------------------------------------- */ int -h5dump1 (FILE *stream, const h5dump_t *info, hid_t oid, hid_t _p_type, int obj_type) +print_data(hid_t oid, hid_t _p_type, int obj_data) { hid_t f_space; hid_t p_type = _p_type; hid_t f_type; int status = -1; - h5dump_t info_dflt; - /* Use default values */ - if (!stream) stream = stdout; - if (!info) { - memset(&info_dflt, 0, sizeof info_dflt); - info = &info_dflt; - } if (p_type < 0) { - if (obj_type == DATASET_DATA) + if (obj_data == DATASET_DATA) f_type = H5Dget_type(oid); else f_type = H5Aget_type(oid); @@ -659,7 +859,7 @@ h5dump1 (FILE *stream, const h5dump_t *info, hid_t oid, hid_t _p_type, int obj_t } /* Check the data space */ - if (obj_type == DATASET_DATA) + if (obj_data == DATASET_DATA) f_space = H5Dget_space(oid); else f_space = H5Aget_space(oid); @@ -667,10 +867,11 @@ h5dump1 (FILE *stream, const h5dump_t *info, hid_t oid, hid_t _p_type, int obj_t if (f_space < 0) return status; if (H5Sis_simple(f_space) >= 0) - status = h5dump_simple(stream, info, oid, p_type, obj_type); + status = h5dump_simple(oid, p_type, obj_data); H5Sclose(f_space); if (p_type != _p_type) H5Tclose(p_type); + return status; } diff --git a/tools/testh5dump.sh b/tools/testh5dump.sh index 6ad84e2..b33987c 100755 --- a/tools/testh5dump.sh +++ b/tools/testh5dump.sh @@ -113,6 +113,9 @@ DUMP tall-3.ddl -d /g2/dset2.1 -l /g1/g1.2/g1.2.1/slink tall.h5 # test for loop detection DUMP tloop-1.ddl tloop.h5 +# test for string +DUMP tstr-1.ddl tstr.h5 + if test "0" = "$nerrors"; then echo "All h5dump tests passed." fi -- cgit v0.12