summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Laird <jlaird@hdfgroup.org>2006-01-02 19:20:19 (GMT)
committerJames Laird <jlaird@hdfgroup.org>2006-01-02 19:20:19 (GMT)
commit216a6e99047f32a8cdf857f6cf3b195d605549a1 (patch)
tree8f48cea87963afad81a38fd70edb45238848299e
parent63e522aa138db60749a97f0d6896934b8a6d338c (diff)
downloadhdf5-216a6e99047f32a8cdf857f6cf3b195d605549a1.zip
hdf5-216a6e99047f32a8cdf857f6cf3b195d605549a1.tar.gz
hdf5-216a6e99047f32a8cdf857f6cf3b195d605549a1.tar.bz2
[svn-r11850] Purpose:
Feature Description: Added character encoding and attribute creation property lists. Solution: Attributes' character encoding is set via the ACPL. The default is ASCII, with UTF-8 being the other option currently. Platforms tested: heping, mir, sleipnir, copper
-rw-r--r--src/H5A.c131
-rw-r--r--src/H5Apkg.h1
-rw-r--r--src/H5Aprivate.h5
-rw-r--r--src/H5Apublic.h1
-rw-r--r--src/H5Fprivate.h4
-rw-r--r--src/H5Oattr.c76
-rw-r--r--src/H5P.c13
-rw-r--r--src/H5Ppublic.h7
-rwxr-xr-xsrc/Makefile.am5
-rw-r--r--src/Makefile.in24
-rw-r--r--test/tattr.c118
11 files changed, 339 insertions, 46 deletions
diff --git a/src/H5A.c b/src/H5A.c
index e26e48b..e0a9681 100644
--- a/src/H5A.c
+++ b/src/H5A.c
@@ -29,7 +29,7 @@
/* PRIVATE PROTOTYPES */
static hid_t H5A_create(const H5G_loc_t *loc, const char *name,
- const H5T_t *type, const H5S_t *space, hid_t dxpl_id);
+ const H5T_t *type, const H5S_t *space, hid_t acpl_id, hid_t dxpl_id);
static hid_t H5A_open(H5G_loc_t *loc, unsigned idx, hid_t dxpl_id);
static herr_t H5A_write(H5A_t *attr, const H5T_t *mem_type, const void *buf, hid_t dxpl_id);
static herr_t H5A_read(const H5A_t *attr, const H5T_t *mem_type, void *buf, hid_t dxpl_id);
@@ -70,16 +70,45 @@ DESCRIPTION
static herr_t
H5A_init_interface(void)
{
+ H5P_genclass_t *crt_pclass;
+ size_t nprops; /* Number of properties */
+ H5T_cset_t default_cset = H5A_CHAR_ENCODING_DEF;
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT(H5A_init_interface)
/*
- * Create attribute group.
+ * Create attribute ID type.
*/
if(H5I_register_type(H5I_ATTR, (size_t)H5I_ATTRID_HASHSIZE, H5A_RESERVED_ATOMS, (H5I_free_t)H5A_close) < H5I_FILE)
HGOTO_ERROR(H5E_INTERNAL, H5E_CANTINIT, FAIL, "unable to initialize interface")
+ /* =========Attribute Creation Property Class Initialization========= */
+ /* Register the default attribute creation properties */
+ assert(H5P_CLS_ATTRIBUTE_CREATE_g!=(-1));
+
+ /* Get the pointer to the attribute creation class */
+ if (NULL == (crt_pclass = H5I_object(H5P_CLS_ATTRIBUTE_CREATE_g)))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a property list class")
+
+ /* Get the number of properties in the class */
+ if(H5P_get_nprops_pclass(crt_pclass,&nprops,FALSE)<0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "can't query number of properties")
+
+ /* Assume that if there are properties in the class, they are the default ones */
+ if(nprops==0) {
+ /* Register the size of the character encoding field */
+ if(H5P_register(crt_pclass,H5A_CHAR_ENCODING_NAME,H5A_CHAR_ENCODING_SIZE,&default_cset,NULL,NULL,NULL,NULL,NULL,NULL,NULL)<0)
+ HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class")
+ }
+
+ /* Only register the default property list if it hasn't been created yet */
+ if(H5P_LST_ATTRIBUTE_CREATE_g==(-1)) {
+ /* Register the default attribute creation property list */
+ if ((H5P_LST_ATTRIBUTE_CREATE_g = H5P_create_id (crt_pclass))<0)
+ HGOTO_ERROR (H5E_PLIST, H5E_CANTREGISTER, FAIL, "can't register default property list")
+ } /* end if */
+
done:
FUNC_LEAVE_NOAPI(ret_value)
}
@@ -157,7 +186,7 @@ H5A_term_interface(void)
/* ARGSUSED */
hid_t
H5Acreate(hid_t loc_id, const char *name, hid_t type_id, hid_t space_id,
- hid_t UNUSED plist_id)
+ hid_t plist_id)
{
H5G_loc_t loc; /* Object location */
H5T_t *type = NULL;
@@ -180,8 +209,8 @@ H5Acreate(hid_t loc_id, const char *name, hid_t type_id, hid_t space_id,
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space")
/* Go do the real work for attaching the attribute to the dataset */
- if((ret_value = H5A_create(&loc, name, type, space, H5AC_dxpl_id)) < 0)
- HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, FAIL, "unable to create attribute")
+ if ((ret_value=H5A_create(&loc, name, type, space, plist_id, H5AC_dxpl_id)) < 0)
+ HGOTO_ERROR (H5E_ATTR, H5E_CANTINIT, FAIL, "unable to create attribute")
done:
FUNC_LEAVE_API(ret_value)
@@ -199,21 +228,31 @@ done:
* const char *name; IN: Name of attribute
* H5T_t *type; IN: Datatype of attribute
* H5S_t *space; IN: Dataspace of attribute
+ * hid_t acpl_id IN: Attribute creation property list
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* April 2, 1998
*
+ * Modifications:
+ *
+ * Pedro Vicente, <pvn@ncsa.uiuc.edu> 22 Aug 2002
+ * Added a deep copy of the symbol table entry
+ *
+ * James Laird, <jlaird@ncsa.uiuc.edu> 9 Nov 2005
+ * Added Attribute Creation Property List
+ *
*-------------------------------------------------------------------------
*/
static hid_t
H5A_create(const H5G_loc_t *loc, const char *name, const H5T_t *type,
- const H5S_t *space, hid_t dxpl_id)
+ const H5S_t *space, hid_t acpl_id, hid_t dxpl_id)
{
- H5A_t *attr = NULL;
- H5A_iter_cb1 cb; /* Iterator callback */
- hid_t ret_value = FAIL;
+ H5A_t *attr = NULL;
+ H5A_iter_cb1 cb; /* Iterator callback */
+ H5P_genplist_t *ac_plist=NULL; /* New Property list */
+ hid_t ret_value = FAIL;
FUNC_ENTER_NOAPI_NOINIT(H5A_create)
@@ -239,6 +278,21 @@ H5A_create(const H5G_loc_t *loc, const char *name, const H5T_t *type,
if((attr = H5FL_CALLOC(H5A_t)) == NULL)
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for attribute info")
+ /* If the creation property list is H5P_DEFAULT, use the default character encoding */
+ if(acpl_id == H5P_DEFAULT)
+ {
+ attr->encoding = H5A_CHAR_ENCODING_DEF;
+ }
+ else
+ {
+ /* Get a local copy of the attribute creation property list */
+ if (NULL == (ac_plist = H5I_object(acpl_id)))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a property list")
+
+ if(H5P_get(ac_plist, H5A_CHAR_ENCODING_NAME, &(attr->encoding)) < 0)
+ HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get character encoding flag")
+ }
+
/* Copy the attribute name */
attr->name = HDstrdup(name);
@@ -513,7 +567,7 @@ static hid_t
H5A_open(H5G_loc_t *loc, unsigned idx, hid_t dxpl_id)
{
H5A_t *attr = NULL;
- hid_t ret_value;
+ hid_t ret_value;
FUNC_ENTER_NOAPI_NOINIT(H5A_open)
@@ -969,6 +1023,61 @@ done:
/*--------------------------------------------------------------------------
NAME
+ H5Aget_create_plist
+ PURPOSE
+ Gets a copy of the creation property list for an attribute
+ USAGE
+ hssize_t H5Aget_create_plist (attr_id, buf_size, buf)
+ hid_t attr_id; IN: Attribute to get name of
+ RETURNS
+ This function returns the ID of a copy of the attribute's creation
+ property list, or negative on failure.
+
+ ERRORS
+
+ DESCRIPTION
+ This function returns a copy of the creation property list for
+ an attribute. The resulting ID must be closed with H5Pclose() or
+ resource leaks will occur.
+--------------------------------------------------------------------------*/
+hid_t
+H5Aget_create_plist(hid_t attr_id)
+{
+ H5A_t *attr = NULL;
+ H5P_genplist_t *plist; /* Default property list */
+ hid_t new_plist_id; /* ID of ACPL to return */
+ H5P_genplist_t *new_plist; /* ACPL to return */
+ hid_t ret_value;
+
+ FUNC_ENTER_API(H5Aget_create_plist, FAIL)
+ H5TRACE1("i","i",attr_id);
+
+ assert(H5P_LST_ATTRIBUTE_CREATE_g != -1);
+
+ /* Get attribute and default attribute creation property list*/
+ if (NULL==(attr=H5I_object_verify(attr_id, H5I_ATTR)))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an attribute")
+ if (NULL==(plist=H5I_object(H5P_LST_ATTRIBUTE_CREATE_g)))
+ HGOTO_ERROR(H5E_PLIST, H5E_BADTYPE, FAIL, "can't get default ACPL")
+
+ /* Create the property list object to return */
+ if((new_plist_id=H5P_copy_plist(plist)) < 0)
+ HGOTO_ERROR(H5E_PLIST, H5E_CANTINIT, FAIL, "unable to copy attribute creation properties")
+ if (NULL == (new_plist = H5I_object(new_plist_id)))
+ HGOTO_ERROR(H5E_PLIST, H5E_BADTYPE, FAIL, "can't get property list")
+
+ /* Set the character encoding on the new property list */
+ if(H5P_set(new_plist, H5A_CHAR_ENCODING_NAME, &(attr->encoding)) < 0)
+ HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set character encoding")
+
+ ret_value = new_plist_id;
+
+done:
+ FUNC_LEAVE_API(ret_value)
+}
+
+/*--------------------------------------------------------------------------
+ NAME
H5Aget_name
PURPOSE
Gets a copy of the name for an attribute
@@ -1587,7 +1696,7 @@ H5A_close(H5A_t *attr)
/* Free temporary buffer */
H5FL_BLK_FREE(attr_buf, tmp_buf);
} /* end if */
-
+
/* Free dynamicly allocated items */
if(H5A_free(attr) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTRELEASE, FAIL, "can't release attribute info")
diff --git a/src/H5Apkg.h b/src/H5Apkg.h
index cfe22ea..cd54ac4 100644
--- a/src/H5Apkg.h
+++ b/src/H5Apkg.h
@@ -55,6 +55,7 @@ struct H5A_t {
size_t ds_size; /* Size of dataspace on disk */
void *data; /* Attribute data (on a temporary basis) */
size_t data_size; /* Size of data on disk */
+ H5T_cset_t encoding; /* Character encoding of attribute */
};
/* Declare extern the free list for H5A_t's */
diff --git a/src/H5Aprivate.h b/src/H5Aprivate.h
index 9b24490..7adbbe1 100644
--- a/src/H5Aprivate.h
+++ b/src/H5Aprivate.h
@@ -27,6 +27,11 @@
/* Forward references of package typedefs */
typedef struct H5A_t H5A_t;
+/* Attribute creation properties */
+#define H5A_CHAR_ENCODING_NAME "character_encoding"
+#define H5A_CHAR_ENCODING_SIZE sizeof(H5T_cset_t)
+#define H5A_CHAR_ENCODING_DEF H5F_CRT_DEFAULT_CSET
+
/* Library private functions in package */
H5_DLL struct H5O_loc_t *H5A_oloc(H5A_t *attr);
H5_DLL H5G_name_t *H5A_nameof(H5A_t *attr);
diff --git a/src/H5Apublic.h b/src/H5Apublic.h
index c7478d8..ec9904a 100644
--- a/src/H5Apublic.h
+++ b/src/H5Apublic.h
@@ -38,6 +38,7 @@ H5_DLL herr_t H5Aread(hid_t attr_id, hid_t type_id, void *buf);
H5_DLL herr_t H5Aclose(hid_t attr_id);
H5_DLL hid_t H5Aget_space(hid_t attr_id);
H5_DLL hid_t H5Aget_type(hid_t attr_id);
+H5_DLL hid_t H5Aget_create_plist(hid_t attr_id);
H5_DLL ssize_t H5Aget_name(hid_t attr_id, size_t buf_size, char *buf);
H5_DLL hsize_t H5Aget_storage_size(hid_t attr_id);
H5_DLL int H5Aget_num_attrs(hid_t loc_id);
diff --git a/src/H5Fprivate.h b/src/H5Fprivate.h
index 2359cb9..8b45ef4 100644
--- a/src/H5Fprivate.h
+++ b/src/H5Fprivate.h
@@ -323,6 +323,10 @@ typedef struct H5F_t H5F_t;
#define H5F_CRT_SHARE_HEAD_VERS_SIZE sizeof(unsigned)
#define H5F_CRT_SHARE_HEAD_VERS_DEF HDF5_SHAREDHEADER_VERSION
+/* File-wide default character encoding can not yet be set via the file
+ * creation property list and is always ASCII. */
+#define H5F_CRT_DEFAULT_CSET H5T_CSET_ASCII
+
/* ========= File Access properties ============ */
/* Definitions for the initial metadata cache resize configuration */
#define H5F_ACS_META_CACHE_INIT_CONFIG_NAME "mdc_initCacheCfg"
diff --git a/src/H5Oattr.c b/src/H5Oattr.c
index 406c486..5d05a7c 100644
--- a/src/H5Oattr.c
+++ b/src/H5Oattr.c
@@ -62,10 +62,13 @@ const H5O_msg_class_t H5O_MSG_ATTR[1] = {{
}};
/* This is the initial version, which does not have support for shared datatypes */
-#define H5O_ATTR_VERSION 1
+#define H5O_ATTR_VERSION_1 1
/* This version allows support for shared datatypes */
-#define H5O_ATTR_VERSION_NEW 2
+#define H5O_ATTR_VERSION_2 2
+
+/* Add support for different character encodings of attribute names */
+#define H5O_ATTR_VERSION_3 3
/* Flags for attribute flag encoding */
#define H5O_ATTR_FLAG_TYPE_SHARED 0x01
@@ -104,6 +107,9 @@ H5FL_EXTERN(H5S_extent_t);
* Raymond Lu, 8 April 2004
* Changed Dataspace operation on H5S_simple_t to H5S_extent_t.
*
+ * James Laird, 15 November 2005
+ * Added character encoding (version 3)
+ *
--------------------------------------------------------------------------*/
static void *
H5O_attr_decode(H5F_t *f, hid_t dxpl_id, const uint8_t *p)
@@ -126,11 +132,11 @@ H5O_attr_decode(H5F_t *f, hid_t dxpl_id, const uint8_t *p)
/* Version number */
version = *p++;
- if (version!=H5O_ATTR_VERSION && version!=H5O_ATTR_VERSION_NEW)
+ if (version<H5O_ATTR_VERSION_1 || version>H5O_ATTR_VERSION_3)
HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, NULL, "bad version number for attribute message");
/* Get the flags byte if we have a later version of the attribute */
- if(version>H5O_ATTR_VERSION)
+ if(version>H5O_ATTR_VERSION_1)
flags = *p++;
else
p++; /* Byte is unused when version<2 */
@@ -143,10 +149,17 @@ H5O_attr_decode(H5F_t *f, hid_t dxpl_id, const uint8_t *p)
UINT16DECODE(p, attr->dt_size);
UINT16DECODE(p, attr->ds_size);
+ /*
+ * Decode the character encoding for the name for versions 3 or later,
+ * as well as some reserved bytes.
+ */
+ if(version >= H5O_ATTR_VERSION_3)
+ attr->encoding = *p++;
+
/* Decode and store the name */
if (NULL==(attr->name=H5MM_strdup((const char *)p)))
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
- if(version < H5O_ATTR_VERSION_NEW)
+ if(version < H5O_ATTR_VERSION_2)
p += H5O_ALIGN(name_len); /* advance the memory pointer */
else
p += name_len; /* advance the memory pointer */
@@ -170,7 +183,7 @@ H5O_attr_decode(H5F_t *f, hid_t dxpl_id, const uint8_t *p)
if((attr->dt=(H5O_MSG_DTYPE->decode)(f,dxpl_id,p))==NULL)
HGOTO_ERROR(H5E_ATTR, H5E_CANTDECODE, NULL, "can't decode attribute datatype");
} /* end else */
- if(version < H5O_ATTR_VERSION_NEW)
+ if(version < H5O_ATTR_VERSION_2)
p += H5O_ALIGN(attr->dt_size);
else
p += attr->dt_size;
@@ -192,7 +205,7 @@ H5O_attr_decode(H5F_t *f, hid_t dxpl_id, const uint8_t *p)
if(H5S_select_all(attr->ds,0)<0)
HGOTO_ERROR (H5E_DATASPACE, H5E_CANTSET, NULL, "unable to set all selection");
- if(version < H5O_ATTR_VERSION_NEW)
+ if(version < H5O_ATTR_VERSION_2)
p += H5O_ALIGN(attr->ds_size);
else
p += attr->ds_size;
@@ -245,6 +258,9 @@ done:
* For data space, changed the operation on H5S_simple_t to
* H5S_extent_t
*
+ * James Laird, 15 November 2005
+ * Added character encoding (version 3)
+ *
--------------------------------------------------------------------------*/
static herr_t
H5O_attr_encode(H5F_t *f, uint8_t *p, const void *mesg)
@@ -269,16 +285,18 @@ H5O_attr_encode(H5F_t *f, uint8_t *p, const void *mesg)
type_shared = FALSE;
/* Check which version to write out */
- if(type_shared)
- version = H5O_ATTR_VERSION_NEW; /* Write out new version if shared datatype */
+ if(attr->encoding != H5T_CSET_ASCII)
+ version = H5O_ATTR_VERSION_3; /* Write version which includes the character encoding */
+ else if(type_shared)
+ version = H5O_ATTR_VERSION_2; /* Write out version with shared datatype */
else
- version = H5O_ATTR_VERSION;
+ version = H5O_ATTR_VERSION_1; /* Write out basic version */
/* Encode Version */
*p++ = version;
/* Set attribute flags if version >1 */
- if(version>H5O_ATTR_VERSION)
+ if(version>H5O_ATTR_VERSION_1)
*p++ = (type_shared ? H5O_ATTR_FLAG_TYPE_SHARED : 0 ); /* Set flags for attribute */
else
*p++ = 0; /* Reserved, for version <2 */
@@ -294,12 +312,19 @@ H5O_attr_encode(H5F_t *f, uint8_t *p, const void *mesg)
UINT16ENCODE(p, attr->ds_size);
/*
+ * Encode the character encoding used for the attribute's name
+ * Also add several "reserved" fields to pad to 16 bytes.
+ */
+ if(version>=H5O_ATTR_VERSION_3)
+ *p++=attr->encoding;
+
+ /*
* Write the name including null terminator padded to the correct number
* of bytes.
*/
HDmemcpy(p, attr->name, name_len);
HDmemset(p+name_len, 0, H5O_ALIGN(name_len)-name_len);
- if(version < H5O_ATTR_VERSION_NEW)
+ if(version < H5O_ATTR_VERSION_2)
p += H5O_ALIGN(name_len);
else
p += name_len;
@@ -324,7 +349,7 @@ H5O_attr_encode(H5F_t *f, uint8_t *p, const void *mesg)
if((H5O_MSG_DTYPE->encode)(f,p,attr->dt)<0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTENCODE, FAIL, "can't encode attribute datatype");
} /* end else */
- if(version < H5O_ATTR_VERSION_NEW) {
+ if(version < H5O_ATTR_VERSION_2) {
HDmemset(p+attr->dt_size, 0, H5O_ALIGN(attr->dt_size)-attr->dt_size);
p += H5O_ALIGN(attr->dt_size);
} /* end if */
@@ -334,7 +359,7 @@ H5O_attr_encode(H5F_t *f, uint8_t *p, const void *mesg)
/* encode the attribute dataspace */
if((H5O_MSG_SDSPACE->encode)(f,p,&(attr->ds->extent))<0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTENCODE, FAIL, "can't encode attribute dataspace");
- if(version < H5O_ATTR_VERSION_NEW) {
+ if(version < H5O_ATTR_VERSION_2) {
HDmemset(p+attr->ds_size, 0, H5O_ALIGN(attr->ds_size)-attr->ds_size);
p += H5O_ALIGN(attr->ds_size);
} /* end if */
@@ -429,12 +454,14 @@ H5O_attr_size(const H5F_t UNUSED *f, const void *_mesg)
type_shared = FALSE;
/* Check which version to write out */
- if(type_shared)
- version = H5O_ATTR_VERSION_NEW; /* Write out new version if shared datatype */
+ if(attr->encoding != H5T_CSET_ASCII)
+ version = H5O_ATTR_VERSION_3; /* Write version which includes the character encoding */
+ else if(type_shared)
+ version = H5O_ATTR_VERSION_2; /* Write out version with shared datatype */
else
- version = H5O_ATTR_VERSION;
+ version = H5O_ATTR_VERSION_1; /* Write out basic version */
- if(version < H5O_ATTR_VERSION_NEW)
+ if(version == H5O_ATTR_VERSION_1)
ret_value = 1 + /*version */
1 + /*reserved */
2 + /*name size inc. null */
@@ -444,12 +471,23 @@ H5O_attr_size(const H5F_t UNUSED *f, const void *_mesg)
H5O_ALIGN(attr->dt_size) + /*data type */
H5O_ALIGN(attr->ds_size) + /*data space */
attr->data_size; /*the data itself */
- else
+ else if(version == H5O_ATTR_VERSION_2)
+ ret_value = 1 + /*version */
+ 1 + /*flags */
+ 2 + /*name size inc. null */
+ 2 + /*type size */
+ 2 + /*space size */
+ name_len + /*attribute name */
+ attr->dt_size + /*data type */
+ attr->ds_size + /*data space */
+ attr->data_size; /*the data itself */
+ else if(version == H5O_ATTR_VERSION_3)
ret_value = 1 + /*version */
1 + /*flags */
2 + /*name size inc. null */
2 + /*type size */
2 + /*space size */
+ 1 + /*character encoding */
name_len + /*attribute name */
attr->dt_size + /*data type */
attr->ds_size + /*data space */
diff --git a/src/H5P.c b/src/H5P.c
index 7ac272f..e31a23e 100644
--- a/src/H5P.c
+++ b/src/H5P.c
@@ -54,6 +54,7 @@ hid_t H5P_CLS_GROUP_CREATE_g = FAIL;
hid_t H5P_CLS_GROUP_ACCESS_g = FAIL;
hid_t H5P_CLS_DATATYPE_CREATE_g = FAIL;
hid_t H5P_CLS_DATATYPE_ACCESS_g = FAIL;
+hid_t H5P_CLS_ATTRIBUTE_CREATE_g = FAIL;
/*
* Predefined property lists for each predefined class. These are initialized
@@ -70,6 +71,7 @@ hid_t H5P_LST_GROUP_CREATE_g = FAIL;
hid_t H5P_LST_GROUP_ACCESS_g = FAIL;
hid_t H5P_LST_DATATYPE_CREATE_g = FAIL;
hid_t H5P_LST_DATATYPE_ACCESS_g = FAIL;
+hid_t H5P_LST_ATTRIBUTE_CREATE_g = FAIL;
/* Track the revision count of a class, to make comparisons faster */
static unsigned H5P_next_rev=0;
@@ -403,6 +405,15 @@ H5P_init_interface(void)
if ((H5P_CLS_DATATYPE_ACCESS_g = H5I_register (H5I_GENPROP_CLS, pclass))<0)
HGOTO_ERROR (H5E_PLIST, H5E_CANTREGISTER, FAIL, "can't register property list class");
+ /* Allocate the attribute creation class */
+ assert(H5P_CLS_ATTRIBUTE_CREATE_g==(-1));
+ if (NULL==(pclass = H5P_create_class (ocrt_class,"attribute create",1,NULL,NULL,NULL,NULL,NULL,NULL)))
+ HGOTO_ERROR (H5E_PLIST, H5E_CANTINIT, FAIL, "class initialization failed");
+
+ /* Register the attribute creation class */
+ if ((H5P_CLS_ATTRIBUTE_CREATE_g = H5I_register (H5I_GENPROP_CLS, pclass))<0)
+ HGOTO_ERROR (H5E_PLIST, H5E_CANTREGISTER, FAIL, "can't register property list class");
+
done:
FUNC_LEAVE_NOAPI(ret_value);
}
@@ -461,6 +472,7 @@ H5P_term_interface(void)
H5P_LST_GROUP_ACCESS_g =
H5P_LST_DATATYPE_CREATE_g =
H5P_LST_DATATYPE_ACCESS_g =
+ H5P_LST_ATTRIBUTE_CREATE_g =
H5P_LST_MOUNT_g = (-1);
} /* end if */
} /* end if */
@@ -482,6 +494,7 @@ H5P_term_interface(void)
H5P_CLS_GROUP_ACCESS_g =
H5P_CLS_DATATYPE_CREATE_g =
H5P_CLS_DATATYPE_ACCESS_g =
+ H5P_CLS_ATTRIBUTE_CREATE_g =
H5P_CLS_MOUNT_g = (-1);
} /* end if */
} /* end if */
diff --git a/src/H5Ppublic.h b/src/H5Ppublic.h
index a470dfd..bb8525b 100644
--- a/src/H5Ppublic.h
+++ b/src/H5Ppublic.h
@@ -92,6 +92,7 @@ typedef herr_t (*H5P_iterate_t)(hid_t id, const char *name, void *iter_data);
#define H5P_GROUP_ACCESS (H5OPEN H5P_CLS_GROUP_ACCESS_g)
#define H5P_DATATYPE_CREATE (H5OPEN H5P_CLS_DATATYPE_CREATE_g)
#define H5P_DATATYPE_ACCESS (H5OPEN H5P_CLS_DATATYPE_ACCESS_g)
+#define H5P_ATTRIBUTE_CREATE (H5OPEN H5P_CLS_ATTRIBUTE_CREATE_g)
H5_DLLVAR hid_t H5P_CLS_NO_CLASS_g;
H5_DLLVAR hid_t H5P_CLS_OBJECT_CREATE_g;
H5_DLLVAR hid_t H5P_CLS_FILE_CREATE_g;
@@ -104,6 +105,7 @@ H5_DLLVAR hid_t H5P_CLS_GROUP_CREATE_g;
H5_DLLVAR hid_t H5P_CLS_GROUP_ACCESS_g;
H5_DLLVAR hid_t H5P_CLS_DATATYPE_CREATE_g;
H5_DLLVAR hid_t H5P_CLS_DATATYPE_ACCESS_g;
+H5_DLLVAR hid_t H5P_CLS_ATTRIBUTE_CREATE_g;
/*
* The library created default property lists
@@ -123,6 +125,7 @@ H5_DLLVAR hid_t H5P_CLS_DATATYPE_ACCESS_g;
#define H5P_GROUP_ACCESS_DEFAULT (H5OPEN H5P_LST_GROUP_ACCESS_g)
#define H5P_DATATYPE_CREATE_DEFAULT (H5OPEN H5P_LST_DATATYPE_CREATE_g)
#define H5P_DATATYPE_ACCESS_DEFAULT (H5OPEN H5P_LST_DATATYPE_ACCESS_g)
+#define H5P_ATTRIBUTE_CREATE_DEFAULT (H5OPEN H5P_LST_ATTRIBUTE_CREATE_g)
H5_DLLVAR hid_t H5P_LST_NO_CLASS_g;
H5_DLLVAR hid_t H5P_LST_FILE_CREATE_g;
H5_DLLVAR hid_t H5P_LST_FILE_ACCESS_g;
@@ -134,6 +137,7 @@ H5_DLLVAR hid_t H5P_LST_GROUP_CREATE_g;
H5_DLLVAR hid_t H5P_LST_GROUP_ACCESS_g;
H5_DLLVAR hid_t H5P_LST_DATATYPE_CREATE_g;
H5_DLLVAR hid_t H5P_LST_DATATYPE_ACCESS_g;
+H5_DLLVAR hid_t H5P_LST_ATTRIBUTE_CREATE_g;
/* Public functions */
H5_DLL hid_t H5Pcreate_class(hid_t parent, const char *name,
@@ -339,6 +343,9 @@ H5_DLL herr_t H5Pget_link_phase_change(hid_t plist_id, unsigned *max_compact /*o
H5_DLL herr_t H5Pset_est_link_info(hid_t plist_id, unsigned est_num_entries, unsigned est_name_len);
H5_DLL herr_t H5Pget_est_link_info(hid_t plist_id, unsigned *est_num_entries /* out */, unsigned *est_name_len /* out */);
+H5_DLL herr_t H5Pset_char_encoding(hid_t plist_id, H5T_cset_t encoding);
+H5_DLL herr_t H5Pget_char_encoding(hid_t plist_id, H5T_cset_t *encoding /*out*/);
+
#ifdef __cplusplus
}
#endif
diff --git a/src/Makefile.am b/src/Makefile.am
index bd0108e..48e86c7 100755
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -64,9 +64,8 @@ libhdf5_la_SOURCES= H5.c H5A.c H5AC.c H5B.c H5Bcache.c H5B2.c H5B2cache.c \
H5Olink.c \
H5Omtime.c \
H5Oname.c H5Onull.c H5Opline.c H5Osdspace.c H5Oshared.c H5Ostab.c \
- H5P.c H5Pdcpl.c H5Pdxpl.c H5Pfapl.c H5Pfcpl.c H5Pgcpl.c H5Pocpl.c \
- H5Ptest.c \
- H5R.c H5RC.c \
+ H5P.c H5Pacpl.c H5Pdcpl.c H5Pdxpl.c H5Pfapl.c H5Pfcpl.c H5Pgcpl.c \
+ H5Pocpl.c H5Ptest.c H5R.c H5RC.c \
H5RS.c H5S.c H5Sall.c H5Shyper.c H5Smpio.c H5Snone.c H5Spoint.c \
H5Sselect.c H5Stest.c H5SH.c H5SHcache.c H5SHdbg.c \
H5SL.c H5ST.c H5T.c H5Tarray.c H5Tbit.c H5Tcommit.c \
diff --git a/src/Makefile.in b/src/Makefile.in
index 92c4fa3..b67881f 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -100,15 +100,15 @@ am_libhdf5_la_OBJECTS = H5.lo H5A.lo H5AC.lo H5B.lo H5Bcache.lo \
H5Ocont.lo H5Odtype.lo H5Oefl.lo H5Ofill.lo H5Oginfo.lo \
H5Olayout.lo H5Olinfo.lo H5Olink.lo H5Omtime.lo H5Oname.lo \
H5Onull.lo H5Opline.lo H5Osdspace.lo H5Oshared.lo H5Ostab.lo \
- H5P.lo H5Pdcpl.lo H5Pdxpl.lo H5Pfapl.lo H5Pfcpl.lo H5Pgcpl.lo \
- H5Pocpl.lo H5Ptest.lo H5R.lo H5RC.lo H5RS.lo H5S.lo H5Sall.lo \
- H5Shyper.lo H5Smpio.lo H5Snone.lo H5Spoint.lo H5Sselect.lo \
- H5Stest.lo H5SH.lo H5SHcache.lo H5SHdbg.lo H5SL.lo H5ST.lo \
- H5T.lo H5Tarray.lo H5Tbit.lo H5Tcommit.lo H5Tcompound.lo \
- H5Tconv.lo H5Tcset.lo H5Tenum.lo H5Tfields.lo H5Tfixed.lo \
- H5Tfloat.lo H5Tinit.lo H5Tnative.lo H5Toffset.lo H5Toh.lo \
- H5Topaque.lo H5Torder.lo H5Tpad.lo H5Tprecis.lo H5Tstrpad.lo \
- H5Tvlen.lo H5TS.lo H5V.lo H5Z.lo H5Zdeflate.lo \
+ H5P.lo H5Pacpl.lo H5Pdcpl.lo H5Pdxpl.lo H5Pfapl.lo H5Pfcpl.lo \
+ H5Pgcpl.lo H5Pocpl.lo H5Ptest.lo H5R.lo H5RC.lo H5RS.lo H5S.lo \
+ H5Sall.lo H5Shyper.lo H5Smpio.lo H5Snone.lo H5Spoint.lo \
+ H5Sselect.lo H5Stest.lo H5SH.lo H5SHcache.lo H5SHdbg.lo \
+ H5SL.lo H5ST.lo H5T.lo H5Tarray.lo H5Tbit.lo H5Tcommit.lo \
+ H5Tcompound.lo H5Tconv.lo H5Tcset.lo H5Tenum.lo H5Tfields.lo \
+ H5Tfixed.lo H5Tfloat.lo H5Tinit.lo H5Tnative.lo H5Toffset.lo \
+ H5Toh.lo H5Topaque.lo H5Torder.lo H5Tpad.lo H5Tprecis.lo \
+ H5Tstrpad.lo H5Tvlen.lo H5TS.lo H5V.lo H5Z.lo H5Zdeflate.lo \
H5Zfletcher32.lo H5Znbit.lo H5Zshuffle.lo H5Zszip.lo \
H5Zscaleoffset.lo H5Ztrans.lo
libhdf5_la_OBJECTS = $(am_libhdf5_la_OBJECTS)
@@ -418,9 +418,8 @@ libhdf5_la_SOURCES = H5.c H5A.c H5AC.c H5B.c H5Bcache.c H5B2.c H5B2cache.c \
H5Olink.c \
H5Omtime.c \
H5Oname.c H5Onull.c H5Opline.c H5Osdspace.c H5Oshared.c H5Ostab.c \
- H5P.c H5Pdcpl.c H5Pdxpl.c H5Pfapl.c H5Pfcpl.c H5Pgcpl.c H5Pocpl.c \
- H5Ptest.c \
- H5R.c H5RC.c \
+ H5P.c H5Pacpl.c H5Pdcpl.c H5Pdxpl.c H5Pfapl.c H5Pfcpl.c H5Pgcpl.c \
+ H5Pocpl.c H5Ptest.c H5R.c H5RC.c \
H5RS.c H5S.c H5Sall.c H5Shyper.c H5Smpio.c H5Snone.c H5Spoint.c \
H5Sselect.c H5Stest.c H5SH.c H5SHcache.c H5SHdbg.c \
H5SL.c H5ST.c H5T.c H5Tarray.c H5Tbit.c H5Tcommit.c \
@@ -657,6 +656,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Oshared.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Ostab.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5P.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Pacpl.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Pdcpl.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Pdxpl.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Pfapl.Plo@am__quote@
diff --git a/test/tattr.c b/test/tattr.c
index dc82190..2363401 100644
--- a/test/tattr.c
+++ b/test/tattr.c
@@ -457,7 +457,120 @@ test_attr_flush(void)
CHECK(ret, FAIL, "H5Dclose");
ret=H5Fclose(fil);
CHECK(ret, FAIL, "H5Fclose");
-} /* test_attr_basic_flush() */
+} /* test_attr_flush() */
+
+/****************************************************************
+**
+** test_attr_plist(): Test Attribute Creation Property Lists
+**
+****************************************************************/
+static void
+test_attr_plist(void)
+{
+ hid_t fid1; /* HDF5 File IDs */
+ hid_t dataset; /* Dataset ID */
+ hid_t sid1,sid2; /* Dataspace ID */
+ hid_t attr; /* Attribute ID */
+ hid_t plist; /* Property list ID */
+ char *attr_name=NULL; /* name of attribute */
+ hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3};
+ hsize_t dims2[] = {ATTR1_DIM1};
+ H5T_cset_t cset; /* Character set for attributes */
+ herr_t ret; /* Generic return value */
+
+ /* Output message about test being performed */
+ MESSAGE(5, ("Testing Attribute Property Lists\n"));
+
+ /* Create file */
+ fid1 = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ CHECK(fid1, FAIL, "H5Fcreate");
+
+ /* Create dataspace for dataset */
+ sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL);
+ CHECK(sid1, FAIL, "H5Screate_simple");
+
+ /* Create a dataset */
+ dataset=H5Dcreate(fid1,DSET1_NAME,H5T_NATIVE_UCHAR,sid1,H5P_DEFAULT);
+ CHECK(dataset, FAIL, "H5Dcreate");
+
+ /* Create dataspace for attribute */
+ sid2 = H5Screate_simple(ATTR1_RANK, dims2, NULL);
+ CHECK(sid2, FAIL, "H5Screate_simple");
+
+ /* Create default property list for attribute */
+ plist = H5Pcreate(H5P_ATTRIBUTE_CREATE);
+ CHECK(plist, FAIL, "H5Pcreate");
+
+ /* Get the character encoding and ensure that it is the default (ASCII) */
+ ret = H5Pget_char_encoding(plist, &cset);
+ CHECK(ret, FAIL, "H5Pget_char_encoding");
+ VERIFY(cset, H5T_CSET_ASCII, "H5Pget_char_encoding");
+
+ /* Create an attribute for the dataset using the property list */
+ attr=H5Acreate(dataset,ATTR1_NAME,H5T_NATIVE_INT,sid2,plist);
+ CHECK(attr, FAIL, "H5Acreate");
+
+ /* Close the property list, and get the attribute's property list */
+ ret = H5Pclose(plist);
+ CHECK(ret, FAIL, "H5Pclose");
+ plist = H5Aget_create_plist(attr);
+ CHECK(plist, FAIL, "H5Aget_create_plist");
+
+ /* Get the character encoding and ensure that it is the default (ASCII) */
+ ret = H5Pget_char_encoding(plist, &cset);
+ CHECK(ret, FAIL, "H5Pget_char_encoding");
+ VERIFY(cset, H5T_CSET_ASCII, "H5Pget_char_encoding");
+
+ /* Close the property list and attribute */
+ ret = H5Pclose(plist);
+ CHECK(ret, FAIL, "H5Pclose");
+ ret = H5Aclose(attr);
+ CHECK(ret, FAIL, "H5Aclose");
+
+ /* Create a new property list and modify it to use a different encoding */
+ plist = H5Pcreate(H5P_ATTRIBUTE_CREATE);
+ CHECK(plist, FAIL, "H5Pcreate");
+ ret=H5Pset_char_encoding(plist, H5T_CSET_UTF8);
+ CHECK(ret, FAIL, "H5Pset_char_encoding");
+
+ /* Get the character encoding and ensure that it has been changed */
+ ret = H5Pget_char_encoding(plist, &cset);
+ CHECK(ret, FAIL, "H5Pget_char_encoding");
+ VERIFY(cset, H5T_CSET_UTF8, "H5Pget_char_encoding");
+
+ /* Create an attribute for the dataset using the modified property list */
+ attr=H5Acreate(dataset,ATTR2_NAME,H5T_NATIVE_INT,sid2,plist);
+ CHECK(attr, FAIL, "H5Acreate");
+
+ /* Close the property list and attribute */
+ ret = H5Pclose(plist);
+ CHECK(ret, FAIL, "H5Pclose");
+ ret = H5Aclose(attr);
+ CHECK(ret, FAIL, "H5Aclose");
+
+ /* Re-open the second attribute and ensure that its character encoding is correct */
+ attr = H5Aopen_name(dataset, ATTR2_NAME);
+ CHECK(attr, FAIL, "H5Aopen_name");
+ plist = H5Aget_create_plist(attr);
+ CHECK(plist, FAIL, "H5Aget_create_plist");
+ ret = H5Pget_char_encoding(plist, &cset);
+ CHECK(ret, FAIL, "H5Pget_char_encoding");
+ VERIFY(cset, H5T_CSET_UTF8, "H5Pget_char_encoding");
+
+ /* Close everything */
+ ret=H5Sclose(sid1);
+ CHECK(ret, FAIL, "H5Sclose");
+ ret=H5Sclose(sid2);
+ CHECK(ret, FAIL, "H5Sclose");
+ ret = H5Pclose(plist);
+ CHECK(ret, FAIL, "H5Pclose");
+ ret=H5Aclose(attr);
+ CHECK(ret, FAIL, "H5Aclose");
+ ret=H5Dclose(dataset);
+ CHECK(ret, FAIL, "H5Dclose");
+ ret=H5Fclose(fid1);
+ CHECK(ret, FAIL, "H5Fclose");
+} /* test_attr_plist() */
/****************************************************************
**
@@ -1571,6 +1684,9 @@ test_attr(void)
test_attr_basic_read(); /* Test basic H5A reading code */
test_attr_flush(); /* Test H5A I/O in the presence of H5Fflush calls */
+ /* This next test uses the same file information */
+ test_attr_plist(); /* Test attribute property lists */
+
/* These next two tests use the same file information */
test_attr_compound_write(); /* Test complex datatype H5A writing code */
test_attr_compound_read(); /* Test complex datatype H5A reading code */