summaryrefslogtreecommitdiffstats
path: root/src/H5Osdtyp.c
diff options
context:
space:
mode:
authorRobb Matzke <matzke@llnl.gov>1997-12-10 22:41:07 (GMT)
committerRobb Matzke <matzke@llnl.gov>1997-12-10 22:41:07 (GMT)
commit082dd8cda9ef3d49be23dfce49e10dd30d0758bc (patch)
treee60a32468ba14f758849f34454fdd8722b72edaa /src/H5Osdtyp.c
parent3aee91269b83b09a186d214c55873fbbfa15602d (diff)
downloadhdf5-082dd8cda9ef3d49be23dfce49e10dd30d0758bc.zip
hdf5-082dd8cda9ef3d49be23dfce49e10dd30d0758bc.tar.gz
hdf5-082dd8cda9ef3d49be23dfce49e10dd30d0758bc.tar.bz2
[svn-r139] ./src/*.[ch]
Removed the interface initialization argument from FUNC_ENTER() and made it a locally-defined preprocessor symbol, INTERFACE_INIT. Changed `offset' to `address' and `length' to `size' in documentation so it's more consistent. `Offset' still appears occassionally when it refers to a byte offset within some other data structure. Moved interface termination function prototypes from public header files to .c files and made them static. ./src/H5.c ./src/H5public.h Added H5init() because it's possible that the predefined data types are not initialized. This happens only if the first call to the hdf5 library passes a predefined data type symbol as an argument. There should be some way to fix this... ./src/H5A.c ./src/H5Aprivate.h ./src/H5Apublic.h The free_func returns SUCCEED or FAIL, although the return value is ignored by H5A. This is so we can use the various H5*_close() functions to free things. H5Ainc_ref() and H5Adec_ref() are no longer public. Many of the other atom functions should also be made private, but I'll save that for later... Added additional template groups called H5_TEMPLATE_0 through H5_TEMPLATE_7 that are used by the various template subclasses. Increased the number of bits used for atom groups to prevent negative atoms. ./src/H5AC.c ./src/H5ACprivate.h Changed H5AC_new() to H5AC_create() to make names more consistent. ./src/H5B.c ./src/H5Bprivate.h Changed H5B_new() to H5B_create() to make names more consistent. ./src/H5C.c ./src/H5Cprivate.h ./src/H5Cpublic.h Now supports multiple subclasses of templates, although it's done with big switch statements. The default values for templates are defined in the source file to which that template belongs. This got rid of lots of needless preprocessor constants. Added H5Ccreate() to create a new template. Changed H5C_release() to H5Cclose() to make the naming more consistent. ./src/H5D.c ./src/H5Dprivate.h ./src/H5Dpublic.h Enhanced to use the new dataset interface, and uses the enhanced data type and data space interfaces, which haven't been completely implemented. The dataset interface doesn't handle non-contiguous storage, compression, or data type and space conversions yet. ./src/H5F.c ./src/H5Fprivate.h ./src/H5Fpublic.h Removed H5Fflush() since just calls H5F_flush(), which doesn't do what the user would probably think it does, namely, flush everything. It only flushes those things sitting in the H5AC cache and the boot block. Changed the `file_create_parms' field of H5F_low_t to just `create_parms' since the `file' part is obvious. ./src/H5Fistore.c Added some support for external files. Mostly just in the file format and not supported much by the library yet. I need to finish some dataset functions first. Changed H5F_istore_new() to H5F_istore_create() to make names more uniform across packages. ./src/H5Flow.c Flushing a file causes the file to be physically extended to the logical eof. This prevents H5F_open() from thinking a file has been truncated. Most of the time the file will already be that large, and when it isn't Unix will often just allocate the final block anyway. ./src/H5G.c ./src/H5Gent.c ./src/H5Gnode.c ./src/H5Gpkg.h ./src/H5Gprivate.h ./src/H5Gstab.c Removed H5G_basename() Removed (temporarily) data type information from symbol table entries and renamed H5G_CACHED_SDATA to H5G_CACHED_SDSPACE to reflect that it's a simple data space and has nothing to do with raw data. Changed H5G_node_new() to H5G_node_create() and H5G_stab_new() to H5G_stab_create() to make names more uniform across packages. Fixed an undefined address bug that happens when H5G_node_debug() program doesn't pass enough info to H5G_node_load(). ./src/H5H.c ./src/H5Hprivate.h Changed H5H_new() to H5H_create() to make the names more uniform across packages. ./src/H5M.c ./src/H5Mprivate.h ./src/H5Mpublic.h Nulled all the create functions. Most of the other callbacks are to public functions. Removed H5Mcreate(). Changed hobjtype_t to group_t since it has to be the same thing anyway. ./src/H5O.c ./src/H5Oprivate.h ./src/H5Osdim.c ./src/H5Osdtyp.c Changed H5O_SIM_DIM to H5O_SDSPACE (simple data space) since `simple data space' is its official name, not `simple dimensions'. Will eventually add H5O_CDSPACE for comples data spaces. Changed _sim_dim_ to _dspace_. Replaced H5O_SIM_DTYPE and the compound data type messages with a single H5O_DTYPE message. Changed _sim_dtype_ to _dtype_. Changed H5O_STD_STORE to H5O_CSTORE (contiguous storage) since contiguous storage is not necessarily standard. Changed _std_store_ to _cstore_ in H5Ocstore.c Added the H5O_EFL (external file list) message. Changed H5O_new() to H5O_create() to make names more uniform across packages. ./src/H5Oefl.c NEW External file list message for specifying which non-hdf5 files contain raw data for a dataset. ./src/H5P.c ./src/H5Pprivate.h ./src/H5Ppublic.h Renamed and moved data structures to make the names conform to our naming scheme. ./src/H5T.c ./src/H5Tprivate.h ./src/H5Tpublic.h ./src/H5Tpkg.h NEW Data structures redesigned to be more flexible. The interface was redesigned to make it more regular and to make some names more uniform across packages. ./src/H5detect.c Output was changed to produce a file that conforms to the hdf5 coding standard. ./src/Makefile.in Generates H5Tinit.c by running H5detect. ./src/debug.c Moved command argument processing.
Diffstat (limited to 'src/H5Osdtyp.c')
-rw-r--r--src/H5Osdtyp.c937
1 files changed, 722 insertions, 215 deletions
diff --git a/src/H5Osdtyp.c b/src/H5Osdtyp.c
index 0800e30..edc4c82 100644
--- a/src/H5Osdtyp.c
+++ b/src/H5Osdtyp.c
@@ -16,67 +16,387 @@ static char RcsId[] = "@(#)$Revision$";
/* $Id$ */
-/*LINTLIBRARY */
-/*+
- FILE
- H5Osdtyp.c
- HDF5 Simple Datatype Object Header Message routines
-
- EXPORTED ROUTINES
-
- LIBRARY-SCOPED ROUTINES
-
- LOCAL ROUTINES
- + */
+#define H5T_PACKAGE /*prevent warning from including H5Tpkg.h */
#include <H5private.h>
#include <H5Eprivate.h>
#include <H5Gprivate.h>
#include <H5MMprivate.h>
#include <H5Oprivate.h>
+#include <H5Tpkg.h>
-#define PABLO_MASK H5O_sim_dtype_mask
+#define PABLO_MASK H5O_dtype_mask
/* PRIVATE PROTOTYPES */
-static void *H5O_sim_dtype_decode (H5F_t *f, size_t raw_size, const uint8 *p);
-static herr_t H5O_sim_dtype_encode (H5F_t *f, size_t size, uint8 *p,
- const void *_mesg);
-static void *H5O_sim_dtype_fast (const H5G_cache_t *cache, void *_mesg);
-static hbool_t H5O_sim_dtype_cache (H5G_type_t *cache_type, H5G_cache_t *cache,
- const void *_mesg);
-static void *H5O_sim_dtype_copy (const void *_mesg, void *_dest);
-static size_t H5O_sim_dtype_size (H5F_t *f, const void *_mesg);
-static herr_t H5O_sim_dtype_debug (H5F_t *f, const void *_mesg,
- FILE *stream, intn indent, intn fwidth);
+static herr_t H5O_dtype_encode (H5F_t *f, size_t raw_size, uint8 *p,
+ const void *mesg);
+static void *H5O_dtype_decode (H5F_t *f, size_t raw_size, const uint8 *p);
+static void *H5O_dtype_copy (const void *_mesg, void *_dest);
+static size_t H5O_dtype_size (H5F_t *f, const void *_mesg);
+static herr_t H5O_dtype_reset (void *_mesg);
+static herr_t H5O_dtype_debug (H5F_t *f, const void *_mesg,
+ FILE *stream, intn indent, intn fwidth);
/* This message derives from H5O */
-const H5O_class_t H5O_SIM_DTYPE[1] = {{
- H5O_SIM_DTYPE_ID, /* message id number */
- "sim_dtype", /* message name for debugging */
- sizeof (H5O_sim_dtype_t), /* native message size */
- H5G_CACHED_SDATA, /* symtab entry `type' field */
- H5O_sim_dtype_decode, /* decode message */
- H5O_sim_dtype_encode, /* encode message */
- H5O_sim_dtype_fast, /* get message from stab entry */
- H5O_sim_dtype_cache, /* put message into stab entry */
- H5O_sim_dtype_copy, /* copy the native value */
- H5O_sim_dtype_size, /* size of symbol table entry */
- NULL, /* default reset method */
- H5O_sim_dtype_debug, /* debug the message */
+const H5O_class_t H5O_DTYPE[1] = {{
+ H5O_DTYPE_ID, /* message id number */
+ "data_type", /* message name for debugging */
+ sizeof (H5T_t), /* native message size */
+ H5G_NOTHING_CACHED, /* symtab entry `type' field */
+ H5O_dtype_decode, /* decode message */
+ H5O_dtype_encode, /* encode message */
+ NULL, /* get message from stab entry */
+ NULL, /* put message into stab entry */
+ H5O_dtype_copy, /* copy the native value */
+ H5O_dtype_size, /* size of raw message */
+ H5O_dtype_reset, /* reset method */
+ H5O_dtype_debug, /* debug the message */
}};
-/* Is the interface initialized? */
+/* Interface initialization */
static hbool_t interface_initialize_g = FALSE;
+#define INTERFACE_INIT NULL
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5O_dtype_decode_helper
+ *
+ * Purpose: Decodes a data type
+ *
+ * Return: Success: SUCCEED
+ *
+ * Failure: FAIL
+ *
+ * Programmer: Robb Matzke
+ * Monday, December 8, 1997
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5O_dtype_decode_helper (const uint8 **pp, H5T_t *dt)
+{
+ uintn flags, perm_word;
+ intn i, j;
+
+ FUNC_ENTER (H5O_dtype_decode_helper, FAIL);
+
+ /* check args */
+ assert (pp && *pp);
+ assert (dt);
+
+ /* decode */
+ UINT32DECODE (*pp, flags);
+ dt->type = flags & 0xff;
+ flags >>= 8;
+ UINT32DECODE (*pp, dt->size);
+
+ switch (dt->type) {
+ case H5T_FIXED:
+ /*
+ * Fixed-point types...
+ */
+ dt->u.atomic.order = (flags & 0x1) ? H5T_ORDER_BE : H5T_ORDER_LE;
+ dt->u.atomic.lo_pad = (flags & 0x2) ? H5T_PAD_ONE : H5T_PAD_ZERO;
+ dt->u.atomic.hi_pad = (flags & 0x4) ? H5T_PAD_ONE : H5T_PAD_ZERO;
+ dt->u.atomic.u.i.sign = (flags & 0x8) ? H5T_SGN_2 : H5T_SGN_NONE;
+ UINT16DECODE (*pp, dt->u.atomic.offset);
+ UINT16DECODE (*pp, dt->u.atomic.prec);
+ break;
+
+ case H5T_FLOAT:
+ /*
+ * Floating-point types...
+ */
+ dt->u.atomic.order = (flags & 0x1) ? H5T_ORDER_BE : H5T_ORDER_LE;
+ dt->u.atomic.lo_pad = (flags & 0x2) ? H5T_PAD_ONE : H5T_PAD_ZERO;
+ dt->u.atomic.hi_pad = (flags & 0x4) ? H5T_PAD_ONE : H5T_PAD_ZERO;
+ dt->u.atomic.u.f.pad = (flags & 0x8) ? H5T_PAD_ONE : H5T_PAD_ZERO;
+ switch ((flags>>4) & 0x03) {
+ case 0:
+ dt->u.atomic.u.f.norm = H5T_NORM_NONE;
+ break;
+ case 1:
+ dt->u.atomic.u.f.norm = H5T_NORM_MSBSET;
+ break;
+ case 2:
+ dt->u.atomic.u.f.norm = H5T_NORM_IMPLIED;
+ break;
+ default:
+ /* unknown floating-point normalization */
+ HRETURN_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL);
+ }
+ dt->u.atomic.u.f.sign = (flags>>8) & 0xff;
+ UINT16DECODE (*pp, dt->u.atomic.offset);
+ UINT16DECODE (*pp, dt->u.atomic.prec);
+ dt->u.atomic.u.f.epos = *(*pp)++;
+ dt->u.atomic.u.f.esize = *(*pp)++;
+ assert (dt->u.atomic.u.f.esize>0);
+ dt->u.atomic.u.f.mpos = *(*pp)++;
+ dt->u.atomic.u.f.msize = *(*pp)++;
+ assert (dt->u.atomic.u.f.msize>0);
+ UINT32DECODE (*pp, dt->u.atomic.u.f.ebias);
+ break;
+
+ case H5T_COMPOUND:
+ /*
+ * Compound data types...
+ */
+ dt->u.compnd.nmembs = flags & 0xffff;
+ assert (dt->u.compnd.nmembs>0);
+ dt->u.compnd.nalloc = dt->u.compnd.nmembs;
+ dt->u.compnd.memb = H5MM_xcalloc (dt->u.compnd.nalloc,
+ sizeof(H5T_member_t));
+ for (i=0; i<dt->u.compnd.nmembs; i++) {
+ dt->u.compnd.memb[i].name = H5MM_xstrdup (*pp);
+ *pp += ((strlen (*pp)+8)/8) * 8; /*multiple of 8 w/ null terminator*/
+ UINT32DECODE (*pp, dt->u.compnd.memb[i].offset);
+ dt->u.compnd.memb[i].ndims = *(*pp)++;
+ assert (dt->u.compnd.memb[i].ndims<=4);
+ *pp += 3; /*reserved bytes*/
+ for (j=0; j<dt->u.compnd.memb[i].ndims; j++) {
+ UINT32DECODE (*pp, dt->u.compnd.memb[i].dim[j]);
+ }
+ UINT32DECODE (*pp, perm_word);
+ dt->u.compnd.memb[i].perm[0] = (perm_word >> 0) & 0xff;
+ dt->u.compnd.memb[i].perm[1] = (perm_word >> 8) & 0xff;
+ dt->u.compnd.memb[i].perm[2] = (perm_word >> 16) & 0xff;
+ dt->u.compnd.memb[i].perm[3] = (perm_word >> 24) & 0xff;
+ if (H5O_dtype_decode_helper (pp, &(dt->u.compnd.memb[i].type))<0 ||
+ H5T_COMPOUND==dt->u.compnd.memb[i].type.type) {
+ for (j=0; j<=i; j++) H5MM_xfree (dt->u.compnd.memb[i].name);
+ H5MM_xfree (dt->u.compnd.memb);
+ /* Can't decode member type */
+ HRETURN_ERROR (H5E_DATATYPE, H5E_CANTDECODE, FAIL);
+ }
+ }
+ break;
+
+ default:
+ if (flags) {
+ /* class flags are non-zero */
+ HRETURN_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL);
+ }
+ break;
+ }
+
+ FUNC_LEAVE (SUCCEED);
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5O_dtype_encode_helper
+ *
+ * Purpose: Encodes a data type.
+ *
+ * Return: Success: SUCCEED
+ *
+ * Failure: FAIL
+ *
+ * Programmer: Robb Matzke
+ * Monday, December 8, 1997
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5O_dtype_encode_helper (uint8 **pp, const H5T_t *dt)
+{
+ uintn flags = 0;
+ uintn perm_word;
+ char *hdr = *pp;
+ intn i, j, n;
+
+ FUNC_ENTER (H5O_dtype_encode_helper, FAIL);
+
+ /* check args */
+ assert (pp && *pp);
+ assert (dt);
+
+ /* skip the type and class bit field for now */
+ *pp += 4;
+ UINT32ENCODE (*pp, dt->size);
+
+ switch (dt->type) {
+ case H5T_FIXED:
+ /*
+ * Fixed-point data types...
+ */
+ switch (dt->u.atomic.order) {
+ case H5T_ORDER_LE:
+ break; /*nothing*/
+ case H5T_ORDER_BE:
+ flags |= 0x01;
+ break;
+ default:
+ /* Byte order is not supported in file format yet */
+ HRETURN_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL);
+ }
+
+ switch (dt->u.atomic.lo_pad) {
+ case H5T_PAD_ZERO:
+ break; /*nothing*/
+ case H5T_PAD_ONE:
+ flags |= 0x02;
+ break;
+ default:
+ /* Bit padding is not supported in file format yet */
+ HRETURN_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL);
+ }
+
+ switch (dt->u.atomic.hi_pad) {
+ case H5T_PAD_ZERO:
+ break; /*nothing*/
+ case H5T_PAD_ONE:
+ flags |= 0x04;
+ break;
+ default:
+ /* Bit padding is not supported in file format yet */
+ HRETURN_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL);
+ }
+
+ switch (dt->u.atomic.u.i.sign) {
+ case H5T_SGN_NONE:
+ break; /*nothing*/
+ case H5T_SGN_2:
+ flags |= 0x08;
+ break;
+ default:
+ /* Sign scheme is not supported in file format yet */
+ HRETURN_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL);
+ }
+
+ UINT16ENCODE (*pp, dt->u.atomic.offset);
+ UINT16ENCODE (*pp, dt->u.atomic.prec);
+ break;
+
+ case H5T_FLOAT:
+ /*
+ * Floating-point types...
+ */
+ switch (dt->u.atomic.order) {
+ case H5T_ORDER_LE:
+ break; /*nothing*/
+ case H5T_ORDER_BE:
+ flags |= 0x01;
+ break;
+ default:
+ /* Byte order is not supported in file format yet */
+ HRETURN_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL);
+ }
+
+ switch (dt->u.atomic.lo_pad) {
+ case H5T_PAD_ZERO:
+ break; /*nothing*/
+ case H5T_PAD_ONE:
+ flags |= 0x02;
+ break;
+ default:
+ /* Bit padding is not supported in file format yet */
+ HRETURN_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL);
+ }
+
+ switch (dt->u.atomic.hi_pad) {
+ case H5T_PAD_ZERO:
+ break; /*nothing*/
+ case H5T_PAD_ONE:
+ flags |= 0x04;
+ break;
+ default:
+ /* Bit padding is not supported in file format yet */
+ HRETURN_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL);
+ }
+
+ switch (dt->u.atomic.u.f.pad) {
+ case H5T_PAD_ZERO:
+ break; /*nothing*/
+ case H5T_PAD_ONE:
+ flags |= 0x08;
+ break;
+ default:
+ /* Bit padding is not supported in file format yet */
+ HRETURN_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL);
+ }
+
+ switch (dt->u.atomic.u.f.norm) {
+ case H5T_NORM_NONE:
+ break; /*nothing*/
+ case H5T_NORM_MSBSET:
+ flags |= 0x10;
+ break;
+ case H5T_NORM_IMPLIED:
+ flags |= 0x20;
+ break;
+ default:
+ /* Normalization scheme is not supported in file format yet */
+ HRETURN_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL);
+ }
+
+ flags |= (dt->u.atomic.u.f.sign << 8) & 0xff00;
+ UINT16ENCODE (*pp, dt->u.atomic.offset);
+ UINT16ENCODE (*pp, dt->u.atomic.prec);
+ *(*pp)++ = dt->u.atomic.u.f.epos;
+ *(*pp)++ = dt->u.atomic.u.f.esize;
+ *(*pp)++ = dt->u.atomic.u.f.mpos;
+ *(*pp)++ = dt->u.atomic.u.f.msize;
+ UINT32ENCODE (*pp, dt->u.atomic.u.f.ebias);
+ break;
+
+ case H5T_COMPOUND:
+ /*
+ * Compound data types...
+ */
+ flags = dt->u.compnd.nmembs & 0xffff;
+ for (i=0; i<dt->u.compnd.nmembs; i++) {
+ n = strlen (dt->u.compnd.memb[i].name);
+ for (j=0; j<=n && j%8; j++) {
+ if (j<n) *(*pp)++ = dt->u.compnd.memb[i].name[j];
+ else *(*pp)++ = '\0';
+ }
+ UINT32ENCODE (*pp, dt->u.compnd.memb[i].offset);
+ *(*pp)++ = dt->u.compnd.memb[i].ndims;
+ assert (dt->u.compnd.memb[i].ndims<=4);
+ *(*pp)++ = '\0';
+ *(*pp)++ = '\0';
+ *(*pp)++ = '\0';
+ for (j=0; j<dt->u.compnd.memb[i].ndims; j++) {
+ UINT32ENCODE (*pp, dt->u.compnd.memb[i].dim[j]);
+ }
+ for (j=0, perm_word=0; j<dt->u.compnd.memb[i].ndims; j++) {
+ perm_word |= dt->u.compnd.memb[i].perm[j] << (8*j);
+ }
+ UINT32ENCODE (*pp, perm_word);
+ if (H5O_dtype_encode_helper (pp, &(dt->u.compnd.memb[i].type))<0) {
+ /* Can't encode member type */
+ HRETURN_ERROR (H5E_DATATYPE, H5E_CANTENCODE, FAIL);
+ }
+ }
+ break;
+
+ default:
+ /*nothing*/
+ break;
+ }
+
+ *hdr++ = dt->type;
+ *hdr++ = (flags >> 0) & 0xff;
+ *hdr++ = (flags >> 8) & 0xff;
+ *hdr++ = (flags >> 16) & 0xff;
+
+ FUNC_LEAVE (SUCCEED);
+}
/*--------------------------------------------------------------------------
NAME
- H5O_sim_dtype_decode
+ H5O_dtype_decode
PURPOSE
- Decode a simple datatype message and return a pointer to a memory struct
+ Decode a datatype message and return a pointer to a memory struct
with the decoded information
USAGE
- void *H5O_sim_dtype_decode(f, raw_size, p)
- H5F_t *f; IN: pointer to the HDF5 file struct
+ void *H5O_dtype_decode(f, raw_size, p)
+ H5F_t *f; IN: pointer to the HDF5 file struct
size_t raw_size; IN: size of the raw information buffer
const uint8 *p; IN: the raw information buffer
RETURNS
@@ -87,36 +407,36 @@ static hbool_t interface_initialize_g = FALSE;
function using malloc() and is returned to the caller.
--------------------------------------------------------------------------*/
static void *
-H5O_sim_dtype_decode (H5F_t *f, size_t raw_size, const uint8 *p)
+H5O_dtype_decode (H5F_t *f, size_t raw_size, const uint8 *p)
{
- H5O_sim_dtype_t *sdtype;
+ H5T_t *dt = NULL;
- FUNC_ENTER (H5O_sim_dtype_decode, NULL, NULL);
+ FUNC_ENTER (H5O_dtype_decode, NULL);
- /* check args */
- assert (f);
- assert (raw_size == 4);
- assert (p);
+ /* check args */
+ assert (f);
+ assert (raw_size>0);
+ assert (p);
- /* decode */
- if((sdtype = H5MM_xcalloc (1, sizeof(H5O_sim_dtype_t)))!=NULL)
- {
- 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 */
+ dt = H5MM_xcalloc (1, sizeof(H5T_t));
- FUNC_LEAVE (sdtype);
-} /* end H5O_sim_dtype_decode() */
+ if (H5O_dtype_decode_helper (&p, dt)<0) {
+ H5MM_xfree (dt);
+ /* can't decode type */
+ HRETURN_ERROR (H5E_DATATYPE, H5E_CANTDECODE, NULL);
+ }
+ assert (raw_size==H5O_dtype_size (f, (void*)dt));
+
+ FUNC_LEAVE (dt);
+}
/*--------------------------------------------------------------------------
NAME
- H5O_sim_dtype_encode
+ H5O_dtype_encode
PURPOSE
Encode a simple datatype message
USAGE
- herr_t H5O_sim_dtype_encode(f, raw_size, p, mesg)
+ herr_t H5O_dtype_encode(f, raw_size, p, mesg)
H5F_t *f; IN: pointer to the HDF5 file struct
size_t raw_size; IN: size of the raw information buffer
const uint8 *p; IN: the raw information buffer
@@ -128,139 +448,38 @@ H5O_sim_dtype_decode (H5F_t *f, size_t raw_size, const uint8 *p)
message in the "raw" disk form.
--------------------------------------------------------------------------*/
static herr_t
-H5O_sim_dtype_encode (H5F_t *f, size_t raw_size, uint8 *p, const void *mesg)
+H5O_dtype_encode (H5F_t *f, size_t raw_size, uint8 *p, const void *mesg)
{
- const H5O_sim_dtype_t *sdtype = (const H5O_sim_dtype_t *)mesg;
-
- FUNC_ENTER (H5O_sim_dtype_encode, NULL, FAIL);
-
- /* check args */
- assert (f);
- assert (raw_size == 4);
- assert (p);
- assert (sdtype);
-
- /* encode */
- *p++=sdtype->len;
- *p++=sdtype->arch;
- UINT16ENCODE(p,sdtype->base);
+ const H5T_t *dt = (const H5T_t *)mesg;
- FUNC_LEAVE (SUCCEED);
-} /* end H5O_sim_dtype_encode() */
-
-/*--------------------------------------------------------------------------
- NAME
- H5O_sim_dtype_fast
- PURPOSE
- Initializes a new simple datatype struct with info from a symbol table
- entry.
- USAGE
- void *H5O_sim_dtype_fast(ent, mesg)
- const H5G_entry_t *ent; IN: pointer to the symbol table entry
- const void *mesg; IN: Pointer to the simple datatype struct
- RETURNS
- Pointer to the message structure (allocated if none is supplied) on success,
- NULL on failure
- DESCRIPTION
- This function fills the native memory form of the simple datatype
- message from a symbol-table entry cache fields. (This method is required
- for simple datatypes, as they can be cached in the symbol-table entry)
---------------------------------------------------------------------------*/
-static void *
-H5O_sim_dtype_fast (const H5G_cache_t *cache, void *mesg)
-{
- H5O_sim_dtype_t *sdtype = (H5O_sim_dtype_t *)mesg;
-
- FUNC_ENTER (H5O_sim_dtype_fast, NULL, NULL);
+ FUNC_ENTER (H5O_dtype_encode, FAIL);
/* check args */
- assert (cache);
-
- if (!sdtype) sdtype = H5MM_xcalloc (1, sizeof(H5O_sim_dtype_t));
- sdtype->len = cache->sdata.nt.length;
- sdtype->arch = cache->sdata.nt.arch;
-
- /* Convert into atomic base type. */
- sdtype->base = MAKE_ATOM (H5_DATATYPE, cache->sdata.nt.type);
+ assert (f);
+ assert (raw_size==H5O_dtype_size (f, mesg));
+ assert (p);
+ assert (dt);
- FUNC_LEAVE (sdtype);
-} /* end H5O_sim_dtype_fast() */
+ /* encode */
+ if (H5O_dtype_encode_helper (&p, dt)<0) {
+ /* can't encode type */
+ HRETURN_ERROR (H5E_DATATYPE, H5E_CANTENCODE, FAIL);
+ }
-/*--------------------------------------------------------------------------
- NAME
- H5O_sim_dtype_cache
- PURPOSE
- Copies a simple datatype message into the cache portion of a symbol table
- entry.
- USAGE
- hbool_t H5O_sim_dtype_cache(ent, mesg)
- const H5G_entry_t *ent; IN: Pointer to the symbol table entry
- const void *mesg; IN: Pointer to the simple datatype struct
- RETURNS
- BTRUE if symbol-table modified, BFALSE if not modified, BFAIL on failure.
- The new cache type is returned through the CACHE_TYPE argument.
- DESCRIPTION
- This function is the opposite of the H5O_sim_dtype_fast method, it
- copies a message into the cached portion of a symbol-table entry. (This
- method is required for simple datatypes, as they can be cached in the
- symbol-table entry)
---------------------------------------------------------------------------*/
-static hbool_t
-H5O_sim_dtype_cache (H5G_type_t *cache_type, H5G_cache_t *cache,
- const void *mesg)
-{
- const H5O_sim_dtype_t *sdtype = (const H5O_sim_dtype_t *)mesg;
- hbool_t modified = BFALSE;
-
- FUNC_ENTER (H5O_sim_dtype_cache, NULL, BFAIL);
-
- /* check args */
- assert (cache_type);
- assert (cache);
- assert (sdtype);
-
- if (H5G_CACHED_SDATA != *cache_type) {
- /*
- * No sdata cached yet.
- */
- modified = BTRUE;
- *cache_type = H5G_CACHED_SDATA;
- cache->sdata.nt.length = sdtype->len;
- cache->sdata.nt.arch = sdtype->arch;
- cache->sdata.nt.type = sdtype->base;
-
- } else {
- /*
- * Some sdata already cached.
- */
- if (cache->sdata.nt.length != sdtype->len) {
- modified = BTRUE;
- cache->sdata.nt.length = sdtype->len;
- }
-
- if (cache->sdata.nt.arch != sdtype->arch) {
- modified = BTRUE;
- cache->sdata.nt.arch = sdtype->arch;
- }
-
- if (cache->sdata.nt.type != (uint16)sdtype->base) {
- modified = BTRUE;
- cache->sdata.nt.type = (uint16)sdtype->base;
- }
- }
-
- FUNC_LEAVE (modified);
-} /* end H5O_sim_dtype_cache() */
+ FUNC_LEAVE (SUCCEED);
+}
/*--------------------------------------------------------------------------
NAME
- H5O_sim_dtype_copy
+ H5O_dtype_copy
PURPOSE
Copies a message from MESG to DEST, allocating DEST if necessary.
USAGE
- void *H5O_sim_dtype_copy(mesg, dest)
- const void *mesg; IN: Pointer to the source simple datatype struct
- const void *dest; IN: Pointer to the destination simple datatype struct
+ void *H5O_dtype_copy(mesg, dest)
+ const void *mesg; IN: Pointer to the source simple datatype
+ struct
+ const void *dest; IN: Pointer to the destination simple
+ datatype struct
RETURNS
Pointer to DEST on success, NULL on failure
DESCRIPTION
@@ -268,32 +487,40 @@ H5O_sim_dtype_cache (H5G_type_t *cache_type, H5G_cache_t *cache,
allocating the destination structure if necessary.
--------------------------------------------------------------------------*/
static void *
-H5O_sim_dtype_copy (const void *mesg, void *dest)
+H5O_dtype_copy (const void *_src, void *_dst)
{
- const H5O_sim_dtype_t *src = (const H5O_sim_dtype_t *)mesg;
- H5O_sim_dtype_t *dst = (H5O_sim_dtype_t *)dest;
+ const H5T_t *src = (const H5T_t *)_src;
+ H5T_t *dst = NULL;
- FUNC_ENTER (H5O_sim_dtype_copy, NULL, NULL);
+ FUNC_ENTER (H5O_dtype_copy, NULL);
/* check args */
assert (src);
- if (!dst) dst = H5MM_xcalloc (1, sizeof(H5O_sim_dtype_t));
/* copy */
- HDmemcpy(dst,src,sizeof(H5O_sim_dtype_t));
+ if (NULL==(dst=H5T_copy (src))) {
+ HRETURN_ERROR (H5E_DATATYPE, H5E_CANTINIT, NULL); /*can't copy type*/
+ }
+
+ /* was result already allocated? */
+ if (_dst) {
+ *((H5T_t*)_dst) = *dst;
+ H5MM_xfree (dst);
+ dst = (H5T_t*)_dst;
+ }
FUNC_LEAVE ((void*)dst);
-} /* end H5O_sim_dtype_copy() */
+}
/*--------------------------------------------------------------------------
NAME
- H5O_sim_dtype_size
+ H5O_dtype_size
PURPOSE
Return the raw message size in bytes
USAGE
- void *H5O_sim_dtype_copy(f, mesg)
+ void *H5O_dtype_size(f, mesg)
H5F_t *f; IN: pointer to the HDF5 file struct
- const void *mesg; IN: Pointer to the source simple datatype struct
+ const void *mesg; IN: Pointer to the source simple datatype struct
RETURNS
Size of message on success, FAIL on failure
DESCRIPTION
@@ -302,21 +529,88 @@ H5O_sim_dtype_copy (const void *mesg, void *dest)
portion of the message). It doesn't take into account alignment.
--------------------------------------------------------------------------*/
static size_t
-H5O_sim_dtype_size (H5F_t *f, const void *mesg)
+H5O_dtype_size (H5F_t *f, const void *mesg)
{
- FUNC_ENTER (H5O_sim_dtype_size, NULL, FAIL);
- FUNC_LEAVE (4);
-} /* end H5O_sim_dtype_size() */
+ intn i;
+ size_t ret_value = 8;
+ const H5T_t *dt = (const H5T_t *)mesg;
+
+ FUNC_ENTER (H5O_dtype_size, FAIL);
+
+ assert (mesg);
+
+ switch (dt->type) {
+ case H5T_FIXED:
+ ret_value += 4;
+ break;
+
+ case H5T_FLOAT:
+ ret_value += 12;
+ break;
+
+ case H5T_COMPOUND:
+ for (i=0; i<dt->u.compnd.nmembs; i++) {
+ ret_value += ((HDstrlen (dt->u.compnd.memb[i].name)+8)/8)*8;
+ ret_value += 12 + dt->u.compnd.memb[i].ndims * 4;
+ ret_value += H5O_dtype_size (f, &(dt->u.compnd.memb[i].type));
+ }
+ break;
+
+ default:
+ /*no properties*/
+ break;
+ }
+
+
+ FUNC_LEAVE (ret_value);
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5O_dtype_reset
+ *
+ * Purpose: Frees resources within a data type message, but doesn't free
+ * the message itself.
+ *
+ * Return: Success: SUCCEED
+ *
+ * Failure: FAIL
+ *
+ * Programmer: Robb Matzke
+ * Tuesday, December 9, 1997
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5O_dtype_reset (void *_mesg)
+{
+ H5T_t *dt = (H5T_t *)_mesg;
+ H5T_t *tmp = NULL;
+
+ FUNC_ENTER (H5O_dtype_reset, FAIL);
+
+ if (dt) {
+ tmp = H5MM_xmalloc (sizeof(H5T_t));
+ *tmp = *dt;
+ H5T_close (tmp);
+ HDmemset (dt, 0, sizeof(H5T_t));
+ }
+
+ FUNC_LEAVE (SUCCEED);
+}
/*--------------------------------------------------------------------------
NAME
- H5O_sim_dtype_debug
+ H5O_dtype_debug
PURPOSE
- Prints debugging information for a simple datatype message
+ Prints debugging information for a data type message
USAGE
- void *H5O_sim_dtype_debug(f, mesg, stream, indent, fwidth)
- H5F_t *f; IN: pointer to the HDF5 file struct
- const void *mesg; IN: Pointer to the source simple datatype struct
+ void *H5O_dtype_debug(f, mesg, stream, indent, fwidth)
+ H5F_t *f; IN: pointer to the HDF5 file struct
+ const void *mesg; IN: Pointer to the source simple datatype
+ struct
FILE *stream; IN: Pointer to the stream for output data
intn indent; IN: Amount to indent information by
intn fwidth; IN: Field width (?)
@@ -327,30 +621,243 @@ H5O_sim_dtype_size (H5F_t *f, const void *mesg)
parameter.
--------------------------------------------------------------------------*/
static herr_t
-H5O_sim_dtype_debug (H5F_t *f, const void *mesg, FILE *stream,
+H5O_dtype_debug (H5F_t *f, const void *mesg, FILE *stream,
intn indent, intn fwidth)
{
- const H5O_sim_dtype_t *sdtype = (const H5O_sim_dtype_t *)mesg;
+ const H5T_t *dt = (const H5T_t *)mesg;
+ const char *s;
+ char buf[256];
+ intn i, j;
- FUNC_ENTER (H5O_sim_dtype_debug, NULL, FAIL);
+ FUNC_ENTER (H5O_dtype_debug, FAIL);
/* check args */
assert (f);
- assert (sdtype);
+ assert (dt);
assert (stream);
assert (indent>=0);
assert (fwidth>=0);
- fprintf (stream, "%*s%-*s %lu\n", indent, "", fwidth,
- "Length:",
- (unsigned long)(sdtype->len));
- fprintf (stream, "%*s%-*s %lu\n", indent, "", fwidth,
- "Architecture:",
- (unsigned long)(sdtype->arch));
- fprintf (stream, "%*s%-*s %lu\n", indent, "", fwidth,
- "Data-Type:",
- (unsigned long)((uint16)sdtype->base));
+ switch (dt->type) {
+ case H5T_FIXED:
+ s = "fixed-point";
+ break;
+ case H5T_FLOAT:
+ s = "floating-point";
+ break;
+ case H5T_DATE:
+ s = "date and time";
+ break;
+ case H5T_STRING:
+ s = "text string";
+ break;
+ case H5T_BITFIELD:
+ s = "bit field";
+ break;
+ case H5T_OPAQUE:
+ s = "opaque";
+ break;
+ case H5T_COMPOUND:
+ s = "compound";
+ break;
+ default:
+ sprintf (buf, "H5T_CLASS_%d", (int)(dt->type));
+ s = buf;
+ break;
+ }
+ fprintf (stream, "%*s%-*s %s\n", indent, "", fwidth,
+ "Type class:",
+ s);
+
+ fprintf (stream, "%*s%-*s %lu byte%s\n", indent, "", fwidth,
+ "Size:",
+ (unsigned long)(dt->size), 1==dt->size?"":"s");
+
+ if (H5T_COMPOUND==dt->type) {
+ fprintf (stream, "%*s%-*s %d\n", indent, "", fwidth,
+ "Number of members:",
+ dt->u.compnd.nmembs);
+ for (i=0; i<dt->u.compnd.nmembs; i++) {
+ sprintf (buf, "Member %d:", i);
+ fprintf (stream, "%*s%-*s %s\n", indent, "", fwidth,
+ buf,
+ dt->u.compnd.memb[i].name);
+ fprintf (stream, "%*s%-*s %lu\n", indent+3, "", MAX (0, fwidth-3),
+ "Byte offset:",
+ (unsigned long)(dt->u.compnd.memb[i].offset));
+ fprintf (stream, "%*s%-*s %d%s\n", indent+3, "", MAX (0, fwidth-3),
+ "Dimensionality:",
+ dt->u.compnd.memb[i].ndims,
+ 0==dt->u.compnd.memb[i].ndims?" (scalar)":"");
+ if (dt->u.compnd.memb[i].ndims>0) {
+ fprintf (stream, "%*s%-*s {", indent+3, "", MAX (0, fwidth-3),
+ "Size:");
+ for (j=0; j<dt->u.compnd.memb[i].ndims; j++) {
+ fprintf (stream, "%s%lu", j?", ":"",
+ (unsigned long)(dt->u.compnd.memb[i].dim[j]));
+ }
+ fprintf (stream, "}\n");
+ fprintf (stream, "%*s%-*s {", indent+3, "", MAX (0, fwidth-3),
+ "Permutation:");
+ for (j=0; j<dt->u.compnd.memb[i].ndims; j++) {
+ fprintf (stream, "%s%lu", j?", ":"",
+ (unsigned long)(dt->u.compnd.memb[i].perm[j]));
+ }
+ fprintf (stream, "}\n");
+ }
+ H5O_dtype_debug (f, &(dt->u.compnd.memb[i].type), stream,
+ indent+3, MAX (0, fwidth-3));
+ }
+ } else {
+ switch (dt->u.atomic.order) {
+ case H5T_ORDER_LE:
+ s = "little endian";
+ break;
+ case H5T_ORDER_BE:
+ s = "big endian";
+ break;
+ case H5T_ORDER_VAX:
+ s = "VAX";
+ break;
+ case H5T_ORDER_NONE:
+ s = "none";
+ break;
+ default:
+ sprintf (buf, "H5T_ORDER_%d", dt->u.atomic.order);
+ s = buf;
+ break;
+ }
+ fprintf (stream, "%*s%-*s %s\n", indent, "", fwidth,
+ "Byte order:",
+ s);
+
+ fprintf (stream, "%*s%-*s %lu bit%s\n", indent, "", fwidth,
+ "Precision:",
+ (unsigned long)(dt->u.atomic.prec),
+ 1==dt->u.atomic.prec?"":"s");
+
+ fprintf (stream, "%*s%-*s %lu bit%s\n", indent, "", fwidth,
+ "Offset:",
+ (unsigned long)(dt->u.atomic.offset),
+ 1==dt->u.atomic.offset?"":"s");
+
+ switch (dt->u.atomic.lo_pad) {
+ case H5T_PAD_ZERO:
+ s = "zero";
+ break;
+ case H5T_PAD_ONE:
+ s = "one";
+ break;
+ default:
+ if (dt->u.atomic.lo_pad<0) {
+ sprintf (buf, "H5T_PAD_%d", -(dt->u.atomic.lo_pad));
+ } else {
+ sprintf (buf, "bit-%d", dt->u.atomic.lo_pad);
+ }
+ s = buf;
+ break;
+ }
+ fprintf (stream, "%*s%-*s %s\n", indent, "", fwidth,
+ "Low pad type:", s);
+
+ switch (dt->u.atomic.hi_pad) {
+ case H5T_PAD_ZERO:
+ s = "zero";
+ break;
+ case H5T_PAD_ONE:
+ s = "one";
+ break;
+ default:
+ if (dt->u.atomic.hi_pad<0) {
+ sprintf (buf, "H5T_PAD_%d", -(dt->u.atomic.hi_pad));
+ } else {
+ sprintf (buf, "bit-%d", dt->u.atomic.hi_pad);
+ }
+ s = buf;
+ break;
+ }
+ fprintf (stream, "%*s%-*s %s\n", indent, "", fwidth,
+ "High pad type:", s);
+
+ if (H5T_FLOAT==dt->type) {
+ switch (dt->u.atomic.u.f.pad) {
+ case H5T_PAD_ZERO:
+ s = "zero";
+ break;
+ case H5T_PAD_ONE:
+ s = "one";
+ break;
+ default:
+ if (dt->u.atomic.u.f.pad<0) {
+ sprintf (buf, "H5T_PAD_%d", -(dt->u.atomic.u.f.pad));
+ } else {
+ sprintf (buf, "bit-%d", dt->u.atomic.u.f.pad);
+ }
+ s = buf;
+ break;
+ }
+ fprintf (stream, "%*s%-*s %s\n", indent, "", fwidth,
+ "Internal pad type:", s);
+
+ switch (dt->u.atomic.u.f.norm) {
+ case H5T_NORM_IMPLIED:
+ s = "implied";
+ break;
+ case H5T_NORM_MSBSET:
+ s = "msb set";
+ break;
+ case H5T_NORM_NONE:
+ s = "none";
+ break;
+ default:
+ sprintf (buf, "H5T_NORM_%d", (int)(dt->u.atomic.u.f.norm));
+ s = buf;
+ }
+ fprintf (stream, "%*s%-*s %s\n", indent, "", fwidth,
+ "Normalization:", s);
+
+ fprintf (stream, "%*s%-*s %lu\n", indent, "", fwidth,
+ "Sign bit location:",
+ (unsigned long)(dt->u.atomic.u.f.sign));
+
+ fprintf (stream, "%*s%-*s %lu\n", indent, "", fwidth,
+ "Exponent location:",
+ (unsigned long)(dt->u.atomic.u.f.epos));
+
+ fprintf (stream, "%*s%-*s 0x%08lx\n", indent, "", fwidth,
+ "Exponent bias:",
+ (unsigned long)(dt->u.atomic.u.f.ebias));
+
+ fprintf (stream, "%*s%-*s %lu\n", indent, "", fwidth,
+ "Exponent size:",
+ (unsigned long)(dt->u.atomic.u.f.esize));
+
+ fprintf (stream, "%*s%-*s %lu\n", indent, "", fwidth,
+ "Mantissa location:",
+ (unsigned long)(dt->u.atomic.u.f.mpos));
+
+ fprintf (stream, "%*s%-*s %lu\n", indent, "", fwidth,
+ "Mantissa size:",
+ (unsigned long)(dt->u.atomic.u.f.msize));
+
+ } else if (H5T_FIXED==dt->type) {
+ switch (dt->u.atomic.u.i.sign) {
+ case H5T_SGN_NONE:
+ s = "none";
+ break;
+ case H5T_SGN_2:
+ s = "2's comp";
+ break;
+ default:
+ sprintf (buf, "H5T_SGN_%d", (int)(dt->u.atomic.u.i.sign));
+ s = buf;
+ break;
+ }
+ fprintf (stream, "%*s%-*s %s\n", indent, "", fwidth,
+ "Sign scheme:", s);
+
+ }
+ }
FUNC_LEAVE (SUCCEED);
-} /* end H5O_sim_dtype_debug() */
-
+}