diff options
-rw-r--r-- | tools/h5dump.c | 2 | ||||
-rw-r--r-- | tools/h5findshd.c | 66 | ||||
-rw-r--r-- | tools/h5toh4.c | 81 | ||||
-rw-r--r-- | tools/h5tools.h | 3 |
4 files changed, 101 insertions, 51 deletions
diff --git a/tools/h5dump.c b/tools/h5dump.c index c38a87c..94052b0 100644 --- a/tools/h5dump.c +++ b/tools/h5dump.c @@ -1196,7 +1196,7 @@ main(int argc, char *argv[]) init_table(&group_table); init_table(&type_table); init_table(&dset_table); - init_prefix(&prefix); + init_prefix(&prefix, prefix_len); /*init the find_objs_t*/ info->threshold = 0; diff --git a/tools/h5findshd.c b/tools/h5findshd.c index 4361886..aceead9 100644 --- a/tools/h5findshd.c +++ b/tools/h5findshd.c @@ -3,22 +3,20 @@ #include <H5private.h> #include <h5tools.h> -int prefix_len = 1024; -char *prefix; -table_t group_table, dset_table, type_table; + typedef herr_t (*H5G_operator_t)(hid_t, const char*, void*); -extern void init_prefix(char **temp); +extern void init_prefix(char **temp, int length); extern void init_table(table_t **table); extern void free_table(table_t **table); extern void dump_table(char *name, table_t* table); extern herr_t find_objs(hid_t group, const char *name, void *op_data); extern int search_obj (table_t *temp, unsigned long *); -extern int get_table_idx(int, unsigned long *); -extern int get_tableflag(int, int); -extern int set_tableflag(int, int); -extern char* get_objectname(int, int); +extern int get_table_idx(table_t *table, unsigned long *); +extern int get_tableflag(table_t*, int); +extern int set_tableflag(table_t*, int); +extern char* get_objectname(table_t*, int); /*------------------------------------------------------------------------- @@ -66,7 +64,7 @@ void init_table (table_t** temp){ * Modifications: * *-----------------------------------------------------------------------*/ -void init_prefix(char **prefix){ +void init_prefix(char **prefix, int prefix_len){ char *temp; temp = (char *) malloc(prefix_len * sizeof (char)); *temp = '\0'; @@ -310,10 +308,10 @@ int i; * *-----------------------------------------------------------------------*/ int -get_table_idx(int type, unsigned long *objno) +get_table_idx(table_t *table, unsigned long *objno) { -int idx; - +int idx = -1; +/* switch (type) { case H5G_GROUP: @@ -336,7 +334,8 @@ int idx; idx = -1; } - +*/ + idx = search_obj(table, objno); return idx; } @@ -355,9 +354,9 @@ int idx; * *-----------------------------------------------------------------------*/ int -get_tableflag(int type, int idx) +get_tableflag(table_t *table, int idx) { - + /* switch (type) { case H5G_GROUP: @@ -375,8 +374,10 @@ get_tableflag(int type, int idx) default: return -1; - - } +} + */ + return(table->objs[idx].objflag); + } /*------------------------------------------------------------------------- @@ -394,9 +395,9 @@ get_tableflag(int type, int idx) * *-----------------------------------------------------------------------*/ int -set_tableflag(int type, int idx) +set_tableflag(table_t *table, int idx) { - +/* switch (type) { case H5G_GROUP: @@ -417,8 +418,11 @@ set_tableflag(int type, int idx) default: return FAIL; - - } +} +*/ + table->objs[idx].objflag = TRUE; + return(SUCCEED); + } /*------------------------------------------------------------------------- @@ -434,9 +438,9 @@ set_tableflag(int type, int idx) * *-----------------------------------------------------------------------*/ char * -get_objectname(int type, int idx) +get_objectname(table_t* table, int idx) { - + /* switch (type) { case H5G_GROUP: @@ -456,5 +460,21 @@ get_objectname(int type, int idx) return NULL; } + */ + return(strdup(table->objs[idx].objname)); } + + + + + + + + + + + + + + diff --git a/tools/h5toh4.c b/tools/h5toh4.c index 2fc78ab..8a41aea 100644 --- a/tools/h5toh4.c +++ b/tools/h5toh4.c @@ -15,6 +15,7 @@ #include <errno.h> #include <string.h> #include <fcntl.h> +#include <h5tools.h> extern int PrintOptions_h5toh4(void); extern char *BuildFilename(char *h5_filename, char *h4_extension); @@ -32,17 +33,23 @@ extern herr_t convert_dataset_string(hid_t, char *, op_data_t *); extern int32 h5type_to_h4type(hid_t); extern hid_t h4type_to_memtype(int32); -extern void init_table(void); -extern void free_table(void); -extern void dump_tables(void); -extern herr_t H5findobj_once(hid_t , char *, void *); -extern int get_table_idx(int, unsigned long *); -extern int get_tableflag(int, int); -extern int set_tableflag(int, int); -extern char* get_objectname(int, int); +extern void init_table(table_t **temp); +extern void free_table(table_t **temp); +extern void init_prefix(char **prefix, int length); +extern void dump_tables(char* name, table_t* table); +extern herr_t find_objs(hid_t , const char *, void *); +extern int get_table_idx(table_t*, unsigned long *); +extern int get_tableflag(table_t*, int); +extern int set_tableflag(table_t*, int); +extern char* get_objectname(table_t*, int); typedef herr_t (*H5G_operator_t)(hid_t, const char*, void*); +static int prefix_len = 1024; +static char *prefix; +static table_t *group_table, *dset_table, *type_table; + + /***************************************************************************** @@ -70,6 +77,7 @@ main(int argc, char **argv) int status = 0; int status2 = 0; + argc--; argv++; @@ -298,6 +306,11 @@ int h5toh4(char *h5_filename, char *h4_filename) void *edata; hid_t (*func)(void*); + + find_objs_t *info = malloc(sizeof(find_objs_t)); + + + /* open hdf5 file */ if ((fid = H5Fopen (h5_filename, H5F_ACC_RDONLY, plist)) <= 0) { fprintf(stderr,"Error: Unable to open file %s\n",h5_filename); @@ -333,14 +346,28 @@ int h5toh4(char *h5_filename, char *h4_filename) } /* allocate and initialize internal data structure */ - init_table(); + init_table(&group_table); + init_table(&type_table); + init_table(&dset_table); + init_prefix(&prefix, prefix_len); + + /* init the find_objs_t*/ + info->threshold = 0; + info->prefix_len = prefix_len; + info->prefix = prefix; + info->group_table = group_table; + info->type_table = type_table; + info->dset_table = dset_table; + info->status = status; + + /* Disable error reporting */ H5Eget_auto (&func, &edata); H5Eset_auto (NULL, NULL); /* find all objects one time */ - if ((status = H5Giterate(fid, "/", NULL, (H5G_operator_t)H5findobj_once, NULL)) != SUCCEED ) { + if ((status = H5Giterate(fid, "/", NULL, (H5G_operator_t)find_objs, (void*)info)) != SUCCEED ) { fprintf(stderr,"Error: Unable to iterate over all of the groups\n"); DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5toh4", __FILE__, __LINE__); } @@ -407,7 +434,9 @@ int h5toh4(char *h5_filename, char *h4_filename) } done: - free_table(); + free_table(&group_table); + free_table(&dset_table); + free_table(&type_table); return status; @@ -493,13 +522,13 @@ H5G_stat_t statbuf; } else { - if ((idx = get_table_idx(H5G_GROUP, statbuf.objno)) < 0 ) { + if ((idx = get_table_idx(group_table, statbuf.objno)) < 0 ) { fprintf(stderr,"Error: object not found, %s\n",name); DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_group", __FILE__, __LINE__); status = FAIL; - } else if((flag = get_tableflag(H5G_GROUP,idx)) < 0 ) { + } else if((flag = get_tableflag(group_table,idx)) < 0 ) { fprintf(stderr,"Error: get_tableflag() should never return < 0\n"); DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_group", __FILE__, __LINE__); @@ -516,7 +545,7 @@ H5G_stat_t statbuf; } else { /* flag == FALSE */ /* this is now being converted */ - if ((status = set_tableflag(H5G_GROUP,idx)) < 0 ) { + if ((status = set_tableflag(group_table,idx)) < 0 ) { fprintf(stderr,"Error: set_tableflag should never return < 0\n"); DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_group", __FILE__, __LINE__); return(status); @@ -1323,13 +1352,13 @@ convert_all (hid_t group, char *name, op_data_t *op_data) if (statbuf.type==H5G_DATASET ) { - if ((idx = get_table_idx(H5G_DATASET, statbuf.objno)) < 0 ) { + if ((idx = get_table_idx(dset_table, statbuf.objno)) < 0 ) { fprintf(stderr,"Error: object not found\n"); DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__); status = FAIL; - } else if((flag = get_tableflag(H5G_DATASET,idx)) < 0 ) { + } else if((flag = get_tableflag(dset_table,idx)) < 0 ) { fprintf(stderr,"Error: get_tableflag() should never return < 0\n"); DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__); @@ -1373,7 +1402,7 @@ convert_all (hid_t group, char *name, op_data_t *op_data) DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__); status = FAIL; } - if(( status = set_tableflag(H5G_DATASET,idx)) != SUCCEED ) { + if(( status = set_tableflag(dset_table,idx)) != SUCCEED ) { fprintf(stderr,"Error: set_tableflag() did not work for %s\n", name); DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__); break; @@ -1390,13 +1419,13 @@ convert_all (hid_t group, char *name, op_data_t *op_data) } else if (statbuf.type==H5G_GROUP ) { - if ((idx = get_table_idx(H5G_GROUP, statbuf.objno)) < 0 ) { + if ((idx = get_table_idx(group_table, statbuf.objno)) < 0 ) { fprintf(stderr,"Error: object not found\n"); DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__); status = FAIL; - } else if((flag = get_tableflag(H5G_GROUP,idx)) < 0 ) { + } else if((flag = get_tableflag(group_table,idx)) < 0 ) { fprintf(stderr,"Error: get_tableflag() should never return < 0\n"); DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__); @@ -1440,13 +1469,13 @@ convert_all (hid_t group, char *name, op_data_t *op_data) case H5G_GROUP: - if ((idx = get_table_idx(H5G_GROUP, statbuf.objno)) < 0 ) { + if ((idx = get_table_idx(group_table, statbuf.objno)) < 0 ) { fprintf(stderr,"Error: object not found\n"); DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__); status = FAIL; - } else if((flag = get_tableflag(H5G_GROUP,idx)) < 0 ) { + } else if((flag = get_tableflag(group_table,idx)) < 0 ) { fprintf(stderr,"Error: get_tableflag() should never return < 0\n"); DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__); @@ -1488,13 +1517,13 @@ convert_all (hid_t group, char *name, op_data_t *op_data) case H5G_DATASET: - if ((idx = get_table_idx(H5G_DATASET, statbuf.objno)) < 0 ) { + if ((idx = get_table_idx(dset_table, statbuf.objno)) < 0 ) { fprintf(stderr,"Error: object not found\n"); DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__); status = FAIL; - } else if((flag = get_tableflag(H5G_DATASET,idx)) < 0 ) { + } else if((flag = get_tableflag(dset_table,idx)) < 0 ) { fprintf(stderr,"Error: get_tableflag() should never return < 0\n"); DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__); @@ -1538,7 +1567,7 @@ convert_all (hid_t group, char *name, op_data_t *op_data) DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__); status = FAIL; } - if(( status = set_tableflag(H5G_DATASET,idx)) != SUCCEED ) { + if(( status = set_tableflag(dset_table,idx)) != SUCCEED ) { fprintf(stderr,"Error: set_tableflag() did not work for %s\n", name); DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__); break; @@ -1607,7 +1636,7 @@ convert_shared_dataset(hid_t did, int idx, op_data_t *op_data) vgroup_id = op_data->vgroup_id; - if ((dataset_name = get_objectname(H5G_DATASET, idx)) == NULL ) { + if ((dataset_name = get_objectname(dset_table, idx)) == NULL ) { fprintf(stderr,"Error: get_objectname() did not work\n"); DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__); return (status); @@ -1770,7 +1799,7 @@ convert_shared_group (hid_t group, int idx, op_data_t *op_data) { group2 = group; hfile_id = op_data->hfile_id; - if ((group_name = get_objectname(H5G_GROUP, idx)) == NULL ) { + if ((group_name = get_objectname(group_table, idx)) == NULL ) { fprintf(stderr,"Error: get_objectname() did not work\n"); DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_group", __FILE__, __LINE__); status = FAIL; diff --git a/tools/h5tools.h b/tools/h5tools.h index 939178a..31b58be 100644 --- a/tools/h5tools.h +++ b/tools/h5tools.h @@ -300,7 +300,8 @@ typedef struct find_objs_t { herr_t find_objs(hid_t group, const char *name, void *op_data); int search_obj (table_t *temp, unsigned long *); void init_table(table_t **temp); -void init_prefix(char **temp); +void init_prefix(char **temp, int); + /* taken from h5dump.h */ |