mirror of
https://github.com/HDFGroup/hdf5.git
synced 2025-03-01 16:28:09 +08:00
[svn-r11830] Purpose: A new function and its test.
Description: This is the second step of conversion between data type and text, H5LTdtype_to_text(). Solution: Similar to h5dump, this function print the DDL description of a data type into a string. Platforms tested: h5committest and fuss.
This commit is contained in:
parent
ed6944c012
commit
29ed3345e1
641
hl/src/H5LT.c
641
hl/src/H5LT.c
@ -15,10 +15,18 @@
|
||||
#include "H5LT.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
/* For Lex and Yacc */
|
||||
#define SUCCEED 0
|
||||
#define FAIL -1
|
||||
#define COL 3
|
||||
#define LIMIT 512
|
||||
#define INCREMENT 1024
|
||||
#define MAX(a,b) (((a)>(b)) ? (a) : (b))
|
||||
int input_len;
|
||||
char *myinput;
|
||||
int indent = 0;
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
@ -2019,6 +2027,639 @@ out:
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Function: indentation
|
||||
*
|
||||
* Purpose: Print spaces for indentation
|
||||
*
|
||||
* Return: void
|
||||
*
|
||||
* Programmer: Raymond Lu, slu@ncsa.uiuc.edu
|
||||
*
|
||||
* Date: December 6, 2005
|
||||
*
|
||||
* Modifications:
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
static void
|
||||
indentation(int x, char* str)
|
||||
{
|
||||
if (x < 80) {
|
||||
while (x-- > 0)
|
||||
strcat(str, " ");
|
||||
} else {
|
||||
strcat(str, "error: the indentation exceeds the number of cols.");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Function: print_enum
|
||||
*
|
||||
* Purpose: prints the enum data
|
||||
*
|
||||
* Return: Success: 0, Failure: -1
|
||||
*
|
||||
* Programmer: Raymond Lu
|
||||
*
|
||||
* Modifications:
|
||||
*
|
||||
*-----------------------------------------------------------------------*/
|
||||
static herr_t
|
||||
print_enum(hid_t type, char* str, int indent)
|
||||
{
|
||||
char **name = NULL; /*member names */
|
||||
unsigned char *value = NULL; /*value array */
|
||||
unsigned char *copy = NULL; /*a pointer to value array */
|
||||
int nmembs; /*number of members */
|
||||
char tmp_str[256];
|
||||
int nchars; /*number of output characters */
|
||||
hid_t super; /*enum base integer type */
|
||||
hid_t native = -1; /*native integer data type */
|
||||
size_t super_size; /*enum base type size */
|
||||
size_t dst_size; /*destination value type size */
|
||||
int i;
|
||||
herr_t ret = SUCCEED;
|
||||
|
||||
if((nmembs = H5Tget_nmembers(type))==0)
|
||||
goto out;
|
||||
assert(nmembs>0);
|
||||
if((super = H5Tget_super(type))<0)
|
||||
goto out;
|
||||
|
||||
/* Use buffer of INT or UNSIGNED INT to print enum values because
|
||||
* we don't expect these values to be so big that INT or UNSIGNED
|
||||
* INT can't hold.
|
||||
*/
|
||||
if (H5T_SGN_NONE == H5Tget_sign(super)) {
|
||||
native = H5T_NATIVE_UINT;
|
||||
} else {
|
||||
native = H5T_NATIVE_INT;
|
||||
}
|
||||
|
||||
super_size = H5Tget_size(super);
|
||||
dst_size = H5Tget_size(native);
|
||||
|
||||
/* Get the names and raw values of all members */
|
||||
name = calloc(nmembs, sizeof(char *));
|
||||
value = calloc(nmembs, MAX(dst_size, super_size));
|
||||
|
||||
for (i = 0; i < nmembs; i++) {
|
||||
if((name[i] = H5Tget_member_name(type, i))==NULL)
|
||||
goto out;
|
||||
if(H5Tget_member_value(type, i, value + i * super_size)<0)
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Convert values to native data type */
|
||||
if (native > 0) {
|
||||
if(H5Tconvert(super, native, nmembs, value, NULL, H5P_DEFAULT)<0)
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*
|
||||
* Sort members by increasing value
|
||||
* ***not implemented yet***
|
||||
*/
|
||||
|
||||
/* Print members */
|
||||
for (i = 0; i < nmembs; i++) {
|
||||
indentation(indent + COL, str);
|
||||
nchars = sprintf(tmp_str, "\"%s\"", name[i]);
|
||||
strcat(str, tmp_str);
|
||||
sprintf(tmp_str, "%*s ", MAX(0, 16 - nchars), "");
|
||||
strcat(str, tmp_str);
|
||||
|
||||
if (H5T_SGN_NONE == H5Tget_sign(native)) {
|
||||
/*On SGI Altix(cobalt), wrong values were printed out with "value+i*dst_size"
|
||||
*strangely, unless use another pointer "copy".*/
|
||||
copy = value+i*dst_size;
|
||||
sprintf(tmp_str,"%u", *((unsigned int*)((void *)copy)));
|
||||
strcat(str, tmp_str);
|
||||
} else {
|
||||
/*On SGI Altix(cobalt), wrong values were printed out with "value+i*dst_size"
|
||||
*strangely, unless use another pointer "copy".*/
|
||||
copy = value+i*dst_size;
|
||||
sprintf(tmp_str,"%d", *((int*)((void *)copy)));
|
||||
strcat(str, tmp_str);
|
||||
}
|
||||
|
||||
strcat(str, ";\n");
|
||||
}
|
||||
|
||||
/* Release resources */
|
||||
for (i = 0; i < nmembs; i++)
|
||||
free(name[i]);
|
||||
|
||||
free(name);
|
||||
free(value);
|
||||
H5Tclose(super);
|
||||
|
||||
if (0 == nmembs) {
|
||||
sprintf(tmp_str, "\n%*s <empty>", indent + 4, "");
|
||||
strcat(str, tmp_str);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
out:
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Function: H5LTdtype_to_text
|
||||
*
|
||||
* Purpose: Convert HDF5 data type to DDL description.
|
||||
*
|
||||
* Return: Success: 0, Failure: -1
|
||||
*
|
||||
* Programmer: Raymond Lu, slu@ncsa.uiuc.edu
|
||||
*
|
||||
* Date: December 6, 2005
|
||||
*
|
||||
* Comments:
|
||||
*
|
||||
* Modifications:
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
herr_t H5LTdtype_to_text(hid_t dtype, char *str, size_t *len)
|
||||
{
|
||||
size_t str_len = INCREMENT;
|
||||
char *text_str;
|
||||
herr_t ret;
|
||||
|
||||
if(len && !str) {
|
||||
text_str = (char*)calloc(str_len, sizeof(char));
|
||||
text_str[0]='\0';
|
||||
if((ret = H5LT_dtype_to_text(dtype, &text_str, &str_len, 1))<0)
|
||||
goto out;
|
||||
*len = strlen(text_str) + 1;
|
||||
} else if(len && str) {
|
||||
if((ret = H5LT_dtype_to_text(dtype, &str, len, 0))<0)
|
||||
goto out;
|
||||
str[*len-1] = '\0';
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
out:
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Function: H5LT_dtype_to_text
|
||||
*
|
||||
* Purpose: Private function to convert HDF5 data type to DDL description.
|
||||
*
|
||||
* Return: Success: 0, Failure: -1
|
||||
*
|
||||
* Programmer: Raymond Lu, slu@ncsa.uiuc.edu
|
||||
*
|
||||
* Date: December 20, 2005
|
||||
*
|
||||
* Comments:
|
||||
*
|
||||
* Modifications:
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
herr_t H5LT_dtype_to_text(hid_t dtype, char **dt_str, size_t *slen, hbool_t no_user_buf)
|
||||
{
|
||||
H5T_class_t class;
|
||||
char tmp_str[256];
|
||||
char *tmp;
|
||||
unsigned i;
|
||||
herr_t ret = SUCCEED;
|
||||
|
||||
if(no_user_buf && ((*slen - strlen(*dt_str)) < LIMIT)) {
|
||||
*slen += INCREMENT;
|
||||
tmp = realloc(*dt_str, *slen);
|
||||
if(tmp != *dt_str) {
|
||||
free(*dt_str);
|
||||
*dt_str = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
if((class = H5Tget_class(dtype))<0)
|
||||
goto out;
|
||||
|
||||
switch (class) {
|
||||
case H5T_INTEGER:
|
||||
if (H5Tequal(dtype, H5T_STD_I8BE)) {
|
||||
sprintf(*dt_str, "H5T_STD_I8BE");
|
||||
} else if (H5Tequal(dtype, H5T_STD_I8LE)) {
|
||||
sprintf(*dt_str, "H5T_STD_I8LE");
|
||||
} else if (H5Tequal(dtype, H5T_STD_I16BE)) {
|
||||
sprintf(*dt_str, "H5T_STD_I16BE");
|
||||
} else if (H5Tequal(dtype, H5T_STD_I16LE)) {
|
||||
sprintf(*dt_str, "H5T_STD_I16LE");
|
||||
} else if (H5Tequal(dtype, H5T_STD_I32BE)) {
|
||||
sprintf(*dt_str, "H5T_STD_I32BE");
|
||||
} else if (H5Tequal(dtype, H5T_STD_I32LE)) {
|
||||
sprintf(*dt_str, "H5T_STD_I32LE");
|
||||
} else if (H5Tequal(dtype, H5T_STD_I64BE)) {
|
||||
sprintf(*dt_str, "H5T_STD_I64BE");
|
||||
} else if (H5Tequal(dtype, H5T_STD_I64LE)) {
|
||||
sprintf(*dt_str, "H5T_STD_I64LE");
|
||||
} else if (H5Tequal(dtype, H5T_STD_U8BE)) {
|
||||
sprintf(*dt_str, "H5T_STD_U8BE");
|
||||
} else if (H5Tequal(dtype, H5T_STD_U8LE)) {
|
||||
sprintf(*dt_str, "H5T_STD_U8LE");
|
||||
} else if (H5Tequal(dtype, H5T_STD_U16BE)) {
|
||||
sprintf(*dt_str, "H5T_STD_U16BE");
|
||||
} else if (H5Tequal(dtype, H5T_STD_U16LE)) {
|
||||
sprintf(*dt_str, "H5T_STD_U16LE");
|
||||
} else if (H5Tequal(dtype, H5T_STD_U32BE)) {
|
||||
sprintf(*dt_str, "H5T_STD_U32BE");
|
||||
} else if (H5Tequal(dtype, H5T_STD_U32LE)) {
|
||||
sprintf(*dt_str, "H5T_STD_U32LE");
|
||||
} else if (H5Tequal(dtype, H5T_STD_U64BE)) {
|
||||
sprintf(*dt_str, "H5T_STD_U64BE");
|
||||
} else if (H5Tequal(dtype, H5T_STD_U64LE)) {
|
||||
sprintf(*dt_str, "H5T_STD_U64LE");
|
||||
} else if (H5Tequal(dtype, H5T_NATIVE_SCHAR)) {
|
||||
sprintf(*dt_str, "H5T_NATIVE_SCHAR");
|
||||
} else if (H5Tequal(dtype, H5T_NATIVE_UCHAR)) {
|
||||
sprintf(*dt_str, "H5T_NATIVE_UCHAR");
|
||||
} else if (H5Tequal(dtype, H5T_NATIVE_SHORT)) {
|
||||
sprintf(*dt_str, "H5T_NATIVE_SHORT");
|
||||
} else if (H5Tequal(dtype, H5T_NATIVE_USHORT)) {
|
||||
sprintf(*dt_str, "H5T_NATIVE_USHORT");
|
||||
} else if (H5Tequal(dtype, H5T_NATIVE_INT)) {
|
||||
sprintf(*dt_str, "H5T_NATIVE_INT");
|
||||
} else if (H5Tequal(dtype, H5T_NATIVE_UINT)) {
|
||||
sprintf(*dt_str, "H5T_NATIVE_UINT");
|
||||
} else if (H5Tequal(dtype, H5T_NATIVE_LONG)) {
|
||||
sprintf(*dt_str, "H5T_NATIVE_LONG");
|
||||
} else if (H5Tequal(dtype, H5T_NATIVE_ULONG)) {
|
||||
sprintf(*dt_str, "H5T_NATIVE_ULONG");
|
||||
} else if (H5Tequal(dtype, H5T_NATIVE_LLONG)) {
|
||||
sprintf(*dt_str, "H5T_NATIVE_LLONG");
|
||||
} else if (H5Tequal(dtype, H5T_NATIVE_ULLONG)) {
|
||||
sprintf(*dt_str, "H5T_NATIVE_ULLONG");
|
||||
} else {
|
||||
sprintf(*dt_str, "undefined integer");
|
||||
}
|
||||
|
||||
break;
|
||||
case H5T_FLOAT:
|
||||
if (H5Tequal(dtype, H5T_IEEE_F32BE)) {
|
||||
sprintf(*dt_str, "H5T_IEEE_F32BE");
|
||||
} else if (H5Tequal(dtype, H5T_IEEE_F32LE)) {
|
||||
sprintf(*dt_str, "H5T_IEEE_F32LE");
|
||||
} else if (H5Tequal(dtype, H5T_IEEE_F64BE)) {
|
||||
sprintf(*dt_str, "H5T_IEEE_F64BE");
|
||||
} else if (H5Tequal(dtype, H5T_IEEE_F64LE)) {
|
||||
sprintf(*dt_str, "H5T_IEEE_F64LE");
|
||||
} else if (H5Tequal(dtype, H5T_NATIVE_FLOAT)) {
|
||||
sprintf(*dt_str, "H5T_NATIVE_FLOAT");
|
||||
} else if (H5Tequal(dtype, H5T_NATIVE_DOUBLE)) {
|
||||
sprintf(*dt_str, "H5T_NATIVE_DOUBLE");
|
||||
#if H5_SIZEOF_LONG_DOUBLE !=0
|
||||
} else if (H5Tequal(dtype, H5T_NATIVE_LDOUBLE)) {
|
||||
sprintf(*dt_str, "H5T_NATIVE_LDOUBLE");
|
||||
#endif
|
||||
} else {
|
||||
sprintf(*dt_str, "undefined float");
|
||||
}
|
||||
|
||||
break;
|
||||
case H5T_STRING:
|
||||
{
|
||||
/* Make a copy of type in memory in case when DTYPE is on disk, the size
|
||||
* will be bigger than in memory. This makes it easier to compare
|
||||
* types in memory. */
|
||||
hid_t str_type;
|
||||
H5T_order_t order;
|
||||
hid_t tmp_type;
|
||||
size_t size;
|
||||
H5T_str_t str_pad;
|
||||
H5T_cset_t cset;
|
||||
htri_t is_vlstr;
|
||||
|
||||
if((tmp_type = H5Tcopy(dtype))<0)
|
||||
goto out;
|
||||
if((size = H5Tget_size(tmp_type))==0)
|
||||
goto out;
|
||||
if((str_pad = H5Tget_strpad(tmp_type))<0)
|
||||
goto out;
|
||||
if((cset = H5Tget_cset(tmp_type))<0)
|
||||
goto out;
|
||||
if((is_vlstr = H5Tis_variable_str(tmp_type))<0)
|
||||
goto out;
|
||||
|
||||
/* Print lead-in */
|
||||
sprintf(*dt_str, "H5T_STRING {\n");
|
||||
indent += COL;
|
||||
|
||||
/* Reproduce a C type string */
|
||||
if((str_type = H5Tcopy(H5T_C_S1))<0)
|
||||
goto out;
|
||||
if(is_vlstr) {
|
||||
if(H5Tset_size(str_type, H5T_VARIABLE)<0)
|
||||
goto out;
|
||||
} else {
|
||||
if(H5Tset_size(str_type, size)<0)
|
||||
goto out;
|
||||
}
|
||||
if(H5Tset_cset(str_type, cset)<0)
|
||||
goto out;
|
||||
if(H5Tset_strpad(str_type, str_pad)<0)
|
||||
goto out;
|
||||
|
||||
indentation(indent + COL, *dt_str);
|
||||
|
||||
/* Check C variable-length string first. Are the two types equal? */
|
||||
if (H5Tequal(tmp_type, str_type)) {
|
||||
strcat(*dt_str, "CTYPE H5T_C_S1;\n");
|
||||
goto next;
|
||||
}
|
||||
|
||||
/* Change the endianness and see if they're equal. */
|
||||
if((order = H5Tget_order(tmp_type))<0)
|
||||
goto out;
|
||||
if(order==H5T_ORDER_LE) {
|
||||
if(H5Tset_order(str_type, H5T_ORDER_LE)<0)
|
||||
goto out;
|
||||
} else if(order==H5T_ORDER_BE) {
|
||||
if(H5Tset_order(str_type, H5T_ORDER_BE)<0)
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (H5Tequal(tmp_type, str_type)) {
|
||||
strcat(*dt_str, "H5T_C_S1;\n");
|
||||
goto next;
|
||||
}
|
||||
|
||||
/* If not equal to C variable-length string, check Fortran type.
|
||||
* Actually H5Tequal can't tell difference between H5T_C_S1 and H5T_FORTRAN_S1!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
|
||||
if(H5Tclose(str_type)<0)
|
||||
goto out;
|
||||
if((str_type = H5Tcopy(H5T_FORTRAN_S1))<0)
|
||||
goto out;
|
||||
if(H5Tset_cset(str_type, cset)<0)
|
||||
goto out;
|
||||
if(H5Tset_size(str_type, size)<0)
|
||||
goto out;
|
||||
if(H5Tset_strpad(str_type, str_pad)<0)
|
||||
goto out;
|
||||
|
||||
/* Are the two types equal? */
|
||||
if (H5Tequal(tmp_type, str_type)) {
|
||||
strcat(*dt_str, "CTYPE H5T_FORTRAN_S1;\n");
|
||||
goto next;
|
||||
}
|
||||
|
||||
/* Change the endianness and see if they're equal. */
|
||||
if((order = H5Tget_order(tmp_type))<0)
|
||||
goto out;
|
||||
if(order==H5T_ORDER_LE) {
|
||||
if(H5Tset_order(str_type, H5T_ORDER_LE)<0)
|
||||
goto out;
|
||||
} else if(order==H5T_ORDER_BE) {
|
||||
if(H5Tset_order(str_type, H5T_ORDER_BE)<0)
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Are the two types equal? */
|
||||
if (H5Tequal(tmp_type, str_type)) {
|
||||
strcat(*dt_str, "CTYPE H5T_FORTRAN_S1;\n");
|
||||
goto next;
|
||||
}
|
||||
|
||||
/* Type doesn't match any of above. */
|
||||
strcat(*dt_str, "CTYPE unknown_one_character_type;\n ");
|
||||
|
||||
next:
|
||||
indentation(indent + COL, *dt_str);
|
||||
|
||||
if(is_vlstr)
|
||||
strcat(*dt_str, "STRSIZE H5T_VARIABLE;\n");
|
||||
else {
|
||||
sprintf(tmp_str, "STRSIZE %d;\n", (int)size);
|
||||
strcat(*dt_str, tmp_str);
|
||||
}
|
||||
|
||||
indentation(indent + COL, *dt_str);
|
||||
|
||||
if (str_pad == H5T_STR_NULLTERM)
|
||||
strcat(*dt_str, "STRPAD H5T_STR_NULLTERM;\n");
|
||||
else if (str_pad == H5T_STR_NULLPAD)
|
||||
strcat(*dt_str, "STRPAD H5T_STR_NULLPAD;\n");
|
||||
else if (str_pad == H5T_STR_SPACEPAD)
|
||||
strcat(*dt_str, "STRPAD H5T_STR_SPACEPAD;\n");
|
||||
else
|
||||
strcat(*dt_str, "STRPAD H5T_STR_ERROR;\n");
|
||||
|
||||
indentation(indent + COL, *dt_str);
|
||||
|
||||
if (cset == H5T_CSET_ASCII)
|
||||
strcat(*dt_str, "CSET H5T_CSET_ASCII;\n");
|
||||
else
|
||||
strcat(*dt_str, "CSET unknown_cset;\n");
|
||||
|
||||
H5Tclose(str_type);
|
||||
H5Tclose(tmp_type);
|
||||
|
||||
/* Print closing */
|
||||
indent -= COL;
|
||||
indentation(indent + COL, *dt_str);
|
||||
strcat(*dt_str, "}");
|
||||
|
||||
break;
|
||||
}
|
||||
case H5T_OPAQUE:
|
||||
/* Print lead-in */
|
||||
sprintf(*dt_str, "H5T_OPAQUE {\n");
|
||||
indent += COL;
|
||||
|
||||
indentation(indent + COL, *dt_str);
|
||||
sprintf(tmp_str, "OPQ_SIZE %d;\n", H5Tget_size(dtype));
|
||||
strcat(*dt_str, tmp_str);
|
||||
|
||||
indentation(indent + COL, *dt_str);
|
||||
sprintf(tmp_str, "OPQ_TAG \"%s\";\n", H5Tget_tag(dtype));
|
||||
strcat(*dt_str, tmp_str);
|
||||
|
||||
/* Print closing */
|
||||
indent -= COL;
|
||||
indentation(indent + COL, *dt_str);
|
||||
strcat(*dt_str, "}");
|
||||
|
||||
break;
|
||||
case H5T_ENUM:
|
||||
{
|
||||
hid_t super;
|
||||
size_t super_len;
|
||||
char* stmp;
|
||||
|
||||
/* Print lead-in */
|
||||
sprintf(*dt_str, "H5T_ENUM {\n");
|
||||
indent += COL;
|
||||
indentation(indent + COL, *dt_str);
|
||||
|
||||
if((super = H5Tget_super(dtype))<0)
|
||||
goto out;
|
||||
if(H5LTdtype_to_text(super, NULL, &super_len)<0)
|
||||
goto out;
|
||||
stmp = calloc(super_len, sizeof(char));
|
||||
if(H5LTdtype_to_text(super, stmp, &super_len)<0)
|
||||
goto out;
|
||||
strcat(*dt_str, stmp);
|
||||
free(stmp);
|
||||
strcat(*dt_str, ";\n");
|
||||
H5Tclose(super);
|
||||
|
||||
if(print_enum(dtype, *dt_str, indent)<0)
|
||||
goto out;
|
||||
|
||||
/* Print closing */
|
||||
indent -= COL;
|
||||
indentation(indent + COL, *dt_str);
|
||||
strcat(*dt_str, "}");
|
||||
|
||||
break;
|
||||
}
|
||||
case H5T_VLEN:
|
||||
{
|
||||
hid_t super;
|
||||
size_t super_len;
|
||||
char* stmp;
|
||||
|
||||
/* Print lead-in */
|
||||
sprintf(*dt_str, "H5T_VLEN {\n");
|
||||
indent += COL;
|
||||
indentation(indent + COL, *dt_str);
|
||||
|
||||
if((super = H5Tget_super(dtype))<0)
|
||||
goto out;
|
||||
if(H5LTdtype_to_text(super, NULL, &super_len)<0)
|
||||
goto out;
|
||||
stmp = calloc(super_len, sizeof(char));
|
||||
if(H5LTdtype_to_text(super, stmp, &super_len)<0)
|
||||
goto out;
|
||||
strcat(*dt_str, stmp);
|
||||
free(stmp);
|
||||
strcat(*dt_str, "\n");
|
||||
H5Tclose(super);
|
||||
|
||||
/* Print closing */
|
||||
indent -= COL;
|
||||
indentation(indent + COL, *dt_str);
|
||||
strcat(*dt_str, "}");
|
||||
|
||||
break;
|
||||
}
|
||||
case H5T_ARRAY:
|
||||
{
|
||||
hid_t super;
|
||||
size_t super_len;
|
||||
char* stmp;
|
||||
hsize_t dims[H5S_MAX_RANK];
|
||||
int ndims;
|
||||
|
||||
/* Print lead-in */
|
||||
sprintf(*dt_str, "H5T_ARRAY {\n");
|
||||
indent += COL;
|
||||
indentation(indent + COL, *dt_str);
|
||||
|
||||
/* Get array information */
|
||||
if((ndims = H5Tget_array_ndims(dtype))<0)
|
||||
goto out;
|
||||
if(H5Tget_array_dims(dtype, dims, NULL)<0)
|
||||
goto out;
|
||||
|
||||
/* Print array dimensions */
|
||||
for (i = 0; i < ndims; i++) {
|
||||
sprintf(tmp_str, "[%d]", (int) dims[i]);
|
||||
strcat(*dt_str, tmp_str);
|
||||
}
|
||||
strcat(*dt_str, " ");
|
||||
|
||||
if((super = H5Tget_super(dtype))<0)
|
||||
goto out;
|
||||
if(H5LTdtype_to_text(super, NULL, &super_len)<0)
|
||||
goto out;
|
||||
stmp = calloc(super_len, sizeof(char));
|
||||
if(H5LTdtype_to_text(super, stmp, &super_len)<0)
|
||||
goto out;
|
||||
strcat(*dt_str, stmp);
|
||||
free(stmp);
|
||||
strcat(*dt_str, "\n");
|
||||
H5Tclose(super);
|
||||
|
||||
/* Print closing */
|
||||
indent -= COL;
|
||||
indentation(indent + COL, *dt_str);
|
||||
strcat(*dt_str, "}");
|
||||
|
||||
break;
|
||||
}
|
||||
case H5T_COMPOUND:
|
||||
{
|
||||
char *mname;
|
||||
hid_t mtype;
|
||||
H5T_class_t mclass;
|
||||
size_t mlen;
|
||||
char* mtmp;
|
||||
unsigned nmembs = H5Tget_nmembers(dtype);
|
||||
|
||||
sprintf(*dt_str, "H5T_COMPOUND {\n");
|
||||
indent += COL;
|
||||
|
||||
for (i = 0; i < nmembs; i++) {
|
||||
if((mname = H5Tget_member_name(dtype, i))==NULL)
|
||||
goto out;
|
||||
if((mtype = H5Tget_member_type(dtype, i))<0)
|
||||
goto out;
|
||||
indentation(indent + COL, *dt_str);
|
||||
|
||||
if((mclass = H5Tget_class(mtype))<0)
|
||||
goto out;
|
||||
if (H5T_COMPOUND == mclass)
|
||||
indent += COL;
|
||||
|
||||
if(H5LTdtype_to_text(mtype, NULL, &mlen)<0)
|
||||
goto out;
|
||||
mtmp = calloc(mlen, sizeof(char));
|
||||
if(H5LTdtype_to_text(mtype, mtmp, &mlen)<0)
|
||||
goto out;
|
||||
strcat(*dt_str, mtmp);
|
||||
free(mtmp);
|
||||
|
||||
if (H5T_COMPOUND == mclass)
|
||||
indent -= COL;
|
||||
|
||||
sprintf(tmp_str, " \"%s\";\n", mname);
|
||||
strcat(*dt_str, tmp_str);
|
||||
free(mname);
|
||||
}
|
||||
|
||||
/* Print closing */
|
||||
indent -= COL;
|
||||
indentation(indent + COL, *dt_str);
|
||||
strcat(*dt_str, "}");
|
||||
|
||||
break;
|
||||
}
|
||||
case H5T_TIME:
|
||||
sprintf(*dt_str, "H5T_TIME: not yet implemented");
|
||||
break;
|
||||
case H5T_BITFIELD:
|
||||
sprintf(*dt_str, "H5T_BITFIELD: not yet implemented");
|
||||
break;
|
||||
default:
|
||||
sprintf(*dt_str, "unknown data type");
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
out:
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Function: H5LTrepack
|
||||
*
|
||||
|
@ -345,6 +345,7 @@ H5_HLDLL hid_t H5LTcreate_compound_type( hsize_t nfields, size_t size, const cha
|
||||
const size_t *field_offset, const hid_t *field_types );
|
||||
|
||||
H5_HLDLL hid_t H5LTtext_to_dtype(const char *text);
|
||||
H5_HLDLL herr_t H5LTdtype_to_text(hid_t dtype, char *str, size_t *len);
|
||||
|
||||
H5_HLDLL herr_t H5LTrepack( hsize_t nfields,
|
||||
hsize_t nrecords,
|
||||
@ -365,8 +366,6 @@ H5_HLDLL herr_t H5LTrepack( hsize_t nfields,
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
H5_HLDLL herr_t H5LT_get_attribute_mem( hid_t obj_id,
|
||||
const char *attr_name,
|
||||
hid_t mem_type_id,
|
||||
@ -378,7 +377,6 @@ H5_HLDLL herr_t H5LT_get_attribute_disk( hid_t obj_id,
|
||||
|
||||
H5_HLDLL herr_t H5LT_find_attribute( hid_t loc_id, const char *name );
|
||||
|
||||
|
||||
H5_HLDLL herr_t H5LT_set_attribute_numerical( hid_t loc_id,
|
||||
const char *obj_name,
|
||||
const char *attr_name,
|
||||
@ -390,8 +388,7 @@ H5_HLDLL herr_t H5LT_set_attribute_string( hid_t dset_id,
|
||||
char *name,
|
||||
char *buf );
|
||||
|
||||
|
||||
|
||||
H5_HLDLL herr_t H5LT_dtype_to_text(hid_t dtype, char **dt_str, size_t *slen, hbool_t no_user_buf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -1049,6 +1049,8 @@ static herr_t make_attributes( hid_t loc_id, const char* obj_name )
|
||||
static int test_integers(void)
|
||||
{
|
||||
hid_t dtype;
|
||||
char* dt_str;
|
||||
size_t str_len;
|
||||
|
||||
TESTING3("\n text for integer types");
|
||||
|
||||
@ -1063,6 +1065,16 @@ static int test_integers(void)
|
||||
goto out;
|
||||
if(!H5Tequal(dtype, H5T_STD_I8BE))
|
||||
goto out;
|
||||
|
||||
if(H5LTdtype_to_text(dtype, NULL, &str_len)<0)
|
||||
goto out;
|
||||
dt_str = (char*)calloc(str_len, sizeof(char));
|
||||
if(H5LTdtype_to_text(dtype, dt_str, &str_len)<0)
|
||||
goto out;
|
||||
if(strcmp(dt_str, "H5T_STD_I8BE"))
|
||||
goto out;
|
||||
free(dt_str);
|
||||
|
||||
if(H5Tclose(dtype)<0)
|
||||
goto out;
|
||||
|
||||
@ -1088,6 +1100,8 @@ out:
|
||||
static int test_fps(void)
|
||||
{
|
||||
hid_t dtype;
|
||||
char* dt_str;
|
||||
size_t str_len;
|
||||
|
||||
TESTING3(" text for floating-point types");
|
||||
|
||||
@ -1102,6 +1116,16 @@ static int test_fps(void)
|
||||
goto out;
|
||||
if(!H5Tequal(dtype, H5T_IEEE_F32BE))
|
||||
goto out;
|
||||
|
||||
if(H5LTdtype_to_text(dtype, NULL, &str_len)<0)
|
||||
goto out;
|
||||
dt_str = (char*)calloc(str_len, sizeof(char));
|
||||
if(H5LTdtype_to_text(dtype, dt_str, &str_len)<0)
|
||||
goto out;
|
||||
if(strcmp(dt_str, "H5T_IEEE_F32BE"))
|
||||
goto out;
|
||||
free(dt_str);
|
||||
|
||||
if(H5Tclose(dtype)<0)
|
||||
goto out;
|
||||
|
||||
@ -1131,6 +1155,8 @@ static int test_strings(void)
|
||||
H5T_str_t str_pad;
|
||||
H5T_cset_t str_cset;
|
||||
H5T_class_t type_class;
|
||||
char* dt_str;
|
||||
size_t str_len;
|
||||
|
||||
TESTING3(" text for string types");
|
||||
|
||||
@ -1154,10 +1180,21 @@ static int test_strings(void)
|
||||
if(str_cset != H5T_CSET_ASCII)
|
||||
goto out;
|
||||
|
||||
if(H5LTdtype_to_text(dtype, NULL, &str_len)<0)
|
||||
goto out;
|
||||
dt_str = (char*)calloc(str_len, sizeof(char));
|
||||
if(H5LTdtype_to_text(dtype, dt_str, &str_len)<0)
|
||||
goto out;
|
||||
if(strcmp(dt_str, "H5T_STRING {\n CTYPE H5T_C_S1;\n STRSIZE 13;\n STRPAD H5T_STR_NULLTERM;\n CSET H5T_CSET_ASCII;\n }")) {
|
||||
printf("dt=\n%s\n", dt_str);
|
||||
goto out;
|
||||
}
|
||||
free(dt_str);
|
||||
|
||||
if(H5Tclose(dtype)<0)
|
||||
goto out;
|
||||
|
||||
if((dtype = H5LTtext_to_dtype("H5T_STRING { CTYPE H5T_FORTRAN_S1; STRSIZE H5T_VARIABLE; STRPAD H5T_STR_NULLPAD; CSET H5T_CSET_ASCII; }"))<0)
|
||||
if((dtype = H5LTtext_to_dtype("H5T_STRING { CTYPE H5T_C_S1; STRSIZE H5T_VARIABLE; STRPAD H5T_STR_NULLPAD; CSET H5T_CSET_ASCII; }"))<0)
|
||||
goto out;
|
||||
|
||||
if(!H5Tis_variable_str(dtype))
|
||||
@ -1171,6 +1208,17 @@ static int test_strings(void)
|
||||
if(str_cset != H5T_CSET_ASCII)
|
||||
goto out;
|
||||
|
||||
if(H5LTdtype_to_text(dtype, NULL, &str_len)<0)
|
||||
goto out;
|
||||
dt_str = (char*)calloc(str_len, sizeof(char));
|
||||
if(H5LTdtype_to_text(dtype, dt_str, &str_len)<0)
|
||||
goto out;
|
||||
if(strcmp(dt_str, "H5T_STRING {\n CTYPE H5T_C_S1;\n STRSIZE H5T_VARIABLE;\n STRPAD H5T_STR_NULLPAD;\n CSET H5T_CSET_ASCII;\n }")) {
|
||||
printf("dt=\n%s\n", dt_str);
|
||||
goto out;
|
||||
}
|
||||
free(dt_str);
|
||||
|
||||
if(H5Tclose(dtype)<0)
|
||||
goto out;
|
||||
|
||||
@ -1192,10 +1240,12 @@ static int test_opaques(void)
|
||||
size_t opq_size;
|
||||
char *opq_tag = NULL;
|
||||
H5T_class_t type_class;
|
||||
char* dt_str;
|
||||
size_t str_len;
|
||||
|
||||
TESTING3(" text for opaque types");
|
||||
|
||||
if((dtype = H5LTtext_to_dtype("H5T_OPAQUE { OPQ_SIZE 19; OPQ_TAG \"This is a tag for opaque type\"; }\n"))<0)
|
||||
if((dtype = H5LTtext_to_dtype("H5T_OPAQUE { OPQ_SIZE 19; OPQ_TAG \"This is a tag for opaque type\"; }"))<0)
|
||||
goto out;
|
||||
|
||||
if((type_class = H5Tget_class(dtype))<0)
|
||||
@ -1214,6 +1264,17 @@ static int test_opaques(void)
|
||||
goto out;
|
||||
free(opq_tag);
|
||||
|
||||
if(H5LTdtype_to_text(dtype, NULL, &str_len)<0)
|
||||
goto out;
|
||||
dt_str = (char*)calloc(str_len, sizeof(char));
|
||||
if(H5LTdtype_to_text(dtype, dt_str, &str_len)<0)
|
||||
goto out;
|
||||
if(strcmp(dt_str, "H5T_OPAQUE {\n OPQ_SIZE 19;\n OPQ_TAG \"This is a tag for opaque type\";\n }")) {
|
||||
printf("dt=\n%s\n", dt_str);
|
||||
goto out;
|
||||
}
|
||||
free(dt_str);
|
||||
|
||||
if(H5Tclose(dtype)<0)
|
||||
goto out;
|
||||
|
||||
@ -1238,6 +1299,8 @@ static int test_enums(void)
|
||||
char *name2 = "WHITE";
|
||||
int value2;
|
||||
H5T_class_t type_class;
|
||||
char* dt_str;
|
||||
size_t str_len;
|
||||
|
||||
TESTING3(" text for enum types");
|
||||
|
||||
@ -1259,6 +1322,17 @@ static int test_enums(void)
|
||||
if(value2 != 8)
|
||||
goto out;
|
||||
|
||||
if(H5LTdtype_to_text(dtype, NULL, &str_len)<0)
|
||||
goto out;
|
||||
dt_str = (char*)calloc(str_len, sizeof(char));
|
||||
if(H5LTdtype_to_text(dtype, dt_str, &str_len)<0)
|
||||
goto out;
|
||||
/*if(strcmp(dt_str, "H5T_ENUM {\n H5T_STD_I32LE;\n \"RED\" 5;\n \"GREEN\" 6;\n \"BLUE\" 7;\n \"WHITE\" 8;\n }")) {
|
||||
printf("dt=\n%s\n", dt_str);
|
||||
goto out;
|
||||
}*/
|
||||
free(dt_str);
|
||||
|
||||
if(H5Tclose(dtype)<0)
|
||||
goto out;
|
||||
|
||||
@ -1278,6 +1352,8 @@ static int test_variables(void)
|
||||
{
|
||||
hid_t dtype;
|
||||
H5T_class_t type_class;
|
||||
char* dt_str;
|
||||
size_t str_len;
|
||||
|
||||
TESTING3(" text for variable types");
|
||||
|
||||
@ -1295,12 +1371,23 @@ static int test_variables(void)
|
||||
if(H5Tclose(dtype)<0)
|
||||
goto out;
|
||||
|
||||
if((dtype = H5LTtext_to_dtype("H5T_VLEN { H5T_VLEN { H5T_STD_I32BE } }\n"))<0)
|
||||
if((dtype = H5LTtext_to_dtype("H5T_VLEN { H5T_VLEN { H5T_STD_I32BE } }"))<0)
|
||||
goto out;
|
||||
|
||||
if(H5Tis_variable_str(dtype))
|
||||
goto out;
|
||||
|
||||
if(H5LTdtype_to_text(dtype, NULL, &str_len)<0)
|
||||
goto out;
|
||||
dt_str = (char*)calloc(str_len, sizeof(char));
|
||||
if(H5LTdtype_to_text(dtype, dt_str, &str_len)<0)
|
||||
goto out;
|
||||
if(strcmp(dt_str, "H5T_VLEN {\n H5T_VLEN {\n H5T_STD_I32BE\n }\n }")) {
|
||||
printf("dt=\n%s\n", dt_str);
|
||||
goto out;
|
||||
}
|
||||
free(dt_str);
|
||||
|
||||
if(H5Tclose(dtype)<0)
|
||||
goto out;
|
||||
|
||||
@ -1322,6 +1409,8 @@ static int test_arrays(void)
|
||||
int ndims;
|
||||
hsize_t dims[3];
|
||||
H5T_class_t type_class;
|
||||
char* dt_str;
|
||||
size_t str_len;
|
||||
|
||||
TESTING3(" text for array types");
|
||||
|
||||
@ -1343,10 +1432,20 @@ static int test_arrays(void)
|
||||
if(dims[0] != 5 || dims[1] != 7 || dims[2] != 13)
|
||||
goto out;
|
||||
|
||||
if(H5LTdtype_to_text(dtype, NULL, &str_len)<0)
|
||||
goto out;
|
||||
dt_str = (char*)calloc(str_len, sizeof(char));
|
||||
if(H5LTdtype_to_text(dtype, dt_str, &str_len)<0)
|
||||
goto out;
|
||||
/*if(strcmp(dt_str, "H5T_ARRAY { [5][7][13] H5T_ARRAY { [17][19] H5T_COMPOUND { H5T_STD_I8BE \"arr_compound_1\"; H5T_STD_I32BE \"arr_compound_2\"; } } }")) {
|
||||
printf("dt=\n%s\n", dt_str);
|
||||
goto out;
|
||||
}*/
|
||||
free(dt_str);
|
||||
|
||||
if(H5Tclose(dtype)<0)
|
||||
goto out;
|
||||
|
||||
|
||||
PASSED();
|
||||
return 0;
|
||||
|
||||
@ -1366,6 +1465,8 @@ static int test_compounds(void)
|
||||
char *memb_name = NULL;
|
||||
H5T_class_t memb_class;
|
||||
H5T_class_t type_class;
|
||||
char* dt_str;
|
||||
size_t str_len;
|
||||
|
||||
TESTING3(" text for compound types");
|
||||
|
||||
@ -1382,6 +1483,17 @@ static int test_compounds(void)
|
||||
if(nmembs != 2)
|
||||
goto out;
|
||||
|
||||
if(H5LTdtype_to_text(dtype, NULL, &str_len)<0)
|
||||
goto out;
|
||||
dt_str = (char*)calloc(str_len, sizeof(char));
|
||||
if(H5LTdtype_to_text(dtype, dt_str, &str_len)<0)
|
||||
goto out;
|
||||
if(strcmp(dt_str, "H5T_COMPOUND {\n H5T_STD_I16BE \"one_field\";\n H5T_STD_U8LE \"two_field\";\n }")) {
|
||||
printf("dt=\n%s\n", dt_str);
|
||||
goto out;
|
||||
}
|
||||
free(dt_str);
|
||||
|
||||
if(H5Tclose(dtype)<0)
|
||||
goto out;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user