summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--hl/src/H5DS.c86
-rw-r--r--hl/src/H5DS.h11
-rw-r--r--hl/src/H5IM.c14
-rw-r--r--hl/src/H5IM.h3
-rw-r--r--hl/src/H5LT.c4
-rw-r--r--hl/src/H5TB.c4
-rw-r--r--hl/src/H5TB.h4
-rw-r--r--hl/test/test_ds.c164
8 files changed, 278 insertions, 12 deletions
diff --git a/hl/src/H5DS.c b/hl/src/H5DS.c
index 214769c..552de73 100644
--- a/hl/src/H5DS.c
+++ b/hl/src/H5DS.c
@@ -14,6 +14,10 @@
#include "H5DS.h"
#include "H5LT.h"
#include <stdlib.h>
+#include "H5IM.h"
+#include "H5TB.h"
+
+
/*-------------------------------------------------------------------------
* Function: H5DSset_scale
@@ -156,6 +160,15 @@ herr_t H5DSattach_scale(hid_t did,
if (H5I_DATASET!=it1 || H5I_DATASET!=it2)
return FAIL;
+ /* the DS dataset cannot have dimension scales */
+ if (H5LT_find_attribute(dsid,DIMENSION_LIST)==1)
+ return FAIL;
+
+ /* check if the dataset is a "reserved" dataset (image, table) */
+ if (H5DS_is_reserved(did)==1)
+ return FAIL;
+
+
/*-------------------------------------------------------------------------
* The dataset may or may not have the associated DS attribute
* First we try to open to see if it is already there; if not, it is created.
@@ -1959,3 +1972,76 @@ out:
+/*-------------------------------------------------------------------------
+ * Function: H5DS_is_reserved
+ *
+ * Purpose: Verify that a dataset's CLASS is either an image, palette or table
+ *
+ * Return: true, false, fail
+ *
+ * Programmer: pvn@ncsa.uiuc.edu
+ *
+ * Date: March 19, 2005
+ *
+ * Comments:
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+
+herr_t H5DS_is_reserved(hid_t did)
+{
+ int has_class;
+ hid_t tid;
+ hid_t aid;
+ char buf[40];
+ herr_t ret;
+
+ /* try to find the attribute "CLASS" on the dataset */
+ if ((has_class = H5LT_find_attribute(did,"CLASS"))<0)
+ return -1;
+
+ if ( has_class == 0 )
+ return 0;
+
+ else if ( has_class == 1 )
+ {
+ if ((aid = H5Aopen_name(did,"CLASS"))<0)
+ goto out;
+
+ if ((tid = H5Aget_type(aid))<0)
+ goto out;
+
+ if (H5Aread(aid,tid,buf)<0)
+ goto out;
+
+ if ( strcmp(buf,IMAGE_CLASS)==0 ||
+ strcmp(buf,PALETTE_CLASS)==0 ||
+ strcmp(buf,TABLE_CLASS)==0 )
+ ret = 1;
+ else
+ ret = 0;
+
+ if (H5Tclose(tid)<0)
+ goto out;
+
+ if (H5Aclose(aid)<0)
+ goto out;
+
+ }
+
+ return ret;
+
+/* error zone, gracefully close */
+out:
+ H5E_BEGIN_TRY {
+ H5Tclose(tid);
+ H5Aclose(aid);
+ } H5E_END_TRY;
+ return FAIL;
+}
+
+
+
+
diff --git a/hl/src/H5DS.h b/hl/src/H5DS.h
index 48e2365..2aba941 100644
--- a/hl/src/H5DS.h
+++ b/hl/src/H5DS.h
@@ -80,6 +80,17 @@ htri_t H5DSis_attached(hid_t did,
unsigned int idx);
+
+/*-------------------------------------------------------------------------
+ * private functions
+ *-------------------------------------------------------------------------
+ */
+
+
+herr_t H5DS_is_reserved(hid_t did);
+
+
+
#ifdef __cplusplus
}
#endif
diff --git a/hl/src/H5IM.c b/hl/src/H5IM.c
index d1633f0..2492562 100644
--- a/hl/src/H5IM.c
+++ b/hl/src/H5IM.c
@@ -55,7 +55,7 @@ herr_t H5IMmake_image_8bit( hid_t loc_id,
return -1;
/* Attach the CLASS attribute */
- if ( H5LTset_attribute_string( loc_id, dset_name, "CLASS", "IMAGE" ) < 0 )
+ if ( H5LTset_attribute_string( loc_id, dset_name, "CLASS", IMAGE_CLASS ) < 0 )
return -1;
/* Attach the VERSION attribute */
@@ -130,7 +130,7 @@ herr_t H5IMmake_image_24bit( hid_t loc_id,
return -1;
/* Attach the CLASS attribute */
- if ( H5LTset_attribute_string( loc_id, dset_name, "CLASS", "IMAGE" ) < 0 )
+ if ( H5LTset_attribute_string( loc_id, dset_name, "CLASS", IMAGE_CLASS ) < 0 )
return -1;
/* Attach the VERSION attribute */
@@ -484,7 +484,7 @@ herr_t H5IMmake_palette( hid_t loc_id,
return -1;
/* Attach the attribute "CLASS" to the >>palette<< dataset*/
- if ( H5LTset_attribute_string( loc_id, pal_name, "CLASS", "PALETTE" ) < 0 )
+ if ( H5LTset_attribute_string( loc_id, pal_name, "CLASS", PALETTE_CLASS ) < 0 )
return -1;
/* Attach the attribute "PAL_VERSION" to the >>palette<< dataset*/
@@ -1152,7 +1152,7 @@ herr_t H5IMis_image( hid_t loc_id,
if ( H5Aread( attr_id, attr_type, attr_data ) < 0 )
goto out;
- if( strcmp( attr_data, "IMAGE" ) == 0 )
+ if( strcmp( attr_data, IMAGE_CLASS ) == 0 )
ret = 1;
else
ret = 0;
@@ -1216,7 +1216,7 @@ herr_t H5IMis_palette( hid_t loc_id,
if ( (did = H5Dopen( loc_id, dset_name )) < 0 )
return -1;
- /* Try to find the attribute "CLASS" on the dataset */
+ /* Try to find the attribute "CLASS" on the dataset */
has_class = H5LT_find_attribute( did, "CLASS" );
if ( has_class == 0 )
@@ -1240,7 +1240,7 @@ herr_t H5IMis_palette( hid_t loc_id,
if ( H5Aread( attr_id, attr_type, attr_data ) < 0 )
goto out;
- if( strcmp( attr_data, "PALETTE" ) == 0 )
+ if( strcmp( attr_data, PALETTE_CLASS ) == 0 )
ret = 1;
else
ret = 0;
@@ -1253,7 +1253,7 @@ herr_t H5IMis_palette( hid_t loc_id,
}
- /* Close the dataset. */
+ /* Close the dataset. */
if ( H5Dclose( did ) < 0 )
return -1;
diff --git a/hl/src/H5IM.h b/hl/src/H5IM.h
index db79222..608028f 100644
--- a/hl/src/H5IM.h
+++ b/hl/src/H5IM.h
@@ -21,6 +21,9 @@
extern "C" {
#endif
+#define IMAGE_CLASS "IMAGE"
+#define PALETTE_CLASS "PALETTE"
+
herr_t H5IMmake_image_8bit( hid_t loc_id,
diff --git a/hl/src/H5LT.c b/hl/src/H5LT.c
index a076058..daa420c 100644
--- a/hl/src/H5LT.c
+++ b/hl/src/H5LT.c
@@ -2691,8 +2691,8 @@ herr_t H5LT_get_attribute_disk( hid_t loc_id,
void *attr_out )
{
/* identifiers */
- hid_t attr_id;
- hid_t attr_type;
+ hid_t attr_id;
+ hid_t attr_type;
if ( ( attr_id = H5Aopen_name( loc_id, attr_name ) ) < 0 )
return -1;
diff --git a/hl/src/H5TB.c b/hl/src/H5TB.c
index 84f626e..d006176 100644
--- a/hl/src/H5TB.c
+++ b/hl/src/H5TB.c
@@ -170,7 +170,7 @@ herr_t H5TBmake_table( const char *table_title,
*/
/* Attach the CLASS attribute */
- if ( H5LTset_attribute_string( loc_id, dset_name, "CLASS", "TABLE" ) < 0 )
+ if ( H5LTset_attribute_string( loc_id, dset_name, "CLASS", TABLE_CLASS ) < 0 )
goto out;
/* Attach the VERSION attribute */
@@ -3512,7 +3512,7 @@ herr_t H5TB_attach_attributes( const char *table_title,
hsize_t i;
/* Attach the CLASS attribute */
- if ( H5LTset_attribute_string( loc_id, dset_name, "CLASS", "TABLE" ) < 0 )
+ if ( H5LTset_attribute_string( loc_id, dset_name, "CLASS", TABLE_CLASS ) < 0 )
goto out;
/* Attach the VERSION attribute */
diff --git a/hl/src/H5TB.h b/hl/src/H5TB.h
index 0b75228..5ce10f3 100644
--- a/hl/src/H5TB.h
+++ b/hl/src/H5TB.h
@@ -21,6 +21,10 @@
#include "H5LT.h"
+
+#define TABLE_CLASS "TABLE"
+
+
#define HLTB_MAX_FIELD_LEN 255
#if !defined(MAX)
diff --git a/hl/test/test_ds.c b/hl/test/test_ds.c
index 83ab7f7..c6d9b34 100644
--- a/hl/test/test_ds.c
+++ b/hl/test/test_ds.c
@@ -17,6 +17,8 @@
#include "H5LT.h"
#include <stdlib.h>
#include <string.h>
+#include "H5IM.h"
+
/* operator functions */
static herr_t verifiy_scale(hid_t dset, unsigned dim, hid_t scale, void *visitor_data);
@@ -1630,6 +1632,7 @@ static int test_errors(void)
hid_t gid; /* group ID */
hid_t sid; /* space ID */
hid_t sidds; /* space ID */
+ hsize_t pal_dims[] = {9,3};
printf("Testing error conditions\n");
@@ -1720,6 +1723,118 @@ static int test_errors(void)
goto out;
+/*-------------------------------------------------------------------------
+ * try to attach a scale that has scales
+ *-------------------------------------------------------------------------
+ */
+
+ TESTING2("attach a scale that has scales");
+
+ /* create the data space for the scale */
+ if ((sidds=H5Screate_simple(rankds,s1_dim,NULL))<0)
+ goto out;
+
+ /* create a dataset "ds_b" for the scale */
+ if ((dsid=H5Dcreate(fid,"ds_b",H5T_NATIVE_INT,sidds,H5P_DEFAULT))<0)
+ goto out;
+
+ /* open the previous written "ds_a" */
+ if ((did = H5Dopen(fid,"ds_a"))<0)
+ goto out;
+
+ /* attach "ds_b" to "ds_a", valid */
+ if(H5DSattach_scale(did,dsid,0)<0)
+ goto out;
+
+ /* close */
+ if (H5Dclose(dsid)<0)
+ goto out;
+ if (H5Dclose(did)<0)
+ goto out;
+ if (H5Sclose(sidds)<0)
+ goto out;
+
+ /* open the previous written "dset_a" */
+ if ((did = H5Dopen(fid,"dset_a"))<0)
+ goto out;
+
+ /* open the previous written "ds_a" */
+ if ((dsid = H5Dopen(fid,"ds_a"))<0)
+ goto out;
+
+ /* try to attach "ds_a" to "dset_a", not valid */
+ if(H5DSattach_scale(did,dsid,0)==SUCCESS)
+ goto out;
+
+ /* close */
+ if (H5Dclose(dsid)<0)
+ goto out;
+ if (H5Dclose(did)<0)
+ goto out;
+
+ PASSED();
+
+/*-------------------------------------------------------------------------
+ * try to attach a dataset that is a scale
+ *-------------------------------------------------------------------------
+ */
+
+ TESTING2("attach to a dataset that is a scale");
+
+ /* open the previous written "ds_b", that is a scale */
+ if ((dsid = H5Dopen(fid,"ds_b"))<0)
+ goto out;
+
+ /* open the previous written "ds_a" */
+ if ((did = H5Dopen(fid,"ds_a"))<0)
+ goto out;
+
+ /* try to attach "ds_a" to "ds_b", not valid */
+ if(H5DSattach_scale(dsid,did,0)==SUCCESS)
+ goto out;
+
+ /* close */
+ if (H5Dclose(dsid)<0)
+ goto out;
+ if (H5Dclose(did)<0)
+ goto out;
+
+ PASSED();
+
+/*-------------------------------------------------------------------------
+ * try to attach a scale to an image, pallete or table
+ *-------------------------------------------------------------------------
+ */
+
+ TESTING2("attach to a dataset that is a reserved class dataset");
+
+ /* make an image */
+ if (H5IMmake_image_8bit(fid,"image",100,50,NULL)<0)
+ goto out;
+
+ /* make a palette */
+ if (H5IMmake_palette(fid,"pallete",pal_dims,NULL)<0)
+ goto out;
+
+ /* open the previous written "ds_b" */
+ if ((dsid = H5Dopen(fid,"ds_b"))<0)
+ goto out;
+
+ /* open the image dataset */
+ if ((did = H5Dopen(fid,"image"))<0)
+ goto out;
+
+ /* try to attach "ds_a" to the image, not valid */
+ if(H5DSattach_scale(did,dsid,0)==SUCCESS)
+ goto out;
+
+ /* close */
+ if (H5Dclose(dsid)<0)
+ goto out;
+ if (H5Dclose(did)<0)
+ goto out;
+
+ PASSED();
/* close */
if (H5Fclose(fid)<0)
@@ -1755,7 +1870,6 @@ static int test_rank(void)
hid_t did; /* dataset ID */
hid_t dsid; /* scale ID */
int rank = 3; /* rank of data dataset */
- int rankds = 2; /* rank of DS dataset */
hsize_t dims[3] = {DIM1_SIZE,DIM2_SIZE,DIM3_SIZE}; /* size of data dataset */
char name[30]; /* dataset name buffer */
char names[30]; /* dataset scale name buffer */
@@ -1886,6 +2000,54 @@ static int test_rank(void)
/*-------------------------------------------------------------------------
+ * create a dataset and attach only to 1 dimension
+ *-------------------------------------------------------------------------
+ */
+
+ TESTING2("attach only to 1 dimension");
+
+ /* make a dataset */
+ if (H5LTmake_dataset_int(fid,"dset_b",rank,dims,NULL)<0)
+ goto out;
+
+ if ((did = H5Dopen(fid,"dset_b"))<0)
+ goto out;
+
+ /* attach a DS to dimension 1 */
+ sprintf(name,"ds_a_%d",1);
+ if((dsid = H5Dopen(fid,name))<0)
+ goto out;
+ if(H5DSattach_scale(did,dsid,DIM1)<0)
+ goto out;
+ if (H5DSis_attached(did,dsid,DIM1)<=0)
+ goto out;
+
+
+ /* try to detach all dimensions. for dimensions 0 and 2, it is an error */
+ for (i=0; i<rank; i++)
+ {
+ if ( i==1 )
+ {
+ if(H5DSdetach_scale(did,dsid,i)<0)
+ goto out;
+ }
+ else
+ {
+ if(H5DSdetach_scale(did,dsid,i)!=FAIL)
+ goto out;
+ }
+ }
+
+ if (H5Dclose(dsid)<0)
+ goto out;
+ if (H5Dclose(did)<0)
+ goto out;
+
+ PASSED();
+
+
+
+/*-------------------------------------------------------------------------
* close
*-------------------------------------------------------------------------
*/