#include "h4toh5main.h" /*------------------------------------------------------------------------- * Function: Sds_h4_to_h5 * * Purpose: translate SDS object into hdf5 dataset * * Return: FAIL if failed, SUCCEED if successful. * * In : sds_id: SDS identifier h5_group: hdf5 group id h5_dimgroup: hdf5 dimension group id 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; 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; int empty; int32 num_sdsattrs; void* sds_data; int check_sdsname; int check_gloattr; char sdsname[MAX_NC_NAME]; char sdslabel[MAX_NC_NAME]; size_t h4size; size_t h4memsize; /* define varibles for hdf5. */ hid_t h5dset; hid_t h5d_sid; hid_t h5ty_id; hid_t h5_memtype; hid_t h5str_type; hid_t h5str_memtype; hsize_t h5dims[MAX_VAR_DIMS]; char* h5csds_name; herr_t ret; /* check whether the sds is empty. */ #if 0 if(SDcheckempty(sds_id,&empty)== FAIL) { printf("error in running SDcheckempty routine. \n"); return FAIL; } printf("empty %d\n",empty); if(empty != 0) return SUCCEED; #endif /*check whether the sds is created with unlimited dimension. */ 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. */ 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