/***************************************************************************** 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 DIM0 40 #define NROWS 100 #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; int add_attrs(hid_t oid, int idx); int add_attr(hid_t oid, const char *name, hid_t tid, hid_t sid, void *buf) ; herr_t create_perf_test_file(const char *fname, int ngrps, int ndsets, int nattrs, hsize_t nrows, hsize_t dim0, hsize_t chunk, int vlen, int compressed, int latest); int main (int argc, char *argv[]) { char fname[32]; int i, ngrps=NGROUPS, ndsets=NDSETS, nattrs=NATTRS, dim0=DIM0, chunk=DIM0/10+1, nrows=NROWS, vlen=MAXVLEN, l=0, z=0; memset(fname, 0, 32); for (i=1; i, Jan. 2013 ****************************************************************************/ herr_t create_perf_test_file(const char *fname, int ngrps, int ndsets, int nattrs, hsize_t nrows, hsize_t dim0, hsize_t chunk, int vlen, int compressed, int latest) { int i, j, k; hid_t fid, sid_null, sid_scalar, sid_1d, sid_2d, did, aid, sid_2, sid_large, 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], tmp_name1[32], tmp_name2[32], tmp_name3[32]; hsize_t dims[1]={dim0}, dims2d[2]={dim0, (dim0/4+1)}, dims_array[1]={FIXED_LEN}, dim1[1]={2}; char *enum_names[4] = {"SOLID", "LIQUID", "GAS", "PLASMA"}; test_comp_t *buf_comp=NULL, *buf_comp_large=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, len; 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; if (nrows < NROWS) nrows = NROWS; if (ngrpsdim0) chunk=dim0/4; if (chunk<1) chunk = 1; if (vlen<1) vlen = MAXVLEN; /* 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 = dim0/10+1;; H5Pset_chunk (dcpl, 1, &chunk); } H5Pset_shuffle (dcpl); H5Pset_deflate (dcpl, 6); } /* allocate buffers */ buf_comp = (test_comp_t *)calloc(dim0, sizeof(test_comp_t)); buf_comp_large = (test_comp_t *)calloc(nrows, sizeof(test_comp_t)); buf_int = (int *)calloc(dim0, sizeof(int)); buf_float_a = malloc(dim0*sizeof(*buf_float_a)); buf_vlen_i = (hvl_t *)calloc(dim0, sizeof (hvl_t)); buf_vlen_s = (char **)calloc(dim0, sizeof(char *)); buf_str = malloc(dim0*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