summaryrefslogtreecommitdiffstats
path: root/tools/h5dump/h5dumpgentest.c
diff options
context:
space:
mode:
authorPedro Vicente Nunes <pvn@hdfgroup.org>2004-06-07 16:40:25 (GMT)
committerPedro Vicente Nunes <pvn@hdfgroup.org>2004-06-07 16:40:25 (GMT)
commitbad5b7ec31f44e1d6fae9300cf27461c92566c5d (patch)
tree672cf1189aff2e694852bc7d1153d75b0abee671 /tools/h5dump/h5dumpgentest.c
parent95da7ce5c4997daae35f695817beeb6b65ae20fe (diff)
downloadhdf5-bad5b7ec31f44e1d6fae9300cf27461c92566c5d.zip
hdf5-bad5b7ec31f44e1d6fae9300cf27461c92566c5d.tar.gz
hdf5-bad5b7ec31f44e1d6fae9300cf27461c92566c5d.tar.bz2
[svn-r8622] Purpose:
h5dump new version Description: added the changes already made for 1.6 support for dumping of 1) filters 2) storage layout 3) fill value 4) comments 5) superblock 6) file contents 7) array indices Solution: Platforms tested: linux solaris AIX Misc. update:
Diffstat (limited to 'tools/h5dump/h5dumpgentest.c')
-rw-r--r--tools/h5dump/h5dumpgentest.c538
1 files changed, 534 insertions, 4 deletions
diff --git a/tools/h5dump/h5dumpgentest.c b/tools/h5dump/h5dumpgentest.c
index b3c55a6..9231b64 100644
--- a/tools/h5dump/h5dumpgentest.c
+++ b/tools/h5dump/h5dumpgentest.c
@@ -68,15 +68,44 @@
#define FILE40 "tattr2.h5"
#define FILE41 "tcompound_complex.h5"
#define FILE42 "tnamed_dtype_attr.h5"
-#define FILE43 "tvldtypes5.h5"
+#define FILE43 "tvldtypes5.h5"
+#define FILE44 "tfilters.h5"
-/* prototypes */
-static int write_attr(hid_t loc_id, int rank, hsize_t *dims, const char *attr_name,
+/*-------------------------------------------------------------------------
+ * prototypes
+ *-------------------------------------------------------------------------
+ */
+
+/* utility functions */
+static int
+write_attr(hid_t loc_id, int rank, hsize_t *dims, const char *attr_name,
hid_t type_id, void *buf);
-static int write_dset( hid_t loc_id, int rank, hsize_t *dims, const char *dset_name,
+static int
+write_dset( hid_t loc_id, int rank, hsize_t *dims, const char *dset_name,
hid_t type_id, void *buf );
+/* a filter operation callback function */
+static size_t
+myfilter(unsigned int UNUSED flags, size_t UNUSED cd_nelmts,
+ const unsigned int UNUSED *cd_values, size_t nbytes,
+ size_t UNUSED *buf_size, void UNUSED **buf);
+
+/* a "set local" callback */
+static herr_t
+set_local_myfilter(hid_t dcpl_id, hid_t type_id, hid_t UNUSED space_id);
+
+#define MYFILTER_ID 405
+
+/* This message derives from H5Z */
+const H5Z_class_t H5Z_MYFILTER[1] = {{
+ MYFILTER_ID, /* Filter id number */
+ "myfilter", /* Filter name for debugging */
+ NULL, /* The "can apply" callback */
+ set_local_myfilter, /* The "set local" callback */
+ myfilter, /* The actual filter function */
+}};
+
#define LENSTR 50
@@ -89,6 +118,12 @@ static int write_dset( hid_t loc_id, int rank, hsize_t *dims, const char *dset_n
#define SPACE1_RANK 1
#define SPACE1_DIM1 4
+#define DIM1 20
+#define DIM2 10
+#define CDIM1 DIM1/2
+#define CDIM2 DIM2/2
+#define RANK 2
+
/* Element selection information */
#define POINT1_NPOINTS 10
@@ -4331,6 +4366,499 @@ static void gent_named_dtype_attr(void)
/*-------------------------------------------------------------------------
+ * Function: make_dset
+ *
+ * Purpose: utility function to create and write a dataset in LOC_ID
+ *
+ *-------------------------------------------------------------------------
+ */
+static
+int make_dset(hid_t loc_id,
+ const char *name,
+ hid_t sid,
+ hid_t dcpl,
+ void *buf)
+{
+ hid_t dsid;
+
+ /* create the dataset */
+ if((dsid = H5Dcreate (loc_id,name,H5T_NATIVE_INT,sid,dcpl))<0)
+ return -1;
+
+ /* write */
+ if(H5Dwrite(dsid,H5T_NATIVE_INT,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf)<0)
+ goto out;
+
+ /* close */
+ if(H5Dclose(dsid)<0)
+ return -1;
+
+ return 0;
+ out:
+ H5E_BEGIN_TRY {
+ H5Dclose(dsid);
+ } H5E_END_TRY;
+ return -1;
+}
+
+
+
+/*-------------------------------------------------------------------------
+ * Function: make_external
+ *
+ * Purpose: make a dataset with external storage
+ *
+ *-------------------------------------------------------------------------
+ */
+static void
+make_external(hid_t fid)
+{
+ hid_t dcpl; /*dataset creation property list */
+ hid_t sid; /*dataspace ID */
+ hid_t dsid; /*dataset ID */
+ hsize_t cur_size[1]; /*data space current size */
+ hsize_t max_size[1]; /*data space maximum size */
+ hsize_t size; /*bytes reserved for data in the external file*/
+ int ret;
+
+ cur_size[0] = max_size[0] = 100;
+ size = (max_size[0]*sizeof(int)/2);
+
+ dcpl=H5Pcreate(H5P_DATASET_CREATE);
+ ret=H5Pset_external(dcpl,"ext1.bin",(off_t)0,size);
+ assert(ret>=0);
+
+ ret=H5Pset_external(dcpl,"ext2.bin",(off_t)0,size);
+ assert(ret>=0);
+
+ sid=H5Screate_simple(1, cur_size, max_size);
+ assert(ret>=0);
+
+ dsid=H5Dcreate(fid, "external", H5T_NATIVE_INT, sid, dcpl);
+ assert(ret>=0);
+
+ H5Dclose(dsid);
+ assert(ret>=0);
+
+ H5Sclose(sid);
+ assert(ret>=0);
+
+ H5Pclose(dcpl);
+ assert(ret>=0);
+}
+
+/*-------------------------------------------------------------------------
+ * Function: gent_filters
+ *
+ * Purpose: make several datasets with filters, external dataset
+ * fill value
+ *
+ *-------------------------------------------------------------------------
+ */
+static void gent_filters(void)
+{
+ hid_t fid; /* file id */
+ hid_t dcpl; /* dataset creation property list */
+ hid_t sid; /* dataspace ID */
+ hid_t sid1; /* dataspace ID */
+ hid_t tid; /* datatype ID */
+ hid_t did; /* dataset ID */
+#if defined (H5_HAVE_FILTER_SZIP)
+ unsigned szip_options_mask=H5_SZIP_ALLOW_K13_OPTION_MASK|H5_SZIP_NN_OPTION_MASK;
+ unsigned szip_pixels_per_block=4;
+#endif
+ hsize_t dims1[RANK]={DIM1,DIM2};
+ hsize_t chunk_dims[RANK]={CDIM1,CDIM2};
+ int buf1[DIM1][DIM2];
+ hsize_t dims2[1]={2};
+ hvl_t buf2[2];
+ hsize_t dims3[1]={1};
+ char buf3[]={"string\n new"};
+ hsize_t dims4[1]={6};
+ char buf4[6]={"abcdef"};
+ hobj_ref_t buf5[2];
+ int i, j, n, ret, fillval, val;
+
+ typedef enum
+ {
+ E_RED,
+ E_GREEN
+ } e_t;
+
+
+ for (i=n=0; i<DIM1; i++){
+ for (j=0; j<DIM2; j++){
+ buf1[i][j]=n++;
+ }
+ }
+
+ /* create a file */
+ fid = H5Fcreate(FILE44, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ assert(fid>=0);
+
+ /* create a space */
+ sid = H5Screate_simple(SPACE2_RANK, dims1, NULL);
+
+ /* create a dataset creation property list; the same DCPL is used for all dsets */
+ dcpl = H5Pcreate(H5P_DATASET_CREATE);
+
+/*-------------------------------------------------------------------------
+ * create a compact and contiguous storage layout dataset
+ * add a comment to the datasets
+ *-------------------------------------------------------------------------
+ */
+ ret=H5Pset_layout(dcpl, H5D_COMPACT);
+ assert(ret>=0);
+
+ ret=make_dset(fid,"compact",sid,dcpl,buf1);
+ assert(ret>=0);
+
+ ret=H5Gset_comment(fid,"compact", "This is a dataset with compact storage");
+ assert(ret>=0);
+
+ ret=H5Pset_layout(dcpl, H5D_CONTIGUOUS);
+ assert(ret>=0);
+
+ ret=make_dset(fid,"contiguous",sid,dcpl,buf1);
+ assert(ret>=0);
+
+ ret=H5Gset_comment(fid,"contiguous", "This is a dataset with contiguous storage");
+ assert(ret>=0);
+
+/*-------------------------------------------------------------------------
+ * make several dataset with filters
+ *-------------------------------------------------------------------------
+ */
+
+ /* set up chunk */
+ ret=H5Pset_chunk(dcpl, SPACE2_RANK, chunk_dims);
+ assert(ret>=0);
+
+/*-------------------------------------------------------------------------
+ * SZIP
+ *-------------------------------------------------------------------------
+ */
+#if defined (H5_HAVE_FILTER_SZIP)
+ /* remove the filters from the dcpl */
+ ret=H5Premove_filter(dcpl,H5Z_FILTER_ALL);
+ assert(ret>=0);
+
+ /* set szip data */
+ ret=H5Pset_szip (dcpl,szip_options_mask,szip_pixels_per_block);
+ assert(ret>=0);
+
+ ret=make_dset(fid,"szip",sid,dcpl,buf1);
+ assert(ret>=0);
+#endif
+
+/*-------------------------------------------------------------------------
+ * GZIP
+ *-------------------------------------------------------------------------
+ */
+#if defined (H5_HAVE_FILTER_DEFLATE)
+ /* remove the filters from the dcpl */
+ ret=H5Premove_filter(dcpl,H5Z_FILTER_ALL);
+ assert(ret>=0);
+
+ /* set deflate data */
+ ret=H5Pset_deflate(dcpl, 9);
+ assert(ret>=0);
+
+ ret=make_dset(fid,"deflate",sid,dcpl,buf1);
+ assert(ret>=0);
+#endif
+
+
+/*-------------------------------------------------------------------------
+ * shuffle
+ *-------------------------------------------------------------------------
+ */
+#if defined (H5_HAVE_FILTER_SHUFFLE)
+ /* remove the filters from the dcpl */
+ ret=H5Premove_filter(dcpl,H5Z_FILTER_ALL);
+ assert(ret>=0);
+
+ /* set the shuffle filter */
+ ret=H5Pset_shuffle(dcpl);
+ assert(ret>=0);
+
+ ret=make_dset(fid,"shuffle",sid,dcpl,buf1);
+ assert(ret>=0);
+#endif
+
+
+/*-------------------------------------------------------------------------
+ * checksum
+ *-------------------------------------------------------------------------
+ */
+#if defined (H5_HAVE_FILTER_FLETCHER32)
+ /* remove the filters from the dcpl */
+ ret=H5Premove_filter(dcpl,H5Z_FILTER_ALL);
+ assert(ret>=0);
+
+ /* set the checksum filter */
+ ret=H5Pset_fletcher32(dcpl);
+ assert(ret>=0);
+
+ ret=make_dset(fid,"fletcher32",sid,dcpl,buf1);
+ assert(ret>=0);
+#endif
+
+/*-------------------------------------------------------------------------
+ * all filters
+ *-------------------------------------------------------------------------
+ */
+ /* remove the filters from the dcpl */
+ ret=H5Premove_filter(dcpl,H5Z_FILTER_ALL);
+ assert(ret>=0);
+
+#if defined (H5_HAVE_FILTER_SHUFFLE)
+ /* set the shuffle filter */
+ ret=H5Pset_shuffle(dcpl);
+ assert(ret>=0);
+#endif
+
+#if defined (H5_HAVE_FILTER_SZIP)
+ szip_options_mask=H5_SZIP_CHIP_OPTION_MASK | H5_SZIP_EC_OPTION_MASK;
+ /* set szip data */
+ ret=H5Pset_szip (dcpl,szip_options_mask,szip_pixels_per_block);
+ assert(ret>=0);
+#endif
+
+#if defined (H5_HAVE_FILTER_DEFLATE)
+ /* set deflate data */
+ ret=H5Pset_deflate(dcpl, 5);
+ assert(ret>=0);
+#endif
+
+#if defined (H5_HAVE_FILTER_FLETCHER32)
+ /* set the checksum filter */
+ ret=H5Pset_fletcher32(dcpl);
+ assert(ret>=0);
+#endif
+
+ ret=make_dset(fid,"all",sid,dcpl,buf1);
+ assert(ret>=0);
+
+
+/*-------------------------------------------------------------------------
+ * user defined filter
+ *-------------------------------------------------------------------------
+ */
+ /* remove the filters from the dcpl */
+ ret=H5Premove_filter(dcpl,H5Z_FILTER_ALL);
+ assert(ret>=0);
+
+#ifdef H5_WANT_H5_V1_4_COMPAT
+ ret=H5Zregister (MYFILTER_ID, "myfilter", myfilter);
+#else
+ ret=H5Zregister (H5Z_MYFILTER);
+#endif
+ assert(ret>=0);
+
+ H5Pset_filter (dcpl, MYFILTER_ID, 0, 0, NULL);
+ assert(ret>=0);
+
+ ret=make_dset(fid,"myfilter",sid,dcpl,buf1);
+ assert(ret>=0);
+
+ /* remove the filters from the dcpl */
+ ret=H5Premove_filter(dcpl,H5Z_FILTER_ALL);
+ assert(ret>=0);
+
+/*-------------------------------------------------------------------------
+ * make an external dataset
+ *-------------------------------------------------------------------------
+ */
+ make_external(fid);
+
+/*-------------------------------------------------------------------------
+ * make datasets with fill value combinations
+ *-------------------------------------------------------------------------
+ */
+
+ fillval = -99;
+
+ ret=H5Pset_alloc_time(dcpl, H5D_ALLOC_TIME_EARLY);
+ assert(ret>=0);
+
+ ret=H5Pset_fill_time(dcpl, H5D_FILL_TIME_ALLOC);
+ assert(ret>=0);
+
+ ret=H5Pset_fill_value(dcpl, H5T_NATIVE_INT, &fillval);
+ assert(ret>=0);
+
+ ret=make_dset(fid,"fill early",sid,dcpl,buf1);
+ assert(ret>=0);
+
+ ret=H5Pset_fill_time(dcpl, H5D_FILL_TIME_NEVER);
+ assert(ret>=0);
+
+ ret=make_dset(fid,"fill never",sid,dcpl,buf1);
+ assert(ret>=0);
+
+ ret=H5Pset_fill_time(dcpl, H5D_FILL_TIME_IFSET);
+ assert(ret>=0);
+
+ ret=make_dset(fid,"fill ifset",sid,dcpl,buf1);
+ assert(ret>=0);
+
+
+/*-------------------------------------------------------------------------
+ * commit a H5G_TYPE type with a comment
+ *-------------------------------------------------------------------------
+ */
+ tid=H5Tcopy(H5T_STD_B8LE);
+ ret=H5Tcommit(fid, "my type", tid);
+ assert(ret>=0);
+
+ ret=H5Gset_comment(fid,"my type", "This is a commited datatype");
+ assert(ret>=0);
+
+ ret=H5Tclose(tid);
+ assert(ret>=0);
+
+/*-------------------------------------------------------------------------
+ * enum type with nonprintable characters in the name
+ *-------------------------------------------------------------------------
+ */
+ tid = H5Tcreate(H5T_ENUM, sizeof(e_t));
+ H5Tenum_insert(tid, "RED 3 \\n", (val = 0, &val));
+ write_dset(fid,2,dims1,"enum",tid,0);
+ ret=H5Tclose(tid);
+ assert(ret>=0);
+
+/*-------------------------------------------------------------------------
+ * vlen
+ *-------------------------------------------------------------------------
+ */
+
+ buf2[0].len = 1;
+ buf2[0].p = malloc( 1 * sizeof(int));
+ ((int *)buf2[0].p)[0]=1;
+ buf2[1].len = 2;
+ buf2[1].p = malloc( 2 * sizeof(int));
+ ((int *)buf2[1].p)[0]=2;
+ ((int *)buf2[1].p)[1]=3;
+
+ sid1=H5Screate_simple(1,dims2,NULL);
+ tid=H5Tvlen_create(H5T_NATIVE_INT);
+ did=H5Dcreate(fid,"vlen",tid,sid1,H5P_DEFAULT);
+ ret=H5Dwrite(did,tid,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf2);
+ assert(ret>=0);
+ ret=H5Tcommit(fid,"myvlen",tid);
+ assert(ret>=0);
+ ret=H5Dvlen_reclaim(tid,sid1,H5P_DEFAULT,buf2);
+ assert(ret>=0);
+ ret=H5Dclose(did);
+ assert(ret>=0);
+ ret=H5Tclose(tid);
+ assert(ret>=0);
+
+/*-------------------------------------------------------------------------
+ * bitfield
+ *-------------------------------------------------------------------------
+ */
+ tid = H5Tcopy(H5T_STD_B8LE);
+ write_dset(fid,1,dims3,"bitfield",tid,buf3);
+ ret=H5Tclose(tid);
+ assert(ret>=0);
+
+/*-------------------------------------------------------------------------
+ * string
+ *-------------------------------------------------------------------------
+ */
+
+ tid=H5Tcopy(H5T_C_S1);
+ ret=H5Tset_size(tid, sizeof(buf3));
+ assert(ret>=0);
+ write_dset(fid,1,dims3,"string",tid,buf3);
+ ret=H5Tclose(tid);
+ assert(ret>=0);
+
+/*-------------------------------------------------------------------------
+ * char array
+ *-------------------------------------------------------------------------
+ */
+ write_dset(fid,1,dims4,"char",H5T_NATIVE_CHAR,buf4);
+
+
+/*-------------------------------------------------------------------------
+ * reference
+ *-------------------------------------------------------------------------
+ */
+ ret=H5Rcreate(&buf5[0],fid,"char",H5R_OBJECT,-1);
+ assert(ret>=0);
+ ret=H5Rcreate(&buf5[1],fid,"string",H5R_OBJECT,-1);
+ assert(ret>=0);
+ write_dset(fid,1,dims2,"reference",H5T_STD_REF_OBJ,buf5);
+
+
+
+/*-------------------------------------------------------------------------
+ * close
+ *-------------------------------------------------------------------------
+ */
+
+ ret=H5Sclose(sid1);
+ assert(ret>=0);
+
+ ret=H5Sclose(sid);
+ assert(ret>=0);
+
+ ret=H5Pclose(dcpl);
+ assert(ret>=0);
+
+ ret=H5Fclose(fid);
+ assert(ret>=0);
+}
+
+/*-------------------------------------------------------------------------
+ * Function: myfilter
+ *
+ * Purpose: filter operation callback function; the filter does nothing
+ *
+ *-------------------------------------------------------------------------
+ */
+static size_t
+myfilter(unsigned int UNUSED flags, size_t UNUSED cd_nelmts,
+ const unsigned int UNUSED *cd_values, size_t nbytes,
+ size_t UNUSED *buf_size, void UNUSED **buf)
+{
+ return nbytes;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: set_local_myfilter
+ *
+ * Purpose: filter operation "set local" callback
+ *
+ *-------------------------------------------------------------------------
+ */
+
+static herr_t
+set_local_myfilter(hid_t dcpl_id, hid_t UNUSED type_id, hid_t UNUSED space_id)
+{
+ unsigned flags; /* Filter flags */
+ size_t cd_nelmts=0; /* Number of filter parameters */
+ unsigned cd_values[2]={5,6}; /* Filter parameters */
+
+ /* Get the filter's current parameters */
+ if(H5Pget_filter_by_id(dcpl_id,MYFILTER_ID,&flags,&cd_nelmts,cd_values,0,NULL)<0)
+ return(FAIL);
+
+ cd_nelmts=2;
+
+ /* Modify the filter's parameters for this dataset */
+ if(H5Pmodify_filter(dcpl_id,MYFILTER_ID,flags, cd_nelmts,cd_values)<0)
+ return(FAIL);
+
+ return(SUCCEED);
+}
+
+
+/*-------------------------------------------------------------------------
* Function: main
*
*-------------------------------------------------------------------------
@@ -4396,6 +4924,8 @@ int main(void)
gent_compound_complex();
gent_named_dtype_attr();
+
+ gent_filters();
return 0;
}