Hi,
I've been having some issues copying datasets; in some cases the new
dataset will be created but will be empty (no storage allocated).
I've finally tracked it down to an open identifier; if you create a
dataset, write to it and then call H5Ocopy, a new dataset will be
created but it will be empty.
This is a problem for my application (h5py) because I don't directly
control the lifecycle of the identifiers; my users do. In any case
this behavior isn't documented.
I've attached a C file which demonstrates the problem. Any ideas?
Thanks,
Andrew Collette
#include <stdio.h>
#include <stdlib.h>
#include "hdf5.h"
int main(){
int *data, *data_out = NULL;
hsize_t dims[] = {3};
herr_t out;
data = (int*)malloc(sizeof(int)*3);
data_out = (int*)malloc(sizeof(int)*3);
data[0] = 1;
data[1] = 2;
data[2] = 3;
data_out[0] = 42;
data_out[1] = 42;
data_out[2] = 42;
hid_t file, dset, dset2, dset3, space, plist;
fprintf(stderr, "HDF5 version: %d %d %d\n", (int)H5_VERS_MAJOR,
(int)H5_VERS_MINOR, (int)H5_VERS_RELEASE);
file = H5Fcreate("foo.hdf5",H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
space = H5Screate_simple(1, dims, NULL);
plist = H5Pcreate(H5P_DATASET_CREATE);
/* Set up dataset and write data */
dset = H5Dcreate2(file, "dataset", H5T_NATIVE_INT, space, H5P_DEFAULT,
plist, H5P_DEFAULT);
H5Dwrite(dset, H5T_NATIVE_INT, space, space, H5P_DEFAULT, data);
data_out[0] = 42;
data_out[1] = 42;
data_out[2] = 42;
H5Dread(dset, H5T_NATIVE_INT, space, space, H5P_DEFAULT, data_out);
fprintf(stderr, "Original data:\n");
fprintf(stderr, " %d %d %d\n", data_out[0], data_out[1], data_out[2]);
/* Try to copy with object open */
H5Ocopy(file, "dataset", file, "dataset_copy", H5P_DEFAULT, H5P_DEFAULT);
dset2 = H5Dopen1(file, "dataset_copy");
data_out[0] = 42;
data_out[1] = 42;
data_out[2] = 42;
H5Dread(dset2, H5T_NATIVE_INT, space, space, H5P_DEFAULT, data_out);
fprintf(stderr, "Reading from copy made with dataset object still open:\n");
fprintf(stderr, " %d %d %d\n", data_out[0], data_out[1], data_out[2]);
/* Try to copy with object closed */
H5Dclose(dset);
H5Ocopy(file, "dataset", file, "dataset_copy_closed", H5P_DEFAULT, H5P_DEFAULT);
dset3 = H5Oopen(file, "dataset_copy_closed", H5P_DEFAULT);
data_out[0] = 42;
data_out[1] = 42;
data_out[2] = 42;
H5Dread(dset3, H5T_NATIVE_INT, space, space, H5P_DEFAULT, data_out);
fprintf(stderr, "Reading from copy made with dataset object closed:\n");
fprintf(stderr, " %d %d %d\n", data_out[0], data_out[1], data_out[2]);
return 0;
}
_______________________________________________
Hdf-forum is for HDF software users discussion.
[email protected]
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org