2016-10-27 23:06:00 +08:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* Copyright by The HDF Group. *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
|
|
|
* This file is part of HDF5. The full HDF5 copyright notice, including *
|
|
|
|
* terms governing use, modification, and redistribution, is contained in *
|
2017-04-18 03:32:16 +08:00
|
|
|
* the COPYING file, which can be found at the root of the source code *
|
2021-02-17 22:52:36 +08:00
|
|
|
* distribution tree, or in https://www.hdfgroup.org/licenses. *
|
2017-04-18 03:32:16 +08:00
|
|
|
* If you do not have access to either file, you may request a copy from *
|
|
|
|
* help@hdfgroup.org. *
|
2016-10-27 23:06:00 +08:00
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
|
|
|
#include "hdf5.h"
|
|
|
|
#include "H5private.h"
|
|
|
|
#include "h5tools.h"
|
|
|
|
#include "h5tools_utils.h"
|
|
|
|
|
|
|
|
/* Name of tool */
|
|
|
|
#define PROGRAMNAME "tellub"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Command-line options: The user can specify short or long-named
|
|
|
|
* parameters. The long-named ones can be partially spelled. When
|
|
|
|
* adding more, make sure that they don't clash with each other.
|
|
|
|
*/
|
2022-07-27 05:45:46 +08:00
|
|
|
static const char *s_opts = "h";
|
2021-06-30 04:06:48 +08:00
|
|
|
static struct h5_long_options l_opts[] = {{"help", no_arg, 'h'}, {"hel", no_arg, 'h'}, {NULL, 0, '\0'}};
|
2016-10-27 23:06:00 +08:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: usage
|
|
|
|
*
|
|
|
|
* Purpose: Print the usage message
|
|
|
|
*
|
|
|
|
* Return: void
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static void
|
2020-09-30 22:27:10 +08:00
|
|
|
usage(const char *prog)
|
2016-10-27 23:06:00 +08:00
|
|
|
{
|
2018-09-19 13:57:37 +08:00
|
|
|
HDfflush(stdout);
|
2023-06-28 23:31:32 +08:00
|
|
|
fprintf(stdout, "usage: %s h5_file\n", prog);
|
|
|
|
fprintf(stdout, " Check that h5_fil is HDF5 file and print size of user block \n");
|
|
|
|
fprintf(stdout, " %s -h\n", prog);
|
|
|
|
fprintf(stdout, " Print a usage message and exit\n");
|
2018-09-19 13:57:37 +08:00
|
|
|
} /* end usage() */
|
2016-10-27 23:06:00 +08:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: parse_command_line
|
|
|
|
*
|
2019-01-01 02:37:58 +08:00
|
|
|
* Purpose: Parse the command line.
|
2016-10-27 23:06:00 +08:00
|
|
|
*
|
2018-09-19 13:57:37 +08:00
|
|
|
* Return: Success: void
|
2016-10-27 23:06:00 +08:00
|
|
|
* Failure: Exits program with EXIT_FAILURE value.
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2022-01-29 06:30:33 +08:00
|
|
|
parse_command_line(int argc, const char *const *argv)
|
2016-10-27 23:06:00 +08:00
|
|
|
{
|
2018-09-19 13:57:37 +08:00
|
|
|
int opt;
|
|
|
|
|
|
|
|
/* parse command line options */
|
2021-06-30 04:06:48 +08:00
|
|
|
while ((opt = H5_get_option(argc, argv, s_opts, l_opts)) != EOF) {
|
2020-09-30 22:27:10 +08:00
|
|
|
switch ((char)opt) {
|
2018-09-19 13:57:37 +08:00
|
|
|
case 'h':
|
2020-09-30 22:27:10 +08:00
|
|
|
usage(h5tools_getprogname());
|
2020-07-16 00:20:16 +08:00
|
|
|
h5tools_setstatus(EXIT_SUCCESS);
|
2020-07-31 20:49:48 +08:00
|
|
|
break;
|
2018-09-19 13:57:37 +08:00
|
|
|
case '?':
|
|
|
|
default:
|
2020-09-30 22:27:10 +08:00
|
|
|
usage(h5tools_getprogname());
|
2020-07-16 00:20:16 +08:00
|
|
|
h5tools_setstatus(EXIT_FAILURE);
|
2018-09-19 13:57:37 +08:00
|
|
|
}
|
2016-10-27 23:06:00 +08:00
|
|
|
}
|
|
|
|
|
2018-09-19 13:57:37 +08:00
|
|
|
/* check for file name to be processed */
|
2021-06-30 04:06:48 +08:00
|
|
|
if (argc <= H5_optind) {
|
2018-09-19 13:57:37 +08:00
|
|
|
error_msg("missing file name\n");
|
2020-09-30 22:27:10 +08:00
|
|
|
usage(h5tools_getprogname());
|
2020-07-16 00:20:16 +08:00
|
|
|
h5tools_setstatus(EXIT_FAILURE);
|
2016-10-27 23:06:00 +08:00
|
|
|
}
|
2018-09-19 13:57:37 +08:00
|
|
|
} /* end parse_command_line() */
|
2016-10-27 23:06:00 +08:00
|
|
|
|
2020-07-16 00:20:16 +08:00
|
|
|
static void
|
|
|
|
leave(int ret)
|
|
|
|
{
|
2020-09-30 22:27:10 +08:00
|
|
|
h5tools_close();
|
2023-06-29 23:18:01 +08:00
|
|
|
exit(ret);
|
2020-07-16 00:20:16 +08:00
|
|
|
}
|
|
|
|
|
2016-10-27 23:06:00 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: main
|
|
|
|
*
|
2019-01-01 02:37:58 +08:00
|
|
|
* Purpose: HDF5 user block tell size
|
2016-10-27 23:06:00 +08:00
|
|
|
*
|
2018-09-19 13:57:37 +08:00
|
|
|
* Return: EXIT_SUCCESS/EXIT_FAILURE
|
2016-10-27 23:06:00 +08:00
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
int
|
2022-01-29 06:30:33 +08:00
|
|
|
main(int argc, char *argv[])
|
2016-10-27 23:06:00 +08:00
|
|
|
{
|
2022-07-27 05:45:46 +08:00
|
|
|
char *ifname;
|
2020-09-30 22:27:10 +08:00
|
|
|
hid_t ifile = H5I_INVALID_HID;
|
2018-09-19 13:57:37 +08:00
|
|
|
hsize_t usize;
|
2020-09-30 22:27:10 +08:00
|
|
|
htri_t testval;
|
|
|
|
herr_t status;
|
|
|
|
hid_t plist = H5I_INVALID_HID;
|
2018-09-19 13:57:37 +08:00
|
|
|
|
|
|
|
h5tools_setprogname(PROGRAMNAME);
|
|
|
|
h5tools_setstatus(EXIT_SUCCESS);
|
|
|
|
|
|
|
|
/* Initialize h5tools lib */
|
|
|
|
h5tools_init();
|
|
|
|
|
2022-01-29 06:30:33 +08:00
|
|
|
parse_command_line(argc, (const char *const *)argv);
|
2018-09-19 13:57:37 +08:00
|
|
|
|
2020-07-16 00:20:16 +08:00
|
|
|
/* enable error reporting if command line option */
|
|
|
|
h5tools_error_report();
|
|
|
|
|
2021-06-30 04:06:48 +08:00
|
|
|
if (argc <= (H5_optind)) {
|
2018-09-19 13:57:37 +08:00
|
|
|
error_msg("missing file name\n");
|
2020-09-30 22:27:10 +08:00
|
|
|
usage(h5tools_getprogname());
|
2020-07-16 00:20:16 +08:00
|
|
|
h5tools_setstatus(EXIT_FAILURE);
|
|
|
|
goto done;
|
2016-10-27 23:06:00 +08:00
|
|
|
}
|
|
|
|
|
2021-06-30 04:06:48 +08:00
|
|
|
ifname = HDstrdup(argv[H5_optind]);
|
2016-10-27 23:06:00 +08:00
|
|
|
|
2018-10-10 23:10:15 +08:00
|
|
|
testval = H5Fis_accessible(ifname, H5P_DEFAULT);
|
2016-10-27 23:06:00 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
if (testval <= 0) {
|
2018-09-19 13:57:37 +08:00
|
|
|
error_msg("Input HDF5 file is not HDF \"%s\"\n", ifname);
|
2020-07-16 00:20:16 +08:00
|
|
|
h5tools_setstatus(EXIT_FAILURE);
|
|
|
|
goto done;
|
2016-10-27 23:06:00 +08:00
|
|
|
}
|
|
|
|
|
2018-09-19 13:57:37 +08:00
|
|
|
ifile = H5Fopen(ifname, H5F_ACC_RDONLY, H5P_DEFAULT);
|
2016-10-27 23:06:00 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
if (ifile < 0) {
|
2018-09-19 13:57:37 +08:00
|
|
|
error_msg("Can't open input HDF5 file \"%s\"\n", ifname);
|
2020-07-16 00:20:16 +08:00
|
|
|
h5tools_setstatus(EXIT_FAILURE);
|
|
|
|
goto done;
|
2016-10-27 23:06:00 +08:00
|
|
|
}
|
|
|
|
|
2018-09-19 13:57:37 +08:00
|
|
|
plist = H5Fget_create_plist(ifile);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (plist < 0) {
|
2018-09-19 13:57:37 +08:00
|
|
|
error_msg("Can't get file creation plist for file \"%s\"\n", ifname);
|
2020-07-16 00:20:16 +08:00
|
|
|
h5tools_setstatus(EXIT_FAILURE);
|
|
|
|
goto done;
|
2016-10-27 23:06:00 +08:00
|
|
|
}
|
|
|
|
|
2018-09-19 13:57:37 +08:00
|
|
|
status = H5Pget_userblock(plist, &usize);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (status < 0) {
|
2018-09-19 13:57:37 +08:00
|
|
|
error_msg("Can't get user block for file \"%s\"\n", ifname);
|
2020-07-16 00:20:16 +08:00
|
|
|
h5tools_setstatus(EXIT_FAILURE);
|
|
|
|
goto done;
|
2016-10-27 23:06:00 +08:00
|
|
|
}
|
|
|
|
|
2023-06-28 23:31:32 +08:00
|
|
|
printf("%ld\n", (long)usize);
|
2016-10-27 23:06:00 +08:00
|
|
|
|
2020-07-16 00:20:16 +08:00
|
|
|
done:
|
2020-09-30 22:27:10 +08:00
|
|
|
H5Pclose(plist);
|
|
|
|
if (ifile >= 0)
|
|
|
|
H5Fclose(ifile);
|
2016-10-27 23:06:00 +08:00
|
|
|
|
2020-07-16 00:20:16 +08:00
|
|
|
leave(h5tools_getstatus());
|
2018-09-19 13:57:37 +08:00
|
|
|
} /* end main() */
|