mirror of
https://github.com/HDFGroup/hdf5.git
synced 2024-11-27 02:10:55 +08:00
[svn-r78] Checkpointing dataset code. Everything is currently working, except writing
a second dataset out to the file seems to loose the first one.
This commit is contained in:
parent
9e1e3eadbe
commit
4dd2b367d5
@ -63,6 +63,7 @@
|
||||
#define H5A_DATATYPEID_HASHSIZE 64
|
||||
#define H5A_DATASPACEID_HASHSIZE 64
|
||||
#define H5A_DATASETID_HASHSIZE 64
|
||||
#define H5A_OID_HASHSIZE 64
|
||||
|
||||
/* Atom information structure used */
|
||||
typedef struct atom_info_struct_tag {
|
||||
|
161
src/H5D.c
161
src/H5D.c
@ -38,6 +38,7 @@ static char RcsId[] = "@(#)$Revision$";
|
||||
#include <H5Dprivate.h> /* Dataset functions */
|
||||
#include <H5Eprivate.h> /* Error handling */
|
||||
#include <H5Mprivate.h> /* Meta data */
|
||||
#include <H5Gprivate.h> /* Group headers */
|
||||
#include <H5Oprivate.h> /* Object headers */
|
||||
#include <H5MFprivate.h> /* File space allocation header */
|
||||
|
||||
@ -67,6 +68,7 @@ static herr_t H5D_init_interface(void)
|
||||
FUNC_ENTER (H5D_init_interface, NULL, FAIL);
|
||||
|
||||
/* Initialize the atom group for the file IDs */
|
||||
ret_value=H5Ainit_group(H5_OID,H5A_OID_HASHSIZE,0);
|
||||
ret_value=H5Ainit_group(H5_DATASET,H5A_DATASETID_HASHSIZE,H5D_RESERVED_ATOMS);
|
||||
|
||||
FUNC_LEAVE(ret_value);
|
||||
@ -165,18 +167,21 @@ hatom_t H5D_access(hatom_t oid)
|
||||
/* Pull information about the dataset out of the file */
|
||||
dset->file=H5Aatom_object(ohdr->fid); /* Get the pointer to the file for the dataset */
|
||||
/* Get the dataset's name */
|
||||
if((dset->name=H5O_read(dset->file,ohdr->ohdr,ohdr->ent,H5O_NAME,1,NULL))==NULL)
|
||||
if((dset->name=H5O_read(dset->file,ohdr->ohdr,&ohdr->ent,H5O_NAME,0,NULL))==NULL)
|
||||
HGOTO_ERROR(H5E_OHDR, H5E_NOTFOUND, FAIL);
|
||||
dset->modified=BFALSE; /* nothing changed yet */
|
||||
/* Get the dataset's type (currently only atomic types) */
|
||||
if((dset->type=H5O_read(dset->file,ohdr->ohdr,ohdr->ent,H5O_SIM_DTYPE,1,NULL))==NULL)
|
||||
if((dset->type=H5O_read(dset->file,ohdr->ohdr,&ohdr->ent,H5O_SIM_DTYPE,0,NULL))==NULL)
|
||||
HGOTO_ERROR(H5E_OHDR, H5E_NOTFOUND, FAIL);
|
||||
/* Get the dataset's dimensionality (currently only simple dataspaces) */
|
||||
if((dset->dim=H5O_read(dset->file,ohdr->ohdr,ohdr->ent,H5O_SIM_DIM,1,NULL))==NULL)
|
||||
if((dset->dim=HDmalloc(sizeof(H5P_dim_t)))==NULL)
|
||||
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL);
|
||||
dset->dim->type=H5P_TYPE_SIMPLE; /* for now... */
|
||||
if((dset->dim->s=H5O_read(dset->file,ohdr->ohdr,&ohdr->ent,H5O_SIM_DIM,0,NULL))==NULL)
|
||||
HGOTO_ERROR(H5E_OHDR, H5E_NOTFOUND, FAIL);
|
||||
dset->header=ohdr->ohdr; /* keep the object header location for later */
|
||||
/* Get the dataset's data offset (currently only standard storage) */
|
||||
if(NULL==H5O_read(dset->file,ohdr->ohdr,ohdr->ent,H5O_STD_STORE,1,&store))
|
||||
if(NULL==H5O_read(dset->file,ohdr->ohdr,&ohdr->ent,H5O_STD_STORE,0,&store))
|
||||
HGOTO_ERROR(H5E_OHDR, H5E_NOTFOUND, FAIL);
|
||||
dset->data=store.off;
|
||||
|
||||
@ -195,6 +200,66 @@ done:
|
||||
FUNC_LEAVE(ret_value);
|
||||
} /* end H5D_access() */
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
NAME
|
||||
H5D_find_name
|
||||
PURPOSE
|
||||
Get the OID for accessing an existing HDF5 dataset object
|
||||
USAGE
|
||||
hoid_t H5D_find_name(grp_id, type, name)
|
||||
hatom_t grp_id; IN: Atom for directory to search for dataset
|
||||
hobjtype_t type; IN: Type of object to search for (dataset in this case)
|
||||
const char *name; IN: Name of the object to search for
|
||||
RETURNS
|
||||
Returns ID (atom) on success, FAIL on failure
|
||||
DESCRIPTION
|
||||
This function finds for a dataset by name in a directory.
|
||||
--------------------------------------------------------------------------*/
|
||||
hatom_t H5D_find_name(hatom_t grp_id, hobjtype_t type, const char *name)
|
||||
{
|
||||
hdf5_file_t *file; /* Pointer to the file-store of this object */
|
||||
H5D_oid_t *ohdr; /* OID for reference to dataset */
|
||||
hatom_t ret_value = SUCCEED;
|
||||
|
||||
FUNC_ENTER(H5D_find_name, H5D_init_interface, FAIL);
|
||||
|
||||
/* Clear errors and check args and all the boring stuff. */
|
||||
H5ECLEAR;
|
||||
|
||||
/* Allocate space for the dataset */
|
||||
if((ohdr=HDmalloc(sizeof(H5D_oid_t)))==NULL)
|
||||
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL);
|
||||
|
||||
/* Get directory symbols, etc... */
|
||||
if(H5Aatom_group(grp_id)!=H5_FILE)
|
||||
HGOTO_ERROR(H5E_ATOM, H5E_BADTYPE, FAIL);
|
||||
file=H5Aatom_object(grp_id);
|
||||
/* WARNING! WARNING! WARNING! */
|
||||
/* The following line explicitly uses the root symbol as the
|
||||
current working directory. This should be changed to something more
|
||||
appropriate and is only hacked in here to get the prototype working. -QAK
|
||||
*/
|
||||
/* WARNING! WARNING! WARNING! */
|
||||
if(H5G_find(file,file->root_sym,&(ohdr->dir),name,&(ohdr->ent))==FAIL)
|
||||
HGOTO_ERROR(H5E_DATASET, H5E_NOTFOUND, FAIL);
|
||||
ohdr->fid=grp_id;
|
||||
ohdr->ohdr=ohdr->ent.header;
|
||||
|
||||
/* Register the new OID and get an ID for it */
|
||||
if((ret_value=H5Aregister_atom(H5_OID, (const VOIDP)ohdr))==FAIL)
|
||||
HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL);
|
||||
|
||||
done:
|
||||
if(ret_value == FAIL)
|
||||
{ /* Error condition cleanup */
|
||||
|
||||
} /* end if */
|
||||
|
||||
/* Normal function cleanup */
|
||||
|
||||
FUNC_LEAVE(ret_value);
|
||||
} /* end H5D_find_name() */
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
NAME
|
||||
H5Dset_info
|
||||
@ -300,13 +365,81 @@ done:
|
||||
FUNC_LEAVE(ret_value);
|
||||
} /* end H5Dset_info() */
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
NAME
|
||||
H5Dread
|
||||
PURPOSE
|
||||
Read data from a dataset
|
||||
USAGE
|
||||
herr_t H5Dread(oid)
|
||||
hatom_t oid; IN: Dataset to read
|
||||
hatom_t did; IN: Dimensionality object to use as dataspace for I/O
|
||||
VOIDP buf; IN: Buffer to fill with data from the file
|
||||
RETURNS
|
||||
SUCCEED/FAIL
|
||||
DESCRIPTION
|
||||
This function reads dataset object data to the file. The dataspace
|
||||
ID determines the slice/hyper-slab/portion of the dataset to write.
|
||||
H5P_SCALAR is a special value which indicates that the entire dataset is
|
||||
to be written out. (For datasets which have a scalar dataspace for the
|
||||
entire dataset, this is somewhat redundant.... :-)
|
||||
--------------------------------------------------------------------------*/
|
||||
herr_t H5Dread(hatom_t oid, hatom_t did, VOIDP buf)
|
||||
{
|
||||
H5D_dataset_t *dataset; /* dataset object to do I/O on */
|
||||
uintn toread; /* number of bytes to read in */
|
||||
herr_t ret_value = SUCCEED;
|
||||
|
||||
FUNC_ENTER(H5Dread, H5D_init_interface, FAIL);
|
||||
|
||||
/* Clear errors and check args and all the boring stuff. */
|
||||
H5ECLEAR;
|
||||
|
||||
/* Check that we've received correctly typed parameters */
|
||||
if(H5Aatom_group(did)!=H5_DATASPACE || H5Aatom_group(oid)!=H5_DATASET)
|
||||
HGOTO_ERROR(H5E_ATOM, H5E_BADTYPE, FAIL);
|
||||
if(buf==NULL)
|
||||
HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL);
|
||||
|
||||
/* Get the object */
|
||||
if((dataset=H5Aatom_object(oid))==NULL)
|
||||
HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL);
|
||||
|
||||
/* Check that the datatype & dataspace have already been initialized */
|
||||
if(dataset->type==NULL || dataset->dim==NULL || dataset->data==(-1))
|
||||
HGOTO_ERROR(H5E_FUNC, H5E_UNINITIALIZED, FAIL);
|
||||
|
||||
/* Compute the number of bytes to read */
|
||||
if(did==H5P_SCALAR) /* Check if we are reading the entire dataset */
|
||||
toread=H5T_size(dataset->type,BTRUE)*H5P_nelem(dataset->dim);
|
||||
else
|
||||
HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL);
|
||||
|
||||
/* Check memory to disk datatype conversions, etc. */
|
||||
/* DO THIS! -QAK */
|
||||
|
||||
/* Write the data out to disk */
|
||||
if(H5F_block_read(dataset->file,dataset->data,toread,buf)==FAIL)
|
||||
HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL);
|
||||
|
||||
done:
|
||||
if(ret_value == FAIL)
|
||||
{ /* Error condition cleanup */
|
||||
|
||||
} /* end if */
|
||||
|
||||
/* Normal function cleanup */
|
||||
|
||||
FUNC_LEAVE(ret_value);
|
||||
} /* end H5Dread() */
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
NAME
|
||||
H5Dwrite
|
||||
PURPOSE
|
||||
Write data for a dataset
|
||||
USAGE
|
||||
herr_t H5Dset_info(oid)
|
||||
herr_t H5Dwrite(oid)
|
||||
hatom_t oid; IN: Dataset object to modify
|
||||
hatom_t did; IN: Dimensionality object to use as dataspace for I/O
|
||||
VOIDP buf; IN: Buffer with data to write to the file
|
||||
@ -321,7 +454,7 @@ done:
|
||||
--------------------------------------------------------------------------*/
|
||||
herr_t H5Dwrite(hatom_t oid, hatom_t did, VOIDP buf)
|
||||
{
|
||||
H5D_dataset_t *dataset; /* dataset object to release */
|
||||
H5D_dataset_t *dataset; /* dataset object to do I/O on */
|
||||
uintn towrite; /* number of bytes to write out */
|
||||
herr_t ret_value = SUCCEED;
|
||||
|
||||
@ -331,7 +464,7 @@ herr_t H5Dwrite(hatom_t oid, hatom_t did, VOIDP buf)
|
||||
H5ECLEAR;
|
||||
|
||||
/* Check that we've received correctly typed parameters */
|
||||
if(did!=0 && H5Aatom_group(did)!=H5_DATASPACE)
|
||||
if(H5Aatom_group(did)!=H5_DATASPACE || H5Aatom_group(oid)!=H5_DATASET)
|
||||
HGOTO_ERROR(H5E_ATOM, H5E_BADTYPE, FAIL);
|
||||
if(buf==NULL)
|
||||
HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL);
|
||||
@ -339,12 +472,13 @@ herr_t H5Dwrite(hatom_t oid, hatom_t did, VOIDP buf)
|
||||
/* Get the object */
|
||||
if((dataset=H5Aatom_object(oid))==NULL)
|
||||
HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL);
|
||||
|
||||
/* Check that the datatype & dataspace haven't already been initialized */
|
||||
if(dataset->type==NULL || dataset->dim==NULL)
|
||||
HGOTO_ERROR(H5E_FUNC, H5E_UNINITIALIZED, FAIL);
|
||||
|
||||
/* Compute the number of bytes to write out */
|
||||
if(did==0) /* Check if we are writing out the entire dataset */
|
||||
if(did==H5P_SCALAR) /* Check if we are writing out the entire dataset */
|
||||
towrite=H5T_size(dataset->type,BTRUE)*H5P_nelem(dataset->dim);
|
||||
else
|
||||
HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL);
|
||||
@ -423,6 +557,12 @@ herr_t H5D_flush(hatom_t oid)
|
||||
/*
|
||||
* Write the necessary messages to the header.
|
||||
*/
|
||||
/* Write the dataset's name */
|
||||
if(dataset->name!=NULL)
|
||||
{
|
||||
if(H5O_modify(dataset->file,dataset->header,&d_sym,NULL,H5O_NAME,H5O_NEW_MESG,dataset->name)==FAIL)
|
||||
HGOTO_ERROR (H5E_INTERNAL, H5E_CANTCREATE, FAIL);
|
||||
} /* end if */
|
||||
/* Check if this dataset has an "atomic" datatype */
|
||||
if(BTRUE==H5T_is_atomic(dataset->type))
|
||||
{
|
||||
@ -443,6 +583,7 @@ herr_t H5D_flush(hatom_t oid)
|
||||
{ /* if it's not an atomic datatype, fail for right now */
|
||||
HGOTO_ERROR (H5E_INTERNAL, H5E_UNSUPPORTED, FAIL);
|
||||
} /* end else */
|
||||
/* Write the dataset's storage information */
|
||||
if(dataset->data>0)
|
||||
{
|
||||
H5O_std_store_t store; /* standard storage info */
|
||||
@ -559,10 +700,12 @@ herr_t H5D_release(hatom_t oid)
|
||||
if(dataset->modified==BTRUE)
|
||||
H5D_flush(oid);
|
||||
|
||||
/* relase the memory used for the dataset */
|
||||
/* release the memory used for the dataset */
|
||||
if(dataset->name!=NULL)
|
||||
{
|
||||
HDfree(dataset->name->s);
|
||||
HDfree(dataset->name);
|
||||
} /* end if */
|
||||
HDfree(dataset);
|
||||
|
||||
/* Delete the dataset from the atom group */
|
||||
|
@ -32,8 +32,8 @@
|
||||
typedef struct {
|
||||
hatom_t fid; /* File Id for object */
|
||||
haddr_t ohdr; /* Offset of the object header */
|
||||
H5G_entry_t *dir; /* directory entry for the directory the object is located in */
|
||||
H5G_entry_t *ent; /* directory entry for the object itself */
|
||||
H5G_entry_t dir; /* directory entry for the directory the object is located in */
|
||||
H5G_entry_t ent; /* directory entry for the object itself */
|
||||
} H5D_oid_t;
|
||||
|
||||
typedef struct {
|
||||
@ -54,6 +54,7 @@ typedef struct {
|
||||
/*-----------------_-- Local function prototypes ----------------------------*/
|
||||
hatom_t H5D_create(hatom_t owner_id, hobjtype_t type, const char *name);
|
||||
hatom_t H5D_access(hatom_t oid);
|
||||
hatom_t H5D_find_name(hatom_t owner_id, hobjtype_t type, const char *name);
|
||||
herr_t H5D_flush(hatom_t oid);
|
||||
herr_t H5D_release(hatom_t oid);
|
||||
|
||||
|
@ -31,6 +31,7 @@ extern "C" {
|
||||
herr_t H5Dset_info(hatom_t oid, hatom_t tid, hatom_t did);
|
||||
herr_t H5Dget_info(hatom_t oid, hatom_t *tid, hatom_t *sid);
|
||||
herr_t H5Dwrite(hatom_t oid, hatom_t did, VOIDP buf);
|
||||
herr_t H5Dread(hatom_t oid, hatom_t did, VOIDP buf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
28
src/H5M.c
28
src/H5M.c
@ -117,7 +117,7 @@ static meta_func_t meta_func_arr[]={
|
||||
H5D_create, /* Dataset Create */
|
||||
H5D_access, /* Dataset Access */
|
||||
NULL, /* Dataset Copy */
|
||||
NULL, /* Dataset FindName */
|
||||
H5D_find_name, /* Dataset FindName */
|
||||
NULL, /* Dataset NameLen */
|
||||
NULL, /* Dataset GetName */
|
||||
NULL, /* Dataset SetName */
|
||||
@ -128,6 +128,23 @@ static meta_func_t meta_func_arr[]={
|
||||
NULL, /* Dataset GetParent */
|
||||
NULL, /* Dataset GetFile */
|
||||
H5D_release /* Dataset Release */
|
||||
},
|
||||
{ /* Dataset object meta-functions (defined in H5D.c) */
|
||||
H5_OID, /* OID Type ID */
|
||||
NULL, /* OID Create */
|
||||
H5D_access, /* OID Access (calls dataset access routine) */
|
||||
NULL, /* OID Copy */
|
||||
NULL, /* OID FindName */
|
||||
NULL, /* OID NameLen */
|
||||
NULL, /* OID GetName */
|
||||
NULL, /* OID SetName */
|
||||
NULL, /* OID Search */
|
||||
NULL, /* OID Index */
|
||||
NULL, /* OID Flush */
|
||||
NULL, /* OID Delete */
|
||||
NULL, /* OID GetParent */
|
||||
NULL, /* OID GetFile */
|
||||
NULL /* OID Release */
|
||||
}
|
||||
};
|
||||
|
||||
@ -350,7 +367,9 @@ done:
|
||||
--------------------------------------------------------------------------*/
|
||||
hatom_t H5Mfind_name(hatom_t owner_id, hobjtype_t type, const char *name)
|
||||
{
|
||||
#ifdef OLD_WAY
|
||||
group_t group=H5Aatom_group(owner_id); /* Atom group for incoming object */
|
||||
#endif /* OLD_WAY */
|
||||
intn i; /* local counting variable */
|
||||
hatom_t ret_value = SUCCEED;
|
||||
|
||||
@ -358,10 +377,17 @@ hatom_t H5Mfind_name(hatom_t owner_id, hobjtype_t type, const char *name)
|
||||
|
||||
/* Clear errors and check args and all the boring stuff. */
|
||||
H5ECLEAR;
|
||||
#ifdef OLD_WAY
|
||||
if(group<=BADGROUP || group>=MAXGROUP)
|
||||
HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL);
|
||||
|
||||
i=H5M_find_type(group);
|
||||
#else /* OLD_WAY */
|
||||
if(type<=BADGROUP || type>=MAXGROUP)
|
||||
HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL);
|
||||
|
||||
i=H5M_find_type(type);
|
||||
#endif /* OLD_WAY */
|
||||
if(meta_func_arr[i].find_name==NULL)
|
||||
HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL);
|
||||
ret_value=(meta_func_arr[i].find_name)(owner_id,type,name);
|
||||
|
@ -196,7 +196,7 @@ H5O_name_size (hdf5_file_t *f, const void *_mesg)
|
||||
const H5O_name_t *mesg = (const H5O_name_t *)_mesg;
|
||||
size_t size;
|
||||
|
||||
FUNC_ENTER (H5O_stab_size, NULL, FAIL);
|
||||
FUNC_ENTER (H5O_name_size, NULL, FAIL);
|
||||
|
||||
/* check args */
|
||||
assert (f);
|
||||
|
@ -171,16 +171,16 @@ H5O_sim_dim_encode (hdf5_file_t *f, size_t raw_size, uint8 *p, const void *mesg)
|
||||
UINT32ENCODE(p,sdim->dim_flags);
|
||||
if(sdim->rank>0)
|
||||
{
|
||||
for(u=0; u<sdim->rank; u++);
|
||||
for(u=0; u<sdim->rank; u++)
|
||||
UINT32ENCODE(p,sdim->size[u]);
|
||||
if(sdim->dim_flags&0x01)
|
||||
{
|
||||
for(u=0; u<sdim->rank; u++);
|
||||
for(u=0; u<sdim->rank; u++)
|
||||
UINT32ENCODE(p,sdim->max[u]);
|
||||
} /* end if */
|
||||
if(sdim->dim_flags&0x02)
|
||||
{
|
||||
for(u=0; u<sdim->rank; u++);
|
||||
for(u=0; u<sdim->rank; u++)
|
||||
UINT32ENCODE(p,sdim->perm[u]);
|
||||
} /* end if */
|
||||
} /* end if */
|
||||
@ -338,6 +338,23 @@ H5O_sim_dim_copy (const void *mesg, void *dest)
|
||||
|
||||
/* copy */
|
||||
HDmemcpy(dst,src,sizeof(H5O_sim_dim_t));
|
||||
if(src->rank>0)
|
||||
{
|
||||
dst->size = H5MM_xcalloc (src->rank, sizeof(uint32));
|
||||
HDmemcpy(dst->size,src->size,src->rank*sizeof(uint32));
|
||||
/* Check for maximum dimensions and copy those */
|
||||
if((src->dim_flags&0x01)>0)
|
||||
{
|
||||
dst->max = H5MM_xcalloc (src->rank, sizeof(uint32));
|
||||
HDmemcpy(dst->max,src->max,src->rank*sizeof(uint32));
|
||||
} /* end if */
|
||||
/* Check for dimension permutation and copy those */
|
||||
if((src->dim_flags&0x02)>0)
|
||||
{
|
||||
dst->perm = H5MM_xcalloc (src->rank, sizeof(uint32));
|
||||
HDmemcpy(dst->perm,src->perm,src->rank*sizeof(uint32));
|
||||
} /* end if */
|
||||
} /* end if */
|
||||
|
||||
FUNC_LEAVE ((void*)dst);
|
||||
} /* end H5O_sim_dim_copy() */
|
||||
|
@ -102,6 +102,7 @@ H5O_sim_dtype_decode (hdf5_file_t *f, size_t raw_size, const uint8 *p)
|
||||
sdtype->len=*p++;
|
||||
sdtype->arch=*p++;
|
||||
UINT16DECODE(p,sdtype->base);
|
||||
sdtype->base=MAKE_ATOM(H5_DATATYPE,sdtype->base); /* convert into atomic base type */
|
||||
} /* end if */
|
||||
|
||||
FUNC_LEAVE (sdtype);
|
||||
|
Loading…
Reference in New Issue
Block a user