summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMuQun Yang <ymuqun@hdfgroup.org>2001-06-11 22:23:27 (GMT)
committerMuQun Yang <ymuqun@hdfgroup.org>2001-06-11 22:23:27 (GMT)
commit1d98202eed3cc3a3ede0f5dabfa670ef15d04309 (patch)
treed7e19c3d3a462de2440e4f8cd7abc2966bec11c3
parent85d8862d8291cb4c42f6a29d19be3bc02bc4b771 (diff)
downloadhdf5-1d98202eed3cc3a3ede0f5dabfa670ef15d04309.zip
hdf5-1d98202eed3cc3a3ede0f5dabfa670ef15d04309.tar.gz
hdf5-1d98202eed3cc3a3ede0f5dabfa670ef15d04309.tar.bz2
[svn-r3990]
Purpose: Update h4toh5 converter tool at hdf5 1.4 branch. Solution: see previous check in messags to development branch New features and bug fixes include: 1. SDS dimensional scale various bugs 2. fill value 3. chunking and compression issue 4. HDF4 specified attribute information 5. Vdata-related bugs Platforms tested: eirene(RedHat 6.2)
-rw-r--r--tools/h4toh5/h4toh5anno.c2
-rw-r--r--tools/h4toh5/h4toh5image.c208
-rw-r--r--tools/h4toh5/h4toh5main.c264
-rw-r--r--tools/h4toh5/h4toh5main.h39
-rw-r--r--tools/h4toh5/h4toh5pal.c7
-rw-r--r--tools/h4toh5/h4toh5sds.c1201
-rw-r--r--tools/h4toh5/h4toh5test.c123
-rw-r--r--tools/h4toh5/h4toh5util.c8
-rw-r--r--tools/h4toh5/h4toh5util.h11
-rw-r--r--tools/h4toh5/h4toh5vdata.c22
-rw-r--r--tools/h4toh5/h4toh5vgroup.c38
11 files changed, 1423 insertions, 500 deletions
diff --git a/tools/h4toh5/h4toh5anno.c b/tools/h4toh5/h4toh5anno.c
index cd09e26..e5e1c5b 100644
--- a/tools/h4toh5/h4toh5anno.c
+++ b/tools/h4toh5/h4toh5anno.c
@@ -346,6 +346,7 @@ int Annoobj_h4_to_h5(int32 file_id,int32 obj_ref, int32 obj_tag,
return FAIL;
}
+
num_lab_anno = ANnumann(an_id,AN_DATA_LABEL,obj_tag,obj_ref);
num_des_anno = ANnumann(an_id,AN_DATA_DESC,obj_tag,obj_ref);
@@ -470,7 +471,6 @@ int Annoobj_h4_to_h5(int32 file_id,int32 obj_ref, int32 obj_tag,
if(num_des_anno > 0) {
-
for (i = 0; i< num_des_anno;i++) {
ann_id = ANselect(an_id,i,AN_DATA_DESC);
diff --git a/tools/h4toh5/h4toh5image.c b/tools/h4toh5/h4toh5image.c
index 8fbbdc0..47c5363 100644
--- a/tools/h4toh5/h4toh5image.c
+++ b/tools/h4toh5/h4toh5image.c
@@ -44,7 +44,7 @@ Author: Kent Yang(ymuqun@ncsa.uiuc.edu)
*-------------------------------------------------------------------------
*/
-int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
+int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup,int h4_attr) {
int32 istat;
int32 ngrattrs;
@@ -67,6 +67,16 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
int32 chunk_dims[2];
int32 c_flags;
+ /* for checking compression */
+
+ sp_info_block_t info_block;
+ int16 special_code;
+ int32 access_id;
+ uint16 ri_ref;
+ int gzip_level;
+ uint16 temp_tag;
+ uint16* ptag_out;
+
/* define varibles for hdf5. */
hid_t h5ty_id;
@@ -82,8 +92,14 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
size_t h4memsize;
hsize_t fielddim[1];
hsize_t h5dims[2];
+ hsize_t bufsize;
herr_t ret;
hid_t create_plist;
+ hid_t write_plist;
+
+
+ temp_tag = DFTAG_NULL;
+ ptag_out = &temp_tag;
/* zeroing out memory.*/
@@ -147,13 +163,13 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
/* change the order of image dimension:
due to the difference of hdf4 image specification and
hdf5 image specification. */
-
h5dims[0] = edges[1]-start[1];
h5dims[1] = edges[0]-start[0];
gr_ref = GRidtoref(ri_id);
+
if(gr_ref == 0) {
printf("error in obtaining gr reference number. \n");
free(image_data);
@@ -196,10 +212,88 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
/* create property list. */
create_plist = H5Pcreate(H5P_DATASET_CREATE);
+ /* wait until the compression information can be obtained for image,
+ 4/28/2001, Kent Yang.*/
+
+ ri_ref = 0;
+ /*
+ ri_ref = get_RIref(file_id,DFTAG_VG,gr_ref,ptag_out);
+
+ if(ri_ref >0 ){
+ if(*ptag_out == DFTAG_RI) printf("okay\n");
+ access_id = Hstartread(file_id,*ptag_out,ri_ref);
+ }
+ */
+ if(ri_ref == 0)
+ access_id = FAIL;
+
+
+ /* if(access_id == FAIL){
+ printf("cannot find RI tag,the compression mode will not be checked");
+ printf(" when RIG is not chunked.\n");
+ }*/
+
+ if(access_id != FAIL) {
+ istat = Hinquire(access_id,NULL,NULL,NULL,NULL,NULL,NULL,NULL,&special_code);
+ if(istat == FAIL) {
+ printf("failed to inquire information \n ");
+ free(image_data);
+ free(h5cimage_name);
+ H5Pclose(create_plist);
+ return FAIL;
+ }
+ if(special_code >0){
+
+ if(HDget_special_info(access_id,&info_block)==FAIL){
+ printf("fail to get special info.\n");
+ free(image_data);
+ free(h5cimage_name);
+ H5Pclose(create_plist);
+ return FAIL;
+ }
+ /* free(info_block.cdims);*/
+ if(info_block.key == SPECIAL_COMP) {
+
+ if(c_flags == HDF_NONE){
+ /* 1. the current HDF5 will not handle compression case itself,
+ in order that the converted HDF5 is compressed, we have to
+ provide a chunking size. currently it is set to h5dim[i].*/
+
+ printf("okay to sds compress.\n");
+
+ chunk_dims[0] = (hsize_t)(h5dims[0]);
+ chunk_dims[1] =(hsize_t)(h5dims[1]);
+
+ if(H5Pset_chunk(create_plist, 2, chunk_dims)<0) {
+ printf("failed to set up chunking information for ");
+ printf("property list.\n");
+ free(image_data);
+ free(h5cimage_name);
+ H5Pclose(create_plist);
+ return FAIL;
+ }
+
+ if(H5Pset_deflate(create_plist,GZIP_COMLEVEL)<0){
+ /* if(H5Pset_deflate(create_plist,2)<0){*/
+ printf("fail to set compression method for HDF5 file.\n");
+ free(image_data);
+ free(h5cimage_name);
+ H5Pclose(create_plist);
+ return FAIL;
+ }
+ }
+
+ }
+ /* free(info_block.cdims);*/
+ }
+
+ }
if(c_flags == HDF_CHUNK || c_flags == (HDF_CHUNK | HDF_COMP)
|| c_flags == (HDF_CHUNK | HDF_NBIT) ){
+ if(c_def_out.comp.comp_type == COMP_CODE_RLE || c_def_out.comp.comp_type == COMP_CODE_NBIT || c_def_out.comp.comp_type == COMP_CODE_SKPHUFF || c_def_out.comp.comp_type == COMP_CODE_DEFLATE || c_def_out.comp.comp_type == COMP_CODE_JPEG) {
+
chunk_dims[0] = c_def_out.chunk_lengths[0];
chunk_dims[1] = c_def_out.chunk_lengths[1];
@@ -207,11 +301,40 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
printf("failed to set up chunking information for ");
printf("property list.\n");
free(image_data);
+ free(h5cimage_name);
H5Pclose(create_plist);
return FAIL;
}
+
+ if(c_def_out.comp.comp_type == COMP_CODE_DEFLATE)
+ gzip_level = c_def_out.comp.cinfo.deflate.level;
+ else gzip_level = GZIP_COMLEVEL;
+ if(H5Pset_deflate(create_plist,gzip_level)<0){
+ printf("fail to set compression method for HDF5 file.\n");
+ free(image_data);
+ free(h5cimage_name);
+ H5Pclose(create_plist);
+ }
+ }
}
- if (ncomp == 1) {
+
+ /* HDF4 can support various compression methods including simple RLE, NBIT, Skip Huffman, gzip,Jpeg , HDF5 currently only supports gzip compression.
+ By default, we will compress HDF5 dataset by using gzip compression if HDF5 file is compressed. */
+
+
+ write_plist = H5Pcreate(H5P_DATASET_XFER);
+ bufsize = h4memsize *h5dims[1]*ncomp;
+
+ if(H5Pset_buffer(write_plist,bufsize,NULL,NULL)<0) {
+ printf("fail to create data transfer property list.\n");
+ free(image_data);
+ free(h5cimage_name);
+ H5Pclose(create_plist);
+ H5Pclose(write_plist);
+ return FAIL;
+ }
+
+ if (ncomp == 1) {
h5d_sid = H5Screate_simple(2,h5dims,NULL);
@@ -219,6 +342,8 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
printf("error in creating space for dataset. \n");
free(image_data);
free(h5cimage_name);
+ H5Pclose(create_plist);
+ H5Pclose(write_plist);
return FAIL;
}
@@ -229,15 +354,17 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
free(image_data);
free(h5cimage_name);
H5Pclose(create_plist);
+ H5Pclose(write_plist);
return FAIL;
}
- if (H5Dwrite(h5dset,h5memtype,h5d_sid,h5d_sid,H5P_DEFAULT,
+ if (H5Dwrite(h5dset,h5memtype,h5d_sid,h5d_sid,write_plist,
image_data)<0) {
printf("error writing data for hdf5 dataset converted from images.\n");
free(image_data);
free(h5cimage_name);
H5Pclose(create_plist);
+ H5Pclose(write_plist);
return FAIL;
}
@@ -251,6 +378,7 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
free(image_data);
free(h5cimage_name);
H5Pclose(create_plist);
+ H5Pclose(write_plist);
return FAIL;
}
@@ -260,6 +388,7 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
free(image_data);
free(h5cimage_name);
H5Pclose(create_plist);
+ H5Pclose(write_plist);
return FAIL;
}
@@ -275,6 +404,7 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
free(image_data);
free(h5cimage_name);
H5Pclose(create_plist);
+ H5Pclose(write_plist);
return FAIL;
}
@@ -284,6 +414,7 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
free(image_data);
free(h5cimage_name);
H5Pclose(create_plist);
+ H5Pclose(write_plist);
return FAIL;
}
@@ -293,6 +424,7 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
free(image_data);
free(h5cimage_name);
H5Pclose(create_plist);
+ H5Pclose(write_plist);
return FAIL;
}
@@ -302,6 +434,7 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
free(image_data);
free(h5cimage_name);
H5Pclose(create_plist);
+ H5Pclose(write_plist);
return FAIL;
}
@@ -311,6 +444,7 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
free(image_data);
free(h5cimage_name);
H5Pclose(create_plist);
+ H5Pclose(write_plist);
return FAIL;
}
@@ -320,6 +454,7 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
free(image_data);
free(h5cimage_name);
H5Pclose(create_plist);
+ H5Pclose(write_plist);
return FAIL;
}
}
@@ -330,6 +465,7 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
free(image_data);
free(h5cimage_name);
H5Pclose(create_plist);
+ H5Pclose(write_plist);
return FAIL;
}
@@ -340,15 +476,17 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
free(image_data);
free(h5cimage_name);
H5Pclose(create_plist);
+ H5Pclose(write_plist);
return FAIL;
}
- if (H5Dwrite(h5dset,h5_cmemtype,h5d_sid,h5d_sid,H5P_DEFAULT,
+ if (H5Dwrite(h5dset,h5_cmemtype,h5d_sid,h5d_sid,write_plist,
(void *)image_data)<0) {
printf("error writing data\n");
free(image_data);
free(h5cimage_name);
H5Pclose(create_plist);
+ H5Pclose(write_plist);
return FAIL;
}
ret = H5Tclose(h5_ctype);
@@ -374,6 +512,7 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
free(image_data);
free(h5cimage_name);
H5Pclose(create_plist);
+ H5Pclose(write_plist);
H5Sclose(h5d_sid);
H5Dclose(h5dset);
return FAIL;
@@ -384,6 +523,7 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
free(h5cimage_name);
free(image_data);
H5Pclose(create_plist);
+ H5Pclose(write_plist);
H5Sclose(h5d_sid);
H5Dclose(h5dset);
return FAIL;
@@ -394,6 +534,7 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
free(h5cimage_name);
free(image_data);
H5Pclose(create_plist);
+ H5Pclose(write_plist);
H5Sclose(h5d_sid);
H5Dclose(h5dset);
return FAIL;
@@ -408,6 +549,7 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
printf(" cannot obtain attributes. \n");
free(image_data);
H5Pclose(create_plist);
+ H5Pclose(write_plist);
H5Sclose(h5d_sid);
H5Dclose(h5dset);
return FAIL;
@@ -416,7 +558,8 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
/* deal with h5dset predefined and user-defined attributes.
Obtain the name and data type and the total number of attributes.
Data attribute at hdf4 is only one-dimensional array. */
-
+
+
if (ncomp == 1 && h4size == 1)
strcpy(grlabel,RAST8LABEL);
else if(ncomp == 3 && h4size == 1)
@@ -430,6 +573,7 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
if(h4_transpredattrs(h5dset,HDF4_OBJECT_TYPE,grlabel)==FAIL){
printf("error in getting hdf4 image type attribute \n");
H5Pclose(create_plist);
+ H5Pclose(write_plist);
H5Sclose(h5d_sid);
H5Dclose(h5dset);
free(h5cimage_name);
@@ -437,19 +581,22 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
return FAIL;
}
+ if(h4_attr!=0) {
if(h4_transpredattrs(h5dset,HDF4_OBJECT_NAME,image_name)==FAIL){
printf("error in getting hdf4 image name attribute. \n");
H5Pclose(create_plist);
+ H5Pclose(write_plist);
H5Sclose(h5d_sid);
H5Dclose(h5dset);
free(h5cimage_name);
free(image_data);
return FAIL;
}
-
+ }
if(h4_transpredattrs(h5dset,HDF4_IMAGE_CLASS,image_class)==FAIL){
printf("error in getting hdf4 image class attribute. \n");
H5Pclose(create_plist);
+ H5Pclose(write_plist);
H5Sclose(h5d_sid);
H5Dclose(h5dset);
free(h5cimage_name);
@@ -457,11 +604,14 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
return FAIL;
}
+ if(h4_attr !=0){
+
gr_ref = GRidtoref(ri_id);
if(gr_ref == 0) {
printf("error in obtaining reference number of GR.\n");
H5Pclose(create_plist);
+ H5Pclose(write_plist);
H5Sclose(h5d_sid);
H5Dclose(h5dset);
free(h5cimage_name);
@@ -472,18 +622,20 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
if(h4_transnumattr(h5dset,HDF4_REF_NUM,gr_ref)==FAIL) {
printf("error in getting hdf4 image number attribute.\n");
H5Pclose(create_plist);
+ H5Pclose(write_plist);
H5Sclose(h5d_sid);
H5Dclose(h5dset);
free(h5cimage_name);
free(image_data);
return FAIL;
}
-
+ }
/* deal with palette. */
- if(gr_palette(file_id,ri_id,h5dset,h5_palgroup)== FAIL) {
+ if(gr_palette(file_id,ri_id,h5dset,h5_palgroup,h4_attr)== FAIL) {
printf("error in translating palette into h5 dataset.\n");
H5Pclose(create_plist);
+ H5Pclose(write_plist);
H5Sclose(h5d_sid);
H5Dclose(h5dset);
free(h5cimage_name);
@@ -492,6 +644,7 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
}
ret = H5Pclose(create_plist);
+ ret = H5Pclose(write_plist);
ret = H5Sclose(h5d_sid);
ret = H5Dclose(h5dset);
istat = GRendaccess(ri_id);
@@ -518,7 +671,7 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) {
*-------------------------------------------------------------------------
*/
-int gr_palette(int32 file_id,int32 ri_id,hid_t h5dset,hid_t h5_palgroup) {
+int gr_palette(int32 file_id,int32 ri_id,hid_t h5dset,hid_t h5_palgroup,int h4_attr) {
int32 pal_id;
uint16 pal_ref;
@@ -595,7 +748,7 @@ int gr_palette(int32 file_id,int32 ri_id,hid_t h5dset,hid_t h5_palgroup) {
return FAIL;
}
- pal_stat = Palette_h4_to_h5(file_id,pal_id,h5_palgroup,h5pal_name);
+ pal_stat = Palette_h4_to_h5(file_id,pal_id,h5_palgroup,h5pal_name,h4_attr);
if(pal_stat == FAIL) {
printf("error occurring in transferring palette into dataset. \n");
@@ -859,3 +1012,36 @@ int create_pal_objref(hid_t h5dset,hid_t h5_palgroup,char *h5pal_name){
H5Aclose(attribID);
return SUCCEED;
}
+
+
+uint16 get_RIref(int32 file_id,uint16 tag,int32 gr_ref,uint16* ptag_out){
+
+ DFdi di;
+ int32 found,GroupID;
+ int ri_ref = 0;
+
+ if((GroupID = DFdiread(file_id,tag,(uint16)gr_ref))<0){
+ printf("cannot find gr_ref\n");
+ return ri_ref;
+ }
+
+ found = 0;
+ di.tag = DFTAG_NULL;
+ di.ref = 0;
+ while((found == 0) &&(DFdiget(GroupID,&di.tag,&di.ref)==0)){
+ if(di.tag == DFTAG_CI ||di.tag == DFTAG_RI || di.tag == DFTAG_CI8 ||
+ di.tag == DFTAG_RI8)
+ found = 1;
+ }
+
+ *ptag_out = di.tag;
+ ri_ref = di.ref;
+ ri_ref = 1;
+ if(!found) {
+ printf("cannot find ri_ref\n");
+ return 0;
+ }
+ DFdifree(GroupID);
+ return ri_ref;
+
+}
diff --git a/tools/h4toh5/h4toh5main.c b/tools/h4toh5/h4toh5main.c
index e9ef567..19d8f23 100644
--- a/tools/h4toh5/h4toh5main.c
+++ b/tools/h4toh5/h4toh5main.c
@@ -67,6 +67,7 @@ int main(int argc, char ** argv) {
char *h4_filename=NULL;
char *h5_extension;
int status = 0;
+ int h4_attr = 1;
argc--;
argv++;
@@ -86,6 +87,15 @@ int main(int argc, char ** argv) {
}
}
+ /* check whether the flag for HDF4 attributes is set.*/
+ { int i;
+ for (i=0; i < argc; i++){
+ if ( HDstrcmp(argv[i],"-na") == 0 ) {
+ h4_attr = 0;
+ break;
+ }
+ }
+ }
switch(argc) {
@@ -94,105 +104,49 @@ int main(int argc, char ** argv) {
PrintOptions_h4toh5();
break;
- case 1: /* h4toh5 file1 */
- h4_filename = argv[0];
-#ifndef WIN32
- if (test_file(h4_filename,O_EXCL,292) != 0 ) {
- /* 292 Decimal - 0444 Octal, a+r */
- printf("the current hdf4 file name 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;
- }
-#endif
- /*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) {
- printf("error in creating hdf5 file name.\n");
- status = -1;
- break;
- }
-#ifndef WIN32
- if (test_file(h5_filename,O_CREAT|O_EXCL,436) != 0) {
- /* 436 Decimal - 0664 Octal, ug+rw,o+r */
- printf("permission of hdf5 file is not set properly.\n");
- status = -1;
- break;
- }
-#endif
- status = h4toh5(h4_filename, h5_filename);
-
- if ( status == FAIL ) {
- printf("error in converting %s into %s\n",h4_filename,h5_filename);
- break;
- }
- if (h5_filename != NULL) {
- HDfree(h5_filename);
- }
-
+ case 1: /* two cases:
+ 1. h4toh5 file1 without HDF4 specified attributes
+ this is the option where h4toh5 -na appears.
+ nothing is done.
+ 2. h4toh5 file1 including HDF4 specified attributes.
+ this is the default behavior.
+ */
+
+ if(HDstrcmp(argv[0],"-na")==0){
+ PrintOptions_h4toh5();
+ break;
+ }
+
+ if(gen_h4toh5(argv[0],NULL,h4_attr)<0){
+ status = -1;
+ return status;
+ }
break;
- case 2: /* h4toh5 file_in file_out */
+ case 2: /* h4toh5 file_in file_out with HDF4 predefined attributes
+ h4toh5 file_in file_in.h5 without HDF4 predefined attributes*/
+ if(h4_attr !=0){
h4_filename = argv[0];
h5_filename = argv[1];
+ status = gen_h4toh5(h4_filename,h5_filename,h4_attr);
+ }
-#ifndef WIN32
- if (test_file(h4_filename,O_EXCL,292) != 0 ) {
- /* 292 Decimal - 0444 Octal, a+r */
- printf("permission of hdf4 file is not set properly.\n");
- status = -1;
- break;
- }
+ else
+ status = gen_h4toh5(argv[1],NULL,h4_attr);
- if (test_dir(h4_filename) != 0 ) {
- fprintf(stderr,"%s: Is a directory\n",h4_filename);
- status = -1;
- break;
- }
+ if(status <0) return status;
+ break;
-#endif
- /*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;
- }
-
-#ifndef WIN32
- 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;
- }
+ case 3:/* h4toh5 file_in file_out without HDF4 predefined attributes.*/
-#endif
- status = h4toh5(h4_filename, h5_filename);
- if ( status == FAIL ) {
- printf("error in converting %sinto %s\n",h4_filename,h5_filename);
- break;
- }
- break;
+ if(h4_attr==0){
+ h4_filename = argv[1];
+ h5_filename = argv[2];
+ status = gen_h4toh5(h4_filename,h5_filename,h4_attr);
+ if(status <0) return status;
+ }
+ break;
default:
break;
@@ -211,7 +165,7 @@ int main(int argc, char ** argv) {
*-------------------------------------------------------------------------
*/
-int h4toh5(char*filename4, char*filename5) {
+int h4toh5(char*filename4, char*filename5,int h4_attr) {
/* define variables for hdf4. */
int32 istat ; /* hdf4 library routine return value. */
@@ -351,7 +305,7 @@ int h4toh5(char*filename4, char*filename5) {
}
/* convert all objects in lone vgroups into corresponding hdf5 objects. */
- if(h4toh5lonevgs(file_id,sd_id,h5_root,h5_dimg,h5_palg)== FAIL) {
+ if(h4toh5lonevgs(file_id,sd_id,h5_root,h5_dimg,h5_palg,h4_attr)== FAIL) {
printf("error in translating lone vgroup into hdf5 objects.\n");
SDend(sd_id);
GRend(gr_id);
@@ -366,7 +320,7 @@ int h4toh5(char*filename4, char*filename5) {
}
/*convert all objects in group rings into corresponding hdf5 objects. */
- if(h4toh5vgrings(file_id,sd_id,h5_root,h5_dimg,h5_palg) == FAIL){
+ if(h4toh5vgrings(file_id,sd_id,h5_root,h5_dimg,h5_palg,h4_attr) == FAIL){
printf("error in translating vgroup rings into hdf5 objects.\n");
SDend(sd_id);
GRend(gr_id);
@@ -382,7 +336,7 @@ int h4toh5(char*filename4, char*filename5) {
/*convert all independent lone vdata into corresponding hdf5 datasets with
- if(h4toh5lonevds(file_id,h5_root) == FAIL){
+ if(h4toh5lonevds(file_id,h5_root,h4_attr) == FAIL){
printf("error in translating lone independent vdata into hdf5 objects.\n");
SDend(sd_id);
GRend(gr_id);
@@ -413,7 +367,7 @@ 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) {
+ if(h4toh5unvisitedsds(file_id,sd_id,h5_root,h5_dimg,h4_attr) == FAIL) {
printf("error in converting unvisited sds objects into hdf5 file.\n");
SDend(sd_id);
GRend(gr_id);
@@ -429,7 +383,7 @@ int h4toh5(char*filename4, char*filename5) {
/*** deal with untouched image objects. convert them into hdf5 datasets under root group. ***/
- if(h4toh5unvisitedimages(file_id,h5_root,h5_palg) == FAIL) {
+ if(h4toh5unvisitedimages(file_id,h5_root,h5_palg,h4_attr) == FAIL) {
printf("error in converting unvisited image objects into hdf5 file.\n");
SDend(sd_id);
GRend(gr_id);
@@ -702,7 +656,7 @@ int set_hashtables(void) {
Modification:
*-------------------------------------------------------------------------
*/
-int h4toh5lonevgs(int32 file_id,int32 sd_id,hid_t h5group,hid_t h5_dimg,hid_t h5_palg) {
+int h4toh5lonevgs(int32 file_id,int32 sd_id,hid_t h5group,hid_t h5_dimg,hid_t h5_palg,int h4_attr) {
int32 vgroup_id;
int num_lonevg; /* number of lone vgroup.*/
@@ -850,7 +804,7 @@ int h4toh5lonevgs(int32 file_id,int32 sd_id,hid_t h5group,hid_t h5_dimg,hid_t h5
return FAIL;
}
- if(Vgroup_h4_to_h5(file_id,vgroup_id,sd_id,h5group,h5_dimg,h5_palg)==FAIL){
+ if(Vgroup_h4_to_h5(file_id,vgroup_id,sd_id,h5group,h5_dimg,h5_palg,h4_attr)==FAIL){
printf("error in translating vgroup into hdf5 objects.\n");
Vdetach(vgroup_id);
free(h5cgroup_name);
@@ -889,7 +843,7 @@ int h4toh5lonevgs(int32 file_id,int32 sd_id,hid_t h5group,hid_t h5_dimg,hid_t h5
*-------------------------------------------------------------------------
*/
-int h4toh5vgrings(int32 file_id,int32 sd_id,hid_t h5group,hid_t h5_dimg,hid_t h5_palg){
+int h4toh5vgrings(int32 file_id,int32 sd_id,hid_t h5group,hid_t h5_dimg,hid_t h5_palg,int h4_attr){
int32 vgroup_id;
int32 ref_num;
@@ -1019,7 +973,7 @@ int h4toh5vgrings(int32 file_id,int32 sd_id,hid_t h5group,hid_t h5_dimg,hid_t h5
return FAIL;
}
- if(Vgroup_h4_to_h5(file_id,vgroup_id,sd_id,h5group,h5_dimg,h5_palg)
+ if(Vgroup_h4_to_h5(file_id,vgroup_id,sd_id,h5group,h5_dimg,h5_palg,h4_attr)
==FAIL){
printf("error in translating vgroup into hdf5 group\n");
@@ -1053,7 +1007,7 @@ int h4toh5vgrings(int32 file_id,int32 sd_id,hid_t h5group,hid_t h5_dimg,hid_t h5
Modification:
*-------------------------------------------------------------------------
*/
-int h4toh5lonevds(int32 file_id, hid_t h5group){
+int h4toh5lonevds(int32 file_id, hid_t h5group,int h4_attr){
int32 vdata_id;
int32 *ref_vdata_array;
@@ -1192,7 +1146,7 @@ int h4toh5lonevds(int32 file_id, hid_t h5group){
return FAIL;
}
- if(Vdata_h4_to_h5(file_id,vdata_id,h5group)== FAIL) {
+ if(Vdata_h4_to_h5(file_id,vdata_id,h5group,h4_attr)== FAIL) {
printf("error in translating independent vdata into");
printf(" hdf5 datasets.\n");
free(h5cvdata_name);
@@ -1231,7 +1185,7 @@ int h4toh5lonevds(int32 file_id, hid_t h5group){
*/
-int h4toh5unvisitedsds(int32 file_id,int32 sd_id,hid_t h5root,hid_t h5_dimg) {
+int h4toh5unvisitedsds(int32 file_id,int32 sd_id,hid_t h5root,hid_t h5_dimg,int h4_attr) {
int i;
int32 sds_id;/* sd dataset identifer*/
@@ -1326,7 +1280,7 @@ int h4toh5unvisitedsds(int32 file_id,int32 sd_id,hid_t h5root,hid_t h5_dimg) {
}
/* do the convertion from sds into hdf5 dataset.*/
- if(Sds_h4_to_h5(file_id,sds_id,h5root,h5_dimg)== FAIL){
+ if(Sds_h4_to_h5(file_id,sds_id,h5root,h5_dimg,h4_attr)== FAIL){
printf("error in translating sds into hdf5 dataset.\n");
SDendaccess(sds_id);
free(h5csds_name);
@@ -1360,7 +1314,7 @@ int h4toh5unvisitedsds(int32 file_id,int32 sd_id,hid_t h5root,hid_t h5_dimg) {
*-------------------------------------------------------------------------
*/
-int h4toh5unvisitedimages(int32 file_id,hid_t h5_root,hid_t h5_palg) {
+int h4toh5unvisitedimages(int32 file_id,hid_t h5_root,hid_t h5_palg,int h4_attr) {
int i;
int32 istat;
@@ -1451,7 +1405,7 @@ int h4toh5unvisitedimages(int32 file_id,hid_t h5_root,hid_t h5_palg) {
}
/* do the convertion from the image into hdf5 dataset.*/
- if(Image_h4_to_h5(file_id,ri_id,h5_root,h5_palg)== FAIL) {
+ if(Image_h4_to_h5(file_id,ri_id,h5_root,h5_palg,h4_attr)== FAIL) {
printf("error in transferring image name into hdf5 dataset.\n");
GRendaccess(ri_id);
free(h5cimage_name);
@@ -1619,11 +1573,109 @@ void PrintOptions_h4toh5(void)
{
fprintf(stderr,"\nUsage: ");
fprintf(stderr,"\n h4toh5 -h (gives this print-out)\n");
+ fprintf(stderr," h4toh5 -na(can convert without HDF4 specified attributes)\n");
fprintf(stderr," h4toh5 input.hdf output.h5\n");
fprintf(stderr," h4toh5 input.hdf\n");
+ fprintf(stderr," h4toh5 -na input.hdf output.h5\n");
+ fprintf(stderr," h4toh5 -na input.hdf\n");
}
+/*****************************************************************************
+
+ Routine: gen_h4toh5()
+
+ Description: This routine prints the acceptable argument formats out to stderr.
+
+ Input: h4_filename: HDF4 file name
+ h5_filename: HDF5 file name
+ h4_attr: flag to indicate whether to include HDF4
+ predefined attribute or not.
+
+ Output: -1 FAIL
+ 0 SUCCEED
+
+*****************************************************************************/
+
+
+int gen_h4toh5(char*h4_filename,char*h5_filename,int h4_attr){
+ char* h5_extension;
+ int status;
+
+#ifndef WIN32
+ if (test_file(h4_filename,O_EXCL,292) != 0 ) {
+ /* 292 Decimal - 0444 Octal, a+r */
+ printf("the current hdf4 file name is not set properly.\n");
+ status = -1;
+ return status;
+ }
+ if (test_dir(h4_filename) != 0 ) {
+ fprintf(stderr,"%s: Is a directory\n",h4_filename);
+ status = -1;
+ return status;
+ }
+#endif
+ /*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;
+ return status;
+ }
+
+ if(h5_filename == NULL){
+ h5_extension = HDstrdup("h5");
+ h5_filename = BuildFilename(h4_filename,h5_extension);
+ if (h5_filename == NULL) {
+ printf("error in creating hdf5 file name.\n");
+ status = -1;
+ return status;
+ }
+#ifndef WIN32
+ if (test_file(h5_filename,O_CREAT|O_EXCL,436) != 0) {
+ /* 436 Decimal - 0664 Octal, ug+rw,o+r */
+ printf("permission of hdf5 file is not set properly.\n");
+ status = -1;
+ return status;
+ }
+#endif
+
+ status = h4toh5(h4_filename, h5_filename,h4_attr);
+
+ if ( status == FAIL ) {
+ printf("error in converting %s into %s\n",h4_filename,h5_filename);
+ return status;
+ }
+ if (h5_filename != NULL) {
+ HDfree(h5_filename);
+ }
+ return 0;
+ }
+
+ else {
+
+#ifndef WIN32
+ 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;
+ return status;
+ }
+ if (test_dir(h4_filename) != 0 ) {
+ fprintf(stderr,"%s: Is a directory\n",h4_filename);
+ status = -1;
+ return status;
+ }
+
+#endif
+ status = h4toh5(h4_filename, h5_filename,h4_attr);
+ if ( status == FAIL ) {
+ printf("error in converting %sinto %s\n",h4_filename,h5_filename);
+ return status;
+ }
+ }
+ return 0;
+}
diff --git a/tools/h4toh5/h4toh5main.h b/tools/h4toh5/h4toh5main.h
index 2bb6c88..7bfa794 100644
--- a/tools/h4toh5/h4toh5main.h
+++ b/tools/h4toh5/h4toh5main.h
@@ -32,6 +32,7 @@ Author: Kent Yang(ymuqun@ncsa.uiuc.edu)
#define H4TOH5MAIN_H
#include "hdf.h"
#include "mfhdf.h"
+#include "hfile.h"
#include "hdf5.h"
#include "h4toh5util.h"
#include <fcntl.h>
@@ -56,50 +57,52 @@ int test_dir(char *);
char *BuildFilename(char *filename, char *ext);
/* subroutines for h4toh5main.c */
-int h4toh5(char*,char*);
+int gen_h4toh5(char*,char*,int);
+int h4toh5(char*,char*,int);
int get_numof_hdf4obj(char*,int32);
int set_hashtables(void);
int set_helpgroups(hid_t,hid_t*,hid_t*);
-int h4toh5lonevds(int32,hid_t);
-int h4toh5lonevgs(int32,int32,hid_t,hid_t,hid_t);
-int h4toh5vgrings(int32,int32,hid_t,hid_t,hid_t);
-int h4toh5unvisitedimages(int32,hid_t,hid_t);
-int h4toh5unvisitedsds(int32,int32,hid_t,hid_t);
+int h4toh5lonevds(int32,hid_t,int);
+int h4toh5lonevgs(int32,int32,hid_t,hid_t,hid_t,int);
+int h4toh5vgrings(int32,int32,hid_t,hid_t,hid_t,int);
+int h4toh5unvisitedimages(int32,hid_t,hid_t,int);
+int h4toh5unvisitedsds(int32,int32,hid_t,hid_t,int);
void free_allhashmemory(void);
/*subroutines for h4toh5vgroup.c*/
-int Vgroup_h4_to_h5(int32,int32,int32,hid_t,hid_t,hid_t);
-int convert_vgroup(int32,int32, int32,char* ,hid_t,hid_t,hid_t);
-int convert_vdata(int32,int32,char*,hid_t);
-int convert_sds(int32,int32,int32,char*,hid_t,hid_t);
-int convert_image(int32,int32,char*,hid_t,hid_t);
+int Vgroup_h4_to_h5(int32,int32,int32,hid_t,hid_t,hid_t,int);
+int convert_vgroup(int32,int32, int32,char* ,hid_t,hid_t,hid_t,int);
+int convert_vdata(int32,int32,char*,hid_t,int);
+int convert_sds(int32,int32,int32,char*,hid_t,hid_t,int);
+int convert_image(int32,int32,char*,hid_t,hid_t,int);
/*subroutines for h4toh5vdata.c*/
-int Vdata_h4_to_h5(int32,int32,hid_t);
+int Vdata_h4_to_h5(int32,int32,hid_t,int);
int vdata_transattrs(int32,hid_t,int,int,char*);
int gen_h5comptype(int32,int32,size_t *,size_t*,hid_t*,hid_t*,hid_t,hid_t);
/* subroutines for h4toh5sds.c*/
-int Sds_h4_to_h5(int32,int32,hid_t,hid_t);
+int Sds_h4_to_h5(int32,int32,hid_t,hid_t,int);
int sds_transattrs(int32, hid_t,int,int);
int sdsdim_to_h5dataset(int32,int32,hid_t,hid_t,int32);
-
+int convert_sdsfillvalue(int32,int32,hid_t,hid_t,int);
+uint16 get_SDref(int32,uint16,int32);
/*subroutines for h4toh5image.c*/
-int Image_h4_to_h5(int32,int32,hid_t,hid_t);
+int Image_h4_to_h5(int32,int32,hid_t,hid_t,int);
int gr_tranattrs(int32, hid_t,int,int);
-int gr_palette(int32,int32,hid_t,hid_t);
+int gr_palette(int32,int32,hid_t,hid_t,int);
int create_pal_objref(hid_t ,hid_t ,char *);
-
+uint16 get_RIref(int32,uint16,int32,uint16*);
/*subroutines for h4toh5anno.c*/
char* trans_tag_name(int32,ann_type);
int Annofil_h4_to_h5(int32,hid_t);
int Annoobj_h4_to_h5(int32,int32,int32,hid_t);
/*subroutines for h4toh5pal.c*/
-int Palette_h4_to_h5(int32,int32 ,hid_t,char *);
+int Palette_h4_to_h5(int32,int32 ,hid_t,char *,int);
diff --git a/tools/h4toh5/h4toh5pal.c b/tools/h4toh5/h4toh5pal.c
index bf90acd..f814489 100644
--- a/tools/h4toh5/h4toh5pal.c
+++ b/tools/h4toh5/h4toh5pal.c
@@ -45,7 +45,7 @@ Author: Kent Yang(ymuqun@ncsa.uiuc.edu)
*-------------------------------------------------------------------------
*/
-int Palette_h4_to_h5(int32 file_id,int32 pal_id,hid_t h5g,char*pal_name) {
+int Palette_h4_to_h5(int32 file_id,int32 pal_id,hid_t h5g,char*pal_name,int h4_attr) {
int32 ncomp;
int32 pal_ref;
@@ -160,12 +160,14 @@ int Palette_h4_to_h5(int32 file_id,int32 pal_id,hid_t h5g,char*pal_name) {
return FAIL;
}
+ if(h4_attr!=0){
if(h4_transpredattrs(h5dset,HDF4_OBJECT_TYPE,palette_label)==FAIL) {
printf("unable to transfer palette label to HDF4 OBJECT TYPE.\n");
H5Sclose(h5d_sid);
H5Dclose(h5dset);
return FAIL;
}
+ }
if(h4_transpredattrs(h5dset,HDF4_PALETTE_CLASS,palette_class)==FAIL){
printf("unable to transfer palette class to HDF4 PALETTE CLASS.\n");
@@ -187,12 +189,15 @@ int Palette_h4_to_h5(int32 file_id,int32 pal_id,hid_t h5g,char*pal_name) {
H5Dclose(h5dset);
return FAIL;
}
+
+ if(h4_attr !=0){
if(h4_transnumattr(h5dset,HDF4_REF_NUM,pal_ref)==FAIL) {
printf("unable to transfer palette reference number to HDF4 REF. NUM.\n");
H5Sclose(h5d_sid);
H5Dclose(h5dset);
return FAIL;
}
+ }
return SUCCEED;
}
diff --git a/tools/h4toh5/h4toh5sds.c b/tools/h4toh5/h4toh5sds.c
index 89e5ddf..a4d9e3b 100644
--- a/tools/h4toh5/h4toh5sds.c
+++ b/tools/h4toh5/h4toh5sds.c
@@ -45,7 +45,7 @@ Author: Kent Yang(ymuqun@ncsa.uiuc.edu)
*-------------------------------------------------------------------------
*/
-int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){
+int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup,int h4_attr){
int32 sds_dtype;
int32 sds_rank;
@@ -72,6 +72,13 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){
hsize_t* chunk_dims;
int32 c_flags;
+ /* for checking compression */
+
+ sp_info_block_t info_block;
+ int16 special_code;
+ int32 access_id;
+ uint16 sd_ref;
+ int gzip_level;
/* define varibles for hdf5. */
hid_t h5dset;
@@ -79,39 +86,47 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){
hid_t h5ty_id;
hid_t h5_memtype;
hid_t create_plist;
+ hid_t write_plist;
hsize_t h5dims[MAX_VAR_DIMS];
hsize_t max_h5dims[MAX_VAR_DIMS];
-
+ hsize_t bufsize;
char* h5csds_name;
-
herr_t ret;
+
+ special_code = -1;
/* zeroing out the memory for sdsname and sdslabel.*/
h4toh5_ZeroMemory(sdsname,MAX_NC_NAME);
h4toh5_ZeroMemory(sdslabel,MAX_NC_NAME);
- /* check whether the sds is empty. */
+ /* check whether the sds is empty. */
if(SDcheckempty(sds_id,&sds_empty)== FAIL) {
- printf("error in running SDcheckempty routine. \n");
- return FAIL;
- }
-
- if(sds_empty != 0) return SUCCEED;
-
+ printf("error in running SDcheckempty routine. \n");
+ return FAIL;
+ }
/*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;
- }
/*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");
+ 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(sds_empty !=0) {
+ if(convert_sdsfillvalue(file_id,sds_id,h5_group,h5_dimgroup,h4_attr)==FAIL) {
+ printf("cannot convert fill value successfully.\n");
return FAIL;
}
+ return SUCCEED;
+ }
+
+ if(SDgetchunkinfo(sds_id,&c_def_out, &c_flags)== FAIL) {
+ printf("error in getting chunking information. \n");
+ return FAIL;
+ }
+
/* obtain start,edge, stride and number of sds data. */
@@ -138,31 +153,31 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){
count_sdsdata = 1;
for (i=0;i<sds_rank;i++){
- sds_stride[i] = 1;
- sds_start[i] = 0;
- sds_edge[i] = sds_dimsizes[i];
- count_sdsdata = count_sdsdata*sds_dimsizes[i];
+ sds_stride[i] = 1;
+ sds_start[i] = 0;
+ sds_edge[i] = sds_dimsizes[i];
+ count_sdsdata = count_sdsdata*sds_dimsizes[i];
}
for (i=0;i<sds_rank;i++) {
- h5dims[i] = sds_edge[i]-sds_start[i];
- max_h5dims[i] = h5dims[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) {
- printf("failed to translate datatype. \n");
- free(sds_start);
- free(sds_edge);
- free(sds_stride);
- return FAIL;
+ &h5ty_id) == FAIL) {
+ printf("failed to translate datatype. \n");
+ free(sds_start);
+ free(sds_edge);
+ free(sds_stride);
+ return FAIL;
}
- /* check whether the datatype is string, if we find string format,
- we will change them back into integer format.*/
+ /* check whether the datatype is string, if we find string format,
+ we will change them back into integer format.*/
if (h5ty_id == H5T_STRING) {
/* rechange string datatype into numerical datatype.*/
@@ -177,6 +192,7 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){
}
sds_data = malloc(h4memsize*count_sdsdata);
+
if(sds_data == NULL) {
printf("error in allocating memory. \n");
free(sds_start);
@@ -188,12 +204,12 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){
istat = SDreaddata(sds_id, sds_start, sds_stride, sds_edge,
(VOIDP)sds_data);
if (istat == FAIL) {
- printf("unable to read data from h5dset. \n");
- free(sds_start);
- free(sds_edge);
- free(sds_stride);
- free(sds_data);
- return FAIL;
+ printf("unable to read data from h5dset. \n");
+ free(sds_start);
+ free(sds_edge);
+ free(sds_stride);
+ free(sds_data);
+ return FAIL;
}
/* obtaining reference number and name of h5 dataset
@@ -211,30 +227,30 @@ 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);
- free(sds_stride);
- free(sds_data);
- printf("error,cannot find sds name \n");
- return FAIL;
+ free(sds_start);
+ free(sds_edge);
+ free(sds_stride);
+ free(sds_data);
+ printf("error,cannot find sds name \n");
+ return FAIL;
}
if (h5csds_name == NULL && check_sdsname == -1) {
- free(sds_start);
- free(sds_edge);
- free(sds_stride);
- free(sds_data);
- printf("error,sds name is not defined.\n");
- return FAIL;
+ free(sds_start);
+ free(sds_edge);
+ free(sds_stride);
+ free(sds_data);
+ printf("error,sds name is not defined.\n");
+ return FAIL;
}
if (h5csds_name == NULL && check_sdsname == -2) {
- free(sds_start);
- free(sds_edge);
- free(sds_stride);
- free(sds_data);
- printf("error,not enough memory for allocating sds name.\n");
- return FAIL;
+ free(sds_start);
+ free(sds_edge);
+ free(sds_stride);
+ free(sds_data);
+ printf("error,not enough memory for allocating sds name.\n");
+ return FAIL;
}
h5d_sid = H5Screate_simple(sds_rank,h5dims,max_h5dims);
@@ -253,50 +269,143 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){
create_plist = H5Pcreate(H5P_DATASET_CREATE);
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. */
+
+ sd_ref = get_SDref(file_id,DFTAG_NDG,sds_ref);
+ if(sd_ref == 0)
+ sd_ref = get_SDref(file_id,DFTAG_SDG,sds_ref);
+ if(sd_ref >0 )
+ access_id = Hstartread(file_id,DFTAG_SD,sd_ref);
+
+ if(sd_ref == 0)
+ access_id = FAIL;
+
+ if(access_id != FAIL) {
+ istat = Hinquire(access_id,NULL,NULL,NULL,NULL,NULL,NULL,NULL,&special_code);
+ if(istat == FAIL) {
+ printf("failed to inquire information \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(special_code >0){
+
+ if(HDget_special_info(access_id,&info_block)==FAIL){
+ printf("fail to get special info.\n");
+ free(sds_start);
+ free(sds_edge);
+ free(sds_stride);
+ free(sds_data);
+ free(chunk_dims);
+ H5Sclose(h5d_sid);
+ H5Pclose(create_plist);
+ return FAIL;
+ }
+
+ /* free(info_block.cdims);*/
+ if(info_block.key == SPECIAL_COMP) {
+
+ if(c_flags == HDF_NONE){
+ /* 1. if the first dimension is unlimited dimension,
+ we have to provide a chunking size.
+ 2. the current HDF5 will not handle compression case itself,
+ in order that the converted HDF5 is compressed, we have to
+ provide a chunking size. currently it is set to h5dim[i].*/
+
+ for(i=0;i<sds_rank;i++){
+ chunk_dims[i] = (hsize_t)(h5dims[i]);
+ }
+ 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;
+ }
+
+ printf("okay compressed \n");
+ if(H5Pset_deflate(create_plist,GZIP_COMLEVEL)<0){
+ /* if(H5Pset_deflate(create_plist,2)<0){*/
+ printf("fail to set compression method for HDF5 file.\n");
+ free(sds_start);
+ free(sds_edge);
+ free(sds_stride);
+ free(sds_data);
+ free(chunk_dims);
+ H5Sclose(h5d_sid);
+ H5Pclose(create_plist);
+ }
+ }
+
+ }
+ else if(c_flags == HDF_NONE && SDisrecord(sds_id))
+ {
+ for(i=0;i<sds_rank;i++){
+ chunk_dims[i] = (hsize_t)(sds_dimsizes[i]);
+ }
+ if(H5Pset_chunk(create_plist, sds_rank, chunk_dims)<0) {
+ printf("failed to set up chunking information for ");
+ printf("property list.\n");
+ free(chunk_dims);
+ H5Pclose(create_plist);
+ return FAIL;
+ }
+ }
- 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;
}
- }
+ }
+
+ /* HDF4 can support various compression methods including simple RLE, NBIT, Skip Huffman, gzip,Jpeg , HDF5 currently only supports gzip compression.
+ By default, we will compress HDF5 dataset by using gzip compression if HDF5 file is compressed. */
+
+
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] = (hsize_t)c_def_out.chunk_lengths[i];
-
- 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_def_out.comp.comp_type == COMP_CODE_RLE || c_def_out.comp.comp_type == COMP_CODE_NBIT || c_def_out.comp.comp_type == COMP_CODE_SKPHUFF || c_def_out.comp.comp_type == COMP_CODE_DEFLATE || c_def_out.comp.comp_type == COMP_CODE_JPEG) {
+
+ for(i=0;i<sds_rank;i++)
+ chunk_dims[i] = (hsize_t)c_def_out.chunk_lengths[i];
+
+ 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_def_out.comp.comp_type == COMP_CODE_DEFLATE)
+ gzip_level = c_def_out.comp.cinfo.deflate.level;
+ else gzip_level = GZIP_COMLEVEL;
+ if(H5Pset_deflate(create_plist,gzip_level)<0){
+ printf("fail to set compression method for HDF5 file.\n");
+ free(sds_start);
+ free(sds_edge);
+ free(sds_stride);
+ free(sds_data);
+ free(chunk_dims);
+ H5Sclose(h5d_sid);
+ H5Pclose(create_plist);
+ }
+ }
}
-
-
+
h5dset = H5Dcreate(h5_group,h5csds_name,h5ty_id,h5d_sid,create_plist);
if (h5dset < 0) {
@@ -310,8 +419,24 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){
H5Pclose(create_plist);
return FAIL;
}
-
- if (H5Dwrite(h5dset,h5_memtype,h5d_sid,h5d_sid,H5P_DEFAULT,
+
+ write_plist = H5Pcreate(H5P_DATASET_XFER);
+ bufsize = h4memsize;
+ for(i=1;i<sds_rank;i++)
+ bufsize *= h5dims[i];
+ if(H5Pset_buffer(write_plist,bufsize,NULL,NULL)<0) {
+ printf("fail to create data transfer 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 (H5Dwrite(h5dset,h5_memtype,h5d_sid,h5d_sid,write_plist,
(void *)sds_data)<0) {
printf("failed to write data into hdf5 dataset");
printf(" converted from SDS.\n");
@@ -405,6 +530,7 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){
/* handle extra attributes of sds : sds label, object type
and reference num */
+ if(h4_attr !=0) {
strcpy(sdslabel,SDSLABEL);
if(h4_transpredattrs(h5dset,HDF4_OBJECT_TYPE,sdslabel)==FAIL) {
@@ -447,7 +573,7 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){
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);
@@ -501,149 +627,149 @@ int sds_transattrs(int32 ssds_id, hid_t sh5_dset,int snum_sdsattrs,
for (i = 0;i < snum_sdsattrs; i++) {
- if (SDattrinfo(ssds_id,i,ssdsatrr_name,&ssds_atype,
- &count_ssdsadata)==FAIL){
- printf("unable to obtain SDS attribute information. \n");
- return FAIL;
- }
+ if (SDattrinfo(ssds_id,i,ssdsatrr_name,&ssds_atype,
+ &count_ssdsadata)==FAIL){
+ printf("unable to obtain SDS attribute information. \n");
+ return FAIL;
+ }
- /* make a table for the attribute type, to do the corresponding type. */
+ /* make a table for the attribute type, to do the corresponding type. */
- if(h4type_to_h5type(ssds_atype,&sh5_amemtype,&sh4_amemsize,
- &sh4_asize,&sh5_atype)== FAIL) {
- printf("fail to translate sds attribute data type from H4 to H5. \n");
- return FAIL;
- }
+ if(h4type_to_h5type(ssds_atype,&sh5_amemtype,&sh4_amemsize,
+ &sh4_asize,&sh5_atype)== FAIL) {
+ 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) {
- printf("error, cannot allocate memory for sds attribute data. \n");
- return FAIL;
- }
+ ssds_adata = malloc(sh4_amemsize * count_ssdsadata);
+ if(ssds_adata == NULL) {
+ printf("error, cannot allocate memory for sds attribute data. \n");
+ return FAIL;
+ }
- if(SDreadattr(ssds_id,i,(VOIDP)ssds_adata)== FAIL) {
- printf("error in reading attributes of sds object. \n");
- free(ssds_adata);
- return FAIL;
- }
+ if(SDreadattr(ssds_id,i,(VOIDP)ssds_adata)== FAIL) {
+ printf("error in reading attributes of sds object. \n");
+ free(ssds_adata);
+ return FAIL;
+ }
- /* if attribute doesn't have name, a default name is set. */
- if(ssdsatrr_name[0] == '\0') {
- sdsrepattr_name = trans_obj_name(DFTAG_NDG,i);
- strcpy(ssdsatrr_name,sdsrepattr_name);
- free(sdsrepattr_name);
- }
+ /* if attribute doesn't have name, a default name is set. */
+ if(ssdsatrr_name[0] == '\0') {
+ sdsrepattr_name = trans_obj_name(DFTAG_NDG,i);
+ strcpy(ssdsatrr_name,sdsrepattr_name);
+ free(sdsrepattr_name);
+ }
- /* if the sds attribute is a file attribute. */
- if(check_gloflag == 1){
- strcpy(sdsglo,GLOSDS);
- strcat(ssdsatrr_name,"_");
- strcat(ssdsatrr_name,sdsglo);
- }
+ /* if the sds attribute is a file attribute. */
+ if(check_gloflag == 1){
+ strcpy(sdsglo,GLOSDS);
+ strcat(ssdsatrr_name,"_");
+ strcat(ssdsatrr_name,sdsglo);
+ }
- /* now do attribute-transferring.
+ /* now do attribute-transferring.
1. deal with string data type
2. set attribute space.
3. get attribute name, set property list. */
- if (sh5_atype == H5T_STRING) {
+ if (sh5_atype == H5T_STRING) {
+
+ sh5a_sid = H5Screate(H5S_SCALAR);
+
+ if (sh5a_sid < 0) {
+ printf("failed to create attribute space for");
+ printf(" HDF4_OBJECT_TYPE SDS. \n");
+ free(ssds_adata);
+ return FAIL;
+ }
+
+ if ((sh5str_type = mkstr(count_ssdsadata,
+ H5T_STR_SPACEPAD))<0) {
+ printf("error in making string. \n");
+ H5Sclose(sh5a_sid);
+ free(ssds_adata);
+ return FAIL;
+ }
+
+ /* check this line later. */
+ if ((sh5str_memtype = mkstr(count_ssdsadata*sh4_amemsize,
+ H5T_STR_SPACEPAD))<0) {
+ printf("error in making memory string. \n");
+ H5Sclose(sh5a_sid);
+ free(ssds_adata);
+ return FAIL;
+ }
+
+ sh5a_id = H5Acreate(sh5_dset,ssdsatrr_name,sh5str_type,
+ sh5a_sid,H5P_DEFAULT);
+
+ if (sh5a_id <0) {
+ printf("failed to obtain attribute id for");
+ printf(" HDF4_OBJECT_TYPE SDS. \n");
+ H5Sclose(sh5a_sid);
+ free(ssds_adata);
+ return FAIL;
+ }
+
+ sret = H5Awrite(sh5a_id,sh5str_memtype,(void *)ssds_adata);
+
+ if (sret <0) {
+ printf("failed to write attribute data for");
+ printf(" HDF4_OBJECT_TYPE SDS. \n");
+ H5Sclose(sh5a_sid);
+ H5Aclose(sh5a_id);
+ free(ssds_adata);
+ return FAIL;
+ }
+
+ sret = H5Sclose(sh5a_sid);
+ sret = H5Aclose(sh5a_id);
+ }
+
+ else {
+
+ if(count_ssdsadata == 1) {
sh5a_sid = H5Screate(H5S_SCALAR);
-
if (sh5a_sid < 0) {
- printf("failed to create attribute space for");
- printf(" HDF4_OBJECT_TYPE SDS. \n");
- free(ssds_adata);
- return FAIL;
- }
-
- if ((sh5str_type = mkstr(count_ssdsadata,
- H5T_STR_SPACEPAD))<0) {
- printf("error in making string. \n");
- H5Sclose(sh5a_sid);
- free(ssds_adata);
- return FAIL;
- }
-
- /* check this line later. */
- if ((sh5str_memtype = mkstr(count_ssdsadata*sh4_amemsize,
- H5T_STR_SPACEPAD))<0) {
- printf("error in making memory string. \n");
- H5Sclose(sh5a_sid);
+ printf("failed to create space id. \n");
free(ssds_adata);
return FAIL;
}
-
- sh5a_id = H5Acreate(sh5_dset,ssdsatrr_name,sh5str_type,
- sh5a_sid,H5P_DEFAULT);
-
- if (sh5a_id <0) {
- printf("failed to obtain attribute id for");
- printf(" HDF4_OBJECT_TYPE SDS. \n");
- H5Sclose(sh5a_sid);
- free(ssds_adata);
- return FAIL;
- }
-
- sret = H5Awrite(sh5a_id,sh5str_memtype,(void *)ssds_adata);
-
- if (sret <0) {
- printf("failed to write attribute data for");
- printf(" HDF4_OBJECT_TYPE SDS. \n");
- H5Sclose(sh5a_sid);
- H5Aclose(sh5a_id);
+ }
+ else {
+ sh5dims[0] = count_ssdsadata;
+ sh5a_sid = H5Screate_simple(1,sh5dims,NULL);
+
+ if (sh5a_sid < 0) {
+ printf("failed to create attribute space. \n");
free(ssds_adata);
return FAIL;
}
-
- sret = H5Sclose(sh5a_sid);
- sret = H5Aclose(sh5a_id);
- }
-
- else {
-
- if(count_ssdsadata == 1) {
-
- sh5a_sid = H5Screate(H5S_SCALAR);
- if (sh5a_sid < 0) {
- printf("failed to create space id. \n");
- free(ssds_adata);
- return FAIL;
- }
- }
- else {
- sh5dims[0] = count_ssdsadata;
- sh5a_sid = H5Screate_simple(1,sh5dims,NULL);
-
- if (sh5a_sid < 0) {
- printf("failed to create attribute space. \n");
- free(ssds_adata);
- return FAIL;
- }
- }
- sh5a_id = H5Acreate(sh5_dset,ssdsatrr_name,sh5_atype,
- sh5a_sid,H5P_DEFAULT);
+ }
+ sh5a_id = H5Acreate(sh5_dset,ssdsatrr_name,sh5_atype,
+ sh5a_sid,H5P_DEFAULT);
- if(sh5a_id <0) {
- printf("failed to obtain attribute id. \n");
- H5Sclose(sh5a_sid);
- free(ssds_adata);
- return FAIL;
- }
-
- sret = H5Awrite(sh5a_id,sh5_amemtype,(void *)ssds_adata);
-
- if(sret <0) {
- printf("failed to write attribute data.\n ");
- H5Sclose(sh5a_sid);
- H5Aclose(sh5a_id);
- free(ssds_adata);
- return FAIL;
- }
- sret = H5Sclose(sh5a_sid);
- sret = H5Aclose(sh5a_id);
- }
- free(ssds_adata);
+ if(sh5a_id <0) {
+ printf("failed to obtain attribute id. \n");
+ H5Sclose(sh5a_sid);
+ free(ssds_adata);
+ return FAIL;
+ }
+
+ sret = H5Awrite(sh5a_id,sh5_amemtype,(void *)ssds_adata);
+
+ if(sret <0) {
+ printf("failed to write attribute data.\n ");
+ H5Sclose(sh5a_sid);
+ H5Aclose(sh5a_id);
+ free(ssds_adata);
+ return FAIL;
+ }
+ sret = H5Sclose(sh5a_sid);
+ sret = H5Aclose(sh5a_id);
+ }
+ free(ssds_adata);
}
return SUCCEED;
}
@@ -670,7 +796,7 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
int32 sdsdim_type = 0;
int32 sds_dimscasize[1];
int32 istat;
- int i;
+ int i,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.*/
@@ -686,6 +812,7 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
HDF_CHUNK_DEF c_def_out;
int32 c_flags;
+ int32* sdsdimempty;
/* define varibles for hdf5. */
@@ -694,8 +821,7 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
hid_t h5dim_tid;
hid_t h5dim_memtype;
-
- hid_t h5dim_nameaid;
+hid_t h5dim_nameaid;
hid_t h5dim_namesid;
hid_t h5str_dimntype;
@@ -705,9 +831,11 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
hid_t attribID;
hid_t create_plist;
+ int dim_index;
hsize_t h5dimscas[1];
hsize_t max_h5dimscas[1];
hsize_t h5dim_dims[1];
+ hsize_t h5dimname_dims[1];
hsize_t attr_refDims[1];
hsize_t h5dim_chunkdim[1];
hobj_ref_t dim_refdat;
@@ -715,18 +843,26 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
hobj_ref_t* alldim_refdat;
char* h5sdsdim_name;
- char h5sdsdim_allname[MAX_VAR_DIMS * MAX_DIM_NAME];
- char h5newsdsdim_name[MAX_DIM_NAME];
+ /* char *h5sdsdim_allname[MAX_VAR_DIMS];
+ char *h5newsdsdim_name; */
+
+ char h5sdsdim_allname[MAX_VAR_DIMS*MAX_DIM_NAME];
+ char h5newsdsdim_name[MAX_DIM_NAME];
char h5dimpath_name[MAX_DIM_NAME];
herr_t ret;
-
+ sdsdimempty = malloc(sds_rank *sizeof(int32));
+
+ for(i=0;i<sds_rank;i++)
+ sdsdimempty[i] = 0;
+
/*zero out memory for h5sdsdim_allname and h5dimpath_name */
+
+ /*** the following line should be erased for variable length HDF5 string.**/
h4toh5_ZeroMemory(h5sdsdim_allname,(MAX_VAR_DIMS*MAX_DIM_NAME)*sizeof(char));
h4toh5_ZeroMemory(h5dimpath_name,MAX_DIM_NAME*sizeof(char));
/*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;
@@ -740,7 +876,7 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
count_h5attrname = 0;
for (i = 0; i<sds_rank;i++) {
-
+
sdsdim_id = SDgetdimid(sds_id,i);
if(sdsdim_id == FAIL) {
@@ -757,9 +893,21 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
return FAIL;
}
- /* for unlimited sds dimension, grab the current dimensional size. */
+ /* Here we have very messy cases for dimensional scale when
+ sdsdim_type is 0(or not set).
+ When sdsdim_type is 0, it means no SDS dimensional scale
+ data for this dimensions. However, users may define SDS dimensional
+ scale name. We want to keep this information.
+ If user doesn't specific the name we will skip this dimension */
+
+ if(sdsdim_type == 0) {
+ if(strncmp(sdsdim_name,fakeDim,strlen(fakeDim))==0)
+ continue;
+ }
+ /* for unlimited SDS dimension, grab the current dimensional size. */
if(sds_dimscasize[0] == 0) sds_dimscasize[0] = firstdimsize;
+
/* check whether this dimensional scale dataset is looked up. */
check_sdsdim = lookup_name(sdsdim_name,DIM_HASHSIZE,dim_hashtab);
@@ -784,13 +932,17 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
}
free(cor_sdsdimname);
- strcpy(&h5sdsdim_allname[count_h5attrname*MAX_DIM_NAME],h5sdsdim_name);
+ strncpy(&h5sdsdim_allname[count_h5attrname*MAX_DIM_NAME],h5sdsdim_name,MAX_DIM_NAME);
+
+
+ /*h5sdsdim_allname[count_h5attrname]=HDstrdup(h5sdsdim_name);
+ should be added for variable length HDF5 string. 6/11/2001. */
/* 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, count_h5objref and count_h5attrname
- will not increase if this dimension doesnot
+ will not increase if this dimension doesnot
have dimensional scale data. That assures the object reference of sds is
correct. */
@@ -798,6 +950,12 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
if (check_sdsdim == 1){/* the dimension is touched, skip this one.*/
free(h5sdsdim_name);
SDendaccess(sdsdim_id);
+ /* here we have to check a special case when the dimension type is 0.
+ We should ignore counting object reference.*/
+ if(sdsdim_type == 0) {
+ count_h5attrname++;
+ continue;
+ }
count_h5objref = count_h5objref + 1;
count_h5attrname = count_h5attrname + 1;
continue;
@@ -810,11 +968,14 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
return FAIL;
}
- /* if this sds dimension has no dimensional scale data. skip it.*/
- if(sdsdim_type == 0)
- continue;
-
+ /* here we want to keep the dimensional scale name without
+ making the object reference. */
+ if(sdsdim_type == 0) {
+ count_h5attrname = count_h5attrname + 1;
+ sdsdimempty[i] = 1;
+ continue;
+ }
/* get h5 dimensional scale data type. */
if(h4type_to_h5type(sdsdim_type,&h5dim_memtype,&h4dim_memsize,
&h4dim_size,&h5dim_tid)== FAIL) {
@@ -825,7 +986,7 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
}
/* dimensional scale dataset cannot be H5T_STRING data type.
- So transferring back to int8 */
+ So transferring back to int8 */
if (h5dim_tid == H5T_STRING) {
if(h5string_to_int(sdsdim_type,&h5dim_memtype,h4dim_memsize,
@@ -870,50 +1031,50 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
/* create property list, for chunked sds or unlimited dimension cases */
- create_plist = H5Pcreate(H5P_DATASET_CREATE);
+ 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(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(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(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) ){
+ 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;
- }
- }
+ 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,
@@ -931,7 +1092,7 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
if (H5Dwrite(h5dim_dset,h5dim_memtype,h5dim_sid,h5dim_sid,
H5P_DEFAULT,(void *)dim_scadata)<0) {
- printf("error writing data\n");
+ printf("error writing dimensional scale data\n");
free(h5sdsdim_name);
free(dim_scadata);
SDendaccess(sdsdim_id);
@@ -966,74 +1127,93 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
/*1. create object reference number to dimensional scale dataset.
2. store absolute name of dimensional name into
dimensional list. */
-
+
if ( count_h5objref != 0) {
- 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((size_t)count_h5objref,sizeof(hobj_ref_t));
-
- if(alldim_refdat == NULL) {
- printf("error in allocating memory. \n");
- H5Sclose(attr_refSpace);
- H5Tclose(attr_refType);
- return FAIL;
- }
+ h5dim_dims[0] = count_h5objref;
- for(i=0;i<count_h5objref;i++){
- h4toh5_ZeroMemory(h5newsdsdim_name,MAX_DIM_NAME);
- strcpy(h5newsdsdim_name,&h5sdsdim_allname[i*MAX_DIM_NAME]);
-
- ret = H5Rcreate(&dim_refdat,sh5_dimgroup,h5newsdsdim_name,
- H5R_OBJECT,-1);
- if(ret <0) {
- free(alldim_refdat);
- H5Sclose(attr_refSpace);
- H5Tclose(attr_refType);
- printf("error in generating H5 reference. \n");
- return FAIL;
- }
- alldim_refdat[i] = dim_refdat;
-
- }
+ attr_refDims[0] = count_h5objref;
+ attr_refSpace = H5Screate_simple(1,attr_refDims,NULL);
+ attr_refType = H5Tcopy(H5T_STD_REF_OBJ);
+ alldim_refdat = calloc((size_t)count_h5objref,sizeof(hobj_ref_t));
- attribID = H5Acreate(sh5dset,DIMSCALE,attr_refType,attr_refSpace,
- H5P_DEFAULT);
- if(attribID < 0) {
- free(alldim_refdat);
- H5Sclose(attr_refSpace);
- H5Tclose(attr_refType);
- H5Aclose(attribID);
- printf("error in generating H5 attribute ID. \n");
- return FAIL;
+ if(alldim_refdat == NULL) {
+ printf("error in allocating memory. \n");
+ H5Sclose(attr_refSpace);
+ H5Tclose(attr_refType);
+ return FAIL;
+ }
+ k =0;
+
+ for(i=0;i<count_h5objref;i++){
+ if(sdsdimempty[i])
+ k = k +1;
+ h4toh5_ZeroMemory(h5newsdsdim_name,MAX_DIM_NAME);
+ strcpy(h5newsdsdim_name,&h5sdsdim_allname[k*MAX_DIM_NAME]);
+
+ /*h5newsdsdim_name = HDstrdup(h5sdsdim_allname[k]);
+ for variable length HDF5 string. 6/11/2001; Kent*/
+
+ ret = H5Rcreate(&dim_refdat,sh5_dimgroup,h5newsdsdim_name,
+ H5R_OBJECT,-1);
+ if(ret <0) {
+ free(alldim_refdat);
+ H5Sclose(attr_refSpace);
+ H5Tclose(attr_refType);
+ printf("error in generating H5 reference. \n");
+ return FAIL;
+ }
+ alldim_refdat[i] = dim_refdat;
+ k = k +1;
+
+ /*free(h5newsdsdim_name); for variable length HDF5 string 6/11/2001.*/
}
- ret = H5Awrite(attribID,attr_refType,(void *)alldim_refdat);
+ attribID = H5Acreate(sh5dset,DIMSCALE,attr_refType,attr_refSpace,
+ H5P_DEFAULT);
+ if(attribID < 0) {
+ free(alldim_refdat);
+ H5Sclose(attr_refSpace);
+ H5Tclose(attr_refType);
+ H5Aclose(attribID);
+ printf("error in generating H5 attribute ID. \n");
+ return FAIL;
+ }
+
+ ret = H5Awrite(attribID,attr_refType,(void *)alldim_refdat);
- H5Sclose(attr_refSpace);
- H5Tclose(attr_refType);
- H5Aclose(attribID);
- free(alldim_refdat);
+ H5Sclose(attr_refSpace);
+ H5Tclose(attr_refType);
+ H5Aclose(attribID);
+ free(alldim_refdat);
}
if(count_h5attrname!= 0) {
- h5dim_namesid = H5Screate_simple(1,h5dim_dims,NULL);
+ h5dimname_dims[0] = count_h5attrname;
+
+ h5dim_namesid = H5Screate_simple(1,h5dimname_dims,NULL);
if(h5dim_namesid <0) {
printf("error in creating sds dimensionlist space.\n");
return FAIL;
}
- h5str_dimntype = mkstr(MAX_DIM_NAME,H5T_STR_SPACEPAD);
+ /*h5str_dimntype = mkstr(MAX_DIM_NAME,H5T_STR_SPACEPAD); */
+
+ h5str_dimntype = mkstr(MAX_DIM_NAME,H5T_STR_NULLTERM);
if(h5str_dimntype < 0) {
H5Sclose(h5dim_namesid);
printf("error in generating H5T_STRING type.\n");
return FAIL;
- }
-
+ }
+
+ /*using variable length, h5dump and h5view do not
+ support this, this will be supported later.
+ h5str_dimntype = H5Tcopy(H5T_C_S1);
+ ret = H5Tset_size(h5str_dimntype,H5T_VARIABLE);
+ 6/11/2001, Kent Yang
+ */
h5dim_nameaid = H5Acreate(sh5dset,HDF4_DIMENSION_LIST,h5str_dimntype,
h5dim_namesid,H5P_DEFAULT);
@@ -1052,35 +1232,424 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset,
return FAIL;
}
+
ret = H5Sclose(h5dim_namesid);
ret = H5Aclose(h5dim_nameaid);
+ /*used for variable length HDF5 string.
+ for(dim_index = 0; dim_index <count_h5attrname;dim_index++)
+ free(h5sdsdim_allname[dim_index]);
+ 6/11/2001, kent*/
}
+
+
+ free(sdsdimempty);
return SUCCEED;
}
+int convert_sdsfillvalue(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup,int h4_attr){
+ int32 sds_dtype;
+ int32 sds_rank;
+ int32 sds_dimsizes[MAX_VAR_DIMS];
+ int32* sds_start;
+ int32* sds_edge;
+ int32* sds_stride;
+ int32 count_sdsdata;
+ int32 sds_ref;
+ int32 istat;
+ int i;
+ int32 num_sdsattrs;
+ void* fill_value;
+ int check_sdsname;
+ int check_gloattr;
+
+ char sdsname[MAX_NC_NAME];
+ char sdslabel[MAX_NC_NAME];
+ size_t h4size;
+ size_t h4memsize;
+ HDF_CHUNK_DEF c_def_out;
+ hsize_t* chunk_dims;
+ int32 c_flags;
+ /* define varibles for hdf5. */
+ hid_t h5dset;
+ hid_t h5d_sid;
+ hid_t h5ty_id;
+ hid_t h5_memtype;
+ hid_t create_plist;
+ hid_t write_plist;
+ hsize_t h5dims[MAX_VAR_DIMS];
+ hsize_t max_h5dims[MAX_VAR_DIMS];
+ hsize_t bufsize;
+ char* h5csds_name;
+ 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;
+ }
+ /* obtain start,edge, stride and number of sds data. */
+ sds_start = malloc(sizeof(int32)*sds_rank);
+ if(sds_start == NULL) {
+ printf("error in allocating memory for sds start.\n");
+ return FAIL;
+ }
+ sds_edge = malloc(sizeof(int32)*sds_rank);
+ if(sds_edge == NULL) {
+ printf("error in allocating memory for sds edge.\n");
+ free(sds_start);
+ return FAIL;
+ }
+ sds_stride = malloc(sizeof(int32)*sds_rank);
+ if(sds_stride == NULL) {
+ printf("error in allocating memory for sds stride. \n");
+ free(sds_start);
+ free(sds_edge);
+ return FAIL;
+ }
+ count_sdsdata = 1;
+ for (i=0;i<sds_rank;i++){
+ sds_stride[i] = 1;
+ sds_start[i] = 0;
+ sds_edge[i] = sds_dimsizes[i];
+ count_sdsdata = count_sdsdata*sds_dimsizes[i];
+ }
+ for (i=0;i<sds_rank;i++) {
+ h5dims[i] = sds_edge[i]-sds_start[i];
+ max_h5dims[i] = h5dims[i];
+ }
+ /* convert hdf4 data type to hdf5 data type. */
+ if (h4type_to_h5type(sds_dtype,&h5_memtype,&h4memsize,&h4size,
+ &h5ty_id) == FAIL) {
+ printf("failed to translate datatype. \n");
+ free(sds_start);
+ free(sds_edge);
+ free(sds_stride);
+ return FAIL;
+ }
+
+ /* check whether the datatype is string, if we find string format,
+ we will change them back into integer format.*/
+
+ 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");
+ free(sds_start);
+ free(sds_edge);
+ free(sds_stride);
+ return FAIL;
+ }
+ }
+ /* Since we know this SDS dataset fills with fill value, so currently
+ we will comment this out. */
+ /*
+ sds_data = malloc(h4memsize*count_sdsdata);
+ if(sds_data == NULL) {
+ printf("error in allocating memory. \n");
+ free(sds_start);
+ free(sds_edge);
+ free(sds_stride);
+ return FAIL;
+ }
+
+ istat = SDreaddata(sds_id, sds_start, sds_stride, sds_edge,
+ (VOIDP)sds_data);
+ if (istat == FAIL) {
+ printf("unable to read data from h5dset. \n");
+ free(sds_start);
+ free(sds_edge);
+ free(sds_stride);
+ free(sds_data);
+ return FAIL;
+ }
+
+ */
+
+ fill_value = malloc(h4memsize);
+ h4toh5_ZeroMemory(fill_value,h4memsize*sizeof(char));
+ if(num_sdsattrs != 0)
+ if(SDgetfillvalue(sds_id,fill_value)==FAIL)
+ printf("unable to get fill value, fill value will be set to zero \n");
+
+
+ sds_ref = SDidtoref(sds_id);
+ if(sds_ref == FAIL) {
+ printf("error in obtaining sds reference number. \n");
+ free(sds_start);
+ free(sds_edge);
+ free(sds_stride);
+ return FAIL;
+ }
+
+ 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);
+ free(sds_stride);
+
+ printf("error,cannot find sds name \n");
+ return FAIL;
+ }
+
+ if (h5csds_name == NULL && check_sdsname == -1) {
+ free(sds_start);
+ free(sds_edge);
+ free(sds_stride);
+
+ printf("error,sds name is not defined.\n");
+ return FAIL;
+ }
+
+ if (h5csds_name == NULL && check_sdsname == -2) {
+ free(sds_start);
+ free(sds_edge);
+ free(sds_stride);
+
+ printf("error,not enough memory for allocating sds name.\n");
+ return FAIL;
+ }
+
+ h5d_sid = H5Screate_simple(sds_rank,h5dims,max_h5dims);
+
+ if (h5d_sid < 0) {
+ printf("failed to create hdf5 data space converted from SDS. \n");
+ free(sds_start);
+ free(sds_edge);
+ free(sds_stride);
+
+ return FAIL;
+ }
+
+ /* set creation property list. */
+
+ create_plist = H5Pcreate(H5P_DATASET_CREATE);
+ if(create_plist <0) {
+ printf("failed to create hdf5 creation list.\n");
+ free(sds_start);
+ free(sds_edge);
+ free(sds_stride);
+
+ return FAIL;
+ }
+
+ if(H5Pset_fill_value(create_plist,h5ty_id,fill_value)<0){
+ printf("failed to set property list fill value.\n");
+ free(sds_start);
+ free(sds_edge);
+ free(sds_stride);
+
+ H5Sclose(h5d_sid);
+ H5Pclose(create_plist);
+ 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);
+
+ H5Sclose(h5d_sid);
+ H5Pclose(create_plist);
+ return FAIL;
+ }
+ /* Before HDF5 library make the optimzation of dealing with fill value
+ data, leave this alone. */
+ /* write_plist = H5Pcreate(H5P_DATASET_XFER);
+ bufsize = h4memsize;
+ for(i=1;i<sds_rank;i++)
+ bufsize *= h5dims[i];
+
+ if(H5Pset_buffer(write_plist,bufsize,NULL,NULL)<0) {
+ printf("fail to create data transfer property list.\n");
+ free(sds_start);
+ free(sds_edge);
+ free(sds_stride);
+
+ H5Sclose(h5d_sid);
+ H5Pclose(create_plist);
+ return FAIL;
+ }
+
+ if (H5Dwrite(h5dset,h5_memtype,h5d_sid,h5d_sid,write_plist,
+ (void *)sds_data)<0) {
+ printf("failed to write data into hdf5 dataset");
+ printf(" converted from SDS.\n");
+ H5Sclose(h5d_sid);
+ H5Dclose(h5dset);
+ H5Pclose(create_plist);
+ H5Pclose(write_plist);
+ free(sds_start);
+ free(sds_edge);
+ free(sds_stride);
+ return FAIL;
+ }
+
+ */
+ /* convert sds annotation into attribute of sds dataset.
+ Since there is no routines to find the exact tag of sds object,
+ we will check three possible object tags of sds objects, that is:
+ DFTAG_SD,DFTAG_SDG,DFTAG_NDG. If the object tag of sds object is
+ falling out of this scope, we will not convert annotations into
+ hdf5 attributes; it is user's responsibility to make sure object tags
+ for sds objects are only one of the above three tags.*/
+ if(Annoobj_h4_to_h5(file_id,sds_ref,DFTAG_SD,h5dset)== FAIL){
+ printf("failed to convert sds annotation into hdf5 attribute.\n");
+ free(sds_start);
+ free(sds_edge);
+ free(sds_stride);
+ H5Sclose(h5d_sid);
+ H5Dclose(h5dset);
+ H5Pclose(create_plist);
+ return FAIL;
+ }
+ if(Annoobj_h4_to_h5(file_id,sds_ref,DFTAG_SDG,h5dset)== FAIL){
+ printf("failed to convert sds annotation into hdf5 attribute.\n");
+ free(sds_start);
+ free(sds_edge);
+ free(sds_stride);
+ H5Sclose(h5d_sid);
+ H5Dclose(h5dset);
+ H5Pclose(create_plist);
+ return FAIL;
+ }
+
+ if(Annoobj_h4_to_h5(file_id,sds_ref,DFTAG_NDG,h5dset)== FAIL){
+ printf("failed to convert sds annotation into hdf5 attribute.\n");
+ free(sds_start);
+ free(sds_edge);
+ free(sds_stride);
+
+ H5Sclose(h5d_sid);
+ H5Dclose(h5dset);
+ H5Pclose(create_plist);
+ return FAIL;
+ }
+ check_gloattr = 0;
+ if (sds_transattrs(sds_id,h5dset,num_sdsattrs,check_gloattr)==FAIL) {
+ free(sds_start);
+ free(sds_edge);
+ free(sds_stride);
+
+ free(chunk_dims);
+ H5Sclose(h5d_sid);
+ H5Dclose(h5dset);
+ H5Pclose(create_plist);
+ printf(" Error in obtaining sds attributes. \n");
+ return FAIL;
+ }
+
+ /********************************************/
+ /* handle extra attributes of sds : sds label, object type
+ and reference num */
+
+ if(h4_attr !=0) {
+ strcpy(sdslabel,SDSLABEL);
+
+ if(h4_transpredattrs(h5dset,HDF4_OBJECT_TYPE,sdslabel)==FAIL) {
+ free(sds_start);
+ free(sds_edge);
+ free(sds_stride);
+
+ free(chunk_dims);
+ H5Sclose(h5d_sid);
+ H5Dclose(h5dset);
+ H5Pclose(create_plist);
+ printf("unable to transfer sds label to HDF4 OBJECT TYPE.\n");
+ return FAIL;
+ }
+
+ if(sdsname[0] != '\0') {
+ if(h4_transpredattrs(h5dset,HDF4_OBJECT_NAME,sdsname)==FAIL){
+ free(sds_start);
+ free(sds_edge);
+ free(sds_stride);
+
+ free(chunk_dims);
+ H5Sclose(h5d_sid);
+ H5Dclose(h5dset);
+ H5Pclose(create_plist);
+ printf("unable to transfer sds name to HDF5 dataset attribute.\n");
+ return FAIL;
+ }
+ }
+
+ if(h4_transnumattr(h5dset,HDF4_REF_NUM,sds_ref)==FAIL){
+ free(sds_start);
+ free(sds_edge);
+ free(sds_stride);
+
+ free(chunk_dims);
+ H5Sclose(h5d_sid);
+ H5Dclose(h5dset);
+ H5Pclose(create_plist);
+ printf("unable to transfer sds ref. to HDF5 dataset attribute.\n");
+ return FAIL;
+ }
+ }
+ free(sds_start);
+ free(sds_edge);
+ free(sds_stride);
+ free(fill_value);
+ H5Sclose(h5d_sid);
+ H5Dclose(h5dset);
+ H5Pclose(create_plist);
+ return SUCCEED;
+}
+
+
+uint16 get_SDref(int32 file_id,uint16 tag,int32 sds_ref){
+
+ DFdi di;
+ int32 found,GroupID;
+ int sd_ref = 0;
+
+
+ if((GroupID = DFdiread(file_id,tag,(uint16)sds_ref))<0){
+ printf("cannot find sd_ref\n");
+ return sd_ref;
+ }
+
+ found = 0;
+ di.tag = DFTAG_NULL;
+ di.ref = 0;
+ while((found == 0) &&(DFdiget(GroupID,&di.tag,&di.ref)==0)){
+ if(di.tag == DFTAG_SD)
+ found = 1;
+ }
+
+ sd_ref = di.ref;
+ if(!found)
+ printf("cannot find sd_ref\n");
+
+ DFdifree(GroupID);
+ return sd_ref;
+}
+
diff --git a/tools/h4toh5/h4toh5test.c b/tools/h4toh5/h4toh5test.c
index 333d49f..743da6d 100644
--- a/tools/h4toh5/h4toh5test.c
+++ b/tools/h4toh5/h4toh5test.c
@@ -396,6 +396,7 @@ int test_sdsdim() {
int32 typ_array[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE];
int32 typ_dims[TYP_RANK];
int32 dim_sca0[TYP_DIMSIZE];
+ int32 dim_sca1[TYP_DIMSIZE];
int32 istat;
char dim_name0[] = "dim0";
@@ -412,9 +413,10 @@ int test_sdsdim() {
for (k=0;k<TYP_DIMSIZE;k++)
typ_array[i][j][k] = i+j+k;
- for (i=0;i<TYP_DIMSIZE;i++)
+ for (i=0;i<TYP_DIMSIZE;i++){
dim_sca0[i] = i;
-
+ dim_sca1[i] = 2*i;
+ }
for(i=0;i<TYP_RANK;i++){
typ_dims[i] = TYP_DIMSIZE;
@@ -462,7 +464,7 @@ int test_sdsdim() {
printf("sds set dim.name failed. \n");
return FAIL;
}
- istat =SDsetdimscale(dim_id,typ_dims[0],DFNT_INT32,(VOIDP)dim_sca0);
+ istat =SDsetdimscale(dim_id,typ_dims[0],DFNT_INT32,(VOIDP)dim_sca0);
if(istat == FAIL) {
printf("sds set dim. scale failed. \n");
return FAIL;
@@ -474,7 +476,7 @@ int test_sdsdim() {
printf("sds set dim.name failed. \n");
return FAIL;
}
- istat = SDsetdimscale(dim_id,typ_dims[1],DFNT_INT32,(VOIDP)dim_sca0);
+ istat = SDsetdimscale(dim_id,typ_dims[1],DFNT_INT32,(VOIDP)dim_sca1);
if(istat == FAIL) {
printf("sds set dim. scale failed. \n");
return FAIL;
@@ -2900,7 +2902,8 @@ int test_vgall() {
int32 sds_ref;
int32 fill_value;
int32 array_data[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE];
- int32 dimo_sca[TYP_DIMSIZE];
+ int32 dim_sca0[TYP_DIMSIZE],dim_sca1[TYP_DIMSIZE];
+ int32 dim_sca2[TYP_DIMSIZE];
int32 dim_sizes[TYP_RANK];
int32 start[TYP_RANK],edges[TYP_RANK],stride[TYP_RANK];
float64 cal;
@@ -2937,6 +2940,7 @@ int test_vgall() {
char dim_name0[] ="dim0";
char dim_name1[] ="dim1";
+ char dim_name2[] ="dim2";
char dim_label[] ="dim.label";
char dim_unit[] ="dim.unit";
char dim_format[] ="dim.format";
@@ -2963,8 +2967,11 @@ int test_vgall() {
}
}
- for (i=0;i<TYP_DIMSIZE;i++)
- dimo_sca[i]= 2*i;
+ for (i=0;i<TYP_DIMSIZE;i++) {
+ dim_sca0[i]= 2*i;
+ dim_sca1[i]= i;
+ dim_sca2[i] =3*i;
+ }
for (i=0;i<TYP_RANK;i++){
stride[i]=1;
@@ -3468,30 +3475,48 @@ int test_vgall() {
printf("sds set dim id failed. \n");
return FAIL;
}
- if (i==0) {
+
+
+ switch(i) {
+
+ case 0:
istat = SDsetdimname(dim_id,dim_name0);
if(istat == FAIL) {
- printf("sds set dim.name failed. \n");
- return FAIL;
+ printf("sds set dim.name failed. \n");
+ return FAIL;
}
- istat= SDsetdimscale(dim_id,dim_sizes[0],DFNT_INT32,(VOIDP)dimo_sca);
+ istat =SDsetdimscale(dim_id,dim_sizes[0],DFNT_INT32,(VOIDP)dim_sca0);
if(istat == FAIL) {
- printf("sds set dim. scale failed. \n");
- return FAIL;
+ printf("sds set dim. scale failed. \n");
+ return FAIL;
}
- }
- else {
+ break;
+ case 1:
istat = SDsetdimname(dim_id,dim_name1);
if(istat == FAIL) {
- printf("sds set dim.name failed. \n");
- return FAIL;
+ printf("sds set dim.name failed. \n");
+ return FAIL;
}
- istat = SDsetdimscale(dim_id,dim_sizes[1],DFNT_INT32,(VOIDP)dimo_sca);
+ istat = SDsetdimscale(dim_id,dim_sizes[1],DFNT_INT32,(VOIDP)dim_sca1);
if(istat == FAIL) {
- printf("sds set dim. scale failed. \n");
- return FAIL;
+ printf("sds set dim. scale failed. \n");
+ return FAIL;
}
- }
+ break;
+ case 2:
+ istat = SDsetdimname(dim_id,dim_name2);
+ if(istat == FAIL) {
+ printf("sds set dim.name failed. \n");
+ return FAIL;
+ }
+ istat = SDsetdimscale(dim_id,dim_sizes[2],DFNT_INT32,(VOIDP)dim_sca2);
+ if(istat == FAIL) {
+ printf("sds set dim. scale failed. \n");
+ return FAIL;
+ }
+ break;
+ }
+
istat=SDsetdimstrs(dim_id,dim_label,dim_unit,dim_format);
if(istat == FAIL) {
@@ -3682,6 +3707,7 @@ int test_vgall() {
}
image_ref = GRidtoref(ri_id);
+
if(image_ref == FAIL) {
printf("fail to obtain image reference number.\n");
return FAIL;
@@ -3778,6 +3804,7 @@ int test_vgall() {
}
image_ref = GRidtoref(ri_id);
+
if(image_ref == FAIL) {
printf("fail to generate image reference number.\n");
return FAIL;
@@ -3823,6 +3850,7 @@ int test_anno() {
static char file_desc[] = "This is a file description.";
static char data_labelvg[] = "This is a vgroup data label.";
static char data_descvg[] = "This is a vgroup data description.";
+ static char data_descvg2[]="This is another vgroup data description.";
/* Create the HDF file. */
file_id = Hopen(FILEANNO, DFACC_CREATE, 0);
@@ -3926,9 +3954,62 @@ int test_anno() {
printf("fail to write annotation.\n");
return FAIL;
}
+ istat = ANendaccess(ann_id);
/* Terminate access to the annotation. */
+ /* Create a data description for the Vgroup just created.*/
+ ann_id = ANcreate(an_id, (uint16)obj_tag, (uint16)obj_ref, AN_DATA_DESC);
+ if(ann_id == FAIL) {
+ printf("fail to create annotation.\n");
+ return FAIL;
+ }
+
+ /* Write the data description to the file. */
+ istat = ANwriteann(ann_id, data_descvg2, (int)(strlen(data_descvg)));
+ if(istat == FAIL) {
+ printf("fail to write annotation.\n");
+ return FAIL;
+ }
+ istat = ANendaccess(ann_id);
+
+ istat = Vdetach(vgroup_id);
+
+ vgroup_id = Vattach(file_id, -1, "w");
+ if(vgroup_id == FAIL) {
+ printf("fail to attach vgroup \n");
+ return FAIL;
+ }
+
+ istat = Vsetname (vgroup_id, "Vgroup2 w/Annotations");
+ if(istat == FAIL) {
+ printf("fail to set group name\n");
+ return FAIL;
+ }
+ /* Get reference number of vgroup just created. */
+ obj_ref = Vfind (file_id, "Vgroup2 w/Annotations");
+ if(obj_ref == 0) {
+ printf("fail to set object reference.\n");
+ return FAIL;
+ }
+
+ obj_tag = DFTAG_VG;
+
+ /* Create a data label for the Vgroup just created. */
+ ann_id = ANcreate(an_id, (uint16)obj_tag, (uint16)obj_ref, AN_DATA_DESC);
+ if(ann_id == FAIL) {
+ printf("fail to create annotation.\n");
+ return FAIL;
+ }
+ /* Write the data label to the file. */
+ istat = ANwriteann(ann_id, data_descvg, (int)(strlen(data_descvg)));
+ if(istat == FAIL){
+ printf("fail to write annotation.\n");
+ return FAIL;
+ }
istat = ANendaccess(ann_id);
+
istat = Vdetach(vgroup_id);
+
+
istat = Vend(file_id);
/* Close the file. */
diff --git a/tools/h4toh5/h4toh5util.c b/tools/h4toh5/h4toh5util.c
index 879e8a9..2b6586e 100644
--- a/tools/h4toh5/h4toh5util.c
+++ b/tools/h4toh5/h4toh5util.c
@@ -1078,7 +1078,7 @@ int h4_transpredattrs(hid_t h5g,const char *attrname,char*data){
*-------------------------------------------------------------------------
*/
-int vg_transattrs(int32 h4vg,hid_t h5g) {
+int vg_transattrs(int32 h4vg,hid_t h5g,int h4_attr) {
/* define variables for hdf4. */
char vgroup_name[VGNAMELENMAX];
@@ -1108,7 +1108,7 @@ int vg_transattrs(int32 h4vg,hid_t h5g) {
int i;
num_vgattr = Vnattrs(h4vg);
-
+
for (i = 0;i <num_vgattr;i++) {
if (Vattrinfo(h4vg,i,vgattr_name,&vg_atype,
@@ -1238,6 +1238,8 @@ int vg_transattrs(int32 h4vg,hid_t h5g) {
}
/*** check this line later. ***/
+
+ if(h4_attr != 0) {
strcpy(obtype,VGROUPLABEL);
vgroup_class[0] = '\0';
@@ -1282,7 +1284,7 @@ int vg_transattrs(int32 h4vg,hid_t h5g) {
printf("error in data attribute transferring.\n");
return FAIL;
}
-
+ }
return SUCCEED;
}
diff --git a/tools/h4toh5/h4toh5util.h b/tools/h4toh5/h4toh5util.h
index ba2420f..2cda0cc 100644
--- a/tools/h4toh5/h4toh5util.h
+++ b/tools/h4toh5/h4toh5util.h
@@ -87,12 +87,13 @@ converter.*/
/* 6. define HDF object label.*/
#define SDSLABEL "SDS"
#define VDATALABEL "Vdata"
+#define VDATTRLAB "Vdata attribute"
#define VGROUPLABEL "Vgroup"
#define GRLABEL "GR"
#define RAST8LABEL "raster8"
#define RAST24LABEL "raster24"
#define PALABEL "palette"
-
+#define LABEL_LENG 20
/* 7. define "IMAGE" CLASS required by image spec. */
#define IM_CLASS "IMAGE"
@@ -135,7 +136,13 @@ converter.*/
independent vdata is hdf chunking table _HDF_CHK_TBL_CLASS, if it becomes
public constant for hdf lib, this constant can be released.*/
#define _HDF_CHK_TBL_CLASS "_HDF_CHK_TBL_"
+
+/*11. the compression level currently is set to the maximum level.*/
+#define GZIP_COMLEVEL 9
+/*12. fake sds dimension name*/
+#define fakeDim "fakeDim"
+
extern int32 estnum_vg;
extern int32 estnum_vd;
extern int32 num_sds;
@@ -211,7 +218,7 @@ herr_t h4type_to_h5type(const int32 h4type, hid_t* h5memtype,
/* routines for translating predefined hdf4 attributes into hdf5 attributes*/
int h4_transpredattrs(hid_t ,const char *,char*data);
int h4_transnumattr(hid_t h5g,const char *,uint16 group_ref);
-int vg_transattrs(int32,hid_t);
+int vg_transattrs(int32,hid_t,int);
/*string and int conversion routines.*/
hid_t mkstr(int size, H5T_str_t pad);
diff --git a/tools/h4toh5/h4toh5vdata.c b/tools/h4toh5/h4toh5vdata.c
index 55a8bf9..e4efd1d 100644
--- a/tools/h4toh5/h4toh5vdata.c
+++ b/tools/h4toh5/h4toh5vdata.c
@@ -46,7 +46,7 @@ Author: Kent Yang(ymuqun@ncsa.uiuc.edu)
*-------------------------------------------------------------------------
*/
-int Vdata_h4_to_h5(int32 file_id,int32 vdata_id, hid_t group_id) {
+int Vdata_h4_to_h5(int32 file_id,int32 vdata_id, hid_t group_id,int h4_attr) {
/* define variables for hdf4. */
@@ -72,7 +72,7 @@ int Vdata_h4_to_h5(int32 file_id,int32 vdata_id, hid_t group_id) {
VOIDP vd_data;
- char vdlabel[10];
+ char vdlabel[LABEL_LENG];
char vdata_name[MAX_NC_NAME];
char fieldname[MAX_NC_NAME];
char vdata_class[VSNAMELENMAX];
@@ -387,7 +387,17 @@ int Vdata_h4_to_h5(int32 file_id,int32 vdata_id, hid_t group_id) {
}
/* converting predefined attributes. */
- strcpy(vdlabel,VDATALABEL);
+
+ if(h4_attr != 0) {
+ istat = VSisattr(vdata_id);
+ if (istat == FAIL) {
+ printf("error in checking vdata attribute. \n");
+ VSdetach(vdata_id);
+ return FAIL;
+ }
+
+ if(istat) strcpy(vdlabel,VDATTRLAB);
+ else strcpy(vdlabel,VDATALABEL);
if(h4_transpredattrs(h5dset,HDF4_OBJECT_TYPE,vdlabel)==FAIL){
printf("error in transfering vdata attributes.\n");
free(h5memtype);
@@ -409,7 +419,7 @@ int Vdata_h4_to_h5(int32 file_id,int32 vdata_id, hid_t group_id) {
return FAIL;
}
}
-
+
if(h4_transnumattr(h5dset,HDF4_REF_NUM,vdata_ref)==FAIL){
printf("error in transfering vdata attributes.\n");
free(h5memtype);
@@ -419,7 +429,7 @@ int Vdata_h4_to_h5(int32 file_id,int32 vdata_id, hid_t group_id) {
free(vd_data);
return FAIL;
}
-
+ }
H5Sclose(h5d_sid);
H5Dclose(h5dset);
VSdetach(vdata_id);
@@ -796,7 +806,6 @@ int gen_h5comptype(int32 vdata_id,int32 nfields,
printf("error closing array datatype.\n");
return FAIL;
}
-
}
@@ -829,3 +838,4 @@ int gen_h5comptype(int32 vdata_id,int32 nfields,
+
diff --git a/tools/h4toh5/h4toh5vgroup.c b/tools/h4toh5/h4toh5vgroup.c
index 92a6735..9d3bbef 100644
--- a/tools/h4toh5/h4toh5vgroup.c
+++ b/tools/h4toh5/h4toh5vgroup.c
@@ -54,7 +54,7 @@ Author: Kent Yang(ymuqun@ncsa.uiuc.edu)
*/
-int Vgroup_h4_to_h5(int32 file_id,int32 vgroup_id,int32 sd_id,hid_t h5_group,hid_t h5_dimgroup,hid_t h5_palgroup)
+int Vgroup_h4_to_h5(int32 file_id,int32 vgroup_id,int32 sd_id,hid_t h5_group,hid_t h5_dimgroup,hid_t h5_palgroup,int h4_attr)
{
@@ -138,7 +138,7 @@ int Vgroup_h4_to_h5(int32 file_id,int32 vgroup_id,int32 sd_id,hid_t h5_group,hid
}
/* vgroup attributes into corresponding hdf5 group attributes.*/
- if(vg_transattrs(vgroup_id,h5_pgroup)==FAIL) {
+ if(vg_transattrs(vgroup_id,h5_pgroup,h4_attr)==FAIL) {
printf("error in translating vgroup attributes into hdf5 group attr.\n");
H5Gclose(h5_pgroup);
free(h5pgroup_name);
@@ -182,7 +182,7 @@ int Vgroup_h4_to_h5(int32 file_id,int32 vgroup_id,int32 sd_id,hid_t h5_group,hid
if (Visvg(vgroup_id,obj_ref)) {
if(convert_vgroup(file_id,sd_id,obj_ref,h5pgroup_name,h5_pgroup,
- h5_dimgroup,h5_palgroup)== FAIL) {
+ h5_dimgroup,h5_palgroup,h4_attr)== FAIL) {
printf("convert_vgroup routine failed,");
printf("cannot convert vgroup into hdf5 group successfully.\n");
free(h5pgroup_name);
@@ -193,7 +193,7 @@ int Vgroup_h4_to_h5(int32 file_id,int32 vgroup_id,int32 sd_id,hid_t h5_group,hid
}
/* the object is independent vdata. */
else if(Visvs(vgroup_id,obj_ref)) {
- if(convert_vdata(file_id,obj_ref,h5pgroup_name,h5_pgroup)==FAIL){
+ if(convert_vdata(file_id,obj_ref,h5pgroup_name,h5_pgroup,h4_attr)==FAIL){
printf("fail to convert vdata into hdf5 dataset.\n");
free(h5pgroup_name);
H5Gclose(h5_pgroup);
@@ -202,7 +202,7 @@ int Vgroup_h4_to_h5(int32 file_id,int32 vgroup_id,int32 sd_id,hid_t h5_group,hid
}
else if(obj_tag == DFTAG_NDG || obj_tag == DFTAG_SDG) {
if(convert_sds(file_id,sd_id,obj_ref,h5pgroup_name,h5_pgroup,
- h5_dimgroup)==FAIL){
+ h5_dimgroup,h4_attr)==FAIL){
printf("fail to convert sds into hdf5 dataset.\n");
H5Gclose(h5_pgroup);
free(h5pgroup_name);
@@ -211,7 +211,7 @@ int Vgroup_h4_to_h5(int32 file_id,int32 vgroup_id,int32 sd_id,hid_t h5_group,hid
}
else if(obj_tag == DFTAG_RIG) {
if(convert_image(file_id,obj_ref,h5pgroup_name,
- h5_pgroup,h5_palgroup)==FAIL){
+ h5_pgroup,h5_palgroup,h4_attr)==FAIL){
printf("fail to convert image into hdf5 dataset.\n");
H5Gclose(h5_pgroup);
free(h5pgroup_name);
@@ -250,7 +250,7 @@ int Vgroup_h4_to_h5(int32 file_id,int32 vgroup_id,int32 sd_id,hid_t h5_group,hid
int convert_vgroup(int32 file_id,int32 sd_id, int32 obj_ref,
char* h5pgroup_name,hid_t h5_pgroup,hid_t h5_dimgroup,
- hid_t h5_palgroup) {
+ hid_t h5_palgroup,int h4_attr) {
int32 vgroup_cid;
int32 istat;
@@ -316,7 +316,7 @@ int convert_vgroup(int32 file_id,int32 sd_id, int32 obj_ref,
return FAIL;
}
if(Vgroup_h4_to_h5(file_id,vgroup_cid,sd_id,h5_pgroup,
- h5_dimgroup,h5_palgroup)== FAIL) {
+ h5_dimgroup,h5_palgroup,h4_attr)== FAIL) {
printf("error in transferring vgroup into hdf5 group.\n");
Vdetach(vgroup_cid);
free(h5cgroup_name);
@@ -390,7 +390,7 @@ int convert_vgroup(int32 file_id,int32 sd_id, int32 obj_ref,
*/
int convert_vdata(int32 file_id,int32 obj_ref,char * h5pgroup_name,
- hid_t h5_pgroup) {
+ hid_t h5_pgroup,int h4_attr) {
int32 vdata_id;
int check_vdata;
@@ -421,7 +421,7 @@ int convert_vdata(int32 file_id,int32 obj_ref,char * h5pgroup_name,
return FAIL;
}
- if(istat); /*ignore, dependent vdata(attributes, etc.)can be retrieved later.*/
+ /* if(istat);*/ /*ignore, dependent vdata(attributes, etc.)can be retrieved later.*/
else { /* independent vdata, read in */
@@ -462,7 +462,7 @@ int convert_vdata(int32 file_id,int32 obj_ref,char * h5pgroup_name,
return FAIL;
}
- if(Vdata_h4_to_h5(file_id,vdata_id,h5_pgroup)==FAIL){
+ if(Vdata_h4_to_h5(file_id,vdata_id,h5_pgroup,h4_attr)==FAIL){
printf("failed to transfer vdata into hdf5 dataset.\n");
VSdetach(vdata_id);
free(h5cvdata_name);
@@ -536,7 +536,7 @@ int convert_vdata(int32 file_id,int32 obj_ref,char * h5pgroup_name,
*-------------------------------------------------------------------------
*/
int convert_sds(int32 file_id,int32 sd_id,int32 obj_ref,char * h5pgroup_name,
- hid_t h5_pgroup,hid_t h5_dimgroup) {
+ hid_t h5_pgroup,hid_t h5_dimgroup,int h4_attr) {
int32 sd_index;
int32 sds_id;
@@ -609,7 +609,7 @@ int convert_sds(int32 file_id,int32 sd_id,int32 obj_ref,char * h5pgroup_name,
return FAIL;
}
/* convert the sds object into hdf5 dataset.*/
- if(Sds_h4_to_h5(file_id,sds_id,h5_pgroup,h5_dimgroup)==FAIL){
+ if(Sds_h4_to_h5(file_id,sds_id,h5_pgroup,h5_dimgroup,h4_attr)==FAIL){
printf("error in translating sds into hdf5 dataset.\n");
SDendaccess(sds_id);
free(h5csds_name);
@@ -673,7 +673,7 @@ int convert_sds(int32 file_id,int32 sd_id,int32 obj_ref,char * h5pgroup_name,
*-------------------------------------------------------------------------
*/
int convert_image(int32 file_id,int32 obj_ref,char * h5pgroup_name,
- hid_t h5_pgroup,hid_t h5_palgroup) {
+ hid_t h5_pgroup,hid_t h5_palgroup,int h4_attr) {
int32 gr_id;
int32 gr_index;
@@ -754,7 +754,7 @@ int convert_image(int32 file_id,int32 obj_ref,char * h5pgroup_name,
free(h5cimage_name);
return FAIL;
}
- if(Image_h4_to_h5(file_id,ri_id,h5_pgroup,h5_palgroup)==FAIL) {
+ if(Image_h4_to_h5(file_id,ri_id,h5_pgroup,h5_palgroup,h4_attr)==FAIL) {
printf("error in transferring image name into hdf5 dataset.\n");
GRendaccess(ri_id);
free(h5cimage_name);
@@ -810,3 +810,11 @@ int convert_image(int32 file_id,int32 obj_ref,char * h5pgroup_name,
+
+
+
+
+
+
+
+