Beispiel #1
0
static void show (const HDF5::Object& obj, int indentLevel = 0) {
  if (obj.getType () == H5I_DATASET) {
    indent (indentLevel);
    Core::OStream::getStdout () << "DATASET" << std::endl;
    HDF5::DataSet ds = (HDF5::DataSet) obj;
    HDF5::DataSetCreatePropList cp = ds.createPropList ();
    HDF5::DataSetAccessPropList ap = ds.accessPropList ();
    int nfilter = HDF5::Exception::check ("H5Pget_nfilters", H5Pget_nfilters (cp.handle ()));
    indent (indentLevel);
    Core::OStream::getStdout ().fprintf ("filters: %s\n", nfilter);
    for (int j = 0; j < nfilter; j++) {
      unsigned int flags;
      unsigned int filter_config;
      size_t cd_nelemts = 0;
      char name[1024];
      H5Z_filter_t filter = HDF5::Exception::check ("H5Pget_filter2", H5Pget_filter2 (cp.handle (), j, &flags, &cd_nelemts, NULL, sizeof (name) / sizeof (*name), name, &filter_config));
      std::vector<unsigned int> cd_values (cd_nelemts);
      filter = HDF5::Exception::check ("H5Pget_filter2", H5Pget_filter2 (cp.handle (), j, &flags, &cd_nelemts, cd_values.data (), sizeof (name) / sizeof (*name), name, &filter_config));
      indent (indentLevel + 1);
      Core::OStream::getStdout ().fprintf ("filter '%s' filter=%s flags=%s config=%s\n", name, filter, flags, filter_config);
      BOOST_FOREACH (unsigned int value, cd_values) {
        indent (indentLevel + 2);
        Core::OStream::getStdout ().fprintf ("parameter %s\n", value);
      }
    }
Beispiel #2
0
  MatlabObject::MatlabObject (const HDF5::Object& o) {
    HDF5::Object object = o;

    bool hasEmptyAttribute;

    for (;;) {
      isOctaveNewFormat_ = object.getType () == H5I_GROUP && object.existsAttribute ("OCTAVE_NEW_FORMAT");
      if (!isOctaveNewFormat_) {
        hasEmptyAttribute = object.existsAttribute ("MATLAB_empty");
        break;
      }

      HDF5::Group grp = (HDF5::Group) object;
      HDF5::DataSet typeDs = (HDF5::DataSet) grp.open ("type", setEFilePrefix ());

      ASSERT (typeDs.getSpace ().getSimpleExtentType () == H5S_SCALAR);
      HDF5::DataSpace s = HDF5::DataSpace::create (H5S_SCALAR);

      HDF5::StringType ty = (HDF5::StringType) typeDs.getDataType ();
      ASSERT (!(Exception::check ("H5Tis_variable_str", H5Tis_variable_str (ty.handle ())) != 0));

      /*
        const char* str = NULL;
        HDF5::DataType t = getH5Type<const char*> ();
        typeDs.read (&str, t, s, s);
        std::string str2 (str);
        typeDs.vlenReclaim (&str, t, s);
      */

      size_t size = H5Tget_size (ty.handle ());
      HDF5::Exception::check ("H5Tget_size", size ? 0 : -1);
      std::vector<char> str (size);
      typeDs.read (str.data (), ty, s, s);
      std::string str2 (str.begin (), str.end ());

      size_t pos = str2.find ('\0');
      if (pos != std::string::npos)
        str2 = str2.substr (0, pos);

      if (str2 != "cell") { 
        hasEmptyAttribute = grp.existsAttribute ("OCTAVE_EMPTY_MATRIX");
        object = grp.open ("value", setEFilePrefix ());
        octaveType_ = str2;
        break;
      } else {
        HDF5::DataSet dimsDs = (HDF5::DataSet) grp.open ("value/dims", setEFilePrefix ());
        HDF5::DataSpace dimsSp = dimsDs.getSpace ();
        ASSERT (dimsSp.getSimpleExtentType () == H5S_SIMPLE);
        ASSERT (dimsSp.getSimpleExtentNdims () == 1);
        hsize_t dim;
        dimsSp.getSimpleExtentDims (&dim);
        ASSERT (dim == 2);
        
        int64_t dims[2];
        dimsDs.read (dims, HDF5::getH5Type<int64_t> (), dimsSp);
        ASSERT (dims[0] == 1);
        ASSERT (dims[1] == 1);

        object = grp.open ("value/_0", setEFilePrefix ());
      }
    }

    H5I_type_t type = object.getType ();

    if (type == H5I_DATASET) {
      isStruct_ = false;
      dataSet_ = (HDF5::DataSet) object;
      if (hasEmptyAttribute) {
        isEmpty_ = true;
        isNullDataSpace_ = false;

        HDF5::DataSpace dataSpace = dataSet_.getSpace ();
        ASSERT (dataSpace.getSimpleExtentType () == H5S_SIMPLE);
        ASSERT (dataSpace.getSimpleExtentNdims () == 1);
        hsize_t ndims;
        dataSpace.getSimpleExtentDims (&ndims);
        ASSERT (ndims > 0);

        std::vector<uint64_t> values (Core::checked_cast<size_t> (ndims));
        dataSet_.read (values.data (), getH5Type<uint64_t> (), dataSpace);

        bool foundZero = false;
        for (size_t i = 0; i < ndims; i++)
          if (!values[i])
            foundZero = true;
        ASSERT (foundZero);

        size_.resize (Core::checked_cast<size_t> (ndims));
        for (size_t i = 0; i < ndims; i++) {
          ASSERT (values[i] <= std::numeric_limits<size_t>::max ());
          size_[i] = Core::checked_cast<size_t> (values[i]);
        }
      } else {
        dataSpace_ = dataSet_.getSpace ();
        H5S_class_t extentType = dataSpace_.getSimpleExtentType ();
        //ASSERT (extentType == H5S_SIMPLE || extentType == H5S_NULL);
        ASSERT (extentType == H5S_SIMPLE || extentType == H5S_NULL || extentType == H5S_SCALAR);
        if (extentType == H5S_SIMPLE) {
          isNullDataSpace_ = false;
          size_t dim = dataSpace_.getSimpleExtentNdims ();
          size_.resize (dim);
          std::vector<hsize_t> dims (dim);
          dataSpace_.getSimpleExtentDims (dims.data ());
          isEmpty_ = false;
          for (size_t i = 0; i < dim; i++) {
            ASSERT (dims[i] >= std::numeric_limits<size_t>::min () && dims[i] <= std::numeric_limits<size_t>::max ());
            size_[dim - 1 - i] = Core::checked_cast<size_t> (dims[i]);
            if (!dims[i])
              isEmpty_ = true;
          }
          if (isEmpty_) {
            dataSpace_ = HDF5::DataSpace ();
          }
        } else if (extentType == H5S_SCALAR) {
          isNullDataSpace_ = false;
          isEmpty_ = false;
          //size_.resize (0);
          size_.resize (1);
          size_[0] = 1;
        } else { // H5S_NULL
          isEmpty_ = true;
          isNullDataSpace_ = true;
          size_.resize (1);
          size_[0] = 0;
        }
      }
      if (isEmpty_)
        dataSet_ = HDF5::DataSet ();
    } else if (type == H5I_GROUP) {
      isStruct_ = true;
      group_ = (HDF5::Group) object;
    } else {
      ABORT_MSG ("Unknown object type");
    }
  }