hdf5/tools/h5ls.c
Robb Matzke a34534c9b8 [svn-r546] Changes since 19980724
----------------------

./MANIFEST
./doc/html/H5.format.html
./src/H5O.c
./src/H5Oprivate.h
./src/H5Omtime.c	[NEW]
./src/H5private.h
./src/Makefile.in
	Added the modification time message.  If an object header has
	this message then it's value is updated with the current time
	whenever anything changes in the object header.

./acconfig.h
./configure.in
	Alas, there seems to be no standard way to convert a string
	time like 19980727122800 in UTC to a time_t since mktime()
	only converts local times to time_t.  So I've modified the
	configuration to check for various ways of getting the time
	zone information:

	   * Added checks for the `tm_gmtoff' field of `struct tm'.
	   * Added a check for the `timezone' global variable.
	   * Added a check for `struct timezone'.
	   * Added a check for BSDgettimeofday().
	   * Added a check for gettimeofday() although it doesn't
	     actually set the timezone argument on some systems.
	   * Added a check to see if `tm_zone' is a member of `struct tm'.
	   * Added a check to see if `tzname' is a global variable.
	   * Added a check to see if `struct tm' is defined in time.h
	     or sys/time.h.

	It's not difficult to get the right UTC modification message
	into the object header, but some systems might have problems
	getting the right time back out (Irix64 is one) and those
	systems will report zero for the H5G_stat_t.mtime from an
	H5Gstat() call as if the mtime message isn't even present.  It
	will, however, continue to be updated as normal.

./src/H5G.c
./src/H5Gpublic.h
	The H5G_stat_t struct now contains an `mtime' field which will
	hold the object modification time.  If the object has no
	object modification time then the `mtime' will be initialized
	to zero.

	Fixed a bug in H5G_stat() that caused the `objno' field of the
	H5G_stat_t to be set incorrectly on some machines.

./src/H5D.c
	Writing to external datasets fail if the hdf5 file is not open
	for writing.

	A modification time message is added to the dataset object
	header when it's created and H5O_touch() is called from
	H5D_write() to update that message.

./src/H5T.c
	Fixed a bug in H5Tget_member_dims() that caused a segmentation
	fault if one of the output array arguments was the null
	pointer.

	Relaxed the member dimension checking in H5Tinsert_array() so
	it can also be used for scalar members.

./test/Makefile.in
	Added additional file names to the `mostlyclean' target.

./tools/h5dump.c
./tools/h5tools.h
	Increased the temporary buffer size to 1MB.

	Added support for printing compound data types with array
	members.

	When printing H5T_NATIVE_CHAR and H5T_NATIVE_UCHAR we escape
	double quote characters.

./tools/h5ls.c
	Changed the output format a little because we were starting to
	get too much info to fit on a line.  Without `--verbose' each
	object occupies one line of output.  Otherwise, additional
	information is printed below the object name: object file
	address, comment, and modification time.  If `--dump' is given
	then the data is printed after the other information.

./test/cmpd_dset.c
	Changed the way the dataset is initialized to be more uniform.
1998-07-29 11:43:59 -05:00

381 lines
9.2 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* Copyright (C) 1998 NCSA
* All rights reserved.
*
* Programmer: Robb Matzke <matzke@llnl.gov>
* Monday, March 23, 1998
*/
#include <ctype.h>
#include <h5tools.h>
#include <hdf5.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <H5private.h>
#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;
/*-------------------------------------------------------------------------
* 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 [GROUP]\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\
GROUP\n\
If a group name is not specified then the contents of the root group\n\
\"/\" are 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 ("%*s%s", 26, "", attr_name);
if ((attr = H5Aopen_name (obj, attr_name))) {
hid_t space = H5Aget_space (attr);
hsize_t size[64];
int ndims = H5Sextent_dims (space, size, NULL);
H5Sclose (space);
printf (" {");
for (i=0; i<ndims; i++) {
HDfprintf (stdout, "%s%Hu", i?", ":"", size[i]);
}
putchar ('}');
H5Aclose (attr);
}
putchar ('\n');
return 0;
}
/*-------------------------------------------------------------------------
* Function: list
*
* Purpose: Prints the group member name.
*
* Return: Success: 0
*
* Failure: -1
*
* Programmer: Robb Matzke
* Monday, March 23, 1998
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static herr_t
list (hid_t group, const char *name, void __unused__ *op_data)
{
hid_t obj;
hid_t (*func)(void*);
void *edata;
int i;
char buf[512], comment[50];
H5G_stat_t statbuf;
struct tm *tm;
/* Disable error reporting */
H5Eget_auto (&func, &edata);
H5Eset_auto (NULL, NULL);
/* Print info about each name */
printf ("%-25s ", name);
if ((obj=H5Dopen (group, name))>=0) {
hsize_t size[64];
hsize_t maxsize[64];
hid_t space = H5Dget_space (obj);
int ndims = H5Sextent_dims(space, size, maxsize);
printf ("Dataset {");
for (i=0; i<ndims; i++) {
HDfprintf (stdout, "%s%Hu", i?", ":"", size[i]);
if (maxsize[i]==H5S_UNLIMITED) {
HDfprintf (stdout, "/%s", "Inf");
} else if (maxsize[i]!=size[i] || verbose_g>0) {
HDfprintf(stdout, "/%Hu", maxsize[i]);
}
}
printf ("}\n");
H5Dclose (space);
H5Aiterate (obj, NULL, list_attr, NULL);
H5Dclose (obj);
} else if ((obj=H5Gopen (group, name))>=0) {
printf ("Group\n");
H5Aiterate (obj, NULL, list_attr, NULL);
H5Gclose (obj);
} else if (H5Gget_linkval (group, name, sizeof(buf), buf)>=0) {
if (NULL==HDmemchr (buf, 0, sizeof(buf))) {
strcpy (buf+sizeof(buf)-4, "...");
}
printf (" -> %s\n", buf);
} else if ((obj=H5Topen (group, name))>=0) {
printf ("Data type\n");
H5Aiterate (obj, NULL, list_attr, NULL);
H5Tclose (obj);
} else {
printf ("Unknown Type\n");
}
if (verbose_g>0) {
if (H5Gstat(group, name, TRUE, &statbuf)>=0) {
printf(" %-10s %lu:%lu:%lu:%lu\n",
"Location:", statbuf.fileno[1], statbuf.fileno[0],
statbuf.objno[1], statbuf.objno[0]);
if (statbuf.mtime>0 && NULL!=(tm = localtime(&(statbuf.mtime)))) {
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S %Z", tm);
printf(" %-10s %s\n", "Modtime:", buf);
}
}
/* Display the comment if the object has one */
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 (dump_g && (obj=H5Dopen(group, name))) {
/* Turn on error reporting before dumping the data */
H5Eset_auto(func, edata);
dump_dataset_values(obj);
H5Dclose(obj);
}
/* Restore error reporting */
H5Eset_auto (func, edata);
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;
const char *fname = NULL;
const char *gname = "/";
const char *progname;
const char *s;
char *rest;
int argno;
/* 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 && '-'==argv[argno][0]; argno++) {
if (!strcmp(argv[argno], "--")) {
/* Last switch */
argno++;
break;
} else if (!strcmp(argv[argno], "--help")) {
usage(progname);
exit(0);
} else if (!strcmp(argv[argno], "--dump")) {
dump_g++;
} else if (!strncmp(argv[argno], "--width=", 8)) {
width_g = strtol(argv[argno]+8, &rest, 0);
if (width_g<=0 || *rest) {
usage(progname);
exit(1);
}
} else if (!strcmp(argv[argno], "--verbose")) {
verbose_g++;
} else if (!strcmp(argv[argno], "--version")) {
printf("This is %s version %u.%u release %u\n",
progname, H5_VERS_MAJOR, H5_VERS_MINOR, H5_VERS_RELEASE);
exit(0);
} else if (!strncmp(argv[argno], "-w", 2)) {
if (argv[argno][2]) {
s = argv[argno]+2;
} else if (argno+1>=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);
}
}
/* Non-switch arguments */
if (argno<argc) {
fname = argv[argno++];
} else {
usage(progname);
exit(1);
}
if (argno<argc) gname = argv[argno++];
if (argno<argc) {
usage(progname);
exit(1);
}
/*
* Open the file. If the file name contains a `%' then assume that a
* file family is being opened.
*/
if (strchr (fname, '%')) {
plist = H5Pcreate (H5P_FILE_ACCESS);
H5Pset_family (plist, 0, H5P_DEFAULT);
}
if ((file = H5Fopen (fname, H5F_ACC_RDONLY, plist))<0) exit (1);
if (H5Giterate (file, gname, NULL, list, NULL)<0) exit (1);
if (H5Fclose (file)<0) exit (1);
return 0;
}