2014-03-19 130 views
1

我有一個問題,運行hdf5中的示例代碼,名爲h5_rdwt.c(在eclipse中)。你可以在這裏找到這樣的:hdf5示例代碼h5_rdwt.c不起作用

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 [email protected]  * 
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 

/* 
* 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 

有人知道出了什麼問題嗎? 謝謝!

回答

0

在你的程序的主程序包括線

/* 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