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>
|
|
|
|
#include <ctype.h>
|
2006-10-05 22:35:40 +08:00
|
|
|
#include "h5tools_utils.h"
|
2003-12-05 03:35:33 +08:00
|
|
|
#include "h5repack.h"
|
2003-10-23 05:43:34 +08:00
|
|
|
|
2006-10-05 22:35:40 +08:00
|
|
|
extern char *progname;
|
2003-10-23 05:43:34 +08:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2003-12-30 04:26:21 +08:00
|
|
|
* Function: parse_filter
|
2003-10-23 05:43:34 +08:00
|
|
|
*
|
2003-12-30 04:26:21 +08:00
|
|
|
* Purpose: read filter information
|
2003-10-23 05:43:34 +08:00
|
|
|
*
|
|
|
|
* Return: a list of names, the number of names and its compression type
|
|
|
|
*
|
2003-12-31 06:59:33 +08:00
|
|
|
* <name of filter> can be:
|
|
|
|
* GZIP, to apply the HDF5 GZIP filter (GZIP compression)
|
|
|
|
* SZIP, to apply the HDF5 SZIP filter (SZIP compression)
|
|
|
|
* SHUF, to apply the HDF5 shuffle filter
|
|
|
|
* FLET, to apply the HDF5 checksum filter
|
2005-02-16 03:21:39 +08:00
|
|
|
* NBIT, to apply the HDF5 NBIT filter (NBIT compression)
|
2005-09-20 05:12:35 +08:00
|
|
|
* SOFF, to apply the HDF5 scale+offset filter (compression)
|
2005-08-14 04:53:35 +08:00
|
|
|
* NONE, to remove the filter
|
2003-12-31 06:59:33 +08:00
|
|
|
*
|
2005-08-14 04:53:35 +08:00
|
|
|
* Examples:
|
2004-04-02 23:52:24 +08:00
|
|
|
* "GZIP=6"
|
2003-10-23 05:43:34 +08:00
|
|
|
* "A,B:NONE"
|
|
|
|
*
|
|
|
|
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
|
|
|
|
*
|
|
|
|
* Date: September, 23, 2003
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
obj_list_t* parse_filter(const char *str,
|
|
|
|
int *n_objs,
|
2003-12-30 04:26:21 +08:00
|
|
|
filter_info_t *filt,
|
|
|
|
pack_opt_t *options)
|
2003-10-23 05:43:34 +08:00
|
|
|
{
|
|
|
|
unsigned i, u;
|
|
|
|
char c;
|
|
|
|
size_t len=strlen(str);
|
2004-07-21 03:21:03 +08:00
|
|
|
int j, m, n, k, l, end_obj=-1, no_param=0;
|
2005-08-14 04:53:35 +08:00
|
|
|
char sobj[MAX_NC_NAME];
|
2003-10-23 05:43:34 +08:00
|
|
|
char scomp[10];
|
|
|
|
char stype[5];
|
2005-08-14 04:53:35 +08:00
|
|
|
char smask[3];
|
2003-10-23 05:43:34 +08:00
|
|
|
obj_list_t* obj_list=NULL;
|
2003-12-30 04:26:21 +08:00
|
|
|
unsigned pixels_per_block;
|
2003-10-23 05:43:34 +08:00
|
|
|
|
2004-04-02 23:52:24 +08:00
|
|
|
#if defined(PARSE_DEBUG)
|
|
|
|
fprintf(stderr,"%s\n",str);
|
|
|
|
#endif
|
|
|
|
|
2003-10-23 05:43:34 +08:00
|
|
|
/* initialize compression info */
|
2003-12-30 04:26:21 +08:00
|
|
|
memset(filt,0,sizeof(filter_info_t));
|
2003-10-23 05:43:34 +08:00
|
|
|
|
|
|
|
/* check for the end of object list and number of objects */
|
|
|
|
for ( i=0, n=0; i<len; i++)
|
|
|
|
{
|
|
|
|
c = str[i];
|
|
|
|
if ( c==':' )
|
|
|
|
{
|
|
|
|
end_obj=i;
|
|
|
|
}
|
|
|
|
if ( c==',' )
|
|
|
|
{
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (end_obj==-1) { /* missing : */
|
2003-12-30 04:26:21 +08:00
|
|
|
/* apply to all objects */
|
|
|
|
options->all_filter=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
|
|
|
n++;
|
|
|
|
obj_list=malloc(n*sizeof(obj_list_t));
|
2003-11-11 04:59:32 +08:00
|
|
|
if (obj_list==NULL)
|
|
|
|
{
|
2006-10-05 22:35:40 +08:00
|
|
|
error_msg(progname, "could not allocate object list\n");
|
2003-11-11 04:59:32 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2003-10-23 05:43:34 +08:00
|
|
|
*n_objs=n;
|
|
|
|
|
|
|
|
/* get object list */
|
|
|
|
for ( j=0, k=0, n=0; j<end_obj; j++,k++)
|
|
|
|
{
|
|
|
|
c = str[j];
|
2003-12-31 06:59:33 +08:00
|
|
|
sobj[k]=c;
|
2005-08-14 04:53:35 +08:00
|
|
|
if ( c==',' || j==end_obj-1)
|
2003-10-23 05:43:34 +08:00
|
|
|
{
|
2003-12-31 06:59:33 +08:00
|
|
|
if ( c==',') sobj[k]='\0'; else sobj[k+1]='\0';
|
|
|
|
strcpy(obj_list[n].obj,sobj);
|
|
|
|
memset(sobj,0,sizeof(sobj));
|
2003-10-23 05:43:34 +08:00
|
|
|
n++;
|
|
|
|
k=-1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* nothing after : */
|
|
|
|
if (end_obj+1==(int)len)
|
|
|
|
{
|
|
|
|
if (obj_list) free(obj_list);
|
2006-10-05 22:35:40 +08:00
|
|
|
error_msg(progname, "input Error: Invalid compression type in <%s>\n",str);
|
2003-10-23 05:43:34 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-30 04:26:21 +08:00
|
|
|
/* get filter additional parameters */
|
2003-10-23 05:43:34 +08:00
|
|
|
m=0;
|
2003-12-30 04:26:21 +08:00
|
|
|
for ( i=end_obj+1, k=0, j=0; i<len; i++,k++)
|
2003-10-23 05:43:34 +08:00
|
|
|
{
|
|
|
|
c = str[i];
|
|
|
|
scomp[k]=c;
|
2005-08-14 04:53:35 +08:00
|
|
|
if ( c=='=' || i==len-1)
|
2003-10-23 05:43:34 +08:00
|
|
|
{
|
2004-04-02 23:52:24 +08:00
|
|
|
if ( c=='=') { /*one more parameter */
|
2003-10-23 05:43:34 +08:00
|
|
|
scomp[k]='\0'; /*cut space */
|
|
|
|
|
2005-09-20 05:12:35 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* H5Z_FILTER_SZIP
|
2006-01-24 04:46:34 +08:00
|
|
|
* szip has the format SZIP=<pixels per block,coding>
|
2005-09-20 05:12:35 +08:00
|
|
|
* pixels per block is a even number in 2-32 and coding method is 'EC' or 'NN'
|
2006-01-24 04:46:34 +08:00
|
|
|
* example SZIP=8,NN
|
2005-09-20 05:12:35 +08:00
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2004-07-21 03:21:03 +08:00
|
|
|
if (strcmp(scomp,"SZIP")==0)
|
|
|
|
{
|
|
|
|
l=-1; /* mask index check */
|
2005-08-14 04:53:35 +08:00
|
|
|
for ( m=0,u=i+1; u<len; u++,m++)
|
2004-07-21 03:21:03 +08:00
|
|
|
{
|
|
|
|
if (str[u]==',')
|
|
|
|
{
|
|
|
|
stype[m]='\0'; /* end digit of szip */
|
|
|
|
l=0; /* start EC or NN search */
|
|
|
|
u++; /* skip ',' */
|
|
|
|
}
|
|
|
|
c = str[u];
|
|
|
|
if (!isdigit(c) && l==-1){
|
|
|
|
if (obj_list) free(obj_list);
|
2006-10-05 22:35:40 +08:00
|
|
|
error_msg(progname, "compression parameter not digit in <%s>\n",str);
|
2004-07-21 03:21:03 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (l==-1)
|
|
|
|
stype[m]=c;
|
2005-08-14 04:53:35 +08:00
|
|
|
else
|
2004-07-21 03:21:03 +08:00
|
|
|
{
|
|
|
|
smask[l]=c;
|
|
|
|
l++;
|
|
|
|
if (l==2)
|
|
|
|
{
|
|
|
|
smask[l]='\0';
|
|
|
|
i=len-1; /* end */
|
|
|
|
(*n_objs)--; /* we counted an extra ',' */
|
2005-08-14 04:53:35 +08:00
|
|
|
if (strcmp(smask,"NN")==0)
|
2006-01-24 04:46:34 +08:00
|
|
|
filt->cd_values[j++]=H5_SZIP_NN_OPTION_MASK;
|
2004-07-21 03:21:03 +08:00
|
|
|
else if (strcmp(smask,"EC")==0)
|
2006-01-24 04:46:34 +08:00
|
|
|
filt->cd_values[j++]=H5_SZIP_EC_OPTION_MASK;
|
2004-07-21 03:21:03 +08:00
|
|
|
else
|
|
|
|
{
|
2006-10-05 22:35:40 +08:00
|
|
|
error_msg(progname, "szip mask must be 'NN' or 'EC' \n");
|
2004-07-21 03:21:03 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2004-07-21 03:21:03 +08:00
|
|
|
}
|
|
|
|
}
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2004-07-21 03:21:03 +08:00
|
|
|
} /* u */
|
|
|
|
} /*if */
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2005-09-20 05:12:35 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* H5Z_FILTER_SCALEOFFSET
|
2006-11-18 04:00:46 +08:00
|
|
|
* scaleoffset has the format SOFF=<scale_factor,scale_type>
|
|
|
|
* scale_type can be
|
|
|
|
* integer datatype, H5Z_SO_INT (IN)
|
|
|
|
* float datatype using D-scaling method, H5Z_SO_FLOAT_DSCALE (DS)
|
|
|
|
* float datatype using E-scaling method, H5Z_SO_FLOAT_ESCALE (ES) , not yet implemented
|
|
|
|
* for integer datatypes, scale_factor denotes Minimum Bits
|
|
|
|
* for float datatypes, scale_factor denotes decimal scale factor
|
2005-09-20 05:12:35 +08:00
|
|
|
* examples
|
2006-11-18 04:00:46 +08:00
|
|
|
* SOFF=31,IN
|
|
|
|
* SOFF=3,DF
|
2005-09-20 05:12:35 +08:00
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2006-11-18 04:00:46 +08:00
|
|
|
else if (strcmp(scomp,"SOFF")==0)
|
2005-09-20 05:12:35 +08:00
|
|
|
{
|
|
|
|
l=-1; /* mask index check */
|
|
|
|
for ( m=0,u=i+1; u<len; u++,m++)
|
|
|
|
{
|
|
|
|
if (str[u]==',')
|
|
|
|
{
|
|
|
|
stype[m]='\0'; /* end digit */
|
|
|
|
l=0; /* start 'IN' , 'DS', or 'ES' search */
|
|
|
|
u++; /* skip ',' */
|
|
|
|
}
|
|
|
|
c = str[u];
|
|
|
|
if (!isdigit(c) && l==-1){
|
|
|
|
if (obj_list) free(obj_list);
|
2006-10-05 22:35:40 +08:00
|
|
|
error_msg(progname, "compression parameter is not a digit in <%s>\n",str);
|
2005-09-20 05:12:35 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (l==-1)
|
|
|
|
stype[m]=c;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
smask[l]=c;
|
|
|
|
l++;
|
|
|
|
if (l==2)
|
|
|
|
{
|
|
|
|
smask[l]='\0';
|
|
|
|
i=len-1; /* end */
|
|
|
|
(*n_objs)--; /* we counted an extra ',' */
|
|
|
|
if (strcmp(smask,"IN")==0)
|
2006-11-18 04:00:46 +08:00
|
|
|
filt->cd_values[j++]=H5Z_SO_INT;
|
2005-09-20 05:12:35 +08:00
|
|
|
else if (strcmp(smask,"DS")==H5Z_SO_FLOAT_DSCALE)
|
2006-11-18 04:00:46 +08:00
|
|
|
filt->cd_values[j++]=H5Z_SO_FLOAT_DSCALE;
|
2005-09-20 05:12:35 +08:00
|
|
|
else
|
|
|
|
{
|
2006-10-05 22:35:40 +08:00
|
|
|
error_msg(progname, "scale type must be 'IN' or 'DS' \n");
|
2005-09-20 05:12:35 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* u */
|
|
|
|
} /*if */
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* all other filters
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2004-07-21 03:21:03 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* here we could have 1 or 2 digits */
|
2005-08-14 04:53:35 +08:00
|
|
|
for ( m=0,u=i+1; u<len; u++,m++)
|
2004-07-21 03:21:03 +08:00
|
|
|
{
|
|
|
|
c = str[u];
|
|
|
|
if (!isdigit(c)){
|
|
|
|
if (obj_list) free(obj_list);
|
2006-10-05 22:35:40 +08:00
|
|
|
error_msg(progname, "compression parameter is not a digit in <%s>\n",str);
|
2004-07-21 03:21:03 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
stype[m]=c;
|
|
|
|
} /* u */
|
|
|
|
|
|
|
|
stype[m]='\0';
|
|
|
|
} /*if */
|
|
|
|
|
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-12-30 04:26:21 +08:00
|
|
|
filt->cd_values[j++]=atoi(stype);
|
2003-10-23 05:43:34 +08:00
|
|
|
i+=m; /* jump */
|
|
|
|
}
|
|
|
|
else if (i==len-1) { /*no more parameters */
|
|
|
|
scomp[k+1]='\0';
|
|
|
|
no_param=1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* H5Z_FILTER_NONE
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
if (strcmp(scomp,"NONE")==0)
|
2003-12-30 04:26:21 +08:00
|
|
|
filt->filtn=H5Z_FILTER_NONE;
|
2003-10-23 05:43:34 +08:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* H5Z_FILTER_DEFLATE
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
else if (strcmp(scomp,"GZIP")==0)
|
|
|
|
{
|
2003-12-30 04:26:21 +08:00
|
|
|
filt->filtn=H5Z_FILTER_DEFLATE;
|
2003-10-23 05:43:34 +08:00
|
|
|
if (no_param) { /*no more parameters, GZIP must have parameter */
|
|
|
|
if (obj_list) free(obj_list);
|
2006-10-05 22:35:40 +08:00
|
|
|
error_msg(progname, "missing compression parameter in <%s>\n",str);
|
2003-10-23 05:43:34 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* H5Z_FILTER_SZIP
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
else if (strcmp(scomp,"SZIP")==0)
|
|
|
|
{
|
2003-12-30 04:26:21 +08:00
|
|
|
filt->filtn=H5Z_FILTER_SZIP;
|
|
|
|
if (no_param) { /*no more parameters, SZIP must have parameter */
|
|
|
|
if (obj_list) free(obj_list);
|
2006-10-05 22:35:40 +08:00
|
|
|
error_msg(progname, "missing compression parameter in <%s>\n",str);
|
2003-12-30 04:26:21 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* H5Z_FILTER_SHUFFLE
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
else if (strcmp(scomp,"SHUF")==0)
|
|
|
|
{
|
|
|
|
filt->filtn=H5Z_FILTER_SHUFFLE;
|
|
|
|
if (m>0){ /*shuffle does not have parameter */
|
|
|
|
if (obj_list) free(obj_list);
|
2006-10-05 22:35:40 +08:00
|
|
|
error_msg(progname, "extra parameter in SHUF <%s>\n",str);
|
2003-12-30 04:26:21 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* H5Z_FILTER_FLETCHER32
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
else if (strcmp(scomp,"FLET")==0)
|
|
|
|
{
|
|
|
|
filt->filtn=H5Z_FILTER_FLETCHER32;
|
|
|
|
if (m>0){ /*shuffle does not have parameter */
|
2003-10-23 05:43:34 +08:00
|
|
|
if (obj_list) free(obj_list);
|
2006-10-05 22:35:40 +08:00
|
|
|
error_msg(progname, "extra parameter in FLET <%s>\n",str);
|
2003-10-23 05:43:34 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2005-02-16 03:21:39 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* H5Z_FILTER_NBIT
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
else if (strcmp(scomp,"NBIT")==0)
|
|
|
|
{
|
|
|
|
filt->filtn=H5Z_FILTER_NBIT;
|
|
|
|
if (m>0){ /*nbit does not have parameter */
|
|
|
|
if (obj_list) free(obj_list);
|
2006-10-05 22:35:40 +08:00
|
|
|
error_msg(progname, "extra parameter in NBIT <%s>\n",str);
|
2005-02-16 03:21:39 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2005-02-24 01:52:03 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* H5Z_FILTER_SCALEOFFSET
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2005-09-20 05:12:35 +08:00
|
|
|
else if (strcmp(scomp,"SOFF")==0)
|
2005-02-24 01:52:03 +08:00
|
|
|
{
|
|
|
|
filt->filtn=H5Z_FILTER_SCALEOFFSET;
|
2005-09-20 05:12:35 +08:00
|
|
|
if (no_param) { /*no more parameters, SOFF must have parameter */
|
2005-02-24 01:52:03 +08:00
|
|
|
if (obj_list) free(obj_list);
|
2006-10-05 22:35:40 +08:00
|
|
|
error_msg(progname, "missing compression parameter in <%s>\n",str);
|
2005-02-24 01:52:03 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2003-10-23 05:43:34 +08:00
|
|
|
else {
|
|
|
|
if (obj_list) free(obj_list);
|
2006-10-05 22:35:40 +08:00
|
|
|
error_msg(progname, "invalid filter type in <%s>\n",str);
|
2003-10-23 05:43:34 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} /*i*/
|
|
|
|
|
2003-12-30 04:26:21 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* check valid parameters
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2003-10-23 05:43:34 +08:00
|
|
|
|
2003-12-30 04:26:21 +08:00
|
|
|
switch (filt->filtn)
|
|
|
|
{
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-12-30 04:26:21 +08:00
|
|
|
case H5Z_FILTER_DEFLATE:
|
|
|
|
if (filt->cd_values[0]<0 || filt->cd_values[0]>9 ){
|
|
|
|
if (obj_list) free(obj_list);
|
2006-10-05 22:35:40 +08:00
|
|
|
error_msg(progname, "invalid compression parameter in <%s>\n",str);
|
2003-12-30 04:26:21 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
break;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
|
|
|
2003-12-30 04:26:21 +08:00
|
|
|
case H5Z_FILTER_SZIP:
|
|
|
|
pixels_per_block=filt->cd_values[0];
|
|
|
|
if ((pixels_per_block%2)==1) {
|
|
|
|
if (obj_list) free(obj_list);
|
2006-10-05 22:35:40 +08:00
|
|
|
error_msg(progname, "pixels_per_block is not even in <%s>\n",str);
|
2003-12-30 04:26:21 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (pixels_per_block>H5_SZIP_MAX_PIXELS_PER_BLOCK) {
|
|
|
|
if (obj_list) free(obj_list);
|
2006-10-05 22:35:40 +08:00
|
|
|
error_msg(progname, "pixels_per_block is too large in <%s>\n",str);
|
2003-12-30 04:26:21 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
2004-07-21 03:21:03 +08:00
|
|
|
if ( (strcmp(smask,"NN")!=0) && (strcmp(smask,"EC")!=0) ) {
|
|
|
|
if (obj_list) free(obj_list);
|
2006-10-05 22:35:40 +08:00
|
|
|
error_msg(progname, "szip mask must be 'NN' or 'EC' \n");
|
2004-07-21 03:21:03 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
2003-12-30 04:26:21 +08:00
|
|
|
break;
|
2005-02-24 01:52:03 +08:00
|
|
|
case H5Z_FILTER_SCALEOFFSET:
|
|
|
|
if (filt->cd_values[0]<0 ){
|
|
|
|
if (obj_list) free(obj_list);
|
2006-10-05 22:35:40 +08:00
|
|
|
error_msg(progname, "invalid compression parameter in <%s>\n",str);
|
2005-02-24 01:52:03 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
break;
|
2003-12-30 04:26:21 +08:00
|
|
|
};
|
2003-10-23 05:43:34 +08:00
|
|
|
|
|
|
|
return obj_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2003-12-30 04:26:21 +08:00
|
|
|
* Function: get_sfilter
|
2003-10-23 05:43:34 +08:00
|
|
|
*
|
2003-12-30 04:26:21 +08:00
|
|
|
* Purpose: return the filter as a string name
|
2003-10-23 05:43:34 +08:00
|
|
|
*
|
|
|
|
* Return: name of filter, exit on error
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2003-12-30 04:26:21 +08:00
|
|
|
const char* get_sfilter(H5Z_filter_t filtn)
|
2003-10-23 05:43:34 +08:00
|
|
|
{
|
2003-12-30 04:26:21 +08:00
|
|
|
if (filtn==H5Z_FILTER_NONE)
|
2003-10-23 05:43:34 +08:00
|
|
|
return "NONE";
|
2003-12-30 04:26:21 +08:00
|
|
|
else if (filtn==H5Z_FILTER_DEFLATE)
|
2003-10-23 05:43:34 +08:00
|
|
|
return "GZIP";
|
2003-12-30 04:26:21 +08:00
|
|
|
else if (filtn==H5Z_FILTER_SZIP)
|
2003-10-23 05:43:34 +08:00
|
|
|
return "SZIP";
|
2003-12-30 04:26:21 +08:00
|
|
|
else if (filtn==H5Z_FILTER_SHUFFLE)
|
|
|
|
return "SHUFFLE";
|
|
|
|
else if (filtn==H5Z_FILTER_FLETCHER32)
|
2004-07-14 03:09:41 +08:00
|
|
|
return "FLETCHER32";
|
2005-02-16 03:21:39 +08:00
|
|
|
else if (filtn==H5Z_FILTER_NBIT)
|
|
|
|
return "NBIT";
|
2005-02-24 01:52:03 +08:00
|
|
|
else if (filtn==H5Z_FILTER_SCALEOFFSET)
|
2005-09-20 05:12:35 +08:00
|
|
|
return "SOFF";
|
2003-10-23 05:43:34 +08:00
|
|
|
else {
|
2006-10-05 22:35:40 +08:00
|
|
|
error_msg(progname, "input error in filter type\n");
|
2003-10-23 05:43:34 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
return NULL;
|
2005-08-14 04:53:35 +08:00
|
|
|
}
|
2003-10-23 05:43:34 +08:00
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2003-12-31 06:59:33 +08:00
|
|
|
* Function: parse_layout
|
2003-10-23 05:43:34 +08:00
|
|
|
*
|
2003-12-31 06:59:33 +08:00
|
|
|
* Purpose: read layout info
|
2003-10-23 05:43:34 +08:00
|
|
|
*
|
2005-08-14 04:53:35 +08:00
|
|
|
* Return: a list of names, the number of names and its chunking info for
|
2003-12-31 06:59:33 +08:00
|
|
|
* chunked. NULL, on error
|
|
|
|
* the layout type can be:
|
|
|
|
* CHUNK, to apply chunking layout
|
|
|
|
* CONTI, to apply continuous layout
|
|
|
|
* COMPA, to apply compact layout
|
2003-10-23 05:43:34 +08:00
|
|
|
*
|
2005-08-14 04:53:35 +08:00
|
|
|
* Example:
|
2004-04-02 23:52:24 +08:00
|
|
|
* "AA,B,CDE:CHUNK=10X10"
|
2003-10-23 05:43:34 +08:00
|
|
|
*
|
|
|
|
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
|
|
|
|
*
|
2003-12-31 06:59:33 +08:00
|
|
|
* Date: December 30, 2003
|
2003-10-23 05:43:34 +08:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2005-08-14 04:53:35 +08:00
|
|
|
obj_list_t* parse_layout(const char *str,
|
|
|
|
int *n_objs,
|
2003-12-31 06:59:33 +08:00
|
|
|
pack_info_t *pack, /* info about layout needed */
|
|
|
|
pack_opt_t *options)
|
2003-10-23 05:43:34 +08:00
|
|
|
{
|
|
|
|
obj_list_t* obj_list=NULL;
|
|
|
|
unsigned i;
|
|
|
|
char c;
|
|
|
|
size_t len=strlen(str);
|
|
|
|
int j, n, k, end_obj=-1, c_index;
|
2005-08-14 04:53:35 +08:00
|
|
|
char sobj[MAX_NC_NAME];
|
2003-10-23 05:43:34 +08:00
|
|
|
char sdim[10];
|
2003-12-31 06:59:33 +08:00
|
|
|
char slayout[10];
|
2004-08-18 03:54:42 +08:00
|
|
|
|
|
|
|
|
|
|
|
memset(sdim, '\0', sizeof(sdim));
|
|
|
|
memset(sobj, '\0', sizeof(sobj));
|
|
|
|
memset(slayout, '\0', sizeof(slayout));
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-10-23 05:43:34 +08:00
|
|
|
/* check for the end of object list and number of objects */
|
|
|
|
for ( i=0, n=0; i<len; i++)
|
|
|
|
{
|
|
|
|
c = str[i];
|
|
|
|
if ( c==':' )
|
|
|
|
{
|
|
|
|
end_obj=i;
|
|
|
|
}
|
|
|
|
if ( c==',' )
|
|
|
|
{
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-30 04:26:21 +08:00
|
|
|
if (end_obj==-1) { /* missing : chunk all */
|
2003-12-31 06:59:33 +08:00
|
|
|
options->all_layout=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
|
|
|
n++;
|
|
|
|
obj_list=malloc(n*sizeof(obj_list_t));
|
2003-11-11 04:59:32 +08:00
|
|
|
if (obj_list==NULL)
|
|
|
|
{
|
2006-10-05 22:35:40 +08:00
|
|
|
error_msg(progname, "could not allocate object list\n");
|
2003-11-11 04:59:32 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2003-10-23 05:43:34 +08:00
|
|
|
*n_objs=n;
|
|
|
|
|
|
|
|
/* get object list */
|
|
|
|
for ( j=0, k=0, n=0; j<end_obj; j++,k++)
|
|
|
|
{
|
|
|
|
c = str[j];
|
2003-12-31 06:59:33 +08:00
|
|
|
sobj[k]=c;
|
2005-08-14 04:53:35 +08:00
|
|
|
if ( c==',' || j==end_obj-1)
|
2003-10-23 05:43:34 +08:00
|
|
|
{
|
2003-12-31 06:59:33 +08:00
|
|
|
if ( c==',') sobj[k]='\0'; else sobj[k+1]='\0';
|
|
|
|
strcpy(obj_list[n].obj,sobj);
|
|
|
|
memset(sobj,0,sizeof(sobj));
|
2003-10-23 05:43:34 +08:00
|
|
|
n++;
|
|
|
|
k=-1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* nothing after : */
|
|
|
|
if (end_obj+1==(int)len)
|
|
|
|
{
|
|
|
|
if (obj_list) free(obj_list);
|
2006-10-05 22:35:40 +08:00
|
|
|
error_msg(progname, "in parse layout, no characters after : in <%s>\n",str);
|
2003-10-23 05:43:34 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2003-12-31 06:59:33 +08:00
|
|
|
/* get layout info */
|
|
|
|
for ( j=end_obj+1, n=0; n<=5; j++,n++)
|
2003-10-23 05:43:34 +08:00
|
|
|
{
|
2005-08-14 04:53:35 +08:00
|
|
|
if (n==5)
|
2003-10-23 05:43:34 +08:00
|
|
|
{
|
2003-12-31 06:59:33 +08:00
|
|
|
slayout[n]='\0'; /*cut string */
|
|
|
|
if (strcmp(slayout,"COMPA")==0)
|
2005-08-14 04:53:35 +08:00
|
|
|
pack->layout=H5D_COMPACT;
|
2003-12-31 06:59:33 +08:00
|
|
|
else if (strcmp(slayout,"CONTI")==0)
|
|
|
|
pack->layout=H5D_CONTIGUOUS;
|
|
|
|
else if (strcmp(slayout,"CHUNK")==0)
|
|
|
|
pack->layout=H5D_CHUNKED;
|
|
|
|
else {
|
2006-10-05 22:35:40 +08:00
|
|
|
error_msg(progname, "in parse layout, not a valid layout in <%s>\n",str);
|
2004-07-16 03:25:27 +08:00
|
|
|
exit(1);
|
2003-10-23 05:43:34 +08:00
|
|
|
}
|
2003-12-31 06:59:33 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
c = str[j];
|
|
|
|
slayout[n]=c;
|
|
|
|
}
|
|
|
|
} /* j */
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-12-31 06:59:33 +08:00
|
|
|
|
2003-12-31 22:00:36 +08:00
|
|
|
if ( pack->layout==H5D_CHUNKED )
|
2003-12-31 06:59:33 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* get chunk info
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2005-08-14 04:53:35 +08:00
|
|
|
k=0;
|
2004-01-08 23:53:32 +08:00
|
|
|
|
|
|
|
if (j>(int)len)
|
|
|
|
{
|
|
|
|
if (obj_list) free(obj_list);
|
2006-10-05 22:35:40 +08:00
|
|
|
error_msg(progname, "in parse layout, <%s> Chunk dimensions missing\n",str);
|
2004-01-08 23:53:32 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2003-12-31 06:59:33 +08:00
|
|
|
for ( i=j, c_index=0; i<len; i++)
|
|
|
|
{
|
|
|
|
c = str[i];
|
|
|
|
sdim[k]=c;
|
|
|
|
k++; /*increment sdim index */
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
|
|
if (!isdigit(c) && c!='x'
|
2004-08-18 03:54:42 +08:00
|
|
|
&& c!='N' && c!='O' && c!='N' && c!='E'
|
|
|
|
){
|
2003-12-31 06:59:33 +08:00
|
|
|
if (obj_list) free(obj_list);
|
2006-10-05 22:35:40 +08:00
|
|
|
error_msg(progname, "in parse layout, <%s> Not a valid character in <%s>\n",
|
2003-12-31 06:59:33 +08:00
|
|
|
sdim,str);
|
|
|
|
exit(1);
|
2003-10-23 05:43:34 +08:00
|
|
|
}
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
|
|
if ( c=='x' || i==len-1)
|
2003-10-23 05:43:34 +08:00
|
|
|
{
|
2005-08-14 04:53:35 +08:00
|
|
|
if ( c=='x') {
|
|
|
|
sdim[k-1]='\0';
|
2003-12-31 06:59:33 +08:00
|
|
|
k=0;
|
|
|
|
pack->chunk.chunk_lengths[c_index]=atoi(sdim);
|
|
|
|
if (pack->chunk.chunk_lengths[c_index]==0) {
|
|
|
|
if (obj_list) free(obj_list);
|
2006-10-05 22:35:40 +08:00
|
|
|
error_msg(progname, "in parse layout, <%s> conversion to number in <%s>\n",
|
2003-12-31 06:59:33 +08:00
|
|
|
sdim,str);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
c_index++;
|
2003-10-23 05:43:34 +08:00
|
|
|
}
|
2003-12-31 06:59:33 +08:00
|
|
|
else if (i==len-1) { /*no more parameters */
|
2005-08-14 04:53:35 +08:00
|
|
|
sdim[k]='\0';
|
2003-12-31 06:59:33 +08:00
|
|
|
k=0;
|
|
|
|
if (strcmp(sdim,"NONE")==0)
|
|
|
|
{
|
|
|
|
pack->chunk.rank=-2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pack->chunk.chunk_lengths[c_index]=atoi(sdim);
|
|
|
|
if (pack->chunk.chunk_lengths[c_index]==0){
|
|
|
|
if (obj_list) free(obj_list);
|
2006-10-05 22:35:40 +08:00
|
|
|
error_msg(progname, "in parse layout, <%s> conversion to number in <%s>\n",
|
2003-12-31 06:59:33 +08:00
|
|
|
sdim,str);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
pack->chunk.rank=c_index+1;
|
|
|
|
}
|
|
|
|
} /*if */
|
|
|
|
} /*if c=='x' || i==len-1 */
|
|
|
|
} /*i*/
|
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-12-31 06:59:33 +08:00
|
|
|
} /*H5D_CHUNKED*/
|
2003-10-23 05:43:34 +08:00
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-10-23 05:43:34 +08:00
|
|
|
return obj_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: parse_number
|
|
|
|
*
|
|
|
|
* Purpose: read a number from command line argument
|
|
|
|
*
|
|
|
|
* Return: number, -1 for FAIL
|
|
|
|
*
|
|
|
|
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
|
|
|
|
*
|
|
|
|
* Date: September, 23, 2003
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
int parse_number(char *str)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
int n;
|
|
|
|
char c;
|
|
|
|
size_t len=strlen(str);
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-10-23 05:43:34 +08:00
|
|
|
for ( i=0; i<len; i++)
|
|
|
|
{
|
|
|
|
c = str[i];
|
|
|
|
if (!isdigit(c)){
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2005-08-14 04:53:35 +08:00
|
|
|
str[i]='\0';
|
2003-10-23 05:43:34 +08:00
|
|
|
n=atoi(str);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|