I have a larger data conversion utility this is a small piece of. It converts from an old format to memory, then writes memory to an HDF5 based output format. Below is a function, WriteFloatDataset, that as described, writes a float dataset. The first few lines show how it is called. It is writing the first half of the lines (always half) correctly, then garbage for the rest. The specification calls for floats rather than doubles. I have the double equivalent of this, and a character string version as well, work like a charm.
...
float* fArray = new float[ ppArrayCount ];
for ( i = 0; i < ppArrayCount; i++ ) fArray[ i ] = this->ppArray[ i ].maop;
MyDataset::WriteFloatDataset( fileid, dataspace, "/data/", "MAOP", fArray );
...
void MyDataset::WriteFloatDataset(
hid_t fileid,
hid_t dataspace,
const char* group,
const char* name,
float data[] )
{
// HDF5 file and datagroup sized to arrayCountx1 should be open prior to calling
hid_t datatype = H5Tcreate( H5T_COMPOUND, sizeof( H5T_NATIVE_FLOAT ) );
H5Tinsert( datatype, name, 0, H5T_NATIVE_FLOAT );
char datasetName[ 256 ];
strcpy_s( datasetName, 256, group );
strcat_s( datasetName, 256, name );
hid_t dataset = H5Dcreate( fileid, datasetName, datatype, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
H5Dwrite( dataset, datatype, dataspace, dataspace, H5P_DEFAULT, ( ( const void* )data ) );
H5Dclose( dataset );
H5Tclose( datatype );
}
As mentioned, this very similar function works great, it is something about the data type.
void POF110Dataset::WriteDoubleDataset(
hid_t fileid,
hid_t dataspace,
const char* group,
const char* name,
double data[] )
{
// HDF5 file and datagroup sized to arrayCountx1 should be open prior to calling
hid_t datatype = H5Tcreate( H5T_COMPOUND, sizeof( H5T_IEEE_F64LE ) );
H5Tinsert( datatype, name, 0, H5T_IEEE_F64LE );
char datasetName[ 256 ];
strcpy_s( datasetName, 256, group );
strcat_s( datasetName, 256, name );
hid_t dataset = H5Dcreate( fileid, datasetName, datatype, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT );
H5Dwrite( dataset, datatype, dataspace, dataspace, H5P_DEFAULT, ( ( const void* )data ) );
H5Dclose( dataset );
H5Tclose( datatype );
}
It occurred to be to try H5T_IEEE_F32LE instead of H5T_NATIVE_FLOAT. If that fixes it, I will answer my own question. Otherwise, any advice appreciated.
2