c - hdf5 示例代码 h5_rdwt.c 不起作用

标签 c eclipse hdf5

我在运行来自 hdf5 的示例代码 h5_rdwt.c(在 eclipse 中)时遇到问题。你可以在这里找到这个:

http://www.hdfgroup.org/HDF5/Tutor/rdwt.html#rdwr

代码是:

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by The HDF Group.                                               *
 * Copyright by the Board of Trustees of the University of Illinois.         *
 * All rights reserved.                                                      *
 *                                                                           *
 * This file is part of HDF5.  The full HDF5 copyright notice, including     *
 * terms governing use, modification, and redistribution, is contained in    *
 * the files COPYING and Copyright.html.  COPYING can be found at the root   *
 * of the source code distribution tree; Copyright.html can be found at the  *
 * root level of an installed copy of the electronic HDF5 document set and   *
 * is linked from the top-level documents page.  It can also be found at     *
 * http://hdfgroup.org/HDF5/doc/Copyright.html.  If you do not have          *
 * access to either file, you may request a copy from help@hdfgroup.org.     *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/* 
 *  This example illustrates how to write and read data in an existing
 *  dataset.  It is used in the HDF5 Tutorial.
 */

#include "hdf5.h"
#define FILE "dset.h5"

int main() {

   hid_t       file_id, dataset_id;  /* identifiers */
   herr_t      status;
   int         i, j, dset_data[4][6];

   /* Initialize the dataset. */
   for (i = 0; i < 4; i++)
      for (j = 0; j < 6; j++)
         dset_data[i][j] = i * 6 + j + 1;

   /* Open an existing file. */
   file_id = H5Fopen(FILE, H5F_ACC_RDWR, H5P_DEFAULT);

   /* Open an existing dataset. */
   dataset_id = H5Dopen2(file_id, "/dset", H5P_DEFAULT);

   /* Write the dataset. */
   status = H5Dwrite(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, 
                     dset_data);

   status = H5Dread(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, 
                    dset_data);

   /* Close the dataset. */
   status = H5Dclose(dataset_id);

   /* Close the file. */
   status = H5Fclose(file_id);
}

在我这样做之前,我创建了一个名为“dset.h5”的文件:

#include "hdf5.h"
#define FILE "dset.h5"

main() {

   hid_t       file_id;   /* file identifier */
   herr_t      status;

   /* Create a new file using default properties. */
   file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);

   /* Terminate access to the file. */
   status = H5Fclose(file_id);
}

构建没有问题,但是当我尝试运行它时,我收到消息:

HDF5-DIAG: Error detected in HDF5 (1.8.11) thread 0:
  #000: ../../src/H5D.c line 334 in H5Dopen2(): not found
    major: Dataset
    minor: Object not found
  #001: ../../src/H5Gloc.c line 430 in H5G_loc_find(): can't find object
    major: Symbol table
    minor: Object not found
  #002: ../../src/H5Gtraverse.c line 861 in H5G_traverse(): internal path traversal failed
    major: Symbol table
    minor: Object not found
  #003: ../../src/H5Gtraverse.c line 641 in H5G_traverse_real(): traversal operator failed
    major: Symbol table
    minor: Callback failed
  #004: ../../src/H5Gloc.c line 385 in H5G_loc_find_cb(): object 'dset' doesn't exist
    major: Symbol table
    minor: Object not found
HDF5-DIAG: Error detected in HDF5 (1.8.11) thread 0:
  #000: ../../src/H5Dio.c line 234 in H5Dwrite(): can't prepare for writing data
    major: Dataset
    minor: Write failed
  #001: ../../src/H5Dio.c line 266 in H5D__pre_write(): not a dataset
    major: Invalid arguments to routine
    minor: Inappropriate type
HDF5-DIAG: Error detected in HDF5 (1.8.11) thread 0:
  #000: ../../src/H5Dio.c line 140 in H5Dread(): not a dataset
    major: Invalid arguments to routine
    minor: Inappropriate type
HDF5-DIAG: Error detected in HDF5 (1.8.11) thread 0:
  #000: ../../src/H5D.c line 391 in H5Dclose(): not a dataset
    major: Invalid arguments to routine
    minor: Inappropriate type

有人知道哪里出了问题吗? 谢谢!

最佳答案

程序中的主例程包括以下行

/* Open an existing dataset. */
dataset_id = H5Dopen2(file_id, "/dset", H5P_DEFAULT);

但是您发布的内容没有证据表明有问题的文件包含任何要打开的数据集。您似乎创建了一个名为 dset 的文件,但这与数据集不同。根据您发布的内容,您的文件是空的。

错误报告中给出了这方面的线索,其中指出,特别是

HDF5-DIAG: Error detected in HDF5 (1.8.11) thread 0:
  #000: ../../src/H5D.c line 334 in H5Dopen2(): not found
    major: Dataset
    minor: Object not found

关于c - hdf5 示例代码 h5_rdwt.c 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22511565/

相关文章:

c - 编译 linux 内核时无法识别 list_head

c - 数组的默认值是多少?

eclipse - 通过 m2e 自动更新生成的 css 文件

csv - 使用 dask 将大于内存的 csv 文件存储到 hdf5 文件

c - 如何阻止同一进程中的其他函数访问文件?

c - 如何在 exec 期间处理 C shell 程序中的输入

java - Eclipse 和 JBoss 不刷新或重建

java - "No resource found that matches the given name"

python - 按数据集名称排列的数据集的 h5py 顺序

c++ - 读取未正确关闭的 HDF5 文件