/* * Copyright (C) 1998 NCSA * All rights reserved. * * Programmer: Robb Matzke * Monday, March 23, 1998 */ #include #include #include #include #include #include #include #ifndef HAVE_ATTRIBUTE # undef __attribute__ # define __attribute__(X) /*void*/ # define __unused__ /*void*/ #else # define __unused__ __attribute__((unused)) #endif /* Command-line switches */ static int verbose_g = 0; static int dump_g = 0; static int width_g = 80; /* Information about how to display each type of object */ static struct dispatch_t { const char *name; hid_t (*open)(hid_t loc, const char *name); herr_t (*close)(hid_t obj); herr_t (*list1)(hid_t obj); herr_t (*list2)(hid_t obj); } dispatch_g[H5G_NTYPES]; #define DISPATCH(TYPE,NAME,OPEN,CLOSE,LIST1,LIST2) { \ dispatch_g[TYPE].name = (NAME); \ dispatch_g[TYPE].open = (OPEN); \ dispatch_g[TYPE].close = (CLOSE); \ dispatch_g[TYPE].list1 = (LIST1); \ dispatch_g[TYPE].list2 = (LIST2); \ } static herr_t list (hid_t group, const char *name, void *cd); /*------------------------------------------------------------------------- * Function: usage * * Purpose: Prints a usage message on stderr and then returns. * * Return: void * * Programmer: Robb Matzke * Thursday, July 16, 1998 * * Modifications: * *------------------------------------------------------------------------- */ static void usage (const char *progname) { fprintf(stderr, "\ usage: %s [OPTIONS] FILE [OBJECTS...]\n\ OPTIONS\n\ -h, -?, --help Print a usage message and exit\n\ -d, --dump Print the values of datasets\n\ -wN, --width=N Set the number of columns of output\n\ -v, --verbose Generate more verbose output\n\ -V, --version Print version number and exit\n\ FILE\n\ The file name may include a printf(3C) integer format such as\n\ \"%%05d\" to open a file family.\n\ OBJECTS\n\ The names of zero or more objects about which information should be\n\ displayed. If a group is mentioned then information about each of its\n\ members is displayed. If no object names are specified then\n\ information about all of the objects in the root group is displayed.\n", progname); } /*------------------------------------------------------------------------- * Function: dump_dataset_values * * Purpose: Prints all values of a dataset. * * Return: void * * Programmer: Robb Matzke * Tuesday, July 21, 1998 * * Modifications: * *------------------------------------------------------------------------- */ static void dump_dataset_values(hid_t dset) { hid_t f_type = H5Dget_type(dset); size_t size = H5Tget_size(f_type); h5dump_t info; /* Set to all default values and then override */ memset(&info, 0, sizeof info); info.idx_fmt = " (%s) "; info.line_ncols = width_g; if (verbose_g) info.cmpd_name = "%s="; /* * If the dataset is a 1-byte integer type then format it as an ASCI * character string instead of integers. */ if (1==size && H5T_INTEGER==H5Tget_class(f_type)) { info.elmt_suf1 = ""; info.elmt_suf2 = ""; info.idx_fmt = " (%s) \""; info.line_suf = "\""; } /* * Print all the values. */ printf(" Data:\n"); if (h5dump(stdout, &info, dset, -1)<0) { printf(" Unable to print data.\n"); } H5Tclose(f_type); } /*------------------------------------------------------------------------- * Function: list_attr * * Purpose: Prints information about attributes. * * Return: Success: 0 * * Failure: -1 * * Programmer: Robb Matzke * Friday, June 5, 1998 * * Modifications: * *------------------------------------------------------------------------- */ static herr_t list_attr (hid_t obj, const char *attr_name, void __unused__ *op_data) { hid_t attr; int i; printf(" %-10s %-10s", "Attribute:", attr_name); if ((attr = H5Aopen_name (obj, attr_name))) { hid_t space = H5Aget_space (attr); hsize_t size[64]; int ndims = H5Sget_simple_extent_dims (space, size, NULL); H5Sclose (space); printf (" {"); for (i=0; i0) { HDfprintf(stdout, "/%Hu", max_size[i]); } } putchar('}'); H5Sclose (space); return 0; } /*------------------------------------------------------------------------- * Function: dataset_list2 * * Purpose: List information about a dataset which should appear after * information which is general to all objects. * * Return: Success: 0 * * Failure: -1 * * Programmer: Robb Matzke * Thursday, August 27, 1998 * * Modifications: * *------------------------------------------------------------------------- */ static herr_t dataset_list2(hid_t dset) { hid_t dcpl; /*dataset creation property list*/ int nf; /*number of filters */ unsigned filt_flags; /*filter flags */ H5Z_filter_t filt_id; /*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[32]; /*filter name */ char s[64]; /*temporary string buffer */ int i; if (verbose_g>0) { dcpl = H5Dget_create_plist(dset); /* Print information about raw data filters */ if ((nf = H5Pget_nfilters(dcpl))>0) { for (i=0; i=H5G_NTYPES) { printf("Unknown type(%d)\n", sb.type); return 0; } if (dispatch_g[sb.type].name) fputs(dispatch_g[sb.type].name, stdout); /* * Open the object. Not all objects can be opened. If this is the case * then return right away. */ if (NULL==dispatch_g[sb.type].open || (obj=(dispatch_g[sb.type].open)(group, name))<0) return 0; /* * List the first line of information for the object. */ if (dispatch_g[sb.type].list1) (dispatch_g[sb.type].list1)(obj); putchar('\n'); /* * Show detailed information about the object, beginning with information * which is common to all objects. */ if (verbose_g>0) { H5Aiterate(obj, NULL, list_attr, NULL); printf(" %-10s %lu:%lu:%lu:%lu\n", "Location:", sb.fileno[1], sb.fileno[0], sb.objno[1], sb.objno[0]); printf(" %-10s %u\n", "Links:", sb.nlink); if (sb.mtime>0 && NULL!=(tm=localtime(&(sb.mtime)))) { strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S %Z", tm); printf(" %-10s %s\n", "Modtime:", buf); } comment[0] = '\0'; H5Gget_comment(group, name, sizeof(comment), comment); strcpy(comment+sizeof(comment)-4, "..."); if (comment[0]) printf(" %-10s %s\n", "Comment:", comment); } if (dispatch_g[sb.type].list2) (dispatch_g[sb.type].list2)(obj); /* * Close the object. */ (dispatch_g[sb.type].close)(obj); return 0; } /*------------------------------------------------------------------------- * Function: main * * Purpose: Opens a file and lists the specified group * * Return: Success: 0 * * Failure: 1 * * Programmer: Robb Matzke * Monday, March 23, 1998 * * Modifications: * *------------------------------------------------------------------------- */ int main (int argc, char *argv[]) { hid_t file, plist=H5P_DEFAULT, root; const char *fname = NULL; const char *progname; const char *s; char *rest; int argno; DISPATCH(H5G_DATASET, "Dataset", H5Dopen, H5Dclose, dataset_list1, dataset_list2); DISPATCH(H5G_GROUP, "Group", H5Gopen, H5Gclose, NULL, NULL); DISPATCH(H5G_TYPE, "Type", H5Topen, H5Tclose, NULL, NULL); DISPATCH(H5G_LINK, "-> ", link_open, NULL, NULL, NULL); /* Name of this program without the path */ if ((progname=strrchr (argv[0], '/'))) progname++; else progname = argv[0]; /* Switches come before non-switch arguments */ for (argno=1; argno=argc) { usage(progname); exit(1); } else { s = argv[++argno]; } width_g = strtol(s, &rest, 0); if (width_g<=0 || *rest) { usage(progname); exit(1); } } else if ('-'!=argv[argno][1]) { /* Single-letter switches */ for (s=argv[argno]+1; *s; s++) { switch (*s) { case '?': case 'h': /* --help */ usage(progname); exit(0); case 'd': /* --dump */ dump_g++; break; case 'v': /* --verbose */ verbose_g++; break; case 'V': /* --version */ printf("This is %s version %u.%u release %u\n", progname, H5_VERS_MAJOR, H5_VERS_MINOR, H5_VERS_RELEASE); exit(0); default: usage(progname); exit(1); } } } else { usage(progname); exit(1); } } /* * The first non-switch argument is a file name. If the file name * contains a `%' then assume that a file family is being opened. */ if (argno=argc) { H5Giterate(file, "/", NULL, list, NULL); } else { for (/*void*/; argno=0) { H5Giterate(file, argv[argno], NULL, list, NULL); } else if ((root=H5Gopen(file, "/"))<0) { exit(1); } else { list(root, argv[argno], NULL); } if (H5Gclose(root)<0) exit(1); } } if (H5Fclose(file)<0) exit(1); return 0; }