summaryrefslogtreecommitdiffstats
path: root/src/H5D.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5D.c')
-rw-r--r--src/H5D.c133
1 files changed, 112 insertions, 21 deletions
diff --git a/src/H5D.c b/src/H5D.c
index bc17e49..01cd378 100644
--- a/src/H5D.c
+++ b/src/H5D.c
@@ -32,6 +32,7 @@
#include "H5FOprivate.h" /* File objects */
#include "H5HLprivate.h" /* Local heaps */
#include "H5Iprivate.h" /* IDs */
+#include "H5Lprivate.h" /* Links */
#include "H5MMprivate.h" /* Memory management */
#include "H5Sprivate.h" /* Dataspaces */
#include "H5Vprivate.h" /* Vectors and arrays */
@@ -62,7 +63,7 @@ typedef struct {
/* General stuff */
static herr_t H5D_init_storage(H5D_t *dataset, hbool_t full_overwrite, hid_t dxpl_id);
static H5D_shared_t * H5D_new(hid_t dcpl_id, hbool_t creating, hbool_t vl_type);
-static H5D_t * H5D_create(H5G_loc_t *loc, const char *name, hid_t type_id,
+static H5D_t * H5D_create(H5F_t *file, hid_t type_id,
const H5S_t *space, hid_t dcpl_id, hid_t dxpl_id);
static herr_t H5D_open_oid(H5D_t *dataset, hid_t dxpl_id);
static herr_t H5D_get_space_status(H5D_t *dset, H5D_space_status_t *allocation, hid_t dxpl_id);
@@ -1174,9 +1175,12 @@ H5Dcreate(hid_t loc_id, const char *name, hid_t type_id, hid_t space_id,
hid_t dcpl_id)
{
H5G_loc_t loc; /* Object location to insert dataset into */
+ H5G_loc_t dset_loc; /* Object location of the dataset */
+ H5F_t* file; /* File in which dataset is being created */
H5D_t *new_dset = NULL; /* New dataset's info */
const H5S_t *space; /* Dataspace for dataset */
- hid_t ret_value; /* Return value */
+ hid_t dset_id = -1; /* New dataset's id */
+ hid_t ret_value; /* Return value */
FUNC_ENTER_API(H5Dcreate, FAIL)
H5TRACE5("i","isiii",loc_id,name,type_id,space_id,dcpl_id);
@@ -1196,8 +1200,108 @@ H5Dcreate(hid_t loc_id, const char *name, hid_t type_id, hid_t space_id,
if(TRUE != H5P_isa_class(dcpl_id, H5P_DATASET_CREATE))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not dataset create property list ID")
+ /* What file is the dataset being added to? */
+ if(NULL == (file = H5G_insertion_file(&loc, name, H5AC_dxpl_id)))
+ HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to locate insertion point")
+
/* build and open the new dataset */
- if(NULL == (new_dset = H5D_create(&loc, name, type_id, space, dcpl_id, H5AC_dxpl_id)))
+ if(NULL == (new_dset = H5D_create(file, type_id, space, dcpl_id, H5AC_dxpl_id)))
+ HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to create dataset")
+
+ /* Register the new dataset to get an ID for it */
+ if((dset_id = H5I_register(H5I_DATASET, new_dset)) < 0)
+ HGOTO_ERROR(H5E_DATASET, H5E_CANTREGISTER, FAIL, "unable to register dataset")
+
+ if(H5G_loc(dset_id, &dset_loc) <0)
+ HGOTO_ERROR(H5E_DATASET, H5E_CANTREGISTER, FAIL, "unable to get location for dataset")
+
+ /* Link the new dataset */
+ if( H5L_link(&loc, name, &dset_loc, H5AC_dxpl_id, H5P_DEFAULT) < 0)
+ HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to create link to dataset")
+
+ ret_value = dset_id;
+
+done:
+ if(ret_value < 0) {
+ if(dset_id >= 0)
+ {
+ H5I_dec_ref(dset_id);
+ }
+ else
+ {
+ if(new_dset != NULL) {
+ if(H5D_close(new_dset) < 0)
+ HDONE_ERROR(H5E_DATASET, H5E_CLOSEERROR, FAIL, "unable to release dataset")
+ } /* end if */
+ } /* end if-else */
+ } /* end if */
+
+ FUNC_LEAVE_API(ret_value)
+} /* end H5Dcreate() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5Dcreate_expand
+ *
+ * Purpose: Creates a new dataset named NAME at LOC_ID, opens the
+ * dataset for access, and associates with that dataset constant
+ * and initial persistent properties including the type of each
+ * datapoint as stored in the file (TYPE_ID), the size of the
+ * dataset (SPACE_ID), and other initial miscellaneous
+ * properties (DCPL_ID).
+ *
+ * All arguments are copied into the dataset, so the caller is
+ * allowed to derive new types, data spaces, and creation
+ * parameters from the old ones and reuse them in calls to
+ * create other datasets.
+ *
+ * The resulting ID should be linked into the file with
+ * H5Lcreate or it will be deleted when closed.
+ *
+ * Return: Success: The object ID of the new dataset. At this
+ * point, the dataset is ready to receive its
+ * raw data. Attempting to read raw data from
+ * the dataset will probably return the fill
+ * value. The dataset should be linked into
+ * the group hierarchy before being closed or
+ * it will be deleted. The dataset should be
+ * closed when the caller is no longer interested
+ * in it.
+ *
+ * Failure: FAIL
+ *
+ * Programmer: James Laird
+ * Tuesday, January 24, 2006
+ *
+ *-------------------------------------------------------------------------
+ */
+hid_t
+H5Dcreate_expand(hid_t loc_id, hid_t type_id, hid_t space_id,
+ hid_t dcpl_id)
+{
+ H5G_loc_t loc; /* Object location to insert dataset into */
+ H5D_t *new_dset = NULL; /* New dataset's info */
+ const H5S_t *space; /* Dataspace for dataset */
+ hid_t ret_value; /* Return value */
+
+ FUNC_ENTER_API(H5Dcreate_expand, FAIL)
+ H5TRACE4("i","iiii",loc_id,type_id,space_id,dcpl_id);
+
+ /* Check arguments */
+ if(H5G_loc(loc_id, &loc) < 0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location ID")
+ if(H5I_DATATYPE != H5I_get_type(type_id))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype ID")
+ if(NULL == (space = H5I_object_verify(space_id,H5I_DATASPACE)))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace ID")
+ if(H5P_DEFAULT == dcpl_id)
+ dcpl_id = H5P_DATASET_CREATE_DEFAULT;
+ else
+ if(TRUE != H5P_isa_class(dcpl_id, H5P_DATASET_CREATE))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not dataset create property list ID")
+
+ /* build and open the new dataset */
+ if(NULL == (new_dset = H5D_create(loc.oloc->file, type_id, space, dcpl_id, H5AC_dxpl_id)))
HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to create dataset")
/* Register the new dataset to get an ID for it */
@@ -2030,14 +2134,13 @@ done:
*-------------------------------------------------------------------------
*/
static H5D_t *
-H5D_create(H5G_loc_t *loc, const char *name, hid_t type_id, const H5S_t *space,
+H5D_create(H5F_t *file, hid_t type_id, const H5S_t *space,
hid_t dcpl_id, hid_t dxpl_id)
{
const H5T_t *type; /* Datatype for dataset */
H5D_t *new_dset = NULL;
int i, ndims;
unsigned u;
- H5F_t *file=NULL;
unsigned chunk_ndims = 0; /* Dimensionality of chunk */
H5P_genplist_t *dc_plist=NULL; /* New Property list */
hbool_t has_vl_type=FALSE; /* Flag to indicate a VL-type for dataset */
@@ -2048,8 +2151,7 @@ H5D_create(H5G_loc_t *loc, const char *name, hid_t type_id, const H5S_t *space,
FUNC_ENTER_NOAPI(H5D_create, NULL)
/* check args */
- HDassert(loc);
- HDassert(name && *name);
+ HDassert(file);
HDassert(H5I_DATATYPE==H5I_get_type(type_id));
HDassert(space);
HDassert(H5I_GENPROP_LST==H5I_get_type(dcpl_id));
@@ -2084,10 +2186,6 @@ H5D_create(H5G_loc_t *loc, const char *name, hid_t type_id, const H5S_t *space,
if(NULL == (new_dset->shared = H5D_new(dcpl_id,TRUE,has_vl_type)))
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
- /* What file is the dataset being added to? */
- if(NULL == (file = H5G_insertion_file(loc, name, dxpl_id)))
- HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, NULL, "unable to locate insertion point")
-
/* Copy datatype for dataset */
if(H5D_init_type(file, new_dset, type_id, type)<0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, NULL, "can't copy datatype")
@@ -2306,18 +2404,11 @@ H5D_create(H5G_loc_t *loc, const char *name, hid_t type_id, const H5S_t *space,
if (H5D_get_dcpl_cache(new_dset->shared->dcpl_id,&new_dset->shared->dcpl_cache)<0)
HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, NULL, "can't fill DCPL cache")
- /*
- * Give the dataset a name. That is, create and add a new object to the
- * group this dataset is being initially created in.
- */
- if(H5G_insert(loc, name, &dset_loc, dxpl_id, dc_plist) < 0)
- HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, NULL, "unable to name dataset")
-
/* Add the dataset to the list of opened objects in the file */
if(H5FO_top_incr(new_dset->oloc.file, new_dset->oloc.addr) < 0)
HGOTO_ERROR(H5E_DATASET, H5E_CANTINC, NULL, "can't incr object ref. count")
- if(H5FO_insert(new_dset->oloc.file, new_dset->oloc.addr, new_dset->shared) < 0)
- HGOTO_ERROR(H5E_DATASET, H5E_CANTINSERT, NULL, "can't insert dataset into list of open objects")
+ if(H5FO_insert(new_dset->oloc.file, new_dset->oloc.addr, new_dset->shared, TRUE) < 0)
+ HGOTO_ERROR(H5E_DATASET, H5E_CANTINSERT, NULL, "can't insert dataset into list of open objects")
new_dset->shared->fo_count = 1;
@@ -2410,7 +2501,7 @@ H5D_open(const H5G_loc_t *loc, hid_t dxpl_id)
HGOTO_ERROR(H5E_DATASET, H5E_NOTFOUND, NULL, "not found")
/* Add the dataset to the list of opened objects in the file */
- if(H5FO_insert(dataset->oloc.file, dataset->oloc.addr, dataset->shared) < 0)
+ if(H5FO_insert(dataset->oloc.file, dataset->oloc.addr, dataset->shared, FALSE) < 0)
HGOTO_ERROR(H5E_DATASET, H5E_CANTINSERT, NULL, "can't insert dataset into list of open objects")
/* Increment object count for the object in the top file */