1998-08-20 05:46:55 +08:00
|
|
|
/*
|
1998-09-01 03:52:53 +08:00
|
|
|
*
|
1999-02-01 16:46:29 +08:00
|
|
|
* Purpose: A library for displaying the values of a dataset or an attribute
|
|
|
|
* in a human readable format.
|
1998-09-01 03:52:53 +08:00
|
|
|
*
|
1999-02-01 16:46:29 +08:00
|
|
|
* Note: h5dumputil is a modification of h5tools.c
|
1998-08-20 05:46:55 +08:00
|
|
|
*/
|
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <h5dump.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1999-05-13 23:42:24 +08:00
|
|
|
#include "h5tools.h"
|
1998-08-20 05:46:55 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The output functions need a temporary buffer to hold a piece of the
|
|
|
|
* dataset while it's being printed. This constant sets the limit on the
|
|
|
|
* size of that temporary buffer in bytes. For efficiency's sake, choose the
|
|
|
|
* largest value suitable for your machine (for testing use a small value).
|
|
|
|
*/
|
1998-09-01 03:52:53 +08:00
|
|
|
#if 0
|
|
|
|
#define H5DUMP_BUFSIZE (1024*1024)
|
|
|
|
#else
|
|
|
|
#define H5DUMP_BUFSIZE (1024)
|
|
|
|
#endif
|
1998-08-20 05:46:55 +08:00
|
|
|
|
1999-09-29 08:31:07 +08:00
|
|
|
#ifndef MIN
|
1998-08-20 05:46:55 +08:00
|
|
|
#define MIN(X,Y) ((X)<(Y)?(X):(Y))
|
1999-09-29 08:31:07 +08:00
|
|
|
#endif
|
|
|
|
#ifndef NELMTS
|
1998-08-20 05:46:55 +08:00
|
|
|
#define NELMTS(X) (sizeof(X)/sizeof(*X))
|
1999-09-29 08:31:07 +08:00
|
|
|
#endif
|
1998-08-20 05:46:55 +08:00
|
|
|
#define ALIGN(A,Z) ((((A)+(Z)-1)/(Z))*(Z))
|
|
|
|
|
1999-05-13 23:18:12 +08:00
|
|
|
|
1999-02-01 16:46:29 +08:00
|
|
|
extern void indentation(int);
|
1999-05-13 23:18:12 +08:00
|
|
|
|
1999-02-01 16:46:29 +08:00
|
|
|
int print_data(hid_t , hid_t , int);
|
1998-08-20 05:46:55 +08:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: h5dump_sprint
|
|
|
|
*
|
|
|
|
* Purpose: Prints the value pointed to by VP into the string S assuming
|
|
|
|
* the data type of VP is TYPE.
|
|
|
|
*
|
|
|
|
* Return: void
|
|
|
|
*
|
|
|
|
* Modifications:
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1999-05-13 23:18:12 +08:00
|
|
|
#if 0
|
1998-08-20 05:46:55 +08:00
|
|
|
static void
|
1999-02-01 16:46:29 +08:00
|
|
|
h5dump_sprint(char *s/*out*/, hid_t type, void *vp)
|
1998-08-20 05:46:55 +08:00
|
|
|
{
|
1999-02-01 16:46:29 +08:00
|
|
|
size_t i, n;
|
|
|
|
char temp[1024];
|
|
|
|
int j;
|
|
|
|
H5T_str_t str_pad;
|
1998-12-22 06:45:01 +08:00
|
|
|
|
1998-08-20 05:46:55 +08:00
|
|
|
if (H5Tequal(type, H5T_NATIVE_DOUBLE)) {
|
1999-02-01 16:46:29 +08:00
|
|
|
sprintf(s, "%g", *((double*)vp));
|
1998-08-20 05:46:55 +08:00
|
|
|
} else if (H5Tequal(type, H5T_NATIVE_FLOAT)) {
|
1999-02-01 16:46:29 +08:00
|
|
|
sprintf(s, "%g", *((float*)vp));
|
1998-12-22 06:45:01 +08:00
|
|
|
} else if (H5Tequal(type, H5T_NATIVE_SHORT)) {
|
1999-02-01 16:46:29 +08:00
|
|
|
sprintf(s, "%d", *((short*)vp));
|
1998-12-22 06:45:01 +08:00
|
|
|
} else if (H5Tequal(type, H5T_NATIVE_USHORT)) {
|
1999-02-01 16:46:29 +08:00
|
|
|
sprintf(s, "%u", *((unsigned short*)vp));
|
1998-12-22 06:45:01 +08:00
|
|
|
} else if (H5Tequal(type, H5T_NATIVE_INT)) {
|
1999-02-01 16:46:29 +08:00
|
|
|
sprintf(s, "%d", *((int*)vp));
|
1998-12-22 06:45:01 +08:00
|
|
|
} else if (H5Tequal(type, H5T_NATIVE_UINT)) {
|
1999-02-01 16:46:29 +08:00
|
|
|
sprintf(s, "%u", *((unsigned*)vp));
|
1998-12-22 06:45:01 +08:00
|
|
|
} else if (H5Tequal(type, H5T_NATIVE_LONG)) {
|
1999-02-01 16:46:29 +08:00
|
|
|
sprintf(s, "%ld", *((long*)vp));
|
1998-12-22 06:45:01 +08:00
|
|
|
} else if (H5Tequal(type, H5T_NATIVE_ULONG)) {
|
1999-02-01 16:46:29 +08:00
|
|
|
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));
|
1998-12-22 06:45:01 +08:00
|
|
|
} else if (H5T_STRING==H5Tget_class(type)) {
|
1999-02-01 16:46:29 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
1998-08-20 05:46:55 +08:00
|
|
|
} else {
|
|
|
|
strcpy(temp, "0x");
|
|
|
|
n = H5Tget_size(type);
|
|
|
|
for (i=0; i<n; i++) {
|
|
|
|
sprintf(temp+strlen(temp), "%02x", ((unsigned char*)vp)[i]);
|
|
|
|
}
|
1999-02-01 16:46:29 +08:00
|
|
|
sprintf(s, "%s", temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-05-13 23:18:12 +08:00
|
|
|
#endif
|
1998-09-01 03:52:53 +08:00
|
|
|
|
1999-02-01 16:46:29 +08:00
|
|
|
|