summaryrefslogtreecommitdiffstats
path: root/tools/h5tools.c
diff options
context:
space:
mode:
authorPatrick Lu <ptlu@hawkwind.ncsa.uiuc.edu>1999-10-29 19:50:25 (GMT)
committerPatrick Lu <ptlu@hawkwind.ncsa.uiuc.edu>1999-10-29 19:50:25 (GMT)
commit23ab35a5a7aadf526d0a3b4c1011a521a838b36b (patch)
tree41952a6420f4f816dcca6c78eb1a810af2ea4994 /tools/h5tools.c
parentea1264842e079187937c8dc27c91edb3702c06bf (diff)
downloadhdf5-23ab35a5a7aadf526d0a3b4c1011a521a838b36b.zip
hdf5-23ab35a5a7aadf526d0a3b4c1011a521a838b36b.tar.gz
hdf5-23ab35a5a7aadf526d0a3b4c1011a521a838b36b.tar.bz2
[svn-r1800] moved the code from the dumper that iterates thru the files and stores the info
into the tables into the tools lib. h5findshd-had some of the same functions so i removed them for now
Diffstat (limited to 'tools/h5tools.c')
-rw-r--r--tools/h5tools.c164
1 files changed, 164 insertions, 0 deletions
diff --git a/tools/h5tools.c b/tools/h5tools.c
index 1ecd067..80b300b 100644
--- a/tools/h5tools.c
+++ b/tools/h5tools.c
@@ -2480,3 +2480,167 @@ int h5dump_attr(hid_t oid, hid_t p_type){
}
+/*-------------------------------------------------------------------------
+ * Function: search_obj
+ *
+ * Purpose: search the object specified by objno in the table
+ *
+ * Return: an integer, the location of the object
+ * -1 if object is not found
+ *
+ *
+ * Programmer: Ruey-Hsia Li
+ *
+ * Modifications:
+ *
+ *-----------------------------------------------------------------------*/
+int
+search_obj (table_t *table, unsigned long *objno) {
+int i=0, found=0;
+
+ while (i < table->nobjs && !found)
+ if (table->objs[i].objno[0] == *(objno) &&
+ table->objs[i].objno[1] == *(objno+1) ) found = 1;
+ else i++;
+
+ if (!found) return -1;
+ else return i;
+
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: add_obj
+ *
+ * Purpose: add a shared object to the table
+ * realloc the table if necessary
+ *
+ * Return: void
+ *
+ * Programmer: Ruey-Hsia Li
+ *
+ * Modifications:
+ *
+ *-----------------------------------------------------------------------*/
+void
+add_obj (table_t *table, unsigned long *objno, char *objname) {
+int i;
+
+ if (table->nobjs == table->size) {
+ table->size *= 2;
+ table->objs = realloc (table->objs, table->size*sizeof(obj_t));
+ for (i = table->nobjs; i < table->size; i++) {
+ table->objs[i].objno[0] = table->objs[i].objno[1] = 0;
+ table->objs[i].displayed = 0;
+ table->objs[i].recorded = 0;
+ }
+ }
+
+ i = table->nobjs++;
+ table->objs[i].objno[0] = *objno;
+ table->objs[i].objno[1] = *(objno+1);
+ strcpy (table->objs[i].objname, objname);
+
+}
+/*-------------------------------------------------------------------------
+ * Function: Find_objs
+ *
+ * Purpose: Find objects, committed types and store them in tables
+ *
+ * Return: Success: SUCCEED
+ *
+ * Failure: FAIL
+ *
+ * Programmer: Ruey-Hsia Li
+ *
+ * Modifications:
+ *
+ *-----------------------------------------------------------------------*/
+herr_t find_objs(hid_t group, const char *name, void *op_data)
+{
+ hid_t obj, type;
+ H5G_stat_t statbuf;
+ char *tmp;
+ int i;
+ find_objs_t *info = (find_objs_t*)op_data;
+
+ if (info->threshold > 1) { /*will get an infinite loop if greater than 1*/
+ return(FAIL);
+ }
+
+ H5Gget_objinfo(group, name, TRUE, &statbuf);
+
+ tmp = (char *) malloc ((strlen(info->prefix)+strlen(name)+2) * sizeof(char));
+
+ strcpy(tmp, info->prefix);
+
+ switch (statbuf.type) {
+
+ case H5G_GROUP:
+ if ((obj=H5Gopen (group, name))>=0) {
+
+ if (info->prefix_len < (int)(strlen(info->prefix) + strlen(name) + 2)) {
+ info->prefix_len *= 2;
+ info->prefix = realloc (info->prefix, info->prefix_len * sizeof(char));
+ }
+ strcat(strcat(info->prefix,"/"), name);
+
+ if (statbuf.nlink > info->threshold) {
+ if (search_obj (info->group_table, statbuf.objno) < 0) {
+ add_obj (info->group_table, statbuf.objno, info->prefix);
+ H5Giterate (obj, ".", NULL, find_objs, (void*)info);
+ }
+ } else
+ H5Giterate (obj, ".", NULL, find_objs, (void*)info);
+
+ strcpy(info->prefix, tmp);
+ H5Gclose (obj);
+
+ } else
+ info->status = 1;
+
+ break;
+
+ case H5G_DATASET:
+
+ strcat(tmp,"/");
+ strcat(tmp,name); /* absolute name of the data set */
+ if (statbuf.nlink > info->threshold &&
+ search_obj (info->dset_table, statbuf.objno) < 0)
+ add_obj (info->dset_table, statbuf.objno, tmp);
+
+ if ((obj=H5Dopen (group, name))>=0) {
+ type = H5Dget_type (obj);
+ if (H5Tcommitted(type) > 0 ) {
+ H5Gget_objinfo(type, ".", TRUE, &statbuf);
+ if (search_obj (info->type_table, statbuf.objno) < 0)
+ add_obj (info->type_table, statbuf.objno, tmp) ;
+ }
+ H5Tclose(type);
+ H5Dclose (obj);
+ } else
+ info->status = 1;
+
+ break;
+
+ case H5G_TYPE:
+ strcat(tmp,"/");
+ strcat(tmp,name); /* absolute name of the type */
+ i = search_obj (info->type_table, statbuf.objno);
+ if (i < 0) {
+ add_obj (info->type_table, statbuf.objno, tmp) ;
+ info->type_table->objs[info->type_table->nobjs-1].recorded = 1; /* named data type */
+ } else {
+ strcpy (info->type_table->objs[i].objname, tmp);
+ info->type_table->objs[i].recorded = 1;
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ free (tmp);
+
+ return SUCCEED;
+}