Пример #1
0
hid_t CreateTestFile()
{
  hid_t fid;
  herr_t status;
  char ah5_status;
  hid_t label_grp;
  hid_t link_grp;
  hid_t links;
  hid_t link;
  char *labels[2] = {"label subject", "label object"};

  fid = H5Fcreate(TEST_FILE, H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT);
  if (fid < 0) return fid;
  // Create nodes
  label_grp = H5Gcreate(fid, "label", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
  if (label_grp < 0) return label_grp;
  link_grp = H5Gcreate(fid, "link", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
  if (link_grp < 0) return link_grp;
  links = H5Gcreate(link_grp, "link", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
  if (links < 0) return links;
  link = H5Gcreate(links, "link_instance_0", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
  if (link < 0) return link;

  // Label array.
  ah5_status = AH5_write_str_dataset(label_grp, "link", 2, 14, (char** const)labels);
  if (ah5_status != AH5_TRUE) return -1;

  // link attribute.s
  status = AH5_write_str_attr(link, ".", "object", "/label/link");
  if (status < 0) return status;
  status = AH5_write_int_attr(link, ".", "object_id", 1);
  if (status < 0) return status;
  status = AH5_write_str_attr(link, ".", "subject", "/label/link");
  if (status < 0) return status;
  status = AH5_write_int_attr(link, ".", "subject_id", 0);
  if (status < 0) return status;
  status = AH5_write_flt_attr(link, ".", "my attr", 1.1);
  if (status < 0) return status;

  // Release nodes
  status = H5Gclose(label_grp);
  if (status < 0) return status;
  status = H5Gclose(link);
  if (status < 0) return status;
  status = H5Gclose(links);
  if (status < 0) return status;
  status = H5Gclose(link_grp);
  if (status < 0) return status;
  return fid;
}
Пример #2
0
// Write all optional attributes
char AH5_write_opt_attrs(hid_t file_id, const char *path, AH5_opt_attrs_t *opt_attrs)
{
    char success = AH5_TRUE;
    hsize_t i;

    for (i = 0; i < opt_attrs->nb_instances && success; i++)
    {
        switch (opt_attrs->instances[i].type)
        {
        case H5T_INTEGER:
            if (!AH5_write_int_attr(file_id, path, opt_attrs->instances[i].name, opt_attrs->instances[i].value.i))
                success = AH5_FALSE;
            break;
        case H5T_FLOAT:
            if (!AH5_write_flt_attr(file_id, path, opt_attrs->instances[i].name, opt_attrs->instances[i].value.f))
                success = AH5_FALSE;
            break;
        case H5T_COMPOUND:
            if (!AH5_write_cpx_attr(file_id, path, opt_attrs->instances[i].name, opt_attrs->instances[i].value.c))
                success = AH5_FALSE;
            break;
        case H5T_STRING:
            if (!AH5_write_str_attr(file_id, path, opt_attrs->instances[i].name, opt_attrs->instances[i].value.s))
                success = AH5_FALSE;
            break;
        default:
            success = AH5_FALSE;
            break;
        }
    }
    return success;
}