HDF5复合类型Native与IEEE

fob*_*122 5 c c++ hdf5 dataformat

我只是拿起HDF5,我对为内存创建数据和为文件创建数据之间的区别感到困惑.有什么不同?

示例中,创建复合类型数据需要在内存中创建数据并将其放在文件中:

 /*
 * Create the memory data type. 
 */
s1_tid = H5Tcreate (H5T_COMPOUND, sizeof(s1_t));
H5Tinsert(s1_tid, "a_name", HOFFSET(s1_t, a), H5T_NATIVE_INT);
H5Tinsert(s1_tid, "c_name", HOFFSET(s1_t, c), H5T_NATIVE_DOUBLE);
H5Tinsert(s1_tid, "b_name", HOFFSET(s1_t, b), H5T_NATIVE_FLOAT);

/* 
 * Create the dataset.
 */
dataset = H5Dcreate(file, DATASETNAME, s1_tid, space, H5P_DEFAULT);

/*
 * Wtite data to the dataset; 
 */
status = H5Dwrite(dataset, s1_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, s1);
Run Code Online (Sandbox Code Playgroud)

但是,在此处的另一个示例中,作者还为文件创建了复合数据,该数据指定了不同的数据类型.例如,在为内存创建数据类型时,serial_no使用了类型H5T_NATIVE_INT,但在创建文件的数据类型时,serial_no使用了H5T_STD_I64BE.他为什么这样做?

    /*
 * Create the compound datatype for memory.
 */
memtype = H5Tcreate (H5T_COMPOUND, sizeof (sensor_t));
status = H5Tinsert (memtype, "Serial number",
            HOFFSET (sensor_t, serial_no), H5T_NATIVE_INT);
status = H5Tinsert (memtype, "Location", HOFFSET (sensor_t, location),
            strtype);
status = H5Tinsert (memtype, "Temperature (F)",
            HOFFSET (sensor_t, temperature), H5T_NATIVE_DOUBLE);
status = H5Tinsert (memtype, "Pressure (inHg)",
            HOFFSET (sensor_t, pressure), H5T_NATIVE_DOUBLE);

/*
 * Create the compound datatype for the file.  Because the standard
 * types we are using for the file may have different sizes than
 * the corresponding native types, we must manually calculate the
 * offset of each member.
 */
filetype = H5Tcreate (H5T_COMPOUND, 8 + sizeof (hvl_t) + 8 + 8);
status = H5Tinsert (filetype, "Serial number", 0, H5T_STD_I64BE);
status = H5Tinsert (filetype, "Location", 8, strtype);
status = H5Tinsert (filetype, "Temperature (F)", 8 + sizeof (hvl_t),
            H5T_IEEE_F64BE);
status = H5Tinsert (filetype, "Pressure (inHg)", 8 + sizeof (hvl_t) + 8,
            H5T_IEEE_F64BE);

/*
 * Create dataspace.  Setting maximum size to NULL sets the maximum
 * size to be the current size.
 */
space = H5Screate_simple (1, dims, NULL);

/*
 * Create the dataset and write the compound data to it.
 */
dset = H5Dcreate (file, DATASET, filetype, space, H5P_DEFAULT, H5P_DEFAULT,
            H5P_DEFAULT);
status = H5Dwrite (dset, memtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata);
Run Code Online (Sandbox Code Playgroud)

这两种方法有什么区别?

Che*_*hen 5

来自http://www.hdfgroup.org/HDF5/doc/UG/UG_frame11Datatypes.html:

H5T_NATIVE_INT对应于C int类型.在基于Intel的PC上,此类型与H5T_STD_I32LE相同,而在MIPS系统上,这相当于H5T_STD_I32BE.

也就是说,H5T_NATIVE_INT在不同类型的处理器上具有不同的内存布局.如果您的数据仅用于内存,这意味着您的数据不会超出本机,您可能希望使用H5T_NATIVE_INT以获得更好的性能.

但是,如果您的数据将保存到文件中,并且将由不同的系统使用,则必须指定某种int类型以保持您的数据正确读取,例如H5T_STD_I64BE或H5T_STD_I32LE.如果您使用H5T_NATIVE_INT,并在基于Intel的PC上创建了数据文件,则该号码将保存为H5T_STD_I32LE.当MIPS系统使用此文件时,它将读取数字H5T_STD_I32BE,这是不期望的.