summaryrefslogtreecommitdiffstats
path: root/tools/h5dumputil.c
blob: 1393db0f0dc022a1e7000d865d19008949f97d53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
 *
 * Purpose:	A library for displaying the values of a dataset or an attribute
 *              in a human readable format.
 *
 * Note:        h5dumputil is a modification of h5tools.c 
 */
#include <assert.h>
#include <ctype.h>
#include <h5dump.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "h5tools.h"

/*
 * 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).
 */
#if 0
#define H5DUMP_BUFSIZE	(1024*1024)
#else
#define H5DUMP_BUFSIZE	(1024)
#endif

#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 void indentation(int);

int print_data(hid_t , hid_t , int);

/*-------------------------------------------------------------------------
 * 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:
 *
 *-------------------------------------------------------------------------
 */
#if 0
static void
h5dump_sprint(char *s/*out*/, hid_t type, void *vp)
{
    size_t	i, n;
    char	temp[1024];
    int		j;
    H5T_str_t   str_pad;

    if (H5Tequal(type, H5T_NATIVE_DOUBLE)) {
	sprintf(s, "%g", *((double*)vp));
    } else if (H5Tequal(type, H5T_NATIVE_FLOAT)) {
	sprintf(s, "%g", *((float*)vp));
    } else if (H5Tequal(type, H5T_NATIVE_SHORT)) {
	sprintf(s, "%d", *((short*)vp));
    } else if (H5Tequal(type, H5T_NATIVE_USHORT)) {
	sprintf(s, "%u", *((unsigned short*)vp));
    } else if (H5Tequal(type, H5T_NATIVE_INT)) {
	sprintf(s, "%d", *((int*)vp));
    } else if (H5Tequal(type, H5T_NATIVE_UINT)) {
	sprintf(s, "%u", *((unsigned*)vp));
    } else if (H5Tequal(type, H5T_NATIVE_LONG)) {
	sprintf(s, "%ld", *((long*)vp));
    } else if (H5Tequal(type, H5T_NATIVE_ULONG)) {
	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)) {
           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<n; i++) {
	    sprintf(temp+strlen(temp), "%02x", ((unsigned char*)vp)[i]);
	}
       sprintf(s,  "%s", temp);
    }

}


#endif