summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorMuQun Yang <ymuqun@hdfgroup.org>2000-11-08 23:14:41 (GMT)
committerMuQun Yang <ymuqun@hdfgroup.org>2000-11-08 23:14:41 (GMT)
commita219b97a88ffbc8d1641b1a1de7897823e7716ae (patch)
tree3a886a5dbe741f76056fa06869a6894c3e11eca5 /tools
parent34b23b7dfab6cfdc6d38d05b8c5cf4dde60a2059 (diff)
downloadhdf5-a219b97a88ffbc8d1641b1a1de7897823e7716ae.zip
hdf5-a219b97a88ffbc8d1641b1a1de7897823e7716ae.tar.gz
hdf5-a219b97a88ffbc8d1641b1a1de7897823e7716ae.tar.bz2
[svn-r2839]
Purpose: check in beta release h4toh5 converter Description: 1. add copy right and other comments to all .h and .c files 2. fix bugs on sds unlimited dimension, hdf5 dimensional scale attribute and vdata translating from h4 to h5. Solution: 2. 1) for sds with unlimited dimension to be converted into extensible hdf5 dataset, on hdf5 side, has to set a default chunk size even though the corresponding hdf4 file is not chunked. 2) in this version, if sds object doesn't have dimensional scale data, we will not show the default hdf4 dimensional name ("fakedim0", etc.) in the new hdf5 dimensional scale name attribute. 3) fix a bug transferring vdata of which the field includes a character array. Make it correctly transfer into the corresponding hdf5 compound data type. Platforms tested: eirene,arabica,baldric,hawkwind,paz,gondolin on new set of hdf4 test files.
Diffstat (limited to 'tools')
-rw-r--r--tools/h4toh5anno.c46
-rw-r--r--tools/h4toh5image.c37
-rw-r--r--tools/h4toh5main.c143
-rw-r--r--tools/h4toh5main.h47
-rw-r--r--tools/h4toh5pal.c30
-rw-r--r--tools/h4toh5sds.c278
-rw-r--r--tools/h4toh5util.c147
-rw-r--r--tools/h4toh5util.h46
-rw-r--r--tools/h4toh5vdata.c91
-rw-r--r--tools/h4toh5vgroup.c49
10 files changed, 649 insertions, 265 deletions
diff --git a/tools/h4toh5anno.c b/tools/h4toh5anno.c
index 199d5f1..31ba145 100644
--- a/tools/h4toh5anno.c
+++ b/tools/h4toh5anno.c
@@ -1,3 +1,33 @@
+/*-------------------------------------------------------------------------
+ *
+ * Copyright (C) 2000 National Center for Supercomputing Applications.
+ * All rights reserved.
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/******************************************************************************
+
+ Description:
+
+1. converter
+
+See HDF4 to HDF5 mapping specification at
+(http://hdf.ncsa.uiuc.edu/HDF5/papers/h4toh5) for the default mapping
+from HDF4 object to HDF5 object.
+
+The whole converter includes 10 files, h4toh5util.h, h4toh5main.h, h4toh5util.c, h4toh5main.c, h4toh5sds.c, h4toh5image.c,h4toh5vdata.c,h4toh5vgroup.c,h4toh5pal.c and h4toh5anno.c.
+
+2. this file
+
+converting an hdf4 annotation into an hdf5 attribute of the corresponding object.
+
+
+Author: Kent Yang(ymuqun@ncsa.uiuc.edu)
+
+
+*****************************************************************************/
+
#include "h4toh5main.h"
@@ -101,7 +131,7 @@ int Annofil_h4_to_h5(int32 file_id,hid_t h5group){
return FAIL;
}
- if ((sh5str_type = mkstr(ann_length+1,H5T_STR_NULLTERM))<0) {
+ if ((sh5str_type = mkstr(ann_length+1,H5T_STR_SPACEPAD))<0) {
printf("error in making string at FILE lABEL ANNO. \n");
ANend(file_id);
ANendaccess(ann_id);
@@ -188,7 +218,7 @@ int Annofil_h4_to_h5(int32 file_id,hid_t h5group){
return FAIL;
}
- if ((sh5str1_type = mkstr(ann_length+1,H5T_STR_NULLTERM))<0) {
+ if ((sh5str1_type = mkstr(ann_length+1,H5T_STR_SPACEPAD))<0) {
printf("error in making string at FILE DESC. \n");
ANend(an_id);
ANendaccess(ann_id);
@@ -331,7 +361,7 @@ int Annoobj_h4_to_h5(int32 file_id,int32 obj_ref, int32 obj_tag,
return FAIL;
}
- if(num_lab_anno != 0) {
+ if(num_lab_anno > 0) {
for(i=0; i<num_lab_anno;i++) {
ann_id = ANselect(an_id,i,AN_DATA_LABEL);
@@ -366,7 +396,7 @@ int Annoobj_h4_to_h5(int32 file_id,int32 obj_ref, int32 obj_tag,
free(ann_buf);
return FAIL;
}
- /* printf("ann_buf %s\n",ann_buf);*/
+
status = ANendaccess(ann_id);
h5_sid = H5Screate(H5S_SCALAR);
@@ -380,7 +410,7 @@ int Annoobj_h4_to_h5(int32 file_id,int32 obj_ref, int32 obj_tag,
return FAIL;
}
- if ((sh5str_type = mkstr(ann_length+1,H5T_STR_NULLTERM))<0) {
+ if ((sh5str_type = mkstr(ann_length+1,H5T_STR_SPACEPAD))<0) {
printf("error in making string at OBJ LABEL. \n");
ANend(an_id);
free(lab_anno_list);
@@ -438,7 +468,7 @@ int Annoobj_h4_to_h5(int32 file_id,int32 obj_ref, int32 obj_tag,
}
}
- if(num_des_anno != 0) {
+ if(num_des_anno > 0) {
for (i = 0; i< num_des_anno;i++) {
@@ -469,7 +499,7 @@ int Annoobj_h4_to_h5(int32 file_id,int32 obj_ref, int32 obj_tag,
h4toh5_ZeroMemory(ann_buf,(ann_length+1)*sizeof(char));
ANreadann(ann_id,ann_buf,ann_length+1);
- if ((sh5str_type = mkstr(ann_length+1,H5T_STR_NULLTERM))<0) {
+ if ((sh5str_type = mkstr(ann_length+1,H5T_STR_SPACEPAD))<0) {
printf("error in making string at OBJECT DESC. \n");
ANend(an_id);
free(des_anno_list);
@@ -536,7 +566,7 @@ int Annoobj_h4_to_h5(int32 file_id,int32 obj_ref, int32 obj_tag,
ret = H5Sclose(h5_sid);
ret = H5Aclose(h5_aid);
free(ann_obj_name);
- /* printf("ann_buf %s\n",ann_buf);*/
+
free(ann_buf);
}
diff --git a/tools/h4toh5image.c b/tools/h4toh5image.c
index 373a854..f651ee9 100644
--- a/tools/h4toh5image.c
+++ b/tools/h4toh5image.c
@@ -1,3 +1,31 @@
+/*-------------------------------------------------------------------------
+ *
+ * Copyright (C) 2000 National Center for Supercomputing Applications.
+ * All rights reserved.
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/******************************************************************************
+
+ Description:
+
+1. converter
+
+See HDF4 to HDF5 mapping specification at
+(http://hdf.ncsa.uiuc.edu/HDF5/papers/h4toh5) for the default mapping
+from HDF4 object to HDF5 object.
+
+The whole converter includes 10 files, h4toh5util.h, h4toh5main.h, h4toh5util.c, h4toh5main.c, h4toh5sds.c, h4toh5image.c,h4toh5vdata.c,h4toh5vgroup.c,h4toh5pal.c and h4toh5anno.c.
+
+2. this file
+
+converting an hdf4 image object into an hdf5 dataset, for three component image, this object will be converted into an hdf5 dataset with compound data type.
+
+Author: Kent Yang(ymuqun@ncsa.uiuc.edu)
+
+
+*****************************************************************************/
#include "h4toh5main.h"
@@ -120,7 +148,7 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
return FAIL;
}
- /* obtaining absolute path of image name.*/
+ /* obtaining absolute path of image name.*/
check_imagename = -10;
h5cimage_name = get_name(gr_ref,2*num_images,gr_hashtab,&check_imagename);
@@ -222,8 +250,7 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
H5Pclose(create_plist);
return FAIL;
}
-
- /* if(h4size != h4memsize) printf("h4size/h4memsize %d\n",h4size/h4memsize);*/
+
fielddim[0] = ncomp;
@@ -634,14 +661,14 @@ int gr_tranattrs(int32 sri_id, hid_t sh5_dset,int snum_grattrs,
return FAIL;
}
- if ((sh5str_type = mkstr(count_sgradata*sh4_asize,H5T_STR_NULLTERM))<0){
+ if ((sh5str_type = mkstr(count_sgradata*sh4_asize,H5T_STR_SPACEPAD))<0){
printf("error in making string for image attribute \n");
return FAIL;
}
/* check this line later. */
if ((sh5str_memtype = mkstr(count_sgradata*sh4_amemsize,
- H5T_STR_NULLTERM))<0){
+ H5T_STR_SPACEPAD))<0){
printf("error in making memory string. \n");
return FAIL;
}
diff --git a/tools/h4toh5main.c b/tools/h4toh5main.c
index de51554..abf3d89 100644
--- a/tools/h4toh5main.c
+++ b/tools/h4toh5main.c
@@ -1,4 +1,35 @@
-/*** This file is the main program of converter. ***/
+/*-------------------------------------------------------------------------
+ *
+ * Copyright (C) 2000 National Center for Supercomputing Applications.
+ * All rights reserved.
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/******************************************************************************
+
+ Description:
+
+1. converter
+
+See HDF4 to HDF5 mapping specification at
+(http://hdf.ncsa.uiuc.edu/HDF5/papers/h4toh5) for the default mapping
+from HDF4 object to HDF5 object.
+
+The whole converter includes 10 files, h4toh5util.h, h4toh5main.h, h4toh5util.c, h4toh5main.c, h4toh5sds.c, h4toh5image.c,h4toh5vdata.c,h4toh5vgroup.c,h4toh5pal.c and h4toh5anno.c.
+
+2. this file
+
+This file describes the main driver of hdf to hdf5 converter. It checks
+the inputting parameters, initializes the global tables, sets up the root level
+hdf5 structure and also check the special case fof vgroup loops at HDF file.
+
+
+Author: Kent Yang(ymuqun@ncsa.uiuc.edu)
+
+
+*****************************************************************************/
+
#include "h4toh5main.h"
@@ -37,14 +68,13 @@ int main(int argc, char ** argv) {
char *h5_extension;
int status = 0;
-
argc--;
argv++;
if (argc == 0) {
fprintf(stderr,"\nError: Invalid Arguments\n");
PrintOptions_h4toh5();
- return -1;
+ return FAIL;
}
/* take care -h (help) option first */
@@ -52,7 +82,7 @@ int main(int argc, char ** argv) {
for (i=0; i < argc; i++)
if ( HDstrcmp(argv[i],"-h") == 0 ) {
PrintOptions_h4toh5();
- return 0;
+ return SUCCEED;
}
}
@@ -79,6 +109,14 @@ int main(int argc, char ** argv) {
break;
}
+ /*0. check whether this file is an hdf file. */
+
+ if(!Hishdf(h4_filename)){
+ printf("error: not an hdf file. \n");
+ printf("the file will not be converted. \n");
+ status = -1;
+ break;
+ }
h5_extension = HDstrdup("h5");
h5_filename = BuildFilename(h4_filename,h5_extension);
if (h5_filename == NULL) {
@@ -94,15 +132,6 @@ int main(int argc, char ** argv) {
break;
}
- /*0. check whether this file is a hdf file. */
-
- if(!Hishdf(h4_filename)){
- printf("error: not an hdf file. \n");
- printf("the file will not be converted. \n");
- return FAIL;
- }
-
-
status = h4toh5(h4_filename, h5_filename);
if ( status == FAIL ) {
@@ -115,7 +144,8 @@ int main(int argc, char ** argv) {
break;
- case 2: /* h5toh4 file_in file_out */
+ case 2: /* h4toh5 file_in file_out */
+
h4_filename = argv[0];
h5_filename = argv[1];
@@ -132,25 +162,27 @@ int main(int argc, char ** argv) {
break;
}
+ /*0. check whether this file is a hdf file. */
+
+ if(!Hishdf(h4_filename)){
+ printf("error: not an hdf file. \n");
+ printf("the file will not be converted. \n");
+ status = -1;
+ break;
+ }
+
if (test_file(h5_filename,O_CREAT|O_RDWR,436) != 0) { /* 436 Decimal - 0664 Octal, ug+rw,o+r */
printf("permission of hdf5 file is not set properly.\n");
status = -1;
break;
}
+
if (test_dir(h4_filename) != 0 ) {
fprintf(stderr,"%s: Is a directory\n",h4_filename);
status = -1;
break;
}
- /*0. check whether this file is a hdf file. */
-
- if(!Hishdf(h4_filename)){
- printf("error: not an hdf file. \n");
- printf("the file will not be converted. \n");
- return FAIL;
- }
-
status = h4toh5(h4_filename, h5_filename);
if ( status == FAIL ) {
printf("error in converting %sinto %s\n",h4_filename,h5_filename);
@@ -191,9 +223,6 @@ int h4toh5(char*filename4, char*filename5) {
hid_t h5_dimg;/* hdf5 dimensional scale group identifier. */
hid_t h5_palg;/* hdf5 palette group identifier. */
-
-
-
/*1. open the current hdf4 file. */
file_id = Hopen(filename4, DFACC_READ, 0);
@@ -381,7 +410,8 @@ int h4toh5(char*filename4, char*filename5) {
/*** deal with untouched sds objects.convert them into hdf5 datasets under root group.***/
if(h4toh5unvisitedsds(file_id,sd_id,h5_root,h5_dimg) == FAIL) {
- printf("error in converting unvisited sds objects into hdf5 file.\n"); SDend(sd_id);
+ printf("error in converting unvisited sds objects into hdf5 file.\n");
+ SDend(sd_id);
GRend(gr_id);
Vend(file_id);
Hclose(file_id);
@@ -462,7 +492,6 @@ int get_numof_hdf4obj(char*filename,int32 file_id) {
return FAIL;
}
-
/* obtain number of images and number of global image attributes.*/
gr_id = GRstart(file_id);
@@ -575,7 +604,7 @@ int set_helpgroups(hid_t h5root,hid_t* h5dimgptr,hid_t* h5palgptr){
*/
int set_hashtables(void) {
- if(num_sds != 0) {
+ if(num_sds > 0) {
sds_hashtab = malloc(sizeof(struct table)*2*num_sds);
if(init_tab(2*num_sds,sds_hashtab)== FAIL){
printf("cannot initialize sds hashing table. \n");
@@ -583,7 +612,7 @@ int set_hashtables(void) {
}
}
- if(num_images != 0) {
+ if(num_images > 0) {
gr_hashtab = malloc(sizeof(struct table)*2*num_images);
if(init_tab(2*num_images,gr_hashtab) == FAIL){
printf("cannot initialize image hashing table. \n");
@@ -593,7 +622,7 @@ int set_hashtables(void) {
/*hashtable is made to be fixed for dimensional scale and palette.*/
- if(num_sds != 0) {
+ if(num_sds > 0) {
dim_hashtab = malloc(sizeof(struct name_table)*DIM_HASHSIZE);
if(init_nametab(DIM_HASHSIZE,dim_hashtab) == FAIL) {
printf("can not initialize dimension hashing table.\n");
@@ -602,7 +631,7 @@ int set_hashtables(void) {
}
/* initialize the palette table */
- if(num_images != 0){
+ if(num_images > 0){
pal_hashtab = malloc(sizeof(struct table)*PAL_HASHSIZE);
if(init_tab(PAL_HASHSIZE,pal_hashtab) == FAIL) {
printf("can not initialize palette hashing table.\n");
@@ -699,6 +728,10 @@ int h4toh5lonevgs(int32 file_id,int32 sd_id,hid_t h5group,hid_t h5_dimg,hid_t h5
/* obtain object reference array. */
+ /* if no lone vgroup, quit from this function. */
+ if(num_lonevg == 0)
+ return SUCCEED;
+
ref_array = (int32 *)malloc(sizeof(int32) *num_lonevg);
if(ref_array == NULL) {
@@ -783,7 +816,7 @@ int h4toh5lonevgs(int32 file_id,int32 sd_id,hid_t h5group,hid_t h5_dimg,hid_t h5
return FAIL;
}
- /* printf("h5cgroup_name %s\n",h5cgroup_name);*/
+ /* free memory of corrected name. */
free(cor_vgroupname);
/* updating lookup table for vgroups.*/
@@ -803,7 +836,7 @@ int h4toh5lonevgs(int32 file_id,int32 sd_id,hid_t h5group,hid_t h5_dimg,hid_t h5
}
}
- /* this line is for debugging. */
+ /* this line should never fail, if failed, something is wrong with converter or hdf library. */
if(check_vgroup == 1){
fprintf(stderr,"this vgroup should not be touched. \n");
@@ -993,7 +1026,7 @@ int h4toh5vgrings(int32 file_id,int32 sd_id,hid_t h5group,hid_t h5_dimg,hid_t h5
Vdetach(vgroup_id);
free(h5cgroup_name);
- }
+ }
ref_num = Vgetid(file_id,ref_num);
}
return SUCCEED;
@@ -1044,6 +1077,7 @@ int h4toh5lonevds(int32 file_id, hid_t h5group){
ref_vdata_array = (int32 *)malloc(sizeof(int32) *(num_lonevd));
num_lonevd = VSlone(file_id,ref_vdata_array,num_lonevd);
+
if(num_lonevd == FAIL) {
printf("error in obtaining lone vdata number the second time.\n");
free(ref_vdata_array);
@@ -1124,6 +1158,8 @@ int h4toh5lonevds(int32 file_id, hid_t h5group){
free(cor_vdataname);
check_vdata = lookup(ref_vdata_array[lone_vd_number],estnum_vd,
vd_hashtab);
+
+ /* check_vdata should be 1, if it is 1, either converter or hdf lib has bugs. */
if(check_vdata == 1){
printf("lone vdata should not be checked before.\n");
free(h5cvdata_name);
@@ -1210,7 +1246,7 @@ int h4toh5unvisitedsds(int32 file_id,int32 sd_id,hid_t h5root,hid_t h5_dimg) {
return FAIL;
}
- /* if this sds is dimensional scale, the converting should be ignored. */
+ /* if this sds is dimensional scale, the converting should be ignored. dimensional scale will be converted separately. */
if(SDiscoordvar(sds_id)) continue;
/* obtain sds information. */
@@ -1246,7 +1282,7 @@ int h4toh5unvisitedsds(int32 file_id,int32 sd_id,hid_t h5root,hid_t h5_dimg) {
if(check_sds == 0) {
/* since different hdf sds may hold the same name and it is also
legal that sds may not have a name; but for hdf5 dataset,
- it must hold a name, so we will use get_obj_aboname to guarrtte
+ it must hold a name, so we will use get_obj_aboname to assure
that each new hdf5 dataset converted from
sds objects will have a disabiguous name. */
@@ -1257,6 +1293,7 @@ int h4toh5unvisitedsds(int32 file_id,int32 sd_id,hid_t h5root,hid_t h5_dimg) {
SDendaccess(sds_id);
return FAIL;
}
+
h5csds_name = get_obj_aboname(cor_sdsname,refstr,NULL,HDF4_SDS);
if(h5csds_name == NULL) {
printf("error in obtaining sds name.\n");
@@ -1281,8 +1318,10 @@ int h4toh5unvisitedsds(int32 file_id,int32 sd_id,hid_t h5root,hid_t h5_dimg) {
return FAIL;
}
free(h5csds_name);
+
}
SDendaccess(sds_id);
+
}
return SUCCEED;
}
@@ -1305,6 +1344,7 @@ int h4toh5unvisitedsds(int32 file_id,int32 sd_id,hid_t h5root,hid_t h5_dimg) {
Modification:
*-------------------------------------------------------------------------
*/
+
int h4toh5unvisitedimages(int32 file_id,hid_t h5_root,hid_t h5_palg) {
int i;
@@ -1443,12 +1483,7 @@ void free_allhashmemory(){
}
-void PrintOptions_h4toh5(void)
-{
- fprintf(stderr,"\nh4toh5 -h (gives this print-out)\n");
- fprintf(stderr,"h4toh5 file.hdf file.h5\n");
- fprintf(stderr,"h4toh5 file.hdf\n");
-}
+
/********The following routines are adapted from h5toh4 converter. *******/
/*****************************************************************************
@@ -1553,3 +1588,27 @@ char *BuildFilename(char *filename, char *ext)
}
+/*****************************************************************************
+
+ Routine: PrintOptions_h4toh5()
+
+ Description: This routine prints the acceptable argument formats out to stderr.
+
+ Input: None
+
+ Output: output to stderr
+
+*****************************************************************************/
+
+void PrintOptions_h4toh5(void)
+{
+ fprintf(stderr,"\nUsage: ");
+ fprintf(stderr,"\n h4toh5 -h (gives this print-out)\n");
+ fprintf(stderr," h4toh5 input.hdf output.h5\n");
+ fprintf(stderr," h4toh5 input.hdf\n");
+}
+
+
+
+
+
diff --git a/tools/h4toh5main.h b/tools/h4toh5main.h
index bac5baf..2bb6c88 100644
--- a/tools/h4toh5main.h
+++ b/tools/h4toh5main.h
@@ -1,3 +1,33 @@
+/*-------------------------------------------------------------------------
+ *
+ * Copyright (C) 2000 National Center for Supercomputing Applications.
+ * All rights reserved.
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/******************************************************************************
+
+Description:
+
+1. converter
+
+See HDF4 to HDF5 mapping specification at
+(http://hdf.ncsa.uiuc.edu/HDF5/papers/h4toh5) for the default mapping
+from HDF4 object to HDF5 object.
+
+The whole converter includes 10 files, h4toh5util.h, h4toh5main.h, h4toh5util.c, h4toh5main.c, h4toh5sds.c, h4toh5image.c,h4toh5vdata.c,h4toh5vgroup.c,h4toh5pal.c and h4toh5anno.c.
+
+2. this file
+
+including declarations of subroutines of all .c files excluding h4toh5util.c.
+
+Author: Kent Yang(ymuqun@ncsa.uiuc.edu)
+
+
+*****************************************************************************/
+
+
#ifndef H4TOH5MAIN_H
#define H4TOH5MAIN_H
#include "hdf.h"
@@ -6,13 +36,26 @@
#include "h4toh5util.h"
#include <fcntl.h>
#include <errno.h>
+#endif
+
+/* For windows support.*/
+#if WIN32
+typedef unsigned int mode_t;
+#endif
+
+#ifndef S_ISDIR
+#define S_ISDIR(mode) (((mode)&0xF000) == S_IFDIR)
+#endif
+
+/* subroutines to check initial settings and inputting parameters.
+Adapted from h5toh4 tools and used for h4toh5main.c */
-/* subroutines adapted from h5toh4 tools and used for h4toh5main.c */
void PrintOptions_h4toh5(void);
int test_file(char *filename,int oflag,mode_t mode);
int test_dir(char *);
char *BuildFilename(char *filename, char *ext);
+/* subroutines for h4toh5main.c */
int h4toh5(char*,char*);
int get_numof_hdf4obj(char*,int32);
int set_hashtables(void);
@@ -57,7 +100,7 @@ int Annoobj_h4_to_h5(int32,int32,int32,hid_t);
/*subroutines for h4toh5pal.c*/
int Palette_h4_to_h5(int32,int32 ,hid_t,char *);
-#endif
+
diff --git a/tools/h4toh5pal.c b/tools/h4toh5pal.c
index fc59cce..9fc1ec7 100644
--- a/tools/h4toh5pal.c
+++ b/tools/h4toh5pal.c
@@ -1,3 +1,31 @@
+/*-------------------------------------------------------------------------
+ *
+ * Copyright (C) 2000 National Center for Supercomputing Applications.
+ * All rights reserved.
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/******************************************************************************
+
+ Description:
+
+1. converter
+
+See HDF4 to HDF5 mapping specification at
+(http://hdf.ncsa.uiuc.edu/HDF5/papers/h4toh5) for the default mapping
+from HDF4 object to HDF5 object.
+
+The whole converter includes 10 files, h4toh5util.h, h4toh5main.h, h4toh5util.c, h4toh5main.c, h4toh5sds.c, h4toh5image.c,h4toh5vdata.c,h4toh5vgroup.c,h4toh5pal.c and h4toh5anno.c.
+
+2. this file
+
+Converting an hdf4 palette object into a hdf5 dataset.
+Author: Kent Yang(ymuqun@ncsa.uiuc.edu)
+
+
+*****************************************************************************/
+
#include "h4toh5main.h"
@@ -62,7 +90,7 @@ int Palette_h4_to_h5(int32 file_id,int32 pal_id,hid_t h5g,char*pal_name) {
uint8. */
if (h5type == H5T_STRING) {
- if(h5string_to_int(DFNT_UCHAR8,&h5memtype,h4memsize,&h5type)==FAIL) {
+ if(h5string_to_int(pal_type,&h5memtype,h4memsize,&h5type)==FAIL) {
fprintf(stderr,"failed to translate H5T_STRING to int8.");
return FAIL;
}
diff --git a/tools/h4toh5sds.c b/tools/h4toh5sds.c
index 265ea55..6c07724 100644
--- a/tools/h4toh5sds.c
+++ b/tools/h4toh5sds.c
@@ -1,5 +1,33 @@
-#include "h4toh5main.h"
+/*-------------------------------------------------------------------------
+ *
+ * Copyright (C) 2000 National Center for Supercomputing Applications.
+ * All rights reserved.
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/******************************************************************************
+
+ Description:
+
+1. converter
+
+See HDF4 to HDF5 mapping specification at
+(http://hdf.ncsa.uiuc.edu/HDF5/papers/h4toh5) for the default mapping
+from HDF4 object to HDF5 object.
+
+The whole converter includes 10 files, h4toh5util.h, h4toh5main.h, h4toh5util.c, h4toh5main.c, h4toh5sds.c, h4toh5image.c,h4toh5vdata.c,h4toh5vgroup.c,h4toh5pal.c and h4toh5anno.c.
+
+2. this file
+
+Converting an hdf4 sds object into an hdf5 dataset.
+
+Author: Kent Yang(ymuqun@ncsa.uiuc.edu)
+
+*****************************************************************************/
+
+#include "h4toh5main.h"
/*-------------------------------------------------------------------------
* Function: Sds_h4_to_h5
@@ -15,7 +43,8 @@
dim_pathname: dimensional path name
*-------------------------------------------------------------------------
- */
+ */
+
int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){
int32 sds_dtype;
@@ -26,6 +55,7 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){
int32* sds_stride;
int32 count_sdsdata;
int32 sds_ref;
+ intn sds_empty;
int32 istat;
int i;
int32 num_sdsattrs;
@@ -39,7 +69,7 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){
size_t h4size;
size_t h4memsize;
HDF_CHUNK_DEF c_def_out;
- int32* chunk_dims;
+ hsize_t* chunk_dims;
int32 c_flags;
/* define varibles for hdf5. */
@@ -50,21 +80,21 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){
hid_t h5_memtype;
hid_t create_plist;
hsize_t h5dims[MAX_VAR_DIMS];
+ hsize_t max_h5dims[MAX_VAR_DIMS];
char* h5csds_name;
herr_t ret;
/* check whether the sds is empty. */
-#if 0
- if(SDcheckempty(sds_id,&empty)== FAIL) {
+
+ if(SDcheckempty(sds_id,&sds_empty)== FAIL) {
printf("error in running SDcheckempty routine. \n");
return FAIL;
}
- printf("empty %d\n",empty);
- if(empty != 0) return SUCCEED;
-#endif
+ if(sds_empty != 0) return SUCCEED;
+
/*check whether the sds is created with unlimited dimension. */
@@ -73,24 +103,12 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){
return FAIL;
}
- if(SDisrecord(sds_id)) {
- if (SDgetinfo(sds_id,sdsname,&sds_rank,sds_dimsizes,&sds_dtype,
- &num_sdsattrs)==FAIL) {
- printf("unable to get information of sds h5dset.\n");
- return FAIL;
- }
-
- }
- else {
/*obtain name,rank,dimsizes,datatype and num of attributes of sds */
if (SDgetinfo(sds_id,sdsname,&sds_rank,sds_dimsizes,&sds_dtype,
&num_sdsattrs)==FAIL) {
printf("unable to get information of sds h5dset.\n");
return FAIL;
}
- }
-
- /* if(sdsname !=NULL) printf("sdsname %s\n",sdsname);*/
/* obtain start,edge, stride and number of sds data. */
@@ -124,9 +142,12 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){
}
- for (i=0;i<sds_rank;i++)
+ for (i=0;i<sds_rank;i++) {
h5dims[i] = sds_edge[i]-sds_start[i];
-
+ max_h5dims[i] = h5dims[i];
+ }
+ if(SDisrecord(sds_id)) max_h5dims[0] = H5S_UNLIMITED;
+
/* convert hdf4 data type to hdf5 data type. */
if (h4type_to_h5type(sds_dtype,&h5_memtype,&h4memsize,&h4size,
&h5ty_id) == FAIL) {
@@ -142,7 +163,6 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){
if (h5ty_id == H5T_STRING) {
/* rechange string datatype into numerical datatype.*/
-
if(h5string_to_int(sds_dtype,&h5_memtype,h4memsize,
&h5ty_id)== FAIL) {
printf("error in translating H5T_STRING to int.\n");
@@ -152,8 +172,7 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){
return FAIL;
}
}
-
-
+
sds_data = malloc(h4memsize*count_sdsdata);
if(sds_data == NULL) {
printf("error in allocating memory. \n");
@@ -188,7 +207,6 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){
}
h5csds_name = get_name(sds_ref,2*num_sds,sds_hashtab,&check_sdsname);
-
if (h5csds_name == NULL && check_sdsname == 0 ) {
free(sds_start);
free(sds_edge);
@@ -216,7 +234,7 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){
return FAIL;
}
- h5d_sid = H5Screate_simple(sds_rank,h5dims,NULL);
+ h5d_sid = H5Screate_simple(sds_rank,h5dims,max_h5dims);
if (h5d_sid < 0) {
printf("failed to create hdf5 data space converted from SDS. \n");
@@ -230,15 +248,38 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){
/* create property list. */
create_plist = H5Pcreate(H5P_DATASET_CREATE);
- chunk_dims = malloc(4*sds_rank);
+ chunk_dims = malloc(sizeof(hsize_t)*sds_rank);
+
+ /* if the sds is not chunked, but with unlimited dimension, we have to
+ provide a chunk size for the corresponding hdf5 dataset. we will choose
+ 1/2 dimension size right now. */
+
+ if(c_flags == HDF_NONE && SDisrecord(sds_id))
+ {
+ for(i=0;i<sds_rank;i++){
+ chunk_dims[i] = (hsize_t)(h5dims[i]/2);
+ }
+ if(H5Pset_chunk(create_plist, sds_rank, chunk_dims)<0) {
+ printf("failed to set up chunking information for ");
+ printf("property list.\n");
+ free(sds_start);
+ free(sds_edge);
+ free(sds_stride);
+ free(sds_data);
+ free(chunk_dims);
+ H5Sclose(h5d_sid);
+ H5Pclose(create_plist);
+ return FAIL;
+ }
+ }
if(c_flags == HDF_CHUNK || c_flags == (HDF_CHUNK | HDF_COMP)
|| c_flags == (HDF_CHUNK | HDF_NBIT) ){
for(i=0;i<sds_rank;i++)
- chunk_dims[i] = c_def_out.chunk_lengths[i];
+ chunk_dims[i] = (hsize_t)c_def_out.chunk_lengths[i];
- if(H5Pset_chunk(create_plist, sds_rank, (hsize_t *)chunk_dims)<0) {
+ if(H5Pset_chunk(create_plist, sds_rank, chunk_dims)<0) {
printf("failed to set up chunking information for ");
printf("property list.\n");
free(sds_start);
@@ -251,14 +292,17 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){
return FAIL;
}
}
+
+
h5dset = H5Dcreate(h5_group,h5csds_name,h5ty_id,h5d_sid,create_plist);
-
+
if (h5dset < 0) {
printf("failed to create hdf5 dataset converted from SDS. \n");
free(sds_start);
free(sds_edge);
free(sds_stride);
free(sds_data);
+ free(chunk_dims);
H5Sclose(h5d_sid);
H5Pclose(create_plist);
return FAIL;
@@ -274,7 +318,8 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){
free(sds_start);
free(sds_edge);
free(sds_stride);
- free(sds_data);
+ free(sds_data);
+ free(chunk_dims);
return FAIL;
}
@@ -293,6 +338,7 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){
free(sds_edge);
free(sds_stride);
free(sds_data);
+ free(chunk_dims);
H5Sclose(h5d_sid);
H5Dclose(h5dset);
H5Pclose(create_plist);
@@ -305,6 +351,7 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){
free(sds_edge);
free(sds_stride);
free(sds_data);
+ free(chunk_dims);
H5Sclose(h5d_sid);
H5Dclose(h5dset);
H5Pclose(create_plist);
@@ -317,6 +364,7 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){
free(sds_edge);
free(sds_stride);
free(sds_data);
+ free(chunk_dims);
H5Sclose(h5d_sid);
H5Dclose(h5dset);
H5Pclose(create_plist);
@@ -330,6 +378,7 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){
free(sds_edge);
free(sds_stride);
free(sds_data);
+ free(chunk_dims);
H5Sclose(h5d_sid);
H5Dclose(h5dset);
H5Pclose(create_plist);
@@ -341,6 +390,7 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){
free(sds_edge);
free(sds_stride);
free(sds_data);
+ free(chunk_dims);
H5Sclose(h5d_sid);
H5Dclose(h5dset);
H5Pclose(create_plist);
@@ -359,6 +409,7 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){
free(sds_edge);
free(sds_stride);
free(sds_data);
+ free(chunk_dims);
H5Sclose(h5d_sid);
H5Dclose(h5dset);
H5Pclose(create_plist);
@@ -372,6 +423,7 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){
free(sds_edge);
free(sds_stride);
free(sds_data);
+ free(chunk_dims);
H5Sclose(h5d_sid);
H5Dclose(h5dset);
H5Pclose(create_plist);
@@ -385,22 +437,23 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){
free(sds_edge);
free(sds_stride);
free(sds_data);
+ free(chunk_dims);
H5Sclose(h5d_sid);
H5Dclose(h5dset);
H5Pclose(create_plist);
printf("unable to transfer sds ref. to HDF5 dataset attribute.\n");
return FAIL;
}
-
+
istat = SDendaccess(sds_id);
ret = H5Pclose(create_plist);
ret = H5Sclose(h5d_sid);
ret = H5Dclose(h5dset);
- free(h5csds_name);
free(sds_data);
free(sds_start);
free(sds_edge);
free(sds_stride);
+ free(chunk_dims);
return SUCCEED;
}
@@ -458,7 +511,6 @@ int sds_transattrs(int32 ssds_id, hid_t sh5_dset,int snum_sdsattrs,
printf("fail to translate sds attribute data type from H4 to H5. \n");
return FAIL;
}
-
ssds_adata = malloc(sh4_amemsize * count_ssdsadata);
if(ssds_adata == NULL) {
@@ -503,7 +555,7 @@ int sds_transattrs(int32 ssds_id, hid_t sh5_dset,int snum_sdsattrs,
}
if ((sh5str_type = mkstr(count_ssdsadata,
- H5T_STR_NULLTERM))<0) {
+ H5T_STR_SPACEPAD))<0) {
printf("error in making string. \n");
H5Sclose(sh5a_sid);
free(ssds_adata);
@@ -512,7 +564,7 @@ int sds_transattrs(int32 ssds_id, hid_t sh5_dset,int snum_sdsattrs,
/* check this line later. */
if ((sh5str_memtype = mkstr(count_ssdsadata*sh4_amemsize,
- H5T_STR_NULLTERM))<0) {
+ H5T_STR_SPACEPAD))<0) {
printf("error in making memory string. \n");
H5Sclose(sh5a_sid);
free(ssds_adata);
@@ -616,8 +668,8 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
int32 sds_dimscasize[1];
int32 istat;
int i;
- int j;
- int k;
+ int count_h5objref;/* this counter updates the number of h5 object reference. */
+ int count_h5attrname;/*this counter updates the number of h5 dimensional name attribute.*/
int check_gloattr;
int32 num_sdsdimattrs;
@@ -629,6 +681,9 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
size_t h4dim_memsize;
size_t h4dim_size;
+ HDF_CHUNK_DEF c_def_out;
+ int32 c_flags;
+
/* define varibles for hdf5. */
hid_t h5dim_dset;
@@ -645,12 +700,14 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
hid_t attr_refSpace;
hid_t attr_refType;
hid_t attribID;
+ hid_t create_plist;
hsize_t h5dimscas[1];
+ hsize_t max_h5dimscas[1];
hsize_t h5dim_dims[1];
hsize_t attr_refDims[1];
-
- hobj_ref_t dim_refdat;
+ hsize_t h5dim_chunkdim[1];
+ hobj_ref_t dim_refdat;
hobj_ref_t* alldim_refdat;
@@ -660,9 +717,19 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
char h5dimpath_name[MAX_DIM_NAME];
herr_t ret;
+ /*check whether the sds is created with unlimited dimension. */
+
+ if(SDgetchunkinfo(sds_id,&c_def_out, &c_flags)== FAIL) {
+ printf("error in getting chunking information. \n");
+ return FAIL;
+ }
+
+ /* initialize the dimensional number of sds dimensions, h5dim_dims
+ is used for grabbing hdf5 dimensional name list and object reference
+ list. */
h5dim_dims[0] = (hsize_t)sds_rank;
- j = 0;
- k = 0;
+ count_h5objref = 0;
+ count_h5attrname = 0;
for (i = 0; i<sds_rank;i++) {
@@ -672,7 +739,6 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
printf("error in obtaining sds dimension id. \n");
return FAIL;
}
-
istat = SDdiminfo(sdsdim_id,sdsdim_name,sds_dimscasize,
&sdsdim_type,&num_sdsdimattrs);
@@ -683,11 +749,8 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
return FAIL;
}
+ /* for unlimited sds dimension, grab the current dimensional size. */
if(sds_dimscasize[0] == 0) sds_dimscasize[0] = firstdimsize;
-
- /* if this sds has no dimensional scale data. skip it.*/
- /* if(sdsdim_type == 0) continue;*/
-
/* check whether this dimensional scale dataset is looked up. */
check_sdsdim = lookup_name(sdsdim_name,DIM_HASHSIZE,dim_hashtab);
@@ -703,6 +766,7 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
return FAIL;
}
+ /* generating hdf5 dimensional scale name. */
h5sdsdim_name = get_obj_aboname(cor_sdsdimname,NULL,h5dimpath_name,NULL);
if (h5sdsdim_name == NULL) {
printf("error in getting hdf5 sds dimension name.\n");
@@ -711,14 +775,22 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
return FAIL;
}
free(cor_sdsdimname);
- strcpy(&h5sdsdim_allname[k*MAX_DIM_NAME],h5sdsdim_name);
- /*if it is not touched, get name of the dimensional scale data. */
- if (check_sdsdim == 1){/* the dimension is touched. */
+ strcpy(&h5sdsdim_allname[count_h5attrname*MAX_DIM_NAME],h5sdsdim_name);
+
+ /* here we should add some comments for fakedim0--name. It seems that
+ hdf4(netcdf) will use unique fake dimension name, fakedim + unique
+ number, so check_sdsdim will never be 1 if the dimension name is fake
+ name. Under this case, j will not increase if this dimension doesnot
+ have dimensional scale data. That assures the object reference of sds is
+ correct. */
+
+ /*if this dimension is not touched, get name of the dimensional scale data. */
+ if (check_sdsdim == 1){/* the dimension is touched, skip this one.*/
free(h5sdsdim_name);
SDendaccess(sdsdim_id);
- j = j + 1;
- k = k + 1;
+ count_h5objref = count_h5objref + 1;
+ count_h5attrname = count_h5attrname + 1;
continue;
}
@@ -729,12 +801,12 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
return FAIL;
}
- /* if this sds has no dimensional scale data. skip it.*/
- if(sdsdim_type == 0) {
- k = k + 1;
-
+ /* if this sds dimension has no dimensional scale data. skip it.*/
+ if(sdsdim_type == 0)
continue;
- }
+
+
+ /* get h5 dimensional scale data type. */
if(h4type_to_h5type(sdsdim_type,&h5dim_memtype,&h4dim_memsize,
&h4dim_size,&h5dim_tid)== FAIL) {
printf("error in transferring sds dimension data type.\n");
@@ -756,6 +828,7 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
}
}
+ /* get the dimensional scale data. */
dim_scadata = malloc(h4dim_memsize*sds_dimscasize[0]);
istat = SDgetdimscale(sdsdim_id,(VOIDP)dim_scadata);
@@ -766,9 +839,17 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
free(dim_scadata);
return FAIL;
}
-
- h5dimscas[0] = sds_dimscasize[0];
- h5dim_sid = H5Screate_simple(1,h5dimscas,NULL);
+
+ /* set dimensional scale size properly. */
+ h5dimscas[0] = sds_dimscasize[0];
+
+ /* only set for the first dimension if SDS is unlimited dimension. */
+ if(SDisrecord(sds_id) && i == 0)
+ max_h5dimscas[0] = H5S_UNLIMITED;
+ else
+ max_h5dimscas[0] = h5dimscas[0];
+
+ h5dim_sid = H5Screate_simple(1,h5dimscas,max_h5dimscas);
if(h5dim_sid <0) {
printf("error in creating space. \n");
@@ -778,9 +859,56 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
return FAIL;
}
+ /* create property list, for chunked sds or unlimited dimension cases */
+
+ create_plist = H5Pcreate(H5P_DATASET_CREATE);
+
+ if(create_plist == -1) {
+ printf("failed to create property list. \n");
+ SDendaccess(sdsdim_id);
+ free(h5sdsdim_name);
+ free(dim_scadata);
+ H5Sclose(h5dim_sid);
+ }
+
+
+ if(c_flags == HDF_NONE && SDisrecord(sds_id) && i == 0)
+ {
+ h5dim_chunkdim[0] = (hsize_t)(h5dimscas[0]/2);
+
+ if(H5Pset_chunk(create_plist,1, h5dim_chunkdim)<0) {
+ printf("failed to set up chunking information for ");
+ printf("dimensional scale property list.\n");
+ SDendaccess(sdsdim_id);
+ free(h5sdsdim_name);
+ free(dim_scadata);
+ H5Sclose(h5dim_sid);
+ H5Pclose(create_plist);
+ return FAIL;
+ }
+
+ }
+
+ if(c_flags == HDF_CHUNK || c_flags == (HDF_CHUNK | HDF_COMP)
+ || c_flags == (HDF_CHUNK | HDF_NBIT) ){
+
+ h5dim_chunkdim[0] = (hsize_t)c_def_out.chunk_lengths[0];
+
+ if(H5Pset_chunk(create_plist,1, h5dim_chunkdim)<0) {
+ printf("failed to set up chunking information for ");
+ printf("property list.\n");
+ SDendaccess(sdsdim_id);
+ free(h5sdsdim_name);
+ free(dim_scadata);
+ H5Sclose(h5dim_sid);
+ H5Pclose(create_plist);
+ return FAIL;
+ }
+ }
+
/* create h5 dataset under group HDF4_DIMG*/
h5dim_dset = H5Dcreate(sh5_dimgroup,h5sdsdim_name,h5dim_tid,
- h5dim_sid,H5P_DEFAULT);
+ h5dim_sid,create_plist);
if(h5dim_dset <0) {
printf("error in creating dataset. \n");
@@ -788,6 +916,7 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
free(dim_scadata);
SDendaccess(sdsdim_id);
H5Sclose(h5dim_sid);
+ H5Pclose(create_plist);
return FAIL;
}
@@ -798,6 +927,7 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
free(dim_scadata);
SDendaccess(sdsdim_id);
H5Sclose(h5dim_sid);
+ H5Pclose(create_plist);
H5Dclose(h5dim_dset);
return FAIL;
}
@@ -811,28 +941,30 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
SDendaccess(sdsdim_id);
H5Sclose(h5dim_sid);
H5Dclose(h5dim_dset);
+ H5Pclose(create_plist);
return FAIL;
}
SDendaccess(sdsdim_id);
free(dim_scadata);
free(h5sdsdim_name);
ret = H5Sclose(h5dim_sid);
- ret = H5Dclose(h5dim_dset);
- j = j + 1;
- k = k + 1;
+ ret = H5Dclose(h5dim_dset);
+ ret = H5Pclose(create_plist);
+ count_h5objref = count_h5objref + 1;
+ count_h5attrname =count_h5attrname + 1;
}
/*1. create object reference number to dimensional scale dataset.
2. store absolute name of dimensional name into
dimensional list. */
- if ( j != 0) {
+ if ( count_h5objref != 0) {
- h5dim_dims[0] = j;
- attr_refDims[0] = j;
+ h5dim_dims[0] = count_h5objref;
+ attr_refDims[0] = count_h5objref;
attr_refSpace = H5Screate_simple(1,attr_refDims,NULL);
attr_refType = H5Tcopy(H5T_STD_REF_OBJ);
- alldim_refdat = calloc(j,sizeof(hobj_ref_t));
+ alldim_refdat = calloc(count_h5objref,sizeof(hobj_ref_t));
if(alldim_refdat == NULL) {
printf("error in allocating memory. \n");
@@ -841,7 +973,7 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
return FAIL;
}
- for(i=0;i<j;i++){
+ for(i=0;i<count_h5objref;i++){
h4toh5_ZeroMemory(h5newsdsdim_name,MAX_DIM_NAME);
strcpy(h5newsdsdim_name,&h5sdsdim_allname[i*MAX_DIM_NAME]);
@@ -870,7 +1002,6 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
}
ret = H5Awrite(attribID,attr_refType,(void *)alldim_refdat);
-
H5Sclose(attr_refSpace);
H5Tclose(attr_refType);
@@ -878,7 +1009,8 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
free(alldim_refdat);
}
- if(k!=0) {
+ if(count_h5attrname!= 0) {
+
h5dim_namesid = H5Screate_simple(1,h5dim_dims,NULL);
if(h5dim_namesid <0) {
@@ -886,7 +1018,7 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
return FAIL;
}
- h5str_dimntype = mkstr(MAX_DIM_NAME,H5T_STR_NULLTERM);
+ h5str_dimntype = mkstr(MAX_DIM_NAME,H5T_STR_SPACEPAD);
if(h5str_dimntype < 0) {
H5Sclose(h5dim_namesid);
printf("error in generating H5T_STRING type.\n");
diff --git a/tools/h4toh5util.c b/tools/h4toh5util.c
index 4c76dd5..ea9c452 100644
--- a/tools/h4toh5util.c
+++ b/tools/h4toh5util.c
@@ -1,10 +1,40 @@
+/*-------------------------------------------------------------------------
+ *
+ * Copyright (C) 2000 National Center for Supercomputing Applications.
+ * All rights reserved.
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/******************************************************************************
+
+ Description:
+
+1. converter
+
+See HDF4 to HDF5 mapping specification at
+(http://hdf.ncsa.uiuc.edu/HDF5/papers/h4toh5) for the default mapping
+from HDF4 object to HDF5 object.
+
+The whole converter includes 10 files, h4toh5util.h, h4toh5main.h, h4toh5util.c, h4toh5main.c, h4toh5sds.c, h4toh5image.c,h4toh5vdata.c,h4toh5vgroup.c,h4toh5pal.c and h4toh5anno.c.
+
+2. this file
+
+including all routines that are useful for other files.
+
+Author: Kent Yang(ymuqun@ncsa.uiuc.edu)
+
+
+*****************************************************************************/
+
+
#include "h4toh5util.h"
/* Function h4toh5_ZeroMemory
-* Purpose: Zero out memory
-* return: None
-* In: size_t n(DWORD in windows)
+ Purpose: Zero out memory
+ return: None
+ In: size_t n(DWORD in windows)
void* s(PVOID in windows)
*/
void h4toh5_ZeroMemory(void*s,size_t n) {
@@ -19,17 +49,17 @@ void h4toh5_ZeroMemory(void*s,size_t n) {
* Function: h5string_to_int
*
* Purpose: This function will convert H5T_STRING into integer.
- This is for cases the user define the numerical datatype int8
- as DFNT_CHAR8 and DFNT_UCHAR8
+ This is a correction routine when the user define the
+ numerical datatype int8 as DFNT_CHAR8 and DFNT_UCHAR8
- * Errors: will return error message to the interface.
- * Return: FAIL if failed, SUCCEED if success.
+ * Errors: will return error message to the interface
+ * Return: FAIL if failed, SUCCEED if success
*
- * In : h4type: HDF4 datatype.
- h4memsize: the real memory size of h4type.
+ * In : h4type: HDF4 datatype
+ h4memsize: the real memory size of h4type
* Out: h5memtype: pointer of which value should be h5memtype(the real
- data type stored at the memory).
+ data type stored at the memory)
h5type: pointer of which value should be h5type(the hdf5
type stored at the disk).
*
@@ -53,6 +83,7 @@ int h5string_to_int(const int32 h4type, hid_t* h5memtype,
else if(h4memsize == H5Tget_size(H5T_NATIVE_LONG))
*h5memtype = H5T_NATIVE_LONG;
else return FAIL;
+ break;
case DFNT_UCHAR8:
@@ -66,6 +97,7 @@ int h5string_to_int(const int32 h4type, hid_t* h5memtype,
else if(h4memsize == H5Tget_size(H5T_NATIVE_LONG))
*h5memtype = H5T_NATIVE_ULONG;
else return FAIL;
+ break;
}
return SUCCEED;
}
@@ -149,7 +181,7 @@ int h4type_to_h5type(const int32 h4type, hid_t* h5memtype,
case DFNT_NINT8:
printf("warning, Native HDF datatype is encountered");
- printf(" the converting results may not be correct.\n");
+ printf(" the converting result may not be correct.\n");
*h4size = 1;
*h5type = H5T_NATIVE_SCHAR;
*h4memsize = sizeof(int8);
@@ -166,7 +198,7 @@ int h4type_to_h5type(const int32 h4type, hid_t* h5memtype,
case DFNT_NUINT8:
printf("warning, Native HDF datatype is encountered");
- printf(" the converting results may not be correct.\n");
+ printf(" the converting result may not be correct.\n");
*h4size = 1;
*h5type = H5T_NATIVE_UCHAR;
*h4memsize = sizeof(int8);
@@ -243,7 +275,7 @@ int h4type_to_h5type(const int32 h4type, hid_t* h5memtype,
case DFNT_NINT16:
printf("warning, Native HDF datatype is encountered");
- printf(" the converting results may not be correct.\n");
+ printf(" the converting result may not be correct.\n");
*h4size = 2;
*h5type = H5T_NATIVE_SHORT;
*h4memsize = sizeof(int16);
@@ -260,7 +292,7 @@ int h4type_to_h5type(const int32 h4type, hid_t* h5memtype,
case DFNT_NUINT16:
printf("warning, Native HDF datatype is encountered");
- printf(" the converting results may not be correct.\n");
+ printf(" the converting result may not be correct.\n");
*h4size = 2;
*h5type = H5T_NATIVE_USHORT;
*h4memsize = sizeof(int16);
@@ -337,7 +369,7 @@ int h4type_to_h5type(const int32 h4type, hid_t* h5memtype,
case DFNT_NINT32:
printf("warning, Native HDF datatype is encountered");
- printf(" the converting results may not be correct.\n");
+ printf(" the converting result may not be correct.\n");
*h4size = 4;
*h5type = H5T_NATIVE_INT;
*h4memsize = sizeof(int32);
@@ -436,7 +468,7 @@ int h4type_to_h5type(const int32 h4type, hid_t* h5memtype,
case DFNT_NFLOAT64:
printf("warning, Native HDF datatype is encountered");
- printf(" the converting results may not be correct.\n");
+ printf(" the converting result may not be correct.\n");
*h4size = 8;
*h5type = H5T_NATIVE_DOUBLE;
*h4memsize = sizeof(float64);
@@ -494,58 +526,13 @@ int conv_int_str(uint16 num, char* str_num) {
/* the maximum reference number is 65536. */
- int d0,d1,d2,d3,d4;
- int i;
-
if(str_num == NULL) {
printf(" memory for str_num should be allocated.\n");
return FAIL;
}
- for (i=0;i<5;i++)
- str_num[i] = '\0';
-
- if((num/10000)!=0) {
- d4 = num/10000;
- str_num[4]= (char)(d4+48);
- d3 = (num-d4*10000)/1000;
- str_num[3]= (char)(d3+48);
- d2 =(num-d4*10000-d3*1000)/100;
- str_num[2]= (char)(d2+48);
- d1 =(num-d4*10000-d3*1000-d2*100)/10;
- str_num[1] =(char)(d1+48);
- d0= num-d4*10000-d3*1000-d2*100-d1*10;
- str_num[0] =(char)(d0+48);
- }
-
- else if ((num/1000)!=0){
-
- d3 = num/1000;
- str_num[3] =(char)(d3+48);
- d2 =(num-d3*1000)/100;
- str_num[2]=(char)(d2+48);
- d1 =(num-d3*1000-d2*100)/10;
- str_num[1]=(char)(d1+48);
- d0 =num-d3*1000-d2*100-d1*10;
- str_num[0] =(char)(d0+48);
- }
- else if ((num/100)!=0){
-
- d2 =num/100;
- str_num[2]=(char)(d2+48);
- d1 =(num-d2*100)/10;
- str_num[1]=(char)(d1+48);
- d0 =num-d2*100-d1*10;
- str_num[0] =(char)(d0+48);
- }
- else if((num/10)!=0) {
- d1= num/10;
- str_num[1]=(char)(d1+48);
- d0 = num%10;
- str_num[0]=(char)(d0+48);
- }
- else
- str_num[0] =(char)(num+48);
+ sprintf(str_num,"%d",num);
+
return SUCCEED;
}
@@ -784,6 +771,10 @@ int lookup_name(char* name, int size,struct name_table *nametab) {
return -1;
}
+ if(nametab == NULL) {
+ printf("no name_table for this category of objects.\n");
+ return -1;
+ }
np = nametab+hash_fun(name,size);
temptr->name = malloc(strlen(name)+1);
@@ -1037,7 +1028,7 @@ int h4_transpredattrs(hid_t h5g,const char *attrname,char*data){
h5str_size = strlen(data);
- if ((h5str_type = mkstr(h5str_size,H5T_STR_NULLTERM))<0) {
+ if ((h5str_type = mkstr(h5str_size,H5T_STR_SPACEPAD))<0) {
printf("error in making string for predefined ATTR. \n");
return FAIL;
}
@@ -1150,7 +1141,7 @@ int vg_transattrs(int32 h4vg,hid_t h5g) {
/* now do attribute-transferring.
1. deal with string data type
- 2. set attribute space.
+ 2. set attribute space
3. get attribute name, set property list. */
if (sh5_atype == H5T_STRING ) {
@@ -1164,15 +1155,15 @@ int vg_transattrs(int32 h4vg,hid_t h5g) {
return FAIL;
}
- if ((sh5str_type = mkstr(count_vgattr*sh4_size,H5T_STR_NULLTERM))<0) {
+ if ((sh5str_type = mkstr(count_vgattr*sh4_size,H5T_STR_SPACEPAD))<0) {
fprintf(stderr,"error in making string for VGROUP ATTR. \n");
free(vg_adata);
return FAIL;
}
- /* check this line later. */
+
if ((sh5str_memtype = mkstr(count_vgattr*sh4_amemsize,
- H5T_STR_NULLTERM))<0){
+ H5T_STR_SPACEPAD))<0){
fprintf(stderr,"error in making memory string for VGROUP ATTR. \n");
free(vg_adata);
return FAIL;
@@ -1322,9 +1313,11 @@ char* get_obj_aboname(char* obj_name,char* refstr,char* path_name,
int check_name;
char check_char;
+
/* sometimes although the object name is not NULL, but it is empty.
We will use make_objname_no under this situation. */
if(obj_name != NULL) check_char = *obj_name;
+
/* obtain the absolute name of the object. */
if (obj_name == NULL || check_char == '\0')
abo_objname = make_objname_no(refstr,path_name,objstr);
@@ -1336,7 +1329,7 @@ char* get_obj_aboname(char* obj_name,char* refstr,char* path_name,
check_name = lookup_name(abo_objname,num_objects,name_hashtab);
if(check_name == 1) {
-
+ /* name_clashing is found. */
if(objstr != NULL && refstr != NULL){
free(abo_objname);
@@ -1370,6 +1363,7 @@ char* get_obj_aboname(char* obj_name,char* refstr,char* path_name,
}
}
}
+
return abo_objname;
}
@@ -1405,7 +1399,7 @@ char* make_objname_no(char* refstr,char* path_name,const char*objstr) {
new_objname= malloc(strlen(objstr)+strlen(refstr)+3);
if(new_objname == NULL) {
- printf("error in allocating memory. \n");
+ printf("error in allocating memory for object name. \n");
return NULL;
}
h4toh5_ZeroMemory(new_objname,strlen(objstr)+strlen(refstr)+3);
@@ -1495,11 +1489,14 @@ char* trans_obj_name(int32 obj_tag,int32 index) {
char* obj_name;
char indstr[5];
+ /* the reason why we allocate memory with strlen(HDF4_PALETTE) is
+ HDF4_PALETTE is the longest string among HDF4_??? */
obj_name = malloc(strlen(HDF4_PALETTE)+strlen(ATTR)+8);
if(obj_name == NULL) {
printf("cannot allocate memory for object name. \n");
return NULL;
}
+
h4toh5_ZeroMemory(obj_name,strlen(HDF4_PALETTE)+strlen(ATTR)+8);
if(conv_int_str(index,indstr)== FAIL) {
@@ -1563,20 +1560,20 @@ char* trans_obj_name(int32 obj_tag,int32 index) {
void freehashmemory(void){
- if(estnum_vg != 0) freetable(estnum_vg,vg_hashtab);
- if(estnum_vd != 0) freetable(estnum_vd,vd_hashtab);
+ if(estnum_vg > 0) freetable(estnum_vg,vg_hashtab);
+ if(estnum_vd > 0) freetable(estnum_vd,vd_hashtab);
- if(num_sds !=0) {
+ if(num_sds > 0) {
freetable(2*num_sds,sds_hashtab);
freenametable(DIM_HASHSIZE,dim_hashtab);
}
- if(num_images !=0) {
+ if(num_images > 0) {
freetable(2*num_images,gr_hashtab);
freetable(PAL_HASHSIZE,pal_hashtab);
}
- if(num_objects !=0) freenametable(num_objects,name_hashtab);
+ if(num_objects > 0) freenametable(num_objects,name_hashtab);
}
diff --git a/tools/h4toh5util.h b/tools/h4toh5util.h
index 503e02c..5772325 100644
--- a/tools/h4toh5util.h
+++ b/tools/h4toh5util.h
@@ -1,3 +1,34 @@
+/*-------------------------------------------------------------------------
+ *
+ * Copyright (C) 2000 National Center for Supercomputing Applications.
+ * All rights reserved.
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/******************************************************************************
+
+ Description:
+
+1. converter
+
+See HDF4 to HDF5 mapping specification at
+(http://hdf.ncsa.uiuc.edu/HDF5/papers/h4toh5) for the default mapping
+from HDF4 object to HDF5 object.
+
+The whole converter includes 10 files, h4toh5util.h, h4toh5main.h, h4toh5util.c, h4toh5main.c, h4toh5sds.c, h4toh5image.c,h4toh5vdata.c,h4toh5vgroup.c,h4toh5pal.c and h4toh5anno.c.
+
+2. this file
+
+Including declarations of global variables,global hashtables,constant
+and utility subroutines of h4toh5util.c
+
+Author: Kent Yang(ymuqun@ncsa.uiuc.edu)
+
+
+*****************************************************************************/
+
+
#ifndef UTILITY_H
#define UTILITY_H
#include "hdf5.h"
@@ -11,7 +42,7 @@ converter.*/
/*********************************************/
/* 0. if "/" is found in hdf4 object name, we will use another
- character "_" to replace it. */
+ character "_" to replace it, since "/" is a reserved symbol for hdf5. */
#define ORI_SLASH '/'
#define CHA_SLASH '_'
@@ -47,7 +78,8 @@ converter.*/
#define DIMSCALE "DIMSCALE"
-/* 5. define affix GLOBAL for dealing sds and image file attributes. */
+/* 5. define affix GLO for sds and image file attributes. these file attributes
+ will be put under root group. */
#define GLOSDS "GLOSDS"
#define GLOIMAGE "GLOIMAGE"
@@ -60,7 +92,7 @@ converter.*/
#define RAST24LABEL "raster24"
#define PALABEL "palette"
-/* 7. define HDF object class. */
+/* 7. define "IMAGE" CLASS required by image spec. */
#define IM_CLASS "IMAGE"
/* 8. reserved group name for HDF4 dimensional scale and palette. */
@@ -112,9 +144,9 @@ extern int32 num_glgrattrs;
functions used in h4-h5 converter.*/
/*********************************************/
/*define two kinds of hashtables.
- 1. struct table will use object reference as the key to handle whether this
+ 1. struct table uses object reference as the key to handle whether this
object is visited or not.
- 2. struct name_table will use name as the key to handle name clashings and
+ 2. struct name_table uses object name as the key to handle name clashings and
dimensional scale dataset.
*/
@@ -139,6 +171,7 @@ extern struct name_table* dim_hashtab;
/* routine for zeroing out the memory. */
void h4toh5_ZeroMemory(void*s,size_t n);
+
/* look-up table, object reference is the key.*/
int lookup(int,int,struct table*);
@@ -165,7 +198,7 @@ void freehashmemory(void);
functions used in h4-h5 converter.*/
/*********************************************/
-/* this routine defines the convertion of data type from h4 to h5. */
+/* this routine defines the conversion of data type from h4 to h5. */
herr_t h4type_to_h5type(const int32 h4type, hid_t* h5memtype,
size_t* h4memsize, size_t* h4size, hid_t *h5type);
@@ -179,6 +212,7 @@ hid_t mkstr(int size, H5T_str_t pad);
herr_t h5string_to_int(const int32, hid_t*,const size_t,hid_t* );
int conv_int_str(uint16, char*);
+/* these routines were utility functions for other routines at h4toh5util.c */
char* trans_obj_name(int32,int32);
char* get_obj_aboname(char*,char*,char*,const char*);
char* make_objname_no(char*,char*,const char*);
diff --git a/tools/h4toh5vdata.c b/tools/h4toh5vdata.c
index f15922a..b078791 100644
--- a/tools/h4toh5vdata.c
+++ b/tools/h4toh5vdata.c
@@ -1,3 +1,31 @@
+/*-------------------------------------------------------------------------
+ *
+ * Copyright (C) 2000 National Center for Supercomputing Applications.
+ * All rights reserved.
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/******************************************************************************
+
+ Description:
+
+1. converter
+
+See HDF4 to HDF5 mapping specification at
+(http://hdf.ncsa.uiuc.edu/HDF5/papers/h4toh5) for the default mapping
+from HDF4 object to HDF5 object.
+
+The whole converter includes 10 files, h4toh5util.h, h4toh5main.h, h4toh5util.c, h4toh5main.c, h4toh5sds.c, h4toh5image.c,h4toh5vdata.c,h4toh5vgroup.c,h4toh5pal.c and h4toh5anno.c.
+
+2. this file
+
+Converting an hdf4 independent vdata object into an hdf5 dataset of compound dataset.
+
+Author: Kent Yang(ymuqun@ncsa.uiuc.edu)
+
+
+*****************************************************************************/
#include "h4toh5main.h"
@@ -161,11 +189,7 @@ int Vdata_h4_to_h5(int32 file_id,int32 vdata_id, hid_t group_id) {
vdatamem_size +=fieldorder*h4memsize[i];
}
-
-
-
- /* printf("vdatamem_size %d\n",vdatamem_size);
- printf("vdata_size %d\n",vdata_size);*/
+
vd_data = malloc(vdatamem_size*n_records);
istat = VSsetfields(vdata_id,field_name_list);
@@ -195,7 +219,7 @@ int Vdata_h4_to_h5(int32 file_id,int32 vdata_id, hid_t group_id) {
for (i=0;i<nfields;i++) {
/* obtain field order.*/
fieldorder = VFfieldorder(vdata_id,i);
- /* printf("%d again fieldorder %d\n",i,fieldorder);*/
+
if(fieldorder == FAIL){
printf("error in obtaining field order. \n");
free(h5memtype);
@@ -515,14 +539,14 @@ int vdata_transattrs(int32 vdata_id,hid_t h5dset,int snum_vdattrs,
if (sh5_atype == H5T_STRING) {
if ((sh5str_type = mkstr(count_svdadata,
- H5T_STR_NULLTERM))<0) {
+ H5T_STR_SPACEPAD))<0) {
printf("error in making string for vdata attribute. \n");
free(svd_adata);
return FAIL;
}
if ((sh5str_memtype = mkstr(count_svdadata*sh4_amemsize,
- H5T_STR_NULLTERM))<0) {
+ H5T_STR_SPACEPAD))<0) {
printf("error in making memory string for vdata attribute. \n");
free(svd_adata);
return FAIL;
@@ -645,8 +669,6 @@ int gen_h5comptype(int32 vdata_id,int32 nfields,
hid_t* sh5type,hid_t* sh5memtype,
hid_t h5_ctype,hid_t h5_cmemtype) {
- /*char fieldname[MAX_NC_NAME];
- char* temp_fieldname;*/
char* fieldname;
int32 fieldorder;
int32 fieldsize;
@@ -669,30 +691,17 @@ int gen_h5comptype(int32 vdata_id,int32 nfields,
fieldname = NULL;
fieldorder = VFfieldorder(vdata_id,i);
- /* printf(" %d fieldorder%d\n",i,fieldorder);*/
if(fieldorder == FAIL){
printf("error in obtaining fieldorder.\n");
return FAIL;
}
- /* temp_fieldname = VFfieldname(vdata_id,i);
- if(temp_fieldname== NULL) {
- printf("fail to obtain Vdata field name. \n");
- return FAIL;
- }
-
- strncpy(fieldname,temp_fieldname,strlen(temp_fieldname));
-
-
- free(temp_fieldname);*/
-
fieldname = VFfieldname(vdata_id,i);
if(fieldname == NULL){
printf("fail to obtain Vdata field name. \n");
return FAIL;
}
-
fieldsize = VFfieldesize(vdata_id,i);
if(fieldsize == FAIL) {
@@ -704,10 +713,8 @@ int gen_h5comptype(int32 vdata_id,int32 nfields,
array as one hdf5 type string. */
if(sh5type[i] == H5T_STRING) {
- /* printf("sh4size in the string %d\n",sh4size[i]);
- printf("fieldsize in the string %d\n",fieldsize);*/
- /* if ((h5str_type = mkstr(sh4size[i],H5T_STR_NULLTERM))<0) {*/
- if ((h5str_type = mkstr(sh4size[i]*fieldorder,H5T_STR_NULLTERM))<0) {
+
+ if ((h5str_type = mkstr(sh4size[i]*fieldorder,H5T_STR_SPACEPAD))<0) {
printf("error in making string of hdf5 string. \n");
return FAIL;
}
@@ -717,8 +724,7 @@ int gen_h5comptype(int32 vdata_id,int32 nfields,
if (sh5memtype[i] == H5T_STRING) {
- /*if((h5str_type = mkstr(sh4memsize[i],H5T_STR_NULLTERM))<0){ */
- if((h5str_type = mkstr(sh4memsize[i]*fieldorder,H5T_STR_NULLTERM))<0){
+ if((h5str_type = mkstr(sh4memsize[i]*fieldorder,H5T_STR_SPACEPAD))<0){
printf("error in making string for VDATA in memory. \n");
return FAIL;
}
@@ -728,22 +734,18 @@ int gen_h5comptype(int32 vdata_id,int32 nfields,
fielddim[0] = fieldorder;
- /* if field type is an array, use H5Tinsert_array.*/
+ /* if field type is an array, use H5Tinsert_array.
+ When the data type is H5T_STRING,
+ we will treat the the vdata as a HDF5 scalar type.*/
if (fielddim[0] == 1 || check_ifstr == 1) {
- /* printf("i%d,sh5type[i] %d\n",i,sh5type[i]);
- printf("i%d,fieldname%s\n",i,fieldname);
- printf("i%d,fil_offset%d\n",i,fil_offset);*/
if(H5Tinsert(h5_ctype,fieldname,fil_offset,sh5type[i])<0) {
printf("error inserting hdf5 compound datatype while ");
printf("converting vdata.\n");
return FAIL;
}
-
- /* printf("i%d,sh5memtype[i] %d\n",i,sh5memtype[i]);
- printf("i%d,fieldname%s\n",i,fieldname);
- printf("i%d,mem_offset%d\n",i,mem_offset);*/
+
if(H5Tinsert(h5_cmemtype,fieldname,mem_offset,sh5memtype[i])<0){
printf("error inserting hdf5 compound datatype of memory");
printf(" while converting vdata.\n");
@@ -758,10 +760,7 @@ int gen_h5comptype(int32 vdata_id,int32 nfields,
printf("error inserting array into hdf5 compound datatype. \n");
return FAIL;
}
- /* printf("i%d,sh5memtype[i] %d\n",i,sh5memtype[i]);
- printf("i%d,fielddim[0]%d\n",i,fielddim[0]);
- printf("i%d,fieldname%s\n",i,fieldname);
- printf("i%d,mem_offset%d\n",i,mem_offset);*/
+
if(H5Tinsert_array(h5_cmemtype,fieldname,mem_offset,1,fielddim,
NULL,sh5memtype[i])<0) {
printf("error inserting array into hdf5 compound datatype for memory. \n");
@@ -771,13 +770,9 @@ int gen_h5comptype(int32 vdata_id,int32 nfields,
}
- /* fieldsizef = (size_t)fieldsize;
- fil_offset = fil_offset + fieldsizef;
- mem_offset = mem_offset + sh4memsize[i];*/
-
if( check_ifstr == 1) {
- fil_offset = fil_offset + sh4size[i];
- mem_offset = mem_offset + sh4memsize[i];
+ fil_offset = fil_offset + sh4size[i]*fieldorder;
+ mem_offset = mem_offset + sh4memsize[i]*fieldorder;
check_ifstr = 0;
}
else {
@@ -785,7 +780,7 @@ int gen_h5comptype(int32 vdata_id,int32 nfields,
fil_offset = fil_offset + sh4size[i]*fieldorder;
mem_offset = mem_offset + sh4memsize[i]*fieldorder;
}
- /* free(fieldname);*/
+
}
return SUCCEED;
diff --git a/tools/h4toh5vgroup.c b/tools/h4toh5vgroup.c
index 4bea19e..81acecc 100644
--- a/tools/h4toh5vgroup.c
+++ b/tools/h4toh5vgroup.c
@@ -1,4 +1,33 @@
-/*** This file is the main program of converter. ***/
+
+/*-------------------------------------------------------------------------
+ *
+ * Copyright (C) 2000 National Center for Supercomputing Applications.
+ * All rights reserved.
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/******************************************************************************
+
+ Description:
+
+1. converter
+
+See HDF4 to HDF5 mapping specification at
+(http://hdf.ncsa.uiuc.edu/HDF5/papers/h4toh5) for the default mapping
+from HDF4 object to HDF5 object.
+
+The whole converter includes 10 files, h4toh5util.h, h4toh5main.h, h4toh5util.c, h4toh5main.c, h4toh5sds.c, h4toh5image.c,h4toh5vdata.c,h4toh5vgroup.c,h4toh5pal.c and h4toh5anno.c.
+
+2. this file
+
+converting an hdf4 vgroup object into a hdf5 group.
+
+Author: Kent Yang(ymuqun@ncsa.uiuc.edu)
+
+
+*****************************************************************************/
+
#include "h4toh5main.h"
@@ -157,8 +186,6 @@ int Vgroup_h4_to_h5(int32 file_id,int32 vgroup_id,int32 sd_id,hid_t h5_group,hid
return FAIL;
}
-
-
}
/* the object is independent vdata. */
else if(Visvs(vgroup_id,obj_ref)) {
@@ -390,7 +417,7 @@ int convert_vdata(int32 file_id,int32 obj_ref,char * h5pgroup_name,
return FAIL;
}
- if(istat); /*ignore, attributes can be retrieved later.*/
+ if(istat); /*ignore, dependent vdata(attributes, etc.)can be retrieved later.*/
else { /* independent vdata, read in */
@@ -455,7 +482,7 @@ int convert_vdata(int32 file_id,int32 obj_ref,char * h5pgroup_name,
VSdetach(vdata_id);
return FAIL;
}
- /*... ADD in the code. create HL,
+ /*create HL,
for the time being, we will use absolute path. */
h5lvdata_name = get_obj_aboname(cor_cvdataname,refstr,h5pgroup_name,
@@ -527,6 +554,11 @@ int convert_sds(int32 file_id,int32 sd_id,int32 obj_ref,char * h5pgroup_name,
return FAIL;
}
+ if(conv_int_str(obj_ref,refstr)== FAIL) {
+ printf("error in converting reference number into string type.\n");
+ return FAIL;
+ }
+
sds_id = SDselect(sd_id,sd_index);
if(sds_id == FAIL){
@@ -550,6 +582,7 @@ int convert_sds(int32 file_id,int32 sd_id,int32 obj_ref,char * h5pgroup_name,
SDendaccess(sds_id);
return FAIL;
}
+
if(check_sds == 0) {
/* obtain the absolute name of sds object, deal with the name clashing by
@@ -563,6 +596,7 @@ int convert_sds(int32 file_id,int32 sd_id,int32 obj_ref,char * h5pgroup_name,
return FAIL;
}
free(cor_sdsname);
+
/* put the absolute path of sds into "hashing table".*/
if(set_name(obj_ref,2*num_sds,sds_hashtab,h5csds_name)==FAIL) {
printf("error in setting object name.\n");
@@ -767,3 +801,8 @@ int convert_image(int32 file_id,int32 obj_ref,char * h5pgroup_name,
return SUCCEED;
}
+
+
+
+
+