Writing a variable length strinf

All,

I have a dataset defined with a compound datatype . One of the consitituents of tbe datatype is a variable length string which is defined as follows

     hid_t stringType = H5Tcopy(H5T_C_S1);

   H5Tset_size(stringType,H5T_VARIABLE);

I am inserting this into the compound datatype as follows

H5Tinsert(datatype,"name",HOFFSET(datastruct,name),stringType);

Datastruct is a C struct wherein name is defined as char* .

For wirting into this dataset , I need to write one field at a time . In such a case I will have to create a compound datatype having a variable length string , which I doing as given below .

     hid_t stringtype = H5Tcopy(H5T_C_S1);

     H5Tset_size(stringtype, H5T_VARIABLE);

     hid_t strtype = H5Tcreate(H5T_COMPOUND, H5Tget_size(stringtype));

     status = H5Tinsert(strtype,"name", 0, stringtype);

   int length = feat.GetName().length(); // obtains the strimg to be written

     char *name = new char[length+1]; //length = 13

     strcpy(name,feat.GetName());

     name[length]='\0';

     status = H5Dwrite(dataset, strtype, memspace, dspace, H5P_DEFAULT, name);

This leads to the following error

HDF5: infinite loop closing library

      D,G,A,S,T,D,G,A,S,F,D,G,A,S,T,G,F,FD,P,D,F,FD,P,FD,P,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,

FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL

,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,F

L,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL

I can understand that I cannot define the string length as H5T_VARIABLE the second time when I am actually writing the data .

But if I give the actual length I will get the error because src and dest datatypes will differ .

What is the correct way to handle this ?

Thanks and Regards

Ramakrishnan