summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2000-11-09 23:01:29 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2000-11-09 23:01:29 (GMT)
commitab5bf9f979fed3a665f302b4e8b93ca1628b5d23 (patch)
treec500e7b7df4979a5933af31336c1583256e325ce
parent66c44914cc582da845571768161302b1b18b26bd (diff)
downloadhdf5-ab5bf9f979fed3a665f302b4e8b93ca1628b5d23.zip
hdf5-ab5bf9f979fed3a665f302b4e8b93ca1628b5d23.tar.gz
hdf5-ab5bf9f979fed3a665f302b4e8b93ca1628b5d23.tar.bz2
[svn-r2851] Purpose:
Updated for new array datatypes. Description: I missed these tools earlier when I wasn't compiling with HDF4... Solution: Updated them (correctly, I hope) to use the new array datatype instead of compound datatype array fields. Platforms tested: FreeBSD 4.1.1 (hawkwind)
-rw-r--r--tools/h4toh5image.c48
-rw-r--r--tools/h4toh5vdata.c33
-rw-r--r--tools/h5toh4.c101
3 files changed, 157 insertions, 25 deletions
diff --git a/tools/h4toh5image.c b/tools/h4toh5image.c
index f651ee9..0f779a3 100644
--- a/tools/h4toh5image.c
+++ b/tools/h4toh5image.c
@@ -80,7 +80,7 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
size_t h4size;
size_t h4memsize;
- size_t fielddim[1];
+ hsize_t fielddim[1];
hsize_t h5dims[2];
herr_t ret;
hid_t create_plist;
@@ -254,8 +254,19 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
fielddim[0] = ncomp;
- ret = H5Tinsert_array(h5_ctype,"HDF4Image_data",0,1,fielddim,NULL,
- h5ty_id);
+ {
+ hid_t arr_type; /* Array datatype for inserting fields */
+
+ /* Create array datatype */
+ if((arr_type=H5Tarray_create(h5ty_id,1,fielddim,NULL))<0) {
+ printf("error creating array datatype.\n");
+ free(image_data);
+ free(h5cimage_name);
+ H5Pclose(create_plist);
+ return FAIL;
+ }
+
+ ret = H5Tinsert(h5_ctype,"HDF4Image_data",0,arr_type);
if(ret < 0) {
printf("error in inserting array of compound datatype. \n");
free(image_data);
@@ -264,8 +275,25 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
return FAIL;
}
- ret = H5Tinsert_array(h5_cmemtype,"HDF4Image_data",0,1,fielddim,NULL,
- h5memtype);
+ /* Close array datatype */
+ if(H5Tclose(arr_type)<0) {
+ printf("error closing array datatype.\n");
+ free(image_data);
+ free(h5cimage_name);
+ H5Pclose(create_plist);
+ return FAIL;
+ }
+
+ /* Create array datatype */
+ if((arr_type=H5Tarray_create(h5memtype,1,fielddim,NULL))<0) {
+ printf("error creating array datatype.\n");
+ free(image_data);
+ free(h5cimage_name);
+ H5Pclose(create_plist);
+ return FAIL;
+ }
+
+ ret = H5Tinsert(h5_cmemtype,"HDF4Image_data",0,arr_type);
if(ret < 0) {
printf("error in inserting array of compound datatype at memory. \n");
free(image_data);
@@ -273,6 +301,16 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
H5Pclose(create_plist);
return FAIL;
}
+
+ /* Close array datatype */
+ if(H5Tclose(arr_type)<0) {
+ printf("error closing array datatype.\n");
+ free(image_data);
+ free(h5cimage_name);
+ H5Pclose(create_plist);
+ return FAIL;
+ }
+ }
h5d_sid = H5Screate_simple(2,h5dims,NULL);
if(h5d_sid < 0) {
diff --git a/tools/h4toh5vdata.c b/tools/h4toh5vdata.c
index b078791..25624a5 100644
--- a/tools/h4toh5vdata.c
+++ b/tools/h4toh5vdata.c
@@ -675,7 +675,7 @@ int gen_h5comptype(int32 vdata_id,int32 nfields,
size_t fil_offset;
size_t mem_offset;
size_t fieldsizef;
- size_t fielddim[1];
+ hsize_t fielddim[1];
hid_t h5str_type;
int check_ifstr;/* flag to check if the h5 type is string.*/
int i;
@@ -754,19 +754,42 @@ int gen_h5comptype(int32 vdata_id,int32 nfields,
}
else {
+ hid_t arr_type; /* Array datatype for inserting fields */
- if(H5Tinsert_array(h5_ctype,fieldname,fil_offset,1,fielddim,
- NULL,sh5type[i])<0) {
+ /* Create array datatype */
+ if((arr_type=H5Tarray_create(sh5type[i],1,fielddim,NULL))<0) {
+ printf("error creating array datatype.\n");
+ return FAIL;
+ }
+
+ if(H5Tinsert(h5_ctype,fieldname,fil_offset,arr_type)<0) {
printf("error inserting array into hdf5 compound datatype. \n");
return FAIL;
}
- if(H5Tinsert_array(h5_cmemtype,fieldname,mem_offset,1,fielddim,
- NULL,sh5memtype[i])<0) {
+ /* Close array datatype */
+ if(H5Tclose(arr_type)<0) {
+ printf("error closing array datatype.\n");
+ return FAIL;
+ }
+
+ /* Create array datatype */
+ if((arr_type=H5Tarray_create(sh5memtype[i],1,fielddim,NULL))<0) {
+ printf("error creating array datatype.\n");
+ return FAIL;
+ }
+
+ if(H5Tinsert(h5_cmemtype,fieldname,fil_offset,arr_type)<0) {
printf("error inserting array into hdf5 compound datatype for memory. \n");
return FAIL;
}
+ /* Close array datatype */
+ if(H5Tclose(arr_type)<0) {
+ printf("error closing array datatype.\n");
+ return FAIL;
+ }
+
}
diff --git a/tools/h5toh4.c b/tools/h5toh4.c
index 7182f8a..5b72985 100644
--- a/tools/h5toh4.c
+++ b/tools/h5toh4.c
@@ -57,6 +57,7 @@ static int prefix_len = 1024;
static char *prefix;
static table_t *group_table, *dset_table, *type_table;
+static herr_t h5atomic_type_to_h4type(const hid_t h5type, hid_t* h5memtype, size_t* h5memsize, int32* h4type);
/*****************************************************************************
@@ -613,7 +614,7 @@ int32 dim_sizes[32], start[32], edges[32];
int ndims;
int ndimf;
hsize_t dims[32], maxdims[32];
-size_t dimf[4];
+hsize_t dimf[4];
int permf[4];
int32 hfile_id;
int32 sd_id;
@@ -774,6 +775,9 @@ int32 order_array[512];
case H5T_OPAQUE:
fprintf(stderr,"Warning: H5T_OPAQUE not yet implemented.\n");
break;
+ case H5T_ARRAY:
+ fprintf(stderr,"Warning: H5T_OPAQUE not yet implemented.\n");
+ break;
case H5T_COMPOUND:
if (ndims==1) {
if ((nmembers = H5Tget_nmembers(type)) <= 0 ) {
@@ -784,16 +788,44 @@ int32 order_array[512];
offset = 0;
for (idx=0;idx<nmembers;idx++) {
- if ((ndimf = H5Tget_member_dims(type, idx, dimf, permf)) < 0 || ndimf > 4 ) {
- fprintf(stderr, "Error: rank of members of compound type should not be %d\n",ndimf);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- return FAIL;
- }
if ((fieldtype = H5Tget_member_type(type, idx)) < 0 ) {
fprintf(stderr,"Error: H5 datasets of H5T_COMPOUND type with fieldtype %d, idx %d.\n",fieldtype,idx);
DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
break;
}
+ /* Special case for array fields */
+ if(H5Tget_class(fieldtype)==H5T_ARRAY) {
+ hid_t arr_base_type;
+
+ /* Get the number of dimensions */
+ if ((ndimf = H5Tget_array_ndims(fieldtype)) < 0 || ndimf > H5S_MAX_RANK ) {
+ fprintf(stderr, "Error: rank of members of compound type should not be %d\n",ndimf);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ return FAIL;
+ }
+ /* Get the dimensions and dimension permutations */
+ if (H5Tget_array_dims(fieldtype,dimf,permf) < 0) {
+ fprintf(stderr, "Error: cannot retrieve dimensions for array\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ return FAIL;
+ }
+ /* Get the 'real' field type */
+ if ((arr_base_type=H5Tget_super(fieldtype)) < 0) {
+ fprintf(stderr, "Error: cannot retrieve base type for array\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ return FAIL;
+ }
+ if (H5Tclose(fieldtype) < 0 ) {
+ fprintf(stderr,"Error: closing type\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ return FAIL;
+ }
+
+ /* Assign the array's base type as the field type for future use */
+ fieldtype=arr_base_type;
+ } /* end if */
+ else
+ ndimf=0;
#ifdef NEWWAY
if (FAIL==h5atomic_type_to_h4type(fieldtype, &mem_type, &typesize, &h4_type)){
fprintf(stderr, "Error: Problems translating h5 type to h4 type\n");
@@ -874,11 +906,36 @@ int32 order_array[512];
break;
}
for (idx=0;idx<nmembers;idx++) {
- if ((ndimf = H5Tget_member_dims(type, idx, dimf, permf)) < 0 || ndimf > 4 ) {
- fprintf(stderr, "Error: rank of members of compound type should not be %d\n",ndimf);
- DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
- return FAIL;
- }
+ /* Special case for array fields */
+ if(H5Tget_member_class(type,idx)==H5T_ARRAY) {
+ hid_t arr_type;
+
+ if ((arr_type = H5Tget_member_type(type, idx)) < 0 ) {
+ fprintf(stderr,"Error: H5 datasets of H5T_COMPOUND type with fieldtype %d, idx %d.\n",arr_type,idx);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ break;
+ }
+ /* Get the number of dimensions */
+ if ((ndimf = H5Tget_array_ndims(arr_type)) < 0 || ndimf > H5S_MAX_RANK ) {
+ fprintf(stderr, "Error: rank of members of compound type should not be %d\n",ndimf);
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ return FAIL;
+ }
+ /* Get the dimensions and dimension permutations */
+ if (H5Tget_array_dims(arr_type,dimf,permf) < 0) {
+ fprintf(stderr, "Error: cannot retrieve dimensions for array\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ return FAIL;
+ }
+ if (H5Tclose(arr_type) < 0 ) {
+ fprintf(stderr,"Error: closing type\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ return FAIL;
+ }
+ } /* end if */
+ else
+ ndimf=0;
+
if ((fieldname = H5Tget_member_name(type, idx)) == NULL ) {
fprintf(stderr, "Error: Unable to get fieldname for compound type %d, idx %d\n", type, idx);
DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
@@ -896,12 +953,26 @@ int32 order_array[512];
return FAIL;
}
} else {
- if ((status = H5Tinsert_array(type2,fieldname,offset_array[idx]+offset,ndimf,dimf,permf,
- memtype_array[idx])) != SUCCEED ) {
- fprintf(stderr, "Error: Problems inserting array field into compound datatype\n");
+ hid_t arr_type;
+
+ /* Create the array datatype */
+ if ((arr_type = H5Tarray_create(memtype_array[idx], ndimf, dimf, permf)) < 0 ) {
+ fprintf(stderr,"Error: cannot create array datatype\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ break;
+ }
+
+ if ((status = H5Tinsert(type2,fieldname,offset_array[idx]+offset,arr_type)) != SUCCEED ) {
+ fprintf(stderr, "Error: Problems inserting field into compound datatype\n");
DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
return FAIL;
}
+
+ if (H5Tclose(arr_type) < 0 ) {
+ fprintf(stderr,"Error: closing type\n");
+ DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
+ return FAIL;
+ }
}
if ((status = VSfdefine(vdata_id, fieldname, h4type_array[idx], order_array[idx])) != SUCCEED ) {
fprintf(stderr, "Error: Unable to set field %d\n", idx);
@@ -2104,7 +2175,7 @@ H5T_str_t strpad;
* Modifications:
*
*-----------------------------------------------------------------------*/
-herr_t h5atomic_type_to_h4type(const hid_t h5type, hid_t* h5memtype, size_t* h5memsize, int32* h4type)
+static herr_t h5atomic_type_to_h4type(const hid_t h5type, hid_t* h5memtype, size_t* h5memsize, int32* h4type)
{
H5T_class_t class;
size_t h5typesize, h4typesize;