From a219b97a88ffbc8d1641b1a1de7897823e7716ae Mon Sep 17 00:00:00 2001 From: MuQun Yang Date: Wed, 8 Nov 2000 18:14:41 -0500 Subject: [svn-r2839] Purpose: check in beta release h4toh5 converter Description: 1. add copy right and other comments to all .h and .c files 2. fix bugs on sds unlimited dimension, hdf5 dimensional scale attribute and vdata translating from h4 to h5. Solution: 2. 1) for sds with unlimited dimension to be converted into extensible hdf5 dataset, on hdf5 side, has to set a default chunk size even though the corresponding hdf4 file is not chunked. 2) in this version, if sds object doesn't have dimensional scale data, we will not show the default hdf4 dimensional name ("fakedim0", etc.) in the new hdf5 dimensional scale name attribute. 3) fix a bug transferring vdata of which the field includes a character array. Make it correctly transfer into the corresponding hdf5 compound data type. Platforms tested: eirene,arabica,baldric,hawkwind,paz,gondolin on new set of hdf4 test files. --- tools/h4toh5anno.c | 46 +++++++-- tools/h4toh5image.c | 37 ++++++- tools/h4toh5main.c | 143 ++++++++++++++++++-------- tools/h4toh5main.h | 47 ++++++++- tools/h4toh5pal.c | 30 +++++- tools/h4toh5sds.c | 278 +++++++++++++++++++++++++++++++++++++-------------- tools/h4toh5util.c | 147 +++++++++++++-------------- tools/h4toh5util.h | 46 +++++++-- tools/h4toh5vdata.c | 91 ++++++++--------- tools/h4toh5vgroup.c | 49 ++++++++- 10 files changed, 649 insertions(+), 265 deletions(-) diff --git a/tools/h4toh5anno.c b/tools/h4toh5anno.c index 199d5f1..31ba145 100644 --- a/tools/h4toh5anno.c +++ b/tools/h4toh5anno.c @@ -1,3 +1,33 @@ +/*------------------------------------------------------------------------- + * + * Copyright (C) 2000 National Center for Supercomputing Applications. + * All rights reserved. + * + *------------------------------------------------------------------------- + */ + +/****************************************************************************** + + Description: + +1. converter + +See HDF4 to HDF5 mapping specification at +(http://hdf.ncsa.uiuc.edu/HDF5/papers/h4toh5) for the default mapping +from HDF4 object to HDF5 object. + +The whole converter includes 10 files, h4toh5util.h, h4toh5main.h, h4toh5util.c, h4toh5main.c, h4toh5sds.c, h4toh5image.c,h4toh5vdata.c,h4toh5vgroup.c,h4toh5pal.c and h4toh5anno.c. + +2. this file + +converting an hdf4 annotation into an hdf5 attribute of the corresponding object. + + +Author: Kent Yang(ymuqun@ncsa.uiuc.edu) + + +*****************************************************************************/ + #include "h4toh5main.h" @@ -101,7 +131,7 @@ int Annofil_h4_to_h5(int32 file_id,hid_t h5group){ return FAIL; } - if ((sh5str_type = mkstr(ann_length+1,H5T_STR_NULLTERM))<0) { + if ((sh5str_type = mkstr(ann_length+1,H5T_STR_SPACEPAD))<0) { printf("error in making string at FILE lABEL ANNO. \n"); ANend(file_id); ANendaccess(ann_id); @@ -188,7 +218,7 @@ int Annofil_h4_to_h5(int32 file_id,hid_t h5group){ return FAIL; } - if ((sh5str1_type = mkstr(ann_length+1,H5T_STR_NULLTERM))<0) { + if ((sh5str1_type = mkstr(ann_length+1,H5T_STR_SPACEPAD))<0) { printf("error in making string at FILE DESC. \n"); ANend(an_id); ANendaccess(ann_id); @@ -331,7 +361,7 @@ int Annoobj_h4_to_h5(int32 file_id,int32 obj_ref, int32 obj_tag, return FAIL; } - if(num_lab_anno != 0) { + if(num_lab_anno > 0) { for(i=0; i 0) { for (i = 0; i< num_des_anno;i++) { @@ -469,7 +499,7 @@ int Annoobj_h4_to_h5(int32 file_id,int32 obj_ref, int32 obj_tag, h4toh5_ZeroMemory(ann_buf,(ann_length+1)*sizeof(char)); ANreadann(ann_id,ann_buf,ann_length+1); - if ((sh5str_type = mkstr(ann_length+1,H5T_STR_NULLTERM))<0) { + if ((sh5str_type = mkstr(ann_length+1,H5T_STR_SPACEPAD))<0) { printf("error in making string at OBJECT DESC. \n"); ANend(an_id); free(des_anno_list); @@ -536,7 +566,7 @@ int Annoobj_h4_to_h5(int32 file_id,int32 obj_ref, int32 obj_tag, ret = H5Sclose(h5_sid); ret = H5Aclose(h5_aid); free(ann_obj_name); - /* printf("ann_buf %s\n",ann_buf);*/ + free(ann_buf); } diff --git a/tools/h4toh5image.c b/tools/h4toh5image.c index 373a854..f651ee9 100644 --- a/tools/h4toh5image.c +++ b/tools/h4toh5image.c @@ -1,3 +1,31 @@ +/*------------------------------------------------------------------------- + * + * Copyright (C) 2000 National Center for Supercomputing Applications. + * All rights reserved. + * + *------------------------------------------------------------------------- + */ + +/****************************************************************************** + + Description: + +1. converter + +See HDF4 to HDF5 mapping specification at +(http://hdf.ncsa.uiuc.edu/HDF5/papers/h4toh5) for the default mapping +from HDF4 object to HDF5 object. + +The whole converter includes 10 files, h4toh5util.h, h4toh5main.h, h4toh5util.c, h4toh5main.c, h4toh5sds.c, h4toh5image.c,h4toh5vdata.c,h4toh5vgroup.c,h4toh5pal.c and h4toh5anno.c. + +2. this file + +converting an hdf4 image object into an hdf5 dataset, for three component image, this object will be converted into an hdf5 dataset with compound data type. + +Author: Kent Yang(ymuqun@ncsa.uiuc.edu) + + +*****************************************************************************/ #include "h4toh5main.h" @@ -120,7 +148,7 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) { return FAIL; } - /* obtaining absolute path of image name.*/ + /* obtaining absolute path of image name.*/ check_imagename = -10; h5cimage_name = get_name(gr_ref,2*num_images,gr_hashtab,&check_imagename); @@ -222,8 +250,7 @@ int Image_h4_to_h5(int32 file_id,int32 ri_id,hid_t h5_group,hid_t h5_palgroup) { H5Pclose(create_plist); return FAIL; } - - /* if(h4size != h4memsize) printf("h4size/h4memsize %d\n",h4size/h4memsize);*/ + fielddim[0] = ncomp; @@ -634,14 +661,14 @@ int gr_tranattrs(int32 sri_id, hid_t sh5_dset,int snum_grattrs, return FAIL; } - if ((sh5str_type = mkstr(count_sgradata*sh4_asize,H5T_STR_NULLTERM))<0){ + if ((sh5str_type = mkstr(count_sgradata*sh4_asize,H5T_STR_SPACEPAD))<0){ printf("error in making string for image attribute \n"); return FAIL; } /* check this line later. */ if ((sh5str_memtype = mkstr(count_sgradata*sh4_amemsize, - H5T_STR_NULLTERM))<0){ + H5T_STR_SPACEPAD))<0){ printf("error in making memory string. \n"); return FAIL; } diff --git a/tools/h4toh5main.c b/tools/h4toh5main.c index de51554..abf3d89 100644 --- a/tools/h4toh5main.c +++ b/tools/h4toh5main.c @@ -1,4 +1,35 @@ -/*** This file is the main program of converter. ***/ +/*------------------------------------------------------------------------- + * + * Copyright (C) 2000 National Center for Supercomputing Applications. + * All rights reserved. + * + *------------------------------------------------------------------------- + */ + +/****************************************************************************** + + Description: + +1. converter + +See HDF4 to HDF5 mapping specification at +(http://hdf.ncsa.uiuc.edu/HDF5/papers/h4toh5) for the default mapping +from HDF4 object to HDF5 object. + +The whole converter includes 10 files, h4toh5util.h, h4toh5main.h, h4toh5util.c, h4toh5main.c, h4toh5sds.c, h4toh5image.c,h4toh5vdata.c,h4toh5vgroup.c,h4toh5pal.c and h4toh5anno.c. + +2. this file + +This file describes the main driver of hdf to hdf5 converter. It checks +the inputting parameters, initializes the global tables, sets up the root level +hdf5 structure and also check the special case fof vgroup loops at HDF file. + + +Author: Kent Yang(ymuqun@ncsa.uiuc.edu) + + +*****************************************************************************/ + #include "h4toh5main.h" @@ -37,14 +68,13 @@ int main(int argc, char ** argv) { char *h5_extension; int status = 0; - argc--; argv++; if (argc == 0) { fprintf(stderr,"\nError: Invalid Arguments\n"); PrintOptions_h4toh5(); - return -1; + return FAIL; } /* take care -h (help) option first */ @@ -52,7 +82,7 @@ int main(int argc, char ** argv) { for (i=0; i < argc; i++) if ( HDstrcmp(argv[i],"-h") == 0 ) { PrintOptions_h4toh5(); - return 0; + return SUCCEED; } } @@ -79,6 +109,14 @@ int main(int argc, char ** argv) { break; } + /*0. check whether this file is an hdf file. */ + + if(!Hishdf(h4_filename)){ + printf("error: not an hdf file. \n"); + printf("the file will not be converted. \n"); + status = -1; + break; + } h5_extension = HDstrdup("h5"); h5_filename = BuildFilename(h4_filename,h5_extension); if (h5_filename == NULL) { @@ -94,15 +132,6 @@ int main(int argc, char ** argv) { break; } - /*0. check whether this file is a hdf file. */ - - if(!Hishdf(h4_filename)){ - printf("error: not an hdf file. \n"); - printf("the file will not be converted. \n"); - return FAIL; - } - - status = h4toh5(h4_filename, h5_filename); if ( status == FAIL ) { @@ -115,7 +144,8 @@ int main(int argc, char ** argv) { break; - case 2: /* h5toh4 file_in file_out */ + case 2: /* h4toh5 file_in file_out */ + h4_filename = argv[0]; h5_filename = argv[1]; @@ -132,25 +162,27 @@ int main(int argc, char ** argv) { break; } + /*0. check whether this file is a hdf file. */ + + if(!Hishdf(h4_filename)){ + printf("error: not an hdf file. \n"); + printf("the file will not be converted. \n"); + status = -1; + break; + } + if (test_file(h5_filename,O_CREAT|O_RDWR,436) != 0) { /* 436 Decimal - 0664 Octal, ug+rw,o+r */ printf("permission of hdf5 file is not set properly.\n"); status = -1; break; } + if (test_dir(h4_filename) != 0 ) { fprintf(stderr,"%s: Is a directory\n",h4_filename); status = -1; break; } - /*0. check whether this file is a hdf file. */ - - if(!Hishdf(h4_filename)){ - printf("error: not an hdf file. \n"); - printf("the file will not be converted. \n"); - return FAIL; - } - status = h4toh5(h4_filename, h5_filename); if ( status == FAIL ) { printf("error in converting %sinto %s\n",h4_filename,h5_filename); @@ -191,9 +223,6 @@ int h4toh5(char*filename4, char*filename5) { hid_t h5_dimg;/* hdf5 dimensional scale group identifier. */ hid_t h5_palg;/* hdf5 palette group identifier. */ - - - /*1. open the current hdf4 file. */ file_id = Hopen(filename4, DFACC_READ, 0); @@ -381,7 +410,8 @@ int h4toh5(char*filename4, char*filename5) { /*** deal with untouched sds objects.convert them into hdf5 datasets under root group.***/ if(h4toh5unvisitedsds(file_id,sd_id,h5_root,h5_dimg) == FAIL) { - printf("error in converting unvisited sds objects into hdf5 file.\n"); SDend(sd_id); + printf("error in converting unvisited sds objects into hdf5 file.\n"); + SDend(sd_id); GRend(gr_id); Vend(file_id); Hclose(file_id); @@ -462,7 +492,6 @@ int get_numof_hdf4obj(char*filename,int32 file_id) { return FAIL; } - /* obtain number of images and number of global image attributes.*/ gr_id = GRstart(file_id); @@ -575,7 +604,7 @@ int set_helpgroups(hid_t h5root,hid_t* h5dimgptr,hid_t* h5palgptr){ */ int set_hashtables(void) { - if(num_sds != 0) { + if(num_sds > 0) { sds_hashtab = malloc(sizeof(struct table)*2*num_sds); if(init_tab(2*num_sds,sds_hashtab)== FAIL){ printf("cannot initialize sds hashing table. \n"); @@ -583,7 +612,7 @@ int set_hashtables(void) { } } - if(num_images != 0) { + if(num_images > 0) { gr_hashtab = malloc(sizeof(struct table)*2*num_images); if(init_tab(2*num_images,gr_hashtab) == FAIL){ printf("cannot initialize image hashing table. \n"); @@ -593,7 +622,7 @@ int set_hashtables(void) { /*hashtable is made to be fixed for dimensional scale and palette.*/ - if(num_sds != 0) { + if(num_sds > 0) { dim_hashtab = malloc(sizeof(struct name_table)*DIM_HASHSIZE); if(init_nametab(DIM_HASHSIZE,dim_hashtab) == FAIL) { printf("can not initialize dimension hashing table.\n"); @@ -602,7 +631,7 @@ int set_hashtables(void) { } /* initialize the palette table */ - if(num_images != 0){ + if(num_images > 0){ pal_hashtab = malloc(sizeof(struct table)*PAL_HASHSIZE); if(init_tab(PAL_HASHSIZE,pal_hashtab) == FAIL) { printf("can not initialize palette hashing table.\n"); @@ -699,6 +728,10 @@ int h4toh5lonevgs(int32 file_id,int32 sd_id,hid_t h5group,hid_t h5_dimg,hid_t h5 /* obtain object reference array. */ + /* if no lone vgroup, quit from this function. */ + if(num_lonevg == 0) + return SUCCEED; + ref_array = (int32 *)malloc(sizeof(int32) *num_lonevg); if(ref_array == NULL) { @@ -783,7 +816,7 @@ int h4toh5lonevgs(int32 file_id,int32 sd_id,hid_t h5group,hid_t h5_dimg,hid_t h5 return FAIL; } - /* printf("h5cgroup_name %s\n",h5cgroup_name);*/ + /* free memory of corrected name. */ free(cor_vgroupname); /* updating lookup table for vgroups.*/ @@ -803,7 +836,7 @@ int h4toh5lonevgs(int32 file_id,int32 sd_id,hid_t h5group,hid_t h5_dimg,hid_t h5 } } - /* this line is for debugging. */ + /* this line should never fail, if failed, something is wrong with converter or hdf library. */ if(check_vgroup == 1){ fprintf(stderr,"this vgroup should not be touched. \n"); @@ -993,7 +1026,7 @@ int h4toh5vgrings(int32 file_id,int32 sd_id,hid_t h5group,hid_t h5_dimg,hid_t h5 Vdetach(vgroup_id); free(h5cgroup_name); - } + } ref_num = Vgetid(file_id,ref_num); } return SUCCEED; @@ -1044,6 +1077,7 @@ int h4toh5lonevds(int32 file_id, hid_t h5group){ ref_vdata_array = (int32 *)malloc(sizeof(int32) *(num_lonevd)); num_lonevd = VSlone(file_id,ref_vdata_array,num_lonevd); + if(num_lonevd == FAIL) { printf("error in obtaining lone vdata number the second time.\n"); free(ref_vdata_array); @@ -1124,6 +1158,8 @@ int h4toh5lonevds(int32 file_id, hid_t h5group){ free(cor_vdataname); check_vdata = lookup(ref_vdata_array[lone_vd_number],estnum_vd, vd_hashtab); + + /* check_vdata should be 1, if it is 1, either converter or hdf lib has bugs. */ if(check_vdata == 1){ printf("lone vdata should not be checked before.\n"); free(h5cvdata_name); @@ -1210,7 +1246,7 @@ int h4toh5unvisitedsds(int32 file_id,int32 sd_id,hid_t h5root,hid_t h5_dimg) { return FAIL; } - /* if this sds is dimensional scale, the converting should be ignored. */ + /* if this sds is dimensional scale, the converting should be ignored. dimensional scale will be converted separately. */ if(SDiscoordvar(sds_id)) continue; /* obtain sds information. */ @@ -1246,7 +1282,7 @@ int h4toh5unvisitedsds(int32 file_id,int32 sd_id,hid_t h5root,hid_t h5_dimg) { if(check_sds == 0) { /* since different hdf sds may hold the same name and it is also legal that sds may not have a name; but for hdf5 dataset, - it must hold a name, so we will use get_obj_aboname to guarrtte + it must hold a name, so we will use get_obj_aboname to assure that each new hdf5 dataset converted from sds objects will have a disabiguous name. */ @@ -1257,6 +1293,7 @@ int h4toh5unvisitedsds(int32 file_id,int32 sd_id,hid_t h5root,hid_t h5_dimg) { SDendaccess(sds_id); return FAIL; } + h5csds_name = get_obj_aboname(cor_sdsname,refstr,NULL,HDF4_SDS); if(h5csds_name == NULL) { printf("error in obtaining sds name.\n"); @@ -1281,8 +1318,10 @@ int h4toh5unvisitedsds(int32 file_id,int32 sd_id,hid_t h5root,hid_t h5_dimg) { return FAIL; } free(h5csds_name); + } SDendaccess(sds_id); + } return SUCCEED; } @@ -1305,6 +1344,7 @@ int h4toh5unvisitedsds(int32 file_id,int32 sd_id,hid_t h5root,hid_t h5_dimg) { Modification: *------------------------------------------------------------------------- */ + int h4toh5unvisitedimages(int32 file_id,hid_t h5_root,hid_t h5_palg) { int i; @@ -1443,12 +1483,7 @@ void free_allhashmemory(){ } -void PrintOptions_h4toh5(void) -{ - fprintf(stderr,"\nh4toh5 -h (gives this print-out)\n"); - fprintf(stderr,"h4toh5 file.hdf file.h5\n"); - fprintf(stderr,"h4toh5 file.hdf\n"); -} + /********The following routines are adapted from h5toh4 converter. *******/ /***************************************************************************** @@ -1553,3 +1588,27 @@ char *BuildFilename(char *filename, char *ext) } +/***************************************************************************** + + Routine: PrintOptions_h4toh5() + + Description: This routine prints the acceptable argument formats out to stderr. + + Input: None + + Output: output to stderr + +*****************************************************************************/ + +void PrintOptions_h4toh5(void) +{ + fprintf(stderr,"\nUsage: "); + fprintf(stderr,"\n h4toh5 -h (gives this print-out)\n"); + fprintf(stderr," h4toh5 input.hdf output.h5\n"); + fprintf(stderr," h4toh5 input.hdf\n"); +} + + + + + diff --git a/tools/h4toh5main.h b/tools/h4toh5main.h index bac5baf..2bb6c88 100644 --- a/tools/h4toh5main.h +++ b/tools/h4toh5main.h @@ -1,3 +1,33 @@ +/*------------------------------------------------------------------------- + * + * Copyright (C) 2000 National Center for Supercomputing Applications. + * All rights reserved. + * + *------------------------------------------------------------------------- + */ + +/****************************************************************************** + +Description: + +1. converter + +See HDF4 to HDF5 mapping specification at +(http://hdf.ncsa.uiuc.edu/HDF5/papers/h4toh5) for the default mapping +from HDF4 object to HDF5 object. + +The whole converter includes 10 files, h4toh5util.h, h4toh5main.h, h4toh5util.c, h4toh5main.c, h4toh5sds.c, h4toh5image.c,h4toh5vdata.c,h4toh5vgroup.c,h4toh5pal.c and h4toh5anno.c. + +2. this file + +including declarations of subroutines of all .c files excluding h4toh5util.c. + +Author: Kent Yang(ymuqun@ncsa.uiuc.edu) + + +*****************************************************************************/ + + #ifndef H4TOH5MAIN_H #define H4TOH5MAIN_H #include "hdf.h" @@ -6,13 +36,26 @@ #include "h4toh5util.h" #include #include +#endif + +/* For windows support.*/ +#if WIN32 +typedef unsigned int mode_t; +#endif + +#ifndef S_ISDIR +#define S_ISDIR(mode) (((mode)&0xF000) == S_IFDIR) +#endif + +/* subroutines to check initial settings and inputting parameters. +Adapted from h5toh4 tools and used for h4toh5main.c */ -/* subroutines adapted from h5toh4 tools and used for h4toh5main.c */ void PrintOptions_h4toh5(void); int test_file(char *filename,int oflag,mode_t mode); int test_dir(char *); char *BuildFilename(char *filename, char *ext); +/* subroutines for h4toh5main.c */ int h4toh5(char*,char*); int get_numof_hdf4obj(char*,int32); int set_hashtables(void); @@ -57,7 +100,7 @@ int Annoobj_h4_to_h5(int32,int32,int32,hid_t); /*subroutines for h4toh5pal.c*/ int Palette_h4_to_h5(int32,int32 ,hid_t,char *); -#endif + diff --git a/tools/h4toh5pal.c b/tools/h4toh5pal.c index fc59cce..9fc1ec7 100644 --- a/tools/h4toh5pal.c +++ b/tools/h4toh5pal.c @@ -1,3 +1,31 @@ +/*------------------------------------------------------------------------- + * + * Copyright (C) 2000 National Center for Supercomputing Applications. + * All rights reserved. + * + *------------------------------------------------------------------------- + */ + +/****************************************************************************** + + Description: + +1. converter + +See HDF4 to HDF5 mapping specification at +(http://hdf.ncsa.uiuc.edu/HDF5/papers/h4toh5) for the default mapping +from HDF4 object to HDF5 object. + +The whole converter includes 10 files, h4toh5util.h, h4toh5main.h, h4toh5util.c, h4toh5main.c, h4toh5sds.c, h4toh5image.c,h4toh5vdata.c,h4toh5vgroup.c,h4toh5pal.c and h4toh5anno.c. + +2. this file + +Converting an hdf4 palette object into a hdf5 dataset. +Author: Kent Yang(ymuqun@ncsa.uiuc.edu) + + +*****************************************************************************/ + #include "h4toh5main.h" @@ -62,7 +90,7 @@ int Palette_h4_to_h5(int32 file_id,int32 pal_id,hid_t h5g,char*pal_name) { uint8. */ if (h5type == H5T_STRING) { - if(h5string_to_int(DFNT_UCHAR8,&h5memtype,h4memsize,&h5type)==FAIL) { + if(h5string_to_int(pal_type,&h5memtype,h4memsize,&h5type)==FAIL) { fprintf(stderr,"failed to translate H5T_STRING to int8."); return FAIL; } diff --git a/tools/h4toh5sds.c b/tools/h4toh5sds.c index 265ea55..6c07724 100644 --- a/tools/h4toh5sds.c +++ b/tools/h4toh5sds.c @@ -1,5 +1,33 @@ -#include "h4toh5main.h" +/*------------------------------------------------------------------------- + * + * Copyright (C) 2000 National Center for Supercomputing Applications. + * All rights reserved. + * + *------------------------------------------------------------------------- + */ + +/****************************************************************************** + + Description: + +1. converter + +See HDF4 to HDF5 mapping specification at +(http://hdf.ncsa.uiuc.edu/HDF5/papers/h4toh5) for the default mapping +from HDF4 object to HDF5 object. + +The whole converter includes 10 files, h4toh5util.h, h4toh5main.h, h4toh5util.c, h4toh5main.c, h4toh5sds.c, h4toh5image.c,h4toh5vdata.c,h4toh5vgroup.c,h4toh5pal.c and h4toh5anno.c. + +2. this file + +Converting an hdf4 sds object into an hdf5 dataset. + +Author: Kent Yang(ymuqun@ncsa.uiuc.edu) + +*****************************************************************************/ + +#include "h4toh5main.h" /*------------------------------------------------------------------------- * Function: Sds_h4_to_h5 @@ -15,7 +43,8 @@ dim_pathname: dimensional path name *------------------------------------------------------------------------- - */ + */ + int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){ int32 sds_dtype; @@ -26,6 +55,7 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){ int32* sds_stride; int32 count_sdsdata; int32 sds_ref; + intn sds_empty; int32 istat; int i; int32 num_sdsattrs; @@ -39,7 +69,7 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){ size_t h4size; size_t h4memsize; HDF_CHUNK_DEF c_def_out; - int32* chunk_dims; + hsize_t* chunk_dims; int32 c_flags; /* define varibles for hdf5. */ @@ -50,21 +80,21 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){ hid_t h5_memtype; hid_t create_plist; hsize_t h5dims[MAX_VAR_DIMS]; + hsize_t max_h5dims[MAX_VAR_DIMS]; char* h5csds_name; herr_t ret; /* check whether the sds is empty. */ -#if 0 - if(SDcheckempty(sds_id,&empty)== FAIL) { + + if(SDcheckempty(sds_id,&sds_empty)== FAIL) { printf("error in running SDcheckempty routine. \n"); return FAIL; } - printf("empty %d\n",empty); - if(empty != 0) return SUCCEED; -#endif + if(sds_empty != 0) return SUCCEED; + /*check whether the sds is created with unlimited dimension. */ @@ -73,24 +103,12 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){ return FAIL; } - if(SDisrecord(sds_id)) { - if (SDgetinfo(sds_id,sdsname,&sds_rank,sds_dimsizes,&sds_dtype, - &num_sdsattrs)==FAIL) { - printf("unable to get information of sds h5dset.\n"); - return FAIL; - } - - } - else { /*obtain name,rank,dimsizes,datatype and num of attributes of sds */ if (SDgetinfo(sds_id,sdsname,&sds_rank,sds_dimsizes,&sds_dtype, &num_sdsattrs)==FAIL) { printf("unable to get information of sds h5dset.\n"); return FAIL; } - } - - /* if(sdsname !=NULL) printf("sdsname %s\n",sdsname);*/ /* obtain start,edge, stride and number of sds data. */ @@ -124,9 +142,12 @@ int Sds_h4_to_h5(int32 file_id,int32 sds_id,hid_t h5_group,hid_t h5_dimgroup){ } - for (i=0;iname = malloc(strlen(name)+1); @@ -1037,7 +1028,7 @@ int h4_transpredattrs(hid_t h5g,const char *attrname,char*data){ h5str_size = strlen(data); - if ((h5str_type = mkstr(h5str_size,H5T_STR_NULLTERM))<0) { + if ((h5str_type = mkstr(h5str_size,H5T_STR_SPACEPAD))<0) { printf("error in making string for predefined ATTR. \n"); return FAIL; } @@ -1150,7 +1141,7 @@ int vg_transattrs(int32 h4vg,hid_t h5g) { /* now do attribute-transferring. 1. deal with string data type - 2. set attribute space. + 2. set attribute space 3. get attribute name, set property list. */ if (sh5_atype == H5T_STRING ) { @@ -1164,15 +1155,15 @@ int vg_transattrs(int32 h4vg,hid_t h5g) { return FAIL; } - if ((sh5str_type = mkstr(count_vgattr*sh4_size,H5T_STR_NULLTERM))<0) { + if ((sh5str_type = mkstr(count_vgattr*sh4_size,H5T_STR_SPACEPAD))<0) { fprintf(stderr,"error in making string for VGROUP ATTR. \n"); free(vg_adata); return FAIL; } - /* check this line later. */ + if ((sh5str_memtype = mkstr(count_vgattr*sh4_amemsize, - H5T_STR_NULLTERM))<0){ + H5T_STR_SPACEPAD))<0){ fprintf(stderr,"error in making memory string for VGROUP ATTR. \n"); free(vg_adata); return FAIL; @@ -1322,9 +1313,11 @@ char* get_obj_aboname(char* obj_name,char* refstr,char* path_name, int check_name; char check_char; + /* sometimes although the object name is not NULL, but it is empty. We will use make_objname_no under this situation. */ if(obj_name != NULL) check_char = *obj_name; + /* obtain the absolute name of the object. */ if (obj_name == NULL || check_char == '\0') abo_objname = make_objname_no(refstr,path_name,objstr); @@ -1336,7 +1329,7 @@ char* get_obj_aboname(char* obj_name,char* refstr,char* path_name, check_name = lookup_name(abo_objname,num_objects,name_hashtab); if(check_name == 1) { - + /* name_clashing is found. */ if(objstr != NULL && refstr != NULL){ free(abo_objname); @@ -1370,6 +1363,7 @@ char* get_obj_aboname(char* obj_name,char* refstr,char* path_name, } } } + return abo_objname; } @@ -1405,7 +1399,7 @@ char* make_objname_no(char* refstr,char* path_name,const char*objstr) { new_objname= malloc(strlen(objstr)+strlen(refstr)+3); if(new_objname == NULL) { - printf("error in allocating memory. \n"); + printf("error in allocating memory for object name. \n"); return NULL; } h4toh5_ZeroMemory(new_objname,strlen(objstr)+strlen(refstr)+3); @@ -1495,11 +1489,14 @@ char* trans_obj_name(int32 obj_tag,int32 index) { char* obj_name; char indstr[5]; + /* the reason why we allocate memory with strlen(HDF4_PALETTE) is + HDF4_PALETTE is the longest string among HDF4_??? */ obj_name = malloc(strlen(HDF4_PALETTE)+strlen(ATTR)+8); if(obj_name == NULL) { printf("cannot allocate memory for object name. \n"); return NULL; } + h4toh5_ZeroMemory(obj_name,strlen(HDF4_PALETTE)+strlen(ATTR)+8); if(conv_int_str(index,indstr)== FAIL) { @@ -1563,20 +1560,20 @@ char* trans_obj_name(int32 obj_tag,int32 index) { void freehashmemory(void){ - if(estnum_vg != 0) freetable(estnum_vg,vg_hashtab); - if(estnum_vd != 0) freetable(estnum_vd,vd_hashtab); + if(estnum_vg > 0) freetable(estnum_vg,vg_hashtab); + if(estnum_vd > 0) freetable(estnum_vd,vd_hashtab); - if(num_sds !=0) { + if(num_sds > 0) { freetable(2*num_sds,sds_hashtab); freenametable(DIM_HASHSIZE,dim_hashtab); } - if(num_images !=0) { + if(num_images > 0) { freetable(2*num_images,gr_hashtab); freetable(PAL_HASHSIZE,pal_hashtab); } - if(num_objects !=0) freenametable(num_objects,name_hashtab); + if(num_objects > 0) freenametable(num_objects,name_hashtab); } diff --git a/tools/h4toh5util.h b/tools/h4toh5util.h index 503e02c..5772325 100644 --- a/tools/h4toh5util.h +++ b/tools/h4toh5util.h @@ -1,3 +1,34 @@ +/*------------------------------------------------------------------------- + * + * Copyright (C) 2000 National Center for Supercomputing Applications. + * All rights reserved. + * + *------------------------------------------------------------------------- + */ + +/****************************************************************************** + + Description: + +1. converter + +See HDF4 to HDF5 mapping specification at +(http://hdf.ncsa.uiuc.edu/HDF5/papers/h4toh5) for the default mapping +from HDF4 object to HDF5 object. + +The whole converter includes 10 files, h4toh5util.h, h4toh5main.h, h4toh5util.c, h4toh5main.c, h4toh5sds.c, h4toh5image.c,h4toh5vdata.c,h4toh5vgroup.c,h4toh5pal.c and h4toh5anno.c. + +2. this file + +Including declarations of global variables,global hashtables,constant +and utility subroutines of h4toh5util.c + +Author: Kent Yang(ymuqun@ncsa.uiuc.edu) + + +*****************************************************************************/ + + #ifndef UTILITY_H #define UTILITY_H #include "hdf5.h" @@ -11,7 +42,7 @@ converter.*/ /*********************************************/ /* 0. if "/" is found in hdf4 object name, we will use another - character "_" to replace it. */ + character "_" to replace it, since "/" is a reserved symbol for hdf5. */ #define ORI_SLASH '/' #define CHA_SLASH '_' @@ -47,7 +78,8 @@ converter.*/ #define DIMSCALE "DIMSCALE" -/* 5. define affix GLOBAL for dealing sds and image file attributes. */ +/* 5. define affix GLO for sds and image file attributes. these file attributes + will be put under root group. */ #define GLOSDS "GLOSDS" #define GLOIMAGE "GLOIMAGE" @@ -60,7 +92,7 @@ converter.*/ #define RAST24LABEL "raster24" #define PALABEL "palette" -/* 7. define HDF object class. */ +/* 7. define "IMAGE" CLASS required by image spec. */ #define IM_CLASS "IMAGE" /* 8. reserved group name for HDF4 dimensional scale and palette. */ @@ -112,9 +144,9 @@ extern int32 num_glgrattrs; functions used in h4-h5 converter.*/ /*********************************************/ /*define two kinds of hashtables. - 1. struct table will use object reference as the key to handle whether this + 1. struct table uses object reference as the key to handle whether this object is visited or not. - 2. struct name_table will use name as the key to handle name clashings and + 2. struct name_table uses object name as the key to handle name clashings and dimensional scale dataset. */ @@ -139,6 +171,7 @@ extern struct name_table* dim_hashtab; /* routine for zeroing out the memory. */ void h4toh5_ZeroMemory(void*s,size_t n); + /* look-up table, object reference is the key.*/ int lookup(int,int,struct table*); @@ -165,7 +198,7 @@ void freehashmemory(void); functions used in h4-h5 converter.*/ /*********************************************/ -/* this routine defines the convertion of data type from h4 to h5. */ +/* this routine defines the conversion of data type from h4 to h5. */ herr_t h4type_to_h5type(const int32 h4type, hid_t* h5memtype, size_t* h4memsize, size_t* h4size, hid_t *h5type); @@ -179,6 +212,7 @@ hid_t mkstr(int size, H5T_str_t pad); herr_t h5string_to_int(const int32, hid_t*,const size_t,hid_t* ); int conv_int_str(uint16, char*); +/* these routines were utility functions for other routines at h4toh5util.c */ char* trans_obj_name(int32,int32); char* get_obj_aboname(char*,char*,char*,const char*); char* make_objname_no(char*,char*,const char*); diff --git a/tools/h4toh5vdata.c b/tools/h4toh5vdata.c index f15922a..b078791 100644 --- a/tools/h4toh5vdata.c +++ b/tools/h4toh5vdata.c @@ -1,3 +1,31 @@ +/*------------------------------------------------------------------------- + * + * Copyright (C) 2000 National Center for Supercomputing Applications. + * All rights reserved. + * + *------------------------------------------------------------------------- + */ + +/****************************************************************************** + + Description: + +1. converter + +See HDF4 to HDF5 mapping specification at +(http://hdf.ncsa.uiuc.edu/HDF5/papers/h4toh5) for the default mapping +from HDF4 object to HDF5 object. + +The whole converter includes 10 files, h4toh5util.h, h4toh5main.h, h4toh5util.c, h4toh5main.c, h4toh5sds.c, h4toh5image.c,h4toh5vdata.c,h4toh5vgroup.c,h4toh5pal.c and h4toh5anno.c. + +2. this file + +Converting an hdf4 independent vdata object into an hdf5 dataset of compound dataset. + +Author: Kent Yang(ymuqun@ncsa.uiuc.edu) + + +*****************************************************************************/ #include "h4toh5main.h" @@ -161,11 +189,7 @@ int Vdata_h4_to_h5(int32 file_id,int32 vdata_id, hid_t group_id) { vdatamem_size +=fieldorder*h4memsize[i]; } - - - - /* printf("vdatamem_size %d\n",vdatamem_size); - printf("vdata_size %d\n",vdata_size);*/ + vd_data = malloc(vdatamem_size*n_records); istat = VSsetfields(vdata_id,field_name_list); @@ -195,7 +219,7 @@ int Vdata_h4_to_h5(int32 file_id,int32 vdata_id, hid_t group_id) { for (i=0;i