From 6f820c0a247ee97a35c597d2510320407f10fc7b Mon Sep 17 00:00:00 2001 From: Pedro Vicente Nunes Date: Thu, 3 Jan 2008 15:45:18 -0500 Subject: [svn-r14368] clean code and reshufle functions between modules, remove unused functions tested: windows, linux --- tools/h5repack/h5repack.c | 119 ------------------------------------ tools/h5repack/h5repack.h | 46 +++++--------- tools/h5repack/h5repack_filters.c | 50 +-------------- tools/h5repack/h5repack_main.c | 124 +++++++++++++++++++++++++++++++++++++- 4 files changed, 141 insertions(+), 198 deletions(-) diff --git a/tools/h5repack/h5repack.c b/tools/h5repack/h5repack.c index 98e910b..954f3e7 100644 --- a/tools/h5repack/h5repack.c +++ b/tools/h5repack/h5repack.c @@ -538,125 +538,6 @@ out: -/*------------------------------------------------------------------------- - * Function: read_info - * - * Purpose: read comp and chunk options from file - * - * Return: void, exit on error - * - * Programmer: pvn@ncsa.uiuc.edu - * - * Date: September, 22, 2003 - * - *------------------------------------------------------------------------- - */ - -void read_info(const char *filename, - pack_opt_t *options) -{ - - char stype[10]; - char comp_info[1024]; - FILE *fp; - char c; - int i, rc=1; - char *srcdir = getenv("srcdir"); /* the source directory */ - char data_file[512]=""; /* buffer to hold name of existing file */ - - /* compose the name of the file to open, using the srcdir, if appropriate */ - if (srcdir){ - strcpy(data_file,srcdir); - strcat(data_file,"/"); - } - strcat(data_file,filename); - - - if ((fp = fopen(data_file, "r")) == (FILE *)NULL) { - error_msg(progname, "cannot open options file %s\n", filename); - exit(1); - } - - /* cycle until end of file reached */ - while( 1 ) - { - rc=fscanf(fp, "%s", stype); - if (rc==-1) - break; - - /*------------------------------------------------------------------------- - * filter - *------------------------------------------------------------------------- - */ - if (strcmp(stype,"-f") == 0) { - - /* find begining of info */ - i=0; c='0'; - while( c!=' ' ) - { - fscanf(fp, "%c", &c); - if (feof(fp)) break; - } - c='0'; - /* go until end */ - while( c!=' ' ) - { - fscanf(fp, "%c", &c); - comp_info[i]=c; - i++; - if (feof(fp)) break; - if (c==10 /*eol*/) break; - } - comp_info[i-1]='\0'; /*cut the last " */ - - if (h5repack_addfilter(comp_info,options)==-1){ - error_msg(progname, "could not add compression option\n"); - exit(1); - } - } - /*------------------------------------------------------------------------- - * layout - *------------------------------------------------------------------------- - */ - else if (strcmp(stype,"-l") == 0) { - - /* find begining of info */ - i=0; c='0'; - while( c!=' ' ) - { - fscanf(fp, "%c", &c); - if (feof(fp)) break; - } - c='0'; - /* go until end */ - while( c!=' ' ) - { - fscanf(fp, "%c", &c); - comp_info[i]=c; - i++; - if (feof(fp)) break; - if (c==10 /*eol*/) break; - } - comp_info[i-1]='\0'; /*cut the last " */ - - if (h5repack_addlayout(comp_info,options)==-1){ - error_msg(progname, "could not add chunck option\n"); - exit(1); - } - } - /*------------------------------------------------------------------------- - * not valid - *------------------------------------------------------------------------- - */ - else { - error_msg(progname, "bad file format for %s", filename); - exit(1); - } - } - - fclose(fp); - return; -} /*------------------------------------------------------------------------- diff --git a/tools/h5repack/h5repack.h b/tools/h5repack/h5repack.h index 95a6584..baa888e 100644 --- a/tools/h5repack/h5repack.h +++ b/tools/h5repack/h5repack.h @@ -147,52 +147,38 @@ int h5repack_cmpdcpl (const char *fname1, */ -int copy_objects(const char* fnamein, - const char* fnameout, - pack_opt_t *options); +/*------------------------------------------------------------------------- + * copy module + *------------------------------------------------------------------------- + */ + +int copy_objects (const char* fnamein, + const char* fnameout, + pack_opt_t *options); int do_copy_refobjs(hid_t fidin, hid_t fidout, trav_table_t *travt, - pack_opt_t *options); /* repack options */ - + pack_opt_t *options); -void read_info(const char *filename,pack_opt_t *options); +/*------------------------------------------------------------------------- + * filters and verify module + *------------------------------------------------------------------------- + */ void init_packobject(pack_info_t *obj); -int print_filters(hid_t dcpl_id); - /*------------------------------------------------------------------------- - * filters + * filters and copy module *------------------------------------------------------------------------- */ int apply_filters(const char* name, /* object name from traverse list */ int rank, /* rank of dataset */ hsize_t *dims, /* dimensions of dataset */ - hid_t dcpl_id, /* (IN,OUT) dataset creation property list */ + hid_t dcpl_id, /* dataset creation property list */ pack_opt_t *options, /* repack options */ - int *has_filter); /* (OUT) object NAME has a filter */ - -int can_read(const char* name, /* object name from traverse list */ - hid_t dcpl_id, /* dataset creation property list */ - pack_opt_t *options); /* repack options */ - - -/*------------------------------------------------------------------------- - * layout functions - *------------------------------------------------------------------------- - */ - - -int layout_this(hid_t dcpl_id, /* DCPL from input object */ - const char* name, /* object name from traverse list */ - pack_opt_t *options, /* repack options */ - pack_info_t *pack /*OUT*/) /* object to apply layout */; - -int apply_layout(hid_t dcpl_id, - pack_info_t *pack); /* info about object */ + int *has_filter); /* (OUT) object NAME has a filter */ /*------------------------------------------------------------------------- diff --git a/tools/h5repack/h5repack_filters.c b/tools/h5repack/h5repack_filters.c index c7a58dc..98ef07e 100644 --- a/tools/h5repack/h5repack_filters.c +++ b/tools/h5repack/h5repack_filters.c @@ -171,8 +171,7 @@ int aux_assign_obj(const char* name, /* object name from traverse lis *obj = tmp; return 1; -} - +} /*------------------------------------------------------------------------- @@ -194,7 +193,7 @@ int aux_assign_obj(const char* name, /* object name from traverse lis int apply_filters(const char* name, /* object name from traverse list */ int rank, /* rank of dataset */ hsize_t *dims, /* dimensions of dataset */ - hid_t dcpl_id, /* (IN,OUT) dataset creation property list */ + hid_t dcpl_id, /* dataset creation property list */ pack_opt_t *options, /* repack options */ int *has_filter) /* (OUT) object NAME has a filter */ @@ -415,48 +414,3 @@ int apply_filters(const char* name, /* object name from traverse list */ return 0; } -/*------------------------------------------------------------------------- - * Function: print_filters - * - * Purpose: print the filters in DCPL - * - * Return: 0, ok, -1 no - * - *------------------------------------------------------------------------- - */ - -int print_filters(hid_t dcpl_id) -{ - int nfilters; /* number of filters */ - unsigned filt_flags; /* filter flags */ - H5Z_filter_t filtn; /* filter identification number */ - unsigned cd_values[20]; /* filter client data values */ - size_t cd_nelmts; /* filter client number of values */ - size_t cd_num; /* filter client data counter */ - char f_name[256]; /* filter name */ - char s[64]; /* temporary string buffer */ - int i; - - /* get information about filters */ - if((nfilters = H5Pget_nfilters(dcpl_id)) < 0) - return -1; - - for(i = 0; i < nfilters; i++) { - cd_nelmts = NELMTS(cd_values); - filtn = H5Pget_filter2(dcpl_id, (unsigned)i, &filt_flags, &cd_nelmts, - cd_values, sizeof(f_name), f_name, NULL); - - f_name[sizeof(f_name)-1] = '\0'; - sprintf(s, "Filter-%d:", i); - printf(" %-10s %s-%u %s {", s, - f_name[0] ? f_name : "method", - (unsigned)filtn, - filt_flags & H5Z_FLAG_OPTIONAL?"OPT":""); - for(cd_num = 0; cd_num < cd_nelmts; cd_num++) - printf("%s%u", cd_num?", ":"", cd_values[cd_num]); - printf("}\n"); - } - - return 0; -} - diff --git a/tools/h5repack/h5repack_main.c b/tools/h5repack/h5repack_main.c index 45cc2db..17056c4 100644 --- a/tools/h5repack/h5repack_main.c +++ b/tools/h5repack/h5repack_main.c @@ -22,8 +22,9 @@ static void usage(const char *prog); -static int parse_number(char *str); +static int parse_number(char *str); static void parse_command_line(int argc, const char* argv[], pack_opt_t* options); +static void read_info(const char *filename,pack_opt_t *options); /* module-scoped variables */ @@ -411,3 +412,124 @@ int parse_number(char *str) return n; } + +/*------------------------------------------------------------------------- + * Function: read_info + * + * Purpose: read comp and chunk options from a file + * + * Return: void, exit on error + * + * Programmer: pvn@ncsa.uiuc.edu + * + * Date: September, 22, 2003 + * + *------------------------------------------------------------------------- + */ + +static +void read_info(const char *filename, + pack_opt_t *options) +{ + + char stype[10]; + char comp_info[1024]; + FILE *fp; + char c; + int i, rc=1; + char *srcdir = getenv("srcdir"); /* the source directory */ + char data_file[512]=""; /* buffer to hold name of existing file */ + + /* compose the name of the file to open, using the srcdir, if appropriate */ + if (srcdir){ + strcpy(data_file,srcdir); + strcat(data_file,"/"); + } + strcat(data_file,filename); + + + if ((fp = fopen(data_file, "r")) == (FILE *)NULL) { + error_msg(progname, "cannot open options file %s\n", filename); + exit(1); + } + + /* cycle until end of file reached */ + while( 1 ) + { + rc=fscanf(fp, "%s", stype); + if (rc==-1) + break; + + /*------------------------------------------------------------------------- + * filter + *------------------------------------------------------------------------- + */ + if (strcmp(stype,"-f") == 0) { + + /* find begining of info */ + i=0; c='0'; + while( c!=' ' ) + { + fscanf(fp, "%c", &c); + if (feof(fp)) break; + } + c='0'; + /* go until end */ + while( c!=' ' ) + { + fscanf(fp, "%c", &c); + comp_info[i]=c; + i++; + if (feof(fp)) break; + if (c==10 /*eol*/) break; + } + comp_info[i-1]='\0'; /*cut the last " */ + + if (h5repack_addfilter(comp_info,options)==-1){ + error_msg(progname, "could not add compression option\n"); + exit(1); + } + } + /*------------------------------------------------------------------------- + * layout + *------------------------------------------------------------------------- + */ + else if (strcmp(stype,"-l") == 0) { + + /* find begining of info */ + i=0; c='0'; + while( c!=' ' ) + { + fscanf(fp, "%c", &c); + if (feof(fp)) break; + } + c='0'; + /* go until end */ + while( c!=' ' ) + { + fscanf(fp, "%c", &c); + comp_info[i]=c; + i++; + if (feof(fp)) break; + if (c==10 /*eol*/) break; + } + comp_info[i-1]='\0'; /*cut the last " */ + + if (h5repack_addlayout(comp_info,options)==-1){ + error_msg(progname, "could not add chunck option\n"); + exit(1); + } + } + /*------------------------------------------------------------------------- + * not valid + *------------------------------------------------------------------------- + */ + else { + error_msg(progname, "bad file format for %s", filename); + exit(1); + } + } + + fclose(fp); + return; +} -- cgit v0.12