diff options
author | MuQun Yang <ymuqun@hdfgroup.org> | 2001-06-11 21:20:10 (GMT) |
---|---|---|
committer | MuQun Yang <ymuqun@hdfgroup.org> | 2001-06-11 21:20:10 (GMT) |
commit | 1a5197918c0ef3e9f26af8538cf8c278bfa09fe2 (patch) | |
tree | 69beb8b96244f379cc524d7d8fac3a66559b3886 /tools | |
parent | 1b484c377cfb56b4f36840f74a85bf86211f71e6 (diff) | |
download | hdf5-1a5197918c0ef3e9f26af8538cf8c278bfa09fe2.zip hdf5-1a5197918c0ef3e9f26af8538cf8c278bfa09fe2.tar.gz hdf5-1a5197918c0ef3e9f26af8538cf8c278bfa09fe2.tar.bz2 |
[svn-r3988]
Purpose:
new features
Description:
1. add an option to convert HDF4 file without HDF4 specified attributes such as
HDF4_OBJECT_TYPE, HDF4_REF_NUM etc.
it can be done by inputting "h4toh5 -na input.hdf"
The default converter will still keep HDF4 specfied attributes.
2. Add compression features (gzip) for image too. Now the compressed HDF4 image
can be supported by using HDF5 gzip. Not sure whether tools can read it. Need to be tested.
3. Change SPACEPAD to NULLTERM for HDF4 dimensional name list. We can use variable length HDF5 string to represent these names, however currently H5dump and H5view cannot support variable length HDF5 string. converter will wait for other tools' update.
Solution:
Platforms tested:
eirene(Red Hat 6.2) and arabica(solaris 2.7)
Diffstat (limited to 'tools')
-rw-r--r-- | tools/h4toh5/h4toh5image.c | 208 | ||||
-rw-r--r-- | tools/h4toh5/h4toh5main.c | 264 | ||||
-rw-r--r-- | tools/h4toh5/h4toh5main.h | 35 | ||||
-rw-r--r-- | tools/h4toh5/h4toh5pal.c | 7 | ||||
-rw-r--r-- | tools/h4toh5/h4toh5sds.c | 87 | ||||
-rw-r--r-- | tools/h4toh5/h4toh5util.c | 8 | ||||
-rw-r--r-- | tools/h4toh5/h4toh5util.h | 2 | ||||
-rw-r--r-- | tools/h4toh5/h4toh5vdata.c | 7 | ||||
-rw-r--r-- | tools/h4toh5/h4toh5vgroup.c | 36 |
9 files changed, 479 insertions, 175 deletions
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 85c416d..7bfa794 100644 --- a/tools/h4toh5/h4toh5main.h +++ b/tools/h4toh5/h4toh5main.h @@ -57,42 +57,43 @@ 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 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*/ @@ -101,7 +102,7 @@ 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 b488f78..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; @@ -115,7 +115,7 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){ return FAIL; } if(sds_empty !=0) { - if(convert_sdsfillvalue(file_id,sds_id,h5_group,h5_dimgroup)==FAIL) { + if(convert_sdsfillvalue(file_id,sds_id,h5_group,h5_dimgroup,h4_attr)==FAIL) { printf("cannot convert fill value successfully.\n"); return FAIL; } @@ -530,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) { @@ -572,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); @@ -820,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; @@ -831,6 +831,7 @@ 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]; @@ -842,8 +843,11 @@ 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; @@ -853,11 +857,12 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset, 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; @@ -887,13 +892,22 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset, SDendaccess(sdsdim_id); return FAIL; } + + /* 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. */ + /* 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); @@ -918,7 +932,11 @@ 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 @@ -932,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; @@ -944,7 +968,10 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset, return FAIL; } + /* 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; @@ -1065,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); @@ -1117,12 +1144,16 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset, return FAIL; } k =0; + for(i=0;i<count_h5objref;i++){ - h4toh5_ZeroMemory(h5newsdsdim_name,MAX_DIM_NAME); if(sdsdimempty[i]) k = k +1; - strcpy(h5newsdsdim_name,&h5sdsdim_allname[k*MAX_DIM_NAME]); - + 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) { @@ -1134,7 +1165,9 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset, } alldim_refdat[i] = dim_refdat; k = k +1; - } + + /*free(h5newsdsdim_name); for variable length HDF5 string 6/11/2001.*/ + } attribID = H5Acreate(sh5dset,DIMSCALE,attr_refType,attr_refSpace, H5P_DEFAULT); @@ -1166,13 +1199,21 @@ int sdsdim_to_h5dataset(int32 sds_id,int32 sds_rank,hid_t sh5dset, 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); @@ -1191,15 +1232,22 @@ 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 convert_sdsfillvalue(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup,int h4_attr){ int32 sds_dtype; @@ -1519,6 +1567,7 @@ int convert_sdsfillvalue(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimg /* 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) { @@ -1561,7 +1610,7 @@ int convert_sdsfillvalue(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimg printf("unable to transfer sds ref. to HDF5 dataset attribute.\n"); return FAIL; } - + } free(sds_start); free(sds_edge); free(sds_stride); 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 31252d3..2cda0cc 100644 --- a/tools/h4toh5/h4toh5util.h +++ b/tools/h4toh5/h4toh5util.h @@ -218,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 e1b20d1..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. */ @@ -388,6 +388,7 @@ int Vdata_h4_to_h5(int32 file_id,int32 vdata_id, hid_t group_id) { /* converting predefined attributes. */ + if(h4_attr != 0) { istat = VSisattr(vdata_id); if (istat == FAIL) { printf("error in checking vdata attribute. \n"); @@ -428,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); @@ -805,7 +806,6 @@ int gen_h5comptype(int32 vdata_id,int32 nfields, printf("error closing array datatype.\n"); return FAIL; } - } @@ -838,3 +838,4 @@ int gen_h5comptype(int32 vdata_id,int32 nfields, + diff --git a/tools/h4toh5/h4toh5vgroup.c b/tools/h4toh5/h4toh5vgroup.c index 1605ec8..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; @@ -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, + + + + + + + + |