2003-09-20 03:33:41 +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. *
|
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
2003-10-23 05:43:34 +08:00
|
|
|
#include <stdlib.h>
|
2006-01-24 22:48:36 +08:00
|
|
|
#include <string.h>
|
2006-10-05 22:35:40 +08:00
|
|
|
#include "h5tools_utils.h"
|
2003-10-23 05:43:34 +08:00
|
|
|
#include "h5repack.h"
|
2003-10-23 05:45:59 +08:00
|
|
|
|
2006-10-05 22:35:40 +08:00
|
|
|
extern char *progname;
|
|
|
|
|
|
|
|
|
2003-12-05 03:35:33 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* File: h5repack.c
|
2005-08-14 04:53:35 +08:00
|
|
|
* Purpose: Public API functions
|
2003-12-05 03:35:33 +08:00
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2003-10-23 05:45:59 +08:00
|
|
|
|
2003-12-05 03:35:33 +08:00
|
|
|
static int check_options(pack_opt_t *options);
|
2003-10-23 05:43:34 +08:00
|
|
|
|
2004-01-07 01:49:00 +08:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: aux_initglb_filter
|
|
|
|
*
|
|
|
|
* Purpose: auxiliary function, initialize the options global filter
|
|
|
|
*
|
|
|
|
* Return: void
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static void aux_initglb_filter(pack_opt_t *options)
|
|
|
|
{
|
|
|
|
int k;
|
|
|
|
options->filter_g.filtn = -1;
|
2005-08-14 04:53:35 +08:00
|
|
|
for ( k=0; k<CDVALUES; k++)
|
2004-01-07 01:49:00 +08:00
|
|
|
options->filter_g.cd_values[k] = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-23 05:43:34 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: h5repack
|
|
|
|
*
|
2005-08-14 04:53:35 +08:00
|
|
|
* Purpose: locate all high-level HDF5 objects in the file
|
2003-10-23 05:43:34 +08:00
|
|
|
* and compress/chunk them using options
|
|
|
|
*
|
|
|
|
* Algorythm: 2 traversals are made to the file; the 1st builds a list of
|
|
|
|
* the objects, the 2nd makes a copy of them, using the options;
|
2005-08-14 04:53:35 +08:00
|
|
|
* the reason for the 1st traversal is to check for invalid
|
2003-10-23 05:43:34 +08:00
|
|
|
* object name requests
|
|
|
|
*
|
|
|
|
* Return: 0, ok, -1, fail
|
|
|
|
*
|
2004-07-16 03:25:27 +08:00
|
|
|
* Programmer: pvn@ncsa.uiuc.edu
|
2003-10-23 05:43:34 +08:00
|
|
|
*
|
|
|
|
* Date: September, 22, 2003
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2005-08-14 04:53:35 +08:00
|
|
|
int h5repack(const char* infile,
|
|
|
|
const char* outfile,
|
2006-10-09 12:18:18 +08:00
|
|
|
pack_opt_t *options)
|
2003-09-20 03:33:41 +08:00
|
|
|
{
|
2003-12-05 03:35:33 +08:00
|
|
|
/* check input */
|
|
|
|
if (check_options(options)<0)
|
|
|
|
return -1;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-12-05 03:35:33 +08:00
|
|
|
/* check for objects in input that are in the file */
|
2006-10-09 12:18:18 +08:00
|
|
|
if (check_objects(infile,options) < 0)
|
2003-12-05 03:35:33 +08:00
|
|
|
return -1;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2004-01-15 01:45:20 +08:00
|
|
|
/* copy the objects */
|
2006-10-09 12:18:18 +08:00
|
|
|
if (copy_objects(infile,outfile,options) < 0)
|
2003-12-05 03:35:33 +08:00
|
|
|
return -1;
|
2004-07-16 03:25:27 +08:00
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-09-20 03:33:41 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2003-10-23 05:43:34 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: h5repack_init
|
|
|
|
*
|
|
|
|
* Purpose: initialize options
|
|
|
|
*
|
|
|
|
* Return: 0, ok, -1, fail
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
int h5repack_init (pack_opt_t *options,
|
2003-10-23 05:43:34 +08:00
|
|
|
int verbose)
|
|
|
|
{
|
2003-10-29 01:40:05 +08:00
|
|
|
memset(options,0,sizeof(pack_opt_t));
|
2003-10-23 05:43:34 +08:00
|
|
|
options->threshold = 1024;
|
|
|
|
options->verbose = verbose;
|
|
|
|
return (options_table_init(&(options->op_tbl)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: h5repack_end
|
|
|
|
*
|
|
|
|
* Purpose: free options table
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2003-10-29 01:40:05 +08:00
|
|
|
int h5repack_end (pack_opt_t *options)
|
2003-10-23 05:43:34 +08:00
|
|
|
{
|
|
|
|
return options_table_free(options->op_tbl);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2003-12-30 04:26:21 +08:00
|
|
|
* Function: h5repack_addfilter
|
2003-10-23 05:43:34 +08:00
|
|
|
*
|
2005-08-14 04:53:35 +08:00
|
|
|
* Purpose: add a compression -f option to table
|
2004-04-07 02:30:30 +08:00
|
|
|
* Example: -f dset:GZIP=6
|
2003-10-23 05:43:34 +08:00
|
|
|
*
|
2003-12-05 03:35:33 +08:00
|
|
|
* Return: 0, ok, -1, fail
|
2003-10-23 05:43:34 +08:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
int h5repack_addfilter(const char* str,
|
2003-12-30 04:26:21 +08:00
|
|
|
pack_opt_t *options)
|
2003-10-23 05:43:34 +08:00
|
|
|
{
|
2003-12-30 04:26:21 +08:00
|
|
|
obj_list_t *obj_list=NULL; /*one object list for the -f and -c option entry */
|
|
|
|
filter_info_t filt; /*filter info for the current -f option entry */
|
|
|
|
int n_objs; /*number of objects in the current -f or -c option entry */
|
2003-10-23 05:43:34 +08:00
|
|
|
|
2003-12-30 04:26:21 +08:00
|
|
|
if (options->all_filter==1){
|
2006-10-05 22:35:40 +08:00
|
|
|
error_msg(progname, "invalid compression input: 'all' option is present \
|
2003-12-30 04:26:21 +08:00
|
|
|
with other objects <%s>\n",str);
|
2003-12-05 03:35:33 +08:00
|
|
|
return -1;
|
2003-10-23 05:43:34 +08:00
|
|
|
}
|
|
|
|
|
2003-12-30 04:26:21 +08:00
|
|
|
/* parse the -f option */
|
|
|
|
obj_list=parse_filter(str,&n_objs,&filt,options);
|
2003-11-11 04:59:32 +08:00
|
|
|
if (obj_list==NULL)
|
2003-10-23 05:43:34 +08:00
|
|
|
{
|
2003-12-30 04:26:21 +08:00
|
|
|
return -1;
|
2003-10-23 05:43:34 +08:00
|
|
|
}
|
|
|
|
|
2003-12-30 04:26:21 +08:00
|
|
|
if (options->all_filter==1)
|
2003-10-23 05:43:34 +08:00
|
|
|
{
|
2003-12-30 04:26:21 +08:00
|
|
|
/* if we are compressing all set the global filter type */
|
2004-01-07 01:49:00 +08:00
|
|
|
aux_initglb_filter(options);
|
2003-12-30 04:26:21 +08:00
|
|
|
options->filter_g=filt;
|
2003-10-23 05:43:34 +08:00
|
|
|
}
|
|
|
|
|
2003-12-30 04:26:21 +08:00
|
|
|
if (options->all_filter==0)
|
|
|
|
options_add_filter(obj_list,n_objs,filt,options->op_tbl);
|
2003-11-11 04:59:32 +08:00
|
|
|
|
|
|
|
free(obj_list);
|
2003-10-23 05:43:34 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2003-12-31 06:59:33 +08:00
|
|
|
* Function: h5repack_addlayout
|
2003-10-23 05:43:34 +08:00
|
|
|
*
|
2003-12-31 06:59:33 +08:00
|
|
|
* Purpose: add a layout option
|
2003-10-23 05:43:34 +08:00
|
|
|
*
|
|
|
|
* Return: 0, ok, -1, fail
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
int h5repack_addlayout(const char* str,
|
2003-12-31 06:59:33 +08:00
|
|
|
pack_opt_t *options)
|
2003-10-23 05:43:34 +08:00
|
|
|
{
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-10-23 05:43:34 +08:00
|
|
|
obj_list_t *obj_list=NULL; /*one object list for the -t and -c option entry */
|
|
|
|
int n_objs; /*number of objects in the current -t or -c option entry */
|
2003-12-31 06:59:33 +08:00
|
|
|
pack_info_t pack; /*info about layout to extract from parse */
|
2004-01-08 23:53:32 +08:00
|
|
|
int j;
|
|
|
|
|
|
|
|
init_packobject(&pack);
|
2003-10-23 05:43:34 +08:00
|
|
|
|
2003-12-31 06:59:33 +08:00
|
|
|
if (options->all_layout==1){
|
2006-10-05 22:35:40 +08:00
|
|
|
error_msg(progname, "invalid layout input: 'all' option \
|
2003-12-31 06:59:33 +08:00
|
|
|
is present with other objects <%s>\n",str);
|
2003-12-05 03:35:33 +08:00
|
|
|
return -1;
|
2003-10-23 05:43:34 +08:00
|
|
|
}
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-12-31 06:59:33 +08:00
|
|
|
/* parse the layout option */
|
|
|
|
obj_list=parse_layout(str,&n_objs,&pack,options);
|
2003-11-11 04:59:32 +08:00
|
|
|
if (obj_list==NULL)
|
|
|
|
return -1;
|
2003-10-23 05:43:34 +08:00
|
|
|
|
2003-12-31 06:59:33 +08:00
|
|
|
/* set global layout option */
|
|
|
|
if (options->all_layout==1 )
|
2003-10-23 05:43:34 +08:00
|
|
|
{
|
2003-12-31 06:59:33 +08:00
|
|
|
options->layout_g=pack.layout;
|
2005-08-14 04:53:35 +08:00
|
|
|
if (pack.layout==H5D_CHUNKED)
|
2004-08-18 03:54:42 +08:00
|
|
|
{
|
|
|
|
/* -2 means the NONE option, remove chunking
|
|
|
|
and set the global layout to contiguous */
|
|
|
|
if (pack.chunk.rank==-2)
|
|
|
|
{
|
|
|
|
options->layout_g = H5D_CONTIGUOUS;
|
|
|
|
}
|
|
|
|
/* otherwise set the global chunking type */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
options->chunk_g.rank=pack.chunk.rank;
|
2005-08-14 04:53:35 +08:00
|
|
|
for (j = 0; j < pack.chunk.rank; j++)
|
2004-08-18 03:54:42 +08:00
|
|
|
options->chunk_g.chunk_lengths[j] = pack.chunk.chunk_lengths[j];
|
|
|
|
}
|
2003-12-31 06:59:33 +08:00
|
|
|
}
|
2003-10-23 05:43:34 +08:00
|
|
|
}
|
|
|
|
|
2003-12-31 06:59:33 +08:00
|
|
|
if (options->all_layout==0)
|
|
|
|
options_add_layout(obj_list,
|
|
|
|
n_objs,
|
|
|
|
&pack,
|
|
|
|
options->op_tbl);
|
2003-10-23 05:43:34 +08:00
|
|
|
|
|
|
|
free(obj_list);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2003-12-05 03:35:33 +08:00
|
|
|
* Function: check_options
|
2003-10-23 05:43:34 +08:00
|
|
|
*
|
|
|
|
* Purpose: print options, checks for invalid options
|
|
|
|
*
|
2003-12-05 03:35:33 +08:00
|
|
|
* Return: void, return -1 on error
|
2003-10-23 05:43:34 +08:00
|
|
|
*
|
2004-07-16 03:25:27 +08:00
|
|
|
* Programmer: pvn@ncsa.uiuc.edu
|
2003-10-23 05:43:34 +08:00
|
|
|
*
|
|
|
|
* Date: September, 22, 2003
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2003-12-05 03:35:33 +08:00
|
|
|
static int check_options(pack_opt_t *options)
|
2003-10-23 05:43:34 +08:00
|
|
|
{
|
|
|
|
int i, k, j, has_cp=0, has_ck=0;
|
2004-12-29 22:26:20 +08:00
|
|
|
char slayout[30];
|
2003-10-23 05:43:34 +08:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2003-12-31 06:59:33 +08:00
|
|
|
* objects to layout
|
2003-10-23 05:43:34 +08:00
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2005-08-14 04:53:35 +08:00
|
|
|
if (options->verbose)
|
2003-10-23 05:43:34 +08:00
|
|
|
{
|
2004-07-14 03:09:41 +08:00
|
|
|
printf("Objects to modify layout are...\n");
|
2003-12-31 06:59:33 +08:00
|
|
|
if (options->all_layout==1) {
|
2004-12-29 22:26:20 +08:00
|
|
|
switch (options->layout_g)
|
|
|
|
{
|
|
|
|
case H5D_COMPACT:
|
|
|
|
strcpy(slayout,"compact");
|
|
|
|
break;
|
|
|
|
case H5D_CONTIGUOUS:
|
|
|
|
strcpy(slayout,"contiguous");
|
|
|
|
break;
|
|
|
|
case H5D_CHUNKED:
|
|
|
|
strcpy(slayout,"chunked");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
strcpy(slayout,"unknown");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
printf(" Apply %s layout to all\n", slayout);
|
2003-12-31 06:59:33 +08:00
|
|
|
if (H5D_CHUNKED==options->layout_g) {
|
|
|
|
printf("with dimension [");
|
2005-08-14 04:53:35 +08:00
|
|
|
for ( j = 0; j < options->chunk_g.rank; j++)
|
2003-12-31 06:59:33 +08:00
|
|
|
printf("%d ",(int)options->chunk_g.chunk_lengths[j]);
|
|
|
|
printf("]\n");
|
|
|
|
}
|
2003-10-23 05:43:34 +08:00
|
|
|
}
|
|
|
|
}/* verbose */
|
|
|
|
|
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-30 04:26:21 +08:00
|
|
|
char* name=options->op_tbl->objs[i].path;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-10-23 05:43:34 +08:00
|
|
|
if (options->op_tbl->objs[i].chunk.rank>0)
|
|
|
|
{
|
|
|
|
if (options->verbose){
|
2005-08-14 04:53:35 +08:00
|
|
|
printf(" <%s> with chunk size ",name);
|
|
|
|
for ( k = 0; k < options->op_tbl->objs[i].chunk.rank; k++)
|
2003-11-11 05:32:01 +08:00
|
|
|
printf("%d ",(int)options->op_tbl->objs[i].chunk.chunk_lengths[k]);
|
2003-10-23 05:43:34 +08:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
has_ck=1;
|
|
|
|
}
|
|
|
|
else if (options->op_tbl->objs[i].chunk.rank==-2)
|
|
|
|
{
|
|
|
|
if (options->verbose)
|
2005-08-14 04:53:35 +08:00
|
|
|
printf(" <%s> %s\n",name,"NONE (contigous)");
|
2003-10-23 05:43:34 +08:00
|
|
|
has_ck=1;
|
|
|
|
}
|
|
|
|
}
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-12-31 06:59:33 +08:00
|
|
|
if (options->all_layout==1 && has_ck){
|
2006-10-05 22:35:40 +08:00
|
|
|
error_msg(progname, "invalid chunking input: 'all' option\
|
2003-12-30 04:26:21 +08:00
|
|
|
is present with other objects\n");
|
2003-12-05 03:35:33 +08:00
|
|
|
return -1;
|
2003-10-23 05:43:34 +08:00
|
|
|
}
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-10-23 05:43:34 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
2004-07-14 03:09:41 +08:00
|
|
|
* objects to filter
|
2003-10-23 05:43:34 +08:00
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
|
|
if (options->verbose)
|
2003-10-23 05:43:34 +08:00
|
|
|
{
|
2004-07-16 03:25:27 +08:00
|
|
|
printf("Objects to apply filter are...\n");
|
2005-08-14 04:53:35 +08:00
|
|
|
if (options->all_filter==1)
|
2003-10-23 05:43:34 +08:00
|
|
|
{
|
2003-12-30 04:26:21 +08:00
|
|
|
H5Z_filter_t filtn=options->filter_g.filtn;
|
|
|
|
switch (filtn)
|
2003-10-23 05:43:34 +08:00
|
|
|
{
|
|
|
|
case H5Z_FILTER_NONE:
|
2004-07-16 03:25:27 +08:00
|
|
|
printf(" Uncompress all\n");
|
2003-10-23 05:43:34 +08:00
|
|
|
break;
|
2004-07-16 03:25:27 +08:00
|
|
|
case H5Z_FILTER_SHUFFLE:
|
|
|
|
case H5Z_FILTER_FLETCHER32:
|
|
|
|
printf(" All with %s\n",get_sfilter(filtn));
|
2003-10-23 05:43:34 +08:00
|
|
|
break;
|
2004-07-16 03:25:27 +08:00
|
|
|
case H5Z_FILTER_SZIP:
|
2003-10-23 05:43:34 +08:00
|
|
|
case H5Z_FILTER_DEFLATE:
|
2004-07-16 03:25:27 +08:00
|
|
|
printf(" All with %s, parameter %d\n",
|
2003-12-30 04:26:21 +08:00
|
|
|
get_sfilter(filtn),
|
|
|
|
options->filter_g.cd_values[0]);
|
2003-10-23 05:43:34 +08:00
|
|
|
break;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
} /* verbose */
|
|
|
|
|
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-31 06:59:33 +08:00
|
|
|
pack_info_t pack = options->op_tbl->objs[i];
|
2004-07-14 03:09:41 +08:00
|
|
|
char* name = pack.path;
|
2004-01-07 01:49:00 +08:00
|
|
|
|
|
|
|
for ( j=0; j<pack.nfilters; j++)
|
2003-10-23 05:43:34 +08:00
|
|
|
{
|
2005-08-14 04:53:35 +08:00
|
|
|
if (options->verbose)
|
2003-12-30 04:26:21 +08:00
|
|
|
{
|
2004-07-16 03:25:27 +08:00
|
|
|
printf(" <%s> with %s filter\n",
|
2003-12-30 04:26:21 +08:00
|
|
|
name,
|
2004-07-16 03:25:27 +08:00
|
|
|
get_sfilter(pack.filter[j].filtn));
|
2003-10-23 05:43:34 +08:00
|
|
|
}
|
2004-01-07 01:49:00 +08:00
|
|
|
|
2003-10-23 05:43:34 +08:00
|
|
|
has_cp=1;
|
2004-07-16 03:25:27 +08:00
|
|
|
|
2004-01-07 01:49:00 +08:00
|
|
|
} /* j */
|
2003-12-30 04:26:21 +08:00
|
|
|
} /* i */
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-12-30 04:26:21 +08:00
|
|
|
if (options->all_filter==1 && has_cp){
|
2006-10-05 22:35:40 +08:00
|
|
|
error_msg(progname, "invalid compression input: 'all' option\
|
2003-12-30 04:26:21 +08:00
|
|
|
is present with other objects\n");
|
2003-12-05 03:35:33 +08:00
|
|
|
return -1;
|
2003-10-23 05:43:34 +08:00
|
|
|
}
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2004-12-29 22:26:20 +08:00
|
|
|
|
2003-12-05 03:35:33 +08:00
|
|
|
return 0;
|
2003-10-23 05:43:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: read_info
|
|
|
|
*
|
|
|
|
* Purpose: read comp and chunk options from file
|
|
|
|
*
|
|
|
|
* Return: void, exit on error
|
|
|
|
*
|
2004-07-16 03:25:27 +08:00
|
|
|
* Programmer: pvn@ncsa.uiuc.edu
|
2003-10-23 05:43:34 +08:00
|
|
|
*
|
|
|
|
* Date: September, 22, 2003
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2003-11-11 04:59:32 +08:00
|
|
|
void read_info(const char *filename,
|
2005-08-14 04:53:35 +08:00
|
|
|
pack_opt_t *options)
|
2003-10-23 05:43:34 +08:00
|
|
|
{
|
2003-12-30 04:26:21 +08:00
|
|
|
|
2003-10-23 05:43:34 +08:00
|
|
|
char stype[10];
|
|
|
|
char comp_info[1024];
|
|
|
|
FILE *fp;
|
|
|
|
char c;
|
|
|
|
int i, rc=1;
|
2004-04-15 00:41:43 +08:00
|
|
|
char *srcdir = getenv("srcdir"); /* the source directory */
|
|
|
|
char data_file[512]=""; /* buffer to hold name of existing file */
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2004-04-15 00:41:43 +08:00
|
|
|
/* compose the name of the file to open, using the srcdir, if appropriate */
|
|
|
|
if (srcdir){
|
|
|
|
strcpy(data_file,srcdir);
|
|
|
|
strcat(data_file,"/");
|
2005-08-14 04:53:35 +08:00
|
|
|
}
|
2004-04-15 00:41:43 +08:00
|
|
|
strcat(data_file,filename);
|
2003-10-23 05:43:34 +08:00
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2004-04-15 00:41:43 +08:00
|
|
|
if ((fp = fopen(data_file, "r")) == (FILE *)NULL) {
|
2006-10-05 22:35:40 +08:00
|
|
|
error_msg(progname, "cannot open options file %s", filename);
|
2003-10-23 05:43:34 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2004-04-15 00:41:43 +08:00
|
|
|
/* cycle until end of file reached */
|
2003-10-23 05:43:34 +08:00
|
|
|
while( 1 )
|
|
|
|
{
|
|
|
|
rc=fscanf(fp, "%s", stype);
|
|
|
|
if (rc==-1)
|
|
|
|
break;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-10-23 05:43:34 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
2004-03-03 02:12:25 +08:00
|
|
|
* filter
|
2003-10-23 05:43:34 +08:00
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2005-08-14 04:53:35 +08:00
|
|
|
if (strcmp(stype,"-f") == 0) {
|
2003-10-23 05:43:34 +08:00
|
|
|
|
|
|
|
/* find begining of info */
|
|
|
|
i=0; c='0';
|
2004-04-15 00:41:43 +08:00
|
|
|
while( c!=' ' )
|
2003-10-23 05:43:34 +08:00
|
|
|
{
|
|
|
|
fscanf(fp, "%c", &c);
|
2004-04-15 00:41:43 +08:00
|
|
|
if (feof(fp)) break;
|
2003-10-23 05:43:34 +08:00
|
|
|
}
|
|
|
|
c='0';
|
|
|
|
/* go until end */
|
2004-04-15 00:41:43 +08:00
|
|
|
while( c!=' ' )
|
2003-10-23 05:43:34 +08:00
|
|
|
{
|
|
|
|
fscanf(fp, "%c", &c);
|
|
|
|
comp_info[i]=c;
|
|
|
|
i++;
|
2004-04-15 00:41:43 +08:00
|
|
|
if (feof(fp)) break;
|
|
|
|
if (c==10 /*eol*/) break;
|
2003-10-23 05:43:34 +08:00
|
|
|
}
|
2005-08-14 04:53:35 +08:00
|
|
|
comp_info[i-1]='\0'; /*cut the last " */
|
2003-10-23 05:43:34 +08:00
|
|
|
|
2003-12-30 04:26:21 +08:00
|
|
|
if (h5repack_addfilter(comp_info,options)==-1){
|
2006-10-05 22:35:40 +08:00
|
|
|
error_msg(progname, "could not add compression option\n");
|
2003-10-23 05:43:34 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*-------------------------------------------------------------------------
|
2004-03-03 02:12:25 +08:00
|
|
|
* layout
|
2003-10-23 05:43:34 +08:00
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2005-08-14 04:53:35 +08:00
|
|
|
else if (strcmp(stype,"-l") == 0) {
|
|
|
|
|
2003-10-23 05:43:34 +08:00
|
|
|
/* find begining of info */
|
|
|
|
i=0; c='0';
|
2004-04-15 00:41:43 +08:00
|
|
|
while( c!=' ' )
|
2003-10-23 05:43:34 +08:00
|
|
|
{
|
|
|
|
fscanf(fp, "%c", &c);
|
2004-04-15 00:41:43 +08:00
|
|
|
if (feof(fp)) break;
|
2003-10-23 05:43:34 +08:00
|
|
|
}
|
|
|
|
c='0';
|
|
|
|
/* go until end */
|
2004-04-15 00:41:43 +08:00
|
|
|
while( c!=' ' )
|
2003-10-23 05:43:34 +08:00
|
|
|
{
|
|
|
|
fscanf(fp, "%c", &c);
|
|
|
|
comp_info[i]=c;
|
|
|
|
i++;
|
2004-04-15 00:41:43 +08:00
|
|
|
if (feof(fp)) break;
|
|
|
|
if (c==10 /*eol*/) break;
|
2003-10-23 05:43:34 +08:00
|
|
|
}
|
2005-08-14 04:53:35 +08:00
|
|
|
comp_info[i-1]='\0'; /*cut the last " */
|
2003-10-23 05:43:34 +08:00
|
|
|
|
2003-12-31 06:59:33 +08:00
|
|
|
if (h5repack_addlayout(comp_info,options)==-1){
|
2006-10-05 22:35:40 +08:00
|
|
|
error_msg(progname, "could not add chunck option\n");
|
2003-10-23 05:43:34 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* not valid
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
else {
|
2006-10-05 22:35:40 +08:00
|
|
|
error_msg(progname, "bad file format for %s", filename);
|
2003-10-23 05:43:34 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|