summaryrefslogtreecommitdiffstats
path: root/tools/h5copy/h5copygentest.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2007-02-13 22:42:43 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2007-02-13 22:42:43 (GMT)
commitd3c5ab50fc8fba8ff72417b125feaac8a3faed68 (patch)
tree541b46eca7b891581a3d29808806db8dfa73906c /tools/h5copy/h5copygentest.c
parent1603adeaee43e22b61055633c1dc2250aaa3a922 (diff)
downloadhdf5-d3c5ab50fc8fba8ff72417b125feaac8a3faed68.zip
hdf5-d3c5ab50fc8fba8ff72417b125feaac8a3faed68.tar.gz
hdf5-d3c5ab50fc8fba8ff72417b125feaac8a3faed68.tar.bz2
[svn-r13292] Description:
Add feature to h5copy to allow it to add an object to an existing file, instead of blowing away existing file. Modify h5tools_fopen() routine to take access flags, so it can be used to open an existing file for writing. Added check to h5copy test script that verifies it has produced a file with the correct structure. Tested on: Linux/32 2.6 (chicago) Linux/64 2.6 (chicago2)
Diffstat (limited to 'tools/h5copy/h5copygentest.c')
-rw-r--r--tools/h5copy/h5copygentest.c435
1 files changed, 217 insertions, 218 deletions
diff --git a/tools/h5copy/h5copygentest.c b/tools/h5copy/h5copygentest.c
index 84ce931..79f43ef 100644
--- a/tools/h5copy/h5copygentest.c
+++ b/tools/h5copy/h5copygentest.c
@@ -34,276 +34,274 @@
/*-------------------------------------------------------------------------
* Function: gent_simple
*
- * Purpose: Generate a simple dataset in FID
+ * Purpose: Generate a simple dataset in LOC_ID
*
*-------------------------------------------------------------------------
*/
-static void gent_simple(hid_t fid)
+static void gent_simple(hid_t loc_id)
{
- hid_t sid, did;
- hsize_t dims[1] = {6};
- int buf[6] = {1,2,3,4,5,6};
-
- /* create dataspace */
- sid = H5Screate_simple(1, dims, NULL);
-
- /* create dataset */
- did = H5Dcreate(fid, DATASET_SIMPLE, H5T_NATIVE_INT, sid, H5P_DEFAULT);
-
- /* write */
- H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
-
- /* close */
- H5Sclose(sid);
- H5Dclose(did);
+ hid_t sid, did;
+ hsize_t dims[1] = {6};
+ int buf[6] = {1,2,3,4,5,6};
+
+ /* create dataspace */
+ sid = H5Screate_simple(1, dims, NULL);
+
+ /* create dataset */
+ did = H5Dcreate(loc_id, DATASET_SIMPLE, H5T_NATIVE_INT, sid, H5P_DEFAULT);
+
+ /* write */
+ H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
+
+ /* close */
+ H5Sclose(sid);
+ H5Dclose(did);
}
/*-------------------------------------------------------------------------
* Function: gent_chunked
*
- * Purpose: Generate a chunked dataset in FID
+ * Purpose: Generate a chunked dataset in LOC_ID
*
*-------------------------------------------------------------------------
*/
-static void gent_chunked(hid_t fid)
+static void gent_chunked(hid_t loc_id)
{
- hid_t sid, did, pid;
- hsize_t dims[1] = {6};
- hsize_t chunk_dims[1] = {2};
- int buf[6] = {1,2,3,4,5,6};
-
- /* create dataspace */
- sid = H5Screate_simple(1, dims, NULL);
-
- /* create property plist */
- pid = H5Pcreate(H5P_DATASET_CREATE);
- H5Pset_chunk(pid, 1, chunk_dims);
-
- /* create dataset */
- did = H5Dcreate(fid, DATASET_CHUNK, H5T_NATIVE_INT, sid, pid);
-
- /* write */
- H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
-
- /* close */
- H5Sclose(sid);
- H5Dclose(did);
- H5Pclose(pid);
+ hid_t sid, did, pid;
+ hsize_t dims[1] = {6};
+ hsize_t chunk_dims[1] = {2};
+ int buf[6] = {1,2,3,4,5,6};
+
+ /* create dataspace */
+ sid = H5Screate_simple(1, dims, NULL);
+
+ /* create property plist */
+ pid = H5Pcreate(H5P_DATASET_CREATE);
+ H5Pset_chunk(pid, 1, chunk_dims);
+
+ /* create dataset */
+ did = H5Dcreate(loc_id, DATASET_CHUNK, H5T_NATIVE_INT, sid, pid);
+
+ /* write */
+ H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
+
+ /* close */
+ H5Sclose(sid);
+ H5Dclose(did);
+ H5Pclose(pid);
}
/*-------------------------------------------------------------------------
* Function: gent_compact
*
- * Purpose: Generate a compact dataset in FID
+ * Purpose: Generate a compact dataset in LOC_ID
*
*-------------------------------------------------------------------------
*/
-static void gent_compact(hid_t fid)
+static void gent_compact(hid_t loc_id)
{
- hid_t sid, did, pid;
- hsize_t dims[1] = {6};
- int buf[6] = {1,2,3,4,5,6};
-
- /* create dataspace */
- sid = H5Screate_simple(1, dims, NULL);
-
- /* create property plist */
- pid = H5Pcreate(H5P_DATASET_CREATE);
- H5Pset_layout (pid,H5D_COMPACT);
-
- /* create dataset */
- did = H5Dcreate(fid, DATASET_COMPACT, H5T_NATIVE_INT, sid, pid);
-
- /* write */
- H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
-
- /* close */
- H5Sclose(sid);
- H5Dclose(did);
- H5Pclose(pid);
+ hid_t sid, did, pid;
+ hsize_t dims[1] = {6};
+ int buf[6] = {1,2,3,4,5,6};
+
+ /* create dataspace */
+ sid = H5Screate_simple(1, dims, NULL);
+
+ /* create property plist */
+ pid = H5Pcreate(H5P_DATASET_CREATE);
+ H5Pset_layout (pid,H5D_COMPACT);
+
+ /* create dataset */
+ did = H5Dcreate(loc_id, DATASET_COMPACT, H5T_NATIVE_INT, sid, pid);
+
+ /* write */
+ H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
+
+ /* close */
+ H5Sclose(sid);
+ H5Dclose(did);
+ H5Pclose(pid);
}
/*-------------------------------------------------------------------------
* Function: gent_compound
*
- * Purpose: Generate a compound dataset in FID
+ * Purpose: Generate a compound dataset in LOC_ID
*
*-------------------------------------------------------------------------
*/
-static void gent_compound(hid_t fid)
+static void gent_compound(hid_t loc_id)
{
- typedef struct s_t
- {
- char str1[20];
- char str2[20];
- } s_t;
- hid_t sid, did, tid_c, tid_s;
- hsize_t dims[1] = {2};
- s_t buf[2] = {{"str1","str2"},{"str3","str4"}};
-
- /* create dataspace */
- sid = H5Screate_simple(1, dims, NULL);
-
- /* create a compound type */
- tid_c = H5Tcreate (H5T_COMPOUND, sizeof(s_t));
- tid_s = H5Tcopy (H5T_C_S1);
- H5Tset_size (tid_s, 20);
-
- H5Tinsert (tid_c, "str1", HOFFSET(s_t,str1), tid_s);
- H5Tinsert (tid_c, "str2", HOFFSET(s_t,str2), tid_s);
-
- /* create dataset */
- did = H5Dcreate(fid, DATASET_COMPOUND, tid_c, sid, H5P_DEFAULT);
-
- /* write */
- H5Dwrite(did, tid_c, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
-
- /* close */
- H5Sclose(sid);
- H5Dclose(did);
- H5Tclose(tid_c);
- H5Tclose(tid_s);
+ typedef struct s_t
+ {
+ char str1[20];
+ char str2[20];
+ } s_t;
+ hid_t sid, did, tid_c, tid_s;
+ hsize_t dims[1] = {2};
+ s_t buf[2] = {{"str1", "str2"}, {"str3", "str4"}};
+
+ /* create dataspace */
+ sid = H5Screate_simple(1, dims, NULL);
+
+ /* create a compound type */
+ tid_c = H5Tcreate(H5T_COMPOUND, sizeof(s_t));
+ tid_s = H5Tcopy(H5T_C_S1);
+ H5Tset_size(tid_s, 20);
+
+ H5Tinsert(tid_c, "str1", HOFFSET(s_t,str1), tid_s);
+ H5Tinsert(tid_c, "str2", HOFFSET(s_t,str2), tid_s);
+
+ /* create dataset */
+ did = H5Dcreate(loc_id, DATASET_COMPOUND, tid_c, sid, H5P_DEFAULT);
+
+ /* write */
+ H5Dwrite(did, tid_c, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
+
+ /* close */
+ H5Sclose(sid);
+ H5Dclose(did);
+ H5Tclose(tid_c);
+ H5Tclose(tid_s);
}
/*-------------------------------------------------------------------------
* Function: gent_compressed
*
- * Purpose: Generate a compressed dataset in FID
+ * Purpose: Generate a compressed dataset in LOC_ID
*
*-------------------------------------------------------------------------
*/
-static void gent_compressed(hid_t fid)
+static void gent_compressed(hid_t loc_id)
{
- hid_t sid, did, pid;
- hsize_t dims[1] = {6};
- hsize_t chunk_dims[1] = {2};
- int buf[6] = {1,2,3,4,5,6};
+ hid_t sid, did, pid;
+ hsize_t dims[1] = {6};
+ hsize_t chunk_dims[1] = {2};
+ int buf[6] = {1,2,3,4,5,6};
- /* create dataspace */
- sid = H5Screate_simple(1, dims, NULL);
+ /* create dataspace */
+ sid = H5Screate_simple(1, dims, NULL);
- /* create property plist for chunk*/
- pid = H5Pcreate(H5P_DATASET_CREATE);
- H5Pset_chunk(pid, 1, chunk_dims);
+ /* create property plist for chunk*/
+ pid = H5Pcreate(H5P_DATASET_CREATE);
+ H5Pset_chunk(pid, 1, chunk_dims);
- /* set the deflate filter */
+ /* set the deflate filter */
#if defined (H5_HAVE_FILTER_DEFLATE)
- H5Pset_deflate(pid, 1);
+ H5Pset_deflate(pid, 1);
#endif
-
- /* create dataset */
- did = H5Dcreate(fid, DATASET_COMPRESSED, H5T_NATIVE_INT, sid, pid);
-
- /* write */
- H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
-
- /* close */
- H5Sclose(sid);
- H5Dclose(did);
- H5Pclose(pid);
+
+ /* create dataset */
+ did = H5Dcreate(loc_id, DATASET_COMPRESSED, H5T_NATIVE_INT, sid, pid);
+
+ /* write */
+ H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
+
+ /* close */
+ H5Sclose(sid);
+ H5Dclose(did);
+ H5Pclose(pid);
}
/*-------------------------------------------------------------------------
* Function: gent_named_vl
*
- * Purpose: Generate a variable lenght named datatype for a dataset in FID
+ * Purpose: Generate a variable lenght named datatype for a dataset in LOC_ID
*
*-------------------------------------------------------------------------
*/
-static void gent_named_vl(hid_t fid)
+static void gent_named_vl(hid_t loc_id)
{
- hid_t sid, did, tid;
- hsize_t dims[1] = {2};
- hvl_t buf[2];
-
- /* allocate and initialize VL dataset to write */
- buf[0].len = 1;
- buf[0].p = malloc( 1 * sizeof(int));
- ((int *)buf[0].p)[0]=1;
- buf[1].len = 2;
- buf[1].p = malloc( 2 * sizeof(int));
- ((int *)buf[1].p)[0]=2;
- ((int *)buf[1].p)[1]=3;
-
- /* create dataspace */
- sid = H5Screate_simple(1, dims, NULL);
-
- /* create datatype */
- tid = H5Tvlen_create(H5T_NATIVE_INT);
-
- /* create named datatype */
- H5Tcommit(fid, "vl", tid);
-
- /* create dataset */
- did = H5Dcreate(fid, DATASET_NAMED_VL, tid, sid, H5P_DEFAULT);
-
- /* write */
- H5Dwrite(did, tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
-
- /* close */
- H5Dvlen_reclaim(tid,sid,H5P_DEFAULT,buf);
- H5Sclose(sid);
- H5Dclose(did);
- H5Tclose(tid);
-
+ hid_t sid, did, tid;
+ hsize_t dims[1] = {2};
+ hvl_t buf[2];
+
+ /* allocate and initialize VL dataset to write */
+ buf[0].len = 1;
+ buf[0].p = malloc( 1 * sizeof(int));
+ ((int *)buf[0].p)[0]=1;
+ buf[1].len = 2;
+ buf[1].p = malloc( 2 * sizeof(int));
+ ((int *)buf[1].p)[0]=2;
+ ((int *)buf[1].p)[1]=3;
+
+ /* create dataspace */
+ sid = H5Screate_simple(1, dims, NULL);
+
+ /* create datatype */
+ tid = H5Tvlen_create(H5T_NATIVE_INT);
+
+ /* create named datatype */
+ H5Tcommit(loc_id, "vl", tid);
+
+ /* create dataset */
+ did = H5Dcreate(loc_id, DATASET_NAMED_VL, tid, sid, H5P_DEFAULT);
+
+ /* write */
+ H5Dwrite(did, tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
+
+ /* close */
+ H5Dvlen_reclaim(tid,sid,H5P_DEFAULT,buf);
+ H5Sclose(sid);
+ H5Dclose(did);
+ H5Tclose(tid);
}
/*-------------------------------------------------------------------------
* Function: gent_nested_vl
*
- * Purpose: Generate a nested variable lenght dataset in FID
+ * Purpose: Generate a nested variable length dataset in LOC_ID
*
*-------------------------------------------------------------------------
*/
-static void gent_nested_vl(hid_t fid)
+static void gent_nested_vl(hid_t loc_id)
{
- hid_t sid, did, tid1, tid2;
- hsize_t dims[1] = {2};
- hvl_t buf[2];
- hvl_t *tvl;
-
- /* allocate and initialize VL dataset to write */
- buf[0].len = 1;
- buf[0].p = malloc( 1 * sizeof(hvl_t));
- tvl = buf[0].p;
- tvl->p = malloc( 1 * sizeof(int) );
- tvl->len = 1;
- ((int *)tvl->p)[0]=1;
-
- buf[1].len = 1;
- buf[1].p = malloc( 1 * sizeof(hvl_t));
- tvl = buf[1].p;
- tvl->p = malloc( 2 * sizeof(int) );
- tvl->len = 2;
- ((int *)tvl->p)[0]=2;
- ((int *)tvl->p)[1]=3;
-
- /* create dataspace */
- sid = H5Screate_simple(1, dims, NULL);
-
- /* create datatype */
- tid1 = H5Tvlen_create(H5T_NATIVE_INT);
-
- /* create nested VL datatype */
- tid2 = H5Tvlen_create(tid1);
-
- /* create dataset */
- did = H5Dcreate(fid, DATASET_NESTED_VL, tid2, sid, H5P_DEFAULT);
-
- /* write */
- H5Dwrite(did, tid2, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
-
- /* close */
- H5Dvlen_reclaim(tid2,sid,H5P_DEFAULT,buf);
- H5Sclose(sid);
- H5Dclose(did);
- H5Tclose(tid1);
- H5Tclose(tid2);
-
+ hid_t sid, did, tid1, tid2;
+ hsize_t dims[1] = {2};
+ hvl_t buf[2];
+ hvl_t *tvl;
+
+ /* allocate and initialize VL dataset to write */
+ buf[0].len = 1;
+ buf[0].p = malloc( 1 * sizeof(hvl_t));
+ tvl = buf[0].p;
+ tvl->p = malloc( 1 * sizeof(int) );
+ tvl->len = 1;
+ ((int *)tvl->p)[0]=1;
+
+ buf[1].len = 1;
+ buf[1].p = malloc( 1 * sizeof(hvl_t));
+ tvl = buf[1].p;
+ tvl->p = malloc( 2 * sizeof(int) );
+ tvl->len = 2;
+ ((int *)tvl->p)[0]=2;
+ ((int *)tvl->p)[1]=3;
+
+ /* create dataspace */
+ sid = H5Screate_simple(1, dims, NULL);
+
+ /* create datatype */
+ tid1 = H5Tvlen_create(H5T_NATIVE_INT);
+
+ /* create nested VL datatype */
+ tid2 = H5Tvlen_create(tid1);
+
+ /* create dataset */
+ did = H5Dcreate(loc_id, DATASET_NESTED_VL, tid2, sid, H5P_DEFAULT);
+
+ /* write */
+ H5Dwrite(did, tid2, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
+
+ /* close */
+ H5Dvlen_reclaim(tid2,sid,H5P_DEFAULT,buf);
+ H5Sclose(sid);
+ H5Dclose(did);
+ H5Tclose(tid1);
+ H5Tclose(tid2);
}
@@ -315,20 +313,21 @@ static void gent_nested_vl(hid_t fid)
int main(void)
{
- hid_t fid;
-
-
- fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
- gent_simple(fid);
- gent_chunked(fid);
- gent_compact(fid);
- gent_compound(fid);
- gent_compressed(fid);
- gent_named_vl(fid);
- gent_nested_vl(fid);
-
- H5Fclose(fid);
- return 0;
+ hid_t fid;
+
+ /* Create source file */
+ fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ gent_simple(fid);
+ gent_chunked(fid);
+ gent_compact(fid);
+ gent_compound(fid);
+ gent_compressed(fid);
+ gent_named_vl(fid);
+ gent_nested_vl(fid);
+ H5Fclose(fid);
+
+ /* Create destination file with all datasets in root group */
+
+ return 0;
}