Hi Rafal,
(Sorry for misspelling your name earlier!)

Thank you for finding this error. I had that line in the code for appending
double data, but then when I was writing the code for appending byte arrays
it somehow got lost. Now it works perfectly fine!

All the best,
Johan




> Hi Johan,
>
> Everything in your code seems to be fine, but since your initial dataset
> X-dimension is "0" (no rows when creating dataset) you have to call:
>
> H5D.set_extent(datasetId, count);
>
> right after you defined a new space dimensions in "count".
>
> See also my minimal working example in C++ (but using C API):
>
>      int rank = 2;
>      int nCols = 30;
>      int nRows = 5;
>      hsize_t tdims[rank] = {0, nCols};
>      hsize_t maxdims[rank] = {H5S_UNLIMITED, nCols};
>      hid_t space_2d = H5Screate_simple (rank, tdims, maxdims);
>      hid_t plist = H5Pcreate(H5P_DATASET_CREATE);
>      H5Pset_layout(plist, H5D_CHUNKED);
>      hsize_t chunk[rank] = {1, nCols};
>      H5Pset_chunk(plist, rank, chunk);
>
>      hid_t datasetId = H5Dcreate(file_id, "TestDataset",
> H5T_NATIVE_DOUBLE, space_2d, H5P_DEFAULT, plist, H5P_DEFAULT);
>
>      hsize_t newdims[rank] = {nRows, nCols};
>      H5Dset_extent(datasetId, newdims);
>      hid_t newspace = H5Dget_space(datasetId);
>      hsize_t offset[rank] = {0, 0};
>      H5Sselect_hyperslab(newspace, H5S_SELECT_SET, offset, NULL,
> newdims, NULL);
>
>      hid_t tmemspace = H5Screate_simple(rank, newdims, NULL);
>      double data[nCols * nRows];
>      double step = 1.1;
>      for(int r = 0; r < nRows; r++)
>      {
>          for(int c = 0; c < nCols; c++)
>          {
>              data[c + r * nCols] = step;
>              step += 1.1;
>          }
>      }
>
>      uint8_t *data_bytes = reinterpret_cast<uint8_t*>(data);
>
>      H5Dwrite (datasetId, H5T_NATIVE_DOUBLE, tmemspace, newspace,
> H5P_DEFAULT, data_bytes);
>
>      H5Sclose(newspace);
>      H5Sclose(tmemspace);
>      H5Dclose(datasetId);
>      H5Pclose(plist);
>      H5Sclose(space_2d);
>
>
> Best regards,
> Rafal
>
>
_______________________________________________
Hdf-forum is for HDF software users discussion.
[email protected]
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5

Reply via email to