2003-10-23 05:43:34 +08:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* Copyright by the Board of Trustees of the University of Illinois. *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
|
|
|
* This file is part of HDF5. The full HDF5 copyright notice, including *
|
|
|
|
* terms governing use, modification, and redistribution, is contained in *
|
|
|
|
* the files COPYING and Copyright.html. COPYING can be found at the root *
|
|
|
|
* of the source code distribution tree; Copyright.html can be found at the *
|
|
|
|
* root level of an installed copy of the electronic HDF5 document set and *
|
|
|
|
* is linked from the top-level documents page. It can also be found at *
|
|
|
|
* http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have *
|
|
|
|
* access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *
|
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
2003-10-24 03:51:51 +08:00
|
|
|
#include "H5private.h"
|
2003-10-23 05:43:34 +08:00
|
|
|
#include "h5repack.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2003-12-05 03:35:33 +08:00
|
|
|
* Function: check_objects
|
2003-10-23 05:43:34 +08:00
|
|
|
*
|
2003-12-05 03:35:33 +08:00
|
|
|
* Purpose: locate all HDF5 objects in the file and compare with user
|
|
|
|
* supplied list
|
2003-10-23 05:43:34 +08:00
|
|
|
*
|
|
|
|
* Return: 0, ok, -1 no
|
|
|
|
*
|
2004-07-16 03:25:27 +08:00
|
|
|
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
|
2003-10-23 05:43:34 +08:00
|
|
|
*
|
|
|
|
* Date: September, 23, 2003
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2005-08-14 04:53:35 +08:00
|
|
|
int check_objects(const char* fname,
|
2006-03-28 04:09:01 +08:00
|
|
|
pack_opt_t *options,
|
|
|
|
int argc,
|
|
|
|
const char *argv[])
|
2003-10-23 05:43:34 +08:00
|
|
|
{
|
2005-08-14 04:53:35 +08:00
|
|
|
hid_t fid;
|
2003-12-19 04:25:11 +08:00
|
|
|
int i;
|
|
|
|
trav_table_t *travt=NULL;
|
2003-10-23 05:43:34 +08:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2005-08-14 04:53:35 +08:00
|
|
|
* open the file
|
2003-10-23 05:43:34 +08:00
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2006-03-28 04:09:01 +08:00
|
|
|
if ((fid=h5tools_fopen(fname, NULL, NULL, 0, argc, argv))<0){
|
|
|
|
printf("<%s>: %s\n", fname, H5FOPENERROR );
|
|
|
|
return -1;
|
2003-10-23 05:43:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* get the list of objects in the file
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2003-12-19 04:25:11 +08:00
|
|
|
/* init table */
|
|
|
|
trav_table_init(&travt);
|
|
|
|
|
|
|
|
/* get the list of objects in the file */
|
|
|
|
if (h5trav_gettable(fid,travt)<0)
|
|
|
|
goto out;
|
2003-10-23 05:43:34 +08:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* compare with user supplied list
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-10-23 05:43:34 +08:00
|
|
|
if (options->verbose)
|
2004-04-07 02:30:30 +08:00
|
|
|
{
|
2003-10-23 05:43:34 +08:00
|
|
|
printf("Opening file <%s>. Searching for objects to modify...\n",fname);
|
2004-04-07 02:30:30 +08:00
|
|
|
}
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
|
|
for ( i = 0; i < options->op_tbl->nelems; i++)
|
2003-10-23 05:43:34 +08:00
|
|
|
{
|
2003-12-19 04:25:11 +08:00
|
|
|
char* name=options->op_tbl->objs[i].path;
|
2003-10-23 05:43:34 +08:00
|
|
|
if (options->verbose)
|
2004-07-14 03:09:41 +08:00
|
|
|
printf(" <%s>",name);
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-10-23 05:43:34 +08:00
|
|
|
/* the input object names are present in the file and are valid */
|
2003-12-19 04:25:11 +08:00
|
|
|
if (h5trav_getindext(name,travt)<0)
|
2003-10-23 05:43:34 +08:00
|
|
|
{
|
2004-07-16 03:25:27 +08:00
|
|
|
printf("%sError: Could not find <%s> in file <%s>. Exiting...\n",
|
|
|
|
(options->verbose?"\n":""),name,fname);
|
2003-12-19 04:25:11 +08:00
|
|
|
goto out;
|
2003-10-23 05:43:34 +08:00
|
|
|
}
|
|
|
|
if (options->verbose)
|
|
|
|
printf("...Found\n");
|
2004-08-20 03:09:13 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* check for extra filter conditions */
|
|
|
|
switch (options->op_tbl->objs[i].filter->filtn)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* chunk size must be smaller than pixels per block */
|
|
|
|
case H5Z_FILTER_SZIP:
|
|
|
|
{
|
|
|
|
int j;
|
|
|
|
int csize=1;
|
|
|
|
int ppb=options->op_tbl->objs[i].filter->cd_values[0];
|
|
|
|
hsize_t dims[H5S_MAX_RANK];
|
|
|
|
int rank;
|
2005-08-14 04:53:35 +08:00
|
|
|
hid_t did;
|
|
|
|
hid_t sid;
|
2004-08-20 03:09:13 +08:00
|
|
|
|
|
|
|
if (options->op_tbl->objs[i].chunk.rank>0)
|
|
|
|
{
|
|
|
|
rank=options->op_tbl->objs[i].chunk.rank;
|
2005-08-14 04:53:35 +08:00
|
|
|
for (j=0; j<rank; j++)
|
2004-08-20 03:09:13 +08:00
|
|
|
csize*=(int)options->op_tbl->objs[i].chunk.chunk_lengths[j];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-08-14 04:53:35 +08:00
|
|
|
if ((did=H5Dopen(fid,travt->objs[i].name))<0)
|
2004-08-20 03:09:13 +08:00
|
|
|
goto out;
|
2005-08-14 04:53:35 +08:00
|
|
|
if ((sid=H5Dget_space(did))<0)
|
2004-08-20 03:09:13 +08:00
|
|
|
goto out;
|
|
|
|
if ( (rank=H5Sget_simple_extent_ndims(sid))<0)
|
|
|
|
goto out;
|
|
|
|
HDmemset(dims, 0, sizeof dims);
|
|
|
|
if ( H5Sget_simple_extent_dims(sid,dims,NULL)<0)
|
|
|
|
goto out;
|
2005-08-14 04:53:35 +08:00
|
|
|
for (j=0; j<rank; j++)
|
2004-08-20 03:09:13 +08:00
|
|
|
csize*=(int)dims[j];
|
2005-08-14 04:53:35 +08:00
|
|
|
if (H5Sclose(sid)<0)
|
2004-08-20 03:09:13 +08:00
|
|
|
goto out;
|
2005-08-14 04:53:35 +08:00
|
|
|
if (H5Dclose(did)<0)
|
2004-08-20 03:09:13 +08:00
|
|
|
goto out;
|
2005-08-14 04:53:35 +08:00
|
|
|
}
|
|
|
|
|
2004-08-20 03:09:13 +08:00
|
|
|
if (csize < ppb )
|
|
|
|
{
|
2006-04-07 05:14:01 +08:00
|
|
|
printf(" <warning: SZIP settins, chunk size is smaller than pixels per block>\n");
|
2004-08-20 03:09:13 +08:00
|
|
|
goto out;
|
|
|
|
}
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
|
|
|
2004-08-20 03:09:13 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} /* i */
|
2003-10-23 05:43:34 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
2003-12-19 04:25:11 +08:00
|
|
|
* close
|
2003-10-23 05:43:34 +08:00
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
H5Fclose(fid);
|
2003-12-19 04:25:11 +08:00
|
|
|
trav_table_free(travt);
|
2003-10-23 05:43:34 +08:00
|
|
|
return 0;
|
2003-12-19 04:25:11 +08:00
|
|
|
|
|
|
|
out:
|
|
|
|
H5Fclose(fid);
|
|
|
|
trav_table_free(travt);
|
|
|
|
return -1;
|
2003-10-24 03:51:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: print_objlist
|
|
|
|
*
|
|
|
|
* Purpose: print list of objects in file
|
|
|
|
*
|
|
|
|
* Return: void
|
|
|
|
*
|
2004-07-16 03:25:27 +08:00
|
|
|
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
|
2003-10-24 03:51:51 +08:00
|
|
|
*
|
|
|
|
* Date: October 23, 2003
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2005-08-14 04:53:35 +08:00
|
|
|
void print_objlist(const char *filename,
|
|
|
|
int nobjects,
|
2003-10-29 01:40:05 +08:00
|
|
|
trav_info_t *info )
|
2003-10-24 03:51:51 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
printf("File <%s>: # of entries = %d\n", filename, nobjects );
|
|
|
|
for ( i = 0; i < nobjects; i++)
|
|
|
|
{
|
|
|
|
switch ( info[i].type )
|
|
|
|
{
|
|
|
|
case H5G_GROUP:
|
2003-10-30 01:46:11 +08:00
|
|
|
printf(" %-10s %s\n", "group", info[i].name );
|
2003-10-24 03:51:51 +08:00
|
|
|
break;
|
|
|
|
case H5G_DATASET:
|
2003-10-30 01:46:11 +08:00
|
|
|
printf(" %-10s %s\n", "dataset", info[i].name );
|
2003-10-24 03:51:51 +08:00
|
|
|
break;
|
|
|
|
case H5G_TYPE:
|
2003-10-30 01:46:11 +08:00
|
|
|
printf(" %-10s %s\n", "datatype", info[i].name );
|
2003-10-24 03:51:51 +08:00
|
|
|
break;
|
|
|
|
case H5G_LINK:
|
2003-10-30 01:46:11 +08:00
|
|
|
printf(" %-10s %s\n", "link", info[i].name );
|
2003-10-24 03:51:51 +08:00
|
|
|
break;
|
|
|
|
default:
|
2003-10-30 01:46:11 +08:00
|
|
|
printf(" %-10s %s\n", "User defined object", info[i].name );
|
2003-10-24 03:51:51 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|