implementation of attachments continued

This commit is contained in:
2011-03-31 15:30:16 +00:00
parent 6661eca765
commit 407bbe4d0c
5 changed files with 168 additions and 384 deletions
+23 -118
View File
@@ -13,148 +13,53 @@ h5_err_t
H5GetAttachmentInfoByIdx (
h5_file_t* const f,
const h5_size_t idx, // IN
char* const name, // OUT
h5_size_t len_name, // IN
h5_int64_t* const type, // OUT
h5_size_t* const npoints // OUT
char* const fname, // OUT
h5_size_t len_fname, // IN
h5_size_t* const fsize // OUT
) {
H5_API_ENTER5 (h5_err_t,
"idx=%llu, name=0x%p, len_name=%llu, type=0x%p, npoints=0x%p",
H5_API_ENTER4 (h5_err_t,
"idx=%llu, fname=0x%p, len_fname=%llu, fsize=0x%p",
(long long unsigned)idx,
name, (long long unsigned)len_name,
type, npoints);
fname, (long long unsigned)len_fname,
fsize);
H5_API_RETURN (h5_get_attachment_info_by_idx (
f, idx, name, len_name, type, npoints));
f, idx, fname, len_fname, fsize));
}
h5_err_t
H5GetAttachmentInfoByName (
h5_file_t* const f,
char* const name, // OUT
h5_int64_t* const type, // OUT
h5_size_t* const npoints // OUT
char* const fname, // OUT
h5_size_t* const fsize // OUT
) {
H5_API_ENTER3 (h5_err_t, "name=\"%s\", type=0x%p, npoints=0x%p",
name, type, npoints);
H5_API_ENTER2 (h5_err_t, "fname=\"%s\", fsize=0x%p", fname, fsize);
H5_API_RETURN (h5_get_attachment_info_by_name (
f, name, type, npoints));
f, fname, fsize));
}
h5_err_t
H5WriteAttachmentBitstream (
H5AddAttachment (
h5_file_t* const f, /*!< [in] Handle to open file */
const char* name, /*!< [in] Name of attribute to create */
const void* const content, /*!< [in] Value of attribute */
const h5_size_t size
const char* fname /*!< [in] Name of file to attach */
) {
H5_API_ENTER3 (h5_err_t, "name=\"%s\", content=0x%p, size=%llu",
name, content, (unsigned long long)size);
H5_API_RETURN (h5_write_attachment (f, name, H5T_NATIVE_CHAR, content, size));
H5_API_ENTER1 (h5_err_t, "fname=\"%s\"", fname);
H5_API_RETURN (h5_add_attachment (f, fname));
}
h5_err_t
H5WriteAttachmentFloat32 (
h5_file_t* const f, /*!< [in] Handle to open file */
const char* name, /*!< [in] Name of attribute to create */
const void* const content, /*!< [in] Value of attribute */
const h5_size_t size
) {
H5_API_ENTER3 (h5_err_t, "name=\"%s\", content=0x%p, size=%llu",
name, content, (unsigned long long)size);
H5_API_RETURN (h5_write_attachment (f, name, H5T_NATIVE_FLOAT, content, size));
}
h5_err_t
H5WriteAttachmentFloat64 (
h5_file_t* const f, /*!< [in] Handle to open file */
const char* name, /*!< [in] Name of attribute to create */
const void* const content, /*!< [in] Value of attribute */
const h5_size_t size
) {
H5_API_ENTER3 (h5_err_t, "name=\"%s\", content=0x%p, size=%llu",
name, content, (unsigned long long)size);
H5_API_RETURN (h5_write_attachment (f, name, H5T_NATIVE_DOUBLE, content, size));
}
h5_err_t
H5WriteAttachmentInt32 (
h5_file_t* const f, /*!< [in] Handle to open file */
const char* name, /*!< [in] Name of attribute to create */
const void* const content, /*!< [in] Value of attribute */
const h5_size_t size
) {
H5_API_ENTER3 (h5_err_t, "name=\"%s\", content=0x%p, size=%llu",
name, content, (unsigned long long)size);
H5_API_RETURN (h5_write_attachment (f, name, H5T_NATIVE_INT32, content, size));
}
h5_err_t
H5WriteAttachmentInt64 (
h5_file_t* const f, /*!< [in] Handle to open file */
const char* name, /*!< [in] Name of attribute to create */
const void* const content, /*!< [in] Value of attribute */
const h5_size_t size
) {
H5_API_ENTER3 (h5_err_t, "name=\"%s\", content=0x%p, size=%llu",
name, content, (unsigned long long)size);
H5_API_RETURN (h5_write_attachment (f, name, H5T_NATIVE_INT64, content, size));
}
h5_err_t
H5ReadAttachmentBitstream (
H5GetAttachment (
h5_file_t* const f, /*!< [in] Handle to open file */
const char* name, /*!< [in] Name of attribute to create */
void* const content /*!< [in] Value of attribute */
const char* fname /*!< [in] Name of attachment */
) {
H5_API_ENTER2 (h5_err_t, "name=\"%s\", content=0x%p", name, content);
H5_API_RETURN (h5_read_attachment (f, name, H5T_NATIVE_CHAR, content));
}
h5_err_t
H5ReadAttachmentFloat32 (
h5_file_t* const f, /*!< [in] Handle to open file */
const char* name, /*!< [in] Name of attribute to create */
void* const content /*!< [in] Attachment */
) {
H5_API_ENTER2 (h5_err_t, "name=\"%s\", content=0x%p", name, content);
H5_API_RETURN (h5_read_attachment (f, name, H5T_NATIVE_FLOAT, content));
}
h5_err_t
H5ReadAttachmentFloat64 (
h5_file_t* const f, /*!< [in] Handle to open file */
const char* name, /*!< [in] Name of attribute to create */
void* const content /*!< [out] Attachment */
) {
H5_API_ENTER2 (h5_err_t, "name=\"%s\", content=0x%p", name, content);
H5_API_RETURN (h5_read_attachment (f, name, H5T_NATIVE_DOUBLE, content));
}
h5_err_t
H5ReadAttachmentInt32 (
h5_file_t* const f, /*!< [in] Handle to open file */
const char* name, /*!< [in] Name of attribute to create */
void* const content /*!< [out] Attachment */
) {
H5_API_ENTER2 (h5_err_t, "name=\"%s\", content=0x%p", name, content);
H5_API_RETURN (h5_read_attachment (f, name, H5T_NATIVE_INT32, content));
}
h5_err_t
H5ReadAttachmentInt64 (
h5_file_t* const f, /*!< [in] Handle to open file */
const char* name, /*!< [in] Name of attribute to create */
void* const content /*!< [out] Attachment */
) {
H5_API_ENTER2 (h5_err_t, "name=\"%s\", content=0x%p", name, content);
H5_API_RETURN (h5_read_attachment (f, name, H5T_NATIVE_INT64, content));
H5_API_ENTER1 (h5_err_t, "fname=\"%s\"", fname);
H5_API_RETURN (h5_get_attachment (f, fname));
}
h5_err_t
H5DeleteAttachment (
h5_file_t* const f,
const char* const name
const char* const fname
) {
H5_API_ENTER1 (h5_err_t, "name=\"%s\"", name);
H5_API_RETURN (h5_delete_attachment (f, name));
H5_API_ENTER1 (h5_err_t, "fname=\"%s\"", fname);
H5_API_RETURN (h5_delete_attachment (f, fname));
}
+124 -175
View File
@@ -2,144 +2,121 @@
#include "h5_core_private.h"
#include <string.h>
static hid_t
open_space_all (
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
h5_err_t
h5_add_attachment (
h5_file_t* const f,
const hid_t dataset_id
const char* const fname
) {
UNUSED_ARGUMENT (f);
UNUSED_ARGUMENT (dataset_id);
return H5S_ALL;
}
/*
experimental code, will replace h5priv_write_dataset_by_name() somewhen
*/
write_dataset_by_name (
h5_file_t* const f,
const hid_t loc_id,
h5_dsetobject_t* dset
) {
H5_PRIV_API_ENTER (h5_err_t);
h5_info ("Writing dataset %s/%s.",
hdf5_get_objname (loc_id), dset->name);
h5_err_t exists;
TRY (exists = hdf5_link_exists (loc_id, dsinfo->name));
if ((exists > 0) && ((f->mode==H5_O_WRONLY) || (f->mode==H5_O_APPEND))) {
h5_warn ("Dataset %s/%s already exist.",
hdf5_get_objname (loc_id), dsinfo->name);
H5_PRIV_API_LEAVE (h5priv_handle_file_mode_error(f->mode));
H5_CORE_API_ENTER1 (h5_err_t, "fname=\"%s\"", fname);
// allowed file modes: O_RDWR, O_WRONLY; O_APPEND
if (f->mode == H5_O_RDONLY) {
H5_PRIV_FUNC_LEAVE (
h5priv_handle_file_mode_error (f->mode));
}
/*
open/create dataset
*/
hid_t dset_id;
hid_t dataspace_id;
hid_t diskspace_id;
hid_t memspace_id;
struct stat st;
if (stat (fname, &st) < 0) {
H5_CORE_API_LEAVE (
h5_error (
H5_ERR_HDF5,
"Cannot stat file \"%s\"",
fname));
}
hsize_t fsize = st.st_size;
hsize_t write_length;
char* buf = NULL;
if (f->myproc == 0) {
buf = malloc (fsize);
write_length = fsize;
int fd;
if ((fd = open (fname, O_RDONLY)) < 0) {
H5_CORE_API_LEAVE (
h5_error (
H5_ERR_HDF5,
"Cannot open file \"%s\" for reading",
fname));
}
again:
if (read (fd, buf, fsize) < 0) {
if (errno == EINTR) {
goto again;
} else {
H5_CORE_API_LEAVE (
h5_error (
H5_ERR_HDF5,
"Cannot read file \"%s\"",
fname));
}
}
if (close (fd) < 0) {
H5_CORE_API_LEAVE (
h5_error (
H5_ERR_HDF5,
"Cannot close file \"%s\"",
fname));
}
if (exists) {
/* overwrite dataset */
TRY (dset_id = hdf5_open_dataset (loc_id, dsinfo->name));
TRY (dataspace_id = hdf5_get_dataset_space (dset_id));
TRY (hdf5_set_dataset_extent (dset_id, dsinfo->dims));
/* exten dataset? */
} else {
/* create dataset */
TRY (dataspace_id = hdf5_create_dataspace (
dsinfo->rank,
dsinfo->dims,
dsinfo->max_dims));
TRY (dset_id = hdf5_create_dataset (
loc_id,
dsinfo->name,
dsinfo->type_id,
dataspace_id,
dsinfo->create_prop));
buf = malloc (1);
write_length = 0;
}
TRY (memspace_id = (*set_memspace)(f, 0));
TRY (diskspace_id = (*set_diskspace)(f, dataspace_id));
#ifdef PARALLEL_IO
TRY (h5_start_throttle (f));
#endif
TRY (hdf5_write_dataset (
dset_id,
dsinfo->type_id,
memspace_id,
hid_t loc_id;
TRY (loc_id = h5priv_open_group (f, f->file, H5_ATTACHMENT));
h5_err_t exists;
TRY (exists = hdf5_link_exists (loc_id, fname));
if (exists && (f->mode == H5_O_RDWR || f->mode == H5_O_WRONLY)) {
// remove
} else if (exists && f->mode == H5_O_APPEND) {
H5_PRIV_FUNC_LEAVE (
h5priv_handle_file_mode_error (f->mode));
}
hid_t diskspace_id;
TRY (diskspace_id = hdf5_create_dataspace (1, &fsize, &fsize));
hid_t dataset_id;
TRY (dataset_id = hdf5_create_dataset (loc_id,
fname,
H5T_NATIVE_CHAR,
diskspace_id,
H5P_DEFAULT));
hsize_t start = 0;
TRY (hdf5_select_hyperslab_of_dataspace (
diskspace_id,
f->xfer_prop,
data));
#ifdef PARALLEL_IO
TRY (h5_end_throttle (f));
#endif
H5S_SELECT_SET,
&start,
NULL,
&write_length,
NULL));
hid_t memspace_id;
hsize_t max = H5S_UNLIMITED;
TRY (memspace_id = hdf5_create_dataspace (1, &write_length, &max));
TRY (hdf5_write_dataset (dataset_id,
H5T_NATIVE_CHAR,
memspace_id,
diskspace_id,
f->xfer_prop,
buf));
TRY (hdf5_close_dataspace (diskspace_id));
TRY (hdf5_close_dataspace (memspace_id));
TRY (hdf5_close_dataset (dset_id));
f->empty = 0;
TRY (hdf5_close_dataset (dataset_id));
TRY (hdf5_close_group (loc_id));
H5_PRIV_API_RETURN (H5_SUCCESS);
}
TRY (h5_free (buf));
/*
- on all procs create dataset with given size of content
- create diskspace
- set hyperslap on diskspace:
- select all on proc 0
- select 0 byte on proc > 0
- create memspace with size of selection
- write
- close objects
*/
h5_err_t
h5_write_attachment (
h5_file_t* const f,
const char* const name,
const hid_t type,
const char* const content,
const h5_size_t size
) {
H5_CORE_API_ENTER4 (h5_ssize_t,
"name=\"%s\", type=%ld, content=0x%p, size=%llu",
name, (long)type, content, (unsigned long long)size);
h5_dsinfo_t dsinfo;
strncpy (dsinfo.name, name, sizeof (dsinfo.name) - 1);
dsinfo.rank = 1;
dsinfo.type_id = type;
dsinfo.create_prop = f->create_prop;
dsinfo.access_prop = f->access_prop;
hid_t group_id;
TRY (group_id = h5priv_open_group (f, f->file, H5_ATTACHMENT));
h5_err_t exists;
TRY (exists = hdf5_link_exists (group_id, name));
// write only on proc 0
if (f->myproc != 0) {
// write on proc 0 only
dsinfo.dims[0] = size;
dsinfo.max_dims[0] = size;
if (exists > 0) {
h5_warn ("Dataset %s/%s already exists",
hdf5_get_objname(group_id), name);
}
} else {
// write 0 bytes on all other procs
dsinfo.dims[0] = 0;
dsinfo.max_dims[0] = 0;
}
TRY (h5priv_write_dataset_by_name (
f,
group_id,
&dsinfo,
open_space_all,
open_space_all,
content));
TRY (hdf5_close_group (group_id));
H5_CORE_API_RETURN (H5_SUCCESS);
}
static inline hid_t
open_attachments (
h5_file_t* const f
@@ -173,10 +150,9 @@ h5_err_t
h5_get_attachment_info_by_idx (
h5_file_t* const f,
const h5_size_t idx, // IN
char* const name, // OUT
h5_size_t len_name, // IN
h5_int64_t* const type, // OUT
h5_size_t* const npoints // OUT
char* const fname, // OUT
h5_size_t len_fname, // IN
h5_size_t* const fsize // OUT
) {
H5_CORE_API_ENTER0 (h5_err_t);
hid_t loc_id;
@@ -187,19 +163,13 @@ h5_get_attachment_info_by_idx (
TRY (hdf5_get_name_of_dataset_by_idx (
loc_id,
idx,
name, len_name));
fname, len_fname));
if (npoints) {
if (fsize) {
// get number of elements, do not change value on error
h5_ssize_t np;
TRY (np = hdf5_get_npoints_of_dataset_by_name (loc_id, name));
*npoints = np;
}
if (type) {
// get normalized data type, do not change value on error
h5_int64_t t;
TRY (t = h5_get_dataset_type (loc_id, name));
*type = t;
h5_ssize_t ssize;
TRY (ssize = hdf5_get_npoints_of_dataset_by_name (loc_id, fname));
*fsize = ssize;
}
TRY (hdf5_close_group (loc_id));
H5_CORE_API_RETURN (H5_SUCCESS);
@@ -208,70 +178,49 @@ h5_get_attachment_info_by_idx (
h5_err_t
h5_get_attachment_info_by_name (
h5_file_t* const f,
const char* const name, // IN
h5_int64_t* const type, // OUT
h5_size_t* const npoints // OUT
const char* const fname, // IN
h5_size_t* const fsize // OUT
) {
H5_CORE_API_ENTER3 (h5_err_t,
"name=\"%s\", type=0x%p, npoints=0x%p",
name, type, npoints);
H5_CORE_API_ENTER2 (h5_err_t, "fname=\"%s\", fsize=0x%p", fname, fsize);
hid_t loc_id;
TRY (loc_id = open_attachments (f));
if (loc_id < 0) {
H5_CORE_API_LEAVE (H5_NOK);
}
if (npoints) {
h5_ssize_t np;
TRY (np = hdf5_get_npoints_of_dataset_by_name (loc_id, name));
*npoints = np;
}
if (type) {
h5_int64_t t;
TRY (t = h5_get_dataset_type (loc_id, name));
*type = t;
if (fsize) {
// get number of elements, do not change value on error
h5_ssize_t ssize;
TRY (ssize = hdf5_get_npoints_of_dataset_by_name (loc_id, fname));
*fsize = ssize;
}
TRY (hdf5_close_group (loc_id));
H5_CORE_API_RETURN (H5_SUCCESS);
}
h5_err_t
h5_read_attachment (
h5_get_attachment (
h5_file_t* const f,
const char* const name,
const hid_t type,
void* const content
const char* const fname
) {
H5_CORE_API_ENTER0 (h5_err_t);
hid_t group_id;
TRY (group_id = open_attachments (f));
h5_dsinfo_t dsinfo;
strncpy (dsinfo.name, name, sizeof (dsinfo.name) - 1);
dsinfo.type_id = type;
TRY (h5priv_read_dataset_by_name (
f,
group_id,
&dsinfo,
open_space_all,
open_space_all,
content));
TRY (hdf5_close_group (group_id));
H5_CORE_API_ENTER1 (h5_err_t, "fname=\"%s\"", fname);
UNUSED_ARGUMENT (f);
UNUSED_ARGUMENT (fname);
H5_CORE_API_RETURN (H5_SUCCESS);
}
h5_err_t
h5_delete_attachment (
h5_file_t* const f,
const char* const name
const char* const fname
) {
H5_CORE_API_ENTER0 (h5_err_t);
H5_CORE_API_ENTER1 (h5_err_t, "fname=\"%s\"", fname);
hid_t group_id;
TRY (group_id = open_attachments (f));
if (group_id < 0) {
H5_CORE_API_LEAVE (H5_NOK);
}
TRY (hdf5_delete_link (group_id, name, H5P_DEFAULT));
TRY (hdf5_delete_link (group_id, fname, H5P_DEFAULT));
TRY (hdf5_close_group (group_id));
H5_CORE_API_RETURN (H5_SUCCESS);
}
+10 -75
View File
@@ -13,94 +13,29 @@ H5GetNumAttachments (
h5_err_t
H5GetAttachmentInfoByIdx (
h5_file_t* const f,
const h5_size_t idx,
char* const name,
h5_size_t len_name,
h5_int64_t* const type,
h5_size_t* const npoints
const h5_size_t idx, // IN
char* const fname, // OUT
h5_size_t len_fname, // IN
h5_size_t* const fsize // OUT
);
h5_err_t
H5GetAttachmentInfoByName (
h5_file_t* const f,
char* const name,
h5_int64_t* const type,
h5_size_t* const npoints
char* const fname,
h5_size_t* const fsize
);
h5_err_t
H5WriteAttachmentBitstream (
H5AddAttachment (
h5_file_t* const f,
const char* name,
const void* const content,
const h5_size_t size
const char* fname
);
h5_err_t
H5WriteAttachmentFloat32 (
H5GetAttachment (
h5_file_t* const f,
const char* name,
const void* const content,
const h5_size_t size
);
h5_err_t
H5WriteAttachmentFloat64 (
h5_file_t* const f,
const char* name,
const void* const content,
const h5_size_t size
);
h5_err_t
H5WriteAttachmentInt32 (
h5_file_t* const f,
const char* name,
const void* const content,
const h5_size_t size
);
h5_err_t
H5WriteAttachmentInt64 (
h5_file_t* const f,
const char* name,
const void* const content,
const h5_size_t size
);
h5_err_t
H5ReadAttachmentBitstream (
h5_file_t* const f,
const char* name,
void* const content
);
h5_err_t
H5ReadAttachmentFloat32 (
h5_file_t* const f,
const char* name,
void* const content
);
h5_err_t
H5ReadAttachmentFloat64 (
h5_file_t* const f,
const char* name,
void* const content
);
h5_err_t
H5ReadAttachmentInt32 (
h5_file_t* const f,
const char* name,
void* const content
);
h5_err_t
H5ReadAttachmentInt64 (
h5_file_t* const f,
const char* name,
void* const content
const char* name
);
h5_err_t
+9 -16
View File
@@ -2,12 +2,9 @@
#define __H5_ATTACH_H
h5_err_t
h5_write_attachment (
h5_add_attachment (
h5_file_t* const f,
const char* const name,
const hid_t type,
const char* const content,
const h5_size_t size
const char* const name
);
h5_ssize_t
@@ -19,26 +16,22 @@ h5_err_t
h5_get_attachment_info_by_idx (
h5_file_t* const f,
const h5_size_t idx, // IN
char* const name, // OUT
h5_size_t len_name, // IN
h5_int64_t* const type, // OUT
h5_size_t* const npoints // OUT
char* const fname, // OUT
h5_size_t len_fname, // IN
h5_size_t* const fsize // OUT
);
h5_err_t
h5_get_attachment_info_by_name (
h5_file_t* const f,
const char* const name, // IN
h5_int64_t* const type, // OUT
h5_size_t* const npoints // OUT
const char* const fname, // IN
h5_size_t* const fsize // OUT
);
h5_err_t
h5_read_attachment (
h5_get_attachment (
h5_file_t* const f,
const char* const name,
const hid_t type,
void* const content
const char* const fname
);
h5_err_t
+2
View File
@@ -1,6 +1,8 @@
#ifndef __H5_ERRORHANDLING_H
#define __H5_ERRORHANDLING_H
#include <stdarg.h>
enum h5_rtypes {
e_int = 0,
e_ssize_t,