/***************************************************************************** This test generates attributes, groups, and datasets of many types. It creates a large number of attributes, groups, and datasets by specifying -a, -g, -d options respectively. Using "-h" option to see details. Programmer: Peter Cao , Jan. 2013 ****************************************************************************/ #include "hdf5.h" #include #include #define FNAME "test_perf.h5" #define NGROUPS 20 #define NDSETS 20 #define NATTRS 20 #define NROWS 40 #define NTYPES 9 #define MAXVLEN 10 #define FIXED_LEN 8 typedef enum { SOLID=0, LIQUID, GAS, PLASMA } phase_t; typedef struct { int i; unsigned long long l; float f; double d; char s[FIXED_LEN]; phase_t e; float f_array[FIXED_LEN]; hvl_t i_vlen; char *s_vlen; } test_comp_t; typedef struct { int zipcode; char *city; } zipcode_t; void add_attrs(hid_t oid, int idx); void add_attr(hid_t oid, const char *name, hid_t tid, hid_t sid, void *buf) ; int main (int argc, char *argv[]) { char fname[32]; int i, ngrps=NGROUPS, ndsets=NDSETS, nattrs=NATTRS, nrows=NROWS, chunk=NROWS/10+1, vlen=MAXVLEN, l=0, z=0; memset(fname, 0, 32); for (i=1; inrows) chunk=nrows/4; if (chunk<1) chunk = 1; if (vlen<1) vlen = MAXVLEN; if (strlen(fname)<=0) sprintf(fname, FNAME); create_perf_test_file(fname, ngrps, ndsets, nattrs, nrows, (hsize_t)chunk, vlen, z, l); return 0; } /***************************************************************************** This function generates attributes, groups, and datasets of many types. Parameters: fname: file_name. ngrps: number of top level groups. ndsets: number of datasets. attrs: number of attributes. nrow: number of rows in a dataset. chunk: chunk size (single number). vlen: max vlen size. comp: use latest format. latest: use gzip comnpression. Return: Non-negative on success/Negative on failure Programmer: Peter Cao , Jan. 2013 ****************************************************************************/ herr_t create_perf_test_file(const char *fname, int ngrps, int ndsets, int nattrs, int nrows, hsize_t chunk, int vlen, int compressed, int latest) { int i, j, k; hid_t fid, sid_null, sid_1d, sid_2d, did, aid, sid_2, fapl=H5P_DEFAULT, dcpl=H5P_DEFAULT, gid1, gid2, cmp_tid, tid_str, tid_enum, tid_array_f, tid_vlen_i, tid_vlen_s; char name[32]; hsize_t dims[1]={nrows}, dims2d[2]={nrows, (nrows/4+1)}, dims_array[1]={FIXED_LEN}, dim1[1]={2}; char *enum_names[4] = {"SOLID", "LIQUID", "GAS", "PLASMA"}; test_comp_t *buf_comp=NULL; int *buf_int=NULL; float (*buf_float_a)[FIXED_LEN]=NULL; double **buf_double2d=NULL; hvl_t *buf_vlen_i=NULL; char (*buf_str)[FIXED_LEN]; char **buf_vlen_s=NULL; hobj_ref_t buf_ref[2]; hdset_reg_ref_t buf_reg_ref[2]; size_t offset; herr_t status; char *names[NTYPES] = { "int", "ulong", "float", "double", "fixed string", "enum", "fixed float array", "vlen int array", "vlen strings"}; hid_t types[NTYPES] = { H5T_NATIVE_INT, H5T_NATIVE_UINT64, H5T_NATIVE_FLOAT, H5T_NATIVE_DOUBLE, tid_str, tid_enum, tid_array_f, tid_vlen_i, tid_vlen_s}; hsize_t coords[4][2] = { {0, 1}, {3, 5}, {1, 0}, {2, 4}}, start=0, stride=1, count=1; /* create fixed string datatype */ types[4] = tid_str = H5Tcopy (H5T_C_S1); H5Tset_size (tid_str, FIXED_LEN); /* create enum datatype */ types[5] = tid_enum = H5Tenum_create(H5T_NATIVE_INT); for (i = (int) SOLID; i <= (int) PLASMA; i++) { phase_t val = (phase_t) i; status = H5Tenum_insert (tid_enum, enum_names[i], &val); } /* create float array datatype */ types[6] = tid_array_f = H5Tarray_create (H5T_NATIVE_FLOAT, 1, dims_array); /* create variable length integer datatypes */ types[7] = tid_vlen_i = H5Tvlen_create (H5T_NATIVE_INT); /* create variable length string datatype */ types[8] = tid_vlen_s = H5Tcopy (H5T_C_S1); H5Tset_size (tid_vlen_s, H5T_VARIABLE); /* create compound datatypes */ cmp_tid = H5Tcreate (H5T_COMPOUND, sizeof (test_comp_t)); offset = 0; for (i=0; i0) { H5Pset_chunk (dcpl, 1, &chunk); } /* set dataset compression */ if (compressed) { if (chunk<=0) { chunk = nrows/10+1;; H5Pset_chunk (dcpl, 1, &chunk); } H5Pset_shuffle (dcpl); H5Pset_deflate (dcpl, 6); } /* allocate buffers */ buf_comp = (test_comp_t *)calloc(nrows, sizeof(test_comp_t)); buf_int = (int *)calloc(nrows, sizeof(int)); buf_float_a = malloc(nrows*sizeof(*buf_float_a)); buf_vlen_i = (hvl_t *)calloc(nrows, sizeof (hvl_t)); buf_vlen_s = (char **)calloc(nrows, sizeof(char *)); buf_str = malloc(nrows*sizeof (*buf_str)); /* allocate array of doulbe pointers */ buf_double2d = (double **)calloc(dims2d[0],sizeof(double *)); /* allocate a contigous chunk of memory for the data */ buf_double2d[0] = (double *)calloc( dims2d[0]*dims2d[1],sizeof(double) ); /* assign memory city to pointer array */ for (i=1; i