Exemplo n.º 1
0
void Attribute::write(H5::H5File f, const cpath & dataset_root)
{  
  //FIXME we should have a path?
  cpath fullpath = dataset_root / name;
  cpath grouppath = fullpath.parent_path();
    
  if (_link.size())
  {
    if (!h5_obj_exists(f, grouppath))
      h5_create_path_groups(f, grouppath.c_str());
    
    H5::Group g = f.openGroup(grouppath.generic_string().c_str());
    
    if (h5_obj_exists(f, fullpath))
      g.unlink(name.filename().generic_string().c_str());
    
    g.link(H5G_LINK_SOFT, (dataset_root/_link).generic_string().c_str(), name.filename().generic_string().c_str());
  }
  else if (_m.total() == 0) {
    //FIXME remove this (legacy) case
    hsize_t *dim = new hsize_t[size.size()+1];
    for(uint i=0;i<size.size();i++)
      dim[i] = size[i];
    H5::DataSpace space(size.size(), dim);
    H5::Attribute attr;
    H5::Group g;

    delete[] dim;
    
    if (!h5_obj_exists(f, grouppath))
      h5_create_path_groups(f, grouppath);
    
    g = f.openGroup(grouppath.generic_string().c_str());
    
    uint min, max;
    
    H5Pget_attr_phase_change(H5Gget_create_plist(g.getId()), &max, &min);
    
    if (min || max)
      printf("WARNING: could not set dense storage on group, may not be able to write large attributes\n");
    
    //FIXME relative to what?
    if (H5Aexists(g.getId(), name.filename().generic_string().c_str()))
      g.removeAttr(name.filename().generic_string().c_str());
      
    attr = g.createAttribute(name.filename().generic_string().c_str(), toH5DataType(type), space);
        
    attr.write(toH5NativeDataType(type), data);
  }
  else
    Mat_H5AttrWrite(_m, f, fullpath);
}
Exemplo n.º 2
0
static void attributes_append_group(Attributes &attrs, H5::Group &g, cpath basename, cpath group_path)
{     
  for(uint i=0;i<g.getNumObjs();i++) {
    
    char g_name[1024];
    g.getObjnameByIdx(hsize_t(i), g_name, 1024);
    cpath name = group_path / g_name;
    
    H5G_stat_t stat;
    g.getObjinfo(g_name, false, stat);
    
    if (stat.type == H5G_GROUP) {
      H5::Group sub = g.openGroup(g_name);
      attributes_append_group(attrs, sub, basename, name);
    }
    else if (stat.type == H5G_LINK)
    {
      //FIXME we assume soft link!
      Attribute attr;
      char attr_name[1024];
      char link[1024];
      
      attr.setName(remove_prefix(name, basename));
      
      H5L_info_t info;
      H5Lget_val(g.getId(), g_name, link, 1024, H5P_DEFAULT);
      attr.setLink(remove_prefix(link, basename));
      
      attrs.append(attr);
    }
  }
  
  
  for(int i=0;i<g.getNumAttrs();i++) {
    H5::Attribute h5attr = g.openAttribute(i);
    Attribute attr;
    BaseType type;
    char name[1024];
    
    H5Aget_name(h5attr.getId(), 1024, name);
    read_attr(&attr, g, basename, group_path, name, type);
    
    attrs.append(attr);
  }
}
Exemplo n.º 3
0
 bool has_key (std::string const & key) const { return (H5Lexists(_g.getId(), key.c_str(), H5P_DEFAULT)); }
Exemplo n.º 4
0
 void write_string_attribute (std::string const & obj_name, std::string const & attr_name, std::string const & value){ 
  herr_t err =  H5LTset_attribute_string(_g.getId(),obj_name.c_str(),attr_name.c_str(), value.c_str() ) ;
  if (err<0) TRIQS_RUNTIME_ERROR << "Error in setting attribute of "<< obj_name<<" named "<< attr_name << " to " << value; 
 }