[svn-r14164]

first batch for displaying groups in creation order

1) Added extra parameter to dump_group of type H5_index_t , to be passed to H5Literate.

When a group is tried to be displayed, an inquiry of its creation properties is made. If H5P_CRT_ORDER_TRACKED is present on the group property list then the display is made by creation order, otherwise it is made by name

2) Added a new file to h5dumpgentest that generates a file with a hierarchy of groups with creation order on and off in alternately  


Note : XML code was not modified

Tested : windows, linux
This commit is contained in:
Pedro Vicente Nunes 2007-10-01 09:49:23 -05:00
parent 5b1a07823f
commit 1bafc18730
3 changed files with 386 additions and 53 deletions

View File

@ -490,7 +490,7 @@ static struct long_options l_opts[] = {
/* The dump functions of the dump_function_table */ /* The dump functions of the dump_function_table */
/* standard format: no change */ /* standard format: no change */
static void dump_group(hid_t, const char *); static void dump_group(hid_t, const char *, H5_index_t idx_type);
static void dump_named_datatype(hid_t, const char *); static void dump_named_datatype(hid_t, const char *);
static void dump_dataset(hid_t, const char *, struct subset_t *); static void dump_dataset(hid_t, const char *, struct subset_t *);
static void dump_dataspace(hid_t space); static void dump_dataspace(hid_t space);
@ -504,7 +504,7 @@ static void dump_fcontents(hid_t fid);
/* XML format: same interface, alternative output */ /* XML format: same interface, alternative output */
static void xml_dump_group(hid_t, const char *); static void xml_dump_group(hid_t, const char *, H5_index_t idx_type);
static void xml_dump_named_datatype(hid_t, const char *); static void xml_dump_named_datatype(hid_t, const char *);
static void xml_dump_dataset(hid_t, const char *, struct subset_t *); static void xml_dump_dataset(hid_t, const char *, struct subset_t *);
static void xml_dump_dataspace(hid_t space); static void xml_dump_dataspace(hid_t space);
@ -519,7 +519,7 @@ static void xml_dump_data(hid_t, int, struct subset_t *, int);
**/ **/
/* the table of dump functions */ /* the table of dump functions */
typedef struct dump_functions_t { typedef struct dump_functions_t {
void (*dump_group_function) (hid_t, const char *); void (*dump_group_function) (hid_t, const char *, H5_index_t idx_type);
void (*dump_named_datatype_function) (hid_t, const char *); void (*dump_named_datatype_function) (hid_t, const char *);
void (*dump_dataset_function) (hid_t, const char *, struct subset_t *); void (*dump_dataset_function) (hid_t, const char *, struct subset_t *);
void (*dump_dataspace_function) (hid_t); void (*dump_dataspace_function) (hid_t);
@ -1355,9 +1355,11 @@ dump_selected_attr(hid_t loc_id, const char *name)
* Programmer: Ruey-Hsia Li * Programmer: Ruey-Hsia Li
* *
* Modifications: * Modifications:
* RMcG, November 2000 * RMcG, November 2000
* Added XML support. Also, optionally checks the op_data * Added XML support. Also, optionally checks the op_data argument
* argument. *
* Pedro Vicente, September 26, 2007
* handle creation order for groups
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -1365,8 +1367,10 @@ static herr_t
dump_all(hid_t group, const char *name, const H5L_info_t *linfo, void UNUSED *op_data) dump_all(hid_t group, const char *name, const H5L_info_t *linfo, void UNUSED *op_data)
{ {
hid_t obj; hid_t obj;
char *obj_path = NULL; /* Full path of object */ char *obj_path = NULL; /* Full path of object */
herr_t ret = SUCCEED; herr_t ret = SUCCEED;
hid_t gcpl_id; /* group creation property list ID */
unsigned crt_order_flags; /* status of creation order info */
/* Build the object's path name */ /* Build the object's path name */
obj_path = HDmalloc(HDstrlen(prefix) + HDstrlen(name) + 2); obj_path = HDmalloc(HDstrlen(prefix) + HDstrlen(name) + 2);
@ -1387,32 +1391,63 @@ dump_all(hid_t group, const char *name, const H5L_info_t *linfo, void UNUSED *op
} /* end if */ } /* end if */
switch(oinfo.type) { switch(oinfo.type) {
case H5O_TYPE_GROUP: case H5O_TYPE_GROUP:
if((obj = H5Gopen2(group, name, H5P_DEFAULT)) < 0) { if((obj = H5Gopen2(group, name, H5P_DEFAULT)) < 0)
error_msg(progname, "unable to dump group \"%s\"\n", name); {
error_msg(progname, "unable to dump group \"%s\"\n", name);
d_status = EXIT_FAILURE;
ret = FAIL;
}
else
{
char *old_prefix; /* Pointer to previous prefix */
/* Keep copy of prefix before iterating into group */
old_prefix = HDstrdup(prefix);
HDassert(old_prefix);
/* Append group name to prefix */
add_prefix(&prefix, &prefix_len, name);
if((gcpl_id = H5Gget_create_plist(obj)) < 0)
{
error_msg(progname, "error in getting group creation property list ID\n");
d_status = EXIT_FAILURE; d_status = EXIT_FAILURE;
ret = FAIL;
} else {
char *old_prefix; /* Pointer to previous prefix */
/* Keep copy of prefix before iterating into group */
old_prefix = HDstrdup(prefix);
HDassert(old_prefix);
/* Append group name to prefix */
add_prefix(&prefix, &prefix_len, name);
/* Iterate into group */
dump_function_table->dump_group_function(obj, name);
/* Restore old prefix name */
HDstrcpy(prefix, old_prefix);
HDfree(old_prefix);
/* Close group */
H5Gclose(obj);
} }
break;
/* query the group creation properties */
if(H5Pget_link_creation_order(gcpl_id, &crt_order_flags) < 0)
{
error_msg(progname, "error in getting group creation properties\n");
d_status = EXIT_FAILURE;
}
/* Iterate into group */
if( (crt_order_flags == H5P_CRT_ORDER_TRACKED ) ||
(crt_order_flags == (H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED)))
{
dump_function_table->dump_group_function(obj, name, H5_INDEX_CRT_ORDER );
}
else
{
dump_function_table->dump_group_function(obj, name, H5_INDEX_NAME );
}
if(H5Pclose(gcpl_id) < 0)
d_status = EXIT_FAILURE;
/* Restore old prefix name */
HDstrcpy(prefix, old_prefix);
HDfree(old_prefix);
/* Close group */
H5Gclose(obj);
}
break;
case H5O_TYPE_DATASET: case H5O_TYPE_DATASET:
if((obj = H5Dopen(group, name)) >= 0) { if((obj = H5Dopen(group, name)) >= 0) {
@ -1784,12 +1819,15 @@ dump_named_datatype(hid_t type, const char *name)
* *
* Modifications: * Modifications:
* *
* Call to dump_all -- add parameter to select everything. * Call to dump_all -- add parameter to select everything.
*
* Pedro Vicente, September 26, 2007
* extra parameter H5_index_t to handle H5Literate iteration order
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
static void static void
dump_group(hid_t gid, const char *name) dump_group(hid_t gid, const char *name, H5_index_t idx_type)
{ {
H5O_info_t oinfo; H5O_info_t oinfo;
hid_t dset, type; hid_t dset, type;
@ -1840,11 +1878,11 @@ dump_group(hid_t gid, const char *name)
} else { } else {
found_obj->displayed = TRUE; found_obj->displayed = TRUE;
H5Aiterate(gid, NULL, dump_attr, NULL); H5Aiterate(gid, NULL, dump_attr, NULL);
H5Literate(gid, ".", H5_INDEX_NAME, H5_ITER_INC, NULL, dump_all, NULL, H5P_DEFAULT); H5Literate(gid, ".", idx_type, H5_ITER_INC, NULL, dump_all, NULL, H5P_DEFAULT);
} }
} else { } else {
H5Aiterate(gid, NULL, dump_attr, NULL); H5Aiterate(gid, NULL, dump_attr, NULL);
H5Literate(gid, ".", H5_INDEX_NAME, H5_ITER_INC, NULL, dump_all, NULL, H5P_DEFAULT); H5Literate(gid, ".", idx_type, H5_ITER_INC, NULL, dump_all, NULL, H5P_DEFAULT);
} }
indent -= COL; indent -= COL;
@ -3093,32 +3131,68 @@ handle_datasets(hid_t fid, char *dset, void *data)
* Programmer: Bill Wendling * Programmer: Bill Wendling
* Tuesday, 9. January 2001 * Tuesday, 9. January 2001
* *
* Modifications: * Modifications: Pedro Vicente, September 26, 2007
* handle creation order
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
static void static void
handle_groups(hid_t fid, char *group, void UNUSED * data) handle_groups(hid_t fid, char *group, void UNUSED * data)
{ {
hid_t gid; hid_t gid;
hid_t gcpl_id; /* group creation property list ID */
if((gid = H5Gopen2(fid, group, H5P_DEFAULT)) < 0) { unsigned crt_order_flags; /* status of creation order info */
if((gid = H5Gopen2(fid, group, H5P_DEFAULT)) < 0)
{
begin_obj(dump_header_format->groupbegin, group, dump_header_format->groupblockbegin); begin_obj(dump_header_format->groupbegin, group, dump_header_format->groupblockbegin);
indentation(COL); indentation(COL);
error_msg(progname, "unable to open group \"%s\"\n", group); error_msg(progname, "unable to open group \"%s\"\n", group);
end_obj(dump_header_format->groupend, dump_header_format->groupblockend); end_obj(dump_header_format->groupend, dump_header_format->groupblockend);
d_status = EXIT_FAILURE; d_status = EXIT_FAILURE;
} else { }
else
{
size_t new_len = HDstrlen(group) + 1; size_t new_len = HDstrlen(group) + 1;
if(prefix_len <= new_len) { if(prefix_len <= new_len)
{
prefix_len = new_len; prefix_len = new_len;
prefix = HDrealloc(prefix, prefix_len); prefix = HDrealloc(prefix, prefix_len);
} /* end if */ } /* end if */
HDstrcpy(prefix, group); HDstrcpy(prefix, group);
dump_group(gid, group);
if((gcpl_id = H5Gget_create_plist(gid)) < 0)
{
error_msg(progname, "error in getting group creation property list ID\n");
d_status = EXIT_FAILURE;
}
/* query the group creation properties */
if(H5Pget_link_creation_order(gcpl_id, &crt_order_flags) < 0)
{
error_msg(progname, "error in getting group creation properties\n");
d_status = EXIT_FAILURE;
}
if( (crt_order_flags == H5P_CRT_ORDER_TRACKED ) ||
(crt_order_flags == (H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED)))
{
dump_group(gid, group, H5_INDEX_CRT_ORDER );
}
else
{
dump_group(gid, group, H5_INDEX_NAME );
}
if(H5Pclose(gcpl_id) < 0)
d_status = EXIT_FAILURE;
if(H5Gclose(gid) < 0) if(H5Gclose(gid) < 0)
d_status = EXIT_FAILURE; d_status = EXIT_FAILURE;
} /* end else */ } /* end else */
@ -3467,6 +3541,7 @@ parse_start:
break; break;
/** begin XML parameters **/ /** begin XML parameters **/
case 'x': case 'x':
/* select XML output */ /* select XML output */
@ -3647,12 +3722,18 @@ free_handler(struct handler_t *hand, int len)
* August 2003 * August 2003
* Major upgrade to XML support. * Major upgrade to XML support.
* *
* Pedro Vicente
* September 2007
* list objects in requested order (creation order or alphabetically)
*
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
int int
main(int argc, const char *argv[]) main(int argc, const char *argv[])
{ {
hid_t fid, gid; hid_t fid, gid;
hid_t gcpl_id; /* group creation property list ID */
unsigned crt_order_flags; /* status of creation order info */
char *fname = NULL; char *fname = NULL;
void *edata; void *edata;
H5E_auto2_t func; H5E_auto2_t func;
@ -3744,6 +3825,7 @@ main(int argc, const char *argv[])
} }
} }
/* find all shared objects */ /* find all shared objects */
if(init_objs(fid, &info, &group_table, &dset_table, &type_table) < 0) { if(init_objs(fid, &info, &group_table, &dset_table, &type_table) < 0) {
error_msg(progname, "internal error (file %s:line %d)\n", __FILE__, __LINE__); error_msg(progname, "internal error (file %s:line %d)\n", __FILE__, __LINE__);
@ -3806,19 +3888,58 @@ main(int argc, const char *argv[])
dump_fcpl(fid); dump_fcpl(fid);
} }
if(display_all) { if(display_all)
if((gid = H5Gopen2(fid, "/", H5P_DEFAULT)) < 0) { {
if((gid = H5Gopen2(fid, "/", H5P_DEFAULT)) < 0)
{
error_msg(progname, "unable to open root group\n"); error_msg(progname, "unable to open root group\n");
d_status = EXIT_FAILURE; d_status = EXIT_FAILURE;
} else { }
dump_function_table->dump_group_function(gid, "/"); else
{
if ((gcpl_id = H5Gget_create_plist(gid)) < 0)
{
error_msg(progname, "error in getting group creation property list ID\n");
d_status = EXIT_FAILURE;
}
/* query the group creation properties */
if (H5Pget_link_creation_order(gcpl_id, &crt_order_flags) < 0)
{
error_msg(progname, "error in getting group creation properties\n");
d_status = EXIT_FAILURE;
}
if( (crt_order_flags == H5P_CRT_ORDER_TRACKED ) ||
(crt_order_flags == (H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED)))
{
dump_function_table->dump_group_function(gid, "/", H5_INDEX_CRT_ORDER );
}
else
{
dump_function_table->dump_group_function(gid, "/", H5_INDEX_NAME );
}
} }
if(H5Gclose(gid) < 0) { if(H5Gclose(gid) < 0)
{
error_msg(progname, "unable to close root group\n"); error_msg(progname, "unable to close root group\n");
d_status = EXIT_FAILURE; d_status = EXIT_FAILURE;
} }
} else {
if(H5Pclose(gcpl_id) < 0)
{
error_msg(progname, "group creation property list ID\n");
d_status = EXIT_FAILURE;
}
}
else
{
/* Note: this option is not supported for XML */ /* Note: this option is not supported for XML */
if(doxml) { if(doxml) {
error_msg(progname, "internal error (file %s:line %d)\n", __FILE__, __LINE__); error_msg(progname, "internal error (file %s:line %d)\n", __FILE__, __LINE__);
@ -5051,7 +5172,7 @@ xml_dump_named_datatype(hid_t type, const char *name)
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
static void static void
xml_dump_group(hid_t gid, const char *name) xml_dump_group(hid_t gid, const char *name, H5_index_t UNUSED idx_type)
{ {
H5O_info_t oinfo; H5O_info_t oinfo;
char *cp; char *cp;
@ -5669,9 +5790,9 @@ xml_dump_fill_value(hid_t dcpl, hid_t type)
} }
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* Function: xml_dump_group * Function: xml_dump_dataset
* *
* Purpose: Dump a description of an HDF5 Group (and its members) in XML. * Purpose: Dump a description of an HDF5 dataset in XML.
* *
* Return: void * Return: void
* *

View File

@ -85,6 +85,9 @@
#define FILE55 "tbinary.h5" #define FILE55 "tbinary.h5"
#define FILE56 "tbigdims.h5" #define FILE56 "tbigdims.h5"
#define FILE57 "thyperslab.h5" #define FILE57 "thyperslab.h5"
#define FILE58 "tordergr.h5"
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* prototypes * prototypes
@ -5751,6 +5754,213 @@ gent_hyperslab(void)
} }
/*-------------------------------------------------------------------------
* Function: gent_link_creation_order
*
* Purpose: generate a file with several groups and set H5Pset_link_creation_order
*
*-------------------------------------------------------------------------
*/
static void
gent_link_creation_order(char* fname, unsigned crt_order_flags)
{
hid_t fid; /* file id */
hid_t gid; /* group id */
hid_t fcpl_id; /* file creation property list id */
if ((fcpl_id = H5Pcreate(H5P_FILE_CREATE)) < 0)
goto out;
if ( crt_order_flags )
{
if (H5Pset_link_creation_order(fcpl_id, crt_order_flags ) < 0)
goto out;
}
if ((fid = H5Fcreate(fname, H5F_ACC_TRUNC, fcpl_id, H5P_DEFAULT)) < 0)
goto out;
/* create some groups */
if ((gid = H5Gcreate2(fid, "c", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
goto out;
if (H5Gclose(gid) < 0)
goto out;
if ((gid = H5Gcreate2(fid, "b", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
goto out;
if (H5Gclose(gid) < 0)
goto out;
if ((gid = H5Gcreate2(fid, "a", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
goto out;
if (H5Gclose(gid) < 0)
goto out;
if (H5Pclose(fcpl_id) < 0)
goto out;
if (H5Fclose(fid) < 0)
goto out;
return;
out:
printf("Error.....\n");
H5E_BEGIN_TRY {
H5Gclose(gid);
H5Pclose(fcpl_id);
H5Fclose(fid);
} H5E_END_TRY;
return;
}
/*-------------------------------------------------------------------------
* Function: gent_group_creation_order
*
* Purpose: generate a file with several groups with creation order set and not
* set tru its hierarchy
*
*-------------------------------------------------------------------------
*/
static void
gent_group_creation_order()
{
hid_t fid; /* file id */
hid_t gid; /* group id */
hid_t gcpl_id; /* group creation property list id */
hid_t fcpl_id; /* file creation property list id (to set root group order) */
if ((fcpl_id = H5Pcreate(H5P_FILE_CREATE)) < 0)
goto out;
if (H5Pset_link_creation_order(fcpl_id, H5P_CRT_ORDER_TRACKED ) < 0)
goto out;
if ((fid = H5Fcreate(FILE58, H5F_ACC_TRUNC, fcpl_id, H5P_DEFAULT)) < 0)
goto out;
/* create group creation property list */
if((gcpl_id = H5Pcreate(H5P_GROUP_CREATE)) < 0)
goto out;
/*-------------------------------------------------------------------------
* create a group "2"
*-------------------------------------------------------------------------
*/
if ((gid = H5Gcreate2(fid, "2", H5P_DEFAULT, gcpl_id, H5P_DEFAULT)) < 0)
goto out;
if (H5Gclose(gid) < 0)
goto out;
if ((gid = H5Gcreate2(fid, "2/c", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
goto out;
if (H5Gclose(gid) < 0)
goto out;
if ((gid = H5Gcreate2(fid, "2/b", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
goto out;
if (H5Gclose(gid) < 0)
goto out;
if ((gid = H5Gcreate2(fid, "2/a", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
goto out;
if (H5Gclose(gid) < 0)
goto out;
if ((gid = H5Gcreate2(fid, "2/a/a2", H5P_DEFAULT, gcpl_id, H5P_DEFAULT)) < 0)
goto out;
if (H5Gclose(gid) < 0)
goto out;
if ((gid = H5Gcreate2(fid, "2/a/a1", H5P_DEFAULT, gcpl_id, H5P_DEFAULT)) < 0)
goto out;
if (H5Gclose(gid) < 0)
goto out;
if ((gid = H5Gcreate2(fid, "2/a/a2/a22", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
goto out;
if (H5Gclose(gid) < 0)
goto out;
if ((gid = H5Gcreate2(fid, "2/a/a2/a21", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
goto out;
if (H5Gclose(gid) < 0)
goto out;
/*-------------------------------------------------------------------------
* create a group "1" with H5P_CRT_ORDER_TRACKED set
*-------------------------------------------------------------------------
*/
if(H5Pset_link_creation_order(gcpl_id, H5P_CRT_ORDER_TRACKED) < 0)
goto out;
if ((gid = H5Gcreate2(fid, "1", H5P_DEFAULT, gcpl_id, H5P_DEFAULT)) < 0)
goto out;
if (H5Gclose(gid) < 0)
goto out;
if ((gid = H5Gcreate2(fid, "1/c", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
goto out;
if (H5Gclose(gid) < 0)
goto out;
if ((gid = H5Gcreate2(fid, "1/b", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
goto out;
if (H5Gclose(gid) < 0)
goto out;
if ((gid = H5Gcreate2(fid, "1/a", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
goto out;
if (H5Gclose(gid) < 0)
goto out;
if ((gid = H5Gcreate2(fid, "1/a/a2", H5P_DEFAULT, gcpl_id, H5P_DEFAULT)) < 0)
goto out;
if (H5Gclose(gid) < 0)
goto out;
if ((gid = H5Gcreate2(fid, "1/a/a1", H5P_DEFAULT, gcpl_id, H5P_DEFAULT)) < 0)
goto out;
if (H5Gclose(gid) < 0)
goto out;
if ((gid = H5Gcreate2(fid, "1/a/a2/a22", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
goto out;
if (H5Gclose(gid) < 0)
goto out;
if ((gid = H5Gcreate2(fid, "1/a/a2/a21", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
goto out;
if (H5Gclose(gid) < 0)
goto out;
if (H5Pclose(gcpl_id) < 0)
goto out;
if (H5Pclose(fcpl_id) < 0)
goto out;
if (H5Fclose(fid) < 0)
goto out;
return;
out:
printf("Error.....\n");
H5E_BEGIN_TRY {
H5Gclose(gid);
H5Pclose(gcpl_id);
H5Pclose(fcpl_id);
H5Fclose(fid);
} H5E_END_TRY;
return;
}
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* Function: main * Function: main
* *
@ -5816,6 +6026,8 @@ int main(void)
gent_binary(); gent_binary();
gent_bigdims(); gent_bigdims();
gent_hyperslab(); gent_hyperslab();
gent_group_creation_order();
return 0; return 0;
} }

BIN
tools/testfiles/tordergr.h5 Normal file

Binary file not shown.