1

I have a problem running an example code from hdf5 called h5_rdwt.c (in eclipse). You can find this here:

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

The code is:

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * 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);
}

Before I did so, I created a file named "dset.h5" with:

#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);
}

Building is no problem, but when I try to run this I get the message:

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

Does someone know what went wrong? Thank you!

Kara
  • 6,115
  • 16
  • 50
  • 57
smaica
  • 723
  • 2
  • 11
  • 26

2 Answers2

0

The main routine in your program includes the lines

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

but there's no evidence from what you have posted that the file in question contains any datasets to open. You seem to have created a file called dset but that's not the same thing as a dataset. From what you've posted your file is empty.

The clue to this is given in the error report which states, inter alia

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
High Performance Mark
  • 77,191
  • 7
  • 105
  • 161
0

You have to create the dataset as well before accessing it. There is an example for that on the hdf5-page as well: ftp://www.hdfgroup.org/HDF5/examples/introductory/C/h5_crtdat.c

Short: using H5Screate_simple to create dataspace and H5Dcreate2 to create the dataset.

Kuishi
  • 157
  • 4