Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8950801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:31:06+00:00 2026-06-15T13:31:06+00:00

I am using HDF5 API and I am trying to create a dataset with

  • 0

I am using HDF5 API and I am trying to create a dataset with variable-length string.
The struct is

struct dataX
{
  std::string data;
};

I was using char[256] with a static hard coded size.
But I want it to be dynamic so after reading the HDF5 Doc, I found H5T_VARIABLE and used it as follows but it still fails.

H5Dcreate returns a negative value (means error).

hid_t mem_type;
mem_type = H5Tcopy( H5T_C_S1 );
H5Tset_size(mem_type,H5T_VARIABLE);

/* Create the memory data type. */
if ((mem_type_id = H5Tcreate (H5T_COMPOUND, mem_type )) < 0 ) {
  return -1;
}
/* Insert fields. */
if ( H5Tinsert(mem_type_id, "field", 0, mem_type_id ) < 0 ) {
  return -1;
}

/* Create a simple data space with unlimited size */
//   hsize_t dims[1]={0};
//   hsize_t maxdimsk[1]={ H5S_UNLIMITED };
if ( (sid = H5Screate_simple( 1, dims, maxdims )) < 0 ){
  return -1;
}

/* Modify dataset creation properties, i.e. enable chunking  */
plist_id = H5Pcreate (H5P_DATASET_CREATE);
//chunk==1
if ( H5Pset_chunk ( plist_id, 1, chunk ) < 0 ){
  return -1;
}

H5Pset_alloc_time( plist_id, H5D_ALLOC_TIME_EARLY )
/* Set the fill value using a struct as the data type. */
// fill_data=0
if ( fill_data )
{
  if ( H5Pset_fill_value( plist_id, mem_type_id, fill_data ) < 0 ){
    LOG_ERROR << "cannot fill value " << LOG_ENDL;
    return -1;
  }
}
else {
  if ( H5Pset_fill_time( plist_id, H5D_FILL_TIME_NEVER ) < 0 ) {
    LOG_ERROR << "error" << LOG_ENDL;
  }
}

/* Create the dataset. */
did = H5Dcreate( loc_id, dset_name, mem_type_id, sid, plist_id )

I tried H5D_ALLOC_TIME_LATE, thinking that maybe if it allocated the memory just before writing it would work but … it didn’t.

Now I’m stuck and I don’t know what to do.

Did I miss something ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:31:08+00:00Added an answer on June 15, 2026 at 1:31 pm

    Your mem_type_id doubly invalid:

    • the second argument of H5Tcreate should be the size of the compound datatype
    • in H5Tinsert, the last argument should be the datatype of the inserted field. Here I guess you meant mem_type instead of mem_type_id.

    I don’t know anything about what you are doing in particular, but to write variable length string, you do not need to create a compound type nor to set any special property lists. Basically your 3 first line are enough to create a valid variable-length string datatype (mem_type). Then you create the simple dataspace, then the dataset.

    Have a look at this example, you will see it’s pretty simple.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using HDF5 to read a string into a char* allocated by new[]
I have daily stock data as an HDF5 file created using PyTables. I would
Using linq2sql I'm trying to take the string in txtOilChange and update the oilChange
Using import datetime in python, is it possible to take a formatted time/date string
I've just discovered the HDF5 format and I'm considering using it to store 3D
How can I put a numpy multidimensional array in a HDF5 file using PyTables?
Using Android TelephonyManager an application can obtain the state of data activity over the
I would like to programatically change the data associated with a dataset in an
I've been working with HDF5 files with C and Matlab , both using the
I've been using SQL Server to store historical time series data for a couple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.