/*------------------------------------------------------------------------- * * 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 * * 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; intn sds_empty; int32 istat; int i; 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; 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; hsize_t h5dims[MAX_VAR_DIMS]; hsize_t max_h5dims[MAX_VAR_DIMS]; char* h5csds_name; herr_t ret; /* 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. */ if(SDcheckempty(sds_id,&sds_empty)== FAIL) { printf("error in running SDcheckempty routine. \n"); return FAIL; } if(sds_empty != 0) return SUCCEED; /*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"); 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